@dev-anywhere/relay 0.9.16 → 0.9.17
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-BeprG8UQ.js → fvad-D1IHUtam.js} +1 -1
- package/assets/web/assets/{index-DNgvy5gG.js → index-BRuVXloL.js} +4 -4
- package/assets/web/assets/{jmuxer.min-DyXp3arz.js → jmuxer.min-M-MIxBvo.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-M-MIxBvo.js","assets/__vite-browser-external-D7Ct-6yo.js"])))=>i.map(i=>d[i]);
|
|
2
2
|
var AW=Object.defineProperty;var NW=(e,t,n)=>t in e?AW(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var je=(e,t,n)=>NW(e,typeof t!="symbol"?t+"":t,n);function MW(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 sm(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function cDe(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 yx={exports:{}},bh={};/**
|
|
3
3
|
* @license React
|
|
4
4
|
* react-jsx-runtime.production.js
|
|
@@ -597,7 +597,7 @@ ${s}`,l=u5(`${a1(r.kind)}:${r.path}`,o,r.kind);n.push(l.kind==="diff"?{...l,co
|
|
|
597
597
|
|
|
598
598
|
If you want to hide the \`${t.titleName}\`, you can wrap it with our VisuallyHidden component.
|
|
599
599
|
|
|
600
|
-
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},mae="DialogDescriptionWarning",gae=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${Z5(mae).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},ok=B5,vae=j5,ak=$5,lk=H5,ck=U5,J5=q5,Q5=Y5,Rb=G5;function yae(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 bae(e){const[t,n]=b.useState(void 0);return Ji(()=>{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 _ae=["top","right","bottom","left"],ec=Math.min,$s=Math.max,zy=Math.round,vv=Math.floor,aa=e=>({x:e,y:e}),wae={left:"right",right:"left",bottom:"top",top:"bottom"};function p1(e,t,n){return $s(e,ec(t,n))}function Va(e,t){return typeof e=="function"?e(t):e}function Ya(e){return e.split("-")[0]}function vf(e){return e.split("-")[1]}function uk(e){return e==="x"?"y":"x"}function dk(e){return e==="y"?"height":"width"}function ra(e){const t=e[0];return t==="t"||t==="b"?"y":"x"}function fk(e){return uk(ra(e))}function xae(e,t,n){n===void 0&&(n=!1);const r=vf(e),i=fk(e),s=dk(i);let o=i==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(o=jy(o)),[o,jy(o)]}function Sae(e){const t=jy(e);return[m1(e),t,m1(t)]}function m1(e){return e.includes("start")?e.replace("start","end"):e.replace("end","start")}const V2=["left","right"],Y2=["right","left"],Eae=["top","bottom"],Cae=["bottom","top"];function kae(e,t,n){switch(e){case"top":case"bottom":return n?t?Y2:V2:t?V2:Y2;case"left":case"right":return t?Eae:Cae;default:return[]}}function Tae(e,t,n,r){const i=vf(e);let s=kae(Ya(e),n==="start",r);return i&&(s=s.map(o=>o+"-"+i),t&&(s=s.concat(s.map(m1)))),s}function jy(e){const t=Ya(e);return wae[t]+e.slice(t.length)}function Rae(e){return{top:0,right:0,bottom:0,left:0,...e}}function e3(e){return typeof e!="number"?Rae(e):{top:e,right:e,bottom:e,left:e}}function Fy(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 K2(e,t,n){let{reference:r,floating:i}=e;const s=ra(t),o=fk(t),l=dk(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,y=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(vf(t)){case"start":g[o]-=y*(n&&d?-1:1);break;case"end":g[o]+=y*(n&&d?-1:1);break}return g}async function Aae(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:y=!1,padding:g=0}=Va(t,e),_=e3(g),S=l[y?h==="floating"?"reference":"floating":h],x=Fy(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})),k=h==="floating"?{x:r,y:i,width:o.floating.width,height:o.floating.height}:o.reference,R=await(s.getOffsetParent==null?void 0:s.getOffsetParent(l.floating)),A=await(s.isElement==null?void 0:s.isElement(R))?await(s.getScale==null?void 0:s.getScale(R))||{x:1,y:1}:{x:1,y:1},O=Fy(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:l,rect:k,offsetParent:R,strategy:u}):k);return{top:(x.top-O.top+_.top)/A.y,bottom:(O.bottom-x.bottom+_.bottom)/A.y,left:(x.left-O.left+_.left)/A.x,right:(O.right-x.right+_.right)/A.x}}const Nae=50,Mae=async(e,t,n)=>{const{placement:r="bottom",strategy:i="absolute",middleware:s=[],platform:o}=n,l=o.detectOverflow?o:{...o,detectOverflow:Aae},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}=K2(d,r,u),y=r,g=0;const _={};for(let w=0;w<s.length;w++){const S=s[w];if(!S)continue;const{name:x,fn:k}=S,{x:R,y:A,data:O,reset:T}=await k({x:f,y:h,initialPlacement:r,placement:y,strategy:i,middlewareData:_,rects:d,platform:l,elements:{reference:e,floating:t}});f=R??f,h=A??h,_[x]={..._[x],...O},T&&g<Nae&&(g++,typeof T=="object"&&(T.placement&&(y=T.placement),T.rects&&(d=T.rects===!0?await o.getElementRects({reference:e,floating:t,strategy:i}):T.rects),{x:f,y:h}=K2(d,y,u)),w=-1)}return{x:f,y:h,placement:y,strategy:i,middlewareData:_}},Pae=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}=Va(e,t)||{};if(d==null)return{};const h=e3(f),y={x:n,y:r},g=fk(i),_=dk(g),w=await o.getDimensions(d),S=g==="y",x=S?"top":"left",k=S?"bottom":"right",R=S?"clientHeight":"clientWidth",A=s.reference[_]+s.reference[g]-y[g]-s.floating[_],O=y[g]-s.reference[g],T=await(o.getOffsetParent==null?void 0:o.getOffsetParent(d));let M=T?T[R]:0;(!M||!await(o.isElement==null?void 0:o.isElement(T)))&&(M=l.floating[R]||s.floating[_]);const z=A/2-O/2,Y=M/2-w[_]/2-1,U=ec(h[x],Y),G=ec(h[k],Y),I=U,N=M-w[_]-G,L=M/2-w[_]/2+z,B=p1(I,L,N),P=!u.arrow&&vf(i)!=null&&L!==B&&s.reference[_]/2-(L<I?U:G)-w[_]/2<0,D=P?L<I?L-I:L-N:0;return{[g]:y[g]+D,data:{[g]:B,centerOffset:L-B-D,...P&&{alignmentOffset:D}},reset:P}}}),Iae=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:y,fallbackStrategy:g="bestFit",fallbackAxisSideDirection:_="none",flipAlignment:w=!0,...S}=Va(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const x=Ya(i),k=ra(l),R=Ya(l)===l,A=await(u.isRTL==null?void 0:u.isRTL(d.floating)),O=y||(R||!w?[jy(l)]:Sae(l)),T=_!=="none";!y&&T&&O.push(...Tae(l,w,_,A));const M=[l,...O],z=await u.detectOverflow(t,S),Y=[];let U=((r=s.flip)==null?void 0:r.overflows)||[];if(f&&Y.push(z[x]),h){const L=xae(i,o,A);Y.push(z[L[0]],z[L[1]])}if(U=[...U,{placement:i,overflows:Y}],!Y.every(L=>L<=0)){var G,I;const L=(((G=s.flip)==null?void 0:G.index)||0)+1,B=M[L];if(B&&(!(h==="alignment"?k!==ra(B):!1)||U.every(F=>ra(F.placement)===k?F.overflows[0]>0:!0)))return{data:{index:L,overflows:U},reset:{placement:B}};let P=(I=U.filter(D=>D.overflows[0]<=0).sort((D,F)=>D.overflows[1]-F.overflows[1])[0])==null?void 0:I.placement;if(!P)switch(g){case"bestFit":{var N;const D=(N=U.filter(F=>{if(T){const q=ra(F.placement);return q===k||q==="y"}return!0}).map(F=>[F.placement,F.overflows.filter(q=>q>0).reduce((q,j)=>q+j,0)]).sort((F,q)=>F[1]-q[1])[0])==null?void 0:N[0];D&&(P=D);break}case"initialPlacement":P=l;break}if(i!==P)return{reset:{placement:P}}}return{}}}};function G2(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function X2(e){return _ae.some(t=>e[t]>=0)}const Oae=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n,platform:r}=t,{strategy:i="referenceHidden",...s}=Va(e,t);switch(i){case"referenceHidden":{const o=await r.detectOverflow(t,{...s,elementContext:"reference"}),l=G2(o,n.reference);return{data:{referenceHiddenOffsets:l,referenceHidden:X2(l)}}}case"escaped":{const o=await r.detectOverflow(t,{...s,altBoundary:!0}),l=G2(o,n.floating);return{data:{escapedOffsets:l,escaped:X2(l)}}}default:return{}}}}},t3=new Set(["left","top"]);async function Lae(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=vf(n),u=ra(n)==="y",d=t3.has(o)?-1:1,f=s&&u?-1:1,h=Va(t,e);let{mainAxis:y,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:y*d}:{x:y*d,y:g*f}}const Dae=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 Lae(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}}}}},Bae=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:k,y:R}=x;return{x:k,y:R}}},...d}=Va(e,t),f={x:n,y:r},h=await s.detectOverflow(t,d),y=ra(Ya(i)),g=uk(y);let _=f[g],w=f[y];if(o){const x=g==="y"?"top":"left",k=g==="y"?"bottom":"right",R=_+h[x],A=_-h[k];_=p1(R,_,A)}if(l){const x=y==="y"?"top":"left",k=y==="y"?"bottom":"right",R=w+h[x],A=w-h[k];w=p1(R,w,A)}const S=u.fn({...t,[g]:_,[y]:w});return{...S,data:{x:S.x-n,y:S.y-r,enabled:{[g]:o,[y]:l}}}}}},zae=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}=Va(e,t),f={x:n,y:r},h=ra(i),y=uk(h);let g=f[y],_=f[h];const w=Va(l,t),S=typeof w=="number"?{mainAxis:w,crossAxis:0}:{mainAxis:0,crossAxis:0,...w};if(u){const R=y==="y"?"height":"width",A=s.reference[y]-s.floating[R]+S.mainAxis,O=s.reference[y]+s.reference[R]-S.mainAxis;g<A?g=A:g>O&&(g=O)}if(d){var x,k;const R=y==="y"?"width":"height",A=t3.has(Ya(i)),O=s.reference[h]-s.floating[R]+(A&&((x=o.offset)==null?void 0:x[h])||0)+(A?0:S.crossAxis),T=s.reference[h]+s.reference[R]+(A?0:((k=o.offset)==null?void 0:k[h])||0)-(A?S.crossAxis:0);_<O?_=O:_>T&&(_=T)}return{[y]:g,[h]:_}}}},jae=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}=Va(e,t),f=await o.detectOverflow(t,d),h=Ya(i),y=vf(i),g=ra(i)==="y",{width:_,height:w}=s.floating;let S,x;h==="top"||h==="bottom"?(S=h,x=y===(await(o.isRTL==null?void 0:o.isRTL(l.floating))?"start":"end")?"left":"right"):(x=h,S=y==="end"?"top":"bottom");const k=w-f.top-f.bottom,R=_-f.left-f.right,A=ec(w-f[S],k),O=ec(_-f[x],R),T=!t.middlewareData.shift;let M=A,z=O;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(z=R),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(M=k),T&&!y){const U=$s(f.left,0),G=$s(f.right,0),I=$s(f.top,0),N=$s(f.bottom,0);g?z=_-2*(U!==0||G!==0?U+G:$s(f.left,f.right)):M=w-2*(I!==0||N!==0?I+N:$s(f.top,f.bottom))}await u({...t,availableWidth:z,availableHeight:M});const Y=await o.getDimensions(l.floating);return _!==Y.width||w!==Y.height?{reset:{rects:!0}}:{}}}};function Ab(){return typeof window<"u"}function yf(e){return n3(e)?(e.nodeName||"").toLowerCase():"#document"}function Ws(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function pa(e){var t;return(t=(n3(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function n3(e){return Ab()?e instanceof Node||e instanceof Ws(e).Node:!1}function Oo(e){return Ab()?e instanceof Element||e instanceof Ws(e).Element:!1}function Za(e){return Ab()?e instanceof HTMLElement||e instanceof Ws(e).HTMLElement:!1}function Z2(e){return!Ab()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Ws(e).ShadowRoot}function ym(e){const{overflow:t,overflowX:n,overflowY:r,display:i}=Lo(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&i!=="inline"&&i!=="contents"}function Fae(e){return/^(table|td|th)$/.test(yf(e))}function Nb(e){try{if(e.matches(":popover-open"))return!0}catch{}try{return e.matches(":modal")}catch{return!1}}const $ae=/transform|translate|scale|rotate|perspective|filter/,Hae=/paint|layout|strict|content/,zc=e=>!!e&&e!=="none";let p0;function hk(e){const t=Oo(e)?Lo(e):e;return zc(t.transform)||zc(t.translate)||zc(t.scale)||zc(t.rotate)||zc(t.perspective)||!pk()&&(zc(t.backdropFilter)||zc(t.filter))||$ae.test(t.willChange||"")||Hae.test(t.contain||"")}function Uae(e){let t=tc(e);for(;Za(t)&&!rf(t);){if(hk(t))return t;if(Nb(t))return null;t=tc(t)}return null}function pk(){return p0==null&&(p0=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),p0}function rf(e){return/^(html|body|#document)$/.test(yf(e))}function Lo(e){return Ws(e).getComputedStyle(e)}function Mb(e){return Oo(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function tc(e){if(yf(e)==="html")return e;const t=e.assignedSlot||e.parentNode||Z2(e)&&e.host||pa(e);return Z2(t)?t.host:t}function r3(e){const t=tc(e);return rf(t)?e.ownerDocument?e.ownerDocument.body:e.body:Za(t)&&ym(t)?t:r3(t)}function Up(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const i=r3(e),s=i===((r=e.ownerDocument)==null?void 0:r.body),o=Ws(i);if(s){const l=g1(o);return t.concat(o,o.visualViewport||[],ym(i)?i:[],l&&n?Up(l):[])}else return t.concat(i,Up(i,[],n))}function g1(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function i3(e){const t=Lo(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const i=Za(e),s=i?e.offsetWidth:n,o=i?e.offsetHeight:r,l=zy(n)!==s||zy(r)!==o;return l&&(n=s,r=o),{width:n,height:r,$:l}}function mk(e){return Oo(e)?e:e.contextElement}function qd(e){const t=mk(e);if(!Za(t))return aa(1);const n=t.getBoundingClientRect(),{width:r,height:i,$:s}=i3(t);let o=(s?zy(n.width):n.width)/r,l=(s?zy(n.height):n.height)/i;return(!o||!Number.isFinite(o))&&(o=1),(!l||!Number.isFinite(l))&&(l=1),{x:o,y:l}}const Wae=aa(0);function s3(e){const t=Ws(e);return!pk()||!t.visualViewport?Wae:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function qae(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==Ws(e)?!1:t}function cu(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const i=e.getBoundingClientRect(),s=mk(e);let o=aa(1);t&&(r?Oo(r)&&(o=qd(r)):o=qd(e));const l=qae(s,n,r)?s3(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 y=Ws(s),g=r&&Oo(r)?Ws(r):r;let _=y,w=g1(_);for(;w&&r&&g!==_;){const S=qd(w),x=w.getBoundingClientRect(),k=Lo(w),R=x.left+(w.clientLeft+parseFloat(k.paddingLeft))*S.x,A=x.top+(w.clientTop+parseFloat(k.paddingTop))*S.y;u*=S.x,d*=S.y,f*=S.x,h*=S.y,u+=R,d+=A,_=Ws(w),w=g1(_)}}return Fy({width:f,height:h,x:u,y:d})}function Pb(e,t){const n=Mb(e).scrollLeft;return t?t.left+n:cu(pa(e)).left+n}function o3(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-Pb(e,n),i=n.top+t.scrollTop;return{x:r,y:i}}function Vae(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e;const s=i==="fixed",o=pa(r),l=t?Nb(t.floating):!1;if(r===o||l&&s)return n;let u={scrollLeft:0,scrollTop:0},d=aa(1);const f=aa(0),h=Za(r);if((h||!h&&!s)&&((yf(r)!=="body"||ym(o))&&(u=Mb(r)),h)){const g=cu(r);d=qd(r),f.x=g.x+r.clientLeft,f.y=g.y+r.clientTop}const y=o&&!h&&!s?o3(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+y.x,y:n.y*d.y-u.scrollTop*d.y+f.y+y.y}}function Yae(e){return Array.from(e.getClientRects())}function Kae(e){const t=pa(e),n=Mb(e),r=e.ownerDocument.body,i=$s(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=$s(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let o=-n.scrollLeft+Pb(e);const l=-n.scrollTop;return Lo(r).direction==="rtl"&&(o+=$s(t.clientWidth,r.clientWidth)-i),{width:i,height:s,x:o,y:l}}const J2=25;function Gae(e,t){const n=Ws(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=pk();(!f||f&&t==="fixed")&&(l=i.offsetLeft,u=i.offsetTop)}const d=Pb(r);if(d<=0){const f=r.ownerDocument,h=f.body,y=getComputedStyle(h),g=f.compatMode==="CSS1Compat"&&parseFloat(y.marginLeft)+parseFloat(y.marginRight)||0,_=Math.abs(r.clientWidth-h.clientWidth-g);_<=J2&&(s-=_)}else d<=J2&&(s+=d);return{width:s,height:o,x:l,y:u}}function Xae(e,t){const n=cu(e,!0,t==="fixed"),r=n.top+e.clientTop,i=n.left+e.clientLeft,s=Za(e)?qd(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 Q2(e,t,n){let r;if(t==="viewport")r=Gae(e,n);else if(t==="document")r=Kae(pa(e));else if(Oo(t))r=Xae(t,n);else{const i=s3(e);r={x:t.x-i.x,y:t.y-i.y,width:t.width,height:t.height}}return Fy(r)}function a3(e,t){const n=tc(e);return n===t||!Oo(n)||rf(n)?!1:Lo(n).position==="fixed"||a3(n,t)}function Zae(e,t){const n=t.get(e);if(n)return n;let r=Up(e,[],!1).filter(l=>Oo(l)&&yf(l)!=="body"),i=null;const s=Lo(e).position==="fixed";let o=s?tc(e):e;for(;Oo(o)&&!rf(o);){const l=Lo(o),u=hk(o);!u&&l.position==="fixed"&&(i=null),(s?!u&&!i:!u&&l.position==="static"&&!!i&&(i.position==="absolute"||i.position==="fixed")||ym(o)&&!u&&a3(e,o))?r=r.filter(f=>f!==o):i=l,o=tc(o)}return t.set(e,r),r}function Jae(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e;const o=[...n==="clippingAncestors"?Nb(t)?[]:Zae(t,this._c):[].concat(n),r],l=Q2(t,o[0],i);let u=l.top,d=l.right,f=l.bottom,h=l.left;for(let y=1;y<o.length;y++){const g=Q2(t,o[y],i);u=$s(g.top,u),d=ec(g.right,d),f=ec(g.bottom,f),h=$s(g.left,h)}return{width:d-h,height:f-u,x:h,y:u}}function Qae(e){const{width:t,height:n}=i3(e);return{width:t,height:n}}function ele(e,t,n){const r=Za(t),i=pa(t),s=n==="fixed",o=cu(e,!0,s,t);let l={scrollLeft:0,scrollTop:0};const u=aa(0);function d(){u.x=Pb(i)}if(r||!r&&!s)if((yf(t)!=="body"||ym(i))&&(l=Mb(t)),r){const g=cu(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?o3(i,l):aa(0),h=o.left+l.scrollLeft-u.x-f.x,y=o.top+l.scrollTop-u.y-f.y;return{x:h,y,width:o.width,height:o.height}}function m0(e){return Lo(e).position==="static"}function eI(e,t){if(!Za(e)||Lo(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return pa(e)===n&&(n=n.ownerDocument.body),n}function l3(e,t){const n=Ws(e);if(Nb(e))return n;if(!Za(e)){let i=tc(e);for(;i&&!rf(i);){if(Oo(i)&&!m0(i))return i;i=tc(i)}return n}let r=eI(e,t);for(;r&&Fae(r)&&m0(r);)r=eI(r,t);return r&&rf(r)&&m0(r)&&!hk(r)?n:r||Uae(e)||n}const tle=async function(e){const t=this.getOffsetParent||l3,n=this.getDimensions,r=await n(e.floating);return{reference:ele(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function nle(e){return Lo(e).direction==="rtl"}const rle={convertOffsetParentRelativeRectToViewportRelativeRect:Vae,getDocumentElement:pa,getClippingRect:Jae,getOffsetParent:l3,getElementRects:tle,getClientRects:Yae,getDimensions:Qae,getScale:qd,isElement:Oo,isRTL:nle};function c3(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function ile(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:y,height:g}=d;if(l||t(),!y||!g)return;const _=vv(h),w=vv(i.clientWidth-(f+y)),S=vv(i.clientHeight-(h+g)),x=vv(f),R={rootMargin:-_+"px "+-w+"px "+-S+"px "+-x+"px",threshold:$s(0,ec(1,u))||1};let A=!0;function O(T){const M=T[0].intersectionRatio;if(M!==u){if(!A)return o();M?o(!1,M):r=setTimeout(()=>{o(!1,1e-7)},1e3)}M===1&&!c3(d,e.getBoundingClientRect())&&o(),A=!1}try{n=new IntersectionObserver(O,{...R,root:i.ownerDocument})}catch{n=new IntersectionObserver(O,R)}n.observe(e)}return o(!0),s}function sle(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=mk(e),f=i||s?[...d?Up(d):[],...t?Up(t):[]]:[];f.forEach(x=>{i&&x.addEventListener("scroll",n,{passive:!0}),s&&x.addEventListener("resize",n)});const h=d&&l?ile(d,n):null;let y=-1,g=null;o&&(g=new ResizeObserver(x=>{let[k]=x;k&&k.target===d&&g&&t&&(g.unobserve(t),cancelAnimationFrame(y),y=requestAnimationFrame(()=>{var R;(R=g)==null||R.observe(t)})),n()}),d&&!u&&g.observe(d),t&&g.observe(t));let _,w=u?cu(e):null;u&&S();function S(){const x=cu(e);w&&!c3(w,x)&&n(),w=x,_=requestAnimationFrame(S)}return n(),()=>{var x;f.forEach(k=>{i&&k.removeEventListener("scroll",n),s&&k.removeEventListener("resize",n)}),h==null||h(),(x=g)==null||x.disconnect(),g=null,u&&cancelAnimationFrame(_)}}const ole=Dae,ale=Bae,lle=Iae,cle=jae,ule=Oae,tI=Pae,dle=zae,fle=(e,t,n)=>{const r=new Map,i={platform:rle,...n},s={...i.platform,_c:r};return Mae(e,t,{...i,platform:s})};var hle=typeof document<"u",ple=function(){},ay=hle?b.useLayoutEffect:ple;function $y(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(!$y(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)&&!$y(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function u3(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function nI(e,t){const n=u3(e);return Math.round(t*n)/n}function g0(e){const t=b.useRef(e);return ay(()=>{t.current=e}),t}function mle(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}),[y,g]=b.useState(r);$y(y,r)||g(r);const[_,w]=b.useState(null),[S,x]=b.useState(null),k=b.useCallback(F=>{F!==T.current&&(T.current=F,w(F))},[]),R=b.useCallback(F=>{F!==M.current&&(M.current=F,x(F))},[]),A=s||_,O=o||S,T=b.useRef(null),M=b.useRef(null),z=b.useRef(f),Y=u!=null,U=g0(u),G=g0(i),I=g0(d),N=b.useCallback(()=>{if(!T.current||!M.current)return;const F={placement:t,strategy:n,middleware:y};G.current&&(F.platform=G.current),fle(T.current,M.current,F).then(q=>{const j={...q,isPositioned:I.current!==!1};L.current&&!$y(z.current,j)&&(z.current=j,xu.flushSync(()=>{h(j)}))})},[y,t,n,G,I]);ay(()=>{d===!1&&z.current.isPositioned&&(z.current.isPositioned=!1,h(F=>({...F,isPositioned:!1})))},[d]);const L=b.useRef(!1);ay(()=>(L.current=!0,()=>{L.current=!1}),[]),ay(()=>{if(A&&(T.current=A),O&&(M.current=O),A&&O){if(U.current)return U.current(A,O,N);N()}},[A,O,N,U,Y]);const B=b.useMemo(()=>({reference:T,floating:M,setReference:k,setFloating:R}),[k,R]),P=b.useMemo(()=>({reference:A,floating:O}),[A,O]),D=b.useMemo(()=>{const F={position:n,left:0,top:0};if(!P.floating)return F;const q=nI(P.floating,f.x),j=nI(P.floating,f.y);return l?{...F,transform:"translate("+q+"px, "+j+"px)",...u3(P.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:q,top:j}},[n,l,P.floating,f.x,f.y]);return b.useMemo(()=>({...f,update:N,refs:B,elements:P,floatingStyles:D}),[f,N,B,P,D])}const gle=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?tI({element:r.current,padding:i}).fn(n):{}:r?tI({element:r,padding:i}).fn(n):{}}}},vle=(e,t)=>{const n=ole(e);return{name:n.name,fn:n.fn,options:[e,t]}},yle=(e,t)=>{const n=ale(e);return{name:n.name,fn:n.fn,options:[e,t]}},ble=(e,t)=>({fn:dle(e).fn,options:[e,t]}),_le=(e,t)=>{const n=lle(e);return{name:n.name,fn:n.fn,options:[e,t]}},wle=(e,t)=>{const n=cle(e);return{name:n.name,fn:n.fn,options:[e,t]}},xle=(e,t)=>{const n=ule(e);return{name:n.name,fn:n.fn,options:[e,t]}},Sle=(e,t)=>{const n=gle(e);return{name:n.name,fn:n.fn,options:[e,t]}};var Ele="Arrow",d3=b.forwardRef((e,t)=>{const{children:n,width:r=10,height:i=5,...s}=e;return m.jsx(yn.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"})})});d3.displayName=Ele;var Cle=d3,gk="Popper",[f3,cc]=Xa(gk),[kle,h3]=f3(gk),p3=e=>{const{__scopePopper:t,children:n}=e,[r,i]=b.useState(null);return m.jsx(kle,{scope:t,anchor:r,onAnchorChange:i,children:n})};p3.displayName=gk;var m3="PopperAnchor",g3=b.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...i}=e,s=h3(m3,n),o=b.useRef(null),l=cr(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(yn.div,{...i,ref:l})});g3.displayName=m3;var vk="PopperContent",[Tle,Rle]=f3(vk),v3=b.forwardRef((e,t)=>{var X,ae,ne,ce,_e,xe;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:y=!1,updatePositionStrategy:g="optimized",onPlaced:_,...w}=e,S=h3(vk,n),[x,k]=b.useState(null),R=cr(t,We=>k(We)),[A,O]=b.useState(null),T=bae(A),M=(T==null?void 0:T.width)??0,z=(T==null?void 0:T.height)??0,Y=r+(s!=="center"?"-"+s:""),U=typeof f=="number"?f:{top:0,right:0,bottom:0,left:0,...f},G=Array.isArray(d)?d:[d],I=G.length>0,N={padding:U,boundary:G.filter(Nle),altBoundary:I},{refs:L,floatingStyles:B,placement:P,isPositioned:D,middlewareData:F}=mle({strategy:"fixed",placement:Y,whileElementsMounted:(...We)=>sle(...We,{animationFrame:g==="always"}),elements:{reference:S.anchor},middleware:[vle({mainAxis:i+z,alignmentAxis:o}),u&&yle({mainAxis:!0,crossAxis:!1,limiter:h==="partial"?ble():void 0,...N}),u&&_le({...N}),wle({...N,apply:({elements:We,rects:De,availableWidth:Pt,availableHeight:tt})=>{const{width:lt,height:$e}=De.reference,Fe=We.floating.style;Fe.setProperty("--radix-popper-available-width",`${Pt}px`),Fe.setProperty("--radix-popper-available-height",`${tt}px`),Fe.setProperty("--radix-popper-anchor-width",`${lt}px`),Fe.setProperty("--radix-popper-anchor-height",`${$e}px`)}}),A&&Sle({element:A,padding:l}),Mle({arrowWidth:M,arrowHeight:z}),y&&xle({strategy:"referenceHidden",...N})]}),[q,j]=_3(P),V=Io(_);Ji(()=>{D&&(V==null||V())},[D,V]);const K=(X=F.arrow)==null?void 0:X.x,$=(ae=F.arrow)==null?void 0:ae.y,te=((ne=F.arrow)==null?void 0:ne.centerOffset)!==0,[re,ee]=b.useState();return Ji(()=>{x&&ee(window.getComputedStyle(x).zIndex)},[x]),m.jsx("div",{ref:L.setFloating,"data-radix-popper-content-wrapper":"",style:{...B,transform:D?B.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:re,"--radix-popper-transform-origin":[(ce=F.transformOrigin)==null?void 0:ce.x,(_e=F.transformOrigin)==null?void 0:_e.y].join(" "),...((xe=F.hide)==null?void 0:xe.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:m.jsx(Tle,{scope:n,placedSide:q,onArrowChange:O,arrowX:K,arrowY:$,shouldHideArrow:te,children:m.jsx(yn.div,{"data-side":q,"data-align":j,...w,ref:R,style:{...w.style,animation:D?void 0:"none"}})})})});v3.displayName=vk;var y3="PopperArrow",Ale={top:"bottom",right:"left",bottom:"top",left:"right"},b3=b.forwardRef(function(t,n){const{__scopePopper:r,...i}=t,s=Rle(y3,r),o=Ale[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(Cle,{...i,ref:n,style:{...i.style,display:"block"}})})});b3.displayName=y3;function Nle(e){return e!==null}var Mle=e=>({name:"transformOrigin",options:e,fn(t){var S,x,k;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]=_3(n),h={start:"0%",center:"50%",end:"100%"}[f],y=(((x=i.arrow)==null?void 0:x.x)??0)+l/2,g=(((k=i.arrow)==null?void 0:k.y)??0)+u/2;let _="",w="";return d==="bottom"?(_=o?h:`${y}px`,w=`${-u}px`):d==="top"?(_=o?h:`${y}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 _3(e){const[t,n="center"]=e.split("-");return[t,n]}var bm=p3,_m=g3,Ib=v3,Ob=b3,v0="rovingFocusGroup.onEntryFocus",Ple={bubbles:!1,cancelable:!0},wm="RovingFocusGroup",[v1,w3,Ile]=tk(wm),[Ole,x3]=Xa(wm,[Ile]),[Lle,Dle]=Ole(wm),S3=b.forwardRef((e,t)=>m.jsx(v1.Provider,{scope:e.__scopeRovingFocusGroup,children:m.jsx(v1.Slot,{scope:e.__scopeRovingFocusGroup,children:m.jsx(Ble,{...e,ref:t})})}));S3.displayName=wm;var Ble=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,y=b.useRef(null),g=cr(t,y),_=nk(s),[w,S]=Ql({prop:o,defaultProp:l??null,onChange:u,caller:wm}),[x,k]=b.useState(!1),R=Io(d),A=w3(n),O=b.useRef(!1),[T,M]=b.useState(0);return b.useEffect(()=>{const z=y.current;if(z)return z.addEventListener(v0,R),()=>z.removeEventListener(v0,R)},[R]),m.jsx(Lle,{scope:n,orientation:r,dir:_,loop:i,currentTabStopId:w,onItemFocus:b.useCallback(z=>S(z),[S]),onItemShiftTab:b.useCallback(()=>k(!0),[]),onFocusableItemAdd:b.useCallback(()=>M(z=>z+1),[]),onFocusableItemRemove:b.useCallback(()=>M(z=>z-1),[]),children:m.jsx(yn.div,{tabIndex:x||T===0?-1:0,"data-orientation":r,...h,ref:g,style:{outline:"none",...e.style},onMouseDown:Wt(e.onMouseDown,()=>{O.current=!0}),onFocus:Wt(e.onFocus,z=>{const Y=!O.current;if(z.target===z.currentTarget&&Y&&!x){const U=new CustomEvent(v0,Ple);if(z.currentTarget.dispatchEvent(U),!U.defaultPrevented){const G=A().filter(P=>P.focusable),I=G.find(P=>P.active),N=G.find(P=>P.id===w),B=[I,N,...G].filter(Boolean).map(P=>P.ref.current);k3(B,f)}}O.current=!1}),onBlur:Wt(e.onBlur,()=>k(!1))})})}),E3="RovingFocusGroupItem",C3=b.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:i=!1,tabStopId:s,children:o,...l}=e,u=bi(),d=s||u,f=Dle(E3,n),h=f.currentTabStopId===d,y=w3(n),{onFocusableItemAdd:g,onFocusableItemRemove:_,currentTabStopId:w}=f;return b.useEffect(()=>{if(r)return g(),()=>_()},[r,g,_]),m.jsx(v1.ItemSlot,{scope:n,id:d,focusable:r,active:i,children:m.jsx(yn.span,{tabIndex:h?0:-1,"data-orientation":f.orientation,...l,ref:t,onMouseDown:Wt(e.onMouseDown,S=>{r?f.onItemFocus(d):S.preventDefault()}),onFocus:Wt(e.onFocus,()=>f.onItemFocus(d)),onKeyDown:Wt(e.onKeyDown,S=>{if(S.key==="Tab"&&S.shiftKey){f.onItemShiftTab();return}if(S.target!==S.currentTarget)return;const x=Fle(S,f.orientation,f.dir);if(x!==void 0){if(S.metaKey||S.ctrlKey||S.altKey||S.shiftKey)return;S.preventDefault();let R=y().filter(A=>A.focusable).map(A=>A.ref.current);if(x==="last")R.reverse();else if(x==="prev"||x==="next"){x==="prev"&&R.reverse();const A=R.indexOf(S.currentTarget);R=f.loop?$le(R,A+1):R.slice(A+1)}setTimeout(()=>k3(R))}}),children:typeof o=="function"?o({isCurrentTabStop:h,hasTabStop:w!=null}):o})})});C3.displayName=E3;var zle={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function jle(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function Fle(e,t,n){const r=jle(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return zle[r]}function k3(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function $le(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Hle=S3,Ule=C3,y1=["Enter"," "],Wle=["ArrowDown","PageUp","Home"],T3=["ArrowUp","PageDown","End"],qle=[...Wle,...T3],Vle={ltr:[...y1,"ArrowRight"],rtl:[...y1,"ArrowLeft"]},Yle={ltr:["ArrowLeft"],rtl:["ArrowRight"]},xm="Menu",[Wp,Kle,Gle]=tk(xm),[Su,R3]=Xa(xm,[Gle,cc,x3]),Sm=cc(),A3=x3(),[N3,uc]=Su(xm),[Xle,Em]=Su(xm),M3=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:i,onOpenChange:s,modal:o=!0}=e,l=Sm(t),[u,d]=b.useState(null),f=b.useRef(!1),h=Io(s),y=nk(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(bm,{...l,children:m.jsx(N3,{scope:t,open:n,onOpenChange:h,content:u,onContentChange:d,children:m.jsx(Xle,{scope:t,onClose:b.useCallback(()=>h(!1),[h]),isUsingKeyboardRef:f,dir:y,modal:o,children:r})})})};M3.displayName=xm;var Zle="MenuAnchor",yk=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=Sm(n);return m.jsx(_m,{...i,...r,ref:t})});yk.displayName=Zle;var bk="MenuPortal",[Jle,P3]=Su(bk,{forceMount:void 0}),I3=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:i}=e,s=uc(bk,t);return m.jsx(Jle,{scope:t,forceMount:n,children:m.jsx(wo,{present:n||s.open,children:m.jsx(gf,{asChild:!0,container:i,children:r})})})};I3.displayName=bk;var mo="MenuContent",[Qle,_k]=Su(mo),O3=b.forwardRef((e,t)=>{const n=P3(mo,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=uc(mo,e.__scopeMenu),o=Em(mo,e.__scopeMenu);return m.jsx(Wp.Provider,{scope:e.__scopeMenu,children:m.jsx(wo,{present:r||s.open,children:m.jsx(Wp.Slot,{scope:e.__scopeMenu,children:o.modal?m.jsx(ece,{...i,ref:t}):m.jsx(tce,{...i,ref:t})})})})}),ece=b.forwardRef((e,t)=>{const n=uc(mo,e.__scopeMenu),r=b.useRef(null),i=cr(t,r);return b.useEffect(()=>{const s=r.current;if(s)return kb(s)},[]),m.jsx(wk,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:Wt(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),tce=b.forwardRef((e,t)=>{const n=uc(mo,e.__scopeMenu);return m.jsx(wk,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),nce=Jl("MenuContent.ScrollLock"),wk=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:y,onDismiss:g,disableOutsideScroll:_,...w}=e,S=uc(mo,n),x=Em(mo,n),k=Sm(n),R=A3(n),A=Kle(n),[O,T]=b.useState(null),M=b.useRef(null),z=cr(t,M,S.onContentChange),Y=b.useRef(0),U=b.useRef(""),G=b.useRef(0),I=b.useRef(null),N=b.useRef("right"),L=b.useRef(0),B=_?vm:b.Fragment,P=_?{as:nce,allowPinchZoom:!0}:void 0,D=q=>{var X,ae;const j=U.current+q,V=A().filter(ne=>!ne.disabled),K=document.activeElement,$=(X=V.find(ne=>ne.ref.current===K))==null?void 0:X.textValue,te=V.map(ne=>ne.textValue),re=pce(te,j,$),ee=(ae=V.find(ne=>ne.textValue===re))==null?void 0:ae.ref.current;(function ne(ce){U.current=ce,window.clearTimeout(Y.current),ce!==""&&(Y.current=window.setTimeout(()=>ne(""),1e3))})(j),ee&&setTimeout(()=>ee.focus())};b.useEffect(()=>()=>window.clearTimeout(Y.current),[]),Eb();const F=b.useCallback(q=>{var V,K;return N.current===((V=I.current)==null?void 0:V.side)&&gce(q,(K=I.current)==null?void 0:K.area)},[]);return m.jsx(Qle,{scope:n,searchRef:U,onItemEnter:b.useCallback(q=>{F(q)&&q.preventDefault()},[F]),onItemLeave:b.useCallback(q=>{var j;F(q)||((j=M.current)==null||j.focus(),T(null))},[F]),onTriggerLeave:b.useCallback(q=>{F(q)&&q.preventDefault()},[F]),pointerGraceTimerRef:G,onPointerGraceIntentChange:b.useCallback(q=>{I.current=q},[]),children:m.jsx(B,{...P,children:m.jsx(gm,{asChild:!0,trapped:i,onMountAutoFocus:Wt(s,q=>{var j;q.preventDefault(),(j=M.current)==null||j.focus({preventScroll:!0})}),onUnmountAutoFocus:o,children:m.jsx(mf,{asChild:!0,disableOutsidePointerEvents:l,onEscapeKeyDown:d,onPointerDownOutside:f,onFocusOutside:h,onInteractOutside:y,onDismiss:g,children:m.jsx(Hle,{asChild:!0,...R,dir:x.dir,orientation:"vertical",loop:r,currentTabStopId:O,onCurrentTabStopIdChange:T,onEntryFocus:Wt(u,q=>{x.isUsingKeyboardRef.current||q.preventDefault()}),preventScrollOnEntryFocus:!0,children:m.jsx(Ib,{role:"menu","aria-orientation":"vertical","data-state":Z3(S.open),"data-radix-menu-content":"",dir:x.dir,...k,...w,ref:z,style:{outline:"none",...w.style},onKeyDown:Wt(w.onKeyDown,q=>{const V=q.target.closest("[data-radix-menu-content]")===q.currentTarget,K=q.ctrlKey||q.altKey||q.metaKey,$=q.key.length===1;V&&(q.key==="Tab"&&q.preventDefault(),!K&&$&&D(q.key));const te=M.current;if(q.target!==te||!qle.includes(q.key))return;q.preventDefault();const ee=A().filter(X=>!X.disabled).map(X=>X.ref.current);T3.includes(q.key)&&ee.reverse(),fce(ee)}),onBlur:Wt(e.onBlur,q=>{q.currentTarget.contains(q.target)||(window.clearTimeout(Y.current),U.current="")}),onPointerMove:Wt(e.onPointerMove,qp(q=>{const j=q.target,V=L.current!==q.clientX;if(q.currentTarget.contains(j)&&V){const K=q.clientX>L.current?"right":"left";N.current=K,L.current=q.clientX}}))})})})})})})});O3.displayName=mo;var rce="MenuGroup",xk=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return m.jsx(yn.div,{role:"group",...r,ref:t})});xk.displayName=rce;var ice="MenuLabel",L3=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return m.jsx(yn.div,{...r,ref:t})});L3.displayName=ice;var Hy="MenuItem",rI="menu.itemSelect",Lb=b.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...i}=e,s=b.useRef(null),o=Em(Hy,e.__scopeMenu),l=_k(Hy,e.__scopeMenu),u=cr(t,s),d=b.useRef(!1),f=()=>{const h=s.current;if(!n&&h){const y=new CustomEvent(rI,{bubbles:!0,cancelable:!0});h.addEventListener(rI,g=>r==null?void 0:r(g),{once:!0}),w5(h,y),y.defaultPrevented?d.current=!1:o.onClose()}};return m.jsx(D3,{...i,ref:u,disabled:n,onClick:Wt(e.onClick,f),onPointerDown:h=>{var y;(y=e.onPointerDown)==null||y.call(e,h),d.current=!0},onPointerUp:Wt(e.onPointerUp,h=>{var y;d.current||(y=h.currentTarget)==null||y.click()}),onKeyDown:Wt(e.onKeyDown,h=>{const y=l.searchRef.current!=="";n||y&&h.key===" "||y1.includes(h.key)&&(h.currentTarget.click(),h.preventDefault())})})});Lb.displayName=Hy;var D3=b.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:i,...s}=e,o=_k(Hy,n),l=A3(n),u=b.useRef(null),d=cr(t,u),[f,h]=b.useState(!1),[y,g]=b.useState("");return b.useEffect(()=>{const _=u.current;_&&g((_.textContent??"").trim())},[s.children]),m.jsx(Wp.ItemSlot,{scope:n,disabled:r,textValue:i??y,children:m.jsx(Ule,{asChild:!0,...l,focusable:!r,children:m.jsx(yn.div,{role:"menuitem","data-highlighted":f?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:d,onPointerMove:Wt(e.onPointerMove,qp(_=>{r?o.onItemLeave(_):(o.onItemEnter(_),_.defaultPrevented||_.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:Wt(e.onPointerLeave,qp(_=>o.onItemLeave(_))),onFocus:Wt(e.onFocus,()=>h(!0)),onBlur:Wt(e.onBlur,()=>h(!1))})})})}),sce="MenuCheckboxItem",B3=b.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...i}=e;return m.jsx(H3,{scope:e.__scopeMenu,checked:n,children:m.jsx(Lb,{role:"menuitemcheckbox","aria-checked":Uy(n)?"mixed":n,...i,ref:t,"data-state":Ck(n),onSelect:Wt(i.onSelect,()=>r==null?void 0:r(Uy(n)?!0:!n),{checkForDefaultPrevented:!1})})})});B3.displayName=sce;var z3="MenuRadioGroup",[oce,ace]=Su(z3,{value:void 0,onValueChange:()=>{}}),j3=b.forwardRef((e,t)=>{const{value:n,onValueChange:r,...i}=e,s=Io(r);return m.jsx(oce,{scope:e.__scopeMenu,value:n,onValueChange:s,children:m.jsx(xk,{...i,ref:t})})});j3.displayName=z3;var F3="MenuRadioItem",$3=b.forwardRef((e,t)=>{const{value:n,...r}=e,i=ace(F3,e.__scopeMenu),s=n===i.value;return m.jsx(H3,{scope:e.__scopeMenu,checked:s,children:m.jsx(Lb,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":Ck(s),onSelect:Wt(r.onSelect,()=>{var o;return(o=i.onValueChange)==null?void 0:o.call(i,n)},{checkForDefaultPrevented:!1})})})});$3.displayName=F3;var Sk="MenuItemIndicator",[H3,lce]=Su(Sk,{checked:!1}),U3=b.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...i}=e,s=lce(Sk,n);return m.jsx(wo,{present:r||Uy(s.checked)||s.checked===!0,children:m.jsx(yn.span,{...i,ref:t,"data-state":Ck(s.checked)})})});U3.displayName=Sk;var cce="MenuSeparator",W3=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return m.jsx(yn.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});W3.displayName=cce;var uce="MenuArrow",q3=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=Sm(n);return m.jsx(Ob,{...i,...r,ref:t})});q3.displayName=uce;var Ek="MenuSub",[dce,V3]=Su(Ek),Y3=e=>{const{__scopeMenu:t,children:n,open:r=!1,onOpenChange:i}=e,s=uc(Ek,t),o=Sm(t),[l,u]=b.useState(null),[d,f]=b.useState(null),h=Io(i);return b.useEffect(()=>(s.open===!1&&h(!1),()=>h(!1)),[s.open,h]),m.jsx(bm,{...o,children:m.jsx(N3,{scope:t,open:r,onOpenChange:h,content:d,onContentChange:f,children:m.jsx(dce,{scope:t,contentId:bi(),triggerId:bi(),trigger:l,onTriggerChange:u,children:n})})})};Y3.displayName=Ek;var op="MenuSubTrigger",K3=b.forwardRef((e,t)=>{const n=uc(op,e.__scopeMenu),r=Em(op,e.__scopeMenu),i=V3(op,e.__scopeMenu),s=_k(op,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(yk,{asChild:!0,...d,children:m.jsx(D3,{id:i.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":i.contentId,"data-state":Z3(n.open),...e,ref:qa(t,i.onTriggerChange),onClick:h=>{var y;(y=e.onClick)==null||y.call(e,h),!(e.disabled||h.defaultPrevented)&&(h.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:Wt(e.onPointerMove,qp(h=>{s.onItemEnter(h),!h.defaultPrevented&&!e.disabled&&!n.open&&!o.current&&(s.onPointerGraceIntentChange(null),o.current=window.setTimeout(()=>{n.onOpenChange(!0),f()},100))})),onPointerLeave:Wt(e.onPointerLeave,qp(h=>{var g,_;f();const y=(g=n.content)==null?void 0:g.getBoundingClientRect();if(y){const w=(_=n.content)==null?void 0:_.dataset.side,S=w==="right",x=S?-5:5,k=y[S?"left":"right"],R=y[S?"right":"left"];s.onPointerGraceIntentChange({area:[{x:h.clientX+x,y:h.clientY},{x:k,y:y.top},{x:R,y:y.top},{x:R,y:y.bottom},{x:k,y:y.bottom}],side:w}),window.clearTimeout(l.current),l.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(h),h.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:Wt(e.onKeyDown,h=>{var g;const y=s.searchRef.current!=="";e.disabled||y&&h.key===" "||Vle[r.dir].includes(h.key)&&(n.onOpenChange(!0),(g=n.content)==null||g.focus(),h.preventDefault())})})})});K3.displayName=op;var G3="MenuSubContent",X3=b.forwardRef((e,t)=>{const n=P3(mo,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=uc(mo,e.__scopeMenu),o=Em(mo,e.__scopeMenu),l=V3(G3,e.__scopeMenu),u=b.useRef(null),d=cr(t,u);return m.jsx(Wp.Provider,{scope:e.__scopeMenu,children:m.jsx(wo,{present:r||s.open,children:m.jsx(Wp.Slot,{scope:e.__scopeMenu,children:m.jsx(wk,{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:Wt(e.onFocusOutside,f=>{f.target!==l.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:Wt(e.onEscapeKeyDown,f=>{o.onClose(),f.preventDefault()}),onKeyDown:Wt(e.onKeyDown,f=>{var g;const h=f.currentTarget.contains(f.target),y=Yle[o.dir].includes(f.key);h&&y&&(s.onOpenChange(!1),(g=l.trigger)==null||g.focus(),f.preventDefault())})})})})})});X3.displayName=G3;function Z3(e){return e?"open":"closed"}function Uy(e){return e==="indeterminate"}function Ck(e){return Uy(e)?"indeterminate":e?"checked":"unchecked"}function fce(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function hce(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function pce(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=hce(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 mce(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,y=u.y;f>r!=y>r&&n<(h-d)*(r-f)/(y-f)+d&&(i=!i)}return i}function gce(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return mce(n,t)}function qp(e){return t=>t.pointerType==="mouse"?e(t):void 0}var vce=M3,yce=yk,bce=I3,_ce=O3,wce=xk,xce=L3,Sce=Lb,Ece=B3,Cce=j3,kce=$3,Tce=U3,Rce=W3,Ace=q3,Nce=Y3,Mce=K3,Pce=X3,Db="DropdownMenu",[Ice]=Xa(Db,[R3]),Qi=R3(),[Oce,J3]=Ice(Db),Q3=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:i,defaultOpen:s,onOpenChange:o,modal:l=!0}=e,u=Qi(t),d=b.useRef(null),[f,h]=Ql({prop:i,defaultProp:s??!1,onChange:o,caller:Db});return m.jsx(Oce,{scope:t,triggerId:bi(),triggerRef:d,contentId:bi(),open:f,onOpenChange:h,onOpenToggle:b.useCallback(()=>h(y=>!y),[h]),modal:l,children:m.jsx(vce,{...u,open:f,onOpenChange:h,dir:r,modal:l,children:n})})};Q3.displayName=Db;var e4="DropdownMenuTrigger",t4=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...i}=e,s=J3(e4,n),o=Qi(n);return m.jsx(yce,{asChild:!0,...o,children:m.jsx(yn.button,{type:"button",id:s.triggerId,"aria-haspopup":"menu","aria-expanded":s.open,"aria-controls":s.open?s.contentId:void 0,"data-state":s.open?"open":"closed","data-disabled":r?"":void 0,disabled:r,...i,ref:qa(t,s.triggerRef),onPointerDown:Wt(e.onPointerDown,l=>{!r&&l.button===0&&l.ctrlKey===!1&&(s.onOpenToggle(),s.open||l.preventDefault())}),onKeyDown:Wt(e.onKeyDown,l=>{r||(["Enter"," "].includes(l.key)&&s.onOpenToggle(),l.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(l.key)&&l.preventDefault())})})})});t4.displayName=e4;var Lce="DropdownMenuPortal",n4=e=>{const{__scopeDropdownMenu:t,...n}=e,r=Qi(t);return m.jsx(bce,{...r,...n})};n4.displayName=Lce;var r4="DropdownMenuContent",i4=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=J3(r4,n),s=Qi(n),o=b.useRef(!1);return m.jsx(_ce,{id:i.contentId,"aria-labelledby":i.triggerId,...s,...r,ref:t,onCloseAutoFocus:Wt(e.onCloseAutoFocus,l=>{var u;o.current||(u=i.triggerRef.current)==null||u.focus(),o.current=!1,l.preventDefault()}),onInteractOutside:Wt(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)"}})});i4.displayName=r4;var Dce="DropdownMenuGroup",Bce=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Qi(n);return m.jsx(wce,{...i,...r,ref:t})});Bce.displayName=Dce;var zce="DropdownMenuLabel",s4=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Qi(n);return m.jsx(xce,{...i,...r,ref:t})});s4.displayName=zce;var jce="DropdownMenuItem",o4=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Qi(n);return m.jsx(Sce,{...i,...r,ref:t})});o4.displayName=jce;var Fce="DropdownMenuCheckboxItem",a4=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Qi(n);return m.jsx(Ece,{...i,...r,ref:t})});a4.displayName=Fce;var $ce="DropdownMenuRadioGroup",Hce=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Qi(n);return m.jsx(Cce,{...i,...r,ref:t})});Hce.displayName=$ce;var Uce="DropdownMenuRadioItem",Wce=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Qi(n);return m.jsx(kce,{...i,...r,ref:t})});Wce.displayName=Uce;var qce="DropdownMenuItemIndicator",l4=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Qi(n);return m.jsx(Tce,{...i,...r,ref:t})});l4.displayName=qce;var Vce="DropdownMenuSeparator",c4=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Qi(n);return m.jsx(Rce,{...i,...r,ref:t})});c4.displayName=Vce;var Yce="DropdownMenuArrow",Kce=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Qi(n);return m.jsx(Ace,{...i,...r,ref:t})});Kce.displayName=Yce;var Gce=e=>{const{__scopeDropdownMenu:t,children:n,open:r,onOpenChange:i,defaultOpen:s}=e,o=Qi(t),[l,u]=Ql({prop:r,defaultProp:s??!1,onChange:i,caller:"DropdownMenuSub"});return m.jsx(Nce,{...o,open:l,onOpenChange:u,children:n})},Xce="DropdownMenuSubTrigger",u4=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Qi(n);return m.jsx(Mce,{...i,...r,ref:t})});u4.displayName=Xce;var Zce="DropdownMenuSubContent",d4=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Qi(n);return m.jsx(Pce,{...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)"}})});d4.displayName=Zce;var Jce=Q3,Qce=t4,f4=n4,eue=i4,tue=s4,nue=o4,rue=a4,iue=l4,sue=c4,oue=Gce,aue=u4,lue=d4;function iI(e,[t,n]){return Math.min(n,Math.max(t,e))}var Bb="Popover",[h4]=Xa(Bb,[cc]),Cm=cc(),[cue,dc]=h4(Bb),p4=e=>{const{__scopePopover:t,children:n,open:r,defaultOpen:i,onOpenChange:s,modal:o=!1}=e,l=Cm(t),u=b.useRef(null),[d,f]=b.useState(!1),[h,y]=Ql({prop:r,defaultProp:i??!1,onChange:s,caller:Bb});return m.jsx(bm,{...l,children:m.jsx(cue,{scope:t,contentId:bi(),triggerRef:u,open:h,onOpenChange:y,onOpenToggle:b.useCallback(()=>y(g=>!g),[y]),hasCustomAnchor:d,onCustomAnchorAdd:b.useCallback(()=>f(!0),[]),onCustomAnchorRemove:b.useCallback(()=>f(!1),[]),modal:o,children:n})})};p4.displayName=Bb;var m4="PopoverAnchor",uue=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=dc(m4,n),s=Cm(n),{onCustomAnchorAdd:o,onCustomAnchorRemove:l}=i;return b.useEffect(()=>(o(),()=>l()),[o,l]),m.jsx(_m,{...s,...r,ref:t})});uue.displayName=m4;var g4="PopoverTrigger",v4=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=dc(g4,n),s=Cm(n),o=cr(t,i.triggerRef),l=m.jsx(yn.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.contentId,"data-state":x4(i.open),...r,ref:o,onClick:Wt(e.onClick,i.onOpenToggle)});return i.hasCustomAnchor?l:m.jsx(_m,{asChild:!0,...s,children:l})});v4.displayName=g4;var kk="PopoverPortal",[due,fue]=h4(kk,{forceMount:void 0}),y4=e=>{const{__scopePopover:t,forceMount:n,children:r,container:i}=e,s=dc(kk,t);return m.jsx(due,{scope:t,forceMount:n,children:m.jsx(wo,{present:n||s.open,children:m.jsx(gf,{asChild:!0,container:i,children:r})})})};y4.displayName=kk;var sf="PopoverContent",b4=b.forwardRef((e,t)=>{const n=fue(sf,e.__scopePopover),{forceMount:r=n.forceMount,...i}=e,s=dc(sf,e.__scopePopover);return m.jsx(wo,{present:r||s.open,children:s.modal?m.jsx(pue,{...i,ref:t}):m.jsx(mue,{...i,ref:t})})});b4.displayName=sf;var hue=Jl("PopoverContent.RemoveScroll"),pue=b.forwardRef((e,t)=>{const n=dc(sf,e.__scopePopover),r=b.useRef(null),i=cr(t,r),s=b.useRef(!1);return b.useEffect(()=>{const o=r.current;if(o)return kb(o)},[]),m.jsx(vm,{as:hue,allowPinchZoom:!0,children:m.jsx(_4,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Wt(e.onCloseAutoFocus,o=>{var l;o.preventDefault(),s.current||(l=n.triggerRef.current)==null||l.focus()}),onPointerDownOutside:Wt(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:Wt(e.onFocusOutside,o=>o.preventDefault(),{checkForDefaultPrevented:!1})})})}),mue=b.forwardRef((e,t)=>{const n=dc(sf,e.__scopePopover),r=b.useRef(!1),i=b.useRef(!1);return m.jsx(_4,{...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()}})}),_4=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,y=dc(sf,n),g=Cm(n);return Eb(),m.jsx(gm,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:s,children:m.jsx(mf,{asChild:!0,disableOutsidePointerEvents:o,onInteractOutside:f,onEscapeKeyDown:l,onPointerDownOutside:u,onFocusOutside:d,onDismiss:()=>y.onOpenChange(!1),children:m.jsx(Ib,{"data-state":x4(y.open),role:"dialog",id:y.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)"}})})})}),w4="PopoverClose",gue=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=dc(w4,n);return m.jsx(yn.button,{type:"button",...r,ref:t,onClick:Wt(e.onClick,()=>i.onOpenChange(!1))})});gue.displayName=w4;var vue="PopoverArrow",yue=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=Cm(n);return m.jsx(Ob,{...i,...r,ref:t})});yue.displayName=vue;function x4(e){return e?"open":"closed"}var bue=p4,_ue=v4,wue=y4,xue=b4,Sue=[" ","Enter","ArrowUp","ArrowDown"],Eue=[" ","Enter"],uu="Select",[zb,jb,Cue]=tk(uu),[bf]=Xa(uu,[Cue,cc]),Fb=cc(),[kue,fc]=bf(uu),[Tue,Rue]=bf(uu),S4=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:y,required:g,form:_}=e,w=Fb(t),[S,x]=b.useState(null),[k,R]=b.useState(null),[A,O]=b.useState(!1),T=nk(d),[M,z]=Ql({prop:r,defaultProp:i??!1,onChange:s,caller:uu}),[Y,U]=Ql({prop:o,defaultProp:l,onChange:u,caller:uu}),G=b.useRef(null),I=S?_||!!S.closest("form"):!0,[N,L]=b.useState(new Set),B=Array.from(N).map(P=>P.props.value).join(";");return m.jsx(bm,{...w,children:m.jsxs(kue,{required:g,scope:t,trigger:S,onTriggerChange:x,valueNode:k,onValueNodeChange:R,valueNodeHasChildren:A,onValueNodeHasChildrenChange:O,contentId:bi(),value:Y,onValueChange:U,open:M,onOpenChange:z,dir:T,triggerPointerDownPosRef:G,disabled:y,children:[m.jsx(zb.Provider,{scope:t,children:m.jsx(Tue,{scope:e.__scopeSelect,onNativeOptionAdd:b.useCallback(P=>{L(D=>new Set(D).add(P))},[]),onNativeOptionRemove:b.useCallback(P=>{L(D=>{const F=new Set(D);return F.delete(P),F})},[]),children:n})}),I?m.jsxs(q4,{"aria-hidden":!0,required:g,tabIndex:-1,name:f,autoComplete:h,value:Y,onChange:P=>U(P.target.value),disabled:y,form:_,children:[Y===void 0?m.jsx("option",{value:""}):null,Array.from(N)]},B):null]})})};S4.displayName=uu;var E4="SelectTrigger",C4=b.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...i}=e,s=Fb(n),o=fc(E4,n),l=o.disabled||r,u=cr(t,o.onTriggerChange),d=jb(n),f=b.useRef("touch"),[h,y,g]=Y4(w=>{const S=d().filter(R=>!R.disabled),x=S.find(R=>R.value===o.value),k=K4(S,w,x);k!==void 0&&o.onValueChange(k.value)}),_=w=>{l||(o.onOpenChange(!0),g()),w&&(o.triggerPointerDownPosRef.current={x:Math.round(w.pageX),y:Math.round(w.pageY)})};return m.jsx(_m,{asChild:!0,...s,children:m.jsx(yn.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":V4(o.value)?"":void 0,...i,ref:u,onClick:Wt(i.onClick,w=>{w.currentTarget.focus(),f.current!=="mouse"&&_(w)}),onPointerDown:Wt(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:Wt(i.onKeyDown,w=>{const S=h.current!=="";!(w.ctrlKey||w.altKey||w.metaKey)&&w.key.length===1&&y(w.key),!(S&&w.key===" ")&&Sue.includes(w.key)&&(_(),w.preventDefault())})})})});C4.displayName=E4;var k4="SelectValue",T4=b.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:i,children:s,placeholder:o="",...l}=e,u=fc(k4,n),{onValueNodeHasChildrenChange:d}=u,f=s!==void 0,h=cr(t,u.onValueNodeChange);return Ji(()=>{d(f)},[d,f]),m.jsx(yn.span,{...l,ref:h,style:{pointerEvents:"none"},children:V4(u.value)?m.jsx(m.Fragment,{children:o}):s})});T4.displayName=k4;var Aue="SelectIcon",R4=b.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...i}=e;return m.jsx(yn.span,{"aria-hidden":!0,...i,ref:t,children:r||"▼"})});R4.displayName=Aue;var Nue="SelectPortal",A4=e=>m.jsx(gf,{asChild:!0,...e});A4.displayName=Nue;var du="SelectContent",N4=b.forwardRef((e,t)=>{const n=fc(du,e.__scopeSelect),[r,i]=b.useState();if(Ji(()=>{i(new DocumentFragment)},[]),!n.open){const s=r;return s?xu.createPortal(m.jsx(M4,{scope:e.__scopeSelect,children:m.jsx(zb.Slot,{scope:e.__scopeSelect,children:m.jsx("div",{children:e.children})})}),s):null}return m.jsx(P4,{...e,ref:t})});N4.displayName=du;var Ao=10,[M4,hc]=bf(du),Mue="SelectContentImpl",Pue=Jl("SelectContent.RemoveScroll"),P4=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:y,collisionPadding:g,sticky:_,hideWhenDetached:w,avoidCollisions:S,...x}=e,k=fc(du,n),[R,A]=b.useState(null),[O,T]=b.useState(null),M=cr(t,X=>A(X)),[z,Y]=b.useState(null),[U,G]=b.useState(null),I=jb(n),[N,L]=b.useState(!1),B=b.useRef(!1);b.useEffect(()=>{if(R)return kb(R)},[R]),Eb();const P=b.useCallback(X=>{const[ae,...ne]=I().map(xe=>xe.ref.current),[ce]=ne.slice(-1),_e=document.activeElement;for(const xe of X)if(xe===_e||(xe==null||xe.scrollIntoView({block:"nearest"}),xe===ae&&O&&(O.scrollTop=0),xe===ce&&O&&(O.scrollTop=O.scrollHeight),xe==null||xe.focus(),document.activeElement!==_e))return},[I,O]),D=b.useCallback(()=>P([z,R]),[P,z,R]);b.useEffect(()=>{N&&D()},[N,D]);const{onOpenChange:F,triggerPointerDownPosRef:q}=k;b.useEffect(()=>{if(R){let X={x:0,y:0};const ae=ce=>{var _e,xe;X={x:Math.abs(Math.round(ce.pageX)-(((_e=q.current)==null?void 0:_e.x)??0)),y:Math.abs(Math.round(ce.pageY)-(((xe=q.current)==null?void 0:xe.y)??0))}},ne=ce=>{X.x<=10&&X.y<=10?ce.preventDefault():R.contains(ce.target)||F(!1),document.removeEventListener("pointermove",ae),q.current=null};return q.current!==null&&(document.addEventListener("pointermove",ae),document.addEventListener("pointerup",ne,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",ae),document.removeEventListener("pointerup",ne,{capture:!0})}}},[R,F,q]),b.useEffect(()=>{const X=()=>F(!1);return window.addEventListener("blur",X),window.addEventListener("resize",X),()=>{window.removeEventListener("blur",X),window.removeEventListener("resize",X)}},[F]);const[j,V]=Y4(X=>{const ae=I().filter(_e=>!_e.disabled),ne=ae.find(_e=>_e.ref.current===document.activeElement),ce=K4(ae,X,ne);ce&&setTimeout(()=>ce.ref.current.focus())}),K=b.useCallback((X,ae,ne)=>{const ce=!B.current&&!ne;(k.value!==void 0&&k.value===ae||ce)&&(Y(X),ce&&(B.current=!0))},[k.value]),$=b.useCallback(()=>R==null?void 0:R.focus(),[R]),te=b.useCallback((X,ae,ne)=>{const ce=!B.current&&!ne;(k.value!==void 0&&k.value===ae||ce)&&G(X)},[k.value]),re=r==="popper"?b1:I4,ee=re===b1?{side:l,sideOffset:u,align:d,alignOffset:f,arrowPadding:h,collisionBoundary:y,collisionPadding:g,sticky:_,hideWhenDetached:w,avoidCollisions:S}:{};return m.jsx(M4,{scope:n,content:R,viewport:O,onViewportChange:T,itemRefCallback:K,selectedItem:z,onItemLeave:$,itemTextRefCallback:te,focusSelectedItem:D,selectedItemText:U,position:r,isPositioned:N,searchRef:j,children:m.jsx(vm,{as:Pue,allowPinchZoom:!0,children:m.jsx(gm,{asChild:!0,trapped:k.open,onMountAutoFocus:X=>{X.preventDefault()},onUnmountAutoFocus:Wt(i,X=>{var ae;(ae=k.trigger)==null||ae.focus({preventScroll:!0}),X.preventDefault()}),children:m.jsx(mf,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:o,onFocusOutside:X=>X.preventDefault(),onDismiss:()=>k.onOpenChange(!1),children:m.jsx(re,{role:"listbox",id:k.contentId,"data-state":k.open?"open":"closed",dir:k.dir,onContextMenu:X=>X.preventDefault(),...x,...ee,onPlaced:()=>L(!0),ref:M,style:{display:"flex",flexDirection:"column",outline:"none",...x.style},onKeyDown:Wt(x.onKeyDown,X=>{const ae=X.ctrlKey||X.altKey||X.metaKey;if(X.key==="Tab"&&X.preventDefault(),!ae&&X.key.length===1&&V(X.key),["ArrowUp","ArrowDown","Home","End"].includes(X.key)){let ce=I().filter(_e=>!_e.disabled).map(_e=>_e.ref.current);if(["ArrowUp","End"].includes(X.key)&&(ce=ce.slice().reverse()),["ArrowUp","ArrowDown"].includes(X.key)){const _e=X.target,xe=ce.indexOf(_e);ce=ce.slice(xe+1)}setTimeout(()=>P(ce)),X.preventDefault()}})})})})})})});P4.displayName=Mue;var Iue="SelectItemAlignedPosition",I4=b.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...i}=e,s=fc(du,n),o=hc(du,n),[l,u]=b.useState(null),[d,f]=b.useState(null),h=cr(t,M=>f(M)),y=jb(n),g=b.useRef(!1),_=b.useRef(!0),{viewport:w,selectedItem:S,selectedItemText:x,focusSelectedItem:k}=o,R=b.useCallback(()=>{if(s.trigger&&s.valueNode&&l&&d&&w&&S&&x){const M=s.trigger.getBoundingClientRect(),z=d.getBoundingClientRect(),Y=s.valueNode.getBoundingClientRect(),U=x.getBoundingClientRect();if(s.dir!=="rtl"){const _e=U.left-z.left,xe=Y.left-_e,We=M.left-xe,De=M.width+We,Pt=Math.max(De,z.width),tt=window.innerWidth-Ao,lt=iI(xe,[Ao,Math.max(Ao,tt-Pt)]);l.style.minWidth=De+"px",l.style.left=lt+"px"}else{const _e=z.right-U.right,xe=window.innerWidth-Y.right-_e,We=window.innerWidth-M.right-xe,De=M.width+We,Pt=Math.max(De,z.width),tt=window.innerWidth-Ao,lt=iI(xe,[Ao,Math.max(Ao,tt-Pt)]);l.style.minWidth=De+"px",l.style.right=lt+"px"}const G=y(),I=window.innerHeight-Ao*2,N=w.scrollHeight,L=window.getComputedStyle(d),B=parseInt(L.borderTopWidth,10),P=parseInt(L.paddingTop,10),D=parseInt(L.borderBottomWidth,10),F=parseInt(L.paddingBottom,10),q=B+P+N+F+D,j=Math.min(S.offsetHeight*5,q),V=window.getComputedStyle(w),K=parseInt(V.paddingTop,10),$=parseInt(V.paddingBottom,10),te=M.top+M.height/2-Ao,re=I-te,ee=S.offsetHeight/2,X=S.offsetTop+ee,ae=B+P+X,ne=q-ae;if(ae<=te){const _e=G.length>0&&S===G[G.length-1].ref.current;l.style.bottom="0px";const xe=d.clientHeight-w.offsetTop-w.offsetHeight,We=Math.max(re,ee+(_e?$:0)+xe+D),De=ae+We;l.style.height=De+"px"}else{const _e=G.length>0&&S===G[0].ref.current;l.style.top="0px";const We=Math.max(te,B+w.offsetTop+(_e?K:0)+ee)+ne;l.style.height=We+"px",w.scrollTop=ae-te+w.offsetTop}l.style.margin=`${Ao}px 0`,l.style.minHeight=j+"px",l.style.maxHeight=I+"px",r==null||r(),requestAnimationFrame(()=>g.current=!0)}},[y,s.trigger,s.valueNode,l,d,w,S,x,s.dir,r]);Ji(()=>R(),[R]);const[A,O]=b.useState();Ji(()=>{d&&O(window.getComputedStyle(d).zIndex)},[d]);const T=b.useCallback(M=>{M&&_.current===!0&&(R(),k==null||k(),_.current=!1)},[R,k]);return m.jsx(Lue,{scope:n,contentWrapper:l,shouldExpandOnScrollRef:g,onScrollButtonChange:T,children:m.jsx("div",{ref:u,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:A},children:m.jsx(yn.div,{...i,ref:h,style:{boxSizing:"border-box",maxHeight:"100%",...i.style}})})})});I4.displayName=Iue;var Oue="SelectPopperPosition",b1=b.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:i=Ao,...s}=e,o=Fb(n);return m.jsx(Ib,{...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)"}})});b1.displayName=Oue;var[Lue,Tk]=bf(du,{}),_1="SelectViewport",O4=b.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...i}=e,s=hc(_1,n),o=Tk(_1,n),l=cr(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(zb.Slot,{scope:n,children:m.jsx(yn.div,{"data-radix-select-viewport":"",role:"presentation",...i,ref:l,style:{position:"relative",flex:1,overflow:"hidden auto",...i.style},onScroll:Wt(i.onScroll,d=>{const f=d.currentTarget,{contentWrapper:h,shouldExpandOnScrollRef:y}=o;if(y!=null&&y.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 k=x+g,R=Math.min(_,k),A=k-R;h.style.height=R+"px",h.style.bottom==="0px"&&(f.scrollTop=A>0?A:0,h.style.justifyContent="flex-end")}}}u.current=f.scrollTop})})})]})});O4.displayName=_1;var L4="SelectGroup",[Due,Bue]=bf(L4),zue=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=bi();return m.jsx(Due,{scope:n,id:i,children:m.jsx(yn.div,{role:"group","aria-labelledby":i,...r,ref:t})})});zue.displayName=L4;var D4="SelectLabel",jue=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=Bue(D4,n);return m.jsx(yn.div,{id:i.id,...r,ref:t})});jue.displayName=D4;var Wy="SelectItem",[Fue,B4]=bf(Wy),z4=b.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:i=!1,textValue:s,...o}=e,l=fc(Wy,n),u=hc(Wy,n),d=l.value===r,[f,h]=b.useState(s??""),[y,g]=b.useState(!1),_=cr(t,k=>{var R;return(R=u.itemRefCallback)==null?void 0:R.call(u,k,r,i)}),w=bi(),S=b.useRef("touch"),x=()=>{i||(l.onValueChange(r),l.onOpenChange(!1))};if(r==="")throw new Error("A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.");return m.jsx(Fue,{scope:n,value:r,disabled:i,textId:w,isSelected:d,onItemTextChange:b.useCallback(k=>{h(R=>R||((k==null?void 0:k.textContent)??"").trim())},[]),children:m.jsx(zb.ItemSlot,{scope:n,value:r,disabled:i,textValue:f,children:m.jsx(yn.div,{role:"option","aria-labelledby":w,"data-highlighted":y?"":void 0,"aria-selected":d&&y,"data-state":d?"checked":"unchecked","aria-disabled":i||void 0,"data-disabled":i?"":void 0,tabIndex:i?void 0:-1,...o,ref:_,onFocus:Wt(o.onFocus,()=>g(!0)),onBlur:Wt(o.onBlur,()=>g(!1)),onClick:Wt(o.onClick,()=>{S.current!=="mouse"&&x()}),onPointerUp:Wt(o.onPointerUp,()=>{S.current==="mouse"&&x()}),onPointerDown:Wt(o.onPointerDown,k=>{S.current=k.pointerType}),onPointerMove:Wt(o.onPointerMove,k=>{var R;S.current=k.pointerType,i?(R=u.onItemLeave)==null||R.call(u):S.current==="mouse"&&k.currentTarget.focus({preventScroll:!0})}),onPointerLeave:Wt(o.onPointerLeave,k=>{var R;k.currentTarget===document.activeElement&&((R=u.onItemLeave)==null||R.call(u))}),onKeyDown:Wt(o.onKeyDown,k=>{var A;((A=u.searchRef)==null?void 0:A.current)!==""&&k.key===" "||(Eue.includes(k.key)&&x(),k.key===" "&&k.preventDefault())})})})})});z4.displayName=Wy;var ap="SelectItemText",j4=b.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:i,...s}=e,o=fc(ap,n),l=hc(ap,n),u=B4(ap,n),d=Rue(ap,n),[f,h]=b.useState(null),y=cr(t,x=>h(x),u.onItemTextChange,x=>{var k;return(k=l.itemTextRefCallback)==null?void 0:k.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 Ji(()=>(w(_),()=>S(_)),[w,S,_]),m.jsxs(m.Fragment,{children:[m.jsx(yn.span,{id:u.textId,...s,ref:y}),u.isSelected&&o.valueNode&&!o.valueNodeHasChildren?xu.createPortal(s.children,o.valueNode):null]})});j4.displayName=ap;var F4="SelectItemIndicator",$4=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return B4(F4,n).isSelected?m.jsx(yn.span,{"aria-hidden":!0,...r,ref:t}):null});$4.displayName=F4;var w1="SelectScrollUpButton",H4=b.forwardRef((e,t)=>{const n=hc(w1,e.__scopeSelect),r=Tk(w1,e.__scopeSelect),[i,s]=b.useState(!1),o=cr(t,r.onScrollButtonChange);return Ji(()=>{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(W4,{...e,ref:o,onAutoScroll:()=>{const{viewport:l,selectedItem:u}=n;l&&u&&(l.scrollTop=l.scrollTop-u.offsetHeight)}}):null});H4.displayName=w1;var x1="SelectScrollDownButton",U4=b.forwardRef((e,t)=>{const n=hc(x1,e.__scopeSelect),r=Tk(x1,e.__scopeSelect),[i,s]=b.useState(!1),o=cr(t,r.onScrollButtonChange);return Ji(()=>{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(W4,{...e,ref:o,onAutoScroll:()=>{const{viewport:l,selectedItem:u}=n;l&&u&&(l.scrollTop=l.scrollTop+u.offsetHeight)}}):null});U4.displayName=x1;var W4=b.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...i}=e,s=hc("SelectScrollButton",n),o=b.useRef(null),l=jb(n),u=b.useCallback(()=>{o.current!==null&&(window.clearInterval(o.current),o.current=null)},[]);return b.useEffect(()=>()=>u(),[u]),Ji(()=>{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(yn.div,{"aria-hidden":!0,...i,ref:t,style:{flexShrink:0,...i.style},onPointerDown:Wt(i.onPointerDown,()=>{o.current===null&&(o.current=window.setInterval(r,50))}),onPointerMove:Wt(i.onPointerMove,()=>{var d;(d=s.onItemLeave)==null||d.call(s),o.current===null&&(o.current=window.setInterval(r,50))}),onPointerLeave:Wt(i.onPointerLeave,()=>{u()})})}),$ue="SelectSeparator",Hue=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return m.jsx(yn.div,{"aria-hidden":!0,...r,ref:t})});Hue.displayName=$ue;var S1="SelectArrow",Uue=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=Fb(n),s=fc(S1,n),o=hc(S1,n);return s.open&&o.position==="popper"?m.jsx(Ob,{...i,...r,ref:t}):null});Uue.displayName=S1;var Wue="SelectBubbleInput",q4=b.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const i=b.useRef(null),s=cr(r,i),o=yae(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(yn.select,{...n,style:{...x5,...n.style},ref:s,defaultValue:t})});q4.displayName=Wue;function V4(e){return e===""||e===void 0}function Y4(e){const t=Io(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 K4(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=que(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 que(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Vue=S4,Yue=C4,Kue=T4,Gue=R4,Xue=A4,Zue=N4,Jue=O4,Que=z4,ede=j4,tde=$4,nde=H4,rde=U4,[$b]=Xa("Tooltip",[cc]),Hb=cc(),G4="TooltipProvider",ide=700,E1="tooltip.open",[sde,Rk]=$b(G4),X4=e=>{const{__scopeTooltip:t,delayDuration:n=ide,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(sde,{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})};X4.displayName=G4;var Vp="Tooltip",[ode,km]=$b(Vp),Z4=e=>{const{__scopeTooltip:t,children:n,open:r,defaultOpen:i,onOpenChange:s,disableHoverableContent:o,delayDuration:l}=e,u=Rk(Vp,e.__scopeTooltip),d=Hb(t),[f,h]=b.useState(null),y=bi(),g=b.useRef(0),_=o??u.disableHoverableContent,w=l??u.delayDuration,S=b.useRef(!1),[x,k]=Ql({prop:r,defaultProp:i??!1,onChange:M=>{M?(u.onOpen(),document.dispatchEvent(new CustomEvent(E1))):u.onClose(),s==null||s(M)},caller:Vp}),R=b.useMemo(()=>x?S.current?"delayed-open":"instant-open":"closed",[x]),A=b.useCallback(()=>{window.clearTimeout(g.current),g.current=0,S.current=!1,k(!0)},[k]),O=b.useCallback(()=>{window.clearTimeout(g.current),g.current=0,k(!1)},[k]),T=b.useCallback(()=>{window.clearTimeout(g.current),g.current=window.setTimeout(()=>{S.current=!0,k(!0),g.current=0},w)},[w,k]);return b.useEffect(()=>()=>{g.current&&(window.clearTimeout(g.current),g.current=0)},[]),m.jsx(bm,{...d,children:m.jsx(ode,{scope:t,contentId:y,open:x,stateAttribute:R,trigger:f,onTriggerChange:h,onTriggerEnter:b.useCallback(()=>{u.isOpenDelayedRef.current?T():A()},[u.isOpenDelayedRef,T,A]),onTriggerLeave:b.useCallback(()=>{_?O():(window.clearTimeout(g.current),g.current=0)},[O,_]),onOpen:A,onClose:O,disableHoverableContent:_,children:n})})};Z4.displayName=Vp;var C1="TooltipTrigger",J4=b.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,i=km(C1,n),s=Rk(C1,n),o=Hb(n),l=b.useRef(null),u=cr(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(_m,{asChild:!0,...o,children:m.jsx(yn.button,{"aria-describedby":i.open?i.contentId:void 0,"data-state":i.stateAttribute,...r,ref:u,onPointerMove:Wt(e.onPointerMove,y=>{y.pointerType!=="touch"&&!f.current&&!s.isPointerInTransitRef.current&&(i.onTriggerEnter(),f.current=!0)}),onPointerLeave:Wt(e.onPointerLeave,()=>{i.onTriggerLeave(),f.current=!1}),onPointerDown:Wt(e.onPointerDown,()=>{i.open&&i.onClose(),d.current=!0,document.addEventListener("pointerup",h,{once:!0})}),onFocus:Wt(e.onFocus,()=>{d.current||i.onOpen()}),onBlur:Wt(e.onBlur,i.onClose),onClick:Wt(e.onClick,i.onClose)})})});J4.displayName=C1;var Ak="TooltipPortal",[ade,lde]=$b(Ak,{forceMount:void 0}),Q4=e=>{const{__scopeTooltip:t,forceMount:n,children:r,container:i}=e,s=km(Ak,t);return m.jsx(ade,{scope:t,forceMount:n,children:m.jsx(wo,{present:n||s.open,children:m.jsx(gf,{asChild:!0,container:i,children:r})})})};Q4.displayName=Ak;var of="TooltipContent",eF=b.forwardRef((e,t)=>{const n=lde(of,e.__scopeTooltip),{forceMount:r=n.forceMount,side:i="top",...s}=e,o=km(of,e.__scopeTooltip);return m.jsx(wo,{present:r||o.open,children:o.disableHoverableContent?m.jsx(tF,{side:i,...s,ref:t}):m.jsx(cde,{side:i,...s,ref:t})})}),cde=b.forwardRef((e,t)=>{const n=km(of,e.__scopeTooltip),r=Rk(of,e.__scopeTooltip),i=b.useRef(null),s=cr(t,i),[o,l]=b.useState(null),{trigger:u,onClose:d}=n,f=i.current,{onPointerInTransitChange:h}=r,y=b.useCallback(()=>{l(null),h(!1)},[h]),g=b.useCallback((_,w)=>{const S=_.currentTarget,x={x:_.clientX,y:_.clientY},k=hde(x,S.getBoundingClientRect()),R=pde(x,k),A=mde(w.getBoundingClientRect()),O=vde([...R,...A]);l(O),h(!0)},[h]);return b.useEffect(()=>()=>y(),[y]),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,y]),b.useEffect(()=>{if(o){const _=w=>{const S=w.target,x={x:w.clientX,y:w.clientY},k=(u==null?void 0:u.contains(S))||(f==null?void 0:f.contains(S)),R=!gde(x,o);k?y():R&&(y(),d())};return document.addEventListener("pointermove",_),()=>document.removeEventListener("pointermove",_)}},[u,f,o,d,y]),m.jsx(tF,{...e,ref:s})}),[ude,dde]=$b(Vp,{isInside:!1}),fde=Wse("TooltipContent"),tF=b.forwardRef((e,t)=>{const{__scopeTooltip:n,children:r,"aria-label":i,onEscapeKeyDown:s,onPointerDownOutside:o,...l}=e,u=km(of,n),d=Hb(n),{onClose:f}=u;return b.useEffect(()=>(document.addEventListener(E1,f),()=>document.removeEventListener(E1,f)),[f]),b.useEffect(()=>{if(u.trigger){const h=y=>{const g=y.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(mf,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:s,onPointerDownOutside:o,onFocusOutside:h=>h.preventDefault(),onDismiss:f,children:m.jsxs(Ib,{"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(fde,{children:r}),m.jsx(ude,{scope:n,isInside:!0,children:m.jsx(E5,{id:u.contentId,role:"tooltip",children:i||r})})]})})});eF.displayName=of;var nF="TooltipArrow",rF=b.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,i=Hb(n);return dde(nF,n).isInside?null:m.jsx(Ob,{...i,...r,ref:t})});rF.displayName=nF;function hde(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 pde(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 mde(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 gde(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,y=u.y;f>r!=y>r&&n<(h-d)*(r-f)/(y-f)+d&&(i=!i)}return i}function vde(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),yde(t)}function yde(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 bde=X4,_de=Z4,wde=J4,xde=Q4,Sde=eF,Ede=rF;const iF=b.createContext(!1);function Cde({blocked:e,children:t}){return m.jsx(iF.Provider,{value:e,children:t})}function Tm(){return b.useContext(iF)}function Ub({...e}){return m.jsx(bue,{"data-slot":"popover",...e})}function Wb({...e}){return m.jsx(_ue,{"data-slot":"popover-trigger",...e})}function qb({className:e,align:t="center",sideOffset:n=4,inert:r,"aria-disabled":i,...s}){const o=Tm();return m.jsx(wue,{children:m.jsx(xue,{"data-slot":"popover-content",align:t,sideOffset:n,className:Ye("z-50 w-72 origin-(--radix-popover-content-transform-origin) rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-hidden data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",e),inert:o||r?!0:void 0,"aria-disabled":o?!0:i,"data-relay-interaction-blocked":o?"true":void 0,...s})})}const sI=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,oI=Iz,kde=(e,t)=>n=>{var r;if((t==null?void 0:t.variants)==null)return oI(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 y=sI(f)||sI(h);return i[d][y]}),l=n&&Object.entries(n).reduce((d,f)=>{let[h,y]=f;return y===void 0||(d[h]=y),d},{}),u=t==null||(r=t.compoundVariants)===null||r===void 0?void 0:r.reduce((d,f)=>{let{class:h,className:y,...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,y]:d},[]);return oI(e,o,u,n==null?void 0:n.class,n==null?void 0:n.className)},Tde=kde("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 yt({className:e,variant:t="default",size:n="default",asChild:r=!1,...i}){const s=r?Hse:"button";return m.jsx(s,{"data-slot":"button","data-variant":t,"data-size":n,className:Ye(Tde({variant:t,size:n,className:e})),...i})}function _f({...e}){return m.jsx(Jce,{"data-slot":"dropdown-menu",...e})}function Rde({...e}){return m.jsx(f4,{"data-slot":"dropdown-menu-portal",...e})}function wf({...e}){return m.jsx(Qce,{"data-slot":"dropdown-menu-trigger",...e})}function xf({className:e,sideOffset:t=4,inert:n,"aria-disabled":r,...i}){const s=Tm();return m.jsx(f4,{children:m.jsx(eue,{"data-slot":"dropdown-menu-content",sideOffset:t,className:Ye("z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",e),inert:s||n?!0:void 0,"aria-disabled":s?!0:r,"data-relay-interaction-blocked":s?"true":void 0,...i})})}function ti({className:e,inset:t,variant:n="default",...r}){return m.jsx(nue,{"data-slot":"dropdown-menu-item","data-inset":t,"data-variant":n,className:Ye("relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground data-[variant=destructive]:*:[svg]:text-destructive!",e),...r})}function y0({className:e,children:t,checked:n,...r}){return m.jsxs(rue,{"data-slot":"dropdown-menu-checkbox-item",className:Ye("relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",e),checked:n,...r,children:[m.jsx("span",{className:"pointer-events-none absolute left-2 flex size-3.5 items-center justify-center",children:m.jsx(iue,{children:m.jsx(ua,{className:"size-4"})})}),t]})}function yv({className:e,inset:t,...n}){return m.jsx(tue,{"data-slot":"dropdown-menu-label","data-inset":t,className:Ye("px-2 py-1.5 text-sm font-medium data-[inset]:pl-8",e),...n})}function Gc({className:e,...t}){return m.jsx(sue,{"data-slot":"dropdown-menu-separator",className:Ye("-mx-1 my-1 h-px bg-border",e),...t})}function Ade({...e}){return m.jsx(oue,{"data-slot":"dropdown-menu-sub",...e})}function Nde({className:e,inset:t,children:n,...r}){return m.jsxs(aue,{"data-slot":"dropdown-menu-sub-trigger","data-inset":t,className:Ye("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(Hd,{className:"ml-auto size-4"})]})}function Mde({className:e,...t}){return m.jsx(lue,{"data-slot":"dropdown-menu-sub-content",className:Ye("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 Pde={"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 Qc({variant:e,action:t}){const{heading:n,body:r}=Pde[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 Ide={online:"bg-[var(--color-status-success)]",offline:"bg-[var(--muted-foreground)]",connecting:"bg-[var(--color-status-working)] animate-pulse"},Ode={online:"开发机在线",offline:"开发机离线",connecting:"正在连接开发机"};function k1({status:e,className:t}){return m.jsx("span",{className:Ye("inline-block w-2 h-2 rounded-full shrink-0",Ide[e],t),role:"status","aria-label":Ode[e]})}function Cp({name:e,osName:t,className:n,nameClassName:r}){return m.jsxs("span",{className:Ye("min-w-0 flex-1",n),children:[m.jsx("span",{"data-slot":"proxy-name",className:Ye("block truncate text-sm font-normal leading-5",r),children:e}),t&&m.jsx("span",{"data-slot":"proxy-os",className:"block truncate text-xs font-normal leading-4 text-muted-foreground",children:t})]})}function es({...e}){return m.jsx(ok,{"data-slot":"dialog",...e})}function Lde({...e}){return m.jsx(ak,{"data-slot":"dialog-portal",...e})}function Dde({...e}){return m.jsx(Rb,{"data-slot":"dialog-close",...e})}function Bde({className:e,...t}){return m.jsx(lk,{"data-slot":"dialog-overlay",className:Ye("fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",e),...t})}function ts({className:e,children:t,showCloseButton:n=!0,focusSurfaceOnOpen:r=!1,onOpenAutoFocus:i,inert:s,"aria-disabled":o,...l}){const u=Tm();return m.jsxs(Lde,{"data-slot":"dialog-portal",children:[m.jsx(Bde,{}),m.jsxs(ck,{"data-slot":"dialog-content",className:Ye("fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border bg-background p-6 shadow-lg duration-200 outline-none data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 sm:max-w-lg",e),onOpenAutoFocus:d=>{i==null||i(d),!(!r||d.defaultPrevented)&&(d.preventDefault(),d.currentTarget.focus({preventScroll:!0}))},inert:u||s?!0:void 0,"aria-disabled":u?!0:o,"data-relay-interaction-blocked":u?"true":void 0,...l,children:[t,n&&m.jsxs(Rb,{"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(bu,{}),m.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function ns({className:e,...t}){return m.jsx("div",{"data-slot":"dialog-header",className:Ye("flex flex-col gap-2 text-center sm:text-left",e),...t})}function Vs({className:e,showCloseButton:t=!1,children:n,...r}){return m.jsxs("div",{"data-slot":"dialog-footer",className:Ye("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end max-sm:[&_button]:min-h-11",e),...r,children:[n,t&&m.jsx(Rb,{asChild:!0,children:m.jsx(yt,{variant:"outline",children:"Close"})})]})}function $i({className:e,...t}){return m.jsx(J5,{"data-slot":"dialog-title",className:Ye("text-lg leading-none font-semibold",e),...t})}function Es({className:e,...t}){return m.jsx(Q5,{"data-slot":"dialog-description",className:Ye("text-sm text-muted-foreground",e),...t})}function zde(e){return`“${(e==null?void 0:e.name)??(e==null?void 0:e.proxyId)??"这台开发机"}”只会从当前 Relay 的开发机列表中移除。不会删除机器上的文件或会话,也不会阻止它再次连接;以后重新运行时,它会重新出现在列表中。`}function jde({open:e,target:t,removing:n,onOpenChange:r,onConfirm:i}){return m.jsx(es,{open:e,onOpenChange:s=>{n||r(s)},children:m.jsxs(ts,{"data-slot":"proxy-removal-dialog",showCloseButton:!n,onEscapeKeyDown:s=>{n&&s.preventDefault()},onPointerDownOutside:s=>{n&&s.preventDefault()},children:[m.jsxs(ns,{children:[m.jsx($i,{children:"移除离线开发机?"}),m.jsx(Es,{children:zde(t)})]}),m.jsxs(Vs,{children:[m.jsx(yt,{type:"button",variant:"ghost",disabled:n,onClick:()=>r(!1),children:"取消"}),m.jsxs(yt,{type:"button",variant:"destructive",disabled:n||!t,"aria-busy":n||void 0,onClick:i,"data-slot":"proxy-removal-confirm",children:[n&&m.jsx(di,{className:"size-4 animate-spin","aria-hidden":"true"}),n?"正在移除":"移除"]})]})]})})}const ly=80,Fde=8,$de=1.2;function aI(e){return Math.max(0,Math.min(ly,e))}function Hde({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,y]=b.useState(null),g=h??(i?ly:0),_=h!==null;function w(R){var A,O;if(!(s||R.pointerType!=="touch"&&R.pointerType!=="pen")&&!R.target.closest("button")){d.current={pointerId:R.pointerId,startX:R.clientX,startY:R.clientY,startOffset:i?ly:0,axis:"pending"};try{(O=(A=R.currentTarget).setPointerCapture)==null||O.call(A,R.pointerId)}catch{}}}function S(R){const A=d.current;if(!A||A.pointerId!==R.pointerId)return;const O=R.clientX-A.startX,T=R.clientY-A.startY;if(A.axis==="pending"){if(Math.hypot(O,T)<Fde)return;A.axis=Math.abs(O)>Math.abs(T)*$de?"horizontal":"vertical"}A.axis!=="vertical"&&(R.preventDefault(),y(aI(A.startOffset-O)))}function x(R,A=!1){var M,z;const O=d.current;if(!O||O.pointerId!==R.pointerId)return;d.current=null;try{(z=(M=R.currentTarget).releasePointerCapture)==null||z.call(M,R.pointerId)}catch{}if(O.axis!=="horizontal"||A){y(null);return}R.preventDefault();const T=h??aI(O.startOffset-(R.clientX-O.startX));y(null),o(T>=ly/2),f.current=!0,window.setTimeout(()=>{f.current=!1},0)}function k(R){if(f.current){f.current=!1,R.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:R=>x(R),onPointerCancel:R=>x(R,!0),onClick:k,children:[m.jsx(k1,{status:"offline"}),m.jsx(Cp,{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 sF({layout:e,variant:t="default"}){const n=Ae(M=>M.proxies),r=Ae(M=>M.proxyListLoaded),i=Ae(M=>M.relayClientAuthIssue),s=Ae(M=>M.selectedProxyId),o=Ae(M=>M.proxySwitchTarget),l=ds(),u=Cs(),[d,f]=b.useState(!1),[h,y]=b.useState(null),[g,_]=b.useState(null),[w,S]=b.useState(null);async function x(M,z){if(o)return;const Y=Ft;if(!Y){Ue.error("请先连接开发机");return}const U=z??M,G=s!==null&&s!==M;Ae.getState().setProxySwitchTarget({proxyId:M,name:U});try{const I=await Y.selectProxy(M);if(!I.success){Ue.error(`无法连接 ${U}:${I.error??"未知错误"}`);return}const N=Y.getPreviewScope();if(!N||N.proxyId!==M||N.bindingId!==I.bindingId)throw Nt.dispose(),Y.clearBoundProxy(),new Error("开发机绑定状态无效,请重试");Nt.activate(Y,N),Nt.syncWebSnapshot(N).catch(L=>{L instanceof Error&&L.name==="AbortError"||console.error("[proxy-switcher] web preview snapshot failed",L)}),Nt.syncDeviceSnapshot(N).catch(L=>{L instanceof Error&&L.name==="AbortError"||console.error("[proxy-switcher] device preview snapshot failed",L)}),G&&(Ht.getState().prepareForProxySwitch(U),Gr.getState().prepareForProxySwitch()),Mr("local",Sn.proxyId,M),Ae.getState().setProxy(M,z??null),Ae.getState().setProxyOnline(!0),Ae.getState().transitionToPhase("session_browsing"),Y.sendControl({type:"session_list_request"}),Y.requestProxyInfo().then(L=>{if(Ae.getState().selectedProxyId!==M||!Nt.isActive(Y,N))return;const B=Gr.getState();B.setHomePath(L.homePath),B.setAgentCli(L.agentCli),Ae.getState().setTerminalShells(L.terminalShells)}).catch(L=>{Nt.isActive(Y,N)&&console.error("[proxy-switcher] post-bind proxy info fetch failed",L)}),Y.requestAgentStatuses().then(L=>{if(Ae.getState().selectedProxyId!==M||!Nt.isActive(Y,N))return;const B=Ht.getState();for(const P of L)B.setAgentStatus(P.sessionId,P.payload)}).catch(L=>{Nt.isActive(Y,N)&&console.error("[proxy-switcher] post-bind data fetch failed",L)}),YC(Y).then(L=>{L.status==="failed"&&console.error("[proxy-switcher] post-bind data fetch failed",L.error)}),f(!1),(e==="page"||l.pathname.startsWith("/chat/")||l.pathname.startsWith("/preview/device/"))&&u("/sessions")}catch(I){const N=I instanceof Error?I.message:"未知错误";Ue.error(`无法连接 ${U}:${N}`)}finally{Ae.getState().setProxySwitchTarget(null)}}function k(M){M.online||w||(y(null),_({proxyId:M.proxyId,...M.name?{name:M.name}:{}}))}async function R(){const M=g;if(!M||w)return;const z=Ft;if(!z){Ue.error("Relay 连接不可用,请稍后重试");return}const Y=Ae.getState().proxies.find(U=>U.proxyId===M.proxyId);if(!Y){if(!Ae.getState().proxyListLoaded){Ue.info("正在重新连接 Relay,请稍后再试");return}Ep(M.proxyId,z)&&u("/"),Ue.info("这台开发机已经不在列表中"),_(null);return}if(Y.online){Ue.warning("这台开发机已重新上线,未移除"),_(null);return}S(M.proxyId),Mie(M.proxyId);try{const U=await z.removeOfflineProxy(M.proxyId);if(U.success){Id(M.proxyId),Ep(M.proxyId,z)&&u("/"),Ue.success(`已移除 ${M.name??M.proxyId}`),_(null);return}if(U.errorCode===Pr.PROXY_ONLINE){Id(M.proxyId),Ue.warning("这台开发机已重新上线,未移除"),_(null),z.listProxies();return}if(U.errorCode===Pr.PROXY_NOT_FOUND){Id(M.proxyId),Ep(M.proxyId,z)&&u("/"),Ue.info("这台开发机已经不在列表中"),_(null),z.listProxies();return}Id(M.proxyId),Ue.error(U.error??"无法移除开发机,请重试")}catch(U){Ue.error(U instanceof Error?U.message:"无法移除开发机,请重试"),z.listProxies()}finally{S(null)}}const A=m.jsx(jde,{open:g!==null,target:g,removing:w!==null,onOpenChange:M=>{M||_(null)},onConfirm:()=>void R()});if(e==="page")return i==="missing_client_token"?m.jsx(Qc,{variant:"client-token-missing"}):i==="invalid_client_token"?m.jsx(Qc,{variant:"client-token-invalid"}):r?n.length===0?m.jsx(Qc,{variant:"no-proxy"}):m.jsxs(m.Fragment,{children:[m.jsxs("div",{className:"flex h-full flex-col gap-3 overflow-auto p-4",children:[m.jsx("h3",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground",children:"开发机"}),m.jsx("ul",{role:"list",className:"flex flex-col gap-2",children:n.map(M=>{const z=(o==null?void 0:o.proxyId)===M.proxyId,Y=o!==null;return M.online?m.jsx("li",{children:m.jsxs("button",{type:"button","data-slot":"proxy-item","data-proxy-id":M.proxyId,"data-online":"true","data-selecting":z||void 0,disabled:Y||w!==null,"aria-busy":z||void 0,onClick:()=>x(M.proxyId,M.name),className:Ye("flex min-h-[44px] w-full items-center gap-3 rounded-md border bg-card px-3 text-left transition-colors disabled:cursor-not-allowed disabled:hover:bg-card",M.osName?"h-14":"h-11",z?"border-primary/40 bg-accent text-accent-foreground":"border-border hover:bg-accent",Y&&!z||w!==null?"opacity-50":""),"aria-pressed":s===M.proxyId,children:[m.jsx(k1,{status:"online"}),m.jsx(Cp,{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(di,{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(Hde,{proxyId:M.proxyId,name:M.name,osName:M.osName,selected:s===M.proxyId,revealed:h===M.proxyId,disabled:Y||w!==null,onRevealedChange:U=>y(U?M.proxyId:null),onRemove:()=>k(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(di,{className:"h-5 w-5 animate-spin","aria-hidden":!0}),m.jsx("p",{className:"text-sm",children:"连接中..."})]});const O=n.find(M=>M.proxyId===s),T=(O==null?void 0:O.name)??(O==null?void 0:O.proxyId)??"未选择开发机";return m.jsxs(m.Fragment,{children:[m.jsxs(Ub,{open:d,onOpenChange:f,children:[m.jsx(Wb,{asChild:!0,children:m.jsxs("button",{type:"button","data-slot":"proxy-switcher-trigger",className:Ye("group transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",t==="sidebarChrome"?"inline-flex min-h-9 min-w-0 max-w-full items-center justify-start gap-1.5 rounded-md text-left text-foreground hover:text-primary":"flex min-h-10 w-full items-center gap-2 rounded-md border border-border bg-background px-4 py-1.5 hover:bg-accent"),"aria-label":`当前连接:${T}`,children:[t==="default"&&m.jsx("span",{className:"h-4 w-4 shrink-0","aria-hidden":!0}),m.jsx(Cp,{name:T,osName:O==null?void 0:O.osName,className:t==="sidebarChrome"?"flex-initial":"text-center",nameClassName:t==="sidebarChrome"?"text-base font-semibold":void 0}),m.jsx(sc,{className:"h-4 w-4 text-muted-foreground shrink-0 transition-transform group-data-[state=open]:rotate-180","aria-hidden":!0})]})}),m.jsx(qb,{align:"start",className:"w-[260px] p-1",children:n.length===0?m.jsx("div",{className:"text-xs text-muted-foreground p-2",children:"暂无可连接开发机"}):m.jsx("ul",{role:"list",className:"flex flex-col",children:n.map(M=>{const z=(o==null?void 0:o.proxyId)===M.proxyId,Y=o!==null;return m.jsxs("li",{className:"group flex min-w-0 items-center rounded-md",children:[m.jsxs("button",{type:"button","data-slot":"proxy-item","data-proxy-id":M.proxyId,"data-online":M.online,"data-selecting":z||void 0,disabled:!M.online||Y,"aria-busy":z||void 0,onClick:()=>x(M.proxyId,M.name),className:Ye("flex min-w-0 flex-1 items-center gap-2 rounded-md px-2 text-left transition-colors disabled:cursor-not-allowed disabled:hover:bg-transparent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",M.osName?"h-12":"h-9",z?"bg-accent text-accent-foreground":"hover:bg-accent",Y&&!z?"opacity-50":"",M.online?"":"opacity-50"),"aria-pressed":s===M.proxyId,title:M.online?void 0:"这台开发机离线",children:[m.jsx(k1,{status:M.online?"online":"offline"}),m.jsx(Cp,{name:M.name??M.proxyId,osName:M.osName}),z?m.jsx(di,{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(_f,{children:[m.jsx(wf,{asChild:!0,children:m.jsx(yt,{type:"button",variant:"ghost",size:"icon-xs",className:"mr-1 size-8 text-muted-foreground opacity-60 hover:opacity-100 focus-visible:opacity-100",disabled:Y||w!==null,"aria-label":`${M.name??M.proxyId} 操作`,"data-slot":"proxy-row-menu-trigger",children:m.jsx(hb,{"aria-hidden":"true"})})}),m.jsx(xf,{align:"end","data-slot":"proxy-row-menu",children:m.jsxs(ti,{variant:"destructive","data-slot":"proxy-row-remove-item",onSelect:U=>{U.stopPropagation(),k(M)},children:[m.jsx(Nz,{"aria-hidden":"true"}),"移除开发机"]})})]})]},M.proxyId)})})})]}),A]})}function Ude({delayDuration:e=0,...t}){return m.jsx(bde,{"data-slot":"tooltip-provider",delayDuration:e,...t})}function Sf({...e}){return m.jsx(_de,{"data-slot":"tooltip",...e})}function Ef({...e}){return m.jsx(wde,{"data-slot":"tooltip-trigger",...e})}function Cf({className:e,sideOffset:t=0,children:n,hideArrow:r=!1,...i}){return m.jsx(xde,{children:m.jsxs(Sde,{"data-slot":"tooltip-content",sideOffset:t,className:Ye("z-50 w-fit origin-(--radix-tooltip-content-transform-origin) animate-in rounded-md bg-foreground px-3 py-1.5 text-xs text-balance text-background fade-in-0 zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95",e),...i,children:[n,!r&&m.jsx(Ede,{className:"z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px] bg-foreground fill-foreground"})]})})}function pc({...e}){return m.jsx(ok,{"data-slot":"sheet",...e})}function Wde({...e}){return m.jsx(vae,{"data-slot":"sheet-trigger",...e})}function qde({...e}){return m.jsx(ak,{"data-slot":"sheet-portal",...e})}function Vde({className:e,...t}){return m.jsx(lk,{"data-slot":"sheet-overlay",className:Ye("fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",e),...t})}function mc({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=Tm();return m.jsxs(qde,{children:[m.jsx(Vde,{className:t}),m.jsxs(ck,{"data-slot":"sheet-content",className:Ye("fixed z-50 flex flex-col gap-4 bg-background shadow-lg transition ease-in-out data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:animate-in data-[state=open]:duration-500",r==="right"&&"inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm",r==="left"&&"inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm",r==="top"&&"inset-x-0 top-0 h-auto border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",r==="bottom"&&"inset-x-0 bottom-0 h-auto border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",e),onOpenAutoFocus: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(Rb,{"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(bu,{className:"size-4"}),m.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function Eu({className:e,...t}){return m.jsx("div",{"data-slot":"sheet-header",className:Ye("flex flex-col gap-1.5 p-4",e),...t})}function gc({className:e,...t}){return m.jsx(J5,{"data-slot":"sheet-title",className:Ye("font-semibold text-foreground",e),...t})}function Vb({className:e,...t}){return m.jsx(Q5,{"data-slot":"sheet-description",className:Ye("text-sm text-muted-foreground",e),...t})}const Yde={claude:"Claude Code",codex:"Codex",kimi:"Kimi Code"},lI=["claude","codex","kimi"];function Yb(e){return Yde[e]}function oF(e,t){return lI.indexOf(e)-lI.indexOf(t)}function Yp(e){return e.provider}const T1=60*1e3,R1=60*T1,Kde=24*R1;function aF(e,t=Date.now()){const n=t-e;if(n<T1)return"刚刚";if(n<R1)return`${Math.floor(n/T1)} 分钟前`;if(n<Kde)return`${Math.floor(n/R1)} 小时前`;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 cI={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 A1(e){return e.kind!=="terminal"?cI[e.state]:e.state==="terminated"?cI.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 Gde({session:e}){const t=A1(e);return m.jsx("span",{className:Ye("inline-block size-2 rounded-full shrink-0",t.dot),"aria-label":`会话状态:${t.label}`,role:"status"})}function Xde({mode:e}){if(e!=="pty"&&e!=="json")return null;const t=e==="json"?"聊天视图":"终端视图",n=e==="json"?EC:kC;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 Zde({session:e,selected:t,now:n,onClick:r,onRename:i,onTerminate:s}){const o=Gr(w=>w.homePath),l=e.lastActive,u=e.cwd,d=ZC(e.name,o),f=JC(e,o),h=e.nameLocked&&e.name?e.name:f||(d==="New Session"?e.sessionId.slice(0,8):d),y=aF(l,n),g=e.mode==="pty"&&e.ptyOwner==="local-terminal",_=e.kind==="terminal"?"终止终端":g?"断开远程连接":"终止会话";return m.jsxs("li",{className:Ye("relative flex items-center gap-2 px-4 py-2 w-full min-w-0 transition-colors","min-h-[44px]","hover:bg-accent",t&&"dev-sidebar-active-row"),"data-slot":"session-row","data-session-id":e.sessionId,"data-selected":t,children:[t&&m.jsx("span",{className:"dev-sidebar-active-indicator absolute left-0 top-0 bottom-0 w-[2px]","aria-hidden":"true"}),m.jsxs("button",{type:"button","data-slot":"session-row-select",onClick:r,className:"flex min-h-11 flex-col justify-center gap-1 flex-1 min-w-0 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring rounded-sm md:min-h-0","aria-pressed":t,children:[m.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[m.jsx(Gde,{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(Xde,{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:Yb(e.provider)}),m.jsx("span",{className:"text-muted-foreground/60 shrink-0","aria-hidden":"true",children:"·"})]}),m.jsx("span",{className:Ye("shrink-0",A1(e).text),children:A1(e).label}),y&&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:y})]})]})]}),(i||s)&&m.jsxs(_f,{children:[m.jsx(wf,{asChild:!0,children:m.jsx(yt,{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(hb,{"aria-hidden":"true"})})}),m.jsxs(xf,{align:"end","data-slot":"session-row-menu",children:[i&&m.jsx(ti,{"data-slot":"session-row-rename-item",onSelect:w=>{w.stopPropagation(),i()},children:"重命名"}),s&&m.jsx(ti,{variant:"destructive","data-slot":"session-row-terminate-item",onSelect:w=>{w.stopPropagation(),s()},children:_})]})]})]})}function yo(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 Jde({session:e,now:t,disabled:n,loading:r,onClick:i,modeTag:s}){const o=m.jsx(Qde,{title:e.title,modeTag:s}),l=m.jsx("span",{className:"text-xs text-muted-foreground tabular-nums",children:aF(e.updatedAt,t)}),u=m.jsxs("span",{className:"flex min-w-0 flex-1 flex-col gap-0.5",children:[o,l]});return m.jsx("li",{"data-slot":"history-row","data-session-id":e.id,"data-loading":r?"true":void 0,className:"group w-full flex items-stretch",children:m.jsxs("button",{type:"button",onClick:i,disabled:n,"data-slot":"history-row-primary",className:Ye("min-w-0 flex-1 flex items-start gap-2 pl-10 pr-4 py-2 min-h-[50px]","text-left transition-colors outline-none","hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring","disabled:opacity-50 disabled:cursor-wait disabled:hover:bg-transparent"),"aria-label":`恢复会话:${e.title}`,children:[u,m.jsx(CV,{className:Ye("mt-0.5 size-3.5 shrink-0 text-muted-foreground transition-opacity",r?"animate-pulse opacity-100":"opacity-0 group-hover:opacity-100 group-focus-visible:opacity-100"),"aria-hidden":"true"})]})})}function Qde({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(efe,{mode:t})]})}function efe({mode:e}){const t=e==="json"?"聊天视图":"终端视图",n=e==="json"?EC:kC;return m.jsx("span",{"data-slot":"history-mode-tag","data-mode":e,role:"img","aria-label":t,title:t,className:Ye("inline-flex size-5 shrink-0 items-center justify-center rounded border","border-border bg-muted/50 text-muted-foreground"),children:m.jsx(n,{className:"size-3","aria-hidden":"true"})})}function lF({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(_K,{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 tfe({now:e}){const t=Gr(I=>I.homePath),n=Ht(I=>I.historySessions),r=Ht(I=>I.historyLoadStatus),[i,s]=b.useState(null),[o,l]=b.useState(null),[u,d]=b.useState("json"),[f,h]=b.useState("default"),[y,g]=b.useState(!1),[_,w]=b.useState(new Set),[S,x]=b.useState(new Set),k=Cs(),R=b.useMemo(()=>{const I=new Map;for(const N of n){const L=Yp(N);let B=I.get(L);B||(B=new Map,I.set(L,B));const P=cF(N.projectDir),D=B.get(P);D?D.sessions.push(N):B.set(P,{dir:P,sessions:[N]})}return Array.from(I.entries()).sort(([N],[L])=>oF(N,L)).map(([N,L])=>({provider:N,sessions:Array.from(L.values()).flatMap(B=>B.sessions),projects:Array.from(L.values()).map(B=>({dir:B.dir,shortDir:$p(B.dir,t,{compact:!0}),sessions:B.sessions}))}))},[n,t]);function A(I){l(I),d(nfe(I)),h(rfe(I))}async function O(I,N,L){if(i)return;const B=Ft;if(!B){Ue.error("请先连接开发机");return}s(I.id);const P=Yp(I);try{const D=await B.createSession({kind:"agent",cwd:I.projectDir,mode:N,provider:P,resumeSessionId:I.id,...L?{permissionMode:L}:{}});if(!D.success){if(D.errorCode===Pr.SESSION_ALREADY_ACTIVE){Ht.getState().setCodexActiveWriterConflict({...D.activeWriterPid?{activeWriterPid:D.activeWriterPid}:{}}),l(null);return}Ue.error(`恢复失败:${D.error}`);return}if(D.kind!=="agent"){Ue.error("恢复失败:开发机返回了错误的会话类型");return}const F={sessionId:D.sessionId,kind:"agent",...D.name!==void 0?{name:D.name}:{},...D.nameLocked!==void 0?{nameLocked:D.nameLocked}:{},state:"idle",cwd:D.cwd,lastActive:D.lastActive,provider:D.provider},q=D.mode==="pty"?{...F,mode:"pty",ptyOwner:D.ptyOwner}:{...F,mode:"json"};Ht.getState().addSession(q),k(`/chat/${D.sessionId}?mode=${D.mode}`),l(null)}catch(D){Ue.error(`恢复失败:${D instanceof Error?D.message:String(D)}`)}finally{s(null)}}function T(){const I=Ft;!I||Ht.getState().historyLoadStatus==="loading"||YC(I).then(N=>{N.status==="failed"&&Ue.error(N.error instanceof Error?N.error.message:String(N.error))})}function M(I,N){const L=uI(I,N);x(B=>{const P=new Set(B);return P.has(L)?P.delete(L):P.add(L),P})}function z(I){w(N=>{const L=new Set(N);return L.has(I)?L.delete(I):L.add(I),L})}const Y=n.length>0,U=r==="loading",G=o?uF():[];return m.jsxs("div",{"data-slot":"history-list",className:"flex flex-col",children:[m.jsxs("div",{className:"flex min-h-11 w-full items-center gap-1.5 px-4 py-1.5 md:min-h-[36px]",children:[m.jsxs("button",{type:"button",onClick:()=>Y&&g(I=>!I),disabled:!Y,"aria-expanded":Y?y:void 0,"data-slot":"history-section-header","data-expanded":y,className:Ye("flex min-w-0 flex-1 items-center gap-1.5 rounded-md py-0.5 text-left","transition-colors outline-none","hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring","disabled:cursor-default disabled:hover:text-inherit"),children:[m.jsxs("h3",{className:"min-w-0 text-sm font-semibold text-foreground",children:["全部会话",Y?m.jsxs("span",{className:"ml-1 text-muted-foreground/70 font-normal",children:["· ",n.length]}):null]}),Y?m.jsx(Hd,{className:Ye("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",y&&"rotate-90"),"aria-hidden":"true"}):null]}),m.jsx(yt,{type:"button",variant:"ghost",size:"icon-sm","aria-label":"刷新全部会话","aria-busy":U,title:U?"正在加载":"刷新",onClick:T,disabled:U,"data-slot":"history-refresh",className:"size-11 md:size-8",children:m.jsx(fm,{className:Ye("size-3.5",U&&"animate-spin motion-reduce:animate-none"),"aria-hidden":"true"})})]}),!Y&&U&&m.jsxs("div",{className:"flex items-center gap-2 px-4 py-3 text-sm text-muted-foreground/80","data-slot":"history-loading",role:"status","aria-live":"polite",children:[m.jsx(di,{className:"size-3.5 shrink-0 animate-spin motion-reduce:animate-none","aria-hidden":"true"}),m.jsx("span",{children:"正在加载会话记录..."})]}),!Y&&r==="idle"&&m.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/80","data-slot":"history-idle",role:"status",children:"会话记录尚未加载"}),!Y&&r==="error"&&m.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/80","data-slot":"history-error",role:"status",children:"会话记录加载失败,请点击刷新重试"}),Y&&r==="error"&&m.jsx("div",{className:"px-4 pb-2 text-xs text-muted-foreground/80","data-slot":"history-stale",role:"status",children:"刷新失败,当前显示上次加载的结果"}),!Y&&r==="loaded"&&m.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/70","data-slot":"history-empty",children:"暂无会话记录"}),Y&&y&&m.jsx("ul",{role:"list",className:"flex flex-col",children:R.map(I=>{const N=_.has(I.provider);return m.jsxs("li",{children:[m.jsxs("button",{type:"button",onClick:()=>z(I.provider),"aria-expanded":!N,"data-slot":"history-provider-header","data-expanded":!N,className:Ye("w-full flex items-center gap-2 px-4 pt-2 pb-1 min-h-[32px]","text-xs text-muted-foreground text-left transition-colors outline-none","hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring"),children:[m.jsx("span",{className:"font-mono",children:Yb(I.provider)}),m.jsx("span",{className:"h-px flex-1 bg-border/70","aria-hidden":"true"}),m.jsx("span",{className:"tabular-nums",children:I.sessions.length}),m.jsx(Hd,{className:Ye("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:I.projects.map(L=>{const B=uI(I.provider,L.dir),P=S.has(B);return m.jsxs("li",{children:[m.jsxs("button",{type:"button",onClick:()=>M(I.provider,L.dir),"aria-expanded":P,"data-slot":"history-group-header","data-expanded":P,className:Ye("w-full flex items-center gap-1.5 pl-6 pr-4 py-2 min-h-[36px]","text-left transition-colors outline-none","hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring"),children:[m.jsx("span",{className:"text-sm font-mono truncate flex-1 min-w-0",title:L.dir,children:L.shortDir}),m.jsx("span",{className:"text-xs text-muted-foreground/80 tabular-nums shrink-0",children:L.sessions.length}),m.jsx(Hd,{className:Ye("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",P&&"rotate-90"),"aria-hidden":"true"})]}),P&&m.jsx("ul",{role:"list",className:"flex flex-col",children:L.sessions.map(D=>m.jsx(Jde,{session:D,now:e,disabled:i!==null,loading:i===D.id,onClick:()=>A(D),modeTag:D.preferredMode},D.id))})]},B)})})]},I.provider)})}),m.jsx(ife,{session:o,open:o!==null,modes:G,mode:u,permissionMode:f,submitting:i!==null,onOpenChange:I=>{I||l(null)},onModeChange:d,onPermissionModeChange:h,onConfirm:()=>{o&&O(o,u,f)}})]})}function uI(e,t){return`${e}:${cF(t)}`}function cF(e){const t=e.trim();return!t||t==="/"?t||"/":t.replace(/\/+$/,"")||"/"}function uF(){return["json","pty"]}function nfe(e){const t=uF();return e.preferredMode&&t.includes(e.preferredMode)?e.preferredMode:t[0]??"json"}function rfe(e){return Yp(e)==="codex"?"auto":"default"}function ife({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),y=i==="bypassPermissions",g=yo("(min-width: 768px)"),_=e?Yp(e):null,w=_==="codex",S=_==="kimi";b.useEffect(()=>{t||h(!1)},[t]);const x=f?m.jsx(lF,{providerLabel:e?Yb(Yp(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(dI,{checked:r==="json",label:"聊天",icon:m.jsx(EC,{className:"size-4","aria-hidden":"true"}),disabled:s,onClick:()=>l("json")}),n.includes("pty")&&m.jsx(dI,{checked:r==="pty",label:"终端",icon:m.jsx(kC,{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(bv,{checked:i==="default",label:S?"手工审批":"严格审批",description:S?"工具调用会在 Web 中请求确认。":"所有需要权限的操作都要确认。",disabled:s,onClick:()=>u("default")}),m.jsx(bv,{checked:i==="auto",label:w?"按需审批":S?"自动审批":"自动判定",description:w?"Codex 在需要时请求确认。":S?"Kimi Code 使用原生 yolo 模式自动审批。":"交给 Agent CLI 的原生策略判断。",disabled:s,onClick:()=>u("auto")}),S&&m.jsx(bv,{checked:i==="plan",label:"只读规划",description:"Kimi Code 使用只读规划模式。",disabled:s,onClick:()=>u("plan")}),m.jsx(bv,{checked:i==="bypassPermissions",label:S?"全自动":"跳过全部审批",description:S?"危险模式,Kimi Code 将全自动执行。":"危险模式,会跳过工具审批和部分沙箱保护。",destructive:!0,disabled:s,onClick:()=>u("bypassPermissions")})]})]})]}),k=m.jsxs(m.Fragment,{children:[m.jsx(yt,{type:"button",variant:"ghost",disabled:s,onClick:()=>{f?h(!1):o(!1)},children:f?"返回":"取消"}),m.jsx(yt,{type:"button",variant:f?"destructive":"default",disabled:s,onClick:()=>{if(y&&!f){h(!0);return}d()},"data-slot":f?"bypass-permission-confirm":void 0,children:s?"恢复中...":f?"确认":"恢复"})]});return g?m.jsx(es,{open:t,onOpenChange:o,children:m.jsxs(ts,{focusSurfaceOnOpen:!0,className:"min-w-0 sm:max-w-md","data-slot":"history-restore-dialog",children:[m.jsxs(ns,{className:"min-w-0",children:[m.jsx($i,{children:f?"跳过全部审批?":"恢复会话"}),m.jsx(Es,{className:"min-w-0 truncate pr-10 sm:pr-0",title:e==null?void 0:e.title,children:(e==null?void 0:e.title)??""})]}),x,m.jsx(Vs,{children:k})]})}):m.jsx(pc,{open:t,onOpenChange:o,children:m.jsxs(mc,{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(Eu,{className:"min-w-0 shrink-0 px-4 pb-2 pt-4 text-left",children:[m.jsx(gc,{children:f?"跳过全部审批?":"恢复会话"}),m.jsx(Vb,{className:"min-w-0 truncate pr-10",title:e==null?void 0:e.title,children:(e==null?void 0:e.title)??""})]}),m.jsx("div",{className:"min-h-0 overflow-y-auto px-4 pb-3","data-slot":"history-restore-body",children:x}),m.jsx("div",{className:"shrink-0 border-t border-border/70 bg-background px-4 pb-[max(theme(spacing.4),env(safe-area-inset-bottom))] pt-3","data-slot":"history-restore-footer",children:m.jsx("div",{className:"flex flex-col-reverse gap-2 [&_button]:min-h-11 [&_button]:w-full",children:k})})]})})}function dI({checked:e,label:t,icon:n,disabled:r,onClick:i}){return m.jsxs("button",{type:"button",role:"radio","aria-label":t,"aria-checked":e,disabled:r,onClick:i,className:Ye("grid min-h-11 w-full min-w-0 max-w-full grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-2 rounded-md border px-3 text-sm outline-none transition-colors md:h-10 md:min-h-0","focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-wait disabled:opacity-60",e?"border-primary text-foreground":"border-border text-muted-foreground hover:bg-accent/60 hover:text-foreground"),children:[n,m.jsx("span",{className:"min-w-0 text-center",children:t}),m.jsx(ua,{className:Ye("size-3.5 justify-self-end transition-opacity",e?"opacity-100":"opacity-0"),"aria-hidden":"true"})]})}function bv({checked:e,label:t,description:n,destructive:r,disabled:i,onClick:s}){return m.jsxs("button",{type:"button",role:"radio","aria-label":t,"aria-checked":e,disabled:i,onClick:s,className:Ye("grid w-full min-w-0 max-w-full grid-cols-[auto_minmax(0,1fr)_auto] items-start gap-3 rounded-md border p-3 text-left outline-none transition-colors","focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-wait disabled:opacity-60",e?r?"border-destructive/70":"border-primary":"border-border hover:bg-accent/60"),children:[m.jsx("span",{className:Ye("mt-0.5 flex size-4 shrink-0 items-center justify-center rounded-full border",e?r?"border-destructive":"border-primary":"border-muted-foreground/50"),"aria-hidden":"true",children:e&&m.jsx("span",{className:Ye("size-2 rounded-full",r?"bg-destructive":"bg-primary")})}),m.jsxs("span",{className:"grid min-w-0 gap-1",children:[m.jsx("span",{className:Ye("text-sm font-medium",r?"text-destructive":"text-foreground"),children:t}),m.jsx("span",{className:"min-w-0 break-words text-xs leading-5 text-muted-foreground",children:n})]}),e&&m.jsx(ua,{className:Ye("mt-0.5 size-4 shrink-0",r?"text-destructive":"text-primary"),"aria-hidden":"true"})]})}function Kb({...e}){return m.jsx(Vue,{"data-slot":"select",...e})}function Gb({...e}){return m.jsx(Kue,{"data-slot":"select-value",...e})}function Xb({className:e,size:t="default",children:n,...r}){return m.jsxs(Yue,{"data-slot":"select-trigger","data-size":t,className:Ye("flex w-fit items-center justify-between gap-2 rounded-md border border-input bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/75 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-[placeholder]:text-muted-foreground data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 dark:bg-input/30 dark:hover:bg-input/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground",e),...r,children:[n,m.jsx(Gue,{asChild:!0,children:m.jsx(sc,{className:"size-4 opacity-50"})})]})}function Zb({className:e,children:t,position:n="item-aligned",align:r="center",inert:i,"aria-disabled":s,...o}){const l=Tm();return m.jsx(Xue,{children:m.jsxs(Zue,{"data-slot":"select-content",className:Ye("relative z-50 max-h-(--radix-select-content-available-height) min-w-[8rem] origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",n==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",e),position:n,align:r,inert:l||i?!0:void 0,"aria-disabled":l?!0:s,"data-relay-interaction-blocked":l?"true":void 0,...o,children:[m.jsx(sfe,{}),m.jsx(Jue,{className:Ye("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1"),children:t}),m.jsx(ofe,{})]})})}function Jb({className:e,children:t,...n}){return m.jsxs(Que,{"data-slot":"select-item",className:Ye("relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2",e),...n,children:[m.jsx("span",{"data-slot":"select-item-indicator",className:"absolute right-2 flex size-3.5 items-center justify-center",children:m.jsx(tde,{children:m.jsx(ua,{className:"size-4"})})}),m.jsx(ede,{children:t})]})}function sfe({className:e,...t}){return m.jsx(nde,{"data-slot":"select-scroll-up-button",className:Ye("flex cursor-default items-center justify-center py-1",e),...t,children:m.jsx(wC,{className:"size-4"})})}function ofe({className:e,...t}){return m.jsx(rde,{"data-slot":"select-scroll-down-button",className:Ye("flex cursor-default items-center justify-center py-1",e),...t,children:m.jsx(sc,{className:"size-4"})})}function afe(e,t,n){var u;if(t==="insert"){const d=e.split("@").pop()??"",f=au((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:Us(r),query:""};const i=bb(r,e);if(!i)return{currentPath:"",query:""};const s=qC(i),o=au(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:Us(i),query:""}:{currentPath:Us(s),query:i.slice(i.lastIndexOf(o)+1).toLowerCase()}}function b0(e,t){return bb(e,t)}const dF=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:y},g){const _=Gr(Te=>f?Te.treeWithHidden:Te.tree),w=Gr(Te=>Te.cwd),S=Gr(Te=>Te.homePath),x=Ae(Te=>Te.selectedProxyId),k=o==="insert"?w:S||w,R=b.useMemo(()=>new Set(_.keys()),[_]),A=b.useMemo(()=>afe(t,o,{baseCwd:k,knownDirs:R}),[t,o,k,R]),O=A.currentPath,T=b.useMemo(()=>b0(k,O),[k,O]),M=A.query,z=b.useRef(new Map),[Y,U]=b.useState(!1),[G,I]=b.useState(""),[N,L]=b.useState(!1),[B,P]=b.useState(null),[D,F]=b.useState(0),[q,j]=b.useState(!1),[V,K]=b.useState(null),[$,te]=b.useState(null);b.useEffect(()=>{if(!q)return;let Te=!1;K(null),te(null);const Ke=Ft==null?void 0:Ft.requestFileSystemRoots();return Ke||te("尚未连接开发机"),Ke==null||Ke.then(Xe=>{Te||(Xe.error!==void 0||Xe.errorCode!==void 0?te(Xe.error||"读取失败"):K(Xe.roots))},Xe=>{Te||te(Xe instanceof Error?Xe.message:"读取失败")}),()=>{Te=!0}},[q,x,D]),b.useEffect(()=>{if(!T||q)return;const Te=`${x}\0${f?"hidden":"default"}\0${T}`;if(_.has(T))return;const Ke=Ft;if(!Ke)return;let Xe=!1;P(it=>(it==null?void 0:it.path)===T?null:it);let Se=z.current.get(Te);if(!Se){Se=Ke.requestDirectoryList(T,{includeHidden:f}),z.current.set(Te,Se);const it=()=>{z.current.get(Te)===Se&&z.current.delete(Te)};Se.then(it,it)}return Se.then(it=>{if(!Xe){if(it.error!==void 0||it.errorCode!==void 0){P({path:T,message:it.error||"读取失败"});return}Gr.getState().setDirEntries(it.path,it.entries,it.includeHidden)}},it=>{Xe||P({path:T,message:it instanceof Error?it.message:"读取失败"})}),()=>{Xe=!0}},[T,f,_,D,q,x]);const re=q?$?{message:$}:null:(B==null?void 0:B.path)===T?B:null,ee=q?V===null&&!$:!_.has(T)&&!re,X=b.useMemo(()=>d==null?void 0:d.map(Te=>Te.startsWith(".")?Te.toLowerCase():`.${Te.toLowerCase()}`),[d]),ae=b.useMemo(()=>{if(q){if(!V)return[];const Ke=[...S?[{name:"主目录",path:S}]:[],...V];return[...new Map(Ke.map(Xe=>[Xe.path,Xe])).values()].map(Xe=>({...Xe,isDir:!0}))}let Te=_.get(T)??[];return u?Te=Te.filter(Ke=>Ke.isDir):X!=null&&X.length&&(Te=Te.filter(Ke=>Ke.isDir||X.some(Xe=>Ke.name.toLowerCase().endsWith(Xe)))),M&&(Te=Te.filter(Ke=>Ke.name.toLowerCase().includes(M))),Te},[_,T,M,u,X,q,V,S]),[ne,ce]=b.useState(h?0:-1);b.useEffect(()=>ce(h?0:-1),[h,O,M,q]),b.useEffect(()=>{U(!1),I("")},[T]),b.useEffect(()=>{ne>=ae.length&&ae.length>0&&ce(ae.length-1)},[ae.length,ne]);const _e=b.useRef(null),xe=b.useRef(!1);b.useEffect(()=>{var Ke;if(!xe.current)return;xe.current=!1;const Te=(Ke=_e.current)==null?void 0:Ke.querySelector(`[data-entry-index="${ne}"]`);Te==null||Te.scrollIntoView({block:"nearest"})},[ne]);const We=b.useCallback(Te=>{const Ke=au(k),Xe=`${Us(O,k)}${Te.name}${Te.isDir?Ke:""}`;if(o==="insert")return Xe.replace(Ke==="\\"?/^\.[\\/]/:/^\.\//,"");const Se=b0(k,Xe);return Te.isDir?Us(Se):Se},[k,O,o]),De=b.useCallback(Te=>{const Ke=b0(k,Te);if(!Ke)return;j(!1);const Xe=Us(Ke);if(o==="select"){r(Xe);return}n(Xe)},[k,o,r,n]),Pt=b.useCallback(Te=>{if(Te.path){De(Te.path);return}const Ke=We(Te);if(Te.isDir){De(Ke);return}n(Ke)},[We,De,n]);async function tt(){const Te=a2(T,G);if(!(!Te||!s)){L(!0);try{const Ke=await s(Te);if(!Ke)return;if(I(""),U(!1),i){i(Us(Ke));return}De(Ke)}finally{L(!1)}}}b.useImperativeHandle(g,()=>({handleKey(Te){return ae.length===0?!1:Te.key==="ArrowDown"?(xe.current=!0,ce(Ke=>Math.min(ae.length-1,Ke+1)),!0):Te.key==="ArrowUp"?(xe.current=!0,ce(Ke=>Math.max(0,Ke-1)),!0):Te.key==="Enter"&&ne>=0&&!Te.nativeEvent.isComposing?(Pt(ae[ne]),!0):!1}}),[ae,ne,Pt]);const lt=b.useMemo(()=>qC(T),[T]),$e=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",Fe=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:$e,"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:[y?m.jsx("p",{className:"mb-2 truncate text-xs text-muted-foreground","data-slot":"file-path-picker-title",children:y}):null,m.jsx("p",{className:"truncate font-mono text-xs text-foreground","data-slot":"file-path-picker-current-directory",title:q?void 0:T,children:q?"磁盘/挂载点":$p(T,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":q,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(Te=>!Te),U(!1)},children:q?"返回目录":"磁盘/挂载点"}),q?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:!T,onClick:()=>{T===lt?j(!0):De(lt)},children:"上一级"})]}),!q&&(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:!T||N,onClick:()=>U(Te=>!Te),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:!T,onClick:()=>i(Us(T)),children:"选定"}):null]}):null]}),Y&&!q?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:Te=>I(Te.target.value),onKeyDown:Te=>{Te.key==="Enter"&&!Te.nativeEvent.isComposing&&(Te.preventDefault(),tt()),Te.key==="Escape"&&(U(!1),I(""))},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:!a2(T,G)||N,onClick:()=>void tt(),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":q,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(Te=>!Te),children:q?"返回目录":"磁盘/挂载点"}),m.jsx("span",{className:"truncate font-mono text-xs text-muted-foreground",children:q?"磁盘/挂载点":$p(T,S)})]}),m.jsx("div",{className:Fe,"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:q?"无法读取磁盘位置":"无法读取这个文件夹"}),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(Te=>Te+1),children:"重试"})]}):ae.length===0?m.jsx("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:ee?"加载中...":"没有匹配的路径"}):m.jsx("ul",{ref:_e,role:"list",className:"flex flex-col",children:ae.map((Te,Ke)=>m.jsx("li",{children:m.jsxs("button",{type:"button",onClick:()=>Pt(Te),onMouseEnter:()=>ce(Ke),className:Ye("w-full flex min-h-11 items-center gap-2 px-3 py-2 text-sm text-left transition-colors md:h-9 md:min-h-0 md:py-0",Ke===ne&&"bg-[color-mix(in_srgb,var(--primary)_15%,transparent)]",Te.isDir&&"font-semibold"),"data-slot":"file-entry","data-entry-type":Te.isDir?"dir":"file","data-entry-name":Te.name,"data-entry-index":Ke,title:Te.path,children:[m.jsxs("span",{className:"min-w-0 truncate font-mono text-[13px]",children:[Te.name,Te.isDir&&!Te.path?"/":""]}),Te.path&&Te.path!==Te.name?m.jsx("span",{className:"ml-auto min-w-0 truncate text-xs font-normal text-muted-foreground",children:Te.path}):null]})},Te.path??Te.name))})})]})});function fI(e,t,n){const r=lp(e,t);return r?n==="file"?Us(qC(r)):n==="directory"?Us(r):r:t}function lp(e,t){const n=oa(e,t);return n?e.endsWith("/")||au(n)==="\\"&&e.endsWith("\\")?Us(n):n:""}function Nk({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:y,autoFocus:g,"aria-describedby":_,"aria-invalid":w,"data-slot":S,className:x,onKeyDown:k}){const R=b.useId(),A=f??`remote-path-${R}`,O=`${A}-label`,T=Gr(ee=>ee.homePath),M=yo("(pointer: coarse), (hover: none)"),z=pf().deviceKind,Y=M||z==="phone"||z==="tablet",[U,G]=b.useState(!1),[I,N]=b.useState(()=>fI(e,T,n)),[L,B]=b.useState(e),P=b.useRef(null),D=b.useRef(null),F=b.useRef(null);b.useEffect(()=>{U||document.activeElement===D.current||L===e||B(e)},[L,U,e]),b.useEffect(()=>{if(!U)return;function ee(X){const ae=P.current,ne=X.target;ae&&(X.composedPath().includes(ae)||ne instanceof Node&&ae.contains(ne))||(G(!1),B(e))}return document.addEventListener("click",ee),()=>document.removeEventListener("click",ee)},[U,e]),b.useEffect(()=>{o&&(G(!1),B(e))},[o,e]);const q=n!=="file";function j(){if(o)return;const ee=fI(e,T,n);N(ee),B(e),G(!0)}function V(){G(!1),B(e)}function K(ee){const X=lp(ee,T);X&&(N(X),B(X),t(X),G(!1))}function $(ee){const X=lp(ee,T);X&&N(X)}function te(ee){var X;if(U&&((X=F.current)!=null&&X.handleKey(ee))){ee.preventDefault();return}if(ee.key==="Escape"&&U){ee.preventDefault(),V();return}k==null||k(ee)}const re=U?m.jsx("div",{className:Ye(Y&&"mt-2"),"data-slot":"remote-path-browser",children:m.jsx(dF,{ref:F,mode:"select",placement:Y?"inline":"floating",filter:I,dirsOnly:n==="directory",fileExtensions:r,includeHidden:i,autoHighlightFirst:!Y,title:l,onNavigate:$,onSelect:K,onSelectCurrentDirectory:q?K:void 0,onCreateDirectory:s})}):null;return m.jsxs("div",{className:Ye("flex min-w-0 flex-col gap-1",x),children:[m.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-3",children:[m.jsx("span",{id:O,className:"min-w-0 text-sm",children:u}),d?m.jsx("div",{className:"flex shrink-0 items-center gap-4",children:d}):null]}),m.jsxs("div",{ref:P,className:"relative min-w-0",onBlur:ee=>{if(!U||Y)return;const X=ee.relatedTarget;X instanceof Node&&ee.currentTarget.contains(X)||window.setTimeout(()=>{var ae;(ae=P.current)!=null&&ae.contains(document.activeElement)||V()},0)},children:[m.jsxs("div",{className:"relative flex min-w-0 items-center",children:[m.jsx("input",{ref:D,id:A,type:"text","aria-labelledby":O,"aria-describedby":_,"aria-invalid":w,name:h,required:y,autoFocus:g&&!Y,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off",spellCheck:!1,disabled:o,value:L,"data-slot":S,"data-path-control":"input",onFocus:()=>{Y?G(!1):j()},onBlur:()=>B(e),onKeyDown:te,onChange:ee=>{const X=ee.target.value,ae=lp(X,T);B(X),N(ae||T),t(ae||X),G(!Y)},onPaste:ee=>{const X=ee.clipboardData.getData("text").trim(),ae=X.startsWith('"')&&X.endsWith('"')?X.slice(1,-1):X,ne=lp(ae,T);ne&&(ee.preventDefault(),B(ne),N(ne),t(ne),G(!Y))},placeholder:l,className:"min-h-11 min-w-0 w-full rounded-md border border-border bg-input pl-3 pr-12 font-mono text-base outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60 md:h-9 md:min-h-0 md:text-sm"}),m.jsx("button",{type:"button","aria-label":typeof u=="string"?`浏览${u}`:"浏览路径","aria-expanded":U,"aria-controls":`${A}-browser`,disabled:o,"data-slot":"remote-path-browse",onClick:()=>{var ee;Y&&((ee=D.current)==null||ee.blur()),U?V():j()},className:"absolute inset-y-0 right-0 flex w-11 items-center justify-center rounded-r-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60",children:m.jsx(bY,{className:"size-5","aria-hidden":"true"})})]}),m.jsx("div",{id:`${A}-browser`,children:re})]})]})}const hI="工作目录不存在或不可访问:",lfe=[{value:"default",label:"严格审批"},{value:"auto",label:"自动判定"},{value:"acceptEdits",label:"自动接受编辑"},{value:"plan",label:"只读规划"},{value:"bypassPermissions",label:"跳过全部审批"}],fF=[{value:"auto",label:"按需审批"},{value:"bypassPermissions",label:"跳过全部审批"}],hF=[{value:"default",label:"手工审批"},{value:"auto",label:"自动审批"},{value:"plan",label:"只读规划"},{value:"bypassPermissions",label:"全自动"}],Kp={claude:"Claude Code",codex:"Codex",kimi:"Kimi Code"};function cfe(e,t){return t!==Pr.PATH_NOT_FOUND||!e.startsWith(hI)?null:e.slice(hI.length).trim()||null}function pF(e,t){if(!t)return{label:"检测中",disabled:!0};const n=t[e];return n.available?{label:"可用",disabled:!1,title:n.command}:{label:"未找到",disabled:!0,title:n.error}}function ufe(e,t){return e==="codex"?fF.some(n=>n.value===t)?t:"auto":e==="kimi"?hF.some(n=>n.value===t)?t:"default":t}async function dfe({relay:e,agentCli:t,form:n,timeoutMs:r=UC}){var d,f;const i=n.cwd.trim();if(!i)return{type:"validation_error",message:"请输入工作目录"};if(!e)return{type:"relay_missing",message:"请先连接开发机"};if(pF(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?`${Kp[n.provider]} 不可用:${h}`:`${Kp[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=cfe(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 y=((f=h.name)==null?void 0:f.trim())||void 0,g={sessionId:h.sessionId,kind:"agent",name:y,...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 ffe({relay:e,shell:t,timeoutMs:n=UC}){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 hfe=["claude","codex","kimi"];function pfe({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,y=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(Kb,{value:t,disabled:i,onValueChange:_=>s(_),children:[m.jsx(Xb,{className:"min-h-11 w-full md:min-h-0","aria-label":"Agent CLI","data-slot":"agent-cli-provider-select",children:m.jsx(Gb,{})}),m.jsx(Zb,{"data-slot":"agent-cli-provider-options",children:hfe.map(_=>m.jsx(Jb,{value:_,className:"min-h-11 md:min-h-0",children:Kp[_]},_))})]}),m.jsxs("div",{className:"relative min-w-0","data-slot":"agent-cli-path-card",children:[m.jsx(Nk,{id:`agent-cli-path-${t}`,"data-slot":"agent-cli-path",label:"CLI 路径",value:y,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 cp({open:e,onOpenChange:t}){var X;const[n,r]=b.useState(""),[i,s]=b.useState(""),[o,l]=b.useState("claude"),[u,d]=b.useState("pty"),[f,h]=b.useState("default"),[y,g]=b.useState(!1),[_,w]=b.useState(!1),[S,x]=b.useState(null),[k,R]=b.useState(null),[A,O]=b.useState(""),[T,M]=b.useState(!1),z=b.useRef(e);z.current=e;const Y=Cs(),U=Gr(ae=>ae.homePath),G=Gr(ae=>ae.agentCli),I=yo("(min-width: 768px)");b.useEffect(()=>{e&&!i&&U&&s(U)},[e,U,i]),b.useEffect(()=>{if(!e||U&&G)return;const ae=Ft==null?void 0:Ft.requestProxyInfo();ae&&ae.then(ne=>{const ce=Gr.getState();ce.setHomePath(ne.homePath),ce.setAgentCli(ne.agentCli)}).catch(ne=>{console.error("[create-session-dialog] requestProxyInfo failed",ne)})},[e,U,G]);function N(){r(""),s(""),l("claude"),d("pty"),h("default"),g(!1),x(null),R(null),O(""),M(!1)}function L(){if(f==="bypassPermissions"){g(!0);return}V()}async function B(){await V(),z.current&&g(!1)}const P=o==="codex"?fF:o==="kimi"?hF:lfe,D=pF(o,G),F=k===o&&A.trim()!==(((X=G==null?void 0:G[o])==null?void 0:X.command)??""),q=_||T||D.disabled||F;function j(ae){const ne=ufe(ae,f);ne!==f&&h(ne)}async function V(ae){x(null),w(!0);try{const ne=await dfe({relay:Ft,agentCli:G,form:{cwd:ae??i,name:n,provider:o,permissionMode:f,mode:u}});if(ne.type==="success"){if(Ht.getState().addSession(ne.session),!z.current)return;t(!1),N(),Y(ne.route);return}if(ne.type==="missing_cwd"&&x(ne.path),Ue.error(ne.message),ne.type==="validation_error"||ne.type==="relay_missing")return}finally{w(!1)}}async function K(ae){const ne=Ft;if(!ne)return Ue.error("请先连接开发机"),null;try{const ce=await ne.createDirectory(ae);return ce.success?(x(null),Ue.success("目录已创建"),ce.path):(Ue.error(`目录创建失败:${ce.error??"未知错误"}`),null)}catch(ce){return Ue.error(ce instanceof Error?ce.message:String(ce)),null}}function $(ae,ne){R(ae),O(ne)}async function te(){if(!k)return;const ae=k,ne=A.trim();if(!ne){Ue.error("请选择 Agent CLI 可执行文件");return}const ce=Ft;if(!ce){Ue.error("请先连接开发机");return}M(!0);try{const _e=await ce.updateAgentCliPath(ae,ne);if(_e.error||!_e.agentCli){Ue.error(`路径保存失败:${_e.error??"未知错误"}`);return}Gr.getState().setAgentCli(_e.agentCli),Ue.success(`${Kp[ae]} 路径已保存`),R(null),O("")}catch(_e){Ue.error(_e instanceof Error?_e.message:String(_e))}finally{M(!1)}}function re(ae){d(ae),j(o)}const ee=y?m.jsxs("div",{className:"grid min-w-0 gap-5","data-slot":"bypass-permission-confirmation",children:[m.jsx(lF,{providerLabel:Kp[o]}),m.jsxs(Vs,{children:[m.jsx(yt,{type:"button",variant:"ghost",className:"min-h-11 md:min-h-0",onClick:()=>g(!1),disabled:_,children:"返回"}),m.jsx(yt,{type:"button",variant:"destructive",className:"min-h-11 md:min-h-0",onClick:()=>void B(),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:ae=>{ae.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:ae=>r(ae.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(Nk,{id:"create-session-cwd",name:"dev-anywhere-session-cwd","data-slot":"create-session-cwd",label:"工作目录",value:i,selectionKind:"directory",placeholder:"选择工作目录",onCreateDirectory:K,onValueChange:ae=>{s(ae),x(null)}}),S?m.jsxs("section",{role:"status","aria-live":"polite",className:"rounded-md border border-primary/50 bg-primary/10 p-3",children:[m.jsx("p",{className:"text-sm font-medium",children:"工作目录不存在"}),m.jsx("p",{className:"mt-1 break-all font-mono text-xs text-muted-foreground",children:S})]}):null,m.jsxs("section",{"aria-label":"交互方式",className:"flex min-w-0 flex-col gap-2",children:[m.jsx("span",{className:"text-sm",children:"交互方式"}),m.jsxs("div",{className:"grid min-w-0 grid-cols-1 gap-2 sm:grid-cols-2",children:[m.jsxs("button",{type:"button","aria-pressed":u==="pty",onClick:()=>re("pty"),className:Ye("flex min-h-14 min-w-0 flex-col items-start justify-center gap-1 rounded-md border px-3 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring",u==="pty"?"border-primary/70 bg-primary/10":"border-border bg-muted/20"),children:[m.jsx("span",{className:"text-sm font-medium",children:"终端模式"}),m.jsx("span",{className:"text-xs text-muted-foreground",children:"像本地终端一样操作"})]}),m.jsxs("button",{type:"button","aria-pressed":u==="json",onClick:()=>re("json"),className:Ye("flex min-h-14 min-w-0 flex-col items-start justify-center gap-1 rounded-md border px-3 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring",u==="json"?"border-primary/70 bg-primary/10":"border-border bg-muted/20"),children:[m.jsx("span",{className:"text-sm font-medium",children:"聊天模式"}),m.jsx("span",{className:"text-xs text-muted-foreground",children:"气泡式对话,支持 Voice Pilot"})]})]})]}),m.jsx(pfe,{agentCli:G,provider:o,cliPathDraftProvider:k,cliPathDraft:A,savingCliPath:T,onProviderChange:ae=>{l(ae),j(ae),R(null),O("")},onCliPathDraftChange:$,onDiscardCliPathDraft:()=>{R(null),O("")},onSaveCliPath:()=>void te()}),m.jsxs("label",{className:"flex min-w-0 flex-col gap-2",children:[m.jsx("span",{className:"text-sm",children:"权限模式"}),m.jsxs(Kb,{value:f,onValueChange:ae=>h(ae),children:[m.jsx(Xb,{className:"w-full",children:m.jsx(Gb,{})}),m.jsx(Zb,{children:P.map(ae=>m.jsx(Jb,{value:ae.value,children:ae.label},ae.value))})]})]}),m.jsxs(Vs,{children:[m.jsx(yt,{type:"button",variant:"ghost",className:"min-h-11 md:min-h-0",onClick:()=>t(!1),disabled:_,children:"取消"}),m.jsx(yt,{type:"submit",className:"min-h-11 md:min-h-0",disabled:q,children:_?"创建中...":"创建"})]})]});return I?m.jsx(es,{open:e,onOpenChange:t,children:m.jsxs(ts,{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(ns,{children:m.jsx($i,{children:y?"跳过全部审批?":"新建会话"})}),ee]})}):m.jsx(pc,{open:e,onOpenChange:t,children:m.jsxs(mc,{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(Eu,{className:"px-0 pb-1 pt-0 text-left",children:m.jsx(gc,{children:y?"跳过全部审批?":"新建会话"})}),ee]})})}function up({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 y(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(es,{open:e,onOpenChange:r,children:m.jsx(ts,{className:"sm:max-w-md","data-slot":"session-rename-dialog",children:m.jsxs("form",{className:"grid gap-4",onSubmit:g=>void y(g),children:[m.jsxs(ns,{children:[m.jsx($i,{children:"重命名会话"}),m.jsx(Es,{children:"自定义名称会显示在会话列表和顶部标题中。"})]}),m.jsxs("div",{className:"grid gap-2",children:[m.jsx("label",{htmlFor:"session-rename-title",className:"text-sm font-medium",children:"会话标题"}),m.jsx("input",{id:"session-rename-title",value:o,autoFocus:!0,maxLength:100,"aria-invalid":!!u,"aria-describedby":u?"session-rename-error":void 0,className:Ye("h-10 rounded-md border border-input bg-background px-3 text-sm shadow-xs outline-none transition-[border-color,box-shadow]","placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/75","disabled:cursor-not-allowed disabled:opacity-50",u&&"border-destructive focus-visible:ring-destructive/20"),disabled:f,onChange:g=>{l(g.target.value),u&&d(null)}}),u?m.jsx("p",{id:"session-rename-error",className:"text-sm text-destructive",children:u}):null]}),m.jsxs(Vs,{children:[m.jsx(yt,{type:"button",variant:"outline",onClick:()=>r(!1),children:"取消"}),m.jsx(yt,{type:"submit",disabled:f,children:"保存"})]})]})})})}function mfe(e){return(e==null?void 0:e.kind)==="agent"&&e.mode==="pty"&&e.ptyOwner==="local-terminal"}function gfe(e){return(e==null?void 0:e.kind)==="terminal"}function vfe(e){return mfe(e)?{title:"断开远程连接?",description:"这只会断开当前页面和本地终端的连接,本地终端里的 Claude Code/Codex/Kimi Code 会继续运行。重新接入前,页面不能继续查看或输入这个会话。",confirmLabel:"断开远程连接",destructive:!1}:gfe(e)?{title:"终止终端?",description:"这会停止当前终端进程,并清理这个终端会话的运行状态。终止后不能继续输入,也无法恢复正在执行的命令。",confirmLabel:"终止终端",destructive:!0}:{title:"终止会话?",description:"这会停止当前 Agent 进程,并清理这个会话的运行状态。终止后不能继续输入,也无法恢复正在执行的任务。",confirmLabel:"终止会话",destructive:!0}}function _v({open:e,session:t,onOpenChange:n,onConfirm:r}){const i=vfe(t);function s(){t&&(r(t),n(!1))}return m.jsx(es,{open:e,onOpenChange:n,children:m.jsxs(ts,{"data-slot":"session-termination-dialog",children:[m.jsxs(ns,{children:[m.jsx($i,{children:i.title}),m.jsx(Es,{children:i.description})]}),m.jsxs(Vs,{children:[m.jsx(yt,{type:"button",variant:"ghost",onClick:()=>n(!1),children:"取消"}),m.jsx(yt,{type:"button",variant:i.destructive?"destructive":"default",onClick:s,"data-slot":"session-termination-confirm",children:i.confirmLabel})]})]})})}function mF(e){var t,n,r,i,s,o,l,u,d,f,h,y;return e.connected===!1||e.proxyOnline===!1?"disconnected":e.routeSessionEnded||((t=e.session)==null?void 0:t.state)==="terminated"?"terminated":((n=e.session)==null?void 0:n.state)==="error"?"error":e.hasPendingApproval||((r=e.session)==null?void 0:r.state)==="waiting_approval"?"waiting_approval":((i=e.session)==null?void 0:i.state)==="compacting"?"compacting":((s=e.session)==null?void 0:s.state)==="working"?"working":((o=e.session)==null?void 0:o.state)==="idle"?"idle":((l=e.agentStatus)==null?void 0:l.phase)==="waiting_permission"||((u=e.ptyState)==null?void 0:u.state)==="approval_wait"?"waiting_approval":((d=e.agentStatus)==null?void 0:d.phase)==="thinking"||((f=e.agentStatus)==null?void 0:f.phase)==="tool_use"||((h=e.agentStatus)==null?void 0:h.phase)==="outputting"||((y=e.ptyState)==null?void 0:y.state)==="working"?"working":"idle"}function yfe(e){if(e.session.state==="error")return"error";const t=mF(e);return t==="disconnected"?e.session.state:t}const bfe=new Set(["localhost","127.0.0.1","[::1]"]),N1={cloudflare:{label:"Cloudflare Tunnel",executable:"cloudflared",installUrl:"https://developers.cloudflare.com/tunnel/downloads/"},cpolar:{label:"Cpolar",executable:"cpolar"}};function _fe(){return Ni("local",Sn.webPreviewTunnelProvider)==="cpolar"?"cpolar":"cloudflare"}function gF(e,t){if(e)return t==="cloudflare"?e.cloudflared:e.cpolar}function _0(e,t){var n;return((n=gF(e,t))==null?void 0:n.available)===!0}function wfe(e){const t=e.trim();if(!t)return"请输入本机网站地址";let n;try{n=new URL(t)}catch{return"请输入完整的 http:// 本机网站地址"}return n.protocol!=="http:"||!bfe.has(n.hostname)||n.username!==""||n.password!==""?"只支持 localhost、127.0.0.1 或 [::1] 的 http:// 地址":null}function Mh(){return{status:"idle"}}function xfe({open:e,onOpenChange:t}){const[n,r]=b.useState(""),[i,s]=b.useState(_fe),[o,l]=b.useState("local"),[u,d]=b.useState(""),[f,h]=b.useState(""),[y,g]=b.useState(""),[_,w]=b.useState(Mh),[S,x]=b.useState(!1),k=b.useRef(null),R=b.useRef(null),A=b.useRef(null),O=b.useRef(null),T=b.useRef(i);T.current=i;const M=b.useRef(e);M.current=e;const z=yo("(min-width: 768px)"),Y=Ae(ee=>ee.selectedProxyId),U=Vr(ee=>ee.capability),G=Vr(ee=>ee.capabilityStatus),I=Vr(ee=>ee.capabilityError),N=Vr(ee=>{var X;return((X=ee.authoritative)==null?void 0:X.scope)??null}),L=N?`${N.proxyId}\0${N.bindingId}`:null,B=b.useCallback(ee=>{T.current=ee,s(ee),Mr("local",Sn.webPreviewTunnelProvider,ee)},[]);function P(){var ee,X;r(""),l("local"),d(""),h(""),g(""),w(Mh()),x(!1),(ee=k.current)==null||ee.abort(),k.current=null,(X=R.current)==null||X.abort(),R.current=null,A.current=null,O.current=null}const D=b.useCallback(async ee=>{var ne;(ne=k.current)==null||ne.abort();const X=new AbortController;k.current=X;const ae=Nt.getActiveScope();if(!(!ae||ae.proxyId!==Y))try{const ce=await Nt.requestWebPreviewCapability(ae,ee,{signal:X.signal});if(!ce||X.signal.aborted||!M.current||!ce.success)return;const _e=T.current,xe=_e==="cloudflare"?"cpolar":"cloudflare";!_0(ce.capability,_e)&&_0(ce.capability,xe)&&B(xe)}catch{}},[B,Y]);function F(ee){!ee&&S||t(ee)}b.useEffect(()=>{if(!e){P();return}return D(!1),()=>{var ee;(ee=k.current)==null||ee.abort(),k.current=null}},[D,e,L]),b.useEffect(()=>{var ne;if(!e||o!=="static")return;(ne=R.current)==null||ne.abort(),R.current=null;const ee=f.trim();if(!ee){w(Mh()),g("");return}const X=new AbortController;R.current=X,w({status:"loading"}),g("");const ae=window.setTimeout(()=>{const ce=Ft,_e=Nt.getActiveScope();if(!ce||!_e||_e.proxyId!==Y){w({status:"error",message:"请先连接开发机"});return}Nt.inspectStaticWebPreview(_e,ee,{signal:X.signal}).then(xe=>{if(!xe||X.signal.aborted||!M.current||!Nt.isActive(ce,_e))return;if(!xe.success){w({status:"error",message:xe.error});return}const We=xe.htmlEntries;if(We.length===0&&!xe.entryPath){w({status:"error",message:"这里没有可以预览的网页"});return}const De={entryPath:xe.entryPath,htmlEntries:We};w({status:"ready",path:ee,result:De}),g(xe.entryPath??"")}).catch(xe=>{X.signal.aborted||!M.current||xe instanceof Error&&xe.name==="AbortError"||!Nt.isActive(ce,_e)||w({status:"error",message:xe instanceof Error?xe.message:"检查网页失败"})})},300);return()=>{window.clearTimeout(ae),X.abort(),R.current===X&&(R.current=null)}},[e,L,Y,o,f]);const q=o==="local"?wfe(u):null,j=o==="static"&&_.status==="ready"&&_.path===f.trim()&&!!(_.result.entryPath||y),V=G==="loaded"&&_0(U,i),$=S||!V||!(o==="local"?q===null:j);async function te(){var ce,_e,xe;if($)return;const ee=Ft;if(!ee){Ue.error("请先连接开发机");return}let X;if(o==="local")X={kind:"local",url:u.trim()};else{if(_.status!=="ready"||_.path!==f.trim())return;const We=_.result.entryPath??y;if(!We)return;X={kind:"static",path:_.path,entryPath:We}}x(!0);const ae=Nt.getActiveScope();if(!ae){x(!1),Ue.error("请先连接开发机");return}let ne=null;try{const We=n.trim(),De=JSON.stringify({proxyId:ae.proxyId,tunnelProvider:i,source:X,name:We||void 0});((ce=A.current)==null?void 0:ce.sourceKey)!==De&&(A.current={sourceKey:De,operationId:mm(`preview-operation-${i}`)}),ne=A.current.operationId,O.current=ne;const Pt=await Nt.createWebPreview(ae,X,{tunnelProvider:i,operationId:ne,...We?{name:We}:{}});if(O.current!==ne)return;if(!Pt.accepted){((_e=A.current)==null?void 0:_e.operationId)===ne&&(A.current=null),Ue.error(Pt.error);return}if(((xe=A.current)==null?void 0:xe.operationId)===ne&&(A.current=null),!M.current||!Nt.isActive(ee,ae))return;t(!1)}catch(We){if(!ne||O.current!==ne||!M.current||!Nt.isActive(ee,ae))return;Ue.error(We instanceof Error?We.message:"无法创建网页预览")}finally{ne&&O.current===ne&&(O.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:ee=>{ee.preventDefault(),te()},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:ee=>{r(ee.target.value)},className:"min-h-11 min-w-0 rounded-md border border-border bg-input px-3 text-base outline-none focus-visible:ring-2 focus-visible:ring-ring 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(Kb,{value:i,disabled:S,onValueChange:ee=>B(ee),children:[m.jsx(Xb,{"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(Gb,{})}),m.jsx(Zb,{"data-slot":"web-preview-tunnel-provider-options",children:Object.keys(N1).map(ee=>m.jsx(Jb,{value:ee,"data-slot":"web-preview-tunnel-provider-option","data-provider":ee,children:N1[ee].label},ee))})]})]}),m.jsx(Sfe,{status:G,capability:U,provider:i,error:I,disabled:S,onRetry:()=>void D(!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 ee;(ee=R.current)==null||ee.abort(),R.current=null,w(Mh()),g(""),l("local")},className:Ye("flex min-h-16 min-w-0 flex-col items-start justify-center gap-1 rounded-md border px-3 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60",o==="local"?"border-primary/70 bg-primary/10":"border-border bg-muted/20"),children:[m.jsx("span",{className:"text-sm font-medium",children:"本机网站"}),m.jsx("span",{className:"text-xs text-muted-foreground",children:"输入 localhost 地址"})]}),m.jsxs("button",{type:"button","data-slot":"web-preview-source-static",disabled:S,"aria-pressed":o==="static",onClick:()=>{var ee;(ee=R.current)==null||ee.abort(),R.current=null,w(Mh()),g(""),l("static")},className:Ye("flex min-h-16 min-w-0 flex-col items-start justify-center gap-1 rounded-md border px-3 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60",o==="static"?"border-primary/70 bg-primary/10":"border-border bg-muted/20"),children:[m.jsx("span",{className:"text-sm font-medium",children:"网页文件"}),m.jsx("span",{className:"text-xs text-muted-foreground",children:"选择 HTML 网页文件或目录"})]})]})]}),o==="local"?m.jsxs("label",{className:"flex min-w-0 flex-col gap-1",children:[m.jsx("span",{className:"text-sm",children:"本机网站地址"}),m.jsx("input",{type:"url","data-slot":"web-preview-local-url","aria-label":"本机网站地址",inputMode:"url",name:"dev-anywhere-preview-local-url",autoComplete:"off",autoCorrect:"off",spellCheck:!1,disabled:S,value:u,onChange:ee=>{d(ee.target.value)},placeholder:"http://localhost:5173","aria-invalid":u.length>0&&q!==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&&q?m.jsx("span",{"data-slot":"web-preview-local-url-error",className:"text-xs text-destructive",role:"alert",children:q}):null]}):m.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[m.jsx(Nk,{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(Efe,{inspection:_,selectedEntryPath:y,disabled:S,onEntryPathChange:ee=>{g(ee)}})]}),m.jsxs(Vs,{children:[m.jsx(yt,{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(yt,{type:"submit",className:"min-h-11 md:min-h-0",disabled:$,"data-slot":"create-web-preview-submit",children:S?"正在创建...":"创建预览"})]})]});return z?m.jsx(es,{open:e,onOpenChange:F,children:m.jsxs(ts,{showCloseButton:!S,onEscapeKeyDown:ee=>{S&&ee.preventDefault()},onPointerDownOutside:ee=>{S&&ee.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(ns,{children:[m.jsx($i,{children:"新建网页预览"}),m.jsx(Es,{children:"输入本机网站地址,或选择 HTML 网页文件或目录。"})]}),re]})}):m.jsx(pc,{open:e,onOpenChange:F,children:m.jsxs(mc,{side:"bottom",showCloseButton:!S,onEscapeKeyDown:ee=>{S&&ee.preventDefault()},onPointerDownOutside:ee=>{S&&ee.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(Eu,{className:"px-0 pb-1 pt-0 text-left",children:[m.jsx(gc,{children:"新建网页预览"}),m.jsx(Vb,{children:"输入本机网站地址,或选择 HTML 网页文件或目录。"})]}),re]})})}function Sfe({status:e,capability:t,provider:n,error:r,disabled:i,onRetry:s}){const o=N1[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(di,{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(_z,{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(pI,{onClick:s,disabled:i})]})});const l=gF(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(YV,{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(pI,{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(jV,{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 pI({onClick:e,disabled:t}){return m.jsxs(yt,{type:"button",variant:"outline",size:"sm","data-slot":"web-preview-capability-retry",className:"shrink-0",onClick:e,disabled:t,children:[m.jsx(fm,{className:"size-3.5","aria-hidden":"true"}),"重新检测"]})}function Efe({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(di,{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(Kb,{value:t,onValueChange:r,disabled:n,children:[m.jsx(Xb,{"data-slot":"web-preview-entry-select",className:"w-full font-mono",children:m.jsx(Gb,{placeholder:"选择网页"})}),m.jsx(Zb,{children:e.result.htmlEntries.map(o=>m.jsx(Jb,{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 M1={ios:"iOS Simulator",android:"Android Emulator"};function Cfe({open:e,platform:t,onOpenChange:n}){const r=Cs(),i=yo("(min-width: 768px)"),s=Ae(F=>F.selectedProxyId),o=pr(F=>F.capability),l=pr(F=>F.targets),u=pr(F=>F.targetsStatus),d=pr(F=>F.targetsError),f=pr(l5),h=pr(F=>{var q;return((q=F.authoritative)==null?void 0:q.scope)??null}),y=h?`${h.proxyId}\0${h.bindingId}`:null,[g,_]=b.useState(""),[w,S]=b.useState(null),[x,k]=b.useState(!1),R=b.useRef(null),A=b.useRef(e);A.current=e;const O=b.useRef(null),T=b.useRef(null),M=b.useMemo(()=>l.filter(F=>F.platform===t),[t,l]),z=b.useMemo(()=>new Set(f.map(F=>F.targetId)),[f]),Y=b.useMemo(()=>M.filter(F=>!z.has(F.targetId)),[z,M]),U=Y.find(F=>F.targetId===w),G=o==null?void 0:o[t],I=b.useCallback(async F=>{var K;(K=R.current)==null||K.abort();const q=new AbortController;R.current=q;const j=Ft,V=Nt.getActiveScope();if(!(!j||!V||V.proxyId!==s))try{const $=await Nt.requestDevicePreviewCapability(V,F,{signal:q.signal});if(!$||q.signal.aborted||!A.current||!$.success)return;await Nt.requestDevicePreviewTargets(V,!0,{signal:q.signal})}catch{}},[s]);b.useEffect(()=>{var F;if(!e){(F=R.current)==null||F.abort(),R.current=null,_(""),S(null),k(!1),O.current=null,T.current=null;return}return I(!1),()=>{var q;(q=R.current)==null||q.abort(),R.current=null}},[I,e,t,y]),b.useEffect(()=>{if(e){if(w&&!U){S(null);return}!w&&Y.length===1&&S(Y[0].targetId)}},[e,Y,U,w]);async function N(){var K,$,te;const F=U;if(!F||x||(G==null?void 0:G.available)!==!0)return;const q=Ft,j=Nt.getActiveScope();if(!q||!j||j.proxyId!==s){Ue.error("请先连接开发机");return}k(!0);let V=null;try{const re=g.trim(),ee=((K=O.current)==null?void 0:K.proxyId)===j.proxyId&&O.current.targetId===F.targetId&&O.current.name===re?O.current:{proxyId:j.proxyId,targetId:F.targetId,name:re,operationId:mm("device-preview-operation")};O.current=ee,V=ee.operationId,T.current=V;const X=await Nt.createDevicePreview(j,F.targetId,{operationId:ee.operationId,...re?{name:re}:{}});if(T.current!==ee.operationId)return;if(!X.accepted){if((($=O.current)==null?void 0:$.operationId)===ee.operationId&&(O.current=null),!A.current||!Nt.isActive(q,j))return;Ue.error(X.error);return}if(((te=O.current)==null?void 0:te.operationId)===ee.operationId&&(O.current=null),!A.current||!Nt.isActive(q,j))return;n(!1),r(`/preview/device/${X.previewId}`)}catch(re){if(!V||T.current!==V||!A.current||!Nt.isActive(q,j))return;Ue.error(re instanceof Error?re.message:"无法创建模拟器预览")}finally{V&&T.current===V&&(T.current=null,A.current&&k(!1))}}function L(F){var q;!F&&x||(F||((q=R.current)==null||q.abort(),R.current=null,O.current=null,T.current=null,_(""),S(null)),n(F))}const B=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(kfe,{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(di,{className:"size-4 animate-spin","aria-hidden":"true"}),"正在查找已启动的模拟器..."]}):u==="error"?m.jsx(mI,{message:d??"无法读取模拟器列表"}):M.length===0?m.jsx(mI,{message:`没有已启动的 ${M1[t]}`}):M.map(F=>{const q=F.targetId===w,j=z.has(F.targetId);return m.jsx(Tfe,{target:F,selected:q,disabled:j||x,alreadyOpen:j,onClick:()=>{S(F.targetId)}},F.targetId)})}),m.jsxs(Vs,{className:"gap-2 sm:gap-2",children:[m.jsxs(yt,{type:"button",variant:"outline",disabled:x||u==="loading",onClick:()=>void I(!0),"data-slot":"device-preview-refresh",children:[m.jsx(fm,{className:"size-4","aria-hidden":"true"}),"重新检测"]}),m.jsx(yt,{type:"button",disabled:!U||x||(G==null?void 0:G.available)!==!0,onClick:()=>void N(),"data-slot":"create-device-preview-submit",children:x?"正在创建...":"创建预览"})]})]}),P=`新建 ${M1[t]} 预览`,D="选择开发机上已经启动的模拟器。";return i?m.jsx(es,{open:e,onOpenChange:L,children:m.jsxs(ts,{showCloseButton:!x,className:"sm:max-w-xl","data-slot":"create-device-preview-dialog","data-platform":t,focusSurfaceOnOpen:!0,children:[m.jsxs(ns,{children:[m.jsx($i,{children:P}),m.jsx(Es,{children:D})]}),B]})}):m.jsx(pc,{open:e,onOpenChange:L,children:m.jsxs(mc,{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(Eu,{className:"px-0 pb-1 pt-0 text-left",children:[m.jsx(gc,{children:P}),m.jsx(Vb,{children:D})]}),B]})})}function kfe({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"?`${M1[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(_z,{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 mI({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 Tfe({target:e,selected:t,disabled:n,alreadyOpen:r,onClick:i}){const s=e.platform==="ios"?"iOS":"Android",o=`${e.model} · ${s} ${e.osVersion}`;return m.jsxs("button",{type:"button",className:Ye("flex min-h-16 w-full min-w-0 max-w-full items-center gap-3 overflow-hidden rounded-lg border px-3 py-2 text-left outline-none transition-colors",t?"border-primary bg-primary/5":"border-border hover:bg-accent",n&&"cursor-not-allowed opacity-55"),disabled:n,"aria-pressed":t,onClick:i,"data-slot":"device-preview-target","data-target-id":e.targetId,"data-already-open":r?"true":"false","data-interactive":e.interactive?"true":"false",children:[m.jsx(Ty,{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 vF({open:e,onOpenChange:t}){const[n,r]=b.useState(()=>e?"chooser":"closed"),i=b.useRef(null),s=yo("(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(w0,{icon:m.jsx(Sz,{className:"size-5","aria-hidden":"true"}),title:"网页",description:"通过临时链接访问或分享本机网页",slot:"frontend-preview-web",onClick:()=>r("web")}),m.jsx(w0,{icon:m.jsx(Ty,{className:"size-5","aria-hidden":"true"}),title:"iOS Simulator",description:"查看和操控开发机上已启动的 iPhone 或 iPad 模拟器",slot:"frontend-preview-ios",onClick:()=>r("ios")}),m.jsx(w0,{icon:m.jsx(Ty,{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(es,{open:d,onOpenChange:f=>!f&&o(),children:m.jsxs(ts,{className:"sm:max-w-lg","data-slot":"create-frontend-preview-dialog",children:[m.jsxs(ns,{children:[m.jsx($i,{children:"新建预览"}),m.jsx(Es,{children:"选择预览类型。"})]}),l]})},"chooser"):m.jsx(pc,{open:d,onOpenChange:f=>!f&&o(),children:m.jsxs(mc,{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(Eu,{className:"px-0 pb-1 pt-0 text-left",children:[m.jsx(gc,{children:"新建预览"}),m.jsx(Vb,{children:"选择预览类型。"})]}),l]})},"chooser");case"web":return m.jsx(xfe,{open:d,onOpenChange:f=>!f&&o()},"web");case"ios":case"android":return m.jsx(Cfe,{open:d,platform:u,onOpenChange:f=>!f&&o()},u);case null:return null}}function w0({icon:e,title:t,description:n,slot:r,onClick:i}){return m.jsxs(yt,{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 Rfe({preview:e,closing:t,onOpenChange:n,onConfirm:r}){return m.jsx(es,{open:e!==null,onOpenChange:n,children:m.jsxs(ts,{"data-slot":"device-preview-close-dialog",children:[m.jsxs(ns,{children:[m.jsx($i,{children:"停止预览?"}),m.jsx(Es,{children:"模拟器会继续在开发机上运行。"})]}),m.jsxs(Vs,{children:[m.jsx(yt,{type:"button",variant:"ghost",disabled:t,onClick:()=>n(!1),children:"取消"}),m.jsx(yt,{type:"button",variant:"destructive",disabled:!e||t,onClick:()=>e&&r(e),"data-slot":"device-preview-close-confirm",children:t?"正在停止...":"停止预览"})]})]})})}const Afe={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 Nfe({preview:e,selected:t,pendingOperation:n,onRename:r,onReconnect:i,onClose:s}){const o=Afe[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:Ye("inline-block size-2 shrink-0 rounded-full",l.dot),role:"status","aria-label":`预览状态:${l.label}`}),m.jsx("span",{className:"flex-1 truncate text-sm font-normal",title:e.name,children:e.name})]}),m.jsxs("span",{className:"flex h-5 min-w-0 items-center gap-1.5 text-xs leading-5",children:[m.jsx(Ty,{className:"size-3.5 shrink-0 text-muted-foreground","aria-hidden":"true"}),m.jsxs("span",{className:"min-w-0 flex-1 truncate text-muted-foreground","data-slot":"device-preview-row-device","data-device-model":e.model,"data-os-version":e.osVersion,children:[e.model," · ",f," ",e.osVersion]}),m.jsx("span",{className:Ye("shrink-0",l.text),children:l.label})]})]});return m.jsxs("li",{className:Ye("relative flex min-h-[44px] w-full min-w-0 items-center gap-2 px-4 py-2 transition-colors hover:bg-accent",t&&"bg-accent"),"data-slot":"device-preview-row","data-preview-id":e.previewId,"data-preview-state":e.state,"data-preview-operation":n,children:[u?m.jsx(_C,{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(_f,{children:[m.jsx(wf,{asChild:!0,children:m.jsx(yt,{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(di,{className:"animate-spin","aria-hidden":"true"}):m.jsx(hb,{"aria-hidden":"true"})})}),m.jsxs(xf,{align:"end","data-slot":"device-preview-row-menu",children:[m.jsx(ti,{"data-slot":"device-preview-row-rename-item",onSelect:r,children:"重命名"}),d?m.jsx(ti,{"data-slot":"device-preview-row-reconnect-item",onSelect:i,children:"重新连接"}):null,m.jsx(Gc,{}),m.jsx(ti,{variant:"destructive","data-slot":"device-preview-row-close-item",onSelect:s,children:"停止预览"})]})]})]})}function Mfe({preview:e,closing:t,onOpenChange:n,onConfirm:r}){return m.jsx(es,{open:e!==null,onOpenChange:n,children:m.jsxs(ts,{"data-slot":"preview-close-dialog",children:[m.jsxs(ns,{children:[m.jsx($i,{children:"关闭预览?"}),m.jsx(Es,{children:"关闭后,当前预览链接将立即失效。"})]}),m.jsxs(Vs,{children:[m.jsx(yt,{type:"button",variant:"ghost",disabled:t,onClick:()=>n(!1),children:"取消"}),m.jsx(yt,{type:"button",variant:"destructive",disabled:!e||t,onClick:()=>e&&r(e),"data-slot":"preview-close-confirm",children:t?"正在关闭...":"关闭预览"})]})]})})}function Pfe({target:e,onOpenChange:t,onRename:n}){return m.jsx(Ife,{target:e,onOpenChange:t,onRename:n},(e==null?void 0:e.targetKey)??"closed")}function Ife({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(y){!y&&l||t(y)}async function h(y){y.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(es,{open:e!==null,onOpenChange:f,children:m.jsx(ts,{showCloseButton:!l,className:"sm:max-w-md","data-slot":"preview-rename-dialog",children:m.jsxs("form",{className:"grid gap-4",onSubmit:y=>void h(y),children:[m.jsx(ns,{children:m.jsx($i,{children:"重命名预览"})}),m.jsxs("div",{className:"grid gap-2",children:[m.jsx("label",{htmlFor:"preview-rename-name",className:"text-sm font-medium",children:"预览名称"}),m.jsx("input",{id:"preview-rename-name",value:r,autoFocus:!0,maxLength:256,autoComplete:"off",autoCorrect:"off",spellCheck:!1,"aria-invalid":!!s,"aria-describedby":s?"preview-rename-error":void 0,"data-slot":"preview-rename-input",className:Ye("h-10 rounded-md border border-input bg-background px-3 text-sm shadow-xs outline-none transition-[border-color,box-shadow]","placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/75","disabled:cursor-not-allowed disabled:opacity-50",s&&"border-destructive focus-visible:ring-destructive/20"),disabled:l,onChange:y=>{i(y.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(Vs,{children:[m.jsx(yt,{type:"button",variant:"outline",disabled:l,onClick:()=>f(!1),children:"取消"}),m.jsx(yt,{type:"submit",disabled:l,"data-slot":"preview-rename-submit",children:"保存"})]})]})})})}const Ofe={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 Lfe(e){return e.source.kind==="local"?e.source.url:bb(e.source.rootPath,e.source.entryPath)}async function Dfe(e){if(await Hp(e,{allowUserGestureFallback:!0})==="failed"){Ue.error("复制失败,请稍后重试");return}Ue.success("链接已复制")}async function Bfe(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;Ue.error("无法打开系统分享面板")}}function zfe({preview:e,pendingOperation:t,onRename:n,onReconnect:r,onClose:i}){const s=Gr(w=>w.homePath),o=Ofe[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",y=Lfe(e),g=e.source.kind==="static"?$p(y,s):y,_=m.jsxs(m.Fragment,{children:[m.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[m.jsx("span",{className:Ye("inline-block size-2 shrink-0 rounded-full",l.dot),role:"status","aria-label":`预览状态:${l.label}`}),m.jsx("span",{className:"flex-1 truncate text-sm font-normal",title:e.name,children:e.name})]}),m.jsxs("span",{className:"flex h-5 min-w-0 items-center gap-1.5 text-xs leading-5",children:[m.jsx(Sz,{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:y,children:g}),m.jsx("span",{className:"shrink-0 text-muted-foreground/60","aria-hidden":"true",children:"·"}),m.jsx("span",{className:Ye("shrink-0",l.text),children:l.label})]}),e.state==="failed"?m.jsx("span",{"data-slot":"preview-row-error",className:"truncate text-xs text-destructive/90",title:e.error,children:e.error}):null]});return m.jsxs("li",{className:"relative flex min-h-[44px] w-full min-w-0 items-center gap-2 px-4 py-2 transition-colors hover:bg-accent","data-slot":"preview-row","data-preview-id":e.previewId,"data-preview-state":e.state,"data-preview-operation":t,children:[d?m.jsx("a",{href:u,target:"_blank",rel:"noopener noreferrer","data-slot":"preview-row-open",className:"flex min-h-11 min-w-0 flex-1 flex-col justify-center gap-1 rounded-sm text-left outline-none focus-visible:ring-2 focus-visible:ring-ring md:min-h-0",children:_}):m.jsx("div",{"data-slot":"preview-row-inactive","aria-disabled":"true",className:"flex min-h-11 min-w-0 flex-1 flex-col justify-center gap-1 md:min-h-0",children:_}),m.jsxs(_f,{children:[m.jsx(wf,{asChild:!0,children:m.jsx(yt,{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(di,{className:"animate-spin","aria-hidden":"true"}):m.jsx(hb,{"aria-hidden":"true"})})}),m.jsxs(xf,{align:"end","data-slot":"preview-row-menu",children:[m.jsx(ti,{"data-slot":"preview-row-rename-item",onSelect:n,children:"重命名"}),d?m.jsx(ti,{"data-slot":"preview-row-copy-item",onSelect:()=>void Dfe(u),children:"复制链接"}):null,h?m.jsx(ti,{"data-slot":"preview-row-share-item",onSelect:()=>void Bfe(e.name,u),children:"分享…"}):null,f?m.jsx(ti,{"data-slot":"preview-row-reconnect-item",onSelect:r,children:"重新连接"}):null,m.jsx(Gc,{}),m.jsx(ti,{variant:"destructive","data-slot":"preview-row-close-item",onSelect:i,children:"关闭预览"})]})]})]})}const jfe=Object.freeze([]),Ffe=Object.freeze([]);function ud(e,t,n){return Object.freeze({kind:e,previewId:t,scope:Object.freeze({proxyId:n.proxyId,bindingId:n.bindingId})})}function jc(e,t){return e!==null&&e.kind===t.kind&&e.previewId===t.previewId&&Qt(e.scope,t.scope)}function dp(e,t,n){return t!==null&&n!==void 0&&Qt(e.scope,t)&&Qt(e.scope,n)}function Ph(e){const t=Nt.getActiveScope(),n=e.kind==="web"?Vr.getState().authoritative:pr.getState().authoritative;return!n||!dp(e,t,n.scope)?!1:n.previews.some(r=>r.previewId===e.previewId)}function Uo(e){const t=Nt.getActiveScope();return t!==null&&Qt(t,e)}function gI(){const e=Vr(N=>N.authoritative),t=pr(N=>N.authoritative),n=Zo(N=>N.registry),r=Nt.getActiveScope(),i=r&&e&&Qt(r,e.scope)?e.scope:null,s=r&&t&&Qt(r,t.scope)?t.scope:null,o=i&&e?e.previews:jfe,l=s&&t?t.previews:Ffe,u=az("/preview/device/:id"),d=Cs(),[f,h]=b.useState(null),[y,g]=b.useState(null),_=(y==null?void 0:y.kind)==="web"&&dp(y,r,e==null?void 0:e.scope)?o.find(N=>N.previewId===y.previewId)??null:null,w=(y==null?void 0:y.kind)==="device"&&dp(y,r,t==null?void 0:t.scope)?l.find(N=>N.previewId===y.previewId)??null:null,S=_??w,x=(f==null?void 0:f.kind)==="web"&&dp(f,r,e==null?void 0:e.scope)?o.find(N=>N.previewId===f.previewId)??null:null,k=(f==null?void 0:f.kind)==="device"&&dp(f,r,t==null?void 0:t.scope)?l.find(N=>N.previewId===f.previewId)??null:null;b.useEffect(()=>{y&&!S&&g(N=>jc(N,y)?null:N),f&&!x&&!k&&h(N=>jc(N,f)?null:N)},[f,k,y,S,x]);function R(N,L,B){var P;return(P=i5(n,N,L,B)[0])==null?void 0:P.kind}if(o.length===0&&l.length===0)return null;async function A(N){if(Ph(N))try{const L=await Nt.reconnectWebPreview(N.scope,N.previewId);if(!Uo(N.scope))return;L.success||Ue.error(L.error)}catch(L){if(!Uo(N.scope))return;Ue.error(L instanceof Error?L.message:"无法重新连接网页预览")}}async function O(N,L){if(!Ph(N))return;let B;try{B=N.kind==="web"?await Nt.renameWebPreview(N.scope,N.previewId,L):await Nt.renameDevicePreview(N.scope,N.previewId,L)}catch(P){if(!Uo(N.scope))return;throw P}if(Uo(N.scope)&&!B.success)throw new Error(B.error)}async function T(N){if(Ph(N))try{const L=await Nt.closeWebPreview(N.scope,N.previewId);if(!Uo(N.scope))return;if(!L.success){Ue.error(L.error);return}h(B=>jc(B,N)?null:B)}catch(L){if(!Uo(N.scope))return;Ue.error(L instanceof Error?L.message:"无法关闭网页预览")}}async function M(N){if(Ph(N))try{const L=await Nt.reconnectDevicePreview(N.scope,N.previewId);if(!Uo(N.scope))return;L.success||Ue.error(L.error)}catch(L){if(!Uo(N.scope))return;Ue.error(L instanceof Error?L.message:"无法重新连接模拟器预览")}}async function z(N){if(Ph(N))try{const L=await Nt.closeDevicePreview(N.scope,N.previewId);if(!Uo(N.scope))return;if(!L.success){Ue.error(L.error);return}h(B=>jc(B,N)?null:B),(u==null?void 0:u.params.id)===N.previewId&&d("/sessions")}catch(L){if(!Uo(N.scope))return;Ue.error(L instanceof Error?L.message:"无法停止模拟器预览")}}const Y=(f==null?void 0:f.kind)==="web"&&R(f.scope,"web",f.previewId)==="close",U=(f==null?void 0:f.kind)==="device"&&R(f.scope,"device",f.previewId)==="close",G=y,I=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(zfe,{preview:N,pendingOperation:i?R(i,"web",N.previewId):void 0,onRename:()=>i&&g(ud("web",N.previewId,i)),onReconnect:()=>i&&void A(ud("web",N.previewId,i)),onClose:()=>i&&h(ud("web",N.previewId,i))},N.previewId)),l.map(N=>m.jsx(Nfe,{preview:N,selected:(u==null?void 0:u.params.id)===N.previewId,pendingOperation:s?R(s,"device",N.previewId):void 0,onRename:()=>s&&g(ud("device",N.previewId,s)),onReconnect:()=>s&&void M(ud("device",N.previewId,s)),onClose:()=>s&&h(ud("device",N.previewId,s))},N.previewId))]}),m.jsx(Pfe,{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=>jc(L,G)?null:L)},onRename:N=>G?O(G,N):Promise.resolve()}),m.jsx(Mfe,{preview:x,closing:Y,onOpenChange:N=>{!N&&!Y&&I&&h(L=>jc(L,I)?null:L)},onConfirm:()=>I&&void T(I)}),m.jsx(Rfe,{preview:k,closing:U,onOpenChange:N=>{!N&&!U&&I&&h(L=>jc(L,I)?null:L)},onConfirm:()=>I&&void z(I)})]})}function yF({layout:e}){const t=Ht(ne=>ne.sessions),n=Ht(ne=>ne.sessionListLoaded),r=Ht(ne=>ne.agentStatusBySessionId),i=Ht(ne=>ne.ptyStateBySessionId),s=Ht(ne=>ne.renameSession),o=fn(ne=>ne.bySessionId),l=az("/chat/:id"),u=(l==null?void 0:l.params.id)??null,d=Ae(ne=>!!ne.selectedProxyId),f=Ae(ne=>ne.proxyListLoaded),h=Ae(ne=>ne.proxySwitchTarget),y=Ht(ne=>ne.loadingProxyName),g=h!==null||!f||d&&!n,_=(h==null?void 0:h.name)??y,w=_?`正在连接 ${_}...`:"连接中...",S=Cs(),[x,k]=b.useState(!1),[R,A]=b.useState(!1),[O,T]=b.useState(!1),[M,z]=b.useState(!1),[Y,U]=b.useState(null),[G,I]=b.useState(null),{creatingTerminal:N,creatingShell:L,createTerminal:B}=bF(),[P,D]=b.useState(new Set),[F,q]=b.useState(()=>Date.now());b.useEffect(()=>{const ne=setInterval(()=>q(Date.now()),6e4);return()=>clearInterval(ne)},[]);function j(ne,ce){S(`/chat/${ne}?mode=${ce}`,{replace:!1})}function V(ne){const ce=ne.sessionId,_e=Ft;if(!_e){Ue.error("请先连接开发机");return}_e.sendControl({type:"session_terminate",sessionId:ce}),Ht.getState().removeSession(ce),fn.getState().clearSession(ce),ce===u&&S("/sessions"),(ne==null?void 0:ne.kind)==="agent"&&ne.mode==="pty"&&ne.ptyOwner==="local-terminal"?Ue.info("已断开页面连接,本地终端仍在运行"):Ue.info("正在终止会话",{duration:1500})}async function K(ne,ce){const _e=Ft;if(!_e)throw new Error("请先连接开发机");const xe=await _e.renameSession(ne,ce);if(!xe.success)throw new Error(xe.error??"重命名失败");s(ne,xe.name??ce),Ue.success("已重命名会话")}function $(ne){D(ce=>{const _e=new Set(ce);return _e.has(ne)?_e.delete(ne):_e.add(ne),_e})}function te(ne){var xe;const ce=ne.mode==="json"&&(((xe=o[ne.sessionId])==null?void 0:xe.pendingApprovals.some(We=>We.status==="pending"))??!1),_e=yfe({session:ne,agentStatus:r[ne.sessionId],ptyState:i[ne.sessionId],hasPendingApproval:ce});return _e===ne.state?ne:{...ne,state:_e}}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(cp,{open:x,onOpenChange:k}),m.jsx(_v,{open:G!==null,session:G,onOpenChange:ne=>{ne||I(null)},onConfirm:V}),m.jsx(up,{open:Y!==null,sessionId:(Y==null?void 0:Y.sessionId)??null,initialName:Y==null?void 0:Y.name,onOpenChange:ne=>{ne||U(null)},onRename:K})]});if(e==="page"&&g)return m.jsxs("div",{className:"flex h-full w-full flex-col items-center justify-center gap-3 text-muted-foreground animate-in fade-in-0 duration-200 motion-reduce:animate-none","data-slot":"session-list-loading",role:"status","aria-live":"polite",children:[m.jsx(di,{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(Qc,{variant:"no-proxy"})}),m.jsx(cp,{open:x,onOpenChange:k}),m.jsx(_v,{open:G!==null,session:G,onOpenChange:ne=>{ne||I(null)},onConfirm:V}),m.jsx(up,{open:Y!==null,sessionId:(Y==null?void 0:Y.sessionId)??null,initialName:Y==null?void 0:Y.name,onOpenChange:ne=>{ne||U(null)},onRename:K})]});const ee=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]}),X=re?m.jsx("ul",{role:"list",className:"flex flex-col w-full min-w-0",children:$fe(t).map(ne=>m.jsxs("li",{children:[m.jsxs("button",{type:"button",onClick:()=>$(ne.provider),"aria-expanded":!P.has(ne.provider),className:Ye("flex w-full items-center gap-2 px-4 pt-2 pb-1 min-h-[32px]","text-xs text-muted-foreground","text-left outline-none transition-colors hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring"),children:[m.jsx("span",{className:"font-mono",children:Hfe(ne.provider)}),m.jsx("span",{className:"h-px flex-1 bg-border/70","aria-hidden":"true"}),m.jsx("span",{className:"tabular-nums",children:ne.sessions.length}),m.jsx(Hd,{className:Ye("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",!P.has(ne.provider)&&"rotate-90"),"aria-hidden":"true"})]}),P.has(ne.provider)?null:m.jsx("ul",{role:"list",className:"flex flex-col",children:ne.sessions.map(ce=>m.jsx(Zde,{session:te(ce),selected:ce.sessionId===u,now:F,onClick:()=>j(ce.sessionId,ce.mode),onRename:()=>U(ce),onTerminate:()=>I(ce)},ce.sessionId))})]},ne.provider))}):m.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/70","data-slot":"active-empty",children:"暂无活跃会话"}),ae=m.jsx(tfe,{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:[ee,X,m.jsx(gI,{}),ae]}),m.jsx("div",{className:"px-4 pt-4 pb-[calc(env(safe-area-inset-bottom)+1rem)] border-t border-border",children:m.jsxs(yt,{className:"min-h-11 w-full md:min-h-0","data-slot":"create-session-mobile-trigger",onClick:()=>A(!0),children:[m.jsx(wz,{"aria-hidden":"true"}),"新建"]})}),m.jsx(Yfe,{open:R,creatingTerminal:N,onOpenChange:A,onCreateAgent:()=>{A(!1),k(!0)},onCreateTerminal:()=>{_F()?(A(!1),T(!0)):B(void 0,()=>A(!1))},onCreatePreview:()=>{A(!1),z(!0)}}),m.jsx(wF,{layout:"mobile",open:O,creatingTerminal:N,creatingShell:L,onOpenChange:T,onBack:()=>{T(!1),A(!0)},onCreate:ne=>void B(ne,()=>T(!1))}),m.jsx(cp,{open:x,onOpenChange:k}),m.jsx(vF,{open:M,onOpenChange:z}),m.jsx(_v,{open:G!==null,session:G,onOpenChange:ne=>{ne||I(null)},onConfirm:V}),m.jsx(up,{open:Y!==null,sessionId:(Y==null?void 0:Y.sessionId)??null,initialName:Y==null?void 0:Y.name,onOpenChange:ne=>{ne||U(null)},onRename:K})]}):m.jsxs(m.Fragment,{children:[m.jsxs("div",{className:"dev-sidebar-scroll h-full overflow-y-auto overscroll-contain",children:[ee,X,m.jsx(gI,{}),ae]}),m.jsx(cp,{open:x,onOpenChange:k}),m.jsx(_v,{open:G!==null,session:G,onOpenChange:ne=>{ne||I(null)},onConfirm:V}),m.jsx(up,{open:Y!==null,sessionId:(Y==null?void 0:Y.sessionId)??null,initialName:Y==null?void 0:Y.name,onOpenChange:ne=>{ne||U(null)},onRename:K})]})}function $fe(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])=>Ufe(n,r)).map(([n,r])=>({provider:n,sessions:r}))}function Hfe(e){return e==="terminal"?"终端":Yb(e)}function Ufe(e,t){return e===t?0:e==="terminal"?-1:t==="terminal"?1:oF(e,t)}function bF(){const e=Cs(),[t,n]=b.useState(null),r=t!==null;async function i(s,o){var u;const l=Ae.getState();if(!(r||!l.connected||!l.proxyOnline||!l.selectedProxyId||l.proxySwitchTarget)&&!Mk(l)&&!(s&&!((u=l.terminalShells)!=null&&u.some(d=>d.id===s)))){n(s??"default");try{const d=await ffe({relay:Ft,shell:s});if(d.type!=="success"){Ue.error(d.message);return}Ht.getState().addSession(d.session),o==null||o(),e(d.route)}finally{n(null)}}}return{creatingTerminal:r,creatingShell:t,createTerminal:i}}function Mk(e){var t;return!e.terminalShellsLoaded&&((t=e.proxies.find(n=>n.proxyId===e.selectedProxyId))==null?void 0:t.osName)==="Windows"}function Wfe(e){const t=Ae(u=>u.terminalShells),n=Ae(Mk),r=Ae(u=>u.selectedProxyId),[i,s]=b.useState(!1),[o,l]=b.useState(0);return b.useEffect(()=>{if(!e||!n)return;let u=!1;const d=Ft,f=d==null?void 0:d.getPreviewScope();if(s(!1),!d||!f||f.proxyId!==r){s(!0);return}return d.requestProxyInfo().then(h=>{const y=Ae.getState(),g=d.getPreviewScope();u||!y.connected||!y.proxyOnline||y.selectedProxyId!==r||!g||!Qt(f,g)||y.setTerminalShells(h.terminalShells)},()=>{u||s(!0)}),()=>{u=!0}},[e,n,r,o]),{terminalShells:t,needsDetection:n,failed:i,retry:()=>l(u=>u+1)}}const qfe=[{label:"启动 Shell"}];function Vfe(e){return e!=null&&e.length?e:qfe}function _F(){var t;const e=Ae.getState();return Mk(e)||!!((t=e.terminalShells)!=null&&t.length)}function vI({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),y=Ae(Y=>!!Y.selectedProxyId),g=Ae(Y=>Y.proxySwitchTarget!==null),_=y&&!g,{creatingTerminal:w,creatingShell:S,createTerminal:x}=bF();function k(){f(!0),window.setTimeout(()=>f(!1),2e3)}function R(){if(!_){k();return}h.current=!0,o(!0)}function A(){if(!_){k();return}h.current=!0,_F()?i(!0):x()}function O(){if(!_){k();return}h.current=!0,u(!0)}function T(Y){Y.preventDefault(),k()}const M=m.jsxs(yt,{variant:"outline","data-slot":"create-session-trigger",className:Ye(e?"h-11 w-11 justify-center border-border px-0":"h-[46px] w-full justify-center gap-2 border-border px-3",!_&&"opacity-50 hover:bg-background"),"aria-label":"新建","aria-disabled":!_,onClick:_?void 0:T,children:[m.jsx(wz,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),!e&&m.jsx("span",{className:"truncate",children:"新建"})]}),z=_?m.jsxs(_f,{open:t,onOpenChange:n,children:[m.jsx(wf,{asChild:!0,children:M}),m.jsxs(xf,{align:e?"end":"start",className:"w-80","data-slot":"create-session-type-menu",onCloseAutoFocus:Y=>{h.current&&(h.current=!1,Y.preventDefault())},children:[m.jsxs(ti,{className:"min-h-9 gap-2.5","data-slot":"create-agent-session-item",onSelect:R,children:[m.jsx(bz,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),"Agent 会话"]}),m.jsxs(ti,{className:"min-h-9 gap-2.5","data-slot":"create-terminal-session-item",disabled:w,onSelect:A,children:[m.jsx(ru,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),w?"正在创建 Shell 会话...":"Shell 会话"]}),m.jsx(Gc,{}),m.jsxs(ti,{className:"min-h-[3.75rem] items-start gap-2.5 py-2","data-slot":"create-frontend-preview-item",onSelect:O,children:[m.jsx(CC,{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(Sf,{open:_?void 0:d,onOpenChange:_?void 0:f,children:[m.jsx(Ef,{asChild:!0,children:z}),m.jsx(Cf,{side:"top",children:g?"正在切换开发机":"请先连接开发机"})]}),m.jsx(wF,{layout:"desktop",open:r,creatingTerminal:w,creatingShell:S,onOpenChange:i,onBack:()=>{i(!1),n(!0)},onCreate:Y=>void x(Y,()=>i(!1))}),m.jsx(cp,{open:s,onOpenChange:o}),m.jsx(vF,{open:l,onOpenChange:u})]})}function Yfe({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(pc,{open:e,onOpenChange:n,children:m.jsxs(mc,{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(Eu,{className:"px-1 pb-1 pt-0 text-left",children:m.jsx(gc,{children:"新建"})}),m.jsxs("div",{className:"grid gap-2 pb-1","data-slot":"create-session-type-options",children:[m.jsxs(yt,{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(bz,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),"Agent 会话"]}),m.jsxs(yt,{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(ru,{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(yt,{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(CC,{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 wF({layout:e,open:t,creatingTerminal:n,creatingShell:r,onOpenChange:i,onBack:s,onCreate:o}){const{terminalShells:l,needsDetection:u,failed:d,retry:f}=Wfe(t),h=b.useRef(!1),y=Ae(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(yt,{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(ru,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),d?"终端检测失败,点击重试":"正在检测终端..."]}):Vfe(l).map(w=>m.jsxs(yt,{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||!y,onClick:()=>o(w.id),children:[m.jsx(ru,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),r===(w.id??"default")?"正在创建 Shell 会话...":w.label]},w.id??"default")),m.jsx("div",{className:"mx-1 h-px bg-border","aria-hidden":"true"}),m.jsxs(yt,{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(ff,{className:"size-4","aria-hidden":"true"}),"返回"]})]});function _(w){h.current&&(h.current=!1,w.preventDefault())}return e==="mobile"?m.jsx(pc,{open:t,onOpenChange:i,children:m.jsxs(mc,{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(Eu,{className:"px-1 pb-1 pt-0 text-left",children:m.jsx(gc,{children:"Shell 会话"})}),g]})}):m.jsx(es,{open:t,onOpenChange:i,children:m.jsxs(ts,{className:"sm:max-w-sm","data-slot":"create-terminal-shell-dialog",focusSurfaceOnOpen:!0,onCloseAutoFocus:_,children:[m.jsx(ns,{children:m.jsx($i,{children:"Shell 会话"})}),g]})})}const Kfe="0.9.16",Gfe={version:Kfe},Xfe={playback:"playback",capture:"play-and-record"};function Zfe(){return typeof navigator>"u"?null:navigator.audioSession??null}function Jfe(){return{setMode:()=>{},release:()=>{}}}class Qfe{constructor(t=Zfe){je(this,"leases",new Map);je(this,"session",null);je(this,"baselineType",null);je(this,"nextLeaseId",1);je(this,"nextOrder",1);this.getAudioSession=t}acquire(t){const n=this.getAudioSession();if(!n)return Jfe();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(Xfe[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 Pk=new Qfe,P1=64,yI=-60,xF=32;function bI(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-yI)/-yI));return e<0?-r:r}function _I(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 y=i.getInt16(h*2,!0)/32768;d=Math.min(d,y),f=Math.max(f,y)}s.push({min:d,max:f})}return s}function ehe(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 the(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 SF{constructor(t,n=24e3,r={}){je(this,"nextStartTime",0);je(this,"activityEndToken",0);je(this,"timelineTimers",new Set);this.context=t,this.sampleRate=n,this.options=r}async resume(){this.emitPlaybackEvent("resume-start");try{if(this.context.state!=="running"&&this.context.state!=="closed"&&await this.context.resume(),this.context.state!=="running")throw new Error("浏览器未允许播放 Voice Pilot 提示音");this.emitPlaybackEvent("resume-finished")}catch(t){throw this.emitPlaybackEvent("resume-failed",{error:t instanceof Error?t.message:String(t)}),t}}enqueue(t){this.context.state==="suspended"&&this.resume().catch(()=>{});const n=ehe(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*xF/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),y=the(n.subarray(l,u));this.scheduleTimer(()=>{var g,_,w,S;(_=(g=this.options).onActivityLevel)==null||_.call(g,y),(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 x0={provider:"aliyun-bailian",configured:!1,region:"cn",asrModel:"qwen3-asr-flash-realtime",ttsModel:"cosyvoice-v3-flash",ttsVoice:"longanyang",turnIdleSeconds:3},wI="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",nhe=800,xI=300,rhe=1600;function I1(e,t){return e.filter(n=>!n.model||n.model===t)}function SI({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 wv({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),y=!!EF(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 ${y?"min-h-[60px] py-2":"min-h-11"}`,onClick:()=>l(g=>!g),"data-slot":"voice-settings-choice-trigger",children:[m.jsx(EI,{label:f,muted:!d&&!t}),m.jsx(sc,{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(EI,{label:g.label})]},g.value)})}):null,s?m.jsx("div",{className:"mt-2 text-xs leading-relaxed text-muted-foreground",children:s}):null]})}function EI({label:e,muted:t=!1}){const n=EF(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 ihe({scrollRef:e}={}){const[t,n]=b.useState(x0),[r,i]=b.useState(String(x0.turnIdleSeconds)),[s,o]=b.useState(()=>ov()),[l,u]=b.useState(""),[d,f]=b.useState(!1),[h,y]=b.useState(!1),[g,_]=b.useState({kind:"idle"}),w=b.useRef(null),S=b.useRef(null),x=b.useRef(null),k=b.useRef(null),R=b.useRef(null),A=b.useRef(!1);b.useEffect(()=>{const X=Ft;if(!X){_({kind:"error",message:"请先连接 Relay 服务器"});return}let ae=!1;return _({kind:"loading"}),X.requestVoiceConfig().then(ne=>{if(!ae){if(ne.error||!ne.config){_({kind:"error",message:ne.error??"读取语音设置失败"});return}n(ne.config),i(String(ne.config.turnIdleSeconds)),u(""),f(!1),y(!0),_({kind:"idle"})}}).catch(ne=>{ae||_({kind:"error",message:ne instanceof Error?ne.message:"读取语音设置失败"})}),()=>{ae=!0}},[]),b.useEffect(()=>{const X=Ft;if(!X||!h)return;let ae=!1;return X.requestVoiceCapabilities({region:t.region}).then(ne=>{if(!ae){if(ne.error||!ne.capabilities){o(ov());return}o(ne.capabilities)}}).catch(()=>{ae||o(ov())}),()=>{ae=!0}},[t.region,h]),b.useEffect(()=>(A.current=!0,()=>{A.current=!1,$(),te()}),[]);const O=b.useMemo(()=>g.kind==="loading"?"读取中...":g.kind==="saving"?"保存中...":g.kind==="testing"?"正在测试语音合成":g.kind==="playingTest"?"正在播放测试音频":g.kind==="testPassed"?"测试通过":g.kind==="saved"?"已保存":g.kind==="error"?g.message:null,[g]),T=g.kind==="saving"||g.kind==="loading"||g.kind==="testing"||g.kind==="playingTest",M=b.useMemo(()=>I1(s.ttsVoices,t.ttsModel),[s.ttsVoices,t.ttsModel]),Y=M.some(X=>X.value===t.ttsVoice)?t.ttsVoice:"",U=M.length===0?"当前模型暂无可用音色":Y?null:"请选择可用音色",G=b.useMemo(()=>lhe(r),[r]),I=G?null:"请输入正整数秒数",N=U??I,L=T||!!N,B=b.useMemo(()=>[{value:"cn",label:"中国大陆"},{value:"intl",label:"国际"}],[]),P=b.useMemo(()=>TI(s.asrModels,t.asrModel),[s.asrModels,t.asrModel]),D=b.useMemo(()=>che(s.ttsModels,s.ttsVoices,t.ttsModel),[s.ttsModels,s.ttsVoices,t.ttsModel]),F=b.useMemo(()=>TI(M,Y),[M,Y]);function q(){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??x0.turnIdleSeconds}}async function j(){if(T)return;if(N){_({kind:"error",message:N});return}const X=Ft;if(!X){_({kind:"error",message:"请先连接 Relay 服务器"});return}const ae=q();te(),_({kind:"saving"});const ne=performance.now();try{const ce=await X.updateVoiceConfig(ae);if(!A.current)return;const _e=performance.now()-ne;if(_e<xI&&await ahe(xI-_e),!A.current)return;if(!ce.success||ce.error||!ce.config){_({kind:"error",message:ce.error??"保存语音设置失败"});return}n(ce.config),i(String(ce.config.turnIdleSeconds)),u(""),f(!1),_({kind:"saved"}),R.current=setTimeout(()=>{R.current=null,_(xe=>xe.kind==="saved"?{kind:"idle"}:xe)},rhe),X.requestVoiceCapabilities({region:ce.config.region}).then(xe=>{A.current&&xe.capabilities&&o(xe.capabilities)}).catch(()=>{A.current&&o(ov())})}catch(ce){if(!A.current)return;_({kind:"error",message:ce instanceof Error?ce.message:"保存语音设置失败"})}}async function V(){if(T)return;if(N){_({kind:"error",message:N});return}const X=Ft;if(!X){_({kind:"error",message:"请先连接 Relay 服务器"});return}let ae;try{ae=K()}catch(ne){_({kind:"error",message:kI(ne)});return}_({kind:"testing"});try{const[ne]=await Promise.all([X.testVoiceConfig(q()),ae.ready]);if(!ne.success||ne.error){$(),_({kind:"error",message:ne.error??"语音配置测试失败"});return}const ce=await re(ne,ae.context);_({kind:"playingTest",transcript:ne.transcript}),k.current=setTimeout(()=>{k.current=null,$(),_({kind:"testPassed",transcript:ne.transcript})},ce)}catch(ne){$(),_({kind:"error",message:kI(ne)})}}function K(){$();const X=Pk.acquire("playback");S.current=X;try{const ae=ohe();return w.current=ae,{context:ae,ready:CI(ae)}}catch(ae){throw X.release(),S.current=null,ae}}function $(){var X,ae,ne;k.current&&(clearTimeout(k.current),k.current=null),(X=x.current)==null||X.stop(),x.current=null,(ae=w.current)==null||ae.close(),w.current=null,(ne=S.current)==null||ne.release(),S.current=null}function te(){R.current&&(clearTimeout(R.current),R.current=null)}async function re(X,ae){if(!X.audioBase64)throw new Error("语音测试未返回可播放音频");if(X.audioEncoding&&X.audioEncoding!=="pcm_s16le")throw new Error("测试音频格式暂不支持");const ne=X.audioSampleRate??24e3,ce=she(X.audioBase64);if(ce.byteLength===0||ce.byteLength%2!==0)throw new Error("测试音频数据无效");await CI(ae);const _e=new SF(ae,ne);x.current=_e,_e.enqueue(ce);const xe=Math.ceil(ce.byteLength/2/ne*1e3);return Math.max(nhe,xe)}function ee(X){var ae;return((ae=I1(s.ttsVoices,X)[0])==null?void 0:ae.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:X=>{X.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(SI,{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(Cz,{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:X=>{u(X.target.value),f(!1)},placeholder:d?"保存后清空":t.configured?"••••••••••••••••":"输入 API Key",className:`${wI} w-full pl-9`})]}),t.configured&&m.jsxs(yt,{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(Nz,{className:"size-4","aria-hidden":"true"}),"清空"]})]})}),m.jsx(wv,{label:"地域",value:t.region,options:B,onChange:X=>n(ae=>({...ae,region:X==="intl"?"intl":"cn"}))}),m.jsx(wv,{label:"语音识别模型",value:t.asrModel,options:P,onChange:X=>n(ae=>({...ae,asrModel:X}))}),m.jsx(wv,{label:"语音合成模型",value:t.ttsModel,options:D,onChange:X=>n(ae=>({...ae,ttsModel:X,ttsVoice:ee(X)}))}),m.jsx(wv,{label:"语音音色",value:Y,options:F,placeholder:M.length===0?"暂无可用音色":"请选择音色",onChange:X=>n(ae=>({...ae,ttsVoice:X})),help:U}),m.jsx(SI,{label:"结束停顿时间(秒)",help:I,children:m.jsx("input",{"aria-label":"结束停顿时间(秒)",type:"number",min:1,step:1,inputMode:"numeric",value:r,onChange:X=>i(X.target.value),className:`${wI} 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:[O?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:O}):null,m.jsxs(yt,{type:"button",variant:"outline",disabled:L,onClick:()=>void V(),children:[m.jsx(Tz,{className:"size-4","aria-hidden":"true"}),"测试"]}),m.jsxs(yt,{type:"submit",disabled:L,children:[m.jsx(sK,{className:"size-4","aria-hidden":"true"}),g.kind==="saving"?"保存中...":"保存"]})]})]})]})}function she(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 ohe(){const e=window,t=e.AudioContext??e.webkitAudioContext;if(!t)throw new Error("当前浏览器不支持音频播放");return new t}async function CI(e){if(e.state!=="running")try{await e.resume()}catch{throw new Error("浏览器阻止了测试音频播放,请再次点击测试")}if(e.state!=="running")throw new Error("浏览器阻止了测试音频播放,请再次点击测试")}function kI(e){return e instanceof Error?e.message:"语音配置测试失败"}function ahe(e){return new Promise(t=>setTimeout(t,e))}function lhe(e){const t=e.trim();if(!/^[1-9]\d*$/.test(t))return null;const n=Number(t);return Number.isSafeInteger(n)?n:null}function TI(e,t){const n=e.map(r=>({value:r.value,label:CF(r)}));return!t||n.some(r=>r.value===t)?n:[{value:t,label:t},...n]}function che(e,t,n){const r=e.map(i=>{const s=I1(t,i.value).length===0;return{value:i.value,label:`${CF(i)}${s?" · 暂无音色":""}`,disabled:s}});return!n||r.some(i=>i.value===n)?r:[{value:n,label:`${n} · 暂无音色`,disabled:!0},...r]}function EF(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 CF(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 uhe=[{value:"auto",label:"跟随系统"},{value:"light",label:"浅色"},{value:"dark",label:"深色"}],dhe=[{value:"auto",label:"自动"},{value:"touch",label:"触控优先"},{value:"hardware",label:"实体键盘优先"}],Ik="dev-render-scroll min-h-0 space-y-3 overflow-y-auto overscroll-contain pr-4 sm:pr-1";function kF(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 fhe(e){const t=e||window.location.origin;return new URL("/health",t).toString()}function hhe(e){return e==="version"?"版本":e==="relay-token"?"Relay Token":e==="clients"?"客户端管理":"设置 Voice Pilot"}function phe(e){return e==="version"?"Web 与 Relay 服务器版本。":e==="relay-token"?"连接受保护的 Relay 服务器,保存后立即重连。":e==="clients"?"管理当前连接的 Web 客户端。":"连接语音服务后,即可以语音交互的形式驱动会话。"}function O1({open:e,onOpenChange:t}){const n=Ae(G=>G.relayUrl),r=Ae(G=>G.latencyMonitorEnabled),i=Ae(G=>G.setLatencyMonitorEnabled),s=Ae(G=>G.sessionIdleNotificationsEnabled),o=Ae(G=>G.setSessionIdleNotificationsEnabled),l=Ae(G=>G.inputModePreference),u=Ae(G=>G.setInputModePreference),d=Ae(G=>G.themePreference),f=Ae(G=>G.setThemePreference),h=Ae(G=>G.ptyScrollTraceEnabled),y=Ae(G=>G.setPtyScrollTraceEnabled),[g,_]=b.useState("menu"),[w,S]=b.useState(e),[x,k]=b.useState({kind:"idle"}),R=b.useRef(null),A=b.useRef(null),O=Lse(),T=b.useMemo(()=>pf().osName==="iPad",[]);e!==w&&(S(e),e&&_("menu"));const M=b.useCallback(async G=>{if(!G){o(!1);return}const I=await ose();if(I==="granted"){o(!0);return}if(I==="denied"){Ue.error("浏览器未授予通知权限,请在浏览器设置中允许通知");return}if(I==="default"){Ue.info("未授予通知权限,会话通知保持关闭");return}Ue.error("当前浏览器不支持系统通知")},[o]),z=b.useCallback(async G=>{k({kind:"loading"});try{const I=await fetch(fhe(n),{cache:"no-store",signal:G});if(!I.ok)throw new Error(`HTTP ${I.status}`);const N=await I.json();if(N.status!=="ok")throw new Error("状态异常");k({kind:"ready",version:N.version??"未知",uptime:N.uptime??0})}catch(I){if(I instanceof DOMException&&I.name==="AbortError")return;k({kind:"error",message:I 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 I;(I=R.current)==null||I.focus({preventScroll:!0}),A.current&&(A.current.scrollTop=0)});return()=>window.cancelAnimationFrame(G)},[e,g]);const Y=x.kind==="ready"?x.version:x.kind==="loading"?"读取中...":x.kind==="error"?"读取失败":"未读取",U=x.kind==="ready"?`运行 ${kF(x.uptime)}`:x.kind==="error"?x.message:"从当前 Relay 服务器 /health 读取";return m.jsx(es,{open:e,onOpenChange:t,children:m.jsxs(ts,{className:Ye("grid max-h-[calc(100dvh-1rem)] grid-rows-[auto_minmax(0,1fr)] overflow-hidden p-4 sm:max-w-[440px] sm:p-6",g==="voice"&&"max-h-[min(760px,calc(100dvh-1rem))] !gap-0 !p-0 sm:max-w-[480px]",g==="voice"&&"max-sm:top-auto max-sm:bottom-0 max-sm:left-2 max-sm:right-2 max-sm:h-[calc(100dvh-1rem)] max-sm:w-auto max-sm:max-h-none max-sm:max-w-none max-sm:translate-x-0 max-sm:translate-y-0 max-sm:rounded-b-none max-sm:rounded-t-2xl max-sm:border-x max-sm:border-b-0"),"data-slot":"settings-dialog","data-view":g,focusSurfaceOnOpen:!0,ref:R,showCloseButton:g==="menu",children:[m.jsx(ns,{className:Ye(g==="menu"&&"pr-12 text-left",g!=="menu"&&"text-left",g==="voice"&&"gap-0 px-4 pb-0 pt-3.5 text-left sm:px-5 sm:pt-4"),children:g!=="menu"?m.jsxs(m.Fragment,{children:[m.jsxs("div",{className:"flex items-start gap-2",children:[m.jsx(yt,{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(ff,{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($i,{children:hhe(g)}),m.jsx(Es,{className:"max-w-[28rem] leading-5",children:phe(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($i,{children:"设置"}),m.jsx(Es,{children:"连接、外观、通知和高级诊断选项。"})]})}),g==="version"?m.jsx(mhe,{relayVersion:Y,relayDetail:U,relayMuted:x.kind==="error"}):g==="relay-token"?m.jsx(vhe,{saved:O}):g==="clients"?m.jsx(xhe,{}):g==="voice"?m.jsx(ihe,{scrollRef:A}):m.jsx(ghe,{relayTokenSaved:O,themePreference:d,onThemePreferenceChange:f,inputModePreference:l,onInputModePreferenceChange:u,showInputModeSetting:T,sessionIdleNotificationsEnabled:s,onSessionIdleNotificationsEnabledChange:M,ptyScrollTraceEnabled:h,onPtyScrollTraceEnabledChange:y,latencyMonitorEnabled:r,onLatencyMonitorEnabledChange:i,onOpenVoice:()=>_("voice"),onOpenRelayToken:()=>_("relay-token"),onOpenClients:()=>_("clients"),onOpenVersion:()=>_("version")})]})})}function mhe({relayVersion:e,relayDetail:t,relayMuted:n}){return m.jsxs("div",{className:Ik,"data-slot":"settings-dialog-body",children:[m.jsx(AI,{icon:m.jsx(kz,{className:"size-4","aria-hidden":"true"}),label:"Web",value:Gfe.version,detail:"当前浏览器加载的版本"}),m.jsx(AI,{icon:m.jsx(Rz,{className:"size-4","aria-hidden":"true"}),label:"Relay 服务器",value:e,detail:t,muted:n})]})}function ghe({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:y,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(dd,{title:"服务",children:[m.jsx(xv,{icon:m.jsx(AV,{className:"size-4","aria-hidden":"true"}),label:"Voice Pilot",detail:"用语音输入、听取回复和处理审批",onClick:y}),m.jsx(xv,{icon:m.jsx(Cz,{className:"size-4","aria-hidden":"true"}),label:"Relay Token",detail:`${e?"已保存":"未设置"} · 受保护的 Relay 服务器`,onClick:g}),m.jsx(xv,{icon:m.jsx(TK,{className:"size-4","aria-hidden":"true"}),label:"客户端管理",detail:"已连接的浏览器页面和设备",onClick:_})]}),m.jsx(dd,{title:"外观",children:m.jsx(RI,{icon:m.jsx(gK,{className:"size-4","aria-hidden":"true"}),label:"主题",value:t,options:uhe,onValueChange:n})}),m.jsx(dd,{title:"通知",children:m.jsx(E0,{icon:m.jsx(MV,{className:"size-4","aria-hidden":"true"}),label:"会话空闲通知",detail:"会话从工作中转为空闲时发送浏览器通知",checked:o,onCheckedChange:l})}),s?m.jsx(dd,{title:"交互",children:m.jsx(RI,{icon:m.jsx(SC,{className:"size-4","aria-hidden":"true"}),label:"输入方式",detail:"默认自动识别软键盘和实体键盘;必要时可强制一种方式",value:r,options:dhe,onValueChange:i})}):null,m.jsxs(dd,{title:"高级诊断",children:[m.jsx(E0,{icon:m.jsx(ru,{className:"size-4","aria-hidden":"true"}),label:"PTY 滚动追踪",detail:"记录终端滚动和视口同步现场,方便复制诊断报告",checked:u,onCheckedChange:d}),m.jsx(E0,{icon:m.jsx(vz,{className:"size-4","aria-hidden":"true"}),label:"延迟监控",detail:"显示可拖动的连接延迟浮窗",checked:f,onCheckedChange:h})]}),m.jsx(dd,{title:"关于",children:m.jsx(xv,{icon:m.jsx(Rz,{className:"size-4","aria-hidden":"true"}),label:"版本",onClick:w})})]})}function dd({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 RI({icon:e,label:t,detail:n,value:r,options:i,onValueChange:s}){const o=b.useId(),l=b.useId();return m.jsxs("div",{className:"flex w-full items-start gap-3 px-3 py-3 text-left","data-slot":"settings-choice-item",children:[m.jsx("div",{className:"flex size-8 shrink-0 items-center justify-center rounded-md bg-background/55 text-muted-foreground",children:e}),m.jsxs("div",{className:"min-w-0 flex-1",children:[m.jsx("div",{id:o,className:"text-sm font-medium text-foreground",children:t}),n?m.jsx("div",{id:l,className:"mt-1 text-xs text-muted-foreground",children:n}):null,m.jsx("div",{role:"radiogroup","aria-labelledby":o,"aria-describedby":n?l:void 0,className:"mt-3 grid grid-cols-3 gap-1 rounded-md border border-border bg-muted/70 p-1","data-slot":"settings-segmented-choice",children:i.map(u=>{const d=u.value===r;return m.jsx("button",{type:"button",role:"radio","aria-checked":d,className:Ye("min-w-0 whitespace-nowrap rounded px-2 py-1.5 text-xs font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",d?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:bg-background/55 hover:text-foreground"),onClick:()=>s(u.value),children:u.label},u.value)})})]})]})}function vhe({saved:e}){const t=b.useId(),n=b.useId(),[r,i]=b.useState(""),[s,o]=b.useState(null),l=()=>{b5().catch(f=>{o(f instanceof Error?f.message:"Relay 重连失败。")})},u=()=>{const f=r.trim();if(!f){o("请输入 token。");return}if(!v5(f)){const h="Relay Token 保存失败,请检查浏览器存储权限。";o(h),Ue.error(h);return}o(null),Ue.success("Relay Token 已保存,正在重新连接"),l()},d=()=>{y5(),l()};return m.jsxs("form",{className:Ik,"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(yt,{type:"button",variant:"outline",onClick:d,children:"清空"}):null,m.jsx(yt,{type:"submit",disabled:!r.trim(),children:"保存"})]})]})}function yhe(e){return e.length<=16?e:`${e.slice(0,8)}...${e.slice(-4)}`}function bhe(e,t){var r;return((r=t.get(e))==null?void 0:r.trim())||yhe(e)}function _he(e){return Zne(e)}function whe(e){const t=Math.max(0,Math.floor((Date.now()-e)/1e3));return kF(t)}function S0({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 xhe(){const e=Ae(y=>y.proxies),[t,n]=b.useState([]),[r,i]=b.useState(!0),[s,o]=b.useState(null),[l,u]=b.useState(null),d=b.useMemo(()=>new Map(e.map(y=>[y.proxyId,y.name]).filter(y=>typeof y[1]=="string")),[e]),f=b.useCallback(async()=>{const y=Ft;if(!y){n([]),o("Relay 未连接。"),i(!1);return}i(!0),o(null);try{n(await y.requestRelayClients())}catch(g){o(g instanceof Error?g.message:"读取客户端列表失败。")}finally{i(!1)}},[]);b.useEffect(()=>{f()},[f]);const h=b.useCallback(async y=>{const g=Ft;if(!g){o("Relay 未连接。");return}u(y),o(null);try{const _=await g.kickRelayClient(y);if(!_.success){o(_.error??"断开客户端失败。");return}n(w=>w.filter(S=>S.clientId!==y))}catch(_){o(_ instanceof Error?_.message:"断开客户端失败。")}finally{u(null)}},[]);return m.jsxs("div",{className:Ik,"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(yt,{type:"button",variant:"ghost",size:"icon-sm","aria-label":"刷新客户端列表",title:"刷新",onClick:()=>void f(),disabled:r,"data-slot":"relay-clients-refresh",children:m.jsx(fm,{className:Ye("size-3.5",r&&"animate-spin"),"aria-hidden":"true"})})]}),s?m.jsx("div",{className:"rounded-md border border-destructive/35 bg-destructive/10 px-3 py-2 text-xs text-destructive",children:s}):null,!r&&t.length===0?m.jsx("div",{className:"rounded-md border border-border bg-card/70 px-3 py-6 text-center text-sm text-muted-foreground",children:"当前没有在线客户端"}):null,t.map(y=>{const g=y.current===!0,_=l===y.clientId;return m.jsx("div",{className:"rounded-md border border-border bg-card/70 p-3","data-slot":"relay-client-row","data-client-id":y.clientId,title:`客户端 ${y.clientId}`,children: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:_he(y)})}),m.jsxs("div",{className:"space-y-1",children:[m.jsx(S0,{label:"已连接",value:whe(y.connectedAt)}),y.proxyId?m.jsx(S0,{label:"连接到",value:bhe(y.proxyId,d),title:y.proxyId}):null,y.remoteAddress?m.jsx(S0,{label:"来源 IP",value:y.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(yt,{type:"button",variant:"outline",size:"sm",className:"h-9 w-full justify-center",disabled:_,onClick:()=>void h(y.clientId),"data-slot":"relay-client-action",children:[m.jsx(PY,{className:"size-3.5","aria-hidden":"true"}),_?"断开中...":"断开"]})]})},y.clientId)})]})}function E0({icon:e,label:t,detail:n,checked:r,onCheckedChange:i}){const s=b.useId(),o=b.useId();return m.jsxs("button",{type:"button",role:"switch",className:"group flex w-full items-center gap-3 px-3 py-3 text-left transition-colors hover:bg-accent/55 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",onClick:()=>i(!r),"aria-checked":r,"aria-labelledby":s,"aria-describedby":o,"data-slot":"settings-toggle-item",children:[m.jsx("div",{className:Ye("flex size-8 shrink-0 items-center justify-center rounded-md bg-background/55 transition-colors",r?"text-primary":"text-muted-foreground"),children:e}),m.jsxs("div",{className:"min-w-0 flex-1",children:[m.jsx("div",{id:s,className:"text-sm font-medium text-foreground",children:t}),m.jsx("div",{id:o,className:"mt-1 text-xs text-muted-foreground",children:n})]}),m.jsx("span",{className:Ye("relative h-6 w-11 shrink-0 rounded-full border transition-colors",r?"border-primary/65 bg-primary/70":"border-border bg-muted/50"),"aria-hidden":"true","data-slot":"settings-toggle-switch",children:m.jsx("span",{className:Ye("absolute top-1/2 size-4 -translate-y-1/2 rounded-full bg-background shadow-sm transition-transform",r?"translate-x-[1.35rem]":"translate-x-1")})})]})}function xv({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(Hd,{className:"size-4 shrink-0 text-muted-foreground","aria-hidden":"true"})]})}function AI({icon:e,label:t,value:n,detail:r,muted:i=!1}){return m.jsxs("div",{className:"flex gap-3 rounded-md border border-border bg-card/70 p-3",children:[m.jsx("div",{className:Ye("mt-0.5 flex size-8 shrink-0 items-center justify-center rounded-md border",i?"border-border text-muted-foreground":"border-primary/35 bg-primary/10 text-primary"),children:e}),m.jsxs("div",{className:"min-w-0 flex-1",children:[m.jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[m.jsx("div",{className:"text-sm text-muted-foreground",children:t}),m.jsx("div",{className:"min-w-0 truncate font-mono text-sm text-foreground",children:n})]}),m.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:r})]})]})}const She="xterm-helper-textarea";function Ehe(e=document.activeElement){return!(e instanceof HTMLElement)||!e.classList.contains(She)?!1:(e.blur(),!0)}function NI(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&&Che(r,n))return!0;if(r===t)break;r=r.parentElement}return!1}function Che(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 khe({releasePtyFocus:e=!0,containVerticalScroll:t=!0}={}){const n=b.useRef(null),r=b.useCallback(()=>{e&&Ehe()},[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,NI(l.target,l.currentTarget,f)||l.preventDefault()},[t]),o=b.useCallback(l=>{r(),t&&(NI(l.target,l.currentTarget,l.deltaY)||l.preventDefault())},[t,r]);return{onPointerDownCapture:r,onTouchStartCapture:i,onTouchMoveCapture:s,onWheelCapture:o}}function The({className:e}){const t=Ae(o=>o.sidebarCollapsed),n=Ae(o=>o.toggleSidebarCollapsed),[r,i]=b.useState(!1),s=khe();return t?m.jsxs(m.Fragment,{children:[m.jsxs("nav",{className:Ye("dev-sidebar-shell dev-sidebar-rail relative flex-col items-center w-12 shrink-0 bg-card border-r border-border overflow-hidden px-1.5 pb-[calc(var(--dev-safe-area-bottom,env(safe-area-inset-bottom))+0.5rem)] pt-[max(0.5rem,env(safe-area-inset-top))]",e),"aria-label":"侧边栏","data-slot":"sidebar-rail","data-collapsed":"true",...s,children:[m.jsx(PI,{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(MI,{compact:!0,tooltipSide:"right",onClick:()=>i(!0)}),m.jsx(vI,{compact:!0})]})]}),m.jsx(O1,{open:r,onOpenChange:i})]}):m.jsxs(m.Fragment,{children:[m.jsxs("nav",{className:Ye("dev-sidebar-shell group/sidebar relative flex-col w-[280px] shrink-0 bg-card border-r border-border overflow-visible pt-[env(safe-area-inset-top)]",e),"aria-label":"侧边栏","data-slot":"sidebar","data-collapsed":"false",...s,children:[m.jsx("div",{className:"dev-sidebar-fade p-2.5","data-slot":"sidebar-proxy-switcher",children:m.jsxs("div",{className:"dev-sidebar-chrome rounded-lg border p-3",children:[m.jsxs("div",{className:"flex items-center justify-between gap-3",children:[m.jsx(Kz,{className:"text-[13px]",slot:"sidebar-brand"}),m.jsx(PI,{collapsed:!1,onClick:n})]}),m.jsx("div",{className:"mt-2.5",children:m.jsx(sF,{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(yF,{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(vI,{})}),m.jsx("div",{className:"min-w-0 flex-1",children:m.jsx(MI,{onClick:()=>i(!0)})})]})]}),m.jsx(O1,{open:r,onOpenChange:i})]})}function MI({compact:e=!1,tooltipSide:t="top",onClick:n}){return m.jsxs(Sf,{delayDuration:500,children:[m.jsx(Ef,{asChild:!0,children:m.jsxs("button",{type:"button","aria-label":"设置","data-slot":"sidebar-settings-trigger",onClick:n,className:Ye("inline-flex items-center justify-center shrink-0 border text-muted-foreground outline-none transition-[color,background-color,border-color,box-shadow]","focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",e?"h-11 w-11 rounded-md border-border bg-card/70 hover:border-primary/60 hover:bg-accent hover:text-foreground":"h-[46px] w-full gap-2 rounded-md border-border bg-background hover:border-primary/50 hover:bg-accent hover:text-foreground"),children:[m.jsx(Az,{className:"size-4","aria-hidden":"true"}),!e&&m.jsx("span",{className:"truncate text-sm font-medium",children:"设置"})]})}),m.jsx(Cf,{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 PI({collapsed:e,onClick:t}){const n=e?"展开侧边栏":"收起侧边栏",r=e?WY:HY;return m.jsxs(Sf,{delayDuration:500,children:[m.jsx(Ef,{asChild:!0,children:m.jsx("button",{type:"button","aria-label":n,"data-slot":e?"sidebar-expand-trigger":"sidebar-collapse-trigger",onClick:t,className:Ye("group inline-flex items-center justify-center text-muted-foreground outline-none transition-[opacity,color,background-color,border-color,box-shadow,transform]","outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",e?"h-9 w-9 rounded-md border border-border/80 bg-card/70 hover:border-primary/60 hover:bg-accent hover:text-foreground":"h-9 w-9 rounded-full border border-primary/25 bg-primary/10 hover:border-primary/60 hover:bg-primary/15 hover:text-foreground"),children:m.jsx(r,{className:Ye("size-3.5 transition-transform",e&&"group-hover:translate-x-0.5",!e&&"group-hover:-translate-x-0.5"),"aria-hidden":"true"})})}),m.jsx(Cf,{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 Rhe=1500,Ahe=300,II=70,OI=35;function TF({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],y=()=>{const g=o.current;if(g==="typing"){const _=h();l.current<_.length?(l.current+=1,r(_.slice(0,l.current)),f=setTimeout(y,II)):(o.current="paused",f=setTimeout(y,Rhe))}else g==="paused"?(o.current="deleting",f=setTimeout(y,OI)):g==="deleting"?l.current>0?(l.current-=1,r(h().slice(0,l.current)),f=setTimeout(y,OI)):(u.current+=1,o.current="waiting",f=setTimeout(y,Ahe)):(o.current="typing",f=setTimeout(y,II))};return f=setTimeout(y,500),()=>clearTimeout(f)},[e]);const d=n.startsWith("DEV")?3:n.length<=3&&"DEV".startsWith(n)?n.length:0;return m.jsxs("div",{className:`font-mono leading-tight select-none ${t??""}`,"data-slot":"brand-typewriter",children:[m.jsx("span",{className:"text-green-500",children:"> "}),m.jsx("span",{className:"text-primary","data-slot":"brand-typewriter-dev",children:n.slice(0,d)}),m.jsx("span",{className:"text-foreground/90",children:n.slice(d)}),m.jsx("span",{className:`text-primary ${i?"opacity-100":"opacity-0"}`,children:"_"})]})}const RF=["DEV Anywhere","/unlimited @anytime"];function Nhe({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(TF,{texts:RF,className:"dev-mobile-brand-typewriter max-w-full overflow-hidden text-ellipsis whitespace-nowrap font-bold tracking-normal"}),e?m.jsx("p",{className:"dev-mobile-brand-subtitle max-w-[34rem] text-sm leading-5 text-muted-foreground",children:e}):null,t?m.jsx("div",{className:"dev-mobile-brand-action flex max-w-full min-w-0 pt-1",children:t}):null]})})}const Mhe=3e3,Phe=1e4,Sv=12,Ihe=4,LI={webRelay:"浏览器 ↔ Relay 服务器",relayProxy:"Relay 服务器 ↔ 开发机",webProxy:"浏览器 ↔ 开发机"},Ohe={webRelay:{state:"idle"},relayProxy:{state:"idle"},webProxy:{state:"idle"}};function C0(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 fd(e){return{state:"unavailable",error:e,updatedAt:Date.now()}}function fp(e){return e===void 0||!Number.isFinite(e)?"--":`${Math.max(0,Math.round(e))}ms`}function DI(e){switch(e){case"bad":return 4;case"unavailable":return 3;case"warn":return 2;case"measuring":return 1;default:return 0}}function AF(e){return e==="bad"||e==="unavailable"?"bad":e==="warn"?"warn":e==="ok"?"ok":"neutral"}function Lhe(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 Dhe(e){return e.state==="measuring"?"检测中":e.state==="unavailable"?e.error??"不可用":e.rttMs!==void 0?fp(e.rttMs):"等待检测"}function Bhe(){const e=Ni("local",Sn.latencyMonitorPosition);if(!e)return null;try{const t=JSON.parse(e);return!Number.isFinite(t.x)||!Number.isFinite(t.y)?null:{x:Number(t.x),y:Number(t.y)}}catch{return null}}function BI(e){Mr("local",Sn.latencyMonitorPosition,JSON.stringify(e))}function zhe(){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 k0(e,t){const n=zhe(),r=Sv,i=Sv,s=Math.max(r,n.width-t.width-Sv),o=Math.max(i,n.height-t.height-Sv);return{x:Math.min(s,Math.max(r,Math.round(e.x))),y:Math.min(o,Math.max(i,Math.round(e.y)))}}function jhe(){const e=Ae(T=>T.latencyMonitorEnabled),t=Ae(T=>T.connected),n=Ae(T=>T.proxyOnline),r=Ae(T=>T.selectedProxyId),[i,s]=b.useState(Ohe),[o,l]=b.useState(()=>Bhe()),u=b.useRef(!1),d=b.useRef(null),f=b.useRef(null),h=b.useRef(!1),y=b.useMemo(()=>(Object.values(i).sort((T,M)=>DI(M.state)-DI(T.state))[0]??{state:"idle"}).state,[i]),g=AF(y);async function _(){if(u.current)return;const T=Ft;if(!T||!t){const U=fd("Relay 服务器未连接");s({webRelay:U,relayProxy:U,webProxy:U});return}u.current=!0,s(U=>({webRelay:{...U.webRelay,state:"measuring"},relayProxy:n?{...U.relayProxy,state:"measuring"}:fd("未连接开发机"),webProxy:n?{...U.webProxy,state:"measuring"}:fd("未连接开发机")}));const[M,z,Y]=await Promise.allSettled([T.measureWebRelayLatency(),n?T.measureRelayProxyLatency():Promise.resolve({success:!1}),n?T.measureWebProxyLatency():Promise.resolve({success:!1})]);s({webRelay:M.status==="fulfilled"?C0(M.value):fd(M.reason instanceof Error?M.reason.message:"测速失败"),relayProxy:z.status==="fulfilled"?C0(z.value):fd(z.reason instanceof Error?z.reason.message:"测速失败"),webProxy:Y.status==="fulfilled"?C0(Y.value):fd(Y.reason instanceof Error?Y.reason.message:"测速失败")}),u.current=!1}if(b.useEffect(()=>{if(!e)return;let T=!1,M=null;const z=async()=>{await _(),!T&&(M=setTimeout(z,document.hidden?Phe:Mhe))};return z(),()=>{T=!0,u.current=!1,M&&clearTimeout(M)}},[e,t,n,r]),b.useEffect(()=>{if(!e||!o)return;const T=d.current;if(!T)return;const M=T.getBoundingClientRect(),z=k0(o,{width:M.width,height:M.height});z.x===o.x&&z.y===o.y||(l(z),BI(z))},[e,o]),!e)return null;const w=i.webProxy.rttMs!==void 0?i.webProxy:i.relayProxy,S=o!==null?{left:`${o.x}px`,top:`${o.y}px`}:void 0;function x(T){var z,Y;if(T.button!==0)return;const M=T.currentTarget.getBoundingClientRect();f.current={pointerId:T.pointerId,startX:T.clientX,startY:T.clientY,originX:M.left,originY:M.top,width:M.width,height:M.height,dragging:!1},(Y=(z=T.currentTarget).setPointerCapture)==null||Y.call(z,T.pointerId)}function k(T){const M=f.current;if(!M||M.pointerId!==T.pointerId)return;const z=T.clientX-M.startX,Y=T.clientY-M.startY;if(!M.dragging&&Math.hypot(z,Y)<Ihe)return;M.dragging=!0,T.preventDefault();const U=k0({x:M.originX+z,y:M.originY+Y},{width:M.width,height:M.height});l(U)}function R(T){var G,I;const M=f.current;if(!M||M.pointerId!==T.pointerId||(f.current=null,(I=(G=T.currentTarget).releasePointerCapture)==null||I.call(G,T.pointerId),!M.dragging))return;T.preventDefault(),h.current=!0,window.setTimeout(()=>{h.current=!1},200);const z=T.clientX-M.startX,Y=T.clientY-M.startY,U=k0({x:M.originX+z,y:M.originY+Y},{width:M.width,height:M.height});l(U),BI(U)}function A(T){var z,Y;const M=f.current;!M||M.pointerId!==T.pointerId||(f.current=null,(Y=(z=T.currentTarget).releasePointerCapture)==null||Y.call(z,T.pointerId))}function O(T){h.current&&(h.current=!1,T.preventDefault(),T.stopPropagation())}return m.jsxs(Ub,{children:[m.jsx(Wb,{asChild:!0,children:m.jsxs("button",{ref:d,type:"button",className:Ye("fixed z-40 flex max-w-[calc(100vw-1.5rem)] touch-none cursor-move select-none items-center gap-2 rounded-md border px-2.5 py-1.5 text-xs shadow-lg backdrop-blur transition-colors",o===null&&"right-[calc(env(safe-area-inset-right)+0.75rem)] top-[calc(env(safe-area-inset-top)+3.75rem)] md:right-4 md:top-4",Lhe(g)),style:S,"data-slot":"latency-monitor-trigger","aria-label":`延迟监控,Relay 服务器 ${fp(i.webRelay.rttMs)},开发机 ${fp(w.rttMs)}`,onPointerDown:x,onPointerMove:k,onPointerUp:R,onPointerCancel:A,onClickCapture:O,children:[m.jsx(vz,{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 ",fp(i.webRelay.rttMs)]}),m.jsxs("span",{className:"text-muted-foreground",children:["开发机 ",fp(w.rttMs)]}),m.jsx(sc,{className:"size-3 text-muted-foreground","aria-hidden":"true"})]})}),m.jsxs(qb,{align:"end",className:"w-[320px] p-3","data-slot":"latency-monitor-popover",children:[m.jsxs("div",{className:"flex items-start justify-between gap-3",children:[m.jsxs("div",{children:[m.jsx("div",{className:"text-sm font-medium text-foreground",children:"连接延迟"}),m.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:"数值越低,操作响应通常越快。"})]}),m.jsx(yt,{type:"button",variant:"ghost",size:"icon-xs","aria-label":"立即测速",onClick:()=>void _(),children:m.jsx(fm,{className:"size-3","aria-hidden":"true"})})]}),m.jsx("div",{className:"mt-3 space-y-2",children:Object.keys(LI).map(T=>m.jsx(Fhe,{label:LI[T],measurement:i[T]},T))})]})]})}function Fhe({label:e,measurement:t}){const n=AF(t.state);return m.jsxs("div",{className:"flex min-h-10 items-center justify-between gap-3 rounded-md border border-border/70 bg-card/60 px-3 py-2",children:[m.jsx("div",{className:"min-w-0 truncate text-xs font-medium text-foreground",children:e}),m.jsxs("div",{className:"flex items-center gap-2",children:[m.jsx("span",{className:Ye("size-1.5 rounded-full",n==="ok"?"bg-emerald-400":n==="warn"?"bg-amber-400":n==="bad"?"bg-destructive":"bg-muted-foreground/60"),"aria-hidden":"true"}),m.jsx("span",{className:"min-w-[4rem] text-right font-mono text-xs text-foreground",children:Dhe(t)})]})]})}const NF="/__dev_anywhere_debug/browser-state-dumps",$he=1500,Hhe=10,T0=80,Ok=500,Uhe=["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"],Whe=["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 zI(){if(typeof window>"u")return"off";const e=zF("debugDump");return e==="auto"?"auto":e!==null||Qhe("debugInput")?"manual":"off"}function qhe(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:Ghe(),document:{title:document.title,readyState:document.readyState,visibilityState:document.visibilityState,activeElement:jI(document.activeElement),selection:Xhe(),focusedInputs:Array.from(document.querySelectorAll("input, textarea, select, [contenteditable]")).filter(i=>i===document.activeElement||i.matches(":focus")).map(i=>jI(i)).filter(i=>!!i),root:MF(document.documentElement,0,t),truncated:t.truncated,nodeCount:t.count},devAnywhere:{ptyDebug:hd(()=>{var i;return((i=n.__devAnywherePtyDebug)==null?void 0:i.call(n))??null}),ptyInputDebugSnapshot:hd(()=>n.__devAnywherePtyInputDebugSnapshot??null),ptyInputDebugText:n.__devAnywherePtyInputDebugText??null,ptyInputDebugEvents:hd(()=>n.__devAnywherePtyInputDebugEvents??null),ptyScrollTraceTail:hd(()=>FI(n.__devAnywherePtyScrollTrace)),jsonScrollTraceTail:hd(()=>FI(n.__devAnywhereJsonScrollTrace)),voicePilotDiagnostics:hd(()=>{var i;return((i=n.__devAnywhereVoicePilotDiagnostics)==null?void 0:i.snapshot())??null})}};return window.__devAnywhereLastBrowserStateDump=r,r}async function Vhe(e="manual"){const t=qhe(e);return Yhe(t)}async function Yhe(e){const t=JSON.stringify(e,null,2),n=new Blob([t]).size;try{const r=await Khe(t);return{status:"saved",path:r.path,bytes:r.bytes,endpoint:NF}}catch(r){const i=jF(r),s=Zhe(e.createdAt);return Jhe(s,t,"application/json")?{status:"downloaded",filename:s,bytes:n,endpointError:i}:{status:"failed",error:"无法保存或下载诊断包",endpointError:i}}}async function Khe(e){const t=await fetch(NF,{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 MF(e,t,n){if(n.count>=$he||t>Hhe)return n.truncated=!0,{kind:"truncated"};if(n.count+=1,e.nodeType===Node.TEXT_NODE){const u=$I(e.textContent??"");return u?{kind:"text",text:Qb(u,Ok)}:{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,T0))u.nodeType===Node.TEXT_NODE&&!$I(u.textContent??"")||r.push(MF(u,t+1,n));s.length>T0&&(i=s.length-T0,n.truncated=!0);const o={kind:"element",tag:e.tagName.toLowerCase(),path:BF(e),attrs:PF(e),rect:IF(e),scroll:OF(e),style:LF(e)},l=DF(e);return l&&(o.value=l),r.length>0&&(o.children=r),i>0&&(o.omittedChildren=i),o}function jI(e){if(!(e instanceof HTMLElement))return null;const t=DF(e);return{path:BF(e),tag:e.tagName.toLowerCase(),id:e.id||null,className:e.className||null,attrs:PF(e),rect:IF(e),scroll:OF(e),style:LF(e),...t?{value:t}:{}}}function Ghe(){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 PF(e){const t={};for(const n of Uhe){const r=e.getAttribute(n);r!==null&&(t[n]=Qb(r,500))}return t}function IF(e){const t=e.getBoundingClientRect();return{x:Ss(t.x),y:Ss(t.y),width:Ss(t.width),height:Ss(t.height),top:Ss(t.top),right:Ss(t.right),bottom:Ss(t.bottom),left:Ss(t.left)}}function OF(e){return{top:Ss(e.scrollTop),left:Ss(e.scrollLeft),height:Ss(e.scrollHeight),width:Ss(e.scrollWidth),clientHeight:Ss(e.clientHeight),clientWidth:Ss(e.clientWidth)}}function LF(e){const t=window.getComputedStyle(e),n={};for(const r of Whe)n[r]=t.getPropertyValue(r);return n}function DF(e){if(!(!(e instanceof HTMLInputElement)&&!(e instanceof HTMLTextAreaElement)))return{length:e.value.length,preview:Qb(e.value,Ok),selectionStart:e.selectionStart,selectionEnd:e.selectionEnd}}function Xhe(){var e;try{return Qb(((e=window.getSelection())==null?void 0:e.toString())??"",Ok)}catch{return null}}function BF(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 Zhe(e){return`dev-anywhere-browser-state-${e.replace(/[:.]/g,"-")}.json`}function Jhe(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 Qhe(e){return zF(e)!==null}function zF(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 FI(e){return e?qy(e.slice(-200)):null}function hd(e){try{return qy(e())}catch(t){return{error:jF(t)}}}function qy(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(qy);if(typeof e=="object"){const t={};for(const[n,r]of Object.entries(e))t[n]=qy(r);return t}return String(e)}function $I(e){return e.replace(/\s+/g," ").trim()}function Qb(e,t){return e.length>t?`${e.slice(0,t)}...`:e}function Ss(e){return Math.round(e*100)/100}function jF(e){return e instanceof Error?e.message:String(e)}const epe=500,tpe=1e3,npe=60;function rpe(){const[e,t]=b.useState(()=>zI()),[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(zI());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 Vhe(_);return o.current=w,s(w),(_==="manual"||w.status==="failed")&&ipe(w),w}finally{l.current=!1,r(!1)}},[]);if(b.useEffect(()=>(window.__devAnywhereDumpBrowserState=h,()=>{window.__devAnywhereDumpBrowserState===h&&delete window.__devAnywhereDumpBrowserState}),[h]),b.useEffect(()=>{var k,R;if(e!=="auto")return;const _=()=>{f.current!==null&&(window.clearTimeout(f.current),f.current=null)},w=A=>{d.current>=npe||(_(),f.current=window.setTimeout(()=>{f.current=null;const O=Date.now(),T=tpe-(O-u.current);if(T>0){f.current=window.setTimeout(()=>w(A),T);return}u.current=Date.now(),d.current+=1,h(`auto:${d.current}:${A}`)},epe))};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)),(k=window.visualViewport)==null||k.addEventListener("resize",x),(R=window.visualViewport)==null||R.addEventListener("scroll",x),()=>{var A,O;_(),S.forEach(T=>window.removeEventListener(T,x,!0)),(A=window.visualViewport)==null||A.removeEventListener("resize",x),(O=window.visualViewport)==null||O.removeEventListener("scroll",x)}},[h,e]),e==="off")return null;const y=e==="auto"?"自动诊断中":"保存诊断",g=spe(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(yt,{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(di,{className:"size-3.5 animate-spin","aria-hidden":"true"}):m.jsx(pY,{className:"size-3.5","aria-hidden":"true"}),m.jsx("span",{children:y})]})]})}function ipe(e){if(e.status==="saved"){Ue.success(`诊断已保存: ${e.path}`);return}if(e.status==="downloaded"){Ue.info(`诊断已下载: ${e.filename}`);return}Ue.error(e.endpointError?`${e.error}: ${e.endpointError}`:e.error)}function spe(e){return e?e.status==="saved"?`已保存 ${e.path}`:e.status==="downloaded"?`已下载 ${e.filename}`:`失败 ${e.endpointError??e.error}`:null}function ope({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(di,{className:"size-5 animate-spin","aria-hidden":"true"}):null,m.jsx("p",{className:"text-sm",children:t}),n?m.jsx(yt,{type:"button",size:"sm",onClick:()=>window.location.reload(),children:n}):null]})}function ape(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 Lk(e){const{windowKey:t,storageKey:n,maxEntries:r=5e3,dedupeKey:i}=e,s=new Map,o=()=>typeof window>"u"?!1:ape(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 y=s.get(d.event);if(y&&i(y)===h&&f.includes(y)){y.t=d.t,y.repeat=(y.repeat??0)+1;const g=f.indexOf(y);g>=0&&g!==f.length-1&&(f.splice(g,1),f.push(y)),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 y of h)s.get(y.event)===y&&s.delete(y.event)}u(f)},getAll:l}}function Zn(e){return Math.round(e*10)/10}function Bl(e){return e.length===0?"":`${Zn(Math.min(...e))}..${Zn(Math.max(...e))}`}function Od(e){return[...new Set(e.filter(t=>t!==void 0).map(Zn))]}function FF(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 lpe="dev_anywhere_pty_input_latency_trace",HI=80,cpe=1e4,upe=new TextDecoder;let dpe=0;const af=new Map,Cu=Lk({windowKey:"__devAnywherePtyInputLatencyTrace",storageKey:lpe,dedupeKey:e=>e.event.startsWith("input")?null:`${e.event}|${e.sessionId}|${e.outputSeq??""}|${e.pendingInputs??""}`});function fpe(){typeof window>"u"||(window.__devAnywherePtyInputLatencyReport=gpe)}function hpe(e,t){if(!Cu.isEnabled())return null;const n=`pty-in-${Date.now().toString(36)}-${++dpe}`,r=performance.now(),i={inputId:n,sessionId:e,data:t,kind:bpe(t),dataLength:t.length,startedAt:r,sentAt:null,firstOutputAt:null,echoMatchedAt:null,xtermWriteAt:null,paintAt:null},s=af.get(e)??[];return s.push(i),Bk(s,r),af.set(e,s),Rm({t:r,event:"input:start",sessionId:e,inputId:n,inputKind:i.kind,dataLength:i.dataLength,pendingInputs:s.length}),{inputId:n,sessionId:e}}function UI(e,t){if(!e||!Cu.isEnabled())return;const n=performance.now(),r=vpe(e.sessionId,e.inputId);r&&(r.sentAt=n),Rm({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 ppe(e,t,n){if(!Cu.isEnabled())return;const r=performance.now(),i=Dk(e,r),s=xpe(t),o=[],l=[];for(const u of i)u.firstOutputAt===null&&(u.firstOutputAt=r,o.push(u.inputId)),u.echoMatchedAt===null&&wpe(u)&&s.includes(u.data)&&(u.echoMatchedAt=r,l.push(u.inputId));Rm({t:r,event:"output:received",sessionId:e,outputSeq:n,bytes:t.byteLength,pendingInputs:i.length,deltaFromInputMs:zk(i,r),details:Spe([o.length>0?`first=${o.length}`:"",l.length>0?`echo=${l.length}`:""])})}function mpe(e,t,n=1){if(!Cu.isEnabled())return;const r=performance.now(),i=Dk(e,r),s=[];for(const o of i)o.xtermWriteAt===null&&(o.xtermWriteAt=r,s.push(o.inputId));Rm({t:r,event:"output:xterm-write",sessionId:e,bytes:t,chunkCount:n,pendingInputs:i.length,deltaFromInputMs:zk(i,r),details:s.length>0?`firstWrite=${s.length}`:""}),typeof requestAnimationFrame=="function"&&s.length>0&&requestAnimationFrame(()=>ype(e,s))}function gpe(){const e=Cu.getAll(),t=e.slice(-200),n=[...af.values()].flat(),r=n.slice(-80).map(s=>[s.inputId,s.sessionId,s.kind,s.dataLength,s.sentAt===null?"":Zn(s.sentAt-s.startedAt),s.firstOutputAt===null?"":Zn(s.firstOutputAt-s.startedAt),s.echoMatchedAt===null?"":Zn(s.echoMatchedAt-s.startedAt),s.xtermWriteAt===null?"":Zn(s.xtermWriteAt-s.startedAt),s.paintAt===null?"":Zn(s.paintAt-s.startedAt)].join(" ")),i=t.map(s=>[Zn(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?"":Zn(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(`
|
|
600
|
+
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},mae="DialogDescriptionWarning",gae=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${Z5(mae).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},ok=B5,vae=j5,ak=$5,lk=H5,ck=U5,J5=q5,Q5=Y5,Rb=G5;function yae(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 bae(e){const[t,n]=b.useState(void 0);return Ji(()=>{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 _ae=["top","right","bottom","left"],ec=Math.min,$s=Math.max,zy=Math.round,vv=Math.floor,aa=e=>({x:e,y:e}),wae={left:"right",right:"left",bottom:"top",top:"bottom"};function p1(e,t,n){return $s(e,ec(t,n))}function Va(e,t){return typeof e=="function"?e(t):e}function Ya(e){return e.split("-")[0]}function vf(e){return e.split("-")[1]}function uk(e){return e==="x"?"y":"x"}function dk(e){return e==="y"?"height":"width"}function ra(e){const t=e[0];return t==="t"||t==="b"?"y":"x"}function fk(e){return uk(ra(e))}function xae(e,t,n){n===void 0&&(n=!1);const r=vf(e),i=fk(e),s=dk(i);let o=i==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(o=jy(o)),[o,jy(o)]}function Sae(e){const t=jy(e);return[m1(e),t,m1(t)]}function m1(e){return e.includes("start")?e.replace("start","end"):e.replace("end","start")}const V2=["left","right"],Y2=["right","left"],Eae=["top","bottom"],Cae=["bottom","top"];function kae(e,t,n){switch(e){case"top":case"bottom":return n?t?Y2:V2:t?V2:Y2;case"left":case"right":return t?Eae:Cae;default:return[]}}function Tae(e,t,n,r){const i=vf(e);let s=kae(Ya(e),n==="start",r);return i&&(s=s.map(o=>o+"-"+i),t&&(s=s.concat(s.map(m1)))),s}function jy(e){const t=Ya(e);return wae[t]+e.slice(t.length)}function Rae(e){return{top:0,right:0,bottom:0,left:0,...e}}function e3(e){return typeof e!="number"?Rae(e):{top:e,right:e,bottom:e,left:e}}function Fy(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 K2(e,t,n){let{reference:r,floating:i}=e;const s=ra(t),o=fk(t),l=dk(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,y=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(vf(t)){case"start":g[o]-=y*(n&&d?-1:1);break;case"end":g[o]+=y*(n&&d?-1:1);break}return g}async function Aae(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:y=!1,padding:g=0}=Va(t,e),_=e3(g),S=l[y?h==="floating"?"reference":"floating":h],x=Fy(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})),k=h==="floating"?{x:r,y:i,width:o.floating.width,height:o.floating.height}:o.reference,R=await(s.getOffsetParent==null?void 0:s.getOffsetParent(l.floating)),A=await(s.isElement==null?void 0:s.isElement(R))?await(s.getScale==null?void 0:s.getScale(R))||{x:1,y:1}:{x:1,y:1},O=Fy(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:l,rect:k,offsetParent:R,strategy:u}):k);return{top:(x.top-O.top+_.top)/A.y,bottom:(O.bottom-x.bottom+_.bottom)/A.y,left:(x.left-O.left+_.left)/A.x,right:(O.right-x.right+_.right)/A.x}}const Nae=50,Mae=async(e,t,n)=>{const{placement:r="bottom",strategy:i="absolute",middleware:s=[],platform:o}=n,l=o.detectOverflow?o:{...o,detectOverflow:Aae},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}=K2(d,r,u),y=r,g=0;const _={};for(let w=0;w<s.length;w++){const S=s[w];if(!S)continue;const{name:x,fn:k}=S,{x:R,y:A,data:O,reset:T}=await k({x:f,y:h,initialPlacement:r,placement:y,strategy:i,middlewareData:_,rects:d,platform:l,elements:{reference:e,floating:t}});f=R??f,h=A??h,_[x]={..._[x],...O},T&&g<Nae&&(g++,typeof T=="object"&&(T.placement&&(y=T.placement),T.rects&&(d=T.rects===!0?await o.getElementRects({reference:e,floating:t,strategy:i}):T.rects),{x:f,y:h}=K2(d,y,u)),w=-1)}return{x:f,y:h,placement:y,strategy:i,middlewareData:_}},Pae=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}=Va(e,t)||{};if(d==null)return{};const h=e3(f),y={x:n,y:r},g=fk(i),_=dk(g),w=await o.getDimensions(d),S=g==="y",x=S?"top":"left",k=S?"bottom":"right",R=S?"clientHeight":"clientWidth",A=s.reference[_]+s.reference[g]-y[g]-s.floating[_],O=y[g]-s.reference[g],T=await(o.getOffsetParent==null?void 0:o.getOffsetParent(d));let M=T?T[R]:0;(!M||!await(o.isElement==null?void 0:o.isElement(T)))&&(M=l.floating[R]||s.floating[_]);const z=A/2-O/2,Y=M/2-w[_]/2-1,U=ec(h[x],Y),G=ec(h[k],Y),I=U,N=M-w[_]-G,L=M/2-w[_]/2+z,B=p1(I,L,N),P=!u.arrow&&vf(i)!=null&&L!==B&&s.reference[_]/2-(L<I?U:G)-w[_]/2<0,D=P?L<I?L-I:L-N:0;return{[g]:y[g]+D,data:{[g]:B,centerOffset:L-B-D,...P&&{alignmentOffset:D}},reset:P}}}),Iae=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:y,fallbackStrategy:g="bestFit",fallbackAxisSideDirection:_="none",flipAlignment:w=!0,...S}=Va(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const x=Ya(i),k=ra(l),R=Ya(l)===l,A=await(u.isRTL==null?void 0:u.isRTL(d.floating)),O=y||(R||!w?[jy(l)]:Sae(l)),T=_!=="none";!y&&T&&O.push(...Tae(l,w,_,A));const M=[l,...O],z=await u.detectOverflow(t,S),Y=[];let U=((r=s.flip)==null?void 0:r.overflows)||[];if(f&&Y.push(z[x]),h){const L=xae(i,o,A);Y.push(z[L[0]],z[L[1]])}if(U=[...U,{placement:i,overflows:Y}],!Y.every(L=>L<=0)){var G,I;const L=(((G=s.flip)==null?void 0:G.index)||0)+1,B=M[L];if(B&&(!(h==="alignment"?k!==ra(B):!1)||U.every(F=>ra(F.placement)===k?F.overflows[0]>0:!0)))return{data:{index:L,overflows:U},reset:{placement:B}};let P=(I=U.filter(D=>D.overflows[0]<=0).sort((D,F)=>D.overflows[1]-F.overflows[1])[0])==null?void 0:I.placement;if(!P)switch(g){case"bestFit":{var N;const D=(N=U.filter(F=>{if(T){const q=ra(F.placement);return q===k||q==="y"}return!0}).map(F=>[F.placement,F.overflows.filter(q=>q>0).reduce((q,j)=>q+j,0)]).sort((F,q)=>F[1]-q[1])[0])==null?void 0:N[0];D&&(P=D);break}case"initialPlacement":P=l;break}if(i!==P)return{reset:{placement:P}}}return{}}}};function G2(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function X2(e){return _ae.some(t=>e[t]>=0)}const Oae=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n,platform:r}=t,{strategy:i="referenceHidden",...s}=Va(e,t);switch(i){case"referenceHidden":{const o=await r.detectOverflow(t,{...s,elementContext:"reference"}),l=G2(o,n.reference);return{data:{referenceHiddenOffsets:l,referenceHidden:X2(l)}}}case"escaped":{const o=await r.detectOverflow(t,{...s,altBoundary:!0}),l=G2(o,n.floating);return{data:{escapedOffsets:l,escaped:X2(l)}}}default:return{}}}}},t3=new Set(["left","top"]);async function Lae(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=vf(n),u=ra(n)==="y",d=t3.has(o)?-1:1,f=s&&u?-1:1,h=Va(t,e);let{mainAxis:y,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:y*d}:{x:y*d,y:g*f}}const Dae=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 Lae(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}}}}},Bae=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:k,y:R}=x;return{x:k,y:R}}},...d}=Va(e,t),f={x:n,y:r},h=await s.detectOverflow(t,d),y=ra(Ya(i)),g=uk(y);let _=f[g],w=f[y];if(o){const x=g==="y"?"top":"left",k=g==="y"?"bottom":"right",R=_+h[x],A=_-h[k];_=p1(R,_,A)}if(l){const x=y==="y"?"top":"left",k=y==="y"?"bottom":"right",R=w+h[x],A=w-h[k];w=p1(R,w,A)}const S=u.fn({...t,[g]:_,[y]:w});return{...S,data:{x:S.x-n,y:S.y-r,enabled:{[g]:o,[y]:l}}}}}},zae=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}=Va(e,t),f={x:n,y:r},h=ra(i),y=uk(h);let g=f[y],_=f[h];const w=Va(l,t),S=typeof w=="number"?{mainAxis:w,crossAxis:0}:{mainAxis:0,crossAxis:0,...w};if(u){const R=y==="y"?"height":"width",A=s.reference[y]-s.floating[R]+S.mainAxis,O=s.reference[y]+s.reference[R]-S.mainAxis;g<A?g=A:g>O&&(g=O)}if(d){var x,k;const R=y==="y"?"width":"height",A=t3.has(Ya(i)),O=s.reference[h]-s.floating[R]+(A&&((x=o.offset)==null?void 0:x[h])||0)+(A?0:S.crossAxis),T=s.reference[h]+s.reference[R]+(A?0:((k=o.offset)==null?void 0:k[h])||0)-(A?S.crossAxis:0);_<O?_=O:_>T&&(_=T)}return{[y]:g,[h]:_}}}},jae=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}=Va(e,t),f=await o.detectOverflow(t,d),h=Ya(i),y=vf(i),g=ra(i)==="y",{width:_,height:w}=s.floating;let S,x;h==="top"||h==="bottom"?(S=h,x=y===(await(o.isRTL==null?void 0:o.isRTL(l.floating))?"start":"end")?"left":"right"):(x=h,S=y==="end"?"top":"bottom");const k=w-f.top-f.bottom,R=_-f.left-f.right,A=ec(w-f[S],k),O=ec(_-f[x],R),T=!t.middlewareData.shift;let M=A,z=O;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(z=R),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(M=k),T&&!y){const U=$s(f.left,0),G=$s(f.right,0),I=$s(f.top,0),N=$s(f.bottom,0);g?z=_-2*(U!==0||G!==0?U+G:$s(f.left,f.right)):M=w-2*(I!==0||N!==0?I+N:$s(f.top,f.bottom))}await u({...t,availableWidth:z,availableHeight:M});const Y=await o.getDimensions(l.floating);return _!==Y.width||w!==Y.height?{reset:{rects:!0}}:{}}}};function Ab(){return typeof window<"u"}function yf(e){return n3(e)?(e.nodeName||"").toLowerCase():"#document"}function Ws(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function pa(e){var t;return(t=(n3(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function n3(e){return Ab()?e instanceof Node||e instanceof Ws(e).Node:!1}function Oo(e){return Ab()?e instanceof Element||e instanceof Ws(e).Element:!1}function Za(e){return Ab()?e instanceof HTMLElement||e instanceof Ws(e).HTMLElement:!1}function Z2(e){return!Ab()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Ws(e).ShadowRoot}function ym(e){const{overflow:t,overflowX:n,overflowY:r,display:i}=Lo(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&i!=="inline"&&i!=="contents"}function Fae(e){return/^(table|td|th)$/.test(yf(e))}function Nb(e){try{if(e.matches(":popover-open"))return!0}catch{}try{return e.matches(":modal")}catch{return!1}}const $ae=/transform|translate|scale|rotate|perspective|filter/,Hae=/paint|layout|strict|content/,zc=e=>!!e&&e!=="none";let p0;function hk(e){const t=Oo(e)?Lo(e):e;return zc(t.transform)||zc(t.translate)||zc(t.scale)||zc(t.rotate)||zc(t.perspective)||!pk()&&(zc(t.backdropFilter)||zc(t.filter))||$ae.test(t.willChange||"")||Hae.test(t.contain||"")}function Uae(e){let t=tc(e);for(;Za(t)&&!rf(t);){if(hk(t))return t;if(Nb(t))return null;t=tc(t)}return null}function pk(){return p0==null&&(p0=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),p0}function rf(e){return/^(html|body|#document)$/.test(yf(e))}function Lo(e){return Ws(e).getComputedStyle(e)}function Mb(e){return Oo(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function tc(e){if(yf(e)==="html")return e;const t=e.assignedSlot||e.parentNode||Z2(e)&&e.host||pa(e);return Z2(t)?t.host:t}function r3(e){const t=tc(e);return rf(t)?e.ownerDocument?e.ownerDocument.body:e.body:Za(t)&&ym(t)?t:r3(t)}function Up(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const i=r3(e),s=i===((r=e.ownerDocument)==null?void 0:r.body),o=Ws(i);if(s){const l=g1(o);return t.concat(o,o.visualViewport||[],ym(i)?i:[],l&&n?Up(l):[])}else return t.concat(i,Up(i,[],n))}function g1(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function i3(e){const t=Lo(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const i=Za(e),s=i?e.offsetWidth:n,o=i?e.offsetHeight:r,l=zy(n)!==s||zy(r)!==o;return l&&(n=s,r=o),{width:n,height:r,$:l}}function mk(e){return Oo(e)?e:e.contextElement}function qd(e){const t=mk(e);if(!Za(t))return aa(1);const n=t.getBoundingClientRect(),{width:r,height:i,$:s}=i3(t);let o=(s?zy(n.width):n.width)/r,l=(s?zy(n.height):n.height)/i;return(!o||!Number.isFinite(o))&&(o=1),(!l||!Number.isFinite(l))&&(l=1),{x:o,y:l}}const Wae=aa(0);function s3(e){const t=Ws(e);return!pk()||!t.visualViewport?Wae:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function qae(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==Ws(e)?!1:t}function cu(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const i=e.getBoundingClientRect(),s=mk(e);let o=aa(1);t&&(r?Oo(r)&&(o=qd(r)):o=qd(e));const l=qae(s,n,r)?s3(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 y=Ws(s),g=r&&Oo(r)?Ws(r):r;let _=y,w=g1(_);for(;w&&r&&g!==_;){const S=qd(w),x=w.getBoundingClientRect(),k=Lo(w),R=x.left+(w.clientLeft+parseFloat(k.paddingLeft))*S.x,A=x.top+(w.clientTop+parseFloat(k.paddingTop))*S.y;u*=S.x,d*=S.y,f*=S.x,h*=S.y,u+=R,d+=A,_=Ws(w),w=g1(_)}}return Fy({width:f,height:h,x:u,y:d})}function Pb(e,t){const n=Mb(e).scrollLeft;return t?t.left+n:cu(pa(e)).left+n}function o3(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-Pb(e,n),i=n.top+t.scrollTop;return{x:r,y:i}}function Vae(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e;const s=i==="fixed",o=pa(r),l=t?Nb(t.floating):!1;if(r===o||l&&s)return n;let u={scrollLeft:0,scrollTop:0},d=aa(1);const f=aa(0),h=Za(r);if((h||!h&&!s)&&((yf(r)!=="body"||ym(o))&&(u=Mb(r)),h)){const g=cu(r);d=qd(r),f.x=g.x+r.clientLeft,f.y=g.y+r.clientTop}const y=o&&!h&&!s?o3(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+y.x,y:n.y*d.y-u.scrollTop*d.y+f.y+y.y}}function Yae(e){return Array.from(e.getClientRects())}function Kae(e){const t=pa(e),n=Mb(e),r=e.ownerDocument.body,i=$s(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=$s(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let o=-n.scrollLeft+Pb(e);const l=-n.scrollTop;return Lo(r).direction==="rtl"&&(o+=$s(t.clientWidth,r.clientWidth)-i),{width:i,height:s,x:o,y:l}}const J2=25;function Gae(e,t){const n=Ws(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=pk();(!f||f&&t==="fixed")&&(l=i.offsetLeft,u=i.offsetTop)}const d=Pb(r);if(d<=0){const f=r.ownerDocument,h=f.body,y=getComputedStyle(h),g=f.compatMode==="CSS1Compat"&&parseFloat(y.marginLeft)+parseFloat(y.marginRight)||0,_=Math.abs(r.clientWidth-h.clientWidth-g);_<=J2&&(s-=_)}else d<=J2&&(s+=d);return{width:s,height:o,x:l,y:u}}function Xae(e,t){const n=cu(e,!0,t==="fixed"),r=n.top+e.clientTop,i=n.left+e.clientLeft,s=Za(e)?qd(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 Q2(e,t,n){let r;if(t==="viewport")r=Gae(e,n);else if(t==="document")r=Kae(pa(e));else if(Oo(t))r=Xae(t,n);else{const i=s3(e);r={x:t.x-i.x,y:t.y-i.y,width:t.width,height:t.height}}return Fy(r)}function a3(e,t){const n=tc(e);return n===t||!Oo(n)||rf(n)?!1:Lo(n).position==="fixed"||a3(n,t)}function Zae(e,t){const n=t.get(e);if(n)return n;let r=Up(e,[],!1).filter(l=>Oo(l)&&yf(l)!=="body"),i=null;const s=Lo(e).position==="fixed";let o=s?tc(e):e;for(;Oo(o)&&!rf(o);){const l=Lo(o),u=hk(o);!u&&l.position==="fixed"&&(i=null),(s?!u&&!i:!u&&l.position==="static"&&!!i&&(i.position==="absolute"||i.position==="fixed")||ym(o)&&!u&&a3(e,o))?r=r.filter(f=>f!==o):i=l,o=tc(o)}return t.set(e,r),r}function Jae(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e;const o=[...n==="clippingAncestors"?Nb(t)?[]:Zae(t,this._c):[].concat(n),r],l=Q2(t,o[0],i);let u=l.top,d=l.right,f=l.bottom,h=l.left;for(let y=1;y<o.length;y++){const g=Q2(t,o[y],i);u=$s(g.top,u),d=ec(g.right,d),f=ec(g.bottom,f),h=$s(g.left,h)}return{width:d-h,height:f-u,x:h,y:u}}function Qae(e){const{width:t,height:n}=i3(e);return{width:t,height:n}}function ele(e,t,n){const r=Za(t),i=pa(t),s=n==="fixed",o=cu(e,!0,s,t);let l={scrollLeft:0,scrollTop:0};const u=aa(0);function d(){u.x=Pb(i)}if(r||!r&&!s)if((yf(t)!=="body"||ym(i))&&(l=Mb(t)),r){const g=cu(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?o3(i,l):aa(0),h=o.left+l.scrollLeft-u.x-f.x,y=o.top+l.scrollTop-u.y-f.y;return{x:h,y,width:o.width,height:o.height}}function m0(e){return Lo(e).position==="static"}function eI(e,t){if(!Za(e)||Lo(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return pa(e)===n&&(n=n.ownerDocument.body),n}function l3(e,t){const n=Ws(e);if(Nb(e))return n;if(!Za(e)){let i=tc(e);for(;i&&!rf(i);){if(Oo(i)&&!m0(i))return i;i=tc(i)}return n}let r=eI(e,t);for(;r&&Fae(r)&&m0(r);)r=eI(r,t);return r&&rf(r)&&m0(r)&&!hk(r)?n:r||Uae(e)||n}const tle=async function(e){const t=this.getOffsetParent||l3,n=this.getDimensions,r=await n(e.floating);return{reference:ele(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function nle(e){return Lo(e).direction==="rtl"}const rle={convertOffsetParentRelativeRectToViewportRelativeRect:Vae,getDocumentElement:pa,getClippingRect:Jae,getOffsetParent:l3,getElementRects:tle,getClientRects:Yae,getDimensions:Qae,getScale:qd,isElement:Oo,isRTL:nle};function c3(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function ile(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:y,height:g}=d;if(l||t(),!y||!g)return;const _=vv(h),w=vv(i.clientWidth-(f+y)),S=vv(i.clientHeight-(h+g)),x=vv(f),R={rootMargin:-_+"px "+-w+"px "+-S+"px "+-x+"px",threshold:$s(0,ec(1,u))||1};let A=!0;function O(T){const M=T[0].intersectionRatio;if(M!==u){if(!A)return o();M?o(!1,M):r=setTimeout(()=>{o(!1,1e-7)},1e3)}M===1&&!c3(d,e.getBoundingClientRect())&&o(),A=!1}try{n=new IntersectionObserver(O,{...R,root:i.ownerDocument})}catch{n=new IntersectionObserver(O,R)}n.observe(e)}return o(!0),s}function sle(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=mk(e),f=i||s?[...d?Up(d):[],...t?Up(t):[]]:[];f.forEach(x=>{i&&x.addEventListener("scroll",n,{passive:!0}),s&&x.addEventListener("resize",n)});const h=d&&l?ile(d,n):null;let y=-1,g=null;o&&(g=new ResizeObserver(x=>{let[k]=x;k&&k.target===d&&g&&t&&(g.unobserve(t),cancelAnimationFrame(y),y=requestAnimationFrame(()=>{var R;(R=g)==null||R.observe(t)})),n()}),d&&!u&&g.observe(d),t&&g.observe(t));let _,w=u?cu(e):null;u&&S();function S(){const x=cu(e);w&&!c3(w,x)&&n(),w=x,_=requestAnimationFrame(S)}return n(),()=>{var x;f.forEach(k=>{i&&k.removeEventListener("scroll",n),s&&k.removeEventListener("resize",n)}),h==null||h(),(x=g)==null||x.disconnect(),g=null,u&&cancelAnimationFrame(_)}}const ole=Dae,ale=Bae,lle=Iae,cle=jae,ule=Oae,tI=Pae,dle=zae,fle=(e,t,n)=>{const r=new Map,i={platform:rle,...n},s={...i.platform,_c:r};return Mae(e,t,{...i,platform:s})};var hle=typeof document<"u",ple=function(){},ay=hle?b.useLayoutEffect:ple;function $y(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(!$y(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)&&!$y(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function u3(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function nI(e,t){const n=u3(e);return Math.round(t*n)/n}function g0(e){const t=b.useRef(e);return ay(()=>{t.current=e}),t}function mle(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}),[y,g]=b.useState(r);$y(y,r)||g(r);const[_,w]=b.useState(null),[S,x]=b.useState(null),k=b.useCallback(F=>{F!==T.current&&(T.current=F,w(F))},[]),R=b.useCallback(F=>{F!==M.current&&(M.current=F,x(F))},[]),A=s||_,O=o||S,T=b.useRef(null),M=b.useRef(null),z=b.useRef(f),Y=u!=null,U=g0(u),G=g0(i),I=g0(d),N=b.useCallback(()=>{if(!T.current||!M.current)return;const F={placement:t,strategy:n,middleware:y};G.current&&(F.platform=G.current),fle(T.current,M.current,F).then(q=>{const j={...q,isPositioned:I.current!==!1};L.current&&!$y(z.current,j)&&(z.current=j,xu.flushSync(()=>{h(j)}))})},[y,t,n,G,I]);ay(()=>{d===!1&&z.current.isPositioned&&(z.current.isPositioned=!1,h(F=>({...F,isPositioned:!1})))},[d]);const L=b.useRef(!1);ay(()=>(L.current=!0,()=>{L.current=!1}),[]),ay(()=>{if(A&&(T.current=A),O&&(M.current=O),A&&O){if(U.current)return U.current(A,O,N);N()}},[A,O,N,U,Y]);const B=b.useMemo(()=>({reference:T,floating:M,setReference:k,setFloating:R}),[k,R]),P=b.useMemo(()=>({reference:A,floating:O}),[A,O]),D=b.useMemo(()=>{const F={position:n,left:0,top:0};if(!P.floating)return F;const q=nI(P.floating,f.x),j=nI(P.floating,f.y);return l?{...F,transform:"translate("+q+"px, "+j+"px)",...u3(P.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:q,top:j}},[n,l,P.floating,f.x,f.y]);return b.useMemo(()=>({...f,update:N,refs:B,elements:P,floatingStyles:D}),[f,N,B,P,D])}const gle=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?tI({element:r.current,padding:i}).fn(n):{}:r?tI({element:r,padding:i}).fn(n):{}}}},vle=(e,t)=>{const n=ole(e);return{name:n.name,fn:n.fn,options:[e,t]}},yle=(e,t)=>{const n=ale(e);return{name:n.name,fn:n.fn,options:[e,t]}},ble=(e,t)=>({fn:dle(e).fn,options:[e,t]}),_le=(e,t)=>{const n=lle(e);return{name:n.name,fn:n.fn,options:[e,t]}},wle=(e,t)=>{const n=cle(e);return{name:n.name,fn:n.fn,options:[e,t]}},xle=(e,t)=>{const n=ule(e);return{name:n.name,fn:n.fn,options:[e,t]}},Sle=(e,t)=>{const n=gle(e);return{name:n.name,fn:n.fn,options:[e,t]}};var Ele="Arrow",d3=b.forwardRef((e,t)=>{const{children:n,width:r=10,height:i=5,...s}=e;return m.jsx(yn.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"})})});d3.displayName=Ele;var Cle=d3,gk="Popper",[f3,cc]=Xa(gk),[kle,h3]=f3(gk),p3=e=>{const{__scopePopper:t,children:n}=e,[r,i]=b.useState(null);return m.jsx(kle,{scope:t,anchor:r,onAnchorChange:i,children:n})};p3.displayName=gk;var m3="PopperAnchor",g3=b.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...i}=e,s=h3(m3,n),o=b.useRef(null),l=cr(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(yn.div,{...i,ref:l})});g3.displayName=m3;var vk="PopperContent",[Tle,Rle]=f3(vk),v3=b.forwardRef((e,t)=>{var X,ae,ne,ce,_e,xe;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:y=!1,updatePositionStrategy:g="optimized",onPlaced:_,...w}=e,S=h3(vk,n),[x,k]=b.useState(null),R=cr(t,We=>k(We)),[A,O]=b.useState(null),T=bae(A),M=(T==null?void 0:T.width)??0,z=(T==null?void 0:T.height)??0,Y=r+(s!=="center"?"-"+s:""),U=typeof f=="number"?f:{top:0,right:0,bottom:0,left:0,...f},G=Array.isArray(d)?d:[d],I=G.length>0,N={padding:U,boundary:G.filter(Nle),altBoundary:I},{refs:L,floatingStyles:B,placement:P,isPositioned:D,middlewareData:F}=mle({strategy:"fixed",placement:Y,whileElementsMounted:(...We)=>sle(...We,{animationFrame:g==="always"}),elements:{reference:S.anchor},middleware:[vle({mainAxis:i+z,alignmentAxis:o}),u&&yle({mainAxis:!0,crossAxis:!1,limiter:h==="partial"?ble():void 0,...N}),u&&_le({...N}),wle({...N,apply:({elements:We,rects:De,availableWidth:Pt,availableHeight:tt})=>{const{width:lt,height:$e}=De.reference,Fe=We.floating.style;Fe.setProperty("--radix-popper-available-width",`${Pt}px`),Fe.setProperty("--radix-popper-available-height",`${tt}px`),Fe.setProperty("--radix-popper-anchor-width",`${lt}px`),Fe.setProperty("--radix-popper-anchor-height",`${$e}px`)}}),A&&Sle({element:A,padding:l}),Mle({arrowWidth:M,arrowHeight:z}),y&&xle({strategy:"referenceHidden",...N})]}),[q,j]=_3(P),V=Io(_);Ji(()=>{D&&(V==null||V())},[D,V]);const K=(X=F.arrow)==null?void 0:X.x,$=(ae=F.arrow)==null?void 0:ae.y,te=((ne=F.arrow)==null?void 0:ne.centerOffset)!==0,[re,ee]=b.useState();return Ji(()=>{x&&ee(window.getComputedStyle(x).zIndex)},[x]),m.jsx("div",{ref:L.setFloating,"data-radix-popper-content-wrapper":"",style:{...B,transform:D?B.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:re,"--radix-popper-transform-origin":[(ce=F.transformOrigin)==null?void 0:ce.x,(_e=F.transformOrigin)==null?void 0:_e.y].join(" "),...((xe=F.hide)==null?void 0:xe.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:m.jsx(Tle,{scope:n,placedSide:q,onArrowChange:O,arrowX:K,arrowY:$,shouldHideArrow:te,children:m.jsx(yn.div,{"data-side":q,"data-align":j,...w,ref:R,style:{...w.style,animation:D?void 0:"none"}})})})});v3.displayName=vk;var y3="PopperArrow",Ale={top:"bottom",right:"left",bottom:"top",left:"right"},b3=b.forwardRef(function(t,n){const{__scopePopper:r,...i}=t,s=Rle(y3,r),o=Ale[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(Cle,{...i,ref:n,style:{...i.style,display:"block"}})})});b3.displayName=y3;function Nle(e){return e!==null}var Mle=e=>({name:"transformOrigin",options:e,fn(t){var S,x,k;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]=_3(n),h={start:"0%",center:"50%",end:"100%"}[f],y=(((x=i.arrow)==null?void 0:x.x)??0)+l/2,g=(((k=i.arrow)==null?void 0:k.y)??0)+u/2;let _="",w="";return d==="bottom"?(_=o?h:`${y}px`,w=`${-u}px`):d==="top"?(_=o?h:`${y}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 _3(e){const[t,n="center"]=e.split("-");return[t,n]}var bm=p3,_m=g3,Ib=v3,Ob=b3,v0="rovingFocusGroup.onEntryFocus",Ple={bubbles:!1,cancelable:!0},wm="RovingFocusGroup",[v1,w3,Ile]=tk(wm),[Ole,x3]=Xa(wm,[Ile]),[Lle,Dle]=Ole(wm),S3=b.forwardRef((e,t)=>m.jsx(v1.Provider,{scope:e.__scopeRovingFocusGroup,children:m.jsx(v1.Slot,{scope:e.__scopeRovingFocusGroup,children:m.jsx(Ble,{...e,ref:t})})}));S3.displayName=wm;var Ble=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,y=b.useRef(null),g=cr(t,y),_=nk(s),[w,S]=Ql({prop:o,defaultProp:l??null,onChange:u,caller:wm}),[x,k]=b.useState(!1),R=Io(d),A=w3(n),O=b.useRef(!1),[T,M]=b.useState(0);return b.useEffect(()=>{const z=y.current;if(z)return z.addEventListener(v0,R),()=>z.removeEventListener(v0,R)},[R]),m.jsx(Lle,{scope:n,orientation:r,dir:_,loop:i,currentTabStopId:w,onItemFocus:b.useCallback(z=>S(z),[S]),onItemShiftTab:b.useCallback(()=>k(!0),[]),onFocusableItemAdd:b.useCallback(()=>M(z=>z+1),[]),onFocusableItemRemove:b.useCallback(()=>M(z=>z-1),[]),children:m.jsx(yn.div,{tabIndex:x||T===0?-1:0,"data-orientation":r,...h,ref:g,style:{outline:"none",...e.style},onMouseDown:Wt(e.onMouseDown,()=>{O.current=!0}),onFocus:Wt(e.onFocus,z=>{const Y=!O.current;if(z.target===z.currentTarget&&Y&&!x){const U=new CustomEvent(v0,Ple);if(z.currentTarget.dispatchEvent(U),!U.defaultPrevented){const G=A().filter(P=>P.focusable),I=G.find(P=>P.active),N=G.find(P=>P.id===w),B=[I,N,...G].filter(Boolean).map(P=>P.ref.current);k3(B,f)}}O.current=!1}),onBlur:Wt(e.onBlur,()=>k(!1))})})}),E3="RovingFocusGroupItem",C3=b.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:i=!1,tabStopId:s,children:o,...l}=e,u=bi(),d=s||u,f=Dle(E3,n),h=f.currentTabStopId===d,y=w3(n),{onFocusableItemAdd:g,onFocusableItemRemove:_,currentTabStopId:w}=f;return b.useEffect(()=>{if(r)return g(),()=>_()},[r,g,_]),m.jsx(v1.ItemSlot,{scope:n,id:d,focusable:r,active:i,children:m.jsx(yn.span,{tabIndex:h?0:-1,"data-orientation":f.orientation,...l,ref:t,onMouseDown:Wt(e.onMouseDown,S=>{r?f.onItemFocus(d):S.preventDefault()}),onFocus:Wt(e.onFocus,()=>f.onItemFocus(d)),onKeyDown:Wt(e.onKeyDown,S=>{if(S.key==="Tab"&&S.shiftKey){f.onItemShiftTab();return}if(S.target!==S.currentTarget)return;const x=Fle(S,f.orientation,f.dir);if(x!==void 0){if(S.metaKey||S.ctrlKey||S.altKey||S.shiftKey)return;S.preventDefault();let R=y().filter(A=>A.focusable).map(A=>A.ref.current);if(x==="last")R.reverse();else if(x==="prev"||x==="next"){x==="prev"&&R.reverse();const A=R.indexOf(S.currentTarget);R=f.loop?$le(R,A+1):R.slice(A+1)}setTimeout(()=>k3(R))}}),children:typeof o=="function"?o({isCurrentTabStop:h,hasTabStop:w!=null}):o})})});C3.displayName=E3;var zle={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function jle(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function Fle(e,t,n){const r=jle(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return zle[r]}function k3(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function $le(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Hle=S3,Ule=C3,y1=["Enter"," "],Wle=["ArrowDown","PageUp","Home"],T3=["ArrowUp","PageDown","End"],qle=[...Wle,...T3],Vle={ltr:[...y1,"ArrowRight"],rtl:[...y1,"ArrowLeft"]},Yle={ltr:["ArrowLeft"],rtl:["ArrowRight"]},xm="Menu",[Wp,Kle,Gle]=tk(xm),[Su,R3]=Xa(xm,[Gle,cc,x3]),Sm=cc(),A3=x3(),[N3,uc]=Su(xm),[Xle,Em]=Su(xm),M3=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:i,onOpenChange:s,modal:o=!0}=e,l=Sm(t),[u,d]=b.useState(null),f=b.useRef(!1),h=Io(s),y=nk(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(bm,{...l,children:m.jsx(N3,{scope:t,open:n,onOpenChange:h,content:u,onContentChange:d,children:m.jsx(Xle,{scope:t,onClose:b.useCallback(()=>h(!1),[h]),isUsingKeyboardRef:f,dir:y,modal:o,children:r})})})};M3.displayName=xm;var Zle="MenuAnchor",yk=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=Sm(n);return m.jsx(_m,{...i,...r,ref:t})});yk.displayName=Zle;var bk="MenuPortal",[Jle,P3]=Su(bk,{forceMount:void 0}),I3=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:i}=e,s=uc(bk,t);return m.jsx(Jle,{scope:t,forceMount:n,children:m.jsx(wo,{present:n||s.open,children:m.jsx(gf,{asChild:!0,container:i,children:r})})})};I3.displayName=bk;var mo="MenuContent",[Qle,_k]=Su(mo),O3=b.forwardRef((e,t)=>{const n=P3(mo,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=uc(mo,e.__scopeMenu),o=Em(mo,e.__scopeMenu);return m.jsx(Wp.Provider,{scope:e.__scopeMenu,children:m.jsx(wo,{present:r||s.open,children:m.jsx(Wp.Slot,{scope:e.__scopeMenu,children:o.modal?m.jsx(ece,{...i,ref:t}):m.jsx(tce,{...i,ref:t})})})})}),ece=b.forwardRef((e,t)=>{const n=uc(mo,e.__scopeMenu),r=b.useRef(null),i=cr(t,r);return b.useEffect(()=>{const s=r.current;if(s)return kb(s)},[]),m.jsx(wk,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:Wt(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),tce=b.forwardRef((e,t)=>{const n=uc(mo,e.__scopeMenu);return m.jsx(wk,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),nce=Jl("MenuContent.ScrollLock"),wk=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:y,onDismiss:g,disableOutsideScroll:_,...w}=e,S=uc(mo,n),x=Em(mo,n),k=Sm(n),R=A3(n),A=Kle(n),[O,T]=b.useState(null),M=b.useRef(null),z=cr(t,M,S.onContentChange),Y=b.useRef(0),U=b.useRef(""),G=b.useRef(0),I=b.useRef(null),N=b.useRef("right"),L=b.useRef(0),B=_?vm:b.Fragment,P=_?{as:nce,allowPinchZoom:!0}:void 0,D=q=>{var X,ae;const j=U.current+q,V=A().filter(ne=>!ne.disabled),K=document.activeElement,$=(X=V.find(ne=>ne.ref.current===K))==null?void 0:X.textValue,te=V.map(ne=>ne.textValue),re=pce(te,j,$),ee=(ae=V.find(ne=>ne.textValue===re))==null?void 0:ae.ref.current;(function ne(ce){U.current=ce,window.clearTimeout(Y.current),ce!==""&&(Y.current=window.setTimeout(()=>ne(""),1e3))})(j),ee&&setTimeout(()=>ee.focus())};b.useEffect(()=>()=>window.clearTimeout(Y.current),[]),Eb();const F=b.useCallback(q=>{var V,K;return N.current===((V=I.current)==null?void 0:V.side)&&gce(q,(K=I.current)==null?void 0:K.area)},[]);return m.jsx(Qle,{scope:n,searchRef:U,onItemEnter:b.useCallback(q=>{F(q)&&q.preventDefault()},[F]),onItemLeave:b.useCallback(q=>{var j;F(q)||((j=M.current)==null||j.focus(),T(null))},[F]),onTriggerLeave:b.useCallback(q=>{F(q)&&q.preventDefault()},[F]),pointerGraceTimerRef:G,onPointerGraceIntentChange:b.useCallback(q=>{I.current=q},[]),children:m.jsx(B,{...P,children:m.jsx(gm,{asChild:!0,trapped:i,onMountAutoFocus:Wt(s,q=>{var j;q.preventDefault(),(j=M.current)==null||j.focus({preventScroll:!0})}),onUnmountAutoFocus:o,children:m.jsx(mf,{asChild:!0,disableOutsidePointerEvents:l,onEscapeKeyDown:d,onPointerDownOutside:f,onFocusOutside:h,onInteractOutside:y,onDismiss:g,children:m.jsx(Hle,{asChild:!0,...R,dir:x.dir,orientation:"vertical",loop:r,currentTabStopId:O,onCurrentTabStopIdChange:T,onEntryFocus:Wt(u,q=>{x.isUsingKeyboardRef.current||q.preventDefault()}),preventScrollOnEntryFocus:!0,children:m.jsx(Ib,{role:"menu","aria-orientation":"vertical","data-state":Z3(S.open),"data-radix-menu-content":"",dir:x.dir,...k,...w,ref:z,style:{outline:"none",...w.style},onKeyDown:Wt(w.onKeyDown,q=>{const V=q.target.closest("[data-radix-menu-content]")===q.currentTarget,K=q.ctrlKey||q.altKey||q.metaKey,$=q.key.length===1;V&&(q.key==="Tab"&&q.preventDefault(),!K&&$&&D(q.key));const te=M.current;if(q.target!==te||!qle.includes(q.key))return;q.preventDefault();const ee=A().filter(X=>!X.disabled).map(X=>X.ref.current);T3.includes(q.key)&&ee.reverse(),fce(ee)}),onBlur:Wt(e.onBlur,q=>{q.currentTarget.contains(q.target)||(window.clearTimeout(Y.current),U.current="")}),onPointerMove:Wt(e.onPointerMove,qp(q=>{const j=q.target,V=L.current!==q.clientX;if(q.currentTarget.contains(j)&&V){const K=q.clientX>L.current?"right":"left";N.current=K,L.current=q.clientX}}))})})})})})})});O3.displayName=mo;var rce="MenuGroup",xk=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return m.jsx(yn.div,{role:"group",...r,ref:t})});xk.displayName=rce;var ice="MenuLabel",L3=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return m.jsx(yn.div,{...r,ref:t})});L3.displayName=ice;var Hy="MenuItem",rI="menu.itemSelect",Lb=b.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...i}=e,s=b.useRef(null),o=Em(Hy,e.__scopeMenu),l=_k(Hy,e.__scopeMenu),u=cr(t,s),d=b.useRef(!1),f=()=>{const h=s.current;if(!n&&h){const y=new CustomEvent(rI,{bubbles:!0,cancelable:!0});h.addEventListener(rI,g=>r==null?void 0:r(g),{once:!0}),w5(h,y),y.defaultPrevented?d.current=!1:o.onClose()}};return m.jsx(D3,{...i,ref:u,disabled:n,onClick:Wt(e.onClick,f),onPointerDown:h=>{var y;(y=e.onPointerDown)==null||y.call(e,h),d.current=!0},onPointerUp:Wt(e.onPointerUp,h=>{var y;d.current||(y=h.currentTarget)==null||y.click()}),onKeyDown:Wt(e.onKeyDown,h=>{const y=l.searchRef.current!=="";n||y&&h.key===" "||y1.includes(h.key)&&(h.currentTarget.click(),h.preventDefault())})})});Lb.displayName=Hy;var D3=b.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:i,...s}=e,o=_k(Hy,n),l=A3(n),u=b.useRef(null),d=cr(t,u),[f,h]=b.useState(!1),[y,g]=b.useState("");return b.useEffect(()=>{const _=u.current;_&&g((_.textContent??"").trim())},[s.children]),m.jsx(Wp.ItemSlot,{scope:n,disabled:r,textValue:i??y,children:m.jsx(Ule,{asChild:!0,...l,focusable:!r,children:m.jsx(yn.div,{role:"menuitem","data-highlighted":f?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:d,onPointerMove:Wt(e.onPointerMove,qp(_=>{r?o.onItemLeave(_):(o.onItemEnter(_),_.defaultPrevented||_.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:Wt(e.onPointerLeave,qp(_=>o.onItemLeave(_))),onFocus:Wt(e.onFocus,()=>h(!0)),onBlur:Wt(e.onBlur,()=>h(!1))})})})}),sce="MenuCheckboxItem",B3=b.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...i}=e;return m.jsx(H3,{scope:e.__scopeMenu,checked:n,children:m.jsx(Lb,{role:"menuitemcheckbox","aria-checked":Uy(n)?"mixed":n,...i,ref:t,"data-state":Ck(n),onSelect:Wt(i.onSelect,()=>r==null?void 0:r(Uy(n)?!0:!n),{checkForDefaultPrevented:!1})})})});B3.displayName=sce;var z3="MenuRadioGroup",[oce,ace]=Su(z3,{value:void 0,onValueChange:()=>{}}),j3=b.forwardRef((e,t)=>{const{value:n,onValueChange:r,...i}=e,s=Io(r);return m.jsx(oce,{scope:e.__scopeMenu,value:n,onValueChange:s,children:m.jsx(xk,{...i,ref:t})})});j3.displayName=z3;var F3="MenuRadioItem",$3=b.forwardRef((e,t)=>{const{value:n,...r}=e,i=ace(F3,e.__scopeMenu),s=n===i.value;return m.jsx(H3,{scope:e.__scopeMenu,checked:s,children:m.jsx(Lb,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":Ck(s),onSelect:Wt(r.onSelect,()=>{var o;return(o=i.onValueChange)==null?void 0:o.call(i,n)},{checkForDefaultPrevented:!1})})})});$3.displayName=F3;var Sk="MenuItemIndicator",[H3,lce]=Su(Sk,{checked:!1}),U3=b.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...i}=e,s=lce(Sk,n);return m.jsx(wo,{present:r||Uy(s.checked)||s.checked===!0,children:m.jsx(yn.span,{...i,ref:t,"data-state":Ck(s.checked)})})});U3.displayName=Sk;var cce="MenuSeparator",W3=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return m.jsx(yn.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});W3.displayName=cce;var uce="MenuArrow",q3=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=Sm(n);return m.jsx(Ob,{...i,...r,ref:t})});q3.displayName=uce;var Ek="MenuSub",[dce,V3]=Su(Ek),Y3=e=>{const{__scopeMenu:t,children:n,open:r=!1,onOpenChange:i}=e,s=uc(Ek,t),o=Sm(t),[l,u]=b.useState(null),[d,f]=b.useState(null),h=Io(i);return b.useEffect(()=>(s.open===!1&&h(!1),()=>h(!1)),[s.open,h]),m.jsx(bm,{...o,children:m.jsx(N3,{scope:t,open:r,onOpenChange:h,content:d,onContentChange:f,children:m.jsx(dce,{scope:t,contentId:bi(),triggerId:bi(),trigger:l,onTriggerChange:u,children:n})})})};Y3.displayName=Ek;var op="MenuSubTrigger",K3=b.forwardRef((e,t)=>{const n=uc(op,e.__scopeMenu),r=Em(op,e.__scopeMenu),i=V3(op,e.__scopeMenu),s=_k(op,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(yk,{asChild:!0,...d,children:m.jsx(D3,{id:i.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":i.contentId,"data-state":Z3(n.open),...e,ref:qa(t,i.onTriggerChange),onClick:h=>{var y;(y=e.onClick)==null||y.call(e,h),!(e.disabled||h.defaultPrevented)&&(h.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:Wt(e.onPointerMove,qp(h=>{s.onItemEnter(h),!h.defaultPrevented&&!e.disabled&&!n.open&&!o.current&&(s.onPointerGraceIntentChange(null),o.current=window.setTimeout(()=>{n.onOpenChange(!0),f()},100))})),onPointerLeave:Wt(e.onPointerLeave,qp(h=>{var g,_;f();const y=(g=n.content)==null?void 0:g.getBoundingClientRect();if(y){const w=(_=n.content)==null?void 0:_.dataset.side,S=w==="right",x=S?-5:5,k=y[S?"left":"right"],R=y[S?"right":"left"];s.onPointerGraceIntentChange({area:[{x:h.clientX+x,y:h.clientY},{x:k,y:y.top},{x:R,y:y.top},{x:R,y:y.bottom},{x:k,y:y.bottom}],side:w}),window.clearTimeout(l.current),l.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(h),h.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:Wt(e.onKeyDown,h=>{var g;const y=s.searchRef.current!=="";e.disabled||y&&h.key===" "||Vle[r.dir].includes(h.key)&&(n.onOpenChange(!0),(g=n.content)==null||g.focus(),h.preventDefault())})})})});K3.displayName=op;var G3="MenuSubContent",X3=b.forwardRef((e,t)=>{const n=P3(mo,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=uc(mo,e.__scopeMenu),o=Em(mo,e.__scopeMenu),l=V3(G3,e.__scopeMenu),u=b.useRef(null),d=cr(t,u);return m.jsx(Wp.Provider,{scope:e.__scopeMenu,children:m.jsx(wo,{present:r||s.open,children:m.jsx(Wp.Slot,{scope:e.__scopeMenu,children:m.jsx(wk,{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:Wt(e.onFocusOutside,f=>{f.target!==l.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:Wt(e.onEscapeKeyDown,f=>{o.onClose(),f.preventDefault()}),onKeyDown:Wt(e.onKeyDown,f=>{var g;const h=f.currentTarget.contains(f.target),y=Yle[o.dir].includes(f.key);h&&y&&(s.onOpenChange(!1),(g=l.trigger)==null||g.focus(),f.preventDefault())})})})})})});X3.displayName=G3;function Z3(e){return e?"open":"closed"}function Uy(e){return e==="indeterminate"}function Ck(e){return Uy(e)?"indeterminate":e?"checked":"unchecked"}function fce(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function hce(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function pce(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=hce(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 mce(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,y=u.y;f>r!=y>r&&n<(h-d)*(r-f)/(y-f)+d&&(i=!i)}return i}function gce(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return mce(n,t)}function qp(e){return t=>t.pointerType==="mouse"?e(t):void 0}var vce=M3,yce=yk,bce=I3,_ce=O3,wce=xk,xce=L3,Sce=Lb,Ece=B3,Cce=j3,kce=$3,Tce=U3,Rce=W3,Ace=q3,Nce=Y3,Mce=K3,Pce=X3,Db="DropdownMenu",[Ice]=Xa(Db,[R3]),Qi=R3(),[Oce,J3]=Ice(Db),Q3=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:i,defaultOpen:s,onOpenChange:o,modal:l=!0}=e,u=Qi(t),d=b.useRef(null),[f,h]=Ql({prop:i,defaultProp:s??!1,onChange:o,caller:Db});return m.jsx(Oce,{scope:t,triggerId:bi(),triggerRef:d,contentId:bi(),open:f,onOpenChange:h,onOpenToggle:b.useCallback(()=>h(y=>!y),[h]),modal:l,children:m.jsx(vce,{...u,open:f,onOpenChange:h,dir:r,modal:l,children:n})})};Q3.displayName=Db;var e4="DropdownMenuTrigger",t4=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...i}=e,s=J3(e4,n),o=Qi(n);return m.jsx(yce,{asChild:!0,...o,children:m.jsx(yn.button,{type:"button",id:s.triggerId,"aria-haspopup":"menu","aria-expanded":s.open,"aria-controls":s.open?s.contentId:void 0,"data-state":s.open?"open":"closed","data-disabled":r?"":void 0,disabled:r,...i,ref:qa(t,s.triggerRef),onPointerDown:Wt(e.onPointerDown,l=>{!r&&l.button===0&&l.ctrlKey===!1&&(s.onOpenToggle(),s.open||l.preventDefault())}),onKeyDown:Wt(e.onKeyDown,l=>{r||(["Enter"," "].includes(l.key)&&s.onOpenToggle(),l.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(l.key)&&l.preventDefault())})})})});t4.displayName=e4;var Lce="DropdownMenuPortal",n4=e=>{const{__scopeDropdownMenu:t,...n}=e,r=Qi(t);return m.jsx(bce,{...r,...n})};n4.displayName=Lce;var r4="DropdownMenuContent",i4=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=J3(r4,n),s=Qi(n),o=b.useRef(!1);return m.jsx(_ce,{id:i.contentId,"aria-labelledby":i.triggerId,...s,...r,ref:t,onCloseAutoFocus:Wt(e.onCloseAutoFocus,l=>{var u;o.current||(u=i.triggerRef.current)==null||u.focus(),o.current=!1,l.preventDefault()}),onInteractOutside:Wt(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)"}})});i4.displayName=r4;var Dce="DropdownMenuGroup",Bce=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Qi(n);return m.jsx(wce,{...i,...r,ref:t})});Bce.displayName=Dce;var zce="DropdownMenuLabel",s4=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Qi(n);return m.jsx(xce,{...i,...r,ref:t})});s4.displayName=zce;var jce="DropdownMenuItem",o4=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Qi(n);return m.jsx(Sce,{...i,...r,ref:t})});o4.displayName=jce;var Fce="DropdownMenuCheckboxItem",a4=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Qi(n);return m.jsx(Ece,{...i,...r,ref:t})});a4.displayName=Fce;var $ce="DropdownMenuRadioGroup",Hce=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Qi(n);return m.jsx(Cce,{...i,...r,ref:t})});Hce.displayName=$ce;var Uce="DropdownMenuRadioItem",Wce=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Qi(n);return m.jsx(kce,{...i,...r,ref:t})});Wce.displayName=Uce;var qce="DropdownMenuItemIndicator",l4=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Qi(n);return m.jsx(Tce,{...i,...r,ref:t})});l4.displayName=qce;var Vce="DropdownMenuSeparator",c4=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Qi(n);return m.jsx(Rce,{...i,...r,ref:t})});c4.displayName=Vce;var Yce="DropdownMenuArrow",Kce=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Qi(n);return m.jsx(Ace,{...i,...r,ref:t})});Kce.displayName=Yce;var Gce=e=>{const{__scopeDropdownMenu:t,children:n,open:r,onOpenChange:i,defaultOpen:s}=e,o=Qi(t),[l,u]=Ql({prop:r,defaultProp:s??!1,onChange:i,caller:"DropdownMenuSub"});return m.jsx(Nce,{...o,open:l,onOpenChange:u,children:n})},Xce="DropdownMenuSubTrigger",u4=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Qi(n);return m.jsx(Mce,{...i,...r,ref:t})});u4.displayName=Xce;var Zce="DropdownMenuSubContent",d4=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Qi(n);return m.jsx(Pce,{...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)"}})});d4.displayName=Zce;var Jce=Q3,Qce=t4,f4=n4,eue=i4,tue=s4,nue=o4,rue=a4,iue=l4,sue=c4,oue=Gce,aue=u4,lue=d4;function iI(e,[t,n]){return Math.min(n,Math.max(t,e))}var Bb="Popover",[h4]=Xa(Bb,[cc]),Cm=cc(),[cue,dc]=h4(Bb),p4=e=>{const{__scopePopover:t,children:n,open:r,defaultOpen:i,onOpenChange:s,modal:o=!1}=e,l=Cm(t),u=b.useRef(null),[d,f]=b.useState(!1),[h,y]=Ql({prop:r,defaultProp:i??!1,onChange:s,caller:Bb});return m.jsx(bm,{...l,children:m.jsx(cue,{scope:t,contentId:bi(),triggerRef:u,open:h,onOpenChange:y,onOpenToggle:b.useCallback(()=>y(g=>!g),[y]),hasCustomAnchor:d,onCustomAnchorAdd:b.useCallback(()=>f(!0),[]),onCustomAnchorRemove:b.useCallback(()=>f(!1),[]),modal:o,children:n})})};p4.displayName=Bb;var m4="PopoverAnchor",uue=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=dc(m4,n),s=Cm(n),{onCustomAnchorAdd:o,onCustomAnchorRemove:l}=i;return b.useEffect(()=>(o(),()=>l()),[o,l]),m.jsx(_m,{...s,...r,ref:t})});uue.displayName=m4;var g4="PopoverTrigger",v4=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=dc(g4,n),s=Cm(n),o=cr(t,i.triggerRef),l=m.jsx(yn.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.contentId,"data-state":x4(i.open),...r,ref:o,onClick:Wt(e.onClick,i.onOpenToggle)});return i.hasCustomAnchor?l:m.jsx(_m,{asChild:!0,...s,children:l})});v4.displayName=g4;var kk="PopoverPortal",[due,fue]=h4(kk,{forceMount:void 0}),y4=e=>{const{__scopePopover:t,forceMount:n,children:r,container:i}=e,s=dc(kk,t);return m.jsx(due,{scope:t,forceMount:n,children:m.jsx(wo,{present:n||s.open,children:m.jsx(gf,{asChild:!0,container:i,children:r})})})};y4.displayName=kk;var sf="PopoverContent",b4=b.forwardRef((e,t)=>{const n=fue(sf,e.__scopePopover),{forceMount:r=n.forceMount,...i}=e,s=dc(sf,e.__scopePopover);return m.jsx(wo,{present:r||s.open,children:s.modal?m.jsx(pue,{...i,ref:t}):m.jsx(mue,{...i,ref:t})})});b4.displayName=sf;var hue=Jl("PopoverContent.RemoveScroll"),pue=b.forwardRef((e,t)=>{const n=dc(sf,e.__scopePopover),r=b.useRef(null),i=cr(t,r),s=b.useRef(!1);return b.useEffect(()=>{const o=r.current;if(o)return kb(o)},[]),m.jsx(vm,{as:hue,allowPinchZoom:!0,children:m.jsx(_4,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Wt(e.onCloseAutoFocus,o=>{var l;o.preventDefault(),s.current||(l=n.triggerRef.current)==null||l.focus()}),onPointerDownOutside:Wt(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:Wt(e.onFocusOutside,o=>o.preventDefault(),{checkForDefaultPrevented:!1})})})}),mue=b.forwardRef((e,t)=>{const n=dc(sf,e.__scopePopover),r=b.useRef(!1),i=b.useRef(!1);return m.jsx(_4,{...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()}})}),_4=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,y=dc(sf,n),g=Cm(n);return Eb(),m.jsx(gm,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:s,children:m.jsx(mf,{asChild:!0,disableOutsidePointerEvents:o,onInteractOutside:f,onEscapeKeyDown:l,onPointerDownOutside:u,onFocusOutside:d,onDismiss:()=>y.onOpenChange(!1),children:m.jsx(Ib,{"data-state":x4(y.open),role:"dialog",id:y.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)"}})})})}),w4="PopoverClose",gue=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=dc(w4,n);return m.jsx(yn.button,{type:"button",...r,ref:t,onClick:Wt(e.onClick,()=>i.onOpenChange(!1))})});gue.displayName=w4;var vue="PopoverArrow",yue=b.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=Cm(n);return m.jsx(Ob,{...i,...r,ref:t})});yue.displayName=vue;function x4(e){return e?"open":"closed"}var bue=p4,_ue=v4,wue=y4,xue=b4,Sue=[" ","Enter","ArrowUp","ArrowDown"],Eue=[" ","Enter"],uu="Select",[zb,jb,Cue]=tk(uu),[bf]=Xa(uu,[Cue,cc]),Fb=cc(),[kue,fc]=bf(uu),[Tue,Rue]=bf(uu),S4=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:y,required:g,form:_}=e,w=Fb(t),[S,x]=b.useState(null),[k,R]=b.useState(null),[A,O]=b.useState(!1),T=nk(d),[M,z]=Ql({prop:r,defaultProp:i??!1,onChange:s,caller:uu}),[Y,U]=Ql({prop:o,defaultProp:l,onChange:u,caller:uu}),G=b.useRef(null),I=S?_||!!S.closest("form"):!0,[N,L]=b.useState(new Set),B=Array.from(N).map(P=>P.props.value).join(";");return m.jsx(bm,{...w,children:m.jsxs(kue,{required:g,scope:t,trigger:S,onTriggerChange:x,valueNode:k,onValueNodeChange:R,valueNodeHasChildren:A,onValueNodeHasChildrenChange:O,contentId:bi(),value:Y,onValueChange:U,open:M,onOpenChange:z,dir:T,triggerPointerDownPosRef:G,disabled:y,children:[m.jsx(zb.Provider,{scope:t,children:m.jsx(Tue,{scope:e.__scopeSelect,onNativeOptionAdd:b.useCallback(P=>{L(D=>new Set(D).add(P))},[]),onNativeOptionRemove:b.useCallback(P=>{L(D=>{const F=new Set(D);return F.delete(P),F})},[]),children:n})}),I?m.jsxs(q4,{"aria-hidden":!0,required:g,tabIndex:-1,name:f,autoComplete:h,value:Y,onChange:P=>U(P.target.value),disabled:y,form:_,children:[Y===void 0?m.jsx("option",{value:""}):null,Array.from(N)]},B):null]})})};S4.displayName=uu;var E4="SelectTrigger",C4=b.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...i}=e,s=Fb(n),o=fc(E4,n),l=o.disabled||r,u=cr(t,o.onTriggerChange),d=jb(n),f=b.useRef("touch"),[h,y,g]=Y4(w=>{const S=d().filter(R=>!R.disabled),x=S.find(R=>R.value===o.value),k=K4(S,w,x);k!==void 0&&o.onValueChange(k.value)}),_=w=>{l||(o.onOpenChange(!0),g()),w&&(o.triggerPointerDownPosRef.current={x:Math.round(w.pageX),y:Math.round(w.pageY)})};return m.jsx(_m,{asChild:!0,...s,children:m.jsx(yn.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":V4(o.value)?"":void 0,...i,ref:u,onClick:Wt(i.onClick,w=>{w.currentTarget.focus(),f.current!=="mouse"&&_(w)}),onPointerDown:Wt(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:Wt(i.onKeyDown,w=>{const S=h.current!=="";!(w.ctrlKey||w.altKey||w.metaKey)&&w.key.length===1&&y(w.key),!(S&&w.key===" ")&&Sue.includes(w.key)&&(_(),w.preventDefault())})})})});C4.displayName=E4;var k4="SelectValue",T4=b.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:i,children:s,placeholder:o="",...l}=e,u=fc(k4,n),{onValueNodeHasChildrenChange:d}=u,f=s!==void 0,h=cr(t,u.onValueNodeChange);return Ji(()=>{d(f)},[d,f]),m.jsx(yn.span,{...l,ref:h,style:{pointerEvents:"none"},children:V4(u.value)?m.jsx(m.Fragment,{children:o}):s})});T4.displayName=k4;var Aue="SelectIcon",R4=b.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...i}=e;return m.jsx(yn.span,{"aria-hidden":!0,...i,ref:t,children:r||"▼"})});R4.displayName=Aue;var Nue="SelectPortal",A4=e=>m.jsx(gf,{asChild:!0,...e});A4.displayName=Nue;var du="SelectContent",N4=b.forwardRef((e,t)=>{const n=fc(du,e.__scopeSelect),[r,i]=b.useState();if(Ji(()=>{i(new DocumentFragment)},[]),!n.open){const s=r;return s?xu.createPortal(m.jsx(M4,{scope:e.__scopeSelect,children:m.jsx(zb.Slot,{scope:e.__scopeSelect,children:m.jsx("div",{children:e.children})})}),s):null}return m.jsx(P4,{...e,ref:t})});N4.displayName=du;var Ao=10,[M4,hc]=bf(du),Mue="SelectContentImpl",Pue=Jl("SelectContent.RemoveScroll"),P4=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:y,collisionPadding:g,sticky:_,hideWhenDetached:w,avoidCollisions:S,...x}=e,k=fc(du,n),[R,A]=b.useState(null),[O,T]=b.useState(null),M=cr(t,X=>A(X)),[z,Y]=b.useState(null),[U,G]=b.useState(null),I=jb(n),[N,L]=b.useState(!1),B=b.useRef(!1);b.useEffect(()=>{if(R)return kb(R)},[R]),Eb();const P=b.useCallback(X=>{const[ae,...ne]=I().map(xe=>xe.ref.current),[ce]=ne.slice(-1),_e=document.activeElement;for(const xe of X)if(xe===_e||(xe==null||xe.scrollIntoView({block:"nearest"}),xe===ae&&O&&(O.scrollTop=0),xe===ce&&O&&(O.scrollTop=O.scrollHeight),xe==null||xe.focus(),document.activeElement!==_e))return},[I,O]),D=b.useCallback(()=>P([z,R]),[P,z,R]);b.useEffect(()=>{N&&D()},[N,D]);const{onOpenChange:F,triggerPointerDownPosRef:q}=k;b.useEffect(()=>{if(R){let X={x:0,y:0};const ae=ce=>{var _e,xe;X={x:Math.abs(Math.round(ce.pageX)-(((_e=q.current)==null?void 0:_e.x)??0)),y:Math.abs(Math.round(ce.pageY)-(((xe=q.current)==null?void 0:xe.y)??0))}},ne=ce=>{X.x<=10&&X.y<=10?ce.preventDefault():R.contains(ce.target)||F(!1),document.removeEventListener("pointermove",ae),q.current=null};return q.current!==null&&(document.addEventListener("pointermove",ae),document.addEventListener("pointerup",ne,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",ae),document.removeEventListener("pointerup",ne,{capture:!0})}}},[R,F,q]),b.useEffect(()=>{const X=()=>F(!1);return window.addEventListener("blur",X),window.addEventListener("resize",X),()=>{window.removeEventListener("blur",X),window.removeEventListener("resize",X)}},[F]);const[j,V]=Y4(X=>{const ae=I().filter(_e=>!_e.disabled),ne=ae.find(_e=>_e.ref.current===document.activeElement),ce=K4(ae,X,ne);ce&&setTimeout(()=>ce.ref.current.focus())}),K=b.useCallback((X,ae,ne)=>{const ce=!B.current&&!ne;(k.value!==void 0&&k.value===ae||ce)&&(Y(X),ce&&(B.current=!0))},[k.value]),$=b.useCallback(()=>R==null?void 0:R.focus(),[R]),te=b.useCallback((X,ae,ne)=>{const ce=!B.current&&!ne;(k.value!==void 0&&k.value===ae||ce)&&G(X)},[k.value]),re=r==="popper"?b1:I4,ee=re===b1?{side:l,sideOffset:u,align:d,alignOffset:f,arrowPadding:h,collisionBoundary:y,collisionPadding:g,sticky:_,hideWhenDetached:w,avoidCollisions:S}:{};return m.jsx(M4,{scope:n,content:R,viewport:O,onViewportChange:T,itemRefCallback:K,selectedItem:z,onItemLeave:$,itemTextRefCallback:te,focusSelectedItem:D,selectedItemText:U,position:r,isPositioned:N,searchRef:j,children:m.jsx(vm,{as:Pue,allowPinchZoom:!0,children:m.jsx(gm,{asChild:!0,trapped:k.open,onMountAutoFocus:X=>{X.preventDefault()},onUnmountAutoFocus:Wt(i,X=>{var ae;(ae=k.trigger)==null||ae.focus({preventScroll:!0}),X.preventDefault()}),children:m.jsx(mf,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:o,onFocusOutside:X=>X.preventDefault(),onDismiss:()=>k.onOpenChange(!1),children:m.jsx(re,{role:"listbox",id:k.contentId,"data-state":k.open?"open":"closed",dir:k.dir,onContextMenu:X=>X.preventDefault(),...x,...ee,onPlaced:()=>L(!0),ref:M,style:{display:"flex",flexDirection:"column",outline:"none",...x.style},onKeyDown:Wt(x.onKeyDown,X=>{const ae=X.ctrlKey||X.altKey||X.metaKey;if(X.key==="Tab"&&X.preventDefault(),!ae&&X.key.length===1&&V(X.key),["ArrowUp","ArrowDown","Home","End"].includes(X.key)){let ce=I().filter(_e=>!_e.disabled).map(_e=>_e.ref.current);if(["ArrowUp","End"].includes(X.key)&&(ce=ce.slice().reverse()),["ArrowUp","ArrowDown"].includes(X.key)){const _e=X.target,xe=ce.indexOf(_e);ce=ce.slice(xe+1)}setTimeout(()=>P(ce)),X.preventDefault()}})})})})})})});P4.displayName=Mue;var Iue="SelectItemAlignedPosition",I4=b.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...i}=e,s=fc(du,n),o=hc(du,n),[l,u]=b.useState(null),[d,f]=b.useState(null),h=cr(t,M=>f(M)),y=jb(n),g=b.useRef(!1),_=b.useRef(!0),{viewport:w,selectedItem:S,selectedItemText:x,focusSelectedItem:k}=o,R=b.useCallback(()=>{if(s.trigger&&s.valueNode&&l&&d&&w&&S&&x){const M=s.trigger.getBoundingClientRect(),z=d.getBoundingClientRect(),Y=s.valueNode.getBoundingClientRect(),U=x.getBoundingClientRect();if(s.dir!=="rtl"){const _e=U.left-z.left,xe=Y.left-_e,We=M.left-xe,De=M.width+We,Pt=Math.max(De,z.width),tt=window.innerWidth-Ao,lt=iI(xe,[Ao,Math.max(Ao,tt-Pt)]);l.style.minWidth=De+"px",l.style.left=lt+"px"}else{const _e=z.right-U.right,xe=window.innerWidth-Y.right-_e,We=window.innerWidth-M.right-xe,De=M.width+We,Pt=Math.max(De,z.width),tt=window.innerWidth-Ao,lt=iI(xe,[Ao,Math.max(Ao,tt-Pt)]);l.style.minWidth=De+"px",l.style.right=lt+"px"}const G=y(),I=window.innerHeight-Ao*2,N=w.scrollHeight,L=window.getComputedStyle(d),B=parseInt(L.borderTopWidth,10),P=parseInt(L.paddingTop,10),D=parseInt(L.borderBottomWidth,10),F=parseInt(L.paddingBottom,10),q=B+P+N+F+D,j=Math.min(S.offsetHeight*5,q),V=window.getComputedStyle(w),K=parseInt(V.paddingTop,10),$=parseInt(V.paddingBottom,10),te=M.top+M.height/2-Ao,re=I-te,ee=S.offsetHeight/2,X=S.offsetTop+ee,ae=B+P+X,ne=q-ae;if(ae<=te){const _e=G.length>0&&S===G[G.length-1].ref.current;l.style.bottom="0px";const xe=d.clientHeight-w.offsetTop-w.offsetHeight,We=Math.max(re,ee+(_e?$:0)+xe+D),De=ae+We;l.style.height=De+"px"}else{const _e=G.length>0&&S===G[0].ref.current;l.style.top="0px";const We=Math.max(te,B+w.offsetTop+(_e?K:0)+ee)+ne;l.style.height=We+"px",w.scrollTop=ae-te+w.offsetTop}l.style.margin=`${Ao}px 0`,l.style.minHeight=j+"px",l.style.maxHeight=I+"px",r==null||r(),requestAnimationFrame(()=>g.current=!0)}},[y,s.trigger,s.valueNode,l,d,w,S,x,s.dir,r]);Ji(()=>R(),[R]);const[A,O]=b.useState();Ji(()=>{d&&O(window.getComputedStyle(d).zIndex)},[d]);const T=b.useCallback(M=>{M&&_.current===!0&&(R(),k==null||k(),_.current=!1)},[R,k]);return m.jsx(Lue,{scope:n,contentWrapper:l,shouldExpandOnScrollRef:g,onScrollButtonChange:T,children:m.jsx("div",{ref:u,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:A},children:m.jsx(yn.div,{...i,ref:h,style:{boxSizing:"border-box",maxHeight:"100%",...i.style}})})})});I4.displayName=Iue;var Oue="SelectPopperPosition",b1=b.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:i=Ao,...s}=e,o=Fb(n);return m.jsx(Ib,{...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)"}})});b1.displayName=Oue;var[Lue,Tk]=bf(du,{}),_1="SelectViewport",O4=b.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...i}=e,s=hc(_1,n),o=Tk(_1,n),l=cr(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(zb.Slot,{scope:n,children:m.jsx(yn.div,{"data-radix-select-viewport":"",role:"presentation",...i,ref:l,style:{position:"relative",flex:1,overflow:"hidden auto",...i.style},onScroll:Wt(i.onScroll,d=>{const f=d.currentTarget,{contentWrapper:h,shouldExpandOnScrollRef:y}=o;if(y!=null&&y.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 k=x+g,R=Math.min(_,k),A=k-R;h.style.height=R+"px",h.style.bottom==="0px"&&(f.scrollTop=A>0?A:0,h.style.justifyContent="flex-end")}}}u.current=f.scrollTop})})})]})});O4.displayName=_1;var L4="SelectGroup",[Due,Bue]=bf(L4),zue=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=bi();return m.jsx(Due,{scope:n,id:i,children:m.jsx(yn.div,{role:"group","aria-labelledby":i,...r,ref:t})})});zue.displayName=L4;var D4="SelectLabel",jue=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=Bue(D4,n);return m.jsx(yn.div,{id:i.id,...r,ref:t})});jue.displayName=D4;var Wy="SelectItem",[Fue,B4]=bf(Wy),z4=b.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:i=!1,textValue:s,...o}=e,l=fc(Wy,n),u=hc(Wy,n),d=l.value===r,[f,h]=b.useState(s??""),[y,g]=b.useState(!1),_=cr(t,k=>{var R;return(R=u.itemRefCallback)==null?void 0:R.call(u,k,r,i)}),w=bi(),S=b.useRef("touch"),x=()=>{i||(l.onValueChange(r),l.onOpenChange(!1))};if(r==="")throw new Error("A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.");return m.jsx(Fue,{scope:n,value:r,disabled:i,textId:w,isSelected:d,onItemTextChange:b.useCallback(k=>{h(R=>R||((k==null?void 0:k.textContent)??"").trim())},[]),children:m.jsx(zb.ItemSlot,{scope:n,value:r,disabled:i,textValue:f,children:m.jsx(yn.div,{role:"option","aria-labelledby":w,"data-highlighted":y?"":void 0,"aria-selected":d&&y,"data-state":d?"checked":"unchecked","aria-disabled":i||void 0,"data-disabled":i?"":void 0,tabIndex:i?void 0:-1,...o,ref:_,onFocus:Wt(o.onFocus,()=>g(!0)),onBlur:Wt(o.onBlur,()=>g(!1)),onClick:Wt(o.onClick,()=>{S.current!=="mouse"&&x()}),onPointerUp:Wt(o.onPointerUp,()=>{S.current==="mouse"&&x()}),onPointerDown:Wt(o.onPointerDown,k=>{S.current=k.pointerType}),onPointerMove:Wt(o.onPointerMove,k=>{var R;S.current=k.pointerType,i?(R=u.onItemLeave)==null||R.call(u):S.current==="mouse"&&k.currentTarget.focus({preventScroll:!0})}),onPointerLeave:Wt(o.onPointerLeave,k=>{var R;k.currentTarget===document.activeElement&&((R=u.onItemLeave)==null||R.call(u))}),onKeyDown:Wt(o.onKeyDown,k=>{var A;((A=u.searchRef)==null?void 0:A.current)!==""&&k.key===" "||(Eue.includes(k.key)&&x(),k.key===" "&&k.preventDefault())})})})})});z4.displayName=Wy;var ap="SelectItemText",j4=b.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:i,...s}=e,o=fc(ap,n),l=hc(ap,n),u=B4(ap,n),d=Rue(ap,n),[f,h]=b.useState(null),y=cr(t,x=>h(x),u.onItemTextChange,x=>{var k;return(k=l.itemTextRefCallback)==null?void 0:k.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 Ji(()=>(w(_),()=>S(_)),[w,S,_]),m.jsxs(m.Fragment,{children:[m.jsx(yn.span,{id:u.textId,...s,ref:y}),u.isSelected&&o.valueNode&&!o.valueNodeHasChildren?xu.createPortal(s.children,o.valueNode):null]})});j4.displayName=ap;var F4="SelectItemIndicator",$4=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return B4(F4,n).isSelected?m.jsx(yn.span,{"aria-hidden":!0,...r,ref:t}):null});$4.displayName=F4;var w1="SelectScrollUpButton",H4=b.forwardRef((e,t)=>{const n=hc(w1,e.__scopeSelect),r=Tk(w1,e.__scopeSelect),[i,s]=b.useState(!1),o=cr(t,r.onScrollButtonChange);return Ji(()=>{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(W4,{...e,ref:o,onAutoScroll:()=>{const{viewport:l,selectedItem:u}=n;l&&u&&(l.scrollTop=l.scrollTop-u.offsetHeight)}}):null});H4.displayName=w1;var x1="SelectScrollDownButton",U4=b.forwardRef((e,t)=>{const n=hc(x1,e.__scopeSelect),r=Tk(x1,e.__scopeSelect),[i,s]=b.useState(!1),o=cr(t,r.onScrollButtonChange);return Ji(()=>{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(W4,{...e,ref:o,onAutoScroll:()=>{const{viewport:l,selectedItem:u}=n;l&&u&&(l.scrollTop=l.scrollTop+u.offsetHeight)}}):null});U4.displayName=x1;var W4=b.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...i}=e,s=hc("SelectScrollButton",n),o=b.useRef(null),l=jb(n),u=b.useCallback(()=>{o.current!==null&&(window.clearInterval(o.current),o.current=null)},[]);return b.useEffect(()=>()=>u(),[u]),Ji(()=>{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(yn.div,{"aria-hidden":!0,...i,ref:t,style:{flexShrink:0,...i.style},onPointerDown:Wt(i.onPointerDown,()=>{o.current===null&&(o.current=window.setInterval(r,50))}),onPointerMove:Wt(i.onPointerMove,()=>{var d;(d=s.onItemLeave)==null||d.call(s),o.current===null&&(o.current=window.setInterval(r,50))}),onPointerLeave:Wt(i.onPointerLeave,()=>{u()})})}),$ue="SelectSeparator",Hue=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return m.jsx(yn.div,{"aria-hidden":!0,...r,ref:t})});Hue.displayName=$ue;var S1="SelectArrow",Uue=b.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,i=Fb(n),s=fc(S1,n),o=hc(S1,n);return s.open&&o.position==="popper"?m.jsx(Ob,{...i,...r,ref:t}):null});Uue.displayName=S1;var Wue="SelectBubbleInput",q4=b.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const i=b.useRef(null),s=cr(r,i),o=yae(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(yn.select,{...n,style:{...x5,...n.style},ref:s,defaultValue:t})});q4.displayName=Wue;function V4(e){return e===""||e===void 0}function Y4(e){const t=Io(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 K4(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=que(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 que(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Vue=S4,Yue=C4,Kue=T4,Gue=R4,Xue=A4,Zue=N4,Jue=O4,Que=z4,ede=j4,tde=$4,nde=H4,rde=U4,[$b]=Xa("Tooltip",[cc]),Hb=cc(),G4="TooltipProvider",ide=700,E1="tooltip.open",[sde,Rk]=$b(G4),X4=e=>{const{__scopeTooltip:t,delayDuration:n=ide,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(sde,{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})};X4.displayName=G4;var Vp="Tooltip",[ode,km]=$b(Vp),Z4=e=>{const{__scopeTooltip:t,children:n,open:r,defaultOpen:i,onOpenChange:s,disableHoverableContent:o,delayDuration:l}=e,u=Rk(Vp,e.__scopeTooltip),d=Hb(t),[f,h]=b.useState(null),y=bi(),g=b.useRef(0),_=o??u.disableHoverableContent,w=l??u.delayDuration,S=b.useRef(!1),[x,k]=Ql({prop:r,defaultProp:i??!1,onChange:M=>{M?(u.onOpen(),document.dispatchEvent(new CustomEvent(E1))):u.onClose(),s==null||s(M)},caller:Vp}),R=b.useMemo(()=>x?S.current?"delayed-open":"instant-open":"closed",[x]),A=b.useCallback(()=>{window.clearTimeout(g.current),g.current=0,S.current=!1,k(!0)},[k]),O=b.useCallback(()=>{window.clearTimeout(g.current),g.current=0,k(!1)},[k]),T=b.useCallback(()=>{window.clearTimeout(g.current),g.current=window.setTimeout(()=>{S.current=!0,k(!0),g.current=0},w)},[w,k]);return b.useEffect(()=>()=>{g.current&&(window.clearTimeout(g.current),g.current=0)},[]),m.jsx(bm,{...d,children:m.jsx(ode,{scope:t,contentId:y,open:x,stateAttribute:R,trigger:f,onTriggerChange:h,onTriggerEnter:b.useCallback(()=>{u.isOpenDelayedRef.current?T():A()},[u.isOpenDelayedRef,T,A]),onTriggerLeave:b.useCallback(()=>{_?O():(window.clearTimeout(g.current),g.current=0)},[O,_]),onOpen:A,onClose:O,disableHoverableContent:_,children:n})})};Z4.displayName=Vp;var C1="TooltipTrigger",J4=b.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,i=km(C1,n),s=Rk(C1,n),o=Hb(n),l=b.useRef(null),u=cr(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(_m,{asChild:!0,...o,children:m.jsx(yn.button,{"aria-describedby":i.open?i.contentId:void 0,"data-state":i.stateAttribute,...r,ref:u,onPointerMove:Wt(e.onPointerMove,y=>{y.pointerType!=="touch"&&!f.current&&!s.isPointerInTransitRef.current&&(i.onTriggerEnter(),f.current=!0)}),onPointerLeave:Wt(e.onPointerLeave,()=>{i.onTriggerLeave(),f.current=!1}),onPointerDown:Wt(e.onPointerDown,()=>{i.open&&i.onClose(),d.current=!0,document.addEventListener("pointerup",h,{once:!0})}),onFocus:Wt(e.onFocus,()=>{d.current||i.onOpen()}),onBlur:Wt(e.onBlur,i.onClose),onClick:Wt(e.onClick,i.onClose)})})});J4.displayName=C1;var Ak="TooltipPortal",[ade,lde]=$b(Ak,{forceMount:void 0}),Q4=e=>{const{__scopeTooltip:t,forceMount:n,children:r,container:i}=e,s=km(Ak,t);return m.jsx(ade,{scope:t,forceMount:n,children:m.jsx(wo,{present:n||s.open,children:m.jsx(gf,{asChild:!0,container:i,children:r})})})};Q4.displayName=Ak;var of="TooltipContent",eF=b.forwardRef((e,t)=>{const n=lde(of,e.__scopeTooltip),{forceMount:r=n.forceMount,side:i="top",...s}=e,o=km(of,e.__scopeTooltip);return m.jsx(wo,{present:r||o.open,children:o.disableHoverableContent?m.jsx(tF,{side:i,...s,ref:t}):m.jsx(cde,{side:i,...s,ref:t})})}),cde=b.forwardRef((e,t)=>{const n=km(of,e.__scopeTooltip),r=Rk(of,e.__scopeTooltip),i=b.useRef(null),s=cr(t,i),[o,l]=b.useState(null),{trigger:u,onClose:d}=n,f=i.current,{onPointerInTransitChange:h}=r,y=b.useCallback(()=>{l(null),h(!1)},[h]),g=b.useCallback((_,w)=>{const S=_.currentTarget,x={x:_.clientX,y:_.clientY},k=hde(x,S.getBoundingClientRect()),R=pde(x,k),A=mde(w.getBoundingClientRect()),O=vde([...R,...A]);l(O),h(!0)},[h]);return b.useEffect(()=>()=>y(),[y]),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,y]),b.useEffect(()=>{if(o){const _=w=>{const S=w.target,x={x:w.clientX,y:w.clientY},k=(u==null?void 0:u.contains(S))||(f==null?void 0:f.contains(S)),R=!gde(x,o);k?y():R&&(y(),d())};return document.addEventListener("pointermove",_),()=>document.removeEventListener("pointermove",_)}},[u,f,o,d,y]),m.jsx(tF,{...e,ref:s})}),[ude,dde]=$b(Vp,{isInside:!1}),fde=Wse("TooltipContent"),tF=b.forwardRef((e,t)=>{const{__scopeTooltip:n,children:r,"aria-label":i,onEscapeKeyDown:s,onPointerDownOutside:o,...l}=e,u=km(of,n),d=Hb(n),{onClose:f}=u;return b.useEffect(()=>(document.addEventListener(E1,f),()=>document.removeEventListener(E1,f)),[f]),b.useEffect(()=>{if(u.trigger){const h=y=>{const g=y.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(mf,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:s,onPointerDownOutside:o,onFocusOutside:h=>h.preventDefault(),onDismiss:f,children:m.jsxs(Ib,{"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(fde,{children:r}),m.jsx(ude,{scope:n,isInside:!0,children:m.jsx(E5,{id:u.contentId,role:"tooltip",children:i||r})})]})})});eF.displayName=of;var nF="TooltipArrow",rF=b.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,i=Hb(n);return dde(nF,n).isInside?null:m.jsx(Ob,{...i,...r,ref:t})});rF.displayName=nF;function hde(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 pde(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 mde(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 gde(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,y=u.y;f>r!=y>r&&n<(h-d)*(r-f)/(y-f)+d&&(i=!i)}return i}function vde(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),yde(t)}function yde(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 bde=X4,_de=Z4,wde=J4,xde=Q4,Sde=eF,Ede=rF;const iF=b.createContext(!1);function Cde({blocked:e,children:t}){return m.jsx(iF.Provider,{value:e,children:t})}function Tm(){return b.useContext(iF)}function Ub({...e}){return m.jsx(bue,{"data-slot":"popover",...e})}function Wb({...e}){return m.jsx(_ue,{"data-slot":"popover-trigger",...e})}function qb({className:e,align:t="center",sideOffset:n=4,inert:r,"aria-disabled":i,...s}){const o=Tm();return m.jsx(wue,{children:m.jsx(xue,{"data-slot":"popover-content",align:t,sideOffset:n,className:Ye("z-50 w-72 origin-(--radix-popover-content-transform-origin) rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-hidden data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",e),inert:o||r?!0:void 0,"aria-disabled":o?!0:i,"data-relay-interaction-blocked":o?"true":void 0,...s})})}const sI=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,oI=Iz,kde=(e,t)=>n=>{var r;if((t==null?void 0:t.variants)==null)return oI(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 y=sI(f)||sI(h);return i[d][y]}),l=n&&Object.entries(n).reduce((d,f)=>{let[h,y]=f;return y===void 0||(d[h]=y),d},{}),u=t==null||(r=t.compoundVariants)===null||r===void 0?void 0:r.reduce((d,f)=>{let{class:h,className:y,...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,y]:d},[]);return oI(e,o,u,n==null?void 0:n.class,n==null?void 0:n.className)},Tde=kde("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 yt({className:e,variant:t="default",size:n="default",asChild:r=!1,...i}){const s=r?Hse:"button";return m.jsx(s,{"data-slot":"button","data-variant":t,"data-size":n,className:Ye(Tde({variant:t,size:n,className:e})),...i})}function _f({...e}){return m.jsx(Jce,{"data-slot":"dropdown-menu",...e})}function Rde({...e}){return m.jsx(f4,{"data-slot":"dropdown-menu-portal",...e})}function wf({...e}){return m.jsx(Qce,{"data-slot":"dropdown-menu-trigger",...e})}function xf({className:e,sideOffset:t=4,inert:n,"aria-disabled":r,...i}){const s=Tm();return m.jsx(f4,{children:m.jsx(eue,{"data-slot":"dropdown-menu-content",sideOffset:t,className:Ye("z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",e),inert:s||n?!0:void 0,"aria-disabled":s?!0:r,"data-relay-interaction-blocked":s?"true":void 0,...i})})}function ti({className:e,inset:t,variant:n="default",...r}){return m.jsx(nue,{"data-slot":"dropdown-menu-item","data-inset":t,"data-variant":n,className:Ye("relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground data-[variant=destructive]:*:[svg]:text-destructive!",e),...r})}function y0({className:e,children:t,checked:n,...r}){return m.jsxs(rue,{"data-slot":"dropdown-menu-checkbox-item",className:Ye("relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",e),checked:n,...r,children:[m.jsx("span",{className:"pointer-events-none absolute left-2 flex size-3.5 items-center justify-center",children:m.jsx(iue,{children:m.jsx(ua,{className:"size-4"})})}),t]})}function yv({className:e,inset:t,...n}){return m.jsx(tue,{"data-slot":"dropdown-menu-label","data-inset":t,className:Ye("px-2 py-1.5 text-sm font-medium data-[inset]:pl-8",e),...n})}function Gc({className:e,...t}){return m.jsx(sue,{"data-slot":"dropdown-menu-separator",className:Ye("-mx-1 my-1 h-px bg-border",e),...t})}function Ade({...e}){return m.jsx(oue,{"data-slot":"dropdown-menu-sub",...e})}function Nde({className:e,inset:t,children:n,...r}){return m.jsxs(aue,{"data-slot":"dropdown-menu-sub-trigger","data-inset":t,className:Ye("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(Hd,{className:"ml-auto size-4"})]})}function Mde({className:e,...t}){return m.jsx(lue,{"data-slot":"dropdown-menu-sub-content",className:Ye("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 Pde={"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 Qc({variant:e,action:t}){const{heading:n,body:r}=Pde[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 Ide={online:"bg-[var(--color-status-success)]",offline:"bg-[var(--muted-foreground)]",connecting:"bg-[var(--color-status-working)] animate-pulse"},Ode={online:"开发机在线",offline:"开发机离线",connecting:"正在连接开发机"};function k1({status:e,className:t}){return m.jsx("span",{className:Ye("inline-block w-2 h-2 rounded-full shrink-0",Ide[e],t),role:"status","aria-label":Ode[e]})}function Cp({name:e,osName:t,className:n,nameClassName:r}){return m.jsxs("span",{className:Ye("min-w-0 flex-1",n),children:[m.jsx("span",{"data-slot":"proxy-name",className:Ye("block truncate text-sm font-normal leading-5",r),children:e}),t&&m.jsx("span",{"data-slot":"proxy-os",className:"block truncate text-xs font-normal leading-4 text-muted-foreground",children:t})]})}function es({...e}){return m.jsx(ok,{"data-slot":"dialog",...e})}function Lde({...e}){return m.jsx(ak,{"data-slot":"dialog-portal",...e})}function Dde({...e}){return m.jsx(Rb,{"data-slot":"dialog-close",...e})}function Bde({className:e,...t}){return m.jsx(lk,{"data-slot":"dialog-overlay",className:Ye("fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",e),...t})}function ts({className:e,children:t,showCloseButton:n=!0,focusSurfaceOnOpen:r=!1,onOpenAutoFocus:i,inert:s,"aria-disabled":o,...l}){const u=Tm();return m.jsxs(Lde,{"data-slot":"dialog-portal",children:[m.jsx(Bde,{}),m.jsxs(ck,{"data-slot":"dialog-content",className:Ye("fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border bg-background p-6 shadow-lg duration-200 outline-none data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 sm:max-w-lg",e),onOpenAutoFocus:d=>{i==null||i(d),!(!r||d.defaultPrevented)&&(d.preventDefault(),d.currentTarget.focus({preventScroll:!0}))},inert:u||s?!0:void 0,"aria-disabled":u?!0:o,"data-relay-interaction-blocked":u?"true":void 0,...l,children:[t,n&&m.jsxs(Rb,{"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(bu,{}),m.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function ns({className:e,...t}){return m.jsx("div",{"data-slot":"dialog-header",className:Ye("flex flex-col gap-2 text-center sm:text-left",e),...t})}function Vs({className:e,showCloseButton:t=!1,children:n,...r}){return m.jsxs("div",{"data-slot":"dialog-footer",className:Ye("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end max-sm:[&_button]:min-h-11",e),...r,children:[n,t&&m.jsx(Rb,{asChild:!0,children:m.jsx(yt,{variant:"outline",children:"Close"})})]})}function $i({className:e,...t}){return m.jsx(J5,{"data-slot":"dialog-title",className:Ye("text-lg leading-none font-semibold",e),...t})}function Es({className:e,...t}){return m.jsx(Q5,{"data-slot":"dialog-description",className:Ye("text-sm text-muted-foreground",e),...t})}function zde(e){return`“${(e==null?void 0:e.name)??(e==null?void 0:e.proxyId)??"这台开发机"}”只会从当前 Relay 的开发机列表中移除。不会删除机器上的文件或会话,也不会阻止它再次连接;以后重新运行时,它会重新出现在列表中。`}function jde({open:e,target:t,removing:n,onOpenChange:r,onConfirm:i}){return m.jsx(es,{open:e,onOpenChange:s=>{n||r(s)},children:m.jsxs(ts,{"data-slot":"proxy-removal-dialog",showCloseButton:!n,onEscapeKeyDown:s=>{n&&s.preventDefault()},onPointerDownOutside:s=>{n&&s.preventDefault()},children:[m.jsxs(ns,{children:[m.jsx($i,{children:"移除离线开发机?"}),m.jsx(Es,{children:zde(t)})]}),m.jsxs(Vs,{children:[m.jsx(yt,{type:"button",variant:"ghost",disabled:n,onClick:()=>r(!1),children:"取消"}),m.jsxs(yt,{type:"button",variant:"destructive",disabled:n||!t,"aria-busy":n||void 0,onClick:i,"data-slot":"proxy-removal-confirm",children:[n&&m.jsx(di,{className:"size-4 animate-spin","aria-hidden":"true"}),n?"正在移除":"移除"]})]})]})})}const ly=80,Fde=8,$de=1.2;function aI(e){return Math.max(0,Math.min(ly,e))}function Hde({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,y]=b.useState(null),g=h??(i?ly:0),_=h!==null;function w(R){var A,O;if(!(s||R.pointerType!=="touch"&&R.pointerType!=="pen")&&!R.target.closest("button")){d.current={pointerId:R.pointerId,startX:R.clientX,startY:R.clientY,startOffset:i?ly:0,axis:"pending"};try{(O=(A=R.currentTarget).setPointerCapture)==null||O.call(A,R.pointerId)}catch{}}}function S(R){const A=d.current;if(!A||A.pointerId!==R.pointerId)return;const O=R.clientX-A.startX,T=R.clientY-A.startY;if(A.axis==="pending"){if(Math.hypot(O,T)<Fde)return;A.axis=Math.abs(O)>Math.abs(T)*$de?"horizontal":"vertical"}A.axis!=="vertical"&&(R.preventDefault(),y(aI(A.startOffset-O)))}function x(R,A=!1){var M,z;const O=d.current;if(!O||O.pointerId!==R.pointerId)return;d.current=null;try{(z=(M=R.currentTarget).releasePointerCapture)==null||z.call(M,R.pointerId)}catch{}if(O.axis!=="horizontal"||A){y(null);return}R.preventDefault();const T=h??aI(O.startOffset-(R.clientX-O.startX));y(null),o(T>=ly/2),f.current=!0,window.setTimeout(()=>{f.current=!1},0)}function k(R){if(f.current){f.current=!1,R.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:R=>x(R),onPointerCancel:R=>x(R,!0),onClick:k,children:[m.jsx(k1,{status:"offline"}),m.jsx(Cp,{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 sF({layout:e,variant:t="default"}){const n=Ae(M=>M.proxies),r=Ae(M=>M.proxyListLoaded),i=Ae(M=>M.relayClientAuthIssue),s=Ae(M=>M.selectedProxyId),o=Ae(M=>M.proxySwitchTarget),l=ds(),u=Cs(),[d,f]=b.useState(!1),[h,y]=b.useState(null),[g,_]=b.useState(null),[w,S]=b.useState(null);async function x(M,z){if(o)return;const Y=Ft;if(!Y){Ue.error("请先连接开发机");return}const U=z??M,G=s!==null&&s!==M;Ae.getState().setProxySwitchTarget({proxyId:M,name:U});try{const I=await Y.selectProxy(M);if(!I.success){Ue.error(`无法连接 ${U}:${I.error??"未知错误"}`);return}const N=Y.getPreviewScope();if(!N||N.proxyId!==M||N.bindingId!==I.bindingId)throw Nt.dispose(),Y.clearBoundProxy(),new Error("开发机绑定状态无效,请重试");Nt.activate(Y,N),Nt.syncWebSnapshot(N).catch(L=>{L instanceof Error&&L.name==="AbortError"||console.error("[proxy-switcher] web preview snapshot failed",L)}),Nt.syncDeviceSnapshot(N).catch(L=>{L instanceof Error&&L.name==="AbortError"||console.error("[proxy-switcher] device preview snapshot failed",L)}),G&&(Ht.getState().prepareForProxySwitch(U),Gr.getState().prepareForProxySwitch()),Mr("local",Sn.proxyId,M),Ae.getState().setProxy(M,z??null),Ae.getState().setProxyOnline(!0),Ae.getState().transitionToPhase("session_browsing"),Y.sendControl({type:"session_list_request"}),Y.requestProxyInfo().then(L=>{if(Ae.getState().selectedProxyId!==M||!Nt.isActive(Y,N))return;const B=Gr.getState();B.setHomePath(L.homePath),B.setAgentCli(L.agentCli),Ae.getState().setTerminalShells(L.terminalShells)}).catch(L=>{Nt.isActive(Y,N)&&console.error("[proxy-switcher] post-bind proxy info fetch failed",L)}),Y.requestAgentStatuses().then(L=>{if(Ae.getState().selectedProxyId!==M||!Nt.isActive(Y,N))return;const B=Ht.getState();for(const P of L)B.setAgentStatus(P.sessionId,P.payload)}).catch(L=>{Nt.isActive(Y,N)&&console.error("[proxy-switcher] post-bind data fetch failed",L)}),YC(Y).then(L=>{L.status==="failed"&&console.error("[proxy-switcher] post-bind data fetch failed",L.error)}),f(!1),(e==="page"||l.pathname.startsWith("/chat/")||l.pathname.startsWith("/preview/device/"))&&u("/sessions")}catch(I){const N=I instanceof Error?I.message:"未知错误";Ue.error(`无法连接 ${U}:${N}`)}finally{Ae.getState().setProxySwitchTarget(null)}}function k(M){M.online||w||(y(null),_({proxyId:M.proxyId,...M.name?{name:M.name}:{}}))}async function R(){const M=g;if(!M||w)return;const z=Ft;if(!z){Ue.error("Relay 连接不可用,请稍后重试");return}const Y=Ae.getState().proxies.find(U=>U.proxyId===M.proxyId);if(!Y){if(!Ae.getState().proxyListLoaded){Ue.info("正在重新连接 Relay,请稍后再试");return}Ep(M.proxyId,z)&&u("/"),Ue.info("这台开发机已经不在列表中"),_(null);return}if(Y.online){Ue.warning("这台开发机已重新上线,未移除"),_(null);return}S(M.proxyId),Mie(M.proxyId);try{const U=await z.removeOfflineProxy(M.proxyId);if(U.success){Id(M.proxyId),Ep(M.proxyId,z)&&u("/"),Ue.success(`已移除 ${M.name??M.proxyId}`),_(null);return}if(U.errorCode===Pr.PROXY_ONLINE){Id(M.proxyId),Ue.warning("这台开发机已重新上线,未移除"),_(null),z.listProxies();return}if(U.errorCode===Pr.PROXY_NOT_FOUND){Id(M.proxyId),Ep(M.proxyId,z)&&u("/"),Ue.info("这台开发机已经不在列表中"),_(null),z.listProxies();return}Id(M.proxyId),Ue.error(U.error??"无法移除开发机,请重试")}catch(U){Ue.error(U instanceof Error?U.message:"无法移除开发机,请重试"),z.listProxies()}finally{S(null)}}const A=m.jsx(jde,{open:g!==null,target:g,removing:w!==null,onOpenChange:M=>{M||_(null)},onConfirm:()=>void R()});if(e==="page")return i==="missing_client_token"?m.jsx(Qc,{variant:"client-token-missing"}):i==="invalid_client_token"?m.jsx(Qc,{variant:"client-token-invalid"}):r?n.length===0?m.jsx(Qc,{variant:"no-proxy"}):m.jsxs(m.Fragment,{children:[m.jsxs("div",{className:"flex h-full flex-col gap-3 overflow-auto p-4",children:[m.jsx("h3",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground",children:"开发机"}),m.jsx("ul",{role:"list",className:"flex flex-col gap-2",children:n.map(M=>{const z=(o==null?void 0:o.proxyId)===M.proxyId,Y=o!==null;return M.online?m.jsx("li",{children:m.jsxs("button",{type:"button","data-slot":"proxy-item","data-proxy-id":M.proxyId,"data-online":"true","data-selecting":z||void 0,disabled:Y||w!==null,"aria-busy":z||void 0,onClick:()=>x(M.proxyId,M.name),className:Ye("flex min-h-[44px] w-full items-center gap-3 rounded-md border bg-card px-3 text-left transition-colors disabled:cursor-not-allowed disabled:hover:bg-card",M.osName?"h-14":"h-11",z?"border-primary/40 bg-accent text-accent-foreground":"border-border hover:bg-accent",Y&&!z||w!==null?"opacity-50":""),"aria-pressed":s===M.proxyId,children:[m.jsx(k1,{status:"online"}),m.jsx(Cp,{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(di,{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(Hde,{proxyId:M.proxyId,name:M.name,osName:M.osName,selected:s===M.proxyId,revealed:h===M.proxyId,disabled:Y||w!==null,onRevealedChange:U=>y(U?M.proxyId:null),onRemove:()=>k(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(di,{className:"h-5 w-5 animate-spin","aria-hidden":!0}),m.jsx("p",{className:"text-sm",children:"连接中..."})]});const O=n.find(M=>M.proxyId===s),T=(O==null?void 0:O.name)??(O==null?void 0:O.proxyId)??"未选择开发机";return m.jsxs(m.Fragment,{children:[m.jsxs(Ub,{open:d,onOpenChange:f,children:[m.jsx(Wb,{asChild:!0,children:m.jsxs("button",{type:"button","data-slot":"proxy-switcher-trigger",className:Ye("group transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",t==="sidebarChrome"?"inline-flex min-h-9 min-w-0 max-w-full items-center justify-start gap-1.5 rounded-md text-left text-foreground hover:text-primary":"flex min-h-10 w-full items-center gap-2 rounded-md border border-border bg-background px-4 py-1.5 hover:bg-accent"),"aria-label":`当前连接:${T}`,children:[t==="default"&&m.jsx("span",{className:"h-4 w-4 shrink-0","aria-hidden":!0}),m.jsx(Cp,{name:T,osName:O==null?void 0:O.osName,className:t==="sidebarChrome"?"flex-initial":"text-center",nameClassName:t==="sidebarChrome"?"text-base font-semibold":void 0}),m.jsx(sc,{className:"h-4 w-4 text-muted-foreground shrink-0 transition-transform group-data-[state=open]:rotate-180","aria-hidden":!0})]})}),m.jsx(qb,{align:"start",className:"w-[260px] p-1",children:n.length===0?m.jsx("div",{className:"text-xs text-muted-foreground p-2",children:"暂无可连接开发机"}):m.jsx("ul",{role:"list",className:"flex flex-col",children:n.map(M=>{const z=(o==null?void 0:o.proxyId)===M.proxyId,Y=o!==null;return m.jsxs("li",{className:"group flex min-w-0 items-center rounded-md",children:[m.jsxs("button",{type:"button","data-slot":"proxy-item","data-proxy-id":M.proxyId,"data-online":M.online,"data-selecting":z||void 0,disabled:!M.online||Y,"aria-busy":z||void 0,onClick:()=>x(M.proxyId,M.name),className:Ye("flex min-w-0 flex-1 items-center gap-2 rounded-md px-2 text-left transition-colors disabled:cursor-not-allowed disabled:hover:bg-transparent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",M.osName?"h-12":"h-9",z?"bg-accent text-accent-foreground":"hover:bg-accent",Y&&!z?"opacity-50":"",M.online?"":"opacity-50"),"aria-pressed":s===M.proxyId,title:M.online?void 0:"这台开发机离线",children:[m.jsx(k1,{status:M.online?"online":"offline"}),m.jsx(Cp,{name:M.name??M.proxyId,osName:M.osName}),z?m.jsx(di,{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(_f,{children:[m.jsx(wf,{asChild:!0,children:m.jsx(yt,{type:"button",variant:"ghost",size:"icon-xs",className:"mr-1 size-8 text-muted-foreground opacity-60 hover:opacity-100 focus-visible:opacity-100",disabled:Y||w!==null,"aria-label":`${M.name??M.proxyId} 操作`,"data-slot":"proxy-row-menu-trigger",children:m.jsx(hb,{"aria-hidden":"true"})})}),m.jsx(xf,{align:"end","data-slot":"proxy-row-menu",children:m.jsxs(ti,{variant:"destructive","data-slot":"proxy-row-remove-item",onSelect:U=>{U.stopPropagation(),k(M)},children:[m.jsx(Nz,{"aria-hidden":"true"}),"移除开发机"]})})]})]},M.proxyId)})})})]}),A]})}function Ude({delayDuration:e=0,...t}){return m.jsx(bde,{"data-slot":"tooltip-provider",delayDuration:e,...t})}function Sf({...e}){return m.jsx(_de,{"data-slot":"tooltip",...e})}function Ef({...e}){return m.jsx(wde,{"data-slot":"tooltip-trigger",...e})}function Cf({className:e,sideOffset:t=0,children:n,hideArrow:r=!1,...i}){return m.jsx(xde,{children:m.jsxs(Sde,{"data-slot":"tooltip-content",sideOffset:t,className:Ye("z-50 w-fit origin-(--radix-tooltip-content-transform-origin) animate-in rounded-md bg-foreground px-3 py-1.5 text-xs text-balance text-background fade-in-0 zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95",e),...i,children:[n,!r&&m.jsx(Ede,{className:"z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px] bg-foreground fill-foreground"})]})})}function pc({...e}){return m.jsx(ok,{"data-slot":"sheet",...e})}function Wde({...e}){return m.jsx(vae,{"data-slot":"sheet-trigger",...e})}function qde({...e}){return m.jsx(ak,{"data-slot":"sheet-portal",...e})}function Vde({className:e,...t}){return m.jsx(lk,{"data-slot":"sheet-overlay",className:Ye("fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",e),...t})}function mc({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=Tm();return m.jsxs(qde,{children:[m.jsx(Vde,{className:t}),m.jsxs(ck,{"data-slot":"sheet-content",className:Ye("fixed z-50 flex flex-col gap-4 bg-background shadow-lg transition ease-in-out data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:animate-in data-[state=open]:duration-500",r==="right"&&"inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm",r==="left"&&"inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm",r==="top"&&"inset-x-0 top-0 h-auto border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",r==="bottom"&&"inset-x-0 bottom-0 h-auto border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",e),onOpenAutoFocus: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(Rb,{"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(bu,{className:"size-4"}),m.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function Eu({className:e,...t}){return m.jsx("div",{"data-slot":"sheet-header",className:Ye("flex flex-col gap-1.5 p-4",e),...t})}function gc({className:e,...t}){return m.jsx(J5,{"data-slot":"sheet-title",className:Ye("font-semibold text-foreground",e),...t})}function Vb({className:e,...t}){return m.jsx(Q5,{"data-slot":"sheet-description",className:Ye("text-sm text-muted-foreground",e),...t})}const Yde={claude:"Claude Code",codex:"Codex",kimi:"Kimi Code"},lI=["claude","codex","kimi"];function Yb(e){return Yde[e]}function oF(e,t){return lI.indexOf(e)-lI.indexOf(t)}function Yp(e){return e.provider}const T1=60*1e3,R1=60*T1,Kde=24*R1;function aF(e,t=Date.now()){const n=t-e;if(n<T1)return"刚刚";if(n<R1)return`${Math.floor(n/T1)} 分钟前`;if(n<Kde)return`${Math.floor(n/R1)} 小时前`;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 cI={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 A1(e){return e.kind!=="terminal"?cI[e.state]:e.state==="terminated"?cI.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 Gde({session:e}){const t=A1(e);return m.jsx("span",{className:Ye("inline-block size-2 rounded-full shrink-0",t.dot),"aria-label":`会话状态:${t.label}`,role:"status"})}function Xde({mode:e}){if(e!=="pty"&&e!=="json")return null;const t=e==="json"?"聊天视图":"终端视图",n=e==="json"?EC:kC;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 Zde({session:e,selected:t,now:n,onClick:r,onRename:i,onTerminate:s}){const o=Gr(w=>w.homePath),l=e.lastActive,u=e.cwd,d=ZC(e.name,o),f=JC(e,o),h=e.nameLocked&&e.name?e.name:f||(d==="New Session"?e.sessionId.slice(0,8):d),y=aF(l,n),g=e.mode==="pty"&&e.ptyOwner==="local-terminal",_=e.kind==="terminal"?"终止终端":g?"断开远程连接":"终止会话";return m.jsxs("li",{className:Ye("relative flex items-center gap-2 px-4 py-2 w-full min-w-0 transition-colors","min-h-[44px]","hover:bg-accent",t&&"dev-sidebar-active-row"),"data-slot":"session-row","data-session-id":e.sessionId,"data-selected":t,children:[t&&m.jsx("span",{className:"dev-sidebar-active-indicator absolute left-0 top-0 bottom-0 w-[2px]","aria-hidden":"true"}),m.jsxs("button",{type:"button","data-slot":"session-row-select",onClick:r,className:"flex min-h-11 flex-col justify-center gap-1 flex-1 min-w-0 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring rounded-sm md:min-h-0","aria-pressed":t,children:[m.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[m.jsx(Gde,{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(Xde,{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:Yb(e.provider)}),m.jsx("span",{className:"text-muted-foreground/60 shrink-0","aria-hidden":"true",children:"·"})]}),m.jsx("span",{className:Ye("shrink-0",A1(e).text),children:A1(e).label}),y&&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:y})]})]})]}),(i||s)&&m.jsxs(_f,{children:[m.jsx(wf,{asChild:!0,children:m.jsx(yt,{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(hb,{"aria-hidden":"true"})})}),m.jsxs(xf,{align:"end","data-slot":"session-row-menu",children:[i&&m.jsx(ti,{"data-slot":"session-row-rename-item",onSelect:w=>{w.stopPropagation(),i()},children:"重命名"}),s&&m.jsx(ti,{variant:"destructive","data-slot":"session-row-terminate-item",onSelect:w=>{w.stopPropagation(),s()},children:_})]})]})]})}function yo(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 Jde({session:e,now:t,disabled:n,loading:r,onClick:i,modeTag:s}){const o=m.jsx(Qde,{title:e.title,modeTag:s}),l=m.jsx("span",{className:"text-xs text-muted-foreground tabular-nums",children:aF(e.updatedAt,t)}),u=m.jsxs("span",{className:"flex min-w-0 flex-1 flex-col gap-0.5",children:[o,l]});return m.jsx("li",{"data-slot":"history-row","data-session-id":e.id,"data-loading":r?"true":void 0,className:"group w-full flex items-stretch",children:m.jsxs("button",{type:"button",onClick:i,disabled:n,"data-slot":"history-row-primary",className:Ye("min-w-0 flex-1 flex items-start gap-2 pl-10 pr-4 py-2 min-h-[50px]","text-left transition-colors outline-none","hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring","disabled:opacity-50 disabled:cursor-wait disabled:hover:bg-transparent"),"aria-label":`恢复会话:${e.title}`,children:[u,m.jsx(CV,{className:Ye("mt-0.5 size-3.5 shrink-0 text-muted-foreground transition-opacity",r?"animate-pulse opacity-100":"opacity-0 group-hover:opacity-100 group-focus-visible:opacity-100"),"aria-hidden":"true"})]})})}function Qde({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(efe,{mode:t})]})}function efe({mode:e}){const t=e==="json"?"聊天视图":"终端视图",n=e==="json"?EC:kC;return m.jsx("span",{"data-slot":"history-mode-tag","data-mode":e,role:"img","aria-label":t,title:t,className:Ye("inline-flex size-5 shrink-0 items-center justify-center rounded border","border-border bg-muted/50 text-muted-foreground"),children:m.jsx(n,{className:"size-3","aria-hidden":"true"})})}function lF({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(_K,{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 tfe({now:e}){const t=Gr(I=>I.homePath),n=Ht(I=>I.historySessions),r=Ht(I=>I.historyLoadStatus),[i,s]=b.useState(null),[o,l]=b.useState(null),[u,d]=b.useState("json"),[f,h]=b.useState("default"),[y,g]=b.useState(!1),[_,w]=b.useState(new Set),[S,x]=b.useState(new Set),k=Cs(),R=b.useMemo(()=>{const I=new Map;for(const N of n){const L=Yp(N);let B=I.get(L);B||(B=new Map,I.set(L,B));const P=cF(N.projectDir),D=B.get(P);D?D.sessions.push(N):B.set(P,{dir:P,sessions:[N]})}return Array.from(I.entries()).sort(([N],[L])=>oF(N,L)).map(([N,L])=>({provider:N,sessions:Array.from(L.values()).flatMap(B=>B.sessions),projects:Array.from(L.values()).map(B=>({dir:B.dir,shortDir:$p(B.dir,t,{compact:!0}),sessions:B.sessions}))}))},[n,t]);function A(I){l(I),d(nfe(I)),h(rfe(I))}async function O(I,N,L){if(i)return;const B=Ft;if(!B){Ue.error("请先连接开发机");return}s(I.id);const P=Yp(I);try{const D=await B.createSession({kind:"agent",cwd:I.projectDir,mode:N,provider:P,resumeSessionId:I.id,...L?{permissionMode:L}:{}});if(!D.success){if(D.errorCode===Pr.SESSION_ALREADY_ACTIVE){Ht.getState().setCodexActiveWriterConflict({...D.activeWriterPid?{activeWriterPid:D.activeWriterPid}:{}}),l(null);return}Ue.error(`恢复失败:${D.error}`);return}if(D.kind!=="agent"){Ue.error("恢复失败:开发机返回了错误的会话类型");return}const F={sessionId:D.sessionId,kind:"agent",...D.name!==void 0?{name:D.name}:{},...D.nameLocked!==void 0?{nameLocked:D.nameLocked}:{},state:"idle",cwd:D.cwd,lastActive:D.lastActive,provider:D.provider},q=D.mode==="pty"?{...F,mode:"pty",ptyOwner:D.ptyOwner}:{...F,mode:"json"};Ht.getState().addSession(q),k(`/chat/${D.sessionId}?mode=${D.mode}`),l(null)}catch(D){Ue.error(`恢复失败:${D instanceof Error?D.message:String(D)}`)}finally{s(null)}}function T(){const I=Ft;!I||Ht.getState().historyLoadStatus==="loading"||YC(I).then(N=>{N.status==="failed"&&Ue.error(N.error instanceof Error?N.error.message:String(N.error))})}function M(I,N){const L=uI(I,N);x(B=>{const P=new Set(B);return P.has(L)?P.delete(L):P.add(L),P})}function z(I){w(N=>{const L=new Set(N);return L.has(I)?L.delete(I):L.add(I),L})}const Y=n.length>0,U=r==="loading",G=o?uF():[];return m.jsxs("div",{"data-slot":"history-list",className:"flex flex-col",children:[m.jsxs("div",{className:"flex min-h-11 w-full items-center gap-1.5 px-4 py-1.5 md:min-h-[36px]",children:[m.jsxs("button",{type:"button",onClick:()=>Y&&g(I=>!I),disabled:!Y,"aria-expanded":Y?y:void 0,"data-slot":"history-section-header","data-expanded":y,className:Ye("flex min-w-0 flex-1 items-center gap-1.5 rounded-md py-0.5 text-left","transition-colors outline-none","hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring","disabled:cursor-default disabled:hover:text-inherit"),children:[m.jsxs("h3",{className:"min-w-0 text-sm font-semibold text-foreground",children:["全部会话",Y?m.jsxs("span",{className:"ml-1 text-muted-foreground/70 font-normal",children:["· ",n.length]}):null]}),Y?m.jsx(Hd,{className:Ye("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",y&&"rotate-90"),"aria-hidden":"true"}):null]}),m.jsx(yt,{type:"button",variant:"ghost",size:"icon-sm","aria-label":"刷新全部会话","aria-busy":U,title:U?"正在加载":"刷新",onClick:T,disabled:U,"data-slot":"history-refresh",className:"size-11 md:size-8",children:m.jsx(fm,{className:Ye("size-3.5",U&&"animate-spin motion-reduce:animate-none"),"aria-hidden":"true"})})]}),!Y&&U&&m.jsxs("div",{className:"flex items-center gap-2 px-4 py-3 text-sm text-muted-foreground/80","data-slot":"history-loading",role:"status","aria-live":"polite",children:[m.jsx(di,{className:"size-3.5 shrink-0 animate-spin motion-reduce:animate-none","aria-hidden":"true"}),m.jsx("span",{children:"正在加载会话记录..."})]}),!Y&&r==="idle"&&m.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/80","data-slot":"history-idle",role:"status",children:"会话记录尚未加载"}),!Y&&r==="error"&&m.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/80","data-slot":"history-error",role:"status",children:"会话记录加载失败,请点击刷新重试"}),Y&&r==="error"&&m.jsx("div",{className:"px-4 pb-2 text-xs text-muted-foreground/80","data-slot":"history-stale",role:"status",children:"刷新失败,当前显示上次加载的结果"}),!Y&&r==="loaded"&&m.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/70","data-slot":"history-empty",children:"暂无会话记录"}),Y&&y&&m.jsx("ul",{role:"list",className:"flex flex-col",children:R.map(I=>{const N=_.has(I.provider);return m.jsxs("li",{children:[m.jsxs("button",{type:"button",onClick:()=>z(I.provider),"aria-expanded":!N,"data-slot":"history-provider-header","data-expanded":!N,className:Ye("w-full flex items-center gap-2 px-4 pt-2 pb-1 min-h-[32px]","text-xs text-muted-foreground text-left transition-colors outline-none","hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring"),children:[m.jsx("span",{className:"font-mono",children:Yb(I.provider)}),m.jsx("span",{className:"h-px flex-1 bg-border/70","aria-hidden":"true"}),m.jsx("span",{className:"tabular-nums",children:I.sessions.length}),m.jsx(Hd,{className:Ye("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:I.projects.map(L=>{const B=uI(I.provider,L.dir),P=S.has(B);return m.jsxs("li",{children:[m.jsxs("button",{type:"button",onClick:()=>M(I.provider,L.dir),"aria-expanded":P,"data-slot":"history-group-header","data-expanded":P,className:Ye("w-full flex items-center gap-1.5 pl-6 pr-4 py-2 min-h-[36px]","text-left transition-colors outline-none","hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring"),children:[m.jsx("span",{className:"text-sm font-mono truncate flex-1 min-w-0",title:L.dir,children:L.shortDir}),m.jsx("span",{className:"text-xs text-muted-foreground/80 tabular-nums shrink-0",children:L.sessions.length}),m.jsx(Hd,{className:Ye("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",P&&"rotate-90"),"aria-hidden":"true"})]}),P&&m.jsx("ul",{role:"list",className:"flex flex-col",children:L.sessions.map(D=>m.jsx(Jde,{session:D,now:e,disabled:i!==null,loading:i===D.id,onClick:()=>A(D),modeTag:D.preferredMode},D.id))})]},B)})})]},I.provider)})}),m.jsx(ife,{session:o,open:o!==null,modes:G,mode:u,permissionMode:f,submitting:i!==null,onOpenChange:I=>{I||l(null)},onModeChange:d,onPermissionModeChange:h,onConfirm:()=>{o&&O(o,u,f)}})]})}function uI(e,t){return`${e}:${cF(t)}`}function cF(e){const t=e.trim();return!t||t==="/"?t||"/":t.replace(/\/+$/,"")||"/"}function uF(){return["json","pty"]}function nfe(e){const t=uF();return e.preferredMode&&t.includes(e.preferredMode)?e.preferredMode:t[0]??"json"}function rfe(e){return Yp(e)==="codex"?"auto":"default"}function ife({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),y=i==="bypassPermissions",g=yo("(min-width: 768px)"),_=e?Yp(e):null,w=_==="codex",S=_==="kimi";b.useEffect(()=>{t||h(!1)},[t]);const x=f?m.jsx(lF,{providerLabel:e?Yb(Yp(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(dI,{checked:r==="json",label:"聊天",icon:m.jsx(EC,{className:"size-4","aria-hidden":"true"}),disabled:s,onClick:()=>l("json")}),n.includes("pty")&&m.jsx(dI,{checked:r==="pty",label:"终端",icon:m.jsx(kC,{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(bv,{checked:i==="default",label:S?"手工审批":"严格审批",description:S?"工具调用会在 Web 中请求确认。":"所有需要权限的操作都要确认。",disabled:s,onClick:()=>u("default")}),m.jsx(bv,{checked:i==="auto",label:w?"按需审批":S?"自动审批":"自动判定",description:w?"Codex 在需要时请求确认。":S?"Kimi Code 使用原生 yolo 模式自动审批。":"交给 Agent CLI 的原生策略判断。",disabled:s,onClick:()=>u("auto")}),S&&m.jsx(bv,{checked:i==="plan",label:"只读规划",description:"Kimi Code 使用只读规划模式。",disabled:s,onClick:()=>u("plan")}),m.jsx(bv,{checked:i==="bypassPermissions",label:S?"全自动":"跳过全部审批",description:S?"危险模式,Kimi Code 将全自动执行。":"危险模式,会跳过工具审批和部分沙箱保护。",destructive:!0,disabled:s,onClick:()=>u("bypassPermissions")})]})]})]}),k=m.jsxs(m.Fragment,{children:[m.jsx(yt,{type:"button",variant:"ghost",disabled:s,onClick:()=>{f?h(!1):o(!1)},children:f?"返回":"取消"}),m.jsx(yt,{type:"button",variant:f?"destructive":"default",disabled:s,onClick:()=>{if(y&&!f){h(!0);return}d()},"data-slot":f?"bypass-permission-confirm":void 0,children:s?"恢复中...":f?"确认":"恢复"})]});return g?m.jsx(es,{open:t,onOpenChange:o,children:m.jsxs(ts,{focusSurfaceOnOpen:!0,className:"min-w-0 sm:max-w-md","data-slot":"history-restore-dialog",children:[m.jsxs(ns,{className:"min-w-0",children:[m.jsx($i,{children:f?"跳过全部审批?":"恢复会话"}),m.jsx(Es,{className:"min-w-0 truncate pr-10 sm:pr-0",title:e==null?void 0:e.title,children:(e==null?void 0:e.title)??""})]}),x,m.jsx(Vs,{children:k})]})}):m.jsx(pc,{open:t,onOpenChange:o,children:m.jsxs(mc,{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(Eu,{className:"min-w-0 shrink-0 px-4 pb-2 pt-4 text-left",children:[m.jsx(gc,{children:f?"跳过全部审批?":"恢复会话"}),m.jsx(Vb,{className:"min-w-0 truncate pr-10",title:e==null?void 0:e.title,children:(e==null?void 0:e.title)??""})]}),m.jsx("div",{className:"min-h-0 overflow-y-auto px-4 pb-3","data-slot":"history-restore-body",children:x}),m.jsx("div",{className:"shrink-0 border-t border-border/70 bg-background px-4 pb-[max(theme(spacing.4),env(safe-area-inset-bottom))] pt-3","data-slot":"history-restore-footer",children:m.jsx("div",{className:"flex flex-col-reverse gap-2 [&_button]:min-h-11 [&_button]:w-full",children:k})})]})})}function dI({checked:e,label:t,icon:n,disabled:r,onClick:i}){return m.jsxs("button",{type:"button",role:"radio","aria-label":t,"aria-checked":e,disabled:r,onClick:i,className:Ye("grid min-h-11 w-full min-w-0 max-w-full grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-2 rounded-md border px-3 text-sm outline-none transition-colors md:h-10 md:min-h-0","focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-wait disabled:opacity-60",e?"border-primary text-foreground":"border-border text-muted-foreground hover:bg-accent/60 hover:text-foreground"),children:[n,m.jsx("span",{className:"min-w-0 text-center",children:t}),m.jsx(ua,{className:Ye("size-3.5 justify-self-end transition-opacity",e?"opacity-100":"opacity-0"),"aria-hidden":"true"})]})}function bv({checked:e,label:t,description:n,destructive:r,disabled:i,onClick:s}){return m.jsxs("button",{type:"button",role:"radio","aria-label":t,"aria-checked":e,disabled:i,onClick:s,className:Ye("grid w-full min-w-0 max-w-full grid-cols-[auto_minmax(0,1fr)_auto] items-start gap-3 rounded-md border p-3 text-left outline-none transition-colors","focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-wait disabled:opacity-60",e?r?"border-destructive/70":"border-primary":"border-border hover:bg-accent/60"),children:[m.jsx("span",{className:Ye("mt-0.5 flex size-4 shrink-0 items-center justify-center rounded-full border",e?r?"border-destructive":"border-primary":"border-muted-foreground/50"),"aria-hidden":"true",children:e&&m.jsx("span",{className:Ye("size-2 rounded-full",r?"bg-destructive":"bg-primary")})}),m.jsxs("span",{className:"grid min-w-0 gap-1",children:[m.jsx("span",{className:Ye("text-sm font-medium",r?"text-destructive":"text-foreground"),children:t}),m.jsx("span",{className:"min-w-0 break-words text-xs leading-5 text-muted-foreground",children:n})]}),e&&m.jsx(ua,{className:Ye("mt-0.5 size-4 shrink-0",r?"text-destructive":"text-primary"),"aria-hidden":"true"})]})}function Kb({...e}){return m.jsx(Vue,{"data-slot":"select",...e})}function Gb({...e}){return m.jsx(Kue,{"data-slot":"select-value",...e})}function Xb({className:e,size:t="default",children:n,...r}){return m.jsxs(Yue,{"data-slot":"select-trigger","data-size":t,className:Ye("flex w-fit items-center justify-between gap-2 rounded-md border border-input bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/75 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-[placeholder]:text-muted-foreground data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 dark:bg-input/30 dark:hover:bg-input/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground",e),...r,children:[n,m.jsx(Gue,{asChild:!0,children:m.jsx(sc,{className:"size-4 opacity-50"})})]})}function Zb({className:e,children:t,position:n="item-aligned",align:r="center",inert:i,"aria-disabled":s,...o}){const l=Tm();return m.jsx(Xue,{children:m.jsxs(Zue,{"data-slot":"select-content",className:Ye("relative z-50 max-h-(--radix-select-content-available-height) min-w-[8rem] origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",n==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",e),position:n,align:r,inert:l||i?!0:void 0,"aria-disabled":l?!0:s,"data-relay-interaction-blocked":l?"true":void 0,...o,children:[m.jsx(sfe,{}),m.jsx(Jue,{className:Ye("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1"),children:t}),m.jsx(ofe,{})]})})}function Jb({className:e,children:t,...n}){return m.jsxs(Que,{"data-slot":"select-item",className:Ye("relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2",e),...n,children:[m.jsx("span",{"data-slot":"select-item-indicator",className:"absolute right-2 flex size-3.5 items-center justify-center",children:m.jsx(tde,{children:m.jsx(ua,{className:"size-4"})})}),m.jsx(ede,{children:t})]})}function sfe({className:e,...t}){return m.jsx(nde,{"data-slot":"select-scroll-up-button",className:Ye("flex cursor-default items-center justify-center py-1",e),...t,children:m.jsx(wC,{className:"size-4"})})}function ofe({className:e,...t}){return m.jsx(rde,{"data-slot":"select-scroll-down-button",className:Ye("flex cursor-default items-center justify-center py-1",e),...t,children:m.jsx(sc,{className:"size-4"})})}function afe(e,t,n){var u;if(t==="insert"){const d=e.split("@").pop()??"",f=au((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:Us(r),query:""};const i=bb(r,e);if(!i)return{currentPath:"",query:""};const s=qC(i),o=au(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:Us(i),query:""}:{currentPath:Us(s),query:i.slice(i.lastIndexOf(o)+1).toLowerCase()}}function b0(e,t){return bb(e,t)}const dF=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:y},g){const _=Gr(Te=>f?Te.treeWithHidden:Te.tree),w=Gr(Te=>Te.cwd),S=Gr(Te=>Te.homePath),x=Ae(Te=>Te.selectedProxyId),k=o==="insert"?w:S||w,R=b.useMemo(()=>new Set(_.keys()),[_]),A=b.useMemo(()=>afe(t,o,{baseCwd:k,knownDirs:R}),[t,o,k,R]),O=A.currentPath,T=b.useMemo(()=>b0(k,O),[k,O]),M=A.query,z=b.useRef(new Map),[Y,U]=b.useState(!1),[G,I]=b.useState(""),[N,L]=b.useState(!1),[B,P]=b.useState(null),[D,F]=b.useState(0),[q,j]=b.useState(!1),[V,K]=b.useState(null),[$,te]=b.useState(null);b.useEffect(()=>{if(!q)return;let Te=!1;K(null),te(null);const Ke=Ft==null?void 0:Ft.requestFileSystemRoots();return Ke||te("尚未连接开发机"),Ke==null||Ke.then(Xe=>{Te||(Xe.error!==void 0||Xe.errorCode!==void 0?te(Xe.error||"读取失败"):K(Xe.roots))},Xe=>{Te||te(Xe instanceof Error?Xe.message:"读取失败")}),()=>{Te=!0}},[q,x,D]),b.useEffect(()=>{if(!T||q)return;const Te=`${x}\0${f?"hidden":"default"}\0${T}`;if(_.has(T))return;const Ke=Ft;if(!Ke)return;let Xe=!1;P(it=>(it==null?void 0:it.path)===T?null:it);let Se=z.current.get(Te);if(!Se){Se=Ke.requestDirectoryList(T,{includeHidden:f}),z.current.set(Te,Se);const it=()=>{z.current.get(Te)===Se&&z.current.delete(Te)};Se.then(it,it)}return Se.then(it=>{if(!Xe){if(it.error!==void 0||it.errorCode!==void 0){P({path:T,message:it.error||"读取失败"});return}Gr.getState().setDirEntries(it.path,it.entries,it.includeHidden)}},it=>{Xe||P({path:T,message:it instanceof Error?it.message:"读取失败"})}),()=>{Xe=!0}},[T,f,_,D,q,x]);const re=q?$?{message:$}:null:(B==null?void 0:B.path)===T?B:null,ee=q?V===null&&!$:!_.has(T)&&!re,X=b.useMemo(()=>d==null?void 0:d.map(Te=>Te.startsWith(".")?Te.toLowerCase():`.${Te.toLowerCase()}`),[d]),ae=b.useMemo(()=>{if(q){if(!V)return[];const Ke=[...S?[{name:"主目录",path:S}]:[],...V];return[...new Map(Ke.map(Xe=>[Xe.path,Xe])).values()].map(Xe=>({...Xe,isDir:!0}))}let Te=_.get(T)??[];return u?Te=Te.filter(Ke=>Ke.isDir):X!=null&&X.length&&(Te=Te.filter(Ke=>Ke.isDir||X.some(Xe=>Ke.name.toLowerCase().endsWith(Xe)))),M&&(Te=Te.filter(Ke=>Ke.name.toLowerCase().includes(M))),Te},[_,T,M,u,X,q,V,S]),[ne,ce]=b.useState(h?0:-1);b.useEffect(()=>ce(h?0:-1),[h,O,M,q]),b.useEffect(()=>{U(!1),I("")},[T]),b.useEffect(()=>{ne>=ae.length&&ae.length>0&&ce(ae.length-1)},[ae.length,ne]);const _e=b.useRef(null),xe=b.useRef(!1);b.useEffect(()=>{var Ke;if(!xe.current)return;xe.current=!1;const Te=(Ke=_e.current)==null?void 0:Ke.querySelector(`[data-entry-index="${ne}"]`);Te==null||Te.scrollIntoView({block:"nearest"})},[ne]);const We=b.useCallback(Te=>{const Ke=au(k),Xe=`${Us(O,k)}${Te.name}${Te.isDir?Ke:""}`;if(o==="insert")return Xe.replace(Ke==="\\"?/^\.[\\/]/:/^\.\//,"");const Se=b0(k,Xe);return Te.isDir?Us(Se):Se},[k,O,o]),De=b.useCallback(Te=>{const Ke=b0(k,Te);if(!Ke)return;j(!1);const Xe=Us(Ke);if(o==="select"){r(Xe);return}n(Xe)},[k,o,r,n]),Pt=b.useCallback(Te=>{if(Te.path){De(Te.path);return}const Ke=We(Te);if(Te.isDir){De(Ke);return}n(Ke)},[We,De,n]);async function tt(){const Te=a2(T,G);if(!(!Te||!s)){L(!0);try{const Ke=await s(Te);if(!Ke)return;if(I(""),U(!1),i){i(Us(Ke));return}De(Ke)}finally{L(!1)}}}b.useImperativeHandle(g,()=>({handleKey(Te){return ae.length===0?!1:Te.key==="ArrowDown"?(xe.current=!0,ce(Ke=>Math.min(ae.length-1,Ke+1)),!0):Te.key==="ArrowUp"?(xe.current=!0,ce(Ke=>Math.max(0,Ke-1)),!0):Te.key==="Enter"&&ne>=0&&!Te.nativeEvent.isComposing?(Pt(ae[ne]),!0):!1}}),[ae,ne,Pt]);const lt=b.useMemo(()=>qC(T),[T]),$e=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",Fe=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:$e,"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:[y?m.jsx("p",{className:"mb-2 truncate text-xs text-muted-foreground","data-slot":"file-path-picker-title",children:y}):null,m.jsx("p",{className:"truncate font-mono text-xs text-foreground","data-slot":"file-path-picker-current-directory",title:q?void 0:T,children:q?"磁盘/挂载点":$p(T,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":q,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(Te=>!Te),U(!1)},children:q?"返回目录":"磁盘/挂载点"}),q?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:!T,onClick:()=>{T===lt?j(!0):De(lt)},children:"上一级"})]}),!q&&(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:!T||N,onClick:()=>U(Te=>!Te),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:!T,onClick:()=>i(Us(T)),children:"选定"}):null]}):null]}),Y&&!q?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:Te=>I(Te.target.value),onKeyDown:Te=>{Te.key==="Enter"&&!Te.nativeEvent.isComposing&&(Te.preventDefault(),tt()),Te.key==="Escape"&&(U(!1),I(""))},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:!a2(T,G)||N,onClick:()=>void tt(),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":q,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(Te=>!Te),children:q?"返回目录":"磁盘/挂载点"}),m.jsx("span",{className:"truncate font-mono text-xs text-muted-foreground",children:q?"磁盘/挂载点":$p(T,S)})]}),m.jsx("div",{className:Fe,"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:q?"无法读取磁盘位置":"无法读取这个文件夹"}),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(Te=>Te+1),children:"重试"})]}):ae.length===0?m.jsx("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:ee?"加载中...":"没有匹配的路径"}):m.jsx("ul",{ref:_e,role:"list",className:"flex flex-col",children:ae.map((Te,Ke)=>m.jsx("li",{children:m.jsxs("button",{type:"button",onClick:()=>Pt(Te),onMouseEnter:()=>ce(Ke),className:Ye("w-full flex min-h-11 items-center gap-2 px-3 py-2 text-sm text-left transition-colors md:h-9 md:min-h-0 md:py-0",Ke===ne&&"bg-[color-mix(in_srgb,var(--primary)_15%,transparent)]",Te.isDir&&"font-semibold"),"data-slot":"file-entry","data-entry-type":Te.isDir?"dir":"file","data-entry-name":Te.name,"data-entry-index":Ke,title:Te.path,children:[m.jsxs("span",{className:"min-w-0 truncate font-mono text-[13px]",children:[Te.name,Te.isDir&&!Te.path?"/":""]}),Te.path&&Te.path!==Te.name?m.jsx("span",{className:"ml-auto min-w-0 truncate text-xs font-normal text-muted-foreground",children:Te.path}):null]})},Te.path??Te.name))})})]})});function fI(e,t,n){const r=lp(e,t);return r?n==="file"?Us(qC(r)):n==="directory"?Us(r):r:t}function lp(e,t){const n=oa(e,t);return n?e.endsWith("/")||au(n)==="\\"&&e.endsWith("\\")?Us(n):n:""}function Nk({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:y,autoFocus:g,"aria-describedby":_,"aria-invalid":w,"data-slot":S,className:x,onKeyDown:k}){const R=b.useId(),A=f??`remote-path-${R}`,O=`${A}-label`,T=Gr(ee=>ee.homePath),M=yo("(pointer: coarse), (hover: none)"),z=pf().deviceKind,Y=M||z==="phone"||z==="tablet",[U,G]=b.useState(!1),[I,N]=b.useState(()=>fI(e,T,n)),[L,B]=b.useState(e),P=b.useRef(null),D=b.useRef(null),F=b.useRef(null);b.useEffect(()=>{U||document.activeElement===D.current||L===e||B(e)},[L,U,e]),b.useEffect(()=>{if(!U)return;function ee(X){const ae=P.current,ne=X.target;ae&&(X.composedPath().includes(ae)||ne instanceof Node&&ae.contains(ne))||(G(!1),B(e))}return document.addEventListener("click",ee),()=>document.removeEventListener("click",ee)},[U,e]),b.useEffect(()=>{o&&(G(!1),B(e))},[o,e]);const q=n!=="file";function j(){if(o)return;const ee=fI(e,T,n);N(ee),B(e),G(!0)}function V(){G(!1),B(e)}function K(ee){const X=lp(ee,T);X&&(N(X),B(X),t(X),G(!1))}function $(ee){const X=lp(ee,T);X&&N(X)}function te(ee){var X;if(U&&((X=F.current)!=null&&X.handleKey(ee))){ee.preventDefault();return}if(ee.key==="Escape"&&U){ee.preventDefault(),V();return}k==null||k(ee)}const re=U?m.jsx("div",{className:Ye(Y&&"mt-2"),"data-slot":"remote-path-browser",children:m.jsx(dF,{ref:F,mode:"select",placement:Y?"inline":"floating",filter:I,dirsOnly:n==="directory",fileExtensions:r,includeHidden:i,autoHighlightFirst:!Y,title:l,onNavigate:$,onSelect:K,onSelectCurrentDirectory:q?K:void 0,onCreateDirectory:s})}):null;return m.jsxs("div",{className:Ye("flex min-w-0 flex-col gap-1",x),children:[m.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-3",children:[m.jsx("span",{id:O,className:"min-w-0 text-sm",children:u}),d?m.jsx("div",{className:"flex shrink-0 items-center gap-4",children:d}):null]}),m.jsxs("div",{ref:P,className:"relative min-w-0",onBlur:ee=>{if(!U||Y)return;const X=ee.relatedTarget;X instanceof Node&&ee.currentTarget.contains(X)||window.setTimeout(()=>{var ae;(ae=P.current)!=null&&ae.contains(document.activeElement)||V()},0)},children:[m.jsxs("div",{className:"relative flex min-w-0 items-center",children:[m.jsx("input",{ref:D,id:A,type:"text","aria-labelledby":O,"aria-describedby":_,"aria-invalid":w,name:h,required:y,autoFocus:g&&!Y,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off",spellCheck:!1,disabled:o,value:L,"data-slot":S,"data-path-control":"input",onFocus:()=>{Y?G(!1):j()},onBlur:()=>B(e),onKeyDown:te,onChange:ee=>{const X=ee.target.value,ae=lp(X,T);B(X),N(ae||T),t(ae||X),G(!Y)},onPaste:ee=>{const X=ee.clipboardData.getData("text").trim(),ae=X.startsWith('"')&&X.endsWith('"')?X.slice(1,-1):X,ne=lp(ae,T);ne&&(ee.preventDefault(),B(ne),N(ne),t(ne),G(!Y))},placeholder:l,className:"min-h-11 min-w-0 w-full rounded-md border border-border bg-input pl-3 pr-12 font-mono text-base outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60 md:h-9 md:min-h-0 md:text-sm"}),m.jsx("button",{type:"button","aria-label":typeof u=="string"?`浏览${u}`:"浏览路径","aria-expanded":U,"aria-controls":`${A}-browser`,disabled:o,"data-slot":"remote-path-browse",onClick:()=>{var ee;Y&&((ee=D.current)==null||ee.blur()),U?V():j()},className:"absolute inset-y-0 right-0 flex w-11 items-center justify-center rounded-r-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60",children:m.jsx(bY,{className:"size-5","aria-hidden":"true"})})]}),m.jsx("div",{id:`${A}-browser`,children:re})]})]})}const hI="工作目录不存在或不可访问:",lfe=[{value:"default",label:"严格审批"},{value:"auto",label:"自动判定"},{value:"acceptEdits",label:"自动接受编辑"},{value:"plan",label:"只读规划"},{value:"bypassPermissions",label:"跳过全部审批"}],fF=[{value:"auto",label:"按需审批"},{value:"bypassPermissions",label:"跳过全部审批"}],hF=[{value:"default",label:"手工审批"},{value:"auto",label:"自动审批"},{value:"plan",label:"只读规划"},{value:"bypassPermissions",label:"全自动"}],Kp={claude:"Claude Code",codex:"Codex",kimi:"Kimi Code"};function cfe(e,t){return t!==Pr.PATH_NOT_FOUND||!e.startsWith(hI)?null:e.slice(hI.length).trim()||null}function pF(e,t){if(!t)return{label:"检测中",disabled:!0};const n=t[e];return n.available?{label:"可用",disabled:!1,title:n.command}:{label:"未找到",disabled:!0,title:n.error}}function ufe(e,t){return e==="codex"?fF.some(n=>n.value===t)?t:"auto":e==="kimi"?hF.some(n=>n.value===t)?t:"default":t}async function dfe({relay:e,agentCli:t,form:n,timeoutMs:r=UC}){var d,f;const i=n.cwd.trim();if(!i)return{type:"validation_error",message:"请输入工作目录"};if(!e)return{type:"relay_missing",message:"请先连接开发机"};if(pF(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?`${Kp[n.provider]} 不可用:${h}`:`${Kp[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=cfe(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 y=((f=h.name)==null?void 0:f.trim())||void 0,g={sessionId:h.sessionId,kind:"agent",name:y,...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 ffe({relay:e,shell:t,timeoutMs:n=UC}){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 hfe=["claude","codex","kimi"];function pfe({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,y=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(Kb,{value:t,disabled:i,onValueChange:_=>s(_),children:[m.jsx(Xb,{className:"min-h-11 w-full md:min-h-0","aria-label":"Agent CLI","data-slot":"agent-cli-provider-select",children:m.jsx(Gb,{})}),m.jsx(Zb,{"data-slot":"agent-cli-provider-options",children:hfe.map(_=>m.jsx(Jb,{value:_,className:"min-h-11 md:min-h-0",children:Kp[_]},_))})]}),m.jsxs("div",{className:"relative min-w-0","data-slot":"agent-cli-path-card",children:[m.jsx(Nk,{id:`agent-cli-path-${t}`,"data-slot":"agent-cli-path",label:"CLI 路径",value:y,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 cp({open:e,onOpenChange:t}){var X;const[n,r]=b.useState(""),[i,s]=b.useState(""),[o,l]=b.useState("claude"),[u,d]=b.useState("pty"),[f,h]=b.useState("default"),[y,g]=b.useState(!1),[_,w]=b.useState(!1),[S,x]=b.useState(null),[k,R]=b.useState(null),[A,O]=b.useState(""),[T,M]=b.useState(!1),z=b.useRef(e);z.current=e;const Y=Cs(),U=Gr(ae=>ae.homePath),G=Gr(ae=>ae.agentCli),I=yo("(min-width: 768px)");b.useEffect(()=>{e&&!i&&U&&s(U)},[e,U,i]),b.useEffect(()=>{if(!e||U&&G)return;const ae=Ft==null?void 0:Ft.requestProxyInfo();ae&&ae.then(ne=>{const ce=Gr.getState();ce.setHomePath(ne.homePath),ce.setAgentCli(ne.agentCli)}).catch(ne=>{console.error("[create-session-dialog] requestProxyInfo failed",ne)})},[e,U,G]);function N(){r(""),s(""),l("claude"),d("pty"),h("default"),g(!1),x(null),R(null),O(""),M(!1)}function L(){if(f==="bypassPermissions"){g(!0);return}V()}async function B(){await V(),z.current&&g(!1)}const P=o==="codex"?fF:o==="kimi"?hF:lfe,D=pF(o,G),F=k===o&&A.trim()!==(((X=G==null?void 0:G[o])==null?void 0:X.command)??""),q=_||T||D.disabled||F;function j(ae){const ne=ufe(ae,f);ne!==f&&h(ne)}async function V(ae){x(null),w(!0);try{const ne=await dfe({relay:Ft,agentCli:G,form:{cwd:ae??i,name:n,provider:o,permissionMode:f,mode:u}});if(ne.type==="success"){if(Ht.getState().addSession(ne.session),!z.current)return;t(!1),N(),Y(ne.route);return}if(ne.type==="missing_cwd"&&x(ne.path),Ue.error(ne.message),ne.type==="validation_error"||ne.type==="relay_missing")return}finally{w(!1)}}async function K(ae){const ne=Ft;if(!ne)return Ue.error("请先连接开发机"),null;try{const ce=await ne.createDirectory(ae);return ce.success?(x(null),Ue.success("目录已创建"),ce.path):(Ue.error(`目录创建失败:${ce.error??"未知错误"}`),null)}catch(ce){return Ue.error(ce instanceof Error?ce.message:String(ce)),null}}function $(ae,ne){R(ae),O(ne)}async function te(){if(!k)return;const ae=k,ne=A.trim();if(!ne){Ue.error("请选择 Agent CLI 可执行文件");return}const ce=Ft;if(!ce){Ue.error("请先连接开发机");return}M(!0);try{const _e=await ce.updateAgentCliPath(ae,ne);if(_e.error||!_e.agentCli){Ue.error(`路径保存失败:${_e.error??"未知错误"}`);return}Gr.getState().setAgentCli(_e.agentCli),Ue.success(`${Kp[ae]} 路径已保存`),R(null),O("")}catch(_e){Ue.error(_e instanceof Error?_e.message:String(_e))}finally{M(!1)}}function re(ae){d(ae),j(o)}const ee=y?m.jsxs("div",{className:"grid min-w-0 gap-5","data-slot":"bypass-permission-confirmation",children:[m.jsx(lF,{providerLabel:Kp[o]}),m.jsxs(Vs,{children:[m.jsx(yt,{type:"button",variant:"ghost",className:"min-h-11 md:min-h-0",onClick:()=>g(!1),disabled:_,children:"返回"}),m.jsx(yt,{type:"button",variant:"destructive",className:"min-h-11 md:min-h-0",onClick:()=>void B(),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:ae=>{ae.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:ae=>r(ae.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(Nk,{id:"create-session-cwd",name:"dev-anywhere-session-cwd","data-slot":"create-session-cwd",label:"工作目录",value:i,selectionKind:"directory",placeholder:"选择工作目录",onCreateDirectory:K,onValueChange:ae=>{s(ae),x(null)}}),S?m.jsxs("section",{role:"status","aria-live":"polite",className:"rounded-md border border-primary/50 bg-primary/10 p-3",children:[m.jsx("p",{className:"text-sm font-medium",children:"工作目录不存在"}),m.jsx("p",{className:"mt-1 break-all font-mono text-xs text-muted-foreground",children:S})]}):null,m.jsxs("section",{"aria-label":"交互方式",className:"flex min-w-0 flex-col gap-2",children:[m.jsx("span",{className:"text-sm",children:"交互方式"}),m.jsxs("div",{className:"grid min-w-0 grid-cols-1 gap-2 sm:grid-cols-2",children:[m.jsxs("button",{type:"button","aria-pressed":u==="pty",onClick:()=>re("pty"),className:Ye("flex min-h-14 min-w-0 flex-col items-start justify-center gap-1 rounded-md border px-3 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring",u==="pty"?"border-primary/70 bg-primary/10":"border-border bg-muted/20"),children:[m.jsx("span",{className:"text-sm font-medium",children:"终端模式"}),m.jsx("span",{className:"text-xs text-muted-foreground",children:"像本地终端一样操作"})]}),m.jsxs("button",{type:"button","aria-pressed":u==="json",onClick:()=>re("json"),className:Ye("flex min-h-14 min-w-0 flex-col items-start justify-center gap-1 rounded-md border px-3 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring",u==="json"?"border-primary/70 bg-primary/10":"border-border bg-muted/20"),children:[m.jsx("span",{className:"text-sm font-medium",children:"聊天模式"}),m.jsx("span",{className:"text-xs text-muted-foreground",children:"气泡式对话,支持 Voice Pilot"})]})]})]}),m.jsx(pfe,{agentCli:G,provider:o,cliPathDraftProvider:k,cliPathDraft:A,savingCliPath:T,onProviderChange:ae=>{l(ae),j(ae),R(null),O("")},onCliPathDraftChange:$,onDiscardCliPathDraft:()=>{R(null),O("")},onSaveCliPath:()=>void te()}),m.jsxs("label",{className:"flex min-w-0 flex-col gap-2",children:[m.jsx("span",{className:"text-sm",children:"权限模式"}),m.jsxs(Kb,{value:f,onValueChange:ae=>h(ae),children:[m.jsx(Xb,{className:"w-full",children:m.jsx(Gb,{})}),m.jsx(Zb,{children:P.map(ae=>m.jsx(Jb,{value:ae.value,children:ae.label},ae.value))})]})]}),m.jsxs(Vs,{children:[m.jsx(yt,{type:"button",variant:"ghost",className:"min-h-11 md:min-h-0",onClick:()=>t(!1),disabled:_,children:"取消"}),m.jsx(yt,{type:"submit",className:"min-h-11 md:min-h-0",disabled:q,children:_?"创建中...":"创建"})]})]});return I?m.jsx(es,{open:e,onOpenChange:t,children:m.jsxs(ts,{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(ns,{children:m.jsx($i,{children:y?"跳过全部审批?":"新建会话"})}),ee]})}):m.jsx(pc,{open:e,onOpenChange:t,children:m.jsxs(mc,{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(Eu,{className:"px-0 pb-1 pt-0 text-left",children:m.jsx(gc,{children:y?"跳过全部审批?":"新建会话"})}),ee]})})}function up({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 y(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(es,{open:e,onOpenChange:r,children:m.jsx(ts,{className:"sm:max-w-md","data-slot":"session-rename-dialog",children:m.jsxs("form",{className:"grid gap-4",onSubmit:g=>void y(g),children:[m.jsxs(ns,{children:[m.jsx($i,{children:"重命名会话"}),m.jsx(Es,{children:"自定义名称会显示在会话列表和顶部标题中。"})]}),m.jsxs("div",{className:"grid gap-2",children:[m.jsx("label",{htmlFor:"session-rename-title",className:"text-sm font-medium",children:"会话标题"}),m.jsx("input",{id:"session-rename-title",value:o,autoFocus:!0,maxLength:100,"aria-invalid":!!u,"aria-describedby":u?"session-rename-error":void 0,className:Ye("h-10 rounded-md border border-input bg-background px-3 text-sm shadow-xs outline-none transition-[border-color,box-shadow]","placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/75","disabled:cursor-not-allowed disabled:opacity-50",u&&"border-destructive focus-visible:ring-destructive/20"),disabled:f,onChange:g=>{l(g.target.value),u&&d(null)}}),u?m.jsx("p",{id:"session-rename-error",className:"text-sm text-destructive",children:u}):null]}),m.jsxs(Vs,{children:[m.jsx(yt,{type:"button",variant:"outline",onClick:()=>r(!1),children:"取消"}),m.jsx(yt,{type:"submit",disabled:f,children:"保存"})]})]})})})}function mfe(e){return(e==null?void 0:e.kind)==="agent"&&e.mode==="pty"&&e.ptyOwner==="local-terminal"}function gfe(e){return(e==null?void 0:e.kind)==="terminal"}function vfe(e){return mfe(e)?{title:"断开远程连接?",description:"这只会断开当前页面和本地终端的连接,本地终端里的 Claude Code/Codex/Kimi Code 会继续运行。重新接入前,页面不能继续查看或输入这个会话。",confirmLabel:"断开远程连接",destructive:!1}:gfe(e)?{title:"终止终端?",description:"这会停止当前终端进程,并清理这个终端会话的运行状态。终止后不能继续输入,也无法恢复正在执行的命令。",confirmLabel:"终止终端",destructive:!0}:{title:"终止会话?",description:"这会停止当前 Agent 进程,并清理这个会话的运行状态。终止后不能继续输入,也无法恢复正在执行的任务。",confirmLabel:"终止会话",destructive:!0}}function _v({open:e,session:t,onOpenChange:n,onConfirm:r}){const i=vfe(t);function s(){t&&(r(t),n(!1))}return m.jsx(es,{open:e,onOpenChange:n,children:m.jsxs(ts,{"data-slot":"session-termination-dialog",children:[m.jsxs(ns,{children:[m.jsx($i,{children:i.title}),m.jsx(Es,{children:i.description})]}),m.jsxs(Vs,{children:[m.jsx(yt,{type:"button",variant:"ghost",onClick:()=>n(!1),children:"取消"}),m.jsx(yt,{type:"button",variant:i.destructive?"destructive":"default",onClick:s,"data-slot":"session-termination-confirm",children:i.confirmLabel})]})]})})}function mF(e){var t,n,r,i,s,o,l,u,d,f,h,y;return e.connected===!1||e.proxyOnline===!1?"disconnected":e.routeSessionEnded||((t=e.session)==null?void 0:t.state)==="terminated"?"terminated":((n=e.session)==null?void 0:n.state)==="error"?"error":e.hasPendingApproval||((r=e.session)==null?void 0:r.state)==="waiting_approval"?"waiting_approval":((i=e.session)==null?void 0:i.state)==="compacting"?"compacting":((s=e.session)==null?void 0:s.state)==="working"?"working":((o=e.session)==null?void 0:o.state)==="idle"?"idle":((l=e.agentStatus)==null?void 0:l.phase)==="waiting_permission"||((u=e.ptyState)==null?void 0:u.state)==="approval_wait"?"waiting_approval":((d=e.agentStatus)==null?void 0:d.phase)==="thinking"||((f=e.agentStatus)==null?void 0:f.phase)==="tool_use"||((h=e.agentStatus)==null?void 0:h.phase)==="outputting"||((y=e.ptyState)==null?void 0:y.state)==="working"?"working":"idle"}function yfe(e){if(e.session.state==="error")return"error";const t=mF(e);return t==="disconnected"?e.session.state:t}const bfe=new Set(["localhost","127.0.0.1","[::1]"]),N1={cloudflare:{label:"Cloudflare Tunnel",executable:"cloudflared",installUrl:"https://developers.cloudflare.com/tunnel/downloads/"},cpolar:{label:"Cpolar",executable:"cpolar"}};function _fe(){return Ni("local",Sn.webPreviewTunnelProvider)==="cpolar"?"cpolar":"cloudflare"}function gF(e,t){if(e)return t==="cloudflare"?e.cloudflared:e.cpolar}function _0(e,t){var n;return((n=gF(e,t))==null?void 0:n.available)===!0}function wfe(e){const t=e.trim();if(!t)return"请输入本机网站地址";let n;try{n=new URL(t)}catch{return"请输入完整的 http:// 本机网站地址"}return n.protocol!=="http:"||!bfe.has(n.hostname)||n.username!==""||n.password!==""?"只支持 localhost、127.0.0.1 或 [::1] 的 http:// 地址":null}function Mh(){return{status:"idle"}}function xfe({open:e,onOpenChange:t}){const[n,r]=b.useState(""),[i,s]=b.useState(_fe),[o,l]=b.useState("local"),[u,d]=b.useState(""),[f,h]=b.useState(""),[y,g]=b.useState(""),[_,w]=b.useState(Mh),[S,x]=b.useState(!1),k=b.useRef(null),R=b.useRef(null),A=b.useRef(null),O=b.useRef(null),T=b.useRef(i);T.current=i;const M=b.useRef(e);M.current=e;const z=yo("(min-width: 768px)"),Y=Ae(ee=>ee.selectedProxyId),U=Vr(ee=>ee.capability),G=Vr(ee=>ee.capabilityStatus),I=Vr(ee=>ee.capabilityError),N=Vr(ee=>{var X;return((X=ee.authoritative)==null?void 0:X.scope)??null}),L=N?`${N.proxyId}\0${N.bindingId}`:null,B=b.useCallback(ee=>{T.current=ee,s(ee),Mr("local",Sn.webPreviewTunnelProvider,ee)},[]);function P(){var ee,X;r(""),l("local"),d(""),h(""),g(""),w(Mh()),x(!1),(ee=k.current)==null||ee.abort(),k.current=null,(X=R.current)==null||X.abort(),R.current=null,A.current=null,O.current=null}const D=b.useCallback(async ee=>{var ne;(ne=k.current)==null||ne.abort();const X=new AbortController;k.current=X;const ae=Nt.getActiveScope();if(!(!ae||ae.proxyId!==Y))try{const ce=await Nt.requestWebPreviewCapability(ae,ee,{signal:X.signal});if(!ce||X.signal.aborted||!M.current||!ce.success)return;const _e=T.current,xe=_e==="cloudflare"?"cpolar":"cloudflare";!_0(ce.capability,_e)&&_0(ce.capability,xe)&&B(xe)}catch{}},[B,Y]);function F(ee){!ee&&S||t(ee)}b.useEffect(()=>{if(!e){P();return}return D(!1),()=>{var ee;(ee=k.current)==null||ee.abort(),k.current=null}},[D,e,L]),b.useEffect(()=>{var ne;if(!e||o!=="static")return;(ne=R.current)==null||ne.abort(),R.current=null;const ee=f.trim();if(!ee){w(Mh()),g("");return}const X=new AbortController;R.current=X,w({status:"loading"}),g("");const ae=window.setTimeout(()=>{const ce=Ft,_e=Nt.getActiveScope();if(!ce||!_e||_e.proxyId!==Y){w({status:"error",message:"请先连接开发机"});return}Nt.inspectStaticWebPreview(_e,ee,{signal:X.signal}).then(xe=>{if(!xe||X.signal.aborted||!M.current||!Nt.isActive(ce,_e))return;if(!xe.success){w({status:"error",message:xe.error});return}const We=xe.htmlEntries;if(We.length===0&&!xe.entryPath){w({status:"error",message:"这里没有可以预览的网页"});return}const De={entryPath:xe.entryPath,htmlEntries:We};w({status:"ready",path:ee,result:De}),g(xe.entryPath??"")}).catch(xe=>{X.signal.aborted||!M.current||xe instanceof Error&&xe.name==="AbortError"||!Nt.isActive(ce,_e)||w({status:"error",message:xe instanceof Error?xe.message:"检查网页失败"})})},300);return()=>{window.clearTimeout(ae),X.abort(),R.current===X&&(R.current=null)}},[e,L,Y,o,f]);const q=o==="local"?wfe(u):null,j=o==="static"&&_.status==="ready"&&_.path===f.trim()&&!!(_.result.entryPath||y),V=G==="loaded"&&_0(U,i),$=S||!V||!(o==="local"?q===null:j);async function te(){var ce,_e,xe;if($)return;const ee=Ft;if(!ee){Ue.error("请先连接开发机");return}let X;if(o==="local")X={kind:"local",url:u.trim()};else{if(_.status!=="ready"||_.path!==f.trim())return;const We=_.result.entryPath??y;if(!We)return;X={kind:"static",path:_.path,entryPath:We}}x(!0);const ae=Nt.getActiveScope();if(!ae){x(!1),Ue.error("请先连接开发机");return}let ne=null;try{const We=n.trim(),De=JSON.stringify({proxyId:ae.proxyId,tunnelProvider:i,source:X,name:We||void 0});((ce=A.current)==null?void 0:ce.sourceKey)!==De&&(A.current={sourceKey:De,operationId:mm(`preview-operation-${i}`)}),ne=A.current.operationId,O.current=ne;const Pt=await Nt.createWebPreview(ae,X,{tunnelProvider:i,operationId:ne,...We?{name:We}:{}});if(O.current!==ne)return;if(!Pt.accepted){((_e=A.current)==null?void 0:_e.operationId)===ne&&(A.current=null),Ue.error(Pt.error);return}if(((xe=A.current)==null?void 0:xe.operationId)===ne&&(A.current=null),!M.current||!Nt.isActive(ee,ae))return;t(!1)}catch(We){if(!ne||O.current!==ne||!M.current||!Nt.isActive(ee,ae))return;Ue.error(We instanceof Error?We.message:"无法创建网页预览")}finally{ne&&O.current===ne&&(O.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:ee=>{ee.preventDefault(),te()},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:ee=>{r(ee.target.value)},className:"min-h-11 min-w-0 rounded-md border border-border bg-input px-3 text-base outline-none focus-visible:ring-2 focus-visible:ring-ring 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(Kb,{value:i,disabled:S,onValueChange:ee=>B(ee),children:[m.jsx(Xb,{"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(Gb,{})}),m.jsx(Zb,{"data-slot":"web-preview-tunnel-provider-options",children:Object.keys(N1).map(ee=>m.jsx(Jb,{value:ee,"data-slot":"web-preview-tunnel-provider-option","data-provider":ee,children:N1[ee].label},ee))})]})]}),m.jsx(Sfe,{status:G,capability:U,provider:i,error:I,disabled:S,onRetry:()=>void D(!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 ee;(ee=R.current)==null||ee.abort(),R.current=null,w(Mh()),g(""),l("local")},className:Ye("flex min-h-16 min-w-0 flex-col items-start justify-center gap-1 rounded-md border px-3 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60",o==="local"?"border-primary/70 bg-primary/10":"border-border bg-muted/20"),children:[m.jsx("span",{className:"text-sm font-medium",children:"本机网站"}),m.jsx("span",{className:"text-xs text-muted-foreground",children:"输入 localhost 地址"})]}),m.jsxs("button",{type:"button","data-slot":"web-preview-source-static",disabled:S,"aria-pressed":o==="static",onClick:()=>{var ee;(ee=R.current)==null||ee.abort(),R.current=null,w(Mh()),g(""),l("static")},className:Ye("flex min-h-16 min-w-0 flex-col items-start justify-center gap-1 rounded-md border px-3 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60",o==="static"?"border-primary/70 bg-primary/10":"border-border bg-muted/20"),children:[m.jsx("span",{className:"text-sm font-medium",children:"网页文件"}),m.jsx("span",{className:"text-xs text-muted-foreground",children:"选择 HTML 网页文件或目录"})]})]})]}),o==="local"?m.jsxs("label",{className:"flex min-w-0 flex-col gap-1",children:[m.jsx("span",{className:"text-sm",children:"本机网站地址"}),m.jsx("input",{type:"url","data-slot":"web-preview-local-url","aria-label":"本机网站地址",inputMode:"url",name:"dev-anywhere-preview-local-url",autoComplete:"off",autoCorrect:"off",spellCheck:!1,disabled:S,value:u,onChange:ee=>{d(ee.target.value)},placeholder:"http://localhost:5173","aria-invalid":u.length>0&&q!==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&&q?m.jsx("span",{"data-slot":"web-preview-local-url-error",className:"text-xs text-destructive",role:"alert",children:q}):null]}):m.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[m.jsx(Nk,{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(Efe,{inspection:_,selectedEntryPath:y,disabled:S,onEntryPathChange:ee=>{g(ee)}})]}),m.jsxs(Vs,{children:[m.jsx(yt,{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(yt,{type:"submit",className:"min-h-11 md:min-h-0",disabled:$,"data-slot":"create-web-preview-submit",children:S?"正在创建...":"创建预览"})]})]});return z?m.jsx(es,{open:e,onOpenChange:F,children:m.jsxs(ts,{showCloseButton:!S,onEscapeKeyDown:ee=>{S&&ee.preventDefault()},onPointerDownOutside:ee=>{S&&ee.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(ns,{children:[m.jsx($i,{children:"新建网页预览"}),m.jsx(Es,{children:"输入本机网站地址,或选择 HTML 网页文件或目录。"})]}),re]})}):m.jsx(pc,{open:e,onOpenChange:F,children:m.jsxs(mc,{side:"bottom",showCloseButton:!S,onEscapeKeyDown:ee=>{S&&ee.preventDefault()},onPointerDownOutside:ee=>{S&&ee.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(Eu,{className:"px-0 pb-1 pt-0 text-left",children:[m.jsx(gc,{children:"新建网页预览"}),m.jsx(Vb,{children:"输入本机网站地址,或选择 HTML 网页文件或目录。"})]}),re]})})}function Sfe({status:e,capability:t,provider:n,error:r,disabled:i,onRetry:s}){const o=N1[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(di,{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(_z,{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(pI,{onClick:s,disabled:i})]})});const l=gF(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(YV,{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(pI,{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(jV,{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 pI({onClick:e,disabled:t}){return m.jsxs(yt,{type:"button",variant:"outline",size:"sm","data-slot":"web-preview-capability-retry",className:"shrink-0",onClick:e,disabled:t,children:[m.jsx(fm,{className:"size-3.5","aria-hidden":"true"}),"重新检测"]})}function Efe({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(di,{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(Kb,{value:t,onValueChange:r,disabled:n,children:[m.jsx(Xb,{"data-slot":"web-preview-entry-select",className:"w-full font-mono",children:m.jsx(Gb,{placeholder:"选择网页"})}),m.jsx(Zb,{children:e.result.htmlEntries.map(o=>m.jsx(Jb,{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 M1={ios:"iOS Simulator",android:"Android Emulator"};function Cfe({open:e,platform:t,onOpenChange:n}){const r=Cs(),i=yo("(min-width: 768px)"),s=Ae(F=>F.selectedProxyId),o=pr(F=>F.capability),l=pr(F=>F.targets),u=pr(F=>F.targetsStatus),d=pr(F=>F.targetsError),f=pr(l5),h=pr(F=>{var q;return((q=F.authoritative)==null?void 0:q.scope)??null}),y=h?`${h.proxyId}\0${h.bindingId}`:null,[g,_]=b.useState(""),[w,S]=b.useState(null),[x,k]=b.useState(!1),R=b.useRef(null),A=b.useRef(e);A.current=e;const O=b.useRef(null),T=b.useRef(null),M=b.useMemo(()=>l.filter(F=>F.platform===t),[t,l]),z=b.useMemo(()=>new Set(f.map(F=>F.targetId)),[f]),Y=b.useMemo(()=>M.filter(F=>!z.has(F.targetId)),[z,M]),U=Y.find(F=>F.targetId===w),G=o==null?void 0:o[t],I=b.useCallback(async F=>{var K;(K=R.current)==null||K.abort();const q=new AbortController;R.current=q;const j=Ft,V=Nt.getActiveScope();if(!(!j||!V||V.proxyId!==s))try{const $=await Nt.requestDevicePreviewCapability(V,F,{signal:q.signal});if(!$||q.signal.aborted||!A.current||!$.success)return;await Nt.requestDevicePreviewTargets(V,!0,{signal:q.signal})}catch{}},[s]);b.useEffect(()=>{var F;if(!e){(F=R.current)==null||F.abort(),R.current=null,_(""),S(null),k(!1),O.current=null,T.current=null;return}return I(!1),()=>{var q;(q=R.current)==null||q.abort(),R.current=null}},[I,e,t,y]),b.useEffect(()=>{if(e){if(w&&!U){S(null);return}!w&&Y.length===1&&S(Y[0].targetId)}},[e,Y,U,w]);async function N(){var K,$,te;const F=U;if(!F||x||(G==null?void 0:G.available)!==!0)return;const q=Ft,j=Nt.getActiveScope();if(!q||!j||j.proxyId!==s){Ue.error("请先连接开发机");return}k(!0);let V=null;try{const re=g.trim(),ee=((K=O.current)==null?void 0:K.proxyId)===j.proxyId&&O.current.targetId===F.targetId&&O.current.name===re?O.current:{proxyId:j.proxyId,targetId:F.targetId,name:re,operationId:mm("device-preview-operation")};O.current=ee,V=ee.operationId,T.current=V;const X=await Nt.createDevicePreview(j,F.targetId,{operationId:ee.operationId,...re?{name:re}:{}});if(T.current!==ee.operationId)return;if(!X.accepted){if((($=O.current)==null?void 0:$.operationId)===ee.operationId&&(O.current=null),!A.current||!Nt.isActive(q,j))return;Ue.error(X.error);return}if(((te=O.current)==null?void 0:te.operationId)===ee.operationId&&(O.current=null),!A.current||!Nt.isActive(q,j))return;n(!1),r(`/preview/device/${X.previewId}`)}catch(re){if(!V||T.current!==V||!A.current||!Nt.isActive(q,j))return;Ue.error(re instanceof Error?re.message:"无法创建模拟器预览")}finally{V&&T.current===V&&(T.current=null,A.current&&k(!1))}}function L(F){var q;!F&&x||(F||((q=R.current)==null||q.abort(),R.current=null,O.current=null,T.current=null,_(""),S(null)),n(F))}const B=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(kfe,{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(di,{className:"size-4 animate-spin","aria-hidden":"true"}),"正在查找已启动的模拟器..."]}):u==="error"?m.jsx(mI,{message:d??"无法读取模拟器列表"}):M.length===0?m.jsx(mI,{message:`没有已启动的 ${M1[t]}`}):M.map(F=>{const q=F.targetId===w,j=z.has(F.targetId);return m.jsx(Tfe,{target:F,selected:q,disabled:j||x,alreadyOpen:j,onClick:()=>{S(F.targetId)}},F.targetId)})}),m.jsxs(Vs,{className:"gap-2 sm:gap-2",children:[m.jsxs(yt,{type:"button",variant:"outline",disabled:x||u==="loading",onClick:()=>void I(!0),"data-slot":"device-preview-refresh",children:[m.jsx(fm,{className:"size-4","aria-hidden":"true"}),"重新检测"]}),m.jsx(yt,{type:"button",disabled:!U||x||(G==null?void 0:G.available)!==!0,onClick:()=>void N(),"data-slot":"create-device-preview-submit",children:x?"正在创建...":"创建预览"})]})]}),P=`新建 ${M1[t]} 预览`,D="选择开发机上已经启动的模拟器。";return i?m.jsx(es,{open:e,onOpenChange:L,children:m.jsxs(ts,{showCloseButton:!x,className:"sm:max-w-xl","data-slot":"create-device-preview-dialog","data-platform":t,focusSurfaceOnOpen:!0,children:[m.jsxs(ns,{children:[m.jsx($i,{children:P}),m.jsx(Es,{children:D})]}),B]})}):m.jsx(pc,{open:e,onOpenChange:L,children:m.jsxs(mc,{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(Eu,{className:"px-0 pb-1 pt-0 text-left",children:[m.jsx(gc,{children:P}),m.jsx(Vb,{children:D})]}),B]})})}function kfe({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"?`${M1[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(_z,{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 mI({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 Tfe({target:e,selected:t,disabled:n,alreadyOpen:r,onClick:i}){const s=e.platform==="ios"?"iOS":"Android",o=`${e.model} · ${s} ${e.osVersion}`;return m.jsxs("button",{type:"button",className:Ye("flex min-h-16 w-full min-w-0 max-w-full items-center gap-3 overflow-hidden rounded-lg border px-3 py-2 text-left outline-none transition-colors",t?"border-primary bg-primary/5":"border-border hover:bg-accent",n&&"cursor-not-allowed opacity-55"),disabled:n,"aria-pressed":t,onClick:i,"data-slot":"device-preview-target","data-target-id":e.targetId,"data-already-open":r?"true":"false","data-interactive":e.interactive?"true":"false",children:[m.jsx(Ty,{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 vF({open:e,onOpenChange:t}){const[n,r]=b.useState(()=>e?"chooser":"closed"),i=b.useRef(null),s=yo("(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(w0,{icon:m.jsx(Sz,{className:"size-5","aria-hidden":"true"}),title:"网页",description:"通过临时链接访问或分享本机网页",slot:"frontend-preview-web",onClick:()=>r("web")}),m.jsx(w0,{icon:m.jsx(Ty,{className:"size-5","aria-hidden":"true"}),title:"iOS Simulator",description:"查看和操控开发机上已启动的 iPhone 或 iPad 模拟器",slot:"frontend-preview-ios",onClick:()=>r("ios")}),m.jsx(w0,{icon:m.jsx(Ty,{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(es,{open:d,onOpenChange:f=>!f&&o(),children:m.jsxs(ts,{className:"sm:max-w-lg","data-slot":"create-frontend-preview-dialog",children:[m.jsxs(ns,{children:[m.jsx($i,{children:"新建预览"}),m.jsx(Es,{children:"选择预览类型。"})]}),l]})},"chooser"):m.jsx(pc,{open:d,onOpenChange:f=>!f&&o(),children:m.jsxs(mc,{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(Eu,{className:"px-0 pb-1 pt-0 text-left",children:[m.jsx(gc,{children:"新建预览"}),m.jsx(Vb,{children:"选择预览类型。"})]}),l]})},"chooser");case"web":return m.jsx(xfe,{open:d,onOpenChange:f=>!f&&o()},"web");case"ios":case"android":return m.jsx(Cfe,{open:d,platform:u,onOpenChange:f=>!f&&o()},u);case null:return null}}function w0({icon:e,title:t,description:n,slot:r,onClick:i}){return m.jsxs(yt,{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 Rfe({preview:e,closing:t,onOpenChange:n,onConfirm:r}){return m.jsx(es,{open:e!==null,onOpenChange:n,children:m.jsxs(ts,{"data-slot":"device-preview-close-dialog",children:[m.jsxs(ns,{children:[m.jsx($i,{children:"停止预览?"}),m.jsx(Es,{children:"模拟器会继续在开发机上运行。"})]}),m.jsxs(Vs,{children:[m.jsx(yt,{type:"button",variant:"ghost",disabled:t,onClick:()=>n(!1),children:"取消"}),m.jsx(yt,{type:"button",variant:"destructive",disabled:!e||t,onClick:()=>e&&r(e),"data-slot":"device-preview-close-confirm",children:t?"正在停止...":"停止预览"})]})]})})}const Afe={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 Nfe({preview:e,selected:t,pendingOperation:n,onRename:r,onReconnect:i,onClose:s}){const o=Afe[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:Ye("inline-block size-2 shrink-0 rounded-full",l.dot),role:"status","aria-label":`预览状态:${l.label}`}),m.jsx("span",{className:"flex-1 truncate text-sm font-normal",title:e.name,children:e.name})]}),m.jsxs("span",{className:"flex h-5 min-w-0 items-center gap-1.5 text-xs leading-5",children:[m.jsx(Ty,{className:"size-3.5 shrink-0 text-muted-foreground","aria-hidden":"true"}),m.jsxs("span",{className:"min-w-0 flex-1 truncate text-muted-foreground","data-slot":"device-preview-row-device","data-device-model":e.model,"data-os-version":e.osVersion,children:[e.model," · ",f," ",e.osVersion]}),m.jsx("span",{className:Ye("shrink-0",l.text),children:l.label})]})]});return m.jsxs("li",{className:Ye("relative flex min-h-[44px] w-full min-w-0 items-center gap-2 px-4 py-2 transition-colors hover:bg-accent",t&&"bg-accent"),"data-slot":"device-preview-row","data-preview-id":e.previewId,"data-preview-state":e.state,"data-preview-operation":n,children:[u?m.jsx(_C,{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(_f,{children:[m.jsx(wf,{asChild:!0,children:m.jsx(yt,{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(di,{className:"animate-spin","aria-hidden":"true"}):m.jsx(hb,{"aria-hidden":"true"})})}),m.jsxs(xf,{align:"end","data-slot":"device-preview-row-menu",children:[m.jsx(ti,{"data-slot":"device-preview-row-rename-item",onSelect:r,children:"重命名"}),d?m.jsx(ti,{"data-slot":"device-preview-row-reconnect-item",onSelect:i,children:"重新连接"}):null,m.jsx(Gc,{}),m.jsx(ti,{variant:"destructive","data-slot":"device-preview-row-close-item",onSelect:s,children:"停止预览"})]})]})]})}function Mfe({preview:e,closing:t,onOpenChange:n,onConfirm:r}){return m.jsx(es,{open:e!==null,onOpenChange:n,children:m.jsxs(ts,{"data-slot":"preview-close-dialog",children:[m.jsxs(ns,{children:[m.jsx($i,{children:"关闭预览?"}),m.jsx(Es,{children:"关闭后,当前预览链接将立即失效。"})]}),m.jsxs(Vs,{children:[m.jsx(yt,{type:"button",variant:"ghost",disabled:t,onClick:()=>n(!1),children:"取消"}),m.jsx(yt,{type:"button",variant:"destructive",disabled:!e||t,onClick:()=>e&&r(e),"data-slot":"preview-close-confirm",children:t?"正在关闭...":"关闭预览"})]})]})})}function Pfe({target:e,onOpenChange:t,onRename:n}){return m.jsx(Ife,{target:e,onOpenChange:t,onRename:n},(e==null?void 0:e.targetKey)??"closed")}function Ife({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(y){!y&&l||t(y)}async function h(y){y.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(es,{open:e!==null,onOpenChange:f,children:m.jsx(ts,{showCloseButton:!l,className:"sm:max-w-md","data-slot":"preview-rename-dialog",children:m.jsxs("form",{className:"grid gap-4",onSubmit:y=>void h(y),children:[m.jsx(ns,{children:m.jsx($i,{children:"重命名预览"})}),m.jsxs("div",{className:"grid gap-2",children:[m.jsx("label",{htmlFor:"preview-rename-name",className:"text-sm font-medium",children:"预览名称"}),m.jsx("input",{id:"preview-rename-name",value:r,autoFocus:!0,maxLength:256,autoComplete:"off",autoCorrect:"off",spellCheck:!1,"aria-invalid":!!s,"aria-describedby":s?"preview-rename-error":void 0,"data-slot":"preview-rename-input",className:Ye("h-10 rounded-md border border-input bg-background px-3 text-sm shadow-xs outline-none transition-[border-color,box-shadow]","placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/75","disabled:cursor-not-allowed disabled:opacity-50",s&&"border-destructive focus-visible:ring-destructive/20"),disabled:l,onChange:y=>{i(y.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(Vs,{children:[m.jsx(yt,{type:"button",variant:"outline",disabled:l,onClick:()=>f(!1),children:"取消"}),m.jsx(yt,{type:"submit",disabled:l,"data-slot":"preview-rename-submit",children:"保存"})]})]})})})}const Ofe={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 Lfe(e){return e.source.kind==="local"?e.source.url:bb(e.source.rootPath,e.source.entryPath)}async function Dfe(e){if(await Hp(e,{allowUserGestureFallback:!0})==="failed"){Ue.error("复制失败,请稍后重试");return}Ue.success("链接已复制")}async function Bfe(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;Ue.error("无法打开系统分享面板")}}function zfe({preview:e,pendingOperation:t,onRename:n,onReconnect:r,onClose:i}){const s=Gr(w=>w.homePath),o=Ofe[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",y=Lfe(e),g=e.source.kind==="static"?$p(y,s):y,_=m.jsxs(m.Fragment,{children:[m.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[m.jsx("span",{className:Ye("inline-block size-2 shrink-0 rounded-full",l.dot),role:"status","aria-label":`预览状态:${l.label}`}),m.jsx("span",{className:"flex-1 truncate text-sm font-normal",title:e.name,children:e.name})]}),m.jsxs("span",{className:"flex h-5 min-w-0 items-center gap-1.5 text-xs leading-5",children:[m.jsx(Sz,{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:y,children:g}),m.jsx("span",{className:"shrink-0 text-muted-foreground/60","aria-hidden":"true",children:"·"}),m.jsx("span",{className:Ye("shrink-0",l.text),children:l.label})]}),e.state==="failed"?m.jsx("span",{"data-slot":"preview-row-error",className:"truncate text-xs text-destructive/90",title:e.error,children:e.error}):null]});return m.jsxs("li",{className:"relative flex min-h-[44px] w-full min-w-0 items-center gap-2 px-4 py-2 transition-colors hover:bg-accent","data-slot":"preview-row","data-preview-id":e.previewId,"data-preview-state":e.state,"data-preview-operation":t,children:[d?m.jsx("a",{href:u,target:"_blank",rel:"noopener noreferrer","data-slot":"preview-row-open",className:"flex min-h-11 min-w-0 flex-1 flex-col justify-center gap-1 rounded-sm text-left outline-none focus-visible:ring-2 focus-visible:ring-ring md:min-h-0",children:_}):m.jsx("div",{"data-slot":"preview-row-inactive","aria-disabled":"true",className:"flex min-h-11 min-w-0 flex-1 flex-col justify-center gap-1 md:min-h-0",children:_}),m.jsxs(_f,{children:[m.jsx(wf,{asChild:!0,children:m.jsx(yt,{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(di,{className:"animate-spin","aria-hidden":"true"}):m.jsx(hb,{"aria-hidden":"true"})})}),m.jsxs(xf,{align:"end","data-slot":"preview-row-menu",children:[m.jsx(ti,{"data-slot":"preview-row-rename-item",onSelect:n,children:"重命名"}),d?m.jsx(ti,{"data-slot":"preview-row-copy-item",onSelect:()=>void Dfe(u),children:"复制链接"}):null,h?m.jsx(ti,{"data-slot":"preview-row-share-item",onSelect:()=>void Bfe(e.name,u),children:"分享…"}):null,f?m.jsx(ti,{"data-slot":"preview-row-reconnect-item",onSelect:r,children:"重新连接"}):null,m.jsx(Gc,{}),m.jsx(ti,{variant:"destructive","data-slot":"preview-row-close-item",onSelect:i,children:"关闭预览"})]})]})]})}const jfe=Object.freeze([]),Ffe=Object.freeze([]);function ud(e,t,n){return Object.freeze({kind:e,previewId:t,scope:Object.freeze({proxyId:n.proxyId,bindingId:n.bindingId})})}function jc(e,t){return e!==null&&e.kind===t.kind&&e.previewId===t.previewId&&Qt(e.scope,t.scope)}function dp(e,t,n){return t!==null&&n!==void 0&&Qt(e.scope,t)&&Qt(e.scope,n)}function Ph(e){const t=Nt.getActiveScope(),n=e.kind==="web"?Vr.getState().authoritative:pr.getState().authoritative;return!n||!dp(e,t,n.scope)?!1:n.previews.some(r=>r.previewId===e.previewId)}function Uo(e){const t=Nt.getActiveScope();return t!==null&&Qt(t,e)}function gI(){const e=Vr(N=>N.authoritative),t=pr(N=>N.authoritative),n=Zo(N=>N.registry),r=Nt.getActiveScope(),i=r&&e&&Qt(r,e.scope)?e.scope:null,s=r&&t&&Qt(r,t.scope)?t.scope:null,o=i&&e?e.previews:jfe,l=s&&t?t.previews:Ffe,u=az("/preview/device/:id"),d=Cs(),[f,h]=b.useState(null),[y,g]=b.useState(null),_=(y==null?void 0:y.kind)==="web"&&dp(y,r,e==null?void 0:e.scope)?o.find(N=>N.previewId===y.previewId)??null:null,w=(y==null?void 0:y.kind)==="device"&&dp(y,r,t==null?void 0:t.scope)?l.find(N=>N.previewId===y.previewId)??null:null,S=_??w,x=(f==null?void 0:f.kind)==="web"&&dp(f,r,e==null?void 0:e.scope)?o.find(N=>N.previewId===f.previewId)??null:null,k=(f==null?void 0:f.kind)==="device"&&dp(f,r,t==null?void 0:t.scope)?l.find(N=>N.previewId===f.previewId)??null:null;b.useEffect(()=>{y&&!S&&g(N=>jc(N,y)?null:N),f&&!x&&!k&&h(N=>jc(N,f)?null:N)},[f,k,y,S,x]);function R(N,L,B){var P;return(P=i5(n,N,L,B)[0])==null?void 0:P.kind}if(o.length===0&&l.length===0)return null;async function A(N){if(Ph(N))try{const L=await Nt.reconnectWebPreview(N.scope,N.previewId);if(!Uo(N.scope))return;L.success||Ue.error(L.error)}catch(L){if(!Uo(N.scope))return;Ue.error(L instanceof Error?L.message:"无法重新连接网页预览")}}async function O(N,L){if(!Ph(N))return;let B;try{B=N.kind==="web"?await Nt.renameWebPreview(N.scope,N.previewId,L):await Nt.renameDevicePreview(N.scope,N.previewId,L)}catch(P){if(!Uo(N.scope))return;throw P}if(Uo(N.scope)&&!B.success)throw new Error(B.error)}async function T(N){if(Ph(N))try{const L=await Nt.closeWebPreview(N.scope,N.previewId);if(!Uo(N.scope))return;if(!L.success){Ue.error(L.error);return}h(B=>jc(B,N)?null:B)}catch(L){if(!Uo(N.scope))return;Ue.error(L instanceof Error?L.message:"无法关闭网页预览")}}async function M(N){if(Ph(N))try{const L=await Nt.reconnectDevicePreview(N.scope,N.previewId);if(!Uo(N.scope))return;L.success||Ue.error(L.error)}catch(L){if(!Uo(N.scope))return;Ue.error(L instanceof Error?L.message:"无法重新连接模拟器预览")}}async function z(N){if(Ph(N))try{const L=await Nt.closeDevicePreview(N.scope,N.previewId);if(!Uo(N.scope))return;if(!L.success){Ue.error(L.error);return}h(B=>jc(B,N)?null:B),(u==null?void 0:u.params.id)===N.previewId&&d("/sessions")}catch(L){if(!Uo(N.scope))return;Ue.error(L instanceof Error?L.message:"无法停止模拟器预览")}}const Y=(f==null?void 0:f.kind)==="web"&&R(f.scope,"web",f.previewId)==="close",U=(f==null?void 0:f.kind)==="device"&&R(f.scope,"device",f.previewId)==="close",G=y,I=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(zfe,{preview:N,pendingOperation:i?R(i,"web",N.previewId):void 0,onRename:()=>i&&g(ud("web",N.previewId,i)),onReconnect:()=>i&&void A(ud("web",N.previewId,i)),onClose:()=>i&&h(ud("web",N.previewId,i))},N.previewId)),l.map(N=>m.jsx(Nfe,{preview:N,selected:(u==null?void 0:u.params.id)===N.previewId,pendingOperation:s?R(s,"device",N.previewId):void 0,onRename:()=>s&&g(ud("device",N.previewId,s)),onReconnect:()=>s&&void M(ud("device",N.previewId,s)),onClose:()=>s&&h(ud("device",N.previewId,s))},N.previewId))]}),m.jsx(Pfe,{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=>jc(L,G)?null:L)},onRename:N=>G?O(G,N):Promise.resolve()}),m.jsx(Mfe,{preview:x,closing:Y,onOpenChange:N=>{!N&&!Y&&I&&h(L=>jc(L,I)?null:L)},onConfirm:()=>I&&void T(I)}),m.jsx(Rfe,{preview:k,closing:U,onOpenChange:N=>{!N&&!U&&I&&h(L=>jc(L,I)?null:L)},onConfirm:()=>I&&void z(I)})]})}function yF({layout:e}){const t=Ht(ne=>ne.sessions),n=Ht(ne=>ne.sessionListLoaded),r=Ht(ne=>ne.agentStatusBySessionId),i=Ht(ne=>ne.ptyStateBySessionId),s=Ht(ne=>ne.renameSession),o=fn(ne=>ne.bySessionId),l=az("/chat/:id"),u=(l==null?void 0:l.params.id)??null,d=Ae(ne=>!!ne.selectedProxyId),f=Ae(ne=>ne.proxyListLoaded),h=Ae(ne=>ne.proxySwitchTarget),y=Ht(ne=>ne.loadingProxyName),g=h!==null||!f||d&&!n,_=(h==null?void 0:h.name)??y,w=_?`正在连接 ${_}...`:"连接中...",S=Cs(),[x,k]=b.useState(!1),[R,A]=b.useState(!1),[O,T]=b.useState(!1),[M,z]=b.useState(!1),[Y,U]=b.useState(null),[G,I]=b.useState(null),{creatingTerminal:N,creatingShell:L,createTerminal:B}=bF(),[P,D]=b.useState(new Set),[F,q]=b.useState(()=>Date.now());b.useEffect(()=>{const ne=setInterval(()=>q(Date.now()),6e4);return()=>clearInterval(ne)},[]);function j(ne,ce){S(`/chat/${ne}?mode=${ce}`,{replace:!1})}function V(ne){const ce=ne.sessionId,_e=Ft;if(!_e){Ue.error("请先连接开发机");return}_e.sendControl({type:"session_terminate",sessionId:ce}),Ht.getState().removeSession(ce),fn.getState().clearSession(ce),ce===u&&S("/sessions"),(ne==null?void 0:ne.kind)==="agent"&&ne.mode==="pty"&&ne.ptyOwner==="local-terminal"?Ue.info("已断开页面连接,本地终端仍在运行"):Ue.info("正在终止会话",{duration:1500})}async function K(ne,ce){const _e=Ft;if(!_e)throw new Error("请先连接开发机");const xe=await _e.renameSession(ne,ce);if(!xe.success)throw new Error(xe.error??"重命名失败");s(ne,xe.name??ce),Ue.success("已重命名会话")}function $(ne){D(ce=>{const _e=new Set(ce);return _e.has(ne)?_e.delete(ne):_e.add(ne),_e})}function te(ne){var xe;const ce=ne.mode==="json"&&(((xe=o[ne.sessionId])==null?void 0:xe.pendingApprovals.some(We=>We.status==="pending"))??!1),_e=yfe({session:ne,agentStatus:r[ne.sessionId],ptyState:i[ne.sessionId],hasPendingApproval:ce});return _e===ne.state?ne:{...ne,state:_e}}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(cp,{open:x,onOpenChange:k}),m.jsx(_v,{open:G!==null,session:G,onOpenChange:ne=>{ne||I(null)},onConfirm:V}),m.jsx(up,{open:Y!==null,sessionId:(Y==null?void 0:Y.sessionId)??null,initialName:Y==null?void 0:Y.name,onOpenChange:ne=>{ne||U(null)},onRename:K})]});if(e==="page"&&g)return m.jsxs("div",{className:"flex h-full w-full flex-col items-center justify-center gap-3 text-muted-foreground animate-in fade-in-0 duration-200 motion-reduce:animate-none","data-slot":"session-list-loading",role:"status","aria-live":"polite",children:[m.jsx(di,{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(Qc,{variant:"no-proxy"})}),m.jsx(cp,{open:x,onOpenChange:k}),m.jsx(_v,{open:G!==null,session:G,onOpenChange:ne=>{ne||I(null)},onConfirm:V}),m.jsx(up,{open:Y!==null,sessionId:(Y==null?void 0:Y.sessionId)??null,initialName:Y==null?void 0:Y.name,onOpenChange:ne=>{ne||U(null)},onRename:K})]});const ee=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]}),X=re?m.jsx("ul",{role:"list",className:"flex flex-col w-full min-w-0",children:$fe(t).map(ne=>m.jsxs("li",{children:[m.jsxs("button",{type:"button",onClick:()=>$(ne.provider),"aria-expanded":!P.has(ne.provider),className:Ye("flex w-full items-center gap-2 px-4 pt-2 pb-1 min-h-[32px]","text-xs text-muted-foreground","text-left outline-none transition-colors hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring"),children:[m.jsx("span",{className:"font-mono",children:Hfe(ne.provider)}),m.jsx("span",{className:"h-px flex-1 bg-border/70","aria-hidden":"true"}),m.jsx("span",{className:"tabular-nums",children:ne.sessions.length}),m.jsx(Hd,{className:Ye("size-3.5 shrink-0 text-muted-foreground/80 transition-transform",!P.has(ne.provider)&&"rotate-90"),"aria-hidden":"true"})]}),P.has(ne.provider)?null:m.jsx("ul",{role:"list",className:"flex flex-col",children:ne.sessions.map(ce=>m.jsx(Zde,{session:te(ce),selected:ce.sessionId===u,now:F,onClick:()=>j(ce.sessionId,ce.mode),onRename:()=>U(ce),onTerminate:()=>I(ce)},ce.sessionId))})]},ne.provider))}):m.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground/70","data-slot":"active-empty",children:"暂无活跃会话"}),ae=m.jsx(tfe,{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:[ee,X,m.jsx(gI,{}),ae]}),m.jsx("div",{className:"px-4 pt-4 pb-[calc(env(safe-area-inset-bottom)+1rem)] border-t border-border",children:m.jsxs(yt,{className:"min-h-11 w-full md:min-h-0","data-slot":"create-session-mobile-trigger",onClick:()=>A(!0),children:[m.jsx(wz,{"aria-hidden":"true"}),"新建"]})}),m.jsx(Yfe,{open:R,creatingTerminal:N,onOpenChange:A,onCreateAgent:()=>{A(!1),k(!0)},onCreateTerminal:()=>{_F()?(A(!1),T(!0)):B(void 0,()=>A(!1))},onCreatePreview:()=>{A(!1),z(!0)}}),m.jsx(wF,{layout:"mobile",open:O,creatingTerminal:N,creatingShell:L,onOpenChange:T,onBack:()=>{T(!1),A(!0)},onCreate:ne=>void B(ne,()=>T(!1))}),m.jsx(cp,{open:x,onOpenChange:k}),m.jsx(vF,{open:M,onOpenChange:z}),m.jsx(_v,{open:G!==null,session:G,onOpenChange:ne=>{ne||I(null)},onConfirm:V}),m.jsx(up,{open:Y!==null,sessionId:(Y==null?void 0:Y.sessionId)??null,initialName:Y==null?void 0:Y.name,onOpenChange:ne=>{ne||U(null)},onRename:K})]}):m.jsxs(m.Fragment,{children:[m.jsxs("div",{className:"dev-sidebar-scroll h-full overflow-y-auto overscroll-contain",children:[ee,X,m.jsx(gI,{}),ae]}),m.jsx(cp,{open:x,onOpenChange:k}),m.jsx(_v,{open:G!==null,session:G,onOpenChange:ne=>{ne||I(null)},onConfirm:V}),m.jsx(up,{open:Y!==null,sessionId:(Y==null?void 0:Y.sessionId)??null,initialName:Y==null?void 0:Y.name,onOpenChange:ne=>{ne||U(null)},onRename:K})]})}function $fe(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])=>Ufe(n,r)).map(([n,r])=>({provider:n,sessions:r}))}function Hfe(e){return e==="terminal"?"终端":Yb(e)}function Ufe(e,t){return e===t?0:e==="terminal"?-1:t==="terminal"?1:oF(e,t)}function bF(){const e=Cs(),[t,n]=b.useState(null),r=t!==null;async function i(s,o){var u;const l=Ae.getState();if(!(r||!l.connected||!l.proxyOnline||!l.selectedProxyId||l.proxySwitchTarget)&&!Mk(l)&&!(s&&!((u=l.terminalShells)!=null&&u.some(d=>d.id===s)))){n(s??"default");try{const d=await ffe({relay:Ft,shell:s});if(d.type!=="success"){Ue.error(d.message);return}Ht.getState().addSession(d.session),o==null||o(),e(d.route)}finally{n(null)}}}return{creatingTerminal:r,creatingShell:t,createTerminal:i}}function Mk(e){var t;return!e.terminalShellsLoaded&&((t=e.proxies.find(n=>n.proxyId===e.selectedProxyId))==null?void 0:t.osName)==="Windows"}function Wfe(e){const t=Ae(u=>u.terminalShells),n=Ae(Mk),r=Ae(u=>u.selectedProxyId),[i,s]=b.useState(!1),[o,l]=b.useState(0);return b.useEffect(()=>{if(!e||!n)return;let u=!1;const d=Ft,f=d==null?void 0:d.getPreviewScope();if(s(!1),!d||!f||f.proxyId!==r){s(!0);return}return d.requestProxyInfo().then(h=>{const y=Ae.getState(),g=d.getPreviewScope();u||!y.connected||!y.proxyOnline||y.selectedProxyId!==r||!g||!Qt(f,g)||y.setTerminalShells(h.terminalShells)},()=>{u||s(!0)}),()=>{u=!0}},[e,n,r,o]),{terminalShells:t,needsDetection:n,failed:i,retry:()=>l(u=>u+1)}}const qfe=[{label:"启动 Shell"}];function Vfe(e){return e!=null&&e.length?e:qfe}function _F(){var t;const e=Ae.getState();return Mk(e)||!!((t=e.terminalShells)!=null&&t.length)}function vI({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),y=Ae(Y=>!!Y.selectedProxyId),g=Ae(Y=>Y.proxySwitchTarget!==null),_=y&&!g,{creatingTerminal:w,creatingShell:S,createTerminal:x}=bF();function k(){f(!0),window.setTimeout(()=>f(!1),2e3)}function R(){if(!_){k();return}h.current=!0,o(!0)}function A(){if(!_){k();return}h.current=!0,_F()?i(!0):x()}function O(){if(!_){k();return}h.current=!0,u(!0)}function T(Y){Y.preventDefault(),k()}const M=m.jsxs(yt,{variant:"outline","data-slot":"create-session-trigger",className:Ye(e?"h-11 w-11 justify-center border-border px-0":"h-[46px] w-full justify-center gap-2 border-border px-3",!_&&"opacity-50 hover:bg-background"),"aria-label":"新建","aria-disabled":!_,onClick:_?void 0:T,children:[m.jsx(wz,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),!e&&m.jsx("span",{className:"truncate",children:"新建"})]}),z=_?m.jsxs(_f,{open:t,onOpenChange:n,children:[m.jsx(wf,{asChild:!0,children:M}),m.jsxs(xf,{align:e?"end":"start",className:"w-80","data-slot":"create-session-type-menu",onCloseAutoFocus:Y=>{h.current&&(h.current=!1,Y.preventDefault())},children:[m.jsxs(ti,{className:"min-h-9 gap-2.5","data-slot":"create-agent-session-item",onSelect:R,children:[m.jsx(bz,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),"Agent 会话"]}),m.jsxs(ti,{className:"min-h-9 gap-2.5","data-slot":"create-terminal-session-item",disabled:w,onSelect:A,children:[m.jsx(ru,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),w?"正在创建 Shell 会话...":"Shell 会话"]}),m.jsx(Gc,{}),m.jsxs(ti,{className:"min-h-[3.75rem] items-start gap-2.5 py-2","data-slot":"create-frontend-preview-item",onSelect:O,children:[m.jsx(CC,{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(Sf,{open:_?void 0:d,onOpenChange:_?void 0:f,children:[m.jsx(Ef,{asChild:!0,children:z}),m.jsx(Cf,{side:"top",children:g?"正在切换开发机":"请先连接开发机"})]}),m.jsx(wF,{layout:"desktop",open:r,creatingTerminal:w,creatingShell:S,onOpenChange:i,onBack:()=>{i(!1),n(!0)},onCreate:Y=>void x(Y,()=>i(!1))}),m.jsx(cp,{open:s,onOpenChange:o}),m.jsx(vF,{open:l,onOpenChange:u})]})}function Yfe({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(pc,{open:e,onOpenChange:n,children:m.jsxs(mc,{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(Eu,{className:"px-1 pb-1 pt-0 text-left",children:m.jsx(gc,{children:"新建"})}),m.jsxs("div",{className:"grid gap-2 pb-1","data-slot":"create-session-type-options",children:[m.jsxs(yt,{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(bz,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),"Agent 会话"]}),m.jsxs(yt,{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(ru,{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(yt,{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(CC,{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 wF({layout:e,open:t,creatingTerminal:n,creatingShell:r,onOpenChange:i,onBack:s,onCreate:o}){const{terminalShells:l,needsDetection:u,failed:d,retry:f}=Wfe(t),h=b.useRef(!1),y=Ae(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(yt,{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(ru,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),d?"终端检测失败,点击重试":"正在检测终端..."]}):Vfe(l).map(w=>m.jsxs(yt,{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||!y,onClick:()=>o(w.id),children:[m.jsx(ru,{className:"size-4 text-muted-foreground","aria-hidden":"true"}),r===(w.id??"default")?"正在创建 Shell 会话...":w.label]},w.id??"default")),m.jsx("div",{className:"mx-1 h-px bg-border","aria-hidden":"true"}),m.jsxs(yt,{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(ff,{className:"size-4","aria-hidden":"true"}),"返回"]})]});function _(w){h.current&&(h.current=!1,w.preventDefault())}return e==="mobile"?m.jsx(pc,{open:t,onOpenChange:i,children:m.jsxs(mc,{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(Eu,{className:"px-1 pb-1 pt-0 text-left",children:m.jsx(gc,{children:"Shell 会话"})}),g]})}):m.jsx(es,{open:t,onOpenChange:i,children:m.jsxs(ts,{className:"sm:max-w-sm","data-slot":"create-terminal-shell-dialog",focusSurfaceOnOpen:!0,onCloseAutoFocus:_,children:[m.jsx(ns,{children:m.jsx($i,{children:"Shell 会话"})}),g]})})}const Kfe="0.9.17",Gfe={version:Kfe},Xfe={playback:"playback",capture:"play-and-record"};function Zfe(){return typeof navigator>"u"?null:navigator.audioSession??null}function Jfe(){return{setMode:()=>{},release:()=>{}}}class Qfe{constructor(t=Zfe){je(this,"leases",new Map);je(this,"session",null);je(this,"baselineType",null);je(this,"nextLeaseId",1);je(this,"nextOrder",1);this.getAudioSession=t}acquire(t){const n=this.getAudioSession();if(!n)return Jfe();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(Xfe[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 Pk=new Qfe,P1=64,yI=-60,xF=32;function bI(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-yI)/-yI));return e<0?-r:r}function _I(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 y=i.getInt16(h*2,!0)/32768;d=Math.min(d,y),f=Math.max(f,y)}s.push({min:d,max:f})}return s}function ehe(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 the(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 SF{constructor(t,n=24e3,r={}){je(this,"nextStartTime",0);je(this,"activityEndToken",0);je(this,"timelineTimers",new Set);this.context=t,this.sampleRate=n,this.options=r}async resume(){this.emitPlaybackEvent("resume-start");try{if(this.context.state!=="running"&&this.context.state!=="closed"&&await this.context.resume(),this.context.state!=="running")throw new Error("浏览器未允许播放 Voice Pilot 提示音");this.emitPlaybackEvent("resume-finished")}catch(t){throw this.emitPlaybackEvent("resume-failed",{error:t instanceof Error?t.message:String(t)}),t}}enqueue(t){this.context.state==="suspended"&&this.resume().catch(()=>{});const n=ehe(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*xF/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),y=the(n.subarray(l,u));this.scheduleTimer(()=>{var g,_,w,S;(_=(g=this.options).onActivityLevel)==null||_.call(g,y),(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 x0={provider:"aliyun-bailian",configured:!1,region:"cn",asrModel:"qwen3-asr-flash-realtime",ttsModel:"cosyvoice-v3-flash",ttsVoice:"longanyang",turnIdleSeconds:3},wI="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",nhe=800,xI=300,rhe=1600;function I1(e,t){return e.filter(n=>!n.model||n.model===t)}function SI({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 wv({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),y=!!EF(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 ${y?"min-h-[60px] py-2":"min-h-11"}`,onClick:()=>l(g=>!g),"data-slot":"voice-settings-choice-trigger",children:[m.jsx(EI,{label:f,muted:!d&&!t}),m.jsx(sc,{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(EI,{label:g.label})]},g.value)})}):null,s?m.jsx("div",{className:"mt-2 text-xs leading-relaxed text-muted-foreground",children:s}):null]})}function EI({label:e,muted:t=!1}){const n=EF(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 ihe({scrollRef:e}={}){const[t,n]=b.useState(x0),[r,i]=b.useState(String(x0.turnIdleSeconds)),[s,o]=b.useState(()=>ov()),[l,u]=b.useState(""),[d,f]=b.useState(!1),[h,y]=b.useState(!1),[g,_]=b.useState({kind:"idle"}),w=b.useRef(null),S=b.useRef(null),x=b.useRef(null),k=b.useRef(null),R=b.useRef(null),A=b.useRef(!1);b.useEffect(()=>{const X=Ft;if(!X){_({kind:"error",message:"请先连接 Relay 服务器"});return}let ae=!1;return _({kind:"loading"}),X.requestVoiceConfig().then(ne=>{if(!ae){if(ne.error||!ne.config){_({kind:"error",message:ne.error??"读取语音设置失败"});return}n(ne.config),i(String(ne.config.turnIdleSeconds)),u(""),f(!1),y(!0),_({kind:"idle"})}}).catch(ne=>{ae||_({kind:"error",message:ne instanceof Error?ne.message:"读取语音设置失败"})}),()=>{ae=!0}},[]),b.useEffect(()=>{const X=Ft;if(!X||!h)return;let ae=!1;return X.requestVoiceCapabilities({region:t.region}).then(ne=>{if(!ae){if(ne.error||!ne.capabilities){o(ov());return}o(ne.capabilities)}}).catch(()=>{ae||o(ov())}),()=>{ae=!0}},[t.region,h]),b.useEffect(()=>(A.current=!0,()=>{A.current=!1,$(),te()}),[]);const O=b.useMemo(()=>g.kind==="loading"?"读取中...":g.kind==="saving"?"保存中...":g.kind==="testing"?"正在测试语音合成":g.kind==="playingTest"?"正在播放测试音频":g.kind==="testPassed"?"测试通过":g.kind==="saved"?"已保存":g.kind==="error"?g.message:null,[g]),T=g.kind==="saving"||g.kind==="loading"||g.kind==="testing"||g.kind==="playingTest",M=b.useMemo(()=>I1(s.ttsVoices,t.ttsModel),[s.ttsVoices,t.ttsModel]),Y=M.some(X=>X.value===t.ttsVoice)?t.ttsVoice:"",U=M.length===0?"当前模型暂无可用音色":Y?null:"请选择可用音色",G=b.useMemo(()=>lhe(r),[r]),I=G?null:"请输入正整数秒数",N=U??I,L=T||!!N,B=b.useMemo(()=>[{value:"cn",label:"中国大陆"},{value:"intl",label:"国际"}],[]),P=b.useMemo(()=>TI(s.asrModels,t.asrModel),[s.asrModels,t.asrModel]),D=b.useMemo(()=>che(s.ttsModels,s.ttsVoices,t.ttsModel),[s.ttsModels,s.ttsVoices,t.ttsModel]),F=b.useMemo(()=>TI(M,Y),[M,Y]);function q(){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??x0.turnIdleSeconds}}async function j(){if(T)return;if(N){_({kind:"error",message:N});return}const X=Ft;if(!X){_({kind:"error",message:"请先连接 Relay 服务器"});return}const ae=q();te(),_({kind:"saving"});const ne=performance.now();try{const ce=await X.updateVoiceConfig(ae);if(!A.current)return;const _e=performance.now()-ne;if(_e<xI&&await ahe(xI-_e),!A.current)return;if(!ce.success||ce.error||!ce.config){_({kind:"error",message:ce.error??"保存语音设置失败"});return}n(ce.config),i(String(ce.config.turnIdleSeconds)),u(""),f(!1),_({kind:"saved"}),R.current=setTimeout(()=>{R.current=null,_(xe=>xe.kind==="saved"?{kind:"idle"}:xe)},rhe),X.requestVoiceCapabilities({region:ce.config.region}).then(xe=>{A.current&&xe.capabilities&&o(xe.capabilities)}).catch(()=>{A.current&&o(ov())})}catch(ce){if(!A.current)return;_({kind:"error",message:ce instanceof Error?ce.message:"保存语音设置失败"})}}async function V(){if(T)return;if(N){_({kind:"error",message:N});return}const X=Ft;if(!X){_({kind:"error",message:"请先连接 Relay 服务器"});return}let ae;try{ae=K()}catch(ne){_({kind:"error",message:kI(ne)});return}_({kind:"testing"});try{const[ne]=await Promise.all([X.testVoiceConfig(q()),ae.ready]);if(!ne.success||ne.error){$(),_({kind:"error",message:ne.error??"语音配置测试失败"});return}const ce=await re(ne,ae.context);_({kind:"playingTest",transcript:ne.transcript}),k.current=setTimeout(()=>{k.current=null,$(),_({kind:"testPassed",transcript:ne.transcript})},ce)}catch(ne){$(),_({kind:"error",message:kI(ne)})}}function K(){$();const X=Pk.acquire("playback");S.current=X;try{const ae=ohe();return w.current=ae,{context:ae,ready:CI(ae)}}catch(ae){throw X.release(),S.current=null,ae}}function $(){var X,ae,ne;k.current&&(clearTimeout(k.current),k.current=null),(X=x.current)==null||X.stop(),x.current=null,(ae=w.current)==null||ae.close(),w.current=null,(ne=S.current)==null||ne.release(),S.current=null}function te(){R.current&&(clearTimeout(R.current),R.current=null)}async function re(X,ae){if(!X.audioBase64)throw new Error("语音测试未返回可播放音频");if(X.audioEncoding&&X.audioEncoding!=="pcm_s16le")throw new Error("测试音频格式暂不支持");const ne=X.audioSampleRate??24e3,ce=she(X.audioBase64);if(ce.byteLength===0||ce.byteLength%2!==0)throw new Error("测试音频数据无效");await CI(ae);const _e=new SF(ae,ne);x.current=_e,_e.enqueue(ce);const xe=Math.ceil(ce.byteLength/2/ne*1e3);return Math.max(nhe,xe)}function ee(X){var ae;return((ae=I1(s.ttsVoices,X)[0])==null?void 0:ae.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:X=>{X.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(SI,{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(Cz,{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:X=>{u(X.target.value),f(!1)},placeholder:d?"保存后清空":t.configured?"••••••••••••••••":"输入 API Key",className:`${wI} w-full pl-9`})]}),t.configured&&m.jsxs(yt,{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(Nz,{className:"size-4","aria-hidden":"true"}),"清空"]})]})}),m.jsx(wv,{label:"地域",value:t.region,options:B,onChange:X=>n(ae=>({...ae,region:X==="intl"?"intl":"cn"}))}),m.jsx(wv,{label:"语音识别模型",value:t.asrModel,options:P,onChange:X=>n(ae=>({...ae,asrModel:X}))}),m.jsx(wv,{label:"语音合成模型",value:t.ttsModel,options:D,onChange:X=>n(ae=>({...ae,ttsModel:X,ttsVoice:ee(X)}))}),m.jsx(wv,{label:"语音音色",value:Y,options:F,placeholder:M.length===0?"暂无可用音色":"请选择音色",onChange:X=>n(ae=>({...ae,ttsVoice:X})),help:U}),m.jsx(SI,{label:"结束停顿时间(秒)",help:I,children:m.jsx("input",{"aria-label":"结束停顿时间(秒)",type:"number",min:1,step:1,inputMode:"numeric",value:r,onChange:X=>i(X.target.value),className:`${wI} 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:[O?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:O}):null,m.jsxs(yt,{type:"button",variant:"outline",disabled:L,onClick:()=>void V(),children:[m.jsx(Tz,{className:"size-4","aria-hidden":"true"}),"测试"]}),m.jsxs(yt,{type:"submit",disabled:L,children:[m.jsx(sK,{className:"size-4","aria-hidden":"true"}),g.kind==="saving"?"保存中...":"保存"]})]})]})]})}function she(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 ohe(){const e=window,t=e.AudioContext??e.webkitAudioContext;if(!t)throw new Error("当前浏览器不支持音频播放");return new t}async function CI(e){if(e.state!=="running")try{await e.resume()}catch{throw new Error("浏览器阻止了测试音频播放,请再次点击测试")}if(e.state!=="running")throw new Error("浏览器阻止了测试音频播放,请再次点击测试")}function kI(e){return e instanceof Error?e.message:"语音配置测试失败"}function ahe(e){return new Promise(t=>setTimeout(t,e))}function lhe(e){const t=e.trim();if(!/^[1-9]\d*$/.test(t))return null;const n=Number(t);return Number.isSafeInteger(n)?n:null}function TI(e,t){const n=e.map(r=>({value:r.value,label:CF(r)}));return!t||n.some(r=>r.value===t)?n:[{value:t,label:t},...n]}function che(e,t,n){const r=e.map(i=>{const s=I1(t,i.value).length===0;return{value:i.value,label:`${CF(i)}${s?" · 暂无音色":""}`,disabled:s}});return!n||r.some(i=>i.value===n)?r:[{value:n,label:`${n} · 暂无音色`,disabled:!0},...r]}function EF(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 CF(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 uhe=[{value:"auto",label:"跟随系统"},{value:"light",label:"浅色"},{value:"dark",label:"深色"}],dhe=[{value:"auto",label:"自动"},{value:"touch",label:"触控优先"},{value:"hardware",label:"实体键盘优先"}],Ik="dev-render-scroll min-h-0 space-y-3 overflow-y-auto overscroll-contain pr-4 sm:pr-1";function kF(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 fhe(e){const t=e||window.location.origin;return new URL("/health",t).toString()}function hhe(e){return e==="version"?"版本":e==="relay-token"?"Relay Token":e==="clients"?"客户端管理":"设置 Voice Pilot"}function phe(e){return e==="version"?"Web 与 Relay 服务器版本。":e==="relay-token"?"连接受保护的 Relay 服务器,保存后立即重连。":e==="clients"?"管理当前连接的 Web 客户端。":"连接语音服务后,即可以语音交互的形式驱动会话。"}function O1({open:e,onOpenChange:t}){const n=Ae(G=>G.relayUrl),r=Ae(G=>G.latencyMonitorEnabled),i=Ae(G=>G.setLatencyMonitorEnabled),s=Ae(G=>G.sessionIdleNotificationsEnabled),o=Ae(G=>G.setSessionIdleNotificationsEnabled),l=Ae(G=>G.inputModePreference),u=Ae(G=>G.setInputModePreference),d=Ae(G=>G.themePreference),f=Ae(G=>G.setThemePreference),h=Ae(G=>G.ptyScrollTraceEnabled),y=Ae(G=>G.setPtyScrollTraceEnabled),[g,_]=b.useState("menu"),[w,S]=b.useState(e),[x,k]=b.useState({kind:"idle"}),R=b.useRef(null),A=b.useRef(null),O=Lse(),T=b.useMemo(()=>pf().osName==="iPad",[]);e!==w&&(S(e),e&&_("menu"));const M=b.useCallback(async G=>{if(!G){o(!1);return}const I=await ose();if(I==="granted"){o(!0);return}if(I==="denied"){Ue.error("浏览器未授予通知权限,请在浏览器设置中允许通知");return}if(I==="default"){Ue.info("未授予通知权限,会话通知保持关闭");return}Ue.error("当前浏览器不支持系统通知")},[o]),z=b.useCallback(async G=>{k({kind:"loading"});try{const I=await fetch(fhe(n),{cache:"no-store",signal:G});if(!I.ok)throw new Error(`HTTP ${I.status}`);const N=await I.json();if(N.status!=="ok")throw new Error("状态异常");k({kind:"ready",version:N.version??"未知",uptime:N.uptime??0})}catch(I){if(I instanceof DOMException&&I.name==="AbortError")return;k({kind:"error",message:I 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 I;(I=R.current)==null||I.focus({preventScroll:!0}),A.current&&(A.current.scrollTop=0)});return()=>window.cancelAnimationFrame(G)},[e,g]);const Y=x.kind==="ready"?x.version:x.kind==="loading"?"读取中...":x.kind==="error"?"读取失败":"未读取",U=x.kind==="ready"?`运行 ${kF(x.uptime)}`:x.kind==="error"?x.message:"从当前 Relay 服务器 /health 读取";return m.jsx(es,{open:e,onOpenChange:t,children:m.jsxs(ts,{className:Ye("grid max-h-[calc(100dvh-1rem)] grid-rows-[auto_minmax(0,1fr)] overflow-hidden p-4 sm:max-w-[440px] sm:p-6",g==="voice"&&"max-h-[min(760px,calc(100dvh-1rem))] !gap-0 !p-0 sm:max-w-[480px]",g==="voice"&&"max-sm:top-auto max-sm:bottom-0 max-sm:left-2 max-sm:right-2 max-sm:h-[calc(100dvh-1rem)] max-sm:w-auto max-sm:max-h-none max-sm:max-w-none max-sm:translate-x-0 max-sm:translate-y-0 max-sm:rounded-b-none max-sm:rounded-t-2xl max-sm:border-x max-sm:border-b-0"),"data-slot":"settings-dialog","data-view":g,focusSurfaceOnOpen:!0,ref:R,showCloseButton:g==="menu",children:[m.jsx(ns,{className:Ye(g==="menu"&&"pr-12 text-left",g!=="menu"&&"text-left",g==="voice"&&"gap-0 px-4 pb-0 pt-3.5 text-left sm:px-5 sm:pt-4"),children:g!=="menu"?m.jsxs(m.Fragment,{children:[m.jsxs("div",{className:"flex items-start gap-2",children:[m.jsx(yt,{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(ff,{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($i,{children:hhe(g)}),m.jsx(Es,{className:"max-w-[28rem] leading-5",children:phe(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($i,{children:"设置"}),m.jsx(Es,{children:"连接、外观、通知和高级诊断选项。"})]})}),g==="version"?m.jsx(mhe,{relayVersion:Y,relayDetail:U,relayMuted:x.kind==="error"}):g==="relay-token"?m.jsx(vhe,{saved:O}):g==="clients"?m.jsx(xhe,{}):g==="voice"?m.jsx(ihe,{scrollRef:A}):m.jsx(ghe,{relayTokenSaved:O,themePreference:d,onThemePreferenceChange:f,inputModePreference:l,onInputModePreferenceChange:u,showInputModeSetting:T,sessionIdleNotificationsEnabled:s,onSessionIdleNotificationsEnabledChange:M,ptyScrollTraceEnabled:h,onPtyScrollTraceEnabledChange:y,latencyMonitorEnabled:r,onLatencyMonitorEnabledChange:i,onOpenVoice:()=>_("voice"),onOpenRelayToken:()=>_("relay-token"),onOpenClients:()=>_("clients"),onOpenVersion:()=>_("version")})]})})}function mhe({relayVersion:e,relayDetail:t,relayMuted:n}){return m.jsxs("div",{className:Ik,"data-slot":"settings-dialog-body",children:[m.jsx(AI,{icon:m.jsx(kz,{className:"size-4","aria-hidden":"true"}),label:"Web",value:Gfe.version,detail:"当前浏览器加载的版本"}),m.jsx(AI,{icon:m.jsx(Rz,{className:"size-4","aria-hidden":"true"}),label:"Relay 服务器",value:e,detail:t,muted:n})]})}function ghe({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:y,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(dd,{title:"服务",children:[m.jsx(xv,{icon:m.jsx(AV,{className:"size-4","aria-hidden":"true"}),label:"Voice Pilot",detail:"用语音输入、听取回复和处理审批",onClick:y}),m.jsx(xv,{icon:m.jsx(Cz,{className:"size-4","aria-hidden":"true"}),label:"Relay Token",detail:`${e?"已保存":"未设置"} · 受保护的 Relay 服务器`,onClick:g}),m.jsx(xv,{icon:m.jsx(TK,{className:"size-4","aria-hidden":"true"}),label:"客户端管理",detail:"已连接的浏览器页面和设备",onClick:_})]}),m.jsx(dd,{title:"外观",children:m.jsx(RI,{icon:m.jsx(gK,{className:"size-4","aria-hidden":"true"}),label:"主题",value:t,options:uhe,onValueChange:n})}),m.jsx(dd,{title:"通知",children:m.jsx(E0,{icon:m.jsx(MV,{className:"size-4","aria-hidden":"true"}),label:"会话空闲通知",detail:"会话从工作中转为空闲时发送浏览器通知",checked:o,onCheckedChange:l})}),s?m.jsx(dd,{title:"交互",children:m.jsx(RI,{icon:m.jsx(SC,{className:"size-4","aria-hidden":"true"}),label:"输入方式",detail:"默认自动识别软键盘和实体键盘;必要时可强制一种方式",value:r,options:dhe,onValueChange:i})}):null,m.jsxs(dd,{title:"高级诊断",children:[m.jsx(E0,{icon:m.jsx(ru,{className:"size-4","aria-hidden":"true"}),label:"PTY 滚动追踪",detail:"记录终端滚动和视口同步现场,方便复制诊断报告",checked:u,onCheckedChange:d}),m.jsx(E0,{icon:m.jsx(vz,{className:"size-4","aria-hidden":"true"}),label:"延迟监控",detail:"显示可拖动的连接延迟浮窗",checked:f,onCheckedChange:h})]}),m.jsx(dd,{title:"关于",children:m.jsx(xv,{icon:m.jsx(Rz,{className:"size-4","aria-hidden":"true"}),label:"版本",onClick:w})})]})}function dd({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 RI({icon:e,label:t,detail:n,value:r,options:i,onValueChange:s}){const o=b.useId(),l=b.useId();return m.jsxs("div",{className:"flex w-full items-start gap-3 px-3 py-3 text-left","data-slot":"settings-choice-item",children:[m.jsx("div",{className:"flex size-8 shrink-0 items-center justify-center rounded-md bg-background/55 text-muted-foreground",children:e}),m.jsxs("div",{className:"min-w-0 flex-1",children:[m.jsx("div",{id:o,className:"text-sm font-medium text-foreground",children:t}),n?m.jsx("div",{id:l,className:"mt-1 text-xs text-muted-foreground",children:n}):null,m.jsx("div",{role:"radiogroup","aria-labelledby":o,"aria-describedby":n?l:void 0,className:"mt-3 grid grid-cols-3 gap-1 rounded-md border border-border bg-muted/70 p-1","data-slot":"settings-segmented-choice",children:i.map(u=>{const d=u.value===r;return m.jsx("button",{type:"button",role:"radio","aria-checked":d,className:Ye("min-w-0 whitespace-nowrap rounded px-2 py-1.5 text-xs font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",d?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:bg-background/55 hover:text-foreground"),onClick:()=>s(u.value),children:u.label},u.value)})})]})]})}function vhe({saved:e}){const t=b.useId(),n=b.useId(),[r,i]=b.useState(""),[s,o]=b.useState(null),l=()=>{b5().catch(f=>{o(f instanceof Error?f.message:"Relay 重连失败。")})},u=()=>{const f=r.trim();if(!f){o("请输入 token。");return}if(!v5(f)){const h="Relay Token 保存失败,请检查浏览器存储权限。";o(h),Ue.error(h);return}o(null),Ue.success("Relay Token 已保存,正在重新连接"),l()},d=()=>{y5(),l()};return m.jsxs("form",{className:Ik,"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(yt,{type:"button",variant:"outline",onClick:d,children:"清空"}):null,m.jsx(yt,{type:"submit",disabled:!r.trim(),children:"保存"})]})]})}function yhe(e){return e.length<=16?e:`${e.slice(0,8)}...${e.slice(-4)}`}function bhe(e,t){var r;return((r=t.get(e))==null?void 0:r.trim())||yhe(e)}function _he(e){return Zne(e)}function whe(e){const t=Math.max(0,Math.floor((Date.now()-e)/1e3));return kF(t)}function S0({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 xhe(){const e=Ae(y=>y.proxies),[t,n]=b.useState([]),[r,i]=b.useState(!0),[s,o]=b.useState(null),[l,u]=b.useState(null),d=b.useMemo(()=>new Map(e.map(y=>[y.proxyId,y.name]).filter(y=>typeof y[1]=="string")),[e]),f=b.useCallback(async()=>{const y=Ft;if(!y){n([]),o("Relay 未连接。"),i(!1);return}i(!0),o(null);try{n(await y.requestRelayClients())}catch(g){o(g instanceof Error?g.message:"读取客户端列表失败。")}finally{i(!1)}},[]);b.useEffect(()=>{f()},[f]);const h=b.useCallback(async y=>{const g=Ft;if(!g){o("Relay 未连接。");return}u(y),o(null);try{const _=await g.kickRelayClient(y);if(!_.success){o(_.error??"断开客户端失败。");return}n(w=>w.filter(S=>S.clientId!==y))}catch(_){o(_ instanceof Error?_.message:"断开客户端失败。")}finally{u(null)}},[]);return m.jsxs("div",{className:Ik,"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(yt,{type:"button",variant:"ghost",size:"icon-sm","aria-label":"刷新客户端列表",title:"刷新",onClick:()=>void f(),disabled:r,"data-slot":"relay-clients-refresh",children:m.jsx(fm,{className:Ye("size-3.5",r&&"animate-spin"),"aria-hidden":"true"})})]}),s?m.jsx("div",{className:"rounded-md border border-destructive/35 bg-destructive/10 px-3 py-2 text-xs text-destructive",children:s}):null,!r&&t.length===0?m.jsx("div",{className:"rounded-md border border-border bg-card/70 px-3 py-6 text-center text-sm text-muted-foreground",children:"当前没有在线客户端"}):null,t.map(y=>{const g=y.current===!0,_=l===y.clientId;return m.jsx("div",{className:"rounded-md border border-border bg-card/70 p-3","data-slot":"relay-client-row","data-client-id":y.clientId,title:`客户端 ${y.clientId}`,children: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:_he(y)})}),m.jsxs("div",{className:"space-y-1",children:[m.jsx(S0,{label:"已连接",value:whe(y.connectedAt)}),y.proxyId?m.jsx(S0,{label:"连接到",value:bhe(y.proxyId,d),title:y.proxyId}):null,y.remoteAddress?m.jsx(S0,{label:"来源 IP",value:y.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(yt,{type:"button",variant:"outline",size:"sm",className:"h-9 w-full justify-center",disabled:_,onClick:()=>void h(y.clientId),"data-slot":"relay-client-action",children:[m.jsx(PY,{className:"size-3.5","aria-hidden":"true"}),_?"断开中...":"断开"]})]})},y.clientId)})]})}function E0({icon:e,label:t,detail:n,checked:r,onCheckedChange:i}){const s=b.useId(),o=b.useId();return m.jsxs("button",{type:"button",role:"switch",className:"group flex w-full items-center gap-3 px-3 py-3 text-left transition-colors hover:bg-accent/55 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",onClick:()=>i(!r),"aria-checked":r,"aria-labelledby":s,"aria-describedby":o,"data-slot":"settings-toggle-item",children:[m.jsx("div",{className:Ye("flex size-8 shrink-0 items-center justify-center rounded-md bg-background/55 transition-colors",r?"text-primary":"text-muted-foreground"),children:e}),m.jsxs("div",{className:"min-w-0 flex-1",children:[m.jsx("div",{id:s,className:"text-sm font-medium text-foreground",children:t}),m.jsx("div",{id:o,className:"mt-1 text-xs text-muted-foreground",children:n})]}),m.jsx("span",{className:Ye("relative h-6 w-11 shrink-0 rounded-full border transition-colors",r?"border-primary/65 bg-primary/70":"border-border bg-muted/50"),"aria-hidden":"true","data-slot":"settings-toggle-switch",children:m.jsx("span",{className:Ye("absolute top-1/2 size-4 -translate-y-1/2 rounded-full bg-background shadow-sm transition-transform",r?"translate-x-[1.35rem]":"translate-x-1")})})]})}function xv({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(Hd,{className:"size-4 shrink-0 text-muted-foreground","aria-hidden":"true"})]})}function AI({icon:e,label:t,value:n,detail:r,muted:i=!1}){return m.jsxs("div",{className:"flex gap-3 rounded-md border border-border bg-card/70 p-3",children:[m.jsx("div",{className:Ye("mt-0.5 flex size-8 shrink-0 items-center justify-center rounded-md border",i?"border-border text-muted-foreground":"border-primary/35 bg-primary/10 text-primary"),children:e}),m.jsxs("div",{className:"min-w-0 flex-1",children:[m.jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[m.jsx("div",{className:"text-sm text-muted-foreground",children:t}),m.jsx("div",{className:"min-w-0 truncate font-mono text-sm text-foreground",children:n})]}),m.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:r})]})]})}const She="xterm-helper-textarea";function Ehe(e=document.activeElement){return!(e instanceof HTMLElement)||!e.classList.contains(She)?!1:(e.blur(),!0)}function NI(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&&Che(r,n))return!0;if(r===t)break;r=r.parentElement}return!1}function Che(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 khe({releasePtyFocus:e=!0,containVerticalScroll:t=!0}={}){const n=b.useRef(null),r=b.useCallback(()=>{e&&Ehe()},[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,NI(l.target,l.currentTarget,f)||l.preventDefault()},[t]),o=b.useCallback(l=>{r(),t&&(NI(l.target,l.currentTarget,l.deltaY)||l.preventDefault())},[t,r]);return{onPointerDownCapture:r,onTouchStartCapture:i,onTouchMoveCapture:s,onWheelCapture:o}}function The({className:e}){const t=Ae(o=>o.sidebarCollapsed),n=Ae(o=>o.toggleSidebarCollapsed),[r,i]=b.useState(!1),s=khe();return t?m.jsxs(m.Fragment,{children:[m.jsxs("nav",{className:Ye("dev-sidebar-shell dev-sidebar-rail relative flex-col items-center w-12 shrink-0 bg-card border-r border-border overflow-hidden px-1.5 pb-[calc(var(--dev-safe-area-bottom,env(safe-area-inset-bottom))+0.5rem)] pt-[max(0.5rem,env(safe-area-inset-top))]",e),"aria-label":"侧边栏","data-slot":"sidebar-rail","data-collapsed":"true",...s,children:[m.jsx(PI,{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(MI,{compact:!0,tooltipSide:"right",onClick:()=>i(!0)}),m.jsx(vI,{compact:!0})]})]}),m.jsx(O1,{open:r,onOpenChange:i})]}):m.jsxs(m.Fragment,{children:[m.jsxs("nav",{className:Ye("dev-sidebar-shell group/sidebar relative flex-col w-[280px] shrink-0 bg-card border-r border-border overflow-visible pt-[env(safe-area-inset-top)]",e),"aria-label":"侧边栏","data-slot":"sidebar","data-collapsed":"false",...s,children:[m.jsx("div",{className:"dev-sidebar-fade p-2.5","data-slot":"sidebar-proxy-switcher",children:m.jsxs("div",{className:"dev-sidebar-chrome rounded-lg border p-3",children:[m.jsxs("div",{className:"flex items-center justify-between gap-3",children:[m.jsx(Kz,{className:"text-[13px]",slot:"sidebar-brand"}),m.jsx(PI,{collapsed:!1,onClick:n})]}),m.jsx("div",{className:"mt-2.5",children:m.jsx(sF,{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(yF,{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(vI,{})}),m.jsx("div",{className:"min-w-0 flex-1",children:m.jsx(MI,{onClick:()=>i(!0)})})]})]}),m.jsx(O1,{open:r,onOpenChange:i})]})}function MI({compact:e=!1,tooltipSide:t="top",onClick:n}){return m.jsxs(Sf,{delayDuration:500,children:[m.jsx(Ef,{asChild:!0,children:m.jsxs("button",{type:"button","aria-label":"设置","data-slot":"sidebar-settings-trigger",onClick:n,className:Ye("inline-flex items-center justify-center shrink-0 border text-muted-foreground outline-none transition-[color,background-color,border-color,box-shadow]","focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",e?"h-11 w-11 rounded-md border-border bg-card/70 hover:border-primary/60 hover:bg-accent hover:text-foreground":"h-[46px] w-full gap-2 rounded-md border-border bg-background hover:border-primary/50 hover:bg-accent hover:text-foreground"),children:[m.jsx(Az,{className:"size-4","aria-hidden":"true"}),!e&&m.jsx("span",{className:"truncate text-sm font-medium",children:"设置"})]})}),m.jsx(Cf,{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 PI({collapsed:e,onClick:t}){const n=e?"展开侧边栏":"收起侧边栏",r=e?WY:HY;return m.jsxs(Sf,{delayDuration:500,children:[m.jsx(Ef,{asChild:!0,children:m.jsx("button",{type:"button","aria-label":n,"data-slot":e?"sidebar-expand-trigger":"sidebar-collapse-trigger",onClick:t,className:Ye("group inline-flex items-center justify-center text-muted-foreground outline-none transition-[opacity,color,background-color,border-color,box-shadow,transform]","outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",e?"h-9 w-9 rounded-md border border-border/80 bg-card/70 hover:border-primary/60 hover:bg-accent hover:text-foreground":"h-9 w-9 rounded-full border border-primary/25 bg-primary/10 hover:border-primary/60 hover:bg-primary/15 hover:text-foreground"),children:m.jsx(r,{className:Ye("size-3.5 transition-transform",e&&"group-hover:translate-x-0.5",!e&&"group-hover:-translate-x-0.5"),"aria-hidden":"true"})})}),m.jsx(Cf,{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 Rhe=1500,Ahe=300,II=70,OI=35;function TF({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],y=()=>{const g=o.current;if(g==="typing"){const _=h();l.current<_.length?(l.current+=1,r(_.slice(0,l.current)),f=setTimeout(y,II)):(o.current="paused",f=setTimeout(y,Rhe))}else g==="paused"?(o.current="deleting",f=setTimeout(y,OI)):g==="deleting"?l.current>0?(l.current-=1,r(h().slice(0,l.current)),f=setTimeout(y,OI)):(u.current+=1,o.current="waiting",f=setTimeout(y,Ahe)):(o.current="typing",f=setTimeout(y,II))};return f=setTimeout(y,500),()=>clearTimeout(f)},[e]);const d=n.startsWith("DEV")?3:n.length<=3&&"DEV".startsWith(n)?n.length:0;return m.jsxs("div",{className:`font-mono leading-tight select-none ${t??""}`,"data-slot":"brand-typewriter",children:[m.jsx("span",{className:"text-green-500",children:"> "}),m.jsx("span",{className:"text-primary","data-slot":"brand-typewriter-dev",children:n.slice(0,d)}),m.jsx("span",{className:"text-foreground/90",children:n.slice(d)}),m.jsx("span",{className:`text-primary ${i?"opacity-100":"opacity-0"}`,children:"_"})]})}const RF=["DEV Anywhere","/unlimited @anytime"];function Nhe({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(TF,{texts:RF,className:"dev-mobile-brand-typewriter max-w-full overflow-hidden text-ellipsis whitespace-nowrap font-bold tracking-normal"}),e?m.jsx("p",{className:"dev-mobile-brand-subtitle max-w-[34rem] text-sm leading-5 text-muted-foreground",children:e}):null,t?m.jsx("div",{className:"dev-mobile-brand-action flex max-w-full min-w-0 pt-1",children:t}):null]})})}const Mhe=3e3,Phe=1e4,Sv=12,Ihe=4,LI={webRelay:"浏览器 ↔ Relay 服务器",relayProxy:"Relay 服务器 ↔ 开发机",webProxy:"浏览器 ↔ 开发机"},Ohe={webRelay:{state:"idle"},relayProxy:{state:"idle"},webProxy:{state:"idle"}};function C0(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 fd(e){return{state:"unavailable",error:e,updatedAt:Date.now()}}function fp(e){return e===void 0||!Number.isFinite(e)?"--":`${Math.max(0,Math.round(e))}ms`}function DI(e){switch(e){case"bad":return 4;case"unavailable":return 3;case"warn":return 2;case"measuring":return 1;default:return 0}}function AF(e){return e==="bad"||e==="unavailable"?"bad":e==="warn"?"warn":e==="ok"?"ok":"neutral"}function Lhe(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 Dhe(e){return e.state==="measuring"?"检测中":e.state==="unavailable"?e.error??"不可用":e.rttMs!==void 0?fp(e.rttMs):"等待检测"}function Bhe(){const e=Ni("local",Sn.latencyMonitorPosition);if(!e)return null;try{const t=JSON.parse(e);return!Number.isFinite(t.x)||!Number.isFinite(t.y)?null:{x:Number(t.x),y:Number(t.y)}}catch{return null}}function BI(e){Mr("local",Sn.latencyMonitorPosition,JSON.stringify(e))}function zhe(){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 k0(e,t){const n=zhe(),r=Sv,i=Sv,s=Math.max(r,n.width-t.width-Sv),o=Math.max(i,n.height-t.height-Sv);return{x:Math.min(s,Math.max(r,Math.round(e.x))),y:Math.min(o,Math.max(i,Math.round(e.y)))}}function jhe(){const e=Ae(T=>T.latencyMonitorEnabled),t=Ae(T=>T.connected),n=Ae(T=>T.proxyOnline),r=Ae(T=>T.selectedProxyId),[i,s]=b.useState(Ohe),[o,l]=b.useState(()=>Bhe()),u=b.useRef(!1),d=b.useRef(null),f=b.useRef(null),h=b.useRef(!1),y=b.useMemo(()=>(Object.values(i).sort((T,M)=>DI(M.state)-DI(T.state))[0]??{state:"idle"}).state,[i]),g=AF(y);async function _(){if(u.current)return;const T=Ft;if(!T||!t){const U=fd("Relay 服务器未连接");s({webRelay:U,relayProxy:U,webProxy:U});return}u.current=!0,s(U=>({webRelay:{...U.webRelay,state:"measuring"},relayProxy:n?{...U.relayProxy,state:"measuring"}:fd("未连接开发机"),webProxy:n?{...U.webProxy,state:"measuring"}:fd("未连接开发机")}));const[M,z,Y]=await Promise.allSettled([T.measureWebRelayLatency(),n?T.measureRelayProxyLatency():Promise.resolve({success:!1}),n?T.measureWebProxyLatency():Promise.resolve({success:!1})]);s({webRelay:M.status==="fulfilled"?C0(M.value):fd(M.reason instanceof Error?M.reason.message:"测速失败"),relayProxy:z.status==="fulfilled"?C0(z.value):fd(z.reason instanceof Error?z.reason.message:"测速失败"),webProxy:Y.status==="fulfilled"?C0(Y.value):fd(Y.reason instanceof Error?Y.reason.message:"测速失败")}),u.current=!1}if(b.useEffect(()=>{if(!e)return;let T=!1,M=null;const z=async()=>{await _(),!T&&(M=setTimeout(z,document.hidden?Phe:Mhe))};return z(),()=>{T=!0,u.current=!1,M&&clearTimeout(M)}},[e,t,n,r]),b.useEffect(()=>{if(!e||!o)return;const T=d.current;if(!T)return;const M=T.getBoundingClientRect(),z=k0(o,{width:M.width,height:M.height});z.x===o.x&&z.y===o.y||(l(z),BI(z))},[e,o]),!e)return null;const w=i.webProxy.rttMs!==void 0?i.webProxy:i.relayProxy,S=o!==null?{left:`${o.x}px`,top:`${o.y}px`}:void 0;function x(T){var z,Y;if(T.button!==0)return;const M=T.currentTarget.getBoundingClientRect();f.current={pointerId:T.pointerId,startX:T.clientX,startY:T.clientY,originX:M.left,originY:M.top,width:M.width,height:M.height,dragging:!1},(Y=(z=T.currentTarget).setPointerCapture)==null||Y.call(z,T.pointerId)}function k(T){const M=f.current;if(!M||M.pointerId!==T.pointerId)return;const z=T.clientX-M.startX,Y=T.clientY-M.startY;if(!M.dragging&&Math.hypot(z,Y)<Ihe)return;M.dragging=!0,T.preventDefault();const U=k0({x:M.originX+z,y:M.originY+Y},{width:M.width,height:M.height});l(U)}function R(T){var G,I;const M=f.current;if(!M||M.pointerId!==T.pointerId||(f.current=null,(I=(G=T.currentTarget).releasePointerCapture)==null||I.call(G,T.pointerId),!M.dragging))return;T.preventDefault(),h.current=!0,window.setTimeout(()=>{h.current=!1},200);const z=T.clientX-M.startX,Y=T.clientY-M.startY,U=k0({x:M.originX+z,y:M.originY+Y},{width:M.width,height:M.height});l(U),BI(U)}function A(T){var z,Y;const M=f.current;!M||M.pointerId!==T.pointerId||(f.current=null,(Y=(z=T.currentTarget).releasePointerCapture)==null||Y.call(z,T.pointerId))}function O(T){h.current&&(h.current=!1,T.preventDefault(),T.stopPropagation())}return m.jsxs(Ub,{children:[m.jsx(Wb,{asChild:!0,children:m.jsxs("button",{ref:d,type:"button",className:Ye("fixed z-40 flex max-w-[calc(100vw-1.5rem)] touch-none cursor-move select-none items-center gap-2 rounded-md border px-2.5 py-1.5 text-xs shadow-lg backdrop-blur transition-colors",o===null&&"right-[calc(env(safe-area-inset-right)+0.75rem)] top-[calc(env(safe-area-inset-top)+3.75rem)] md:right-4 md:top-4",Lhe(g)),style:S,"data-slot":"latency-monitor-trigger","aria-label":`延迟监控,Relay 服务器 ${fp(i.webRelay.rttMs)},开发机 ${fp(w.rttMs)}`,onPointerDown:x,onPointerMove:k,onPointerUp:R,onPointerCancel:A,onClickCapture:O,children:[m.jsx(vz,{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 ",fp(i.webRelay.rttMs)]}),m.jsxs("span",{className:"text-muted-foreground",children:["开发机 ",fp(w.rttMs)]}),m.jsx(sc,{className:"size-3 text-muted-foreground","aria-hidden":"true"})]})}),m.jsxs(qb,{align:"end",className:"w-[320px] p-3","data-slot":"latency-monitor-popover",children:[m.jsxs("div",{className:"flex items-start justify-between gap-3",children:[m.jsxs("div",{children:[m.jsx("div",{className:"text-sm font-medium text-foreground",children:"连接延迟"}),m.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:"数值越低,操作响应通常越快。"})]}),m.jsx(yt,{type:"button",variant:"ghost",size:"icon-xs","aria-label":"立即测速",onClick:()=>void _(),children:m.jsx(fm,{className:"size-3","aria-hidden":"true"})})]}),m.jsx("div",{className:"mt-3 space-y-2",children:Object.keys(LI).map(T=>m.jsx(Fhe,{label:LI[T],measurement:i[T]},T))})]})]})}function Fhe({label:e,measurement:t}){const n=AF(t.state);return m.jsxs("div",{className:"flex min-h-10 items-center justify-between gap-3 rounded-md border border-border/70 bg-card/60 px-3 py-2",children:[m.jsx("div",{className:"min-w-0 truncate text-xs font-medium text-foreground",children:e}),m.jsxs("div",{className:"flex items-center gap-2",children:[m.jsx("span",{className:Ye("size-1.5 rounded-full",n==="ok"?"bg-emerald-400":n==="warn"?"bg-amber-400":n==="bad"?"bg-destructive":"bg-muted-foreground/60"),"aria-hidden":"true"}),m.jsx("span",{className:"min-w-[4rem] text-right font-mono text-xs text-foreground",children:Dhe(t)})]})]})}const NF="/__dev_anywhere_debug/browser-state-dumps",$he=1500,Hhe=10,T0=80,Ok=500,Uhe=["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"],Whe=["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 zI(){if(typeof window>"u")return"off";const e=zF("debugDump");return e==="auto"?"auto":e!==null||Qhe("debugInput")?"manual":"off"}function qhe(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:Ghe(),document:{title:document.title,readyState:document.readyState,visibilityState:document.visibilityState,activeElement:jI(document.activeElement),selection:Xhe(),focusedInputs:Array.from(document.querySelectorAll("input, textarea, select, [contenteditable]")).filter(i=>i===document.activeElement||i.matches(":focus")).map(i=>jI(i)).filter(i=>!!i),root:MF(document.documentElement,0,t),truncated:t.truncated,nodeCount:t.count},devAnywhere:{ptyDebug:hd(()=>{var i;return((i=n.__devAnywherePtyDebug)==null?void 0:i.call(n))??null}),ptyInputDebugSnapshot:hd(()=>n.__devAnywherePtyInputDebugSnapshot??null),ptyInputDebugText:n.__devAnywherePtyInputDebugText??null,ptyInputDebugEvents:hd(()=>n.__devAnywherePtyInputDebugEvents??null),ptyScrollTraceTail:hd(()=>FI(n.__devAnywherePtyScrollTrace)),jsonScrollTraceTail:hd(()=>FI(n.__devAnywhereJsonScrollTrace)),voicePilotDiagnostics:hd(()=>{var i;return((i=n.__devAnywhereVoicePilotDiagnostics)==null?void 0:i.snapshot())??null})}};return window.__devAnywhereLastBrowserStateDump=r,r}async function Vhe(e="manual"){const t=qhe(e);return Yhe(t)}async function Yhe(e){const t=JSON.stringify(e,null,2),n=new Blob([t]).size;try{const r=await Khe(t);return{status:"saved",path:r.path,bytes:r.bytes,endpoint:NF}}catch(r){const i=jF(r),s=Zhe(e.createdAt);return Jhe(s,t,"application/json")?{status:"downloaded",filename:s,bytes:n,endpointError:i}:{status:"failed",error:"无法保存或下载诊断包",endpointError:i}}}async function Khe(e){const t=await fetch(NF,{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 MF(e,t,n){if(n.count>=$he||t>Hhe)return n.truncated=!0,{kind:"truncated"};if(n.count+=1,e.nodeType===Node.TEXT_NODE){const u=$I(e.textContent??"");return u?{kind:"text",text:Qb(u,Ok)}:{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,T0))u.nodeType===Node.TEXT_NODE&&!$I(u.textContent??"")||r.push(MF(u,t+1,n));s.length>T0&&(i=s.length-T0,n.truncated=!0);const o={kind:"element",tag:e.tagName.toLowerCase(),path:BF(e),attrs:PF(e),rect:IF(e),scroll:OF(e),style:LF(e)},l=DF(e);return l&&(o.value=l),r.length>0&&(o.children=r),i>0&&(o.omittedChildren=i),o}function jI(e){if(!(e instanceof HTMLElement))return null;const t=DF(e);return{path:BF(e),tag:e.tagName.toLowerCase(),id:e.id||null,className:e.className||null,attrs:PF(e),rect:IF(e),scroll:OF(e),style:LF(e),...t?{value:t}:{}}}function Ghe(){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 PF(e){const t={};for(const n of Uhe){const r=e.getAttribute(n);r!==null&&(t[n]=Qb(r,500))}return t}function IF(e){const t=e.getBoundingClientRect();return{x:Ss(t.x),y:Ss(t.y),width:Ss(t.width),height:Ss(t.height),top:Ss(t.top),right:Ss(t.right),bottom:Ss(t.bottom),left:Ss(t.left)}}function OF(e){return{top:Ss(e.scrollTop),left:Ss(e.scrollLeft),height:Ss(e.scrollHeight),width:Ss(e.scrollWidth),clientHeight:Ss(e.clientHeight),clientWidth:Ss(e.clientWidth)}}function LF(e){const t=window.getComputedStyle(e),n={};for(const r of Whe)n[r]=t.getPropertyValue(r);return n}function DF(e){if(!(!(e instanceof HTMLInputElement)&&!(e instanceof HTMLTextAreaElement)))return{length:e.value.length,preview:Qb(e.value,Ok),selectionStart:e.selectionStart,selectionEnd:e.selectionEnd}}function Xhe(){var e;try{return Qb(((e=window.getSelection())==null?void 0:e.toString())??"",Ok)}catch{return null}}function BF(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 Zhe(e){return`dev-anywhere-browser-state-${e.replace(/[:.]/g,"-")}.json`}function Jhe(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 Qhe(e){return zF(e)!==null}function zF(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 FI(e){return e?qy(e.slice(-200)):null}function hd(e){try{return qy(e())}catch(t){return{error:jF(t)}}}function qy(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(qy);if(typeof e=="object"){const t={};for(const[n,r]of Object.entries(e))t[n]=qy(r);return t}return String(e)}function $I(e){return e.replace(/\s+/g," ").trim()}function Qb(e,t){return e.length>t?`${e.slice(0,t)}...`:e}function Ss(e){return Math.round(e*100)/100}function jF(e){return e instanceof Error?e.message:String(e)}const epe=500,tpe=1e3,npe=60;function rpe(){const[e,t]=b.useState(()=>zI()),[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(zI());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 Vhe(_);return o.current=w,s(w),(_==="manual"||w.status==="failed")&&ipe(w),w}finally{l.current=!1,r(!1)}},[]);if(b.useEffect(()=>(window.__devAnywhereDumpBrowserState=h,()=>{window.__devAnywhereDumpBrowserState===h&&delete window.__devAnywhereDumpBrowserState}),[h]),b.useEffect(()=>{var k,R;if(e!=="auto")return;const _=()=>{f.current!==null&&(window.clearTimeout(f.current),f.current=null)},w=A=>{d.current>=npe||(_(),f.current=window.setTimeout(()=>{f.current=null;const O=Date.now(),T=tpe-(O-u.current);if(T>0){f.current=window.setTimeout(()=>w(A),T);return}u.current=Date.now(),d.current+=1,h(`auto:${d.current}:${A}`)},epe))};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)),(k=window.visualViewport)==null||k.addEventListener("resize",x),(R=window.visualViewport)==null||R.addEventListener("scroll",x),()=>{var A,O;_(),S.forEach(T=>window.removeEventListener(T,x,!0)),(A=window.visualViewport)==null||A.removeEventListener("resize",x),(O=window.visualViewport)==null||O.removeEventListener("scroll",x)}},[h,e]),e==="off")return null;const y=e==="auto"?"自动诊断中":"保存诊断",g=spe(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(yt,{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(di,{className:"size-3.5 animate-spin","aria-hidden":"true"}):m.jsx(pY,{className:"size-3.5","aria-hidden":"true"}),m.jsx("span",{children:y})]})]})}function ipe(e){if(e.status==="saved"){Ue.success(`诊断已保存: ${e.path}`);return}if(e.status==="downloaded"){Ue.info(`诊断已下载: ${e.filename}`);return}Ue.error(e.endpointError?`${e.error}: ${e.endpointError}`:e.error)}function spe(e){return e?e.status==="saved"?`已保存 ${e.path}`:e.status==="downloaded"?`已下载 ${e.filename}`:`失败 ${e.endpointError??e.error}`:null}function ope({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(di,{className:"size-5 animate-spin","aria-hidden":"true"}):null,m.jsx("p",{className:"text-sm",children:t}),n?m.jsx(yt,{type:"button",size:"sm",onClick:()=>window.location.reload(),children:n}):null]})}function ape(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 Lk(e){const{windowKey:t,storageKey:n,maxEntries:r=5e3,dedupeKey:i}=e,s=new Map,o=()=>typeof window>"u"?!1:ape(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 y=s.get(d.event);if(y&&i(y)===h&&f.includes(y)){y.t=d.t,y.repeat=(y.repeat??0)+1;const g=f.indexOf(y);g>=0&&g!==f.length-1&&(f.splice(g,1),f.push(y)),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 y of h)s.get(y.event)===y&&s.delete(y.event)}u(f)},getAll:l}}function Zn(e){return Math.round(e*10)/10}function Bl(e){return e.length===0?"":`${Zn(Math.min(...e))}..${Zn(Math.max(...e))}`}function Od(e){return[...new Set(e.filter(t=>t!==void 0).map(Zn))]}function FF(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 lpe="dev_anywhere_pty_input_latency_trace",HI=80,cpe=1e4,upe=new TextDecoder;let dpe=0;const af=new Map,Cu=Lk({windowKey:"__devAnywherePtyInputLatencyTrace",storageKey:lpe,dedupeKey:e=>e.event.startsWith("input")?null:`${e.event}|${e.sessionId}|${e.outputSeq??""}|${e.pendingInputs??""}`});function fpe(){typeof window>"u"||(window.__devAnywherePtyInputLatencyReport=gpe)}function hpe(e,t){if(!Cu.isEnabled())return null;const n=`pty-in-${Date.now().toString(36)}-${++dpe}`,r=performance.now(),i={inputId:n,sessionId:e,data:t,kind:bpe(t),dataLength:t.length,startedAt:r,sentAt:null,firstOutputAt:null,echoMatchedAt:null,xtermWriteAt:null,paintAt:null},s=af.get(e)??[];return s.push(i),Bk(s,r),af.set(e,s),Rm({t:r,event:"input:start",sessionId:e,inputId:n,inputKind:i.kind,dataLength:i.dataLength,pendingInputs:s.length}),{inputId:n,sessionId:e}}function UI(e,t){if(!e||!Cu.isEnabled())return;const n=performance.now(),r=vpe(e.sessionId,e.inputId);r&&(r.sentAt=n),Rm({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 ppe(e,t,n){if(!Cu.isEnabled())return;const r=performance.now(),i=Dk(e,r),s=xpe(t),o=[],l=[];for(const u of i)u.firstOutputAt===null&&(u.firstOutputAt=r,o.push(u.inputId)),u.echoMatchedAt===null&&wpe(u)&&s.includes(u.data)&&(u.echoMatchedAt=r,l.push(u.inputId));Rm({t:r,event:"output:received",sessionId:e,outputSeq:n,bytes:t.byteLength,pendingInputs:i.length,deltaFromInputMs:zk(i,r),details:Spe([o.length>0?`first=${o.length}`:"",l.length>0?`echo=${l.length}`:""])})}function mpe(e,t,n=1){if(!Cu.isEnabled())return;const r=performance.now(),i=Dk(e,r),s=[];for(const o of i)o.xtermWriteAt===null&&(o.xtermWriteAt=r,s.push(o.inputId));Rm({t:r,event:"output:xterm-write",sessionId:e,bytes:t,chunkCount:n,pendingInputs:i.length,deltaFromInputMs:zk(i,r),details:s.length>0?`firstWrite=${s.length}`:""}),typeof requestAnimationFrame=="function"&&s.length>0&&requestAnimationFrame(()=>ype(e,s))}function gpe(){const e=Cu.getAll(),t=e.slice(-200),n=[...af.values()].flat(),r=n.slice(-80).map(s=>[s.inputId,s.sessionId,s.kind,s.dataLength,s.sentAt===null?"":Zn(s.sentAt-s.startedAt),s.firstOutputAt===null?"":Zn(s.firstOutputAt-s.startedAt),s.echoMatchedAt===null?"":Zn(s.echoMatchedAt-s.startedAt),s.xtermWriteAt===null?"":Zn(s.xtermWriteAt-s.startedAt),s.paintAt===null?"":Zn(s.paintAt-s.startedAt)].join(" ")),i=t.map(s=>[Zn(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?"":Zn(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(`
|
|
601
601
|
`)}function Rm(e){Cu.append(e)}function Dk(e,t){const n=af.get(e)??[];return Bk(n,t),af.set(e,n),n}function Bk(e,t){for(let n=e.length-1;n>=0;n-=1){const r=e[n],i=r.paintAt!==null,s=t-r.startedAt>cpe;(i||s)&&e.splice(n,1)}e.length>HI&&e.splice(0,e.length-HI)}function vpe(e,t){return(af.get(e)??[]).find(n=>n.inputId===t)??null}function ype(e,t){if(!Cu.isEnabled())return;const n=performance.now(),r=Dk(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)}Rm({t:n,event:"output:paint",sessionId:e,pendingInputs:r.length,deltaFromInputMs:zk(r,n),details:i>0?`paint=${i}`:""}),Bk(r,n)}function zk(e,t){const n=e[0];return n?t-n.startedAt:null}function bpe(e){return e==="\r"||e===`
|
|
602
602
|
`?"enter":e.startsWith("\x1B")?"escape":_pe(e)?"control":e.length>16?"paste":/[\r\n]/.test(e)?"mixed":"printable"}function _pe(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 wpe(e){return e.kind==="printable"&&e.data.length>0&&e.data.length<=16}function xpe(e){try{return upe.decode(e)}catch{return""}}function Spe(e){return e.filter(Boolean).join(" ")}function Mo(e,t){if(!e||!t)return;const n=hpe(e,t),r=Ua;if(!r){UI(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});UI(n,{sent:s,queueWhenDisconnected:!0,details:s?"sent-open-socket":"queued-or-dropped"})}function Epe({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 Cpe(e){var i,s;if(e.session.mode!=="pty"||e.session.kind==="terminal"||e.session.provider==="codex")return null;const t=WC(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 kpe({target:e,sendRawInput:t,history:n}){return Epe({sessionId:e.sessionId,enabled:e.enabled,waiting:e.waiting,approvalRequestId:e.approvalRequestId,approvalScopeKey:e.key,history:n,sendRawInput:t}),null}function Tpe({sendRawInput:e=Mo}){const t=Ae(d=>d.connected),n=Ae(d=>d.proxyOnline),r=Ae(d=>d.selectedProxyId),i=Ht(d=>d.sessions),s=Ht(d=>d.agentStatusBySessionId),o=Ht(d=>d.ptyAutoYesBySessionKey),l=b.useRef(new Map),u=i.map(d=>Cpe({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(kpe,{target:d,sendRawInput:e,history:l.current},d.key))})}function Rpe(e,t){return e.some(n=>n.sessionId===t)?e:[...e,{sessionId:t}]}var Xc=function(e,t){return Number(e.toFixed(t))},Ape=function(e,t){return t},ir=function(e,t,n){n&&typeof n=="function"&&n(e,t)},Npe=function(e){return-Math.cos(e*Math.PI)/2+.5},Mpe=function(e){return e},Ppe=function(e){return e*e},Ipe=function(e){return e*(2-e)},Ope=function(e){return e<.5?2*e*e:-1+(4-2*e)*e},Lpe=function(e){return e*e*e},Dpe=function(e){return--e*e*e+1},Bpe=function(e){return e<.5?4*e*e*e:(e-1)*(2*e-2)*(2*e-2)+1},zpe=function(e){return e*e*e*e},jpe=function(e){return 1- --e*e*e*e},Fpe=function(e){return e<.5?8*e*e*e*e:1-8*--e*e*e*e},$pe=function(e){return e*e*e*e*e},Hpe=function(e){return 1+--e*e*e*e*e},Upe=function(e){return e<.5?16*e*e*e*e*e:1+16*--e*e*e*e*e},$F={easeOut:Npe,linear:Mpe,easeInQuad:Ppe,easeOutQuad:Ipe,easeInOutQuad:Ope,easeInCubic:Lpe,easeOutCubic:Dpe,easeInOutCubic:Bpe,easeInQuart:zpe,easeOutQuart:jpe,easeInOutQuart:Fpe,easeInQuint:$pe,easeOutQuint:Hpe,easeInOutQuint:Upe},HF=function(e){typeof e=="number"&&cancelAnimationFrame(e)},No=function(e){e.mounted&&(HF(e.animation),e.isAnimating=!1,e.animation=null,e.velocity=null)};function UF(e,t,n,r){if(e.mounted){var i=new Date().getTime(),s=1;No(e),e.animation=function(){if(!e.mounted)return HF(e.animation);var o=new Date().getTime()-i,l=o/n,u=$F[t],d=u(l);o>=n?(r(s),e.animation=null):e.animation&&(r(d),requestAnimationFrame(e.animation))},requestAnimationFrame(e.animation)}}function Wpe(e){var t=e.scale,n=e.positionX,r=e.positionY;return!(Number.isNaN(t)||Number.isNaN(n)||Number.isNaN(r))}function vc(e,t,n,r){var i=Wpe(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,y=t.positionY-d;n===0?s(t.scale,t.positionX,t.positionY):UF(e,r,n,function(g){g!==1?e.isAnimating=!0:e.isAnimating=!1;var _=l+f*g,w=u+h*g,S=d+y*g;s(_,w,S)})}}function qpe(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 Vpe=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,y=u;return{minPositionX:d,maxPositionX:f,minPositionY:h,maxPositionY:y,scaleWidthFactor:l,scaleHeightFactor:u}},jk=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=qpe(n,r,t),u=l.wrapperWidth,d=l.wrapperHeight,f=l.newContentWidth,h=l.newContentHeight,y=l.newDiffWidth,g=l.newDiffHeight,_=Vpe(u,f,y,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,k=S.maxPositionX,R=S.minPositionY,A=S.maxPositionY;return x!=null&&(_.minPositionX=u*(1-t)+x*t),k!=null&&(_.maxPositionX=k*t),R!=null&&(_.minPositionY=d*(1-t)+R*t),A!=null&&(_.maxPositionY=A*t),_},Gp=function(e,t,n,r){return r?e<t?Xc(t,2):e>n?Xc(n,2):Xc(e,2):Xc(e,2)},lf=function(e,t){var n=jk(e,t);return e.bounds=n,n};function Am(e,t,n,r,i,s,o){var l=n.minPositionX,u=n.minPositionY,d=n.maxPositionX,f=n.maxPositionY,h=0,y=0;o&&(h=i,y=s);var g=Gp(e,l-h,d+h,r),_=Gp(t,u-y,f+y,r);return{x:g,y:_}}function e_(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,y=d-n*f,g=Am(h,y,i,s,0,0,null);return g}var WI=1e-7;function Nm(e,t,n,r,i){var s=i?r:0,o=Math.max(t-s,WI),l=n+s;return!Number.isNaN(n)&&e>=l?l:!Number.isNaN(t)&&e<=o?o:Math.max(e,WI)}var qI=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=Mm(s,n);return!(d||s.getAttribute("draggable")==="true"||s.getAttribute("contenteditable")==="true"||s.isContentEditable)},VI=function(e){var t=e.isInitialized,n=e.isPanning,r=e.setup,i=r.panning.disabled,s=t&&n&&!i;return!!s},Ype=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}},Kpe=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 Gpe(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,y=f.minPositionX,g=f.maxPositionY,_=f.minPositionY,w=n>h||n<y,S=r>g||r<_,x=n>h?d.offsetWidth:e.setup.minPositionX||0,k=r>g?d.offsetHeight:e.setup.minPositionY||0,R=e_(e,x,k,i,e.bounds,l||u),A=R.x,O=R.y;return{scale:i,positionX:w?A:n,positionY:S?O:r}}}function WF(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 y=Am(t,n,l,s,r,i,o),g=y.x,_=y.y;e.setState(d,g,_)}}var Xpe=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,y=o?u:f,g=l?d:h;return{x:y,y:g}},nc=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},ql;(function(e){e.TRACK_PAD="track_pad",e.MOUSE="mouse",e.TOUCH="touch"})(ql||(ql={}));var Zpe=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},Jpe=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 Qpe(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 YI(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:Gp(e,s,o,i)}function eme(e){var t=1,n=e.offsetWidth/window.innerWidth;return Number.isNaN(n)?t:Math.min(t,n)}var R0=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 tme(e,t,n){var r,i,s=Zpe(e);if(s){var o=e.lastMousePosition,l=e.velocityTime,u=e.setup,d=e.wrapperComponent,f=u.velocityAnimation,h=f.maxStrengthMouse,y=f.maxStrengthTouch,g=f.sensitivityTouch,_=f.sensitivityMouse,w=Date.now();if(o&&l&&d){var S=eme(d),x=(r={},r[ql.TOUCH]=g,r[ql.MOUSE]=_,r)[n],k=(i={},i[ql.TOUCH]=y,i[ql.MOUSE]=h,i)[n],R=t.x-o.x,A=t.y-o.y,O=R0(R/S,k,x),T=R0(A/S,k,x),M=w-l,z=R*R+A*A,Y=R0(Math.sqrt(z)/M,k,x);e.velocity={velocityX:O,velocityY:T,total:Y}}e.lastMousePosition=t,e.velocityTime=w}}function nme(e){var t=e.velocity,n=e.bounds,r=e.setup,i=e.wrapperComponent,s=Jpe(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,y=n.minPositionY,g=r.limitToBounds,_=r.autoAlignment,w=r.zoomAnimation,S=r.panning,x=S.lockAxisY,k=S.lockAxisX,R=w.animationType,A=_.sizeX,O=_.sizeY,T=_.velocityAlignmentTime,M=T,z=Qpe(e,u),Y=Math.max(z,M),U=nc(e,A),G=nc(e,O),I=U*i.offsetWidth/100,N=G*i.offsetHeight/100,L=d+I,B=f-I,P=h+N,D=y-N,F=e.state,q=new Date().getTime();UF(e,R,Y,function(j){var V=e.state,K=V.scale,$=V.positionX,te=V.positionY,re=new Date().getTime()-q,ee=re/M,X=$F[_.animationType],ae=1-X(Math.min(1,ee)),ne=1-j,ce=$+o*ne,_e=te+l*ne,xe=YI(ce,F.positionX,$,k,g,f,d,B,L,ae),We=YI(_e,F.positionY,te,x,g,y,h,D,P,ae);if($!==ce||te!==_e){e.setState(K,xe,We);var De=e.props.onPanning;De&&De(Jn(e),{})}})}}function KI(e,t){var n=e.state,r=n.scale,i=n.positionX,s=n.positionY;e.panStartPosition={x:i,y:s},No(e),lf(e,r),window.TouchEvent!==void 0&&t instanceof TouchEvent?Kpe(e,t):Ype(e,t)}function qF(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 y=Gpe(e);y&&vc(e,y,d,f)}}function GI(e,t,n,r){var i=e.startCoords,s=e.setup,o=s.autoAlignment,l=o.sizeX,u=o.sizeY;if(i){var d=Xpe(e,t,n),f=d.x,h=d.y,y=nc(e,l),g=nc(e,u);tme(e,{x:f,y:h},r),WF(e,f,h,y,g)}}function rme(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 y=(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||y<_||g<w,x=!t&&n&&n.total>.1&&S;x?nme(e):qF(e)}}function Fk(e,t,n,r){var i=e.setup,s=i.minScale,o=i.maxScale,l=i.limitToBounds,u=Nm(Xc(t,2),s,o,0,!1),d=lf(e,u),f=e_(e,n,r,u,d,l),h=f.x,y=f.y;return{scale:u,positionX:h,positionY:y}}function $k(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,y=d.animationType,g=r>=o&&r<=l,_=f||g;if((r>=1||u)&&qF(e),!(_||!i||!e.mounted)){var w=t||i.offsetWidth/2,S=n||i.offsetHeight/2,x=r<o?o:l,k=Fk(e,x,w,S);k&&vc(e,k,h,y)}}var ho=function(){return ho=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},ho.apply(this,arguments)};function XI(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 A0={scale:1,positionX:0,positionY:0},Yc={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"}},L1={wrapperClass:"react-transform-wrapper",contentClass:"react-transform-component"},VF=function(e){var t,n,r,i,s,o,l,u,d,f=Math.max((t=e.minScale)!==null&&t!==void 0?t:Yc.minScale,1e-7),h=(n=e.maxScale)!==null&&n!==void 0?n:Yc.maxScale,y=(r=e.initialScale)!==null&&r!==void 0?r:A0.scale,g=Math.min(Math.max(y,f),h),_=Gp((i=e.initialPositionX)!==null&&i!==void 0?i:A0.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=Gp((l=e.initialPositionY)!==null&&l!==void 0?l:A0.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}},ZI=function(e){var t=ho({},Yc);return Object.keys(e).forEach(function(n){var r=n,i=typeof e[r]<"u",s=typeof Yc[r]<"u";if(s&&i){var o=Object.prototype.toString.call(Yc[r]),l=o==="[object Object]",u=o==="[object Array]";l?t[r]=ho(ho({},Yc[r]),e[r]):u?t[r]=XI(XI([],Yc[r],!0),e[r]):t[r]=e[r]}}),t.minScale<=0&&(t.minScale=1e-7),t},YF=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,y=Nm(Xc(h,3),l,o,f,!1);return y};function KF(e,t,n,r,i){var s,o,l=e.wrapperComponent,u=e.state,d=u.scale,f=u.positionX,h=u.positionY,y=e.setup.zoomAnimation;if(!l)return console.error("No WrapperComponent found");var g=y.disabled?0:r,_=l.offsetWidth,w=l.offsetHeight,S=(_/2-f)/d,x=(w/2-h)/d,k=YF(e,t,n),R=Fk(e,k,S,x);if(!R)return console.error("Error during zoom event. New transformation state was not calculated.");var A=e.props,O=A.onZoomStart,T=A.onZoom,M=A.onZoomStop,z=new MouseEvent("mousemove",{bubbles:!0}),Y=Jn(e);ir(Y,z,O),ir(Y,z,T),vc(e,R,g,i);var U=(o=(s=l.ownerDocument)===null||s===void 0?void 0:s.defaultView)!==null&&o!==void 0?o:typeof window<"u"?window:null;U&&U.setTimeout(function(){e.mounted&&ir(Jn(e),z,M)},g)}function GF(e,t,n,r){var i,s,o=e.setup,l=e.wrapperComponent,u=e.contentComponent,d=o.limitToBounds,f=o.centerOnInit,h=VF(e.props),y=e.state,g=y.scale,_=y.positionX,w=y.positionY;if(l){var S=h.positionX,x=h.positionY;if(f&&u){var k=Hk(h.scale,l,u);S=k.positionX,x=k.positionY}var R=jk(e,h.scale),A=Am(S,x,R,d,0,0,l),O={scale:h.scale,positionX:A.x,positionY:A.y};if(!(g===h.scale&&_===h.positionX&&w===h.positionY)){r==null||r();var T=e.props,M=T.onZoomStart,z=T.onZoom,Y=T.onZoomStop,U=new MouseEvent("mousemove",{bubbles:!0}),G=Jn(e);ir(G,U,M),ir(G,U,z),vc(e,O,t,n);var I=(s=(i=l.ownerDocument)===null||i===void 0?void 0:i.defaultView)!==null&&s!==void 0?s:typeof window<"u"?window:null;I&&I.setTimeout(function(){e.mounted&&ir(Jn(e),U,Y)},t)}}}function ime(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 sme(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 y=s.getBoundingClientRect(),g=t.getBoundingClientRect(),_=ime(t,s,o,l),w=_.x,S=_.y,x=g.width/l.scale,k=g.height/l.scale,R=s.offsetWidth/x,A=s.offsetHeight/k,O=Nm(n||Math.min(R,A),f,h,0,!1),T=(y.width-x*O)/2,M=(y.height-k*O)/2,z=(y.left-w)*O+T+r,Y=(y.top-S)*O+M+i,U=jk(e,O),G=Am(z,Y,U,d,0,0,s),I=G.x,N=G.y;return{positionX:I,positionY:N,scale:O}}var ome=function(e){return function(t,n,r){t===void 0&&(t=.5),n===void 0&&(n=300),r===void 0&&(r="easeOut"),KF(e,1,t,n,r)}},ame=function(e){return function(t,n,r){t===void 0&&(t=.5),n===void 0&&(n=300),r===void 0&&(r="easeOut"),KF(e,-1,t,n,r)}},lme=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,y=e.setup.disabled;if(!(y||!f||!h)){var g={positionX:Number.isNaN(t)?l:t,positionY:Number.isNaN(n)?u:n,scale:Number.isNaN(r)?d:r};vc(e,g,i,s)}}},cme=function(e){return function(t,n){t===void 0&&(t=200),n===void 0&&(n="easeOut"),GF(e,t,n)}},ume=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=Hk(t||i.scale,s,o);vc(e,l,n,r)}}},dme=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=sme(e,u,n,s,o);vc(e,d,r,i)}}},D1=function(e){return{instance:e,state:e.state,zoomIn:ome(e),zoomOut:ame(e),setTransform:lme(e),resetTransform:cme(e),centerView:ume(e),zoomToElement:dme(e)}},fme=function(e){return{instance:e,state:e.state}},Jn=function(e){var t={};return Object.assign(t,fme(e)),Object.assign(t,D1(e)),t},N0=!1;function M0(){try{var e={get passive(){return N0=!0,!1}};return e}catch{return N0=!1,N0}}var Ev=".".concat(L1.wrapperClass),Mm=function(e,t){return t.some(function(n){return e.matches("".concat(Ev," ").concat(n,", ").concat(Ev," .").concat(n,", ").concat(Ev," ").concat(n," *, ").concat(Ev," .").concat(n," *"))})},Xp=function(e){e&&clearTimeout(e)},hme=function(e){return Number.parseFloat(e.toFixed(8))},XF=function(e,t,n){var r=hme(n);return"translate(".concat(e,"px, ").concat(t,"px) scale(").concat(r,")")},Hk=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 pme(e,t){e!=null&&(typeof e=="function"?e(t):e.current=t)}function mme(e){return function(t){e.forEach(function(n){typeof n=="function"?n(t):n!=null&&(n.current=t)})}}var ZF=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=Mm(d,o);if(h)return!1;var y=e.isPressingKeys(e.setup.wheel.activationKeys);return!!y},gme=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=ZF(e,t);if(l)return!1;var u=t.target,d=Mm(u,o);if(d)return!1;var f=e.isPressingKeys(s);return!!f},vme=function(e){return e?e.deltaY<0?1:-1:0};function yme(e,t){var n=vme(e),r=Ape(t,n);return r}function JF(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 bme=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,y=f.size,g=f.disabled;if(!o)throw new Error("Wrapper is not mounted");var _=s+t*n,w=r?!1:!g,S=Nm(_,d,u,y,w&&!h);return S},QF=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},_me=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=Mm(o,i);return!u},wme=function(e){var t=e.setup.pinch.disabled,n=e.isInitialized,r=e.pinchStartDistance,i=n&&!t&&r!==null;return!!i},xme=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}},e$=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))},Sme=5,Eme=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,y=d.step;if(!n||r===null)throw new Error("Pinch touches distance was not provided");if(t<0)return e.state.scale;var g=t/r,_=g*n,w=(_-n)*(y/Sme),S=n+w,x=S===1/0?0:Xc(S,10);return Nm(x,o,s,f,!h&&!u)},t$=160,n$=100,Cme=function(e,t){var n=e.props,r=n.onWheelStart,i=n.onZoomStart;e.wheelStopEventTimer||(No(e),ir(Jn(e),t,r),ir(Jn(e),t,i))},kme=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,y=o.wheel,g=o.disablePadding,_=o.smooth,w=h.size,S=h.disabled,x=y.step;if(!s)throw new Error("Component not mounted");t.preventDefault(),t.stopPropagation();var k=yme(t,null),R=_?x*Math.abs(t.deltaY):x,A=bme(e,k,R,!t.ctrlKey);if(u!==A){var O=lf(e,A),T=JF(t,s,u),M=S||w===0||f||g,z=d&&M,Y=e_(e,T.x,T.y,A,O,z),U=Y.x,G=Y.y;e.previousWheelEvent=t,e.setState(A,U,G),ir(Jn(e),t,r),ir(Jn(e),t,i)}},Tme=function(e,t){var n=e.props,r=n.onWheelStop,i=n.onZoomStop;Xp(e.wheelAnimationTimer),e.wheelAnimationTimer=setTimeout(function(){e.mounted&&($k(e,t.x,t.y),e.wheelAnimationTimer=null)},n$);var s=QF(e,t);s&&(Xp(e.wheelStopEventTimer),e.wheelStopEventTimer=setTimeout(function(){e.mounted&&(e.wheelStopEventTimer=null,ir(Jn(e),t,r),ir(Jn(e),t,i))},t$))},Rme=function(e,t){var n=e.props,r=n.onWheelStart,i=n.onPanningStart;e.wheelStopEventTimer||(No(e),ir(Jn(e),t,r),ir(Jn(e),t,i))},Ame=function(e,t){var n=e.props,r=n.onWheelStop,i=n.onPanningStop;Xp(e.wheelAnimationTimer),e.wheelAnimationTimer=setTimeout(function(){e.mounted&&($k(e,t.x,t.y),e.wheelAnimationTimer=null)},n$);var s=QF(e,t);s&&(Xp(e.wheelStopEventTimer),e.wheelStopEventTimer=setTimeout(function(){e.mounted&&(e.wheelStopEventTimer=null,ir(Jn(e),t,r),ir(Jn(e),t,i))},t$))},r$=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}},Nme=function(e,t){var n=e$(t);e.pinchStartDistance=n,e.lastDistance=n,e.pinchStartScale=e.state.scale,e.isPanning=!1,e.isPinching=!0,e.pinchPreviousCenter=r$(t),No(e)},Mme=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,y=l.pinch,g=l.panning,_=f.disabled,w=f.size,S=y.allowPanning;if(!(r===null||!n)){var x=xme(t,o,n);if(!(!Number.isFinite(x.x)||!Number.isFinite(x.y))){var k=e$(t),R=Eme(e,k),A=r$(t),O=o/R,T=(A.x-((s==null?void 0:s.x)||0))*O,M=(A.y-((s==null?void 0:s.y)||0))*O;if(!(R===o&&T===0&&M===0)){e.pinchPreviousCenter=A;var z=lf(e,R),Y=_||w===0||d,U=u&&Y,G=e_(e,x.x,x.y,R,z,U),I=G.x,N=G.y;if(e.pinchMidpoint=x,e.lastDistance=k,g.disabled||!S)e.setState(R,I,N);else{var L=h.sizeX,B=h.sizeY,P=nc(e,L,R),D=nc(e,B,R),F=I+T,q=N+M,j=Am(F,q,z,u,P,D,i),V=j.x,K=j.y;e.setState(R,V,K)}}}}},Pme=function(e){var t=e.pinchMidpoint;e.velocity=null,e.lastDistance=null,e.pinchMidpoint=null,e.pinchStartScale=null,e.pinchStartDistance=null,e.isPinching=!1,$k(e,t==null?void 0:t.x,t==null?void 0:t.y)},i$=function(e,t){var n=e.props.onZoomStop,r=e.setup.doubleClick.animationTime;Xp(e.doubleClickStopEventTimer),e.doubleClickStopEventTimer=setTimeout(function(){e.doubleClickStopEventTimer=null,ir(Jn(e),t,n)},r)},Ime=function(e,t){var n=e.props,r=n.onZoomStart,i=n.onZoom,s=e.setup.doubleClick,o=s.animationTime,l=s.animationType;ir(Jn(e),t,r),GF(e,o,l,function(){return ir(Jn(e),t,i)}),i$(e,t)};function Ome(e,t){return e==="toggle"?t===1?1:-1:e==="zoomOut"?-1:1}function Lme(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,y=f.mode,g=f.step,_=f.animationTime,w=f.animationType;if(!h&&!r){if(y==="reset")return Ime(e,t);if(!s)return console.error("No ContentComponent found");var S=Ome(y,e.state.scale),x=YF(e,S,g);if(o!==x){ir(Jn(e),t,u);var k=JF(t,s,o),R=Fk(e,x,k.x,k.y);if(!R)return console.error("Error during zoom event. New transformation state was not calculated.");ir(Jn(e),t,d),vc(e,R,_,w),i$(e,t)}}}var Dme=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=Mm(u,l);return!h},Bme=(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&&lf(n,n.state.scale),n.setup=ZI(r)},this.initializeWindowEvents=function(){var r,i,s,o,l=M0(),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=M0(),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=M0();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(Jn(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(Jn(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=ZF(n,r);s&&(Cme(n,r),kme(n,r),Tme(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=gme(n,r);if(u){r.preventDefault(),r.stopPropagation();var d=n.state,f=d.positionX,h=d.positionY,y=f-r.deltaX,g=h-r.deltaY,_=o?f:y,w=l?h:g,S=n.setup.autoAlignment,x=S.sizeX,k=S.sizeY,R=nc(n,x),A=nc(n,k);_===f&&w===h||(Rme(n,r),WF(n,_,w,R,A),ir(Jn(n),r,i),Ame(n,r))}},this.onPanningStart=function(r){var i=n.setup.disabled,s=n.props.onPanningStart;if(!i){n.syncModifierKeys(r);var o=qI(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),KI(n,r),ir(Jn(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=VI(n);if(o){var l=n.isPressingKeys(n.setup.panning.activationKeys);l&&(r.preventDefault(),r.stopPropagation(),GI(n,r.clientX,r.clientY,ql.MOUSE),ir(Jn(n),r,s))}}},this.onPanningStop=function(r){var i=n.setup.panning.velocityDisabled,s=n.props.onPanningStop;n.isPanning&&(rme(n,i),ir(Jn(n),r,s))},this.onPinchStart=function(r){var i=n.setup.disabled,s=n.props.onPinchStart;if(!i){var o=_me(n,r);o&&(Nme(n,r),No(n),ir(Jn(n),r,s))}},this.onPinch=function(r){var i=n.setup.disabled,s=n.props.onPinch;if(!i){var o=wme(n);o&&(r.preventDefault(),r.stopPropagation(),Mme(n,r),ir(Jn(n),r,s))}},this.onPinchStop=function(r){var i=n.props.onPinchStop;n.pinchStartScale&&(Pme(n),ir(Jn(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,y=f.length===2,g=qI(n,r);if(h){if(!g)return;No(n),KI(n,r),ir(Jn(n),r,l)}y&&n.onPinchStart(r)}}},this.onTouchPanning=function(r){var i=n.setup.disabled,s=n.props.onPanning;if(n.isPanning&&r.touches.length===1){if(i)return;var o=VI(n);if(!o)return;r.cancelable&&r.preventDefault(),r.stopPropagation();var l=r.touches[0];GI(n,l.clientX,l.clientY,ql.TOUCH),ir(Jn(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=Dme(n,r);s&&Lme(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=Hk(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):XF(r,i,s)},this.getContext=function(){return Jn(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:Jn(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=Jn(n);n.onChangeCallbacks.forEach(function(d){return d(u)}),ir(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,lf(n,n.state.scale),n.handleInitializeWrapperEvents(r),n.handleInitialize(i),n.initializeWindowEvents(),n.isInitialized=!0;var s=Jn(n);ir(s,void 0,n.props.onInit),pme(n.props.ref,s)},this.props=t,this.setup=ZI(this.props),this.state=VF(this.props)}return e})(),t_=gt.createContext(null),zme=function(e,t){return typeof e=="function"?e(t):e},jme=gt.forwardRef(function(e,t){var n=b.useRef(new Bme(e)).current,r=zme(e.children,D1(n));return b.useImperativeHandle(t,function(){return D1(n)},[n]),b.useEffect(function(){n.update(e)},[n,e]),m.jsx(t_.Provider,ho({value:n},{children:r}))});gt.forwardRef(function(e,t){var n=b.useRef(null),r=b.useContext(t_);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",ho({},e,{ref:mme([n,t])}))});function Fme(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 $me=`.transform-component-module_wrapper__SPB86 {
|
|
603
603
|
position: relative;
|
|
@@ -736,7 +736,7 @@ WARNING: This link could potentially be dangerous`)){let n=window.open();if(n){t
|
|
|
736
736
|
`:"\r":e.key==="Backspace"?"":e.key==="Tab"?e.shiftKey?"\x1B[Z":" ":e.key==="Escape"?"\x1B":e.key==="ArrowUp"?_p("\x1B[A",t):e.key==="ArrowDown"?_p("\x1B[B",t):e.key==="ArrowRight"?_p("\x1B[C",t):e.key==="ArrowLeft"?_p("\x1B[D",t):e.key==="Delete"?"\x1B[3~":e.key==="Home"?"\x1B[H":e.key==="End"?"\x1B[F":null}function A1e(e){const{sessionId:t,active:n=!0,containerEl:r,spacerRef:i,xtermHostRef:s,selectionHandleLayerRef:o,mobileControlsHeight:l}=e,u=wSe(),d=u.markDisconnected,f=CSe(),h=g1e(),{openImagePreview:y}=Wk(),g=b.useRef(null),_=b.useRef([]),w=b.useRef(null),S=b.useRef(null),x=b.useRef(!1),k=b.useRef([]),R=b.useRef(null),A=b.useRef(null),O=b.useRef(n),T=b.useRef(n),M=b.useRef(!1),z=b.useRef(!1),Y=b.useRef(!1),U=b.useRef(!1),G=b.useRef(null),I=b.useRef(null),N=b.useRef(null),L=b.useRef(null),B=b.useRef({keyboardOpen:!1,controlsVisible:!1}),P=b.useRef(!1),D=b.useRef(!1),F=b.useRef(!1),q=b.useRef({keyboardOffset:0,hasSeenSoftKeyboard:!1,showMobilePtyControls:!1,touchEditingSurface:!1,ptyInputFocused:!1,containerPaddingBottom:0,mobileControlsBottomInset:0}),[j,V]=b.useState({scrollTop:0,scrollLeft:0,scrollHeight:0,scrollWidth:0,clientHeight:0,clientWidth:0,scrollable:!1,horizontalScrollable:!1}),[K,$]=b.useState(!1),[te,re]=b.useState(!1),[ee,X]=b.useState({resultIndex:-1,resultCount:0}),ae=Ae(Be=>Be.connected),ne=Ae(Be=>Be.proxyOnline),ce=Ae(Be=>Be.ptyFontSize),_e=Ae(Be=>Be.inputModePreference),xe=Ae(Be=>Be.adaptiveInputModality),We=Ae(Be=>Be.setAdaptiveInputModality),De=xe==="hardware",Pt=yo("(pointer: coarse), (hover: none)"),{bottomOffset:tt,layoutBottomInset:lt}=vT(),$e=_e==="hardware",Fe=E1e({touchEditingSurface:Pt,inputModePreference:_e,detectedPhysicalKeyboard:De,softKeyboardDetected:tt>0}),Te=Pt&&!Fe,Ke=Fe?0:tt,Xe=Ke>0,Se=Fe?0:lt,[it,vt]=b.useState(()=>ae&&ne);P.current=Fe,O.current=n,M.current=u.ready,z.current=ae&≠const ge=b.useCallback(()=>O.current&&M.current&&z.current,[]),Ge=b.useCallback(Be=>{const qe=Ht.getState().sessions.find(Me=>Me.sessionId===t);if((qe==null?void 0:qe.mode)!=="pty"||qe.ptyOwner!=="proxy-hosted")return;const at=g.current,_t=s.current,Ee=Ft;if(!ge()||!at||!_t||!r||!Ee){Ue.error("终端尚未就绪");return}const dt=_.current.at(-1)??at,xt=Be==="fit"?$we(r,_t,at):Fwe(dt,Be);if(!xt){Ue.error("无法获取终端显示区域的尺寸");return}xt.cols===dt.cols&&xt.rows===dt.rows||(Ee.sendControl({type:"terminal_resize_request",sessionId:t,...xt})?(_.current.push(xt),Ht.getState().setPtyGeometry(t,xt)):Ue.error("终端尺寸调整失败,请检查连接"))},[ge,r,t,s]);b.useEffect(()=>{(!n||!u.ready||!ae||!ne)&&(_.current=[]);const Be=_.current.at(-1)??g.current;Ht.getState().setPtyGeometry(t,u.ready&&ae&&ne&&Be?{cols:Be.cols,rows:Be.rows}:null)},[n,u.ready,ae,ne,t]),b.useEffect(()=>{ae&&ne&&vt(!0)},[ae,ne]),b.useEffect(()=>{Ke>0&&$(!0)},[Ke]);const ve=ESe({containerEl:r,xtermHostRef:s,terminalRef:g}),{ptyInputFocused:rt,suppressPtyFocus:ht,focusPtyInput:Mt,handleFocusCapture:It,handleBlurCapture:sn}=ve,Gt=x1e({softKeyboardEditingSurface:Te,ptyInputFocused:rt,keyboardOpen:Xe});q.current={keyboardOffset:Ke,hasSeenSoftKeyboard:K,showMobilePtyControls:Gt,touchEditingSurface:Pt,ptyInputFocused:rt,containerPaddingBottom:q.current.containerPaddingBottom,mobileControlsBottomInset:Se};const on=f.clearNewFramesWhileAway;I.current||(I.current=AL(()=>{var Be;(Be=A.current)==null||Be.relayout()}));const wt=b.useCallback(()=>{F.current=!1},[]);N.current||(N.current=AL(()=>{var qe,at;const Be=L.current??{reason:"rawInput",force:!1};L.current=null,Be.force&&wt(),(qe=A.current)==null||qe.traceRawInputFollowFire(),(at=A.current)==null||at.scrollToBottom(Be.reason,Be.force?{force:!0}:void 0),on()}));const gn=b.useCallback(()=>{if(F.current)return;const Be=A.current;Be&&Be.preparePageResumeRestore(),F.current=!0},[]),Bt=b.useCallback(()=>{if(!F.current||document.visibilityState==="hidden"||!O.current||!M.current)return;const Be=A.current;Be&&(Be.restorePageResume(),on(),F.current=!1)},[on]);b.useEffect(()=>()=>{var Be,qe;(Be=I.current)==null||Be.dispose(),(qe=N.current)==null||qe.dispose(),I.current=null,N.current=null},[]),b.useEffect(()=>{const Be=()=>{gn()},qe=()=>{if(document.visibilityState==="hidden"){Be();return}Bt()};return document.addEventListener("visibilitychange",qe),window.addEventListener("pagehide",Be),window.addEventListener("pageshow",Bt),window.addEventListener("focus",Bt),()=>{document.removeEventListener("visibilitychange",qe),window.removeEventListener("pagehide",Be),window.removeEventListener("pageshow",Bt),window.removeEventListener("focus",Bt)}},[gn,Bt]),b.useLayoutEffect(()=>{const Be=T.current;if(T.current=n,!n){Be&&gn();return}(!Be||F.current)&&u.ready&&Bt()},[n,u.ready,gn,Bt]);const nn=b.useCallback((Be="rawInput",qe)=>{var Ee,dt;const at=L.current,_t=(at==null?void 0:at.force)===!0||(qe==null?void 0:qe.force)===!0;L.current={reason:(qe==null?void 0:qe.force)===!0||!at?Be:at.reason,force:_t},(Ee=A.current)==null||Ee.traceRawInputFollowScheduled(Be),(dt=N.current)==null||dt.schedule()},[]),Rn=b.useCallback((Be,qe)=>{var at,_t;!Be||_L(Be)||((at=A.current)==null||at.resumeHorizontalCursorFollow(qe),!(!Be.includes("\r")&&!Be.includes(`
|
|
737
737
|
`))&&((_t=A.current)==null||_t.resetHorizontalScroll(qe,{holdUntilCursorVisible:!0})))},[]),$n=b.useCallback(()=>P.current?"submit":"linefeed",[]),Qn=b.useCallback(()=>P.current,[]);b.useEffect(()=>{if(!n||_e!=="auto"||!Pt)return;const Be=at=>{const _t=s.current,Ee=r;return at instanceof Node?_t!=null&&_t.contains(at)||at===document.body||at===document.documentElement?!0:Ee!=null&&Ee.contains(at)?at instanceof HTMLElement?at.closest('a,button,input,textarea,select,[contenteditable="true"],[role="button"],[role="textbox"]')===null:!0:!1:at===window},qe=at=>{var dt,xt;if(!C1e({active:O.current,touchEditingSurface:Pt,key:at.key,code:at.code,altKey:at.altKey,ctrlKey:at.ctrlKey,metaKey:at.metaKey,isComposing:at.isComposing,targetAcceptsPtyInput:Be(at.target)}))return;We("hardware"),P.current=!0,(dt=g.current)==null||dt.focus();const _t=s.current;if(at.target instanceof Node&&(_t!=null&&_t.contains(at.target)))return;const Ee=R1e(at,(xt=g.current)==null?void 0:xt.modes);!Ee||!ge()||(at.preventDefault(),at.stopPropagation(),Mo(t,Ee),nn("physicalKeyboard"),Rn(Ee,"physicalKeyboardEnter"))};return window.addEventListener("keydown",qe,!0),()=>window.removeEventListener("keydown",qe,!0)},[n,ge,r,_e,Rn,nn,t,We,Pt,s]);const Pn=b.useCallback(Be=>{const qe=Ft;if(!qe){Ue.error("请先连接开发机");return}const at=Ue.loading(`下载 ${Be} ...`);Uk({relay:qe,sessionId:t,path:Be}).then(_t=>{_t.ok?Ue.success(`已开始下载 ${Be}`,{id:at}):Ue.error(_t.error,{id:at})}).catch(_t=>{Ue.error(_t instanceof Error?_t.message:String(_t),{id:at})})},[t]),W=b.useCallback(Be=>{const qe=g.current;return qe?J0e(qe,k.current,Be):!1},[]),ie=b.useCallback(Be=>{const qe=g.current;return qe?Z0e(qe,k.current,Be):!1},[]),oe=m1e({terminalRef:g,xtermHostRef:s,selectionHandleLayerRef:o,scrollControllerRef:A,containerEl:r,keyboardOffset:Ke,ptyFontSize:ce,suppressPtyFocus:ht,focusPtyInput:Mt,onTap:W,isTapCandidate:ie,onDownloadPath:Pn,onPreviewPath:y}),ue=oe.clearManagedPtySelection,be=oe.clearPtySelection;D.current=oe.hasPtySelection();const Z=b.useCallback(()=>{const Be=g.current,qe=S.current,at=x.current&&Be?vL(Be.getSelectionPosition(),Be.cols):null;qe==null||qe.render(at)},[]),se=_1e({sessionId:t,terminalRef:g,onAfterPaste:()=>nn("paste")}),fe=b.useCallback(Be=>{if(!ge()){Be.preventDefault();return}se(Be)},[ge,se]),[pe,J]=b.useState(!1),le=b.useCallback(Be=>{Be.dataTransfer.types.includes("Files")&&(Be.preventDefault(),J(qe=>qe||!0))},[]),he=b.useCallback(Be=>{Be.currentTarget.contains(Be.relatedTarget)||J(!1)},[]),Oe=b.useCallback(async Be=>{var Ee,dt;const qe=(Ee=Be.dataTransfer.files)==null?void 0:Ee[0];if(!qe||(Be.preventDefault(),J(!1),!ge()))return;const at=Ft;if(!at){Ue.error("请先连接开发机");return}const _t=await nm({relay:at,sessionId:t,file:qe});_t&&(Mo(t,`@${_t} `),(dt=A.current)==null||dt.resumeHorizontalCursorFollow("dropUpload"),nn("dropUpload"))},[ge,nn,t]),Je=b.useCallback(Be=>{var at;if(!ge()){Be.preventDefault();return}const qe=Be.target;qe instanceof Element&&qe.closest(".xterm")||(Be.preventDefault(),(at=g.current)==null||at.focus())},[ge]);b.useEffect(()=>{if(!it)return;const Be=s.current,qe=Ua,at=Ft,_t=r,Ee=i.current;if(!Be||!qe||!at||!_t||!Ee)return;let dt=null,xt=null,Me=null,ft=null,Lt=null,rn=null,dn=null,Ut=null,wn=null;const Le=f0e({host:Be,sessionId:t,ws:qe,relay:at,scheduleAutoFocus:Te?()=>{}:Ne=>{requestAnimationFrame(()=>{OL(s.current)&&Ne()})},createTerminal:async Ne=>{const Ze=await D6(Ne,{fontSize:Ae.getState().ptyFontSize});return wn=Ze.serializeAddon,Ze},attachRawInput:(Ne,Ze,kt)=>bxe(Ne,Ze,{...kt,getPlainEnterBehavior:$n,isPhysicalKeyboardMode:Qn,physicalKeyboardMode:$e}),isInputEnabled:ge,canFocus:ge,onTerminalReady:Ne=>{be();const Ze=Ne;g.current=Ze,_.current=[],dn=Ze.onResize(({cols:qn,rows:Sr})=>{const zt=_.current,ri=zt.findIndex(_r=>_r.cols===qn&&_r.rows===Sr);_.current=ri>=0?zt.slice(ri+1):[],M.current&&z.current&&Ht.getState().setPtyGeometry(t,_.current.at(-1)??{cols:qn,rows:Sr})});const kt=new uve({highlightLimit:1e3});Ze.loadAddon(kt),w.current=kt,Lt=kt.onDidChangeResults(qn=>{X(qn),Z()}),re(!0);const Xt=N0e(Ze,y);dt=Xt.dispose;const Rt=W0e(Ze,Pn);xt=Rt.dispose,k.current=[Xt.provider,Rt.provider],mSe(()=>g.current);const On=Hwe(Ze),sr=Xwe(Be,{serializeRangeAsHtml:(qn,Sr)=>(wn==null?void 0:wn.serializeAsHTML({range:{startLine:qn,endLine:Math.min(Sr,Math.max(0,Ze.buffer.active.length-1)),startCol:0},includeGlobalBackground:!0,onlySelection:!1,scrollback:0}))??"",getSerializedCell:(qn,Sr)=>{var ri;const zt=(ri=Ze.buffer.active.getLine(qn))==null?void 0:ri.getCell(Sr);return zt?{text:zt.getWidth()===0?"":zt.getChars()||" ",isDim:!!zt.isDim(),isRenderedFgRGB:zt.isInverse()?zt.isBgRGB():zt.isFgRGB()}:null},getSelectionLine:qn=>Ze.buffer.active.getLine(qn)??null,getBufferRowIdentityOffset:On.getOffset});ft=()=>{sr.dispose(),On.dispose()};const Ur=F.current;Ur&&(U.current=!1);const ur=r0e({container:_t,spacer:Ee,host:Be,term:Ze,hasNewFrame:()=>Y.current,consumeNewFrame:()=>{Y.current=!1},hasNewFramesWhileAway:()=>f.hasNewFramesWhileAwayRef.current,setNewFramesWhileAway:f.setHasNewFramesWhileAway,onAtBottomChange:f.handleAtBottomChange,onScrollStateChange:V,initialUserHasVerticalScrollIntent:Ur?!1:U.current,onUserVerticalScrollIntentChange:qn=>{U.current=qn},onTouchReviewStart:ht,onHistoryProjectionChange:qn=>{const Sr=sr.render(qn);return Sr&&Z(),Sr},getBufferRowIdentityOffset:On.getOffset});A.current=ur,Me=ur.dispose,Ut=H6({terminal:Ze,container:_t,getLine:qn=>nb(Be,qn)??Ze.buffer.active.getLine(qn)??null,resolveRange:()=>x.current?vL(Ze.getSelectionPosition(),Ze.cols):null,projectionOnly:!0,overlaySlot:"pty-search-selection-overlay",segmentSlot:"pty-search-selection-segment",selectionBackground:LE.activeMatchBackground,borderColor:LE.activeMatchBorder,opacity:"0.62"}),S.current=Ut,rn=Ze.onSelectionChange(Z),Z(),Ur&&(ur.restorePageResume(),on(),F.current=!1),vSe(()=>{var xo;const qn=Ks=>{if(!Ks)return null;const Gs=Ks.getBoundingClientRect();return{top:Gs.top,bottom:Gs.bottom,height:Gs.height,left:Gs.left,right:Gs.right,width:Gs.width}},Sr=document.querySelector('[data-slot="pty-mobile-controls"]'),zt=document.querySelector("[data-keyboard-offset]"),ri=window.visualViewport,_r=qn(Sr),or=(ri==null?void 0:ri.height)??window.innerHeight;return{...bSe(ur.getDebugProbe,{container:_t,spacer:Ee,host:Be,term:Ze}),mobileLayout:{...q.current,window:{innerHeight:window.innerHeight,outerHeight:window.outerHeight,documentClientHeight:document.documentElement.clientHeight},visualViewport:ri?{height:ri.height,width:ri.width,offsetTop:ri.offsetTop,pageTop:ri.pageTop,scale:ri.scale}:null,chatRoot:{dataKeyboardOffset:(zt==null?void 0:zt.getAttribute("data-keyboard-offset"))??null,rect:qn(zt)},ptyViewRect:qn(_t.parentElement),containerRect:qn(_t),controlsRect:_r,controlsOverflowBelowVisualViewport:_r===null?null:_r.bottom-or,activeElement:document.activeElement instanceof HTMLElement?{tag:document.activeElement.tagName,ariaLabel:document.activeElement.getAttribute("aria-label"),slot:(xo=document.activeElement.closest("[data-slot]"))==null?void 0:xo.getAttribute("data-slot")}:null},frame:{lastWriteAt:G.current,pendingNewFrame:Y.current}}})},onFramePending:()=>{var Ne;Y.current=!0,(Ne=A.current)==null||Ne.markHorizontalLiveFramePending(),U.current&&!f.hasNewFramesWhileAwayRef.current&&f.setHasNewFramesWhileAway(!0)},onFrameWritten:()=>{var Ne;G.current=performance.now(),(Ne=I.current)==null||Ne.schedule()},onRawInput:Ne=>{_L(Ne)||(nn("rawInput",{force:!0}),Rn(Ne,"rawInputEnter"))},onError:Ne=>{const Ze=Ne instanceof Error?Ne.message:String(Ne);Ue.error(`终端初始化失败:${Ze}`)},connectTransportInitially:ae&&ne,...u.transport,onReady:()=>{_.current=[];const Ne=g.current;Ne&&Ht.getState().setPtyGeometry(t,{cols:Ne.cols,rows:Ne.rows}),u.transport.onReady()}});return R.current=Le,()=>{x.current=!1,rn==null||rn.dispose(),dn==null||dn.dispose(),_.current=[],Ht.getState().setPtyGeometry(t,null),Ut==null||Ut.dispose(),S.current===Ut&&(S.current=null),be(),Me==null||Me(),ft==null||ft(),Lt==null||Lt.dispose(),ySe(),dt==null||dt(),xt==null||xt(),k.current=[],gSe(),w.current=null,re(!1),X({resultIndex:-1,resultCount:0}),Le.dispose(),g.current=null,A.current=null,R.current=null}},[t,it,r,i,s,u.transport,f.handleAtBottomChange,f.hasNewFramesWhileAwayRef,f.setHasNewFramesWhileAway,ge,$e,$n,Qn,Pn,y,ht,nn,Rn,be,Z]),b.useEffect(()=>{if(!it)return;const Be=R.current;if(Be){if(!ae||!ne){d(),Be.setTransportActive(!1);return}return p0e(t,n?"active":"background",()=>{var qe;(qe=R.current)==null||qe.setTransportActive(!0)})}},[n,ae,d,ne,t,it]),b.useEffect(()=>{const Be=g.current,qe=A.current;!Be||!qe||zwe(Be,ce,qe.relayout)},[ce]),b.useEffect(()=>{if(!n||!u.ready||Te)return;const Be=requestAnimationFrame(()=>{var qe;OL(s.current)&&((qe=g.current)==null||qe.focus())});return()=>cancelAnimationFrame(Be)},[n,u.ready,Te,s]);const ct=b.useCallback((Be="viewExternal",qe)=>{var at;qe!=null&&qe.force&&wt(),(at=A.current)==null||at.scrollToBottom(Be,qe)},[wt]),ut=b.useCallback(Be=>{var qe;(qe=A.current)==null||qe.scrollToRatio(Be)},[]),St=b.useCallback(Be=>{var qe;(qe=A.current)==null||qe.scrollToXRatio(Be)},[]),Et=b.useCallback(Be=>{var xt;const qe=g.current,at=qe==null?void 0:qe.getSelectionPosition();if(!qe||!at)return;const _t=at.start.y;if(_t>=Be&&_t<Be+qe.rows)return;const Ee=Math.max(0,qe.buffer.active.length-qe.rows);if(Ee===0)return;const dt=Math.max(0,Math.min(Ee,_t-Math.floor(qe.rows/2)));(xt=A.current)==null||xt.scrollToRatio(dt/Ee)},[]),pt=b.useCallback((Be,qe=!1)=>{const at=g.current,_t=w.current;if(!at||!_t||!Be)return Be||(x.current=!1,_t==null||_t.clearDecorations(),at==null||at.clearSelection(),ue(),Z(),X({resultIndex:-1,resultCount:0})),!1;ue(),x.current=!0;const Ee=at.buffer.active.viewportY,dt=_t.findNext(Be,{...UL,incremental:qe});return dt&&Et(Ee),Z(),dt},[ue,Z,Et]),qt=b.useCallback(Be=>{const qe=g.current,at=w.current;if(!qe||!at||!Be)return!1;ue(),x.current=!0;const _t=qe.buffer.active.viewportY,Ee=at.findPrevious(Be,UL);return Ee&&Et(_t),Z(),Ee},[ue,Z,Et]),Ot=b.useCallback(()=>{var Be,qe;x.current=!1,(Be=w.current)==null||Be.clearDecorations(),(qe=g.current)==null||qe.clearSelection(),ue(),Z(),X({resultIndex:-1,resultCount:0})},[ue,Z]),mn=b.useCallback(Be=>{var at,_t;if(!ge())return;const qe=_p(Be,(at=g.current)==null?void 0:at.modes);Mo(t,qe),nn("mobileControl",{force:!0}),Rn(Be,"mobileControlEnter"),(_t=g.current)==null||_t.focus()},[ge,Rn,nn,t]),an=b.useCallback(()=>{var qe,at,_t;if(!ge())return;const Be=(at=(qe=navigator.clipboard)==null?void 0:qe.readText)==null?void 0:at.bind(navigator.clipboard);if(!window.isSecureContext||!Be){Ue.error("无法读取剪贴板"),(_t=g.current)==null||_t.focus();return}Be().then(Ee=>{if(!Ee)return;const dt=g.current;if(dt){dt.paste(Ee);return}Mo(t,Ee),nn("paste"),Rn(Ee,"pasteEnter")}).catch(Ee=>{const dt=Ee instanceof Error&&Ee.message?Ee.message:"无法读取剪贴板";Ue.error(dt)}).finally(()=>{var Ee;return(Ee=g.current)==null?void 0:Ee.focus()})},[ge,Rn,nn,t]),bn=T1e({showMobilePtyControls:Gt,horizontalScrollable:j.horizontalScrollable,mobileControlsHeight:l});q.current.containerPaddingBottom=bn,b.useEffect(()=>{var at,_t;D.current?(at=A.current)==null||at.relayout():(_t=I.current)==null||_t.schedule();const Be=B.current,qe=S1e({controlsVisible:Gt,keyboardOpen:Xe,previous:Be});B.current={keyboardOpen:Xe,controlsVisible:Gt},Gt&&(D.current?on():qe&&nn("keyboardOffset",{force:!0}))},[Ke,Xe,Gt,bn,on,nn]);const _n=b.useMemo(()=>({onFocusCapture:It,onBlurCapture:sn}),[It,sn]);return{scrollState:j,isAtBottom:f.isAtBottom,hasNewFramesWhileAway:f.hasNewFramesWhileAway,ptyInputFocused:rt,showMobilePtyControls:Gt,touchEditingSurface:Pt,keyboardOffset:Ke,physicalKeyboardMode:Fe,softKeyboardEditingSurface:Te,mobileControlsBottomInset:Se,connectionReady:u.ready,connectionOverlay:u.overlay,containerPaddingBottom:bn,traceEnabled:h,findReady:te,findResultIndex:ee.resultIndex,findResultCount:ee.resultCount,findNext:pt,findPrevious:qt,clearFind:Ot,resizeTerminal:Ge,scrollToBottom:ct,scrollToRatio:ut,scrollToXRatio:St,clearNewFramesWhileAway:on,sendMobileInput:mn,pasteMobileClipboard:an,handleTerminalContainerMouseDown:Je,handlePasteCapture:fe,pointerHandlers:oe.pointerHandlers,focusHandlers:_n,ptySelectionToolbar:oe.ptySelectionToolbar,ptySelectionHandles:oe.ptySelectionHandles,ptySelectionPathAction:oe.ptySelectionPathAction,ptySelectionHandleMetrics:oe.ptySelectionHandleMetrics,copyPtySelection:oe.copyPtySelection,openPtySelectionPathAction:oe.openPtySelectionPathAction,handlePtySelectionHandlePointerDown:oe.handlePtySelectionHandlePointerDown,handlePtySelectionHandleTouchStart:oe.handlePtySelectionHandleTouchStart,isPtyDragOver:pe,handlePtyDragOver:le,handlePtyDragLeave:he,handlePtyDrop:Oe}}function N1e({sessionId:e,sessionKind:t,provider:n,active:r=!0,findRequest:i,resizeRequest:s}){const o=Ht(D=>{const F=D.sessions.find(q=>q.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,y]=b.useState(!1),[g,_]=b.useState(""),w=b.useRef(null),S=b.useRef(null),x=b.useRef(null),k=A1e({sessionId:e,active:r,containerEl:l,spacerRef:w,xtermHostRef:S,selectionHandleLayerRef:x,mobileControlsHeight:d}),R=k.ptySelectionHandleMetrics,{clearFind:A,findNext:O,findPrevious:T,findReady:M,findResultCount:z,findResultIndex:Y}=k,U=b.useRef(s==null?void 0:s.requestId),{resizeTerminal:G}=k;b.useEffect(()=>{s===void 0||s.requestId===U.current||(U.current=s.requestId,r&&G(s.action))},[r,s,G]);const I=b.useCallback(()=>{T(g)},[T,g]),N=b.useCallback(()=>{O(g)},[O,g]),L=b.useCallback(()=>y(!0),[]),B=b.useCallback(()=>{y(!1),A()},[A]),P=f$({enabled:r,open:h,openRequest:i,onOpen:L,onClose:B,onPrevious:I,onNext:N});return b.useEffect(()=>{!h||!M||(g?O(g,!0):A())},[A,O,h,g,M]),m.jsxs("div",{className:"flex flex-col h-full relative","data-slot":"chat-pty-view","data-connection-ready":k.connectionReady?"true":"false","aria-busy":!k.connectionReady,children:[h?m.jsx(B1,{query:g,resultIndex:Y,resultCount:z,focusRequest:P.focusRequest,loading:!!g&&!M,onQueryChange:_,onPrevious:I,onNext:N,onClose:P.closeFind}):null,m.jsxs("div",{ref:u,className:"relative flex-1 min-h-0 overflow-auto overscroll-contain bg-background px-3 pt-2",style:{paddingBottom:`calc(env(safe-area-inset-bottom) + ${k.containerPaddingBottom}px)`,touchAction:"pan-x pan-y",overflowAnchor:"none"},onMouseDownCapture:k.handleTerminalContainerMouseDown,onPointerDownCapture:D=>{k.pointerHandlers.onPointerDownCapture(D)},onPointerMoveCapture:k.pointerHandlers.onPointerMoveCapture,onPointerUpCapture:k.pointerHandlers.onPointerUpCapture,onPointerCancelCapture:k.pointerHandlers.onPointerCancelCapture,onTouchStartCapture:k.pointerHandlers.onTouchStartCapture,onTouchMoveCapture:k.pointerHandlers.onTouchMoveCapture,onTouchEndCapture:k.pointerHandlers.onTouchEndCapture,onTouchCancelCapture:k.pointerHandlers.onTouchCancelCapture,onContextMenuCapture:k.pointerHandlers.onContextMenuCapture,onPasteCapture:k.handlePasteCapture,onDragOver:k.handlePtyDragOver,onDragLeave:k.handlePtyDragLeave,onDrop:k.handlePtyDrop,onFocusCapture:k.focusHandlers.onFocusCapture,onBlurCapture:k.focusHandlers.onBlurCapture,"data-slot":"pty-terminal","data-drag-over":k.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(l$,{visible:!k.isAtBottom,hasNewMessages:k.hasNewFramesWhileAway,className:h?"top-14":"top-10",onClick:()=>{k.scrollToBottom("backToBottomBtn",{force:!0}),k.clearNewFramesWhileAway()}}),k.showMobilePtyControls?m.jsx(xge,{sessionKind:t,provider:n,shellFamily:o,bottomInset:k.mobileControlsBottomInset,onInput:k.sendMobileInput,onPaste:k.pasteMobileClipboard,onHeightChange:f}):null,k.ptySelectionHandles&&x.current?xu.createPortal(m.jsxs(m.Fragment,{children:[m.jsx(qL,{kind:"anchor",metrics:R,"aria-label":"调整选区起点",onPointerDown:D=>k.handlePtySelectionHandlePointerDown("anchor",D),onTouchStart:D=>k.handlePtySelectionHandleTouchStart("anchor",D)}),m.jsx(qL,{kind:"focus",metrics:R,"aria-label":"调整选区终点",onPointerDown:D=>k.handlePtySelectionHandlePointerDown("focus",D),onTouchStart:D=>k.handlePtySelectionHandleTouchStart("focus",D)})]}),x.current):null,k.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:k.ptySelectionToolbar.left,top:k.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:D=>D.preventDefault(),onClick:k.copyPtySelection,"aria-label":"复制终端选区",children:"复制"}),k.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:D=>D.preventDefault(),onClick:k.openPtySelectionPathAction,"aria-label":k.ptySelectionPathAction.kind==="image-preview"?"预览终端选区图片":"下载终端选区文件",children:k.ptySelectionPathAction.kind==="image-preview"?"预览":"下载"}):null]}):null,m.jsx(Nge,{state:k.scrollState,scrollContainer:l,onScrollRatio:k.scrollToRatio}),m.jsx(Mge,{state:k.scrollState,onScrollRatio:k.scrollToXRatio}),m.jsx(oge,{...k.connectionOverlay}),m.jsx(lge,{ptyInputFocused:k.ptyInputFocused,touchEditingSurface:k.touchEditingSurface,softKeyboardEditingSurface:k.softKeyboardEditingSurface,physicalKeyboardMode:k.physicalKeyboardMode,keyboardOffset:k.keyboardOffset,showMobilePtyControls:k.showMobilePtyControls,mobileControlsBottomInset:k.mobileControlsBottomInset}),k.traceEnabled?m.jsx(M1e,{}):null]})}function qL({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,y=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:y,width:l,height:l,...g},"data-slot":"pty-selection-handle-dot"})]})}function M1e(){const[e,t]=b.useState(!1);async function n(){const r=ige();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 P1e=1024,I1e=720,Fv=.5,gH=b.createContext(null);function O1e({children:e}){const[t,n]=b.useState([]),[r,i]=b.useState(null),[s,o]=b.useState(null),l=Ae(R=>R.selectedProxyId),u=Ht(R=>R.sessions),d=Ht(R=>R.sessionListLoaded),f=b.useRef(l),h=b.useRef(null),y=b.useMemo(()=>u.filter(R=>R.mode==="pty").map(R=>R.sessionId).sort().join(`
|
|
738
738
|
`),[u]),g=b.useCallback(R=>{h.current=R.sessionId,i(R),n(A=>Rpe(A,R.sessionId).map(T=>T.sessionId===R.sessionId?{...T,sessionKind:R.sessionKind,provider:R.provider}:T))},[]),_=b.useCallback(R=>{h.current===R&&(h.current=null),i(A=>(A==null?void 0:A.sessionId)===R?null:A),o(A=>h.current===null?null:A)},[]),w=b.useCallback((R,A)=>{h.current===R&&o(O=>!A||O&&B1e(O,A)?O:A)},[]),S=b.useCallback((R,A)=>{A!==void 0&&n(O=>O.map(T=>T.sessionId===R?{...T,findRequest:A}:T))},[]),x=b.useCallback((R,A)=>{A===void 0||h.current!==R||n(O=>O.map(T=>T.sessionId===R?{...T,resizeRequest:A}:T))},[]);b.useEffect(()=>{if(!d)return;const R=new Set(y?y.split(`
|
|
739
|
-
`):[]);n(A=>A.filter(O=>R.has(O.sessionId))),i(A=>A&&R.has(A.sessionId)?A:null),h.current&&!R.has(h.current)&&(h.current=null,o(null))},[y,d]),b.useEffect(()=>{const R=f.current;f.current=l,!(!R||R===l)&&(h.current=null,n([]),i(null),o(null))},[l]);const k=b.useMemo(()=>({activate:g,deactivate:_,updateFindRequest:S,updateResizeRequest:x,updateViewportRect:w}),[g,_,S,x,w]);return m.jsxs(gH.Provider,{value:k,children:[e,m.jsx(D1e,{entries:t,activeView:r,viewportRect:s})]})}function L1e({sessionId:e,sessionKind:t,provider:n,findRequest:r,resizeRequest:i}){const s=b.useContext(gH),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 y=o.current;if(!y)return;const g=()=>{const w=y.getBoundingClientRect();h(e,{top:w.top,left:w.left,width:w.width,height:w.height})};g();const _=new ResizeObserver(g);return _.observe(y),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 D1e({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)??P1e,height:(n==null?void 0:n.height)??I1e};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(a$,{sessionId:r.sessionId,children:m.jsx(N1e,{sessionId:r.sessionId,sessionKind:r.sessionKind,provider:r.provider,active:i,findRequest:r.findRequest,resizeRequest:r.resizeRequest})})},r.sessionId)})})}function B1e(e,t){return Math.abs(e.top-t.top)<=Fv&&Math.abs(e.left-t.left)<=Fv&&Math.abs(e.width-t.width)<=Fv&&Math.abs(e.height-t.height)<=Fv}function z1e(){const e=Ht(r=>r.codexActiveWriterConflict),t=Ht(r=>r.setCodexActiveWriterConflict),n=()=>t(null);return m.jsx(es,{open:e!==null,onOpenChange:r=>!r&&n(),children:m.jsxs(ts,{focusSurfaceOnOpen:!0,className:"min-w-0 sm:max-w-md",children:[m.jsxs(ns,{children:[m.jsx($i,{children:"该 Codex 会话仍在运行"}),m.jsxs(Es,{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(Vs,{children:m.jsx(yt,{type:"button",onClick:n,autoFocus:!0,children:"知道了"})})]})})}function _T({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 j1e(e){const t=e5(e);return t.osName!=="iPad"?{supported:!0}:e.standalone||t.browserName==="Safari"?{supported:!0}:{supported:!1,reason:"ipad-safari-required",browserName:t.browserName}}function xy(){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 F1e(){return typeof navigator>"u"?{supported:!0}:j1e({userAgent:navigator.userAgent,platform:navigator.platform,maxTouchPoints:navigator.maxTouchPoints,standalone:xy()})}function $1e(){cSe(),uSe();const e=ds(),t=Cs(),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(()=>xy()),f=Ae(I=>I.proxies.length),h=Ae(I=>I.proxyListLoaded),y=Ae(I=>I.relayClientAuthIssue),g=Ae(I=>I.relayConnectionIssue),_=Ae(I=>!!I.selectedProxyId),w=Ae(I=>I.selectedProxyId),S=Ae(I=>I.selectedProxyName),x=Ae(I=>{var N;return(N=I.proxies.find(L=>L.proxyId===I.selectedProxyId))==null?void 0:N.osName});Ht(I=>I.sessions.length);const k=Ae(I=>I.pendingToast),R=Ae(I=>I.setPendingToast),A=e.pathname==="/"?"proxy-select":"sessions",O=g!==null&&y===null,T=_T({route:A,surface:"mobile",proxiesLength:f,proxyListLoaded:h,hasProxy:_,relayClientAuthIssue:y}),M=S??w,Y=e.pathname==="/sessions"&&h&&f>0?m.jsxs(yt,{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(kz,{className:"size-4 text-primary","aria-hidden":"true"}),m.jsx(Cp,{name:M??"切换开发机",osName:x,nameClassName:"text-foreground"})]}):null;b.useEffect(()=>{if(!k)return;({error:Ue.error,info:Ue.info,success:Ue.success})[k.kind](k.message),R(null)},[k,R]),b.useEffect(()=>{if(typeof window.matchMedia!="function"){d(xy());return}const I=window.matchMedia("(display-mode: standalone)"),N=window.matchMedia("(display-mode: fullscreen)"),L=()=>d(xy());return L(),I.addEventListener("change",L),N.addEventListener("change",L),()=>{I.removeEventListener("change",L),N.removeEventListener("change",L)}},[]);const U=b.useRef(!1);b.useEffect(()=>{if(U.current)return;U.current=!0;const I=Eie({pathname:e.pathname,alreadyRestored:Tie(),lastRoute:Cie()});Rie(),I&&(Aie(I),t(I,{replace:!0}))},[]);const G=b.useRef(!1);return b.useEffect(()=>{n?(G.current=!0,kie(`${e.pathname}${e.search}`)):G.current&&(G.current=!1,Dy())},[n,e.pathname,e.search]),m.jsxs(Cde,{blocked:O,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:O?!0:void 0,"aria-hidden":O?!0:void 0,children:[!i&&m.jsx(yt,{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(Az,{className:"size-4","aria-hidden":"true"})})}),!i&&m.jsx(Nhe,{subtitle:T,action:Y}),m.jsx(Tpe,{}),m.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[m.jsx(The,{className:"hidden md:flex"}),m.jsx("main",{className:"relative flex-1 overflow-hidden",role:"main",children:m.jsx(O1e,{children:m.jsx("div",{className:Ye("h-full",!s&&"animate-in fade-in-0 duration-200 motion-reduce:animate-none"),"data-slot":"route-content",children:m.jsx(R7,{})},s?"top-level":e.pathname)})})]}),m.jsx(O1,{open:o,onOpenChange:l}),m.jsx(z1e,{}),m.jsx(rpe,{}),m.jsx(jhe,{}),m.jsx(Xre,{})]}),O&&g?m.jsx("div",{className:"fixed inset-0 z-[60] bg-background",children:m.jsx(ope,{issue:g})}):null]})}function vH({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(TF,{texts:RF,className:"text-2xl md:text-3xl font-bold"}),e?m.jsx("p",{className:"max-w-md text-sm text-muted-foreground",children:e}):null,t&&m.jsx("div",{children:t})]})}function H1e(){const e=Ae(o=>o.proxies),t=Ae(o=>o.proxyListLoaded),n=Ae(o=>!!o.selectedProxyId),r=Ae(o=>o.relayClientAuthIssue);Ht(o=>o.sessions.length);const i=_T({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(sF,{layout:"page"})}),m.jsx("div",{className:"hidden md:block h-full",children:s?m.jsx(Qc,{variant:s}):m.jsx(vH,{subtitle:i})})]})}function U1e(){const e=Ae(o=>o.proxies),t=Ae(o=>o.proxyListLoaded),n=Ae(o=>!!o.selectedProxyId),r=Ae(o=>o.relayClientAuthIssue);Ht(o=>o.sessions.length);const i=Ni("local",Sn.proxyId)!==null;if(!n&&!i)return m.jsx(T7,{to:"/",replace:!0});const s=_T({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(yF,{layout:"page"})}),m.jsx("div",{className:"hidden md:block h-full",children:m.jsx(vH,{subtitle:s})})]})}function yH(){if(!(typeof navigator>"u"))return navigator.wakeLock}function W1e(e,t){return e===!1?"insecure-context":t?null:"unsupported"}function bH(){var t;const e=typeof window>"u"?void 0:window.isSecureContext;return W1e(e,typeof((t=yH())==null?void 0:t.request)=="function")}function q1e(e){return e==="insecure-context"?"屏幕常亮需要 HTTPS":"当前浏览器不支持屏幕常亮"}function V1e(){const e=yH();if(typeof(e==null?void 0:e.request)!="function")throw new Error(q1e(bH()));return e.request("screen")}function Y1e(e){return e instanceof Error&&e.message.trim()?e.message:"无法开启屏幕常亮"}class K1e{constructor(t={}){je(this,"activeScopes",new Set);je(this,"pendingScopes",new Set);je(this,"listeners",new Map);je(this,"sentinel",null);je(this,"requestInFlight",null);je(this,"requestWakeLock");je(this,"documentRef");je(this,"windowRef");je(this,"unavailableReason");je(this,"handleVisibilityChange",()=>{var t,n;if(((t=this.documentRef)==null?void 0:t.visibilityState)==="hidden"){this.releaseSentinel().catch(()=>{});return}((n=this.documentRef)==null?void 0:n.visibilityState)==="visible"&&this.ensureWakeLock().catch(()=>{})});je(this,"handlePageHide",()=>{this.releaseSentinel().catch(()=>{})});var n,r;this.requestWakeLock=t.request??V1e,this.unavailableReason=typeof t.request=="function"?null:bH(),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(Y1e(n),{cause:n})}finally{this.pendingScopes.delete(t),this.notify(t)}}async disable(t){const n=this.activeScopes.delete(t);this.pendingScopes.delete(t),this.notify(t),!(!n||this.activeScopes.size>0)&&await this.releaseSentinel()}async toggle(t){this.activeScopes.has(t)?await this.disable(t):await this.enable(t)}dispose(){var t,n;(t=this.documentRef)==null||t.removeEventListener("visibilitychange",this.handleVisibilityChange),(n=this.windowRef)==null||n.removeEventListener("pagehide",this.handlePageHide),this.activeScopes.clear(),this.pendingScopes.clear(),this.releaseSentinel().catch(()=>{});for(const r of this.listeners.keys())this.notify(r)}async ensureWakeLock(){var t;if(this.activeScopes.size!==0&&((t=this.documentRef)==null?void 0:t.visibilityState)!=="hidden"&&!(this.sentinel&&!this.sentinel.released))return this.requestInFlight?this.requestInFlight:(this.requestInFlight=this.requestWakeLock().then(async n=>{var r;if(this.activeScopes.size===0||((r=this.documentRef)==null?void 0:r.visibilityState)==="hidden"){n.released||await n.release();return}this.sentinel=n,n.addEventListener("release",()=>{var i;this.sentinel===n&&(this.sentinel=null),this.activeScopes.size>0&&((i=this.documentRef)==null?void 0:i.visibilityState)!=="hidden"&&this.ensureWakeLock().catch(()=>{})},{once:!0})}).finally(()=>{this.requestInFlight=null}),this.requestInFlight)}async releaseSentinel(){const t=this.sentinel;this.sentinel=null,!(!t||t.released)&&await t.release()}notify(t){var r;const n=this.getSnapshot(t);(r=this.listeners.get(t))==null||r.forEach(i=>i(n))}}const jl=new K1e;function _H(e){const[t,n]=b.useState(()=>jl.getSnapshot(e));b.useEffect(()=>jl.subscribe(e,n),[e]),b.useEffect(()=>()=>{jl.disable(e).catch(()=>{})},[e]);const r=b.useCallback(()=>jl.enable(e),[e]),i=b.useCallback(()=>jl.disable(e),[e]),s=b.useCallback(()=>jl.toggle(e),[e]);return{...t,enable:r,disable:i,toggle:s}}function G1e({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,y]=b.useState(!1);function g(){u(null),f(!1),y(!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){Ue.error(`请输入 ${r}–${i} 之间的整数`),w?y(!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:Ye("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),y(!1)},onBlur:()=>_(!1),onKeyDown:w=>{w.stopPropagation(),!w.nativeEvent.isComposing&&(w.key==="Enter"?(w.preventDefault(),_(!0)):w.key==="Escape"&&(w.preventDefault(),g()))}})}function X1e(){return new AudioContext}class Z1e{constructor(t=X1e){je(this,"context",null);this.createContext=t}get(){return this.context??(this.context=this.createContext()),this.context}async prepare(){const t=this.get();if(t.state!=="running"&&t.state!=="closed"&&await t.resume(),t.state!=="running")throw new Error("浏览器未允许播放 Voice Pilot 提示音");return t}async reactivateAfterCapture(){const t=this.get();if(t.state==="closed")throw new Error("Voice Pilot 播放上下文已关闭");if(t.state==="running"&&await t.suspend(),t.state!=="running"&&await t.resume(),t.state!=="running")throw new Error("浏览器未能恢复 Voice Pilot 音频输出");return t}}const Sy=new Z1e,VL=400,jd=[];let wH=1;function J1e(){return typeof performance>"u"?0:Math.round(performance.now()*10)/10}function xp(e){const t={sequence:wH++,timestamp:new Date().toISOString(),monotonicMs:J1e(),sessionId:e.sessionId,scope:e.scope,event:e.event,...e.attemptId?{attemptId:e.attemptId}:{},...e.requestId?{requestId:e.requestId}:{},...e.details?{details:{...e.details}}:{}};jd.push(t),jd.length>VL&&jd.splice(0,jd.length-VL)}function Q1e(){return jd.map(e=>({...e,...e.details?{details:{...e.details}}:{}}))}function eEe(){jd.length=0,wH=1}typeof window<"u"&&(window.__devAnywhereVoicePilotDiagnostics={snapshot:Q1e,clear:eEe});function xH(e){return`voice-pilot:${e}`}function tEe(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 nEe="modulepreload",rEe=function(e){return"/"+e},YL={},SH=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=rEe(d),d in YL)return;YL[d]=!0;const f=d.endsWith(".css"),h=f?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${d}"]${h}`))return;const y=document.createElement("link");if(y.rel=f?"stylesheet":nEe,f||(y.as="script"),y.crossOrigin="",y.href=d,u&&y.setAttribute("nonce",u),document.head.appendChild(y),f)return new Promise((g,_)=>{y.addEventListener("load",g),y.addEventListener("error",()=>_(new Error(`Unable to preload CSS for ${d}`)))})}))}function s(o){const l=new Event("vite:preloadError",{cancelable:!0});if(l.payload=o,window.dispatchEvent(l),!l.defaultPrevented)throw o}return i.then(o=>{for(const l of o||[])l.status==="rejected"&&s(l.reason);return t().catch(s)})},iEe="/assets/fvad-DYxbW2my.wasm",uf=16e3,sEe=20,Fl=uf*sEe/1e3,fS=Fl*Int16Array.BYTES_PER_ELEMENT;let KL=null;async function oEe(){return KL??(KL=SH(async()=>{const{default:e}=await import("./fvad-BeprG8UQ.js");return{default:e}},[]).then(({default:e})=>e({locateFile:t=>t.endsWith(".wasm")?iEe:t}))),KL}class wT{constructor(t,n,r){je(this,"destroyed",!1);this.module=t,this.handle=n,this.framePointer=r}static async create(t=3){const n=await oEe(),r=n._fvad_new();if(!r)throw new Error("无法初始化浏览器语音活动检测器");const i=n._malloc(fS);if(!i)throw n._fvad_free(r),new Error("无法分配浏览器语音活动检测缓冲区");if(n._fvad_set_sample_rate(r,uf)!==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 wT(n,r,i)}process(t){if(this.destroyed)throw new Error("浏览器语音活动检测器已释放");if(t.byteLength!==fS)throw new Error(`语音活动检测帧必须为 ${fS} 字节`);this.module.HEAPU8.set(t,this.framePointer);const n=this.module._fvad_process(this.handle,this.framePointer,Fl);if(n<0)throw new Error("浏览器语音活动检测失败");return n===1}reset(){this.destroyed||this.module._fvad_reset(this.handle)}destroy(){this.destroyed||(this.destroyed=!0,this.module._free(this.framePointer),this.module._fvad_free(this.handle))}}class aEe{constructor(t={}){je(this,"startSpeechFrames");je(this,"endSilenceFrames");je(this,"active",!1);je(this,"speechFrames",0);je(this,"silenceFrames",0);if(this.startSpeechFrames=t.startSpeechFrames??10,this.endSilenceFrames=t.endSilenceFrames??30,this.startSpeechFrames<1||this.endSilenceFrames<1)throw new Error("Invalid voice activity gate configuration")}push(t){return this.active?t?(this.silenceFrames=0,"none"):(this.silenceFrames+=1,this.silenceFrames<this.endSilenceFrames?"none":(this.active=!1,this.silenceFrames=0,"speech-end")):(this.speechFrames=t?this.speechFrames+1:0,this.speechFrames>=this.startSpeechFrames?(this.active=!0,this.speechFrames=0,this.silenceFrames=0,"speech-start"):"none")}reset(){this.active=!1,this.speechFrames=0,this.silenceFrames=0}}class lEe{constructor(){je(this,"pending",new Float32Array(Fl));je(this,"pendingLength",0)}push(t,n){let r=0;if(this.pendingLength>0){const i=Fl-this.pendingLength,s=Math.min(i,t.length);this.pending.set(t.subarray(0,s),this.pendingLength),this.pendingLength+=s,r+=s,this.pendingLength===Fl&&(n(this.pending.slice()),this.pendingLength=0)}for(;r+Fl<=t.length;)n(t.slice(r,r+Fl)),r+=Fl;if(r<t.length){const i=t.subarray(r);this.pending.set(i,0),this.pendingLength=i.length}}reset(){this.pendingLength=0}}const cEe="/__dev_anywhere_debug/voice-fixture",uEe=uf*xF/1e3;function dEe(){return wT.create(3)}const fEe={createVad:dEe,getUserMedia:e=>navigator.mediaDevices.getUserMedia(e),createAudioContext:e=>new AudioContext(e),fetch:e=>fetch(e)};function hEe(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 pEe(e){for(const t of e.getTracks())t.stop()}function EH(e){const t=e.createAudioContext({sampleRate:uf});if(t.sampleRate!==uf)throw t.close().catch(()=>{}),new Error("浏览器无法提供 Voice Pilot 所需的 16 kHz 音频输入");return t}async function mEe(e){const t=EH(e);let n;try{n=await e.getUserMedia({audio:{channelCount:1,echoCancellation:!0,autoGainControl:!0,noiseSuppression:!0,sampleRate:uf}})}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(),pEe(n),t.state!=="closed"&&await t.close()}}}async function gEe(e,t){const n=EH(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 CH(e=window.location.search,t=!1){return t&&new URLSearchParams(e).get("voice-fixture")==="default"?{kind:"fixture",url:cEe}:{kind:"microphone"}}async function vEe(e,t=fEe){const n=await t.createVad();let r;try{r=e.source.kind==="fixture"?await gEe(e.source.url,t):await mEe(t)}catch(f){throw n.destroy(),f}const i=new aEe,s=new lEe,o=r.context.createScriptProcessor(uEe,1,1);let l=!1,u=null,d=null;return o.onaudioprocess=f=>{l&&s.push(f.inputBuffer.getChannelData(0),h=>{const y=tEe(h),g=n.process(y);e.onFrame({pcm:y,speechProbability:g?1:0,activityLevel:hEe(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 kH(e=pf().osName){return{mediaAccept:"image/*,video/*",fileAccept:e==="Android"?"application/*,text/*":void 0}}function yEe(e){const[t,n,...r]=Array.from(e);return t&&n===" "&&r.length>0?{indicator:t,label:r.join("")}:{label:e}}function bEe({title:e,isPtyTitle:t}){if(!t)return m.jsx(m.Fragment,{children:e});const{indicator:n,label:r}=yEe(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 _Ee(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 wEe(){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(_Ee(n),{cause:n})}finally{e==null||e.getTracks().forEach(n=>n.stop())}}const Ml="min-h-9 gap-2.5",$v="px-2 pb-1 pt-2 text-xs font-semibold text-muted-foreground",xEe=[{axis:"cols",label:"列数",unit:"列",Icon:GV,min:eb,max:iu},{axis:"rows",label:"行数",unit:"行",Icon:rK,min:tb,max:su}];function Bs({children:e,className:t}){return m.jsx("span",{"aria-hidden":"true","data-slot":"chat-menu-icon",className:Ye("inline-flex size-5 shrink-0 items-center justify-center text-muted-foreground [&_svg]:size-4",t),children:e})}function SEe({label:e}){return m.jsxs(Bs,{className:"relative",children:[m.jsx(SC,{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 EEe({sessionId:e,mode:t,onFind:n,onResizeTerminal:r}){const i=Gr(ve=>ve.homePath),s=kH(),o=Cs(),l=Ht(ve=>ve.sessions.find(rt=>rt.sessionId===e)),u=Ht(ve=>ve.ptyTitles[e]),d=Ht(ve=>ve.ptyGeometryBySessionId[e]),f=Ae(ve=>ve.ptyFontSize),h=Ae(ve=>ve.chatContentFontSize),y=Ae(ve=>ve.selectedProxyId),g=Ae(ve=>ve.connected),_=Ae(ve=>ve.proxyOnline),w=Ae(ve=>ve.adjustPtyFontSize),S=Ae(ve=>ve.adjustChatContentFontSize),x=Ae(ve=>ve.setChatContentFontSize),k=Ae(ve=>ve.resetPtyFontSize),R=Ae(ve=>ve.resetChatContentFontSize),A=Ae(ve=>ve.inputModePreference==="hardware"),O=Ht(ve=>ve.renameSession),T=WC(y,e),M=(l==null?void 0:l.provider)!=="codex",z=Ht(ve=>M&&T?!!ve.ptyAutoYesBySessionKey[T]:!1),Y=Ht(ve=>ve.setPtyAutoYes),G=yo("(pointer: coarse), (hover: none)")&&!A,I=t==="pty"||(l==null?void 0:l.mode)==="pty",N=u$(l??{}).menu,L=b.useRef(null),B=b.useRef(null),P=b.useRef(!1),[D,F]=b.useState(!1),q=(l==null?void 0:l.kind)==="terminal",j=_H(e),V=Mn(ve=>ve.bySessionId[e]??l_),K=Mn(ve=>ve.enable),$=Mn(ve=>ve.disable),te=!!(l!=null&&l.nameLocked&&(l!=null&&l.name)),re=JC(l,i),ee=te&&(l==null?void 0:l.name)||re||I&&u||(l==null?void 0:l.name)||e.slice(0,8),X=!!(I&&!q&&u&&!te),ae=I?f:AC(h,G),ne=!I&&G?Zz:Gz,ce=I?k:R,[_e,xe]=b.useState(!1),[We,De]=b.useState(!1),Pt=V.enabled,tt=j.active||Pt,lt=j.pending||!j.supported||Pt;function $e(ve){if(I){w(ve);return}if(G){x(ae+ve);return}S(ve)}function Fe(){j.toggle().catch(ve=>{Ue.error(ve instanceof Error?ve.message:String(ve))})}async function Te(ve){var ht;if(I||q){Ue.info("Voice Pilot 目前适用于聊天会话。");return}if(ve!==!0){$(e);return}const rt=Ft;if(!rt){Ue.error("请先连接开发机");return}try{if(!((ht=(await rt.requestVoiceConfig()).config)!=null&&ht.configured)){Ue.info("请先在设置里配置 Voice Pilot。");return}xe(!0)}catch(Mt){Ue.error(Mt instanceof Error?Mt.message:String(Mt))}}async function Ke(){var Mt;De(!0);let ve=null,rt=!1;const ht=xH(e);try{xp({sessionId:e,scope:"runtime",event:"wake-lock-requested",details:{userActivationActive:((Mt=navigator.userActivation)==null?void 0:Mt.isActive)??!1,visibilityState:document.visibilityState,secureContext:window.isSecureContext}});const It=jl.enable(ht).then(()=>{xp({sessionId:e,scope:"runtime",event:"wake-lock-acquired"})},wt=>{throw xp({sessionId:e,scope:"runtime",event:"wake-lock-failed",details:{error:wt instanceof Error?wt.message:String(wt)}}),new Error("屏幕常亮请求被浏览器拒绝,Voice Pilot 未开启。",{cause:wt})});ve=Pk.acquire("capture");const sn=Sy.prepare(),on=CH().kind==="microphone"?wEe():Promise.resolve();await Promise.all([It,sn,on]),K(e),rt=!0,xe(!1)}catch(It){xp({sessionId:e,scope:"runtime",event:"startup-failed",details:{error:It instanceof Error?It.message:String(It)}}),Ue.error(It instanceof Error?It.message:String(It))}finally{ve==null||ve.release(),rt||await jl.disable(ht).catch(()=>{}),De(!1)}}const Xe=b.useRef(null),Se=b.useRef(null),[it,vt]=b.useState(!1);async function ge(ve){var It;const rt=(It=ve.target.files)==null?void 0:It[0];if(ve.target.value="",!rt)return;const ht=Ft;if(!ht){Ue.error("请先连接开发机");return}const Mt=await nm({relay:ht,sessionId:e,file:rt});Mt&&Mo(e,`@${Mt} `)}async function Ge(ve,rt){const ht=Ft;if(!ht)throw new Error("请先连接开发机");const Mt=await ht.renameSession(ve,rt);if(!Mt.success)throw new Error(Mt.error??"重命名失败");O(ve,Mt.name??rt),Ue.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(yt,{variant:"ghost",size:"icon-sm",className:"md:hidden",onClick:()=>o("/sessions"),"aria-label":"返回会话列表","data-slot":"chat-back-button",children:m.jsx(ff,{"aria-hidden":"true"})})}),m.jsx("span",{className:"text-sm font-semibold truncate text-center px-2","data-slot":"chat-session-title",children:m.jsx(bEe,{title:ee,isPtyTitle:X})}),m.jsxs(_f,{modal:!1,onOpenChange:ve=>{ve?P.current=!1:F(!1)},children:[m.jsx(wf,{asChild:!0,children:m.jsx(yt,{ref:L,variant:"ghost",size:"icon-sm",className:"justify-self-end","aria-label":"会话操作","data-slot":"chat-overflow-trigger",onPointerDownCapture:ve=>{if(ve.currentTarget.getAttribute("data-state")==="open")return;const rt=document.activeElement,ht=rt==null?void 0:rt.closest('[data-slot="pty-keepalive-entry"]');B.current=I&&rt instanceof HTMLTextAreaElement&&rt.matches('[data-slot="pty-host"] .xterm-helper-textarea')&&(ht==null?void 0:ht.getAttribute("data-session-id"))===e&&ht.getAttribute("data-active")==="true"?rt:null},onKeyDownCapture:ve=>{["Enter"," ","ArrowDown"].includes(ve.key)&&(B.current=null)},children:m.jsx(iY,{"aria-hidden":"true"})})}),m.jsxs(xf,{align:"end",className:"w-max min-w-44 max-w-[calc(100vw-1rem)] data-[state=open]:animate-none","data-slot":"chat-overflow-menu",onEscapeKeyDown:ve=>{if(ve.target instanceof HTMLElement&&ve.target.matches('[data-terminal-dimension-input][data-editing="true"]')){ve.preventDefault();return}P.current=!0},onInteractOutside:()=>{const ve=document.activeElement;ve instanceof HTMLInputElement&&ve.hasAttribute("data-terminal-dimension-input")&&ve.blur()},onCloseAutoFocus:ve=>{const rt=B.current,ht=P.current;B.current=null,P.current=!1;const Mt=rt==null?void 0:rt.closest('[data-slot="pty-keepalive-entry"]'),It=document.activeElement;ve.defaultPrevented||!ht||!I||!(rt!=null&&rt.isConnected)||(Mt==null?void 0:Mt.getAttribute("data-session-id"))!==e||Mt.getAttribute("data-active")!=="true"||It!==document.body&&It!==document.documentElement&&It!==L.current&&It!==rt&&!(It!=null&&It.closest('[data-slot="chat-overflow-menu"]'))||(ve.preventDefault(),rt.focus({preventScroll:!0}))},children:[m.jsx(yv,{className:$v,children:"会话"}),m.jsxs(ti,{className:Ml,"data-slot":"chat-menu-find",onSelect:n,children:[m.jsx(Bs,{children:m.jsx(ky,{"aria-hidden":"true"})}),"在会话中查找"]}),m.jsxs(ti,{className:Ml,"data-slot":"chat-menu-rename",onSelect:()=>vt(!0),children:[m.jsx(Bs,{children:m.jsx(KY,{"aria-hidden":"true"})}),"重命名"]}),m.jsxs(y0,{checked:tt,className:Ye("min-h-9 justify-start gap-2.5 pl-2 pr-8 [&>span:first-child]:left-auto [&>span:first-child]:right-2",!j.supported&&!tt&&"pr-2"),disabled:lt,"data-slot":"chat-menu-screen-wake-lock-item",onCheckedChange:Fe,children:[m.jsx(Bs,{children:m.jsx(AY,{"aria-hidden":"true"})}),m.jsx("span",{className:"min-w-0 flex-1",children:j.supported?Pt?"屏幕常亮(Voice Pilot 控制)":"屏幕常亮":j.unavailableReason==="insecure-context"?"屏幕常亮(需要 HTTPS)":"屏幕常亮(浏览器不支持)"})]}),I&&!q&&M&&m.jsxs(y0,{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:!T,"data-slot":"chat-menu-pty-auto-yes-item",onCheckedChange:ve=>{T&&Y(T,ve===!0)},children:[m.jsx(Bs,{children:m.jsx(PK,{"aria-hidden":"true"})}),m.jsx("span",{className:"min-w-0 flex-1",children:"Always yes"})]}),!I&&!q&&m.jsxs(y0,{checked:V.enabled,className:"min-h-9 justify-start gap-2.5 pl-2 pr-8 [&>span:first-child]:left-auto [&>span:first-child]:right-2","data-slot":"chat-menu-voice-pilot-item",onCheckedChange:Te,children:[m.jsx(Bs,{children:m.jsx(BY,{"aria-hidden":"true"})}),m.jsx("span",{className:"min-w-0 flex-1",children:"Voice Pilot"})]}),m.jsx(Gc,{}),(l==null?void 0:l.mode)==="pty"&&l.ptyOwner==="proxy-hosted"&&r&&m.jsxs(m.Fragment,{children:[m.jsx(yv,{className:$v,children:"终端尺寸"}),m.jsxs(ti,{className:Ml,"data-slot":"chat-menu-fit-terminal",disabled:!g||!_||l.state==="error",onSelect:()=>r("fit"),children:[m.jsx(Bs,{children:m.jsx(OY,{"aria-hidden":"true"})}),"按窗口调整终端尺寸"]}),xEe.map(({axis:ve,label:rt,unit:ht,Icon:Mt,min:It,max:sn})=>{const Gt=d==null?void 0:d[ve],on=!g||!_||l.state==="error"||Gt===void 0;return m.jsxs("div",{role:"group","aria-label":rt,className:"flex min-h-9 items-center gap-2.5 px-2 text-sm","data-slot":`chat-menu-${ve}-control`,children:[m.jsx(Bs,{children:m.jsx(Mt,{"aria-hidden":"true"})}),m.jsx("span",{children:rt}),m.jsxs("div",{className:"inline-flex shrink-0 items-center gap-2",children:[m.jsx(yt,{variant:"ghost",size:"icon-sm",className:"size-[22px] rounded-[5px] bg-muted/45 text-muted-foreground hover:bg-accent hover:text-accent-foreground",disabled:on||Gt!==void 0&&Gt<=It,"aria-label":`减少${ht}`,"data-slot":`chat-menu-decrease-${ve}`,onClick:wt=>{wt.stopPropagation(),r(`decrease-${ve}`)},children:m.jsx(cP,{"aria-hidden":"true"})}),m.jsx(G1e,{axis:ve,label:rt,value:Gt,min:It,max:sn,disabled:on,onCommit:wt=>r({axis:ve,value:wt})},`${e}-${ve}`),m.jsx(yt,{variant:"ghost",size:"icon-sm",className:"size-[22px] rounded-[5px] bg-muted/45 text-muted-foreground hover:bg-accent hover:text-accent-foreground",disabled:on||Gt!==void 0&&Gt>=sn,"aria-label":`增加${ht}`,"data-slot":`chat-menu-increase-${ve}`,onClick:wt=>{wt.stopPropagation(),r(`increase-${ve}`)},children:m.jsx(uP,{"aria-hidden":"true"})})]})]},ve)}),m.jsx(Gc,{})]}),I&&m.jsxs(m.Fragment,{children:[m.jsxs(Ade,{open:D,onOpenChange:F,children:[m.jsxs(Nde,{className:Ye(Ml,"[&>svg:last-child]:ml-0"),"data-slot":"chat-menu-shortcuts-trigger",onClick:ve=>{D&&(ve.preventDefault(),F(!1))},children:[m.jsx(Bs,{children:m.jsx(SC,{"aria-hidden":"true"})}),"发送快捷键"]}),m.jsx(Rde,{children:m.jsx(Mde,{className:Ye("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,"data-slot":"chat-menu-shortcuts",children:N.map(ve=>m.jsxs(ti,{className:Ml,"data-slot":`chat-menu-send-${ve.id}`,disabled:!g||!_||(l==null?void 0:l.mode)!=="pty"||l.state==="error",onSelect:()=>Mo(e,ve.data),children:[m.jsx(SEe,{label:ve.display}),"发送 ",ve.key]},ve.id))})})]}),m.jsx(Gc,{})]}),I&&!q?m.jsxs(m.Fragment,{children:[m.jsx(yv,{className:$v,children:"文件"}),m.jsxs(ti,{className:Ml,"data-slot":"chat-menu-upload-image",onClick:()=>{var ve;return(ve=Se.current)==null?void 0:ve.click()},children:[m.jsx(Bs,{children:m.jsx(dm,{"aria-hidden":"true"})}),"上传照片或视频"]}),m.jsxs(ti,{className:Ml,"data-slot":"chat-menu-upload-file",onClick:()=>{var ve;return(ve=Xe.current)==null?void 0:ve.click()},children:[m.jsx(Bs,{children:m.jsx(Mz,{"aria-hidden":"true"})}),"上传文件"]}),m.jsx(Gc,{})]}):null,m.jsx(yv,{className:$v,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(Bs,{children:m.jsx(xK,{"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(yt,{variant:"ghost",size:"icon-sm",className:"size-[22px] rounded-[5px] bg-muted/45 text-muted-foreground hover:bg-accent hover:text-accent-foreground",disabled:ae<=ne,"aria-label":"字号变小","data-slot":"chat-menu-font-smaller",onClick:ve=>{ve.stopPropagation(),$e(-1)},children:m.jsx(cP,{"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:[ae,"px"]}),m.jsx(yt,{variant:"ghost",size:"icon-sm",className:"size-[22px] rounded-[5px] bg-muted/45 text-muted-foreground hover:bg-accent hover:text-accent-foreground",disabled:ae>=Xz,"aria-label":"字号变大","data-slot":"chat-menu-font-larger",onClick:ve=>{ve.stopPropagation(),$e(1)},children:m.jsx(uP,{"aria-hidden":"true"})})]})]})}),m.jsxs(ti,{className:Ml,"data-slot":"chat-menu-font-reset",onClick:ce,children:[m.jsx(Bs,{children:m.jsx(QY,{"aria-hidden":"true"})}),m.jsx("span",{"data-slot":"chat-menu-font-reset-label",children:"恢复默认"})]})]})]})]})}),m.jsx(up,{open:it,sessionId:e,initialName:l==null?void 0:l.name,onOpenChange:vt,onRename:Ge}),m.jsx(es,{open:_e&&!V.enabled,onOpenChange:ve=>{We||xe(ve)},children:m.jsxs(ts,{className:"sm:max-w-md","data-slot":"voice-pilot-wake-lock-dialog",focusSurfaceOnOpen:!0,children:[m.jsxs(ns,{children:[m.jsx($i,{children:"开启 Voice Pilot?"}),m.jsx(Es,{children:"开启后会持续聆听并保持屏幕常亮,停止后自动恢复。"})]}),m.jsxs(Vs,{children:[m.jsx(yt,{type:"button",variant:"outline",disabled:We,onClick:()=>xe(!1),children:"取消"}),m.jsx(yt,{type:"button","data-slot":"voice-pilot-confirm-start",disabled:We,onClick:()=>{Ke()},children:We?"正在开启...":"开启 Voice Pilot"})]})]})}),I?m.jsxs(m.Fragment,{children:[m.jsx("input",{ref:Se,type:"file",accept:s.mediaAccept,className:"hidden","data-slot":"chat-menu-upload-image-input",onChange:ve=>{ge(ve)}}),m.jsx("input",{ref:Xe,type:"file",accept:s.fileAccept,className:"hidden","data-slot":"chat-menu-upload-file-input",onChange:ve=>{ge(ve)}})]}):null]})}function _d(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=(k,R)=>{for(k=String(k);k.length<R;)k=" "+k;return k};console.info(`%c⏱ ${x(w,5)} /${x(_,5)} ms`,`
|
|
739
|
+
`):[]);n(A=>A.filter(O=>R.has(O.sessionId))),i(A=>A&&R.has(A.sessionId)?A:null),h.current&&!R.has(h.current)&&(h.current=null,o(null))},[y,d]),b.useEffect(()=>{const R=f.current;f.current=l,!(!R||R===l)&&(h.current=null,n([]),i(null),o(null))},[l]);const k=b.useMemo(()=>({activate:g,deactivate:_,updateFindRequest:S,updateResizeRequest:x,updateViewportRect:w}),[g,_,S,x,w]);return m.jsxs(gH.Provider,{value:k,children:[e,m.jsx(D1e,{entries:t,activeView:r,viewportRect:s})]})}function L1e({sessionId:e,sessionKind:t,provider:n,findRequest:r,resizeRequest:i}){const s=b.useContext(gH),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 y=o.current;if(!y)return;const g=()=>{const w=y.getBoundingClientRect();h(e,{top:w.top,left:w.left,width:w.width,height:w.height})};g();const _=new ResizeObserver(g);return _.observe(y),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 D1e({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)??P1e,height:(n==null?void 0:n.height)??I1e};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(a$,{sessionId:r.sessionId,children:m.jsx(N1e,{sessionId:r.sessionId,sessionKind:r.sessionKind,provider:r.provider,active:i,findRequest:r.findRequest,resizeRequest:r.resizeRequest})})},r.sessionId)})})}function B1e(e,t){return Math.abs(e.top-t.top)<=Fv&&Math.abs(e.left-t.left)<=Fv&&Math.abs(e.width-t.width)<=Fv&&Math.abs(e.height-t.height)<=Fv}function z1e(){const e=Ht(r=>r.codexActiveWriterConflict),t=Ht(r=>r.setCodexActiveWriterConflict),n=()=>t(null);return m.jsx(es,{open:e!==null,onOpenChange:r=>!r&&n(),children:m.jsxs(ts,{focusSurfaceOnOpen:!0,className:"min-w-0 sm:max-w-md",children:[m.jsxs(ns,{children:[m.jsx($i,{children:"该 Codex 会话仍在运行"}),m.jsxs(Es,{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(Vs,{children:m.jsx(yt,{type:"button",onClick:n,autoFocus:!0,children:"知道了"})})]})})}function _T({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 j1e(e){const t=e5(e);return t.osName!=="iPad"?{supported:!0}:e.standalone||t.browserName==="Safari"?{supported:!0}:{supported:!1,reason:"ipad-safari-required",browserName:t.browserName}}function xy(){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 F1e(){return typeof navigator>"u"?{supported:!0}:j1e({userAgent:navigator.userAgent,platform:navigator.platform,maxTouchPoints:navigator.maxTouchPoints,standalone:xy()})}function $1e(){cSe(),uSe();const e=ds(),t=Cs(),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(()=>xy()),f=Ae(I=>I.proxies.length),h=Ae(I=>I.proxyListLoaded),y=Ae(I=>I.relayClientAuthIssue),g=Ae(I=>I.relayConnectionIssue),_=Ae(I=>!!I.selectedProxyId),w=Ae(I=>I.selectedProxyId),S=Ae(I=>I.selectedProxyName),x=Ae(I=>{var N;return(N=I.proxies.find(L=>L.proxyId===I.selectedProxyId))==null?void 0:N.osName});Ht(I=>I.sessions.length);const k=Ae(I=>I.pendingToast),R=Ae(I=>I.setPendingToast),A=e.pathname==="/"?"proxy-select":"sessions",O=g!==null&&y===null,T=_T({route:A,surface:"mobile",proxiesLength:f,proxyListLoaded:h,hasProxy:_,relayClientAuthIssue:y}),M=S??w,Y=e.pathname==="/sessions"&&h&&f>0?m.jsxs(yt,{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(kz,{className:"size-4 text-primary","aria-hidden":"true"}),m.jsx(Cp,{name:M??"切换开发机",osName:x,nameClassName:"text-foreground"})]}):null;b.useEffect(()=>{if(!k)return;({error:Ue.error,info:Ue.info,success:Ue.success})[k.kind](k.message),R(null)},[k,R]),b.useEffect(()=>{if(typeof window.matchMedia!="function"){d(xy());return}const I=window.matchMedia("(display-mode: standalone)"),N=window.matchMedia("(display-mode: fullscreen)"),L=()=>d(xy());return L(),I.addEventListener("change",L),N.addEventListener("change",L),()=>{I.removeEventListener("change",L),N.removeEventListener("change",L)}},[]);const U=b.useRef(!1);b.useEffect(()=>{if(U.current)return;U.current=!0;const I=Eie({pathname:e.pathname,alreadyRestored:Tie(),lastRoute:Cie()});Rie(),I&&(Aie(I),t(I,{replace:!0}))},[]);const G=b.useRef(!1);return b.useEffect(()=>{n?(G.current=!0,kie(`${e.pathname}${e.search}`)):G.current&&(G.current=!1,Dy())},[n,e.pathname,e.search]),m.jsxs(Cde,{blocked:O,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:O?!0:void 0,"aria-hidden":O?!0:void 0,children:[!i&&m.jsx(yt,{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(Az,{className:"size-4","aria-hidden":"true"})})}),!i&&m.jsx(Nhe,{subtitle:T,action:Y}),m.jsx(Tpe,{}),m.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[m.jsx(The,{className:"hidden md:flex"}),m.jsx("main",{className:"relative flex-1 overflow-hidden",role:"main",children:m.jsx(O1e,{children:m.jsx("div",{className:Ye("h-full",!s&&"animate-in fade-in-0 duration-200 motion-reduce:animate-none"),"data-slot":"route-content",children:m.jsx(R7,{})},s?"top-level":e.pathname)})})]}),m.jsx(O1,{open:o,onOpenChange:l}),m.jsx(z1e,{}),m.jsx(rpe,{}),m.jsx(jhe,{}),m.jsx(Xre,{})]}),O&&g?m.jsx("div",{className:"fixed inset-0 z-[60] bg-background",children:m.jsx(ope,{issue:g})}):null]})}function vH({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(TF,{texts:RF,className:"text-2xl md:text-3xl font-bold"}),e?m.jsx("p",{className:"max-w-md text-sm text-muted-foreground",children:e}):null,t&&m.jsx("div",{children:t})]})}function H1e(){const e=Ae(o=>o.proxies),t=Ae(o=>o.proxyListLoaded),n=Ae(o=>!!o.selectedProxyId),r=Ae(o=>o.relayClientAuthIssue);Ht(o=>o.sessions.length);const i=_T({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(sF,{layout:"page"})}),m.jsx("div",{className:"hidden md:block h-full",children:s?m.jsx(Qc,{variant:s}):m.jsx(vH,{subtitle:i})})]})}function U1e(){const e=Ae(o=>o.proxies),t=Ae(o=>o.proxyListLoaded),n=Ae(o=>!!o.selectedProxyId),r=Ae(o=>o.relayClientAuthIssue);Ht(o=>o.sessions.length);const i=Ni("local",Sn.proxyId)!==null;if(!n&&!i)return m.jsx(T7,{to:"/",replace:!0});const s=_T({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(yF,{layout:"page"})}),m.jsx("div",{className:"hidden md:block h-full",children:m.jsx(vH,{subtitle:s})})]})}function yH(){if(!(typeof navigator>"u"))return navigator.wakeLock}function W1e(e,t){return e===!1?"insecure-context":t?null:"unsupported"}function bH(){var t;const e=typeof window>"u"?void 0:window.isSecureContext;return W1e(e,typeof((t=yH())==null?void 0:t.request)=="function")}function q1e(e){return e==="insecure-context"?"屏幕常亮需要 HTTPS":"当前浏览器不支持屏幕常亮"}function V1e(){const e=yH();if(typeof(e==null?void 0:e.request)!="function")throw new Error(q1e(bH()));return e.request("screen")}function Y1e(e){return e instanceof Error&&e.message.trim()?e.message:"无法开启屏幕常亮"}class K1e{constructor(t={}){je(this,"activeScopes",new Set);je(this,"pendingScopes",new Set);je(this,"listeners",new Map);je(this,"sentinel",null);je(this,"requestInFlight",null);je(this,"requestWakeLock");je(this,"documentRef");je(this,"windowRef");je(this,"unavailableReason");je(this,"handleVisibilityChange",()=>{var t,n;if(((t=this.documentRef)==null?void 0:t.visibilityState)==="hidden"){this.releaseSentinel().catch(()=>{});return}((n=this.documentRef)==null?void 0:n.visibilityState)==="visible"&&this.ensureWakeLock().catch(()=>{})});je(this,"handlePageHide",()=>{this.releaseSentinel().catch(()=>{})});var n,r;this.requestWakeLock=t.request??V1e,this.unavailableReason=typeof t.request=="function"?null:bH(),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(Y1e(n),{cause:n})}finally{this.pendingScopes.delete(t),this.notify(t)}}async disable(t){const n=this.activeScopes.delete(t);this.pendingScopes.delete(t),this.notify(t),!(!n||this.activeScopes.size>0)&&await this.releaseSentinel()}async toggle(t){this.activeScopes.has(t)?await this.disable(t):await this.enable(t)}dispose(){var t,n;(t=this.documentRef)==null||t.removeEventListener("visibilitychange",this.handleVisibilityChange),(n=this.windowRef)==null||n.removeEventListener("pagehide",this.handlePageHide),this.activeScopes.clear(),this.pendingScopes.clear(),this.releaseSentinel().catch(()=>{});for(const r of this.listeners.keys())this.notify(r)}async ensureWakeLock(){var t;if(this.activeScopes.size!==0&&((t=this.documentRef)==null?void 0:t.visibilityState)!=="hidden"&&!(this.sentinel&&!this.sentinel.released))return this.requestInFlight?this.requestInFlight:(this.requestInFlight=this.requestWakeLock().then(async n=>{var r;if(this.activeScopes.size===0||((r=this.documentRef)==null?void 0:r.visibilityState)==="hidden"){n.released||await n.release();return}this.sentinel=n,n.addEventListener("release",()=>{var i;this.sentinel===n&&(this.sentinel=null),this.activeScopes.size>0&&((i=this.documentRef)==null?void 0:i.visibilityState)!=="hidden"&&this.ensureWakeLock().catch(()=>{})},{once:!0})}).finally(()=>{this.requestInFlight=null}),this.requestInFlight)}async releaseSentinel(){const t=this.sentinel;this.sentinel=null,!(!t||t.released)&&await t.release()}notify(t){var r;const n=this.getSnapshot(t);(r=this.listeners.get(t))==null||r.forEach(i=>i(n))}}const jl=new K1e;function _H(e){const[t,n]=b.useState(()=>jl.getSnapshot(e));b.useEffect(()=>jl.subscribe(e,n),[e]),b.useEffect(()=>()=>{jl.disable(e).catch(()=>{})},[e]);const r=b.useCallback(()=>jl.enable(e),[e]),i=b.useCallback(()=>jl.disable(e),[e]),s=b.useCallback(()=>jl.toggle(e),[e]);return{...t,enable:r,disable:i,toggle:s}}function G1e({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,y]=b.useState(!1);function g(){u(null),f(!1),y(!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){Ue.error(`请输入 ${r}–${i} 之间的整数`),w?y(!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:Ye("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),y(!1)},onBlur:()=>_(!1),onKeyDown:w=>{w.stopPropagation(),!w.nativeEvent.isComposing&&(w.key==="Enter"?(w.preventDefault(),_(!0)):w.key==="Escape"&&(w.preventDefault(),g()))}})}function X1e(){return new AudioContext}class Z1e{constructor(t=X1e){je(this,"context",null);this.createContext=t}get(){return this.context??(this.context=this.createContext()),this.context}async prepare(){const t=this.get();if(t.state!=="running"&&t.state!=="closed"&&await t.resume(),t.state!=="running")throw new Error("浏览器未允许播放 Voice Pilot 提示音");return t}async reactivateAfterCapture(){const t=this.get();if(t.state==="closed")throw new Error("Voice Pilot 播放上下文已关闭");if(t.state==="running"&&await t.suspend(),t.state!=="running"&&await t.resume(),t.state!=="running")throw new Error("浏览器未能恢复 Voice Pilot 音频输出");return t}}const Sy=new Z1e,VL=400,jd=[];let wH=1;function J1e(){return typeof performance>"u"?0:Math.round(performance.now()*10)/10}function xp(e){const t={sequence:wH++,timestamp:new Date().toISOString(),monotonicMs:J1e(),sessionId:e.sessionId,scope:e.scope,event:e.event,...e.attemptId?{attemptId:e.attemptId}:{},...e.requestId?{requestId:e.requestId}:{},...e.details?{details:{...e.details}}:{}};jd.push(t),jd.length>VL&&jd.splice(0,jd.length-VL)}function Q1e(){return jd.map(e=>({...e,...e.details?{details:{...e.details}}:{}}))}function eEe(){jd.length=0,wH=1}typeof window<"u"&&(window.__devAnywhereVoicePilotDiagnostics={snapshot:Q1e,clear:eEe});function xH(e){return`voice-pilot:${e}`}function tEe(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 nEe="modulepreload",rEe=function(e){return"/"+e},YL={},SH=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=rEe(d),d in YL)return;YL[d]=!0;const f=d.endsWith(".css"),h=f?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${d}"]${h}`))return;const y=document.createElement("link");if(y.rel=f?"stylesheet":nEe,f||(y.as="script"),y.crossOrigin="",y.href=d,u&&y.setAttribute("nonce",u),document.head.appendChild(y),f)return new Promise((g,_)=>{y.addEventListener("load",g),y.addEventListener("error",()=>_(new Error(`Unable to preload CSS for ${d}`)))})}))}function s(o){const l=new Event("vite:preloadError",{cancelable:!0});if(l.payload=o,window.dispatchEvent(l),!l.defaultPrevented)throw o}return i.then(o=>{for(const l of o||[])l.status==="rejected"&&s(l.reason);return t().catch(s)})},iEe="/assets/fvad-DYxbW2my.wasm",uf=16e3,sEe=20,Fl=uf*sEe/1e3,fS=Fl*Int16Array.BYTES_PER_ELEMENT;let KL=null;async function oEe(){return KL??(KL=SH(async()=>{const{default:e}=await import("./fvad-D1IHUtam.js");return{default:e}},[]).then(({default:e})=>e({locateFile:t=>t.endsWith(".wasm")?iEe:t}))),KL}class wT{constructor(t,n,r){je(this,"destroyed",!1);this.module=t,this.handle=n,this.framePointer=r}static async create(t=3){const n=await oEe(),r=n._fvad_new();if(!r)throw new Error("无法初始化浏览器语音活动检测器");const i=n._malloc(fS);if(!i)throw n._fvad_free(r),new Error("无法分配浏览器语音活动检测缓冲区");if(n._fvad_set_sample_rate(r,uf)!==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 wT(n,r,i)}process(t){if(this.destroyed)throw new Error("浏览器语音活动检测器已释放");if(t.byteLength!==fS)throw new Error(`语音活动检测帧必须为 ${fS} 字节`);this.module.HEAPU8.set(t,this.framePointer);const n=this.module._fvad_process(this.handle,this.framePointer,Fl);if(n<0)throw new Error("浏览器语音活动检测失败");return n===1}reset(){this.destroyed||this.module._fvad_reset(this.handle)}destroy(){this.destroyed||(this.destroyed=!0,this.module._free(this.framePointer),this.module._fvad_free(this.handle))}}class aEe{constructor(t={}){je(this,"startSpeechFrames");je(this,"endSilenceFrames");je(this,"active",!1);je(this,"speechFrames",0);je(this,"silenceFrames",0);if(this.startSpeechFrames=t.startSpeechFrames??10,this.endSilenceFrames=t.endSilenceFrames??30,this.startSpeechFrames<1||this.endSilenceFrames<1)throw new Error("Invalid voice activity gate configuration")}push(t){return this.active?t?(this.silenceFrames=0,"none"):(this.silenceFrames+=1,this.silenceFrames<this.endSilenceFrames?"none":(this.active=!1,this.silenceFrames=0,"speech-end")):(this.speechFrames=t?this.speechFrames+1:0,this.speechFrames>=this.startSpeechFrames?(this.active=!0,this.speechFrames=0,this.silenceFrames=0,"speech-start"):"none")}reset(){this.active=!1,this.speechFrames=0,this.silenceFrames=0}}class lEe{constructor(){je(this,"pending",new Float32Array(Fl));je(this,"pendingLength",0)}push(t,n){let r=0;if(this.pendingLength>0){const i=Fl-this.pendingLength,s=Math.min(i,t.length);this.pending.set(t.subarray(0,s),this.pendingLength),this.pendingLength+=s,r+=s,this.pendingLength===Fl&&(n(this.pending.slice()),this.pendingLength=0)}for(;r+Fl<=t.length;)n(t.slice(r,r+Fl)),r+=Fl;if(r<t.length){const i=t.subarray(r);this.pending.set(i,0),this.pendingLength=i.length}}reset(){this.pendingLength=0}}const cEe="/__dev_anywhere_debug/voice-fixture",uEe=uf*xF/1e3;function dEe(){return wT.create(3)}const fEe={createVad:dEe,getUserMedia:e=>navigator.mediaDevices.getUserMedia(e),createAudioContext:e=>new AudioContext(e),fetch:e=>fetch(e)};function hEe(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 pEe(e){for(const t of e.getTracks())t.stop()}function EH(e){const t=e.createAudioContext({sampleRate:uf});if(t.sampleRate!==uf)throw t.close().catch(()=>{}),new Error("浏览器无法提供 Voice Pilot 所需的 16 kHz 音频输入");return t}async function mEe(e){const t=EH(e);let n;try{n=await e.getUserMedia({audio:{channelCount:1,echoCancellation:!0,autoGainControl:!0,noiseSuppression:!0,sampleRate:uf}})}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(),pEe(n),t.state!=="closed"&&await t.close()}}}async function gEe(e,t){const n=EH(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 CH(e=window.location.search,t=!1){return t&&new URLSearchParams(e).get("voice-fixture")==="default"?{kind:"fixture",url:cEe}:{kind:"microphone"}}async function vEe(e,t=fEe){const n=await t.createVad();let r;try{r=e.source.kind==="fixture"?await gEe(e.source.url,t):await mEe(t)}catch(f){throw n.destroy(),f}const i=new aEe,s=new lEe,o=r.context.createScriptProcessor(uEe,1,1);let l=!1,u=null,d=null;return o.onaudioprocess=f=>{l&&s.push(f.inputBuffer.getChannelData(0),h=>{const y=tEe(h),g=n.process(y);e.onFrame({pcm:y,speechProbability:g?1:0,activityLevel:hEe(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 kH(e=pf().osName){return{mediaAccept:"image/*,video/*",fileAccept:e==="Android"?"application/*,text/*":void 0}}function yEe(e){const[t,n,...r]=Array.from(e);return t&&n===" "&&r.length>0?{indicator:t,label:r.join("")}:{label:e}}function bEe({title:e,isPtyTitle:t}){if(!t)return m.jsx(m.Fragment,{children:e});const{indicator:n,label:r}=yEe(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 _Ee(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 wEe(){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(_Ee(n),{cause:n})}finally{e==null||e.getTracks().forEach(n=>n.stop())}}const Ml="min-h-9 gap-2.5",$v="px-2 pb-1 pt-2 text-xs font-semibold text-muted-foreground",xEe=[{axis:"cols",label:"列数",unit:"列",Icon:GV,min:eb,max:iu},{axis:"rows",label:"行数",unit:"行",Icon:rK,min:tb,max:su}];function Bs({children:e,className:t}){return m.jsx("span",{"aria-hidden":"true","data-slot":"chat-menu-icon",className:Ye("inline-flex size-5 shrink-0 items-center justify-center text-muted-foreground [&_svg]:size-4",t),children:e})}function SEe({label:e}){return m.jsxs(Bs,{className:"relative",children:[m.jsx(SC,{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 EEe({sessionId:e,mode:t,onFind:n,onResizeTerminal:r}){const i=Gr(ve=>ve.homePath),s=kH(),o=Cs(),l=Ht(ve=>ve.sessions.find(rt=>rt.sessionId===e)),u=Ht(ve=>ve.ptyTitles[e]),d=Ht(ve=>ve.ptyGeometryBySessionId[e]),f=Ae(ve=>ve.ptyFontSize),h=Ae(ve=>ve.chatContentFontSize),y=Ae(ve=>ve.selectedProxyId),g=Ae(ve=>ve.connected),_=Ae(ve=>ve.proxyOnline),w=Ae(ve=>ve.adjustPtyFontSize),S=Ae(ve=>ve.adjustChatContentFontSize),x=Ae(ve=>ve.setChatContentFontSize),k=Ae(ve=>ve.resetPtyFontSize),R=Ae(ve=>ve.resetChatContentFontSize),A=Ae(ve=>ve.inputModePreference==="hardware"),O=Ht(ve=>ve.renameSession),T=WC(y,e),M=(l==null?void 0:l.provider)!=="codex",z=Ht(ve=>M&&T?!!ve.ptyAutoYesBySessionKey[T]:!1),Y=Ht(ve=>ve.setPtyAutoYes),G=yo("(pointer: coarse), (hover: none)")&&!A,I=t==="pty"||(l==null?void 0:l.mode)==="pty",N=u$(l??{}).menu,L=b.useRef(null),B=b.useRef(null),P=b.useRef(!1),[D,F]=b.useState(!1),q=(l==null?void 0:l.kind)==="terminal",j=_H(e),V=Mn(ve=>ve.bySessionId[e]??l_),K=Mn(ve=>ve.enable),$=Mn(ve=>ve.disable),te=!!(l!=null&&l.nameLocked&&(l!=null&&l.name)),re=JC(l,i),ee=te&&(l==null?void 0:l.name)||re||I&&u||(l==null?void 0:l.name)||e.slice(0,8),X=!!(I&&!q&&u&&!te),ae=I?f:AC(h,G),ne=!I&&G?Zz:Gz,ce=I?k:R,[_e,xe]=b.useState(!1),[We,De]=b.useState(!1),Pt=V.enabled,tt=j.active||Pt,lt=j.pending||!j.supported||Pt;function $e(ve){if(I){w(ve);return}if(G){x(ae+ve);return}S(ve)}function Fe(){j.toggle().catch(ve=>{Ue.error(ve instanceof Error?ve.message:String(ve))})}async function Te(ve){var ht;if(I||q){Ue.info("Voice Pilot 目前适用于聊天会话。");return}if(ve!==!0){$(e);return}const rt=Ft;if(!rt){Ue.error("请先连接开发机");return}try{if(!((ht=(await rt.requestVoiceConfig()).config)!=null&&ht.configured)){Ue.info("请先在设置里配置 Voice Pilot。");return}xe(!0)}catch(Mt){Ue.error(Mt instanceof Error?Mt.message:String(Mt))}}async function Ke(){var Mt;De(!0);let ve=null,rt=!1;const ht=xH(e);try{xp({sessionId:e,scope:"runtime",event:"wake-lock-requested",details:{userActivationActive:((Mt=navigator.userActivation)==null?void 0:Mt.isActive)??!1,visibilityState:document.visibilityState,secureContext:window.isSecureContext}});const It=jl.enable(ht).then(()=>{xp({sessionId:e,scope:"runtime",event:"wake-lock-acquired"})},wt=>{throw xp({sessionId:e,scope:"runtime",event:"wake-lock-failed",details:{error:wt instanceof Error?wt.message:String(wt)}}),new Error("屏幕常亮请求被浏览器拒绝,Voice Pilot 未开启。",{cause:wt})});ve=Pk.acquire("capture");const sn=Sy.prepare(),on=CH().kind==="microphone"?wEe():Promise.resolve();await Promise.all([It,sn,on]),K(e),rt=!0,xe(!1)}catch(It){xp({sessionId:e,scope:"runtime",event:"startup-failed",details:{error:It instanceof Error?It.message:String(It)}}),Ue.error(It instanceof Error?It.message:String(It))}finally{ve==null||ve.release(),rt||await jl.disable(ht).catch(()=>{}),De(!1)}}const Xe=b.useRef(null),Se=b.useRef(null),[it,vt]=b.useState(!1);async function ge(ve){var It;const rt=(It=ve.target.files)==null?void 0:It[0];if(ve.target.value="",!rt)return;const ht=Ft;if(!ht){Ue.error("请先连接开发机");return}const Mt=await nm({relay:ht,sessionId:e,file:rt});Mt&&Mo(e,`@${Mt} `)}async function Ge(ve,rt){const ht=Ft;if(!ht)throw new Error("请先连接开发机");const Mt=await ht.renameSession(ve,rt);if(!Mt.success)throw new Error(Mt.error??"重命名失败");O(ve,Mt.name??rt),Ue.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(yt,{variant:"ghost",size:"icon-sm",className:"md:hidden",onClick:()=>o("/sessions"),"aria-label":"返回会话列表","data-slot":"chat-back-button",children:m.jsx(ff,{"aria-hidden":"true"})})}),m.jsx("span",{className:"text-sm font-semibold truncate text-center px-2","data-slot":"chat-session-title",children:m.jsx(bEe,{title:ee,isPtyTitle:X})}),m.jsxs(_f,{modal:!1,onOpenChange:ve=>{ve?P.current=!1:F(!1)},children:[m.jsx(wf,{asChild:!0,children:m.jsx(yt,{ref:L,variant:"ghost",size:"icon-sm",className:"justify-self-end","aria-label":"会话操作","data-slot":"chat-overflow-trigger",onPointerDownCapture:ve=>{if(ve.currentTarget.getAttribute("data-state")==="open")return;const rt=document.activeElement,ht=rt==null?void 0:rt.closest('[data-slot="pty-keepalive-entry"]');B.current=I&&rt instanceof HTMLTextAreaElement&&rt.matches('[data-slot="pty-host"] .xterm-helper-textarea')&&(ht==null?void 0:ht.getAttribute("data-session-id"))===e&&ht.getAttribute("data-active")==="true"?rt:null},onKeyDownCapture:ve=>{["Enter"," ","ArrowDown"].includes(ve.key)&&(B.current=null)},children:m.jsx(iY,{"aria-hidden":"true"})})}),m.jsxs(xf,{align:"end",className:"w-max min-w-44 max-w-[calc(100vw-1rem)] data-[state=open]:animate-none","data-slot":"chat-overflow-menu",onEscapeKeyDown:ve=>{if(ve.target instanceof HTMLElement&&ve.target.matches('[data-terminal-dimension-input][data-editing="true"]')){ve.preventDefault();return}P.current=!0},onInteractOutside:()=>{const ve=document.activeElement;ve instanceof HTMLInputElement&&ve.hasAttribute("data-terminal-dimension-input")&&ve.blur()},onCloseAutoFocus:ve=>{const rt=B.current,ht=P.current;B.current=null,P.current=!1;const Mt=rt==null?void 0:rt.closest('[data-slot="pty-keepalive-entry"]'),It=document.activeElement;ve.defaultPrevented||!ht||!I||!(rt!=null&&rt.isConnected)||(Mt==null?void 0:Mt.getAttribute("data-session-id"))!==e||Mt.getAttribute("data-active")!=="true"||It!==document.body&&It!==document.documentElement&&It!==L.current&&It!==rt&&!(It!=null&&It.closest('[data-slot="chat-overflow-menu"]'))||(ve.preventDefault(),rt.focus({preventScroll:!0}))},children:[m.jsx(yv,{className:$v,children:"会话"}),m.jsxs(ti,{className:Ml,"data-slot":"chat-menu-find",onSelect:n,children:[m.jsx(Bs,{children:m.jsx(ky,{"aria-hidden":"true"})}),"在会话中查找"]}),m.jsxs(ti,{className:Ml,"data-slot":"chat-menu-rename",onSelect:()=>vt(!0),children:[m.jsx(Bs,{children:m.jsx(KY,{"aria-hidden":"true"})}),"重命名"]}),m.jsxs(y0,{checked:tt,className:Ye("min-h-9 justify-start gap-2.5 pl-2 pr-8 [&>span:first-child]:left-auto [&>span:first-child]:right-2",!j.supported&&!tt&&"pr-2"),disabled:lt,"data-slot":"chat-menu-screen-wake-lock-item",onCheckedChange:Fe,children:[m.jsx(Bs,{children:m.jsx(AY,{"aria-hidden":"true"})}),m.jsx("span",{className:"min-w-0 flex-1",children:j.supported?Pt?"屏幕常亮(Voice Pilot 控制)":"屏幕常亮":j.unavailableReason==="insecure-context"?"屏幕常亮(需要 HTTPS)":"屏幕常亮(浏览器不支持)"})]}),I&&!q&&M&&m.jsxs(y0,{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:!T,"data-slot":"chat-menu-pty-auto-yes-item",onCheckedChange:ve=>{T&&Y(T,ve===!0)},children:[m.jsx(Bs,{children:m.jsx(PK,{"aria-hidden":"true"})}),m.jsx("span",{className:"min-w-0 flex-1",children:"Always yes"})]}),!I&&!q&&m.jsxs(y0,{checked:V.enabled,className:"min-h-9 justify-start gap-2.5 pl-2 pr-8 [&>span:first-child]:left-auto [&>span:first-child]:right-2","data-slot":"chat-menu-voice-pilot-item",onCheckedChange:Te,children:[m.jsx(Bs,{children:m.jsx(BY,{"aria-hidden":"true"})}),m.jsx("span",{className:"min-w-0 flex-1",children:"Voice Pilot"})]}),m.jsx(Gc,{}),(l==null?void 0:l.mode)==="pty"&&l.ptyOwner==="proxy-hosted"&&r&&m.jsxs(m.Fragment,{children:[m.jsx(yv,{className:$v,children:"终端尺寸"}),m.jsxs(ti,{className:Ml,"data-slot":"chat-menu-fit-terminal",disabled:!g||!_||l.state==="error",onSelect:()=>r("fit"),children:[m.jsx(Bs,{children:m.jsx(OY,{"aria-hidden":"true"})}),"按窗口调整终端尺寸"]}),xEe.map(({axis:ve,label:rt,unit:ht,Icon:Mt,min:It,max:sn})=>{const Gt=d==null?void 0:d[ve],on=!g||!_||l.state==="error"||Gt===void 0;return m.jsxs("div",{role:"group","aria-label":rt,className:"flex min-h-9 items-center gap-2.5 px-2 text-sm","data-slot":`chat-menu-${ve}-control`,children:[m.jsx(Bs,{children:m.jsx(Mt,{"aria-hidden":"true"})}),m.jsx("span",{children:rt}),m.jsxs("div",{className:"inline-flex shrink-0 items-center gap-2",children:[m.jsx(yt,{variant:"ghost",size:"icon-sm",className:"size-[22px] rounded-[5px] bg-muted/45 text-muted-foreground hover:bg-accent hover:text-accent-foreground",disabled:on||Gt!==void 0&&Gt<=It,"aria-label":`减少${ht}`,"data-slot":`chat-menu-decrease-${ve}`,onClick:wt=>{wt.stopPropagation(),r(`decrease-${ve}`)},children:m.jsx(cP,{"aria-hidden":"true"})}),m.jsx(G1e,{axis:ve,label:rt,value:Gt,min:It,max:sn,disabled:on,onCommit:wt=>r({axis:ve,value:wt})},`${e}-${ve}`),m.jsx(yt,{variant:"ghost",size:"icon-sm",className:"size-[22px] rounded-[5px] bg-muted/45 text-muted-foreground hover:bg-accent hover:text-accent-foreground",disabled:on||Gt!==void 0&&Gt>=sn,"aria-label":`增加${ht}`,"data-slot":`chat-menu-increase-${ve}`,onClick:wt=>{wt.stopPropagation(),r(`increase-${ve}`)},children:m.jsx(uP,{"aria-hidden":"true"})})]})]},ve)}),m.jsx(Gc,{})]}),I&&m.jsxs(m.Fragment,{children:[m.jsxs(Ade,{open:D,onOpenChange:F,children:[m.jsxs(Nde,{className:Ye(Ml,"[&>svg:last-child]:ml-0"),"data-slot":"chat-menu-shortcuts-trigger",onClick:ve=>{D&&(ve.preventDefault(),F(!1))},children:[m.jsx(Bs,{children:m.jsx(SC,{"aria-hidden":"true"})}),"发送快捷键"]}),m.jsx(Rde,{children:m.jsx(Mde,{className:Ye("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,"data-slot":"chat-menu-shortcuts",children:N.map(ve=>m.jsxs(ti,{className:Ml,"data-slot":`chat-menu-send-${ve.id}`,disabled:!g||!_||(l==null?void 0:l.mode)!=="pty"||l.state==="error",onSelect:()=>Mo(e,ve.data),children:[m.jsx(SEe,{label:ve.display}),"发送 ",ve.key]},ve.id))})})]}),m.jsx(Gc,{})]}),I&&!q?m.jsxs(m.Fragment,{children:[m.jsx(yv,{className:$v,children:"文件"}),m.jsxs(ti,{className:Ml,"data-slot":"chat-menu-upload-image",onClick:()=>{var ve;return(ve=Se.current)==null?void 0:ve.click()},children:[m.jsx(Bs,{children:m.jsx(dm,{"aria-hidden":"true"})}),"上传照片或视频"]}),m.jsxs(ti,{className:Ml,"data-slot":"chat-menu-upload-file",onClick:()=>{var ve;return(ve=Xe.current)==null?void 0:ve.click()},children:[m.jsx(Bs,{children:m.jsx(Mz,{"aria-hidden":"true"})}),"上传文件"]}),m.jsx(Gc,{})]}):null,m.jsx(yv,{className:$v,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(Bs,{children:m.jsx(xK,{"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(yt,{variant:"ghost",size:"icon-sm",className:"size-[22px] rounded-[5px] bg-muted/45 text-muted-foreground hover:bg-accent hover:text-accent-foreground",disabled:ae<=ne,"aria-label":"字号变小","data-slot":"chat-menu-font-smaller",onClick:ve=>{ve.stopPropagation(),$e(-1)},children:m.jsx(cP,{"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:[ae,"px"]}),m.jsx(yt,{variant:"ghost",size:"icon-sm",className:"size-[22px] rounded-[5px] bg-muted/45 text-muted-foreground hover:bg-accent hover:text-accent-foreground",disabled:ae>=Xz,"aria-label":"字号变大","data-slot":"chat-menu-font-larger",onClick:ve=>{ve.stopPropagation(),$e(1)},children:m.jsx(uP,{"aria-hidden":"true"})})]})]})}),m.jsxs(ti,{className:Ml,"data-slot":"chat-menu-font-reset",onClick:ce,children:[m.jsx(Bs,{children:m.jsx(QY,{"aria-hidden":"true"})}),m.jsx("span",{"data-slot":"chat-menu-font-reset-label",children:"恢复默认"})]})]})]})]})}),m.jsx(up,{open:it,sessionId:e,initialName:l==null?void 0:l.name,onOpenChange:vt,onRename:Ge}),m.jsx(es,{open:_e&&!V.enabled,onOpenChange:ve=>{We||xe(ve)},children:m.jsxs(ts,{className:"sm:max-w-md","data-slot":"voice-pilot-wake-lock-dialog",focusSurfaceOnOpen:!0,children:[m.jsxs(ns,{children:[m.jsx($i,{children:"开启 Voice Pilot?"}),m.jsx(Es,{children:"开启后会持续聆听并保持屏幕常亮,停止后自动恢复。"})]}),m.jsxs(Vs,{children:[m.jsx(yt,{type:"button",variant:"outline",disabled:We,onClick:()=>xe(!1),children:"取消"}),m.jsx(yt,{type:"button","data-slot":"voice-pilot-confirm-start",disabled:We,onClick:()=>{Ke()},children:We?"正在开启...":"开启 Voice Pilot"})]})]})}),I?m.jsxs(m.Fragment,{children:[m.jsx("input",{ref:Se,type:"file",accept:s.mediaAccept,className:"hidden","data-slot":"chat-menu-upload-image-input",onChange:ve=>{ge(ve)}}),m.jsx("input",{ref:Xe,type:"file",accept:s.fileAccept,className:"hidden","data-slot":"chat-menu-upload-file-input",onChange:ve=>{ge(ve)}})]}):null]})}function _d(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=(k,R)=>{for(k=String(k);k.length<R;)k=" "+k;return k};console.info(`%c⏱ ${x(w,5)} /${x(_,5)} ms`,`
|
|
740
740
|
font-size: .6rem;
|
|
741
741
|
font-weight: bold;
|
|
742
742
|
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 GL(e,t){if(e===void 0)throw new Error("Unexpected undefined");return e}const CEe=(e,t)=>Math.abs(e-t)<1.01,kEe=(e,t,n)=>{let r;return function(...i){e.clearTimeout(r),r=e.setTimeout(()=>t.apply(this,i),n)}},XL=e=>{const{offsetWidth:t,offsetHeight:n}=e;return{width:t,height:n}},TEe=e=>e,REe=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},AEe=(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(XL(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(XL(n))};e.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(l):l()});return s.observe(n,{box:"border-box"}),()=>{s.unobserve(n)}},ZL={passive:!0},JL=typeof window>"u"?!0:"onscrollend"in window,NEe=(e,t)=>{const n=e.scrollElement;if(!n)return;const r=e.targetWindow;if(!r)return;let i=0;const s=e.options.useScrollendEvent&&JL?()=>{}:kEe(r,()=>{t(i,!1)},e.options.isScrollingResetDelay),o=f=>()=>{const{horizontal:h,isRtl:y}=e.options;i=h?n.scrollLeft*(y&&-1||1):n.scrollTop,s(),t(i,f)},l=o(!0),u=o(!1);n.addEventListener("scroll",l,ZL);const d=e.options.useScrollendEvent&&JL;return d&&n.addEventListener("scrollend",u,ZL),()=>{n.removeEventListener("scroll",l),d&&n.removeEventListener("scrollend",u)}},MEe=(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"]},PEe=(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 IEe{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:TEe,rangeExtractor:REe,onChange:()=>{},measureElement:MEe,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=_d(()=>(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=_d(()=>[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=_d(()=>[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),y=new Array(l).fill(void 0);for(let g=0;g<f;g++){const _=h[g];_&&(y[_.lane]=g)}for(let g=f;g<n;g++){const _=s(g),w=this.laneAssignments.get(g);let S,x;const k=u==="estimate"||d.has(_);if(w!==void 0&&this.options.lanes>1){S=w;const T=y[S],M=T!==void 0?h[T]:void 0;x=M?M.end+this.options.gap:r+i}else{const T=this.options.lanes===1?h[g-1]:this.getFurthestMeasurement(h,g);x=T?T.end+this.options.gap:r+i,S=T?T.lane:g%this.options.lanes,this.options.lanes>1&&k&&this.laneAssignments.set(g,S)}const R=d.get(_),A=typeof R=="number"?R:this.options.estimateSize(g),O=x+A;h[g]={index:g,start:x,size:A,end:O,key:_,lane:S},y[S]=g}return this.measurementsCache=h,h},{key:!1,debug:()=>this.options.debug}),this.calculateRange=_d(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(n,r,i,s)=>this.range=n.length>0&&r>0?OEe({measurements:n,outerSize:r,scrollOffset:i,lanes:s}):null,{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=_d(()=>{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=_d(()=>[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 GL(r[TH(0,r.length-1,i=>GL(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&&CEe(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 TH=(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 OEe({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=TH(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 QL=typeof document<"u"?b.useLayoutEffect:b.useEffect;function LEe({useFlushSync:e=!0,...t}){const n=b.useReducer(()=>({}),{})[1],r={...t,onChange:(s,o)=>{var l;e&&o?xu.flushSync(n):n(),(l=t.onChange)==null||l.call(t,s,o)}},[i]=b.useState(()=>new IEe(r));return i.setOptions(r),QL(()=>i._didMount(),[]),QL(()=>i._willUpdate()),i}function DEe(e){return LEe({observeElementRect:AEe,observeElementOffset:NEe,scrollToFn:PEe,...e})}function BEe(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=pT(i)?"image":gT(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 zEe(e){const t=BEe(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 jEe(e){return e.kind==="diff"}const FEe=12e4;function eD(e){return e?e.replace(/\r\n?/gu,`
|
|
@@ -861,4 +861,4 @@ fn main() {
|
|
|
861
861
|
---
|
|
862
862
|
|
|
863
863
|
_End of sample._
|
|
864
|
-
`;function RLe(){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(tC,{text:TLe})})})]})})}function E8(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 C8(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 ALe(e,t,n){if(!Number.isFinite(e)||!Number.isFinite(t))return null;const r=E8(n);return!r||e<r.left||e>r.right||t<r.top||t>r.bottom?null:C8(e,t,r)}function NLe(e,t,n){if(!Number.isFinite(e)||!Number.isFinite(t))return null;const r=E8(n);return r?C8(e,t,r):null}async function MLe(e){const t=e.slice();return createImageBitmap(new Blob([t.buffer],{type:"image/jpeg"}))}class PLe{constructor(t,n,r=MLe){je(this,"latest",null);je(this,"painting",!1);je(this,"disposed",!1);je(this,"generation",0);je(this,"lastSequence",-1);je(this,"sizeReportedGeneration",-1);this.canvas=t,this.onSize=n,this.decoder=r}enqueue(t,n){var r;this.disposed||t<=this.lastSequence||((r=this.latest)==null?void 0:r.generation)===this.generation&&t<=this.latest.sequence||(this.latest={generation:this.generation,sequence:t,jpeg:n.slice()},this.painting||this.paintLoop())}reset(t=!1){var n;this.disposed||(this.generation+=1,this.latest=null,this.lastSequence=-1,t&&((n=this.canvas.getContext("2d",{alpha:!1}))==null||n.clearRect(0,0,this.canvas.width,this.canvas.height)))}dispose(){this.disposed=!0,this.generation+=1,this.latest=null}async paintLoop(){var t;this.painting=!0;try{for(;!this.disposed&&this.latest;){const n=this.latest;this.latest=null;let r;try{r=await this.decoder(n.jpeg)}catch(i){!this.disposed&&n.generation===this.generation&&console.warn("Failed to decode device preview frame",i);continue}try{if(this.disposed||n.generation!==this.generation||n.sequence<=this.lastSequence)continue;const i=this.canvas.width!==r.width||this.canvas.height!==r.height;i&&(this.canvas.width=r.width,this.canvas.height=r.height),(i||this.sizeReportedGeneration!==n.generation)&&(this.sizeReportedGeneration=n.generation,this.onSize({width:r.width,height:r.height})),(t=this.canvas.getContext("2d",{alpha:!1}))==null||t.drawImage(r,0,0),this.lastSequence=n.sequence}finally{r.close()}}}finally{this.painting=!1,!this.disposed&&this.latest&&this.paintLoop()}}}const ILe=120,OLe=8*1024*1024,LLe=1e3/30,DLe=.15,BLe=100,zLe=.001;function jLe(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 Wc(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 FLe(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 $Le{constructor(t,n={}){je(this,"muxer",null);je(this,"initialSources");je(this,"initialVideoState");je(this,"configuration",null);je(this,"configurationApplied",!1);je(this,"muxerReady",!1);je(this,"awaitingKeyframe",!0);je(this,"pendingFrames",[]);je(this,"fedFramesAwaitingPlayback",[]);je(this,"bufferedPacketCount",0);je(this,"bufferedBytes",0);je(this,"maxBufferedPackets");je(this,"maxBufferedBytes");je(this,"lastObservedMediaTime",null);je(this,"resyncRequired",!1);je(this,"playPending",!1);je(this,"playRequested",!1);je(this,"started",!1);je(this,"destroyed",!1);je(this,"generation",0);je(this,"playbackDelayTimer",null);je(this,"handlePlaying",()=>{this.destroyed||(this.observePlaybackProgress(),this.playRequested=!0,this.markStarted())});je(this,"handleTimeUpdate",()=>{this.observePlaybackProgress()});je(this,"handleVideoError",()=>{this.destroyed||this.reportError(FLe(this.video))});this.video=t,this.options=n,this.maxBufferedPackets=TB(n.maxBufferedPackets,ILe),this.maxBufferedBytes=TB(n.maxBufferedBytes,OLe),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 SH(async()=>{const{default:r}=await import("./jmuxer.min-DyXp3arz.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(Wc(n,"Failed to initialize H.264 video playback")),this.destroy()}}feedConfiguration(t){if(this.configuration&&jLe(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:LLe,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(Wc(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()},BLe))}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<=DLe)return;this.video.currentTime=Math.max(0,n-zLe),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(Wc(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(Wc(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(Wc(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(Wc(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(Wc(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 TB(e,t){return typeof e=="number"&&Number.isSafeInteger(e)&&e>0?e:t}class HLe{constructor(){je(this,"buffer",new Uint8Array(0))}push(t){if(t.byteLength===0)return[];const n=new Uint8Array(this.buffer.byteLength+t.byteLength);n.set(this.buffer),n.set(t,this.buffer.byteLength),this.buffer=n;const r=[];let i=0;for(;this.buffer.byteLength-i>=Ah;){const s=new DataView(this.buffer.buffer,this.buffer.byteOffset+i,Ah),o=s.getUint32(0,!0),l=s.getUint32(4,!0);if(o===0||o>Oy)throw this.buffer=new Uint8Array(0),new RangeError(`Invalid device preview frame length: ${o}`);const u=Ah+o;if(this.buffer.byteLength-i<u)break;r.push({sequence:l,jpeg:this.buffer.slice(i+Ah,i+u)}),i+=u}if(i>0&&(this.buffer=this.buffer.slice(i)),this.buffer.byteLength>Ah+Oy)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 ULe{constructor(){je(this,"buffer",new Uint8Array(0))}push(t){if(t.byteLength===0)return[];const n=new Uint8Array(this.buffer.byteLength+t.byteLength);n.set(this.buffer),n.set(t,this.buffer.byteLength),this.buffer=n;const r=[];let i=0;for(;this.buffer.byteLength-i>=rp;){const s=this.buffer.subarray(i),o=zne(s);if(!o)throw this.buffer=new Uint8Array(0),new RangeError("Invalid H.264 device preview packet header");const l=rp+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+rp,i+l)}),i+=l}if(i>0&&(this.buffer=this.buffer.slice(i)),this.buffer.byteLength>rp+Oy)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 WLe(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 qLe(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 k8(e,t,n){WLe(e);const r=Sb(),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 VLe(e,t){const n=t.fetch??globalThis.fetch,r=await k8(e,t.signal,n);if(r.headers.get("X-Device-Preview-Format")!=="jpeg")throw new Error("开发机返回了错误的模拟器画面格式");const i=new HLe,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 YLe(e,t){var l;const n=t.fetch??globalThis.fetch,r=await k8(e,t.signal,n);if(r.headers.get("X-Device-Preview-Format")!=="h264_annex_b")throw new Error("开发机没有返回 H.264 模拟器画面");const i=qLe(r);i&&((l=t.onSize)==null||l.call(t,i));const s=new ULe,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 KLe=16,GLe=16;class XLe{constructor(t){je(this,"send");je(this,"onFailure");je(this,"now");je(this,"moveFlushMs");je(this,"maxInFlightMoves");je(this,"active",null);je(this,"inFlightMoves",0);je(this,"disposed",!1);je(this,"failed",!1);this.send=t.send,this.onFailure=t.onFailure,this.now=t.now??(()=>performance.now()),this.moveFlushMs=t.moveFlushMs??KLe,this.maxInFlightMoves=t.maxInFlightMoves??GLe}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 ZLe=15e3,JLe=1e4,QLe={ios:40,android:28},eDe={ios:{width:390,height:844},android:{width:412,height:915}};function tDe(){const{id:e=""}=uz(),t=Cs(),n=pr($e=>l5($e).find(Fe=>Fe.previewId===e)),r=pr($e=>$e.listLoaded),i=pr($e=>{var Fe;return((Fe=$e.authoritative)==null?void 0:Fe.scope)??null}),s=Zo($e=>uie($e,i,"device",e,"reconnect")),o=b.useRef(null),l=b.useRef(null),u=b.useRef(null),d=b.useRef(null),f=b.useRef(null),h=b.useRef(()=>{}),y=b.useRef(null),g=b.useRef(null),[_,w]=b.useState(0),[S,x]=b.useState("waiting"),[k,R]=b.useState(null),[A,O]=b.useState(null),[T,M]=b.useState(null),[z,Y]=b.useState(""),[U,G]=b.useState(!1),[I,N]=b.useState(!1),[L,B]=b.useState(!1),P=n==null?void 0:n.previewId,D=n==null?void 0:n.state,F=n==null?void 0:n.platform,q=b.useCallback(()=>{const $e=f.current;f.current=null,$e==null||$e.dispose()},[]);b.useEffect(()=>{if(F!=="ios"){d.current=null,M(null);return}const $e=o.current;if(!$e)return;const Fe=new PLe($e,M);return Fe.reset(!0),M(null),d.current=Fe,()=>{Fe.dispose(),d.current=null}},[P,F]),b.useEffect(()=>{if(q(),h.current=()=>{},y.current=null,g.current=null,O(null),N(!1),B(!1),!P||D!=="ready"){D==="disconnected"?(x("error"),R("模拟器已断开")):(x("waiting"),R(null));return}const $e=Ft,Fe=i;if(!$e||!Fe||!Nt.isActive($e,Fe)){x("error"),R("开发机连接已断开");return}let Te=!1,Ke=null,Xe=null,Se=null,it=null,vt=null,ge=0,Ge=!1;const ve=()=>{vt=null,Se==null||Se.abort(),Se=null,it==null||it.destroy(),it=null,Ke&&clearTimeout(Ke),Ke=null,Xe&&clearTimeout(Xe),Xe=null},rt=wt=>{x("streaming"),Xe&&clearTimeout(Xe),Xe=setTimeout(()=>{Xe=null,!(Te||wt.signal.aborted||vt!==wt.leaseId||!Nt.isActive($e,Fe))&&(ge=0)},JLe)},ht=()=>{if(Te||document.visibilityState==="hidden"||!Nt.isActive($e,Fe))return;const wt=Math.min(5e3,500*2**ge);ge+=1,Ke=setTimeout(()=>void Mt(),wt)},Mt=async()=>{var gn;if(q(),ve(),Te||document.visibilityState==="hidden"||!Nt.isActive($e,Fe))return;Ge=!1,(gn=d.current)==null||gn.reset(),M(null),x("connecting"),R(null),O(null);const wt=new AbortController;Se=wt;try{const Bt=await Nt.requestDevicePreviewStream(Fe,P,F==="android"?{format:"h264_annex_b"}:{format:"jpeg",maxFps:15},{signal:wt.signal});if(Te||wt.signal.aborted||!Nt.isActive($e,Fe)||!Bt)return;if(!Bt.success)throw new Error(Bt.error);const nn=Bt;if(vt=nn.leaseId,O(nn),F==="android"){const $n=l.current;if(!$n)throw new Error("无法初始化 Android 模拟器播放器");let Qn;const Pn=new Promise((ue,be)=>{Qn=be}),W=setTimeout(()=>{Qn(new Error("Android 模拟器画面启动超时"))},ZLe),ie=ue=>{Qn(ue instanceof Error?ue:new Error(String(ue)))},oe=new $Le($n,{onStart:()=>{clearTimeout(W),!(Te||nn.signal.aborted||!Nt.isActive($e,Fe))&&rt(nn)},onError:ie,onResyncRequired:ie});it=oe;try{await Promise.race([YLe(nn.url,{signal:nn.signal,onSize:ue=>{!Te&&!nn.signal.aborted&&Nt.isActive($e,Fe)&&M(ue)},onPacket:ue=>{!Te&&!nn.signal.aborted&&Nt.isActive($e,Fe)&&oe.feed(ue)}}),Pn])}finally{clearTimeout(W)}if(!Te&&!nn.signal.aborted&&Nt.isActive($e,Fe))throw new Error("模拟器画面已断开");return}let Rn=!1;if(await VLe(nn.url,{signal:nn.signal,onFrame:$n=>{if(Te||nn.signal.aborted||!Nt.isActive($e,Fe))return;const Qn=d.current;Qn&&(Qn.enqueue($n.sequence,$n.jpeg),Rn||(Rn=!0,rt(nn)))}}),!Te&&!nn.signal.aborted&&Nt.isActive($e,Fe))throw new Error("模拟器画面已断开")}catch(Bt){if(Te||wt.signal.aborted||!Nt.isActive($e,Fe))return;It(Bt,!1)}},It=(wt,gn)=>{if(Te||Ge||!Nt.isActive($e,Fe))return;Ge=!0;const Bt=wt instanceof Error?wt.message:"模拟器画面已断开";q(),ve(),y.current=null,g.current=null,O(null),N(!1),B(!1),x("error"),R(Bt),gn&&Ue.error(Bt),ht()},sn=(wt,gn,Bt=!0)=>{wt===vt&&It(gn,Bt)};h.current=sn;const Gt=$e.onMessage(wt=>{if(wt.type!=="device_preview_control_revoked_push"||!Qt(wt.scope,Fe)||wt.leaseId!==vt||!Nt.isActive($e,Fe))return;if(g.current=null,B(!1),wt.reason==="taken_over"){y.current=null,N(!1),q(),O(Bt=>(Bt==null?void 0:Bt.leaseId)===wt.leaseId?{...Bt,controlMode:"view_only"}:Bt),Ue.info("控制权已由其他页面接管");return}const gn=new Error(wt.reason==="proxy_offline"?"开发机连接已断开":wt.reason==="lease_expired"?"模拟器画面连接已过期":"模拟器画面已断开");sn(wt.leaseId,gn,!1)}),on=()=>{if(document.visibilityState==="hidden"){q(),ve(),y.current=null,g.current=null,O(null),N(!1),B(!1),x("waiting");return}ge=0,Mt()};return document.addEventListener("visibilitychange",on),Mt(),()=>{Te=!0,h.current===sn&&(h.current=()=>{}),Gt(),document.removeEventListener("visibilitychange",on),q(),ve()}},[q,P,F,i,D,_]),b.useEffect(()=>{var $e;($e=f.current)==null||$e.cancel()},[T==null?void 0:T.height,T==null?void 0:T.width]);const j=(n==null?void 0:n.state)==="ready"&&(A==null?void 0:A.previewId)===n.previewId&&i&&Qt(A.scope,i)?A:null,V=(n==null?void 0:n.interactive)===!0&&S==="streaming"&&(j==null?void 0:j.controlMode)==="controller";b.useEffect(()=>{q();const $e=Ft,Fe=j;if(!$e||!Fe||!V)return;const Te=new XLe({send:async Ke=>{const Xe=await Nt.sendDevicePreviewInput(Fe,Ke);if(!Xe)throw new Error("模拟器控制连接已失效");if(!Xe.success)throw new Error(Xe.error)},onFailure:Ke=>{f.current===Te&&h.current(Fe.leaseId,Ke)}});return f.current=Te,()=>{f.current===Te&&(f.current=null),Te.dispose()}},[V,j,q]);const K=T??eDe[(n==null?void 0:n.platform)==="android"?"android":"ios"],$=QLe[(n==null?void 0:n.platform)==="android"?"android":"ios"],te=K.width/K.height,re=K.width>K.height?"landscape":"portrait",ee=re==="landscape"?`, ${K.width}px`:"",X={aspectRatio:`${K.width} / ${K.height}`,width:`max(1px, min(calc(100cqw - ${$}px), calc(${(te*100).toFixed(6)}cqh - ${(te*$).toFixed(6)}px)${ee}))`};b.useEffect(()=>{V||G(!1)},[V]);const ae=b.useCallback(async($e,Fe=!0)=>{const Te=Ft,Ke=j;if(!Te||!Ke||!V)return!1;try{const Xe=await Nt.sendDevicePreviewInput(Ke,$e);return!Xe||!Nt.isActive(Te,Ke.scope)?!1:Xe.success?!0:(Fe&&Ue.error(Xe.error),!1)}catch(Xe){return Ke.signal.aborted||!Nt.isActive(Te,Ke.scope)||Fe&&Ue.error(Xe instanceof Error?Xe.message:"模拟器操作失败"),!1}},[V,j]);function ne($e,Fe){const Te=u.current;if(!Te||!T)return null;const Ke=Te.getBoundingClientRect(),Xe={left:Ke.left,top:Ke.top,width:Ke.width,height:Ke.height,frameWidth:T.width,frameHeight:T.height};return Fe==="start"?ALe($e.clientX,$e.clientY,Xe):NLe($e.clientX,$e.clientY,Xe)}function ce($e){var Ke,Xe;if(!V||$e.button!==0)return;const Fe=ne($e,"start");if(!Fe)return;const Te=f.current;Te!=null&&Te.begin($e.pointerId,Fe)&&($e.preventDefault(),(Xe=(Ke=$e.currentTarget).setPointerCapture)==null||Xe.call(Ke,$e.pointerId))}function _e($e){var Te;const Fe=ne($e,"captured");Fe&&(Te=f.current)!=null&&Te.move($e.pointerId,Fe)&&$e.preventDefault()}function xe($e){var Te;const Fe=ne($e,"captured");Fe&&((Te=f.current)!=null&&Te.end($e.pointerId,Fe))&&$e.preventDefault()}function We($e){var Fe;(Fe=f.current)==null||Fe.cancel($e.pointerId)}async function De(){const $e=Ft,Fe=j;if(!$e||!Fe||L||S!=="streaming")return;const Te=Symbol("device-preview-control-claim");g.current=Te,B(!0);try{const Ke=await Nt.claimDevicePreviewControl(Fe);if(g.current!==Te||!Ke||!Nt.isActive($e,Fe.scope))return;if(!Ke.success){Ue.error(Ke.error);return}O(Xe=>(Xe==null?void 0:Xe.leaseId)===Fe.leaseId?{...Xe,controlMode:"controller"}:Xe)}catch(Ke){if(g.current!==Te||Fe.signal.aborted||!Nt.isActive($e,Fe.scope))return;Ue.error(Ke instanceof Error?Ke.message:"暂时无法取得控制权")}finally{g.current===Te&&(g.current=null,B(!1))}}async function Pt($e){$e.preventDefault();const Fe=z;if(!Fe||I)return;const Te=Symbol("device-preview-text-input");y.current=Te,N(!0);const Ke=await ae({kind:"text",text:Fe});y.current===Te&&(Ke&&(Y(""),G(!1)),y.current=null,N(!1))}function tt(){var $e;($e=f.current)==null||$e.cancel(),ae({kind:"orientation",orientation:T&&T.width>T.height?"portrait":"landscape_right"})}async function lt(){if((n==null?void 0:n.state)!=="disconnected"){w(Te=>Te+1);return}const $e=Ft,Fe=Nt.getActiveScope();if(!$e||!Fe){Ue.error("请先连接开发机");return}try{const Te=await Nt.reconnectDevicePreview(Fe,n.previewId);Te.success||Ue.error(Te.error)}catch(Te){if(!Nt.isActive($e,Fe))return;Ue.error(Te instanceof Error?Te.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(yt,{variant:"ghost",size:"icon",className:"md:hidden","aria-label":"返回",onClick:()=>t("/sessions"),children:m.jsx(ff,{"aria-hidden":"true"})}),m.jsx(CC,{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(yt,{size:"sm",variant:"outline",disabled:L,onClick:()=>void De(),"data-slot":"device-preview-claim-control",children:"接管控制"}):m.jsx("span",{className:"text-xs text-muted-foreground",children:V?"可操控":S==="streaming"?"仅查看":"连接中"})]}),m.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-muted/30",children:m.jsxs("div",{className:Ye("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:Ye("relative isolate shrink-0 transition-[width,aspect-ratio] duration-300 ease-out motion-reduce:transition-none [container-type:size]",n.platform==="ios"?"[--device-screen-radius:clamp(22px,14cqmin,56px)] [--ios-rail:clamp(10px,4cqmin,16px)]":"[--device-screen-radius:clamp(14px,6.5cqw,38px)]"),style:X,"data-slot":"device-preview-device-shell","data-platform":n.platform,"data-orientation":re,children:[m.jsx(nDe,{platform:n.platform,orientation:re}),m.jsx("div",{ref:u,className:Ye("relative z-10 flex h-full w-full min-h-0 min-w-0 items-center justify-center overflow-hidden rounded-[var(--device-screen-radius)] bg-black ring-1 ring-black",V&&"cursor-pointer"),"data-slot":"device-preview-surface","data-control-enabled":V?"true":"false",children:n.platform==="android"?m.jsx("video",{ref:l,className:"pointer-events-none h-full w-full object-contain","data-slot":"device-preview-video",muted:!0,autoPlay:!0,playsInline:!0,disableRemotePlayback:!0,onLoadedMetadata:$e=>{const Fe=$e.currentTarget;Fe.videoWidth>0&&Fe.videoHeight>0&&M({width:Fe.videoWidth,height:Fe.videoHeight})},onResize:$e=>{const Fe=$e.currentTarget;Fe.videoWidth>0&&Fe.videoHeight>0&&M({width:Fe.videoWidth,height:Fe.videoHeight})}}):m.jsx("canvas",{ref:o,className:"pointer-events-none h-full w-full object-contain","data-slot":"device-preview-canvas"})}),m.jsx("div",{className:Ye("absolute inset-0 z-20 select-none rounded-[var(--device-screen-radius)]",V?"touch-none cursor-pointer":"pointer-events-none"),onPointerDown:ce,onPointerMove:_e,onPointerUp:xe,onPointerCancel:We,onLostPointerCapture:We,onContextMenu:$e=>{V&&$e.preventDefault()},"data-slot":"device-preview-input-surface","data-control-enabled":V?"true":"false","aria-hidden":"true"})]}),S!=="streaming"?m.jsx("div",{className:"absolute inset-0 z-30 flex items-center justify-center bg-background/55 p-6 backdrop-blur-[1px]","data-slot":"device-preview-stream-overlay","data-stream-status":S,children:m.jsx("div",{className:"grid max-w-sm justify-items-center gap-3 text-center",children:S==="error"?m.jsxs(m.Fragment,{children:[m.jsx("p",{className:"text-sm text-muted-foreground",children:k}),m.jsxs(yt,{variant:"outline",size:"sm",disabled:s,onClick:()=>void lt(),"data-slot":"device-preview-retry",children:[s?m.jsx(di,{className:"size-4 animate-spin","aria-hidden":!0}):null,s?"正在重新连接":"重新连接"]})]}):m.jsxs(m.Fragment,{children:[m.jsx(di,{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:Ye("flex max-w-full items-center gap-1 rounded-full border border-border/70 bg-card/85 p-1.5 shadow-xl ring-1 ring-black/5 backdrop-blur-xl",re==="portrait"&&"md:flex-col"),children:[m.jsx(jS,{control:"home",label:"主屏幕",disabled:!V,icon:m.jsx(xY,{"aria-hidden":"true"}),tooltipSide:re==="portrait"?"left":"top",onClick:()=>void ae({kind:"button",button:"home"})}),n.platform==="android"?m.jsx(jS,{control:"back",label:"返回",disabled:!V,icon:m.jsx(EK,{"aria-hidden":"true"}),tooltipSide:re==="portrait"?"left":"top",onClick:()=>void ae({kind:"button",button:"back"})}):null,m.jsx(jS,{control:"orientation",label:"旋转",disabled:!V||!T,icon:m.jsx(tK,{"aria-hidden":"true"}),tooltipSide:re==="portrait"?"left":"top",onClick:tt}),m.jsx("span",{className:Ye("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(Ub,{open:U,onOpenChange:$e=>{(!$e||V)&&G($e)},children:[m.jsxs(Sf,{children:[m.jsx(Ef,{asChild:!0,children:m.jsx(Wb,{asChild:!0,children:m.jsx(yt,{type:"button",variant:"ghost",size:"icon",className:Ye("size-11 rounded-full text-muted-foreground hover:text-foreground",U&&"bg-accent text-foreground"),disabled:!V,"aria-label":"粘贴文字","aria-expanded":U,"aria-controls":"device-preview-text-form","data-slot":"device-preview-text-toggle",children:m.jsx(WS,{"aria-hidden":"true"})})})}),m.jsx(Cf,{side:re==="portrait"?"left":"top",sideOffset:10,hideArrow:!0,children:"粘贴文字"})]}),m.jsx(qb,{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:$e=>void Pt($e),children:[m.jsx("textarea",{value:z,onChange:$e=>Y($e.target.value),disabled:!V||I,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(yt,{type:"submit",size:"icon",className:"size-10 rounded-xl",disabled:!V||!z||I,"aria-label":"粘贴","data-slot":"device-preview-send-text",children:I?m.jsx(di,{className:"animate-spin","aria-hidden":"true"}):m.jsx(WS,{"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(yt,{variant:"outline",onClick:()=>t("/sessions"),children:"返回"})]}):m.jsx(di,{className:"size-5 animate-spin text-muted-foreground","aria-label":"加载中"})})}function jS({control:e,label:t,icon:n,disabled:r,tooltipSide:i,onClick:s}){return m.jsxs(Sf,{children:[m.jsx(Ef,{asChild:!0,children:m.jsx(yt,{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(Cf,{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 nDe({platform:e,orientation:t}){const n=t==="portrait";return e==="ios"?m.jsxs("div",{"aria-hidden":"true","data-slot":"device-preview-device-chrome","data-platform":"ios","data-orientation":t,className:Ye("pointer-events-none absolute -inset-[var(--ios-rail)] z-0 select-none rounded-[calc(var(--device-screen-radius)+var(--ios-rail))] border border-black/85 bg-[#202024] ring-1 ring-black/30","shadow-[inset_1px_1px_0_rgba(255,255,255,0.16),inset_-1px_-1px_0_rgba(0,0,0,0.72)]"),children:[m.jsx("span",{className:"absolute inset-[2px] rounded-[calc(var(--device-screen-radius)+var(--ios-rail)-2px)] ring-1 ring-inset ring-white/[0.05]"}),n?m.jsxs(m.Fragment,{children:[m.jsx("span",{className:"absolute -left-[4px] top-[16%] h-[clamp(12px,4%,22px)] w-[4px] rounded-l-[3px] border border-r-0 border-black/70 bg-[#343439] shadow-[inset_1px_0_0_rgba(255,255,255,0.14)]"}),m.jsx("span",{className:"absolute -left-[4px] top-[23%] h-[clamp(24px,7%,42px)] w-[4px] rounded-l-[3px] border border-r-0 border-black/70 bg-[#343439] shadow-[inset_1px_0_0_rgba(255,255,255,0.14)]"}),m.jsx("span",{className:"absolute -left-[4px] top-[32%] h-[clamp(24px,7%,42px)] w-[4px] rounded-l-[3px] border border-r-0 border-black/70 bg-[#343439] shadow-[inset_1px_0_0_rgba(255,255,255,0.14)]"}),m.jsx("span",{className:"absolute -right-[4px] top-[28%] h-[clamp(36px,12%,64px)] w-[4px] rounded-r-[3px] border border-l-0 border-black/70 bg-[#343439] shadow-[inset_-1px_0_0_rgba(255,255,255,0.14)]"})]}):m.jsxs(m.Fragment,{children:[m.jsx("span",{className:"absolute -top-[4px] left-[16%] h-[4px] w-[clamp(12px,4%,22px)] rounded-t-[3px] border border-b-0 border-black/70 bg-[#343439] shadow-[inset_0_1px_0_rgba(255,255,255,0.14)]"}),m.jsx("span",{className:"absolute -top-[4px] left-[23%] h-[4px] w-[clamp(24px,7%,42px)] rounded-t-[3px] border border-b-0 border-black/70 bg-[#343439] shadow-[inset_0_1px_0_rgba(255,255,255,0.14)]"}),m.jsx("span",{className:"absolute -top-[4px] left-[32%] h-[4px] w-[clamp(24px,7%,42px)] rounded-t-[3px] border border-b-0 border-black/70 bg-[#343439] shadow-[inset_0_1px_0_rgba(255,255,255,0.14)]"}),m.jsx("span",{className:"absolute -bottom-[4px] left-[28%] h-[4px] w-[clamp(36px,12%,64px)] rounded-b-[3px] border border-t-0 border-black/70 bg-[#343439] shadow-[inset_0_-1px_0_rgba(255,255,255,0.14)]"})]})]}):m.jsxs("div",{"aria-hidden":"true","data-slot":"device-preview-device-chrome","data-platform":"android","data-orientation":t,className:Ye("pointer-events-none absolute -inset-[9px] z-0 select-none rounded-[calc(var(--device-screen-radius)+9px)] border border-black/70 bg-[linear-gradient(145deg,#68717a_0%,#22272d_22%,#08090b_58%,#454c55_100%)] ring-1 ring-white/15"),children:[m.jsx("span",{className:Ye("absolute rounded-full bg-white/25 shadow-sm",n?"left-1/2 top-[3px] h-px w-[14%] -translate-x-1/2":"left-[3px] top-1/2 h-[14%] w-px -translate-y-1/2")}),n?m.jsxs(m.Fragment,{children:[m.jsx("span",{className:"absolute -right-[4px] top-[20%] h-[14%] min-h-7 w-[3px] rounded-r-sm bg-slate-500 shadow-sm"}),m.jsx("span",{className:"absolute -right-[4px] top-[38%] h-[9%] min-h-4 w-[3px] rounded-r-sm bg-slate-400 shadow-sm"})]}):m.jsxs(m.Fragment,{children:[m.jsx("span",{className:"absolute -top-[4px] left-[20%] h-[3px] w-[14%] min-w-7 rounded-t-sm bg-slate-500 shadow-sm"}),m.jsx("span",{className:"absolute -top-[4px] left-[38%] h-[3px] w-[9%] min-w-4 rounded-t-sm bg-slate-400 shadow-sm"})]})]})}const Kd=eV([{path:"/",element:m.jsx($1e,{}),children:[{index:!0,element:m.jsx(H1e,{})},{path:"sessions",element:m.jsx(U1e,{})},{path:"chat/:id",element:m.jsx(mLe,{})},{path:"preview/device/:id",element:m.jsx(tDe,{})}]},{path:"/pty-test",element:m.jsx(_Le,{})},{path:"/tokens",element:m.jsx(kLe,{})},{path:"/markdown-test",element:m.jsx(RLe,{})}]);function rDe({browserName:e}){const[t,n]=b.useState("idle"),r=async()=>{const i=await Hp(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(Kz,{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(ZV,{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(yt,{className:"h-11 px-4",onClick:r,children:[t==="copied"?m.jsx(ua,{className:"size-4","aria-hidden":"true"}):m.jsx(xz,{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 iDe({children:e}){const t=F1e();return t.supported?e:m.jsx(rDe,{browserName:t.browserName})}function sDe(){return m.jsx(iDe,{children:m.jsx(oDe,{})})}function oDe(){return $se(),m.jsx(Ude,{delayDuration:200,children:m.jsx(E7,{router:Kd})})}function aDe(e=window.history){e.scrollRestoration="manual"}aDe();jG();fpe();FW.createRoot(document.getElementById("root")).render(m.jsx(b.StrictMode,{children:m.jsx(sDe,{})}));export{SH as _,sm as a,cDe as g};
|
|
864
|
+
`;function RLe(){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(tC,{text:TLe})})})]})})}function E8(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 C8(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 ALe(e,t,n){if(!Number.isFinite(e)||!Number.isFinite(t))return null;const r=E8(n);return!r||e<r.left||e>r.right||t<r.top||t>r.bottom?null:C8(e,t,r)}function NLe(e,t,n){if(!Number.isFinite(e)||!Number.isFinite(t))return null;const r=E8(n);return r?C8(e,t,r):null}async function MLe(e){const t=e.slice();return createImageBitmap(new Blob([t.buffer],{type:"image/jpeg"}))}class PLe{constructor(t,n,r=MLe){je(this,"latest",null);je(this,"painting",!1);je(this,"disposed",!1);je(this,"generation",0);je(this,"lastSequence",-1);je(this,"sizeReportedGeneration",-1);this.canvas=t,this.onSize=n,this.decoder=r}enqueue(t,n){var r;this.disposed||t<=this.lastSequence||((r=this.latest)==null?void 0:r.generation)===this.generation&&t<=this.latest.sequence||(this.latest={generation:this.generation,sequence:t,jpeg:n.slice()},this.painting||this.paintLoop())}reset(t=!1){var n;this.disposed||(this.generation+=1,this.latest=null,this.lastSequence=-1,t&&((n=this.canvas.getContext("2d",{alpha:!1}))==null||n.clearRect(0,0,this.canvas.width,this.canvas.height)))}dispose(){this.disposed=!0,this.generation+=1,this.latest=null}async paintLoop(){var t;this.painting=!0;try{for(;!this.disposed&&this.latest;){const n=this.latest;this.latest=null;let r;try{r=await this.decoder(n.jpeg)}catch(i){!this.disposed&&n.generation===this.generation&&console.warn("Failed to decode device preview frame",i);continue}try{if(this.disposed||n.generation!==this.generation||n.sequence<=this.lastSequence)continue;const i=this.canvas.width!==r.width||this.canvas.height!==r.height;i&&(this.canvas.width=r.width,this.canvas.height=r.height),(i||this.sizeReportedGeneration!==n.generation)&&(this.sizeReportedGeneration=n.generation,this.onSize({width:r.width,height:r.height})),(t=this.canvas.getContext("2d",{alpha:!1}))==null||t.drawImage(r,0,0),this.lastSequence=n.sequence}finally{r.close()}}}finally{this.painting=!1,!this.disposed&&this.latest&&this.paintLoop()}}}const ILe=120,OLe=8*1024*1024,LLe=1e3/30,DLe=.15,BLe=100,zLe=.001;function jLe(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 Wc(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 FLe(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 $Le{constructor(t,n={}){je(this,"muxer",null);je(this,"initialSources");je(this,"initialVideoState");je(this,"configuration",null);je(this,"configurationApplied",!1);je(this,"muxerReady",!1);je(this,"awaitingKeyframe",!0);je(this,"pendingFrames",[]);je(this,"fedFramesAwaitingPlayback",[]);je(this,"bufferedPacketCount",0);je(this,"bufferedBytes",0);je(this,"maxBufferedPackets");je(this,"maxBufferedBytes");je(this,"lastObservedMediaTime",null);je(this,"resyncRequired",!1);je(this,"playPending",!1);je(this,"playRequested",!1);je(this,"started",!1);je(this,"destroyed",!1);je(this,"generation",0);je(this,"playbackDelayTimer",null);je(this,"handlePlaying",()=>{this.destroyed||(this.observePlaybackProgress(),this.playRequested=!0,this.markStarted())});je(this,"handleTimeUpdate",()=>{this.observePlaybackProgress()});je(this,"handleVideoError",()=>{this.destroyed||this.reportError(FLe(this.video))});this.video=t,this.options=n,this.maxBufferedPackets=TB(n.maxBufferedPackets,ILe),this.maxBufferedBytes=TB(n.maxBufferedBytes,OLe),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 SH(async()=>{const{default:r}=await import("./jmuxer.min-M-MIxBvo.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(Wc(n,"Failed to initialize H.264 video playback")),this.destroy()}}feedConfiguration(t){if(this.configuration&&jLe(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:LLe,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(Wc(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()},BLe))}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<=DLe)return;this.video.currentTime=Math.max(0,n-zLe),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(Wc(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(Wc(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(Wc(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(Wc(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(Wc(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 TB(e,t){return typeof e=="number"&&Number.isSafeInteger(e)&&e>0?e:t}class HLe{constructor(){je(this,"buffer",new Uint8Array(0))}push(t){if(t.byteLength===0)return[];const n=new Uint8Array(this.buffer.byteLength+t.byteLength);n.set(this.buffer),n.set(t,this.buffer.byteLength),this.buffer=n;const r=[];let i=0;for(;this.buffer.byteLength-i>=Ah;){const s=new DataView(this.buffer.buffer,this.buffer.byteOffset+i,Ah),o=s.getUint32(0,!0),l=s.getUint32(4,!0);if(o===0||o>Oy)throw this.buffer=new Uint8Array(0),new RangeError(`Invalid device preview frame length: ${o}`);const u=Ah+o;if(this.buffer.byteLength-i<u)break;r.push({sequence:l,jpeg:this.buffer.slice(i+Ah,i+u)}),i+=u}if(i>0&&(this.buffer=this.buffer.slice(i)),this.buffer.byteLength>Ah+Oy)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 ULe{constructor(){je(this,"buffer",new Uint8Array(0))}push(t){if(t.byteLength===0)return[];const n=new Uint8Array(this.buffer.byteLength+t.byteLength);n.set(this.buffer),n.set(t,this.buffer.byteLength),this.buffer=n;const r=[];let i=0;for(;this.buffer.byteLength-i>=rp;){const s=this.buffer.subarray(i),o=zne(s);if(!o)throw this.buffer=new Uint8Array(0),new RangeError("Invalid H.264 device preview packet header");const l=rp+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+rp,i+l)}),i+=l}if(i>0&&(this.buffer=this.buffer.slice(i)),this.buffer.byteLength>rp+Oy)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 WLe(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 qLe(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 k8(e,t,n){WLe(e);const r=Sb(),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 VLe(e,t){const n=t.fetch??globalThis.fetch,r=await k8(e,t.signal,n);if(r.headers.get("X-Device-Preview-Format")!=="jpeg")throw new Error("开发机返回了错误的模拟器画面格式");const i=new HLe,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 YLe(e,t){var l;const n=t.fetch??globalThis.fetch,r=await k8(e,t.signal,n);if(r.headers.get("X-Device-Preview-Format")!=="h264_annex_b")throw new Error("开发机没有返回 H.264 模拟器画面");const i=qLe(r);i&&((l=t.onSize)==null||l.call(t,i));const s=new ULe,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 KLe=16,GLe=16;class XLe{constructor(t){je(this,"send");je(this,"onFailure");je(this,"now");je(this,"moveFlushMs");je(this,"maxInFlightMoves");je(this,"active",null);je(this,"inFlightMoves",0);je(this,"disposed",!1);je(this,"failed",!1);this.send=t.send,this.onFailure=t.onFailure,this.now=t.now??(()=>performance.now()),this.moveFlushMs=t.moveFlushMs??KLe,this.maxInFlightMoves=t.maxInFlightMoves??GLe}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 ZLe=15e3,JLe=1e4,QLe={ios:40,android:28},eDe={ios:{width:390,height:844},android:{width:412,height:915}};function tDe(){const{id:e=""}=uz(),t=Cs(),n=pr($e=>l5($e).find(Fe=>Fe.previewId===e)),r=pr($e=>$e.listLoaded),i=pr($e=>{var Fe;return((Fe=$e.authoritative)==null?void 0:Fe.scope)??null}),s=Zo($e=>uie($e,i,"device",e,"reconnect")),o=b.useRef(null),l=b.useRef(null),u=b.useRef(null),d=b.useRef(null),f=b.useRef(null),h=b.useRef(()=>{}),y=b.useRef(null),g=b.useRef(null),[_,w]=b.useState(0),[S,x]=b.useState("waiting"),[k,R]=b.useState(null),[A,O]=b.useState(null),[T,M]=b.useState(null),[z,Y]=b.useState(""),[U,G]=b.useState(!1),[I,N]=b.useState(!1),[L,B]=b.useState(!1),P=n==null?void 0:n.previewId,D=n==null?void 0:n.state,F=n==null?void 0:n.platform,q=b.useCallback(()=>{const $e=f.current;f.current=null,$e==null||$e.dispose()},[]);b.useEffect(()=>{if(F!=="ios"){d.current=null,M(null);return}const $e=o.current;if(!$e)return;const Fe=new PLe($e,M);return Fe.reset(!0),M(null),d.current=Fe,()=>{Fe.dispose(),d.current=null}},[P,F]),b.useEffect(()=>{if(q(),h.current=()=>{},y.current=null,g.current=null,O(null),N(!1),B(!1),!P||D!=="ready"){D==="disconnected"?(x("error"),R("模拟器已断开")):(x("waiting"),R(null));return}const $e=Ft,Fe=i;if(!$e||!Fe||!Nt.isActive($e,Fe)){x("error"),R("开发机连接已断开");return}let Te=!1,Ke=null,Xe=null,Se=null,it=null,vt=null,ge=0,Ge=!1;const ve=()=>{vt=null,Se==null||Se.abort(),Se=null,it==null||it.destroy(),it=null,Ke&&clearTimeout(Ke),Ke=null,Xe&&clearTimeout(Xe),Xe=null},rt=wt=>{x("streaming"),Xe&&clearTimeout(Xe),Xe=setTimeout(()=>{Xe=null,!(Te||wt.signal.aborted||vt!==wt.leaseId||!Nt.isActive($e,Fe))&&(ge=0)},JLe)},ht=()=>{if(Te||document.visibilityState==="hidden"||!Nt.isActive($e,Fe))return;const wt=Math.min(5e3,500*2**ge);ge+=1,Ke=setTimeout(()=>void Mt(),wt)},Mt=async()=>{var gn;if(q(),ve(),Te||document.visibilityState==="hidden"||!Nt.isActive($e,Fe))return;Ge=!1,(gn=d.current)==null||gn.reset(),M(null),x("connecting"),R(null),O(null);const wt=new AbortController;Se=wt;try{const Bt=await Nt.requestDevicePreviewStream(Fe,P,F==="android"?{format:"h264_annex_b"}:{format:"jpeg",maxFps:15},{signal:wt.signal});if(Te||wt.signal.aborted||!Nt.isActive($e,Fe)||!Bt)return;if(!Bt.success)throw new Error(Bt.error);const nn=Bt;if(vt=nn.leaseId,O(nn),F==="android"){const $n=l.current;if(!$n)throw new Error("无法初始化 Android 模拟器播放器");let Qn;const Pn=new Promise((ue,be)=>{Qn=be}),W=setTimeout(()=>{Qn(new Error("Android 模拟器画面启动超时"))},ZLe),ie=ue=>{Qn(ue instanceof Error?ue:new Error(String(ue)))},oe=new $Le($n,{onStart:()=>{clearTimeout(W),!(Te||nn.signal.aborted||!Nt.isActive($e,Fe))&&rt(nn)},onError:ie,onResyncRequired:ie});it=oe;try{await Promise.race([YLe(nn.url,{signal:nn.signal,onSize:ue=>{!Te&&!nn.signal.aborted&&Nt.isActive($e,Fe)&&M(ue)},onPacket:ue=>{!Te&&!nn.signal.aborted&&Nt.isActive($e,Fe)&&oe.feed(ue)}}),Pn])}finally{clearTimeout(W)}if(!Te&&!nn.signal.aborted&&Nt.isActive($e,Fe))throw new Error("模拟器画面已断开");return}let Rn=!1;if(await VLe(nn.url,{signal:nn.signal,onFrame:$n=>{if(Te||nn.signal.aborted||!Nt.isActive($e,Fe))return;const Qn=d.current;Qn&&(Qn.enqueue($n.sequence,$n.jpeg),Rn||(Rn=!0,rt(nn)))}}),!Te&&!nn.signal.aborted&&Nt.isActive($e,Fe))throw new Error("模拟器画面已断开")}catch(Bt){if(Te||wt.signal.aborted||!Nt.isActive($e,Fe))return;It(Bt,!1)}},It=(wt,gn)=>{if(Te||Ge||!Nt.isActive($e,Fe))return;Ge=!0;const Bt=wt instanceof Error?wt.message:"模拟器画面已断开";q(),ve(),y.current=null,g.current=null,O(null),N(!1),B(!1),x("error"),R(Bt),gn&&Ue.error(Bt),ht()},sn=(wt,gn,Bt=!0)=>{wt===vt&&It(gn,Bt)};h.current=sn;const Gt=$e.onMessage(wt=>{if(wt.type!=="device_preview_control_revoked_push"||!Qt(wt.scope,Fe)||wt.leaseId!==vt||!Nt.isActive($e,Fe))return;if(g.current=null,B(!1),wt.reason==="taken_over"){y.current=null,N(!1),q(),O(Bt=>(Bt==null?void 0:Bt.leaseId)===wt.leaseId?{...Bt,controlMode:"view_only"}:Bt),Ue.info("控制权已由其他页面接管");return}const gn=new Error(wt.reason==="proxy_offline"?"开发机连接已断开":wt.reason==="lease_expired"?"模拟器画面连接已过期":"模拟器画面已断开");sn(wt.leaseId,gn,!1)}),on=()=>{if(document.visibilityState==="hidden"){q(),ve(),y.current=null,g.current=null,O(null),N(!1),B(!1),x("waiting");return}ge=0,Mt()};return document.addEventListener("visibilitychange",on),Mt(),()=>{Te=!0,h.current===sn&&(h.current=()=>{}),Gt(),document.removeEventListener("visibilitychange",on),q(),ve()}},[q,P,F,i,D,_]),b.useEffect(()=>{var $e;($e=f.current)==null||$e.cancel()},[T==null?void 0:T.height,T==null?void 0:T.width]);const j=(n==null?void 0:n.state)==="ready"&&(A==null?void 0:A.previewId)===n.previewId&&i&&Qt(A.scope,i)?A:null,V=(n==null?void 0:n.interactive)===!0&&S==="streaming"&&(j==null?void 0:j.controlMode)==="controller";b.useEffect(()=>{q();const $e=Ft,Fe=j;if(!$e||!Fe||!V)return;const Te=new XLe({send:async Ke=>{const Xe=await Nt.sendDevicePreviewInput(Fe,Ke);if(!Xe)throw new Error("模拟器控制连接已失效");if(!Xe.success)throw new Error(Xe.error)},onFailure:Ke=>{f.current===Te&&h.current(Fe.leaseId,Ke)}});return f.current=Te,()=>{f.current===Te&&(f.current=null),Te.dispose()}},[V,j,q]);const K=T??eDe[(n==null?void 0:n.platform)==="android"?"android":"ios"],$=QLe[(n==null?void 0:n.platform)==="android"?"android":"ios"],te=K.width/K.height,re=K.width>K.height?"landscape":"portrait",ee=re==="landscape"?`, ${K.width}px`:"",X={aspectRatio:`${K.width} / ${K.height}`,width:`max(1px, min(calc(100cqw - ${$}px), calc(${(te*100).toFixed(6)}cqh - ${(te*$).toFixed(6)}px)${ee}))`};b.useEffect(()=>{V||G(!1)},[V]);const ae=b.useCallback(async($e,Fe=!0)=>{const Te=Ft,Ke=j;if(!Te||!Ke||!V)return!1;try{const Xe=await Nt.sendDevicePreviewInput(Ke,$e);return!Xe||!Nt.isActive(Te,Ke.scope)?!1:Xe.success?!0:(Fe&&Ue.error(Xe.error),!1)}catch(Xe){return Ke.signal.aborted||!Nt.isActive(Te,Ke.scope)||Fe&&Ue.error(Xe instanceof Error?Xe.message:"模拟器操作失败"),!1}},[V,j]);function ne($e,Fe){const Te=u.current;if(!Te||!T)return null;const Ke=Te.getBoundingClientRect(),Xe={left:Ke.left,top:Ke.top,width:Ke.width,height:Ke.height,frameWidth:T.width,frameHeight:T.height};return Fe==="start"?ALe($e.clientX,$e.clientY,Xe):NLe($e.clientX,$e.clientY,Xe)}function ce($e){var Ke,Xe;if(!V||$e.button!==0)return;const Fe=ne($e,"start");if(!Fe)return;const Te=f.current;Te!=null&&Te.begin($e.pointerId,Fe)&&($e.preventDefault(),(Xe=(Ke=$e.currentTarget).setPointerCapture)==null||Xe.call(Ke,$e.pointerId))}function _e($e){var Te;const Fe=ne($e,"captured");Fe&&(Te=f.current)!=null&&Te.move($e.pointerId,Fe)&&$e.preventDefault()}function xe($e){var Te;const Fe=ne($e,"captured");Fe&&((Te=f.current)!=null&&Te.end($e.pointerId,Fe))&&$e.preventDefault()}function We($e){var Fe;(Fe=f.current)==null||Fe.cancel($e.pointerId)}async function De(){const $e=Ft,Fe=j;if(!$e||!Fe||L||S!=="streaming")return;const Te=Symbol("device-preview-control-claim");g.current=Te,B(!0);try{const Ke=await Nt.claimDevicePreviewControl(Fe);if(g.current!==Te||!Ke||!Nt.isActive($e,Fe.scope))return;if(!Ke.success){Ue.error(Ke.error);return}O(Xe=>(Xe==null?void 0:Xe.leaseId)===Fe.leaseId?{...Xe,controlMode:"controller"}:Xe)}catch(Ke){if(g.current!==Te||Fe.signal.aborted||!Nt.isActive($e,Fe.scope))return;Ue.error(Ke instanceof Error?Ke.message:"暂时无法取得控制权")}finally{g.current===Te&&(g.current=null,B(!1))}}async function Pt($e){$e.preventDefault();const Fe=z;if(!Fe||I)return;const Te=Symbol("device-preview-text-input");y.current=Te,N(!0);const Ke=await ae({kind:"text",text:Fe});y.current===Te&&(Ke&&(Y(""),G(!1)),y.current=null,N(!1))}function tt(){var $e;($e=f.current)==null||$e.cancel(),ae({kind:"orientation",orientation:T&&T.width>T.height?"portrait":"landscape_right"})}async function lt(){if((n==null?void 0:n.state)!=="disconnected"){w(Te=>Te+1);return}const $e=Ft,Fe=Nt.getActiveScope();if(!$e||!Fe){Ue.error("请先连接开发机");return}try{const Te=await Nt.reconnectDevicePreview(Fe,n.previewId);Te.success||Ue.error(Te.error)}catch(Te){if(!Nt.isActive($e,Fe))return;Ue.error(Te instanceof Error?Te.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(yt,{variant:"ghost",size:"icon",className:"md:hidden","aria-label":"返回",onClick:()=>t("/sessions"),children:m.jsx(ff,{"aria-hidden":"true"})}),m.jsx(CC,{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(yt,{size:"sm",variant:"outline",disabled:L,onClick:()=>void De(),"data-slot":"device-preview-claim-control",children:"接管控制"}):m.jsx("span",{className:"text-xs text-muted-foreground",children:V?"可操控":S==="streaming"?"仅查看":"连接中"})]}),m.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-muted/30",children:m.jsxs("div",{className:Ye("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:Ye("relative isolate shrink-0 transition-[width,aspect-ratio] duration-300 ease-out motion-reduce:transition-none [container-type:size]",n.platform==="ios"?"[--device-screen-radius:clamp(22px,14cqmin,56px)] [--ios-rail:clamp(10px,4cqmin,16px)]":"[--device-screen-radius:clamp(14px,6.5cqw,38px)]"),style:X,"data-slot":"device-preview-device-shell","data-platform":n.platform,"data-orientation":re,children:[m.jsx(nDe,{platform:n.platform,orientation:re}),m.jsx("div",{ref:u,className:Ye("relative z-10 flex h-full w-full min-h-0 min-w-0 items-center justify-center overflow-hidden rounded-[var(--device-screen-radius)] bg-black ring-1 ring-black",V&&"cursor-pointer"),"data-slot":"device-preview-surface","data-control-enabled":V?"true":"false",children:n.platform==="android"?m.jsx("video",{ref:l,className:"pointer-events-none h-full w-full object-contain","data-slot":"device-preview-video",muted:!0,autoPlay:!0,playsInline:!0,disableRemotePlayback:!0,onLoadedMetadata:$e=>{const Fe=$e.currentTarget;Fe.videoWidth>0&&Fe.videoHeight>0&&M({width:Fe.videoWidth,height:Fe.videoHeight})},onResize:$e=>{const Fe=$e.currentTarget;Fe.videoWidth>0&&Fe.videoHeight>0&&M({width:Fe.videoWidth,height:Fe.videoHeight})}}):m.jsx("canvas",{ref:o,className:"pointer-events-none h-full w-full object-contain","data-slot":"device-preview-canvas"})}),m.jsx("div",{className:Ye("absolute inset-0 z-20 select-none rounded-[var(--device-screen-radius)]",V?"touch-none cursor-pointer":"pointer-events-none"),onPointerDown:ce,onPointerMove:_e,onPointerUp:xe,onPointerCancel:We,onLostPointerCapture:We,onContextMenu:$e=>{V&&$e.preventDefault()},"data-slot":"device-preview-input-surface","data-control-enabled":V?"true":"false","aria-hidden":"true"})]}),S!=="streaming"?m.jsx("div",{className:"absolute inset-0 z-30 flex items-center justify-center bg-background/55 p-6 backdrop-blur-[1px]","data-slot":"device-preview-stream-overlay","data-stream-status":S,children:m.jsx("div",{className:"grid max-w-sm justify-items-center gap-3 text-center",children:S==="error"?m.jsxs(m.Fragment,{children:[m.jsx("p",{className:"text-sm text-muted-foreground",children:k}),m.jsxs(yt,{variant:"outline",size:"sm",disabled:s,onClick:()=>void lt(),"data-slot":"device-preview-retry",children:[s?m.jsx(di,{className:"size-4 animate-spin","aria-hidden":!0}):null,s?"正在重新连接":"重新连接"]})]}):m.jsxs(m.Fragment,{children:[m.jsx(di,{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:Ye("flex max-w-full items-center gap-1 rounded-full border border-border/70 bg-card/85 p-1.5 shadow-xl ring-1 ring-black/5 backdrop-blur-xl",re==="portrait"&&"md:flex-col"),children:[m.jsx(jS,{control:"home",label:"主屏幕",disabled:!V,icon:m.jsx(xY,{"aria-hidden":"true"}),tooltipSide:re==="portrait"?"left":"top",onClick:()=>void ae({kind:"button",button:"home"})}),n.platform==="android"?m.jsx(jS,{control:"back",label:"返回",disabled:!V,icon:m.jsx(EK,{"aria-hidden":"true"}),tooltipSide:re==="portrait"?"left":"top",onClick:()=>void ae({kind:"button",button:"back"})}):null,m.jsx(jS,{control:"orientation",label:"旋转",disabled:!V||!T,icon:m.jsx(tK,{"aria-hidden":"true"}),tooltipSide:re==="portrait"?"left":"top",onClick:tt}),m.jsx("span",{className:Ye("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(Ub,{open:U,onOpenChange:$e=>{(!$e||V)&&G($e)},children:[m.jsxs(Sf,{children:[m.jsx(Ef,{asChild:!0,children:m.jsx(Wb,{asChild:!0,children:m.jsx(yt,{type:"button",variant:"ghost",size:"icon",className:Ye("size-11 rounded-full text-muted-foreground hover:text-foreground",U&&"bg-accent text-foreground"),disabled:!V,"aria-label":"粘贴文字","aria-expanded":U,"aria-controls":"device-preview-text-form","data-slot":"device-preview-text-toggle",children:m.jsx(WS,{"aria-hidden":"true"})})})}),m.jsx(Cf,{side:re==="portrait"?"left":"top",sideOffset:10,hideArrow:!0,children:"粘贴文字"})]}),m.jsx(qb,{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:$e=>void Pt($e),children:[m.jsx("textarea",{value:z,onChange:$e=>Y($e.target.value),disabled:!V||I,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(yt,{type:"submit",size:"icon",className:"size-10 rounded-xl",disabled:!V||!z||I,"aria-label":"粘贴","data-slot":"device-preview-send-text",children:I?m.jsx(di,{className:"animate-spin","aria-hidden":"true"}):m.jsx(WS,{"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(yt,{variant:"outline",onClick:()=>t("/sessions"),children:"返回"})]}):m.jsx(di,{className:"size-5 animate-spin text-muted-foreground","aria-label":"加载中"})})}function jS({control:e,label:t,icon:n,disabled:r,tooltipSide:i,onClick:s}){return m.jsxs(Sf,{children:[m.jsx(Ef,{asChild:!0,children:m.jsx(yt,{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(Cf,{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 nDe({platform:e,orientation:t}){const n=t==="portrait";return e==="ios"?m.jsxs("div",{"aria-hidden":"true","data-slot":"device-preview-device-chrome","data-platform":"ios","data-orientation":t,className:Ye("pointer-events-none absolute -inset-[var(--ios-rail)] z-0 select-none rounded-[calc(var(--device-screen-radius)+var(--ios-rail))] border border-black/85 bg-[#202024] ring-1 ring-black/30","shadow-[inset_1px_1px_0_rgba(255,255,255,0.16),inset_-1px_-1px_0_rgba(0,0,0,0.72)]"),children:[m.jsx("span",{className:"absolute inset-[2px] rounded-[calc(var(--device-screen-radius)+var(--ios-rail)-2px)] ring-1 ring-inset ring-white/[0.05]"}),n?m.jsxs(m.Fragment,{children:[m.jsx("span",{className:"absolute -left-[4px] top-[16%] h-[clamp(12px,4%,22px)] w-[4px] rounded-l-[3px] border border-r-0 border-black/70 bg-[#343439] shadow-[inset_1px_0_0_rgba(255,255,255,0.14)]"}),m.jsx("span",{className:"absolute -left-[4px] top-[23%] h-[clamp(24px,7%,42px)] w-[4px] rounded-l-[3px] border border-r-0 border-black/70 bg-[#343439] shadow-[inset_1px_0_0_rgba(255,255,255,0.14)]"}),m.jsx("span",{className:"absolute -left-[4px] top-[32%] h-[clamp(24px,7%,42px)] w-[4px] rounded-l-[3px] border border-r-0 border-black/70 bg-[#343439] shadow-[inset_1px_0_0_rgba(255,255,255,0.14)]"}),m.jsx("span",{className:"absolute -right-[4px] top-[28%] h-[clamp(36px,12%,64px)] w-[4px] rounded-r-[3px] border border-l-0 border-black/70 bg-[#343439] shadow-[inset_-1px_0_0_rgba(255,255,255,0.14)]"})]}):m.jsxs(m.Fragment,{children:[m.jsx("span",{className:"absolute -top-[4px] left-[16%] h-[4px] w-[clamp(12px,4%,22px)] rounded-t-[3px] border border-b-0 border-black/70 bg-[#343439] shadow-[inset_0_1px_0_rgba(255,255,255,0.14)]"}),m.jsx("span",{className:"absolute -top-[4px] left-[23%] h-[4px] w-[clamp(24px,7%,42px)] rounded-t-[3px] border border-b-0 border-black/70 bg-[#343439] shadow-[inset_0_1px_0_rgba(255,255,255,0.14)]"}),m.jsx("span",{className:"absolute -top-[4px] left-[32%] h-[4px] w-[clamp(24px,7%,42px)] rounded-t-[3px] border border-b-0 border-black/70 bg-[#343439] shadow-[inset_0_1px_0_rgba(255,255,255,0.14)]"}),m.jsx("span",{className:"absolute -bottom-[4px] left-[28%] h-[4px] w-[clamp(36px,12%,64px)] rounded-b-[3px] border border-t-0 border-black/70 bg-[#343439] shadow-[inset_0_-1px_0_rgba(255,255,255,0.14)]"})]})]}):m.jsxs("div",{"aria-hidden":"true","data-slot":"device-preview-device-chrome","data-platform":"android","data-orientation":t,className:Ye("pointer-events-none absolute -inset-[9px] z-0 select-none rounded-[calc(var(--device-screen-radius)+9px)] border border-black/70 bg-[linear-gradient(145deg,#68717a_0%,#22272d_22%,#08090b_58%,#454c55_100%)] ring-1 ring-white/15"),children:[m.jsx("span",{className:Ye("absolute rounded-full bg-white/25 shadow-sm",n?"left-1/2 top-[3px] h-px w-[14%] -translate-x-1/2":"left-[3px] top-1/2 h-[14%] w-px -translate-y-1/2")}),n?m.jsxs(m.Fragment,{children:[m.jsx("span",{className:"absolute -right-[4px] top-[20%] h-[14%] min-h-7 w-[3px] rounded-r-sm bg-slate-500 shadow-sm"}),m.jsx("span",{className:"absolute -right-[4px] top-[38%] h-[9%] min-h-4 w-[3px] rounded-r-sm bg-slate-400 shadow-sm"})]}):m.jsxs(m.Fragment,{children:[m.jsx("span",{className:"absolute -top-[4px] left-[20%] h-[3px] w-[14%] min-w-7 rounded-t-sm bg-slate-500 shadow-sm"}),m.jsx("span",{className:"absolute -top-[4px] left-[38%] h-[3px] w-[9%] min-w-4 rounded-t-sm bg-slate-400 shadow-sm"})]})]})}const Kd=eV([{path:"/",element:m.jsx($1e,{}),children:[{index:!0,element:m.jsx(H1e,{})},{path:"sessions",element:m.jsx(U1e,{})},{path:"chat/:id",element:m.jsx(mLe,{})},{path:"preview/device/:id",element:m.jsx(tDe,{})}]},{path:"/pty-test",element:m.jsx(_Le,{})},{path:"/tokens",element:m.jsx(kLe,{})},{path:"/markdown-test",element:m.jsx(RLe,{})}]);function rDe({browserName:e}){const[t,n]=b.useState("idle"),r=async()=>{const i=await Hp(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(Kz,{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(ZV,{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(yt,{className:"h-11 px-4",onClick:r,children:[t==="copied"?m.jsx(ua,{className:"size-4","aria-hidden":"true"}):m.jsx(xz,{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 iDe({children:e}){const t=F1e();return t.supported?e:m.jsx(rDe,{browserName:t.browserName})}function sDe(){return m.jsx(iDe,{children:m.jsx(oDe,{})})}function oDe(){return $se(),m.jsx(Ude,{delayDuration:200,children:m.jsx(E7,{router:Kd})})}function aDe(e=window.history){e.scrollRestoration="manual"}aDe();jG();fpe();FW.createRoot(document.getElementById("root")).render(m.jsx(b.StrictMode,{children:m.jsx(sDe,{})}));export{SH as _,sm as a,cDe as g};
|