@dev-anywhere/relay 0.10.3 → 0.10.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/web/assets/{fvad-BPZopehQ.js → fvad-B4AqN0qc.js} +1 -1
- package/assets/web/assets/{index-Dj9F-Tk8.js → index-B2Qm0XWF.js} +4 -4
- package/assets/web/assets/{jmuxer.min-CT3OjDKg.js → jmuxer.min-CA3NmHb7.js} +1 -1
- package/assets/web/index.html +1 -1
- package/assets/web/sw.js +1 -1
- package/package.json +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/jmuxer.min-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/jmuxer.min-CA3NmHb7.js","assets/__vite-browser-external-D7Ct-6yo.js"])))=>i.map(i=>d[i]);
|
|
2
2
|
var QW=Object.defineProperty;var eq=(e,t,n)=>t in e?QW(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var ze=(e,t,n)=>eq(e,typeof t!="symbol"?t+"":t,n);function tq(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 cm(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function JDe(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 Cx={exports:{}},Eh={};/**
|
|
3
3
|
* @license React
|
|
4
4
|
* react-jsx-runtime.production.js
|
|
@@ -602,7 +602,7 @@ ${s}`,l=C5(`${p1(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},Yae="DialogDescriptionWarning",Vae=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${f3(Yae).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},hk=J5,Kae=e3,pk=n3,mk=r3,gk=i3,h3=o3,p3=l3,Ib=u3;function Gae(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 Xae(e){const[t,n]=b.useState(void 0);return ns(()=>{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 Zae=["top","right","bottom","left"],tc=Math.min,Ws=Math.max,$y=Math.round,xv=Math.floor,aa=e=>({x:e,y:e}),Jae={left:"right",right:"left",bottom:"top",top:"bottom"};function w1(e,t,n){return Ws(e,tc(t,n))}function qa(e,t){return typeof e=="function"?e(t):e}function Ya(e){return e.split("-")[0]}function xf(e){return e.split("-")[1]}function vk(e){return e==="x"?"y":"x"}function yk(e){return e==="y"?"height":"width"}function ia(e){const t=e[0];return t==="t"||t==="b"?"y":"x"}function bk(e){return vk(ia(e))}function Qae(e,t,n){n===void 0&&(n=!1);const r=xf(e),i=bk(e),s=yk(i);let o=i==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(o=Hy(o)),[o,Hy(o)]}function ele(e){const t=Hy(e);return[x1(e),t,x1(t)]}function x1(e){return e.includes("start")?e.replace("start","end"):e.replace("end","start")}const Q2=["left","right"],eI=["right","left"],tle=["top","bottom"],nle=["bottom","top"];function rle(e,t,n){switch(e){case"top":case"bottom":return n?t?eI:Q2:t?Q2:eI;case"left":case"right":return t?tle:nle;default:return[]}}function ile(e,t,n,r){const i=xf(e);let s=rle(Ya(e),n==="start",r);return i&&(s=s.map(o=>o+"-"+i),t&&(s=s.concat(s.map(x1)))),s}function Hy(e){const t=Ya(e);return Jae[t]+e.slice(t.length)}function sle(e){return{top:0,right:0,bottom:0,left:0,...e}}function m3(e){return typeof e!="number"?sle(e):{top:e,right:e,bottom:e,left:e}}function Uy(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 tI(e,t,n){let{reference:r,floating:i}=e;const s=ia(t),o=bk(t),l=yk(o),u=Ya(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 ole(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}=qa(t,e),_=m3(g),S=l[v?h==="floating"?"reference":"floating":h],x=Uy(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},P=Uy(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:l,rect:T,offsetParent:k,strategy:u}):T);return{top:(x.top-P.top+_.top)/A.y,bottom:(P.bottom-x.bottom+_.bottom)/A.y,left:(x.left-P.left+_.left)/A.x,right:(P.right-x.right+_.right)/A.x}}const ale=50,lle=async(e,t,n)=>{const{placement:r="bottom",strategy:i="absolute",middleware:s=[],platform:o}=n,l=o.detectOverflow?o:{...o,detectOverflow:ole},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}=tI(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:P,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],...P},R&&g<ale&&(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}=tI(d,v,u)),w=-1)}return{x:f,y:h,placement:v,strategy:i,middlewareData:_}},cle=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}=qa(e,t)||{};if(d==null)return{};const h=m3(f),v={x:n,y:r},g=bk(i),_=yk(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[_],P=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-P/2,V=M/2-w[_]/2-1,W=tc(h[x],V),G=tc(h[T],V),O=W,N=M-w[_]-G,L=M/2-w[_]/2+z,D=w1(O,L,N),I=!u.arrow&&xf(i)!=null&&L!==D&&s.reference[_]/2-(L<O?W:G)-w[_]/2<0,B=I?L<O?L-O:L-N:0;return{[g]:v[g]+B,data:{[g]:D,centerOffset:L-D-B,...I&&{alignmentOffset:B}},reset:I}}}),ule=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}=qa(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const x=Ya(i),T=ia(l),k=Ya(l)===l,A=await(u.isRTL==null?void 0:u.isRTL(d.floating)),P=v||(k||!w?[Hy(l)]:ele(l)),R=_!=="none";!v&&R&&P.push(...ile(l,w,_,A));const M=[l,...P],z=await u.detectOverflow(t,S),V=[];let W=((r=s.flip)==null?void 0:r.overflows)||[];if(f&&V.push(z[x]),h){const L=Qae(i,o,A);V.push(z[L[0]],z[L[1]])}if(W=[...W,{placement:i,overflows:V}],!V.every(L=>L<=0)){var G,O;const L=(((G=s.flip)==null?void 0:G.index)||0)+1,D=M[L];if(D&&(!(h==="alignment"?T!==ia(D):!1)||W.every(F=>ia(F.placement)===T?F.overflows[0]>0:!0)))return{data:{index:L,overflows:W},reset:{placement:D}};let I=(O=W.filter(B=>B.overflows[0]<=0).sort((B,F)=>B.overflows[1]-F.overflows[1])[0])==null?void 0:O.placement;if(!I)switch(g){case"bestFit":{var N;const B=(N=W.filter(F=>{if(R){const U=ia(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&&(I=B);break}case"initialPlacement":I=l;break}if(i!==I)return{reset:{placement:I}}}return{}}}};function nI(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function rI(e){return Zae.some(t=>e[t]>=0)}const dle=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n,platform:r}=t,{strategy:i="referenceHidden",...s}=qa(e,t);switch(i){case"referenceHidden":{const o=await r.detectOverflow(t,{...s,elementContext:"reference"}),l=nI(o,n.reference);return{data:{referenceHiddenOffsets:l,referenceHidden:rI(l)}}}case"escaped":{const o=await r.detectOverflow(t,{...s,altBoundary:!0}),l=nI(o,n.floating);return{data:{escapedOffsets:l,escaped:rI(l)}}}default:return{}}}}},g3=new Set(["left","top"]);async function fle(e,t){const{placement:n,platform:r,elements:i}=e,s=await(r.isRTL==null?void 0:r.isRTL(i.floating)),o=Ya(n),l=xf(n),u=ia(n)==="y",d=g3.has(o)?-1:1,f=s&&u?-1:1,h=qa(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 hle=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 fle(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}}}}},ple=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}=qa(e,t),f={x:n,y:r},h=await s.detectOverflow(t,d),v=ia(Ya(i)),g=vk(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];_=w1(k,_,A)}if(l){const x=v==="y"?"top":"left",T=v==="y"?"bottom":"right",k=w+h[x],A=w-h[T];w=w1(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}}}}}},mle=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}=qa(e,t),f={x:n,y:r},h=ia(i),v=vk(h);let g=f[v],_=f[h];const w=qa(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,P=s.reference[v]+s.reference[k]-S.mainAxis;g<A?g=A:g>P&&(g=P)}if(d){var x,T;const k=v==="y"?"width":"height",A=g3.has(Ya(i)),P=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);_<P?_=P:_>R&&(_=R)}return{[v]:g,[h]:_}}}},gle=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}=qa(e,t),f=await o.detectOverflow(t,d),h=Ya(i),v=xf(i),g=ia(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=tc(w-f[S],T),P=tc(_-f[x],k),R=!t.middlewareData.shift;let M=A,z=P;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 V=await o.getDimensions(l.floating);return _!==V.width||w!==V.height?{reset:{rects:!0}}:{}}}};function Ob(){return typeof window<"u"}function Sf(e){return v3(e)?(e.nodeName||"").toLowerCase():"#document"}function Vs(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function pa(e){var t;return(t=(v3(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function v3(e){return Ob()?e instanceof Node||e instanceof Vs(e).Node:!1}function Lo(e){return Ob()?e instanceof Element||e instanceof Vs(e).Element:!1}function Xa(e){return Ob()?e instanceof HTMLElement||e instanceof Vs(e).HTMLElement:!1}function iI(e){return!Ob()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Vs(e).ShadowRoot}function wm(e){const{overflow:t,overflowX:n,overflowY:r,display:i}=Do(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&i!=="inline"&&i!=="contents"}function vle(e){return/^(table|td|th)$/.test(Sf(e))}function Lb(e){try{if(e.matches(":popover-open"))return!0}catch{}try{return e.matches(":modal")}catch{return!1}}const yle=/transform|translate|scale|rotate|perspective|filter/,ble=/paint|layout|strict|content/,Hc=e=>!!e&&e!=="none";let _0;function _k(e){const t=Lo(e)?Do(e):e;return Hc(t.transform)||Hc(t.translate)||Hc(t.scale)||Hc(t.rotate)||Hc(t.perspective)||!wk()&&(Hc(t.backdropFilter)||Hc(t.filter))||yle.test(t.willChange||"")||ble.test(t.contain||"")}function _le(e){let t=nc(e);for(;Xa(t)&&!lf(t);){if(_k(t))return t;if(Lb(t))return null;t=nc(t)}return null}function wk(){return _0==null&&(_0=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),_0}function lf(e){return/^(html|body|#document)$/.test(Sf(e))}function Do(e){return Vs(e).getComputedStyle(e)}function Db(e){return Lo(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function nc(e){if(Sf(e)==="html")return e;const t=e.assignedSlot||e.parentNode||iI(e)&&e.host||pa(e);return iI(t)?t.host:t}function y3(e){const t=nc(e);return lf(t)?e.ownerDocument?e.ownerDocument.body:e.body:Xa(t)&&wm(t)?t:y3(t)}function Kp(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const i=y3(e),s=i===((r=e.ownerDocument)==null?void 0:r.body),o=Vs(i);if(s){const l=S1(o);return t.concat(o,o.visualViewport||[],wm(i)?i:[],l&&n?Kp(l):[])}else return t.concat(i,Kp(i,[],n))}function S1(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function b3(e){const t=Do(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const i=Xa(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 xk(e){return Lo(e)?e:e.contextElement}function Gd(e){const t=xk(e);if(!Xa(t))return aa(1);const n=t.getBoundingClientRect(),{width:r,height:i,$:s}=b3(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 wle=aa(0);function _3(e){const t=Vs(e);return!wk()||!t.visualViewport?wle:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function xle(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=xk(e);let o=aa(1);t&&(r?Lo(r)&&(o=Gd(r)):o=Gd(e));const l=xle(s,n,r)?_3(s):aa(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&&Lo(r)?Vs(r):r;let _=v,w=S1(_);for(;w&&r&&g!==_;){const S=Gd(w),x=w.getBoundingClientRect(),T=Do(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=S1(_)}}return Uy({width:f,height:h,x:u,y:d})}function Bb(e,t){const n=Db(e).scrollLeft;return t?t.left+n:fu(pa(e)).left+n}function w3(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-Bb(e,n),i=n.top+t.scrollTop;return{x:r,y:i}}function Sle(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e;const s=i==="fixed",o=pa(r),l=t?Lb(t.floating):!1;if(r===o||l&&s)return n;let u={scrollLeft:0,scrollTop:0},d=aa(1);const f=aa(0),h=Xa(r);if((h||!h&&!s)&&((Sf(r)!=="body"||wm(o))&&(u=Db(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?w3(o,u):aa(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 Ele(e){return Array.from(e.getClientRects())}function Cle(e){const t=pa(e),n=Db(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+Bb(e);const l=-n.scrollTop;return Do(r).direction==="rtl"&&(o+=Ws(t.clientWidth,r.clientWidth)-i),{width:i,height:s,x:o,y:l}}const sI=25;function kle(e,t){const n=Vs(e),r=pa(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=wk();(!f||f&&t==="fixed")&&(l=i.offsetLeft,u=i.offsetTop)}const d=Bb(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);_<=sI&&(s-=_)}else d<=sI&&(s+=d);return{width:s,height:o,x:l,y:u}}function Tle(e,t){const n=fu(e,!0,t==="fixed"),r=n.top+e.clientTop,i=n.left+e.clientLeft,s=Xa(e)?Gd(e):aa(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 oI(e,t,n){let r;if(t==="viewport")r=kle(e,n);else if(t==="document")r=Cle(pa(e));else if(Lo(t))r=Tle(t,n);else{const i=_3(e);r={x:t.x-i.x,y:t.y-i.y,width:t.width,height:t.height}}return Uy(r)}function x3(e,t){const n=nc(e);return n===t||!Lo(n)||lf(n)?!1:Do(n).position==="fixed"||x3(n,t)}function Rle(e,t){const n=t.get(e);if(n)return n;let r=Kp(e,[],!1).filter(l=>Lo(l)&&Sf(l)!=="body"),i=null;const s=Do(e).position==="fixed";let o=s?nc(e):e;for(;Lo(o)&&!lf(o);){const l=Do(o),u=_k(o);!u&&l.position==="fixed"&&(i=null),(s?!u&&!i:!u&&l.position==="static"&&!!i&&(i.position==="absolute"||i.position==="fixed")||wm(o)&&!u&&x3(e,o))?r=r.filter(f=>f!==o):i=l,o=nc(o)}return t.set(e,r),r}function Ale(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e;const o=[...n==="clippingAncestors"?Lb(t)?[]:Rle(t,this._c):[].concat(n),r],l=oI(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=oI(t,o[v],i);u=Ws(g.top,u),d=tc(g.right,d),f=tc(g.bottom,f),h=Ws(g.left,h)}return{width:d-h,height:f-u,x:h,y:u}}function Nle(e){const{width:t,height:n}=b3(e);return{width:t,height:n}}function Mle(e,t,n){const r=Xa(t),i=pa(t),s=n==="fixed",o=fu(e,!0,s,t);let l={scrollLeft:0,scrollTop:0};const u=aa(0);function d(){u.x=Bb(i)}if(r||!r&&!s)if((Sf(t)!=="body"||wm(i))&&(l=Db(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?w3(i,l):aa(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 w0(e){return Do(e).position==="static"}function aI(e,t){if(!Xa(e)||Do(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return pa(e)===n&&(n=n.ownerDocument.body),n}function S3(e,t){const n=Vs(e);if(Lb(e))return n;if(!Xa(e)){let i=nc(e);for(;i&&!lf(i);){if(Lo(i)&&!w0(i))return i;i=nc(i)}return n}let r=aI(e,t);for(;r&&vle(r)&&w0(r);)r=aI(r,t);return r&&lf(r)&&w0(r)&&!_k(r)?n:r||_le(e)||n}const Ple=async function(e){const t=this.getOffsetParent||S3,n=this.getDimensions,r=await n(e.floating);return{reference:Mle(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function Ile(e){return Do(e).direction==="rtl"}const Ole={convertOffsetParentRelativeRectToViewportRelativeRect:Sle,getDocumentElement:pa,getClippingRect:Ale,getOffsetParent:S3,getElementRects:Ple,getClientRects:Ele,getDimensions:Nle,getScale:Gd,isElement:Lo,isRTL:Ile};function E3(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function Lle(e,t){let n=null,r;const i=pa(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 _=xv(h),w=xv(i.clientWidth-(f+v)),S=xv(i.clientHeight-(h+g)),x=xv(f),k={rootMargin:-_+"px "+-w+"px "+-S+"px "+-x+"px",threshold:Ws(0,tc(1,u))||1};let A=!0;function P(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&&!E3(d,e.getBoundingClientRect())&&o(),A=!1}try{n=new IntersectionObserver(P,{...k,root:i.ownerDocument})}catch{n=new IntersectionObserver(P,k)}n.observe(e)}return o(!0),s}function Dle(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=xk(e),f=i||s?[...d?Kp(d):[],...t?Kp(t):[]]:[];f.forEach(x=>{i&&x.addEventListener("scroll",n,{passive:!0}),s&&x.addEventListener("resize",n)});const h=d&&l?Lle(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&&!E3(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 Ble=hle,zle=ple,jle=ule,Fle=gle,$le=dle,lI=cle,Hle=mle,Ule=(e,t,n)=>{const r=new Map,i={platform:Ole,...n},s={...i.platform,_c:r};return lle(e,t,{...i,platform:s})};var Wle=typeof document<"u",qle=function(){},uy=Wle?b.useLayoutEffect:qle;function Wy(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(!Wy(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)&&!Wy(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function C3(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function cI(e,t){const n=C3(e);return Math.round(t*n)/n}function x0(e){const t=b.useRef(e);return uy(()=>{t.current=e}),t}function Yle(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);Wy(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||_,P=o||S,R=b.useRef(null),M=b.useRef(null),z=b.useRef(f),V=u!=null,W=x0(u),G=x0(i),O=x0(d),N=b.useCallback(()=>{if(!R.current||!M.current)return;const F={placement:t,strategy:n,middleware:v};G.current&&(F.platform=G.current),Ule(R.current,M.current,F).then(U=>{const j={...U,isPositioned:O.current!==!1};L.current&&!Wy(z.current,j)&&(z.current=j,Eu.flushSync(()=>{h(j)}))})},[v,t,n,G,O]);uy(()=>{d===!1&&z.current.isPositioned&&(z.current.isPositioned=!1,h(F=>({...F,isPositioned:!1})))},[d]);const L=b.useRef(!1);uy(()=>(L.current=!0,()=>{L.current=!1}),[]),uy(()=>{if(A&&(R.current=A),P&&(M.current=P),A&&P){if(W.current)return W.current(A,P,N);N()}},[A,P,N,W,V]);const D=b.useMemo(()=>({reference:R,floating:M,setReference:T,setFloating:k}),[T,k]),I=b.useMemo(()=>({reference:A,floating:P}),[A,P]),B=b.useMemo(()=>{const F={position:n,left:0,top:0};if(!I.floating)return F;const U=cI(I.floating,f.x),j=cI(I.floating,f.y);return l?{...F,transform:"translate("+U+"px, "+j+"px)",...C3(I.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:U,top:j}},[n,l,I.floating,f.x,f.y]);return b.useMemo(()=>({...f,update:N,refs:D,elements:I,floatingStyles:B}),[f,N,D,I,B])}const Vle=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?lI({element:r.current,padding:i}).fn(n):{}:r?lI({element:r,padding:i}).fn(n):{}}}},Kle=(e,t)=>{const n=Ble(e);return{name:n.name,fn:n.fn,options:[e,t]}},Gle=(e,t)=>{const n=zle(e);return{name:n.name,fn:n.fn,options:[e,t]}},Xle=(e,t)=>({fn:Hle(e).fn,options:[e,t]}),Zle=(e,t)=>{const n=jle(e);return{name:n.name,fn:n.fn,options:[e,t]}},Jle=(e,t)=>{const n=Fle(e);return{name:n.name,fn:n.fn,options:[e,t]}},Qle=(e,t)=>{const n=$le(e);return{name:n.name,fn:n.fn,options:[e,t]}},ece=(e,t)=>{const n=Vle(e);return{name:n.name,fn:n.fn,options:[e,t]}};var tce="Arrow",k3=b.forwardRef((e,t)=>{const{children:n,width:r=10,height:i=5,...s}=e;return m.jsx(En.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"})})});k3.displayName=tce;var nce=k3,Sk="Popper",[T3,dc]=Ga(Sk),[rce,R3]=T3(Sk),A3=e=>{const{__scopePopper:t,children:n}=e,[r,i]=b.useState(null);return m.jsx(rce,{scope:t,anchor:r,onAnchorChange:i,children:n})};A3.displayName=Sk;var N3="PopperAnchor",M3=b.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...i}=e,s=R3(N3,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(En.div,{...i,ref:l})});M3.displayName=N3;var Ek="PopperContent",[ice,sce]=T3(Ek),P3=b.forwardRef((e,t)=>{var Z,oe,Q,fe,ge,Ce;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=R3(Ek,n),[x,T]=b.useState(null),k=dr(t,De=>T(De)),[A,P]=b.useState(null),R=Xae(A),M=(R==null?void 0:R.width)??0,z=(R==null?void 0:R.height)??0,V=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(ace),altBoundary:O},{refs:L,floatingStyles:D,placement:I,isPositioned:B,middlewareData:F}=Yle({strategy:"fixed",placement:V,whileElementsMounted:(...De)=>Dle(...De,{animationFrame:g==="always"}),elements:{reference:S.anchor},middleware:[Kle({mainAxis:i+z,alignmentAxis:o}),u&&Gle({mainAxis:!0,crossAxis:!1,limiter:h==="partial"?Xle():void 0,...N}),u&&Zle({...N}),Jle({...N,apply:({elements:De,rects:ot,availableWidth:Dt,availableHeight:et})=>{const{width:ut,height:Ne}=ot.reference,Ue=De.floating.style;Ue.setProperty("--radix-popper-available-width",`${Dt}px`),Ue.setProperty("--radix-popper-available-height",`${et}px`),Ue.setProperty("--radix-popper-anchor-width",`${ut}px`),Ue.setProperty("--radix-popper-anchor-height",`${Ne}px`)}}),A&&ece({element:A,padding:l}),lce({arrowWidth:M,arrowHeight:z}),v&&Qle({strategy:"referenceHidden",...N})]}),[U,j]=L3(I),Y=Oo(_);ns(()=>{B&&(Y==null||Y())},[B,Y]);const X=(Z=F.arrow)==null?void 0:Z.x,$=(oe=F.arrow)==null?void 0:oe.y,ee=((Q=F.arrow)==null?void 0:Q.centerOffset)!==0,[re,te]=b.useState();return ns(()=>{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:re,"--radix-popper-transform-origin":[(fe=F.transformOrigin)==null?void 0:fe.x,(ge=F.transformOrigin)==null?void 0:ge.y].join(" "),...((Ce=F.hide)==null?void 0:Ce.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:m.jsx(ice,{scope:n,placedSide:U,onArrowChange:P,arrowX:X,arrowY:$,shouldHideArrow:ee,children:m.jsx(En.div,{"data-side":U,"data-align":j,...w,ref:k,style:{...w.style,animation:B?void 0:"none"}})})})});P3.displayName=Ek;var I3="PopperArrow",oce={top:"bottom",right:"left",bottom:"top",left:"right"},O3=b.forwardRef(function(t,n){const{__scopePopper:r,...i}=t,s=sce(I3,r),o=oce[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(nce,{...i,ref:n,style:{...i.style,display:"block"}})})});O3.displayName=I3;function ace(e){return e!==null}var lce=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]=L3(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 L3(e){const[t,n="center"]=e.split("-");return[t,n]}var xm=A3,Sm=M3,zb=P3,jb=O3,S0="rovingFocusGroup.onEntryFocus",cce={bubbles:!1,cancelable:!0},Em="RovingFocusGroup",[E1,D3,uce]=lk(Em),[dce,B3]=Ga(Em,[uce]),[fce,hce]=dce(Em),z3=b.forwardRef((e,t)=>m.jsx(E1.Provider,{scope:e.__scopeRovingFocusGroup,children:m.jsx(E1.Slot,{scope:e.__scopeRovingFocusGroup,children:m.jsx(pce,{...e,ref:t})})}));z3.displayName=Em;var pce=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),_=ck(s),[w,S]=ec({prop:o,defaultProp:l??null,onChange:u,caller:Em}),[x,T]=b.useState(!1),k=Oo(d),A=D3(n),P=b.useRef(!1),[R,M]=b.useState(0);return b.useEffect(()=>{const z=v.current;if(z)return z.addEventListener(S0,k),()=>z.removeEventListener(S0,k)},[k]),m.jsx(fce,{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(En.div,{tabIndex:x||R===0?-1:0,"data-orientation":r,...h,ref:g,style:{outline:"none",...e.style},onMouseDown:Yt(e.onMouseDown,()=>{P.current=!0}),onFocus:Yt(e.onFocus,z=>{const V=!P.current;if(z.target===z.currentTarget&&V&&!x){const W=new CustomEvent(S0,cce);if(z.currentTarget.dispatchEvent(W),!W.defaultPrevented){const G=A().filter(I=>I.focusable),O=G.find(I=>I.active),N=G.find(I=>I.id===w),D=[O,N,...G].filter(Boolean).map(I=>I.ref.current);$3(D,f)}}P.current=!1}),onBlur:Yt(e.onBlur,()=>T(!1))})})}),j3="RovingFocusGroupItem",F3=b.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:i=!1,tabStopId:s,children:o,...l}=e,u=_i(),d=s||u,f=hce(j3,n),h=f.currentTabStopId===d,v=D3(n),{onFocusableItemAdd:g,onFocusableItemRemove:_,currentTabStopId:w}=f;return b.useEffect(()=>{if(r)return g(),()=>_()},[r,g,_]),m.jsx(E1.ItemSlot,{scope:n,id:d,focusable:r,active:i,children:m.jsx(En.span,{tabIndex:h?0:-1,"data-orientation":f.orientation,...l,ref:t,onMouseDown:Yt(e.onMouseDown,S=>{r?f.onItemFocus(d):S.preventDefault()}),onFocus:Yt(e.onFocus,()=>f.onItemFocus(d)),onKeyDown:Yt(e.onKeyDown,S=>{if(S.key==="Tab"&&S.shiftKey){f.onItemShiftTab();return}if(S.target!==S.currentTarget)return;const x=vce(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?yce(k,A+1):k.slice(A+1)}setTimeout(()=>$3(k))}}),children:typeof o=="function"?o({isCurrentTabStop:h,hasTabStop:w!=null}):o})})});F3.displayName=j3;var mce={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function gce(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function vce(e,t,n){const r=gce(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return mce[r]}function $3(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function yce(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var bce=z3,_ce=F3,C1=["Enter"," "],wce=["ArrowDown","PageUp","Home"],H3=["ArrowUp","PageDown","End"],xce=[...wce,...H3],Sce={ltr:[...C1,"ArrowRight"],rtl:[...C1,"ArrowLeft"]},Ece={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Cm="Menu",[Gp,Cce,kce]=lk(Cm),[Cu,U3]=Ga(Cm,[kce,dc,B3]),km=dc(),W3=B3(),[q3,fc]=Cu(Cm),[Tce,Tm]=Cu(Cm),Y3=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:i,onOpenChange:s,modal:o=!0}=e,l=km(t),[u,d]=b.useState(null),f=b.useRef(!1),h=Oo(s),v=ck(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(xm,{...l,children:m.jsx(q3,{scope:t,open:n,onOpenChange:h,content:u,onContentChange:d,children:m.jsx(Tce,{scope:t,onClose:b.useCallback(()=>h(!1),[h]),isUsingKeyboardRef:f,dir:v,modal:o,children:r})})})};Y3.displayName=Cm;var Rce="MenuAnchor",Ck=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=km(n);return m.jsx(Sm,{...i,...r,ref:t})});Ck.displayName=Rce;var kk="MenuPortal",[Ace,V3]=Cu(kk,{forceMount:void 0}),K3=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:i}=e,s=fc(kk,t);return m.jsx(Ace,{scope:t,forceMount:n,children:m.jsx(xo,{present:n||s.open,children:m.jsx(wf,{asChild:!0,container:i,children:r})})})};K3.displayName=kk;var go="MenuContent",[Nce,Tk]=Cu(go),G3=b.forwardRef((e,t)=>{const n=V3(go,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=fc(go,e.__scopeMenu),o=Tm(go,e.__scopeMenu);return m.jsx(Gp.Provider,{scope:e.__scopeMenu,children:m.jsx(xo,{present:r||s.open,children:m.jsx(Gp.Slot,{scope:e.__scopeMenu,children:o.modal?m.jsx(Mce,{...i,ref:t}):m.jsx(Pce,{...i,ref:t})})})})}),Mce=b.forwardRef((e,t)=>{const n=fc(go,e.__scopeMenu),r=b.useRef(null),i=dr(t,r);return b.useEffect(()=>{const s=r.current;if(s)return Mb(s)},[]),m.jsx(Rk,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:Yt(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),Pce=b.forwardRef((e,t)=>{const n=fc(go,e.__scopeMenu);return m.jsx(Rk,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),Ice=Ql("MenuContent.ScrollLock"),Rk=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=fc(go,n),x=Tm(go,n),T=km(n),k=W3(n),A=Cce(n),[P,R]=b.useState(null),M=b.useRef(null),z=dr(t,M,S.onContentChange),V=b.useRef(0),W=b.useRef(""),G=b.useRef(0),O=b.useRef(null),N=b.useRef("right"),L=b.useRef(0),D=_?_m:b.Fragment,I=_?{as:Ice,allowPinchZoom:!0}:void 0,B=U=>{var Z,oe;const j=W.current+U,Y=A().filter(Q=>!Q.disabled),X=document.activeElement,$=(Z=Y.find(Q=>Q.ref.current===X))==null?void 0:Z.textValue,ee=Y.map(Q=>Q.textValue),re=qce(ee,j,$),te=(oe=Y.find(Q=>Q.textValue===re))==null?void 0:oe.ref.current;(function Q(fe){W.current=fe,window.clearTimeout(V.current),fe!==""&&(V.current=window.setTimeout(()=>Q(""),1e3))})(j),te&&setTimeout(()=>te.focus())};b.useEffect(()=>()=>window.clearTimeout(V.current),[]),Ab();const F=b.useCallback(U=>{var Y,X;return N.current===((Y=O.current)==null?void 0:Y.side)&&Vce(U,(X=O.current)==null?void 0:X.area)},[]);return m.jsx(Nce,{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,{...I,children:m.jsx(bm,{asChild:!0,trapped:i,onMountAutoFocus:Yt(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(bce,{asChild:!0,...k,dir:x.dir,orientation:"vertical",loop:r,currentTabStopId:P,onCurrentTabStopIdChange:R,onEntryFocus:Yt(u,U=>{x.isUsingKeyboardRef.current||U.preventDefault()}),preventScrollOnEntryFocus:!0,children:m.jsx(zb,{role:"menu","aria-orientation":"vertical","data-state":f4(S.open),"data-radix-menu-content":"",dir:x.dir,...T,...w,ref:z,style:{outline:"none",...w.style},onKeyDown:Yt(w.onKeyDown,U=>{const Y=U.target.closest("[data-radix-menu-content]")===U.currentTarget,X=U.ctrlKey||U.altKey||U.metaKey,$=U.key.length===1;Y&&(U.key==="Tab"&&U.preventDefault(),!X&&$&&B(U.key));const ee=M.current;if(U.target!==ee||!xce.includes(U.key))return;U.preventDefault();const te=A().filter(Z=>!Z.disabled).map(Z=>Z.ref.current);H3.includes(U.key)&&te.reverse(),Uce(te)}),onBlur:Yt(e.onBlur,U=>{U.currentTarget.contains(U.target)||(window.clearTimeout(V.current),W.current="")}),onPointerMove:Yt(e.onPointerMove,Xp(U=>{const j=U.target,Y=L.current!==U.clientX;if(U.currentTarget.contains(j)&&Y){const X=U.clientX>L.current?"right":"left";N.current=X,L.current=U.clientX}}))})})})})})})});G3.displayName=go;var Oce="MenuGroup",Ak=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return m.jsx(En.div,{role:"group",...r,ref:t})});Ak.displayName=Oce;var Lce="MenuLabel",X3=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return m.jsx(En.div,{...r,ref:t})});X3.displayName=Lce;var qy="MenuItem",uI="menu.itemSelect",Fb=b.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...i}=e,s=b.useRef(null),o=Tm(qy,e.__scopeMenu),l=Tk(qy,e.__scopeMenu),u=dr(t,s),d=b.useRef(!1),f=()=>{const h=s.current;if(!n&&h){const v=new CustomEvent(uI,{bubbles:!0,cancelable:!0});h.addEventListener(uI,g=>r==null?void 0:r(g),{once:!0}),D5(h,v),v.defaultPrevented?d.current=!1:o.onClose()}};return m.jsx(Z3,{...i,ref:u,disabled:n,onClick:Yt(e.onClick,f),onPointerDown:h=>{var v;(v=e.onPointerDown)==null||v.call(e,h),d.current=!0},onPointerUp:Yt(e.onPointerUp,h=>{var v;d.current||(v=h.currentTarget)==null||v.click()}),onKeyDown:Yt(e.onKeyDown,h=>{const v=l.searchRef.current!=="";n||v&&h.key===" "||C1.includes(h.key)&&(h.currentTarget.click(),h.preventDefault())})})});Fb.displayName=qy;var Z3=b.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:i,...s}=e,o=Tk(qy,n),l=W3(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(Gp.ItemSlot,{scope:n,disabled:r,textValue:i??v,children:m.jsx(_ce,{asChild:!0,...l,focusable:!r,children:m.jsx(En.div,{role:"menuitem","data-highlighted":f?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:d,onPointerMove:Yt(e.onPointerMove,Xp(_=>{r?o.onItemLeave(_):(o.onItemEnter(_),_.defaultPrevented||_.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:Yt(e.onPointerLeave,Xp(_=>o.onItemLeave(_))),onFocus:Yt(e.onFocus,()=>h(!0)),onBlur:Yt(e.onBlur,()=>h(!1))})})})}),Dce="MenuCheckboxItem",J3=b.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...i}=e;return m.jsx(r4,{scope:e.__scopeMenu,checked:n,children:m.jsx(Fb,{role:"menuitemcheckbox","aria-checked":Yy(n)?"mixed":n,...i,ref:t,"data-state":Pk(n),onSelect:Yt(i.onSelect,()=>r==null?void 0:r(Yy(n)?!0:!n),{checkForDefaultPrevented:!1})})})});J3.displayName=Dce;var Q3="MenuRadioGroup",[Bce,zce]=Cu(Q3,{value:void 0,onValueChange:()=>{}}),e4=b.forwardRef((e,t)=>{const{value:n,onValueChange:r,...i}=e,s=Oo(r);return m.jsx(Bce,{scope:e.__scopeMenu,value:n,onValueChange:s,children:m.jsx(Ak,{...i,ref:t})})});e4.displayName=Q3;var t4="MenuRadioItem",n4=b.forwardRef((e,t)=>{const{value:n,...r}=e,i=zce(t4,e.__scopeMenu),s=n===i.value;return m.jsx(r4,{scope:e.__scopeMenu,checked:s,children:m.jsx(Fb,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":Pk(s),onSelect:Yt(r.onSelect,()=>{var o;return(o=i.onValueChange)==null?void 0:o.call(i,n)},{checkForDefaultPrevented:!1})})})});n4.displayName=t4;var Nk="MenuItemIndicator",[r4,jce]=Cu(Nk,{checked:!1}),i4=b.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...i}=e,s=jce(Nk,n);return m.jsx(xo,{present:r||Yy(s.checked)||s.checked===!0,children:m.jsx(En.span,{...i,ref:t,"data-state":Pk(s.checked)})})});i4.displayName=Nk;var Fce="MenuSeparator",s4=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return m.jsx(En.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});s4.displayName=Fce;var $ce="MenuArrow",o4=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=km(n);return m.jsx(jb,{...i,...r,ref:t})});o4.displayName=$ce;var Mk="MenuSub",[Hce,a4]=Cu(Mk),l4=e=>{const{__scopeMenu:t,children:n,open:r=!1,onOpenChange:i}=e,s=fc(Mk,t),o=km(t),[l,u]=b.useState(null),[d,f]=b.useState(null),h=Oo(i);return b.useEffect(()=>(s.open===!1&&h(!1),()=>h(!1)),[s.open,h]),m.jsx(xm,{...o,children:m.jsx(q3,{scope:t,open:r,onOpenChange:h,content:d,onContentChange:f,children:m.jsx(Hce,{scope:t,contentId:_i(),triggerId:_i(),trigger:l,onTriggerChange:u,children:n})})})};l4.displayName=Mk;var fp="MenuSubTrigger",c4=b.forwardRef((e,t)=>{const n=fc(fp,e.__scopeMenu),r=Tm(fp,e.__scopeMenu),i=a4(fp,e.__scopeMenu),s=Tk(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(Ck,{asChild:!0,...d,children:m.jsx(Z3,{id:i.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":i.contentId,"data-state":f4(n.open),...e,ref:Wa(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:Yt(e.onPointerMove,Xp(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:Yt(e.onPointerLeave,Xp(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:Yt(e.onKeyDown,h=>{var g;const v=s.searchRef.current!=="";e.disabled||v&&h.key===" "||Sce[r.dir].includes(h.key)&&(n.onOpenChange(!0),(g=n.content)==null||g.focus(),h.preventDefault())})})})});c4.displayName=fp;var u4="MenuSubContent",d4=b.forwardRef((e,t)=>{const n=V3(go,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=fc(go,e.__scopeMenu),o=Tm(go,e.__scopeMenu),l=a4(u4,e.__scopeMenu),u=b.useRef(null),d=dr(t,u);return m.jsx(Gp.Provider,{scope:e.__scopeMenu,children:m.jsx(xo,{present:r||s.open,children:m.jsx(Gp.Slot,{scope:e.__scopeMenu,children:m.jsx(Rk,{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:Yt(e.onFocusOutside,f=>{f.target!==l.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:Yt(e.onEscapeKeyDown,f=>{o.onClose(),f.preventDefault()}),onKeyDown:Yt(e.onKeyDown,f=>{var g;const h=f.currentTarget.contains(f.target),v=Ece[o.dir].includes(f.key);h&&v&&(s.onOpenChange(!1),(g=l.trigger)==null||g.focus(),f.preventDefault())})})})})})});d4.displayName=u4;function f4(e){return e?"open":"closed"}function Yy(e){return e==="indeterminate"}function Pk(e){return Yy(e)?"indeterminate":e?"checked":"unchecked"}function Uce(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function Wce(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function qce(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=Wce(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 Yce(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 Vce(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return Yce(n,t)}function Xp(e){return t=>t.pointerType==="mouse"?e(t):void 0}var Kce=Y3,Gce=Ck,Xce=K3,Zce=G3,Jce=Ak,Qce=X3,eue=Fb,tue=J3,nue=e4,rue=n4,iue=i4,sue=s4,oue=o4,aue=l4,lue=c4,cue=d4,$b="DropdownMenu",[uue]=Ga($b,[U3]),rs=U3(),[due,h4]=uue($b),p4=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:i,defaultOpen:s,onOpenChange:o,modal:l=!0}=e,u=rs(t),d=b.useRef(null),[f,h]=ec({prop:i,defaultProp:s??!1,onChange:o,caller:$b});return m.jsx(due,{scope:t,triggerId:_i(),triggerRef:d,contentId:_i(),open:f,onOpenChange:h,onOpenToggle:b.useCallback(()=>h(v=>!v),[h]),modal:l,children:m.jsx(Kce,{...u,open:f,onOpenChange:h,dir:r,modal:l,children:n})})};p4.displayName=$b;var m4="DropdownMenuTrigger",g4=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...i}=e,s=h4(m4,n),o=rs(n);return m.jsx(Gce,{asChild:!0,...o,children:m.jsx(En.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:Wa(t,s.triggerRef),onPointerDown:Yt(e.onPointerDown,l=>{!r&&l.button===0&&l.ctrlKey===!1&&(s.onOpenToggle(),s.open||l.preventDefault())}),onKeyDown:Yt(e.onKeyDown,l=>{r||(["Enter"," "].includes(l.key)&&s.onOpenToggle(),l.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(l.key)&&l.preventDefault())})})})});g4.displayName=m4;var fue="DropdownMenuPortal",v4=e=>{const{__scopeDropdownMenu:t,...n}=e,r=rs(t);return m.jsx(Xce,{...r,...n})};v4.displayName=fue;var y4="DropdownMenuContent",b4=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=h4(y4,n),s=rs(n),o=b.useRef(!1);return m.jsx(Zce,{id:i.contentId,"aria-labelledby":i.triggerId,...s,...r,ref:t,onCloseAutoFocus:Yt(e.onCloseAutoFocus,l=>{var u;o.current||(u=i.triggerRef.current)==null||u.focus(),o.current=!1,l.preventDefault()}),onInteractOutside:Yt(e.onInteractOutside,l=>{const u=l.detail.originalEvent,d=u.button===0&&u.ctrlKey===!0,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)"}})});b4.displayName=y4;var hue="DropdownMenuGroup",pue=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=rs(n);return m.jsx(Jce,{...i,...r,ref:t})});pue.displayName=hue;var mue="DropdownMenuLabel",_4=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=rs(n);return m.jsx(Qce,{...i,...r,ref:t})});_4.displayName=mue;var gue="DropdownMenuItem",w4=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=rs(n);return m.jsx(eue,{...i,...r,ref:t})});w4.displayName=gue;var vue="DropdownMenuCheckboxItem",x4=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=rs(n);return m.jsx(tue,{...i,...r,ref:t})});x4.displayName=vue;var yue="DropdownMenuRadioGroup",bue=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=rs(n);return m.jsx(nue,{...i,...r,ref:t})});bue.displayName=yue;var _ue="DropdownMenuRadioItem",wue=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=rs(n);return m.jsx(rue,{...i,...r,ref:t})});wue.displayName=_ue;var xue="DropdownMenuItemIndicator",S4=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=rs(n);return m.jsx(iue,{...i,...r,ref:t})});S4.displayName=xue;var Sue="DropdownMenuSeparator",E4=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=rs(n);return m.jsx(sue,{...i,...r,ref:t})});E4.displayName=Sue;var Eue="DropdownMenuArrow",Cue=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=rs(n);return m.jsx(oue,{...i,...r,ref:t})});Cue.displayName=Eue;var kue=e=>{const{__scopeDropdownMenu:t,children:n,open:r,onOpenChange:i,defaultOpen:s}=e,o=rs(t),[l,u]=ec({prop:r,defaultProp:s??!1,onChange:i,caller:"DropdownMenuSub"});return m.jsx(aue,{...o,open:l,onOpenChange:u,children:n})},Tue="DropdownMenuSubTrigger",C4=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=rs(n);return m.jsx(lue,{...i,...r,ref:t})});C4.displayName=Tue;var Rue="DropdownMenuSubContent",k4=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=rs(n);return m.jsx(cue,{...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)"}})});k4.displayName=Rue;var Aue=p4,Nue=g4,T4=v4,Mue=b4,Pue=_4,Iue=w4,Oue=x4,Lue=S4,Due=E4,Bue=kue,zue=C4,jue=k4;function dI(e,[t,n]){return Math.min(n,Math.max(t,e))}var Hb="Popover",[R4]=Ga(Hb,[dc]),Rm=dc(),[Fue,hc]=R4(Hb),A4=e=>{const{__scopePopover:t,children:n,open:r,defaultOpen:i,onOpenChange:s,modal:o=!1}=e,l=Rm(t),u=b.useRef(null),[d,f]=b.useState(!1),[h,v]=ec({prop:r,defaultProp:i??!1,onChange:s,caller:Hb});return m.jsx(xm,{...l,children:m.jsx(Fue,{scope:t,contentId:_i(),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})})};A4.displayName=Hb;var N4="PopoverAnchor",$ue=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=hc(N4,n),s=Rm(n),{onCustomAnchorAdd:o,onCustomAnchorRemove:l}=i;return b.useEffect(()=>(o(),()=>l()),[o,l]),m.jsx(Sm,{...s,...r,ref:t})});$ue.displayName=N4;var M4="PopoverTrigger",P4=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=hc(M4,n),s=Rm(n),o=dr(t,i.triggerRef),l=m.jsx(En.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.contentId,"data-state":B4(i.open),...r,ref:o,onClick:Yt(e.onClick,i.onOpenToggle)});return i.hasCustomAnchor?l:m.jsx(Sm,{asChild:!0,...s,children:l})});P4.displayName=M4;var Ik="PopoverPortal",[Hue,Uue]=R4(Ik,{forceMount:void 0}),I4=e=>{const{__scopePopover:t,forceMount:n,children:r,container:i}=e,s=hc(Ik,t);return m.jsx(Hue,{scope:t,forceMount:n,children:m.jsx(xo,{present:n||s.open,children:m.jsx(wf,{asChild:!0,container:i,children:r})})})};I4.displayName=Ik;var cf="PopoverContent",O4=b.forwardRef((e,t)=>{const n=Uue(cf,e.__scopePopover),{forceMount:r=n.forceMount,...i}=e,s=hc(cf,e.__scopePopover);return m.jsx(xo,{present:r||s.open,children:s.modal?m.jsx(que,{...i,ref:t}):m.jsx(Yue,{...i,ref:t})})});O4.displayName=cf;var Wue=Ql("PopoverContent.RemoveScroll"),que=b.forwardRef((e,t)=>{const n=hc(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 Mb(o)},[]),m.jsx(_m,{as:Wue,allowPinchZoom:!0,children:m.jsx(L4,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Yt(e.onCloseAutoFocus,o=>{var l;o.preventDefault(),s.current||(l=n.triggerRef.current)==null||l.focus()}),onPointerDownOutside:Yt(e.onPointerDownOutside,o=>{const l=o.detail.originalEvent,u=l.button===0&&l.ctrlKey===!0,d=l.button===2||u;s.current=d},{checkForDefaultPrevented:!1}),onFocusOutside:Yt(e.onFocusOutside,o=>o.preventDefault(),{checkForDefaultPrevented:!1})})})}),Yue=b.forwardRef((e,t)=>{const n=hc(cf,e.__scopePopover),r=b.useRef(!1),i=b.useRef(!1);return m.jsx(L4,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var o,l;(o=e.onCloseAutoFocus)==null||o.call(e,s),s.defaultPrevented||(r.current||(l=n.triggerRef.current)==null||l.focus(),s.preventDefault()),r.current=!1,i.current=!1},onInteractOutside:s=>{var u,d;(u=e.onInteractOutside)==null||u.call(e,s),s.defaultPrevented||(r.current=!0,s.detail.originalEvent.type==="pointerdown"&&(i.current=!0));const o=s.target;((d=n.triggerRef.current)==null?void 0:d.contains(o))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&i.current&&s.preventDefault()}})}),L4=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=hc(cf,n),g=Rm(n);return Ab(),m.jsx(bm,{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(zb,{"data-state":B4(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)"}})})})}),D4="PopoverClose",Vue=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=hc(D4,n);return m.jsx(En.button,{type:"button",...r,ref:t,onClick:Yt(e.onClick,()=>i.onOpenChange(!1))})});Vue.displayName=D4;var Kue="PopoverArrow",Gue=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=Rm(n);return m.jsx(jb,{...i,...r,ref:t})});Gue.displayName=Kue;function B4(e){return e?"open":"closed"}var Xue=A4,Zue=P4,Jue=I4,Que=O4,ede=[" ","Enter","ArrowUp","ArrowDown"],tde=[" ","Enter"],hu="Select",[Ub,Wb,nde]=lk(hu),[Ef]=Ga(hu,[nde,dc]),qb=dc(),[rde,pc]=Ef(hu),[ide,sde]=Ef(hu),z4=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=qb(t),[S,x]=b.useState(null),[T,k]=b.useState(null),[A,P]=b.useState(!1),R=ck(d),[M,z]=ec({prop:r,defaultProp:i??!1,onChange:s,caller:hu}),[V,W]=ec({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(I=>I.props.value).join(";");return m.jsx(xm,{...w,children:m.jsxs(rde,{required:g,scope:t,trigger:S,onTriggerChange:x,valueNode:T,onValueNodeChange:k,valueNodeHasChildren:A,onValueNodeHasChildrenChange:P,contentId:_i(),value:V,onValueChange:W,open:M,onOpenChange:z,dir:R,triggerPointerDownPosRef:G,disabled:v,children:[m.jsx(Ub.Provider,{scope:t,children:m.jsx(ide,{scope:e.__scopeSelect,onNativeOptionAdd:b.useCallback(I=>{L(B=>new Set(B).add(I))},[]),onNativeOptionRemove:b.useCallback(I=>{L(B=>{const F=new Set(B);return F.delete(I),F})},[]),children:n})}),O?m.jsxs(oF,{"aria-hidden":!0,required:g,tabIndex:-1,name:f,autoComplete:h,value:V,onChange:I=>W(I.target.value),disabled:v,form:_,children:[V===void 0?m.jsx("option",{value:""}):null,Array.from(N)]},D):null]})})};z4.displayName=hu;var j4="SelectTrigger",F4=b.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...i}=e,s=qb(n),o=pc(j4,n),l=o.disabled||r,u=dr(t,o.onTriggerChange),d=Wb(n),f=b.useRef("touch"),[h,v,g]=lF(w=>{const S=d().filter(k=>!k.disabled),x=S.find(k=>k.value===o.value),T=cF(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(Sm,{asChild:!0,...s,children:m.jsx(En.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":aF(o.value)?"":void 0,...i,ref:u,onClick:Yt(i.onClick,w=>{w.currentTarget.focus(),f.current!=="mouse"&&_(w)}),onPointerDown:Yt(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:Yt(i.onKeyDown,w=>{const S=h.current!=="";!(w.ctrlKey||w.altKey||w.metaKey)&&w.key.length===1&&v(w.key),!(S&&w.key===" ")&&ede.includes(w.key)&&(_(),w.preventDefault())})})})});F4.displayName=j4;var $4="SelectValue",H4=b.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:i,children:s,placeholder:o="",...l}=e,u=pc($4,n),{onValueNodeHasChildrenChange:d}=u,f=s!==void 0,h=dr(t,u.onValueNodeChange);return ns(()=>{d(f)},[d,f]),m.jsx(En.span,{...l,ref:h,style:{pointerEvents:"none"},children:aF(u.value)?m.jsx(m.Fragment,{children:o}):s})});H4.displayName=$4;var ode="SelectIcon",U4=b.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...i}=e;return m.jsx(En.span,{"aria-hidden":!0,...i,ref:t,children:r||"▼"})});U4.displayName=ode;var ade="SelectPortal",W4=e=>m.jsx(wf,{asChild:!0,...e});W4.displayName=ade;var pu="SelectContent",q4=b.forwardRef((e,t)=>{const n=pc(pu,e.__scopeSelect),[r,i]=b.useState();if(ns(()=>{i(new DocumentFragment)},[]),!n.open){const s=r;return s?Eu.createPortal(m.jsx(Y4,{scope:e.__scopeSelect,children:m.jsx(Ub.Slot,{scope:e.__scopeSelect,children:m.jsx("div",{children:e.children})})}),s):null}return m.jsx(V4,{...e,ref:t})});q4.displayName=pu;var Ao=10,[Y4,mc]=Ef(pu),lde="SelectContentImpl",cde=Ql("SelectContent.RemoveScroll"),V4=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=pc(pu,n),[k,A]=b.useState(null),[P,R]=b.useState(null),M=dr(t,Z=>A(Z)),[z,V]=b.useState(null),[W,G]=b.useState(null),O=Wb(n),[N,L]=b.useState(!1),D=b.useRef(!1);b.useEffect(()=>{if(k)return Mb(k)},[k]),Ab();const I=b.useCallback(Z=>{const[oe,...Q]=O().map(Ce=>Ce.ref.current),[fe]=Q.slice(-1),ge=document.activeElement;for(const Ce of Z)if(Ce===ge||(Ce==null||Ce.scrollIntoView({block:"nearest"}),Ce===oe&&P&&(P.scrollTop=0),Ce===fe&&P&&(P.scrollTop=P.scrollHeight),Ce==null||Ce.focus(),document.activeElement!==ge))return},[O,P]),B=b.useCallback(()=>I([z,k]),[I,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 oe=fe=>{var ge,Ce;Z={x:Math.abs(Math.round(fe.pageX)-(((ge=U.current)==null?void 0:ge.x)??0)),y:Math.abs(Math.round(fe.pageY)-(((Ce=U.current)==null?void 0:Ce.y)??0))}},Q=fe=>{Z.x<=10&&Z.y<=10?fe.preventDefault():k.contains(fe.target)||F(!1),document.removeEventListener("pointermove",oe),U.current=null};return U.current!==null&&(document.addEventListener("pointermove",oe),document.addEventListener("pointerup",Q,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",oe),document.removeEventListener("pointerup",Q,{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,Y]=lF(Z=>{const oe=O().filter(ge=>!ge.disabled),Q=oe.find(ge=>ge.ref.current===document.activeElement),fe=cF(oe,Z,Q);fe&&setTimeout(()=>fe.ref.current.focus())}),X=b.useCallback((Z,oe,Q)=>{const fe=!D.current&&!Q;(T.value!==void 0&&T.value===oe||fe)&&(V(Z),fe&&(D.current=!0))},[T.value]),$=b.useCallback(()=>k==null?void 0:k.focus(),[k]),ee=b.useCallback((Z,oe,Q)=>{const fe=!D.current&&!Q;(T.value!==void 0&&T.value===oe||fe)&&G(Z)},[T.value]),re=r==="popper"?k1:K4,te=re===k1?{side:l,sideOffset:u,align:d,alignOffset:f,arrowPadding:h,collisionBoundary:v,collisionPadding:g,sticky:_,hideWhenDetached:w,avoidCollisions:S}:{};return m.jsx(Y4,{scope:n,content:k,viewport:P,onViewportChange:R,itemRefCallback:X,selectedItem:z,onItemLeave:$,itemTextRefCallback:ee,focusSelectedItem:B,selectedItemText:W,position:r,isPositioned:N,searchRef:j,children:m.jsx(_m,{as:cde,allowPinchZoom:!0,children:m.jsx(bm,{asChild:!0,trapped:T.open,onMountAutoFocus:Z=>{Z.preventDefault()},onUnmountAutoFocus:Yt(i,Z=>{var oe;(oe=T.trigger)==null||oe.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(re,{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:Yt(x.onKeyDown,Z=>{const oe=Z.ctrlKey||Z.altKey||Z.metaKey;if(Z.key==="Tab"&&Z.preventDefault(),!oe&&Z.key.length===1&&Y(Z.key),["ArrowUp","ArrowDown","Home","End"].includes(Z.key)){let fe=O().filter(ge=>!ge.disabled).map(ge=>ge.ref.current);if(["ArrowUp","End"].includes(Z.key)&&(fe=fe.slice().reverse()),["ArrowUp","ArrowDown"].includes(Z.key)){const ge=Z.target,Ce=fe.indexOf(ge);fe=fe.slice(Ce+1)}setTimeout(()=>I(fe)),Z.preventDefault()}})})})})})})});V4.displayName=lde;var ude="SelectItemAlignedPosition",K4=b.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...i}=e,s=pc(pu,n),o=mc(pu,n),[l,u]=b.useState(null),[d,f]=b.useState(null),h=dr(t,M=>f(M)),v=Wb(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(),V=s.valueNode.getBoundingClientRect(),W=x.getBoundingClientRect();if(s.dir!=="rtl"){const ge=W.left-z.left,Ce=V.left-ge,De=M.left-Ce,ot=M.width+De,Dt=Math.max(ot,z.width),et=window.innerWidth-Ao,ut=dI(Ce,[Ao,Math.max(Ao,et-Dt)]);l.style.minWidth=ot+"px",l.style.left=ut+"px"}else{const ge=z.right-W.right,Ce=window.innerWidth-V.right-ge,De=window.innerWidth-M.right-Ce,ot=M.width+De,Dt=Math.max(ot,z.width),et=window.innerWidth-Ao,ut=dI(Ce,[Ao,Math.max(Ao,et-Dt)]);l.style.minWidth=ot+"px",l.style.right=ut+"px"}const G=v(),O=window.innerHeight-Ao*2,N=w.scrollHeight,L=window.getComputedStyle(d),D=parseInt(L.borderTopWidth,10),I=parseInt(L.paddingTop,10),B=parseInt(L.borderBottomWidth,10),F=parseInt(L.paddingBottom,10),U=D+I+N+F+B,j=Math.min(S.offsetHeight*5,U),Y=window.getComputedStyle(w),X=parseInt(Y.paddingTop,10),$=parseInt(Y.paddingBottom,10),ee=M.top+M.height/2-Ao,re=O-ee,te=S.offsetHeight/2,Z=S.offsetTop+te,oe=D+I+Z,Q=U-oe;if(oe<=ee){const ge=G.length>0&&S===G[G.length-1].ref.current;l.style.bottom="0px";const Ce=d.clientHeight-w.offsetTop-w.offsetHeight,De=Math.max(re,te+(ge?$:0)+Ce+B),ot=oe+De;l.style.height=ot+"px"}else{const ge=G.length>0&&S===G[0].ref.current;l.style.top="0px";const De=Math.max(ee,D+w.offsetTop+(ge?X:0)+te)+Q;l.style.height=De+"px",w.scrollTop=oe-ee+w.offsetTop}l.style.margin=`${Ao}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]);ns(()=>k(),[k]);const[A,P]=b.useState();ns(()=>{d&&P(window.getComputedStyle(d).zIndex)},[d]);const R=b.useCallback(M=>{M&&_.current===!0&&(k(),T==null||T(),_.current=!1)},[k,T]);return m.jsx(fde,{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(En.div,{...i,ref:h,style:{boxSizing:"border-box",maxHeight:"100%",...i.style}})})})});K4.displayName=ude;var dde="SelectPopperPosition",k1=b.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:i=Ao,...s}=e,o=qb(n);return m.jsx(zb,{...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)"}})});k1.displayName=dde;var[fde,Ok]=Ef(pu,{}),T1="SelectViewport",G4=b.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...i}=e,s=mc(T1,n),o=Ok(T1,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(Ub.Slot,{scope:n,children:m.jsx(En.div,{"data-radix-select-viewport":"",role:"presentation",...i,ref:l,style:{position:"relative",flex:1,overflow:"hidden auto",...i.style},onScroll:Yt(i.onScroll,d=>{const 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-Ao*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})})})]})});G4.displayName=T1;var X4="SelectGroup",[hde,pde]=Ef(X4),mde=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=_i();return m.jsx(hde,{scope:n,id:i,children:m.jsx(En.div,{role:"group","aria-labelledby":i,...r,ref:t})})});mde.displayName=X4;var Z4="SelectLabel",gde=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=pde(Z4,n);return m.jsx(En.div,{id:i.id,...r,ref:t})});gde.displayName=Z4;var Vy="SelectItem",[vde,J4]=Ef(Vy),Q4=b.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:i=!1,textValue:s,...o}=e,l=pc(Vy,n),u=mc(Vy,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=_i(),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(vde,{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(Ub.ItemSlot,{scope:n,value:r,disabled:i,textValue:f,children:m.jsx(En.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:Yt(o.onFocus,()=>g(!0)),onBlur:Yt(o.onBlur,()=>g(!1)),onClick:Yt(o.onClick,()=>{S.current!=="mouse"&&x()}),onPointerUp:Yt(o.onPointerUp,()=>{S.current==="mouse"&&x()}),onPointerDown:Yt(o.onPointerDown,T=>{S.current=T.pointerType}),onPointerMove:Yt(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:Yt(o.onPointerLeave,T=>{var k;T.currentTarget===document.activeElement&&((k=u.onItemLeave)==null||k.call(u))}),onKeyDown:Yt(o.onKeyDown,T=>{var A;((A=u.searchRef)==null?void 0:A.current)!==""&&T.key===" "||(tde.includes(T.key)&&x(),T.key===" "&&T.preventDefault())})})})})});Q4.displayName=Vy;var hp="SelectItemText",eF=b.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:i,...s}=e,o=pc(hp,n),l=mc(hp,n),u=J4(hp,n),d=sde(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 ns(()=>(w(_),()=>S(_)),[w,S,_]),m.jsxs(m.Fragment,{children:[m.jsx(En.span,{id:u.textId,...s,ref:v}),u.isSelected&&o.valueNode&&!o.valueNodeHasChildren?Eu.createPortal(s.children,o.valueNode):null]})});eF.displayName=hp;var tF="SelectItemIndicator",nF=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return J4(tF,n).isSelected?m.jsx(En.span,{"aria-hidden":!0,...r,ref:t}):null});nF.displayName=tF;var R1="SelectScrollUpButton",rF=b.forwardRef((e,t)=>{const n=mc(R1,e.__scopeSelect),r=Ok(R1,e.__scopeSelect),[i,s]=b.useState(!1),o=dr(t,r.onScrollButtonChange);return ns(()=>{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(sF,{...e,ref:o,onAutoScroll:()=>{const{viewport:l,selectedItem:u}=n;l&&u&&(l.scrollTop=l.scrollTop-u.offsetHeight)}}):null});rF.displayName=R1;var A1="SelectScrollDownButton",iF=b.forwardRef((e,t)=>{const n=mc(A1,e.__scopeSelect),r=Ok(A1,e.__scopeSelect),[i,s]=b.useState(!1),o=dr(t,r.onScrollButtonChange);return ns(()=>{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(sF,{...e,ref:o,onAutoScroll:()=>{const{viewport:l,selectedItem:u}=n;l&&u&&(l.scrollTop=l.scrollTop+u.offsetHeight)}}):null});iF.displayName=A1;var sF=b.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...i}=e,s=mc("SelectScrollButton",n),o=b.useRef(null),l=Wb(n),u=b.useCallback(()=>{o.current!==null&&(window.clearInterval(o.current),o.current=null)},[]);return b.useEffect(()=>()=>u(),[u]),ns(()=>{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(En.div,{"aria-hidden":!0,...i,ref:t,style:{flexShrink:0,...i.style},onPointerDown:Yt(i.onPointerDown,()=>{o.current===null&&(o.current=window.setInterval(r,50))}),onPointerMove:Yt(i.onPointerMove,()=>{var d;(d=s.onItemLeave)==null||d.call(s),o.current===null&&(o.current=window.setInterval(r,50))}),onPointerLeave:Yt(i.onPointerLeave,()=>{u()})})}),yde="SelectSeparator",bde=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return m.jsx(En.div,{"aria-hidden":!0,...r,ref:t})});bde.displayName=yde;var N1="SelectArrow",_de=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=qb(n),s=pc(N1,n),o=mc(N1,n);return s.open&&o.position==="popper"?m.jsx(jb,{...i,...r,ref:t}):null});_de.displayName=N1;var wde="SelectBubbleInput",oF=b.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const i=b.useRef(null),s=dr(r,i),o=Gae(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(En.select,{...n,style:{...B5,...n.style},ref:s,defaultValue:t})});oF.displayName=wde;function aF(e){return e===""||e===void 0}function lF(e){const t=Oo(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 cF(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=xde(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 xde(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Sde=z4,Ede=F4,Cde=H4,kde=U4,Tde=W4,Rde=q4,Ade=G4,Nde=Q4,Mde=eF,Pde=nF,Ide=rF,Ode=iF,[Yb]=Ga("Tooltip",[dc]),Vb=dc(),uF="TooltipProvider",Lde=700,M1="tooltip.open",[Dde,Lk]=Yb(uF),dF=e=>{const{__scopeTooltip:t,delayDuration:n=Lde,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(Dde,{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})};dF.displayName=uF;var Zp="Tooltip",[Bde,Am]=Yb(Zp),fF=e=>{const{__scopeTooltip:t,children:n,open:r,defaultOpen:i,onOpenChange:s,disableHoverableContent:o,delayDuration:l}=e,u=Lk(Zp,e.__scopeTooltip),d=Vb(t),[f,h]=b.useState(null),v=_i(),g=b.useRef(0),_=o??u.disableHoverableContent,w=l??u.delayDuration,S=b.useRef(!1),[x,T]=ec({prop:r,defaultProp:i??!1,onChange:M=>{M?(u.onOpen(),document.dispatchEvent(new CustomEvent(M1))):u.onClose(),s==null||s(M)},caller:Zp}),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]),P=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(xm,{...d,children:m.jsx(Bde,{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(()=>{_?P():(window.clearTimeout(g.current),g.current=0)},[P,_]),onOpen:A,onClose:P,disableHoverableContent:_,children:n})})};fF.displayName=Zp;var P1="TooltipTrigger",hF=b.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,i=Am(P1,n),s=Lk(P1,n),o=Vb(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(Sm,{asChild:!0,...o,children:m.jsx(En.button,{"aria-describedby":i.open?i.contentId:void 0,"data-state":i.stateAttribute,...r,ref:u,onPointerMove:Yt(e.onPointerMove,v=>{v.pointerType!=="touch"&&!f.current&&!s.isPointerInTransitRef.current&&(i.onTriggerEnter(),f.current=!0)}),onPointerLeave:Yt(e.onPointerLeave,()=>{i.onTriggerLeave(),f.current=!1}),onPointerDown:Yt(e.onPointerDown,()=>{i.open&&i.onClose(),d.current=!0,document.addEventListener("pointerup",h,{once:!0})}),onFocus:Yt(e.onFocus,()=>{d.current||i.onOpen()}),onBlur:Yt(e.onBlur,i.onClose),onClick:Yt(e.onClick,i.onClose)})})});hF.displayName=P1;var Dk="TooltipPortal",[zde,jde]=Yb(Dk,{forceMount:void 0}),pF=e=>{const{__scopeTooltip:t,forceMount:n,children:r,container:i}=e,s=Am(Dk,t);return m.jsx(zde,{scope:t,forceMount:n,children:m.jsx(xo,{present:n||s.open,children:m.jsx(wf,{asChild:!0,container:i,children:r})})})};pF.displayName=Dk;var uf="TooltipContent",mF=b.forwardRef((e,t)=>{const n=jde(uf,e.__scopeTooltip),{forceMount:r=n.forceMount,side:i="top",...s}=e,o=Am(uf,e.__scopeTooltip);return m.jsx(xo,{present:r||o.open,children:o.disableHoverableContent?m.jsx(gF,{side:i,...s,ref:t}):m.jsx(Fde,{side:i,...s,ref:t})})}),Fde=b.forwardRef((e,t)=>{const n=Am(uf,e.__scopeTooltip),r=Lk(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=Wde(x,S.getBoundingClientRect()),k=qde(x,T),A=Yde(w.getBoundingClientRect()),P=Kde([...k,...A]);l(P),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=!Vde(x,o);T?v():k&&(v(),d())};return document.addEventListener("pointermove",_),()=>document.removeEventListener("pointermove",_)}},[u,f,o,d,v]),m.jsx(gF,{...e,ref:s})}),[$de,Hde]=Yb(Zp,{isInside:!1}),Ude=woe("TooltipContent"),gF=b.forwardRef((e,t)=>{const{__scopeTooltip:n,children:r,"aria-label":i,onEscapeKeyDown:s,onPointerDownOutside:o,...l}=e,u=Am(uf,n),d=Vb(n),{onClose:f}=u;return b.useEffect(()=>(document.addEventListener(M1,f),()=>document.removeEventListener(M1,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(zb,{"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(Ude,{children:r}),m.jsx($de,{scope:n,isInside:!0,children:m.jsx(j5,{id:u.contentId,role:"tooltip",children:i||r})})]})})});mF.displayName=uf;var vF="TooltipArrow",yF=b.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,i=Vb(n);return Hde(vF,n).isInside?null:m.jsx(jb,{...i,...r,ref:t})});yF.displayName=vF;function Wde(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 qde(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 Yde(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 Vde(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 Kde(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),Gde(t)}function Gde(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 Xde=dF,Zde=fF,Jde=hF,Qde=pF,efe=mF,tfe=yF;const bF=b.createContext(!1);function nfe({blocked:e,children:t}){return m.jsx(bF.Provider,{value:e,children:t})}function Nm(){return b.useContext(bF)}function Kb({...e}){return m.jsx(Xue,{"data-slot":"popover",...e})}function Gb({...e}){return m.jsx(Zue,{"data-slot":"popover-trigger",...e})}function Xb({className:e,align:t="center",sideOffset:n=4,inert:r,"aria-disabled":i,...s}){const o=Nm();return m.jsx(Jue,{children:m.jsx(Que,{"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 fI=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,hI=Yz,rfe=(e,t)=>n=>{var r;if((t==null?void 0:t.variants)==null)return hI(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=fI(f)||fI(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 hI(e,o,u,n==null?void 0:n.class,n==null?void 0:n.className)},ife=rfe("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 dt({className:e,variant:t="default",size:n="default",asChild:r=!1,...i}){const s=r?boe:"button";return m.jsx(s,{"data-slot":"button","data-variant":t,"data-size":n,className:We(ife({variant:t,size:n,className:e})),...i})}function Cf({...e}){return m.jsx(Aue,{"data-slot":"dropdown-menu",...e})}function sfe({...e}){return m.jsx(T4,{"data-slot":"dropdown-menu-portal",...e})}function kf({...e}){return m.jsx(Nue,{"data-slot":"dropdown-menu-trigger",...e})}function Tf({className:e,sideOffset:t=4,inert:n,"aria-disabled":r,...i}){const s=Nm();return m.jsx(T4,{children:m.jsx(Mue,{"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 ii({className:e,inset:t,variant:n="default",...r}){return m.jsx(Iue,{"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 E0({className:e,children:t,checked:n,...r}){return m.jsxs(Oue,{"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(Lue,{children:m.jsx(ua,{className:"size-4"})})}),t]})}function Dh({className:e,inset:t,...n}){return m.jsx(Pue,{"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 Hl({className:e,...t}){return m.jsx(Due,{"data-slot":"dropdown-menu-separator",className:We("-mx-1 my-1 h-px bg-border",e),...t})}function ofe({...e}){return m.jsx(Bue,{"data-slot":"dropdown-menu-sub",...e})}function afe({className:e,inset:t,children:n,...r}){return m.jsxs(zue,{"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 lfe({className:e,...t}){return m.jsx(jue,{"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 cfe={"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}=cfe[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 ufe={online:"bg-[var(--color-status-success)]",offline:"bg-[var(--muted-foreground)]",connecting:"bg-[var(--color-status-working)] animate-pulse"},dfe={online:"开发机在线",offline:"开发机离线",connecting:"正在连接开发机"};function I1({status:e,className:t}){return m.jsx("span",{className:We("inline-block w-2 h-2 rounded-full shrink-0",ufe[e],t),role:"status","aria-label":dfe[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 qi({...e}){return m.jsx(hk,{"data-slot":"dialog",...e})}function ffe({...e}){return m.jsx(pk,{"data-slot":"dialog-portal",...e})}function _F({...e}){return m.jsx(Ib,{"data-slot":"dialog-close",...e})}function hfe({className:e,...t}){return m.jsx(mk,{"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 Yi({className:e,children:t,showCloseButton:n=!0,focusSurfaceOnOpen:r=!1,onOpenAutoFocus:i,inert:s,"aria-disabled":o,...l}){const u=Nm();return m.jsxs(ffe,{"data-slot":"dialog-portal",children:[m.jsx(hfe,{}),m.jsxs(gk,{"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(Ib,{"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(ac,{}),m.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function Vi({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(Ib,{asChild:!0,children:m.jsx(dt,{variant:"outline",children:"Close"})})]})}function Pi({className:e,...t}){return m.jsx(h3,{"data-slot":"dialog-title",className:We("text-lg leading-none font-semibold",e),...t})}function fs({className:e,...t}){return m.jsx(p3,{"data-slot":"dialog-description",className:We("text-sm text-muted-foreground",e),...t})}function pfe(e){return`“${(e==null?void 0:e.name)??(e==null?void 0:e.proxyId)??"这台开发机"}”只会从当前 Relay 的开发机列表中移除。不会删除机器上的文件或会话,也不会阻止它再次连接;以后重新运行时,它会重新出现在列表中。`}function mfe({open:e,target:t,removing:n,onOpenChange:r,onConfirm:i}){return m.jsx(qi,{open:e,onOpenChange:s=>{n||r(s)},children:m.jsxs(Yi,{"data-slot":"proxy-removal-dialog",showCloseButton:!n,onEscapeKeyDown:s=>{n&&s.preventDefault()},onPointerDownOutside:s=>{n&&s.preventDefault()},children:[m.jsxs(Vi,{children:[m.jsx(Pi,{children:"移除离线开发机?"}),m.jsx(fs,{children:pfe(t)})]}),m.jsxs(Gs,{children:[m.jsx(dt,{type:"button",variant:"ghost",disabled:n,onClick:()=>r(!1),children:"取消"}),m.jsxs(dt,{type:"button",variant:"destructive",disabled:n||!t,"aria-busy":n||void 0,onClick:i,"data-slot":"proxy-removal-confirm",children:[n&&m.jsx(Xr,{className:"size-4 animate-spin","aria-hidden":"true"}),n?"正在移除":"移除"]})]})]})})}const dy=80,gfe=8,vfe=1.2;function pI(e){return Math.max(0,Math.min(dy,e))}function yfe({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?dy:0),_=h!==null;function w(k){var A,P;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?dy:0,axis:"pending"};try{(P=(A=k.currentTarget).setPointerCapture)==null||P.call(A,k.pointerId)}catch{}}}function S(k){const A=d.current;if(!A||A.pointerId!==k.pointerId)return;const P=k.clientX-A.startX,R=k.clientY-A.startY;if(A.axis==="pending"){if(Math.hypot(P,R)<gfe)return;A.axis=Math.abs(P)>Math.abs(R)*vfe?"horizontal":"vertical"}A.axis!=="vertical"&&(k.preventDefault(),v(pI(A.startOffset-P)))}function x(k,A=!1){var M,z;const P=d.current;if(!P||P.pointerId!==k.pointerId)return;d.current=null;try{(z=(M=k.currentTarget).releasePointerCapture)==null||z.call(M,k.pointerId)}catch{}if(P.axis!=="horizontal"||A){v(null);return}k.preventDefault();const R=h??pI(P.startOffset-(k.clientX-P.startX));v(null),o(R>=dy/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(I1,{status:"offline"}),m.jsx(Mp,{name:u,osName:n}),r&&m.jsx(ua,{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 wF({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 V=zt;if(!V){$e.error("请先连接开发机");return}const W=z??M,G=s!==null&&s!==M;Re.getState().setProxySwitchTarget({proxyId:M,name:W});try{const O=await V.selectProxy(M);if(!O.success){$e.error(`无法连接 ${W}:${O.error??"未知错误"}`);return}const N=V.getPreviewScope();if(!N||N.proxyId!==M||N.bindingId!==O.bindingId)throw Pt.dispose(),V.clearBoundProxy(),new Error("开发机绑定状态无效,请重试");Pt.activate(V,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),Zr.getState().prepareForProxySwitch()),Pr("local",Tn.proxyId,M),Re.getState().setProxy(M,z??null),Re.getState().setProxyOnline(!0),Re.getState().transitionToPhase("session_browsing"),V.sendControl({type:"session_list_request"}),V.requestProxyInfo().then(L=>{if(Re.getState().selectedProxyId!==M||!Pt.isActive(V,N))return;const D=Zr.getState();D.setHomePath(L.homePath),D.setAgentCli(L.agentCli),Re.getState().setTerminalShells(L.terminalShells)}).catch(L=>{Pt.isActive(V,N)&&console.error("[proxy-switcher] post-bind proxy info fetch failed",L)}),V.requestAgentStatuses().then(L=>{if(Re.getState().selectedProxyId!==M||!Pt.isActive(V,N))return;const D=Ut.getState();for(const I of L)D.setAgentStatus(I.sessionId,I.payload)}).catch(L=>{Pt.isActive(V,N)&&console.error("[proxy-switcher] post-bind data fetch failed",L)}),ek(V).then(L=>{L.status==="failed"&&console.error("[proxy-switcher] post-bind data fetch failed",L.error)}),f(!1),(e==="page"||l.pathname.startsWith("/chat/")||l.pathname.startsWith("/preview/device/"))&&u("/sessions")}catch(O){const N=O instanceof Error?O.message:"未知错误";$e.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=zt;if(!z){$e.error("Relay 连接不可用,请稍后重试");return}const V=Re.getState().proxies.find(W=>W.proxyId===M.proxyId);if(!V){if(!Re.getState().proxyListLoaded){$e.info("正在重新连接 Relay,请稍后再试");return}Np(M.proxyId,z)&&u("/"),$e.info("这台开发机已经不在列表中"),_(null);return}if(V.online){$e.warning("这台开发机已重新上线,未移除"),_(null);return}S(M.proxyId),lse(M.proxyId);try{const W=await z.removeOfflineProxy(M.proxyId);if(W.success){Dd(M.proxyId),Np(M.proxyId,z)&&u("/"),$e.success(`已移除 ${M.name??M.proxyId}`),_(null);return}if(W.errorCode===Ir.PROXY_ONLINE){Dd(M.proxyId),$e.warning("这台开发机已重新上线,未移除"),_(null),z.listProxies();return}if(W.errorCode===Ir.PROXY_NOT_FOUND){Dd(M.proxyId),Np(M.proxyId,z)&&u("/"),$e.info("这台开发机已经不在列表中"),_(null),z.listProxies();return}Dd(M.proxyId),$e.error(W.error??"无法移除开发机,请重试")}catch(W){$e.error(W instanceof Error?W.message:"无法移除开发机,请重试"),z.listProxies()}finally{S(null)}}const A=m.jsx(mfe,{open:g!==null,target:g,removing:w!==null,onOpenChange:M=>{M||_(null)},onConfirm:()=>void 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,V=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:V||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",V&&!z||w!==null?"opacity-50":""),"aria-pressed":s===M.proxyId,children:[m.jsx(I1,{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(Xr,{className:"size-4 shrink-0 animate-spin text-primary","aria-hidden":!0})]}):s===M.proxyId?m.jsx(ua,{className:"size-4 shrink-0 text-primary","aria-label":"已选"}):null]})},M.proxyId):m.jsx(yfe,{proxyId:M.proxyId,name:M.name,osName:M.osName,selected:s===M.proxyId,revealed:h===M.proxyId,disabled:V||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(Xr,{className:"h-5 w-5 animate-spin","aria-hidden":!0}),m.jsx("p",{className:"text-sm",children:"连接中..."})]});const P=n.find(M=>M.proxyId===s),R=(P==null?void 0:P.name)??(P==null?void 0:P.proxyId)??"未选择开发机";return m.jsxs(m.Fragment,{children:[m.jsxs(Kb,{open:d,onOpenChange:f,children:[m.jsx(Gb,{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:P==null?void 0:P.osName,className:t==="sidebarChrome"?"flex-initial":"text-center",nameClassName:t==="sidebarChrome"?"text-base font-semibold":void 0}),m.jsx(oc,{className:"h-4 w-4 text-muted-foreground shrink-0 transition-transform group-data-[state=open]:rotate-180","aria-hidden":!0})]})}),m.jsx(Xb,{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,V=o!==null;return m.jsxs("li",{className:"group flex min-w-0 items-center rounded-md",children:[m.jsxs("button",{type:"button","data-slot":"proxy-item","data-proxy-id":M.proxyId,"data-online":M.online,"data-selecting":z||void 0,disabled:!M.online||V,"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",V&&!z?"opacity-50":"",M.online?"":"opacity-50"),"aria-pressed":s===M.proxyId,title:M.online?void 0:"这台开发机离线",children:[m.jsx(I1,{status:M.online?"online":"offline"}),m.jsx(Mp,{name:M.name??M.proxyId,osName:M.osName}),z?m.jsx(Xr,{className:"h-4 w-4 animate-spin text-primary shrink-0","aria-label":"正在连接"}):s===M.proxyId?m.jsx(ua,{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(dt,{type:"button",variant:"ghost",size:"icon-xs",className:"mr-1 size-8 text-muted-foreground opacity-60 hover:opacity-100 focus-visible:opacity-100",disabled:V||w!==null,"aria-label":`${M.name??M.proxyId} 操作`,"data-slot":"proxy-row-menu-trigger",children:m.jsx(yb,{"aria-hidden":"true"})})}),m.jsx(Tf,{align:"end","data-slot":"proxy-row-menu",children:m.jsxs(ii,{variant:"destructive","data-slot":"proxy-row-remove-item",onSelect:W=>{W.stopPropagation(),T(M)},children:[m.jsx(Uz,{"aria-hidden":"true"}),"移除开发机"]})})]})]},M.proxyId)})})})]}),A]})}function bfe({delayDuration:e=0,...t}){return m.jsx(Xde,{"data-slot":"tooltip-provider",delayDuration:e,...t})}function Rf({...e}){return m.jsx(Zde,{"data-slot":"tooltip",...e})}function Af({...e}){return m.jsx(Jde,{"data-slot":"tooltip-trigger",...e})}function Nf({className:e,sideOffset:t=0,children:n,hideArrow:r=!1,...i}){return m.jsx(Qde,{children:m.jsxs(efe,{"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(tfe,{className:"z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px] bg-foreground fill-foreground"})]})})}function gc({...e}){return m.jsx(hk,{"data-slot":"sheet",...e})}function _fe({...e}){return m.jsx(Kae,{"data-slot":"sheet-trigger",...e})}function wfe({...e}){return m.jsx(pk,{"data-slot":"sheet-portal",...e})}function xfe({className:e,...t}){return m.jsx(mk,{"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 vc({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=Nm();return m.jsxs(wfe,{children:[m.jsx(xfe,{className:t}),m.jsxs(gk,{"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(Ib,{"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(ac,{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 yc({className:e,...t}){return m.jsx(h3,{"data-slot":"sheet-title",className:We("font-semibold text-foreground",e),...t})}function Zb({className:e,...t}){return m.jsx(p3,{"data-slot":"sheet-description",className:We("text-sm text-muted-foreground",e),...t})}const Sfe={claude:"Claude Code",codex:"Codex",kimi:"Kimi Code",cursor:"Cursor CLI"},mI=["claude","codex","kimi","cursor"];function Jb(e){return Sfe[e]}function xF(e,t){return mI.indexOf(e)-mI.indexOf(t)}function ql(e){return e.provider}const O1=60*1e3,L1=60*O1,Efe=24*L1;function SF(e,t=Date.now()){const n=t-e;if(n<O1)return"刚刚";if(n<L1)return`${Math.floor(n/O1)} 分钟前`;if(n<Efe)return`${Math.floor(n/L1)} 小时前`;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 gI={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 D1(e){return e.kind!=="terminal"?gI[e.state]:e.state==="terminated"?gI.terminated:e.state==="error"?{dot:"bg-[var(--color-status-error)]",text:"text-[var(--color-status-error)]",label:"已断开"}:{dot:"bg-[var(--color-status-success)]",text:"text-[var(--color-status-success)]",label:"运行中"}}function Cfe({session:e}){const t=D1(e);return m.jsx("span",{className:We("inline-block size-2 rounded-full shrink-0",t.dot),"aria-label":`会话状态:${t.label}`,role:"status"})}function kfe({mode:e}){if(e!=="pty"&&e!=="json")return null;const t=e==="json"?"聊天视图":"终端视图",n=e==="json"?NC:IC;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 Tfe({session:e,selected:t,now:n,onClick:r,onRename:i,onTerminate:s}){const o=Zr(w=>w.homePath),l=e.lastActive,u=e.cwd,d=ik(e.name,o),f=sk(e,o),h=e.nameLocked&&e.name?e.name:f||(d==="New Session"?e.sessionId.slice(0,8):d),v=SF(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:[m.jsx(Cfe,{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(kfe,{mode:e.mode}),m.jsx("span",{className:"text-muted-foreground/60 shrink-0","aria-hidden":"true",children:"·"}),e.kind!=="terminal"&&m.jsxs(m.Fragment,{children:[m.jsx("span",{className:"font-mono text-muted-foreground shrink-0",children:Jb(e.provider)}),m.jsx("span",{className:"text-muted-foreground/60 shrink-0","aria-hidden":"true",children:"·"})]}),m.jsx("span",{className:We("shrink-0",D1(e).text),children:D1(e).label}),v&&m.jsxs(m.Fragment,{children:[m.jsx("span",{className:"text-muted-foreground/60 shrink-0","aria-hidden":"true",children:"·"}),m.jsx("span",{className:"text-muted-foreground shrink-0 tabular-nums",children:v})]})]})]}),(i||s)&&m.jsxs(Cf,{children:[m.jsx(kf,{asChild:!0,children:m.jsx(dt,{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(yb,{"aria-hidden":"true"})})}),m.jsxs(Tf,{align:"end","data-slot":"session-row-menu",children:[i&&m.jsx(ii,{"data-slot":"session-row-rename-item",onSelect:w=>{w.stopPropagation(),i()},children:"重命名"}),s&&m.jsx(ii,{variant:"destructive","data-slot":"session-row-terminate-item",onSelect:w=>{w.stopPropagation(),s()},children:_})]})]})]})}const Rfe="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=",Afe="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==",Nfe="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 Mfe({shell:e,label:t}){const n=e==="cmd"?Rfe:e==="powershell"?t==="Windows PowerShell"?Nfe:Afe: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 Pfe({session:e,now:t,disabled:n,loading:r,onClick:i,modeTag:s}){const o=m.jsx(Ife,{title:e.title,modeTag:s}),l=m.jsx("span",{className:"text-xs text-muted-foreground tabular-nums",children:SF(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(GY,{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 Ife({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(Ofe,{mode:t})]})}function Ofe({mode:e}){const t=e==="json"?"聊天视图":"终端视图",n=e==="json"?NC:IC;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 EF({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(UK,{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 Lfe({now:e}){const t=Zr(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=ql(N);let D=O.get(L);D||(D=new Map,O.set(L,D));const I=CF(N.projectDir),B=D.get(I);B?B.sessions.push(N):D.set(I,{dir:I,sessions:[N]})}return Array.from(O.entries()).sort(([N],[L])=>xF(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:Yp(D.dir,t,{compact:!0}),sessions:D.sessions}))}))},[n,t]);function A(O){l(O),d(Dfe(O)),h(Bfe(O))}async function P(O,N,L){if(i)return;const D=zt;if(!D){$e.error("请先连接开发机");return}s(O.id);const I=ql(O);try{const B=await D.createSession({kind:"agent",cwd:O.projectDir,mode:N,provider:I,resumeSessionId:O.id,...L?{permissionMode:L}:{}});if(!B.success){if(B.errorCode===Ir.SESSION_ALREADY_ACTIVE){Ut.getState().setCodexActiveWriterConflict({...B.activeWriterPid?{activeWriterPid:B.activeWriterPid}:{}}),l(null);return}$e.error(`恢复失败:${B.error}`);return}if(B.kind!=="agent"){$e.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){$e.error(`恢复失败:${B instanceof Error?B.message:String(B)}`)}finally{s(null)}}function R(){const O=zt;!O||Ut.getState().historyLoadStatus==="loading"||ek(O).then(N=>{N.status==="failed"&&$e.error(N.error instanceof Error?N.error.message:String(N.error))})}function M(O,N){const L=vI(O,N);x(D=>{const I=new Set(D);return I.has(L)?I.delete(L):I.add(L),I})}function z(O){w(N=>{const L=new Set(N);return L.has(O)?L.delete(O):L.add(O),L})}const V=n.length>0,W=r==="loading",G=o?kF(ql(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:()=>V&&g(O=>!O),disabled:!V,"aria-expanded":V?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:["全部会话",V?m.jsxs("span",{className:"ml-1 text-muted-foreground/70 font-normal",children:["· ",n.length]}):null]}),V?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(dt,{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(gm,{className:We("size-3.5",W&&"animate-spin motion-reduce:animate-none"),"aria-hidden":"true"})})]}),!V&&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(Xr,{className:"size-3.5 shrink-0 animate-spin motion-reduce:animate-none","aria-hidden":"true"}),m.jsx("span",{children:"正在加载会话记录..."})]}),!V&&r==="idle"&&m.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/80","data-slot":"history-idle",role:"status",children:"会话记录尚未加载"}),!V&&r==="error"&&m.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/80","data-slot":"history-error",role:"status",children:"会话记录加载失败,请点击刷新重试"}),V&&r==="error"&&m.jsx("div",{className:"px-4 pb-2 text-xs text-muted-foreground/80","data-slot":"history-stale",role:"status",children:"刷新失败,当前显示上次加载的结果"}),!V&&r==="loaded"&&m.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/70","data-slot":"history-empty",children:"暂无会话记录"}),V&&v&&m.jsx("ul",{role:"list",className:"flex flex-col",children:k.map(O=>{const 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:Jb(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=vI(O.provider,L.dir),I=S.has(D);return m.jsxs("li",{children:[m.jsxs("button",{type:"button",onClick:()=>M(O.provider,L.dir),"aria-expanded":I,"data-slot":"history-group-header","data-expanded":I,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",I&&"rotate-90"),"aria-hidden":"true"})]}),I&&m.jsx("ul",{role:"list",className:"flex flex-col",children:L.sessions.map(B=>m.jsx(Pfe,{session:B,now:e,disabled:i!==null,loading:i===B.id,onClick:()=>A(B),modeTag:B.preferredMode},B.id))})]},D)})})]},O.provider)})}),m.jsx(zfe,{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&&ql(o)==="cursor"&&f==="auto"&&h("default")},onPermissionModeChange:h,onConfirm:()=>{o&&P(o,u,f)}})]})}function vI(e,t){return`${e}:${CF(t)}`}function CF(e){const t=e.trim();return!t||t==="/"?t||"/":t.replace(/\/+$/,"")||"/"}function kF(e){return["json","pty"]}function Dfe(e){const t=kF(ql(e));return e.preferredMode&&t.includes(e.preferredMode)?e.preferredMode:t[0]??"pty"}function Bfe(e){return ql(e)==="codex"?"auto":"default"}function zfe({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?ql(e):null,w=_==="codex",S=_==="kimi",x=_==="cursor";b.useEffect(()=>{t||h(!1)},[t]);const T=f?m.jsx(EF,{providerLabel:e?Jb(ql(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(yI,{checked:r==="json",label:"聊天",icon:m.jsx(NC,{className:"size-4","aria-hidden":"true"}),disabled:s,onClick:()=>l("json")}),n.includes("pty")&&m.jsx(yI,{checked:r==="pty",label:"终端",icon:m.jsx(IC,{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(Sv,{checked:i==="default",label:S?"手工审批":x?"命令审批":"严格审批",description:S?"工具调用会在 Web 中请求确认。":x?"Cursor CLI 在执行命令前询问。":"所有需要权限的操作都要确认。",disabled:s,onClick:()=>u("default")}),!(x&&r==="json")&&m.jsx(Sv,{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(Sv,{checked:i==="plan",label:"只读规划",description:x?"Cursor CLI 使用只读规划模式。":"Kimi Code 使用只读规划模式。",disabled:s,onClick:()=>u("plan")}),m.jsx(Sv,{checked:i==="bypassPermissions",label:S?"全自动":"跳过全部审批",description:S?"危险模式,Kimi Code 将全自动执行。":"危险模式,会跳过工具审批和部分沙箱保护。",destructive:!0,disabled:s,onClick:()=>u("bypassPermissions")})]})]})]}),k=m.jsxs(m.Fragment,{children:[m.jsx(dt,{type:"button",variant:"ghost",disabled:s,onClick:()=>{f?h(!1):o(!1)},children:f?"返回":"取消"}),m.jsx(dt,{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(qi,{open:t,onOpenChange:o,children:m.jsxs(Yi,{focusSurfaceOnOpen:!0,className:"min-w-0 sm:max-w-md","data-slot":"history-restore-dialog",children:[m.jsxs(Vi,{className:"min-w-0",children:[m.jsx(Pi,{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(gc,{open:t,onOpenChange:o,children:m.jsxs(vc,{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(yc,{children:f?"跳过全部审批?":"恢复会话"}),m.jsx(Zb,{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 yI({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(ua,{className:We("size-3.5 justify-self-end transition-opacity",e?"opacity-100":"opacity-0"),"aria-hidden":"true"})]})}function Sv({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(ua,{className:We("mt-0.5 size-4 shrink-0",r?"text-destructive":"text-primary"),"aria-hidden":"true"})]})}function Qb({...e}){return m.jsx(Sde,{"data-slot":"select",...e})}function e_({...e}){return m.jsx(Cde,{"data-slot":"select-value",...e})}function t_({className:e,size:t="default",children:n,...r}){return m.jsxs(Ede,{"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(kde,{asChild:!0,children:m.jsx(oc,{className:"size-4 opacity-50"})})]})}function n_({className:e,children:t,position:n="item-aligned",align:r="center",inert:i,"aria-disabled":s,...o}){const l=Nm();return m.jsx(Tde,{children:m.jsxs(Rde,{"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(jfe,{}),m.jsx(Ade,{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(Ffe,{})]})})}function r_({className:e,children:t,...n}){return m.jsxs(Nde,{"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(Pde,{children:m.jsx(ua,{className:"size-4"})})}),m.jsx(Mde,{children:t})]})}function jfe({className:e,...t}){return m.jsx(Ide,{"data-slot":"select-scroll-up-button",className:We("flex cursor-default items-center justify-center py-1",e),...t,children:m.jsx(TC,{className:"size-4"})})}function Ffe({className:e,...t}){return m.jsx(Ode,{"data-slot":"select-scroll-down-button",className:We("flex cursor-default items-center justify-center py-1",e),...t,children:m.jsx(oc,{className:"size-4"})})}function $fe(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=oa((n==null?void 0:n.baseCwd)??"");if(!e)return{currentPath:Ys(r),query:""};const i=Eb(r,e);if(!i)return{currentPath:"",query:""};const s=JC(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 C0(e,t){return Eb(e,t)}const TF=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 _=Zr(ye=>f?ye.treeWithHidden:ye.tree),w=Zr(ye=>ye.cwd),S=Zr(ye=>ye.homePath),x=Re(ye=>ye.selectedProxyId),T=o==="insert"?w:S||w,k=b.useMemo(()=>new Set(_.keys()),[_]),A=b.useMemo(()=>$fe(t,o,{baseCwd:T,knownDirs:k}),[t,o,T,k]),P=A.currentPath,R=b.useMemo(()=>C0(T,P),[T,P]),M=A.query,z=b.useRef(new Map),[V,W]=b.useState(!1),[G,O]=b.useState(""),[N,L]=b.useState(!1),[D,I]=b.useState(null),[B,F]=b.useState(0),[U,j]=b.useState(!1),[Y,X]=b.useState(null),[$,ee]=b.useState(null);b.useEffect(()=>{if(!U)return;let ye=!1;X(null),ee(null);const nt=zt==null?void 0:zt.requestFileSystemRoots();return nt||ee("尚未连接开发机"),nt==null||nt.then(He=>{ye||(He.error!==void 0||He.errorCode!==void 0?ee(He.error||"读取失败"):X(He.roots))},He=>{ye||ee(He instanceof Error?He.message:"读取失败")}),()=>{ye=!0}},[U,x,B]),b.useEffect(()=>{if(!R||U)return;const ye=`${x}\0${f?"hidden":"default"}\0${R}`;if(_.has(R))return;const nt=zt;if(!nt)return;let He=!1;I(Ze=>(Ze==null?void 0:Ze.path)===R?null:Ze);let Ae=z.current.get(ye);if(!Ae){Ae=nt.requestDirectoryList(R,{includeHidden:f}),z.current.set(ye,Ae);const Ze=()=>{z.current.get(ye)===Ae&&z.current.delete(ye)};Ae.then(Ze,Ze)}return Ae.then(Ze=>{if(!He){if(Ze.error!==void 0||Ze.errorCode!==void 0){I({path:R,message:Ze.error||"读取失败"});return}Zr.getState().setDirEntries(Ze.path,Ze.entries,Ze.includeHidden)}},Ze=>{He||I({path:R,message:Ze instanceof Error?Ze.message:"读取失败"})}),()=>{He=!0}},[R,f,_,B,U,x]);const re=U?$?{message:$}:null:(D==null?void 0:D.path)===R?D:null,te=U?Y===null&&!$:!_.has(R)&&!re,Z=b.useMemo(()=>d==null?void 0:d.map(ye=>ye.startsWith(".")?ye.toLowerCase():`.${ye.toLowerCase()}`),[d]),oe=b.useMemo(()=>{if(U){if(!Y)return[];const nt=[...S?[{name:"主目录",path:S}]:[],...Y];return[...new Map(nt.map(He=>[He.path,He])).values()].map(He=>({...He,isDir:!0}))}let ye=_.get(R)??[];return u?ye=ye.filter(nt=>nt.isDir):Z!=null&&Z.length&&(ye=ye.filter(nt=>nt.isDir||Z.some(He=>nt.name.toLowerCase().endsWith(He)))),M&&(ye=ye.filter(nt=>nt.name.toLowerCase().includes(M))),ye},[_,R,M,u,Z,U,Y,S]),[Q,fe]=b.useState(h?0:-1);b.useEffect(()=>fe(h?0:-1),[h,P,M,U]),b.useEffect(()=>{W(!1),O("")},[R]),b.useEffect(()=>{Q>=oe.length&&oe.length>0&&fe(oe.length-1)},[oe.length,Q]);const ge=b.useRef(null),Ce=b.useRef(!1);b.useEffect(()=>{var nt;if(!Ce.current)return;Ce.current=!1;const ye=(nt=ge.current)==null?void 0:nt.querySelector(`[data-entry-index="${Q}"]`);ye==null||ye.scrollIntoView({block:"nearest"})},[Q]);const De=b.useCallback(ye=>{const nt=uu(T),He=`${Ys(P,T)}${ye.name}${ye.isDir?nt:""}`;if(o==="insert")return He.replace(nt==="\\"?/^\.[\\/]/:/^\.\//,"");const Ae=C0(T,He);return ye.isDir?Ys(Ae):Ae},[T,P,o]),ot=b.useCallback(ye=>{const nt=C0(T,ye);if(!nt)return;j(!1);const He=Ys(nt);if(o==="select"){r(He);return}n(He)},[T,o,r,n]),Dt=b.useCallback(ye=>{if(ye.path){ot(ye.path);return}const nt=De(ye);if(ye.isDir){ot(nt);return}n(nt)},[De,ot,n]);async function et(){const ye=p2(R,G);if(!(!ye||!s)){L(!0);try{const nt=await s(ye);if(!nt)return;if(O(""),W(!1),i){i(Ys(nt));return}ot(nt)}finally{L(!1)}}}b.useImperativeHandle(g,()=>({handleKey(ye){return oe.length===0?!1:ye.key==="ArrowDown"?(Ce.current=!0,fe(nt=>Math.min(oe.length-1,nt+1)),!0):ye.key==="ArrowUp"?(Ce.current=!0,fe(nt=>Math.max(0,nt-1)),!0):ye.key==="Enter"&&Q>=0&&!ye.nativeEvent.isComposing?(Dt(oe[Q]),!0):!1}}),[oe,Q,Dt]);const ut=b.useMemo(()=>JC(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?"磁盘/挂载点":Yp(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(ye=>!ye),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===ut?j(!0):ot(ut)},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(ye=>!ye),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]}),V&&!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:ye=>O(ye.target.value),onKeyDown:ye=>{ye.key==="Enter"&&!ye.nativeEvent.isComposing&&(ye.preventDefault(),et()),ye.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:!p2(R,G)||N,onClick:()=>void 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(ye=>!ye),children:U?"返回目录":"磁盘/挂载点"}),m.jsx("span",{className:"truncate font-mono text-xs text-muted-foreground",children:U?"磁盘/挂载点":Yp(R,S)})]}),m.jsx("div",{className:Ue,"data-slot":"file-path-picker-entries",children:re?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:re.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(ye=>ye+1),children:"重试"})]}):oe.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:oe.map((ye,nt)=>m.jsx("li",{children:m.jsxs("button",{type:"button",onClick:()=>Dt(ye),onMouseEnter:()=>fe(nt),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",nt===Q&&"bg-[color-mix(in_srgb,var(--primary)_15%,transparent)]",ye.isDir&&"font-semibold"),"data-slot":"file-entry","data-entry-type":ye.isDir?"dir":"file","data-entry-name":ye.name,"data-entry-index":nt,title:ye.path,children:[m.jsxs("span",{className:"min-w-0 truncate font-mono text-[13px]",children:[ye.name,ye.isDir&&!ye.path?"/":""]}),ye.path&&ye.path!==ye.name?m.jsx("span",{className:"ml-auto min-w-0 truncate text-xs font-normal text-muted-foreground",children:ye.path}):null]})},ye.path??ye.name))})})]})});function bI(e,t,n){const r=pp(e,t);return r?n==="file"?Ys(JC(r)):n==="directory"?Ys(r):r:t}function pp(e,t){const n=oa(e,t);return n?e.endsWith("/")||uu(n)==="\\"&&e.endsWith("\\")?Ys(n):n:""}function Bk({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}`,P=`${A}-label`,R=Zr(te=>te.homePath),M=bo("(pointer: coarse), (hover: none)"),z=bf().deviceKind,V=M||z==="phone"||z==="tablet",[W,G]=b.useState(!1),[O,N]=b.useState(()=>bI(e,R,n)),[L,D]=b.useState(e),I=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 oe=I.current,Q=Z.target;oe&&(Z.composedPath().includes(oe)||Q instanceof Node&&oe.contains(Q))||(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=bI(e,R,n);N(te),D(e),G(!0)}function Y(){G(!1),D(e)}function X(te){const Z=pp(te,R);Z&&(N(Z),D(Z),t(Z),G(!1))}function $(te){const Z=pp(te,R);Z&&N(Z)}function ee(te){var Z;if(W&&((Z=F.current)!=null&&Z.handleKey(te))){te.preventDefault();return}if(te.key==="Escape"&&W){te.preventDefault(),Y();return}T==null||T(te)}const re=W?m.jsx("div",{className:We(V&&"mt-2"),"data-slot":"remote-path-browser",children:m.jsx(TF,{ref:F,mode:"select",placement:V?"inline":"floating",filter:O,dirsOnly:n==="directory",fileExtensions:r,includeHidden:i,autoHighlightFirst:!V,title:l,onNavigate:$,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:P,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:I,className:"relative min-w-0",onBlur:te=>{if(!W||V)return;const Z=te.relatedTarget;Z instanceof Node&&te.currentTarget.contains(Z)||window.setTimeout(()=>{var oe;(oe=I.current)!=null&&oe.contains(document.activeElement)||Y()},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":P,"aria-describedby":_,"aria-invalid":w,name:h,required:v,autoFocus:g&&!V,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off",spellCheck:!1,disabled:o,value:L,"data-slot":S,"data-path-control":"input",onFocus:()=>{V?G(!1):j()},onBlur:()=>D(e),onKeyDown:ee,onChange:te=>{const Z=te.target.value,oe=pp(Z,R);D(Z),N(oe||R),t(oe||Z),G(!V)},onPaste:te=>{const Z=te.clipboardData.getData("text").trim(),oe=Z.startsWith('"')&&Z.endsWith('"')?Z.slice(1,-1):Z,Q=pp(oe,R);Q&&(te.preventDefault(),D(Q),N(Q),t(Q),G(!V))},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;V&&((te=B.current)==null||te.blur()),W?Y():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(WV,{className:"size-5","aria-hidden":"true"})})]}),m.jsx("div",{id:`${A}-browser`,children:re})]})]})}const _I="工作目录不存在或不可访问:",Hfe=[{value:"default",label:"严格审批"},{value:"auto",label:"自动判定"},{value:"acceptEdits",label:"自动接受编辑"},{value:"plan",label:"只读规划"},{value:"bypassPermissions",label:"跳过全部审批"}],RF=[{value:"auto",label:"按需审批"},{value:"bypassPermissions",label:"跳过全部审批"}],AF=[{value:"default",label:"手工审批"},{value:"auto",label:"自动审批"},{value:"plan",label:"只读规划"},{value:"bypassPermissions",label:"全自动"}],zk=[{value:"default",label:"命令审批"},{value:"auto",label:"智能自动"},{value:"plan",label:"只读规划"},{value:"bypassPermissions",label:"跳过全部审批"}],NF=zk.filter(e=>e.value!=="auto"),Jp={claude:"Claude Code",codex:"Codex",kimi:"Kimi Code",cursor:"Cursor CLI"};function Ufe(e,t){return t!==Ir.PATH_NOT_FOUND||!e.startsWith(_I)?null:e.slice(_I.length).trim()||null}function MF(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 Wfe(e,t,n="pty"){return e==="codex"?RF.some(r=>r.value===t)?t:"auto":e==="kimi"?AF.some(r=>r.value===t)?t:"default":e==="cursor"?(n==="json"?NF:zk).some(i=>i.value===t)?t:"default":t}async function qfe({relay:e,agentCli:t,form:n,timeoutMs:r=XC}){var d,f;const i=n.cwd.trim();if(!i)return{type:"validation_error",message:"请输入工作目录"};if(!e)return{type:"relay_missing",message:"请先连接开发机"};if(MF(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?`${Jp[n.provider]} 不可用:${h}`:`${Jp[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=Ufe(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 Yfe({relay:e,shell:t,timeoutMs:n=XC}){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 Vfe=["claude","codex","kimi","cursor"];function Kfe({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(Qb,{value:t,disabled:i,onValueChange:_=>s(_),children:[m.jsx(t_,{className:"min-h-11 w-full md:min-h-0","aria-label":"Agent CLI","data-slot":"agent-cli-provider-select",children:m.jsx(e_,{})}),m.jsx(n_,{"data-slot":"agent-cli-provider-options",children:Vfe.map(_=>m.jsx(r_,{value:_,className:"min-h-11 md:min-h-0",children:Jp[_]},_))})]}),m.jsxs("div",{className:"relative min-w-0","data-slot":"agent-cli-path-card",children:[m.jsx(Bk,{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({open:e,onOpenChange:t}){var Z;const[n,r]=b.useState(""),[i,s]=b.useState(""),[o,l]=b.useState("claude"),[u,d]=b.useState("pty"),[f,h]=b.useState("default"),[v,g]=b.useState(!1),[_,w]=b.useState(!1),[S,x]=b.useState(null),[T,k]=b.useState(null),[A,P]=b.useState(""),[R,M]=b.useState(!1),z=b.useRef(e);z.current=e;const V=ks(),W=Zr(oe=>oe.homePath),G=Zr(oe=>oe.agentCli),O=bo("(min-width: 768px)");b.useEffect(()=>{e&&!i&&W&&s(W)},[e,W,i]),b.useEffect(()=>{if(!e||W&&G)return;const oe=zt==null?void 0:zt.requestProxyInfo();oe&&oe.then(Q=>{const fe=Zr.getState();fe.setHomePath(Q.homePath),fe.setAgentCli(Q.agentCli)}).catch(Q=>{console.error("[create-session-dialog] requestProxyInfo failed",Q)})},[e,W,G]);function N(){r(""),s(""),l("claude"),d("pty"),h("default"),g(!1),x(null),k(null),P(""),M(!1)}function L(){if(f==="bypassPermissions"){g(!0);return}Y()}async function D(){await Y(),z.current&&g(!1)}const I=o==="codex"?RF:o==="kimi"?AF:o==="cursor"?u==="json"?NF:zk:Hfe,B=MF(o,G),F=T===o&&A.trim()!==(((Z=G==null?void 0:G[o])==null?void 0:Z.command)??""),U=_||R||B.disabled||F;function j(oe,Q=u){const fe=Wfe(oe,f,Q);fe!==f&&h(fe)}async function Y(oe){x(null),w(!0);try{const Q=await qfe({relay:zt,agentCli:G,form:{cwd:oe??i,name:n,provider:o,permissionMode:f,mode:u}});if(Q.type==="success"){if(Ut.getState().addSession(Q.session),!z.current)return;t(!1),N(),V(Q.route);return}if(Q.type==="missing_cwd"&&x(Q.path),$e.error(Q.message),Q.type==="validation_error"||Q.type==="relay_missing")return}finally{w(!1)}}async function X(oe){const Q=zt;if(!Q)return $e.error("请先连接开发机"),null;try{const fe=await Q.createDirectory(oe);return fe.success?(x(null),$e.success("目录已创建"),fe.path):($e.error(`目录创建失败:${fe.error??"未知错误"}`),null)}catch(fe){return $e.error(fe instanceof Error?fe.message:String(fe)),null}}function $(oe,Q){k(oe),P(Q)}async function ee(){if(!T)return;const oe=T,Q=A.trim();if(!Q){$e.error("请选择 Agent CLI 可执行文件");return}const fe=zt;if(!fe){$e.error("请先连接开发机");return}M(!0);try{const ge=await fe.updateAgentCliPath(oe,Q);if(ge.error||!ge.agentCli){$e.error(`路径保存失败:${ge.error??"未知错误"}`);return}Zr.getState().setAgentCli(ge.agentCli),$e.success(`${Jp[oe]} 路径已保存`),k(null),P("")}catch(ge){$e.error(ge instanceof Error?ge.message:String(ge))}finally{M(!1)}}function re(oe){d(oe),j(o,oe)}const te=v?m.jsxs("div",{className:"grid min-w-0 gap-5","data-slot":"bypass-permission-confirmation",children:[m.jsx(EF,{providerLabel:Jp[o]}),m.jsxs(Gs,{children:[m.jsx(dt,{type:"button",variant:"ghost",className:"min-h-11 md:min-h-0",onClick:()=>g(!1),disabled:_,children:"返回"}),m.jsx(dt,{type:"button",variant:"destructive",className:"min-h-11 md:min-h-0",onClick:()=>void D(),disabled:_,"data-slot":"bypass-permission-confirm",children:_?"创建中...":"确认"})]})]}):m.jsxs("form",{className:"flex min-w-0 flex-col gap-4","data-slot":"create-session-form",autoComplete:"off",onSubmit:oe=>{oe.preventDefault(),L()},children:[m.jsxs("label",{className:"flex min-w-0 flex-col gap-1",children:[m.jsx("span",{className:"text-sm",children:"名称(可选)"}),m.jsx("input",{type:"text",name:"dev-anywhere-session-name",autoComplete:"off",autoCorrect:"off",spellCheck:!1,value:n,onChange:oe=>r(oe.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(Bk,{id:"create-session-cwd",name:"dev-anywhere-session-cwd","data-slot":"create-session-cwd",label:"工作目录",value:i,selectionKind:"directory",placeholder:"选择工作目录",onCreateDirectory:X,onValueChange:oe=>{s(oe),x(null)}}),S?m.jsxs("section",{role:"status","aria-live":"polite",className:"rounded-md border border-primary/50 bg-primary/10 p-3",children:[m.jsx("p",{className:"text-sm font-medium",children:"工作目录不存在"}),m.jsx("p",{className:"mt-1 break-all font-mono text-xs text-muted-foreground",children:S})]}):null,m.jsxs("section",{"aria-label":"交互方式",className:"flex min-w-0 flex-col gap-2",children:[m.jsx("span",{className:"text-sm",children:"交互方式"}),m.jsxs("div",{className:We("grid min-w-0 gap-2","grid-cols-1 sm:grid-cols-2"),children:[m.jsxs("button",{type:"button","aria-pressed":u==="pty",onClick:()=>re("pty"),className:We("flex min-h-14 min-w-0 flex-col items-start justify-center gap-1 rounded-md border px-3 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring",u==="pty"?"border-primary/70 bg-primary/10":"border-border bg-muted/20"),children:[m.jsx("span",{className:"text-sm font-medium",children:"终端模式"}),m.jsx("span",{className:"text-xs text-muted-foreground",children:"像本地终端一样操作"})]}),m.jsxs("button",{type:"button","aria-pressed":u==="json",onClick:()=>re("json"),className:We("flex min-h-14 min-w-0 flex-col items-start justify-center gap-1 rounded-md border px-3 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring",u==="json"?"border-primary/70 bg-primary/10":"border-border bg-muted/20"),children:[m.jsx("span",{className:"text-sm font-medium",children:"聊天模式"}),m.jsx("span",{className:"text-xs text-muted-foreground",children:"气泡式对话,支持 Voice Pilot"})]})]})]}),m.jsx(Kfe,{agentCli:G,provider:o,cliPathDraftProvider:T,cliPathDraft:A,savingCliPath:R,onProviderChange:oe=>{l(oe),j(oe),k(null),P("")},onCliPathDraftChange:$,onDiscardCliPathDraft:()=>{k(null),P("")},onSaveCliPath:()=>void ee()}),m.jsxs("label",{className:"flex min-w-0 flex-col gap-2",children:[m.jsx("span",{className:"text-sm",children:"权限模式"}),m.jsxs(Qb,{value:f,onValueChange:oe=>h(oe),children:[m.jsx(t_,{className:"w-full",children:m.jsx(e_,{})}),m.jsx(n_,{children:I.map(oe=>m.jsx(r_,{value:oe.value,children:oe.label},oe.value))})]})]}),m.jsxs(Gs,{children:[m.jsx(dt,{type:"button",variant:"ghost",className:"min-h-11 md:min-h-0",onClick:()=>t(!1),disabled:_,children:"取消"}),m.jsx(dt,{type:"submit",className:"min-h-11 md:min-h-0",disabled:U,children:_?"创建中...":"创建"})]})]});return O?m.jsx(qi,{open:e,onOpenChange:t,children:m.jsxs(Yi,{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(Vi,{children:m.jsx(Pi,{children:v?"跳过全部审批?":"新建会话"})}),te]})}):m.jsx(gc,{open:e,onOpenChange:t,children:m.jsxs(vc,{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(yc,{children:v?"跳过全部审批?":"新建会话"})}),te]})})}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(qi,{open:e,onOpenChange:r,children:m.jsx(Yi,{className:"sm:max-w-md","data-slot":"session-rename-dialog",children:m.jsxs("form",{className:"grid gap-4",onSubmit:g=>void v(g),children:[m.jsxs(Vi,{children:[m.jsx(Pi,{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(dt,{type:"button",variant:"outline",onClick:()=>r(!1),children:"取消"}),m.jsx(dt,{type:"submit",disabled:f,children:"保存"})]})]})})})}function Gfe(e){return(e==null?void 0:e.kind)==="agent"&&e.mode==="pty"&&e.ptyOwner==="local-terminal"}function Xfe(e){return(e==null?void 0:e.kind)==="terminal"}function Zfe(e){return Gfe(e)?{title:"断开远程连接?",description:"这只会断开当前页面和本地终端的连接,本地终端里的 Claude Code/Codex/Kimi Code/Cursor CLI 会继续运行。重新接入前,页面不能继续查看或输入这个会话。",confirmLabel:"断开远程连接",destructive:!1}:Xfe(e)?{title:"终止终端?",description:"这会停止当前终端进程,并清理这个终端会话的运行状态。终止后不能继续输入,也无法恢复正在执行的命令。",confirmLabel:"终止终端",destructive:!0}:{title:"终止会话?",description:"这会停止当前 Agent 进程,并清理这个会话的运行状态。终止后不能继续输入,也无法恢复正在执行的任务。",confirmLabel:"终止会话",destructive:!0}}function Ev({open:e,session:t,onOpenChange:n,onConfirm:r}){const i=Zfe(t);function s(){t&&(r(t),n(!1))}return m.jsx(qi,{open:e,onOpenChange:n,children:m.jsxs(Yi,{"data-slot":"session-termination-dialog",children:[m.jsxs(Vi,{children:[m.jsx(Pi,{children:i.title}),m.jsx(fs,{children:i.description})]}),m.jsxs(Gs,{children:[m.jsx(dt,{type:"button",variant:"ghost",onClick:()=>n(!1),children:"取消"}),m.jsx(dt,{type:"button",variant:i.destructive?"destructive":"default",onClick:s,"data-slot":"session-termination-confirm",children:i.confirmLabel})]})]})})}function PF(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 Jfe(e){if(e.session.state==="error")return"error";const t=PF(e);return t==="disconnected"?e.session.state:t}const Qfe=new Set(["localhost","127.0.0.1","[::1]"]),B1={cloudflare:{label:"Cloudflare Tunnel",executable:"cloudflared",installUrl:"https://developers.cloudflare.com/tunnel/downloads/"},cpolar:{label:"Cpolar",executable:"cpolar"}};function ehe(){return Mi("local",Tn.webPreviewTunnelProvider)==="cpolar"?"cpolar":"cloudflare"}function IF(e,t){if(e)return t==="cloudflare"?e.cloudflared:e.cpolar}function k0(e,t){var n;return((n=IF(e,t))==null?void 0:n.available)===!0}function the(e){const t=e.trim();if(!t)return"请输入本机网站地址";let n;try{n=new URL(t)}catch{return"请输入完整的 http:// 本机网站地址"}return n.protocol!=="http:"||!Qfe.has(n.hostname)||n.username!==""||n.password!==""?"只支持 localhost、127.0.0.1 或 [::1] 的 http:// 地址":null}function Bh(){return{status:"idle"}}function nhe({open:e,onOpenChange:t}){const[n,r]=b.useState(""),[i,s]=b.useState(ehe),[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),P=b.useRef(null),R=b.useRef(i);R.current=i;const M=b.useRef(e);M.current=e;const z=bo("(min-width: 768px)"),V=Re(te=>te.selectedProxyId),W=Vr(te=>te.capability),G=Vr(te=>te.capabilityStatus),O=Vr(te=>te.capabilityError),N=Vr(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),Pr("local",Tn.webPreviewTunnelProvider,te)},[]);function I(){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,P.current=null}const B=b.useCallback(async te=>{var Q;(Q=T.current)==null||Q.abort();const Z=new AbortController;T.current=Z;const oe=Pt.getActiveScope();if(!(!oe||oe.proxyId!==V))try{const fe=await Pt.requestWebPreviewCapability(oe,te,{signal:Z.signal});if(!fe||Z.signal.aborted||!M.current||!fe.success)return;const ge=R.current,Ce=ge==="cloudflare"?"cpolar":"cloudflare";!k0(fe.capability,ge)&&k0(fe.capability,Ce)&&D(Ce)}catch{}},[D,V]);function F(te){!te&&S||t(te)}b.useEffect(()=>{if(!e){I();return}return B(!1),()=>{var te;(te=T.current)==null||te.abort(),T.current=null}},[B,e,L]),b.useEffect(()=>{var Q;if(!e||o!=="static")return;(Q=k.current)==null||Q.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 oe=window.setTimeout(()=>{const fe=zt,ge=Pt.getActiveScope();if(!fe||!ge||ge.proxyId!==V){w({status:"error",message:"请先连接开发机"});return}Pt.inspectStaticWebPreview(ge,te,{signal:Z.signal}).then(Ce=>{if(!Ce||Z.signal.aborted||!M.current||!Pt.isActive(fe,ge))return;if(!Ce.success){w({status:"error",message:Ce.error});return}const De=Ce.htmlEntries;if(De.length===0&&!Ce.entryPath){w({status:"error",message:"这里没有可以预览的网页"});return}const ot={entryPath:Ce.entryPath,htmlEntries:De};w({status:"ready",path:te,result:ot}),g(Ce.entryPath??"")}).catch(Ce=>{Z.signal.aborted||!M.current||Ce instanceof Error&&Ce.name==="AbortError"||!Pt.isActive(fe,ge)||w({status:"error",message:Ce instanceof Error?Ce.message:"检查网页失败"})})},300);return()=>{window.clearTimeout(oe),Z.abort(),k.current===Z&&(k.current=null)}},[e,L,V,o,f]);const U=o==="local"?the(u):null,j=o==="static"&&_.status==="ready"&&_.path===f.trim()&&!!(_.result.entryPath||v),Y=G==="loaded"&&k0(W,i),$=S||!Y||!(o==="local"?U===null:j);async function ee(){var fe,ge,Ce;if($)return;const te=zt;if(!te){$e.error("请先连接开发机");return}let Z;if(o==="local")Z={kind:"local",url:u.trim()};else{if(_.status!=="ready"||_.path!==f.trim())return;const De=_.result.entryPath??v;if(!De)return;Z={kind:"static",path:_.path,entryPath:De}}x(!0);const oe=Pt.getActiveScope();if(!oe){x(!1),$e.error("请先连接开发机");return}let Q=null;try{const De=n.trim(),ot=JSON.stringify({proxyId:oe.proxyId,tunnelProvider:i,source:Z,name:De||void 0});((fe=A.current)==null?void 0:fe.sourceKey)!==ot&&(A.current={sourceKey:ot,operationId:ym(`preview-operation-${i}`)}),Q=A.current.operationId,P.current=Q;const Dt=await Pt.createWebPreview(oe,Z,{tunnelProvider:i,operationId:Q,...De?{name:De}:{}});if(P.current!==Q)return;if(!Dt.accepted){((ge=A.current)==null?void 0:ge.operationId)===Q&&(A.current=null),$e.error(Dt.error);return}if(((Ce=A.current)==null?void 0:Ce.operationId)===Q&&(A.current=null),!M.current||!Pt.isActive(te,oe))return;t(!1)}catch(De){if(!Q||P.current!==Q||!M.current||!Pt.isActive(te,oe))return;$e.error(De instanceof Error?De.message:"无法创建网页预览")}finally{Q&&P.current===Q&&(P.current=null,M.current&&x(!1))}}const re=m.jsxs("form",{className:"flex min-w-0 flex-col gap-4","data-slot":"create-web-preview-form",autoComplete:"off",onSubmit:te=>{te.preventDefault(),ee()},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(Qb,{value:i,disabled:S,onValueChange:te=>D(te),children:[m.jsx(t_,{"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(e_,{})}),m.jsx(n_,{"data-slot":"web-preview-tunnel-provider-options",children:Object.keys(B1).map(te=>m.jsx(r_,{value:te,"data-slot":"web-preview-tunnel-provider-option","data-provider":te,children:B1[te].label},te))})]})]}),m.jsx(rhe,{status:G,capability:W,provider:i,error:O,disabled:S,onRetry:()=>void B(!0)}),m.jsxs("section",{"aria-label":"网页来源",className:"flex min-w-0 flex-col gap-2",children:[m.jsx("span",{className:"text-sm",children:"网页来源"}),m.jsxs("div",{className:"grid min-w-0 grid-cols-1 gap-2 sm:grid-cols-2",children:[m.jsxs("button",{type:"button","data-slot":"web-preview-source-local",disabled:S,"aria-pressed":o==="local",onClick:()=>{var te;(te=k.current)==null||te.abort(),k.current=null,w(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(Bk,{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(ihe,{inspection:_,selectedEntryPath:v,disabled:S,onEntryPathChange:te=>{g(te)}})]}),m.jsxs(Gs,{children:[m.jsx(dt,{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(dt,{type:"submit",className:"min-h-11 md:min-h-0",disabled:$,"data-slot":"create-web-preview-submit",children:S?"正在创建...":"创建预览"})]})]});return z?m.jsx(qi,{open:e,onOpenChange:F,children:m.jsxs(Yi,{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(Vi,{children:[m.jsx(Pi,{children:"新建网页预览"}),m.jsx(fs,{children:"输入本机网站地址,或选择 HTML 网页文件或目录。"})]}),re]})}):m.jsx(gc,{open:e,onOpenChange:F,children:m.jsxs(vc,{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(yc,{children:"新建网页预览"}),m.jsx(Zb,{children:"输入本机网站地址,或选择 HTML 网页文件或目录。"})]}),re]})})}function rhe({status:e,capability:t,provider:n,error:r,disabled:i,onRetry:s}){const o=B1[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(Xr,{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(Pz,{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(wI,{onClick:s,disabled:i})]})});const l=IF(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(vV,{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(wI,{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(cV,{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 wI({onClick:e,disabled:t}){return m.jsxs(dt,{type:"button",variant:"outline",size:"sm","data-slot":"web-preview-capability-retry",className:"shrink-0",onClick:e,disabled:t,children:[m.jsx(gm,{className:"size-3.5","aria-hidden":"true"}),"重新检测"]})}function ihe({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(Xr,{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(Qb,{value:t,onValueChange:r,disabled:n,children:[m.jsx(t_,{"data-slot":"web-preview-entry-select",className:"w-full font-mono",children:m.jsx(e_,{placeholder:"选择网页"})}),m.jsx(n_,{children:e.result.htmlEntries.map(o=>m.jsx(r_,{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 z1={ios:"iOS Simulator",android:"Android Emulator"};function she({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(S5),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 P=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]),V=b.useMemo(()=>M.filter(F=>!z.has(F.targetId)),[z,M]),W=V.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=zt,Y=Pt.getActiveScope();if(!(!j||!Y||Y.proxyId!==s))try{const $=await Pt.requestDevicePreviewCapability(Y,F,{signal:U.signal});if(!$||U.signal.aborted||!A.current||!$.success)return;await Pt.requestDevicePreviewTargets(Y,!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),P.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&&V.length===1&&S(V[0].targetId)}},[e,V,W,w]);async function N(){var X,$,ee;const F=W;if(!F||x||(G==null?void 0:G.available)!==!0)return;const U=zt,j=Pt.getActiveScope();if(!U||!j||j.proxyId!==s){$e.error("请先连接开发机");return}T(!0);let Y=null;try{const re=g.trim(),te=((X=P.current)==null?void 0:X.proxyId)===j.proxyId&&P.current.targetId===F.targetId&&P.current.name===re?P.current:{proxyId:j.proxyId,targetId:F.targetId,name:re,operationId:ym("device-preview-operation")};P.current=te,Y=te.operationId,R.current=Y;const Z=await Pt.createDevicePreview(j,F.targetId,{operationId:te.operationId,...re?{name:re}:{}});if(R.current!==te.operationId)return;if(!Z.accepted){if((($=P.current)==null?void 0:$.operationId)===te.operationId&&(P.current=null),!A.current||!Pt.isActive(U,j))return;$e.error(Z.error);return}if(((ee=P.current)==null?void 0:ee.operationId)===te.operationId&&(P.current=null),!A.current||!Pt.isActive(U,j))return;n(!1),r(`/preview/device/${Z.previewId}`)}catch(re){if(!Y||R.current!==Y||!A.current||!Pt.isActive(U,j))return;$e.error(re instanceof Error?re.message:"无法创建模拟器预览")}finally{Y&&R.current===Y&&(R.current=null,A.current&&T(!1))}}function L(F){var U;!F&&x||(F||((U=k.current)==null||U.abort(),k.current=null,P.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(ohe,{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(Xr,{className:"size-4 animate-spin","aria-hidden":"true"}),"正在查找已启动的模拟器..."]}):u==="error"?m.jsx(xI,{message:d??"无法读取模拟器列表"}):M.length===0?m.jsx(xI,{message:`没有已启动的 ${z1[t]}`}):M.map(F=>{const U=F.targetId===w,j=z.has(F.targetId);return m.jsx(ahe,{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(dt,{type:"button",variant:"outline",disabled:x||u==="loading",onClick:()=>void O(!0),"data-slot":"device-preview-refresh",children:[m.jsx(gm,{className:"size-4","aria-hidden":"true"}),"重新检测"]}),m.jsx(dt,{type:"button",disabled:!W||x||(G==null?void 0:G.available)!==!0,onClick:()=>void N(),"data-slot":"create-device-preview-submit",children:x?"正在创建...":"创建预览"})]})]}),I=`新建 ${z1[t]} 预览`,B="选择开发机上已经启动的模拟器。";return i?m.jsx(qi,{open:e,onOpenChange:L,children:m.jsxs(Yi,{showCloseButton:!x,className:"sm:max-w-xl","data-slot":"create-device-preview-dialog","data-platform":t,focusSurfaceOnOpen:!0,children:[m.jsxs(Vi,{children:[m.jsx(Pi,{children:I}),m.jsx(fs,{children:B})]}),D]})}):m.jsx(gc,{open:e,onOpenChange:L,children:m.jsxs(vc,{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(yc,{children:I}),m.jsx(Zb,{children:B})]}),D]})})}function ohe({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"?`${z1[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(Pz,{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 xI({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 ahe({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(Ny,{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(ua,{className:"size-4 text-primary","aria-hidden":"true"}):null]})}function OF({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(T0,{icon:m.jsx(Oz,{className:"size-5","aria-hidden":"true"}),title:"网页",description:"通过临时链接访问或分享本机网页",slot:"frontend-preview-web",onClick:()=>r("web")}),m.jsx(T0,{icon:m.jsx(Ny,{className:"size-5","aria-hidden":"true"}),title:"iOS Simulator",description:"查看和操控开发机上已启动的 iPhone 或 iPad 模拟器",slot:"frontend-preview-ios",onClick:()=>r("ios")}),m.jsx(T0,{icon:m.jsx(Ny,{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(qi,{open:d,onOpenChange:f=>!f&&o(),children:m.jsxs(Yi,{className:"sm:max-w-lg","data-slot":"create-frontend-preview-dialog",children:[m.jsxs(Vi,{children:[m.jsx(Pi,{children:"新建预览"}),m.jsx(fs,{children:"选择预览类型。"})]}),l]})},"chooser"):m.jsx(gc,{open:d,onOpenChange:f=>!f&&o(),children:m.jsxs(vc,{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(yc,{children:"新建预览"}),m.jsx(Zb,{children:"选择预览类型。"})]}),l]})},"chooser");case"web":return m.jsx(nhe,{open:d,onOpenChange:f=>!f&&o()},"web");case"ios":case"android":return m.jsx(she,{open:d,platform:u,onOpenChange:f=>!f&&o()},u);case null:return null}}function T0({icon:e,title:t,description:n,slot:r,onClick:i}){return m.jsxs(dt,{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 lhe({preview:e,closing:t,onOpenChange:n,onConfirm:r}){return m.jsx(qi,{open:e!==null,onOpenChange:n,children:m.jsxs(Yi,{"data-slot":"device-preview-close-dialog",children:[m.jsxs(Vi,{children:[m.jsx(Pi,{children:"停止预览?"}),m.jsx(fs,{children:"模拟器会继续在开发机上运行。"})]}),m.jsxs(Gs,{children:[m.jsx(dt,{type:"button",variant:"ghost",disabled:t,onClick:()=>n(!1),children:"取消"}),m.jsx(dt,{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 uhe({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(Ny,{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(kC,{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(dt,{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(Xr,{className:"animate-spin","aria-hidden":"true"}):m.jsx(yb,{"aria-hidden":"true"})})}),m.jsxs(Tf,{align:"end","data-slot":"device-preview-row-menu",children:[m.jsx(ii,{"data-slot":"device-preview-row-rename-item",onSelect:r,children:"重命名"}),d?m.jsx(ii,{"data-slot":"device-preview-row-reconnect-item",onSelect:i,children:"重新连接"}):null,m.jsx(Hl,{}),m.jsx(ii,{variant:"destructive","data-slot":"device-preview-row-close-item",onSelect:s,children:"停止预览"})]})]})]})}function dhe({preview:e,closing:t,onOpenChange:n,onConfirm:r}){return m.jsx(qi,{open:e!==null,onOpenChange:n,children:m.jsxs(Yi,{"data-slot":"preview-close-dialog",children:[m.jsxs(Vi,{children:[m.jsx(Pi,{children:"关闭预览?"}),m.jsx(fs,{children:"关闭后,当前预览链接将立即失效。"})]}),m.jsxs(Gs,{children:[m.jsx(dt,{type:"button",variant:"ghost",disabled:t,onClick:()=>n(!1),children:"取消"}),m.jsx(dt,{type:"button",variant:"destructive",disabled:!e||t,onClick:()=>e&&r(e),"data-slot":"preview-close-confirm",children:t?"正在关闭...":"关闭预览"})]})]})})}function fhe({target:e,onOpenChange:t,onRename:n}){return m.jsx(hhe,{target:e,onOpenChange:t,onRename:n},(e==null?void 0:e.targetKey)??"closed")}function hhe({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(qi,{open:e!==null,onOpenChange:f,children:m.jsx(Yi,{showCloseButton:!l,className:"sm:max-w-md","data-slot":"preview-rename-dialog",children:m.jsxs("form",{className:"grid gap-4",onSubmit:v=>void h(v),children:[m.jsx(Vi,{children:m.jsx(Pi,{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(dt,{type:"button",variant:"outline",disabled:l,onClick:()=>f(!1),children:"取消"}),m.jsx(dt,{type:"submit",disabled:l,"data-slot":"preview-rename-submit",children:"保存"})]})]})})})}const phe={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:Eb(e.source.rootPath,e.source.entryPath)}async function ghe(e){if(await Vp(e,{allowUserGestureFallback:!0})==="failed"){$e.error("复制失败,请稍后重试");return}$e.success("链接已复制")}async function vhe(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;$e.error("无法打开系统分享面板")}}function yhe({preview:e,pendingOperation:t,onRename:n,onReconnect:r,onClose:i}){const s=Zr(w=>w.homePath),o=phe[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"?Yp(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(Oz,{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(dt,{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(Xr,{className:"animate-spin","aria-hidden":"true"}):m.jsx(yb,{"aria-hidden":"true"})})}),m.jsxs(Tf,{align:"end","data-slot":"preview-row-menu",children:[m.jsx(ii,{"data-slot":"preview-row-rename-item",onSelect:n,children:"重命名"}),d?m.jsx(ii,{"data-slot":"preview-row-copy-item",onSelect:()=>void ghe(u),children:"复制链接"}):null,h?m.jsx(ii,{"data-slot":"preview-row-share-item",onSelect:()=>void vhe(e.name,u),children:"分享…"}):null,f?m.jsx(ii,{"data-slot":"preview-row-reconnect-item",onSelect:r,children:"重新连接"}):null,m.jsx(Hl,{}),m.jsx(ii,{variant:"destructive","data-slot":"preview-row-close-item",onSelect:i,children:"关闭预览"})]})]})]})}const bhe=Object.freeze([]),_he=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"?Vr.getState().authoritative:mr.getState().authoritative;return!n||!vp(e,t,n.scope)?!1:n.previews.some(r=>r.previewId===e.previewId)}function Wo(e){const t=Pt.getActiveScope();return t!==null&&rn(t,e)}function SI(){const e=Vr(N=>N.authoritative),t=mr(N=>N.authoritative),n=Jo(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:bhe,l=s&&t?t.previews:_he,u=bz("/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 I;return(I=b5(n,N,L,D)[0])==null?void 0:I.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(!Wo(N.scope))return;L.success||$e.error(L.error)}catch(L){if(!Wo(N.scope))return;$e.error(L instanceof Error?L.message:"无法重新连接网页预览")}}async function P(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(I){if(!Wo(N.scope))return;throw I}if(Wo(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(!Wo(N.scope))return;if(!L.success){$e.error(L.error);return}h(D=>Uc(D,N)?null:D)}catch(L){if(!Wo(N.scope))return;$e.error(L instanceof Error?L.message:"无法关闭网页预览")}}async function M(N){if(zh(N))try{const L=await Pt.reconnectDevicePreview(N.scope,N.previewId);if(!Wo(N.scope))return;L.success||$e.error(L.error)}catch(L){if(!Wo(N.scope))return;$e.error(L instanceof Error?L.message:"无法重新连接模拟器预览")}}async function z(N){if(zh(N))try{const L=await Pt.closeDevicePreview(N.scope,N.previewId);if(!Wo(N.scope))return;if(!L.success){$e.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(!Wo(N.scope))return;$e.error(L instanceof Error?L.message:"无法停止模拟器预览")}}const V=(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(yhe,{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(uhe,{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(fhe,{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?P(G,N):Promise.resolve()}),m.jsx(dhe,{preview:x,closing:V,onOpenChange:N=>{!N&&!V&&O&&h(L=>Uc(L,O)?null:L)},onConfirm:()=>O&&void R(O)}),m.jsx(lhe,{preview:T,closing:W,onOpenChange:N=>{!N&&!W&&O&&h(L=>Uc(L,O)?null:L)},onConfirm:()=>O&&void z(O)})]})}function LF({layout:e}){const t=Ut(Q=>Q.sessions),n=Ut(Q=>Q.sessionListLoaded),r=Ut(Q=>Q.agentStatusBySessionId),i=Ut(Q=>Q.ptyStateBySessionId),s=Ut(Q=>Q.renameSession),o=ln(Q=>Q.bySessionId),l=bz("/chat/:id"),u=(l==null?void 0:l.params.id)??null,d=Re(Q=>!!Q.selectedProxyId),f=Re(Q=>Q.proxyListLoaded),h=Re(Q=>Q.proxySwitchTarget),v=Ut(Q=>Q.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),[P,R]=b.useState(!1),[M,z]=b.useState(!1),[V,W]=b.useState(null),[G,O]=b.useState(null),{creatingTerminal:N,creatingShell:L,createTerminal:D}=DF(),[I,B]=b.useState(new Set),[F,U]=b.useState(()=>Date.now());b.useEffect(()=>{const Q=setInterval(()=>U(Date.now()),6e4);return()=>clearInterval(Q)},[]);function j(Q,fe){S(`/chat/${Q}?mode=${fe}`,{replace:!1})}function Y(Q){const fe=Q.sessionId,ge=zt;if(!ge){$e.error("请先连接开发机");return}ge.sendControl({type:"session_terminate",sessionId:fe}),Ut.getState().removeSession(fe),ln.getState().clearSession(fe),fe===u&&S("/sessions"),(Q==null?void 0:Q.kind)==="agent"&&Q.mode==="pty"&&Q.ptyOwner==="local-terminal"?$e.info("已断开页面连接,本地终端仍在运行"):$e.info("正在终止会话",{duration:1500})}async function X(Q,fe){const ge=zt;if(!ge)throw new Error("请先连接开发机");const Ce=await ge.renameSession(Q,fe);if(!Ce.success)throw new Error(Ce.error??"重命名失败");s(Q,Ce.name??fe),$e.success("已重命名会话")}function $(Q){B(fe=>{const ge=new Set(fe);return ge.has(Q)?ge.delete(Q):ge.add(Q),ge})}function ee(Q){var Ce;const fe=Q.mode==="json"&&(((Ce=o[Q.sessionId])==null?void 0:Ce.pendingApprovals.some(De=>De.status==="pending"))??!1),ge=Jfe({session:Q,agentStatus:r[Q.sessionId],ptyState:i[Q.sessionId],hasPendingApproval:fe});return ge===Q.state?Q:{...Q,state:ge}}const re=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(Ev,{open:G!==null,session:G,onOpenChange:Q=>{Q||O(null)},onConfirm:Y}),m.jsx(gp,{open:V!==null,sessionId:(V==null?void 0:V.sessionId)??null,initialName:V==null?void 0:V.name,onOpenChange:Q=>{Q||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(Xr,{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(Ev,{open:G!==null,session:G,onOpenChange:Q=>{Q||O(null)},onConfirm:Y}),m.jsx(gp,{open:V!==null,sessionId:(V==null?void 0:V.sessionId)??null,initialName:V==null?void 0:V.name,onOpenChange:Q=>{Q||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:["活跃会话",re?m.jsxs("span",{className:"ml-1 text-muted-foreground/70 font-normal",children:["· ",t.length]}):null]}),Z=re?m.jsx("ul",{role:"list",className:"flex flex-col w-full min-w-0",children:whe(t).map(Q=>m.jsxs("li",{children:[m.jsxs("button",{type:"button",onClick:()=>$(Q.provider),"aria-expanded":!I.has(Q.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:xhe(Q.provider)}),m.jsx("span",{className:"h-px flex-1 bg-border/70","aria-hidden":"true"}),m.jsx("span",{className:"tabular-nums",children:Q.sessions.length}),m.jsx(Yd,{className:We("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",!I.has(Q.provider)&&"rotate-90"),"aria-hidden":"true"})]}),I.has(Q.provider)?null:m.jsx("ul",{role:"list",className:"flex flex-col",children:Q.sessions.map(fe=>m.jsx(Tfe,{session:ee(fe),selected:fe.sessionId===u,now:F,onClick:()=>j(fe.sessionId,fe.mode),onRename:()=>W(fe),onTerminate:()=>O(fe)},fe.sessionId))})]},Q.provider))}):m.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/70","data-slot":"active-empty",children:"暂无活跃会话"}),oe=m.jsx(Lfe,{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(SI,{}),oe]}),m.jsx("div",{className:"px-4 pt-4 pb-[calc(env(safe-area-inset-bottom)+1rem)] border-t border-border",children:m.jsxs(dt,{className:"min-h-11 w-full md:min-h-0","data-slot":"create-session-mobile-trigger",onClick:()=>A(!0),children:[m.jsx(Iz,{"aria-hidden":"true"}),"新建"]})}),m.jsx(The,{open:k,creatingTerminal:N,onOpenChange:A,onCreateAgent:()=>{A(!1),T(!0)},onCreateTerminal:()=>{BF()?(A(!1),R(!0)):D(void 0,()=>A(!1))},onCreatePreview:()=>{A(!1),z(!0)}}),m.jsx(zF,{layout:"mobile",open:P,creatingTerminal:N,creatingShell:L,onOpenChange:R,onBack:()=>{R(!1),A(!0)},onCreate:Q=>void D(Q,()=>R(!1))}),m.jsx(mp,{open:x,onOpenChange:T}),m.jsx(OF,{open:M,onOpenChange:z}),m.jsx(Ev,{open:G!==null,session:G,onOpenChange:Q=>{Q||O(null)},onConfirm:Y}),m.jsx(gp,{open:V!==null,sessionId:(V==null?void 0:V.sessionId)??null,initialName:V==null?void 0:V.name,onOpenChange:Q=>{Q||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(SI,{}),oe]}),m.jsx(mp,{open:x,onOpenChange:T}),m.jsx(Ev,{open:G!==null,session:G,onOpenChange:Q=>{Q||O(null)},onConfirm:Y}),m.jsx(gp,{open:V!==null,sessionId:(V==null?void 0:V.sessionId)??null,initialName:V==null?void 0:V.name,onOpenChange:Q=>{Q||W(null)},onRename:X})]})}function whe(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])=>She(n,r)).map(([n,r])=>({provider:n,sessions:r}))}function xhe(e){return e==="terminal"?"终端":Jb(e)}function She(e,t){return e===t?0:e==="terminal"?-1:t==="terminal"?1:xF(e,t)}function DF(){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)&&!jk(l)&&!(s&&!((u=l.terminalShells)!=null&&u.some(d=>d.id===s)))){n(s??"default");try{const d=await Yfe({relay:zt,shell:s});if(d.type!=="success"){$e.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 jk(e){var t;return!e.terminalShellsLoaded&&((t=e.proxies.find(n=>n.proxyId===e.selectedProxyId))==null?void 0:t.osName)==="Windows"}function Ehe(e){const t=Re(u=>u.terminalShells),n=Re(jk),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=zt,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 Che=[{label:"启动 Shell"}];function khe(e){return e!=null&&e.length?e:Che}function BF(){var t;const e=Re.getState();return jk(e)||!!((t=e.terminalShells)!=null&&t.length)}function EI({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(V=>!!V.selectedProxyId),g=Re(V=>V.proxySwitchTarget!==null),_=v&&!g,{creatingTerminal:w,creatingShell:S,createTerminal:x}=DF();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,BF()?i(!0):x()}function P(){if(!_){T();return}h.current=!0,u(!0)}function R(V){V.preventDefault(),T()}const M=m.jsxs(dt,{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(Iz,{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:V=>{h.current&&(h.current=!1,V.preventDefault())},children:[m.jsxs(ii,{className:"min-h-9 gap-2.5","data-slot":"create-agent-session-item",onSelect:k,children:[m.jsx(Mz,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),"Agent 会话"]}),m.jsxs(ii,{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(Hl,{}),m.jsxs(ii,{className:"min-h-[3.75rem] items-start gap-2.5 py-2","data-slot":"create-frontend-preview-item",onSelect:P,children:[m.jsx(MC,{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(zF,{layout:"desktop",open:r,creatingTerminal:w,creatingShell:S,onOpenChange:i,onBack:()=>{i(!1),n(!0)},onCreate:V=>void x(V,()=>i(!1))}),m.jsx(mp,{open:s,onOpenChange:o}),m.jsx(OF,{open:l,onOpenChange:u})]})}function The({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(gc,{open:e,onOpenChange:n,children:m.jsxs(vc,{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(yc,{children:"新建"})}),m.jsxs("div",{className:"grid gap-2 pb-1","data-slot":"create-session-type-options",children:[m.jsxs(dt,{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(Mz,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),"Agent 会话"]}),m.jsxs(dt,{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(dt,{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(MC,{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 zF({layout:e,open:t,creatingTerminal:n,creatingShell:r,onOpenChange:i,onBack:s,onCreate:o}){const{terminalShells:l,needsDetection:u,failed:d,retry:f}=Ehe(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(dt,{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?"终端检测失败,点击重试":"正在检测终端..."]}):khe(l).map(w=>m.jsxs(dt,{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(Mfe,{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(dt,{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(gc,{open:t,onOpenChange:i,children:m.jsxs(vc,{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(yc,{children:"Shell 会话"})}),g]})}):m.jsx(qi,{open:t,onOpenChange:i,children:m.jsxs(Yi,{className:"sm:max-w-sm","data-slot":"create-terminal-shell-dialog",focusSurfaceOnOpen:!0,onCloseAutoFocus:_,children:[m.jsx(Vi,{children:m.jsx(Pi,{children:"Shell 会话"})}),g]})})}const Rhe="0.10.3",Ahe={version:Rhe},Nhe={playback:"playback",capture:"play-and-record"};function Mhe(){return typeof navigator>"u"?null:navigator.audioSession??null}function Phe(){return{setMode:()=>{},release:()=>{}}}class Ihe{constructor(t=Mhe){ze(this,"leases",new Map);ze(this,"session",null);ze(this,"baselineType",null);ze(this,"nextLeaseId",1);ze(this,"nextOrder",1);this.getAudioSession=t}acquire(t){const n=this.getAudioSession();if(!n)return Phe();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(Nhe[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 Fk=new Ihe,j1=64,CI=-60,jF=32;function kI(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-CI)/-CI));return e<0?-r:r}function TI(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 Ohe(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 Lhe(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 FF{constructor(t,n=24e3,r={}){ze(this,"nextStartTime",0);ze(this,"activityEndToken",0);ze(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=Ohe(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*jF/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=Lhe(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 R0={provider:"aliyun-bailian",configured:!1,region:"cn",asrModel:"qwen3-asr-flash-realtime",ttsModel:"cosyvoice-v3-flash",ttsVoice:"longanyang",turnIdleSeconds:3},RI="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",Dhe=800,AI=300,Bhe=1600;function F1(e,t){return e.filter(n=>!n.model||n.model===t)}function NI({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 Cv({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=!!$F(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(MI,{label:f,muted:!d&&!t}),m.jsx(oc,{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(ua,{className:"size-4","aria-hidden":"true"}):null}),m.jsx(MI,{label:g.label})]},g.value)})}):null,s?m.jsx("div",{className:"mt-2 text-xs leading-relaxed text-muted-foreground",children:s}):null]})}function MI({label:e,muted:t=!1}){const n=$F(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 zhe({scrollRef:e}={}){const[t,n]=b.useState(R0),[r,i]=b.useState(String(R0.turnIdleSeconds)),[s,o]=b.useState(()=>cv()),[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=zt;if(!Z){_({kind:"error",message:"请先连接 Relay 服务器"});return}let oe=!1;return _({kind:"loading"}),Z.requestVoiceConfig().then(Q=>{if(!oe){if(Q.error||!Q.config){_({kind:"error",message:Q.error??"读取语音设置失败"});return}n(Q.config),i(String(Q.config.turnIdleSeconds)),u(""),f(!1),v(!0),_({kind:"idle"})}}).catch(Q=>{oe||_({kind:"error",message:Q instanceof Error?Q.message:"读取语音设置失败"})}),()=>{oe=!0}},[]),b.useEffect(()=>{const Z=zt;if(!Z||!h)return;let oe=!1;return Z.requestVoiceCapabilities({region:t.region}).then(Q=>{if(!oe){if(Q.error||!Q.capabilities){o(cv());return}o(Q.capabilities)}}).catch(()=>{oe||o(cv())}),()=>{oe=!0}},[t.region,h]),b.useEffect(()=>(A.current=!0,()=>{A.current=!1,$(),ee()}),[]);const P=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(()=>F1(s.ttsVoices,t.ttsModel),[s.ttsVoices,t.ttsModel]),V=M.some(Z=>Z.value===t.ttsVoice)?t.ttsVoice:"",W=M.length===0?"当前模型暂无可用音色":V?null:"请选择可用音色",G=b.useMemo(()=>Hhe(r),[r]),O=G?null:"请输入正整数秒数",N=W??O,L=R||!!N,D=b.useMemo(()=>[{value:"cn",label:"中国大陆"},{value:"intl",label:"国际"}],[]),I=b.useMemo(()=>OI(s.asrModels,t.asrModel),[s.asrModels,t.asrModel]),B=b.useMemo(()=>Uhe(s.ttsModels,s.ttsVoices,t.ttsModel),[s.ttsModels,s.ttsVoices,t.ttsModel]),F=b.useMemo(()=>OI(M,V),[M,V]);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??R0.turnIdleSeconds}}async function j(){if(R)return;if(N){_({kind:"error",message:N});return}const Z=zt;if(!Z){_({kind:"error",message:"请先连接 Relay 服务器"});return}const oe=U();ee(),_({kind:"saving"});const Q=performance.now();try{const fe=await Z.updateVoiceConfig(oe);if(!A.current)return;const ge=performance.now()-Q;if(ge<AI&&await $he(AI-ge),!A.current)return;if(!fe.success||fe.error||!fe.config){_({kind:"error",message:fe.error??"保存语音设置失败"});return}n(fe.config),i(String(fe.config.turnIdleSeconds)),u(""),f(!1),_({kind:"saved"}),k.current=setTimeout(()=>{k.current=null,_(Ce=>Ce.kind==="saved"?{kind:"idle"}:Ce)},Bhe),Z.requestVoiceCapabilities({region:fe.config.region}).then(Ce=>{A.current&&Ce.capabilities&&o(Ce.capabilities)}).catch(()=>{A.current&&o(cv())})}catch(fe){if(!A.current)return;_({kind:"error",message:fe instanceof Error?fe.message:"保存语音设置失败"})}}async function Y(){if(R)return;if(N){_({kind:"error",message:N});return}const Z=zt;if(!Z){_({kind:"error",message:"请先连接 Relay 服务器"});return}let oe;try{oe=X()}catch(Q){_({kind:"error",message:II(Q)});return}_({kind:"testing"});try{const[Q]=await Promise.all([Z.testVoiceConfig(U()),oe.ready]);if(!Q.success||Q.error){$(),_({kind:"error",message:Q.error??"语音配置测试失败"});return}const fe=await re(Q,oe.context);_({kind:"playingTest",transcript:Q.transcript}),T.current=setTimeout(()=>{T.current=null,$(),_({kind:"testPassed",transcript:Q.transcript})},fe)}catch(Q){$(),_({kind:"error",message:II(Q)})}}function X(){$();const Z=Fk.acquire("playback");S.current=Z;try{const oe=Fhe();return w.current=oe,{context:oe,ready:PI(oe)}}catch(oe){throw Z.release(),S.current=null,oe}}function $(){var Z,oe,Q;T.current&&(clearTimeout(T.current),T.current=null),(Z=x.current)==null||Z.stop(),x.current=null,(oe=w.current)==null||oe.close(),w.current=null,(Q=S.current)==null||Q.release(),S.current=null}function ee(){k.current&&(clearTimeout(k.current),k.current=null)}async function re(Z,oe){if(!Z.audioBase64)throw new Error("语音测试未返回可播放音频");if(Z.audioEncoding&&Z.audioEncoding!=="pcm_s16le")throw new Error("测试音频格式暂不支持");const Q=Z.audioSampleRate??24e3,fe=jhe(Z.audioBase64);if(fe.byteLength===0||fe.byteLength%2!==0)throw new Error("测试音频数据无效");await PI(oe);const ge=new FF(oe,Q);x.current=ge,ge.enqueue(fe);const Ce=Math.ceil(fe.byteLength/2/Q*1e3);return Math.max(Dhe,Ce)}function te(Z){var oe;return((oe=F1(s.ttsVoices,Z)[0])==null?void 0:oe.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(NI,{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(zz,{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:`${RI} w-full pl-9`})]}),t.configured&&m.jsxs(dt,{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(Uz,{className:"size-4","aria-hidden":"true"}),"清空"]})]})}),m.jsx(Cv,{label:"地域",value:t.region,options:D,onChange:Z=>n(oe=>({...oe,region:Z==="intl"?"intl":"cn"}))}),m.jsx(Cv,{label:"语音识别模型",value:t.asrModel,options:I,onChange:Z=>n(oe=>({...oe,asrModel:Z}))}),m.jsx(Cv,{label:"语音合成模型",value:t.ttsModel,options:B,onChange:Z=>n(oe=>({...oe,ttsModel:Z,ttsVoice:te(Z)}))}),m.jsx(Cv,{label:"语音音色",value:V,options:F,placeholder:M.length===0?"暂无可用音色":"请选择音色",onChange:Z=>n(oe=>({...oe,ttsVoice:Z})),help:W}),m.jsx(NI,{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:`${RI} 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:[P?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:P}):null,m.jsxs(dt,{type:"button",variant:"outline",disabled:L,onClick:()=>void Y(),children:[m.jsx(PC,{className:"size-4","aria-hidden":"true"}),"测试"]}),m.jsxs(dt,{type:"submit",disabled:L,children:[m.jsx(RK,{className:"size-4","aria-hidden":"true"}),g.kind==="saving"?"保存中...":"保存"]})]})]})]})}function jhe(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 Fhe(){const e=window,t=e.AudioContext??e.webkitAudioContext;if(!t)throw new Error("当前浏览器不支持音频播放");return new t}async function PI(e){if(e.state!=="running")try{await e.resume()}catch{throw new Error("浏览器阻止了测试音频播放,请再次点击测试")}if(e.state!=="running")throw new Error("浏览器阻止了测试音频播放,请再次点击测试")}function II(e){return e instanceof Error?e.message:"语音配置测试失败"}function $he(e){return new Promise(t=>setTimeout(t,e))}function Hhe(e){const t=e.trim();if(!/^[1-9]\d*$/.test(t))return null;const n=Number(t);return Number.isSafeInteger(n)?n:null}function OI(e,t){const n=e.map(r=>({value:r.value,label:HF(r)}));return!t||n.some(r=>r.value===t)?n:[{value:t,label:t},...n]}function Uhe(e,t,n){const r=e.map(i=>{const s=F1(t,i.value).length===0;return{value:i.value,label:`${HF(i)}${s?" · 暂无音色":""}`,disabled:s}});return!n||r.some(i=>i.value===n)?r:[{value:n,label:`${n} · 暂无音色`,disabled:!0},...r]}function $F(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 HF(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 Whe=[{value:"auto",label:"跟随系统"},{value:"light",label:"浅色"},{value:"dark",label:"深色"}],qhe=[{value:"auto",label:"自动"},{value:"touch",label:"触控优先"},{value:"hardware",label:"实体键盘优先"}],$k="dev-render-scroll min-h-0 space-y-3 overflow-y-auto overscroll-contain pr-4 sm:pr-1";function UF(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 Yhe(e){const t=e||window.location.origin;return new URL("/health",t).toString()}function Vhe(e){return e==="version"?"版本":e==="relay-token"?"Relay Token":e==="clients"?"客户端管理":"设置 Voice Pilot"}function Khe(e){return e==="version"?"Web 与 Relay 服务器版本。":e==="relay-token"?"连接受保护的 Relay 服务器,保存后立即重连。":e==="clients"?"管理当前连接的 Web 客户端。":"连接语音服务后,即可以语音交互的形式驱动会话。"}function $1({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),P=foe(),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 Bse();if(O==="granted"){o(!0);return}if(O==="denied"){$e.error("浏览器未授予通知权限,请在浏览器设置中允许通知");return}if(O==="default"){$e.info("未授予通知权限,会话通知保持关闭");return}$e.error("当前浏览器不支持系统通知")},[o]),z=b.useCallback(async G=>{T({kind:"loading"});try{const O=await fetch(Yhe(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 V=x.kind==="ready"?x.version:x.kind==="loading"?"读取中...":x.kind==="error"?"读取失败":"未读取",W=x.kind==="ready"?`运行 ${UF(x.uptime)}`:x.kind==="error"?x.message:"从当前 Relay 服务器 /health 读取";return m.jsx(qi,{open:e,onOpenChange:t,children:m.jsxs(Yi,{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(Vi,{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(dt,{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(Pi,{children:Vhe(g)}),m.jsx(fs,{className:"max-w-[28rem] leading-5",children:Khe(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(Pi,{children:"设置"}),m.jsx(fs,{children:"连接、外观、通知和高级诊断选项。"})]})}),g==="version"?m.jsx(Ghe,{relayVersion:V,relayDetail:W,relayMuted:x.kind==="error"}):g==="relay-token"?m.jsx(Zhe,{saved:P}):g==="clients"?m.jsx(npe,{}):g==="voice"?m.jsx(zhe,{scrollRef:A}):m.jsx(Xhe,{relayTokenSaved:P,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 Ghe({relayVersion:e,relayDetail:t,relayMuted:n}){return m.jsxs("div",{className:$k,"data-slot":"settings-dialog-body",children:[m.jsx(DI,{icon:m.jsx(jz,{className:"size-4","aria-hidden":"true"}),label:"Web",value:Ahe.version,detail:"当前浏览器加载的版本"}),m.jsx(DI,{icon:m.jsx($z,{className:"size-4","aria-hidden":"true"}),label:"Relay 服务器",value:e,detail:t,muted:n})]})}function Xhe({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(kv,{icon:m.jsx(QY,{className:"size-4","aria-hidden":"true"}),label:"Voice Pilot",detail:"用语音输入、听取回复和处理审批",onClick:v}),m.jsx(kv,{icon:m.jsx(zz,{className:"size-4","aria-hidden":"true"}),label:"Relay Token",detail:`${e?"已保存":"未设置"} · 受保护的 Relay 服务器`,onClick:g}),m.jsx(kv,{icon:m.jsx(XK,{className:"size-4","aria-hidden":"true"}),label:"客户端管理",detail:"已连接的浏览器页面和设备",onClick:_})]}),m.jsx(hd,{title:"外观",children:m.jsx(LI,{icon:m.jsx(jK,{className:"size-4","aria-hidden":"true"}),label:"主题",value:t,options:Whe,onValueChange:n})}),m.jsx(hd,{title:"通知",children:m.jsx(N0,{icon:m.jsx(tV,{className:"size-4","aria-hidden":"true"}),label:"会话空闲通知",detail:"会话从工作中转为空闲时发送浏览器通知",checked:o,onCheckedChange:l})}),s?m.jsx(hd,{title:"交互",children:m.jsx(LI,{icon:m.jsx(AC,{className:"size-4","aria-hidden":"true"}),label:"输入方式",detail:"默认自动识别软键盘和实体键盘;必要时可强制一种方式",value:r,options:qhe,onValueChange:i})}):null,m.jsxs(hd,{title:"高级诊断",children:[m.jsx(N0,{icon:m.jsx(ou,{className:"size-4","aria-hidden":"true"}),label:"PTY 滚动追踪",detail:"记录终端滚动和视口同步现场,方便复制诊断报告",checked:u,onCheckedChange:d}),m.jsx(N0,{icon:m.jsx(Az,{className:"size-4","aria-hidden":"true"}),label:"延迟监控",detail:"显示可拖动的连接延迟浮窗",checked:f,onCheckedChange:h})]}),m.jsx(hd,{title:"关于",children:m.jsx(kv,{icon:m.jsx($z,{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 LI({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 Zhe({saved:e}){const t=b.useId(),n=b.useId(),[r,i]=b.useState(""),[s,o]=b.useState(null),l=()=>{O5().catch(f=>{o(f instanceof Error?f.message:"Relay 重连失败。")})},u=()=>{const f=r.trim();if(!f){o("请输入 token。");return}if(!P5(f)){const h="Relay Token 保存失败,请检查浏览器存储权限。";o(h),$e.error(h);return}o(null),$e.success("Relay Token 已保存,正在重新连接"),l()},d=()=>{I5(),l()};return m.jsxs("form",{className:$k,"data-slot":"settings-dialog-body",onSubmit:f=>{f.preventDefault(),u()},children:[m.jsxs("div",{className:"rounded-md border border-border bg-card/70 p-3","data-slot":"relay-token-card",children:[m.jsx("label",{htmlFor:t,className:"text-sm font-medium text-foreground",children:"Token"}),m.jsx("input",{id:t,type:"password",value:r,onChange:f=>{i(f.currentTarget.value),s&&o(null)},autoComplete:"off",spellCheck:!1,"aria-describedby":s?n:void 0,className:"mt-2 h-10 w-full rounded-md border border-border bg-background px-3 font-mono text-sm text-foreground outline-none transition-colors placeholder:text-muted-foreground focus:border-ring focus:ring-2 focus:ring-ring/75",placeholder:"粘贴 token"}),s?m.jsx("p",{id:n,className:"mt-2 text-xs text-destructive",children:s}):null]}),m.jsxs("div",{className:"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",children:[e?m.jsx(dt,{type:"button",variant:"outline",onClick:d,children:"清空"}):null,m.jsx(dt,{type:"submit",disabled:!r.trim(),children:"保存"})]})]})}function Jhe(e){return e.length<=16?e:`${e.slice(0,8)}...${e.slice(-4)}`}function Qhe(e,t){var r;return((r=t.get(e))==null?void 0:r.trim())||Jhe(e)}function epe(e){return Rre(e)}function tpe(e){const t=Math.max(0,Math.floor((Date.now()-e)/1e3));return UF(t)}function A0({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 npe(){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=zt;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=zt;if(!g){o("Relay 未连接。");return}u(v),o(null);try{const _=await g.kickRelayClient(v);if(!_.success){o(_.error??"断开客户端失败。");return}n(w=>w.filter(S=>S.clientId!==v))}catch(_){o(_ instanceof Error?_.message:"断开客户端失败。")}finally{u(null)}},[]);return m.jsxs("div",{className:$k,"data-slot":"settings-dialog-body",children:[m.jsxs("div",{className:"flex min-h-9 items-center gap-2","data-slot":"relay-clients-toolbar",children:[m.jsx("div",{className:"text-sm font-medium text-foreground",children:r?"正在读取客户端":`${t.length} 个在线客户端`}),m.jsx(dt,{type:"button",variant:"ghost",size:"icon-sm","aria-label":"刷新客户端列表",title:"刷新",onClick:()=>void f(),disabled:r,"data-slot":"relay-clients-refresh",children:m.jsx(gm,{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:epe(v)})}),m.jsxs("div",{className:"space-y-1",children:[m.jsx(A0,{label:"已连接",value:tpe(v.connectedAt)}),v.proxyId?m.jsx(A0,{label:"连接到",value:Qhe(v.proxyId,d),title:v.proxyId}):null,v.remoteAddress?m.jsx(A0,{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(dt,{type:"button",variant:"outline",size:"sm",className:"h-9 w-full justify-center",disabled:_,onClick:()=>void h(v.clientId),"data-slot":"relay-client-action",children:[m.jsx(nK,{className:"size-3.5","aria-hidden":"true"}),_?"断开中...":"断开"]})]})},v.clientId)})]})}function N0({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 kv({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 DI({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 rpe="xterm-helper-textarea";function ipe(e=document.activeElement){return!(e instanceof HTMLElement)||!e.classList.contains(rpe)?!1:(e.blur(),!0)}function BI(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&&spe(r,n))return!0;if(r===t)break;r=r.parentElement}return!1}function spe(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 ope({releasePtyFocus:e=!0,containVerticalScroll:t=!0}={}){const n=b.useRef(null),r=b.useCallback(()=>{e&&ipe()},[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,BI(l.target,l.currentTarget,f)||l.preventDefault()},[t]),o=b.useCallback(l=>{r(),t&&(BI(l.target,l.currentTarget,l.deltaY)||l.preventDefault())},[t,r]);return{onPointerDownCapture:r,onTouchStartCapture:i,onTouchMoveCapture:s,onWheelCapture:o}}function ape({className:e}){const t=Re(o=>o.sidebarCollapsed),n=Re(o=>o.toggleSidebarCollapsed),[r,i]=b.useState(!1),s=ope();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(jI,{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(zI,{compact:!0,tooltipSide:"right",onClick:()=>i(!0)}),m.jsx(EI,{compact:!0})]})]}),m.jsx($1,{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(aj,{className:"text-[13px]",slot:"sidebar-brand"}),m.jsx(jI,{collapsed:!1,onClick:n})]}),m.jsx("div",{className:"mt-2.5",children:m.jsx(wF,{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(LF,{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(EI,{})}),m.jsx("div",{className:"min-w-0 flex-1",children:m.jsx(zI,{onClick:()=>i(!0)})})]})]}),m.jsx($1,{open:r,onOpenChange:i})]})}function zI({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(Hz,{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 jI({collapsed:e,onClick:t}){const n=e?"展开侧边栏":"收起侧边栏",r=e?pK:fK;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 lpe=1500,cpe=300,FI=70,$I=35;function WF({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,FI)):(o.current="paused",f=setTimeout(v,lpe))}else g==="paused"?(o.current="deleting",f=setTimeout(v,$I)):g==="deleting"?l.current>0?(l.current-=1,r(h().slice(0,l.current)),f=setTimeout(v,$I)):(u.current+=1,o.current="waiting",f=setTimeout(v,cpe)):(o.current="typing",f=setTimeout(v,FI))};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 qF=["DEV Anywhere","/unlimited @anytime"];function upe({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(WF,{texts:qF,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 dpe=3e3,fpe=1e4,Tv=12,hpe=4,HI={webRelay:"浏览器 ↔ Relay 服务器",relayProxy:"Relay 服务器 ↔ 开发机",webProxy:"浏览器 ↔ 开发机"},ppe={webRelay:{state:"idle"},relayProxy:{state:"idle"},webProxy:{state:"idle"}};function M0(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 UI(e){switch(e){case"bad":return 4;case"unavailable":return 3;case"warn":return 2;case"measuring":return 1;default:return 0}}function YF(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 gpe(e){return e.state==="measuring"?"检测中":e.state==="unavailable"?e.error??"不可用":e.rttMs!==void 0?yp(e.rttMs):"等待检测"}function vpe(){const e=Mi("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 WI(e){Pr("local",Tn.latencyMonitorPosition,JSON.stringify(e))}function ype(){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 P0(e,t){const n=ype(),r=Tv,i=Tv,s=Math.max(r,n.width-t.width-Tv),o=Math.max(i,n.height-t.height-Tv);return{x:Math.min(s,Math.max(r,Math.round(e.x))),y:Math.min(o,Math.max(i,Math.round(e.y)))}}function bpe(){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(ppe),[o,l]=b.useState(()=>vpe()),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)=>UI(M.state)-UI(R.state))[0]??{state:"idle"}).state,[i]),g=YF(v);async function _(){if(u.current)return;const R=zt;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,V]=await Promise.allSettled([R.measureWebRelayLatency(),n?R.measureRelayProxyLatency():Promise.resolve({success:!1}),n?R.measureWebProxyLatency():Promise.resolve({success:!1})]);s({webRelay:M.status==="fulfilled"?M0(M.value):pd(M.reason instanceof Error?M.reason.message:"测速失败"),relayProxy:z.status==="fulfilled"?M0(z.value):pd(z.reason instanceof Error?z.reason.message:"测速失败"),webProxy:V.status==="fulfilled"?M0(V.value):pd(V.reason instanceof Error?V.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?fpe:dpe))};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=P0(o,{width:M.width,height:M.height});z.x===o.x&&z.y===o.y||(l(z),WI(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,V;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},(V=(z=R.currentTarget).setPointerCapture)==null||V.call(z,R.pointerId)}function T(R){const M=f.current;if(!M||M.pointerId!==R.pointerId)return;const z=R.clientX-M.startX,V=R.clientY-M.startY;if(!M.dragging&&Math.hypot(z,V)<hpe)return;M.dragging=!0,R.preventDefault();const W=P0({x:M.originX+z,y:M.originY+V},{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,V=R.clientY-M.startY,W=P0({x:M.originX+z,y:M.originY+V},{width:M.width,height:M.height});l(W),WI(W)}function A(R){var z,V;const M=f.current;!M||M.pointerId!==R.pointerId||(f.current=null,(V=(z=R.currentTarget).releasePointerCapture)==null||V.call(z,R.pointerId))}function P(R){h.current&&(h.current=!1,R.preventDefault(),R.stopPropagation())}return m.jsxs(Kb,{children:[m.jsx(Gb,{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:P,children:[m.jsx(Az,{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(oc,{className:"size-3 text-muted-foreground","aria-hidden":"true"})]})}),m.jsxs(Xb,{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(dt,{type:"button",variant:"ghost",size:"icon-xs","aria-label":"立即测速",onClick:()=>void _(),children:m.jsx(gm,{className:"size-3","aria-hidden":"true"})})]}),m.jsx("div",{className:"mt-3 space-y-2",children:Object.keys(HI).map(R=>m.jsx(_pe,{label:HI[R],measurement:i[R]},R))})]})]})}function _pe({label:e,measurement:t}){const n=YF(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:gpe(t)})]})]})}const VF="/__dev_anywhere_debug/browser-state-dumps",wpe=1500,xpe=10,I0=80,Hk=500,Spe=["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"],Epe=["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 qI(){if(typeof window>"u")return"off";const e=t6("debugDump");return e==="auto"?"auto":e!==null||Ipe("debugInput")?"manual":"off"}function Cpe(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:Ape(),document:{title:document.title,readyState:document.readyState,visibilityState:document.visibilityState,activeElement:YI(document.activeElement),selection:Npe(),focusedInputs:Array.from(document.querySelectorAll("input, textarea, select, [contenteditable]")).filter(i=>i===document.activeElement||i.matches(":focus")).map(i=>YI(i)).filter(i=>!!i),root:KF(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(()=>VI(n.__devAnywherePtyScrollTrace)),jsonScrollTraceTail:md(()=>VI(n.__devAnywhereJsonScrollTrace)),voicePilotDiagnostics:md(()=>{var i;return((i=n.__devAnywhereVoicePilotDiagnostics)==null?void 0:i.snapshot())??null})}};return window.__devAnywhereLastBrowserStateDump=r,r}async function kpe(e="manual"){const t=Cpe(e);return Tpe(t)}async function Tpe(e){const t=JSON.stringify(e,null,2),n=new Blob([t]).size;try{const r=await Rpe(t);return{status:"saved",path:r.path,bytes:r.bytes,endpoint:VF}}catch(r){const i=n6(r),s=Mpe(e.createdAt);return Ppe(s,t,"application/json")?{status:"downloaded",filename:s,bytes:n,endpointError:i}:{status:"failed",error:"无法保存或下载诊断包",endpointError:i}}}async function Rpe(e){const t=await fetch(VF,{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 KF(e,t,n){if(n.count>=wpe||t>xpe)return n.truncated=!0,{kind:"truncated"};if(n.count+=1,e.nodeType===Node.TEXT_NODE){const u=KI(e.textContent??"");return u?{kind:"text",text:i_(u,Hk)}:{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,I0))u.nodeType===Node.TEXT_NODE&&!KI(u.textContent??"")||r.push(KF(u,t+1,n));s.length>I0&&(i=s.length-I0,n.truncated=!0);const o={kind:"element",tag:e.tagName.toLowerCase(),path:e6(e),attrs:GF(e),rect:XF(e),scroll:ZF(e),style:JF(e)},l=QF(e);return l&&(o.value=l),r.length>0&&(o.children=r),i>0&&(o.omittedChildren=i),o}function YI(e){if(!(e instanceof HTMLElement))return null;const t=QF(e);return{path:e6(e),tag:e.tagName.toLowerCase(),id:e.id||null,className:e.className||null,attrs:GF(e),rect:XF(e),scroll:ZF(e),style:JF(e),...t?{value:t}:{}}}function Ape(){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 GF(e){const t={};for(const n of Spe){const r=e.getAttribute(n);r!==null&&(t[n]=i_(r,500))}return t}function XF(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 ZF(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 JF(e){const t=window.getComputedStyle(e),n={};for(const r of Epe)n[r]=t.getPropertyValue(r);return n}function QF(e){if(!(!(e instanceof HTMLInputElement)&&!(e instanceof HTMLTextAreaElement)))return{length:e.value.length,preview:i_(e.value,Hk),selectionStart:e.selectionStart,selectionEnd:e.selectionEnd}}function Npe(){var e;try{return i_(((e=window.getSelection())==null?void 0:e.toString())??"",Hk)}catch{return null}}function e6(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 Mpe(e){return`dev-anywhere-browser-state-${e.replace(/[:.]/g,"-")}.json`}function Ppe(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 Ipe(e){return t6(e)!==null}function t6(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 VI(e){return e?Ky(e.slice(-200)):null}function md(e){try{return Ky(e())}catch(t){return{error:n6(t)}}}function Ky(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(Ky);if(typeof e=="object"){const t={};for(const[n,r]of Object.entries(e))t[n]=Ky(r);return t}return String(e)}function KI(e){return e.replace(/\s+/g," ").trim()}function i_(e,t){return e.length>t?`${e.slice(0,t)}...`:e}function Cs(e){return Math.round(e*100)/100}function n6(e){return e instanceof Error?e.message:String(e)}const Ope=500,Lpe=1e3,Dpe=60;function Bpe(){const[e,t]=b.useState(()=>qI()),[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(qI());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 kpe(_);return o.current=w,s(w),(_==="manual"||w.status==="failed")&&zpe(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>=Dpe||(_(),f.current=window.setTimeout(()=>{f.current=null;const P=Date.now(),R=Lpe-(P-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}`)},Ope))};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,P;_(),S.forEach(R=>window.removeEventListener(R,x,!0)),(A=window.visualViewport)==null||A.removeEventListener("resize",x),(P=window.visualViewport)==null||P.removeEventListener("scroll",x)}},[h,e]),e==="off")return null;const v=e==="auto"?"自动诊断中":"保存诊断",g=jpe(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(dt,{type:"button",size:"sm",variant:e==="auto"?"secondary":"outline",className:"h-9 rounded-md px-3 text-xs shadow-lg",onClick:()=>void h("manual"),disabled:n,"data-slot":"browser-state-dump",children:[n?m.jsx(Xr,{className:"size-3.5 animate-spin","aria-hidden":"true"}):m.jsx(zV,{className:"size-3.5","aria-hidden":"true"}),m.jsx("span",{children:v})]})]})}function zpe(e){if(e.status==="saved"){$e.success(`诊断已保存: ${e.path}`);return}if(e.status==="downloaded"){$e.info(`诊断已下载: ${e.filename}`);return}$e.error(e.endpointError?`${e.error}: ${e.endpointError}`:e.error)}function jpe(e){return e?e.status==="saved"?`已保存 ${e.path}`:e.status==="downloaded"?`已下载 ${e.filename}`:`失败 ${e.endpointError??e.error}`:null}function Fpe({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(Xr,{className:"size-5 animate-spin","aria-hidden":"true"}):null,m.jsx("p",{className:"text-sm",children:t}),n?m.jsx(dt,{type:"button",size:"sm",onClick:()=>window.location.reload(),children:n}):null]})}function $pe(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 Uk(e){const{windowKey:t,storageKey:n,maxEntries:r=5e3,dedupeKey:i}=e,s=new Map,o=()=>typeof window>"u"?!1:$pe(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 er(e){return Math.round(e*10)/10}function Dl(e){return e.length===0?"":`${er(Math.min(...e))}..${er(Math.max(...e))}`}function Bd(e){return[...new Set(e.filter(t=>t!==void 0).map(er))]}function r6(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 Hpe="dev_anywhere_pty_input_latency_trace",GI=80,Upe=1e4,Wpe=new TextDecoder;let qpe=0;const df=new Map,Tu=Uk({windowKey:"__devAnywherePtyInputLatencyTrace",storageKey:Hpe,dedupeKey:e=>e.event.startsWith("input")?null:`${e.event}|${e.sessionId}|${e.outputSeq??""}|${e.pendingInputs??""}`});function Ype(){typeof window>"u"||(window.__devAnywherePtyInputLatencyReport=Xpe)}function Vpe(e,t){if(!Tu.isEnabled())return null;const n=`pty-in-${Date.now().toString(36)}-${++qpe}`,r=performance.now(),i={inputId:n,sessionId:e,data:t,kind:Qpe(t),dataLength:t.length,startedAt:r,sentAt:null,firstOutputAt:null,echoMatchedAt:null,xtermWriteAt:null,paintAt:null},s=df.get(e)??[];return s.push(i),qk(s,r),df.set(e,s),Mm({t:r,event:"input:start",sessionId:e,inputId:n,inputKind:i.kind,dataLength:i.dataLength,pendingInputs:s.length}),{inputId:n,sessionId:e}}function XI(e,t){if(!e||!Tu.isEnabled())return;const n=performance.now(),r=Zpe(e.sessionId,e.inputId);r&&(r.sentAt=n),Mm({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 Kpe(e,t,n){if(!Tu.isEnabled())return;const r=performance.now(),i=Wk(e,r),s=nme(t),o=[],l=[];for(const u of i)u.firstOutputAt===null&&(u.firstOutputAt=r,o.push(u.inputId)),u.echoMatchedAt===null&&tme(u)&&s.includes(u.data)&&(u.echoMatchedAt=r,l.push(u.inputId));Mm({t:r,event:"output:received",sessionId:e,outputSeq:n,bytes:t.byteLength,pendingInputs:i.length,deltaFromInputMs:Yk(i,r),details:rme([o.length>0?`first=${o.length}`:"",l.length>0?`echo=${l.length}`:""])})}function Gpe(e,t,n=1){if(!Tu.isEnabled())return;const r=performance.now(),i=Wk(e,r),s=[];for(const o of i)o.xtermWriteAt===null&&(o.xtermWriteAt=r,s.push(o.inputId));Mm({t:r,event:"output:xterm-write",sessionId:e,bytes:t,chunkCount:n,pendingInputs:i.length,deltaFromInputMs:Yk(i,r),details:s.length>0?`firstWrite=${s.length}`:""}),typeof requestAnimationFrame=="function"&&s.length>0&&requestAnimationFrame(()=>Jpe(e,s))}function Xpe(){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?"":er(s.sentAt-s.startedAt),s.firstOutputAt===null?"":er(s.firstOutputAt-s.startedAt),s.echoMatchedAt===null?"":er(s.echoMatchedAt-s.startedAt),s.xtermWriteAt===null?"":er(s.xtermWriteAt-s.startedAt),s.paintAt===null?"":er(s.paintAt-s.startedAt)].join(" ")),i=t.map(s=>[er(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?"":er(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},Yae="DialogDescriptionWarning",Vae=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${f3(Yae).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},hk=J5,Kae=e3,pk=n3,mk=r3,gk=i3,h3=o3,p3=l3,Ib=u3;function Gae(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 Xae(e){const[t,n]=b.useState(void 0);return ns(()=>{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 Zae=["top","right","bottom","left"],tc=Math.min,Ws=Math.max,$y=Math.round,xv=Math.floor,aa=e=>({x:e,y:e}),Jae={left:"right",right:"left",bottom:"top",top:"bottom"};function w1(e,t,n){return Ws(e,tc(t,n))}function qa(e,t){return typeof e=="function"?e(t):e}function Ya(e){return e.split("-")[0]}function xf(e){return e.split("-")[1]}function vk(e){return e==="x"?"y":"x"}function yk(e){return e==="y"?"height":"width"}function ia(e){const t=e[0];return t==="t"||t==="b"?"y":"x"}function bk(e){return vk(ia(e))}function Qae(e,t,n){n===void 0&&(n=!1);const r=xf(e),i=bk(e),s=yk(i);let o=i==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(o=Hy(o)),[o,Hy(o)]}function ele(e){const t=Hy(e);return[x1(e),t,x1(t)]}function x1(e){return e.includes("start")?e.replace("start","end"):e.replace("end","start")}const Q2=["left","right"],eI=["right","left"],tle=["top","bottom"],nle=["bottom","top"];function rle(e,t,n){switch(e){case"top":case"bottom":return n?t?eI:Q2:t?Q2:eI;case"left":case"right":return t?tle:nle;default:return[]}}function ile(e,t,n,r){const i=xf(e);let s=rle(Ya(e),n==="start",r);return i&&(s=s.map(o=>o+"-"+i),t&&(s=s.concat(s.map(x1)))),s}function Hy(e){const t=Ya(e);return Jae[t]+e.slice(t.length)}function sle(e){return{top:0,right:0,bottom:0,left:0,...e}}function m3(e){return typeof e!="number"?sle(e):{top:e,right:e,bottom:e,left:e}}function Uy(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 tI(e,t,n){let{reference:r,floating:i}=e;const s=ia(t),o=bk(t),l=yk(o),u=Ya(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 ole(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}=qa(t,e),_=m3(g),S=l[v?h==="floating"?"reference":"floating":h],x=Uy(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},P=Uy(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:l,rect:T,offsetParent:k,strategy:u}):T);return{top:(x.top-P.top+_.top)/A.y,bottom:(P.bottom-x.bottom+_.bottom)/A.y,left:(x.left-P.left+_.left)/A.x,right:(P.right-x.right+_.right)/A.x}}const ale=50,lle=async(e,t,n)=>{const{placement:r="bottom",strategy:i="absolute",middleware:s=[],platform:o}=n,l=o.detectOverflow?o:{...o,detectOverflow:ole},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}=tI(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:P,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],...P},R&&g<ale&&(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}=tI(d,v,u)),w=-1)}return{x:f,y:h,placement:v,strategy:i,middlewareData:_}},cle=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}=qa(e,t)||{};if(d==null)return{};const h=m3(f),v={x:n,y:r},g=bk(i),_=yk(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[_],P=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-P/2,V=M/2-w[_]/2-1,W=tc(h[x],V),G=tc(h[T],V),O=W,N=M-w[_]-G,L=M/2-w[_]/2+z,D=w1(O,L,N),I=!u.arrow&&xf(i)!=null&&L!==D&&s.reference[_]/2-(L<O?W:G)-w[_]/2<0,B=I?L<O?L-O:L-N:0;return{[g]:v[g]+B,data:{[g]:D,centerOffset:L-D-B,...I&&{alignmentOffset:B}},reset:I}}}),ule=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}=qa(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const x=Ya(i),T=ia(l),k=Ya(l)===l,A=await(u.isRTL==null?void 0:u.isRTL(d.floating)),P=v||(k||!w?[Hy(l)]:ele(l)),R=_!=="none";!v&&R&&P.push(...ile(l,w,_,A));const M=[l,...P],z=await u.detectOverflow(t,S),V=[];let W=((r=s.flip)==null?void 0:r.overflows)||[];if(f&&V.push(z[x]),h){const L=Qae(i,o,A);V.push(z[L[0]],z[L[1]])}if(W=[...W,{placement:i,overflows:V}],!V.every(L=>L<=0)){var G,O;const L=(((G=s.flip)==null?void 0:G.index)||0)+1,D=M[L];if(D&&(!(h==="alignment"?T!==ia(D):!1)||W.every(F=>ia(F.placement)===T?F.overflows[0]>0:!0)))return{data:{index:L,overflows:W},reset:{placement:D}};let I=(O=W.filter(B=>B.overflows[0]<=0).sort((B,F)=>B.overflows[1]-F.overflows[1])[0])==null?void 0:O.placement;if(!I)switch(g){case"bestFit":{var N;const B=(N=W.filter(F=>{if(R){const U=ia(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&&(I=B);break}case"initialPlacement":I=l;break}if(i!==I)return{reset:{placement:I}}}return{}}}};function nI(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function rI(e){return Zae.some(t=>e[t]>=0)}const dle=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n,platform:r}=t,{strategy:i="referenceHidden",...s}=qa(e,t);switch(i){case"referenceHidden":{const o=await r.detectOverflow(t,{...s,elementContext:"reference"}),l=nI(o,n.reference);return{data:{referenceHiddenOffsets:l,referenceHidden:rI(l)}}}case"escaped":{const o=await r.detectOverflow(t,{...s,altBoundary:!0}),l=nI(o,n.floating);return{data:{escapedOffsets:l,escaped:rI(l)}}}default:return{}}}}},g3=new Set(["left","top"]);async function fle(e,t){const{placement:n,platform:r,elements:i}=e,s=await(r.isRTL==null?void 0:r.isRTL(i.floating)),o=Ya(n),l=xf(n),u=ia(n)==="y",d=g3.has(o)?-1:1,f=s&&u?-1:1,h=qa(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 hle=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 fle(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}}}}},ple=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}=qa(e,t),f={x:n,y:r},h=await s.detectOverflow(t,d),v=ia(Ya(i)),g=vk(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];_=w1(k,_,A)}if(l){const x=v==="y"?"top":"left",T=v==="y"?"bottom":"right",k=w+h[x],A=w-h[T];w=w1(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}}}}}},mle=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}=qa(e,t),f={x:n,y:r},h=ia(i),v=vk(h);let g=f[v],_=f[h];const w=qa(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,P=s.reference[v]+s.reference[k]-S.mainAxis;g<A?g=A:g>P&&(g=P)}if(d){var x,T;const k=v==="y"?"width":"height",A=g3.has(Ya(i)),P=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);_<P?_=P:_>R&&(_=R)}return{[v]:g,[h]:_}}}},gle=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}=qa(e,t),f=await o.detectOverflow(t,d),h=Ya(i),v=xf(i),g=ia(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=tc(w-f[S],T),P=tc(_-f[x],k),R=!t.middlewareData.shift;let M=A,z=P;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 V=await o.getDimensions(l.floating);return _!==V.width||w!==V.height?{reset:{rects:!0}}:{}}}};function Ob(){return typeof window<"u"}function Sf(e){return v3(e)?(e.nodeName||"").toLowerCase():"#document"}function Vs(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function pa(e){var t;return(t=(v3(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function v3(e){return Ob()?e instanceof Node||e instanceof Vs(e).Node:!1}function Lo(e){return Ob()?e instanceof Element||e instanceof Vs(e).Element:!1}function Xa(e){return Ob()?e instanceof HTMLElement||e instanceof Vs(e).HTMLElement:!1}function iI(e){return!Ob()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Vs(e).ShadowRoot}function wm(e){const{overflow:t,overflowX:n,overflowY:r,display:i}=Do(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&i!=="inline"&&i!=="contents"}function vle(e){return/^(table|td|th)$/.test(Sf(e))}function Lb(e){try{if(e.matches(":popover-open"))return!0}catch{}try{return e.matches(":modal")}catch{return!1}}const yle=/transform|translate|scale|rotate|perspective|filter/,ble=/paint|layout|strict|content/,Hc=e=>!!e&&e!=="none";let _0;function _k(e){const t=Lo(e)?Do(e):e;return Hc(t.transform)||Hc(t.translate)||Hc(t.scale)||Hc(t.rotate)||Hc(t.perspective)||!wk()&&(Hc(t.backdropFilter)||Hc(t.filter))||yle.test(t.willChange||"")||ble.test(t.contain||"")}function _le(e){let t=nc(e);for(;Xa(t)&&!lf(t);){if(_k(t))return t;if(Lb(t))return null;t=nc(t)}return null}function wk(){return _0==null&&(_0=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),_0}function lf(e){return/^(html|body|#document)$/.test(Sf(e))}function Do(e){return Vs(e).getComputedStyle(e)}function Db(e){return Lo(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function nc(e){if(Sf(e)==="html")return e;const t=e.assignedSlot||e.parentNode||iI(e)&&e.host||pa(e);return iI(t)?t.host:t}function y3(e){const t=nc(e);return lf(t)?e.ownerDocument?e.ownerDocument.body:e.body:Xa(t)&&wm(t)?t:y3(t)}function Kp(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const i=y3(e),s=i===((r=e.ownerDocument)==null?void 0:r.body),o=Vs(i);if(s){const l=S1(o);return t.concat(o,o.visualViewport||[],wm(i)?i:[],l&&n?Kp(l):[])}else return t.concat(i,Kp(i,[],n))}function S1(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function b3(e){const t=Do(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const i=Xa(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 xk(e){return Lo(e)?e:e.contextElement}function Gd(e){const t=xk(e);if(!Xa(t))return aa(1);const n=t.getBoundingClientRect(),{width:r,height:i,$:s}=b3(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 wle=aa(0);function _3(e){const t=Vs(e);return!wk()||!t.visualViewport?wle:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function xle(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=xk(e);let o=aa(1);t&&(r?Lo(r)&&(o=Gd(r)):o=Gd(e));const l=xle(s,n,r)?_3(s):aa(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&&Lo(r)?Vs(r):r;let _=v,w=S1(_);for(;w&&r&&g!==_;){const S=Gd(w),x=w.getBoundingClientRect(),T=Do(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=S1(_)}}return Uy({width:f,height:h,x:u,y:d})}function Bb(e,t){const n=Db(e).scrollLeft;return t?t.left+n:fu(pa(e)).left+n}function w3(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-Bb(e,n),i=n.top+t.scrollTop;return{x:r,y:i}}function Sle(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e;const s=i==="fixed",o=pa(r),l=t?Lb(t.floating):!1;if(r===o||l&&s)return n;let u={scrollLeft:0,scrollTop:0},d=aa(1);const f=aa(0),h=Xa(r);if((h||!h&&!s)&&((Sf(r)!=="body"||wm(o))&&(u=Db(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?w3(o,u):aa(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 Ele(e){return Array.from(e.getClientRects())}function Cle(e){const t=pa(e),n=Db(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+Bb(e);const l=-n.scrollTop;return Do(r).direction==="rtl"&&(o+=Ws(t.clientWidth,r.clientWidth)-i),{width:i,height:s,x:o,y:l}}const sI=25;function kle(e,t){const n=Vs(e),r=pa(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=wk();(!f||f&&t==="fixed")&&(l=i.offsetLeft,u=i.offsetTop)}const d=Bb(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);_<=sI&&(s-=_)}else d<=sI&&(s+=d);return{width:s,height:o,x:l,y:u}}function Tle(e,t){const n=fu(e,!0,t==="fixed"),r=n.top+e.clientTop,i=n.left+e.clientLeft,s=Xa(e)?Gd(e):aa(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 oI(e,t,n){let r;if(t==="viewport")r=kle(e,n);else if(t==="document")r=Cle(pa(e));else if(Lo(t))r=Tle(t,n);else{const i=_3(e);r={x:t.x-i.x,y:t.y-i.y,width:t.width,height:t.height}}return Uy(r)}function x3(e,t){const n=nc(e);return n===t||!Lo(n)||lf(n)?!1:Do(n).position==="fixed"||x3(n,t)}function Rle(e,t){const n=t.get(e);if(n)return n;let r=Kp(e,[],!1).filter(l=>Lo(l)&&Sf(l)!=="body"),i=null;const s=Do(e).position==="fixed";let o=s?nc(e):e;for(;Lo(o)&&!lf(o);){const l=Do(o),u=_k(o);!u&&l.position==="fixed"&&(i=null),(s?!u&&!i:!u&&l.position==="static"&&!!i&&(i.position==="absolute"||i.position==="fixed")||wm(o)&&!u&&x3(e,o))?r=r.filter(f=>f!==o):i=l,o=nc(o)}return t.set(e,r),r}function Ale(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e;const o=[...n==="clippingAncestors"?Lb(t)?[]:Rle(t,this._c):[].concat(n),r],l=oI(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=oI(t,o[v],i);u=Ws(g.top,u),d=tc(g.right,d),f=tc(g.bottom,f),h=Ws(g.left,h)}return{width:d-h,height:f-u,x:h,y:u}}function Nle(e){const{width:t,height:n}=b3(e);return{width:t,height:n}}function Mle(e,t,n){const r=Xa(t),i=pa(t),s=n==="fixed",o=fu(e,!0,s,t);let l={scrollLeft:0,scrollTop:0};const u=aa(0);function d(){u.x=Bb(i)}if(r||!r&&!s)if((Sf(t)!=="body"||wm(i))&&(l=Db(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?w3(i,l):aa(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 w0(e){return Do(e).position==="static"}function aI(e,t){if(!Xa(e)||Do(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return pa(e)===n&&(n=n.ownerDocument.body),n}function S3(e,t){const n=Vs(e);if(Lb(e))return n;if(!Xa(e)){let i=nc(e);for(;i&&!lf(i);){if(Lo(i)&&!w0(i))return i;i=nc(i)}return n}let r=aI(e,t);for(;r&&vle(r)&&w0(r);)r=aI(r,t);return r&&lf(r)&&w0(r)&&!_k(r)?n:r||_le(e)||n}const Ple=async function(e){const t=this.getOffsetParent||S3,n=this.getDimensions,r=await n(e.floating);return{reference:Mle(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function Ile(e){return Do(e).direction==="rtl"}const Ole={convertOffsetParentRelativeRectToViewportRelativeRect:Sle,getDocumentElement:pa,getClippingRect:Ale,getOffsetParent:S3,getElementRects:Ple,getClientRects:Ele,getDimensions:Nle,getScale:Gd,isElement:Lo,isRTL:Ile};function E3(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function Lle(e,t){let n=null,r;const i=pa(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 _=xv(h),w=xv(i.clientWidth-(f+v)),S=xv(i.clientHeight-(h+g)),x=xv(f),k={rootMargin:-_+"px "+-w+"px "+-S+"px "+-x+"px",threshold:Ws(0,tc(1,u))||1};let A=!0;function P(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&&!E3(d,e.getBoundingClientRect())&&o(),A=!1}try{n=new IntersectionObserver(P,{...k,root:i.ownerDocument})}catch{n=new IntersectionObserver(P,k)}n.observe(e)}return o(!0),s}function Dle(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=xk(e),f=i||s?[...d?Kp(d):[],...t?Kp(t):[]]:[];f.forEach(x=>{i&&x.addEventListener("scroll",n,{passive:!0}),s&&x.addEventListener("resize",n)});const h=d&&l?Lle(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&&!E3(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 Ble=hle,zle=ple,jle=ule,Fle=gle,$le=dle,lI=cle,Hle=mle,Ule=(e,t,n)=>{const r=new Map,i={platform:Ole,...n},s={...i.platform,_c:r};return lle(e,t,{...i,platform:s})};var Wle=typeof document<"u",qle=function(){},uy=Wle?b.useLayoutEffect:qle;function Wy(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(!Wy(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)&&!Wy(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function C3(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function cI(e,t){const n=C3(e);return Math.round(t*n)/n}function x0(e){const t=b.useRef(e);return uy(()=>{t.current=e}),t}function Yle(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);Wy(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||_,P=o||S,R=b.useRef(null),M=b.useRef(null),z=b.useRef(f),V=u!=null,W=x0(u),G=x0(i),O=x0(d),N=b.useCallback(()=>{if(!R.current||!M.current)return;const F={placement:t,strategy:n,middleware:v};G.current&&(F.platform=G.current),Ule(R.current,M.current,F).then(U=>{const j={...U,isPositioned:O.current!==!1};L.current&&!Wy(z.current,j)&&(z.current=j,Eu.flushSync(()=>{h(j)}))})},[v,t,n,G,O]);uy(()=>{d===!1&&z.current.isPositioned&&(z.current.isPositioned=!1,h(F=>({...F,isPositioned:!1})))},[d]);const L=b.useRef(!1);uy(()=>(L.current=!0,()=>{L.current=!1}),[]),uy(()=>{if(A&&(R.current=A),P&&(M.current=P),A&&P){if(W.current)return W.current(A,P,N);N()}},[A,P,N,W,V]);const D=b.useMemo(()=>({reference:R,floating:M,setReference:T,setFloating:k}),[T,k]),I=b.useMemo(()=>({reference:A,floating:P}),[A,P]),B=b.useMemo(()=>{const F={position:n,left:0,top:0};if(!I.floating)return F;const U=cI(I.floating,f.x),j=cI(I.floating,f.y);return l?{...F,transform:"translate("+U+"px, "+j+"px)",...C3(I.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:U,top:j}},[n,l,I.floating,f.x,f.y]);return b.useMemo(()=>({...f,update:N,refs:D,elements:I,floatingStyles:B}),[f,N,D,I,B])}const Vle=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?lI({element:r.current,padding:i}).fn(n):{}:r?lI({element:r,padding:i}).fn(n):{}}}},Kle=(e,t)=>{const n=Ble(e);return{name:n.name,fn:n.fn,options:[e,t]}},Gle=(e,t)=>{const n=zle(e);return{name:n.name,fn:n.fn,options:[e,t]}},Xle=(e,t)=>({fn:Hle(e).fn,options:[e,t]}),Zle=(e,t)=>{const n=jle(e);return{name:n.name,fn:n.fn,options:[e,t]}},Jle=(e,t)=>{const n=Fle(e);return{name:n.name,fn:n.fn,options:[e,t]}},Qle=(e,t)=>{const n=$le(e);return{name:n.name,fn:n.fn,options:[e,t]}},ece=(e,t)=>{const n=Vle(e);return{name:n.name,fn:n.fn,options:[e,t]}};var tce="Arrow",k3=b.forwardRef((e,t)=>{const{children:n,width:r=10,height:i=5,...s}=e;return m.jsx(En.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"})})});k3.displayName=tce;var nce=k3,Sk="Popper",[T3,dc]=Ga(Sk),[rce,R3]=T3(Sk),A3=e=>{const{__scopePopper:t,children:n}=e,[r,i]=b.useState(null);return m.jsx(rce,{scope:t,anchor:r,onAnchorChange:i,children:n})};A3.displayName=Sk;var N3="PopperAnchor",M3=b.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...i}=e,s=R3(N3,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(En.div,{...i,ref:l})});M3.displayName=N3;var Ek="PopperContent",[ice,sce]=T3(Ek),P3=b.forwardRef((e,t)=>{var Z,oe,Q,fe,ge,Ce;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=R3(Ek,n),[x,T]=b.useState(null),k=dr(t,De=>T(De)),[A,P]=b.useState(null),R=Xae(A),M=(R==null?void 0:R.width)??0,z=(R==null?void 0:R.height)??0,V=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(ace),altBoundary:O},{refs:L,floatingStyles:D,placement:I,isPositioned:B,middlewareData:F}=Yle({strategy:"fixed",placement:V,whileElementsMounted:(...De)=>Dle(...De,{animationFrame:g==="always"}),elements:{reference:S.anchor},middleware:[Kle({mainAxis:i+z,alignmentAxis:o}),u&&Gle({mainAxis:!0,crossAxis:!1,limiter:h==="partial"?Xle():void 0,...N}),u&&Zle({...N}),Jle({...N,apply:({elements:De,rects:ot,availableWidth:Dt,availableHeight:et})=>{const{width:ut,height:Ne}=ot.reference,Ue=De.floating.style;Ue.setProperty("--radix-popper-available-width",`${Dt}px`),Ue.setProperty("--radix-popper-available-height",`${et}px`),Ue.setProperty("--radix-popper-anchor-width",`${ut}px`),Ue.setProperty("--radix-popper-anchor-height",`${Ne}px`)}}),A&&ece({element:A,padding:l}),lce({arrowWidth:M,arrowHeight:z}),v&&Qle({strategy:"referenceHidden",...N})]}),[U,j]=L3(I),Y=Oo(_);ns(()=>{B&&(Y==null||Y())},[B,Y]);const X=(Z=F.arrow)==null?void 0:Z.x,$=(oe=F.arrow)==null?void 0:oe.y,ee=((Q=F.arrow)==null?void 0:Q.centerOffset)!==0,[re,te]=b.useState();return ns(()=>{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:re,"--radix-popper-transform-origin":[(fe=F.transformOrigin)==null?void 0:fe.x,(ge=F.transformOrigin)==null?void 0:ge.y].join(" "),...((Ce=F.hide)==null?void 0:Ce.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:m.jsx(ice,{scope:n,placedSide:U,onArrowChange:P,arrowX:X,arrowY:$,shouldHideArrow:ee,children:m.jsx(En.div,{"data-side":U,"data-align":j,...w,ref:k,style:{...w.style,animation:B?void 0:"none"}})})})});P3.displayName=Ek;var I3="PopperArrow",oce={top:"bottom",right:"left",bottom:"top",left:"right"},O3=b.forwardRef(function(t,n){const{__scopePopper:r,...i}=t,s=sce(I3,r),o=oce[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(nce,{...i,ref:n,style:{...i.style,display:"block"}})})});O3.displayName=I3;function ace(e){return e!==null}var lce=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]=L3(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 L3(e){const[t,n="center"]=e.split("-");return[t,n]}var xm=A3,Sm=M3,zb=P3,jb=O3,S0="rovingFocusGroup.onEntryFocus",cce={bubbles:!1,cancelable:!0},Em="RovingFocusGroup",[E1,D3,uce]=lk(Em),[dce,B3]=Ga(Em,[uce]),[fce,hce]=dce(Em),z3=b.forwardRef((e,t)=>m.jsx(E1.Provider,{scope:e.__scopeRovingFocusGroup,children:m.jsx(E1.Slot,{scope:e.__scopeRovingFocusGroup,children:m.jsx(pce,{...e,ref:t})})}));z3.displayName=Em;var pce=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),_=ck(s),[w,S]=ec({prop:o,defaultProp:l??null,onChange:u,caller:Em}),[x,T]=b.useState(!1),k=Oo(d),A=D3(n),P=b.useRef(!1),[R,M]=b.useState(0);return b.useEffect(()=>{const z=v.current;if(z)return z.addEventListener(S0,k),()=>z.removeEventListener(S0,k)},[k]),m.jsx(fce,{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(En.div,{tabIndex:x||R===0?-1:0,"data-orientation":r,...h,ref:g,style:{outline:"none",...e.style},onMouseDown:Yt(e.onMouseDown,()=>{P.current=!0}),onFocus:Yt(e.onFocus,z=>{const V=!P.current;if(z.target===z.currentTarget&&V&&!x){const W=new CustomEvent(S0,cce);if(z.currentTarget.dispatchEvent(W),!W.defaultPrevented){const G=A().filter(I=>I.focusable),O=G.find(I=>I.active),N=G.find(I=>I.id===w),D=[O,N,...G].filter(Boolean).map(I=>I.ref.current);$3(D,f)}}P.current=!1}),onBlur:Yt(e.onBlur,()=>T(!1))})})}),j3="RovingFocusGroupItem",F3=b.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:i=!1,tabStopId:s,children:o,...l}=e,u=_i(),d=s||u,f=hce(j3,n),h=f.currentTabStopId===d,v=D3(n),{onFocusableItemAdd:g,onFocusableItemRemove:_,currentTabStopId:w}=f;return b.useEffect(()=>{if(r)return g(),()=>_()},[r,g,_]),m.jsx(E1.ItemSlot,{scope:n,id:d,focusable:r,active:i,children:m.jsx(En.span,{tabIndex:h?0:-1,"data-orientation":f.orientation,...l,ref:t,onMouseDown:Yt(e.onMouseDown,S=>{r?f.onItemFocus(d):S.preventDefault()}),onFocus:Yt(e.onFocus,()=>f.onItemFocus(d)),onKeyDown:Yt(e.onKeyDown,S=>{if(S.key==="Tab"&&S.shiftKey){f.onItemShiftTab();return}if(S.target!==S.currentTarget)return;const x=vce(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?yce(k,A+1):k.slice(A+1)}setTimeout(()=>$3(k))}}),children:typeof o=="function"?o({isCurrentTabStop:h,hasTabStop:w!=null}):o})})});F3.displayName=j3;var mce={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function gce(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function vce(e,t,n){const r=gce(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return mce[r]}function $3(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function yce(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var bce=z3,_ce=F3,C1=["Enter"," "],wce=["ArrowDown","PageUp","Home"],H3=["ArrowUp","PageDown","End"],xce=[...wce,...H3],Sce={ltr:[...C1,"ArrowRight"],rtl:[...C1,"ArrowLeft"]},Ece={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Cm="Menu",[Gp,Cce,kce]=lk(Cm),[Cu,U3]=Ga(Cm,[kce,dc,B3]),km=dc(),W3=B3(),[q3,fc]=Cu(Cm),[Tce,Tm]=Cu(Cm),Y3=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:i,onOpenChange:s,modal:o=!0}=e,l=km(t),[u,d]=b.useState(null),f=b.useRef(!1),h=Oo(s),v=ck(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(xm,{...l,children:m.jsx(q3,{scope:t,open:n,onOpenChange:h,content:u,onContentChange:d,children:m.jsx(Tce,{scope:t,onClose:b.useCallback(()=>h(!1),[h]),isUsingKeyboardRef:f,dir:v,modal:o,children:r})})})};Y3.displayName=Cm;var Rce="MenuAnchor",Ck=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=km(n);return m.jsx(Sm,{...i,...r,ref:t})});Ck.displayName=Rce;var kk="MenuPortal",[Ace,V3]=Cu(kk,{forceMount:void 0}),K3=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:i}=e,s=fc(kk,t);return m.jsx(Ace,{scope:t,forceMount:n,children:m.jsx(xo,{present:n||s.open,children:m.jsx(wf,{asChild:!0,container:i,children:r})})})};K3.displayName=kk;var go="MenuContent",[Nce,Tk]=Cu(go),G3=b.forwardRef((e,t)=>{const n=V3(go,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=fc(go,e.__scopeMenu),o=Tm(go,e.__scopeMenu);return m.jsx(Gp.Provider,{scope:e.__scopeMenu,children:m.jsx(xo,{present:r||s.open,children:m.jsx(Gp.Slot,{scope:e.__scopeMenu,children:o.modal?m.jsx(Mce,{...i,ref:t}):m.jsx(Pce,{...i,ref:t})})})})}),Mce=b.forwardRef((e,t)=>{const n=fc(go,e.__scopeMenu),r=b.useRef(null),i=dr(t,r);return b.useEffect(()=>{const s=r.current;if(s)return Mb(s)},[]),m.jsx(Rk,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:Yt(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),Pce=b.forwardRef((e,t)=>{const n=fc(go,e.__scopeMenu);return m.jsx(Rk,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),Ice=Ql("MenuContent.ScrollLock"),Rk=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=fc(go,n),x=Tm(go,n),T=km(n),k=W3(n),A=Cce(n),[P,R]=b.useState(null),M=b.useRef(null),z=dr(t,M,S.onContentChange),V=b.useRef(0),W=b.useRef(""),G=b.useRef(0),O=b.useRef(null),N=b.useRef("right"),L=b.useRef(0),D=_?_m:b.Fragment,I=_?{as:Ice,allowPinchZoom:!0}:void 0,B=U=>{var Z,oe;const j=W.current+U,Y=A().filter(Q=>!Q.disabled),X=document.activeElement,$=(Z=Y.find(Q=>Q.ref.current===X))==null?void 0:Z.textValue,ee=Y.map(Q=>Q.textValue),re=qce(ee,j,$),te=(oe=Y.find(Q=>Q.textValue===re))==null?void 0:oe.ref.current;(function Q(fe){W.current=fe,window.clearTimeout(V.current),fe!==""&&(V.current=window.setTimeout(()=>Q(""),1e3))})(j),te&&setTimeout(()=>te.focus())};b.useEffect(()=>()=>window.clearTimeout(V.current),[]),Ab();const F=b.useCallback(U=>{var Y,X;return N.current===((Y=O.current)==null?void 0:Y.side)&&Vce(U,(X=O.current)==null?void 0:X.area)},[]);return m.jsx(Nce,{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,{...I,children:m.jsx(bm,{asChild:!0,trapped:i,onMountAutoFocus:Yt(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(bce,{asChild:!0,...k,dir:x.dir,orientation:"vertical",loop:r,currentTabStopId:P,onCurrentTabStopIdChange:R,onEntryFocus:Yt(u,U=>{x.isUsingKeyboardRef.current||U.preventDefault()}),preventScrollOnEntryFocus:!0,children:m.jsx(zb,{role:"menu","aria-orientation":"vertical","data-state":f4(S.open),"data-radix-menu-content":"",dir:x.dir,...T,...w,ref:z,style:{outline:"none",...w.style},onKeyDown:Yt(w.onKeyDown,U=>{const Y=U.target.closest("[data-radix-menu-content]")===U.currentTarget,X=U.ctrlKey||U.altKey||U.metaKey,$=U.key.length===1;Y&&(U.key==="Tab"&&U.preventDefault(),!X&&$&&B(U.key));const ee=M.current;if(U.target!==ee||!xce.includes(U.key))return;U.preventDefault();const te=A().filter(Z=>!Z.disabled).map(Z=>Z.ref.current);H3.includes(U.key)&&te.reverse(),Uce(te)}),onBlur:Yt(e.onBlur,U=>{U.currentTarget.contains(U.target)||(window.clearTimeout(V.current),W.current="")}),onPointerMove:Yt(e.onPointerMove,Xp(U=>{const j=U.target,Y=L.current!==U.clientX;if(U.currentTarget.contains(j)&&Y){const X=U.clientX>L.current?"right":"left";N.current=X,L.current=U.clientX}}))})})})})})})});G3.displayName=go;var Oce="MenuGroup",Ak=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return m.jsx(En.div,{role:"group",...r,ref:t})});Ak.displayName=Oce;var Lce="MenuLabel",X3=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return m.jsx(En.div,{...r,ref:t})});X3.displayName=Lce;var qy="MenuItem",uI="menu.itemSelect",Fb=b.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...i}=e,s=b.useRef(null),o=Tm(qy,e.__scopeMenu),l=Tk(qy,e.__scopeMenu),u=dr(t,s),d=b.useRef(!1),f=()=>{const h=s.current;if(!n&&h){const v=new CustomEvent(uI,{bubbles:!0,cancelable:!0});h.addEventListener(uI,g=>r==null?void 0:r(g),{once:!0}),D5(h,v),v.defaultPrevented?d.current=!1:o.onClose()}};return m.jsx(Z3,{...i,ref:u,disabled:n,onClick:Yt(e.onClick,f),onPointerDown:h=>{var v;(v=e.onPointerDown)==null||v.call(e,h),d.current=!0},onPointerUp:Yt(e.onPointerUp,h=>{var v;d.current||(v=h.currentTarget)==null||v.click()}),onKeyDown:Yt(e.onKeyDown,h=>{const v=l.searchRef.current!=="";n||v&&h.key===" "||C1.includes(h.key)&&(h.currentTarget.click(),h.preventDefault())})})});Fb.displayName=qy;var Z3=b.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:i,...s}=e,o=Tk(qy,n),l=W3(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(Gp.ItemSlot,{scope:n,disabled:r,textValue:i??v,children:m.jsx(_ce,{asChild:!0,...l,focusable:!r,children:m.jsx(En.div,{role:"menuitem","data-highlighted":f?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:d,onPointerMove:Yt(e.onPointerMove,Xp(_=>{r?o.onItemLeave(_):(o.onItemEnter(_),_.defaultPrevented||_.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:Yt(e.onPointerLeave,Xp(_=>o.onItemLeave(_))),onFocus:Yt(e.onFocus,()=>h(!0)),onBlur:Yt(e.onBlur,()=>h(!1))})})})}),Dce="MenuCheckboxItem",J3=b.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...i}=e;return m.jsx(r4,{scope:e.__scopeMenu,checked:n,children:m.jsx(Fb,{role:"menuitemcheckbox","aria-checked":Yy(n)?"mixed":n,...i,ref:t,"data-state":Pk(n),onSelect:Yt(i.onSelect,()=>r==null?void 0:r(Yy(n)?!0:!n),{checkForDefaultPrevented:!1})})})});J3.displayName=Dce;var Q3="MenuRadioGroup",[Bce,zce]=Cu(Q3,{value:void 0,onValueChange:()=>{}}),e4=b.forwardRef((e,t)=>{const{value:n,onValueChange:r,...i}=e,s=Oo(r);return m.jsx(Bce,{scope:e.__scopeMenu,value:n,onValueChange:s,children:m.jsx(Ak,{...i,ref:t})})});e4.displayName=Q3;var t4="MenuRadioItem",n4=b.forwardRef((e,t)=>{const{value:n,...r}=e,i=zce(t4,e.__scopeMenu),s=n===i.value;return m.jsx(r4,{scope:e.__scopeMenu,checked:s,children:m.jsx(Fb,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":Pk(s),onSelect:Yt(r.onSelect,()=>{var o;return(o=i.onValueChange)==null?void 0:o.call(i,n)},{checkForDefaultPrevented:!1})})})});n4.displayName=t4;var Nk="MenuItemIndicator",[r4,jce]=Cu(Nk,{checked:!1}),i4=b.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...i}=e,s=jce(Nk,n);return m.jsx(xo,{present:r||Yy(s.checked)||s.checked===!0,children:m.jsx(En.span,{...i,ref:t,"data-state":Pk(s.checked)})})});i4.displayName=Nk;var Fce="MenuSeparator",s4=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return m.jsx(En.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});s4.displayName=Fce;var $ce="MenuArrow",o4=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=km(n);return m.jsx(jb,{...i,...r,ref:t})});o4.displayName=$ce;var Mk="MenuSub",[Hce,a4]=Cu(Mk),l4=e=>{const{__scopeMenu:t,children:n,open:r=!1,onOpenChange:i}=e,s=fc(Mk,t),o=km(t),[l,u]=b.useState(null),[d,f]=b.useState(null),h=Oo(i);return b.useEffect(()=>(s.open===!1&&h(!1),()=>h(!1)),[s.open,h]),m.jsx(xm,{...o,children:m.jsx(q3,{scope:t,open:r,onOpenChange:h,content:d,onContentChange:f,children:m.jsx(Hce,{scope:t,contentId:_i(),triggerId:_i(),trigger:l,onTriggerChange:u,children:n})})})};l4.displayName=Mk;var fp="MenuSubTrigger",c4=b.forwardRef((e,t)=>{const n=fc(fp,e.__scopeMenu),r=Tm(fp,e.__scopeMenu),i=a4(fp,e.__scopeMenu),s=Tk(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(Ck,{asChild:!0,...d,children:m.jsx(Z3,{id:i.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":i.contentId,"data-state":f4(n.open),...e,ref:Wa(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:Yt(e.onPointerMove,Xp(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:Yt(e.onPointerLeave,Xp(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:Yt(e.onKeyDown,h=>{var g;const v=s.searchRef.current!=="";e.disabled||v&&h.key===" "||Sce[r.dir].includes(h.key)&&(n.onOpenChange(!0),(g=n.content)==null||g.focus(),h.preventDefault())})})})});c4.displayName=fp;var u4="MenuSubContent",d4=b.forwardRef((e,t)=>{const n=V3(go,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=fc(go,e.__scopeMenu),o=Tm(go,e.__scopeMenu),l=a4(u4,e.__scopeMenu),u=b.useRef(null),d=dr(t,u);return m.jsx(Gp.Provider,{scope:e.__scopeMenu,children:m.jsx(xo,{present:r||s.open,children:m.jsx(Gp.Slot,{scope:e.__scopeMenu,children:m.jsx(Rk,{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:Yt(e.onFocusOutside,f=>{f.target!==l.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:Yt(e.onEscapeKeyDown,f=>{o.onClose(),f.preventDefault()}),onKeyDown:Yt(e.onKeyDown,f=>{var g;const h=f.currentTarget.contains(f.target),v=Ece[o.dir].includes(f.key);h&&v&&(s.onOpenChange(!1),(g=l.trigger)==null||g.focus(),f.preventDefault())})})})})})});d4.displayName=u4;function f4(e){return e?"open":"closed"}function Yy(e){return e==="indeterminate"}function Pk(e){return Yy(e)?"indeterminate":e?"checked":"unchecked"}function Uce(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function Wce(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function qce(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=Wce(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 Yce(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 Vce(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return Yce(n,t)}function Xp(e){return t=>t.pointerType==="mouse"?e(t):void 0}var Kce=Y3,Gce=Ck,Xce=K3,Zce=G3,Jce=Ak,Qce=X3,eue=Fb,tue=J3,nue=e4,rue=n4,iue=i4,sue=s4,oue=o4,aue=l4,lue=c4,cue=d4,$b="DropdownMenu",[uue]=Ga($b,[U3]),rs=U3(),[due,h4]=uue($b),p4=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:i,defaultOpen:s,onOpenChange:o,modal:l=!0}=e,u=rs(t),d=b.useRef(null),[f,h]=ec({prop:i,defaultProp:s??!1,onChange:o,caller:$b});return m.jsx(due,{scope:t,triggerId:_i(),triggerRef:d,contentId:_i(),open:f,onOpenChange:h,onOpenToggle:b.useCallback(()=>h(v=>!v),[h]),modal:l,children:m.jsx(Kce,{...u,open:f,onOpenChange:h,dir:r,modal:l,children:n})})};p4.displayName=$b;var m4="DropdownMenuTrigger",g4=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...i}=e,s=h4(m4,n),o=rs(n);return m.jsx(Gce,{asChild:!0,...o,children:m.jsx(En.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:Wa(t,s.triggerRef),onPointerDown:Yt(e.onPointerDown,l=>{!r&&l.button===0&&l.ctrlKey===!1&&(s.onOpenToggle(),s.open||l.preventDefault())}),onKeyDown:Yt(e.onKeyDown,l=>{r||(["Enter"," "].includes(l.key)&&s.onOpenToggle(),l.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(l.key)&&l.preventDefault())})})})});g4.displayName=m4;var fue="DropdownMenuPortal",v4=e=>{const{__scopeDropdownMenu:t,...n}=e,r=rs(t);return m.jsx(Xce,{...r,...n})};v4.displayName=fue;var y4="DropdownMenuContent",b4=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=h4(y4,n),s=rs(n),o=b.useRef(!1);return m.jsx(Zce,{id:i.contentId,"aria-labelledby":i.triggerId,...s,...r,ref:t,onCloseAutoFocus:Yt(e.onCloseAutoFocus,l=>{var u;o.current||(u=i.triggerRef.current)==null||u.focus(),o.current=!1,l.preventDefault()}),onInteractOutside:Yt(e.onInteractOutside,l=>{const u=l.detail.originalEvent,d=u.button===0&&u.ctrlKey===!0,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)"}})});b4.displayName=y4;var hue="DropdownMenuGroup",pue=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=rs(n);return m.jsx(Jce,{...i,...r,ref:t})});pue.displayName=hue;var mue="DropdownMenuLabel",_4=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=rs(n);return m.jsx(Qce,{...i,...r,ref:t})});_4.displayName=mue;var gue="DropdownMenuItem",w4=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=rs(n);return m.jsx(eue,{...i,...r,ref:t})});w4.displayName=gue;var vue="DropdownMenuCheckboxItem",x4=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=rs(n);return m.jsx(tue,{...i,...r,ref:t})});x4.displayName=vue;var yue="DropdownMenuRadioGroup",bue=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=rs(n);return m.jsx(nue,{...i,...r,ref:t})});bue.displayName=yue;var _ue="DropdownMenuRadioItem",wue=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=rs(n);return m.jsx(rue,{...i,...r,ref:t})});wue.displayName=_ue;var xue="DropdownMenuItemIndicator",S4=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=rs(n);return m.jsx(iue,{...i,...r,ref:t})});S4.displayName=xue;var Sue="DropdownMenuSeparator",E4=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=rs(n);return m.jsx(sue,{...i,...r,ref:t})});E4.displayName=Sue;var Eue="DropdownMenuArrow",Cue=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=rs(n);return m.jsx(oue,{...i,...r,ref:t})});Cue.displayName=Eue;var kue=e=>{const{__scopeDropdownMenu:t,children:n,open:r,onOpenChange:i,defaultOpen:s}=e,o=rs(t),[l,u]=ec({prop:r,defaultProp:s??!1,onChange:i,caller:"DropdownMenuSub"});return m.jsx(aue,{...o,open:l,onOpenChange:u,children:n})},Tue="DropdownMenuSubTrigger",C4=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=rs(n);return m.jsx(lue,{...i,...r,ref:t})});C4.displayName=Tue;var Rue="DropdownMenuSubContent",k4=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=rs(n);return m.jsx(cue,{...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)"}})});k4.displayName=Rue;var Aue=p4,Nue=g4,T4=v4,Mue=b4,Pue=_4,Iue=w4,Oue=x4,Lue=S4,Due=E4,Bue=kue,zue=C4,jue=k4;function dI(e,[t,n]){return Math.min(n,Math.max(t,e))}var Hb="Popover",[R4]=Ga(Hb,[dc]),Rm=dc(),[Fue,hc]=R4(Hb),A4=e=>{const{__scopePopover:t,children:n,open:r,defaultOpen:i,onOpenChange:s,modal:o=!1}=e,l=Rm(t),u=b.useRef(null),[d,f]=b.useState(!1),[h,v]=ec({prop:r,defaultProp:i??!1,onChange:s,caller:Hb});return m.jsx(xm,{...l,children:m.jsx(Fue,{scope:t,contentId:_i(),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})})};A4.displayName=Hb;var N4="PopoverAnchor",$ue=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=hc(N4,n),s=Rm(n),{onCustomAnchorAdd:o,onCustomAnchorRemove:l}=i;return b.useEffect(()=>(o(),()=>l()),[o,l]),m.jsx(Sm,{...s,...r,ref:t})});$ue.displayName=N4;var M4="PopoverTrigger",P4=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=hc(M4,n),s=Rm(n),o=dr(t,i.triggerRef),l=m.jsx(En.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.contentId,"data-state":B4(i.open),...r,ref:o,onClick:Yt(e.onClick,i.onOpenToggle)});return i.hasCustomAnchor?l:m.jsx(Sm,{asChild:!0,...s,children:l})});P4.displayName=M4;var Ik="PopoverPortal",[Hue,Uue]=R4(Ik,{forceMount:void 0}),I4=e=>{const{__scopePopover:t,forceMount:n,children:r,container:i}=e,s=hc(Ik,t);return m.jsx(Hue,{scope:t,forceMount:n,children:m.jsx(xo,{present:n||s.open,children:m.jsx(wf,{asChild:!0,container:i,children:r})})})};I4.displayName=Ik;var cf="PopoverContent",O4=b.forwardRef((e,t)=>{const n=Uue(cf,e.__scopePopover),{forceMount:r=n.forceMount,...i}=e,s=hc(cf,e.__scopePopover);return m.jsx(xo,{present:r||s.open,children:s.modal?m.jsx(que,{...i,ref:t}):m.jsx(Yue,{...i,ref:t})})});O4.displayName=cf;var Wue=Ql("PopoverContent.RemoveScroll"),que=b.forwardRef((e,t)=>{const n=hc(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 Mb(o)},[]),m.jsx(_m,{as:Wue,allowPinchZoom:!0,children:m.jsx(L4,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Yt(e.onCloseAutoFocus,o=>{var l;o.preventDefault(),s.current||(l=n.triggerRef.current)==null||l.focus()}),onPointerDownOutside:Yt(e.onPointerDownOutside,o=>{const l=o.detail.originalEvent,u=l.button===0&&l.ctrlKey===!0,d=l.button===2||u;s.current=d},{checkForDefaultPrevented:!1}),onFocusOutside:Yt(e.onFocusOutside,o=>o.preventDefault(),{checkForDefaultPrevented:!1})})})}),Yue=b.forwardRef((e,t)=>{const n=hc(cf,e.__scopePopover),r=b.useRef(!1),i=b.useRef(!1);return m.jsx(L4,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var o,l;(o=e.onCloseAutoFocus)==null||o.call(e,s),s.defaultPrevented||(r.current||(l=n.triggerRef.current)==null||l.focus(),s.preventDefault()),r.current=!1,i.current=!1},onInteractOutside:s=>{var u,d;(u=e.onInteractOutside)==null||u.call(e,s),s.defaultPrevented||(r.current=!0,s.detail.originalEvent.type==="pointerdown"&&(i.current=!0));const o=s.target;((d=n.triggerRef.current)==null?void 0:d.contains(o))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&i.current&&s.preventDefault()}})}),L4=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=hc(cf,n),g=Rm(n);return Ab(),m.jsx(bm,{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(zb,{"data-state":B4(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)"}})})})}),D4="PopoverClose",Vue=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=hc(D4,n);return m.jsx(En.button,{type:"button",...r,ref:t,onClick:Yt(e.onClick,()=>i.onOpenChange(!1))})});Vue.displayName=D4;var Kue="PopoverArrow",Gue=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=Rm(n);return m.jsx(jb,{...i,...r,ref:t})});Gue.displayName=Kue;function B4(e){return e?"open":"closed"}var Xue=A4,Zue=P4,Jue=I4,Que=O4,ede=[" ","Enter","ArrowUp","ArrowDown"],tde=[" ","Enter"],hu="Select",[Ub,Wb,nde]=lk(hu),[Ef]=Ga(hu,[nde,dc]),qb=dc(),[rde,pc]=Ef(hu),[ide,sde]=Ef(hu),z4=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=qb(t),[S,x]=b.useState(null),[T,k]=b.useState(null),[A,P]=b.useState(!1),R=ck(d),[M,z]=ec({prop:r,defaultProp:i??!1,onChange:s,caller:hu}),[V,W]=ec({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(I=>I.props.value).join(";");return m.jsx(xm,{...w,children:m.jsxs(rde,{required:g,scope:t,trigger:S,onTriggerChange:x,valueNode:T,onValueNodeChange:k,valueNodeHasChildren:A,onValueNodeHasChildrenChange:P,contentId:_i(),value:V,onValueChange:W,open:M,onOpenChange:z,dir:R,triggerPointerDownPosRef:G,disabled:v,children:[m.jsx(Ub.Provider,{scope:t,children:m.jsx(ide,{scope:e.__scopeSelect,onNativeOptionAdd:b.useCallback(I=>{L(B=>new Set(B).add(I))},[]),onNativeOptionRemove:b.useCallback(I=>{L(B=>{const F=new Set(B);return F.delete(I),F})},[]),children:n})}),O?m.jsxs(oF,{"aria-hidden":!0,required:g,tabIndex:-1,name:f,autoComplete:h,value:V,onChange:I=>W(I.target.value),disabled:v,form:_,children:[V===void 0?m.jsx("option",{value:""}):null,Array.from(N)]},D):null]})})};z4.displayName=hu;var j4="SelectTrigger",F4=b.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...i}=e,s=qb(n),o=pc(j4,n),l=o.disabled||r,u=dr(t,o.onTriggerChange),d=Wb(n),f=b.useRef("touch"),[h,v,g]=lF(w=>{const S=d().filter(k=>!k.disabled),x=S.find(k=>k.value===o.value),T=cF(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(Sm,{asChild:!0,...s,children:m.jsx(En.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":aF(o.value)?"":void 0,...i,ref:u,onClick:Yt(i.onClick,w=>{w.currentTarget.focus(),f.current!=="mouse"&&_(w)}),onPointerDown:Yt(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:Yt(i.onKeyDown,w=>{const S=h.current!=="";!(w.ctrlKey||w.altKey||w.metaKey)&&w.key.length===1&&v(w.key),!(S&&w.key===" ")&&ede.includes(w.key)&&(_(),w.preventDefault())})})})});F4.displayName=j4;var $4="SelectValue",H4=b.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:i,children:s,placeholder:o="",...l}=e,u=pc($4,n),{onValueNodeHasChildrenChange:d}=u,f=s!==void 0,h=dr(t,u.onValueNodeChange);return ns(()=>{d(f)},[d,f]),m.jsx(En.span,{...l,ref:h,style:{pointerEvents:"none"},children:aF(u.value)?m.jsx(m.Fragment,{children:o}):s})});H4.displayName=$4;var ode="SelectIcon",U4=b.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...i}=e;return m.jsx(En.span,{"aria-hidden":!0,...i,ref:t,children:r||"▼"})});U4.displayName=ode;var ade="SelectPortal",W4=e=>m.jsx(wf,{asChild:!0,...e});W4.displayName=ade;var pu="SelectContent",q4=b.forwardRef((e,t)=>{const n=pc(pu,e.__scopeSelect),[r,i]=b.useState();if(ns(()=>{i(new DocumentFragment)},[]),!n.open){const s=r;return s?Eu.createPortal(m.jsx(Y4,{scope:e.__scopeSelect,children:m.jsx(Ub.Slot,{scope:e.__scopeSelect,children:m.jsx("div",{children:e.children})})}),s):null}return m.jsx(V4,{...e,ref:t})});q4.displayName=pu;var Ao=10,[Y4,mc]=Ef(pu),lde="SelectContentImpl",cde=Ql("SelectContent.RemoveScroll"),V4=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=pc(pu,n),[k,A]=b.useState(null),[P,R]=b.useState(null),M=dr(t,Z=>A(Z)),[z,V]=b.useState(null),[W,G]=b.useState(null),O=Wb(n),[N,L]=b.useState(!1),D=b.useRef(!1);b.useEffect(()=>{if(k)return Mb(k)},[k]),Ab();const I=b.useCallback(Z=>{const[oe,...Q]=O().map(Ce=>Ce.ref.current),[fe]=Q.slice(-1),ge=document.activeElement;for(const Ce of Z)if(Ce===ge||(Ce==null||Ce.scrollIntoView({block:"nearest"}),Ce===oe&&P&&(P.scrollTop=0),Ce===fe&&P&&(P.scrollTop=P.scrollHeight),Ce==null||Ce.focus(),document.activeElement!==ge))return},[O,P]),B=b.useCallback(()=>I([z,k]),[I,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 oe=fe=>{var ge,Ce;Z={x:Math.abs(Math.round(fe.pageX)-(((ge=U.current)==null?void 0:ge.x)??0)),y:Math.abs(Math.round(fe.pageY)-(((Ce=U.current)==null?void 0:Ce.y)??0))}},Q=fe=>{Z.x<=10&&Z.y<=10?fe.preventDefault():k.contains(fe.target)||F(!1),document.removeEventListener("pointermove",oe),U.current=null};return U.current!==null&&(document.addEventListener("pointermove",oe),document.addEventListener("pointerup",Q,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",oe),document.removeEventListener("pointerup",Q,{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,Y]=lF(Z=>{const oe=O().filter(ge=>!ge.disabled),Q=oe.find(ge=>ge.ref.current===document.activeElement),fe=cF(oe,Z,Q);fe&&setTimeout(()=>fe.ref.current.focus())}),X=b.useCallback((Z,oe,Q)=>{const fe=!D.current&&!Q;(T.value!==void 0&&T.value===oe||fe)&&(V(Z),fe&&(D.current=!0))},[T.value]),$=b.useCallback(()=>k==null?void 0:k.focus(),[k]),ee=b.useCallback((Z,oe,Q)=>{const fe=!D.current&&!Q;(T.value!==void 0&&T.value===oe||fe)&&G(Z)},[T.value]),re=r==="popper"?k1:K4,te=re===k1?{side:l,sideOffset:u,align:d,alignOffset:f,arrowPadding:h,collisionBoundary:v,collisionPadding:g,sticky:_,hideWhenDetached:w,avoidCollisions:S}:{};return m.jsx(Y4,{scope:n,content:k,viewport:P,onViewportChange:R,itemRefCallback:X,selectedItem:z,onItemLeave:$,itemTextRefCallback:ee,focusSelectedItem:B,selectedItemText:W,position:r,isPositioned:N,searchRef:j,children:m.jsx(_m,{as:cde,allowPinchZoom:!0,children:m.jsx(bm,{asChild:!0,trapped:T.open,onMountAutoFocus:Z=>{Z.preventDefault()},onUnmountAutoFocus:Yt(i,Z=>{var oe;(oe=T.trigger)==null||oe.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(re,{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:Yt(x.onKeyDown,Z=>{const oe=Z.ctrlKey||Z.altKey||Z.metaKey;if(Z.key==="Tab"&&Z.preventDefault(),!oe&&Z.key.length===1&&Y(Z.key),["ArrowUp","ArrowDown","Home","End"].includes(Z.key)){let fe=O().filter(ge=>!ge.disabled).map(ge=>ge.ref.current);if(["ArrowUp","End"].includes(Z.key)&&(fe=fe.slice().reverse()),["ArrowUp","ArrowDown"].includes(Z.key)){const ge=Z.target,Ce=fe.indexOf(ge);fe=fe.slice(Ce+1)}setTimeout(()=>I(fe)),Z.preventDefault()}})})})})})})});V4.displayName=lde;var ude="SelectItemAlignedPosition",K4=b.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...i}=e,s=pc(pu,n),o=mc(pu,n),[l,u]=b.useState(null),[d,f]=b.useState(null),h=dr(t,M=>f(M)),v=Wb(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(),V=s.valueNode.getBoundingClientRect(),W=x.getBoundingClientRect();if(s.dir!=="rtl"){const ge=W.left-z.left,Ce=V.left-ge,De=M.left-Ce,ot=M.width+De,Dt=Math.max(ot,z.width),et=window.innerWidth-Ao,ut=dI(Ce,[Ao,Math.max(Ao,et-Dt)]);l.style.minWidth=ot+"px",l.style.left=ut+"px"}else{const ge=z.right-W.right,Ce=window.innerWidth-V.right-ge,De=window.innerWidth-M.right-Ce,ot=M.width+De,Dt=Math.max(ot,z.width),et=window.innerWidth-Ao,ut=dI(Ce,[Ao,Math.max(Ao,et-Dt)]);l.style.minWidth=ot+"px",l.style.right=ut+"px"}const G=v(),O=window.innerHeight-Ao*2,N=w.scrollHeight,L=window.getComputedStyle(d),D=parseInt(L.borderTopWidth,10),I=parseInt(L.paddingTop,10),B=parseInt(L.borderBottomWidth,10),F=parseInt(L.paddingBottom,10),U=D+I+N+F+B,j=Math.min(S.offsetHeight*5,U),Y=window.getComputedStyle(w),X=parseInt(Y.paddingTop,10),$=parseInt(Y.paddingBottom,10),ee=M.top+M.height/2-Ao,re=O-ee,te=S.offsetHeight/2,Z=S.offsetTop+te,oe=D+I+Z,Q=U-oe;if(oe<=ee){const ge=G.length>0&&S===G[G.length-1].ref.current;l.style.bottom="0px";const Ce=d.clientHeight-w.offsetTop-w.offsetHeight,De=Math.max(re,te+(ge?$:0)+Ce+B),ot=oe+De;l.style.height=ot+"px"}else{const ge=G.length>0&&S===G[0].ref.current;l.style.top="0px";const De=Math.max(ee,D+w.offsetTop+(ge?X:0)+te)+Q;l.style.height=De+"px",w.scrollTop=oe-ee+w.offsetTop}l.style.margin=`${Ao}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]);ns(()=>k(),[k]);const[A,P]=b.useState();ns(()=>{d&&P(window.getComputedStyle(d).zIndex)},[d]);const R=b.useCallback(M=>{M&&_.current===!0&&(k(),T==null||T(),_.current=!1)},[k,T]);return m.jsx(fde,{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(En.div,{...i,ref:h,style:{boxSizing:"border-box",maxHeight:"100%",...i.style}})})})});K4.displayName=ude;var dde="SelectPopperPosition",k1=b.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:i=Ao,...s}=e,o=qb(n);return m.jsx(zb,{...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)"}})});k1.displayName=dde;var[fde,Ok]=Ef(pu,{}),T1="SelectViewport",G4=b.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...i}=e,s=mc(T1,n),o=Ok(T1,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(Ub.Slot,{scope:n,children:m.jsx(En.div,{"data-radix-select-viewport":"",role:"presentation",...i,ref:l,style:{position:"relative",flex:1,overflow:"hidden auto",...i.style},onScroll:Yt(i.onScroll,d=>{const 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-Ao*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})})})]})});G4.displayName=T1;var X4="SelectGroup",[hde,pde]=Ef(X4),mde=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=_i();return m.jsx(hde,{scope:n,id:i,children:m.jsx(En.div,{role:"group","aria-labelledby":i,...r,ref:t})})});mde.displayName=X4;var Z4="SelectLabel",gde=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=pde(Z4,n);return m.jsx(En.div,{id:i.id,...r,ref:t})});gde.displayName=Z4;var Vy="SelectItem",[vde,J4]=Ef(Vy),Q4=b.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:i=!1,textValue:s,...o}=e,l=pc(Vy,n),u=mc(Vy,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=_i(),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(vde,{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(Ub.ItemSlot,{scope:n,value:r,disabled:i,textValue:f,children:m.jsx(En.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:Yt(o.onFocus,()=>g(!0)),onBlur:Yt(o.onBlur,()=>g(!1)),onClick:Yt(o.onClick,()=>{S.current!=="mouse"&&x()}),onPointerUp:Yt(o.onPointerUp,()=>{S.current==="mouse"&&x()}),onPointerDown:Yt(o.onPointerDown,T=>{S.current=T.pointerType}),onPointerMove:Yt(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:Yt(o.onPointerLeave,T=>{var k;T.currentTarget===document.activeElement&&((k=u.onItemLeave)==null||k.call(u))}),onKeyDown:Yt(o.onKeyDown,T=>{var A;((A=u.searchRef)==null?void 0:A.current)!==""&&T.key===" "||(tde.includes(T.key)&&x(),T.key===" "&&T.preventDefault())})})})})});Q4.displayName=Vy;var hp="SelectItemText",eF=b.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:i,...s}=e,o=pc(hp,n),l=mc(hp,n),u=J4(hp,n),d=sde(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 ns(()=>(w(_),()=>S(_)),[w,S,_]),m.jsxs(m.Fragment,{children:[m.jsx(En.span,{id:u.textId,...s,ref:v}),u.isSelected&&o.valueNode&&!o.valueNodeHasChildren?Eu.createPortal(s.children,o.valueNode):null]})});eF.displayName=hp;var tF="SelectItemIndicator",nF=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return J4(tF,n).isSelected?m.jsx(En.span,{"aria-hidden":!0,...r,ref:t}):null});nF.displayName=tF;var R1="SelectScrollUpButton",rF=b.forwardRef((e,t)=>{const n=mc(R1,e.__scopeSelect),r=Ok(R1,e.__scopeSelect),[i,s]=b.useState(!1),o=dr(t,r.onScrollButtonChange);return ns(()=>{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(sF,{...e,ref:o,onAutoScroll:()=>{const{viewport:l,selectedItem:u}=n;l&&u&&(l.scrollTop=l.scrollTop-u.offsetHeight)}}):null});rF.displayName=R1;var A1="SelectScrollDownButton",iF=b.forwardRef((e,t)=>{const n=mc(A1,e.__scopeSelect),r=Ok(A1,e.__scopeSelect),[i,s]=b.useState(!1),o=dr(t,r.onScrollButtonChange);return ns(()=>{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(sF,{...e,ref:o,onAutoScroll:()=>{const{viewport:l,selectedItem:u}=n;l&&u&&(l.scrollTop=l.scrollTop+u.offsetHeight)}}):null});iF.displayName=A1;var sF=b.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...i}=e,s=mc("SelectScrollButton",n),o=b.useRef(null),l=Wb(n),u=b.useCallback(()=>{o.current!==null&&(window.clearInterval(o.current),o.current=null)},[]);return b.useEffect(()=>()=>u(),[u]),ns(()=>{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(En.div,{"aria-hidden":!0,...i,ref:t,style:{flexShrink:0,...i.style},onPointerDown:Yt(i.onPointerDown,()=>{o.current===null&&(o.current=window.setInterval(r,50))}),onPointerMove:Yt(i.onPointerMove,()=>{var d;(d=s.onItemLeave)==null||d.call(s),o.current===null&&(o.current=window.setInterval(r,50))}),onPointerLeave:Yt(i.onPointerLeave,()=>{u()})})}),yde="SelectSeparator",bde=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return m.jsx(En.div,{"aria-hidden":!0,...r,ref:t})});bde.displayName=yde;var N1="SelectArrow",_de=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=qb(n),s=pc(N1,n),o=mc(N1,n);return s.open&&o.position==="popper"?m.jsx(jb,{...i,...r,ref:t}):null});_de.displayName=N1;var wde="SelectBubbleInput",oF=b.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const i=b.useRef(null),s=dr(r,i),o=Gae(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(En.select,{...n,style:{...B5,...n.style},ref:s,defaultValue:t})});oF.displayName=wde;function aF(e){return e===""||e===void 0}function lF(e){const t=Oo(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 cF(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=xde(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 xde(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Sde=z4,Ede=F4,Cde=H4,kde=U4,Tde=W4,Rde=q4,Ade=G4,Nde=Q4,Mde=eF,Pde=nF,Ide=rF,Ode=iF,[Yb]=Ga("Tooltip",[dc]),Vb=dc(),uF="TooltipProvider",Lde=700,M1="tooltip.open",[Dde,Lk]=Yb(uF),dF=e=>{const{__scopeTooltip:t,delayDuration:n=Lde,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(Dde,{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})};dF.displayName=uF;var Zp="Tooltip",[Bde,Am]=Yb(Zp),fF=e=>{const{__scopeTooltip:t,children:n,open:r,defaultOpen:i,onOpenChange:s,disableHoverableContent:o,delayDuration:l}=e,u=Lk(Zp,e.__scopeTooltip),d=Vb(t),[f,h]=b.useState(null),v=_i(),g=b.useRef(0),_=o??u.disableHoverableContent,w=l??u.delayDuration,S=b.useRef(!1),[x,T]=ec({prop:r,defaultProp:i??!1,onChange:M=>{M?(u.onOpen(),document.dispatchEvent(new CustomEvent(M1))):u.onClose(),s==null||s(M)},caller:Zp}),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]),P=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(xm,{...d,children:m.jsx(Bde,{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(()=>{_?P():(window.clearTimeout(g.current),g.current=0)},[P,_]),onOpen:A,onClose:P,disableHoverableContent:_,children:n})})};fF.displayName=Zp;var P1="TooltipTrigger",hF=b.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,i=Am(P1,n),s=Lk(P1,n),o=Vb(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(Sm,{asChild:!0,...o,children:m.jsx(En.button,{"aria-describedby":i.open?i.contentId:void 0,"data-state":i.stateAttribute,...r,ref:u,onPointerMove:Yt(e.onPointerMove,v=>{v.pointerType!=="touch"&&!f.current&&!s.isPointerInTransitRef.current&&(i.onTriggerEnter(),f.current=!0)}),onPointerLeave:Yt(e.onPointerLeave,()=>{i.onTriggerLeave(),f.current=!1}),onPointerDown:Yt(e.onPointerDown,()=>{i.open&&i.onClose(),d.current=!0,document.addEventListener("pointerup",h,{once:!0})}),onFocus:Yt(e.onFocus,()=>{d.current||i.onOpen()}),onBlur:Yt(e.onBlur,i.onClose),onClick:Yt(e.onClick,i.onClose)})})});hF.displayName=P1;var Dk="TooltipPortal",[zde,jde]=Yb(Dk,{forceMount:void 0}),pF=e=>{const{__scopeTooltip:t,forceMount:n,children:r,container:i}=e,s=Am(Dk,t);return m.jsx(zde,{scope:t,forceMount:n,children:m.jsx(xo,{present:n||s.open,children:m.jsx(wf,{asChild:!0,container:i,children:r})})})};pF.displayName=Dk;var uf="TooltipContent",mF=b.forwardRef((e,t)=>{const n=jde(uf,e.__scopeTooltip),{forceMount:r=n.forceMount,side:i="top",...s}=e,o=Am(uf,e.__scopeTooltip);return m.jsx(xo,{present:r||o.open,children:o.disableHoverableContent?m.jsx(gF,{side:i,...s,ref:t}):m.jsx(Fde,{side:i,...s,ref:t})})}),Fde=b.forwardRef((e,t)=>{const n=Am(uf,e.__scopeTooltip),r=Lk(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=Wde(x,S.getBoundingClientRect()),k=qde(x,T),A=Yde(w.getBoundingClientRect()),P=Kde([...k,...A]);l(P),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=!Vde(x,o);T?v():k&&(v(),d())};return document.addEventListener("pointermove",_),()=>document.removeEventListener("pointermove",_)}},[u,f,o,d,v]),m.jsx(gF,{...e,ref:s})}),[$de,Hde]=Yb(Zp,{isInside:!1}),Ude=woe("TooltipContent"),gF=b.forwardRef((e,t)=>{const{__scopeTooltip:n,children:r,"aria-label":i,onEscapeKeyDown:s,onPointerDownOutside:o,...l}=e,u=Am(uf,n),d=Vb(n),{onClose:f}=u;return b.useEffect(()=>(document.addEventListener(M1,f),()=>document.removeEventListener(M1,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(zb,{"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(Ude,{children:r}),m.jsx($de,{scope:n,isInside:!0,children:m.jsx(j5,{id:u.contentId,role:"tooltip",children:i||r})})]})})});mF.displayName=uf;var vF="TooltipArrow",yF=b.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,i=Vb(n);return Hde(vF,n).isInside?null:m.jsx(jb,{...i,...r,ref:t})});yF.displayName=vF;function Wde(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 qde(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 Yde(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 Vde(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 Kde(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),Gde(t)}function Gde(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 Xde=dF,Zde=fF,Jde=hF,Qde=pF,efe=mF,tfe=yF;const bF=b.createContext(!1);function nfe({blocked:e,children:t}){return m.jsx(bF.Provider,{value:e,children:t})}function Nm(){return b.useContext(bF)}function Kb({...e}){return m.jsx(Xue,{"data-slot":"popover",...e})}function Gb({...e}){return m.jsx(Zue,{"data-slot":"popover-trigger",...e})}function Xb({className:e,align:t="center",sideOffset:n=4,inert:r,"aria-disabled":i,...s}){const o=Nm();return m.jsx(Jue,{children:m.jsx(Que,{"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 fI=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,hI=Yz,rfe=(e,t)=>n=>{var r;if((t==null?void 0:t.variants)==null)return hI(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=fI(f)||fI(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 hI(e,o,u,n==null?void 0:n.class,n==null?void 0:n.className)},ife=rfe("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 dt({className:e,variant:t="default",size:n="default",asChild:r=!1,...i}){const s=r?boe:"button";return m.jsx(s,{"data-slot":"button","data-variant":t,"data-size":n,className:We(ife({variant:t,size:n,className:e})),...i})}function Cf({...e}){return m.jsx(Aue,{"data-slot":"dropdown-menu",...e})}function sfe({...e}){return m.jsx(T4,{"data-slot":"dropdown-menu-portal",...e})}function kf({...e}){return m.jsx(Nue,{"data-slot":"dropdown-menu-trigger",...e})}function Tf({className:e,sideOffset:t=4,inert:n,"aria-disabled":r,...i}){const s=Nm();return m.jsx(T4,{children:m.jsx(Mue,{"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 ii({className:e,inset:t,variant:n="default",...r}){return m.jsx(Iue,{"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 E0({className:e,children:t,checked:n,...r}){return m.jsxs(Oue,{"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(Lue,{children:m.jsx(ua,{className:"size-4"})})}),t]})}function Dh({className:e,inset:t,...n}){return m.jsx(Pue,{"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 Hl({className:e,...t}){return m.jsx(Due,{"data-slot":"dropdown-menu-separator",className:We("-mx-1 my-1 h-px bg-border",e),...t})}function ofe({...e}){return m.jsx(Bue,{"data-slot":"dropdown-menu-sub",...e})}function afe({className:e,inset:t,children:n,...r}){return m.jsxs(zue,{"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 lfe({className:e,...t}){return m.jsx(jue,{"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 cfe={"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}=cfe[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 ufe={online:"bg-[var(--color-status-success)]",offline:"bg-[var(--muted-foreground)]",connecting:"bg-[var(--color-status-working)] animate-pulse"},dfe={online:"开发机在线",offline:"开发机离线",connecting:"正在连接开发机"};function I1({status:e,className:t}){return m.jsx("span",{className:We("inline-block w-2 h-2 rounded-full shrink-0",ufe[e],t),role:"status","aria-label":dfe[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 qi({...e}){return m.jsx(hk,{"data-slot":"dialog",...e})}function ffe({...e}){return m.jsx(pk,{"data-slot":"dialog-portal",...e})}function _F({...e}){return m.jsx(Ib,{"data-slot":"dialog-close",...e})}function hfe({className:e,...t}){return m.jsx(mk,{"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 Yi({className:e,children:t,showCloseButton:n=!0,focusSurfaceOnOpen:r=!1,onOpenAutoFocus:i,inert:s,"aria-disabled":o,...l}){const u=Nm();return m.jsxs(ffe,{"data-slot":"dialog-portal",children:[m.jsx(hfe,{}),m.jsxs(gk,{"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(Ib,{"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(ac,{}),m.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function Vi({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(Ib,{asChild:!0,children:m.jsx(dt,{variant:"outline",children:"Close"})})]})}function Pi({className:e,...t}){return m.jsx(h3,{"data-slot":"dialog-title",className:We("text-lg leading-none font-semibold",e),...t})}function fs({className:e,...t}){return m.jsx(p3,{"data-slot":"dialog-description",className:We("text-sm text-muted-foreground",e),...t})}function pfe(e){return`“${(e==null?void 0:e.name)??(e==null?void 0:e.proxyId)??"这台开发机"}”只会从当前 Relay 的开发机列表中移除。不会删除机器上的文件或会话,也不会阻止它再次连接;以后重新运行时,它会重新出现在列表中。`}function mfe({open:e,target:t,removing:n,onOpenChange:r,onConfirm:i}){return m.jsx(qi,{open:e,onOpenChange:s=>{n||r(s)},children:m.jsxs(Yi,{"data-slot":"proxy-removal-dialog",showCloseButton:!n,onEscapeKeyDown:s=>{n&&s.preventDefault()},onPointerDownOutside:s=>{n&&s.preventDefault()},children:[m.jsxs(Vi,{children:[m.jsx(Pi,{children:"移除离线开发机?"}),m.jsx(fs,{children:pfe(t)})]}),m.jsxs(Gs,{children:[m.jsx(dt,{type:"button",variant:"ghost",disabled:n,onClick:()=>r(!1),children:"取消"}),m.jsxs(dt,{type:"button",variant:"destructive",disabled:n||!t,"aria-busy":n||void 0,onClick:i,"data-slot":"proxy-removal-confirm",children:[n&&m.jsx(Xr,{className:"size-4 animate-spin","aria-hidden":"true"}),n?"正在移除":"移除"]})]})]})})}const dy=80,gfe=8,vfe=1.2;function pI(e){return Math.max(0,Math.min(dy,e))}function yfe({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?dy:0),_=h!==null;function w(k){var A,P;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?dy:0,axis:"pending"};try{(P=(A=k.currentTarget).setPointerCapture)==null||P.call(A,k.pointerId)}catch{}}}function S(k){const A=d.current;if(!A||A.pointerId!==k.pointerId)return;const P=k.clientX-A.startX,R=k.clientY-A.startY;if(A.axis==="pending"){if(Math.hypot(P,R)<gfe)return;A.axis=Math.abs(P)>Math.abs(R)*vfe?"horizontal":"vertical"}A.axis!=="vertical"&&(k.preventDefault(),v(pI(A.startOffset-P)))}function x(k,A=!1){var M,z;const P=d.current;if(!P||P.pointerId!==k.pointerId)return;d.current=null;try{(z=(M=k.currentTarget).releasePointerCapture)==null||z.call(M,k.pointerId)}catch{}if(P.axis!=="horizontal"||A){v(null);return}k.preventDefault();const R=h??pI(P.startOffset-(k.clientX-P.startX));v(null),o(R>=dy/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(I1,{status:"offline"}),m.jsx(Mp,{name:u,osName:n}),r&&m.jsx(ua,{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 wF({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 V=zt;if(!V){$e.error("请先连接开发机");return}const W=z??M,G=s!==null&&s!==M;Re.getState().setProxySwitchTarget({proxyId:M,name:W});try{const O=await V.selectProxy(M);if(!O.success){$e.error(`无法连接 ${W}:${O.error??"未知错误"}`);return}const N=V.getPreviewScope();if(!N||N.proxyId!==M||N.bindingId!==O.bindingId)throw Pt.dispose(),V.clearBoundProxy(),new Error("开发机绑定状态无效,请重试");Pt.activate(V,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),Zr.getState().prepareForProxySwitch()),Pr("local",Tn.proxyId,M),Re.getState().setProxy(M,z??null),Re.getState().setProxyOnline(!0),Re.getState().transitionToPhase("session_browsing"),V.sendControl({type:"session_list_request"}),V.requestProxyInfo().then(L=>{if(Re.getState().selectedProxyId!==M||!Pt.isActive(V,N))return;const D=Zr.getState();D.setHomePath(L.homePath),D.setAgentCli(L.agentCli),Re.getState().setTerminalShells(L.terminalShells)}).catch(L=>{Pt.isActive(V,N)&&console.error("[proxy-switcher] post-bind proxy info fetch failed",L)}),V.requestAgentStatuses().then(L=>{if(Re.getState().selectedProxyId!==M||!Pt.isActive(V,N))return;const D=Ut.getState();for(const I of L)D.setAgentStatus(I.sessionId,I.payload)}).catch(L=>{Pt.isActive(V,N)&&console.error("[proxy-switcher] post-bind data fetch failed",L)}),ek(V).then(L=>{L.status==="failed"&&console.error("[proxy-switcher] post-bind data fetch failed",L.error)}),f(!1),(e==="page"||l.pathname.startsWith("/chat/")||l.pathname.startsWith("/preview/device/"))&&u("/sessions")}catch(O){const N=O instanceof Error?O.message:"未知错误";$e.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=zt;if(!z){$e.error("Relay 连接不可用,请稍后重试");return}const V=Re.getState().proxies.find(W=>W.proxyId===M.proxyId);if(!V){if(!Re.getState().proxyListLoaded){$e.info("正在重新连接 Relay,请稍后再试");return}Np(M.proxyId,z)&&u("/"),$e.info("这台开发机已经不在列表中"),_(null);return}if(V.online){$e.warning("这台开发机已重新上线,未移除"),_(null);return}S(M.proxyId),lse(M.proxyId);try{const W=await z.removeOfflineProxy(M.proxyId);if(W.success){Dd(M.proxyId),Np(M.proxyId,z)&&u("/"),$e.success(`已移除 ${M.name??M.proxyId}`),_(null);return}if(W.errorCode===Ir.PROXY_ONLINE){Dd(M.proxyId),$e.warning("这台开发机已重新上线,未移除"),_(null),z.listProxies();return}if(W.errorCode===Ir.PROXY_NOT_FOUND){Dd(M.proxyId),Np(M.proxyId,z)&&u("/"),$e.info("这台开发机已经不在列表中"),_(null),z.listProxies();return}Dd(M.proxyId),$e.error(W.error??"无法移除开发机,请重试")}catch(W){$e.error(W instanceof Error?W.message:"无法移除开发机,请重试"),z.listProxies()}finally{S(null)}}const A=m.jsx(mfe,{open:g!==null,target:g,removing:w!==null,onOpenChange:M=>{M||_(null)},onConfirm:()=>void 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,V=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:V||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",V&&!z||w!==null?"opacity-50":""),"aria-pressed":s===M.proxyId,children:[m.jsx(I1,{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(Xr,{className:"size-4 shrink-0 animate-spin text-primary","aria-hidden":!0})]}):s===M.proxyId?m.jsx(ua,{className:"size-4 shrink-0 text-primary","aria-label":"已选"}):null]})},M.proxyId):m.jsx(yfe,{proxyId:M.proxyId,name:M.name,osName:M.osName,selected:s===M.proxyId,revealed:h===M.proxyId,disabled:V||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(Xr,{className:"h-5 w-5 animate-spin","aria-hidden":!0}),m.jsx("p",{className:"text-sm",children:"连接中..."})]});const P=n.find(M=>M.proxyId===s),R=(P==null?void 0:P.name)??(P==null?void 0:P.proxyId)??"未选择开发机";return m.jsxs(m.Fragment,{children:[m.jsxs(Kb,{open:d,onOpenChange:f,children:[m.jsx(Gb,{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:P==null?void 0:P.osName,className:t==="sidebarChrome"?"flex-initial":"text-center",nameClassName:t==="sidebarChrome"?"text-base font-semibold":void 0}),m.jsx(oc,{className:"h-4 w-4 text-muted-foreground shrink-0 transition-transform group-data-[state=open]:rotate-180","aria-hidden":!0})]})}),m.jsx(Xb,{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,V=o!==null;return m.jsxs("li",{className:"group flex min-w-0 items-center rounded-md",children:[m.jsxs("button",{type:"button","data-slot":"proxy-item","data-proxy-id":M.proxyId,"data-online":M.online,"data-selecting":z||void 0,disabled:!M.online||V,"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",V&&!z?"opacity-50":"",M.online?"":"opacity-50"),"aria-pressed":s===M.proxyId,title:M.online?void 0:"这台开发机离线",children:[m.jsx(I1,{status:M.online?"online":"offline"}),m.jsx(Mp,{name:M.name??M.proxyId,osName:M.osName}),z?m.jsx(Xr,{className:"h-4 w-4 animate-spin text-primary shrink-0","aria-label":"正在连接"}):s===M.proxyId?m.jsx(ua,{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(dt,{type:"button",variant:"ghost",size:"icon-xs",className:"mr-1 size-8 text-muted-foreground opacity-60 hover:opacity-100 focus-visible:opacity-100",disabled:V||w!==null,"aria-label":`${M.name??M.proxyId} 操作`,"data-slot":"proxy-row-menu-trigger",children:m.jsx(yb,{"aria-hidden":"true"})})}),m.jsx(Tf,{align:"end","data-slot":"proxy-row-menu",children:m.jsxs(ii,{variant:"destructive","data-slot":"proxy-row-remove-item",onSelect:W=>{W.stopPropagation(),T(M)},children:[m.jsx(Uz,{"aria-hidden":"true"}),"移除开发机"]})})]})]},M.proxyId)})})})]}),A]})}function bfe({delayDuration:e=0,...t}){return m.jsx(Xde,{"data-slot":"tooltip-provider",delayDuration:e,...t})}function Rf({...e}){return m.jsx(Zde,{"data-slot":"tooltip",...e})}function Af({...e}){return m.jsx(Jde,{"data-slot":"tooltip-trigger",...e})}function Nf({className:e,sideOffset:t=0,children:n,hideArrow:r=!1,...i}){return m.jsx(Qde,{children:m.jsxs(efe,{"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(tfe,{className:"z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px] bg-foreground fill-foreground"})]})})}function gc({...e}){return m.jsx(hk,{"data-slot":"sheet",...e})}function _fe({...e}){return m.jsx(Kae,{"data-slot":"sheet-trigger",...e})}function wfe({...e}){return m.jsx(pk,{"data-slot":"sheet-portal",...e})}function xfe({className:e,...t}){return m.jsx(mk,{"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 vc({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=Nm();return m.jsxs(wfe,{children:[m.jsx(xfe,{className:t}),m.jsxs(gk,{"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(Ib,{"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(ac,{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 yc({className:e,...t}){return m.jsx(h3,{"data-slot":"sheet-title",className:We("font-semibold text-foreground",e),...t})}function Zb({className:e,...t}){return m.jsx(p3,{"data-slot":"sheet-description",className:We("text-sm text-muted-foreground",e),...t})}const Sfe={claude:"Claude Code",codex:"Codex",kimi:"Kimi Code",cursor:"Cursor CLI"},mI=["claude","codex","kimi","cursor"];function Jb(e){return Sfe[e]}function xF(e,t){return mI.indexOf(e)-mI.indexOf(t)}function ql(e){return e.provider}const O1=60*1e3,L1=60*O1,Efe=24*L1;function SF(e,t=Date.now()){const n=t-e;if(n<O1)return"刚刚";if(n<L1)return`${Math.floor(n/O1)} 分钟前`;if(n<Efe)return`${Math.floor(n/L1)} 小时前`;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 gI={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 D1(e){return e.kind!=="terminal"?gI[e.state]:e.state==="terminated"?gI.terminated:e.state==="error"?{dot:"bg-[var(--color-status-error)]",text:"text-[var(--color-status-error)]",label:"已断开"}:{dot:"bg-[var(--color-status-success)]",text:"text-[var(--color-status-success)]",label:"运行中"}}function Cfe({session:e}){const t=D1(e);return m.jsx("span",{className:We("inline-block size-2 rounded-full shrink-0",t.dot),"aria-label":`会话状态:${t.label}`,role:"status"})}function kfe({mode:e}){if(e!=="pty"&&e!=="json")return null;const t=e==="json"?"聊天视图":"终端视图",n=e==="json"?NC:IC;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 Tfe({session:e,selected:t,now:n,onClick:r,onRename:i,onTerminate:s}){const o=Zr(w=>w.homePath),l=e.lastActive,u=e.cwd,d=ik(e.name,o),f=sk(e,o),h=e.nameLocked&&e.name?e.name:f||(d==="New Session"?e.sessionId.slice(0,8):d),v=SF(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:[m.jsx(Cfe,{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(kfe,{mode:e.mode}),m.jsx("span",{className:"text-muted-foreground/60 shrink-0","aria-hidden":"true",children:"·"}),e.kind!=="terminal"&&m.jsxs(m.Fragment,{children:[m.jsx("span",{className:"font-mono text-muted-foreground shrink-0",children:Jb(e.provider)}),m.jsx("span",{className:"text-muted-foreground/60 shrink-0","aria-hidden":"true",children:"·"})]}),m.jsx("span",{className:We("shrink-0",D1(e).text),children:D1(e).label}),v&&m.jsxs(m.Fragment,{children:[m.jsx("span",{className:"text-muted-foreground/60 shrink-0","aria-hidden":"true",children:"·"}),m.jsx("span",{className:"text-muted-foreground shrink-0 tabular-nums",children:v})]})]})]}),(i||s)&&m.jsxs(Cf,{children:[m.jsx(kf,{asChild:!0,children:m.jsx(dt,{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(yb,{"aria-hidden":"true"})})}),m.jsxs(Tf,{align:"end","data-slot":"session-row-menu",children:[i&&m.jsx(ii,{"data-slot":"session-row-rename-item",onSelect:w=>{w.stopPropagation(),i()},children:"重命名"}),s&&m.jsx(ii,{variant:"destructive","data-slot":"session-row-terminate-item",onSelect:w=>{w.stopPropagation(),s()},children:_})]})]})]})}const Rfe="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=",Afe="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==",Nfe="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 Mfe({shell:e,label:t}){const n=e==="cmd"?Rfe:e==="powershell"?t==="Windows PowerShell"?Nfe:Afe: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 Pfe({session:e,now:t,disabled:n,loading:r,onClick:i,modeTag:s}){const o=m.jsx(Ife,{title:e.title,modeTag:s}),l=m.jsx("span",{className:"text-xs text-muted-foreground tabular-nums",children:SF(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(GY,{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 Ife({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(Ofe,{mode:t})]})}function Ofe({mode:e}){const t=e==="json"?"聊天视图":"终端视图",n=e==="json"?NC:IC;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 EF({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(UK,{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 Lfe({now:e}){const t=Zr(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=ql(N);let D=O.get(L);D||(D=new Map,O.set(L,D));const I=CF(N.projectDir),B=D.get(I);B?B.sessions.push(N):D.set(I,{dir:I,sessions:[N]})}return Array.from(O.entries()).sort(([N],[L])=>xF(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:Yp(D.dir,t,{compact:!0}),sessions:D.sessions}))}))},[n,t]);function A(O){l(O),d(Dfe(O)),h(Bfe(O))}async function P(O,N,L){if(i)return;const D=zt;if(!D){$e.error("请先连接开发机");return}s(O.id);const I=ql(O);try{const B=await D.createSession({kind:"agent",cwd:O.projectDir,mode:N,provider:I,resumeSessionId:O.id,...L?{permissionMode:L}:{}});if(!B.success){if(B.errorCode===Ir.SESSION_ALREADY_ACTIVE){Ut.getState().setCodexActiveWriterConflict({...B.activeWriterPid?{activeWriterPid:B.activeWriterPid}:{}}),l(null);return}$e.error(`恢复失败:${B.error}`);return}if(B.kind!=="agent"){$e.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){$e.error(`恢复失败:${B instanceof Error?B.message:String(B)}`)}finally{s(null)}}function R(){const O=zt;!O||Ut.getState().historyLoadStatus==="loading"||ek(O).then(N=>{N.status==="failed"&&$e.error(N.error instanceof Error?N.error.message:String(N.error))})}function M(O,N){const L=vI(O,N);x(D=>{const I=new Set(D);return I.has(L)?I.delete(L):I.add(L),I})}function z(O){w(N=>{const L=new Set(N);return L.has(O)?L.delete(O):L.add(O),L})}const V=n.length>0,W=r==="loading",G=o?kF(ql(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:()=>V&&g(O=>!O),disabled:!V,"aria-expanded":V?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:["全部会话",V?m.jsxs("span",{className:"ml-1 text-muted-foreground/70 font-normal",children:["· ",n.length]}):null]}),V?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(dt,{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(gm,{className:We("size-3.5",W&&"animate-spin motion-reduce:animate-none"),"aria-hidden":"true"})})]}),!V&&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(Xr,{className:"size-3.5 shrink-0 animate-spin motion-reduce:animate-none","aria-hidden":"true"}),m.jsx("span",{children:"正在加载会话记录..."})]}),!V&&r==="idle"&&m.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/80","data-slot":"history-idle",role:"status",children:"会话记录尚未加载"}),!V&&r==="error"&&m.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/80","data-slot":"history-error",role:"status",children:"会话记录加载失败,请点击刷新重试"}),V&&r==="error"&&m.jsx("div",{className:"px-4 pb-2 text-xs text-muted-foreground/80","data-slot":"history-stale",role:"status",children:"刷新失败,当前显示上次加载的结果"}),!V&&r==="loaded"&&m.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/70","data-slot":"history-empty",children:"暂无会话记录"}),V&&v&&m.jsx("ul",{role:"list",className:"flex flex-col",children:k.map(O=>{const 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:Jb(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=vI(O.provider,L.dir),I=S.has(D);return m.jsxs("li",{children:[m.jsxs("button",{type:"button",onClick:()=>M(O.provider,L.dir),"aria-expanded":I,"data-slot":"history-group-header","data-expanded":I,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",I&&"rotate-90"),"aria-hidden":"true"})]}),I&&m.jsx("ul",{role:"list",className:"flex flex-col",children:L.sessions.map(B=>m.jsx(Pfe,{session:B,now:e,disabled:i!==null,loading:i===B.id,onClick:()=>A(B),modeTag:B.preferredMode},B.id))})]},D)})})]},O.provider)})}),m.jsx(zfe,{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&&ql(o)==="cursor"&&f==="auto"&&h("default")},onPermissionModeChange:h,onConfirm:()=>{o&&P(o,u,f)}})]})}function vI(e,t){return`${e}:${CF(t)}`}function CF(e){const t=e.trim();return!t||t==="/"?t||"/":t.replace(/\/+$/,"")||"/"}function kF(e){return["json","pty"]}function Dfe(e){const t=kF(ql(e));return e.preferredMode&&t.includes(e.preferredMode)?e.preferredMode:t[0]??"pty"}function Bfe(e){return ql(e)==="codex"?"auto":"default"}function zfe({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?ql(e):null,w=_==="codex",S=_==="kimi",x=_==="cursor";b.useEffect(()=>{t||h(!1)},[t]);const T=f?m.jsx(EF,{providerLabel:e?Jb(ql(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(yI,{checked:r==="json",label:"聊天",icon:m.jsx(NC,{className:"size-4","aria-hidden":"true"}),disabled:s,onClick:()=>l("json")}),n.includes("pty")&&m.jsx(yI,{checked:r==="pty",label:"终端",icon:m.jsx(IC,{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(Sv,{checked:i==="default",label:S?"手工审批":x?"命令审批":"严格审批",description:S?"工具调用会在 Web 中请求确认。":x?"Cursor CLI 在执行命令前询问。":"所有需要权限的操作都要确认。",disabled:s,onClick:()=>u("default")}),!(x&&r==="json")&&m.jsx(Sv,{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(Sv,{checked:i==="plan",label:"只读规划",description:x?"Cursor CLI 使用只读规划模式。":"Kimi Code 使用只读规划模式。",disabled:s,onClick:()=>u("plan")}),m.jsx(Sv,{checked:i==="bypassPermissions",label:S?"全自动":"跳过全部审批",description:S?"危险模式,Kimi Code 将全自动执行。":"危险模式,会跳过工具审批和部分沙箱保护。",destructive:!0,disabled:s,onClick:()=>u("bypassPermissions")})]})]})]}),k=m.jsxs(m.Fragment,{children:[m.jsx(dt,{type:"button",variant:"ghost",disabled:s,onClick:()=>{f?h(!1):o(!1)},children:f?"返回":"取消"}),m.jsx(dt,{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(qi,{open:t,onOpenChange:o,children:m.jsxs(Yi,{focusSurfaceOnOpen:!0,className:"min-w-0 sm:max-w-md","data-slot":"history-restore-dialog",children:[m.jsxs(Vi,{className:"min-w-0",children:[m.jsx(Pi,{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(gc,{open:t,onOpenChange:o,children:m.jsxs(vc,{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(yc,{children:f?"跳过全部审批?":"恢复会话"}),m.jsx(Zb,{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 yI({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(ua,{className:We("size-3.5 justify-self-end transition-opacity",e?"opacity-100":"opacity-0"),"aria-hidden":"true"})]})}function Sv({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(ua,{className:We("mt-0.5 size-4 shrink-0",r?"text-destructive":"text-primary"),"aria-hidden":"true"})]})}function Qb({...e}){return m.jsx(Sde,{"data-slot":"select",...e})}function e_({...e}){return m.jsx(Cde,{"data-slot":"select-value",...e})}function t_({className:e,size:t="default",children:n,...r}){return m.jsxs(Ede,{"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(kde,{asChild:!0,children:m.jsx(oc,{className:"size-4 opacity-50"})})]})}function n_({className:e,children:t,position:n="item-aligned",align:r="center",inert:i,"aria-disabled":s,...o}){const l=Nm();return m.jsx(Tde,{children:m.jsxs(Rde,{"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(jfe,{}),m.jsx(Ade,{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(Ffe,{})]})})}function r_({className:e,children:t,...n}){return m.jsxs(Nde,{"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(Pde,{children:m.jsx(ua,{className:"size-4"})})}),m.jsx(Mde,{children:t})]})}function jfe({className:e,...t}){return m.jsx(Ide,{"data-slot":"select-scroll-up-button",className:We("flex cursor-default items-center justify-center py-1",e),...t,children:m.jsx(TC,{className:"size-4"})})}function Ffe({className:e,...t}){return m.jsx(Ode,{"data-slot":"select-scroll-down-button",className:We("flex cursor-default items-center justify-center py-1",e),...t,children:m.jsx(oc,{className:"size-4"})})}function $fe(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=oa((n==null?void 0:n.baseCwd)??"");if(!e)return{currentPath:Ys(r),query:""};const i=Eb(r,e);if(!i)return{currentPath:"",query:""};const s=JC(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 C0(e,t){return Eb(e,t)}const TF=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 _=Zr(ye=>f?ye.treeWithHidden:ye.tree),w=Zr(ye=>ye.cwd),S=Zr(ye=>ye.homePath),x=Re(ye=>ye.selectedProxyId),T=o==="insert"?w:S||w,k=b.useMemo(()=>new Set(_.keys()),[_]),A=b.useMemo(()=>$fe(t,o,{baseCwd:T,knownDirs:k}),[t,o,T,k]),P=A.currentPath,R=b.useMemo(()=>C0(T,P),[T,P]),M=A.query,z=b.useRef(new Map),[V,W]=b.useState(!1),[G,O]=b.useState(""),[N,L]=b.useState(!1),[D,I]=b.useState(null),[B,F]=b.useState(0),[U,j]=b.useState(!1),[Y,X]=b.useState(null),[$,ee]=b.useState(null);b.useEffect(()=>{if(!U)return;let ye=!1;X(null),ee(null);const nt=zt==null?void 0:zt.requestFileSystemRoots();return nt||ee("尚未连接开发机"),nt==null||nt.then(He=>{ye||(He.error!==void 0||He.errorCode!==void 0?ee(He.error||"读取失败"):X(He.roots))},He=>{ye||ee(He instanceof Error?He.message:"读取失败")}),()=>{ye=!0}},[U,x,B]),b.useEffect(()=>{if(!R||U)return;const ye=`${x}\0${f?"hidden":"default"}\0${R}`;if(_.has(R))return;const nt=zt;if(!nt)return;let He=!1;I(Ze=>(Ze==null?void 0:Ze.path)===R?null:Ze);let Ae=z.current.get(ye);if(!Ae){Ae=nt.requestDirectoryList(R,{includeHidden:f}),z.current.set(ye,Ae);const Ze=()=>{z.current.get(ye)===Ae&&z.current.delete(ye)};Ae.then(Ze,Ze)}return Ae.then(Ze=>{if(!He){if(Ze.error!==void 0||Ze.errorCode!==void 0){I({path:R,message:Ze.error||"读取失败"});return}Zr.getState().setDirEntries(Ze.path,Ze.entries,Ze.includeHidden)}},Ze=>{He||I({path:R,message:Ze instanceof Error?Ze.message:"读取失败"})}),()=>{He=!0}},[R,f,_,B,U,x]);const re=U?$?{message:$}:null:(D==null?void 0:D.path)===R?D:null,te=U?Y===null&&!$:!_.has(R)&&!re,Z=b.useMemo(()=>d==null?void 0:d.map(ye=>ye.startsWith(".")?ye.toLowerCase():`.${ye.toLowerCase()}`),[d]),oe=b.useMemo(()=>{if(U){if(!Y)return[];const nt=[...S?[{name:"主目录",path:S}]:[],...Y];return[...new Map(nt.map(He=>[He.path,He])).values()].map(He=>({...He,isDir:!0}))}let ye=_.get(R)??[];return u?ye=ye.filter(nt=>nt.isDir):Z!=null&&Z.length&&(ye=ye.filter(nt=>nt.isDir||Z.some(He=>nt.name.toLowerCase().endsWith(He)))),M&&(ye=ye.filter(nt=>nt.name.toLowerCase().includes(M))),ye},[_,R,M,u,Z,U,Y,S]),[Q,fe]=b.useState(h?0:-1);b.useEffect(()=>fe(h?0:-1),[h,P,M,U]),b.useEffect(()=>{W(!1),O("")},[R]),b.useEffect(()=>{Q>=oe.length&&oe.length>0&&fe(oe.length-1)},[oe.length,Q]);const ge=b.useRef(null),Ce=b.useRef(!1);b.useEffect(()=>{var nt;if(!Ce.current)return;Ce.current=!1;const ye=(nt=ge.current)==null?void 0:nt.querySelector(`[data-entry-index="${Q}"]`);ye==null||ye.scrollIntoView({block:"nearest"})},[Q]);const De=b.useCallback(ye=>{const nt=uu(T),He=`${Ys(P,T)}${ye.name}${ye.isDir?nt:""}`;if(o==="insert")return He.replace(nt==="\\"?/^\.[\\/]/:/^\.\//,"");const Ae=C0(T,He);return ye.isDir?Ys(Ae):Ae},[T,P,o]),ot=b.useCallback(ye=>{const nt=C0(T,ye);if(!nt)return;j(!1);const He=Ys(nt);if(o==="select"){r(He);return}n(He)},[T,o,r,n]),Dt=b.useCallback(ye=>{if(ye.path){ot(ye.path);return}const nt=De(ye);if(ye.isDir){ot(nt);return}n(nt)},[De,ot,n]);async function et(){const ye=p2(R,G);if(!(!ye||!s)){L(!0);try{const nt=await s(ye);if(!nt)return;if(O(""),W(!1),i){i(Ys(nt));return}ot(nt)}finally{L(!1)}}}b.useImperativeHandle(g,()=>({handleKey(ye){return oe.length===0?!1:ye.key==="ArrowDown"?(Ce.current=!0,fe(nt=>Math.min(oe.length-1,nt+1)),!0):ye.key==="ArrowUp"?(Ce.current=!0,fe(nt=>Math.max(0,nt-1)),!0):ye.key==="Enter"&&Q>=0&&!ye.nativeEvent.isComposing?(Dt(oe[Q]),!0):!1}}),[oe,Q,Dt]);const ut=b.useMemo(()=>JC(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?"磁盘/挂载点":Yp(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(ye=>!ye),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===ut?j(!0):ot(ut)},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(ye=>!ye),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]}),V&&!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:ye=>O(ye.target.value),onKeyDown:ye=>{ye.key==="Enter"&&!ye.nativeEvent.isComposing&&(ye.preventDefault(),et()),ye.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:!p2(R,G)||N,onClick:()=>void 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(ye=>!ye),children:U?"返回目录":"磁盘/挂载点"}),m.jsx("span",{className:"truncate font-mono text-xs text-muted-foreground",children:U?"磁盘/挂载点":Yp(R,S)})]}),m.jsx("div",{className:Ue,"data-slot":"file-path-picker-entries",children:re?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:re.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(ye=>ye+1),children:"重试"})]}):oe.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:oe.map((ye,nt)=>m.jsx("li",{children:m.jsxs("button",{type:"button",onClick:()=>Dt(ye),onMouseEnter:()=>fe(nt),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",nt===Q&&"bg-[color-mix(in_srgb,var(--primary)_15%,transparent)]",ye.isDir&&"font-semibold"),"data-slot":"file-entry","data-entry-type":ye.isDir?"dir":"file","data-entry-name":ye.name,"data-entry-index":nt,title:ye.path,children:[m.jsxs("span",{className:"min-w-0 truncate font-mono text-[13px]",children:[ye.name,ye.isDir&&!ye.path?"/":""]}),ye.path&&ye.path!==ye.name?m.jsx("span",{className:"ml-auto min-w-0 truncate text-xs font-normal text-muted-foreground",children:ye.path}):null]})},ye.path??ye.name))})})]})});function bI(e,t,n){const r=pp(e,t);return r?n==="file"?Ys(JC(r)):n==="directory"?Ys(r):r:t}function pp(e,t){const n=oa(e,t);return n?e.endsWith("/")||uu(n)==="\\"&&e.endsWith("\\")?Ys(n):n:""}function Bk({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}`,P=`${A}-label`,R=Zr(te=>te.homePath),M=bo("(pointer: coarse), (hover: none)"),z=bf().deviceKind,V=M||z==="phone"||z==="tablet",[W,G]=b.useState(!1),[O,N]=b.useState(()=>bI(e,R,n)),[L,D]=b.useState(e),I=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 oe=I.current,Q=Z.target;oe&&(Z.composedPath().includes(oe)||Q instanceof Node&&oe.contains(Q))||(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=bI(e,R,n);N(te),D(e),G(!0)}function Y(){G(!1),D(e)}function X(te){const Z=pp(te,R);Z&&(N(Z),D(Z),t(Z),G(!1))}function $(te){const Z=pp(te,R);Z&&N(Z)}function ee(te){var Z;if(W&&((Z=F.current)!=null&&Z.handleKey(te))){te.preventDefault();return}if(te.key==="Escape"&&W){te.preventDefault(),Y();return}T==null||T(te)}const re=W?m.jsx("div",{className:We(V&&"mt-2"),"data-slot":"remote-path-browser",children:m.jsx(TF,{ref:F,mode:"select",placement:V?"inline":"floating",filter:O,dirsOnly:n==="directory",fileExtensions:r,includeHidden:i,autoHighlightFirst:!V,title:l,onNavigate:$,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:P,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:I,className:"relative min-w-0",onBlur:te=>{if(!W||V)return;const Z=te.relatedTarget;Z instanceof Node&&te.currentTarget.contains(Z)||window.setTimeout(()=>{var oe;(oe=I.current)!=null&&oe.contains(document.activeElement)||Y()},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":P,"aria-describedby":_,"aria-invalid":w,name:h,required:v,autoFocus:g&&!V,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off",spellCheck:!1,disabled:o,value:L,"data-slot":S,"data-path-control":"input",onFocus:()=>{V?G(!1):j()},onBlur:()=>D(e),onKeyDown:ee,onChange:te=>{const Z=te.target.value,oe=pp(Z,R);D(Z),N(oe||R),t(oe||Z),G(!V)},onPaste:te=>{const Z=te.clipboardData.getData("text").trim(),oe=Z.startsWith('"')&&Z.endsWith('"')?Z.slice(1,-1):Z,Q=pp(oe,R);Q&&(te.preventDefault(),D(Q),N(Q),t(Q),G(!V))},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;V&&((te=B.current)==null||te.blur()),W?Y():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(WV,{className:"size-5","aria-hidden":"true"})})]}),m.jsx("div",{id:`${A}-browser`,children:re})]})]})}const _I="工作目录不存在或不可访问:",Hfe=[{value:"default",label:"严格审批"},{value:"auto",label:"自动判定"},{value:"acceptEdits",label:"自动接受编辑"},{value:"plan",label:"只读规划"},{value:"bypassPermissions",label:"跳过全部审批"}],RF=[{value:"auto",label:"按需审批"},{value:"bypassPermissions",label:"跳过全部审批"}],AF=[{value:"default",label:"手工审批"},{value:"auto",label:"自动审批"},{value:"plan",label:"只读规划"},{value:"bypassPermissions",label:"全自动"}],zk=[{value:"default",label:"命令审批"},{value:"auto",label:"智能自动"},{value:"plan",label:"只读规划"},{value:"bypassPermissions",label:"跳过全部审批"}],NF=zk.filter(e=>e.value!=="auto"),Jp={claude:"Claude Code",codex:"Codex",kimi:"Kimi Code",cursor:"Cursor CLI"};function Ufe(e,t){return t!==Ir.PATH_NOT_FOUND||!e.startsWith(_I)?null:e.slice(_I.length).trim()||null}function MF(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 Wfe(e,t,n="pty"){return e==="codex"?RF.some(r=>r.value===t)?t:"auto":e==="kimi"?AF.some(r=>r.value===t)?t:"default":e==="cursor"?(n==="json"?NF:zk).some(i=>i.value===t)?t:"default":t}async function qfe({relay:e,agentCli:t,form:n,timeoutMs:r=XC}){var d,f;const i=n.cwd.trim();if(!i)return{type:"validation_error",message:"请输入工作目录"};if(!e)return{type:"relay_missing",message:"请先连接开发机"};if(MF(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?`${Jp[n.provider]} 不可用:${h}`:`${Jp[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=Ufe(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 Yfe({relay:e,shell:t,timeoutMs:n=XC}){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 Vfe=["claude","codex","kimi","cursor"];function Kfe({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(Qb,{value:t,disabled:i,onValueChange:_=>s(_),children:[m.jsx(t_,{className:"min-h-11 w-full md:min-h-0","aria-label":"Agent CLI","data-slot":"agent-cli-provider-select",children:m.jsx(e_,{})}),m.jsx(n_,{"data-slot":"agent-cli-provider-options",children:Vfe.map(_=>m.jsx(r_,{value:_,className:"min-h-11 md:min-h-0",children:Jp[_]},_))})]}),m.jsxs("div",{className:"relative min-w-0","data-slot":"agent-cli-path-card",children:[m.jsx(Bk,{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({open:e,onOpenChange:t}){var Z;const[n,r]=b.useState(""),[i,s]=b.useState(""),[o,l]=b.useState("claude"),[u,d]=b.useState("pty"),[f,h]=b.useState("default"),[v,g]=b.useState(!1),[_,w]=b.useState(!1),[S,x]=b.useState(null),[T,k]=b.useState(null),[A,P]=b.useState(""),[R,M]=b.useState(!1),z=b.useRef(e);z.current=e;const V=ks(),W=Zr(oe=>oe.homePath),G=Zr(oe=>oe.agentCli),O=bo("(min-width: 768px)");b.useEffect(()=>{e&&!i&&W&&s(W)},[e,W,i]),b.useEffect(()=>{if(!e||W&&G)return;const oe=zt==null?void 0:zt.requestProxyInfo();oe&&oe.then(Q=>{const fe=Zr.getState();fe.setHomePath(Q.homePath),fe.setAgentCli(Q.agentCli)}).catch(Q=>{console.error("[create-session-dialog] requestProxyInfo failed",Q)})},[e,W,G]);function N(){r(""),s(""),l("claude"),d("pty"),h("default"),g(!1),x(null),k(null),P(""),M(!1)}function L(){if(f==="bypassPermissions"){g(!0);return}Y()}async function D(){await Y(),z.current&&g(!1)}const I=o==="codex"?RF:o==="kimi"?AF:o==="cursor"?u==="json"?NF:zk:Hfe,B=MF(o,G),F=T===o&&A.trim()!==(((Z=G==null?void 0:G[o])==null?void 0:Z.command)??""),U=_||R||B.disabled||F;function j(oe,Q=u){const fe=Wfe(oe,f,Q);fe!==f&&h(fe)}async function Y(oe){x(null),w(!0);try{const Q=await qfe({relay:zt,agentCli:G,form:{cwd:oe??i,name:n,provider:o,permissionMode:f,mode:u}});if(Q.type==="success"){if(Ut.getState().addSession(Q.session),!z.current)return;t(!1),N(),V(Q.route);return}if(Q.type==="missing_cwd"&&x(Q.path),$e.error(Q.message),Q.type==="validation_error"||Q.type==="relay_missing")return}finally{w(!1)}}async function X(oe){const Q=zt;if(!Q)return $e.error("请先连接开发机"),null;try{const fe=await Q.createDirectory(oe);return fe.success?(x(null),$e.success("目录已创建"),fe.path):($e.error(`目录创建失败:${fe.error??"未知错误"}`),null)}catch(fe){return $e.error(fe instanceof Error?fe.message:String(fe)),null}}function $(oe,Q){k(oe),P(Q)}async function ee(){if(!T)return;const oe=T,Q=A.trim();if(!Q){$e.error("请选择 Agent CLI 可执行文件");return}const fe=zt;if(!fe){$e.error("请先连接开发机");return}M(!0);try{const ge=await fe.updateAgentCliPath(oe,Q);if(ge.error||!ge.agentCli){$e.error(`路径保存失败:${ge.error??"未知错误"}`);return}Zr.getState().setAgentCli(ge.agentCli),$e.success(`${Jp[oe]} 路径已保存`),k(null),P("")}catch(ge){$e.error(ge instanceof Error?ge.message:String(ge))}finally{M(!1)}}function re(oe){d(oe),j(o,oe)}const te=v?m.jsxs("div",{className:"grid min-w-0 gap-5","data-slot":"bypass-permission-confirmation",children:[m.jsx(EF,{providerLabel:Jp[o]}),m.jsxs(Gs,{children:[m.jsx(dt,{type:"button",variant:"ghost",className:"min-h-11 md:min-h-0",onClick:()=>g(!1),disabled:_,children:"返回"}),m.jsx(dt,{type:"button",variant:"destructive",className:"min-h-11 md:min-h-0",onClick:()=>void D(),disabled:_,"data-slot":"bypass-permission-confirm",children:_?"创建中...":"确认"})]})]}):m.jsxs("form",{className:"flex min-w-0 flex-col gap-4","data-slot":"create-session-form",autoComplete:"off",onSubmit:oe=>{oe.preventDefault(),L()},children:[m.jsxs("label",{className:"flex min-w-0 flex-col gap-1",children:[m.jsx("span",{className:"text-sm",children:"名称(可选)"}),m.jsx("input",{type:"text",name:"dev-anywhere-session-name",autoComplete:"off",autoCorrect:"off",spellCheck:!1,value:n,onChange:oe=>r(oe.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(Bk,{id:"create-session-cwd",name:"dev-anywhere-session-cwd","data-slot":"create-session-cwd",label:"工作目录",value:i,selectionKind:"directory",placeholder:"选择工作目录",onCreateDirectory:X,onValueChange:oe=>{s(oe),x(null)}}),S?m.jsxs("section",{role:"status","aria-live":"polite",className:"rounded-md border border-primary/50 bg-primary/10 p-3",children:[m.jsx("p",{className:"text-sm font-medium",children:"工作目录不存在"}),m.jsx("p",{className:"mt-1 break-all font-mono text-xs text-muted-foreground",children:S})]}):null,m.jsxs("section",{"aria-label":"交互方式",className:"flex min-w-0 flex-col gap-2",children:[m.jsx("span",{className:"text-sm",children:"交互方式"}),m.jsxs("div",{className:We("grid min-w-0 gap-2","grid-cols-1 sm:grid-cols-2"),children:[m.jsxs("button",{type:"button","aria-pressed":u==="pty",onClick:()=>re("pty"),className:We("flex min-h-14 min-w-0 flex-col items-start justify-center gap-1 rounded-md border px-3 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring",u==="pty"?"border-primary/70 bg-primary/10":"border-border bg-muted/20"),children:[m.jsx("span",{className:"text-sm font-medium",children:"终端模式"}),m.jsx("span",{className:"text-xs text-muted-foreground",children:"像本地终端一样操作"})]}),m.jsxs("button",{type:"button","aria-pressed":u==="json",onClick:()=>re("json"),className:We("flex min-h-14 min-w-0 flex-col items-start justify-center gap-1 rounded-md border px-3 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring",u==="json"?"border-primary/70 bg-primary/10":"border-border bg-muted/20"),children:[m.jsx("span",{className:"text-sm font-medium",children:"聊天模式"}),m.jsx("span",{className:"text-xs text-muted-foreground",children:"气泡式对话,支持 Voice Pilot"})]})]})]}),m.jsx(Kfe,{agentCli:G,provider:o,cliPathDraftProvider:T,cliPathDraft:A,savingCliPath:R,onProviderChange:oe=>{l(oe),j(oe),k(null),P("")},onCliPathDraftChange:$,onDiscardCliPathDraft:()=>{k(null),P("")},onSaveCliPath:()=>void ee()}),m.jsxs("label",{className:"flex min-w-0 flex-col gap-2",children:[m.jsx("span",{className:"text-sm",children:"权限模式"}),m.jsxs(Qb,{value:f,onValueChange:oe=>h(oe),children:[m.jsx(t_,{className:"w-full",children:m.jsx(e_,{})}),m.jsx(n_,{children:I.map(oe=>m.jsx(r_,{value:oe.value,children:oe.label},oe.value))})]})]}),m.jsxs(Gs,{children:[m.jsx(dt,{type:"button",variant:"ghost",className:"min-h-11 md:min-h-0",onClick:()=>t(!1),disabled:_,children:"取消"}),m.jsx(dt,{type:"submit",className:"min-h-11 md:min-h-0",disabled:U,children:_?"创建中...":"创建"})]})]});return O?m.jsx(qi,{open:e,onOpenChange:t,children:m.jsxs(Yi,{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(Vi,{children:m.jsx(Pi,{children:v?"跳过全部审批?":"新建会话"})}),te]})}):m.jsx(gc,{open:e,onOpenChange:t,children:m.jsxs(vc,{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(yc,{children:v?"跳过全部审批?":"新建会话"})}),te]})})}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(qi,{open:e,onOpenChange:r,children:m.jsx(Yi,{className:"sm:max-w-md","data-slot":"session-rename-dialog",children:m.jsxs("form",{className:"grid gap-4",onSubmit:g=>void v(g),children:[m.jsxs(Vi,{children:[m.jsx(Pi,{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(dt,{type:"button",variant:"outline",onClick:()=>r(!1),children:"取消"}),m.jsx(dt,{type:"submit",disabled:f,children:"保存"})]})]})})})}function Gfe(e){return(e==null?void 0:e.kind)==="agent"&&e.mode==="pty"&&e.ptyOwner==="local-terminal"}function Xfe(e){return(e==null?void 0:e.kind)==="terminal"}function Zfe(e){return Gfe(e)?{title:"断开远程连接?",description:"这只会断开当前页面和本地终端的连接,本地终端里的 Claude Code/Codex/Kimi Code/Cursor CLI 会继续运行。重新接入前,页面不能继续查看或输入这个会话。",confirmLabel:"断开远程连接",destructive:!1}:Xfe(e)?{title:"终止终端?",description:"这会停止当前终端进程,并清理这个终端会话的运行状态。终止后不能继续输入,也无法恢复正在执行的命令。",confirmLabel:"终止终端",destructive:!0}:{title:"终止会话?",description:"这会停止当前 Agent 进程,并清理这个会话的运行状态。终止后不能继续输入,也无法恢复正在执行的任务。",confirmLabel:"终止会话",destructive:!0}}function Ev({open:e,session:t,onOpenChange:n,onConfirm:r}){const i=Zfe(t);function s(){t&&(r(t),n(!1))}return m.jsx(qi,{open:e,onOpenChange:n,children:m.jsxs(Yi,{"data-slot":"session-termination-dialog",children:[m.jsxs(Vi,{children:[m.jsx(Pi,{children:i.title}),m.jsx(fs,{children:i.description})]}),m.jsxs(Gs,{children:[m.jsx(dt,{type:"button",variant:"ghost",onClick:()=>n(!1),children:"取消"}),m.jsx(dt,{type:"button",variant:i.destructive?"destructive":"default",onClick:s,"data-slot":"session-termination-confirm",children:i.confirmLabel})]})]})})}function PF(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 Jfe(e){if(e.session.state==="error")return"error";const t=PF(e);return t==="disconnected"?e.session.state:t}const Qfe=new Set(["localhost","127.0.0.1","[::1]"]),B1={cloudflare:{label:"Cloudflare Tunnel",executable:"cloudflared",installUrl:"https://developers.cloudflare.com/tunnel/downloads/"},cpolar:{label:"Cpolar",executable:"cpolar"}};function ehe(){return Mi("local",Tn.webPreviewTunnelProvider)==="cpolar"?"cpolar":"cloudflare"}function IF(e,t){if(e)return t==="cloudflare"?e.cloudflared:e.cpolar}function k0(e,t){var n;return((n=IF(e,t))==null?void 0:n.available)===!0}function the(e){const t=e.trim();if(!t)return"请输入本机网站地址";let n;try{n=new URL(t)}catch{return"请输入完整的 http:// 本机网站地址"}return n.protocol!=="http:"||!Qfe.has(n.hostname)||n.username!==""||n.password!==""?"只支持 localhost、127.0.0.1 或 [::1] 的 http:// 地址":null}function Bh(){return{status:"idle"}}function nhe({open:e,onOpenChange:t}){const[n,r]=b.useState(""),[i,s]=b.useState(ehe),[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),P=b.useRef(null),R=b.useRef(i);R.current=i;const M=b.useRef(e);M.current=e;const z=bo("(min-width: 768px)"),V=Re(te=>te.selectedProxyId),W=Vr(te=>te.capability),G=Vr(te=>te.capabilityStatus),O=Vr(te=>te.capabilityError),N=Vr(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),Pr("local",Tn.webPreviewTunnelProvider,te)},[]);function I(){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,P.current=null}const B=b.useCallback(async te=>{var Q;(Q=T.current)==null||Q.abort();const Z=new AbortController;T.current=Z;const oe=Pt.getActiveScope();if(!(!oe||oe.proxyId!==V))try{const fe=await Pt.requestWebPreviewCapability(oe,te,{signal:Z.signal});if(!fe||Z.signal.aborted||!M.current||!fe.success)return;const ge=R.current,Ce=ge==="cloudflare"?"cpolar":"cloudflare";!k0(fe.capability,ge)&&k0(fe.capability,Ce)&&D(Ce)}catch{}},[D,V]);function F(te){!te&&S||t(te)}b.useEffect(()=>{if(!e){I();return}return B(!1),()=>{var te;(te=T.current)==null||te.abort(),T.current=null}},[B,e,L]),b.useEffect(()=>{var Q;if(!e||o!=="static")return;(Q=k.current)==null||Q.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 oe=window.setTimeout(()=>{const fe=zt,ge=Pt.getActiveScope();if(!fe||!ge||ge.proxyId!==V){w({status:"error",message:"请先连接开发机"});return}Pt.inspectStaticWebPreview(ge,te,{signal:Z.signal}).then(Ce=>{if(!Ce||Z.signal.aborted||!M.current||!Pt.isActive(fe,ge))return;if(!Ce.success){w({status:"error",message:Ce.error});return}const De=Ce.htmlEntries;if(De.length===0&&!Ce.entryPath){w({status:"error",message:"这里没有可以预览的网页"});return}const ot={entryPath:Ce.entryPath,htmlEntries:De};w({status:"ready",path:te,result:ot}),g(Ce.entryPath??"")}).catch(Ce=>{Z.signal.aborted||!M.current||Ce instanceof Error&&Ce.name==="AbortError"||!Pt.isActive(fe,ge)||w({status:"error",message:Ce instanceof Error?Ce.message:"检查网页失败"})})},300);return()=>{window.clearTimeout(oe),Z.abort(),k.current===Z&&(k.current=null)}},[e,L,V,o,f]);const U=o==="local"?the(u):null,j=o==="static"&&_.status==="ready"&&_.path===f.trim()&&!!(_.result.entryPath||v),Y=G==="loaded"&&k0(W,i),$=S||!Y||!(o==="local"?U===null:j);async function ee(){var fe,ge,Ce;if($)return;const te=zt;if(!te){$e.error("请先连接开发机");return}let Z;if(o==="local")Z={kind:"local",url:u.trim()};else{if(_.status!=="ready"||_.path!==f.trim())return;const De=_.result.entryPath??v;if(!De)return;Z={kind:"static",path:_.path,entryPath:De}}x(!0);const oe=Pt.getActiveScope();if(!oe){x(!1),$e.error("请先连接开发机");return}let Q=null;try{const De=n.trim(),ot=JSON.stringify({proxyId:oe.proxyId,tunnelProvider:i,source:Z,name:De||void 0});((fe=A.current)==null?void 0:fe.sourceKey)!==ot&&(A.current={sourceKey:ot,operationId:ym(`preview-operation-${i}`)}),Q=A.current.operationId,P.current=Q;const Dt=await Pt.createWebPreview(oe,Z,{tunnelProvider:i,operationId:Q,...De?{name:De}:{}});if(P.current!==Q)return;if(!Dt.accepted){((ge=A.current)==null?void 0:ge.operationId)===Q&&(A.current=null),$e.error(Dt.error);return}if(((Ce=A.current)==null?void 0:Ce.operationId)===Q&&(A.current=null),!M.current||!Pt.isActive(te,oe))return;t(!1)}catch(De){if(!Q||P.current!==Q||!M.current||!Pt.isActive(te,oe))return;$e.error(De instanceof Error?De.message:"无法创建网页预览")}finally{Q&&P.current===Q&&(P.current=null,M.current&&x(!1))}}const re=m.jsxs("form",{className:"flex min-w-0 flex-col gap-4","data-slot":"create-web-preview-form",autoComplete:"off",onSubmit:te=>{te.preventDefault(),ee()},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(Qb,{value:i,disabled:S,onValueChange:te=>D(te),children:[m.jsx(t_,{"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(e_,{})}),m.jsx(n_,{"data-slot":"web-preview-tunnel-provider-options",children:Object.keys(B1).map(te=>m.jsx(r_,{value:te,"data-slot":"web-preview-tunnel-provider-option","data-provider":te,children:B1[te].label},te))})]})]}),m.jsx(rhe,{status:G,capability:W,provider:i,error:O,disabled:S,onRetry:()=>void B(!0)}),m.jsxs("section",{"aria-label":"网页来源",className:"flex min-w-0 flex-col gap-2",children:[m.jsx("span",{className:"text-sm",children:"网页来源"}),m.jsxs("div",{className:"grid min-w-0 grid-cols-1 gap-2 sm:grid-cols-2",children:[m.jsxs("button",{type:"button","data-slot":"web-preview-source-local",disabled:S,"aria-pressed":o==="local",onClick:()=>{var te;(te=k.current)==null||te.abort(),k.current=null,w(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(Bk,{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(ihe,{inspection:_,selectedEntryPath:v,disabled:S,onEntryPathChange:te=>{g(te)}})]}),m.jsxs(Gs,{children:[m.jsx(dt,{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(dt,{type:"submit",className:"min-h-11 md:min-h-0",disabled:$,"data-slot":"create-web-preview-submit",children:S?"正在创建...":"创建预览"})]})]});return z?m.jsx(qi,{open:e,onOpenChange:F,children:m.jsxs(Yi,{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(Vi,{children:[m.jsx(Pi,{children:"新建网页预览"}),m.jsx(fs,{children:"输入本机网站地址,或选择 HTML 网页文件或目录。"})]}),re]})}):m.jsx(gc,{open:e,onOpenChange:F,children:m.jsxs(vc,{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(yc,{children:"新建网页预览"}),m.jsx(Zb,{children:"输入本机网站地址,或选择 HTML 网页文件或目录。"})]}),re]})})}function rhe({status:e,capability:t,provider:n,error:r,disabled:i,onRetry:s}){const o=B1[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(Xr,{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(Pz,{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(wI,{onClick:s,disabled:i})]})});const l=IF(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(vV,{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(wI,{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(cV,{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 wI({onClick:e,disabled:t}){return m.jsxs(dt,{type:"button",variant:"outline",size:"sm","data-slot":"web-preview-capability-retry",className:"shrink-0",onClick:e,disabled:t,children:[m.jsx(gm,{className:"size-3.5","aria-hidden":"true"}),"重新检测"]})}function ihe({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(Xr,{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(Qb,{value:t,onValueChange:r,disabled:n,children:[m.jsx(t_,{"data-slot":"web-preview-entry-select",className:"w-full font-mono",children:m.jsx(e_,{placeholder:"选择网页"})}),m.jsx(n_,{children:e.result.htmlEntries.map(o=>m.jsx(r_,{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 z1={ios:"iOS Simulator",android:"Android Emulator"};function she({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(S5),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 P=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]),V=b.useMemo(()=>M.filter(F=>!z.has(F.targetId)),[z,M]),W=V.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=zt,Y=Pt.getActiveScope();if(!(!j||!Y||Y.proxyId!==s))try{const $=await Pt.requestDevicePreviewCapability(Y,F,{signal:U.signal});if(!$||U.signal.aborted||!A.current||!$.success)return;await Pt.requestDevicePreviewTargets(Y,!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),P.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&&V.length===1&&S(V[0].targetId)}},[e,V,W,w]);async function N(){var X,$,ee;const F=W;if(!F||x||(G==null?void 0:G.available)!==!0)return;const U=zt,j=Pt.getActiveScope();if(!U||!j||j.proxyId!==s){$e.error("请先连接开发机");return}T(!0);let Y=null;try{const re=g.trim(),te=((X=P.current)==null?void 0:X.proxyId)===j.proxyId&&P.current.targetId===F.targetId&&P.current.name===re?P.current:{proxyId:j.proxyId,targetId:F.targetId,name:re,operationId:ym("device-preview-operation")};P.current=te,Y=te.operationId,R.current=Y;const Z=await Pt.createDevicePreview(j,F.targetId,{operationId:te.operationId,...re?{name:re}:{}});if(R.current!==te.operationId)return;if(!Z.accepted){if((($=P.current)==null?void 0:$.operationId)===te.operationId&&(P.current=null),!A.current||!Pt.isActive(U,j))return;$e.error(Z.error);return}if(((ee=P.current)==null?void 0:ee.operationId)===te.operationId&&(P.current=null),!A.current||!Pt.isActive(U,j))return;n(!1),r(`/preview/device/${Z.previewId}`)}catch(re){if(!Y||R.current!==Y||!A.current||!Pt.isActive(U,j))return;$e.error(re instanceof Error?re.message:"无法创建模拟器预览")}finally{Y&&R.current===Y&&(R.current=null,A.current&&T(!1))}}function L(F){var U;!F&&x||(F||((U=k.current)==null||U.abort(),k.current=null,P.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(ohe,{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(Xr,{className:"size-4 animate-spin","aria-hidden":"true"}),"正在查找已启动的模拟器..."]}):u==="error"?m.jsx(xI,{message:d??"无法读取模拟器列表"}):M.length===0?m.jsx(xI,{message:`没有已启动的 ${z1[t]}`}):M.map(F=>{const U=F.targetId===w,j=z.has(F.targetId);return m.jsx(ahe,{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(dt,{type:"button",variant:"outline",disabled:x||u==="loading",onClick:()=>void O(!0),"data-slot":"device-preview-refresh",children:[m.jsx(gm,{className:"size-4","aria-hidden":"true"}),"重新检测"]}),m.jsx(dt,{type:"button",disabled:!W||x||(G==null?void 0:G.available)!==!0,onClick:()=>void N(),"data-slot":"create-device-preview-submit",children:x?"正在创建...":"创建预览"})]})]}),I=`新建 ${z1[t]} 预览`,B="选择开发机上已经启动的模拟器。";return i?m.jsx(qi,{open:e,onOpenChange:L,children:m.jsxs(Yi,{showCloseButton:!x,className:"sm:max-w-xl","data-slot":"create-device-preview-dialog","data-platform":t,focusSurfaceOnOpen:!0,children:[m.jsxs(Vi,{children:[m.jsx(Pi,{children:I}),m.jsx(fs,{children:B})]}),D]})}):m.jsx(gc,{open:e,onOpenChange:L,children:m.jsxs(vc,{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(yc,{children:I}),m.jsx(Zb,{children:B})]}),D]})})}function ohe({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"?`${z1[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(Pz,{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 xI({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 ahe({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(Ny,{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(ua,{className:"size-4 text-primary","aria-hidden":"true"}):null]})}function OF({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(T0,{icon:m.jsx(Oz,{className:"size-5","aria-hidden":"true"}),title:"网页",description:"通过临时链接访问或分享本机网页",slot:"frontend-preview-web",onClick:()=>r("web")}),m.jsx(T0,{icon:m.jsx(Ny,{className:"size-5","aria-hidden":"true"}),title:"iOS Simulator",description:"查看和操控开发机上已启动的 iPhone 或 iPad 模拟器",slot:"frontend-preview-ios",onClick:()=>r("ios")}),m.jsx(T0,{icon:m.jsx(Ny,{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(qi,{open:d,onOpenChange:f=>!f&&o(),children:m.jsxs(Yi,{className:"sm:max-w-lg","data-slot":"create-frontend-preview-dialog",children:[m.jsxs(Vi,{children:[m.jsx(Pi,{children:"新建预览"}),m.jsx(fs,{children:"选择预览类型。"})]}),l]})},"chooser"):m.jsx(gc,{open:d,onOpenChange:f=>!f&&o(),children:m.jsxs(vc,{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(yc,{children:"新建预览"}),m.jsx(Zb,{children:"选择预览类型。"})]}),l]})},"chooser");case"web":return m.jsx(nhe,{open:d,onOpenChange:f=>!f&&o()},"web");case"ios":case"android":return m.jsx(she,{open:d,platform:u,onOpenChange:f=>!f&&o()},u);case null:return null}}function T0({icon:e,title:t,description:n,slot:r,onClick:i}){return m.jsxs(dt,{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 lhe({preview:e,closing:t,onOpenChange:n,onConfirm:r}){return m.jsx(qi,{open:e!==null,onOpenChange:n,children:m.jsxs(Yi,{"data-slot":"device-preview-close-dialog",children:[m.jsxs(Vi,{children:[m.jsx(Pi,{children:"停止预览?"}),m.jsx(fs,{children:"模拟器会继续在开发机上运行。"})]}),m.jsxs(Gs,{children:[m.jsx(dt,{type:"button",variant:"ghost",disabled:t,onClick:()=>n(!1),children:"取消"}),m.jsx(dt,{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 uhe({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(Ny,{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(kC,{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(dt,{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(Xr,{className:"animate-spin","aria-hidden":"true"}):m.jsx(yb,{"aria-hidden":"true"})})}),m.jsxs(Tf,{align:"end","data-slot":"device-preview-row-menu",children:[m.jsx(ii,{"data-slot":"device-preview-row-rename-item",onSelect:r,children:"重命名"}),d?m.jsx(ii,{"data-slot":"device-preview-row-reconnect-item",onSelect:i,children:"重新连接"}):null,m.jsx(Hl,{}),m.jsx(ii,{variant:"destructive","data-slot":"device-preview-row-close-item",onSelect:s,children:"停止预览"})]})]})]})}function dhe({preview:e,closing:t,onOpenChange:n,onConfirm:r}){return m.jsx(qi,{open:e!==null,onOpenChange:n,children:m.jsxs(Yi,{"data-slot":"preview-close-dialog",children:[m.jsxs(Vi,{children:[m.jsx(Pi,{children:"关闭预览?"}),m.jsx(fs,{children:"关闭后,当前预览链接将立即失效。"})]}),m.jsxs(Gs,{children:[m.jsx(dt,{type:"button",variant:"ghost",disabled:t,onClick:()=>n(!1),children:"取消"}),m.jsx(dt,{type:"button",variant:"destructive",disabled:!e||t,onClick:()=>e&&r(e),"data-slot":"preview-close-confirm",children:t?"正在关闭...":"关闭预览"})]})]})})}function fhe({target:e,onOpenChange:t,onRename:n}){return m.jsx(hhe,{target:e,onOpenChange:t,onRename:n},(e==null?void 0:e.targetKey)??"closed")}function hhe({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(qi,{open:e!==null,onOpenChange:f,children:m.jsx(Yi,{showCloseButton:!l,className:"sm:max-w-md","data-slot":"preview-rename-dialog",children:m.jsxs("form",{className:"grid gap-4",onSubmit:v=>void h(v),children:[m.jsx(Vi,{children:m.jsx(Pi,{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(dt,{type:"button",variant:"outline",disabled:l,onClick:()=>f(!1),children:"取消"}),m.jsx(dt,{type:"submit",disabled:l,"data-slot":"preview-rename-submit",children:"保存"})]})]})})})}const phe={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:Eb(e.source.rootPath,e.source.entryPath)}async function ghe(e){if(await Vp(e,{allowUserGestureFallback:!0})==="failed"){$e.error("复制失败,请稍后重试");return}$e.success("链接已复制")}async function vhe(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;$e.error("无法打开系统分享面板")}}function yhe({preview:e,pendingOperation:t,onRename:n,onReconnect:r,onClose:i}){const s=Zr(w=>w.homePath),o=phe[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"?Yp(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(Oz,{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(dt,{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(Xr,{className:"animate-spin","aria-hidden":"true"}):m.jsx(yb,{"aria-hidden":"true"})})}),m.jsxs(Tf,{align:"end","data-slot":"preview-row-menu",children:[m.jsx(ii,{"data-slot":"preview-row-rename-item",onSelect:n,children:"重命名"}),d?m.jsx(ii,{"data-slot":"preview-row-copy-item",onSelect:()=>void ghe(u),children:"复制链接"}):null,h?m.jsx(ii,{"data-slot":"preview-row-share-item",onSelect:()=>void vhe(e.name,u),children:"分享…"}):null,f?m.jsx(ii,{"data-slot":"preview-row-reconnect-item",onSelect:r,children:"重新连接"}):null,m.jsx(Hl,{}),m.jsx(ii,{variant:"destructive","data-slot":"preview-row-close-item",onSelect:i,children:"关闭预览"})]})]})]})}const bhe=Object.freeze([]),_he=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"?Vr.getState().authoritative:mr.getState().authoritative;return!n||!vp(e,t,n.scope)?!1:n.previews.some(r=>r.previewId===e.previewId)}function Wo(e){const t=Pt.getActiveScope();return t!==null&&rn(t,e)}function SI(){const e=Vr(N=>N.authoritative),t=mr(N=>N.authoritative),n=Jo(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:bhe,l=s&&t?t.previews:_he,u=bz("/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 I;return(I=b5(n,N,L,D)[0])==null?void 0:I.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(!Wo(N.scope))return;L.success||$e.error(L.error)}catch(L){if(!Wo(N.scope))return;$e.error(L instanceof Error?L.message:"无法重新连接网页预览")}}async function P(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(I){if(!Wo(N.scope))return;throw I}if(Wo(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(!Wo(N.scope))return;if(!L.success){$e.error(L.error);return}h(D=>Uc(D,N)?null:D)}catch(L){if(!Wo(N.scope))return;$e.error(L instanceof Error?L.message:"无法关闭网页预览")}}async function M(N){if(zh(N))try{const L=await Pt.reconnectDevicePreview(N.scope,N.previewId);if(!Wo(N.scope))return;L.success||$e.error(L.error)}catch(L){if(!Wo(N.scope))return;$e.error(L instanceof Error?L.message:"无法重新连接模拟器预览")}}async function z(N){if(zh(N))try{const L=await Pt.closeDevicePreview(N.scope,N.previewId);if(!Wo(N.scope))return;if(!L.success){$e.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(!Wo(N.scope))return;$e.error(L instanceof Error?L.message:"无法停止模拟器预览")}}const V=(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(yhe,{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(uhe,{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(fhe,{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?P(G,N):Promise.resolve()}),m.jsx(dhe,{preview:x,closing:V,onOpenChange:N=>{!N&&!V&&O&&h(L=>Uc(L,O)?null:L)},onConfirm:()=>O&&void R(O)}),m.jsx(lhe,{preview:T,closing:W,onOpenChange:N=>{!N&&!W&&O&&h(L=>Uc(L,O)?null:L)},onConfirm:()=>O&&void z(O)})]})}function LF({layout:e}){const t=Ut(Q=>Q.sessions),n=Ut(Q=>Q.sessionListLoaded),r=Ut(Q=>Q.agentStatusBySessionId),i=Ut(Q=>Q.ptyStateBySessionId),s=Ut(Q=>Q.renameSession),o=ln(Q=>Q.bySessionId),l=bz("/chat/:id"),u=(l==null?void 0:l.params.id)??null,d=Re(Q=>!!Q.selectedProxyId),f=Re(Q=>Q.proxyListLoaded),h=Re(Q=>Q.proxySwitchTarget),v=Ut(Q=>Q.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),[P,R]=b.useState(!1),[M,z]=b.useState(!1),[V,W]=b.useState(null),[G,O]=b.useState(null),{creatingTerminal:N,creatingShell:L,createTerminal:D}=DF(),[I,B]=b.useState(new Set),[F,U]=b.useState(()=>Date.now());b.useEffect(()=>{const Q=setInterval(()=>U(Date.now()),6e4);return()=>clearInterval(Q)},[]);function j(Q,fe){S(`/chat/${Q}?mode=${fe}`,{replace:!1})}function Y(Q){const fe=Q.sessionId,ge=zt;if(!ge){$e.error("请先连接开发机");return}ge.sendControl({type:"session_terminate",sessionId:fe}),Ut.getState().removeSession(fe),ln.getState().clearSession(fe),fe===u&&S("/sessions"),(Q==null?void 0:Q.kind)==="agent"&&Q.mode==="pty"&&Q.ptyOwner==="local-terminal"?$e.info("已断开页面连接,本地终端仍在运行"):$e.info("正在终止会话",{duration:1500})}async function X(Q,fe){const ge=zt;if(!ge)throw new Error("请先连接开发机");const Ce=await ge.renameSession(Q,fe);if(!Ce.success)throw new Error(Ce.error??"重命名失败");s(Q,Ce.name??fe),$e.success("已重命名会话")}function $(Q){B(fe=>{const ge=new Set(fe);return ge.has(Q)?ge.delete(Q):ge.add(Q),ge})}function ee(Q){var Ce;const fe=Q.mode==="json"&&(((Ce=o[Q.sessionId])==null?void 0:Ce.pendingApprovals.some(De=>De.status==="pending"))??!1),ge=Jfe({session:Q,agentStatus:r[Q.sessionId],ptyState:i[Q.sessionId],hasPendingApproval:fe});return ge===Q.state?Q:{...Q,state:ge}}const re=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(Ev,{open:G!==null,session:G,onOpenChange:Q=>{Q||O(null)},onConfirm:Y}),m.jsx(gp,{open:V!==null,sessionId:(V==null?void 0:V.sessionId)??null,initialName:V==null?void 0:V.name,onOpenChange:Q=>{Q||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(Xr,{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(Ev,{open:G!==null,session:G,onOpenChange:Q=>{Q||O(null)},onConfirm:Y}),m.jsx(gp,{open:V!==null,sessionId:(V==null?void 0:V.sessionId)??null,initialName:V==null?void 0:V.name,onOpenChange:Q=>{Q||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:["活跃会话",re?m.jsxs("span",{className:"ml-1 text-muted-foreground/70 font-normal",children:["· ",t.length]}):null]}),Z=re?m.jsx("ul",{role:"list",className:"flex flex-col w-full min-w-0",children:whe(t).map(Q=>m.jsxs("li",{children:[m.jsxs("button",{type:"button",onClick:()=>$(Q.provider),"aria-expanded":!I.has(Q.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:xhe(Q.provider)}),m.jsx("span",{className:"h-px flex-1 bg-border/70","aria-hidden":"true"}),m.jsx("span",{className:"tabular-nums",children:Q.sessions.length}),m.jsx(Yd,{className:We("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",!I.has(Q.provider)&&"rotate-90"),"aria-hidden":"true"})]}),I.has(Q.provider)?null:m.jsx("ul",{role:"list",className:"flex flex-col",children:Q.sessions.map(fe=>m.jsx(Tfe,{session:ee(fe),selected:fe.sessionId===u,now:F,onClick:()=>j(fe.sessionId,fe.mode),onRename:()=>W(fe),onTerminate:()=>O(fe)},fe.sessionId))})]},Q.provider))}):m.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/70","data-slot":"active-empty",children:"暂无活跃会话"}),oe=m.jsx(Lfe,{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(SI,{}),oe]}),m.jsx("div",{className:"px-4 pt-4 pb-[calc(env(safe-area-inset-bottom)+1rem)] border-t border-border",children:m.jsxs(dt,{className:"min-h-11 w-full md:min-h-0","data-slot":"create-session-mobile-trigger",onClick:()=>A(!0),children:[m.jsx(Iz,{"aria-hidden":"true"}),"新建"]})}),m.jsx(The,{open:k,creatingTerminal:N,onOpenChange:A,onCreateAgent:()=>{A(!1),T(!0)},onCreateTerminal:()=>{BF()?(A(!1),R(!0)):D(void 0,()=>A(!1))},onCreatePreview:()=>{A(!1),z(!0)}}),m.jsx(zF,{layout:"mobile",open:P,creatingTerminal:N,creatingShell:L,onOpenChange:R,onBack:()=>{R(!1),A(!0)},onCreate:Q=>void D(Q,()=>R(!1))}),m.jsx(mp,{open:x,onOpenChange:T}),m.jsx(OF,{open:M,onOpenChange:z}),m.jsx(Ev,{open:G!==null,session:G,onOpenChange:Q=>{Q||O(null)},onConfirm:Y}),m.jsx(gp,{open:V!==null,sessionId:(V==null?void 0:V.sessionId)??null,initialName:V==null?void 0:V.name,onOpenChange:Q=>{Q||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(SI,{}),oe]}),m.jsx(mp,{open:x,onOpenChange:T}),m.jsx(Ev,{open:G!==null,session:G,onOpenChange:Q=>{Q||O(null)},onConfirm:Y}),m.jsx(gp,{open:V!==null,sessionId:(V==null?void 0:V.sessionId)??null,initialName:V==null?void 0:V.name,onOpenChange:Q=>{Q||W(null)},onRename:X})]})}function whe(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])=>She(n,r)).map(([n,r])=>({provider:n,sessions:r}))}function xhe(e){return e==="terminal"?"终端":Jb(e)}function She(e,t){return e===t?0:e==="terminal"?-1:t==="terminal"?1:xF(e,t)}function DF(){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)&&!jk(l)&&!(s&&!((u=l.terminalShells)!=null&&u.some(d=>d.id===s)))){n(s??"default");try{const d=await Yfe({relay:zt,shell:s});if(d.type!=="success"){$e.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 jk(e){var t;return!e.terminalShellsLoaded&&((t=e.proxies.find(n=>n.proxyId===e.selectedProxyId))==null?void 0:t.osName)==="Windows"}function Ehe(e){const t=Re(u=>u.terminalShells),n=Re(jk),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=zt,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 Che=[{label:"启动 Shell"}];function khe(e){return e!=null&&e.length?e:Che}function BF(){var t;const e=Re.getState();return jk(e)||!!((t=e.terminalShells)!=null&&t.length)}function EI({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(V=>!!V.selectedProxyId),g=Re(V=>V.proxySwitchTarget!==null),_=v&&!g,{creatingTerminal:w,creatingShell:S,createTerminal:x}=DF();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,BF()?i(!0):x()}function P(){if(!_){T();return}h.current=!0,u(!0)}function R(V){V.preventDefault(),T()}const M=m.jsxs(dt,{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(Iz,{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:V=>{h.current&&(h.current=!1,V.preventDefault())},children:[m.jsxs(ii,{className:"min-h-9 gap-2.5","data-slot":"create-agent-session-item",onSelect:k,children:[m.jsx(Mz,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),"Agent 会话"]}),m.jsxs(ii,{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(Hl,{}),m.jsxs(ii,{className:"min-h-[3.75rem] items-start gap-2.5 py-2","data-slot":"create-frontend-preview-item",onSelect:P,children:[m.jsx(MC,{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(zF,{layout:"desktop",open:r,creatingTerminal:w,creatingShell:S,onOpenChange:i,onBack:()=>{i(!1),n(!0)},onCreate:V=>void x(V,()=>i(!1))}),m.jsx(mp,{open:s,onOpenChange:o}),m.jsx(OF,{open:l,onOpenChange:u})]})}function The({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(gc,{open:e,onOpenChange:n,children:m.jsxs(vc,{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(yc,{children:"新建"})}),m.jsxs("div",{className:"grid gap-2 pb-1","data-slot":"create-session-type-options",children:[m.jsxs(dt,{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(Mz,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),"Agent 会话"]}),m.jsxs(dt,{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(dt,{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(MC,{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 zF({layout:e,open:t,creatingTerminal:n,creatingShell:r,onOpenChange:i,onBack:s,onCreate:o}){const{terminalShells:l,needsDetection:u,failed:d,retry:f}=Ehe(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(dt,{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?"终端检测失败,点击重试":"正在检测终端..."]}):khe(l).map(w=>m.jsxs(dt,{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(Mfe,{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(dt,{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(gc,{open:t,onOpenChange:i,children:m.jsxs(vc,{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(yc,{children:"Shell 会话"})}),g]})}):m.jsx(qi,{open:t,onOpenChange:i,children:m.jsxs(Yi,{className:"sm:max-w-sm","data-slot":"create-terminal-shell-dialog",focusSurfaceOnOpen:!0,onCloseAutoFocus:_,children:[m.jsx(Vi,{children:m.jsx(Pi,{children:"Shell 会话"})}),g]})})}const Rhe="0.10.4",Ahe={version:Rhe},Nhe={playback:"playback",capture:"play-and-record"};function Mhe(){return typeof navigator>"u"?null:navigator.audioSession??null}function Phe(){return{setMode:()=>{},release:()=>{}}}class Ihe{constructor(t=Mhe){ze(this,"leases",new Map);ze(this,"session",null);ze(this,"baselineType",null);ze(this,"nextLeaseId",1);ze(this,"nextOrder",1);this.getAudioSession=t}acquire(t){const n=this.getAudioSession();if(!n)return Phe();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(Nhe[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 Fk=new Ihe,j1=64,CI=-60,jF=32;function kI(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-CI)/-CI));return e<0?-r:r}function TI(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 Ohe(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 Lhe(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 FF{constructor(t,n=24e3,r={}){ze(this,"nextStartTime",0);ze(this,"activityEndToken",0);ze(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=Ohe(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*jF/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=Lhe(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 R0={provider:"aliyun-bailian",configured:!1,region:"cn",asrModel:"qwen3-asr-flash-realtime",ttsModel:"cosyvoice-v3-flash",ttsVoice:"longanyang",turnIdleSeconds:3},RI="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",Dhe=800,AI=300,Bhe=1600;function F1(e,t){return e.filter(n=>!n.model||n.model===t)}function NI({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 Cv({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=!!$F(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(MI,{label:f,muted:!d&&!t}),m.jsx(oc,{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(ua,{className:"size-4","aria-hidden":"true"}):null}),m.jsx(MI,{label:g.label})]},g.value)})}):null,s?m.jsx("div",{className:"mt-2 text-xs leading-relaxed text-muted-foreground",children:s}):null]})}function MI({label:e,muted:t=!1}){const n=$F(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 zhe({scrollRef:e}={}){const[t,n]=b.useState(R0),[r,i]=b.useState(String(R0.turnIdleSeconds)),[s,o]=b.useState(()=>cv()),[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=zt;if(!Z){_({kind:"error",message:"请先连接 Relay 服务器"});return}let oe=!1;return _({kind:"loading"}),Z.requestVoiceConfig().then(Q=>{if(!oe){if(Q.error||!Q.config){_({kind:"error",message:Q.error??"读取语音设置失败"});return}n(Q.config),i(String(Q.config.turnIdleSeconds)),u(""),f(!1),v(!0),_({kind:"idle"})}}).catch(Q=>{oe||_({kind:"error",message:Q instanceof Error?Q.message:"读取语音设置失败"})}),()=>{oe=!0}},[]),b.useEffect(()=>{const Z=zt;if(!Z||!h)return;let oe=!1;return Z.requestVoiceCapabilities({region:t.region}).then(Q=>{if(!oe){if(Q.error||!Q.capabilities){o(cv());return}o(Q.capabilities)}}).catch(()=>{oe||o(cv())}),()=>{oe=!0}},[t.region,h]),b.useEffect(()=>(A.current=!0,()=>{A.current=!1,$(),ee()}),[]);const P=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(()=>F1(s.ttsVoices,t.ttsModel),[s.ttsVoices,t.ttsModel]),V=M.some(Z=>Z.value===t.ttsVoice)?t.ttsVoice:"",W=M.length===0?"当前模型暂无可用音色":V?null:"请选择可用音色",G=b.useMemo(()=>Hhe(r),[r]),O=G?null:"请输入正整数秒数",N=W??O,L=R||!!N,D=b.useMemo(()=>[{value:"cn",label:"中国大陆"},{value:"intl",label:"国际"}],[]),I=b.useMemo(()=>OI(s.asrModels,t.asrModel),[s.asrModels,t.asrModel]),B=b.useMemo(()=>Uhe(s.ttsModels,s.ttsVoices,t.ttsModel),[s.ttsModels,s.ttsVoices,t.ttsModel]),F=b.useMemo(()=>OI(M,V),[M,V]);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??R0.turnIdleSeconds}}async function j(){if(R)return;if(N){_({kind:"error",message:N});return}const Z=zt;if(!Z){_({kind:"error",message:"请先连接 Relay 服务器"});return}const oe=U();ee(),_({kind:"saving"});const Q=performance.now();try{const fe=await Z.updateVoiceConfig(oe);if(!A.current)return;const ge=performance.now()-Q;if(ge<AI&&await $he(AI-ge),!A.current)return;if(!fe.success||fe.error||!fe.config){_({kind:"error",message:fe.error??"保存语音设置失败"});return}n(fe.config),i(String(fe.config.turnIdleSeconds)),u(""),f(!1),_({kind:"saved"}),k.current=setTimeout(()=>{k.current=null,_(Ce=>Ce.kind==="saved"?{kind:"idle"}:Ce)},Bhe),Z.requestVoiceCapabilities({region:fe.config.region}).then(Ce=>{A.current&&Ce.capabilities&&o(Ce.capabilities)}).catch(()=>{A.current&&o(cv())})}catch(fe){if(!A.current)return;_({kind:"error",message:fe instanceof Error?fe.message:"保存语音设置失败"})}}async function Y(){if(R)return;if(N){_({kind:"error",message:N});return}const Z=zt;if(!Z){_({kind:"error",message:"请先连接 Relay 服务器"});return}let oe;try{oe=X()}catch(Q){_({kind:"error",message:II(Q)});return}_({kind:"testing"});try{const[Q]=await Promise.all([Z.testVoiceConfig(U()),oe.ready]);if(!Q.success||Q.error){$(),_({kind:"error",message:Q.error??"语音配置测试失败"});return}const fe=await re(Q,oe.context);_({kind:"playingTest",transcript:Q.transcript}),T.current=setTimeout(()=>{T.current=null,$(),_({kind:"testPassed",transcript:Q.transcript})},fe)}catch(Q){$(),_({kind:"error",message:II(Q)})}}function X(){$();const Z=Fk.acquire("playback");S.current=Z;try{const oe=Fhe();return w.current=oe,{context:oe,ready:PI(oe)}}catch(oe){throw Z.release(),S.current=null,oe}}function $(){var Z,oe,Q;T.current&&(clearTimeout(T.current),T.current=null),(Z=x.current)==null||Z.stop(),x.current=null,(oe=w.current)==null||oe.close(),w.current=null,(Q=S.current)==null||Q.release(),S.current=null}function ee(){k.current&&(clearTimeout(k.current),k.current=null)}async function re(Z,oe){if(!Z.audioBase64)throw new Error("语音测试未返回可播放音频");if(Z.audioEncoding&&Z.audioEncoding!=="pcm_s16le")throw new Error("测试音频格式暂不支持");const Q=Z.audioSampleRate??24e3,fe=jhe(Z.audioBase64);if(fe.byteLength===0||fe.byteLength%2!==0)throw new Error("测试音频数据无效");await PI(oe);const ge=new FF(oe,Q);x.current=ge,ge.enqueue(fe);const Ce=Math.ceil(fe.byteLength/2/Q*1e3);return Math.max(Dhe,Ce)}function te(Z){var oe;return((oe=F1(s.ttsVoices,Z)[0])==null?void 0:oe.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(NI,{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(zz,{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:`${RI} w-full pl-9`})]}),t.configured&&m.jsxs(dt,{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(Uz,{className:"size-4","aria-hidden":"true"}),"清空"]})]})}),m.jsx(Cv,{label:"地域",value:t.region,options:D,onChange:Z=>n(oe=>({...oe,region:Z==="intl"?"intl":"cn"}))}),m.jsx(Cv,{label:"语音识别模型",value:t.asrModel,options:I,onChange:Z=>n(oe=>({...oe,asrModel:Z}))}),m.jsx(Cv,{label:"语音合成模型",value:t.ttsModel,options:B,onChange:Z=>n(oe=>({...oe,ttsModel:Z,ttsVoice:te(Z)}))}),m.jsx(Cv,{label:"语音音色",value:V,options:F,placeholder:M.length===0?"暂无可用音色":"请选择音色",onChange:Z=>n(oe=>({...oe,ttsVoice:Z})),help:W}),m.jsx(NI,{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:`${RI} 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:[P?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:P}):null,m.jsxs(dt,{type:"button",variant:"outline",disabled:L,onClick:()=>void Y(),children:[m.jsx(PC,{className:"size-4","aria-hidden":"true"}),"测试"]}),m.jsxs(dt,{type:"submit",disabled:L,children:[m.jsx(RK,{className:"size-4","aria-hidden":"true"}),g.kind==="saving"?"保存中...":"保存"]})]})]})]})}function jhe(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 Fhe(){const e=window,t=e.AudioContext??e.webkitAudioContext;if(!t)throw new Error("当前浏览器不支持音频播放");return new t}async function PI(e){if(e.state!=="running")try{await e.resume()}catch{throw new Error("浏览器阻止了测试音频播放,请再次点击测试")}if(e.state!=="running")throw new Error("浏览器阻止了测试音频播放,请再次点击测试")}function II(e){return e instanceof Error?e.message:"语音配置测试失败"}function $he(e){return new Promise(t=>setTimeout(t,e))}function Hhe(e){const t=e.trim();if(!/^[1-9]\d*$/.test(t))return null;const n=Number(t);return Number.isSafeInteger(n)?n:null}function OI(e,t){const n=e.map(r=>({value:r.value,label:HF(r)}));return!t||n.some(r=>r.value===t)?n:[{value:t,label:t},...n]}function Uhe(e,t,n){const r=e.map(i=>{const s=F1(t,i.value).length===0;return{value:i.value,label:`${HF(i)}${s?" · 暂无音色":""}`,disabled:s}});return!n||r.some(i=>i.value===n)?r:[{value:n,label:`${n} · 暂无音色`,disabled:!0},...r]}function $F(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 HF(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 Whe=[{value:"auto",label:"跟随系统"},{value:"light",label:"浅色"},{value:"dark",label:"深色"}],qhe=[{value:"auto",label:"自动"},{value:"touch",label:"触控优先"},{value:"hardware",label:"实体键盘优先"}],$k="dev-render-scroll min-h-0 space-y-3 overflow-y-auto overscroll-contain pr-4 sm:pr-1";function UF(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 Yhe(e){const t=e||window.location.origin;return new URL("/health",t).toString()}function Vhe(e){return e==="version"?"版本":e==="relay-token"?"Relay Token":e==="clients"?"客户端管理":"设置 Voice Pilot"}function Khe(e){return e==="version"?"Web 与 Relay 服务器版本。":e==="relay-token"?"连接受保护的 Relay 服务器,保存后立即重连。":e==="clients"?"管理当前连接的 Web 客户端。":"连接语音服务后,即可以语音交互的形式驱动会话。"}function $1({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),P=foe(),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 Bse();if(O==="granted"){o(!0);return}if(O==="denied"){$e.error("浏览器未授予通知权限,请在浏览器设置中允许通知");return}if(O==="default"){$e.info("未授予通知权限,会话通知保持关闭");return}$e.error("当前浏览器不支持系统通知")},[o]),z=b.useCallback(async G=>{T({kind:"loading"});try{const O=await fetch(Yhe(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 V=x.kind==="ready"?x.version:x.kind==="loading"?"读取中...":x.kind==="error"?"读取失败":"未读取",W=x.kind==="ready"?`运行 ${UF(x.uptime)}`:x.kind==="error"?x.message:"从当前 Relay 服务器 /health 读取";return m.jsx(qi,{open:e,onOpenChange:t,children:m.jsxs(Yi,{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(Vi,{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(dt,{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(Pi,{children:Vhe(g)}),m.jsx(fs,{className:"max-w-[28rem] leading-5",children:Khe(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(Pi,{children:"设置"}),m.jsx(fs,{children:"连接、外观、通知和高级诊断选项。"})]})}),g==="version"?m.jsx(Ghe,{relayVersion:V,relayDetail:W,relayMuted:x.kind==="error"}):g==="relay-token"?m.jsx(Zhe,{saved:P}):g==="clients"?m.jsx(npe,{}):g==="voice"?m.jsx(zhe,{scrollRef:A}):m.jsx(Xhe,{relayTokenSaved:P,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 Ghe({relayVersion:e,relayDetail:t,relayMuted:n}){return m.jsxs("div",{className:$k,"data-slot":"settings-dialog-body",children:[m.jsx(DI,{icon:m.jsx(jz,{className:"size-4","aria-hidden":"true"}),label:"Web",value:Ahe.version,detail:"当前浏览器加载的版本"}),m.jsx(DI,{icon:m.jsx($z,{className:"size-4","aria-hidden":"true"}),label:"Relay 服务器",value:e,detail:t,muted:n})]})}function Xhe({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(kv,{icon:m.jsx(QY,{className:"size-4","aria-hidden":"true"}),label:"Voice Pilot",detail:"用语音输入、听取回复和处理审批",onClick:v}),m.jsx(kv,{icon:m.jsx(zz,{className:"size-4","aria-hidden":"true"}),label:"Relay Token",detail:`${e?"已保存":"未设置"} · 受保护的 Relay 服务器`,onClick:g}),m.jsx(kv,{icon:m.jsx(XK,{className:"size-4","aria-hidden":"true"}),label:"客户端管理",detail:"已连接的浏览器页面和设备",onClick:_})]}),m.jsx(hd,{title:"外观",children:m.jsx(LI,{icon:m.jsx(jK,{className:"size-4","aria-hidden":"true"}),label:"主题",value:t,options:Whe,onValueChange:n})}),m.jsx(hd,{title:"通知",children:m.jsx(N0,{icon:m.jsx(tV,{className:"size-4","aria-hidden":"true"}),label:"会话空闲通知",detail:"会话从工作中转为空闲时发送浏览器通知",checked:o,onCheckedChange:l})}),s?m.jsx(hd,{title:"交互",children:m.jsx(LI,{icon:m.jsx(AC,{className:"size-4","aria-hidden":"true"}),label:"输入方式",detail:"默认自动识别软键盘和实体键盘;必要时可强制一种方式",value:r,options:qhe,onValueChange:i})}):null,m.jsxs(hd,{title:"高级诊断",children:[m.jsx(N0,{icon:m.jsx(ou,{className:"size-4","aria-hidden":"true"}),label:"PTY 滚动追踪",detail:"记录终端滚动和视口同步现场,方便复制诊断报告",checked:u,onCheckedChange:d}),m.jsx(N0,{icon:m.jsx(Az,{className:"size-4","aria-hidden":"true"}),label:"延迟监控",detail:"显示可拖动的连接延迟浮窗",checked:f,onCheckedChange:h})]}),m.jsx(hd,{title:"关于",children:m.jsx(kv,{icon:m.jsx($z,{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 LI({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 Zhe({saved:e}){const t=b.useId(),n=b.useId(),[r,i]=b.useState(""),[s,o]=b.useState(null),l=()=>{O5().catch(f=>{o(f instanceof Error?f.message:"Relay 重连失败。")})},u=()=>{const f=r.trim();if(!f){o("请输入 token。");return}if(!P5(f)){const h="Relay Token 保存失败,请检查浏览器存储权限。";o(h),$e.error(h);return}o(null),$e.success("Relay Token 已保存,正在重新连接"),l()},d=()=>{I5(),l()};return m.jsxs("form",{className:$k,"data-slot":"settings-dialog-body",onSubmit:f=>{f.preventDefault(),u()},children:[m.jsxs("div",{className:"rounded-md border border-border bg-card/70 p-3","data-slot":"relay-token-card",children:[m.jsx("label",{htmlFor:t,className:"text-sm font-medium text-foreground",children:"Token"}),m.jsx("input",{id:t,type:"password",value:r,onChange:f=>{i(f.currentTarget.value),s&&o(null)},autoComplete:"off",spellCheck:!1,"aria-describedby":s?n:void 0,className:"mt-2 h-10 w-full rounded-md border border-border bg-background px-3 font-mono text-sm text-foreground outline-none transition-colors placeholder:text-muted-foreground focus:border-ring focus:ring-2 focus:ring-ring/75",placeholder:"粘贴 token"}),s?m.jsx("p",{id:n,className:"mt-2 text-xs text-destructive",children:s}):null]}),m.jsxs("div",{className:"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",children:[e?m.jsx(dt,{type:"button",variant:"outline",onClick:d,children:"清空"}):null,m.jsx(dt,{type:"submit",disabled:!r.trim(),children:"保存"})]})]})}function Jhe(e){return e.length<=16?e:`${e.slice(0,8)}...${e.slice(-4)}`}function Qhe(e,t){var r;return((r=t.get(e))==null?void 0:r.trim())||Jhe(e)}function epe(e){return Rre(e)}function tpe(e){const t=Math.max(0,Math.floor((Date.now()-e)/1e3));return UF(t)}function A0({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 npe(){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=zt;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=zt;if(!g){o("Relay 未连接。");return}u(v),o(null);try{const _=await g.kickRelayClient(v);if(!_.success){o(_.error??"断开客户端失败。");return}n(w=>w.filter(S=>S.clientId!==v))}catch(_){o(_ instanceof Error?_.message:"断开客户端失败。")}finally{u(null)}},[]);return m.jsxs("div",{className:$k,"data-slot":"settings-dialog-body",children:[m.jsxs("div",{className:"flex min-h-9 items-center gap-2","data-slot":"relay-clients-toolbar",children:[m.jsx("div",{className:"text-sm font-medium text-foreground",children:r?"正在读取客户端":`${t.length} 个在线客户端`}),m.jsx(dt,{type:"button",variant:"ghost",size:"icon-sm","aria-label":"刷新客户端列表",title:"刷新",onClick:()=>void f(),disabled:r,"data-slot":"relay-clients-refresh",children:m.jsx(gm,{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:epe(v)})}),m.jsxs("div",{className:"space-y-1",children:[m.jsx(A0,{label:"已连接",value:tpe(v.connectedAt)}),v.proxyId?m.jsx(A0,{label:"连接到",value:Qhe(v.proxyId,d),title:v.proxyId}):null,v.remoteAddress?m.jsx(A0,{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(dt,{type:"button",variant:"outline",size:"sm",className:"h-9 w-full justify-center",disabled:_,onClick:()=>void h(v.clientId),"data-slot":"relay-client-action",children:[m.jsx(nK,{className:"size-3.5","aria-hidden":"true"}),_?"断开中...":"断开"]})]})},v.clientId)})]})}function N0({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 kv({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 DI({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 rpe="xterm-helper-textarea";function ipe(e=document.activeElement){return!(e instanceof HTMLElement)||!e.classList.contains(rpe)?!1:(e.blur(),!0)}function BI(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&&spe(r,n))return!0;if(r===t)break;r=r.parentElement}return!1}function spe(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 ope({releasePtyFocus:e=!0,containVerticalScroll:t=!0}={}){const n=b.useRef(null),r=b.useCallback(()=>{e&&ipe()},[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,BI(l.target,l.currentTarget,f)||l.preventDefault()},[t]),o=b.useCallback(l=>{r(),t&&(BI(l.target,l.currentTarget,l.deltaY)||l.preventDefault())},[t,r]);return{onPointerDownCapture:r,onTouchStartCapture:i,onTouchMoveCapture:s,onWheelCapture:o}}function ape({className:e}){const t=Re(o=>o.sidebarCollapsed),n=Re(o=>o.toggleSidebarCollapsed),[r,i]=b.useState(!1),s=ope();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(jI,{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(zI,{compact:!0,tooltipSide:"right",onClick:()=>i(!0)}),m.jsx(EI,{compact:!0})]})]}),m.jsx($1,{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(aj,{className:"text-[13px]",slot:"sidebar-brand"}),m.jsx(jI,{collapsed:!1,onClick:n})]}),m.jsx("div",{className:"mt-2.5",children:m.jsx(wF,{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(LF,{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(EI,{})}),m.jsx("div",{className:"min-w-0 flex-1",children:m.jsx(zI,{onClick:()=>i(!0)})})]})]}),m.jsx($1,{open:r,onOpenChange:i})]})}function zI({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(Hz,{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 jI({collapsed:e,onClick:t}){const n=e?"展开侧边栏":"收起侧边栏",r=e?pK:fK;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 lpe=1500,cpe=300,FI=70,$I=35;function WF({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,FI)):(o.current="paused",f=setTimeout(v,lpe))}else g==="paused"?(o.current="deleting",f=setTimeout(v,$I)):g==="deleting"?l.current>0?(l.current-=1,r(h().slice(0,l.current)),f=setTimeout(v,$I)):(u.current+=1,o.current="waiting",f=setTimeout(v,cpe)):(o.current="typing",f=setTimeout(v,FI))};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 qF=["DEV Anywhere","/unlimited @anytime"];function upe({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(WF,{texts:qF,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 dpe=3e3,fpe=1e4,Tv=12,hpe=4,HI={webRelay:"浏览器 ↔ Relay 服务器",relayProxy:"Relay 服务器 ↔ 开发机",webProxy:"浏览器 ↔ 开发机"},ppe={webRelay:{state:"idle"},relayProxy:{state:"idle"},webProxy:{state:"idle"}};function M0(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 UI(e){switch(e){case"bad":return 4;case"unavailable":return 3;case"warn":return 2;case"measuring":return 1;default:return 0}}function YF(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 gpe(e){return e.state==="measuring"?"检测中":e.state==="unavailable"?e.error??"不可用":e.rttMs!==void 0?yp(e.rttMs):"等待检测"}function vpe(){const e=Mi("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 WI(e){Pr("local",Tn.latencyMonitorPosition,JSON.stringify(e))}function ype(){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 P0(e,t){const n=ype(),r=Tv,i=Tv,s=Math.max(r,n.width-t.width-Tv),o=Math.max(i,n.height-t.height-Tv);return{x:Math.min(s,Math.max(r,Math.round(e.x))),y:Math.min(o,Math.max(i,Math.round(e.y)))}}function bpe(){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(ppe),[o,l]=b.useState(()=>vpe()),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)=>UI(M.state)-UI(R.state))[0]??{state:"idle"}).state,[i]),g=YF(v);async function _(){if(u.current)return;const R=zt;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,V]=await Promise.allSettled([R.measureWebRelayLatency(),n?R.measureRelayProxyLatency():Promise.resolve({success:!1}),n?R.measureWebProxyLatency():Promise.resolve({success:!1})]);s({webRelay:M.status==="fulfilled"?M0(M.value):pd(M.reason instanceof Error?M.reason.message:"测速失败"),relayProxy:z.status==="fulfilled"?M0(z.value):pd(z.reason instanceof Error?z.reason.message:"测速失败"),webProxy:V.status==="fulfilled"?M0(V.value):pd(V.reason instanceof Error?V.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?fpe:dpe))};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=P0(o,{width:M.width,height:M.height});z.x===o.x&&z.y===o.y||(l(z),WI(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,V;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},(V=(z=R.currentTarget).setPointerCapture)==null||V.call(z,R.pointerId)}function T(R){const M=f.current;if(!M||M.pointerId!==R.pointerId)return;const z=R.clientX-M.startX,V=R.clientY-M.startY;if(!M.dragging&&Math.hypot(z,V)<hpe)return;M.dragging=!0,R.preventDefault();const W=P0({x:M.originX+z,y:M.originY+V},{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,V=R.clientY-M.startY,W=P0({x:M.originX+z,y:M.originY+V},{width:M.width,height:M.height});l(W),WI(W)}function A(R){var z,V;const M=f.current;!M||M.pointerId!==R.pointerId||(f.current=null,(V=(z=R.currentTarget).releasePointerCapture)==null||V.call(z,R.pointerId))}function P(R){h.current&&(h.current=!1,R.preventDefault(),R.stopPropagation())}return m.jsxs(Kb,{children:[m.jsx(Gb,{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:P,children:[m.jsx(Az,{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(oc,{className:"size-3 text-muted-foreground","aria-hidden":"true"})]})}),m.jsxs(Xb,{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(dt,{type:"button",variant:"ghost",size:"icon-xs","aria-label":"立即测速",onClick:()=>void _(),children:m.jsx(gm,{className:"size-3","aria-hidden":"true"})})]}),m.jsx("div",{className:"mt-3 space-y-2",children:Object.keys(HI).map(R=>m.jsx(_pe,{label:HI[R],measurement:i[R]},R))})]})]})}function _pe({label:e,measurement:t}){const n=YF(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:gpe(t)})]})]})}const VF="/__dev_anywhere_debug/browser-state-dumps",wpe=1500,xpe=10,I0=80,Hk=500,Spe=["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"],Epe=["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 qI(){if(typeof window>"u")return"off";const e=t6("debugDump");return e==="auto"?"auto":e!==null||Ipe("debugInput")?"manual":"off"}function Cpe(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:Ape(),document:{title:document.title,readyState:document.readyState,visibilityState:document.visibilityState,activeElement:YI(document.activeElement),selection:Npe(),focusedInputs:Array.from(document.querySelectorAll("input, textarea, select, [contenteditable]")).filter(i=>i===document.activeElement||i.matches(":focus")).map(i=>YI(i)).filter(i=>!!i),root:KF(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(()=>VI(n.__devAnywherePtyScrollTrace)),jsonScrollTraceTail:md(()=>VI(n.__devAnywhereJsonScrollTrace)),voicePilotDiagnostics:md(()=>{var i;return((i=n.__devAnywhereVoicePilotDiagnostics)==null?void 0:i.snapshot())??null})}};return window.__devAnywhereLastBrowserStateDump=r,r}async function kpe(e="manual"){const t=Cpe(e);return Tpe(t)}async function Tpe(e){const t=JSON.stringify(e,null,2),n=new Blob([t]).size;try{const r=await Rpe(t);return{status:"saved",path:r.path,bytes:r.bytes,endpoint:VF}}catch(r){const i=n6(r),s=Mpe(e.createdAt);return Ppe(s,t,"application/json")?{status:"downloaded",filename:s,bytes:n,endpointError:i}:{status:"failed",error:"无法保存或下载诊断包",endpointError:i}}}async function Rpe(e){const t=await fetch(VF,{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 KF(e,t,n){if(n.count>=wpe||t>xpe)return n.truncated=!0,{kind:"truncated"};if(n.count+=1,e.nodeType===Node.TEXT_NODE){const u=KI(e.textContent??"");return u?{kind:"text",text:i_(u,Hk)}:{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,I0))u.nodeType===Node.TEXT_NODE&&!KI(u.textContent??"")||r.push(KF(u,t+1,n));s.length>I0&&(i=s.length-I0,n.truncated=!0);const o={kind:"element",tag:e.tagName.toLowerCase(),path:e6(e),attrs:GF(e),rect:XF(e),scroll:ZF(e),style:JF(e)},l=QF(e);return l&&(o.value=l),r.length>0&&(o.children=r),i>0&&(o.omittedChildren=i),o}function YI(e){if(!(e instanceof HTMLElement))return null;const t=QF(e);return{path:e6(e),tag:e.tagName.toLowerCase(),id:e.id||null,className:e.className||null,attrs:GF(e),rect:XF(e),scroll:ZF(e),style:JF(e),...t?{value:t}:{}}}function Ape(){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 GF(e){const t={};for(const n of Spe){const r=e.getAttribute(n);r!==null&&(t[n]=i_(r,500))}return t}function XF(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 ZF(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 JF(e){const t=window.getComputedStyle(e),n={};for(const r of Epe)n[r]=t.getPropertyValue(r);return n}function QF(e){if(!(!(e instanceof HTMLInputElement)&&!(e instanceof HTMLTextAreaElement)))return{length:e.value.length,preview:i_(e.value,Hk),selectionStart:e.selectionStart,selectionEnd:e.selectionEnd}}function Npe(){var e;try{return i_(((e=window.getSelection())==null?void 0:e.toString())??"",Hk)}catch{return null}}function e6(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 Mpe(e){return`dev-anywhere-browser-state-${e.replace(/[:.]/g,"-")}.json`}function Ppe(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 Ipe(e){return t6(e)!==null}function t6(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 VI(e){return e?Ky(e.slice(-200)):null}function md(e){try{return Ky(e())}catch(t){return{error:n6(t)}}}function Ky(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(Ky);if(typeof e=="object"){const t={};for(const[n,r]of Object.entries(e))t[n]=Ky(r);return t}return String(e)}function KI(e){return e.replace(/\s+/g," ").trim()}function i_(e,t){return e.length>t?`${e.slice(0,t)}...`:e}function Cs(e){return Math.round(e*100)/100}function n6(e){return e instanceof Error?e.message:String(e)}const Ope=500,Lpe=1e3,Dpe=60;function Bpe(){const[e,t]=b.useState(()=>qI()),[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(qI());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 kpe(_);return o.current=w,s(w),(_==="manual"||w.status==="failed")&&zpe(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>=Dpe||(_(),f.current=window.setTimeout(()=>{f.current=null;const P=Date.now(),R=Lpe-(P-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}`)},Ope))};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,P;_(),S.forEach(R=>window.removeEventListener(R,x,!0)),(A=window.visualViewport)==null||A.removeEventListener("resize",x),(P=window.visualViewport)==null||P.removeEventListener("scroll",x)}},[h,e]),e==="off")return null;const v=e==="auto"?"自动诊断中":"保存诊断",g=jpe(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(dt,{type:"button",size:"sm",variant:e==="auto"?"secondary":"outline",className:"h-9 rounded-md px-3 text-xs shadow-lg",onClick:()=>void h("manual"),disabled:n,"data-slot":"browser-state-dump",children:[n?m.jsx(Xr,{className:"size-3.5 animate-spin","aria-hidden":"true"}):m.jsx(zV,{className:"size-3.5","aria-hidden":"true"}),m.jsx("span",{children:v})]})]})}function zpe(e){if(e.status==="saved"){$e.success(`诊断已保存: ${e.path}`);return}if(e.status==="downloaded"){$e.info(`诊断已下载: ${e.filename}`);return}$e.error(e.endpointError?`${e.error}: ${e.endpointError}`:e.error)}function jpe(e){return e?e.status==="saved"?`已保存 ${e.path}`:e.status==="downloaded"?`已下载 ${e.filename}`:`失败 ${e.endpointError??e.error}`:null}function Fpe({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(Xr,{className:"size-5 animate-spin","aria-hidden":"true"}):null,m.jsx("p",{className:"text-sm",children:t}),n?m.jsx(dt,{type:"button",size:"sm",onClick:()=>window.location.reload(),children:n}):null]})}function $pe(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 Uk(e){const{windowKey:t,storageKey:n,maxEntries:r=5e3,dedupeKey:i}=e,s=new Map,o=()=>typeof window>"u"?!1:$pe(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 er(e){return Math.round(e*10)/10}function Dl(e){return e.length===0?"":`${er(Math.min(...e))}..${er(Math.max(...e))}`}function Bd(e){return[...new Set(e.filter(t=>t!==void 0).map(er))]}function r6(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 Hpe="dev_anywhere_pty_input_latency_trace",GI=80,Upe=1e4,Wpe=new TextDecoder;let qpe=0;const df=new Map,Tu=Uk({windowKey:"__devAnywherePtyInputLatencyTrace",storageKey:Hpe,dedupeKey:e=>e.event.startsWith("input")?null:`${e.event}|${e.sessionId}|${e.outputSeq??""}|${e.pendingInputs??""}`});function Ype(){typeof window>"u"||(window.__devAnywherePtyInputLatencyReport=Xpe)}function Vpe(e,t){if(!Tu.isEnabled())return null;const n=`pty-in-${Date.now().toString(36)}-${++qpe}`,r=performance.now(),i={inputId:n,sessionId:e,data:t,kind:Qpe(t),dataLength:t.length,startedAt:r,sentAt:null,firstOutputAt:null,echoMatchedAt:null,xtermWriteAt:null,paintAt:null},s=df.get(e)??[];return s.push(i),qk(s,r),df.set(e,s),Mm({t:r,event:"input:start",sessionId:e,inputId:n,inputKind:i.kind,dataLength:i.dataLength,pendingInputs:s.length}),{inputId:n,sessionId:e}}function XI(e,t){if(!e||!Tu.isEnabled())return;const n=performance.now(),r=Zpe(e.sessionId,e.inputId);r&&(r.sentAt=n),Mm({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 Kpe(e,t,n){if(!Tu.isEnabled())return;const r=performance.now(),i=Wk(e,r),s=nme(t),o=[],l=[];for(const u of i)u.firstOutputAt===null&&(u.firstOutputAt=r,o.push(u.inputId)),u.echoMatchedAt===null&&tme(u)&&s.includes(u.data)&&(u.echoMatchedAt=r,l.push(u.inputId));Mm({t:r,event:"output:received",sessionId:e,outputSeq:n,bytes:t.byteLength,pendingInputs:i.length,deltaFromInputMs:Yk(i,r),details:rme([o.length>0?`first=${o.length}`:"",l.length>0?`echo=${l.length}`:""])})}function Gpe(e,t,n=1){if(!Tu.isEnabled())return;const r=performance.now(),i=Wk(e,r),s=[];for(const o of i)o.xtermWriteAt===null&&(o.xtermWriteAt=r,s.push(o.inputId));Mm({t:r,event:"output:xterm-write",sessionId:e,bytes:t,chunkCount:n,pendingInputs:i.length,deltaFromInputMs:Yk(i,r),details:s.length>0?`firstWrite=${s.length}`:""}),typeof requestAnimationFrame=="function"&&s.length>0&&requestAnimationFrame(()=>Jpe(e,s))}function Xpe(){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?"":er(s.sentAt-s.startedAt),s.firstOutputAt===null?"":er(s.firstOutputAt-s.startedAt),s.echoMatchedAt===null?"":er(s.echoMatchedAt-s.startedAt),s.xtermWriteAt===null?"":er(s.xtermWriteAt-s.startedAt),s.paintAt===null?"":er(s.paintAt-s.startedAt)].join(" ")),i=t.map(s=>[er(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?"":er(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 Mm(e){Tu.append(e)}function Wk(e,t){const n=df.get(e)??[];return qk(n,t),df.set(e,n),n}function qk(e,t){for(let n=e.length-1;n>=0;n-=1){const r=e[n],i=r.paintAt!==null,s=t-r.startedAt>Upe;(i||s)&&e.splice(n,1)}e.length>GI&&e.splice(0,e.length-GI)}function Zpe(e,t){return(df.get(e)??[]).find(n=>n.inputId===t)??null}function Jpe(e,t){if(!Tu.isEnabled())return;const n=performance.now(),r=Wk(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)}Mm({t:n,event:"output:paint",sessionId:e,pendingInputs:r.length,deltaFromInputMs:Yk(r,n),details:i>0?`paint=${i}`:""}),qk(r,n)}function Yk(e,t){const n=e[0];return n?t-n.startedAt:null}function Qpe(e){return e==="\r"||e===`
|
|
607
607
|
`?"enter":e.startsWith("\x1B")?"escape":eme(e)?"control":e.length>16?"paste":/[\r\n]/.test(e)?"mixed":"printable"}function eme(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 tme(e){return e.kind==="printable"&&e.data.length>0&&e.data.length<=16}function nme(e){try{return Wpe.decode(e)}catch{return""}}function rme(e){return e.filter(Boolean).join(" ")}function Mo(e,t){if(!e||!t)return;const n=Vpe(e,t),r=Ua;if(!r){XI(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});XI(n,{sent:s,queueWhenDisconnected:!0,details:s?"sent-open-socket":"queued-or-dropped"})}function ime({sessionId:e,enabled:t,waiting:n,approvalRequestId:r,approvalScopeKey:i=e,history:s,sendRawInput:o=Mo}){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 sme(e){var i,s;if(e.session.mode!=="pty"||e.session.kind==="terminal"||e.session.provider==="codex")return null;const t=ZC(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 ome({target:e,sendRawInput:t,history:n}){return ime({sessionId:e.sessionId,enabled:e.enabled,waiting:e.waiting,approvalRequestId:e.approvalRequestId,approvalScopeKey:e.key,history:n,sendRawInput:t}),null}function ame({sendRawInput:e=Mo}){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=>sme({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(ome,{target:d,sendRawInput:e,history:l.current},d.key))})}function lme(e,t){return e.some(n=>n.sessionId===t)?e:[...e,{sessionId:t}]}const cme={[Ir.PATH_NOT_FOUND]:"文件不存在",[Ir.PATH_NOT_DIRECTORY]:"路径不是目录",[Ir.PATH_ACCESS_DENIED]:"无权访问该路径",[Ir.INVALID_PATH]:"路径无效",[Ir.SESSION_NOT_FOUND]:"会话已结束",[Ir.SESSION_ALREADY_ACTIVE]:"Codex 会话仍在运行",[Ir.PROXY_OFFLINE]:"开发机已离线",[Ir.PROVIDER_UNSUPPORTED]:"不支持的 Provider",[Ir.APPROVAL_POLICY_UNSUPPORTED]:"不支持的审批策略",[Ir.WORKER_START_FAILED]:"Worker 启动失败",[Ir.PROCESS_START_FAILED]:"进程启动失败"};function i6(e){const t=e.errorCode?cme[e.errorCode]:void 0;return t||(e.rawError&&e.rawError.trim().length>0?e.rawError:e.fallback)}function Vk(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 ume=new RegExp("(?<![\\p{L}\\p{N}@:/.-])(?:~\\/|[^\\s`\"'<>,。;:!?、@])[^\\s`\"'<>,。;:!?、@]*?\\.(?:png|jpe?g|webp|gif|bmp|heic|heif|mp4|webm|mov|m4v|ogv)(?=$|[\\s`\"'<>),;:!?,。;:!?、]|\\.(?:$|[\\s`\"'<>),;:!?,。;:!?、]))","giu"),dme=new RegExp("(?<![A-Za-z0-9._+-])@(?:~\\/|[^\\s`\"'<>,。;:!?、@])[^\\s`\"'<>,。;:!?、@]*?\\.(?:png|jpe?g|webp|gif|bmp|heic|heif|mp4|webm|mov|m4v|ogv)(?=$|[\\s`\"'<>),;:!?,。;:!?、]|\\.(?:$|[\\s`\"'<>),;:!?,。;:!?、]))","giu"),s6=/\.(?:png|jpe?g|webp|gif|bmp|heic|heif|mp4|webm|mov|m4v|ogv)$/i;function Kk(e){return e.replace(/^@/,"").replace(/^[([{]+/,"").replace(/[)\].,;:!?,。;:!?、]+$/u,"")}function o6(e){if(/[\\/]/.test(e))return!0;const t=e.replace(s6,""),n=t.split(/[\\/]/).pop()??t;return n.length<2?!1:/[\p{L}_-]/u.test(n)}function bc(e){const t=Kk(e);return/^[a-z][a-z0-9+.-]*:\/\//i.test(t)||Vk(t)||!s6.test(t)?null:/\.(?:mp4|webm|mov|m4v|ogv)$/i.test(t)?"video":"image"}function fme(e){const t=Kk(e);return bc(t)?o6(t):!1}function a6(e){const t=[];for(const n of[dme,ume])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=Kk(i),u=bc(l);!u||!o6(l)||t.push({kind:u,path:l,start:s,end:o})}return t.sort((n,r)=>n.start-r.start)}function hme(e){const t=new Set,n=[];for(const{path:r}of a6(e))t.has(r)||(t.add(r),n.push(r));return n}var Qc=function(e,t){return Number(e.toFixed(t))},pme=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},gme=function(e){return e},vme=function(e){return e*e},yme=function(e){return e*(2-e)},bme=function(e){return e<.5?2*e*e:-1+(4-2*e)*e},_me=function(e){return e*e*e},wme=function(e){return--e*e*e+1},xme=function(e){return e<.5?4*e*e*e:(e-1)*(2*e-2)*(2*e-2)+1},Sme=function(e){return e*e*e*e},Eme=function(e){return 1- --e*e*e*e},Cme=function(e){return e<.5?8*e*e*e*e:1-8*--e*e*e*e},kme=function(e){return e*e*e*e*e},Tme=function(e){return 1+--e*e*e*e*e},Rme=function(e){return e<.5?16*e*e*e*e*e:1+16*--e*e*e*e*e},l6={easeOut:mme,linear:gme,easeInQuad:vme,easeOutQuad:yme,easeInOutQuad:bme,easeInCubic:_me,easeOutCubic:wme,easeInOutCubic:xme,easeInQuart:Sme,easeOutQuart:Eme,easeInOutQuart:Cme,easeInQuint:kme,easeOutQuint:Tme,easeInOutQuint:Rme},c6=function(e){typeof e=="number"&&cancelAnimationFrame(e)},No=function(e){e.mounted&&(c6(e.animation),e.isAnimating=!1,e.animation=null,e.velocity=null)};function u6(e,t,n,r){if(e.mounted){var i=new Date().getTime(),s=1;No(e),e.animation=function(){if(!e.mounted)return c6(e.animation);var o=new Date().getTime()-i,l=o/n,u=l6[t],d=u(l);o>=n?(r(s),e.animation=null):e.animation&&(r(d),requestAnimationFrame(e.animation))},requestAnimationFrame(e.animation)}}function Ame(e){var t=e.scale,n=e.positionX,r=e.positionY;return!(Number.isNaN(t)||Number.isNaN(n)||Number.isNaN(r))}function _c(e,t,n,r){var i=Ame(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):u6(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 Nme(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 Mme=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}},Gk=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=Nme(n,r,t),u=l.wrapperWidth,d=l.wrapperHeight,f=l.newContentWidth,h=l.newContentHeight,v=l.newDiffWidth,g=l.newDiffHeight,_=Mme(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),_},Qp=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=Gk(e,t);return e.bounds=n,n};function Pm(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=Qp(e,l-h,d+h,r),_=Qp(t,u-v,f+v,r);return{x:g,y:_}}function s_(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=Pm(h,v,i,s,0,0,null);return g}var ZI=1e-7;function Im(e,t,n,r,i){var s=i?r:0,o=Math.max(t-s,ZI),l=n+s;return!Number.isNaN(n)&&e>=l?l:!Number.isNaN(t)&&e<=o?o:Math.max(e,ZI)}var JI=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=Om(s,n);return!(d||s.getAttribute("draggable")==="true"||s.getAttribute("contenteditable")==="true"||s.isContentEditable)},QI=function(e){var t=e.isInitialized,n=e.isPanning,r=e.setup,i=r.panning.disabled,s=t&&n&&!i;return!!s},Pme=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}},Ime=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 Ome(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=s_(e,x,T,i,e.bounds,l||u),A=k.x,P=k.y;return{scale:i,positionX:w?A:n,positionY:S?P:r}}}function d6(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=Pm(t,n,l,s,r,i,o),g=v.x,_=v.y;e.setState(d,g,_)}}var Lme=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}},rc=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},Yl;(function(e){e.TRACK_PAD="track_pad",e.MOUSE="mouse",e.TOUCH="touch"})(Yl||(Yl={}));var Dme=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},Bme=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 zme(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 eO(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:Qp(e,s,o,i)}function jme(e){var t=1,n=e.offsetWidth/window.innerWidth;return Number.isNaN(n)?t:Math.min(t,n)}var O0=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 Fme(e,t,n){var r,i,s=Dme(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=jme(d),x=(r={},r[Yl.TOUCH]=g,r[Yl.MOUSE]=_,r)[n],T=(i={},i[Yl.TOUCH]=v,i[Yl.MOUSE]=h,i)[n],k=t.x-o.x,A=t.y-o.y,P=O0(k/S,T,x),R=O0(A/S,T,x),M=w-l,z=k*k+A*A,V=O0(Math.sqrt(z)/M,T,x);e.velocity={velocityX:P,velocityY:R,total:V}}e.lastMousePosition=t,e.velocityTime=w}}function $me(e){var t=e.velocity,n=e.bounds,r=e.setup,i=e.wrapperComponent,s=Bme(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,P=_.sizeY,R=_.velocityAlignmentTime,M=R,z=zme(e,u),V=Math.max(z,M),W=rc(e,A),G=rc(e,P),O=W*i.offsetWidth/100,N=G*i.offsetHeight/100,L=d+O,D=f-O,I=h+N,B=v-N,F=e.state,U=new Date().getTime();u6(e,k,V,function(j){var Y=e.state,X=Y.scale,$=Y.positionX,ee=Y.positionY,re=new Date().getTime()-U,te=re/M,Z=l6[_.animationType],oe=1-Z(Math.min(1,te)),Q=1-j,fe=$+o*Q,ge=ee+l*Q,Ce=eO(fe,F.positionX,$,T,g,f,d,D,L,oe),De=eO(ge,F.positionY,ee,x,g,v,h,B,I,oe);if($!==fe||ee!==ge){e.setState(X,Ce,De);var ot=e.props.onPanning;ot&&ot(tr(e),{})}})}}function tO(e,t){var n=e.state,r=n.scale,i=n.positionX,s=n.positionY;e.panStartPosition={x:i,y:s},No(e),ff(e,r),window.TouchEvent!==void 0&&t instanceof TouchEvent?Ime(e,t):Pme(e,t)}function f6(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=Ome(e);v&&_c(e,v,d,f)}}function nO(e,t,n,r){var i=e.startCoords,s=e.setup,o=s.autoAlignment,l=o.sizeX,u=o.sizeY;if(i){var d=Lme(e,t,n),f=d.x,h=d.y,v=rc(e,l),g=rc(e,u);Fme(e,{x:f,y:h},r),d6(e,f,h,v,g)}}function Hme(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?$me(e):f6(e)}}function Xk(e,t,n,r){var i=e.setup,s=i.minScale,o=i.maxScale,l=i.limitToBounds,u=Im(Qc(t,2),s,o,0,!1),d=ff(e,u),f=s_(e,n,r,u,d,l),h=f.x,v=f.y;return{scale:u,positionX:h,positionY:v}}function Zk(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)&&f6(e),!(_||!i||!e.mounted)){var w=t||i.offsetWidth/2,S=n||i.offsetHeight/2,x=r<o?o:l,T=Xk(e,x,w,S);T&&_c(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 rO(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 L0={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"}},H1={wrapperClass:"react-transform-wrapper",contentClass:"react-transform-component"},h6=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:L0.scale,g=Math.min(Math.max(v,f),h),_=Qp((i=e.initialPositionX)!==null&&i!==void 0?i:L0.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=Qp((l=e.initialPositionY)!==null&&l!==void 0?l:L0.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}},iO=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]=rO(rO([],Zc[r],!0),e[r]):t[r]=e[r]}}),t.minScale<=0&&(t.minScale=1e-7),t},p6=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=Im(Qc(h,3),l,o,f,!1);return v};function m6(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=p6(e,t,n),k=Xk(e,T,S,x);if(!k)return console.error("Error during zoom event. New transformation state was not calculated.");var A=e.props,P=A.onZoomStart,R=A.onZoom,M=A.onZoomStop,z=new MouseEvent("mousemove",{bubbles:!0}),V=tr(e);cr(V,z,P),cr(V,z,R),_c(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(tr(e),z,M)},g)}function g6(e,t,n,r){var i,s,o=e.setup,l=e.wrapperComponent,u=e.contentComponent,d=o.limitToBounds,f=o.centerOnInit,h=h6(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=Jk(h.scale,l,u);S=T.positionX,x=T.positionY}var k=Gk(e,h.scale),A=Pm(S,x,k,d,0,0,l),P={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,V=R.onZoomStop,W=new MouseEvent("mousemove",{bubbles:!0}),G=tr(e);cr(G,W,M),cr(G,W,z),_c(e,P,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(tr(e),W,V)},t)}}}function Ume(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 Wme(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(),_=Ume(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,P=Im(n||Math.min(k,A),f,h,0,!1),R=(v.width-x*P)/2,M=(v.height-T*P)/2,z=(v.left-w)*P+R+r,V=(v.top-S)*P+M+i,W=Gk(e,P),G=Pm(z,V,W,d,0,0,s),O=G.x,N=G.y;return{positionX:O,positionY:N,scale:P}}var qme=function(e){return function(t,n,r){t===void 0&&(t=.5),n===void 0&&(n=300),r===void 0&&(r="easeOut"),m6(e,1,t,n,r)}},Yme=function(e){return function(t,n,r){t===void 0&&(t=.5),n===void 0&&(n=300),r===void 0&&(r="easeOut"),m6(e,-1,t,n,r)}},Vme=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};_c(e,g,i,s)}}},Kme=function(e){return function(t,n){t===void 0&&(t=200),n===void 0&&(n="easeOut"),g6(e,t,n)}},Gme=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=Jk(t||i.scale,s,o);_c(e,l,n,r)}}},Xme=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),No(e);var l=e.wrapperComponent,u=typeof t=="string"?document.getElementById(t):t;if(l&&u&&l.contains(u)){var d=Wme(e,u,n,s,o);_c(e,d,r,i)}}},U1=function(e){return{instance:e,state:e.state,zoomIn:qme(e),zoomOut:Yme(e),setTransform:Vme(e),resetTransform:Kme(e),centerView:Gme(e),zoomToElement:Xme(e)}},Zme=function(e){return{instance:e,state:e.state}},tr=function(e){var t={};return Object.assign(t,Zme(e)),Object.assign(t,U1(e)),t},D0=!1;function B0(){try{var e={get passive(){return D0=!0,!1}};return e}catch{return D0=!1,D0}}var Rv=".".concat(H1.wrapperClass),Om=function(e,t){return t.some(function(n){return e.matches("".concat(Rv," ").concat(n,", ").concat(Rv," .").concat(n,", ").concat(Rv," ").concat(n," *, ").concat(Rv," .").concat(n," *"))})},em=function(e){e&&clearTimeout(e)},Jme=function(e){return Number.parseFloat(e.toFixed(8))},v6=function(e,t,n){var r=Jme(n);return"translate(".concat(e,"px, ").concat(t,"px) scale(").concat(r,")")},Jk=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 Qme(e,t){e!=null&&(typeof e=="function"?e(t):e.current=t)}function ege(e){return function(t){e.forEach(function(n){typeof n=="function"?n(t):n!=null&&(n.current=t)})}}var y6=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=Om(d,o);if(h)return!1;var v=e.isPressingKeys(e.setup.wheel.activationKeys);return!!v},tge=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=y6(e,t);if(l)return!1;var u=t.target,d=Om(u,o);if(d)return!1;var f=e.isPressingKeys(s);return!!f},nge=function(e){return e?e.deltaY<0?1:-1:0};function rge(e,t){var n=nge(e),r=pme(t,n);return r}function b6(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 ige=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=Im(_,d,u,v,w&&!h);return S},_6=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},sge=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=Om(o,i);return!u},oge=function(e){var t=e.setup.pinch.disabled,n=e.isInitialized,r=e.pinchStartDistance,i=n&&!t&&r!==null;return!!i},age=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}},w6=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))},lge=5,cge=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/lge),S=n+w,x=S===1/0?0:Qc(S,10);return Im(x,o,s,f,!h&&!u)},x6=160,S6=100,uge=function(e,t){var n=e.props,r=n.onWheelStart,i=n.onZoomStart;e.wheelStopEventTimer||(No(e),cr(tr(e),t,r),cr(tr(e),t,i))},dge=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=rge(t,null),k=_?x*Math.abs(t.deltaY):x,A=ige(e,T,k,!t.ctrlKey);if(u!==A){var P=ff(e,A),R=b6(t,s,u),M=S||w===0||f||g,z=d&&M,V=s_(e,R.x,R.y,A,P,z),W=V.x,G=V.y;e.previousWheelEvent=t,e.setState(A,W,G),cr(tr(e),t,r),cr(tr(e),t,i)}},fge=function(e,t){var n=e.props,r=n.onWheelStop,i=n.onZoomStop;em(e.wheelAnimationTimer),e.wheelAnimationTimer=setTimeout(function(){e.mounted&&(Zk(e,t.x,t.y),e.wheelAnimationTimer=null)},S6);var s=_6(e,t);s&&(em(e.wheelStopEventTimer),e.wheelStopEventTimer=setTimeout(function(){e.mounted&&(e.wheelStopEventTimer=null,cr(tr(e),t,r),cr(tr(e),t,i))},x6))},hge=function(e,t){var n=e.props,r=n.onWheelStart,i=n.onPanningStart;e.wheelStopEventTimer||(No(e),cr(tr(e),t,r),cr(tr(e),t,i))},pge=function(e,t){var n=e.props,r=n.onWheelStop,i=n.onPanningStop;em(e.wheelAnimationTimer),e.wheelAnimationTimer=setTimeout(function(){e.mounted&&(Zk(e,t.x,t.y),e.wheelAnimationTimer=null)},S6);var s=_6(e,t);s&&(em(e.wheelStopEventTimer),e.wheelStopEventTimer=setTimeout(function(){e.mounted&&(e.wheelStopEventTimer=null,cr(tr(e),t,r),cr(tr(e),t,i))},x6))},E6=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}},mge=function(e,t){var n=w6(t);e.pinchStartDistance=n,e.lastDistance=n,e.pinchStartScale=e.state.scale,e.isPanning=!1,e.isPinching=!0,e.pinchPreviousCenter=E6(t),No(e)},gge=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=age(t,o,n);if(!(!Number.isFinite(x.x)||!Number.isFinite(x.y))){var T=w6(t),k=cge(e,T),A=E6(t),P=o/k,R=(A.x-((s==null?void 0:s.x)||0))*P,M=(A.y-((s==null?void 0:s.y)||0))*P;if(!(k===o&&R===0&&M===0)){e.pinchPreviousCenter=A;var z=ff(e,k),V=_||w===0||d,W=u&&V,G=s_(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,I=rc(e,L,k),B=rc(e,D,k),F=O+R,U=N+M,j=Pm(F,U,z,u,I,B,i),Y=j.x,X=j.y;e.setState(k,Y,X)}}}}},vge=function(e){var t=e.pinchMidpoint;e.velocity=null,e.lastDistance=null,e.pinchMidpoint=null,e.pinchStartScale=null,e.pinchStartDistance=null,e.isPinching=!1,Zk(e,t==null?void 0:t.x,t==null?void 0:t.y)},C6=function(e,t){var n=e.props.onZoomStop,r=e.setup.doubleClick.animationTime;em(e.doubleClickStopEventTimer),e.doubleClickStopEventTimer=setTimeout(function(){e.doubleClickStopEventTimer=null,cr(tr(e),t,n)},r)},yge=function(e,t){var n=e.props,r=n.onZoomStart,i=n.onZoom,s=e.setup.doubleClick,o=s.animationTime,l=s.animationType;cr(tr(e),t,r),g6(e,o,l,function(){return cr(tr(e),t,i)}),C6(e,t)};function bge(e,t){return e==="toggle"?t===1?1:-1:e==="zoomOut"?-1:1}function _ge(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 yge(e,t);if(!s)return console.error("No ContentComponent found");var S=bge(v,e.state.scale),x=p6(e,S,g);if(o!==x){cr(tr(e),t,u);var T=b6(t,s,o),k=Xk(e,x,T.x,T.y);if(!k)return console.error("Error during zoom event. New transformation state was not calculated.");cr(tr(e),t,d),_c(e,k,_,w),C6(e,t)}}}var wge=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=Om(u,l);return!h},xge=(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=iO(r)},this.initializeWindowEvents=function(){var r,i,s,o,l=B0(),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=B0(),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),No(n),(l=n.observer)===null||l===void 0||l.disconnect()},this.handleInitializeWrapperEvents=function(r){var i=B0();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(tr(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(tr(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=y6(n,r);s&&(uge(n,r),dge(n,r),fge(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=tge(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=rc(n,x),A=rc(n,T);_===f&&w===h||(hge(n,r),d6(n,_,w,k,A),cr(tr(n),r,i),pge(n,r))}},this.onPanningStart=function(r){var i=n.setup.disabled,s=n.props.onPanningStart;if(!i){n.syncModifierKeys(r);var o=JI(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(),No(n),tO(n,r),cr(tr(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=QI(n);if(o){var l=n.isPressingKeys(n.setup.panning.activationKeys);l&&(r.preventDefault(),r.stopPropagation(),nO(n,r.clientX,r.clientY,Yl.MOUSE),cr(tr(n),r,s))}}},this.onPanningStop=function(r){var i=n.setup.panning.velocityDisabled,s=n.props.onPanningStop;n.isPanning&&(Hme(n,i),cr(tr(n),r,s))},this.onPinchStart=function(r){var i=n.setup.disabled,s=n.props.onPinchStart;if(!i){var o=sge(n,r);o&&(mge(n,r),No(n),cr(tr(n),r,s))}},this.onPinch=function(r){var i=n.setup.disabled,s=n.props.onPinch;if(!i){var o=oge(n);o&&(r.preventDefault(),r.stopPropagation(),gge(n,r),cr(tr(n),r,s))}},this.onPinchStop=function(r){var i=n.props.onPinchStop;n.pinchStartScale&&(vge(n),cr(tr(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,No(n);var f=r.touches,h=f.length===1,v=f.length===2,g=JI(n,r);if(h){if(!g)return;No(n),tO(n,r),cr(tr(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=QI(n);if(!o)return;r.cancelable&&r.preventDefault(),r.stopPropagation();var l=r.touches[0];nO(n,l.clientX,l.clientY,Yl.TOUCH),cr(tr(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=wge(n,r);s&&_ge(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=Jk(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):v6(r,i,s)},this.getContext=function(){return tr(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:tr(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=tr(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=tr(n);cr(s,void 0,n.props.onInit),Qme(n.props.ref,s)},this.props=t,this.setup=iO(this.props),this.state=h6(this.props)}return e})(),o_=mt.createContext(null),Sge=function(e,t){return typeof e=="function"?e(t):e},Ege=mt.forwardRef(function(e,t){var n=b.useRef(new xge(e)).current,r=Sge(e.children,U1(n));return b.useImperativeHandle(t,function(){return U1(n)},[n]),b.useEffect(function(){n.update(e)},[n,e]),m.jsx(o_.Provider,po({value:n},{children:r}))});mt.forwardRef(function(e,t){var n=b.useRef(null),r=b.useContext(o_);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:ege([n,t])}))});function Cge(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 kge=`.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 fEe(e){const{sessionId:t,active:n=!0,containerEl:r,spacerRef:i,xtermHostRef:s,selectionHandleLayerRef:o,mobileControlsHeight:l}=e,u=s1e(),d=u.markDisconnected,f=c1e(),h=Q1e(),{openMediaPreview:v}=l_(),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),P=b.useRef(n),R=b.useRef(n),M=b.useRef(!1),z=b.useRef(!1),V=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}),I=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,Y]=b.useState({scrollTop:0,scrollLeft:0,scrollHeight:0,scrollWidth:0,clientHeight:0,clientWidth:0,scrollable:!1,horizontalScrollable:!1}),[X,$]=b.useState(!1),[ee,re]=b.useState(!1),[te,Z]=b.useState({resultIndex:-1,resultCount:0}),oe=Re(Oe=>Oe.connected),Q=Re(Oe=>Oe.proxyOnline),fe=Re(Oe=>Oe.ptyFontSize),ge=Re(Oe=>Oe.inputModePreference),Ce=Re(Oe=>Oe.adaptiveInputModality),De=Re(Oe=>Oe.setAdaptiveInputModality),ot=Ce==="hardware",Dt=bo("(pointer: coarse), (hover: none)"),{bottomOffset:et,layoutBottomInset:ut}=ET(),Ne=ge==="hardware",Ue=aEe({touchEditingSurface:Dt,inputModePreference:ge,detectedPhysicalKeyboard:ot,softKeyboardDetected:et>0}),ye=Dt&&!Ue,nt=Ue?0:et,He=nt>0,Ae=Ue?0:ut,[Ze,Tt]=b.useState(()=>oe&&Q);I.current=Ue,P.current=n,M.current=u.ready,z.current=oe&&Q;const ve=b.useCallback(()=>P.current&&M.current&&z.current,[]),Ke=b.useCallback(Oe=>{const qe=Ut.getState().sessions.find(Be=>Be.sessionId===t);if((qe==null?void 0:qe.mode)!=="pty"||qe.ptyOwner!=="proxy-hosted")return;const ct=g.current,yt=s.current,Gt=zt;if(!ve()||!ct||!yt||!r||!Gt){$e.error("终端尚未就绪");return}const Te=_.current.at(-1)??ct,_t=Oe==="fit"?Mxe(r,yt,ct):Nxe(Te,Oe);if(!_t){$e.error("无法获取终端显示区域的尺寸");return}_t.cols===Te.cols&&_t.rows===Te.rows||(Gt.sendControl({type:"terminal_resize_request",sessionId:t,..._t})?(_.current.push(_t),Ut.getState().setPtyGeometry(t,_t)):$e.error("终端尺寸调整失败,请检查连接"))},[ve,r,t,s]);b.useEffect(()=>{(!n||!u.ready||!oe||!Q)&&(_.current=[]);const Oe=_.current.at(-1)??g.current;Ut.getState().setPtyGeometry(t,u.ready&&oe&&Q&&Oe?{cols:Oe.cols,rows:Oe.rows}:null)},[n,u.ready,oe,Q,t]),b.useEffect(()=>{oe&&Q&&Tt(!0)},[oe,Q]),b.useEffect(()=>{nt>0&&$(!0)},[nt]);const be=l1e({containerEl:r,xtermHostRef:s,terminalRef:g}),{ptyInputFocused:Je,suppressPtyFocus:pt,focusPtyInput:wt,handleFocusCapture:Bt,handleBlurCapture:mn}=be,on=sEe({softKeyboardEditingSurface:ye,ptyInputFocused:Je,keyboardOpen:He});U.current={keyboardOffset:nt,hasSeenSoftKeyboard:X,showMobilePtyControls:on,touchEditingSurface:Dt,ptyInputFocused:Je,containerPaddingBottom:U.current.containerPaddingBottom,mobileControlsBottomInset:Ae};const nn=f.clearNewFramesWhileAway;O.current||(O.current=FL(()=>{var Oe;(Oe=A.current)==null||Oe.relayout()}));const Et=b.useCallback(()=>{F.current=!1},[]);N.current||(N.current=FL(()=>{var qe,ct;const Oe=L.current??{reason:"rawInput",force:!1};L.current=null,Oe.force&&Et(),(qe=A.current)==null||qe.traceRawInputFollowFire(),(ct=A.current)==null||ct.scrollToBottom(Oe.reason,Oe.force?{force:!0}:void 0),nn()}));const pn=b.useCallback(()=>{if(F.current)return;const Oe=A.current;Oe&&Oe.preparePageResumeRestore(),F.current=!0},[]),Wt=b.useCallback(()=>{if(!F.current||document.visibilityState==="hidden"||!P.current||!M.current)return;const Oe=A.current;Oe&&(Oe.restorePageResume(),nn(),F.current=!1)},[nn]);b.useEffect(()=>()=>{var Oe,qe;(Oe=O.current)==null||Oe.dispose(),(qe=N.current)==null||qe.dispose(),O.current=null,N.current=null},[]),b.useEffect(()=>{const Oe=()=>{pn()},qe=()=>{if(document.visibilityState==="hidden"){Oe();return}Wt()};return document.addEventListener("visibilitychange",qe),window.addEventListener("pagehide",Oe),window.addEventListener("pageshow",Wt),window.addEventListener("focus",Wt),()=>{document.removeEventListener("visibilitychange",qe),window.removeEventListener("pagehide",Oe),window.removeEventListener("pageshow",Wt),window.removeEventListener("focus",Wt)}},[pn,Wt]),b.useLayoutEffect(()=>{const Oe=R.current;if(R.current=n,!n){Oe&&pn();return}(!Oe||F.current)&&u.ready&&Wt()},[n,u.ready,pn,Wt]);const tn=b.useCallback((Oe="rawInput",qe)=>{var Gt,Te;const ct=L.current,yt=(ct==null?void 0:ct.force)===!0||(qe==null?void 0:qe.force)===!0;L.current={reason:(qe==null?void 0:qe.force)===!0||!ct?Oe:ct.reason,force:yt},(Gt=A.current)==null||Gt.traceRawInputFollowScheduled(Oe),(Te=N.current)==null||Te.schedule()},[]),wn=b.useCallback((Oe,qe)=>{var ct,yt;!Oe||PL(Oe)||((ct=A.current)==null||ct.resumeHorizontalCursorFollow(qe),!(!Oe.includes("\r")&&!Oe.includes(`
|
|
742
742
|
`))&&((yt=A.current)==null||yt.resetHorizontalScroll(qe,{holdUntilCursorVisible:!0})))},[]),nr=b.useCallback(()=>I.current?"submit":"linefeed",[]),or=b.useCallback(()=>I.current,[]);b.useEffect(()=>{if(!n||ge!=="auto"||!Dt)return;const Oe=ct=>{const yt=s.current,Gt=r;return ct instanceof Node?yt!=null&&yt.contains(ct)||ct===document.body||ct===document.documentElement?!0:Gt!=null&&Gt.contains(ct)?ct instanceof HTMLElement?ct.closest('a,button,input,textarea,select,[contenteditable="true"],[role="button"],[role="textbox"]')===null:!0:!1:ct===window},qe=ct=>{var Te,_t;if(!lEe({active:P.current,touchEditingSurface:Dt,key:ct.key,code:ct.code,altKey:ct.altKey,ctrlKey:ct.ctrlKey,metaKey:ct.metaKey,isComposing:ct.isComposing,targetAcceptsPtyInput:Oe(ct.target)}))return;De("hardware"),I.current=!0,(Te=g.current)==null||Te.focus();const yt=s.current;if(ct.target instanceof Node&&(yt!=null&&yt.contains(ct.target)))return;const Gt=dEe(ct,(_t=g.current)==null?void 0:_t.modes);!Gt||!ve()||(ct.preventDefault(),ct.stopPropagation(),Mo(t,Gt),tn("physicalKeyboard"),wn(Gt,"physicalKeyboardEnter"))};return window.addEventListener("keydown",qe,!0),()=>window.removeEventListener("keydown",qe,!0)},[n,ve,r,ge,wn,tn,t,De,Dt,s]);const Cn=b.useCallback(Oe=>{const qe=zt;if(!qe){$e.error("请先连接开发机");return}const ct=$e.loading(`下载 ${Oe} ...`);a_({relay:qe,sessionId:t,path:Oe}).then(yt=>{yt.ok?$e.success(`已开始下载 ${Oe}`,{id:ct}):$e.error(yt.error,{id:ct})}).catch(yt=>{$e.error(yt instanceof Error?yt.message:String(yt),{id:ct})})},[t]),q=b.useCallback(Oe=>{const qe=g.current;return qe?DSe(qe,T.current,Oe):!1},[]),se=b.useCallback(Oe=>{const qe=g.current;return qe?LSe(qe,T.current,Oe):!1},[]),ae=J1e({terminalRef:g,xtermHostRef:s,selectionHandleLayerRef:o,scrollControllerRef:A,containerEl:r,keyboardOffset:nt,ptyFontSize:fe,suppressPtyFocus:pt,focusPtyInput:wt,onTap:q,isTapCandidate:se,onDownloadPath:Cn,onPreviewPath:v}),ke=ae.clearManagedPtySelection,he=ae.clearPtySelection;B.current=ae.hasPtySelection();const K=b.useCallback(()=>{const Oe=g.current,qe=S.current,ct=x.current&&Oe?AL(Oe.getSelectionPosition(),Oe.cols):null;qe==null||qe.render(ct)},[]),ie=rEe({sessionId:t,terminalRef:g,onAfterPaste:()=>tn("paste")}),ce=b.useCallback(Oe=>{if(!ve()){Oe.preventDefault();return}ie(Oe)},[ve,ie]),[pe,J]=b.useState(!1),le=b.useCallback(Oe=>{Oe.dataTransfer.types.includes("Files")&&(Oe.preventDefault(),J(qe=>qe||!0))},[]),ue=b.useCallback(Oe=>{Oe.currentTarget.contains(Oe.relatedTarget)||J(!1)},[]),Me=b.useCallback(async Oe=>{var Gt,Te;const qe=(Gt=Oe.dataTransfer.files)==null?void 0:Gt[0];if(!qe||(Oe.preventDefault(),J(!1),!ve()))return;const ct=zt;if(!ct){$e.error("请先连接开发机");return}const yt=await om({relay:ct,sessionId:t,file:qe});yt&&(Mo(t,`@${yt} `),(Te=A.current)==null||Te.resumeHorizontalCursorFollow("dropUpload"),tn("dropUpload"))},[ve,tn,t]),Xe=b.useCallback(Oe=>{var ct;if(!ve()){Oe.preventDefault();return}const qe=Oe.target;qe instanceof Element&&qe.closest(".xterm")||(Oe.preventDefault(),(ct=g.current)==null||ct.focus())},[ve]);b.useEffect(()=>{if(!Ze)return;const Oe=s.current,qe=Ua,ct=zt,yt=r,Gt=i.current;if(!Oe||!qe||!ct||!yt||!Gt)return;let Te=null,_t=null,Be=null,Ge=null,Rt=null,Jt=null,vn=null,At=null,gn=null;const Qr=nSe({host:Oe,sessionId:t,ws:qe,relay:ct,scheduleAutoFocus:ye?()=>{}:Pn=>{requestAnimationFrame(()=>{qL(s.current)&&Pn()})},createTerminal:async Pn=>{const jn=await iH(Pn,{fontSize:Re.getState().ptyFontSize});return gn=jn.serializeAddon,jn},attachRawInput:(Pn,jn,Wr)=>c0e(Pn,jn,{...Wr,getPlainEnterBehavior:nr,isPhysicalKeyboardMode:or,physicalKeyboardMode:Ne}),isInputEnabled:ve,canFocus:ve,onTerminalReady:Pn=>{he();const jn=Pn;g.current=jn,_.current=[],vn=jn.onResize(({cols:Mt,rows:Lt})=>{const gt=_.current,In=gt.findIndex(Hn=>Hn.cols===Mt&&Hn.rows===Lt);_.current=In>=0?gt.slice(In+1):[],M.current&&z.current&&Ut.getState().setPtyGeometry(t,_.current.at(-1)??{cols:Mt,rows:Lt})});const Wr=new eye({highlightLimit:1e3});jn.loadAddon(Wr),w.current=Wr,Rt=Wr.onDidChangeResults(Mt=>{Z(Mt),K()}),re(!0);const xc=mSe(jn,v);Te=xc.dispose;const de=RSe(jn,Cn);_t=de.dispose,T.current=[xc.provider,de.provider],QSe(()=>g.current);const je=Pxe(jn),Ye=Fxe(Oe,{serializeRangeAsHtml:(Mt,Lt)=>(gn==null?void 0:gn.serializeAsHTML({range:{startLine:Mt,endLine:Math.min(Lt,Math.max(0,jn.buffer.active.length-1)),startCol:0},includeGlobalBackground:!0,onlySelection:!1,scrollback:0}))??"",getSerializedCell:(Mt,Lt)=>{var In;const gt=(In=jn.buffer.active.getLine(Mt))==null?void 0:In.getCell(Lt);return gt?{text:gt.getWidth()===0?"":gt.getChars()||" ",isDim:!!gt.isDim(),isRenderedFgRGB:gt.isInverse()?gt.isBgRGB():gt.isFgRGB()}:null},getSelectionLine:Mt=>jn.buffer.active.getLine(Mt)??null,getBufferRowIdentityOffset:je.getOffset});Ge=()=>{Ye.dispose(),je.dispose()};const at=F.current;at&&(W.current=!1);const vt=V0e({container:yt,spacer:Gt,host:Oe,term:jn,hasNewFrame:()=>V.current,consumeNewFrame:()=>{V.current=!1},hasNewFramesWhileAway:()=>f.hasNewFramesWhileAwayRef.current,setNewFramesWhileAway:f.setHasNewFramesWhileAway,onAtBottomChange:f.handleAtBottomChange,onScrollStateChange:Y,initialUserHasVerticalScrollIntent:at?!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=vt,Be=vt.dispose,At=uH({terminal:jn,container:yt,getLine:Mt=>sb(Oe,Mt)??jn.buffer.active.getLine(Mt)??null,resolveRange:()=>x.current?AL(jn.getSelectionPosition(),jn.cols):null,projectionOnly:!0,overlaySlot:"pty-search-selection-overlay",segmentSlot:"pty-search-selection-segment",selectionBackground:HE.activeMatchBackground,borderColor:HE.activeMatchBorder,opacity:"0.62"}),S.current=At,Jt=jn.onSelectionChange(K),K(),at&&(vt.restorePageResume(),nn(),F.current=!1),t1e(()=>{var Li;const Mt=Sr=>{if(!Sr)return null;const hi=Sr.getBoundingClientRect();return{top:hi.top,bottom:hi.bottom,height:hi.height,left:hi.left,right:hi.right,width:hi.width}},Lt=document.querySelector('[data-slot="pty-mobile-controls"]'),gt=document.querySelector("[data-keyboard-offset]"),In=window.visualViewport,Hn=Mt(Lt),Fn=(In==null?void 0:In.height)??window.innerHeight;return{...r1e(vt.getDebugProbe,{container:yt,spacer:Gt,host:Oe,term:jn}),mobileLayout:{...U.current,window:{innerHeight:window.innerHeight,outerHeight:window.outerHeight,documentClientHeight:document.documentElement.clientHeight},visualViewport:In?{height:In.height,width:In.width,offsetTop:In.offsetTop,pageTop:In.pageTop,scale:In.scale}:null,chatRoot:{dataKeyboardOffset:(gt==null?void 0:gt.getAttribute("data-keyboard-offset"))??null,rect:Mt(gt)},ptyViewRect:Mt(yt.parentElement),containerRect:Mt(yt),controlsRect:Hn,controlsOverflowBelowVisualViewport:Hn===null?null:Hn.bottom-Fn,activeElement:document.activeElement instanceof HTMLElement?{tag:document.activeElement.tagName,ariaLabel:document.activeElement.getAttribute("aria-label"),slot:(Li=document.activeElement.closest("[data-slot]"))==null?void 0:Li.getAttribute("data-slot")}:null},frame:{lastWriteAt:G.current,pendingNewFrame:V.current}}})},onFramePending:()=>{var Pn;V.current=!0,(Pn=A.current)==null||Pn.markHorizontalLiveFramePending(),W.current&&!f.hasNewFramesWhileAwayRef.current&&f.setHasNewFramesWhileAway(!0)},onFrameWritten:()=>{var Pn;G.current=performance.now(),(Pn=O.current)==null||Pn.schedule()},onRawInput:Pn=>{PL(Pn)||(tn("rawInput",{force:!0}),wn(Pn,"rawInputEnter"))},onError:Pn=>{const jn=Pn instanceof Error?Pn.message:String(Pn);$e.error(`终端初始化失败:${jn}`)},connectTransportInitially:oe&&Q,...u.transport,onReady:()=>{_.current=[];const Pn=g.current;Pn&&Ut.getState().setPtyGeometry(t,{cols:Pn.cols,rows:Pn.rows}),u.transport.onReady()}});return k.current=Qr,()=>{x.current=!1,Jt==null||Jt.dispose(),vn==null||vn.dispose(),_.current=[],Ut.getState().setPtyGeometry(t,null),At==null||At.dispose(),S.current===At&&(S.current=null),he(),Be==null||Be(),Ge==null||Ge(),Rt==null||Rt.dispose(),n1e(),Te==null||Te(),_t==null||_t(),T.current=[],e1e(),w.current=null,re(!1),Z({resultIndex:-1,resultCount:0}),Qr.dispose(),g.current=null,A.current=null,k.current=null}},[t,Ze,r,i,s,u.transport,f.handleAtBottomChange,f.hasNewFramesWhileAwayRef,f.setHasNewFramesWhileAway,ve,Ne,nr,or,Cn,v,pt,tn,wn,he,K]),b.useEffect(()=>{if(!Ze)return;const Oe=k.current;if(Oe){if(!oe||!Q){d(),Oe.setTransportActive(!1);return}return iSe(t,n?"active":"background",()=>{var qe;(qe=k.current)==null||qe.setTransportActive(!0)})}},[n,oe,d,Q,t,Ze]),b.useEffect(()=>{const Oe=g.current,qe=A.current;!Oe||!qe||Rxe(Oe,fe,qe.relayout)},[fe]),b.useEffect(()=>{if(!n||!u.ready||ye)return;const Oe=requestAnimationFrame(()=>{var qe;qL(s.current)&&((qe=g.current)==null||qe.focus())});return()=>cancelAnimationFrame(Oe)},[n,u.ready,ye,s]);const ft=b.useCallback((Oe="viewExternal",qe)=>{var ct;qe!=null&&qe.force&&Et(),(ct=A.current)==null||ct.scrollToBottom(Oe,qe)},[Et]),lt=b.useCallback(Oe=>{var qe;(qe=A.current)==null||qe.scrollToRatio(Oe)},[]),Ot=b.useCallback(Oe=>{var qe;(qe=A.current)==null||qe.scrollToXRatio(Oe)},[]),Ct=b.useCallback(Oe=>{var _t;const qe=g.current,ct=qe==null?void 0:qe.getSelectionPosition();if(!qe||!ct)return;const yt=ct.start.y;if(yt>=Oe&&yt<Oe+qe.rows)return;const Gt=Math.max(0,qe.buffer.active.length-qe.rows);if(Gt===0)return;const Te=Math.max(0,Math.min(Gt,yt-Math.floor(qe.rows/2)));(_t=A.current)==null||_t.scrollToRatio(Te/Gt)},[]),xt=b.useCallback((Oe,qe=!1)=>{const ct=g.current,yt=w.current;if(!ct||!yt||!Oe)return Oe||(x.current=!1,yt==null||yt.clearDecorations(),ct==null||ct.clearSelection(),ke(),K(),Z({resultIndex:-1,resultCount:0})),!1;ke(),x.current=!0;const Gt=ct.buffer.active.viewportY,Te=yt.findNext(Oe,{...eD,incremental:qe});return Te&&Ct(Gt),K(),Te},[ke,K,Ct]),qt=b.useCallback(Oe=>{const qe=g.current,ct=w.current;if(!qe||!ct||!Oe)return!1;ke(),x.current=!0;const yt=qe.buffer.active.viewportY,Gt=ct.findPrevious(Oe,eD);return Gt&&Ct(yt),K(),Gt},[ke,K,Ct]),jt=b.useCallback(()=>{var Oe,qe;x.current=!1,(Oe=w.current)==null||Oe.clearDecorations(),(qe=g.current)==null||qe.clearSelection(),ke(),K(),Z({resultIndex:-1,resultCount:0})},[ke,K]),fn=b.useCallback(Oe=>{var ct,yt;if(!ve())return;const qe=kp(Oe,(ct=g.current)==null?void 0:ct.modes);Mo(t,qe),tn("mobileControl",{force:!0}),wn(Oe,"mobileControlEnter"),(yt=g.current)==null||yt.focus()},[ve,wn,tn,t]),Ht=b.useCallback(()=>{var qe,ct,yt;if(!ve())return;const Oe=(ct=(qe=navigator.clipboard)==null?void 0:qe.readText)==null?void 0:ct.bind(navigator.clipboard);if(!window.isSecureContext||!Oe){$e.error("无法读取剪贴板"),(yt=g.current)==null||yt.focus();return}Oe().then(Gt=>{if(!Gt)return;const Te=g.current;if(Te){Te.paste(Gt);return}Mo(t,Gt),tn("paste"),wn(Gt,"pasteEnter")}).catch(Gt=>{const Te=Gt instanceof Error&&Gt.message?Gt.message:"无法读取剪贴板";$e.error(Te)}).finally(()=>{var Gt;return(Gt=g.current)==null?void 0:Gt.focus()})},[ve,wn,tn,t]),Mn=uEe({showMobilePtyControls:on,horizontalScrollable:j.horizontalScrollable,mobileControlsHeight:l});U.current.containerPaddingBottom=Mn,b.useEffect(()=>{var ct,yt;B.current?(ct=A.current)==null||ct.relayout():(yt=O.current)==null||yt.schedule();const Oe=D.current,qe=oEe({controlsVisible:on,keyboardOpen:He,previous:Oe});D.current={keyboardOpen:He,controlsVisible:on},on&&(B.current?nn():qe&&tn("keyboardOffset",{force:!0}))},[nt,He,on,Mn,nn,tn]);const bn=b.useMemo(()=>({onFocusCapture:Bt,onBlurCapture:mn}),[Bt,mn]);return{scrollState:j,isAtBottom:f.isAtBottom,hasNewFramesWhileAway:f.hasNewFramesWhileAway,ptyInputFocused:Je,showMobilePtyControls:on,touchEditingSurface:Dt,keyboardOffset:nt,physicalKeyboardMode:Ue,softKeyboardEditingSurface:ye,mobileControlsBottomInset:Ae,connectionReady:u.ready,connectionOverlay:u.overlay,containerPaddingBottom:Mn,traceEnabled:h,findReady:ee,findResultIndex:te.resultIndex,findResultCount:te.resultCount,findNext:xt,findPrevious:qt,clearFind:jt,resizeTerminal:Ke,scrollToBottom:ft,scrollToRatio:lt,scrollToXRatio:Ot,clearNewFramesWhileAway:nn,sendMobileInput:fn,pasteMobileClipboard:Ht,handleTerminalContainerMouseDown:Xe,handlePasteCapture:ce,pointerHandlers:ae.pointerHandlers,focusHandlers:bn,ptySelectionToolbar:ae.ptySelectionToolbar,ptySelectionHandles:ae.ptySelectionHandles,ptySelectionPathAction:ae.ptySelectionPathAction,ptySelectionHandleMetrics:ae.ptySelectionHandleMetrics,copyPtySelection:ae.copyPtySelection,openPtySelectionPathAction:ae.openPtySelectionPathAction,handlePtySelectionHandlePointerDown:ae.handlePtySelectionHandlePointerDown,handlePtySelectionHandleTouchStart:ae.handlePtySelectionHandleTouchStart,isPtyDragOver:pe,handlePtyDragOver:le,handlePtyDragLeave:ue,handlePtyDrop:Me}}function hEe({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=fEe({sessionId:e,active:r,containerEl:l,spacerRef:w,xtermHostRef:S,selectionHandleLayerRef:x,mobileControlsHeight:d}),k=T.ptySelectionHandleMetrics,{clearFind:A,findNext:P,findPrevious:R,findReady:M,findResultCount:z,findResultIndex:V}=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(()=>{P(g)},[P,g]),L=b.useCallback(()=>v(!0),[]),D=b.useCallback(()=>{v(!1),A()},[A]),I=O6({enabled:r,open:h,openRequest:i,onOpen:L,onClose:D,onPrevious:O,onNext:N});return b.useEffect(()=>{!h||!M||(g?P(g,!0):A())},[A,P,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(W1,{query:g,resultIndex:V,resultCount:z,focusRequest:I.focusRequest,loading:!!g&&!M,onQueryChange:_,onPrevious:O,onNext:N,onClose:I.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(N6,{visible:!T.isAtBottom,hasNewMessages:T.hasNewFramesWhileAway,className:h?"top-14":"top-10",onClick:()=>{T.scrollToBottom("backToBottomBtn",{force:!0}),T.clearNewFramesWhileAway()}}),T.showMobilePtyControls?m.jsx(fve,{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(nD,{kind:"anchor",metrics:k,"aria-label":"调整选区起点",onPointerDown:B=>T.handlePtySelectionHandlePointerDown("anchor",B),onTouchStart:B=>T.handlePtySelectionHandleTouchStart("anchor",B)}),m.jsx(nD,{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"?bc(T.ptySelectionPathAction.path)==="video"?"预览终端选区视频":"预览终端选区图片":"下载终端选区文件",children:T.ptySelectionPathAction.kind==="media-preview"?"预览":"下载"}):null]}):null,m.jsx(_ve,{state:T.scrollState,scrollContainer:l,onScrollRatio:T.scrollToRatio}),m.jsx(wve,{state:T.scrollState,onScrollRatio:T.scrollToXRatio}),m.jsx(Xge,{...T.connectionOverlay}),m.jsx(Jge,{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(pEe,{}):null]})}function nD({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 pEe(){const[e,t]=b.useState(!1);async function n(){const r=Kge();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 mEe=1024,gEe=720,Wv=.5,BH=b.createContext(null);function vEe({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=>lme(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(P=>!A||P&&_Ee(P,A)?P:A)},[]),S=b.useCallback((k,A)=>{A!==void 0&&n(P=>P.map(R=>R.sessionId===k?{...R,findRequest:A}:R))},[]),x=b.useCallback((k,A)=>{A===void 0||h.current!==k||n(P=>P.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(P=>k.has(P.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(BH.Provider,{value:T,children:[e,m.jsx(bEe,{entries:t,activeView:r,viewportRect:s})]})}function yEe({sessionId:e,sessionKind:t,provider:n,findRequest:r,resizeRequest:i}){const s=b.useContext(BH),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 bEe({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)??mEe,height:(n==null?void 0:n.height)??gEe};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(A6,{sessionId:r.sessionId,active:i,children:m.jsx(hEe,{sessionId:r.sessionId,sessionKind:r.sessionKind,provider:r.provider,active:i,findRequest:r.findRequest,resizeRequest:r.resizeRequest})})},r.sessionId)})})}function _Ee(e,t){return Math.abs(e.top-t.top)<=Wv&&Math.abs(e.left-t.left)<=Wv&&Math.abs(e.width-t.width)<=Wv&&Math.abs(e.height-t.height)<=Wv}function wEe(){const e=Ut(r=>r.codexActiveWriterConflict),t=Ut(r=>r.setCodexActiveWriterConflict),n=()=>t(null);return m.jsx(qi,{open:e!==null,onOpenChange:r=>!r&&n(),children:m.jsxs(Yi,{focusSurfaceOnOpen:!0,className:"min-w-0 sm:max-w-md",children:[m.jsxs(Vi,{children:[m.jsx(Pi,{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(dt,{type:"button",onClick:n,autoFocus:!0,children:"知道了"})})]})})}function TT({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 xEe(e){const t=m5(e);return t.osName!=="iPad"?{supported:!0}:e.standalone||t.browserName==="Safari"?{supported:!0}:{supported:!1,reason:"ipad-safari-required",browserName:t.browserName}}function Cy(){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 SEe(){return typeof navigator>"u"?{supported:!0}:xEe({userAgent:navigator.userAgent,platform:navigator.platform,maxTouchPoints:navigator.maxTouchPoints,standalone:Cy()})}function EEe(){VSe(),KSe();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(()=>Cy()),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",P=g!==null&&v===null,R=TT({route:A,surface:"mobile",proxiesLength:f,proxyListLoaded:h,hasProxy:_,relayClientAuthIssue:v}),M=S??w,V=e.pathname==="/sessions"&&h&&f>0?m.jsxs(dt,{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(jz,{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:$e.error,info:$e.info,success:$e.success})[T.kind](T.message),k(null)},[T,k]),b.useEffect(()=>{if(typeof window.matchMedia!="function"){d(Cy());return}const O=window.matchMedia("(display-mode: standalone)"),N=window.matchMedia("(display-mode: fullscreen)"),L=()=>d(Cy());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=tse({pathname:e.pathname,alreadyRestored:ise(),lastRoute:nse()});sse(),O&&(ose(O),t(O,{replace:!0}))},[]);const G=b.useRef(!1);return b.useEffect(()=>{n?(G.current=!0,rse(`${e.pathname}${e.search}`)):G.current&&(G.current=!1,jy())},[n,e.pathname,e.search]),m.jsxs(nfe,{blocked:P,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:P?!0:void 0,"aria-hidden":P?!0:void 0,children:[!i&&m.jsx(dt,{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(Hz,{className:"size-4","aria-hidden":"true"})})}),!i&&m.jsx(upe,{subtitle:R,action:V}),m.jsx(ame,{}),m.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[m.jsx(ape,{className:"hidden md:flex"}),m.jsx("main",{className:"relative flex-1 overflow-hidden",role:"main",children:m.jsx(vEe,{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(J7,{})},s?"top-level":e.pathname)})})]}),m.jsx($1,{open:o,onOpenChange:l}),m.jsx(wEe,{}),m.jsx(Bpe,{}),m.jsx(bpe,{}),m.jsx(Tie,{})]}),P&&g?m.jsx("div",{className:"fixed inset-0 z-[60] bg-background",children:m.jsx(Fpe,{issue:g})}):null]})}function zH({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(WF,{texts:qF,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 CEe(){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=TT({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(wF,{layout:"page"})}),m.jsx("div",{className:"hidden md:block h-full",children:s?m.jsx(nu,{variant:s}):m.jsx(zH,{subtitle:i})})]})}function kEe(){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=Mi("local",Tn.proxyId)!==null;if(!n&&!i)return m.jsx(Z7,{to:"/",replace:!0});const s=TT({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(LF,{layout:"page"})}),m.jsx("div",{className:"hidden md:block h-full",children:m.jsx(zH,{subtitle:s})})]})}function jH(){if(!(typeof navigator>"u"))return navigator.wakeLock}function TEe(e,t){return e===!1?"insecure-context":t?null:"unsupported"}function FH(){var t;const e=typeof window>"u"?void 0:window.isSecureContext;return TEe(e,typeof((t=jH())==null?void 0:t.request)=="function")}function REe(e){return e==="insecure-context"?"屏幕常亮需要 HTTPS":"当前浏览器不支持屏幕常亮"}function AEe(){const e=jH();if(typeof(e==null?void 0:e.request)!="function")throw new Error(REe(FH()));return e.request("screen")}function NEe(e){return e instanceof Error&&e.message.trim()?e.message:"无法开启屏幕常亮"}class MEe{constructor(t={}){ze(this,"activeScopes",new Set);ze(this,"pendingScopes",new Set);ze(this,"listeners",new Map);ze(this,"sentinel",null);ze(this,"requestInFlight",null);ze(this,"requestWakeLock");ze(this,"documentRef");ze(this,"windowRef");ze(this,"unavailableReason");ze(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(()=>{})});ze(this,"handlePageHide",()=>{this.releaseSentinel().catch(()=>{})});var n,r;this.requestWakeLock=t.request??AEe,this.unavailableReason=typeof t.request=="function"?null:FH(),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(NEe(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 zl=new MEe;function $H(e){const[t,n]=b.useState(()=>zl.getSnapshot(e));b.useEffect(()=>zl.subscribe(e,n),[e]),b.useEffect(()=>()=>{zl.disable(e).catch(()=>{})},[e]);const r=b.useCallback(()=>zl.enable(e),[e]),i=b.useCallback(()=>zl.disable(e),[e]),s=b.useCallback(()=>zl.toggle(e),[e]);return{...t,enable:r,disable:i,toggle:s}}function PEe({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){$e.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 IEe(){return new AudioContext}class OEe{constructor(t=IEe){ze(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 ky=new OEe,rD=400,Ud=[];let HH=1;function LEe(){return typeof performance>"u"?0:Math.round(performance.now()*10)/10}function Rp(e){const t={sequence:HH++,timestamp:new Date().toISOString(),monotonicMs:LEe(),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>rD&&Ud.splice(0,Ud.length-rD)}function DEe(){return Ud.map(e=>({...e,...e.details?{details:{...e.details}}:{}}))}function BEe(){Ud.length=0,HH=1}typeof window<"u"&&(window.__devAnywhereVoicePilotDiagnostics={snapshot:DEe,clear:BEe});function UH(e){return`voice-pilot:${e}`}function zEe(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 jEe="modulepreload",FEe=function(e){return"/"+e},iD={},WH=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=FEe(d),d in iD)return;iD[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":jEe,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)})},$Ee="/assets/fvad-DYxbW2my.wasm",pf=16e3,HEe=20,jl=pf*HEe/1e3,yS=jl*Int16Array.BYTES_PER_ELEMENT;let sD=null;async function UEe(){return sD??(sD=WH(async()=>{const{default:e}=await import("./fvad-BPZopehQ.js");return{default:e}},[]).then(({default:e})=>e({locateFile:t=>t.endsWith(".wasm")?$Ee:t}))),sD}class RT{constructor(t,n,r){ze(this,"destroyed",!1);this.module=t,this.handle=n,this.framePointer=r}static async create(t=3){const n=await UEe(),r=n._fvad_new();if(!r)throw new Error("无法初始化浏览器语音活动检测器");const i=n._malloc(yS);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 RT(n,r,i)}process(t){if(this.destroyed)throw new Error("浏览器语音活动检测器已释放");if(t.byteLength!==yS)throw new Error(`语音活动检测帧必须为 ${yS} 字节`);this.module.HEAPU8.set(t,this.framePointer);const n=this.module._fvad_process(this.handle,this.framePointer,jl);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 WEe{constructor(t={}){ze(this,"startSpeechFrames");ze(this,"endSilenceFrames");ze(this,"active",!1);ze(this,"speechFrames",0);ze(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 qEe{constructor(){ze(this,"pending",new Float32Array(jl));ze(this,"pendingLength",0)}push(t,n){let r=0;if(this.pendingLength>0){const i=jl-this.pendingLength,s=Math.min(i,t.length);this.pending.set(t.subarray(0,s),this.pendingLength),this.pendingLength+=s,r+=s,this.pendingLength===jl&&(n(this.pending.slice()),this.pendingLength=0)}for(;r+jl<=t.length;)n(t.slice(r,r+jl)),r+=jl;if(r<t.length){const i=t.subarray(r);this.pending.set(i,0),this.pendingLength=i.length}}reset(){this.pendingLength=0}}const YEe="/__dev_anywhere_debug/voice-fixture",VEe=pf*jF/1e3;function KEe(){return RT.create(3)}const GEe={createVad:KEe,getUserMedia:e=>navigator.mediaDevices.getUserMedia(e),createAudioContext:e=>new AudioContext(e),fetch:e=>fetch(e)};function XEe(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 ZEe(e){for(const t of e.getTracks())t.stop()}function qH(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 JEe(e){const t=qH(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(),ZEe(n),t.state!=="closed"&&await t.close()}}}async function QEe(e,t){const n=qH(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 YH(e=window.location.search,t=!1){return t&&new URLSearchParams(e).get("voice-fixture")==="default"?{kind:"fixture",url:YEe}:{kind:"microphone"}}async function eCe(e,t=GEe){const n=await t.createVad();let r;try{r=e.source.kind==="fixture"?await QEe(e.source.url,t):await JEe(t)}catch(f){throw n.destroy(),f}const i=new WEe,s=new qEe,o=r.context.createScriptProcessor(VEe,1,1);let l=!1,u=null,d=null;return o.onaudioprocess=f=>{l&&s.push(f.inputBuffer.getChannelData(0),h=>{const v=zEe(h),g=n.process(v);e.onFrame({pcm:v,speechProbability:g?1:0,activityLevel:XEe(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 VH(e=bf().osName){return{mediaAccept:"image/*,video/*",fileAccept:e==="Android"?"application/*,text/*":void 0}}function tCe(e){const[t,n,...r]=Array.from(e);return t&&n===" "&&r.length>0?{indicator:t,label:r.join("")}:{label:e}}function nCe({title:e,isPtyTitle:t}){if(!t)return m.jsx(m.Fragment,{children:e});const{indicator:n,label:r}=tCe(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 rCe(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 iCe(){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(rCe(n),{cause:n})}finally{e==null||e.getTracks().forEach(n=>n.stop())}}const Nl="min-h-9 gap-2.5",Xh="px-2 pb-1 pt-2 text-xs font-semibold text-muted-foreground",sCe=[{axis:"cols",label:"列数",unit:"列",Icon:bV,min:rb,max:au},{axis:"rows",label:"行数",unit:"行",Icon:kK,min:ib,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 oCe({label:e}){return m.jsxs(zs,{className:"relative",children:[m.jsx(AC,{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 aCe({sessionId:e,mode:t,onFind:n,onResizeTerminal:r}){const i=Zr(be=>be.homePath),s=VH(),o=ks(),l=Ut(be=>be.sessions.find(Je=>Je.sessionId===e)),u=Ut(be=>be.ptyTitles[e]),d=Ut(be=>be.ptyGeometryBySessionId[e]),f=Re(be=>be.ptyFontSize),h=Re(be=>be.chatContentFontSize),v=Re(be=>be.selectedProxyId),g=Re(be=>be.connected),_=Re(be=>be.proxyOnline),w=Re(be=>be.adjustPtyFontSize),S=Re(be=>be.adjustChatContentFontSize),x=Re(be=>be.setChatContentFontSize),T=Re(be=>be.resetPtyFontSize),k=Re(be=>be.resetChatContentFontSize),A=Re(be=>be.inputModePreference==="hardware"),P=Ut(be=>be.renameSession),R=ZC(v,e),M=(l==null?void 0:l.provider)!=="codex",z=Ut(be=>M&&R?!!be.ptyAutoYesBySessionKey[R]:!1),V=Ut(be=>be.setPtyAutoYes),G=bo("(pointer: coarse), (hover: none)")&&!A,O=t==="pty"||(l==null?void 0:l.mode)==="pty",N=P6(l??{}).menu,L=b.useRef(null),D=b.useRef(null),I=b.useRef(!1),[B,F]=b.useState(!1),U=(l==null?void 0:l.kind)==="terminal",j=$H(e),Y=Dn(be=>be.bySessionId[e]??m_),X=Dn(be=>be.enable),$=Dn(be=>be.disable),ee=!!(l!=null&&l.nameLocked&&(l!=null&&l.name)),re=sk(l,i),te=ee&&(l==null?void 0:l.name)||re||O&&u||(l==null?void 0:l.name)||e.slice(0,8),Z=!!(O&&!U&&u&&!ee),oe=O?f:DC(h,G),Q=!O&&G?uj:lj,fe=O?T:k,[ge,Ce]=b.useState(!1),[De,ot]=b.useState(!1),Dt=Y.enabled,et=j.active||Dt,ut=j.pending||!j.supported||Dt;function Ne(be){if(O){w(be);return}if(G){x(oe+be);return}S(be)}function Ue(){j.toggle().catch(be=>{$e.error(be instanceof Error?be.message:String(be))})}async function ye(be){var pt;if(O||U){$e.info("Voice Pilot 目前适用于聊天会话。");return}if(be!==!0){$(e);return}const Je=zt;if(!Je){$e.error("请先连接开发机");return}try{if(!((pt=(await Je.requestVoiceConfig()).config)!=null&&pt.configured)){$e.info("请先在设置里配置 Voice Pilot。");return}Ce(!0)}catch(wt){$e.error(wt instanceof Error?wt.message:String(wt))}}async function nt(){var wt;ot(!0);let be=null,Je=!1;const pt=UH(e);try{Rp({sessionId:e,scope:"runtime",event:"wake-lock-requested",details:{userActivationActive:((wt=navigator.userActivation)==null?void 0:wt.isActive)??!1,visibilityState:document.visibilityState,secureContext:window.isSecureContext}});const Bt=zl.enable(pt).then(()=>{Rp({sessionId:e,scope:"runtime",event:"wake-lock-acquired"})},Et=>{throw Rp({sessionId:e,scope:"runtime",event:"wake-lock-failed",details:{error:Et instanceof Error?Et.message:String(Et)}}),new Error("屏幕常亮请求被浏览器拒绝,Voice Pilot 未开启。",{cause:Et})});be=Fk.acquire("capture");const mn=ky.prepare(),nn=YH().kind==="microphone"?iCe():Promise.resolve();await Promise.all([Bt,mn,nn]),X(e),Je=!0,Ce(!1)}catch(Bt){Rp({sessionId:e,scope:"runtime",event:"startup-failed",details:{error:Bt instanceof Error?Bt.message:String(Bt)}}),$e.error(Bt instanceof Error?Bt.message:String(Bt))}finally{be==null||be.release(),Je||await zl.disable(pt).catch(()=>{}),ot(!1)}}const He=b.useRef(null),Ae=b.useRef(null),[Ze,Tt]=b.useState(!1);async function ve(be){var Bt;const Je=(Bt=be.target.files)==null?void 0:Bt[0];if(be.target.value="",!Je)return;const pt=zt;if(!pt){$e.error("请先连接开发机");return}const wt=await om({relay:pt,sessionId:e,file:Je});wt&&Mo(e,`@${wt} `)}async function Ke(be,Je){const pt=zt;if(!pt)throw new Error("请先连接开发机");const wt=await pt.renameSession(be,Je);if(!wt.success)throw new Error(wt.error??"重命名失败");P(be,wt.name??Je),$e.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(dt,{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(nCe,{title:te,isPtyTitle:Z})}),m.jsxs(Cf,{modal:!1,onOpenChange:be=>{be?I.current=!1:F(!1)},children:[m.jsx(kf,{asChild:!0,children:m.jsx(dt,{ref:L,variant:"ghost",size:"icon-sm",className:"justify-self-end","aria-label":"会话操作","data-slot":"chat-overflow-trigger",onPointerDownCapture:be=>{if(be.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:be=>{["Enter"," ","ArrowDown"].includes(be.key)&&(D.current=null)},children:m.jsx(RV,{"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:be=>{if(be.target instanceof HTMLElement&&be.target.matches('[data-terminal-dimension-input][data-editing="true"]')){be.preventDefault();return}I.current=!0},onInteractOutside:()=>{const be=document.activeElement;be instanceof HTMLInputElement&&be.hasAttribute("data-terminal-dimension-input")&&be.blur()},onCloseAutoFocus:be=>{const Je=D.current,pt=I.current;D.current=null,I.current=!1;const wt=Je==null?void 0:Je.closest('[data-slot="pty-keepalive-entry"]'),Bt=document.activeElement;be.defaultPrevented||!pt||!O||!(Je!=null&&Je.isConnected)||(wt==null?void 0:wt.getAttribute("data-session-id"))!==e||wt.getAttribute("data-active")!=="true"||Bt!==document.body&&Bt!==document.documentElement&&Bt!==L.current&&Bt!==Je&&!(Bt!=null&&Bt.closest('[data-slot="chat-overflow-menu"]'))||(be.preventDefault(),Je.focus({preventScroll:!0}))},children:[m.jsx(Dh,{className:Xh,children:"会话"}),m.jsxs(ii,{className:Nl,"data-slot":"chat-menu-find",onSelect:n,children:[m.jsx(zs,{children:m.jsx(Ay,{"aria-hidden":"true"})}),"在会话中查找"]}),m.jsxs(ii,{className:Nl,"data-slot":"chat-menu-rename",onSelect:()=>Tt(!0),children:[m.jsx(zs,{children:m.jsx(yK,{"aria-hidden":"true"})}),"重命名"]}),m.jsxs(E0,{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:ut,"data-slot":"chat-menu-screen-wake-lock-item",onCheckedChange:Ue,children:[m.jsx(zs,{children:m.jsx(QV,{"aria-hidden":"true"})}),m.jsx("span",{className:"min-w-0 flex-1",children:j.supported?Dt?"屏幕常亮(Voice Pilot 控制)":"屏幕常亮":j.unavailableReason==="insecure-context"?"屏幕常亮(需要 HTTPS)":"屏幕常亮(浏览器不支持)"})]}),O&&!U&&M&&m.jsxs(E0,{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:be=>{R&&V(R,be===!0)},children:[m.jsx(zs,{children:m.jsx(tG,{"aria-hidden":"true"})}),m.jsx("span",{className:"min-w-0 flex-1",children:"Always yes"})]}),!O&&!U&&m.jsxs(E0,{checked:Y.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:ye,children:[m.jsx(zs,{children:m.jsx(aK,{"aria-hidden":"true"})}),m.jsx("span",{className:"min-w-0 flex-1",children:"Voice Pilot"})]}),m.jsx(Hl,{}),(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(Hl,{})]}),(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(ii,{className:Nl,"data-slot":"chat-menu-fit-terminal",disabled:!g||!_||l.state==="error",onSelect:()=>r("fit"),children:[m.jsx(zs,{children:m.jsx(iK,{"aria-hidden":"true"})}),"按窗口调整终端尺寸"]}),sCe.map(({axis:be,label:Je,unit:pt,Icon:wt,min:Bt,max:mn})=>{const on=d==null?void 0:d[be],nn=!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-${be}-control`,children:[m.jsx(zs,{children:m.jsx(wt,{"aria-hidden":"true"})}),m.jsx("span",{children:Je}),m.jsxs("div",{className:"inline-flex shrink-0 items-center gap-2",children:[m.jsx(dt,{variant:"ghost",size:"icon-sm",className:"size-[22px] rounded-[5px] bg-muted/45 text-muted-foreground hover:bg-accent hover:text-accent-foreground",disabled:nn||on!==void 0&&on<=Bt,"aria-label":`减少${pt}`,"data-slot":`chat-menu-decrease-${be}`,onClick:Et=>{Et.stopPropagation(),r(`decrease-${be}`)},children:m.jsx(gP,{"aria-hidden":"true"})}),m.jsx(PEe,{axis:be,label:Je,value:on,min:Bt,max:mn,disabled:nn,onCommit:Et=>r({axis:be,value:Et})},`${e}-${be}`),m.jsx(dt,{variant:"ghost",size:"icon-sm",className:"size-[22px] rounded-[5px] bg-muted/45 text-muted-foreground hover:bg-accent hover:text-accent-foreground",disabled:nn||on!==void 0&&on>=mn,"aria-label":`增加${pt}`,"data-slot":`chat-menu-increase-${be}`,onClick:Et=>{Et.stopPropagation(),r(`increase-${be}`)},children:m.jsx(vP,{"aria-hidden":"true"})})]})]},be)}),m.jsx(Hl,{})]}),O&&m.jsxs(m.Fragment,{children:[m.jsxs(ofe,{open:B,onOpenChange:F,children:[m.jsxs(afe,{className:We(Nl,"[&>svg:last-child]:ml-0"),"data-slot":"chat-menu-shortcuts-trigger",onClick:be=>{B&&(be.preventDefault(),F(!1))},children:[m.jsx(zs,{children:m.jsx(AC,{"aria-hidden":"true"})}),"发送快捷键"]}),m.jsx(sfe,{children:m.jsx(lfe,{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(be=>m.jsxs(ii,{className:Nl,"data-slot":`chat-menu-send-${be.id}`,disabled:!g||!_||(l==null?void 0:l.mode)!=="pty"||l.state==="error",onSelect:()=>Mo(e,be.data),children:[m.jsx(oCe,{label:be.display}),"发送 ",be.key]},be.id))})})]}),m.jsx(Hl,{})]}),O&&!U?m.jsxs(m.Fragment,{children:[m.jsx(Dh,{className:Xh,children:"文件"}),m.jsxs(ii,{className:Nl,"data-slot":"chat-menu-upload-image",onClick:()=>{var be;return(be=Ae.current)==null?void 0:be.click()},children:[m.jsx(zs,{children:m.jsx(mm,{"aria-hidden":"true"})}),"上传照片或视频"]}),m.jsxs(ii,{className:Nl,"data-slot":"chat-menu-upload-file",onClick:()=>{var be;return(be=He.current)==null?void 0:be.click()},children:[m.jsx(zs,{children:m.jsx(Wz,{"aria-hidden":"true"})}),"上传文件"]}),m.jsx(Hl,{})]}):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(qK,{"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(dt,{variant:"ghost",size:"icon-sm",className:"size-[22px] rounded-[5px] bg-muted/45 text-muted-foreground hover:bg-accent hover:text-accent-foreground",disabled:oe<=Q,"aria-label":"字号变小","data-slot":"chat-menu-font-smaller",onClick:be=>{be.stopPropagation(),Ne(-1)},children:m.jsx(gP,{"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:[oe,"px"]}),m.jsx(dt,{variant:"ghost",size:"icon-sm",className:"size-[22px] rounded-[5px] bg-muted/45 text-muted-foreground hover:bg-accent hover:text-accent-foreground",disabled:oe>=cj,"aria-label":"字号变大","data-slot":"chat-menu-font-larger",onClick:be=>{be.stopPropagation(),Ne(1)},children:m.jsx(vP,{"aria-hidden":"true"})})]})]})}),m.jsxs(ii,{className:Nl,"data-slot":"chat-menu-font-reset",onClick:fe,children:[m.jsx(zs,{children:m.jsx(Fz,{"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(qi,{open:ge&&!Y.enabled,onOpenChange:be=>{De||Ce(be)},children:m.jsxs(Yi,{className:"sm:max-w-md","data-slot":"voice-pilot-wake-lock-dialog",focusSurfaceOnOpen:!0,children:[m.jsxs(Vi,{children:[m.jsx(Pi,{children:"开启 Voice Pilot?"}),m.jsx(fs,{children:"开启后会持续聆听并保持屏幕常亮,停止后自动恢复。"})]}),m.jsxs(Gs,{children:[m.jsx(dt,{type:"button",variant:"outline",disabled:De,onClick:()=>Ce(!1),children:"取消"}),m.jsx(dt,{type:"button","data-slot":"voice-pilot-confirm-start",disabled:De,onClick:()=>{nt()},children:De?"正在开启...":"开启 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:be=>{ve(be)}}),m.jsx("input",{ref:He,type:"file",accept:s.fileAccept,className:"hidden","data-slot":"chat-menu-upload-file-input",onChange:be=>{ve(be)}})]}):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(P=>k.has(P.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(BH.Provider,{value:T,children:[e,m.jsx(bEe,{entries:t,activeView:r,viewportRect:s})]})}function yEe({sessionId:e,sessionKind:t,provider:n,findRequest:r,resizeRequest:i}){const s=b.useContext(BH),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 bEe({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)??mEe,height:(n==null?void 0:n.height)??gEe};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(A6,{sessionId:r.sessionId,active:i,children:m.jsx(hEe,{sessionId:r.sessionId,sessionKind:r.sessionKind,provider:r.provider,active:i,findRequest:r.findRequest,resizeRequest:r.resizeRequest})})},r.sessionId)})})}function _Ee(e,t){return Math.abs(e.top-t.top)<=Wv&&Math.abs(e.left-t.left)<=Wv&&Math.abs(e.width-t.width)<=Wv&&Math.abs(e.height-t.height)<=Wv}function wEe(){const e=Ut(r=>r.codexActiveWriterConflict),t=Ut(r=>r.setCodexActiveWriterConflict),n=()=>t(null);return m.jsx(qi,{open:e!==null,onOpenChange:r=>!r&&n(),children:m.jsxs(Yi,{focusSurfaceOnOpen:!0,className:"min-w-0 sm:max-w-md",children:[m.jsxs(Vi,{children:[m.jsx(Pi,{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(dt,{type:"button",onClick:n,autoFocus:!0,children:"知道了"})})]})})}function TT({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 xEe(e){const t=m5(e);return t.osName!=="iPad"?{supported:!0}:e.standalone||t.browserName==="Safari"?{supported:!0}:{supported:!1,reason:"ipad-safari-required",browserName:t.browserName}}function Cy(){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 SEe(){return typeof navigator>"u"?{supported:!0}:xEe({userAgent:navigator.userAgent,platform:navigator.platform,maxTouchPoints:navigator.maxTouchPoints,standalone:Cy()})}function EEe(){VSe(),KSe();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(()=>Cy()),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",P=g!==null&&v===null,R=TT({route:A,surface:"mobile",proxiesLength:f,proxyListLoaded:h,hasProxy:_,relayClientAuthIssue:v}),M=S??w,V=e.pathname==="/sessions"&&h&&f>0?m.jsxs(dt,{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(jz,{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:$e.error,info:$e.info,success:$e.success})[T.kind](T.message),k(null)},[T,k]),b.useEffect(()=>{if(typeof window.matchMedia!="function"){d(Cy());return}const O=window.matchMedia("(display-mode: standalone)"),N=window.matchMedia("(display-mode: fullscreen)"),L=()=>d(Cy());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=tse({pathname:e.pathname,alreadyRestored:ise(),lastRoute:nse()});sse(),O&&(ose(O),t(O,{replace:!0}))},[]);const G=b.useRef(!1);return b.useEffect(()=>{n?(G.current=!0,rse(`${e.pathname}${e.search}`)):G.current&&(G.current=!1,jy())},[n,e.pathname,e.search]),m.jsxs(nfe,{blocked:P,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:P?!0:void 0,"aria-hidden":P?!0:void 0,children:[!i&&m.jsx(dt,{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(Hz,{className:"size-4","aria-hidden":"true"})})}),!i&&m.jsx(upe,{subtitle:R,action:V}),m.jsx(ame,{}),m.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[m.jsx(ape,{className:"hidden md:flex"}),m.jsx("main",{className:"relative flex-1 overflow-hidden",role:"main",children:m.jsx(vEe,{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(J7,{})},s?"top-level":e.pathname)})})]}),m.jsx($1,{open:o,onOpenChange:l}),m.jsx(wEe,{}),m.jsx(Bpe,{}),m.jsx(bpe,{}),m.jsx(Tie,{})]}),P&&g?m.jsx("div",{className:"fixed inset-0 z-[60] bg-background",children:m.jsx(Fpe,{issue:g})}):null]})}function zH({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(WF,{texts:qF,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 CEe(){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=TT({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(wF,{layout:"page"})}),m.jsx("div",{className:"hidden md:block h-full",children:s?m.jsx(nu,{variant:s}):m.jsx(zH,{subtitle:i})})]})}function kEe(){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=Mi("local",Tn.proxyId)!==null;if(!n&&!i)return m.jsx(Z7,{to:"/",replace:!0});const s=TT({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(LF,{layout:"page"})}),m.jsx("div",{className:"hidden md:block h-full",children:m.jsx(zH,{subtitle:s})})]})}function jH(){if(!(typeof navigator>"u"))return navigator.wakeLock}function TEe(e,t){return e===!1?"insecure-context":t?null:"unsupported"}function FH(){var t;const e=typeof window>"u"?void 0:window.isSecureContext;return TEe(e,typeof((t=jH())==null?void 0:t.request)=="function")}function REe(e){return e==="insecure-context"?"屏幕常亮需要 HTTPS":"当前浏览器不支持屏幕常亮"}function AEe(){const e=jH();if(typeof(e==null?void 0:e.request)!="function")throw new Error(REe(FH()));return e.request("screen")}function NEe(e){return e instanceof Error&&e.message.trim()?e.message:"无法开启屏幕常亮"}class MEe{constructor(t={}){ze(this,"activeScopes",new Set);ze(this,"pendingScopes",new Set);ze(this,"listeners",new Map);ze(this,"sentinel",null);ze(this,"requestInFlight",null);ze(this,"requestWakeLock");ze(this,"documentRef");ze(this,"windowRef");ze(this,"unavailableReason");ze(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(()=>{})});ze(this,"handlePageHide",()=>{this.releaseSentinel().catch(()=>{})});var n,r;this.requestWakeLock=t.request??AEe,this.unavailableReason=typeof t.request=="function"?null:FH(),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(NEe(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 zl=new MEe;function $H(e){const[t,n]=b.useState(()=>zl.getSnapshot(e));b.useEffect(()=>zl.subscribe(e,n),[e]),b.useEffect(()=>()=>{zl.disable(e).catch(()=>{})},[e]);const r=b.useCallback(()=>zl.enable(e),[e]),i=b.useCallback(()=>zl.disable(e),[e]),s=b.useCallback(()=>zl.toggle(e),[e]);return{...t,enable:r,disable:i,toggle:s}}function PEe({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){$e.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 IEe(){return new AudioContext}class OEe{constructor(t=IEe){ze(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 ky=new OEe,rD=400,Ud=[];let HH=1;function LEe(){return typeof performance>"u"?0:Math.round(performance.now()*10)/10}function Rp(e){const t={sequence:HH++,timestamp:new Date().toISOString(),monotonicMs:LEe(),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>rD&&Ud.splice(0,Ud.length-rD)}function DEe(){return Ud.map(e=>({...e,...e.details?{details:{...e.details}}:{}}))}function BEe(){Ud.length=0,HH=1}typeof window<"u"&&(window.__devAnywhereVoicePilotDiagnostics={snapshot:DEe,clear:BEe});function UH(e){return`voice-pilot:${e}`}function zEe(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 jEe="modulepreload",FEe=function(e){return"/"+e},iD={},WH=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=FEe(d),d in iD)return;iD[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":jEe,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)})},$Ee="/assets/fvad-DYxbW2my.wasm",pf=16e3,HEe=20,jl=pf*HEe/1e3,yS=jl*Int16Array.BYTES_PER_ELEMENT;let sD=null;async function UEe(){return sD??(sD=WH(async()=>{const{default:e}=await import("./fvad-B4AqN0qc.js");return{default:e}},[]).then(({default:e})=>e({locateFile:t=>t.endsWith(".wasm")?$Ee:t}))),sD}class RT{constructor(t,n,r){ze(this,"destroyed",!1);this.module=t,this.handle=n,this.framePointer=r}static async create(t=3){const n=await UEe(),r=n._fvad_new();if(!r)throw new Error("无法初始化浏览器语音活动检测器");const i=n._malloc(yS);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 RT(n,r,i)}process(t){if(this.destroyed)throw new Error("浏览器语音活动检测器已释放");if(t.byteLength!==yS)throw new Error(`语音活动检测帧必须为 ${yS} 字节`);this.module.HEAPU8.set(t,this.framePointer);const n=this.module._fvad_process(this.handle,this.framePointer,jl);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 WEe{constructor(t={}){ze(this,"startSpeechFrames");ze(this,"endSilenceFrames");ze(this,"active",!1);ze(this,"speechFrames",0);ze(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 qEe{constructor(){ze(this,"pending",new Float32Array(jl));ze(this,"pendingLength",0)}push(t,n){let r=0;if(this.pendingLength>0){const i=jl-this.pendingLength,s=Math.min(i,t.length);this.pending.set(t.subarray(0,s),this.pendingLength),this.pendingLength+=s,r+=s,this.pendingLength===jl&&(n(this.pending.slice()),this.pendingLength=0)}for(;r+jl<=t.length;)n(t.slice(r,r+jl)),r+=jl;if(r<t.length){const i=t.subarray(r);this.pending.set(i,0),this.pendingLength=i.length}}reset(){this.pendingLength=0}}const YEe="/__dev_anywhere_debug/voice-fixture",VEe=pf*jF/1e3;function KEe(){return RT.create(3)}const GEe={createVad:KEe,getUserMedia:e=>navigator.mediaDevices.getUserMedia(e),createAudioContext:e=>new AudioContext(e),fetch:e=>fetch(e)};function XEe(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 ZEe(e){for(const t of e.getTracks())t.stop()}function qH(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 JEe(e){const t=qH(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(),ZEe(n),t.state!=="closed"&&await t.close()}}}async function QEe(e,t){const n=qH(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 YH(e=window.location.search,t=!1){return t&&new URLSearchParams(e).get("voice-fixture")==="default"?{kind:"fixture",url:YEe}:{kind:"microphone"}}async function eCe(e,t=GEe){const n=await t.createVad();let r;try{r=e.source.kind==="fixture"?await QEe(e.source.url,t):await JEe(t)}catch(f){throw n.destroy(),f}const i=new WEe,s=new qEe,o=r.context.createScriptProcessor(VEe,1,1);let l=!1,u=null,d=null;return o.onaudioprocess=f=>{l&&s.push(f.inputBuffer.getChannelData(0),h=>{const v=zEe(h),g=n.process(v);e.onFrame({pcm:v,speechProbability:g?1:0,activityLevel:XEe(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 VH(e=bf().osName){return{mediaAccept:"image/*,video/*",fileAccept:e==="Android"?"application/*,text/*":void 0}}function tCe(e){const[t,n,...r]=Array.from(e);return t&&n===" "&&r.length>0?{indicator:t,label:r.join("")}:{label:e}}function nCe({title:e,isPtyTitle:t}){if(!t)return m.jsx(m.Fragment,{children:e});const{indicator:n,label:r}=tCe(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 rCe(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 iCe(){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(rCe(n),{cause:n})}finally{e==null||e.getTracks().forEach(n=>n.stop())}}const Nl="min-h-9 gap-2.5",Xh="px-2 pb-1 pt-2 text-xs font-semibold text-muted-foreground",sCe=[{axis:"cols",label:"列数",unit:"列",Icon:bV,min:rb,max:au},{axis:"rows",label:"行数",unit:"行",Icon:kK,min:ib,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 oCe({label:e}){return m.jsxs(zs,{className:"relative",children:[m.jsx(AC,{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 aCe({sessionId:e,mode:t,onFind:n,onResizeTerminal:r}){const i=Zr(be=>be.homePath),s=VH(),o=ks(),l=Ut(be=>be.sessions.find(Je=>Je.sessionId===e)),u=Ut(be=>be.ptyTitles[e]),d=Ut(be=>be.ptyGeometryBySessionId[e]),f=Re(be=>be.ptyFontSize),h=Re(be=>be.chatContentFontSize),v=Re(be=>be.selectedProxyId),g=Re(be=>be.connected),_=Re(be=>be.proxyOnline),w=Re(be=>be.adjustPtyFontSize),S=Re(be=>be.adjustChatContentFontSize),x=Re(be=>be.setChatContentFontSize),T=Re(be=>be.resetPtyFontSize),k=Re(be=>be.resetChatContentFontSize),A=Re(be=>be.inputModePreference==="hardware"),P=Ut(be=>be.renameSession),R=ZC(v,e),M=(l==null?void 0:l.provider)!=="codex",z=Ut(be=>M&&R?!!be.ptyAutoYesBySessionKey[R]:!1),V=Ut(be=>be.setPtyAutoYes),G=bo("(pointer: coarse), (hover: none)")&&!A,O=t==="pty"||(l==null?void 0:l.mode)==="pty",N=P6(l??{}).menu,L=b.useRef(null),D=b.useRef(null),I=b.useRef(!1),[B,F]=b.useState(!1),U=(l==null?void 0:l.kind)==="terminal",j=$H(e),Y=Dn(be=>be.bySessionId[e]??m_),X=Dn(be=>be.enable),$=Dn(be=>be.disable),ee=!!(l!=null&&l.nameLocked&&(l!=null&&l.name)),re=sk(l,i),te=ee&&(l==null?void 0:l.name)||re||O&&u||(l==null?void 0:l.name)||e.slice(0,8),Z=!!(O&&!U&&u&&!ee),oe=O?f:DC(h,G),Q=!O&&G?uj:lj,fe=O?T:k,[ge,Ce]=b.useState(!1),[De,ot]=b.useState(!1),Dt=Y.enabled,et=j.active||Dt,ut=j.pending||!j.supported||Dt;function Ne(be){if(O){w(be);return}if(G){x(oe+be);return}S(be)}function Ue(){j.toggle().catch(be=>{$e.error(be instanceof Error?be.message:String(be))})}async function ye(be){var pt;if(O||U){$e.info("Voice Pilot 目前适用于聊天会话。");return}if(be!==!0){$(e);return}const Je=zt;if(!Je){$e.error("请先连接开发机");return}try{if(!((pt=(await Je.requestVoiceConfig()).config)!=null&&pt.configured)){$e.info("请先在设置里配置 Voice Pilot。");return}Ce(!0)}catch(wt){$e.error(wt instanceof Error?wt.message:String(wt))}}async function nt(){var wt;ot(!0);let be=null,Je=!1;const pt=UH(e);try{Rp({sessionId:e,scope:"runtime",event:"wake-lock-requested",details:{userActivationActive:((wt=navigator.userActivation)==null?void 0:wt.isActive)??!1,visibilityState:document.visibilityState,secureContext:window.isSecureContext}});const Bt=zl.enable(pt).then(()=>{Rp({sessionId:e,scope:"runtime",event:"wake-lock-acquired"})},Et=>{throw Rp({sessionId:e,scope:"runtime",event:"wake-lock-failed",details:{error:Et instanceof Error?Et.message:String(Et)}}),new Error("屏幕常亮请求被浏览器拒绝,Voice Pilot 未开启。",{cause:Et})});be=Fk.acquire("capture");const mn=ky.prepare(),nn=YH().kind==="microphone"?iCe():Promise.resolve();await Promise.all([Bt,mn,nn]),X(e),Je=!0,Ce(!1)}catch(Bt){Rp({sessionId:e,scope:"runtime",event:"startup-failed",details:{error:Bt instanceof Error?Bt.message:String(Bt)}}),$e.error(Bt instanceof Error?Bt.message:String(Bt))}finally{be==null||be.release(),Je||await zl.disable(pt).catch(()=>{}),ot(!1)}}const He=b.useRef(null),Ae=b.useRef(null),[Ze,Tt]=b.useState(!1);async function ve(be){var Bt;const Je=(Bt=be.target.files)==null?void 0:Bt[0];if(be.target.value="",!Je)return;const pt=zt;if(!pt){$e.error("请先连接开发机");return}const wt=await om({relay:pt,sessionId:e,file:Je});wt&&Mo(e,`@${wt} `)}async function Ke(be,Je){const pt=zt;if(!pt)throw new Error("请先连接开发机");const wt=await pt.renameSession(be,Je);if(!wt.success)throw new Error(wt.error??"重命名失败");P(be,wt.name??Je),$e.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(dt,{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(nCe,{title:te,isPtyTitle:Z})}),m.jsxs(Cf,{modal:!1,onOpenChange:be=>{be?I.current=!1:F(!1)},children:[m.jsx(kf,{asChild:!0,children:m.jsx(dt,{ref:L,variant:"ghost",size:"icon-sm",className:"justify-self-end","aria-label":"会话操作","data-slot":"chat-overflow-trigger",onPointerDownCapture:be=>{if(be.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:be=>{["Enter"," ","ArrowDown"].includes(be.key)&&(D.current=null)},children:m.jsx(RV,{"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:be=>{if(be.target instanceof HTMLElement&&be.target.matches('[data-terminal-dimension-input][data-editing="true"]')){be.preventDefault();return}I.current=!0},onInteractOutside:()=>{const be=document.activeElement;be instanceof HTMLInputElement&&be.hasAttribute("data-terminal-dimension-input")&&be.blur()},onCloseAutoFocus:be=>{const Je=D.current,pt=I.current;D.current=null,I.current=!1;const wt=Je==null?void 0:Je.closest('[data-slot="pty-keepalive-entry"]'),Bt=document.activeElement;be.defaultPrevented||!pt||!O||!(Je!=null&&Je.isConnected)||(wt==null?void 0:wt.getAttribute("data-session-id"))!==e||wt.getAttribute("data-active")!=="true"||Bt!==document.body&&Bt!==document.documentElement&&Bt!==L.current&&Bt!==Je&&!(Bt!=null&&Bt.closest('[data-slot="chat-overflow-menu"]'))||(be.preventDefault(),Je.focus({preventScroll:!0}))},children:[m.jsx(Dh,{className:Xh,children:"会话"}),m.jsxs(ii,{className:Nl,"data-slot":"chat-menu-find",onSelect:n,children:[m.jsx(zs,{children:m.jsx(Ay,{"aria-hidden":"true"})}),"在会话中查找"]}),m.jsxs(ii,{className:Nl,"data-slot":"chat-menu-rename",onSelect:()=>Tt(!0),children:[m.jsx(zs,{children:m.jsx(yK,{"aria-hidden":"true"})}),"重命名"]}),m.jsxs(E0,{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:ut,"data-slot":"chat-menu-screen-wake-lock-item",onCheckedChange:Ue,children:[m.jsx(zs,{children:m.jsx(QV,{"aria-hidden":"true"})}),m.jsx("span",{className:"min-w-0 flex-1",children:j.supported?Dt?"屏幕常亮(Voice Pilot 控制)":"屏幕常亮":j.unavailableReason==="insecure-context"?"屏幕常亮(需要 HTTPS)":"屏幕常亮(浏览器不支持)"})]}),O&&!U&&M&&m.jsxs(E0,{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:be=>{R&&V(R,be===!0)},children:[m.jsx(zs,{children:m.jsx(tG,{"aria-hidden":"true"})}),m.jsx("span",{className:"min-w-0 flex-1",children:"Always yes"})]}),!O&&!U&&m.jsxs(E0,{checked:Y.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:ye,children:[m.jsx(zs,{children:m.jsx(aK,{"aria-hidden":"true"})}),m.jsx("span",{className:"min-w-0 flex-1",children:"Voice Pilot"})]}),m.jsx(Hl,{}),(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(Hl,{})]}),(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(ii,{className:Nl,"data-slot":"chat-menu-fit-terminal",disabled:!g||!_||l.state==="error",onSelect:()=>r("fit"),children:[m.jsx(zs,{children:m.jsx(iK,{"aria-hidden":"true"})}),"按窗口调整终端尺寸"]}),sCe.map(({axis:be,label:Je,unit:pt,Icon:wt,min:Bt,max:mn})=>{const on=d==null?void 0:d[be],nn=!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-${be}-control`,children:[m.jsx(zs,{children:m.jsx(wt,{"aria-hidden":"true"})}),m.jsx("span",{children:Je}),m.jsxs("div",{className:"inline-flex shrink-0 items-center gap-2",children:[m.jsx(dt,{variant:"ghost",size:"icon-sm",className:"size-[22px] rounded-[5px] bg-muted/45 text-muted-foreground hover:bg-accent hover:text-accent-foreground",disabled:nn||on!==void 0&&on<=Bt,"aria-label":`减少${pt}`,"data-slot":`chat-menu-decrease-${be}`,onClick:Et=>{Et.stopPropagation(),r(`decrease-${be}`)},children:m.jsx(gP,{"aria-hidden":"true"})}),m.jsx(PEe,{axis:be,label:Je,value:on,min:Bt,max:mn,disabled:nn,onCommit:Et=>r({axis:be,value:Et})},`${e}-${be}`),m.jsx(dt,{variant:"ghost",size:"icon-sm",className:"size-[22px] rounded-[5px] bg-muted/45 text-muted-foreground hover:bg-accent hover:text-accent-foreground",disabled:nn||on!==void 0&&on>=mn,"aria-label":`增加${pt}`,"data-slot":`chat-menu-increase-${be}`,onClick:Et=>{Et.stopPropagation(),r(`increase-${be}`)},children:m.jsx(vP,{"aria-hidden":"true"})})]})]},be)}),m.jsx(Hl,{})]}),O&&m.jsxs(m.Fragment,{children:[m.jsxs(ofe,{open:B,onOpenChange:F,children:[m.jsxs(afe,{className:We(Nl,"[&>svg:last-child]:ml-0"),"data-slot":"chat-menu-shortcuts-trigger",onClick:be=>{B&&(be.preventDefault(),F(!1))},children:[m.jsx(zs,{children:m.jsx(AC,{"aria-hidden":"true"})}),"发送快捷键"]}),m.jsx(sfe,{children:m.jsx(lfe,{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(be=>m.jsxs(ii,{className:Nl,"data-slot":`chat-menu-send-${be.id}`,disabled:!g||!_||(l==null?void 0:l.mode)!=="pty"||l.state==="error",onSelect:()=>Mo(e,be.data),children:[m.jsx(oCe,{label:be.display}),"发送 ",be.key]},be.id))})})]}),m.jsx(Hl,{})]}),O&&!U?m.jsxs(m.Fragment,{children:[m.jsx(Dh,{className:Xh,children:"文件"}),m.jsxs(ii,{className:Nl,"data-slot":"chat-menu-upload-image",onClick:()=>{var be;return(be=Ae.current)==null?void 0:be.click()},children:[m.jsx(zs,{children:m.jsx(mm,{"aria-hidden":"true"})}),"上传照片或视频"]}),m.jsxs(ii,{className:Nl,"data-slot":"chat-menu-upload-file",onClick:()=>{var be;return(be=He.current)==null?void 0:be.click()},children:[m.jsx(zs,{children:m.jsx(Wz,{"aria-hidden":"true"})}),"上传文件"]}),m.jsx(Hl,{})]}):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(qK,{"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(dt,{variant:"ghost",size:"icon-sm",className:"size-[22px] rounded-[5px] bg-muted/45 text-muted-foreground hover:bg-accent hover:text-accent-foreground",disabled:oe<=Q,"aria-label":"字号变小","data-slot":"chat-menu-font-smaller",onClick:be=>{be.stopPropagation(),Ne(-1)},children:m.jsx(gP,{"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:[oe,"px"]}),m.jsx(dt,{variant:"ghost",size:"icon-sm",className:"size-[22px] rounded-[5px] bg-muted/45 text-muted-foreground hover:bg-accent hover:text-accent-foreground",disabled:oe>=cj,"aria-label":"字号变大","data-slot":"chat-menu-font-larger",onClick:be=>{be.stopPropagation(),Ne(1)},children:m.jsx(vP,{"aria-hidden":"true"})})]})]})}),m.jsxs(ii,{className:Nl,"data-slot":"chat-menu-font-reset",onClick:fe,children:[m.jsx(zs,{children:m.jsx(Fz,{"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(qi,{open:ge&&!Y.enabled,onOpenChange:be=>{De||Ce(be)},children:m.jsxs(Yi,{className:"sm:max-w-md","data-slot":"voice-pilot-wake-lock-dialog",focusSurfaceOnOpen:!0,children:[m.jsxs(Vi,{children:[m.jsx(Pi,{children:"开启 Voice Pilot?"}),m.jsx(fs,{children:"开启后会持续聆听并保持屏幕常亮,停止后自动恢复。"})]}),m.jsxs(Gs,{children:[m.jsx(dt,{type:"button",variant:"outline",disabled:De,onClick:()=>Ce(!1),children:"取消"}),m.jsx(dt,{type:"button","data-slot":"voice-pilot-confirm-start",disabled:De,onClick:()=>{nt()},children:De?"正在开启...":"开启 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:be=>{ve(be)}}),m.jsx("input",{ref:He,type:"file",accept:s.fileAccept,className:"hidden","data-slot":"chat-menu-upload-file-input",onChange:be=>{ve(be)}})]}):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 oD(e,t){if(e===void 0)throw new Error("Unexpected undefined");return e}const lCe=(e,t)=>Math.abs(e-t)<1.01,cCe=(e,t,n)=>{let r;return function(...i){e.clearTimeout(r),r=e.setTimeout(()=>t.apply(this,i),n)}},aD=e=>{const{offsetWidth:t,offsetHeight:n}=e;return{width:t,height:n}},uCe=e=>e,dCe=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},fCe=(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(aD(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(aD(n))};e.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(l):l()});return s.observe(n,{box:"border-box"}),()=>{s.unobserve(n)}},lD={passive:!0},cD=typeof window>"u"?!0:"onscrollend"in window,hCe=(e,t)=>{const n=e.scrollElement;if(!n)return;const r=e.targetWindow;if(!r)return;let i=0;const s=e.options.useScrollendEvent&&cD?()=>{}:cCe(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,lD);const d=e.options.useScrollendEvent&&cD;return d&&n.addEventListener("scrollend",u,lD),()=>{n.removeEventListener("scroll",l),d&&n.removeEventListener("scrollend",u)}},pCe=(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"]},mCe=(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 gCe{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:uCe,rangeExtractor:dCe,onChange:()=>{},measureElement:pCe,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),P=x+A;h[g]={index:g,start:x,size:A,end:P,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?vCe({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 oD(r[KH(0,r.length-1,i=>oD(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&&lCe(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 KH=(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 vCe({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=KH(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 uD=typeof document<"u"?b.useLayoutEffect:b.useEffect;function yCe({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 gCe(r));return i.setOptions(r),uD(()=>i._didMount(),[]),uD(()=>i._willUpdate()),i}function bCe(e){return yCe({observeElementRect:fCe,observeElementOffset:hCe,scrollToFn:mCe,...e})}function _Ce(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=bc(i)??(ST(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 wCe(e){const t=_Ce(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 xCe(e){return e.kind==="diff"}const SCe=12e4;function dD(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 vDe(){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(hb,{text:gDe})})})]})})}function K8(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 G8(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 yDe(e,t,n){if(!Number.isFinite(e)||!Number.isFinite(t))return null;const r=K8(n);return!r||e<r.left||e>r.right||t<r.top||t>r.bottom?null:G8(e,t,r)}function bDe(e,t,n){if(!Number.isFinite(e)||!Number.isFinite(t))return null;const r=K8(n);return r?G8(e,t,r):null}async function _De(e){const t=e.slice();return createImageBitmap(new Blob([t.buffer],{type:"image/jpeg"}))}class wDe{constructor(t,n,r=_De){ze(this,"latest",null);ze(this,"painting",!1);ze(this,"disposed",!1);ze(this,"generation",0);ze(this,"lastSequence",-1);ze(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 xDe=120,SDe=8*1024*1024,EDe=1e3/30,CDe=.15,kDe=100,TDe=.001;function RDe(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 ADe(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 NDe{constructor(t,n={}){ze(this,"muxer",null);ze(this,"initialSources");ze(this,"initialVideoState");ze(this,"configuration",null);ze(this,"configurationApplied",!1);ze(this,"muxerReady",!1);ze(this,"awaitingKeyframe",!0);ze(this,"pendingFrames",[]);ze(this,"fedFramesAwaitingPlayback",[]);ze(this,"bufferedPacketCount",0);ze(this,"bufferedBytes",0);ze(this,"maxBufferedPackets");ze(this,"maxBufferedBytes");ze(this,"lastObservedMediaTime",null);ze(this,"resyncRequired",!1);ze(this,"playPending",!1);ze(this,"playRequested",!1);ze(this,"started",!1);ze(this,"destroyed",!1);ze(this,"generation",0);ze(this,"playbackDelayTimer",null);ze(this,"handlePlaying",()=>{this.destroyed||(this.observePlaybackProgress(),this.playRequested=!0,this.markStarted())});ze(this,"handleTimeUpdate",()=>{this.observePlaybackProgress()});ze(this,"handleVideoError",()=>{this.destroyed||this.reportError(ADe(this.video))});this.video=t,this.options=n,this.maxBufferedPackets=jB(n.maxBufferedPackets,xDe),this.maxBufferedBytes=jB(n.maxBufferedBytes,SDe),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 WH(async()=>{const{default:r}=await import("./jmuxer.min-CT3OjDKg.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&&RDe(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:EDe,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()},kDe))}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<=CDe)return;this.video.currentTime=Math.max(0,n-TDe),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 jB(e,t){return typeof e=="number"&&Number.isSafeInteger(e)&&e>0?e:t}class MDe{constructor(){ze(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>By)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+By)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 PDe{constructor(){ze(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=mre(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+By)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 IDe(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 ODe(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 X8(e,t,n){IDe(e);const r=Rb(),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 LDe(e,t){const n=t.fetch??globalThis.fetch,r=await X8(e,t.signal,n);if(r.headers.get("X-Device-Preview-Format")!=="jpeg")throw new Error("开发机返回了错误的模拟器画面格式");const i=new MDe,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 DDe(e,t){var l;const n=t.fetch??globalThis.fetch,r=await X8(e,t.signal,n);if(r.headers.get("X-Device-Preview-Format")!=="h264_annex_b")throw new Error("开发机没有返回 H.264 模拟器画面");const i=ODe(r);i&&((l=t.onSize)==null||l.call(t,i));const s=new PDe,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 BDe=16,zDe=16;class jDe{constructor(t){ze(this,"send");ze(this,"onFailure");ze(this,"now");ze(this,"moveFlushMs");ze(this,"maxInFlightMoves");ze(this,"active",null);ze(this,"inFlightMoves",0);ze(this,"disposed",!1);ze(this,"failed",!1);this.send=t.send,this.onFailure=t.onFailure,this.now=t.now??(()=>performance.now()),this.moveFlushMs=t.moveFlushMs??BDe,this.maxInFlightMoves=t.maxInFlightMoves??zDe}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 FDe=15e3,$De=1e4,HDe={ios:40,android:28},UDe={ios:{width:390,height:844},android:{width:412,height:915}};function WDe(){const{id:e=""}=xz(),t=ks(),n=mr(Ne=>S5(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=Jo(Ne=>$ie(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,P]=b.useState(null),[R,M]=b.useState(null),[z,V]=b.useState(""),[W,G]=b.useState(!1),[O,N]=b.useState(!1),[L,D]=b.useState(!1),I=n==null?void 0:n.previewId,B=n==null?void 0:n.state,F=n==null?void 0:n.platform,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 wDe(Ne,M);return Ue.reset(!0),M(null),d.current=Ue,()=>{Ue.dispose(),d.current=null}},[I,F]),b.useEffect(()=>{if(U(),h.current=()=>{},v.current=null,g.current=null,P(null),N(!1),D(!1),!I||B!=="ready"){B==="disconnected"?(x("error"),k("模拟器已断开")):(x("waiting"),k(null));return}const Ne=zt,Ue=i;if(!Ne||!Ue||!Pt.isActive(Ne,Ue)){x("error"),k("开发机连接已断开");return}let ye=!1,nt=null,He=null,Ae=null,Ze=null,Tt=null,ve=0,Ke=!1;const be=()=>{Tt=null,Ae==null||Ae.abort(),Ae=null,Ze==null||Ze.destroy(),Ze=null,nt&&clearTimeout(nt),nt=null,He&&clearTimeout(He),He=null},Je=Et=>{x("streaming"),He&&clearTimeout(He),He=setTimeout(()=>{He=null,!(ye||Et.signal.aborted||Tt!==Et.leaseId||!Pt.isActive(Ne,Ue))&&(ve=0)},$De)},pt=()=>{if(ye||document.visibilityState==="hidden"||!Pt.isActive(Ne,Ue))return;const Et=Math.min(5e3,500*2**ve);ve+=1,nt=setTimeout(()=>void wt(),Et)},wt=async()=>{var pn;if(U(),be(),ye||document.visibilityState==="hidden"||!Pt.isActive(Ne,Ue))return;Ke=!1,(pn=d.current)==null||pn.reset(),M(null),x("connecting"),k(null),P(null);const Et=new AbortController;Ae=Et;try{const Wt=await Pt.requestDevicePreviewStream(Ue,I,F==="android"?{format:"h264_annex_b"}:{format:"jpeg",maxFps:15},{signal:Et.signal});if(ye||Et.signal.aborted||!Pt.isActive(Ne,Ue)||!Wt)return;if(!Wt.success)throw new Error(Wt.error);const tn=Wt;if(Tt=tn.leaseId,P(tn),F==="android"){const nr=l.current;if(!nr)throw new Error("无法初始化 Android 模拟器播放器");let or;const Cn=new Promise((ke,he)=>{or=he}),q=setTimeout(()=>{or(new Error("Android 模拟器画面启动超时"))},FDe),se=ke=>{or(ke instanceof Error?ke:new Error(String(ke)))},ae=new NDe(nr,{onStart:()=>{clearTimeout(q),!(ye||tn.signal.aborted||!Pt.isActive(Ne,Ue))&&Je(tn)},onError:se,onResyncRequired:se});Ze=ae;try{await Promise.race([DDe(tn.url,{signal:tn.signal,onSize:ke=>{!ye&&!tn.signal.aborted&&Pt.isActive(Ne,Ue)&&M(ke)},onPacket:ke=>{!ye&&!tn.signal.aborted&&Pt.isActive(Ne,Ue)&&ae.feed(ke)}}),Cn])}finally{clearTimeout(q)}if(!ye&&!tn.signal.aborted&&Pt.isActive(Ne,Ue))throw new Error("模拟器画面已断开");return}let wn=!1;if(await LDe(tn.url,{signal:tn.signal,onFrame:nr=>{if(ye||tn.signal.aborted||!Pt.isActive(Ne,Ue))return;const or=d.current;or&&(or.enqueue(nr.sequence,nr.jpeg),wn||(wn=!0,Je(tn)))}}),!ye&&!tn.signal.aborted&&Pt.isActive(Ne,Ue))throw new Error("模拟器画面已断开")}catch(Wt){if(ye||Et.signal.aborted||!Pt.isActive(Ne,Ue))return;Bt(Wt,!1)}},Bt=(Et,pn)=>{if(ye||Ke||!Pt.isActive(Ne,Ue))return;Ke=!0;const Wt=Et instanceof Error?Et.message:"模拟器画面已断开";U(),be(),v.current=null,g.current=null,P(null),N(!1),D(!1),x("error"),k(Wt),pn&&$e.error(Wt),pt()},mn=(Et,pn,Wt=!0)=>{Et===Tt&&Bt(pn,Wt)};h.current=mn;const on=Ne.onMessage(Et=>{if(Et.type!=="device_preview_control_revoked_push"||!rn(Et.scope,Ue)||Et.leaseId!==Tt||!Pt.isActive(Ne,Ue))return;if(g.current=null,D(!1),Et.reason==="taken_over"){v.current=null,N(!1),U(),P(Wt=>(Wt==null?void 0:Wt.leaseId)===Et.leaseId?{...Wt,controlMode:"view_only"}:Wt),$e.info("控制权已由其他页面接管");return}const pn=new Error(Et.reason==="proxy_offline"?"开发机连接已断开":Et.reason==="lease_expired"?"模拟器画面连接已过期":"模拟器画面已断开");mn(Et.leaseId,pn,!1)}),nn=()=>{if(document.visibilityState==="hidden"){U(),be(),v.current=null,g.current=null,P(null),N(!1),D(!1),x("waiting");return}ve=0,wt()};return document.addEventListener("visibilitychange",nn),wt(),()=>{ye=!0,h.current===mn&&(h.current=()=>{}),on(),document.removeEventListener("visibilitychange",nn),U(),be()}},[U,I,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,Y=(n==null?void 0:n.interactive)===!0&&S==="streaming"&&(j==null?void 0:j.controlMode)==="controller";b.useEffect(()=>{U();const Ne=zt,Ue=j;if(!Ne||!Ue||!Y)return;const ye=new jDe({send:async nt=>{const He=await Pt.sendDevicePreviewInput(Ue,nt);if(!He)throw new Error("模拟器控制连接已失效");if(!He.success)throw new Error(He.error)},onFailure:nt=>{f.current===ye&&h.current(Ue.leaseId,nt)}});return f.current=ye,()=>{f.current===ye&&(f.current=null),ye.dispose()}},[Y,j,U]);const X=R??UDe[(n==null?void 0:n.platform)==="android"?"android":"ios"],$=HDe[(n==null?void 0:n.platform)==="android"?"android":"ios"],ee=X.width/X.height,re=X.width>X.height?"landscape":"portrait",te=re==="landscape"?`, ${X.width}px`:"",Z={aspectRatio:`${X.width} / ${X.height}`,width:`max(1px, min(calc(100cqw - ${$}px), calc(${(ee*100).toFixed(6)}cqh - ${(ee*$).toFixed(6)}px)${te}))`};b.useEffect(()=>{Y||G(!1)},[Y]);const oe=b.useCallback(async(Ne,Ue=!0)=>{const ye=zt,nt=j;if(!ye||!nt||!Y)return!1;try{const He=await Pt.sendDevicePreviewInput(nt,Ne);return!He||!Pt.isActive(ye,nt.scope)?!1:He.success?!0:(Ue&&$e.error(He.error),!1)}catch(He){return nt.signal.aborted||!Pt.isActive(ye,nt.scope)||Ue&&$e.error(He instanceof Error?He.message:"模拟器操作失败"),!1}},[Y,j]);function Q(Ne,Ue){const ye=u.current;if(!ye||!R)return null;const nt=ye.getBoundingClientRect(),He={left:nt.left,top:nt.top,width:nt.width,height:nt.height,frameWidth:R.width,frameHeight:R.height};return Ue==="start"?yDe(Ne.clientX,Ne.clientY,He):bDe(Ne.clientX,Ne.clientY,He)}function fe(Ne){var nt,He;if(!Y||Ne.button!==0)return;const Ue=Q(Ne,"start");if(!Ue)return;const ye=f.current;ye!=null&&ye.begin(Ne.pointerId,Ue)&&(Ne.preventDefault(),(He=(nt=Ne.currentTarget).setPointerCapture)==null||He.call(nt,Ne.pointerId))}function ge(Ne){var ye;const Ue=Q(Ne,"captured");Ue&&(ye=f.current)!=null&&ye.move(Ne.pointerId,Ue)&&Ne.preventDefault()}function Ce(Ne){var ye;const Ue=Q(Ne,"captured");Ue&&((ye=f.current)!=null&&ye.end(Ne.pointerId,Ue))&&Ne.preventDefault()}function De(Ne){var Ue;(Ue=f.current)==null||Ue.cancel(Ne.pointerId)}async function ot(){const Ne=zt,Ue=j;if(!Ne||!Ue||L||S!=="streaming")return;const ye=Symbol("device-preview-control-claim");g.current=ye,D(!0);try{const nt=await Pt.claimDevicePreviewControl(Ue);if(g.current!==ye||!nt||!Pt.isActive(Ne,Ue.scope))return;if(!nt.success){$e.error(nt.error);return}P(He=>(He==null?void 0:He.leaseId)===Ue.leaseId?{...He,controlMode:"controller"}:He)}catch(nt){if(g.current!==ye||Ue.signal.aborted||!Pt.isActive(Ne,Ue.scope))return;$e.error(nt instanceof Error?nt.message:"暂时无法取得控制权")}finally{g.current===ye&&(g.current=null,D(!1))}}async function Dt(Ne){Ne.preventDefault();const Ue=z;if(!Ue||O)return;const ye=Symbol("device-preview-text-input");v.current=ye,N(!0);const nt=await oe({kind:"text",text:Ue});v.current===ye&&(nt&&(V(""),G(!1)),v.current=null,N(!1))}function et(){var Ne;(Ne=f.current)==null||Ne.cancel(),oe({kind:"orientation",orientation:R&&R.width>R.height?"portrait":"landscape_right"})}async function ut(){if((n==null?void 0:n.state)!=="disconnected"){w(ye=>ye+1);return}const Ne=zt,Ue=Pt.getActiveScope();if(!Ne||!Ue){$e.error("请先连接开发机");return}try{const ye=await Pt.reconnectDevicePreview(Ue,n.previewId);ye.success||$e.error(ye.error)}catch(ye){if(!Pt.isActive(Ne,Ue))return;$e.error(ye instanceof Error?ye.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(dt,{variant:"ghost",size:"icon",className:"md:hidden","aria-label":"返回",onClick:()=>t("/sessions"),children:m.jsx(gf,{"aria-hidden":"true"})}),m.jsx(MC,{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(dt,{size:"sm",variant:"outline",disabled:L,onClick:()=>void ot(),"data-slot":"device-preview-claim-control",children:"接管控制"}):m.jsx("span",{className:"text-xs text-muted-foreground",children:Y?"可操控":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",re==="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":re,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":re,children:[m.jsx(qDe,{platform:n.platform,orientation:re}),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",Y&&"cursor-pointer"),"data-slot":"device-preview-surface","data-control-enabled":Y?"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)]",Y?"touch-none cursor-pointer":"pointer-events-none"),onPointerDown:fe,onPointerMove:ge,onPointerUp:Ce,onPointerCancel:De,onLostPointerCapture:De,onContextMenu:Ne=>{Y&&Ne.preventDefault()},"data-slot":"device-preview-input-surface","data-control-enabled":Y?"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(dt,{variant:"outline",size:"sm",disabled:s,onClick:()=>void ut(),"data-slot":"device-preview-retry",children:[s?m.jsx(Xr,{className:"size-4 animate-spin","aria-hidden":!0}):null,s?"正在重新连接":"重新连接"]})]}):m.jsxs(m.Fragment,{children:[m.jsx(Xr,{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":re,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",re==="portrait"&&"md:flex-col"),children:[m.jsx(qS,{control:"home",label:"主屏幕",disabled:!Y,icon:m.jsx(VV,{"aria-hidden":"true"}),tooltipSide:re==="portrait"?"left":"top",onClick:()=>void oe({kind:"button",button:"home"})}),n.platform==="android"?m.jsx(qS,{control:"back",label:"返回",disabled:!Y,icon:m.jsx(VK,{"aria-hidden":"true"}),tooltipSide:re==="portrait"?"left":"top",onClick:()=>void oe({kind:"button",button:"back"})}):null,m.jsx(qS,{control:"orientation",label:"旋转",disabled:!Y||!R,icon:m.jsx(EK,{"aria-hidden":"true"}),tooltipSide:re==="portrait"?"left":"top",onClick:et}),m.jsx("span",{className:We("mx-0.5 h-6 w-px shrink-0 bg-border/80",re==="portrait"&&"md:mx-0 md:h-px md:w-6"),"aria-hidden":"true"}),m.jsxs(Kb,{open:W,onOpenChange:Ne=>{(!Ne||Y)&&G(Ne)},children:[m.jsxs(Rf,{children:[m.jsx(Af,{asChild:!0,children:m.jsx(Gb,{asChild:!0,children:m.jsx(dt,{type:"button",variant:"ghost",size:"icon",className:We("size-11 rounded-full text-muted-foreground hover:text-foreground",W&&"bg-accent text-foreground"),disabled:!Y,"aria-label":"粘贴文字","aria-expanded":W,"aria-controls":"device-preview-text-form","data-slot":"device-preview-text-toggle",children:m.jsx(XS,{"aria-hidden":"true"})})})}),m.jsx(Nf,{side:re==="portrait"?"left":"top",sideOffset:10,hideArrow:!0,children:"粘贴文字"})]}),m.jsx(Xb,{side:re==="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=>void Dt(Ne),children:[m.jsx("textarea",{value:z,onChange:Ne=>V(Ne.target.value),disabled:!Y||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(dt,{type:"submit",size:"icon",className:"size-10 rounded-xl",disabled:!Y||!z||O,"aria-label":"粘贴","data-slot":"device-preview-send-text",children:O?m.jsx(Xr,{className:"animate-spin","aria-hidden":"true"}):m.jsx(XS,{"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(dt,{variant:"outline",onClick:()=>t("/sessions"),children:"返回"})]}):m.jsx(Xr,{className:"size-5 animate-spin text-muted-foreground","aria-label":"加载中"})})}function qS({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(dt,{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 qDe({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=EY([{path:"/",element:m.jsx(EEe,{}),children:[{index:!0,element:m.jsx(CEe,{})},{path:"sessions",element:m.jsx(kEe,{})},{path:"chat/:id",element:m.jsx(oDe,{})},{path:"preview/device/:id",element:m.jsx(WDe,{})}]},{path:"/pty-test",element:m.jsx(cDe,{})},{path:"/tokens",element:m.jsx(mDe,{})},{path:"/markdown-test",element:m.jsx(vDe,{})}]);function YDe({browserName:e}){const[t,n]=b.useState("idle"),r=async()=>{const i=await Vp(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(aj,{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(wV,{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(dt,{className:"h-11 px-4",onClick:r,children:[t==="copied"?m.jsx(ua,{className:"size-4","aria-hidden":"true"}):m.jsx(RC,{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 VDe({children:e}){const t=SEe();return t.supported?e:m.jsx(YDe,{browserName:t.browserName})}function KDe(){return m.jsx(VDe,{children:m.jsx(GDe,{})})}function GDe(){return yoe(),m.jsx(bfe,{delayDuration:200,children:m.jsx(K7,{router:Jd})})}function XDe(e=window.history){e.scrollRestoration="manual"}XDe();lX();Ype();uq.createRoot(document.getElementById("root")).render(m.jsx(b.StrictMode,{children:m.jsx(KDe,{})}));export{WH as _,cm as a,JDe as g};
|
|
869
|
+
`;function vDe(){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(hb,{text:gDe})})})]})})}function K8(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 G8(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 yDe(e,t,n){if(!Number.isFinite(e)||!Number.isFinite(t))return null;const r=K8(n);return!r||e<r.left||e>r.right||t<r.top||t>r.bottom?null:G8(e,t,r)}function bDe(e,t,n){if(!Number.isFinite(e)||!Number.isFinite(t))return null;const r=K8(n);return r?G8(e,t,r):null}async function _De(e){const t=e.slice();return createImageBitmap(new Blob([t.buffer],{type:"image/jpeg"}))}class wDe{constructor(t,n,r=_De){ze(this,"latest",null);ze(this,"painting",!1);ze(this,"disposed",!1);ze(this,"generation",0);ze(this,"lastSequence",-1);ze(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 xDe=120,SDe=8*1024*1024,EDe=1e3/30,CDe=.15,kDe=100,TDe=.001;function RDe(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 ADe(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 NDe{constructor(t,n={}){ze(this,"muxer",null);ze(this,"initialSources");ze(this,"initialVideoState");ze(this,"configuration",null);ze(this,"configurationApplied",!1);ze(this,"muxerReady",!1);ze(this,"awaitingKeyframe",!0);ze(this,"pendingFrames",[]);ze(this,"fedFramesAwaitingPlayback",[]);ze(this,"bufferedPacketCount",0);ze(this,"bufferedBytes",0);ze(this,"maxBufferedPackets");ze(this,"maxBufferedBytes");ze(this,"lastObservedMediaTime",null);ze(this,"resyncRequired",!1);ze(this,"playPending",!1);ze(this,"playRequested",!1);ze(this,"started",!1);ze(this,"destroyed",!1);ze(this,"generation",0);ze(this,"playbackDelayTimer",null);ze(this,"handlePlaying",()=>{this.destroyed||(this.observePlaybackProgress(),this.playRequested=!0,this.markStarted())});ze(this,"handleTimeUpdate",()=>{this.observePlaybackProgress()});ze(this,"handleVideoError",()=>{this.destroyed||this.reportError(ADe(this.video))});this.video=t,this.options=n,this.maxBufferedPackets=jB(n.maxBufferedPackets,xDe),this.maxBufferedBytes=jB(n.maxBufferedBytes,SDe),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 WH(async()=>{const{default:r}=await import("./jmuxer.min-CA3NmHb7.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&&RDe(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:EDe,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()},kDe))}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<=CDe)return;this.video.currentTime=Math.max(0,n-TDe),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 jB(e,t){return typeof e=="number"&&Number.isSafeInteger(e)&&e>0?e:t}class MDe{constructor(){ze(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>By)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+By)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 PDe{constructor(){ze(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=mre(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+By)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 IDe(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 ODe(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 X8(e,t,n){IDe(e);const r=Rb(),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 LDe(e,t){const n=t.fetch??globalThis.fetch,r=await X8(e,t.signal,n);if(r.headers.get("X-Device-Preview-Format")!=="jpeg")throw new Error("开发机返回了错误的模拟器画面格式");const i=new MDe,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 DDe(e,t){var l;const n=t.fetch??globalThis.fetch,r=await X8(e,t.signal,n);if(r.headers.get("X-Device-Preview-Format")!=="h264_annex_b")throw new Error("开发机没有返回 H.264 模拟器画面");const i=ODe(r);i&&((l=t.onSize)==null||l.call(t,i));const s=new PDe,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 BDe=16,zDe=16;class jDe{constructor(t){ze(this,"send");ze(this,"onFailure");ze(this,"now");ze(this,"moveFlushMs");ze(this,"maxInFlightMoves");ze(this,"active",null);ze(this,"inFlightMoves",0);ze(this,"disposed",!1);ze(this,"failed",!1);this.send=t.send,this.onFailure=t.onFailure,this.now=t.now??(()=>performance.now()),this.moveFlushMs=t.moveFlushMs??BDe,this.maxInFlightMoves=t.maxInFlightMoves??zDe}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 FDe=15e3,$De=1e4,HDe={ios:40,android:28},UDe={ios:{width:390,height:844},android:{width:412,height:915}};function WDe(){const{id:e=""}=xz(),t=ks(),n=mr(Ne=>S5(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=Jo(Ne=>$ie(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,P]=b.useState(null),[R,M]=b.useState(null),[z,V]=b.useState(""),[W,G]=b.useState(!1),[O,N]=b.useState(!1),[L,D]=b.useState(!1),I=n==null?void 0:n.previewId,B=n==null?void 0:n.state,F=n==null?void 0:n.platform,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 wDe(Ne,M);return Ue.reset(!0),M(null),d.current=Ue,()=>{Ue.dispose(),d.current=null}},[I,F]),b.useEffect(()=>{if(U(),h.current=()=>{},v.current=null,g.current=null,P(null),N(!1),D(!1),!I||B!=="ready"){B==="disconnected"?(x("error"),k("模拟器已断开")):(x("waiting"),k(null));return}const Ne=zt,Ue=i;if(!Ne||!Ue||!Pt.isActive(Ne,Ue)){x("error"),k("开发机连接已断开");return}let ye=!1,nt=null,He=null,Ae=null,Ze=null,Tt=null,ve=0,Ke=!1;const be=()=>{Tt=null,Ae==null||Ae.abort(),Ae=null,Ze==null||Ze.destroy(),Ze=null,nt&&clearTimeout(nt),nt=null,He&&clearTimeout(He),He=null},Je=Et=>{x("streaming"),He&&clearTimeout(He),He=setTimeout(()=>{He=null,!(ye||Et.signal.aborted||Tt!==Et.leaseId||!Pt.isActive(Ne,Ue))&&(ve=0)},$De)},pt=()=>{if(ye||document.visibilityState==="hidden"||!Pt.isActive(Ne,Ue))return;const Et=Math.min(5e3,500*2**ve);ve+=1,nt=setTimeout(()=>void wt(),Et)},wt=async()=>{var pn;if(U(),be(),ye||document.visibilityState==="hidden"||!Pt.isActive(Ne,Ue))return;Ke=!1,(pn=d.current)==null||pn.reset(),M(null),x("connecting"),k(null),P(null);const Et=new AbortController;Ae=Et;try{const Wt=await Pt.requestDevicePreviewStream(Ue,I,F==="android"?{format:"h264_annex_b"}:{format:"jpeg",maxFps:15},{signal:Et.signal});if(ye||Et.signal.aborted||!Pt.isActive(Ne,Ue)||!Wt)return;if(!Wt.success)throw new Error(Wt.error);const tn=Wt;if(Tt=tn.leaseId,P(tn),F==="android"){const nr=l.current;if(!nr)throw new Error("无法初始化 Android 模拟器播放器");let or;const Cn=new Promise((ke,he)=>{or=he}),q=setTimeout(()=>{or(new Error("Android 模拟器画面启动超时"))},FDe),se=ke=>{or(ke instanceof Error?ke:new Error(String(ke)))},ae=new NDe(nr,{onStart:()=>{clearTimeout(q),!(ye||tn.signal.aborted||!Pt.isActive(Ne,Ue))&&Je(tn)},onError:se,onResyncRequired:se});Ze=ae;try{await Promise.race([DDe(tn.url,{signal:tn.signal,onSize:ke=>{!ye&&!tn.signal.aborted&&Pt.isActive(Ne,Ue)&&M(ke)},onPacket:ke=>{!ye&&!tn.signal.aborted&&Pt.isActive(Ne,Ue)&&ae.feed(ke)}}),Cn])}finally{clearTimeout(q)}if(!ye&&!tn.signal.aborted&&Pt.isActive(Ne,Ue))throw new Error("模拟器画面已断开");return}let wn=!1;if(await LDe(tn.url,{signal:tn.signal,onFrame:nr=>{if(ye||tn.signal.aborted||!Pt.isActive(Ne,Ue))return;const or=d.current;or&&(or.enqueue(nr.sequence,nr.jpeg),wn||(wn=!0,Je(tn)))}}),!ye&&!tn.signal.aborted&&Pt.isActive(Ne,Ue))throw new Error("模拟器画面已断开")}catch(Wt){if(ye||Et.signal.aborted||!Pt.isActive(Ne,Ue))return;Bt(Wt,!1)}},Bt=(Et,pn)=>{if(ye||Ke||!Pt.isActive(Ne,Ue))return;Ke=!0;const Wt=Et instanceof Error?Et.message:"模拟器画面已断开";U(),be(),v.current=null,g.current=null,P(null),N(!1),D(!1),x("error"),k(Wt),pn&&$e.error(Wt),pt()},mn=(Et,pn,Wt=!0)=>{Et===Tt&&Bt(pn,Wt)};h.current=mn;const on=Ne.onMessage(Et=>{if(Et.type!=="device_preview_control_revoked_push"||!rn(Et.scope,Ue)||Et.leaseId!==Tt||!Pt.isActive(Ne,Ue))return;if(g.current=null,D(!1),Et.reason==="taken_over"){v.current=null,N(!1),U(),P(Wt=>(Wt==null?void 0:Wt.leaseId)===Et.leaseId?{...Wt,controlMode:"view_only"}:Wt),$e.info("控制权已由其他页面接管");return}const pn=new Error(Et.reason==="proxy_offline"?"开发机连接已断开":Et.reason==="lease_expired"?"模拟器画面连接已过期":"模拟器画面已断开");mn(Et.leaseId,pn,!1)}),nn=()=>{if(document.visibilityState==="hidden"){U(),be(),v.current=null,g.current=null,P(null),N(!1),D(!1),x("waiting");return}ve=0,wt()};return document.addEventListener("visibilitychange",nn),wt(),()=>{ye=!0,h.current===mn&&(h.current=()=>{}),on(),document.removeEventListener("visibilitychange",nn),U(),be()}},[U,I,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,Y=(n==null?void 0:n.interactive)===!0&&S==="streaming"&&(j==null?void 0:j.controlMode)==="controller";b.useEffect(()=>{U();const Ne=zt,Ue=j;if(!Ne||!Ue||!Y)return;const ye=new jDe({send:async nt=>{const He=await Pt.sendDevicePreviewInput(Ue,nt);if(!He)throw new Error("模拟器控制连接已失效");if(!He.success)throw new Error(He.error)},onFailure:nt=>{f.current===ye&&h.current(Ue.leaseId,nt)}});return f.current=ye,()=>{f.current===ye&&(f.current=null),ye.dispose()}},[Y,j,U]);const X=R??UDe[(n==null?void 0:n.platform)==="android"?"android":"ios"],$=HDe[(n==null?void 0:n.platform)==="android"?"android":"ios"],ee=X.width/X.height,re=X.width>X.height?"landscape":"portrait",te=re==="landscape"?`, ${X.width}px`:"",Z={aspectRatio:`${X.width} / ${X.height}`,width:`max(1px, min(calc(100cqw - ${$}px), calc(${(ee*100).toFixed(6)}cqh - ${(ee*$).toFixed(6)}px)${te}))`};b.useEffect(()=>{Y||G(!1)},[Y]);const oe=b.useCallback(async(Ne,Ue=!0)=>{const ye=zt,nt=j;if(!ye||!nt||!Y)return!1;try{const He=await Pt.sendDevicePreviewInput(nt,Ne);return!He||!Pt.isActive(ye,nt.scope)?!1:He.success?!0:(Ue&&$e.error(He.error),!1)}catch(He){return nt.signal.aborted||!Pt.isActive(ye,nt.scope)||Ue&&$e.error(He instanceof Error?He.message:"模拟器操作失败"),!1}},[Y,j]);function Q(Ne,Ue){const ye=u.current;if(!ye||!R)return null;const nt=ye.getBoundingClientRect(),He={left:nt.left,top:nt.top,width:nt.width,height:nt.height,frameWidth:R.width,frameHeight:R.height};return Ue==="start"?yDe(Ne.clientX,Ne.clientY,He):bDe(Ne.clientX,Ne.clientY,He)}function fe(Ne){var nt,He;if(!Y||Ne.button!==0)return;const Ue=Q(Ne,"start");if(!Ue)return;const ye=f.current;ye!=null&&ye.begin(Ne.pointerId,Ue)&&(Ne.preventDefault(),(He=(nt=Ne.currentTarget).setPointerCapture)==null||He.call(nt,Ne.pointerId))}function ge(Ne){var ye;const Ue=Q(Ne,"captured");Ue&&(ye=f.current)!=null&&ye.move(Ne.pointerId,Ue)&&Ne.preventDefault()}function Ce(Ne){var ye;const Ue=Q(Ne,"captured");Ue&&((ye=f.current)!=null&&ye.end(Ne.pointerId,Ue))&&Ne.preventDefault()}function De(Ne){var Ue;(Ue=f.current)==null||Ue.cancel(Ne.pointerId)}async function ot(){const Ne=zt,Ue=j;if(!Ne||!Ue||L||S!=="streaming")return;const ye=Symbol("device-preview-control-claim");g.current=ye,D(!0);try{const nt=await Pt.claimDevicePreviewControl(Ue);if(g.current!==ye||!nt||!Pt.isActive(Ne,Ue.scope))return;if(!nt.success){$e.error(nt.error);return}P(He=>(He==null?void 0:He.leaseId)===Ue.leaseId?{...He,controlMode:"controller"}:He)}catch(nt){if(g.current!==ye||Ue.signal.aborted||!Pt.isActive(Ne,Ue.scope))return;$e.error(nt instanceof Error?nt.message:"暂时无法取得控制权")}finally{g.current===ye&&(g.current=null,D(!1))}}async function Dt(Ne){Ne.preventDefault();const Ue=z;if(!Ue||O)return;const ye=Symbol("device-preview-text-input");v.current=ye,N(!0);const nt=await oe({kind:"text",text:Ue});v.current===ye&&(nt&&(V(""),G(!1)),v.current=null,N(!1))}function et(){var Ne;(Ne=f.current)==null||Ne.cancel(),oe({kind:"orientation",orientation:R&&R.width>R.height?"portrait":"landscape_right"})}async function ut(){if((n==null?void 0:n.state)!=="disconnected"){w(ye=>ye+1);return}const Ne=zt,Ue=Pt.getActiveScope();if(!Ne||!Ue){$e.error("请先连接开发机");return}try{const ye=await Pt.reconnectDevicePreview(Ue,n.previewId);ye.success||$e.error(ye.error)}catch(ye){if(!Pt.isActive(Ne,Ue))return;$e.error(ye instanceof Error?ye.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(dt,{variant:"ghost",size:"icon",className:"md:hidden","aria-label":"返回",onClick:()=>t("/sessions"),children:m.jsx(gf,{"aria-hidden":"true"})}),m.jsx(MC,{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(dt,{size:"sm",variant:"outline",disabled:L,onClick:()=>void ot(),"data-slot":"device-preview-claim-control",children:"接管控制"}):m.jsx("span",{className:"text-xs text-muted-foreground",children:Y?"可操控":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",re==="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":re,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":re,children:[m.jsx(qDe,{platform:n.platform,orientation:re}),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",Y&&"cursor-pointer"),"data-slot":"device-preview-surface","data-control-enabled":Y?"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)]",Y?"touch-none cursor-pointer":"pointer-events-none"),onPointerDown:fe,onPointerMove:ge,onPointerUp:Ce,onPointerCancel:De,onLostPointerCapture:De,onContextMenu:Ne=>{Y&&Ne.preventDefault()},"data-slot":"device-preview-input-surface","data-control-enabled":Y?"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(dt,{variant:"outline",size:"sm",disabled:s,onClick:()=>void ut(),"data-slot":"device-preview-retry",children:[s?m.jsx(Xr,{className:"size-4 animate-spin","aria-hidden":!0}):null,s?"正在重新连接":"重新连接"]})]}):m.jsxs(m.Fragment,{children:[m.jsx(Xr,{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":re,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",re==="portrait"&&"md:flex-col"),children:[m.jsx(qS,{control:"home",label:"主屏幕",disabled:!Y,icon:m.jsx(VV,{"aria-hidden":"true"}),tooltipSide:re==="portrait"?"left":"top",onClick:()=>void oe({kind:"button",button:"home"})}),n.platform==="android"?m.jsx(qS,{control:"back",label:"返回",disabled:!Y,icon:m.jsx(VK,{"aria-hidden":"true"}),tooltipSide:re==="portrait"?"left":"top",onClick:()=>void oe({kind:"button",button:"back"})}):null,m.jsx(qS,{control:"orientation",label:"旋转",disabled:!Y||!R,icon:m.jsx(EK,{"aria-hidden":"true"}),tooltipSide:re==="portrait"?"left":"top",onClick:et}),m.jsx("span",{className:We("mx-0.5 h-6 w-px shrink-0 bg-border/80",re==="portrait"&&"md:mx-0 md:h-px md:w-6"),"aria-hidden":"true"}),m.jsxs(Kb,{open:W,onOpenChange:Ne=>{(!Ne||Y)&&G(Ne)},children:[m.jsxs(Rf,{children:[m.jsx(Af,{asChild:!0,children:m.jsx(Gb,{asChild:!0,children:m.jsx(dt,{type:"button",variant:"ghost",size:"icon",className:We("size-11 rounded-full text-muted-foreground hover:text-foreground",W&&"bg-accent text-foreground"),disabled:!Y,"aria-label":"粘贴文字","aria-expanded":W,"aria-controls":"device-preview-text-form","data-slot":"device-preview-text-toggle",children:m.jsx(XS,{"aria-hidden":"true"})})})}),m.jsx(Nf,{side:re==="portrait"?"left":"top",sideOffset:10,hideArrow:!0,children:"粘贴文字"})]}),m.jsx(Xb,{side:re==="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=>void Dt(Ne),children:[m.jsx("textarea",{value:z,onChange:Ne=>V(Ne.target.value),disabled:!Y||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(dt,{type:"submit",size:"icon",className:"size-10 rounded-xl",disabled:!Y||!z||O,"aria-label":"粘贴","data-slot":"device-preview-send-text",children:O?m.jsx(Xr,{className:"animate-spin","aria-hidden":"true"}):m.jsx(XS,{"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(dt,{variant:"outline",onClick:()=>t("/sessions"),children:"返回"})]}):m.jsx(Xr,{className:"size-5 animate-spin text-muted-foreground","aria-label":"加载中"})})}function qS({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(dt,{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 qDe({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=EY([{path:"/",element:m.jsx(EEe,{}),children:[{index:!0,element:m.jsx(CEe,{})},{path:"sessions",element:m.jsx(kEe,{})},{path:"chat/:id",element:m.jsx(oDe,{})},{path:"preview/device/:id",element:m.jsx(WDe,{})}]},{path:"/pty-test",element:m.jsx(cDe,{})},{path:"/tokens",element:m.jsx(mDe,{})},{path:"/markdown-test",element:m.jsx(vDe,{})}]);function YDe({browserName:e}){const[t,n]=b.useState("idle"),r=async()=>{const i=await Vp(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(aj,{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(wV,{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(dt,{className:"h-11 px-4",onClick:r,children:[t==="copied"?m.jsx(ua,{className:"size-4","aria-hidden":"true"}):m.jsx(RC,{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 VDe({children:e}){const t=SEe();return t.supported?e:m.jsx(YDe,{browserName:t.browserName})}function KDe(){return m.jsx(VDe,{children:m.jsx(GDe,{})})}function GDe(){return yoe(),m.jsx(bfe,{delayDuration:200,children:m.jsx(K7,{router:Jd})})}function XDe(e=window.history){e.scrollRestoration="manual"}XDe();lX();Ype();uq.createRoot(document.getElementById("root")).render(m.jsx(b.StrictMode,{children:m.jsx(KDe,{})}));export{WH as _,cm as a,JDe as g};
|