@pablopunk/webr 0.3.9 → 0.3.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
1
  const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["_astro/xterm.B-l5AIf6.js","_astro/client.CLSsMr2g.js","_astro/addon-fit.jgKqzwky.js","_astro/addon-web-links.C9lyQRxI.js","_astro/addon-webgl.Bd5ox92E.js"])))=>i.map(i=>d[i]);
2
- import{a as e,i as t,n,r,t as i}from"./client.CLSsMr2g.js";import{t as a}from"./client.Bbg9OBwT.js";var o=e=>e.replace(/([a-z0-9])([A-Z])/g,`$1-$2`).toLowerCase(),s=(...e)=>e.filter((e,t,n)=>!!e&&e.trim()!==``&&n.indexOf(e)===t).join(` `).trim(),c={xmlns:`http://www.w3.org/2000/svg`,width:24,height:24,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,strokeLinecap:`round`,strokeLinejoin:`round`},l=e(r()),u=(0,l.forwardRef)(({color:e=`currentColor`,size:t=24,strokeWidth:n=2,absoluteStrokeWidth:r,className:i=``,children:a,iconNode:o,...u},d)=>(0,l.createElement)(`svg`,{ref:d,...c,width:t,height:t,stroke:e,strokeWidth:r?Number(n)*24/Number(t):n,className:s(`lucide`,i),...u},[...o.map(([e,t])=>(0,l.createElement)(e,t)),...Array.isArray(a)?a:[a]])),d=(e,t)=>{let n=(0,l.forwardRef)(({className:n,...r},i)=>(0,l.createElement)(u,{ref:i,iconNode:t,className:s(`lucide-${o(e)}`,n),...r}));return n.displayName=`${e}`,n},f=d(`ArchiveRestore`,[[`rect`,{width:`20`,height:`5`,x:`2`,y:`3`,rx:`1`,key:`1wp1u1`}],[`path`,{d:`M4 8v11a2 2 0 0 0 2 2h2`,key:`tvwodi`}],[`path`,{d:`M20 8v11a2 2 0 0 1-2 2h-2`,key:`1gkqxj`}],[`path`,{d:`m9 15 3-3 3 3`,key:`1pd0qc`}],[`path`,{d:`M12 12v9`,key:`192myk`}]]),p=d(`Archive`,[[`rect`,{width:`20`,height:`5`,x:`2`,y:`3`,rx:`1`,key:`1wp1u1`}],[`path`,{d:`M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8`,key:`1s80jp`}],[`path`,{d:`M10 12h4`,key:`a56b0p`}]]),m=d(`ArrowDown`,[[`path`,{d:`M12 5v14`,key:`s699le`}],[`path`,{d:`m19 12-7 7-7-7`,key:`1idqje`}]]),h=d(`ArrowLeft`,[[`path`,{d:`m12 19-7-7 7-7`,key:`1l729n`}],[`path`,{d:`M19 12H5`,key:`x3x0zl`}]]),g=d(`ArrowRight`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`m12 5 7 7-7 7`,key:`xquz4c`}]]),_=d(`ArrowUp`,[[`path`,{d:`m5 12 7-7 7 7`,key:`hav0vg`}],[`path`,{d:`M12 19V5`,key:`x0mq9r`}]]),v=d(`Bot`,[[`path`,{d:`M12 8V4H8`,key:`hb8ula`}],[`rect`,{width:`16`,height:`12`,x:`4`,y:`8`,rx:`2`,key:`enze0r`}],[`path`,{d:`M2 14h2`,key:`vft8re`}],[`path`,{d:`M20 14h2`,key:`4cs60a`}],[`path`,{d:`M15 13v2`,key:`1xurst`}],[`path`,{d:`M9 13v2`,key:`rq6x2g`}]]),y=d(`Check`,[[`path`,{d:`M20 6 9 17l-5-5`,key:`1gmf2c`}]]),b=d(`ChevronDown`,[[`path`,{d:`m6 9 6 6 6-6`,key:`qrunsl`}]]),x=d(`ChevronRight`,[[`path`,{d:`m9 18 6-6-6-6`,key:`mthhwq`}]]),S=d(`CircleAlert`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`line`,{x1:`12`,x2:`12`,y1:`8`,y2:`12`,key:`1pkeuh`}],[`line`,{x1:`12`,x2:`12.01`,y1:`16`,y2:`16`,key:`4dfq90`}]]),C=d(`CircleCheck`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m9 12 2 2 4-4`,key:`dzmm74`}]]),w=d(`CircleHelp`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3`,key:`1u773s`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),T=d(`Circle`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]),E=d(`Command`,[[`path`,{d:`M15 6v12a3 3 0 1 0 3-3H6a3 3 0 1 0 3 3V6a3 3 0 1 0-3 3h12a3 3 0 1 0-3-3`,key:`11bfej`}]]),D=d(`Copy`,[[`rect`,{width:`14`,height:`14`,x:`8`,y:`8`,rx:`2`,ry:`2`,key:`17jyea`}],[`path`,{d:`M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2`,key:`zix9uf`}]]),O=d(`Cpu`,[[`rect`,{width:`16`,height:`16`,x:`4`,y:`4`,rx:`2`,key:`14l7u7`}],[`rect`,{width:`6`,height:`6`,x:`9`,y:`9`,rx:`1`,key:`5aljv4`}],[`path`,{d:`M15 2v2`,key:`13l42r`}],[`path`,{d:`M15 20v2`,key:`15mkzm`}],[`path`,{d:`M2 15h2`,key:`1gxd5l`}],[`path`,{d:`M2 9h2`,key:`1bbxkp`}],[`path`,{d:`M20 15h2`,key:`19e6y8`}],[`path`,{d:`M20 9h2`,key:`19tzq7`}],[`path`,{d:`M9 2v2`,key:`165o2o`}],[`path`,{d:`M9 20v2`,key:`i2bqo8`}]]),k=d(`FileText`,[[`path`,{d:`M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z`,key:`1rqfz7`}],[`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`,key:`tnqrlb`}],[`path`,{d:`M10 9H8`,key:`b1mrlr`}],[`path`,{d:`M16 13H8`,key:`t4e002`}],[`path`,{d:`M16 17H8`,key:`z1uh3a`}]]),A=d(`FolderTree`,[[`path`,{d:`M20 10a1 1 0 0 0 1-1V6a1 1 0 0 0-1-1h-2.5a1 1 0 0 1-.8-.4l-.9-1.2A1 1 0 0 0 15 3h-2a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1Z`,key:`hod4my`}],[`path`,{d:`M20 21a1 1 0 0 0 1-1v-3a1 1 0 0 0-1-1h-2.9a1 1 0 0 1-.88-.55l-.42-.85a1 1 0 0 0-.92-.6H13a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1Z`,key:`w4yl2u`}],[`path`,{d:`M3 5a2 2 0 0 0 2 2h3`,key:`f2jnh7`}],[`path`,{d:`M3 3v13a2 2 0 0 0 2 2h3`,key:`k8epm1`}]]),j=d(`Folder`,[[`path`,{d:`M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z`,key:`1kt360`}]]);d(`Gauge`,[[`path`,{d:`m12 14 4-4`,key:`9kzdfg`}],[`path`,{d:`M3.34 19a10 10 0 1 1 17.32 0`,key:`19p75a`}]]);var M=d(`GitBranch`,[[`line`,{x1:`6`,x2:`6`,y1:`3`,y2:`15`,key:`17qcm7`}],[`circle`,{cx:`18`,cy:`6`,r:`3`,key:`1h7g24`}],[`circle`,{cx:`6`,cy:`18`,r:`3`,key:`fqmcym`}],[`path`,{d:`M18 9a9 9 0 0 1-9 9`,key:`n2h4wq`}]]),N=d(`ImagePlus`,[[`path`,{d:`M16 5h6`,key:`1vod17`}],[`path`,{d:`M19 2v6`,key:`4bpg5p`}],[`path`,{d:`M21 11.5V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h7.5`,key:`1ue2ih`}],[`path`,{d:`m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21`,key:`1xmnt7`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}]]),P=d(`ImageUp`,[[`path`,{d:`M10.3 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2v10l-3.1-3.1a2 2 0 0 0-2.814.014L6 21`,key:`9csbqa`}],[`path`,{d:`m14 19.5 3-3 3 3`,key:`9vmjn0`}],[`path`,{d:`M17 22v-5.5`,key:`1aa6fl`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}]]),F=d(`LayoutList`,[[`rect`,{width:`7`,height:`7`,x:`3`,y:`3`,rx:`1`,key:`1g98yp`}],[`rect`,{width:`7`,height:`7`,x:`3`,y:`14`,rx:`1`,key:`1bb6yr`}],[`path`,{d:`M14 4h7`,key:`3xa0d5`}],[`path`,{d:`M14 9h7`,key:`1icrd9`}],[`path`,{d:`M14 15h7`,key:`1mj8o2`}],[`path`,{d:`M14 20h7`,key:`11slyb`}]]),I=d(`LoaderCircle`,[[`path`,{d:`M21 12a9 9 0 1 1-6.219-8.56`,key:`13zald`}]]),L=d(`MessageCircleQuestion`,[[`path`,{d:`M7.9 20A9 9 0 1 0 4 16.1L2 22Z`,key:`vv11sd`}],[`path`,{d:`M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3`,key:`1u773s`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),R=d(`Mic`,[[`path`,{d:`M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3Z`,key:`131961`}],[`path`,{d:`M19 10v2a7 7 0 0 1-14 0v-2`,key:`1vc78b`}],[`line`,{x1:`12`,x2:`12`,y1:`19`,y2:`22`,key:`x3vr5v`}]]),z=d(`Monitor`,[[`rect`,{width:`20`,height:`14`,x:`2`,y:`3`,rx:`2`,key:`48i651`}],[`line`,{x1:`8`,x2:`16`,y1:`21`,y2:`21`,key:`1svkeh`}],[`line`,{x1:`12`,x2:`12`,y1:`17`,y2:`21`,key:`vw1qmm`}]]),ee=d(`Moon`,[[`path`,{d:`M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z`,key:`a7tn18`}]]),B=d(`PanelLeftClose`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 3v18`,key:`fh3hqa`}],[`path`,{d:`m16 15-3-3 3-3`,key:`14y99z`}]]),te=d(`PanelLeftOpen`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 3v18`,key:`fh3hqa`}],[`path`,{d:`m14 9 3 3-3 3`,key:`8010ee`}]]),ne=d(`PanelLeft`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 3v18`,key:`fh3hqa`}]]),re=d(`Pencil`,[[`path`,{d:`M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z`,key:`1a8usu`}],[`path`,{d:`m15 5 4 4`,key:`1mk7zo`}]]),V=d(`Plus`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`M12 5v14`,key:`s699le`}]]),H=d(`Search`,[[`circle`,{cx:`11`,cy:`11`,r:`8`,key:`4ej97u`}],[`path`,{d:`m21 21-4.3-4.3`,key:`1qie3q`}]]),ie=d(`Server`,[[`rect`,{width:`20`,height:`8`,x:`2`,y:`2`,rx:`2`,ry:`2`,key:`ngkwjq`}],[`rect`,{width:`20`,height:`8`,x:`2`,y:`14`,rx:`2`,ry:`2`,key:`iecqi9`}],[`line`,{x1:`6`,x2:`6.01`,y1:`6`,y2:`6`,key:`16zg32`}],[`line`,{x1:`6`,x2:`6.01`,y1:`18`,y2:`18`,key:`nzw8ys`}]]),ae=d(`Settings2`,[[`path`,{d:`M20 7h-9`,key:`3s1dr2`}],[`path`,{d:`M14 17H5`,key:`gfn3mx`}],[`circle`,{cx:`17`,cy:`17`,r:`3`,key:`18b49y`}],[`circle`,{cx:`7`,cy:`7`,r:`3`,key:`dfmy0x`}]]),oe=d(`SquarePen`,[[`path`,{d:`M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7`,key:`1m0v6g`}],[`path`,{d:`M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z`,key:`ohrbg2`}]]),se=d(`SquareTerminal`,[[`path`,{d:`m7 11 2-2-2-2`,key:`1lz0vl`}],[`path`,{d:`M11 13h4`,key:`1p7l4v`}],[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,ry:`2`,key:`1m3agn`}]]),ce=d(`Square`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]),le=d(`Sun`,[[`circle`,{cx:`12`,cy:`12`,r:`4`,key:`4exip2`}],[`path`,{d:`M12 2v2`,key:`tus03m`}],[`path`,{d:`M12 20v2`,key:`1lh1kg`}],[`path`,{d:`m4.93 4.93 1.41 1.41`,key:`149t6j`}],[`path`,{d:`m17.66 17.66 1.41 1.41`,key:`ptbguv`}],[`path`,{d:`M2 12h2`,key:`1t8f8n`}],[`path`,{d:`M20 12h2`,key:`1q8mjw`}],[`path`,{d:`m6.34 17.66-1.41 1.41`,key:`1m8zz5`}],[`path`,{d:`m19.07 4.93-1.41 1.41`,key:`1shlcs`}]]),ue=d(`Trash2`,[[`path`,{d:`M3 6h18`,key:`d0wm0j`}],[`path`,{d:`M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6`,key:`4alrt4`}],[`path`,{d:`M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2`,key:`v07s0e`}],[`line`,{x1:`10`,x2:`10`,y1:`11`,y2:`17`,key:`1uufr5`}],[`line`,{x1:`14`,x2:`14`,y1:`11`,y2:`17`,key:`xtxkd`}]]),de=d(`TriangleAlert`,[[`path`,{d:`m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3`,key:`wmoenq`}],[`path`,{d:`M12 9v4`,key:`juzpu7`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),fe=d(`X`,[[`path`,{d:`M18 6 6 18`,key:`1bl5f8`}],[`path`,{d:`m6 6 12 12`,key:`d8bk6v`}]]),U=typeof document<`u`?l.useLayoutEffect:()=>{};function pe(){return typeof window<`u`}function W(e){return ge(e)?(e.nodeName||``).toLowerCase():`#document`}function me(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function he(e){return((ge(e)?e.ownerDocument:e.document)||window.document)?.documentElement}function ge(e){return pe()?e instanceof Node||e instanceof me(e).Node:!1}function G(e){return pe()?e instanceof Element||e instanceof me(e).Element:!1}function K(e){return pe()?e instanceof HTMLElement||e instanceof me(e).HTMLElement:!1}function _e(e){return!pe()||typeof ShadowRoot>`u`?!1:e instanceof ShadowRoot||e instanceof me(e).ShadowRoot}function ve(e){let{overflow:t,overflowX:n,overflowY:r,display:i}=ke(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&i!==`inline`&&i!==`contents`}function ye(e){return/^(table|td|th)$/.test(W(e))}function be(e){try{if(e.matches(`:popover-open`))return!0}catch{}try{return e.matches(`:modal`)}catch{return!1}}var xe=/transform|translate|scale|rotate|perspective|filter/,Se=/paint|layout|strict|content/,Ce=e=>!!e&&e!==`none`,we;function Te(e){let t=G(e)?ke(e):e;return Ce(t.transform)||Ce(t.translate)||Ce(t.scale)||Ce(t.rotate)||Ce(t.perspective)||!De()&&(Ce(t.backdropFilter)||Ce(t.filter))||xe.test(t.willChange||``)||Se.test(t.contain||``)}function Ee(e){let t=je(e);for(;K(t)&&!Oe(t);){if(Te(t))return t;if(be(t))return null;t=je(t)}return null}function De(){return we??=typeof CSS<`u`&&CSS.supports&&CSS.supports(`-webkit-backdrop-filter`,`none`),we}function Oe(e){return/^(html|body|#document)$/.test(W(e))}function ke(e){return me(e).getComputedStyle(e)}function Ae(e){return G(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function je(e){if(W(e)===`html`)return e;let t=e.assignedSlot||e.parentNode||_e(e)&&e.host||he(e);return _e(t)?t.host:t}function Me(e){let t=je(e);return Oe(t)?(e.ownerDocument||e).body:K(t)&&ve(t)?t:Me(t)}function Ne(e,t,n){t===void 0&&(t=[]),n===void 0&&(n=!0);let r=Me(e),i=r===e.ownerDocument?.body,a=me(r);if(i){let e=Pe(a);return t.concat(a,a.visualViewport||[],ve(r)?r:[],e&&n?Ne(e):[])}return t.concat(r,Ne(r,[],n))}function Pe(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function q(e,t,n,r){return e.addEventListener(t,n,r),()=>{e.removeEventListener(t,n,r)}}function Fe(){return typeof navigator>`u`?{userAgent:``,platform:``,maxTouchPoints:0}:{userAgent:navigator.userAgent,platform:navigator.platform??``,maxTouchPoints:navigator.maxTouchPoints??0}}var{userAgent:Ie,platform:Le,maxTouchPoints:Re}=Fe(),ze=Ie.toLowerCase(),Be=Le.toLowerCase(),Ve=/^i(os$|p)/.test(Be)||Be===`macintel`&&Re>1,He=`android`,Ue=Be===He||ze.includes(He),We=!Ve&&Be.startsWith(`mac`);Be.startsWith(`win`),!Ue&&/^(linux|chrome os)/.test(Be);var Ge=We||Ve,Ke=typeof CSS<`u`&&!!CSS.supports?.(`-webkit-backdrop-filter:none`),qe=!Ke&&ze.includes(`firefox`);!Ke&&ze.includes(`chrom`);var Je=Ge,Ye=/jsdom|happydom/.test(ze);function J(e){return e?.ownerDocument||document}var Xe={};function Ze(e,t){let n=l.useRef(Xe);return n.current===Xe&&(n.current=e(t)),n}function Qe(){}var $e=Object.freeze([]),et=Object.freeze({});function tt(e){l.useEffect(e,$e)}var nt=0,rt=class e{static create(){return new e}currentId=nt;start(e,t){this.clear(),this.currentId=setTimeout(()=>{this.currentId=nt,t()},e)}isStarted(){return this.currentId!==nt}clear=()=>{this.currentId!==nt&&(clearTimeout(this.currentId),this.currentId=nt)};disposeEffect=()=>this.clear};function it(){let e=Ze(rt.create).current;return tt(e.disposeEffect),e}var at=null;globalThis.requestAnimationFrame;var ot=new class{callbacks=[];callbacksCount=0;nextId=1;startId=1;isScheduled=!1;tick=e=>{this.isScheduled=!1;let t=this.callbacks,n=this.callbacksCount;if(this.callbacks=[],this.callbacksCount=0,this.startId=this.nextId,n>0)for(let n=0;n<t.length;n+=1)t[n]?.(e)};request(e){let t=this.nextId;return this.nextId+=1,this.callbacks.push(e),this.callbacksCount+=1,this.isScheduled||=(requestAnimationFrame(this.tick),!0),t}cancel(e){let t=e-this.startId;t<0||t>=this.callbacks.length||this.callbacks[t]!==null&&(this.callbacks[t]=null,--this.callbacksCount)}},st=class e{static create(){return new e}static request(e){return ot.request(e)}static cancel(e){return ot.cancel(e)}currentId=at;request(e){this.cancel(),this.currentId=ot.request(()=>{this.currentId=at,e()})}cancel=()=>{this.currentId!==at&&(ot.cancel(this.currentId),this.currentId=at)};disposeEffect=()=>this.cancel};function ct(){let e=Ze(st.create).current;return tt(e.disposeEffect),e}var lt={},ut={},dt=``;function Y(e,t){return ve(e)?e:t}function ft(e,t,n){return/hidden|clip/.test(e.getComputedStyle(Y(t,n)).overflowY)}function pt(e){if(typeof document>`u`)return!1;let t=J(e);return me(t).innerWidth-t.documentElement.clientWidth>0}function mt(e){if(!(typeof CSS<`u`&&CSS.supports&&CSS.supports(`scrollbar-gutter`,`stable`))||typeof document>`u`)return!1;let t=J(e),n=t.documentElement,r=t.body,i=Y(n,r),a=i.style.overflowY,o=n.style.scrollbarGutter;n.style.scrollbarGutter=`stable`,i.style.overflowY=`scroll`;let s=i.offsetWidth;i.style.overflowY=`hidden`;let c=i.offsetWidth;return i.style.overflowY=a,n.style.scrollbarGutter=o,s===c}function ht(e){let t=J(e),n=t.documentElement,r=t.body,i=Y(n,r),a={overflowY:i.style.overflowY,overflowX:i.style.overflowX};return Object.assign(i.style,{overflowY:`hidden`,overflowX:`hidden`}),()=>{Object.assign(i.style,a)}}function gt(e){let t=J(e),n=t.documentElement,r=t.body,i=me(n),a=0,o=0,s=!1,c=st.create();if(Ke&&(i.visualViewport?.scale??1)!==1)return()=>{};function l(){let t=i.getComputedStyle(n),c=i.getComputedStyle(r),l=(t.scrollbarGutter||``).includes(`both-edges`)?`stable both-edges`:`stable`;a=n.scrollTop,o=n.scrollLeft,lt={scrollbarGutter:n.style.scrollbarGutter,overflowY:n.style.overflowY,overflowX:n.style.overflowX},dt=n.style.scrollBehavior,ut={position:r.style.position,height:r.style.height,width:r.style.width,boxSizing:r.style.boxSizing,overflowY:r.style.overflowY,overflowX:r.style.overflowX,scrollBehavior:r.style.scrollBehavior};let u=n.scrollHeight>n.clientHeight,d=n.scrollWidth>n.clientWidth,f=t.overflowY===`scroll`||c.overflowY===`scroll`,p=t.overflowX===`scroll`||c.overflowX===`scroll`,m=Math.max(0,i.innerWidth-r.clientWidth),h=Math.max(0,i.innerHeight-r.clientHeight),g=parseFloat(c.marginTop)+parseFloat(c.marginBottom),_=parseFloat(c.marginLeft)+parseFloat(c.marginRight),v=Y(n,r);if(s=mt(e),s){n.style.scrollbarGutter=l,v.style.overflowY=`hidden`,v.style.overflowX=`hidden`;return}Object.assign(n.style,{scrollbarGutter:l,overflowY:`hidden`,overflowX:`hidden`}),(u||f)&&(n.style.overflowY=`scroll`),(d||p)&&(n.style.overflowX=`scroll`),Object.assign(r.style,{position:`relative`,height:g||h?`calc(100dvh - ${g+h}px)`:`100dvh`,width:_||m?`calc(100vw - ${_+m}px)`:`100vw`,boxSizing:`border-box`,overflowY:`hidden`,overflowX:`hidden`,scrollBehavior:`unset`}),r.scrollTop=a,r.scrollLeft=o,n.setAttribute(`data-base-ui-scroll-locked`,``),n.style.scrollBehavior=`unset`}function u(){Object.assign(n.style,lt),Object.assign(r.style,ut),s||(n.scrollTop=a,n.scrollLeft=o,n.removeAttribute(`data-base-ui-scroll-locked`),n.style.scrollBehavior=dt)}function d(){u(),c.request(l)}l();let f=q(i,`resize`,d);return()=>{c.cancel(),u(),typeof i.removeEventListener==`function`&&f()}}var _t=new class{lockCount=0;restore=null;timeoutLock=rt.create();timeoutUnlock=rt.create();acquire(e){return this.lockCount+=1,this.lockCount===1&&this.restore===null&&this.timeoutLock.start(0,()=>this.lock(e)),this.release}release=()=>{--this.lockCount,this.lockCount===0&&this.restore&&this.timeoutUnlock.start(0,this.unlock)};unlock=()=>{this.lockCount===0&&this.restore&&(this.restore?.(),this.restore=null)};lock(e){if(this.lockCount===0||this.restore!==null)return;let t=J(e),n=t.documentElement,r=t.body,i=me(n);if(ft(i,n,r)){let t=new i.MutationObserver(()=>{ft(i,n,r)||(t.disconnect(),this.restore=null,this.lock(e))}),a={attributes:!0};t.observe(n,a),t.observe(r,a),this.restore=()=>t.disconnect();return}let a=Ve||!pt(e);this.restore=a?ht(e):gt(e)}};function vt(e=!0,t=null){U(()=>{if(e)return _t.acquire(t)},[e,t])}function yt(e){e.preventDefault(),e.stopPropagation()}function bt(e){return`nativeEvent`in e}function xt(e){return e.pointerType===``&&e.isTrusted?!0:Ue&&e.pointerType?e.type===`click`&&e.buttons===1:e.detail===0&&!e.pointerType}function St(e){return Ye?!1:!Ue&&e.width===0&&e.height===0||Ue&&e.width===1&&e.height===1&&e.pressure===0&&e.detail===0&&e.pointerType===`mouse`||e.width<1&&e.height<1&&e.pressure===0&&e.detail===0&&e.pointerType===`touch`}function Ct(e,t){let n=[`mouse`,`pen`];return t||n.push(``,void 0),n.includes(e)}function wt(e){let t=e.type;return t===`click`||t===`mousedown`||t===`keydown`||t===`keyup`}function Tt(e){let t=e.activeElement;for(;t?.shadowRoot?.activeElement!=null;)t=t.shadowRoot.activeElement;return t}function X(e,t){if(!e||!t)return!1;let n=t.getRootNode?.();if(e.contains(t))return!0;if(n&&_e(n)){let n=t;for(;n;){if(e===n)return!0;n=n.parentNode||n.host}}return!1}function Et(e){return`composedPath`in e?e.composedPath()[0]??e.target:e.target}var Dt=`data-base-ui-focusable`,Ot=`input:not([type='hidden']):not([disabled]),[contenteditable]:not([contenteditable='false']),textarea:not([disabled])`,kt=`ArrowLeft`,At=`ArrowRight`,jt=`ArrowUp`,Mt=`ArrowDown`,Nt=`data-starting-style`,Pt=`data-ending-style`,Ft={[Nt]:``},It={[Pt]:``},Lt={transitionStatus(e){return e===`starting`?Ft:e===`ending`?It:null}},Rt=`data-open`,zt=`data-closed`,Bt=`data-anchor-hidden`,Vt=`data-popup-open`,Ht=`data-pressed`,Ut={[Vt]:``},Wt={[Vt]:``,[Ht]:``},Gt={[Rt]:``},Kt={[zt]:``},qt={[Bt]:``},Jt={open(e){return e?Ut:null}},Yt={open(e){return e?Wt:null}},Xt={open(e){return e?Gt:Kt},anchorHidden(e){return e?qt:null}},Zt={...Xt,...Lt},Qt=`data-trigger-disabled`;function $t(e,t){if(!G(e))return!1;let n=e;if(t.hasElement(n))return!n.hasAttribute(Qt);for(let[,e]of t.entries())if(X(e,n))return!e.hasAttribute(Qt);return!1}function en(e,t){if(t==null)return!1;if(`composedPath`in e)return e.composedPath().includes(t);let n=e;return n.target!=null&&t.contains(n.target)}function tn(e){return e.matches(`html,body`)}function nn(e){return K(e)&&e.matches(`input:not([type='hidden']):not([disabled]),[contenteditable]:not([contenteditable='false']),textarea:not([disabled])`)}function rn(e){return e?.closest(`button,a[href],[role="button"],select,[tabindex]:not([tabindex="-1"]),${Ot}`)!=null}function an(e){return e?e.getAttribute(`role`)===`combobox`&&nn(e):!1}function on(e){if(!e||Ye)return!0;try{return e.matches(`:focus-visible`)}catch{return!0}}function sn(e){return e?e.hasAttribute(`data-base-ui-focusable`)?e:e.querySelector(`[data-base-ui-focusable]`)||e:null}function cn(e,t){return t!=null&&!Ct(t)?0:typeof e==`function`?e():e}function ln(e,t,n){let r=cn(e,n);return typeof r==`number`?r:r?.[t]}function un(e){return typeof e==`function`?e():e}function dn(e,t){return t||e===`click`||e===`mousedown`}function fn(e){return e?.includes(`mouse`)&&e!==`mousedown`}var pn=`none`,mn=`trigger-press`,hn=`trigger-hover`,gn=`trigger-focus`,_n=`outside-press`,vn=`item-press`,yn=`close-press`,bn=`input-change`,xn=`input-clear`,Sn=`input-press`,Cn=`focus-out`,wn=`escape-key`,Tn=`list-navigation`,En=`keyboard`,Dn=`pointer`,On=`cancel-open`,kn=`sibling-open`,An=`disabled`,jn=`imperative-action`;function Z(e,t,n,r){let i=!1,a=!1,o=r??et;return{reason:e,event:t??new Event(`base-ui`),cancel(){i=!0},allowPropagation(){a=!0},get isCanceled(){return i},get isPropagationAllowed(){return a},trigger:n,...o}}function Mn(e,t,n){let r=n??et;return{reason:e,event:t??new Event(`base-ui`),...r}}var Nn=t((e=>{var t=Symbol.for(`react.transitional.element`),n=Symbol.for(`react.fragment`);function r(e,n,r){var i=null;if(r!==void 0&&(i=``+r),n.key!==void 0&&(i=``+n.key),`key`in n)for(var a in r={},n)a!==`key`&&(r[a]=n[a]);else r=n;return n=r.ref,{$$typeof:t,type:e,key:i,ref:n===void 0?null:n,props:r}}e.Fragment=n,e.jsx=r,e.jsxs=r})),Q=t(((e,t)=>{t.exports=Nn()}))(),Pn=l.createContext({hasProvider:!1,timeoutMs:0,delayRef:{current:0},initialDelayRef:{current:0},timeout:new rt,currentIdRef:{current:null},currentContextRef:{current:null}});function Fn(e,t){e.current=t.current}function In(e,t={open:!1}){let{open:n}=t,r=`rootStore`in e?e.rootStore:e,i=r.useState(`floatingId`),{currentIdRef:a,delayRef:o,timeoutMs:s,initialDelayRef:c,currentContextRef:u,hasProvider:d,timeout:f}=l.useContext(Pn),[p,m]=l.useState(!1),h=l.useRef(n);return U(()=>{h.current=n},[n]),U(()=>{function e(){u.current?.setIsInstantPhase(!1),a.current=null,u.current=null,o.current=c.current,f.clear()}if(a.current&&!n&&a.current===i){if(m(!1),s){let t=i;return f.start(s,()=>{r.select(`open`)||a.current&&a.current!==t||e()}),()=>{(h.current||a.current!==t)&&f.clear()}}e()}},[n,i,a,o,s,c,u,f,r]),U(()=>{if(!n)return;let e=u.current,t=a.current;f.clear(),u.current={onOpenChange:r.setOpen,setIsInstantPhase:m},a.current=i,o.current={open:0,close:ln(c.current,`close`)},t!==null&&t!==i?(m(!0),e?.setIsInstantPhase(!0),e?.onOpenChange(!1,Z(pn))):(m(!1),e?.setIsInstantPhase(!1))},[n,i,r,a,o,c,u,f]),U(()=>()=>{if(a.current===i){if(u.current=null,!h.current)return;a.current=null,Fn(o,c),f.clear()}},[u,a,o,i,c,f]),l.useMemo(()=>({activeIdRef:a,hasProvider:d,delayRef:o,isInstantPhase:p}),[a,d,o,p])}function Ln(...e){return()=>{for(let t=0;t<e.length;t+=1){let n=e[t];n&&n()}}}function Rn(e,t,n,r){let i=Ze(Bn).current;return Vn(i,e,t,n,r)&&Un(i,[e,t,n,r]),i.callback}function zn(e){let t=Ze(Bn).current;return Hn(t,e)&&Un(t,e),t.callback}function Bn(){return{callback:null,cleanup:null,refs:[]}}function Vn(e,t,n,r,i){return e.refs[0]!==t||e.refs[1]!==n||e.refs[2]!==r||e.refs[3]!==i}function Hn(e,t){return e.refs.length!==t.length||e.refs.some((e,n)=>e!==t[n])}function Un(e,t){if(e.refs=t,t.every(e=>e==null)){e.callback=null;return}e.callback=n=>{if(e.cleanup&&=(e.cleanup(),null),n!=null){let r=Array(t.length).fill(null);for(let e=0;e<t.length;e+=1){let i=t[e];if(i!=null)switch(typeof i){case`function`:{let t=i(n);typeof t==`function`&&(r[e]=t);break}case`object`:i.current=n}}e.cleanup=()=>{for(let e=0;e<t.length;e+=1){let n=t[e];if(n!=null)switch(typeof n){case`function`:{let t=r[e];typeof t==`function`?t():n(null);break}case`object`:n.current=null}}}}}}function Wn(e){let t=Ze(Gn,e).current;return t.next=e,U(t.effect),t}function Gn(e){let t={current:e,next:e,effect:()=>{t.current=t.next}};return t}var Kn={...l},qn=Kn.useInsertionEffect,Jn=qn&&qn!==Kn.useLayoutEffect?qn:e=>e();function $(e){let t=Ze(Yn).current;return t.next=e,Jn(t.effect),t.trampoline}function Yn(){let e={next:void 0,callback:Xn,trampoline:(...t)=>e.callback?.(...t),effect:()=>{e.callback=e.next}};return e}function Xn(){}var Zn={clipPath:`inset(50%)`,overflow:`hidden`,whiteSpace:`nowrap`,border:0,padding:0,width:1,height:1,margin:-1},Qn={...Zn,position:`fixed`,top:0,left:0},$n={...Zn,position:`absolute`},er=l.forwardRef(function(e,t){let[n,r]=l.useState();U(()=>{Je&&Ke&&r(`button`)},[]);let i={tabIndex:0,role:n};return(0,Q.jsx)(`span`,{...e,ref:t,style:Qn,"aria-hidden":!n||void 0,...i,"data-base-ui-focus-guard":``})}),tr=Math.min,nr=Math.max,rr=Math.round,ir=Math.floor,ar=e=>({x:e,y:e}),or={left:`right`,right:`left`,bottom:`top`,top:`bottom`};function sr(e,t,n){return nr(e,tr(t,n))}function cr(e,t){return typeof e==`function`?e(t):e}function lr(e){return e.split(`-`)[0]}function ur(e){return e.split(`-`)[1]}function dr(e){return e===`x`?`y`:`x`}function fr(e){return e===`y`?`height`:`width`}function pr(e){let t=e[0];return t===`t`||t===`b`?`y`:`x`}function mr(e){return dr(pr(e))}function hr(e,t,n){n===void 0&&(n=!1);let r=ur(e),i=mr(e),a=fr(i),o=i===`x`?r===(n?`end`:`start`)?`right`:`left`:r===`start`?`bottom`:`top`;return t.reference[a]>t.floating[a]&&(o=wr(o)),[o,wr(o)]}function gr(e){let t=wr(e);return[_r(e),t,_r(t)]}function _r(e){return e.includes(`start`)?e.replace(`start`,`end`):e.replace(`end`,`start`)}var vr=[`left`,`right`],yr=[`right`,`left`],br=[`top`,`bottom`],xr=[`bottom`,`top`];function Sr(e,t,n){switch(e){case`top`:case`bottom`:return n?t?yr:vr:t?vr:yr;case`left`:case`right`:return t?br:xr;default:return[]}}function Cr(e,t,n,r){let i=ur(e),a=Sr(lr(e),n===`start`,r);return i&&(a=a.map(e=>e+`-`+i),t&&(a=a.concat(a.map(_r)))),a}function wr(e){let t=lr(e);return or[t]+e.slice(t.length)}function Tr(e){return{top:e.top??0,right:e.right??0,bottom:e.bottom??0,left:e.left??0}}function Er(e){return typeof e==`number`?{top:e,right:e,bottom:e,left:e}:Tr(e)}function Dr(e){let{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 Or(e,t,n){return Math.floor(e/t)!==n}function kr(e,t){return t<0||t>=e.length}function Ar(e,t){return Mr(e.current,{disabledIndices:t})}function jr(e,t){return Mr(e.current,{decrement:!0,startingIndex:e.current.length,disabledIndices:t})}function Mr(e,{startingIndex:t=-1,decrement:n=!1,disabledIndices:r,amount:i=1}={}){let a=t;do a+=n?-i:i;while(a>=0&&a<=e.length-1&&Pr(e,a,r));return a}function Nr(e,{event:t,orientation:n,loopFocus:r,onLoop:i,rtl:a,cols:o,disabledIndices:s,minIndex:c,maxIndex:l,prevIndex:u,stopEvent:d=!1}){let f=u,p;if(t.key===`ArrowUp`?p=`up`:t.key===`ArrowDown`&&(p=`down`),p){let n=[],a=[],m=!1,h=0;{let t=null,r=-1;e.forEach((e,i)=>{if(e==null)return;h+=1;let o=e.closest(`[role="row"]`);o&&(m=!0),(o!==t||r===-1)&&(t=o,r+=1,n[r]=[]),n[r].push(i),a[i]=r})}let g=!1,_=0;if(m)for(let e of n){let t=e.length;t>_&&(_=t),t!==o&&(g=!0)}let v=g&&h<e.length,y=_||o,b=o=>{if(!g||u===-1)return;let c=a[u];if(c==null)return;let l=n[c].indexOf(u),d=o===`up`?-1:1;for(let o=c+d,f=0;f<n.length;f+=1,o+=d){if(o<0||o>=n.length){if(!r||v)return;if(o=o<0?n.length-1:0,i){let e=Math.min(l,n[o].length-1),r=i(t,u,n[o][e]??n[o][0]);o=a[r]??o}}let c=n[o];for(let t=Math.min(l,c.length-1);t>=0;--t){let n=c[t];if(!Pr(e,n,s))return n}}},x=t=>{if(!v||u===-1)return;let n=u%y,i=t===`up`?-y:y,a=l-l%y,o=ir(l/y)+1;for(let t=u-n+i,c=0;c<o;c+=1,t+=i){if(t<0||t>l){if(!r)return;t=t<0?a:0}let i=Math.min(t+y-1,l);for(let r=Math.min(t+n,i);r>=t;--r)if(!Pr(e,r,s))return r}};d&&yt(t);let S=b(p)??x(p);if(S!==void 0)f=S;else if(u===-1)f=p===`up`?l:c;else if(f=Mr(e,{startingIndex:u,amount:y,decrement:p===`up`,disabledIndices:s}),r){if(p===`up`&&(u-y<c||f<0)){let e=u%y,n=l%y,r=l-(n-e);f=n===e?l:n>e?r:r-y,i&&(f=i(t,u,f))}p===`down`&&u+y>l&&(f=Mr(e,{startingIndex:u%y-y,amount:y,disabledIndices:s}),i&&(f=i(t,u,f)))}kr(e,f)&&(f=u)}if(n===`both`){let n=ir(u/o);t.key===(a?`ArrowLeft`:`ArrowRight`)&&(d&&yt(t),u%o===o-1?r&&(f=Mr(e,{startingIndex:u-u%o-1,disabledIndices:s}),i&&(f=i(t,u,f))):(f=Mr(e,{startingIndex:u,disabledIndices:s}),r&&Or(f,o,n)&&(f=Mr(e,{startingIndex:u-u%o-1,disabledIndices:s}),i&&(f=i(t,u,f)))),Or(f,o,n)&&(f=u)),t.key===(a?`ArrowRight`:`ArrowLeft`)&&(d&&yt(t),u%o===0?r&&(f=Mr(e,{startingIndex:u+(o-u%o),decrement:!0,disabledIndices:s}),i&&(f=i(t,u,f))):(f=Mr(e,{startingIndex:u,decrement:!0,disabledIndices:s}),r&&Or(f,o,n)&&(f=Mr(e,{startingIndex:u+(o-u%o),decrement:!0,disabledIndices:s}),i&&(f=i(t,u,f)))),Or(f,o,n)&&(f=u));let c=ir(l/o)===n;kr(e,f)&&(r&&c?(f=t.key===(a?`ArrowRight`:`ArrowLeft`)?l:Mr(e,{startingIndex:u-u%o-1,disabledIndices:s}),i&&(f=i(t,u,f))):f=u)}return f}function Pr(e,t,n){if(typeof n==`function`?n(t):n?.includes(t)??!1)return!0;let r=e[t];return r?!Ir(r)||r.matches(`:disabled`)?!0:!n&&(r.hasAttribute(`disabled`)||r.getAttribute(`aria-disabled`)===`true`):!1}function Fr(e){return e.visibility===`hidden`||e.visibility===`collapse`}function Ir(e,t=e?ke(e):null){return!e||!e.isConnected||!t||Fr(t)?!1:typeof e.checkVisibility==`function`?e.checkVisibility():t.display!==`none`&&t.display!==`contents`}var Lr=`a[href],button,input,select,textarea,summary,details,iframe,object,embed,[tabindex],[contenteditable]:not([contenteditable="false"]),audio[controls],video[controls]`;function Rr(e){let t=e.assignedSlot;if(t)return t;if(e.parentElement)return e.parentElement;let n=e.getRootNode();return _e(n)?n.host:null}function zr(e){for(let t of Array.from(e.children))if(W(t)===`summary`)return t;return null}function Br(e,t){let n=zr(t);return!!n&&(e===n||X(n,e))}function Vr(e){let t=e?W(e):``;return e!=null&&e.matches(Lr)&&(t!==`summary`||e.parentElement!=null&&W(e.parentElement)===`details`&&zr(e.parentElement)===e)&&(t!==`details`||zr(e)==null)&&(t!==`input`||e.type!==`hidden`)}function Hr(e){if(!Vr(e)||!e.isConnected||e.matches(`:disabled`))return!1;for(let t=e;t;t=Rr(t)){let n=t!==e,r=W(t)===`slot`;if(t.hasAttribute(`inert`)||n&&W(t)===`details`&&!t.open&&!Br(e,t)||t.hasAttribute(`hidden`)||!r&&!Ur(t,n))return!1}return!0}function Ur(e,t){let n=ke(e);return t?n.display!==`none`:Ir(e,n)}function Wr(e){let t=e.tabIndex;if(t<0){let t=W(e);if(t===`details`||t===`audio`||t===`video`||K(e)&&e.isContentEditable)return 0}return t}function Gr(e){if(W(e)!==`input`)return null;let t=e;return t.type===`radio`&&t.name!==``?t:null}function Kr(e,t){let n=Gr(e);if(!n)return!0;let r=t.find(e=>{let t=Gr(e);return t?.name===n.name&&t.form===n.form&&t.checked});return r?r===n:t.find(e=>{let t=Gr(e);return t?.name===n.name&&t.form===n.form})===n}function qr(e){if(K(e)&&W(e)===`slot`){let t=e.assignedElements({flatten:!0});if(t.length>0)return t}return K(e)&&e.shadowRoot?Array.from(e.shadowRoot.children):Array.from(e.children)}function Jr(e,t){qr(e).forEach(e=>{Vr(e)&&t.push(e),Jr(e,t)})}function Yr(e,t,n){qr(e).forEach(e=>{K(e)&&e.matches(t)&&n.push(e),Yr(e,t,n)})}function Xr(e){return Hr(e)&&Wr(e)>=0}function Zr(e){let t=[];return Jr(e,t),t.filter(Hr)}function Qr(e){let t=Zr(e);return t.filter(e=>Wr(e)>=0&&Kr(e,t))}function $r(e,t){let n=Qr(e),r=n.length;if(r===0)return;let i=Tt(J(e)),a=n.indexOf(i);return n[a===-1?t===1?0:r-1:a+t]}function ei(e){return $r(J(e).body,1)||e}function ti(e){return $r(J(e).body,-1)||e}function ni(e,t){if(!e)return null;let n=Qr(J(e).body),r=n.length;if(r===0)return null;let i=n.indexOf(e);return i===-1?null:n[(i+t+r)%r]}function ri(e){return ni(e,1)}function ii(e){return ni(e,-1)}function ai(e,t){let n=t||e.currentTarget,r=e.relatedTarget;return!r||!X(n,r)}function oi(e){Qr(e).forEach(e=>{e.dataset.tabindex=e.getAttribute(`tabindex`)||``,e.setAttribute(`tabindex`,`-1`)})}function si(e){let t=[];Yr(e,`[data-tabindex]`,t),t.forEach(e=>{let t=e.dataset.tabindex;delete e.dataset.tabindex,t?e.setAttribute(`tabindex`,t):e.removeAttribute(`tabindex`)})}function ci(e,t,n=!0){return e.filter(e=>e.parentId===t).flatMap(t=>[...!n||t.context?.open?[t]:[],...ci(e,t.id,n)])}function li(e,t){let n=[],r=e.find(e=>e.id===t)?.parentId;for(;r;){let t=e.find(e=>e.id===r);r=t?.parentId,t&&(n=n.concat(t))}return n}function ui(e){return`data-base-ui-${e}`}var di=0;function fi(e,t={}){let{preventScroll:n=!1,sync:r=!1,shouldFocus:i}=t;cancelAnimationFrame(di);function a(){(!i||i())&&e?.focus({preventScroll:n})}if(r)return a(),Qe;let o=requestAnimationFrame(a);return di=o,()=>{di===o&&(cancelAnimationFrame(o),di=0)}}var pi={inert:new WeakMap,"aria-hidden":new WeakMap},mi=`data-base-ui-inert`,hi={inert:new WeakSet,"aria-hidden":new WeakSet},gi=new WeakMap,_i=0;function vi(e){return hi[e]}function yi(e){return e?_e(e)?e.host:yi(e.parentNode):null}var bi=(e,t)=>t.map(t=>{if(e.contains(t))return t;let n=yi(t);return e.contains(n)?n:null}).filter(e=>e!=null),xi=e=>{let t=new Set;return e.forEach(e=>{let n=e;for(;n&&!t.has(n);)t.add(n),n=n.parentNode}),t},Si=(e,t,n)=>{let r=[],i=e=>{e&&!n.has(e)&&Array.from(e.children).forEach(e=>{W(e)!==`script`&&(t.has(e)?i(e):r.push(e))})};return i(e),r};function Ci(e,t,n,r,{mark:i=!0}){let a=null;r?a=`inert`:n&&(a=`aria-hidden`);let o=null,s=null,c=bi(t,e),l=i?Si(t,xi(c),new Set(c)):[],u=[],d=[];if(a){let e=pi[a],n=vi(a);s=n,o=e;let r=bi(t,Array.from(t.querySelectorAll(`[aria-live]`))),i=c.concat(r);Si(t,xi(i),new Set(i)).forEach(t=>{let r=t.getAttribute(a),i=r!==null&&r!==`false`,o=(e.get(t)||0)+1;e.set(t,o),u.push(t),o===1&&i&&n.add(t),i||t.setAttribute(a,a===`inert`?``:`true`)})}return i&&l.forEach(e=>{let t=(gi.get(e)||0)+1;gi.set(e,t),d.push(e),t===1&&e.setAttribute(mi,``)}),_i+=1,()=>{o&&u.forEach(e=>{let t=(o.get(e)||0)-1;o.set(e,t),t||(!s?.has(e)&&a&&e.removeAttribute(a),s?.delete(e))}),i&&d.forEach(e=>{let t=(gi.get(e)||0)-1;gi.set(e,t),t||e.removeAttribute(mi)}),--_i,_i||(pi.inert=new WeakMap,pi[`aria-hidden`]=new WeakMap,hi.inert=new WeakSet,hi[`aria-hidden`]=new WeakSet,gi=new WeakMap)}}function wi(e,t={}){let{ariaHidden:n=!1,inert:r=!1,mark:i=!0}=t,a=J(e[0]).body;return Ci(e,a,n,r,{mark:i})}var Ti=0;function Ei(e,t=`mui`){let[n,r]=l.useState(e),i=e||n;return l.useEffect(()=>{n??(Ti+=1,r(`${t}-${Ti}`))},[n,t]),i}var Di=Kn.useId;function Oi(e,t){if(Di!==void 0){let n=Di();return e??(t?`${t}-${n}`:n)}return Ei(e,t)}function ki(e,t){return function(n,...r){let i=new URL(e);return i.searchParams.set(`code`,n.toString()),r.forEach(e=>i.searchParams.append(`args[]`,e)),`${t} error #${n}; visit ${i} for the full message.`}}var Ai=ki(`https://base-ui.com/production-error`,`Base UI`),ji=19;function Mi(e){return ji>=e}function Ni(e){if(!l.isValidElement(e))return null;let t=e,n=t.props;return(Mi(19)?n?.ref:t.ref)??null}function Pi(e,t){if(e&&!t)return e;if(!e&&t)return t;if(e||t)return{...e,...t}}function Fi(e,t){let n={};for(let r in e){let i=e[r];if(t?.hasOwnProperty(r)){let e=t[r](i);e!=null&&Object.assign(n,e);continue}i===!0?n[`data-${r.toLowerCase()}`]=``:i&&(n[`data-${r.toLowerCase()}`]=i.toString())}return n}function Ii(e,t){return typeof e==`function`?e(t):e}function Li(e,t){return typeof e==`function`?e(t):e}var Ri={};function zi(e,t,n,r,i){if(!n&&!r&&!i&&!e)return Vi(t);let a=Vi(e);return t&&(a=Hi(a,t)),n&&(a=Hi(a,n)),r&&(a=Hi(a,r)),i&&(a=Hi(a,i)),a}function Bi(e){if(e.length===0)return Ri;if(e.length===1)return Vi(e[0]);let t=Vi(e[0]);for(let n=1;n<e.length;n+=1)t=Hi(t,e[n]);return t}function Vi(e){return Ki(e)?{...qi(e,Ri)}:Ui(e)}function Hi(e,t){return Ki(t)?qi(t,e):Wi(e,t)}function Ui(e){let t={...e};for(let e in t){let n=t[e];Gi(e,n)&&(t[e]=Yi(n))}return t}function Wi(e,t){if(!t)return e;for(let n in t){let r=t[n];switch(n){case`style`:e[n]=Pi(e.style,r);break;case`className`:e[n]=Zi(e.className,r);break;default:e[n]=Gi(n,r)?Ji(e[n],r):r}}return e}function Gi(e,t){let n=e.charCodeAt(0),r=e.charCodeAt(1),i=e.charCodeAt(2);return n===111&&r===110&&i>=65&&i<=90&&(typeof t==`function`||t===void 0)}function Ki(e){return typeof e==`function`}function qi(e,t){return Ki(e)?e(t):e??Ri}function Ji(e,t){return t?e?(...n)=>{let r=n[0];if(Qi(r)){let i=r;Xi(i);let a=t(...n);return i.baseUIHandlerPrevented||e?.(...n),a}let i=t(...n);return e?.(...n),i}:Yi(t):e}function Yi(e){return e&&((...t)=>{let n=t[0];return Qi(n)&&Xi(n),e(...t)})}function Xi(e){return e.preventBaseUIHandler=()=>{e.baseUIHandlerPrevented=!0},e}function Zi(e,t){return t?e?t+` `+e:t:e}function Qi(e){return typeof e==`object`&&!!e&&`nativeEvent`in e}function $i(e,t,n={}){let r=t.render;n.enabled!==!1&&(r=ra(r));let i=ea(t,n,r);if(n.enabled===!1)return null;let a=n.state??et;return ia(e,r,i,a)}function ea(e,t,n){let{className:r,style:i}=e,{state:a=et,ref:o,props:s,stateAttributesMapping:c,enabled:l=!0}=t,u=l?Ii(r,a):void 0,d=l?Li(i,a):void 0,f=l?Fi(a,c):et,p=l&&s?ta(s):void 0,m=l?Pi(f,p)??{}:et;return typeof document<`u`&&(l?m.ref=Array.isArray(o)?zn([m.ref,Ni(n),...o]):Rn(m.ref,Ni(n),o):Rn(null,null)),l?(u!==void 0&&(m.className=Zi(m.className,u)),d!==void 0&&(m.style=Pi(m.style,d)),m):et}function ta(e){return Array.isArray(e)?Bi(e):zi(void 0,e)}var na=Symbol.for(`react.lazy`);function ra(e){if(e?.$$typeof!==na)return e;let t=l.Children.toArray(e)[0];return l.isValidElement(t)?t:e}function ia(e,t,n,r){if(t){if(typeof t==`function`)return t(n,r);let e=zi(n,t.props);return e.ref=n.ref,l.cloneElement(t,e)}if(e&&typeof e==`string`)return aa(e,n);throw Error(Ai(8))}function aa(e,t){return e===`button`?(0,l.createElement)(`button`,{type:`button`,...t,key:t.key}):e===`img`?(0,l.createElement)(`img`,{alt:``,...t,key:t.key}):l.createElement(e,t)}var oa={style:{transition:`none`}},sa={fallbackAxisSide:`none`},ca={fallbackAxisSide:`end`},la={clipPath:`inset(50%)`,position:`fixed`,top:0,left:0},ua=e(n(),1),da=l.createContext(null),fa=()=>l.useContext(da),pa=ui(`portal`);function ma(e={}){let{ref:t,container:n,componentProps:r=et,elementProps:i}=e,a=Oi(),o=fa()?.portalNode,[s,c]=l.useState(null),[u,d]=l.useState(null),f=$(e=>{e!==null&&d(e)}),p=l.useRef(null);U(()=>{if(n===null){p.current&&(p.current=null,d(null),c(null));return}let e=(n&&(ge(n)?n:n.current))??o??document.body;if(e==null){p.current&&(p.current=null,d(null),c(null));return}p.current!==e&&(p.current=e,d(null),c(e))},[n,o]);let m=$i(`div`,r,{ref:[t,f],props:[{id:a,[pa]:``},i]}),h=s&&m?ua.createPortal(m,s):null;return{node:u,nodeId:l.isValidElement(m)?m.props.id:void 0,subtree:h}}var ha=l.forwardRef(function(e,t){let{render:n,className:r,style:i,children:a,container:o,portalOwnerRole:s,...c}=e,{node:u,nodeId:d,subtree:f}=ma({container:o,ref:t,componentProps:e,elementProps:c}),p=l.useRef(null),m=l.useRef(null),h=l.useRef(null),g=l.useRef(null),[_,v]=l.useState(null),y=l.useRef(!1),b=_?.modal,x=_?.open,S=!!_&&!_.modal&&_.open&&!!u;l.useEffect(()=>{if(!u||b)return;function e(e){u&&e.relatedTarget&&ai(e)&&(e.type===`focusin`?y.current&&=(si(u),!1):(oi(u),y.current=!0))}return Ln(q(u,`focusin`,e,!0),q(u,`focusout`,e,!0))},[u,b]),U(()=>{u&&x===!0&&y.current&&(si(u),y.current=!1)},[x,u]);let C=l.useMemo(()=>({beforeOutsideRef:p,afterOutsideRef:m,beforeInsideRef:h,afterInsideRef:g,portalNode:u,setFocusManagerState:v}),[u]);return(0,Q.jsxs)(l.Fragment,{children:[f,(0,Q.jsxs)(da.Provider,{value:C,children:[S&&u&&(0,Q.jsx)(er,{"data-type":`outside`,ref:p,onFocus:e=>{ai(e,u)?h.current?.focus():ti(_?_.domReference:null)?.focus()}}),S&&u&&(0,Q.jsx)(`span`,{role:s,"aria-owns":d,style:la}),u&&ua.createPortal(a,u),S&&u&&(0,Q.jsx)(er,{"data-type":`outside`,ref:m,onFocus:e=>{ai(e,u)?g.current?.focus():(ei(_?_.domReference:null)?.focus(),_?.closeOnFocusOut&&_?.onOpenChange(!1,Z(`focus-out`,e.nativeEvent)))}})]})]})});function ga(){let e=new Map;return{emit(t,n){e.get(t)?.forEach(e=>e(n))},on(t,n){e.has(t)||e.set(t,new Set),e.get(t).add(n)},off(t,n){e.get(t)?.delete(n)}}}var _a=class{nodesRef={current:[]};events=ga();addNode(e){this.nodesRef.current.push(e)}removeNode(e){let t=this.nodesRef.current.findIndex(t=>t===e);t!==-1&&this.nodesRef.current.splice(t,1)}},va=l.createContext(null),ya=l.createContext(null),ba=()=>l.useContext(va)?.id||null,xa=e=>{let t=l.useContext(ya);return e??t};function Sa(e){let t=Oi(),n=xa(e),r=ba();return U(()=>{if(!t)return;let e={id:t,parentId:r};return n?.addNode(e),()=>{n?.removeNode(e)}},[n,t,r]),t}function Ca(e){let{children:t,id:n}=e,r=ba();return(0,Q.jsx)(va.Provider,{value:l.useMemo(()=>({id:n,parentId:r}),[n,r]),children:t})}function wa(e){let{children:t,externalTree:n}=e,r=Ze(()=>n??new _a).current;return(0,Q.jsx)(ya.Provider,{value:r,children:t})}function Ta(e){return e==null?e:`current`in e?e.current:e}function Ea(e,t){let n=me(Et(e));return e instanceof n.KeyboardEvent?`keyboard`:e instanceof n.FocusEvent?t||`keyboard`:`pointerType`in e?e.pointerType||`keyboard`:`touches`in e?`touch`:e instanceof n.MouseEvent?t||(e.detail===0?`keyboard`:`mouse`):``}var Da=20,Oa=[];function ka(){Oa=Oa.filter(e=>e.deref()?.isConnected)}function Aa(e){ka(),e&&W(e)!==`body`&&(Oa.push(new WeakRef(e)),Oa.length>Da&&(Oa=Oa.slice(-20)))}function ja(){return ka(),Oa[Oa.length-1]?.deref()}function Ma(e){return e?Xr(e)?e:Qr(e)[0]||e:null}function Na(e){if(e.hasAttribute(`tabindex`)&&!e.hasAttribute(`data-tabindex`)||!e.getAttribute(`role`)?.includes(`dialog`))return;let t=Zr(e).filter(e=>{let t=e.getAttribute(`data-tabindex`)||``;return Xr(e)||e.hasAttribute(`data-tabindex`)&&!t.startsWith(`-`)}),n=e.getAttribute(`tabindex`);t.length===0?n!==`0`&&(e.setAttribute(`tabindex`,`0`),e.setAttribute(`data-tabindex`,`0`)):(n!==`-1`||e.hasAttribute(`data-tabindex`)&&e.getAttribute(`data-tabindex`)!==`-1`)&&(e.setAttribute(`tabindex`,`-1`),e.setAttribute(`data-tabindex`,`-1`))}function Pa(e){let{context:t,children:n,disabled:r=!1,initialFocus:i=!0,returnFocus:a=!0,restoreFocus:o=!1,modal:s=!0,closeOnFocusOut:c=!0,openInteractionType:u=``,nextFocusableElement:d,previousFocusableElement:f,beforeContentFocusGuardRef:p,externalTree:m,getInsideElements:h}=e,g=`rootStore`in t?t.rootStore:t,_=g.useState(`open`),v=g.useState(`domReferenceElement`),y=g.useState(`floatingElement`),{events:b,dataRef:x}=g.context,S=$(()=>x.current.floatingContext?.nodeId),C=i===!1,w=an(v)&&C,T=Wn(i),E=Wn(a),D=Wn(u),O=Wn(_),k=xa(m),A=fa(),j=l.useRef(!1),M=l.useRef(!1),N=l.useRef(!1),P=l.useRef(null),F=l.useRef(``),I=l.useRef(``),L=l.useRef(null),R=l.useRef(null),z=Rn(L,p,A?.beforeInsideRef),ee=Rn(R,A?.afterInsideRef),B=it(),te=it(),ne=ct(),re=A!=null,V=sn(y),H=$((e=V)=>e?Qr(e):[]),ie=$(()=>h?.().filter(e=>e!=null)??[]);l.useEffect(()=>{if(r||!s)return;function e(e){e.key===`Tab`&&X(V,Tt(J(V)))&&H().length===0&&!w&&yt(e)}return q(J(V),`keydown`,e)},[r,V,s,w,H]),l.useEffect(()=>{if(r||!_)return;let e=J(V);function t(){N.current=!1}function n(e){let t=Et(e),n=ie(),r=X(y,t)||X(v,t)||X(A?.portalNode,t)||n.some(e=>e===t||X(e,t));N.current=!r,I.current=e.pointerType||`keyboard`,t?.closest(`[data-base-ui-click-trigger]`)&&(M.current=!0,te.start(0,()=>{M.current=!1}))}function i(){I.current=`keyboard`}return Ln(q(e,`pointerdown`,n,!0),q(e,`pointerup`,t,!0),q(e,`pointercancel`,t,!0),q(e,`keydown`,i,!0),t)},[r,y,v,V,_,A,te,ie]),l.useEffect(()=>{if(r||!c)return;let e=J(V);function t(){M.current=!0,te.start(0,()=>{M.current=!1})}function n(e){let t=Et(e);Xr(t)&&(P.current=t)}function i(t){let n=t.relatedTarget,r=t.currentTarget,i=Et(t);s&&n==null&&i!=null&&X(y,i)&&Aa(i),queueMicrotask(()=>{let a=S(),c=g.context.triggerElements,l=ie(),u=n?.hasAttribute(ui(`focus-guard`))&&[L.current,R.current,A?.beforeInsideRef.current,A?.afterInsideRef.current,A?.beforeOutsideRef.current,A?.afterOutsideRef.current,Ta(f),Ta(d)].includes(n),p=!(X(v,n)||X(y,n)||X(n,y)||X(A?.portalNode,n)||l.some(e=>e===n||X(e,n))||c.hasMatchingElement(e=>X(e,n))||u||k&&(ci(k.nodesRef.current,a).find(e=>X(e.context?.elements.floating,n)||X(e.context?.elements.domReference,n))||li(k.nodesRef.current,a).find(e=>[e.context?.elements.floating,sn(e.context?.elements.floating)].includes(n)||e.context?.elements.domReference===n)));if(r===v&&V&&Na(V),o&&r!==v&&!Ir(i)&&Tt(e)===e.body){if(K(V)&&(V.focus(),o===`popup`)){ne.request(()=>{V.focus()});return}let e=H(),t=P.current,n=(t&&e.includes(t)?t:null)||e[e.length-1]||V;K(n)&&n.focus()}if(x.current.insideReactTree){x.current.insideReactTree=!1;return}(w||!s)&&n&&p&&!M.current&&(w||n!==ja())&&(j.current=!0,g.setOpen(!1,Z(Cn,t)))})}function a(){N.current||(x.current.insideReactTree=!0,B.start(0,()=>{x.current.insideReactTree=!1}))}let l=K(v)?v:null;if(y||l)return Ln(l&&q(l,`focusout`,i),l&&q(l,`pointerdown`,t),y&&q(y,`focusin`,n),y&&q(y,`focusout`,i),y&&A&&q(y,`focusout`,a,!0))},[r,v,y,V,s,k,A,g,c,o,H,w,S,x,B,te,ne,d,f,ie]),l.useEffect(()=>{if(r||!y||!_)return;let e=Array.from(A?.portalNode?.querySelectorAll(`[${ui(`portal`)}]`)||[]),t=(k?li(k.nodesRef.current,S()):[]).find(e=>an(e.context?.elements.domReference||null))?.context?.elements.domReference,n=wi([y,...e,L.current,R.current,A?.beforeOutsideRef.current,A?.afterOutsideRef.current,...ie(),t,Ta(f),Ta(d),w?v:null].filter(e=>e!=null),{ariaHidden:s||w,mark:!1}),i=wi([y,...e].filter(e=>e!=null));return()=>{i(),n()}},[_,r,v,y,s,A,w,k,S,d,f,ie]),U(()=>{if(!_||r||!K(V))return;F.current=``,I.current=``;let e=J(V),t=Tt(e);queueMicrotask(()=>{let n=T.current,r=typeof n==`function`?n(D.current||``):n;if(r===void 0||r===!1||X(V,t))return;let i=null,a=()=>(i??=H(V),i[0]||V),o;o=r===!0||r===null?a():Ta(r),o||=a();let s=X(V,Tt(e));fi(o,{preventScroll:o===V,shouldFocus(){if(!O.current)return!1;if(s)return!0;let t=Tt(e);return!(t!==o&&X(V,t))}})})},[r,_,V,H,T,D,O]),U(()=>{if(r||!V)return;let e=J(V),t=Tt(e),n=D.current==null;Aa(t);function i(e){if(e.open||(F.current=Ea(e.nativeEvent,I.current)),e.reason===`trigger-hover`&&e.nativeEvent.type===`mouseleave`&&(j.current=!0),e.reason===`outside-press`){if(e.nested)j.current=!1;else if(xt(e.nativeEvent)||St(e.nativeEvent))j.current=!1;else{let e=!1;J(V).createElement(`div`).focus({get preventScroll(){return e=!0,!1}}),e?j.current=!1:j.current=!0}}}b.on(`openchange`,i);function a(e){let r=E.current,i=typeof r==`function`?r(e):r;if(i===void 0||i===!1)return null;i===null&&(i=!0);let a=v?.isConnected?v:null,o=t?.isConnected&&W(t)!==`body`?t:null,s=n?o||a:a||o;return s||=ja()||null,typeof i==`boolean`?s:Ta(i)||s||null}return()=>{b.off(`openchange`,i);let t=Tt(e),n=ie(),r=X(y,t)||n.some(e=>e===t||X(e,t))||k&&ci(k.nodesRef.current,S(),!1).some(e=>X(e.context?.elements.floating,t)),o=E.current,s=F.current,c=a(s);queueMicrotask(()=>{let n=Ma(c),i=typeof o!=`boolean`;if(o&&!j.current&&K(n)&&(i||n===t||t===e.body||r)){let e={preventScroll:!0};s===`keyboard`&&(e.focusVisible=!0),n.focus(e)}j.current=!1})}},[r,y,V,E,D,b,k,v,S,ie]),U(()=>{if(!Ke||_||!y)return;let e=Tt(J(y));K(e)&&nn(e)&&X(y,e)&&e.blur()},[_,y]),U(()=>{if(!r&&A)return A.setFocusManagerState({modal:s,closeOnFocusOut:c,open:_,onOpenChange:g.setOpen,domReference:v}),()=>{A.setFocusManagerState(null)}},[r,A,s,_,g,c,v]),U(()=>{if(!r&&V)return Na(V),()=>{queueMicrotask(ka)}},[r,V]);let ae=!r&&(!s||!w)&&(re||s);return(0,Q.jsxs)(l.Fragment,{children:[ae&&(0,Q.jsx)(er,{"data-type":`inside`,ref:z,onFocus:e=>{if(s){let e=H();fi(e[e.length-1])}else A?.portalNode&&(j.current=!1,ai(e,A.portalNode)?ei(v)?.focus():Ta(f??A.beforeOutsideRef)?.focus())}}),n,ae&&(0,Q.jsx)(er,{"data-type":`inside`,ref:ee,onFocus:e=>{s?fi(H()[0]):A?.portalNode&&(c&&(j.current=!0),ai(e,A.portalNode)?ti(v)?.focus():Ta(d??A.afterOutsideRef)?.focus())}})]})}function Fa(e,t={}){let{enabled:n=!0,event:r=`click`,toggle:i=!0,ignoreMouse:a=!1,stickIfOpen:o=!0,touchOpenDelay:s=0,reason:c=mn}=t,u=`rootStore`in e?e.rootStore:e,d=u.context.dataRef,f=l.useRef(void 0),p=ct(),m=it(),h=l.useMemo(()=>{function e(e,t,n,r){let i=Z(c,t,n);e&&r===`touch`&&s>0?m.start(s,()=>{u.setOpen(!0,i)}):u.setOpen(e,i)}function t(e,t,n){let r=d.current.openEvent,a=u.select(`domReferenceElement`)!==t;return e&&a||!e||!i?!0:r&&o?!n(r.type):!1}return{onPointerDown(e){f.current=Ct(e.pointerType,!0)&&St(e.nativeEvent)?`virtual`:e.pointerType},onMouseDown(n){let i=f.current,o=n.nativeEvent,s=u.select(`open`);if(n.button!==0||r===`click`||Ct(i,!0)&&a)return;let c=t(s,n.currentTarget,e=>e===`click`||e===`mousedown`),l=Et(o);if(nn(l)){e(c,o,l,i);return}let d=n.currentTarget;p.request(()=>{e(c,o,d,i)})},onClick(n){if(r===`mousedown-only`)return;let i=f.current;if(r===`mousedown`&&i){f.current=void 0;return}Ct(i,!0)&&a||e(t(u.select(`open`),n.currentTarget,e=>e===`click`||e===`mousedown`||e===`keydown`||e===`keyup`),n.nativeEvent,n.currentTarget,i)},onKeyDown(){f.current=void 0}}},[d,r,a,c,u,o,i,p,m,s]);return l.useMemo(()=>n?{reference:h}:et,[n,h])}function Ia(e,t){let n=null,r=null,i=!1;return{contextElement:e||void 0,getBoundingClientRect(){let a=e?.getBoundingClientRect()||{width:0,height:0,x:0,y:0},o=t.axis===`x`||t.axis===`both`,s=t.axis===`y`||t.axis===`both`,c=[`mouseenter`,`mousemove`].includes(t.dataRef.current.openEvent?.type||``)&&t.pointerType!==`touch`,l=a.width,u=a.height,d=a.x,f=a.y;return n==null&&t.x&&o&&(n=a.x-t.x),r==null&&t.y&&s&&(r=a.y-t.y),d-=n||0,f-=r||0,l=0,u=0,!i||c?(l=t.axis===`y`?a.width:0,u=t.axis===`x`?a.height:0,d=o&&t.x!=null?t.x:d,f=s&&t.y!=null?t.y:f):i&&!c&&(u=t.axis===`x`?a.height:u,l=t.axis===`y`?a.width:l),i=!0,{width:l,height:u,x:d,y:f,top:f,right:d+l,bottom:f+u,left:d}}}}function La(e){return e!=null&&e.clientX!=null}function Ra(e,t={}){let{enabled:n=!0,axis:r=`both`}=t,i=`rootStore`in e?e.rootStore:e,a=i.useState(`open`),o=i.useState(`floatingElement`),s=i.useState(`domReferenceElement`),c=i.context.dataRef,u=l.useRef(!1),d=l.useRef(null),[f,p]=l.useState(),[m,h]=l.useState([]),g=$(e=>{i.set(`positionReference`,e)}),_=$((e,t,n)=>{u.current||(!c.current.openEvent||La(c.current.openEvent))&&i.set(`positionReference`,Ia(n??s,{x:e,y:t,axis:r,dataRef:c,pointerType:f}))}),v=$(e=>{a?d.current||(_(e.clientX,e.clientY,e.currentTarget),h([])):_(e.clientX,e.clientY,e.currentTarget)}),y=Ct(f)?o:a;l.useEffect(()=>{if(!n){g(s);return}if(!y)return;function e(){d.current?.(),d.current=null}let t=me(o);function r(t){let n=Et(t);X(o,n)?e():_(t.clientX,t.clientY)}return!c.current.openEvent||La(c.current.openEvent)?d.current=q(t,`mousemove`,r):g(s),e},[y,n,o,c,s,i,_,g,m]),l.useEffect(()=>()=>{i.set(`positionReference`,null)},[i]),l.useEffect(()=>{n&&!o&&(u.current=!1)},[n,o]),l.useEffect(()=>{!n&&a&&(u.current=!0)},[n,a]);let b=l.useMemo(()=>{function e(e){p(e.pointerType)}return{onPointerDown:e,onPointerEnter:e,onMouseMove:v,onMouseEnter:v}},[v]);return l.useMemo(()=>n?{reference:b,trigger:b}:{},[n,b])}function za(){return!1}function Ba(e){return{escapeKey:typeof e==`boolean`?e:e?.escapeKey??!1,outsidePress:typeof e==`boolean`?e:e?.outsidePress??!0}}function Va(e,t={}){let{enabled:n=!0,escapeKey:r=!0,outsidePress:i=!0,outsidePressEvent:a=`sloppy`,referencePress:o=za,bubbles:s,externalTree:c}=t,u=`rootStore`in e?e.rootStore:e,d=u.useState(`open`),f=u.useState(`floatingElement`),{dataRef:p,events:m}=u.context,h=xa(c),g=$(typeof i==`function`?i:()=>!1),_=typeof i==`function`?g:i,v=_!==!1,y=$(()=>a),{escapeKey:b,outsidePress:x}=Ba(s),S=l.useRef(!1),C=l.useRef(!1),w=l.useRef(!1),T=l.useRef(!1),E=l.useRef(!1),D=l.useRef(``),O=l.useRef(null),k=it(),A=it(),j=$(()=>{A.clear(),p.current.insideReactTree=!1}),M=$(e=>{let t=p.current.floatingContext?.nodeId;return(h?ci(h.nodesRef.current,t):[]).some(t=>t.context?.open&&!t.context.dataRef.current[e])}),N=$(e=>en(e,u.select(`floatingElement`))||en(e,u.select(`domReferenceElement`))),P=$(e=>{o()&&u.setOpen(!1,Z(mn,e.nativeEvent))}),F=$(e=>{if(!d||!n||!r||e.key!==`Escape`||E.current||!b&&M(`__escapeKeyBubbles`))return;let t=Z(wn,bt(e)?e.nativeEvent:e);u.setOpen(!1,t),t.isCanceled||e.preventDefault(),!b&&!t.isPropagationAllowed&&e.stopPropagation()}),I=$(()=>{p.current.insideReactTree=!0,A.start(0,j)}),L=$(e=>{if(!d||!n||e.button!==0)return;let t=Et(e.nativeEvent);X(u.select(`floatingElement`),t)&&(S.current||(S.current=!0,C.current=!1))}),R=$(e=>{d&&n&&(e.defaultPrevented||e.nativeEvent.defaultPrevented)&&S.current&&(C.current=!0)});l.useEffect(()=>{function e(e){e.open||(T.current=!1)}return m.on(`openchange`,e),()=>{m.off(`openchange`,e)}},[m]),l.useEffect(()=>{if(!d||!n)return d||(T.current=!1),j;p.current.__escapeKeyBubbles=b,p.current.__outsidePressBubbles=x;let e=new rt,t=new rt,i=J(f);function a(){e.clear(),E.current=!0}function o(){e.start(Ke?5:0,()=>{E.current=!1})}function s(){w.current=!0,t.start(0,()=>{w.current=!1})}function c(){S.current=!1,C.current=!1}function l(){let e=D.current,t=e===`pen`||!e?`mouse`:e,n=y(),r=typeof n==`function`?n():n;return typeof r==`string`?r:r[t]}function m(e){let t=l();return t===`intentional`&&e.type!==`click`||t===`sloppy`&&e.type===`click`}function g(e){let t=p.current.floatingContext?.nodeId,n=h&&ci(h.nodesRef.current,t).some(t=>en(e,t.context?.elements.floating));return N(e)||n}function A(e){if(m(e)){e.type!==`click`&&!N(e)&&(t.clear(),w.current=!1),j();return}if(p.current.insideReactTree){j();return}let n=Et(e),r=`[${ui(`inert`)}]`,i=G(n)?n.getRootNode():null,a=Array.from((_e(i)?i:J(u.select(`floatingElement`))).querySelectorAll(r)),o=u.context.triggerElements;if(n&&(o.hasElement(n)||o.hasMatchingElement(e=>X(e,n))))return;let s=G(n)?n:null;for(;s&&!Oe(s);){let e=je(s);if(Oe(e)||!G(e))break;s=e}if(!(a.length&&G(n)&&!tn(n)&&!X(n,u.select(`floatingElement`))&&a.every(e=>!X(s,e)))){if(K(n)&&!(`touches`in e)){let t=Oe(n),r=ke(n),i=/auto|scroll/,a=t||i.test(r.overflowX),o=t||i.test(r.overflowY),s=a&&n.clientWidth>0&&n.scrollWidth>n.clientWidth,c=o&&n.clientHeight>0&&n.scrollHeight>n.clientHeight,l=r.direction===`rtl`,u=c&&(l?e.offsetX<=n.offsetWidth-n.clientWidth:e.offsetX>n.clientWidth),d=s&&e.offsetY>n.clientHeight;if(u||d)return}if(!g(e)){if(l()===`intentional`){if(e.detail!==0&&!xt(e)&&!T.current)return;if(w.current){t.clear(),w.current=!1;return}}(typeof _!=`function`||_(e))&&(M(`__outsidePressBubbles`)||(u.setOpen(!1,Z(_n,e)),j()))}}}function P(e){l()===`sloppy`&&e.pointerType!==`touch`&&u.select(`open`)&&n&&!N(e)&&A(e)}function I(e){if(l()!==`sloppy`||!u.select(`open`)||!n||N(e))return;let t=e.touches[0];t&&(O.current={startTime:Date.now(),startX:t.clientX,startY:t.clientY,dismissOnTouchEnd:!1,dismissOnMouseDown:!0},k.start(1e3,()=>{O.current&&(O.current.dismissOnTouchEnd=!1,O.current.dismissOnMouseDown=!1)}))}function L(e,t){let n=Et(e);if(!n)return;let r=q(n,e.type,()=>{t(e),r()})}function R(e){D.current=`touch`,L(e,I)}function z(e){k.clear(),e.type===`pointerdown`&&(e.button===0&&(T.current=!0),D.current=e.pointerType),(e.type!==`mousedown`||!O.current||O.current.dismissOnMouseDown)&&L(e,e=>{e.type===`pointerdown`?P(e):A(e)})}function ee(e){if(e.type===`pointercancel`&&(T.current=!1),!S.current)return;let n=C.current;if(c(),l()===`intentional`){if(e.type===`pointercancel`){n&&s();return}if(!g(e)){if(n){s();return}(typeof _!=`function`||_(e))&&(t.clear(),w.current=!0,j())}}}function B(e){if(l()!==`sloppy`||!O.current||N(e))return;let t=e.touches[0];if(!t)return;let n=Math.abs(t.clientX-O.current.startX),r=Math.abs(t.clientY-O.current.startY),i=Math.sqrt(n*n+r*r);i>5&&(O.current.dismissOnTouchEnd=!0),i>10&&(A(e),k.clear(),O.current=null)}function te(e){L(e,B)}function ne(e){l()===`sloppy`&&O.current&&!N(e)&&(O.current.dismissOnTouchEnd&&A(e),k.clear(),O.current=null)}function re(e){L(e,ne)}let V=Ln(r&&Ln(q(i,`keydown`,F),q(i,`compositionstart`,a),q(i,`compositionend`,o)),v&&Ln(q(i,`click`,z,!0),q(i,`pointerdown`,z,!0),q(i,`pointerup`,ee,!0),q(i,`pointercancel`,ee,!0),q(i,`mousedown`,z,!0),q(i,`mouseup`,ee,!0),q(i,`touchstart`,R,{capture:!0,passive:!0}),q(i,`touchmove`,te,{capture:!0,passive:!0}),q(i,`touchend`,re,{capture:!0,passive:!0})));return()=>{V(),e.clear(),t.clear(),c(),w.current=!1,j()}},[p,f,r,v,_,d,n,b,x,F,j,y,M,N,h,u,k]);let z=l.useMemo(()=>({onKeyDown:F,onPointerDown:P,onClick:P}),[F,P]),ee=l.useMemo(()=>({onKeyDown:F,onPointerDown:R,onMouseDown:R,onClickCapture:I,onMouseDownCapture(e){I(),L(e)},onPointerDownCapture(e){I(),L(e)},onMouseUpCapture:I,onTouchEndCapture:I,onTouchMoveCapture:I}),[F,I,L,R]);return l.useMemo(()=>n?{reference:z,floating:ee,trigger:z}:{},[n,z,ee])}function Ha(e,t,n){let{reference:r,floating:i}=e,a=pr(t),o=mr(t),s=fr(o),c=lr(t),l=a===`y`,u=r.x+r.width/2-i.width/2,d=r.y+r.height/2-i.height/2,f=r[s]/2-i[s]/2,p;switch(c){case`top`:p={x:u,y:r.y-i.height};break;case`bottom`:p={x:u,y:r.y+r.height};break;case`right`:p={x:r.x+r.width,y:d};break;case`left`:p={x:r.x-i.width,y:d};break;default:p={x:r.x,y:r.y}}let m=ur(t);return m&&(p[o]+=f*(m===`end`?1:-1)*(n&&l?-1:1)),p}async function Ua(e,t){t===void 0&&(t={});let{x:n,y:r,platform:i,rects:a,elements:o,strategy:s}=e,{boundary:c=`clippingAncestors`,rootBoundary:l=`viewport`,elementContext:u=`floating`,altBoundary:d=!1,padding:f=0}=cr(t,e),p=Er(f),m=o[d?u===`floating`?`reference`:`floating`:u],h=Dr(await i.getClippingRect({element:await(i.isElement==null?void 0:i.isElement(m))??!0?m:m.contextElement||await(i.getDocumentElement==null?void 0:i.getDocumentElement(o.floating)),boundary:c,rootBoundary:l,strategy:s})),g=u===`floating`?{x:n,y:r,width:a.floating.width,height:a.floating.height}:a.reference,_=await(i.getOffsetParent==null?void 0:i.getOffsetParent(o.floating)),v=await(i.isElement==null?void 0:i.isElement(_))&&await(i.getScale==null?void 0:i.getScale(_))||{x:1,y:1},y=Dr(i.convertOffsetParentRelativeRectToViewportRelativeRect?await i.convertOffsetParentRelativeRectToViewportRelativeRect({elements:o,rect:g,offsetParent:_,strategy:s}):g);return{top:(h.top-y.top+p.top)/v.y,bottom:(y.bottom-h.bottom+p.bottom)/v.y,left:(h.left-y.left+p.left)/v.x,right:(y.right-h.right+p.right)/v.x}}var Wa=50,Ga=async(e,t,n)=>{let{placement:r=`bottom`,strategy:i=`absolute`,middleware:a=[],platform:o}=n,s=o.detectOverflow?o:{...o,detectOverflow:Ua},c=await(o.isRTL==null?void 0:o.isRTL(t)),l=await o.getElementRects({reference:e,floating:t,strategy:i}),{x:u,y:d}=Ha(l,r,c),f=r,p=0,m={};for(let n=0;n<a.length;n++){let h=a[n];if(!h)continue;let{name:g,fn:_}=h,{x:v,y,data:b,reset:x}=await _({x:u,y:d,initialPlacement:r,placement:f,strategy:i,middlewareData:m,rects:l,platform:s,elements:{reference:e,floating:t}});u=v??u,d=y??d,m[g]={...m[g],...b},x&&p<Wa&&(p++,typeof x==`object`&&(x.placement&&(f=x.placement),x.rects&&(l=x.rects===!0?await o.getElementRects({reference:e,floating:t,strategy:i}):x.rects),{x:u,y:d}=Ha(l,f,c)),n=-1)}return{x:u,y:d,placement:f,strategy:i,middlewareData:m}},Ka=function(e){return e===void 0&&(e={}),{name:`flip`,options:e,async fn(t){var n;let{placement:r,middlewareData:i,rects:a,initialPlacement:o,platform:s,elements:c}=t,{mainAxis:l=!0,crossAxis:u=!0,fallbackPlacements:d,fallbackStrategy:f=`bestFit`,fallbackAxisSideDirection:p=`none`,flipAlignment:m=!0,...h}=cr(e,t);if((n=i.arrow)!=null&&n.alignmentOffset)return{};let g=lr(r),_=pr(o),v=lr(o)===o,y=await(s.isRTL==null?void 0:s.isRTL(c.floating)),b=d||(v||!m?[wr(o)]:gr(o)),x=p!==`none`;!d&&x&&b.push(...Cr(o,m,p,y));let S=[o,...b],C=await s.detectOverflow(t,h),w=[],T=i.flip?.overflows||[];if(l&&w.push(C[g]),u){let e=hr(r,a,y);w.push(C[e[0]],C[e[1]])}if(T=[...T,{placement:r,overflows:w}],!w.every(e=>e<=0)){let e=(i.flip?.index||0)+1,t=S[e];if(t&&(u!==`alignment`||_===pr(t)||T.every(e=>pr(e.placement)!==_||e.overflows[0]>0)))return{data:{index:e,overflows:T},reset:{placement:t}};let n=T.filter(e=>e.overflows[0]<=0).sort((e,t)=>e.overflows[1]-t.overflows[1])[0]?.placement;if(!n)switch(f){case`bestFit`:{let e=T.filter(e=>{if(x){let t=pr(e.placement);return t===_||t===`y`}return!0}).map(e=>[e.placement,e.overflows.filter(e=>e>0).reduce((e,t)=>e+t,0)]).sort((e,t)=>e[1]-t[1])[0]?.[0];e&&(n=e);break}case`initialPlacement`:n=o}if(r!==n)return{reset:{placement:n}}}return{}}}},qa=new Set([`left`,`top`]);async function Ja(e,t){let{placement:n,platform:r,elements:i}=e,a=await(r.isRTL==null?void 0:r.isRTL(i.floating)),o=lr(n),s=ur(n),c=pr(n)===`y`,l=qa.has(o)?-1:1,u=a&&c?-1:1,d=cr(t,e),{mainAxis:f,crossAxis:p,alignmentAxis:m}=typeof d==`number`?{mainAxis:d,crossAxis:0,alignmentAxis:null}:{mainAxis:d.mainAxis||0,crossAxis:d.crossAxis||0,alignmentAxis:d.alignmentAxis};return s&&typeof m==`number`&&(p=s===`end`?m*-1:m),c?{x:p*u,y:f*l}:{x:f*l,y:p*u}}var Ya=function(e){return e===void 0&&(e=0),{name:`offset`,options:e,async fn(t){var n;let{x:r,y:i,placement:a,middlewareData:o}=t,s=await Ja(t,e);return a===o.offset?.placement&&(n=o.arrow)!=null&&n.alignmentOffset?{}:{x:r+s.x,y:i+s.y,data:{...s,placement:a}}}}},Xa=function(e){return e===void 0&&(e={}),{name:`shift`,options:e,async fn(t){let{x:n,y:r,placement:i,platform:a}=t,{mainAxis:o=!0,crossAxis:s=!1,limiter:c={fn:e=>{let{x:t,y:n}=e;return{x:t,y:n}}},...l}=cr(e,t),u={x:n,y:r},d=await a.detectOverflow(t,l),f=pr(i),p=dr(f),m=u[p],h=u[f],g=(e,t)=>sr(t+d[e===`y`?`top`:`left`],t,t-d[e===`y`?`bottom`:`right`]);o&&(m=g(p,m)),s&&(h=g(f,h));let _=c.fn({...t,[p]:m,[f]:h});return{..._,data:{x:_.x-n,y:_.y-r,enabled:{[p]:o,[f]:s}}}}}},Za=function(e){return e===void 0&&(e={}),{options:e,fn(t){let{x:n,y:r,placement:i,rects:a,middlewareData:o}=t,{offset:s=0,mainAxis:c=!0,crossAxis:l=!0}=cr(e,t),u={x:n,y:r},d=pr(i),f=dr(d),p=u[f],m=u[d],h=cr(s,t),g=typeof h==`number`?{mainAxis:h,crossAxis:0}:{mainAxis:h.mainAxis??0,crossAxis:h.crossAxis??0};if(c){let e=f===`y`?`height`:`width`,t=a.reference[f]-a.floating[e]+g.mainAxis,n=a.reference[f]+a.reference[e]-g.mainAxis;p<t?p=t:p>n&&(p=n)}if(l){let e=f===`y`?`width`:`height`,t=qa.has(lr(i)),n=a.reference[d]-a.floating[e]+(t&&o.offset?.[d]||0)+(t?0:g.crossAxis),r=a.reference[d]+a.reference[e]+(t?0:o.offset?.[d]||0)-(t?g.crossAxis:0);m<n?m=n:m>r&&(m=r)}return{[f]:p,[d]:m}}}},Qa=function(e){return e===void 0&&(e={}),{name:`size`,options:e,async fn(t){let{placement:n,rects:r,platform:i,elements:a}=t,{apply:o=()=>{},...s}=cr(e,t),c=await i.detectOverflow(t,s),l=lr(n),u=ur(n),d=pr(n)===`y`,{width:f,height:p}=r.floating,m,h;l===`top`||l===`bottom`?(m=l,h=u===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?`start`:`end`)?`left`:`right`):(h=l,m=u===`end`?`top`:`bottom`);let g=p-c.top-c.bottom,_=f-c.left-c.right,v=tr(p-c[m],g),y=tr(f-c[h],_),b=t.middlewareData.shift,x=!b,S=v,C=y;b!=null&&b.enabled.x&&(C=_),b!=null&&b.enabled.y&&(S=g),x&&!u&&(d?C=f-2*nr(c.left,c.right):S=p-2*nr(c.top,c.bottom)),await o({...t,availableWidth:C,availableHeight:S});let w=await i.getDimensions(a.floating);return f!==w.width||p!==w.height?{reset:{rects:!0}}:{}}}};function $a(e){let t=ke(e),n=parseFloat(t.width)||0,r=parseFloat(t.height)||0,i=K(e),a=i?e.offsetWidth:n,o=i?e.offsetHeight:r,s=rr(n)!==a||rr(r)!==o;return s&&(n=a,r=o),{width:n,height:r,$:s}}function eo(e){return G(e)?e:e.contextElement}function to(e){let t=eo(e);if(!K(t))return ar(1);let n=t.getBoundingClientRect(),{width:r,height:i,$:a}=$a(t),o=(a?rr(n.width):n.width)/r,s=(a?rr(n.height):n.height)/i;return(!o||!Number.isFinite(o))&&(o=1),(!s||!Number.isFinite(s))&&(s=1),{x:o,y:s}}var no=ar(0);function ro(e){let t=me(e);return!De()||!t.visualViewport?no:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function io(e,t,n){return t===void 0&&(t=!1),!!n&&t&&n===me(e)}function ao(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);let i=e.getBoundingClientRect(),a=eo(e),o=ar(1);t&&(r?G(r)&&(o=to(r)):o=to(e));let s=io(a,n,r)?ro(a):ar(0),c=(i.left+s.x)/o.x,l=(i.top+s.y)/o.y,u=i.width/o.x,d=i.height/o.y;if(a&&r){let e=me(a),t=G(r)?me(r):r,n=e,i=Pe(n);for(;i&&t!==n;){let e=to(i),t=i.getBoundingClientRect(),r=ke(i),a=t.left+(i.clientLeft+parseFloat(r.paddingLeft))*e.x,o=t.top+(i.clientTop+parseFloat(r.paddingTop))*e.y;c*=e.x,l*=e.y,u*=e.x,d*=e.y,c+=a,l+=o,n=me(i),i=Pe(n)}}return Dr({width:u,height:d,x:c,y:l})}function oo(e,t){let n=Ae(e).scrollLeft;return t?t.left+n:ao(he(e)).left+n}function so(e,t){let n=e.getBoundingClientRect();return{x:n.left+t.scrollLeft-oo(e,n),y:n.top+t.scrollTop}}function co(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e,a=i===`fixed`,o=he(r),s=t?be(t.floating):!1;if(r===o||s&&a)return n;let c={scrollLeft:0,scrollTop:0},l=ar(1),u=ar(0),d=K(r);if((d||!a)&&((W(r)!==`body`||ve(o))&&(c=Ae(r)),d)){let e=ao(r);l=to(r),u.x=e.x+r.clientLeft,u.y=e.y+r.clientTop}let f=o&&!d&&!a?so(o,c):ar(0);return{width:n.width*l.x,height:n.height*l.y,x:n.x*l.x-c.scrollLeft*l.x+u.x+f.x,y:n.y*l.y-c.scrollTop*l.y+u.y+f.y}}function lo(e){return e.getClientRects?Array.from(e.getClientRects()):[]}function uo(e){let t=Ae(e),n=e.ownerDocument.body,r=nr(e.scrollWidth,e.clientWidth,n.scrollWidth,n.clientWidth),i=nr(e.scrollHeight,e.clientHeight,n.scrollHeight,n.clientHeight),a=-t.scrollLeft+oo(e),o=-t.scrollTop;return ke(n).direction===`rtl`&&(a+=nr(e.clientWidth,n.clientWidth)-r),{width:r,height:i,x:a,y:o}}var fo=25;function po(e,t,n){n===void 0&&(n=`viewport`);let r=n===`layoutViewport`,i=me(e),a=he(e),o=i.visualViewport,s=a.clientWidth,c=a.clientHeight,l=0,u=0;if(o){let e=!De()||t===`fixed`;r?e||(l=-o.offsetLeft,u=-o.offsetTop):(s=o.width,c=o.height,e&&(l=o.offsetLeft,u=o.offsetTop))}if(oo(a)<=0){let e=a.ownerDocument,t=e.body,n=getComputedStyle(t),r=e.compatMode===`CSS1Compat`&&parseFloat(n.marginLeft)+parseFloat(n.marginRight)||0,i=Math.abs(a.clientWidth-t.clientWidth-r),o=getComputedStyle(a).scrollbarGutter===`stable both-edges`?i/2:i;o<=fo&&(s-=o)}return{width:s,height:c,x:l,y:u}}function mo(e,t){let n=ao(e,!0,t===`fixed`),r=n.top+e.clientTop,i=n.left+e.clientLeft,a=to(e);return{width:e.clientWidth*a.x,height:e.clientHeight*a.y,x:i*a.x,y:r*a.y}}function ho(e,t,n){let r;if(t===`viewport`||t===`layoutViewport`)r=po(e,n,t);else if(t===`document`)r=uo(he(e));else if(G(t))r=mo(t,n);else{let n=ro(e);r={x:t.x-n.x,y:t.y-n.y,width:t.width,height:t.height}}return Dr(r)}function go(e,t){let n=t.get(e);if(n)return n;let r=Ne(e,[],!1).filter(e=>G(e)&&W(e)!==`body`),i=null,a=ke(e).position===`fixed`,o=a?je(e):e;for(;G(o)&&!Oe(o);){let e=ke(o),t=Te(o),n=i?i.position:a?`fixed`:``;!t&&(n===`fixed`||n===`absolute`&&e.position===`static`)?r=r.filter(e=>e!==o):i=e,o=je(o)}return t.set(e,r),r}function _o(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e,a=[...n===`clippingAncestors`?be(t)?[]:go(t,this._c):[].concat(n),r],o=ho(t,a[0],i),s=o.top,c=o.right,l=o.bottom,u=o.left;for(let e=1;e<a.length;e++){let n=ho(t,a[e],i);s=nr(n.top,s),c=tr(n.right,c),l=tr(n.bottom,l),u=nr(n.left,u)}return{width:c-u,height:l-s,x:u,y:s}}function vo(e){let{width:t,height:n}=$a(e);return{width:t,height:n}}function yo(e,t,n){let r=K(t),i=he(t),a=n===`fixed`,o=ao(e,!0,a,t),s={scrollLeft:0,scrollTop:0},c=ar(0);if((r||!a)&&((W(t)!==`body`||ve(i))&&(s=Ae(t)),r)){let e=ao(t,!0,a,t);c.x=e.x+t.clientLeft,c.y=e.y+t.clientTop}!r&&i&&(c.x=oo(i));let l=i&&!r&&!a?so(i,s):ar(0);return{x:o.left+s.scrollLeft-c.x-l.x,y:o.top+s.scrollTop-c.y-l.y,width:o.width,height:o.height}}function bo(e){return ke(e).position===`static`}function xo(e,t){if(!K(e)||ke(e).position===`fixed`)return null;if(t)return t(e);let n=e.offsetParent;return he(e)===n&&(n=n.ownerDocument.body),n}function So(e,t){let n=me(e);if(be(e))return n;if(!K(e)){let t=je(e);for(;t&&!Oe(t);){if(G(t)&&!bo(t))return t;t=je(t)}return n}let r=xo(e,t);for(;r&&ye(r)&&bo(r);)r=xo(r,t);return r&&Oe(r)&&bo(r)&&!Te(r)?n:r||Ee(e)||n}var Co=async function(e){let t=this.getOffsetParent||So,n=this.getDimensions,r=await n(e.floating);return{reference:yo(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function wo(e){return ke(e).direction===`rtl`}var To={convertOffsetParentRelativeRectToViewportRelativeRect:co,getDocumentElement:he,getClippingRect:_o,getOffsetParent:So,getElementRects:Co,getClientRects:lo,getDimensions:vo,getScale:to,isElement:G,isRTL:wo};function Eo(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function Do(e,t,n){let r=null,i,a=he(e);function o(){var e;clearTimeout(i),(e=r)==null||e.disconnect(),r=null}function s(n,c){n===void 0&&(n=!1),c===void 0&&(c=1),o();let l=e.getBoundingClientRect(),{left:u,top:d,width:f,height:p}=l;if(n||t(),!f||!p)return;let m=ir(d),h=ir(a.clientWidth-(u+f)),g=ir(a.clientHeight-(d+p)),_=ir(u),v={rootMargin:-m+`px `+-h+`px `+-g+`px `+-_+`px`,threshold:nr(0,tr(1,c))||1},y=!0;function b(t){let n=t[0].intersectionRatio;if(!Eo(l,e.getBoundingClientRect()))return s();if(n!==c){if(!y)return s();n?s(!1,n):i=setTimeout(()=>{s(!1,1e-7)},1e3)}y=!1}try{r=new IntersectionObserver(b,{...v,root:a.ownerDocument})}catch{r=new IntersectionObserver(b,v)}r.observe(e)}let c=me(e),l=()=>s(n);return c.addEventListener(`resize`,l),s(!0),()=>{c.removeEventListener(`resize`,l),o()}}function Oo(e,t,n,r){r===void 0&&(r={});let{ancestorScroll:i=!0,ancestorResize:a=!0,elementResize:o=typeof ResizeObserver==`function`,layoutShift:s=typeof IntersectionObserver==`function`,animationFrame:c=!1}=r,l=eo(e),u=i||a?[...l?Ne(l):[],...t?Ne(t):[]]:[];u.forEach(e=>{i&&e.addEventListener(`scroll`,n),a&&e.addEventListener(`resize`,n)});let d=l&&s?Do(l,n,a):null,f=-1,p=null;o&&(p=new ResizeObserver(e=>{let[r]=e;r&&r.target===l&&p&&t&&(p.unobserve(t),cancelAnimationFrame(f),f=requestAnimationFrame(()=>{var e;(e=p)==null||e.observe(t)})),n()}),l&&!c&&p.observe(l),t&&p.observe(t));let m,h=c?ao(e):null;c&&g();function g(){let t=ao(e);h&&!Eo(h,t)&&n(),h=t,m=requestAnimationFrame(g)}return n(),()=>{var e;u.forEach(e=>{i&&e.removeEventListener(`scroll`,n),a&&e.removeEventListener(`resize`,n)}),d?.(),(e=p)==null||e.disconnect(),p=null,c&&cancelAnimationFrame(m)}}var ko=Ya,Ao=Xa,jo=Ka,Mo=Qa,No=Za,Po=(e,t,n)=>{let r=new Map,i=n??{},a={...To,...i.platform,_c:r};return Ga(e,t,{...i,platform:a})},Fo=typeof document<`u`?l.useLayoutEffect:function(){};function Io(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(!Io(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;){let n=i[r];if(!(n===`_owner`&&e.$$typeof)&&!Io(e[n],t[n]))return!1}return!0}return e!==e&&t!==t}function Lo(e){return typeof window>`u`?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function Ro(e,t){let n=Lo(e);return Math.round(t*n)/n}function zo(e){let t=l.useRef(e);return Fo(()=>{t.current=e}),t}function Bo(e){e===void 0&&(e={});let{placement:t=`bottom`,strategy:n=`absolute`,middleware:r=[],platform:i,elements:{reference:a,floating:o}={},transform:s=!0,whileElementsMounted:c,open:u}=e,[d,f]=l.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[p,m]=l.useState(r);Io(p,r)||m(r);let[h,g]=l.useState(null),[_,v]=l.useState(null),y=l.useCallback(e=>{e!==C.current&&(C.current=e,g(e))},[]),b=l.useCallback(e=>{e!==w.current&&(w.current=e,v(e))},[]),x=a||h,S=o||_,C=l.useRef(null),w=l.useRef(null),T=l.useRef(d),E=c!=null,D=zo(c),O=zo(i),k=zo(u),A=l.useCallback(()=>{if(!C.current||!w.current)return;let e={placement:t,strategy:n,middleware:p};O.current&&(e.platform=O.current),Po(C.current,w.current,e).then(e=>{let t={...e,isPositioned:k.current!==!1};j.current&&!Io(T.current,t)&&(T.current=t,ua.flushSync(()=>{f(t)}))})},[p,t,n,O,k]);Fo(()=>{u===!1&&T.current.isPositioned&&(T.current.isPositioned=!1,f(e=>({...e,isPositioned:!1})))},[u]);let j=l.useRef(!1);Fo(()=>(j.current=!0,()=>{j.current=!1}),[]),Fo(()=>{if(x&&(C.current=x),S&&(w.current=S),x&&S){if(D.current)return D.current(x,S,A);A()}},[x,S,A,D,E]);let M=l.useMemo(()=>({reference:C,floating:w,setReference:y,setFloating:b}),[y,b]),N=l.useMemo(()=>({reference:x,floating:S}),[x,S]),P=l.useMemo(()=>{let e={position:n,left:0,top:0};if(!N.floating)return e;let t=Ro(N.floating,d.x),r=Ro(N.floating,d.y);return s?{...e,transform:`translate(`+t+`px, `+r+`px)`,...Lo(N.floating)>=1.5&&{willChange:`transform`}}:{position:n,left:t,top:r}},[n,s,N.floating,d.x,d.y]);return l.useMemo(()=>({...d,update:A,refs:M,elements:N,floatingStyles:P}),[d,A,M,N,P])}var Vo=(e,t)=>{let n=ko(e);return{name:n.name,fn:n.fn,options:[e,t]}},Ho=(e,t)=>{let n=Ao(e);return{name:n.name,fn:n.fn,options:[e,t]}},Uo=(e,t)=>({fn:No(e).fn,options:[e,t]}),Wo=(e,t)=>{let n=jo(e);return{name:n.name,fn:n.fn,options:[e,t]}},Go=(e,t)=>{let n=Mo(e);return{name:n.name,fn:n.fn,options:[e,t]}},Ko=t((e=>{var t=r();function n(e,t){return e===t&&(e!==0||1/e==1/t)||e!==e&&t!==t}var i=typeof Object.is==`function`?Object.is:n,a=t.useState,o=t.useEffect,s=t.useLayoutEffect,c=t.useDebugValue;function l(e,t){var n=t(),r=a({inst:{value:n,getSnapshot:t}}),i=r[0].inst,l=r[1];return s(function(){i.value=n,i.getSnapshot=t,u(i)&&l({inst:i})},[e,n,t]),o(function(){return u(i)&&l({inst:i}),e(function(){u(i)&&l({inst:i})})},[e]),c(n),n}function u(e){var t=e.getSnapshot;e=e.value;try{var n=t();return!i(e,n)}catch{return!0}}function d(e,t){return t()}var f=typeof window>`u`||window.document===void 0||window.document.createElement===void 0?d:l;e.useSyncExternalStore=t.useSyncExternalStore===void 0?f:t.useSyncExternalStore})),qo=t(((e,t)=>{t.exports=Ko()})),Jo=t((e=>{var t=r(),n=qo();function i(e,t){return e===t&&(e!==0||1/e==1/t)||e!==e&&t!==t}var a=typeof Object.is==`function`?Object.is:i,o=n.useSyncExternalStore,s=t.useRef,c=t.useEffect,l=t.useMemo,u=t.useDebugValue;e.useSyncExternalStoreWithSelector=function(e,t,n,r,i){var d=s(null);if(d.current===null){var f={hasValue:!1,value:null};d.current=f}else f=d.current;d=l(function(){function e(e){if(!o){if(o=!0,s=e,e=r(e),i!==void 0&&f.hasValue){var t=f.value;if(i(t,e))return c=t}return c=e}if(t=c,a(s,e))return t;var n=r(e);return i!==void 0&&i(t,n)?(s=e,t):(s=e,c=n)}var o=!1,s,c,l=n===void 0?null:n;return[function(){return e(t())},l===null?void 0:function(){return e(l())}]},[t,n,r,i]);var p=o(e,d[0],d[1]);return c(function(){f.hasValue=!0,f.value=p},[p]),u(p),p}})),Yo=t(((e,t)=>{t.exports=Jo()})),Xo=[],Zo=void 0;function Qo(){return Zo}function $o(e){Xo.push(e)}function es(e){let t=(t,n)=>{let r=Ze(ns).current,i;try{Zo=r;for(let e of Xo)e.before(r);i=e(t,n);for(let e of Xo)e.after(r);r.didInitialize=!0}finally{Zo=void 0}return i};return t.displayName=e.displayName||e.name,t}function ts(e){return l.forwardRef(es(e))}function ns(){return{didInitialize:!1}}var rs=qo(),is=Yo(),as=Mi(19)?cs:ls;function os(e,t,n,r,i){return as(e,t,n,r,i)}function ss(e,t,n,r,i){let a=l.useCallback(()=>t(e.getSnapshot(),n,r,i),[e,t,n,r,i]);return(0,rs.useSyncExternalStore)(e.subscribe,a,a)}$o({before(e){e.syncIndex=0,e.didInitialize||(e.syncTick=1,e.syncHooks=[],e.didChangeStore=!0,e.getSnapshot=()=>{let t=!1;for(let n=0;n<e.syncHooks.length;n+=1){let r=e.syncHooks[n],i=r.selector(r.store.state,r.a1,r.a2,r.a3);Object.is(r.value,i)||(t=!0,r.value=i)}return t&&(e.syncTick+=1),e.syncTick})},after(e){e.syncHooks.length>0&&(e.didChangeStore&&(e.didChangeStore=!1,e.subscribe=t=>{let n=new Set;for(let t of e.syncHooks)n.add(t.store);let r=[];for(let e of n)r.push(e.subscribe(t));return()=>{for(let e of r)e()}}),(0,rs.useSyncExternalStore)(e.subscribe,e.getSnapshot,e.getSnapshot))}});function cs(e,t,n,r,i){let a=Qo();if(!a)return ss(e,t,n,r,i);let o=a.syncIndex;a.syncIndex+=1;let s;return a.didInitialize?(s=a.syncHooks[o],(s.store!==e||s.selector!==t||!Object.is(s.a1,n)||!Object.is(s.a2,r)||!Object.is(s.a3,i))&&(s.store!==e&&(a.didChangeStore=!0),s.store=e,s.selector=t,s.a1=n,s.a2=r,s.a3=i,s.value=t(e.getSnapshot(),n,r,i))):(s={store:e,selector:t,a1:n,a2:r,a3:i,value:t(e.getSnapshot(),n,r,i)},a.syncHooks.push(s)),s.value}function ls(e,t,n,r,i){return(0,is.useSyncExternalStoreWithSelector)(e.subscribe,e.getSnapshot,e.getSnapshot,e=>t(e,n,r,i))}var us=class{static create(e){return new this(e)}constructor(e){this.state=e,this.listeners=new Set,this.updateTick=0}subscribe=e=>(this.listeners.add(e),()=>{this.listeners.delete(e)});getSnapshot=()=>this.state;setState(e){if(this.state===e)return;this.state=e,this.updateTick+=1;let t=this.updateTick;for(let n of this.listeners){if(t!==this.updateTick)return;n(e)}}update(e){for(let t in e)if(!Object.is(this.state[t],e[t])){this.setState({...this.state,...e});return}}set(e,t){Object.is(this.state[e],t)||this.setState({...this.state,[e]:t})}notifyAll(){let e={...this.state};this.setState(e)}use(e,t,n,r){return os(this,e,t,n,r)}},ds=class extends us{constructor(e,t={},n){super(e),this.context=t,this.selectors=n}useSyncedValue(e,t){l.useDebugValue(e);let n=this;U(()=>{n.state[e]!==t&&n.set(e,t)},[n,e,t])}useSyncedValueWithCleanup(e,t){let n=this;U(()=>(n.state[e]!==t&&n.set(e,t),()=>{n.set(e,void 0)}),[n,e,t])}useSyncedValues(e){let t=this;U(()=>{t.update(e)},[t,...Object.values(e)])}useControlledProp(e,t){l.useDebugValue(e);let n=this,r=t!==void 0;U(()=>{r&&!Object.is(n.state[e],t)&&n.setState({...n.state,[e]:t})},[n,e,t,r])}select(e,t,n,r){let i=this.selectors[e];return i(this.state,t,n,r)}useState(e,t,n,r){return l.useDebugValue(e),os(this,this.selectors[e],t,n,r)}useContextCallback(e,t){l.useDebugValue(e);let n=$(t??Qe);this.context[e]=n}useStateSetter(e){let t=l.useRef(void 0);return t.current===void 0&&(t.current=t=>{this.set(e,t)}),t.current}observe(e,t){let n;n=typeof e==`function`?e:this.selectors[e];let r=n(this.state);return t(r,r,this),this.subscribe(e=>{let i=n(e);if(!Object.is(r,i)){let e=r;r=i,t(i,e,this)}})}},fs={open:e=>e.open,transitionStatus:e=>e.transitionStatus,domReferenceElement:e=>e.domReferenceElement,referenceElement:e=>e.positionReference??e.referenceElement,floatingElement:e=>e.floatingElement,floatingId:e=>e.floatingId},ps=class extends ds{constructor(e){let{syncOnly:t,nested:n,onOpenChange:r,triggerElements:i,...a}=e;super({...a,positionReference:a.referenceElement,domReferenceElement:a.referenceElement},{onOpenChange:r,dataRef:{current:{}},events:ga(),nested:n,triggerElements:i},fs),this.syncOnly=t}syncOpenEvent=(e,t)=>{(!e||!this.state.open||t!=null&&wt(t))&&(this.context.dataRef.current.openEvent=e?t:void 0)};dispatchOpenChange=(e,t)=>{this.syncOpenEvent(e,t.event);let n={open:e,reason:t.reason,nativeEvent:t.event,nested:this.context.nested,triggerElement:t.trigger};this.context.events.emit(`openchange`,n)};setOpen=(e,t)=>{if(this.syncOnly){this.context.onOpenChange?.(e,t);return}this.dispatchOpenChange(e,t),this.context.onOpenChange?.(e,t)}};function ms(e){let{popupStore:t,treatPopupAsFloatingElement:n=!1,floatingRootContext:r,floatingId:i,nested:a,onOpenChange:o}=e,s=t.useState(`open`),c=t.useState(`activeTriggerElement`),u=t.useState(n?`popupElement`:`positionerElement`),d=t.context.triggerElements,f=o,p=l.useRef(null);r===void 0&&p.current===null&&(p.current=new ps({open:s,transitionStatus:void 0,referenceElement:c,floatingElement:u,triggerElements:d,onOpenChange:f,floatingId:i,syncOnly:!0,nested:a}));let m=r??p.current;return t.useSyncedValue(`floatingId`,i),U(()=>{let e={open:s,floatingId:i,referenceElement:c,floatingElement:u};G(c)&&(e.domReferenceElement=c),m.state.positionReference===m.state.referenceElement&&(e.positionReference=c),m.update(e)},[s,i,c,u,m]),m.context.onOpenChange=f,m.context.nested=a,m}function hs(e,t=!1,n=!1,r=!1){let[i,a]=l.useState(e&&t?`idle`:void 0),[o,s]=l.useState(e&&!r);return e&&!o&&(s(!0),a(`starting`)),!e&&o&&i!==`ending`&&!n&&a(`ending`),!e&&!o&&i===`ending`&&a(void 0),U(()=>{if(!e&&o&&i!==`ending`&&n){let e=st.request(()=>{a(`ending`)});return()=>{st.cancel(e)}}},[e,o,i,n]),U(()=>{if(!e||t)return;let n=st.request(()=>{a(void 0)});return()=>{st.cancel(n)}},[t,e]),U(()=>{if(!e||!t)return;e&&o&&i!==`idle`&&a(`starting`);let n=st.request(()=>{a(`idle`)});return()=>{st.cancel(n)}},[t,e,o,i]),{mounted:o,setMounted:s,transitionStatus:i}}var gs=null;function _s(e){if(!gs){let e=[];gs=e,queueMicrotask(()=>{gs=null,ua.flushSync(()=>{for(let t of e)t()})})}gs.push(e)}function vs(e,t=!1,n=!1){let r=ct();return $((i,a=null)=>{r.cancel();let o=Ta(e);if(o==null)return;let s=o,c=()=>{if(!n){ua.flushSync(i);return}_s(()=>{a?.aborted||i()})};if(typeof s.getAnimations!=`function`||globalThis.BASE_UI_ANIMATIONS_DISABLED){i();return}function l(){Promise.all(s.getAnimations().map(e=>e.finished)).then(()=>{a?.aborted||c()},()=>{if(!a?.aborted){if(s.getAnimations().some(e=>e.pending||e.playState!==`finished`)){l();return}c()}})}if(t){let e=Nt;if(!s.hasAttribute(e)){r.request(l);return}let t=new MutationObserver(()=>{s.hasAttribute(e)||(t.disconnect(),l())});t.observe(s,{attributes:!0,attributeFilter:[e]}),a?.addEventListener(`abort`,()=>t.disconnect(),{once:!0});return}r.request(l)})}function ys(e){let{enabled:t=!0,open:n,ref:r,batch:i=!1,onComplete:a}=e,o=$(a),s=vs(r,n,i);l.useEffect(()=>{if(!t)return;let e=new AbortController;return s(o,e.signal),()=>{e.abort()}},[t,n,o,s])}var bs={tabIndex:-1,[Dt]:``};function xs(e){return t=>t!==`touch`||e.current}function Ss(e,t=!1){let n=Oi(),r=ba()!=null,i=Ze(()=>e(n,r)).current;return ms({popupStore:i,treatPopupAsFloatingElement:t,floatingRootContext:i.state.floatingRootContext,floatingId:n,nested:r,onOpenChange:i.setOpen}),i}function Cs({handle:e,store:t}){return U(()=>e.attachStore(t),[e,t]),null}function ws(e){let t=e.context.triggerElements.size;e.select(`open`)&&e.state.triggerCount!==t&&e.set(`triggerCount`,t)}function Ts(e,t){let n=l.useRef(null);return $(r=>{let i=n.current;if(i!==null){if(i.element===r&&i.store===t&&i.id===e)return;n.current=null;let a=i.store;a.context.triggerElements.getById(i.id)===i.element&&(a.context.triggerElements.delete(i.id),ws(a))}r!==null&&e!==void 0&&(n.current={store:t,id:e,element:r},t.context.triggerElements.add(e,r),ws(t))})}function Es(e,t,n,r=!1){let i=e.preventUnmountingOnClose;t?i=!1:r&&(i=!0);let a=n?.id??null,o=e.activeTriggerId,s=e.activeTriggerElement;return(a||t)&&(o=a,s=n??null),{open:t,preventUnmountingOnClose:i,activeTriggerId:o,activeTriggerElement:s}}function Ds(e){let t=!1;return e.preventUnmountOnClose=()=>{t=!0},()=>t}function Os(e,t,n,r={}){let i=n.reason,a=i===hn,o=t&&i===`trigger-focus`,s=!t&&(i===`trigger-press`||i===`escape-key`),c=Ds(n);if(e.context.onOpenChange?.(t,n),n.isCanceled)return;r.onBeforeDispatch?.(),e.state.floatingRootContext.dispatchOpenChange(t,n);let l=()=>{let i=Es(e.state,t,n.trigger,c()),l={...r.extraState,...i};o?l.instantType=`focus`:s?l.instantType=`dismiss`:a&&(l.instantType=void 0),e.update(l)};a?ua.flushSync(l):l()}function ks(e,t,n,r){let i=n.useState(`isMountedByTrigger`,e),a=Ts(e,n),o=$(t=>{let i=n.select(`open`),a=n.select(`activeTriggerId`);if(a===e){let e={activeTriggerElement:t,...i?r:null};n.update(e);return}if(a==null&&i){let i={activeTriggerId:e??null,activeTriggerElement:t,...r};n.update(i)}}),s=$(e=>{a(e),e&&o(e)});return U(()=>(s(t.current),()=>s(null)),[s,t,n,e]),U(()=>{if(i){let e={activeTriggerElement:t.current,...r};n.update(e)}},[i,n,t,...Object.values(r)]),{registerTrigger:s,isMountedByThisTrigger:i}}function As(e,t={}){let{closeOnActiveTriggerUnmount:n=!1}=t,r=l.useRef(null),i=e.useState(`open`);U(()=>{if(!i){r.current=null,e.state.triggerCount!==0&&e.set(`triggerCount`,0);return}let t=e.context.triggerElements.size,a={};e.state.triggerCount!==t&&(a.triggerCount=t);let o=e.select(`activeTriggerId`),s=null;if(o){let t=e.context.triggerElements.getById(o);if(t)r.current=o,t!==e.state.activeTriggerElement&&(a.activeTriggerElement=t);else{for(let[t,n]of e.context.triggerElements.entries())if(n===e.state.activeTriggerElement){a.activeTriggerId=t,a.activeTriggerElement=n,r.current=t;break}a.activeTriggerId===void 0&&(r.current===o?s=o:r.current=null)}}else r.current=null;if(!s&&!o&&t===1){let t=e.context.triggerElements.entries().next();if(!t.done){let[e,n]=t.value;a.activeTriggerId=e,a.activeTriggerElement=n,r.current=e}}(a.triggerCount!==void 0||a.activeTriggerId!==void 0||a.activeTriggerElement!==void 0)&&e.update(a),s&&n&&queueMicrotask(()=>{if(e.select(`open`)&&e.select(`activeTriggerId`)===s&&!e.context.triggerElements.getById(s)){let t=Z(pn);e.setOpen(!1,t),t.isCanceled||e.update({activeTriggerId:null,activeTriggerElement:null})}})},[i,e,e.useState(`triggerCount`),e.useState(`activeTriggerId`),e.useState(`activeTriggerElement`),n])}function js(e,t,n,r){let{mounted:i,setMounted:a,transitionStatus:o}=hs(e,!1,!1,r),s=t.useState(`preventUnmountingOnClose`),c=!e&&s;t.useSyncedValues({mounted:i,transitionStatus:o,preventUnmountingOnClose:c});let l=$(()=>{a(!1),t.update({activeTriggerId:null,activeTriggerElement:null,mounted:!1,preventUnmountingOnClose:!1}),n?.(),t.context.onOpenChangeComplete?.(!1)});return ys({enabled:i&&!e&&!c,open:e,ref:t.context.popupRef,onComplete(){e||l()}}),{forceUnmount:l,transitionStatus:o}}function Ms(e,t){e.useSyncedValues(t),U(()=>()=>{e.update({activeTriggerProps:et,inactiveTriggerProps:et,popupProps:et})},[e])}function Ns(e,t){U(()=>{!t&&e.state.openMethod!==null&&e.set(`openMethod`,null)},[t,e]),U(()=>()=>{e.state.openMethod!==null&&e.set(`openMethod`,null)},[e])}var Ps=class{constructor(){this.idMap=new Map}add(e,t){this.idMap.set(e,t)}delete(e){this.idMap.delete(e)}hasElement(e){for(let t of this.idMap.values())if(t===e)return!0;return!1}hasMatchingElement(e){for(let t of this.idMap.values())if(e(t))return!0;return!1}getById(e){return this.idMap.get(e)}entries(){return this.idMap.entries()}elements(){return this.idMap.values()}get size(){return this.idMap.size}};function Fs(e,t,n=!1){return{open:!1,openProp:void 0,mounted:!1,transitionStatus:void 0,floatingRootContext:new ps({open:!1,transitionStatus:void 0,floatingElement:null,referenceElement:null,triggerElements:e,floatingId:t,syncOnly:!0,nested:n,onOpenChange:void 0}),floatingId:t,triggerCount:0,preventUnmountingOnClose:!1,payload:void 0,activeTriggerId:null,activeTriggerElement:null,triggerIdProp:void 0,popupElement:null,positionerElement:null,activeTriggerProps:et,inactiveTriggerProps:et,popupProps:et}}var Is=e=>e.triggerIdProp??e.activeTriggerId,Ls=e=>e.openProp??e.open,Rs=e=>(e.popupElement?.id??e.floatingId)||void 0;function zs(e,t){return t!==void 0&&Ls(e)&&Is(e)===t}function Bs(e,t){return zs(e,t)?!0:t!==void 0&&Ls(e)&&Is(e)==null&&e.triggerCount===1}var Vs={open:Ls,mounted:e=>e.mounted,transitionStatus:e=>e.transitionStatus,floatingRootContext:e=>e.floatingRootContext,triggerCount:e=>e.triggerCount,preventUnmountingOnClose:e=>e.preventUnmountingOnClose,payload:e=>e.payload,activeTriggerId:Is,activeTriggerElement:e=>e.mounted?e.activeTriggerElement:null,popupId:Rs,isTriggerActive:(e,t)=>t!==void 0&&Is(e)===t,isOpenedByTrigger:(e,t)=>zs(e,t),isMountedByTrigger:(e,t)=>t!==void 0&&Is(e)===t&&e.mounted,triggerProps:(e,t)=>t?e.activeTriggerProps:e.inactiveTriggerProps,triggerPopupId:(e,t)=>Bs(e,t)?Rs(e):void 0,popupProps:e=>e.popupProps,popupElement:e=>e.popupElement,positionerElement:e=>e.positionerElement};function Hs(e){let t=l.useCallback(t=>e===void 0?Qe:e.subscribeStore(t),[e]),n=l.useCallback(()=>e===void 0?void 0:e.store,[e]);return(0,rs.useSyncExternalStore)(t,n,()=>e?.serverStore)}function Us(e){let{open:t=!1,onOpenChange:n,elements:r={}}=e,i=Oi(),a=ba()!=null,o=Ze(()=>new ps({open:t,transitionStatus:void 0,onOpenChange:n,referenceElement:r.reference??null,floatingElement:r.floating??null,triggerElements:new Ps,floatingId:i,syncOnly:!1,nested:a})).current;return U(()=>{let e={open:t,floatingId:i};r.reference!==void 0&&(e.referenceElement=r.reference,e.domReferenceElement=G(r.reference)?r.reference:null),r.floating!==void 0&&(e.floatingElement=r.floating),o.update(e)},[t,i,r.reference,r.floating,o]),o.context.onOpenChange=n,o.context.nested=a,o}function Ws(e){return Gs(e,e.rootContext)}function Gs(e,t){let{nodeId:n,externalTree:r}=e,i=t.useState(`referenceElement`),a=t.useState(`floatingElement`),o=t.useState(`domReferenceElement`),s=t.useState(`open`),c=t.useState(`floatingId`),[u,d]=l.useState(null),[f,p]=l.useState(void 0),[m,h]=l.useState(void 0),g=l.useRef(null),_=xa(r),v=l.useMemo(()=>({reference:i,floating:a,domReference:o}),[i,a,o]),y=Bo({...e,elements:{...v,...u&&{reference:u}}}),b=G(f)?f:null,x=m===void 0?t.state.floatingElement:m;t.useSyncedValue(`referenceElement`,f??null),t.useSyncedValue(`domReferenceElement`,f===void 0?o:b),t.useSyncedValue(`floatingElement`,x);let S=l.useCallback(e=>{let t=G(e)?{getBoundingClientRect:()=>e.getBoundingClientRect(),getClientRects:()=>e.getClientRects(),contextElement:e}:e;d(t),y.refs.setReference(t)},[y.refs]),C=l.useCallback(e=>{(G(e)||e===null)&&(g.current=e,p(e)),(G(y.refs.reference.current)||y.refs.reference.current===null||e!==null&&!G(e))&&y.refs.setReference(e)},[y.refs,p]),w=l.useCallback(e=>{h(e),y.refs.setFloating(e)},[y.refs]),T=l.useMemo(()=>({...y.refs,setReference:C,setFloating:w,setPositionReference:S,domReference:g}),[y.refs,C,w,S]),E=l.useMemo(()=>({...y.elements,domReference:o}),[y.elements,o]),D=l.useMemo(()=>({...y,dataRef:t.context.dataRef,open:s,onOpenChange:t.setOpen,events:t.context.events,floatingId:c,refs:T,elements:E,nodeId:n,rootStore:t}),[y,T,E,n,t,s,c]);return U(()=>{o&&(g.current=o)},[o]),U(()=>{t.context.dataRef.current.floatingContext=D;let e=_?.nodesRef.current.find(e=>e.id===n);e&&(e.context=D)}),l.useMemo(()=>({...y,context:D,refs:T,elements:E,rootStore:t}),[y,T,E,D,t])}var Ks=We&&Ke;function qs(e,t={}){let{enabled:n=!0,delay:r}=t,i=`rootStore`in e?e.rootStore:e,{events:a,dataRef:o}=i.context,s=l.useRef(!1),c=l.useRef(null),u=l.useRef(!0),d=it();l.useEffect(()=>{let e=i.select(`domReferenceElement`);if(!n)return;let t=me(e);function r(){let e=i.select(`domReferenceElement`);!i.select(`open`)&&K(e)&&e===Tt(J(e))&&(s.current=!0,c.current=e)}function a(){u.current=!0}function o(){u.current=!1}return Ln(q(t,`blur`,r),Ks&&q(t,`keydown`,a,!0),Ks&&q(t,`pointerdown`,o,!0))},[i,n]),l.useEffect(()=>{if(!n)return;function e(e){if(e.reason===`trigger-press`||e.reason===`escape-key`){let e=i.select(`domReferenceElement`);G(e)&&(c.current=e,s.current=!0)}}return a.on(`openchange`,e),()=>{a.off(`openchange`,e)}},[a,n,i]);let f=l.useMemo(()=>{function e(){s.current=!1,c.current=null}return{onMouseLeave(){e()},onFocus(t){let n=t.currentTarget;if(s.current){if(c.current===n)return;e()}let a=Et(t.nativeEvent);if(G(a)){if(Ks&&!t.relatedTarget){if(!u.current&&!nn(a))return}else if(!on(a))return}let o=$t(t.relatedTarget,i.context.triggerElements),{nativeEvent:l,currentTarget:f}=t,p=typeof r==`function`?r():r;if(i.select(`open`)&&o||p===0||p===void 0){i.setOpen(!0,Z(gn,l,f));return}d.start(p,()=>{s.current||i.setOpen(!0,Z(gn,l,f))})},onBlur(t){e();let n=t.relatedTarget,r=t.nativeEvent,a=G(n)&&n.hasAttribute(ui(`focus-guard`))&&n.getAttribute(`data-type`)===`outside`;d.start(0,()=>{let e=i.select(`domReferenceElement`),t=Tt(J(e));(n||t!==e)&&(X(o.current.floatingContext?.refs.floating.current,t)||X(e,t)||a||$t(n??t,i.context.triggerElements)||i.setOpen(!1,Z(gn,r)))})}}},[o,r,i,d]);return l.useMemo(()=>n?{reference:f,trigger:f}:{},[n,f])}var Js=class e{constructor(){this.pointerType=void 0,this.interactedInside=!1,this.handler=void 0,this.blockMouseMove=!0,this.performedPointerEventsMutation=!1,this.pointerEventsScopeElement=null,this.pointerEventsReferenceElement=null,this.pointerEventsFloatingElement=null,this.restTimeoutPending=!1,this.openChangeTimeout=new rt,this.restTimeout=new rt,this.handleCloseOptions=void 0}static create(){return new e}dispose=()=>{this.openChangeTimeout.clear(),this.restTimeout.clear()};disposeEffect=()=>this.dispose},Ys=new WeakMap;function Xs(e){if(!e.performedPointerEventsMutation)return;let t=e.pointerEventsScopeElement;t&&Ys.get(t)===e&&(e.pointerEventsScopeElement?.style.removeProperty(`pointer-events`),e.pointerEventsReferenceElement?.style.removeProperty(`pointer-events`),e.pointerEventsFloatingElement?.style.removeProperty(`pointer-events`),Ys.delete(t)),e.performedPointerEventsMutation=!1,e.pointerEventsScopeElement=null,e.pointerEventsReferenceElement=null,e.pointerEventsFloatingElement=null}function Zs(e,t){let{scopeElement:n,referenceElement:r,floatingElement:i}=t,a=Ys.get(n);a&&a!==e&&Xs(a),Xs(e),e.performedPointerEventsMutation=!0,e.pointerEventsScopeElement=n,e.pointerEventsReferenceElement=r,e.pointerEventsFloatingElement=i,Ys.set(n,e),n.style.pointerEvents=`none`,r.style.pointerEvents=`auto`,i.style.pointerEvents=`auto`}function Qs(e){let t=e.context.dataRef.current,n=Ze(()=>t.hoverInteractionState??Js.create()).current;return t.hoverInteractionState||=n,tt(t.hoverInteractionState.disposeEffect),t.hoverInteractionState}function $s(e,t={}){let{enabled:n=!0,closeDelay:r=0,nodeId:i}=t,a=`rootStore`in e?e.rootStore:e,o=a.useState(`open`),s=a.useState(`floatingElement`),c=a.useState(`domReferenceElement`),{dataRef:u}=a.context,d=xa(),f=ba(),p=Qs(a),m=it(),h=$(()=>dn(u.current.openEvent?.type,p.interactedInside)),g=$(()=>fn(u.current.openEvent?.type)),_=$(()=>{Xs(p)});U(()=>{o||(p.pointerType=void 0,p.restTimeoutPending=!1,p.interactedInside=!1,_())},[o,p,_]),l.useEffect(()=>_,[_]),U(()=>{if(n&&o&&p.handleCloseOptions?.blockPointerEvents&&g()&&G(c)&&s){let e=c,t=s,n=J(s),r=d?.nodesRef.current.find(e=>e.id===f)?.context?.elements.floating;r&&(r.style.pointerEvents=``);let i=p.pointerEventsScopeElement===t?null:p.pointerEventsScopeElement,a=r===t?null:r,o=p.handleCloseOptions?.getScope?.()??i??a??e.closest(`[data-rootownerid]`)??n.body;return Zs(p,{scopeElement:o,referenceElement:e,floatingElement:t}),()=>{_()}}},[n,o,c,s,p,g,d,f,_]),l.useEffect(()=>{if(!n)return;function e(){return!!(d&&f&&ci(d.nodesRef.current,f).length>0)}function t(e){let t=ln(r,`close`,p.pointerType),n=()=>{a.setOpen(!1,Z(hn,e)),d?.events.emit(`floating.closed`,e)};t?p.openChangeTimeout.start(t,n):(p.openChangeTimeout.clear(),n())}function o(e){let t=Et(e);if(!rn(t)){p.interactedInside=!1;return}p.interactedInside=t?.closest(`[aria-haspopup]`)!=null}function c(){p.openChangeTimeout.clear(),m.clear(),d?.events.off(`floating.closed`,v),_()}function l(n){if(e()&&d){d.events.on(`floating.closed`,v);return}if($t(n.relatedTarget,a.context.triggerElements))return;let r=u.current.floatingContext?.nodeId??i,o=n.relatedTarget;if(!(d&&r&&G(o)&&ci(d.nodesRef.current,r,!1).some(e=>X(e.context?.elements.floating,o)))){if(p.handler){p.handler(n);return}_(),g()&&!h()&&t(n)}}function v(t){d&&f&&!e()&&m.start(0,()=>{d.events.off(`floating.closed`,v),a.setOpen(!1,Z(hn,t)),d.events.emit(`floating.closed`,t)})}let y=s;return Ln(y&&q(y,`mouseenter`,c),y&&q(y,`mouseleave`,l),y&&q(y,`pointerdown`,o,!0),()=>{d?.events.off(`floating.closed`,v)})},[n,s,a,u,r,i,g,h,_,p,d,f,m])}var ec={current:null};function tc(e,t={}){let{enabled:n=!0,delay:r=0,handleClose:i=null,mouseOnly:a=!1,restMs:o=0,move:s=!0,triggerElementRef:c=ec,externalTree:u,isActiveTrigger:d=!0,getHandleCloseContext:f,isClosing:p,shouldOpen:m,guardStaleOpen:h=!1}=t,g=`rootStore`in e?e.rootStore:e,{dataRef:_,events:v}=g.context,y=xa(u),b=Qs(g),x=l.useRef(!1),S=Wn(i),C=Wn(r),w=Wn(o),T=Wn(n),E=Wn(m),D=Wn(p),O=$(()=>dn(_.current.openEvent?.type,b.interactedInside)),k=$(()=>E.current?.()!==!1),A=$((e,t,n)=>{let r=g.context.triggerElements;if(r.hasElement(t))return!e||!X(e,t);if(!G(n))return!1;let i=n;return r.hasMatchingElement(e=>X(e,i))&&(!e||!X(e,i))}),j=$(()=>{b.handler&&=(J(g.select(`domReferenceElement`)).removeEventListener(`mousemove`,b.handler),void 0)}),M=$(()=>{Xs(b)});return d&&(b.handleCloseOptions=i?.__options),l.useEffect(()=>j,[j]),l.useEffect(()=>{if(!n)return;function e(e){e.open?x.current=!1:(x.current=e.reason===hn,j(),b.openChangeTimeout.clear(),b.restTimeout.clear(),b.blockMouseMove=!0,b.restTimeoutPending=!1)}return v.on(`openchange`,e),()=>{v.off(`openchange`,e)}},[n,v,b,j]),l.useEffect(()=>{if(!n)return;function e(e,t=!0){let n=ln(C.current,`close`,b.pointerType);n?b.openChangeTimeout.start(n,()=>{g.setOpen(!1,Z(hn,e)),y?.events.emit(`floating.closed`,e)}):t&&(b.openChangeTimeout.clear(),g.setOpen(!1,Z(hn,e)),y?.events.emit(`floating.closed`,e))}let t=c.current??(d?g.select(`domReferenceElement`):null);if(!G(t))return;function r(e){if(b.openChangeTimeout.clear(),b.blockMouseMove=!1,a&&!Ct(b.pointerType))return;let t=un(w.current),n=ln(C.current,`open`,b.pointerType),r=Et(e),i=e.currentTarget??null,o=g.select(`domReferenceElement`),s=i;if(G(r)&&!g.context.triggerElements.hasElement(r)){for(let e of g.context.triggerElements.elements())if(X(e,r)){s=e;break}}G(i)&&G(o)&&!g.context.triggerElements.hasElement(i)&&X(i,o)&&(s=o);let c=s!=null&&A(o,s,r),l=g.select(`open`),u=D.current?.()??g.select(`transitionStatus`)===`ending`,d=!l&&u&&x.current,f=!c&&G(s)&&G(o)&&X(o,s)&&d,p=t>0&&!n,m=c&&(l||d)||f,h=!l||c;if(m){k()&&g.setOpen(!0,Z(hn,e,s));return}p||(n?b.openChangeTimeout.start(n,()=>{h&&k()&&g.setOpen(!0,Z(hn,e,s))}):h&&k()&&g.setOpen(!0,Z(hn,e,s)))}function i(t){if(O()){M();return}j();let n=J(g.select(`domReferenceElement`));b.restTimeout.clear(),b.restTimeoutPending=!1;let r=_.current.floatingContext??f?.();if(!$t(t.relatedTarget,g.context.triggerElements)){if(S.current&&r){g.select(`open`)||b.openChangeTimeout.clear();let i=c.current;b.handler=S.current({...r,tree:y,x:t.clientX,y:t.clientY,onClose(){M(),j(),T.current&&!O()&&i===g.select(`domReferenceElement`)&&e(t,!0)}}),n.addEventListener(`mousemove`,b.handler),b.handler(t);return}(b.pointerType!==`touch`||!X(g.select(`floatingElement`),t.relatedTarget))&&e(t)}}function o(e){X(t,e.relatedTarget)||(b.openChangeTimeout.clear(),b.restTimeout.clear(),b.restTimeoutPending=!1)}let l=h?q(t,`mouseout`,o):void 0;return s?Ln(q(t,`mousemove`,r,{once:!0}),q(t,`mouseenter`,r),q(t,`mouseleave`,i),l):Ln(q(t,`mouseenter`,r),q(t,`mouseleave`,i),l)},[j,M,_,C,g,n,S,b,d,A,O,a,s,w,c,y,T,f,D,k,h]),l.useMemo(()=>{if(!n)return;function e(e){b.pointerType=e.pointerType}return{onPointerDown:e,onPointerEnter:e,onMouseMove(e){let{nativeEvent:t}=e,n=e.currentTarget,r=g.select(`domReferenceElement`),i=g.select(`open`),o=A(r,n,e.target);if(a&&!Ct(b.pointerType))return;if(i&&o&&b.handleCloseOptions?.blockPointerEvents){let e=g.select(`floatingElement`);if(e){let t=b.handleCloseOptions?.getScope?.()??n.ownerDocument.body;Zs(b,{scopeElement:t,referenceElement:n,floatingElement:e})}}let s=un(w.current);if(i&&!o||s===0||!o&&b.restTimeoutPending&&e.movementX**2+e.movementY**2<2)return;b.restTimeout.clear();function c(){if(b.restTimeoutPending=!1,O())return;let e=g.select(`open`);!b.blockMouseMove&&(!e||o)&&k()&&g.setOpen(!0,Z(hn,t,n))}b.pointerType===`touch`?ua.flushSync(()=>{c()}):o&&i?c():(b.restTimeoutPending=!0,b.restTimeout.start(s,c))}}},[n,b,O,A,a,g,w,k])}var nc=`Escape`;function rc(e){return Ke&&e.movementX===0&&e.movementY===0}function ic(e,t,n){switch(e){case`vertical`:return t;case`horizontal`:return n;default:return t||n}}function ac(e,t){return ic(t,e===`ArrowUp`||e===`ArrowDown`,e===`ArrowLeft`||e===`ArrowRight`)}function oc(e,t,n){return ic(t,e===`ArrowDown`,n?e===`ArrowLeft`:e===`ArrowRight`)||e===`Enter`||e===` `||e===``}function sc(e,t,n){return ic(t,n?e===kt:e===At,e===Mt)}function cc(e,t,n,r){return t===`both`||t===`horizontal`&&r?e===nc:ic(t,n?e===At:e===kt,e===jt)}function lc(e,t){let{listRef:n,activeIndex:r,onNavigate:i=()=>{},enabled:a=!0,selectedIndex:o=null,allowEscape:s=!1,loopFocus:c=!1,nested:u=!1,rtl:d=!1,virtual:f=!1,focusItemOnOpen:p=`auto`,focusItemOnHover:m=!0,openOnArrowKeyDown:h=!0,disabledIndices:g=void 0,orientation:_=`vertical`,parentOrientation:v,id:y,resetOnPointerLeave:b=!0,externalTree:x,grid:S}=t,C=S!=null,w=`rootStore`in e?e.rootStore:e,T=w.useState(`open`),E=w.useState(`floatingElement`),D=w.useState(`domReferenceElement`),O=w.context.dataRef,k=sn(E),A=an(D),j=Wn(k),M=ba(),N=xa(x),P=l.useRef(p),F=l.useRef(o??-1),I=l.useRef(null),L=l.useRef(!0),R=$(e=>{i(F.current===-1?null:F.current,e)}),z=l.useRef(!!E),ee=l.useRef(T),B=l.useRef(!1),te=l.useRef(!1),ne=l.useRef(null),re=Wn(g),V=Wn(T),H=Wn(o),ie=Wn(b),ae=ct(),oe=ct(),se=$(()=>{function e(e){f?N?.events.emit(`virtualfocus`,e):ne.current=fi(e,{sync:B.current,preventScroll:!0})}let t=n.current[F.current],r=te.current;t&&e(t),(B.current?e=>e():e=>ae.request(e))(()=>{let i=n.current[F.current]||t;i&&(t||e(i),pe&&(r||!L.current)&&i.scrollIntoView?.({block:`nearest`,inline:`nearest`}))})});U(()=>{O.current.orientation=_},[O,_]),U(()=>{a&&(T&&E?(F.current=o??-1,P.current&&o!=null&&(te.current=!0,R())):z.current&&(F.current=-1,R()))},[a,T,E,o,R]),U(()=>{if(a){if(!T){B.current=!1;return}if(E){if(r==null){if(B.current=!1,H.current!=null)return;if(z.current&&(F.current=-1,se()),(!ee.current||!z.current)&&P.current&&(I.current!=null||P.current===!0&&I.current==null)){let e=0,t=()=>{n.current[0]==null?(e<2&&(e?e=>oe.request(e):queueMicrotask)(t),e+=1):(F.current=I.current==null||oc(I.current,_,d)||u?Ar(n):jr(n),I.current=null,R())};t()}}else kr(n.current,r)||(F.current=r,se(),te.current=!1)}}},[a,T,E,r,H,u,n,_,d,R,se,oe]),U(()=>{if(!a||E||!N||f||!z.current)return;let e=N.nodesRef.current,t=e.find(e=>e.id===M)?.context?.elements.floating,n=Tt(J(D??t??null)),r=e.some(e=>e.context&&X(e.context.elements.floating,n));t&&!r&&L.current&&t.focus({preventScroll:!0})},[a,E,D,N,M,f]),U(()=>{ee.current=T,z.current=!!E}),U(()=>{T||(I.current=null,P.current=p)},[T,p]);let ce=r!=null,le=$(e=>{if(!V.current)return;let t=n.current.indexOf(e.currentTarget);t!==-1&&(F.current!==t||r!==t)&&(F.current=t,R(e))}),ue=$(()=>v??N?.nodesRef.current.find(e=>e.id===M)?.context?.dataRef?.current.orientation),de=$(()=>Ar(n,re.current)),fe=$(e=>{if(L.current=!1,B.current=!0,e.which===229||!V.current&&e.currentTarget===j.current)return;if(u&&cc(e.key,_,d,C)){ac(e.key,ue())||yt(e),w.setOpen(!1,Z(Tn,e.nativeEvent)),K(D)&&(f?N?.events.emit(`virtualfocus`,D):D.focus());return}let t=F.current,r=Ar(n,g),i=jr(n,g);if(A||(e.key===`Home`&&(yt(e),F.current=r,R(e)),e.key===`End`&&(yt(e),F.current=i,R(e))),S!=null){let t=S(e,F.current,n,_,c,d,g,r,i);if(t!=null&&(F.current=t,R(e)),_===`both`)return}if(ac(e.key,_)){if(yt(e),T&&!f&&Tt(e.currentTarget.ownerDocument)===e.currentTarget){F.current=oc(e.key,_,d)?r:i,R(e);return}oc(e.key,_,d)?c?t>=i?s&&t!==n.current.length?F.current=-1:(B.current=!1,F.current=r):F.current=Mr(n.current,{startingIndex:t,disabledIndices:g}):F.current=Math.min(i,Mr(n.current,{startingIndex:t,disabledIndices:g})):c?t<=r?s&&t!==-1?F.current=n.current.length:(B.current=!1,F.current=i):F.current=Mr(n.current,{startingIndex:t,decrement:!0,disabledIndices:g}):F.current=Math.max(r,Mr(n.current,{startingIndex:t,decrement:!0,disabledIndices:g})),kr(n.current,F.current)&&(F.current=-1),R(e)}}),pe=l.useMemo(()=>({onFocus(e){B.current=!0,le(e)},onClick:({currentTarget:e})=>e.focus({preventScroll:!0}),onMouseMove(e){rc(e)||(B.current=!0,te.current=!1,m&&le(e))},onPointerLeave(e){if(!V.current||!L.current||e.pointerType===`touch`)return;B.current=!0;let t=e.relatedTarget;if(m&&!n.current.includes(t)&&ie.current&&(ne.current?.(),ne.current=null,F.current=-1,R(e),!f)){let e=j.current,t=Tt(J(e));e&&X(e,t)&&e.focus({preventScroll:!0})}}}),[le,V,j,m,n,R,ie,f]),W=l.useMemo(()=>f&&T&&ce&&{"aria-activedescendant":`${y}-${r}`},[f,T,ce,y,r]),me=l.useMemo(()=>({...A?{}:W,onKeyDown(e){if(e.key===`Tab`&&e.shiftKey&&T&&!f){let t=Et(e.nativeEvent);if(t&&!X(j.current,t))return;yt(e),w.setOpen(!1,Z(Cn,e.nativeEvent)),K(D)&&D.focus();return}fe(e)},onPointerMove(e){rc(e)||(L.current=!0)}}),[W,fe,j,A,w,T,f,D]),he=l.useMemo(()=>{function e(e){w.setOpen(!0,Z(Tn,e.nativeEvent,e.currentTarget))}function t(e){p===`auto`&&xt(e.nativeEvent)&&(P.current=!f)}function n(e){P.current=p,p===`auto`&&St(e.nativeEvent)&&(P.current=!0)}return{onKeyDown(t){let n=w.select(`open`);L.current=!1;let r=t.key.startsWith(`Arrow`),i=sc(t.key,ue(),d),a=ac(t.key,_),o=(u?i:a)||t.key===`Enter`||t.key.trim()===``;if(f&&n)return fe(t);if(n||h||!r){if(o){let e=ac(t.key,ue());I.current=u&&e?null:t.key}if(u){i&&(yt(t),n?(F.current=de(),R(t)):e(t));return}a&&(H.current!=null&&(F.current=H.current),yt(t),!n&&h?e(t):fe(t),n&&R(t))}},onFocus(e){w.select(`open`)&&!f&&(F.current=-1,R(e))},onPointerDown:n,onPointerEnter:n,onMouseDown:t,onClick:t}},[fe,p,de,u,R,w,h,_,ue,d,H,f]),ge=l.useMemo(()=>({...W,...he}),[W,he]);return l.useMemo(()=>a?{reference:ge,floating:me,item:pe,trigger:he}:{},[a,ge,me,he,pe])}function uc(e,t){let{listRef:n,elementsRef:r,activeIndex:i,onMatch:a,disabledIndices:o,onTyping:s,enabled:c=!0,resetMs:u=750,selectedIndex:d=null}=t,f=`rootStore`in e?e.rootStore:e,p=f.useState(`open`),m=it(),h=l.useRef(``),g=l.useRef(d??i??-1),_=l.useRef(null),v=$(e=>{function t(e){return r?.current[e]}function c(e){let n=t(e);return n&&!Ir(n)||n?.matches(`:disabled`)?!1:o==null||!Pr($e,e,o)}function l(e,t,n=0){if(e.length===0)return-1;let r=(n%e.length+e.length)%e.length,i=t.toLowerCase();for(let t=0;t<e.length;t+=1){let n=(r+t)%e.length;if(e[n]?.toLowerCase().startsWith(i)&&c(n))return n}return-1}let f=n.current;if(h.current.length>0&&e.key===` `&&(yt(e),s?.(!0)),h.current.length>0&&h.current[0]!==` `&&l(f,h.current)===-1&&e.key!==` `&&s?.(!1),f==null||e.key.length!==1||e.ctrlKey||e.metaKey||e.altKey)return;p&&e.key!==` `&&(yt(e),s?.(!0));let v=h.current===``;v&&(g.current=d??i??-1),f.every((e,t)=>e&&c(t)?e[0]?.toLowerCase()!==e[1]?.toLowerCase():!0)&&h.current===e.key&&(h.current=``,g.current=_.current),h.current+=e.key,m.start(u,()=>{h.current=``,g.current=_.current,s?.(!1)});let y=((v?d??i??-1:g.current)??0)+1,b=l(f,h.current,y);b===-1?e.key!==` `&&(h.current=``,s?.(!1)):(a?.(b),_.current=b)}),y=$(e=>{let t=e.relatedTarget,n=f.select(`domReferenceElement`),r=f.select(`floatingElement`);X(n,t)||X(r,t)||(m.clear(),h.current=``,g.current=_.current,s?.(!1))});U(()=>{(p||d===null)&&(m.clear(),_.current=null,h.current!==``&&(h.current=``))},[p,d,m]);let b=l.useMemo(()=>({onKeyDown:v,onBlur:y}),[v,y]);return l.useMemo(()=>c?{reference:b,floating:b}:{},[c,b])}var dc=.1,fc=dc*dc,pc=.5;function mc(e,t,n,r,i,a){return r>=t!=a>=t&&e<=(i-n)*(t-r)/(a-r)+n}function hc(e,t,n,r,i,a,o,s,c,l){let u=!1;return mc(e,t,n,r,i,a)&&(u=!u),mc(e,t,i,a,o,s)&&(u=!u),mc(e,t,o,s,c,l)&&(u=!u),mc(e,t,c,l,n,r)&&(u=!u),u}function gc(e,t,n){return e>=n.x&&e<=n.x+n.width&&t>=n.y&&t<=n.y+n.height}function _c(e,t,n,r,i,a){return e>=Math.min(n,i)&&e<=Math.max(n,i)&&t>=Math.min(r,a)&&t<=Math.max(r,a)}function vc(e={}){let{blockPointerEvents:t=!1}=e,n=new rt,r=({x:e,y:t,placement:r,elements:i,onClose:a,nodeId:o,tree:s})=>{let c=r?.split(`-`)[0],l=!1,u=null,d=null,f=typeof performance<`u`?performance.now():0;function p(e,t){let n=performance.now(),r=n-f;if(u===null||d===null||r===0)return u=e,d=t,f=n,!1;let i=e-u,a=t-d,o=i*i+a*a,s=r*r*fc;return u=e,d=t,f=n,o<s}function m(){n.clear(),a()}return function(r){n.clear();let a=i.domReference,u=i.floating;if(!a||!u||c==null||e==null||t==null)return;let{clientX:d,clientY:f}=r,h=Et(r),g=r.type===`mouseleave`,_=X(u,h),v=X(a,h);if(_&&(l=!0,!g))return;if(v&&(l=!1,!g)){l=!0;return}if(g&&G(r.relatedTarget)&&X(u,r.relatedTarget))return;function y(){return!!(s&&ci(s.nodesRef.current,o).length>0)}function b(){y()||m()}if(y())return;let x=a.getBoundingClientRect(),S=u.getBoundingClientRect(),C=e>S.right-S.width/2,w=t>S.bottom-S.height/2,T=S.width>x.width,E=S.height>x.height,D=(T?x:S).left,O=(T?x:S).right,k=(E?x:S).top,A=(E?x:S).bottom;if(c===`top`&&t>=x.bottom-1||c===`bottom`&&t<=x.top+1||c===`left`&&e>=x.right-1||c===`right`&&e<=x.left+1){b();return}let j=!1;switch(c){case`top`:j=_c(d,f,D,x.top+1,O,S.bottom-1);break;case`bottom`:j=_c(d,f,D,S.top+1,O,x.bottom-1);break;case`left`:j=_c(d,f,S.right-1,A,x.left+1,k);break;case`right`:j=_c(d,f,x.right-1,A,S.left+1,k)}if(j)return;if(l&&!gc(d,f,x)){b();return}if(!g&&p(d,f)){b();return}let M=!1;switch(c){case`top`:{let n=T?pc/2:pc*4,r=T||C?e+n:e-n,i=T?e-n:C?e+n:e-n,a=t+pc+1,o=C||T?S.bottom-pc:S.top,s=C?T?S.bottom-pc:S.top:S.bottom-pc;M=hc(d,f,r,a,i,a,S.left,o,S.right,s);break}case`bottom`:{let n=T?pc/2:pc*4,r=T||C?e+n:e-n,i=T?e-n:C?e+n:e-n,a=t-pc,o=C||T?S.top+pc:S.bottom,s=C?T?S.top+pc:S.bottom:S.top+pc;M=hc(d,f,r,a,i,a,S.left,o,S.right,s);break}case`left`:{let n=E?pc/2:pc*4,r=E||w?t+n:t-n,i=E?t-n:w?t+n:t-n,a=e+pc+1,o=w||E?S.right-pc:S.left,s=w?E?S.right-pc:S.left:S.right-pc;M=hc(d,f,o,S.top,s,S.bottom,a,r,a,i);break}case`right`:{let n=E?pc/2:pc*4,r=E||w?t+n:t-n,i=E?t-n:w?t+n:t-n,a=e-pc,o=w||E?S.left+pc:S.right,s=w?E?S.left+pc:S.right:S.left+pc;M=hc(d,f,a,r,a,i,o,S.top,s,S.bottom);break}}M?l||n.start(40,b):b()}};return r.__options={...e,blockPointerEvents:t},r}function yc({store:e,parentContext:t,isDrawer:n}){let r=e.useState(`open`),i=e.useState(`disablePointerDismissal`),a=e.useState(`modal`),o=e.useState(`popupElement`),s=e.useState(`floatingRootContext`),[c,u]=l.useState(0),[d,f]=l.useState(0),p=c===0,m=Va(s,{outsidePressEvent(){return e.context.internalBackdropRef.current||e.context.backdropRef.current?`intentional`:{mouse:a===`trap-focus`?`sloppy`:`intentional`,touch:`sloppy`}},outsidePress(t){if(!e.context.outsidePressEnabledRef.current||`button`in t&&t.button!==0)return!1;if(`touches`in t){if(t.type===`touchend`){if(t.changedTouches.length!==1||t.touches.length!==0)return!1}else if(t.touches.length!==1)return!1}let n=Et(t);if(p&&!i){if(a){let t=e.context.internalBackdropRef.current,r=e.context.backdropRef.current;return t||r?t===n||r===n||X(n,o)&&!n?.hasAttribute(`data-base-ui-portal`):!0}return!0}return!1},escapeKey:p});return vt(r&&a===!0,o),e.useContextCallback(`onNestedDialogOpen`,(e,t)=>{u(e),f(t)}),U(()=>(t?.onNestedDialogOpen&&(r?t.onNestedDialogOpen(c+1,d+ +!!n):t.onNestedDialogOpen(0,0)),()=>{t?.onNestedDialogOpen&&r&&t.onNestedDialogOpen(0,0)}),[n,r,c,d,t]),Ms(e,{activeTriggerProps:m.reference,inactiveTriggerProps:m.trigger,popupProps:m.floating,nestedOpenDialogCount:c,nestedOpenDrawerCount:d}),null}var bc=l.createContext(void 0);function xc(e){let t=l.useContext(bc);if(!e&&t===void 0)throw Error(Ai(27));return t}var Sc={...Vs,modal:e=>e.modal,nested:e=>e.nested,nestedOpenDialogCount:e=>e.nestedOpenDialogCount,nestedOpenDrawerCount:e=>e.nestedOpenDrawerCount,disablePointerDismissal:e=>e.disablePointerDismissal,openMethod:e=>e.openMethod,descriptionElementId:e=>e.descriptionElementId,titleElementId:e=>e.titleElementId,viewportElement:e=>e.viewportElement,role:e=>e.role},Cc=class extends ds{constructor(e,t,n){let r=new Ps,i=wc(e,r,t,n);super(i,Tc(r),Sc)}setOpen=(e,t)=>{t.preventUnmountOnClose=()=>{this.set(`preventUnmountingOnClose`,!0)},!e&&t.trigger==null&&this.state.activeTriggerId!=null&&(t.trigger=this.state.activeTriggerElement??void 0),this.context.onOpenChange?.(e,t),!t.isCanceled&&(this.state.floatingRootContext.dispatchOpenChange(e,t),this.update(Es(this.state,e,t.trigger)))}};function wc(e,t,n,r=!1){return{...Fs(t,n,r),modal:!0,disablePointerDismissal:!1,viewportElement:null,descriptionElementId:void 0,titleElementId:void 0,openMethod:null,nested:!1,nestedOpenDialogCount:0,nestedOpenDrawerCount:0,role:`dialog`,...e}}function Tc(e){return{popupRef:l.createRef(),backdropRef:l.createRef(),internalBackdropRef:l.createRef(),outsidePressEnabledRef:{current:!0},triggerElements:e,onOpenChange:void 0,onOpenChangeComplete:void 0}}function Ec(e,t){let{children:n,open:r,defaultOpen:i=!1,onOpenChange:a,onOpenChangeComplete:o,disablePointerDismissal:s=!1,modal:c=!0,actionsRef:u,handle:d,triggerId:f,defaultTriggerId:p=null}=t,m=e===`drawer`,h=e===`alert-dialog`,g=h?!0:c,_=h||s,v=h?`alertdialog`:`dialog`,y=xc(!0),b={modal:g,disablePointerDismissal:_,nested:y!=null,role:v},x=Ss((e,t)=>new Cc({open:i,openProp:r,activeTriggerId:p,triggerIdProp:f,...b},e,t),!0);x.useControlledProp(`openProp`,r),x.useControlledProp(`triggerIdProp`,f),x.useSyncedValues(b),x.useContextCallback(`onOpenChange`,a),x.useContextCallback(`onOpenChangeComplete`,o);let S=x.useState(`open`),C=x.useState(`mounted`),w=x.useState(`payload`);Ns(x,S),As(x);let{forceUnmount:T}=js(S,x);l.useImperativeHandle(u,()=>({unmount:T,close:()=>x.setOpen(!1,Z(jn))}),[T,x]);let E=S||C;return(0,Q.jsxs)(bc.Provider,{value:x,children:[d&&(0,Q.jsx)(Cs,{handle:d,store:x}),E&&(0,Q.jsx)(yc,{store:x,parentContext:y?.context,isDrawer:m}),typeof n==`function`?n({payload:w}):n]})}function Dc(e){return Ec(`alert-dialog`,e)}var Oc=l.forwardRef(function(e,t){let{render:n,className:r,style:i,forceRender:a=!1,...o}=e,s=xc(),c=s.useState(`open`),l=s.useState(`nested`),u=s.useState(`mounted`);return $i(`div`,e,{state:{open:c,transitionStatus:s.useState(`transitionStatus`)},ref:[s.context.backdropRef,t],stateAttributesMapping:Zt,props:[{role:`presentation`,hidden:!u,style:{userSelect:`none`,WebkitUserSelect:`none`}},o],enabled:a||!l})}),kc=l.createContext(void 0);function Ac(e=!1){let t=l.useContext(kc);if(t===void 0&&!e)throw Error(Ai(16));return t}function jc(e){let{focusableWhenDisabled:t,disabled:n,composite:r=!1,tabIndex:i=0,isNativeButton:a}=e,o=r&&t!==!1,s=r&&t===!1;return{props:l.useMemo(()=>{let e={onKeyDown(e){n&&t&&e.key!==`Tab`&&e.preventDefault()}};return r||(e.tabIndex=i,!a&&n&&(e.tabIndex=t?i:-1)),(a&&(t||o)||!a&&n)&&(e[`aria-disabled`]=n),a&&(!t||s)&&(e.disabled=n),e},[r,n,t,o,s,a,i])}}function Mc(e,t,{detail:n=0}={}){e.dispatchEvent(new(me(e)).PointerEvent(`click`,{bubbles:!0,cancelable:!0,composed:!0,detail:n,shiftKey:t.shiftKey,ctrlKey:t.ctrlKey,altKey:t.altKey,metaKey:t.metaKey}))}function Nc(e={}){let{disabled:t=!1,focusableWhenDisabled:n,tabIndex:r=0,native:i=!0,composite:a}=e,o=l.useRef(null),s=Ac(!0),c=a??s!==void 0,{props:u}=jc({focusableWhenDisabled:n,disabled:t,composite:c,tabIndex:r,isNativeButton:i}),d=l.useCallback(()=>{let e=o.current;Pc(e)&&c&&t&&u.disabled===void 0&&e.disabled&&(e.disabled=!1)},[t,u.disabled,c]);return U(d,[d]),{getButtonProps:l.useCallback((e={})=>{let{onClick:n,onMouseDown:r,onKeyUp:a,onKeyDown:o,onPointerDown:s,...l}=e;return zi({onClick(e){if(t){e.preventDefault();return}n?.(e)},onMouseDown(e){t||r?.(e)},onKeyDown(e){if(t||(Xi(e),o?.(e),e.baseUIHandlerPrevented))return;let n=e.target===e.currentTarget,r=e.currentTarget,a=Pc(r),s=!i&&Fc(r),l=n&&(i?a:!s),u=e.key===`Enter`,d=e.key===` `,f=r.getAttribute(`role`),p=f?.startsWith(`menuitem`)||f===`option`||f===`gridcell`;if(n&&c&&d){if(e.defaultPrevented&&p)return;e.preventDefault(),(!i||a)&&(e.preventBaseUIHandler(),Mc(r,e));return}if(!l||i||!d&&!u){n&&s&&d&&e.preventDefault();return}e.defaultPrevented||(e.preventDefault(),u&&(e.preventBaseUIHandler(),Mc(r,e)))},onKeyUp(e){if(!t){if(Xi(e),a?.(e),e.target===e.currentTarget&&i&&c&&Pc(e.currentTarget)&&e.key===` `){e.preventDefault();return}e.baseUIHandlerPrevented||e.target===e.currentTarget&&!i&&!c&&!e.defaultPrevented&&e.key===` `&&(e.preventBaseUIHandler(),Mc(e.currentTarget,e))}},onPointerDown(e){if(t){e.preventDefault();return}s?.(e)}},i?{type:`button`}:{role:`button`},u,l)},[t,u,c,i]),buttonRef:$(e=>{o.current=e,d()})}}function Pc(e){return K(e)&&e.tagName===`BUTTON`}function Fc(e){return K(e)&&e.tagName===`A`&&!!e.href}var Ic=l.forwardRef(function(e,t){let{render:n,className:r,style:i,disabled:a=!1,nativeButton:o=!0,...s}=e,c=xc(),l=c.useState(`open`),{getButtonProps:u,buttonRef:d}=Nc({disabled:a,native:o}),f={disabled:a};function p(e){l&&c.setOpen(!1,Z(yn,e.nativeEvent))}return $i(`button`,e,{state:f,ref:[t,d],props:[{onClick:p},s,u]})});function Lc(e){return Oi(e,`base-ui`)}var Rc=l.forwardRef(function(e,t){let{render:n,className:r,style:i,id:a,...o}=e,s=xc(),c=Lc(a);return s.useSyncedValueWithCleanup(`descriptionElementId`,c),$i(`p`,e,{ref:t,props:[{id:c},o]})}),zc=l.createContext(void 0);function Bc(){let e=l.useContext(zc);if(e===void 0)throw Error(Ai(26));return e}var Vc=new Set([`ArrowUp`,`ArrowDown`,`ArrowLeft`,`ArrowRight`,`Home`,`End`]),Hc=`--nested-dialogs`,Uc=`data-nested-dialog-open`,Wc={...Xt,...Lt,nestedDialogOpen(e){return e?{[Uc]:``}:null}},Gc=l.forwardRef(function(e,t){let{render:n,className:r,style:i,finalFocus:a,initialFocus:o,...s}=e,c=xc(),l=c.useState(`descriptionElementId`),u=c.useState(`disablePointerDismissal`),d=c.useState(`floatingRootContext`),f=c.useState(`popupProps`),p=c.useState(`modal`),m=c.useState(`mounted`),h=c.useState(`nested`),g=c.useState(`nestedOpenDialogCount`),_=c.useState(`open`),v=c.useState(`openMethod`),y=c.useState(`titleElementId`),b=c.useState(`transitionStatus`),x=c.useState(`role`),S=d.useState(`floatingId`);Bc(),ys({open:_,ref:c.context.popupRef,onComplete(){_&&c.context.onOpenChangeComplete?.(!0)}});let C=o===void 0?xs(c.context.popupRef):o,w=g>0,T=c.useStateSetter(`popupElement`),E=$i(`div`,e,{state:{open:_,nested:h,transitionStatus:b,nestedDialogOpen:w},props:[f,{id:S,"aria-labelledby":y,"aria-describedby":l,role:x,...bs,hidden:!m,onKeyDown(e){Vc.has(e.key)&&e.stopPropagation()},style:{[Hc]:g}},s],ref:[t,c.context.popupRef,T],stateAttributesMapping:Wc});return(0,Q.jsx)(Pa,{context:d,openInteractionType:v,disabled:!m,closeOnFocusOut:!u,initialFocus:C,returnFocus:a,modal:p!==!1,restoreFocus:`popup`,children:E})});function Kc(e){return Mi(19)?e:e?`true`:void 0}var qc=l.forwardRef(function(e,t){let{cutout:n,...r}=e,i;if(n){let e=n.getBoundingClientRect();i=`polygon(0% 0%,100% 0%,100% 100%,0% 100%,0% 0%,${e.left}px ${e.top}px,${e.left}px ${e.bottom}px,${e.right}px ${e.bottom}px,${e.right}px ${e.top}px,${e.left}px ${e.top}px)`}return(0,Q.jsx)(`div`,{ref:t,role:`presentation`,"data-base-ui-inert":``,...r,style:{position:`fixed`,inset:0,userSelect:`none`,WebkitUserSelect:`none`,clipPath:i}})}),Jc=l.forwardRef(function(e,t){let{keepMounted:n=!1,...r}=e,i=xc(),a=i.useState(`mounted`),o=i.useState(`modal`),s=i.useState(`open`);return a||n?(0,Q.jsx)(zc.Provider,{value:n,children:(0,Q.jsxs)(ha,{ref:t,...r,children:[a&&o===!0&&(0,Q.jsx)(qc,{ref:i.context.internalBackdropRef,inert:Kc(!s)}),e.children]})}):null}),Yc=l.forwardRef(function(e,t){let{render:n,className:r,style:i,id:a,...o}=e,s=xc(),c=Lc(a);return s.useSyncedValueWithCleanup(`titleElementId`,c),$i(`h2`,e,{ref:t,props:[{id:c},o]})});function Xc(e){let t=l.useRef(``),n=l.useCallback(n=>{n.defaultPrevented||(t.current=n.pointerType,e(n,n.pointerType))},[e]);return{onClick:l.useCallback(n=>{if(n.detail===0){e(n,`keyboard`);return}`pointerType`in n?e(n,n.pointerType):e(n,t.current),t.current=``},[e]),onPointerDown:n}}function Zc(e,t){let n=l.useRef(e),r=$(t);U(()=>{n.current!==e&&r(n.current),n.current=e},[e,r])}function Qc(e,t){let{onClick:n,onPointerDown:r}=Xc($((n,r)=>{(typeof e==`function`?e():e)||t(r||(Ve?`touch`:``))}));return l.useMemo(()=>({onClick:n,onPointerDown:r}),[n,r])}function $c(e){let[t,n]=l.useState(null),r=Qc(e,n);return Zc(e,t=>{t&&!e&&n(null)}),l.useMemo(()=>({openMethod:t,triggerProps:r}),[t,r])}var el=i(),tl,nl,rl=e=>{tl??=(0,el.createRoot)(document.body.appendChild(document.createElement(`div`))),nl?.resolve(!1),nl=e,tl.render((0,Q.jsx)(il,{request:e,settle:t=>{nl===e&&(nl=void 0,tl?.render(null),e.resolve(t))}}))};function il({request:e,settle:t}){return(0,Q.jsx)(Dc,{open:!0,onOpenChange:e=>{e||t(!1)},children:(0,Q.jsxs)(Jc,{children:[(0,Q.jsx)(Oc,{className:`dialog-backdrop`}),(0,Q.jsxs)(Gc,{className:`dialog`,children:[(0,Q.jsx)(Rc,{className:`dialog-message`,children:e.message}),(0,Q.jsxs)(`div`,{className:`dialog-actions`,children:[e.cancelLabel&&(0,Q.jsx)(Ic,{className:`dialog-button`,children:e.cancelLabel}),(0,Q.jsx)(`button`,{type:`button`,autoFocus:!0,className:`dialog-button is-primary ${e.danger?`is-danger`:``}`,onClick:()=>t(!0),children:e.confirmLabel})]})]})]})})}var al=(e,{confirmLabel:t=`Confirm`,danger:n=!1}={})=>new Promise(r=>rl({message:e,confirmLabel:t,cancelLabel:`Cancel`,danger:n,resolve:r})),ol=e=>new Promise(t=>rl({message:e,confirmLabel:`OK`,resolve:()=>t()})),sl=l.createContext(void 0);function cl(e){let t=l.useContext(sl);if(t===void 0&&!e)throw Error(Ai(72));return t}var ll={...Vs,disabled:e=>e.disabled,instantType:e=>e.instantType,isInstantPhase:e=>e.isInstantPhase,trackCursorAxis:e=>e.trackCursorAxis,disableHoverablePopup:e=>e.disableHoverablePopup,lastOpenChangeReason:e=>e.openChangeReason,closeOnClick:e=>e.closeOnClick,closeDelay:e=>e.closeDelay,adaptiveOrigin:e=>e.adaptiveOrigin},ul=class extends ds{constructor(e,t,n){let r=new Ps;super(dl(e,r,t,n),fl(r),ll)}setOpen=(e,t)=>{Os(this,e,t,{extraState:{openChangeReason:t.reason}})};cancelPendingOpen(e){this.state.floatingRootContext.dispatchOpenChange(!1,Z(mn,e))}};function dl(e,t,n,r=!1){return{...Fs(t,n,r),disabled:!1,instantType:void 0,isInstantPhase:!1,trackCursorAxis:`none`,disableHoverablePopup:!1,openChangeReason:null,closeOnClick:!0,closeDelay:0,adaptiveOrigin:void 0,...e}}function fl(e){return{popupRef:l.createRef(),onOpenChange:void 0,onOpenChangeComplete:void 0,triggerElements:e}}var pl=es(function(e){let{disabled:t=!1,defaultOpen:n=!1,open:r,disableHoverablePopup:i=!1,trackCursorAxis:a=`none`,actionsRef:o,onOpenChange:s,onOpenChangeComplete:c,handle:u,triggerId:d,defaultTriggerId:f=null,children:p}=e,m=Ss((e,t)=>new ul({open:n,openProp:r,activeTriggerId:f,triggerIdProp:d},e,t));m.useControlledProp(`openProp`,r),m.useControlledProp(`triggerIdProp`,d),m.useContextCallback(`onOpenChange`,s),m.useContextCallback(`onOpenChangeComplete`,c);let h=m.useState(`open`),g=!t&&h,_=m.useState(`activeTriggerId`),v=m.useState(`mounted`),y=m.useState(`payload`);m.useSyncedValues({trackCursorAxis:a,disableHoverablePopup:i,disabled:t}),As(m,{closeOnActiveTriggerUnmount:!0});let{forceUnmount:b,transitionStatus:x}=js(g,m),S=m.useState(`isInstantPhase`),C=m.useState(`instantType`),w=m.useState(`lastOpenChangeReason`),T=l.useRef(null);U(()=>{h&&t&&m.setOpen(!1,Z(An))},[h,t,m]),U(()=>{x===`ending`&&w===`none`||x!==`ending`&&S?(C!==`delay`&&(T.current=C),m.set(`instantType`,`delay`)):T.current!==null&&(m.set(`instantType`,T.current),T.current=null)},[x,S,w,C,m]),U(()=>{g&&(_??m.set(`payload`,void 0))},[m,_,g]),l.useImperativeHandle(o,()=>({unmount:b,close:()=>m.setOpen(!1,Z(jn))}),[b,m]);let E=g||v||!t&&a!==`none`;return(0,Q.jsxs)(sl.Provider,{value:m,children:[u&&(0,Q.jsx)(Cs,{handle:u,store:m}),E&&(0,Q.jsx)(ml,{store:m,disabled:t,trackCursorAxis:a}),typeof p==`function`?p({payload:y}):p]})});function ml({store:e,disabled:t,trackCursorAxis:n}){let r=e.useState(`floatingRootContext`),i=Va(r,{enabled:!t,referencePress:()=>e.select(`closeOnClick`)}),a=Ra(r,{enabled:!t&&n!==`none`,axis:n===`none`?void 0:n}),o=l.useMemo(()=>zi(a.reference,i.reference),[a.reference,i.reference]);return Ms(e,{activeTriggerProps:o,inactiveTriggerProps:o,popupProps:i.floating??et}),null}var hl=l.createContext(void 0);function gl(){return l.useContext(hl)}var _l=`data-base-ui-tooltip-trigger`;function vl(e){if(`composedPath`in e){let t=e.composedPath();for(let e=0;e<t.length;e+=1){let n=t[e];if(G(n))return n}}let t=e.target;return G(t)?t:null}function yl(e){let t=e;for(;t;){let e=t.closest(`[${_l}]`);if(e)return e;let n=t.getRootNode();t=`host`in n&&G(n.host)?n.host:null}return null}var bl=ts(function(e,t){let{render:n,className:r,style:i,handle:a,payload:o,disabled:s,delay:c,closeOnClick:u=!0,closeDelay:d,id:f,...p}=e,m=cl(!0),h=Hs(a)??m;if(!h)throw Error(Ai(82));let g=Lc(f),_=h.useState(`isTriggerActive`,g),v=h.useState(`isOpenedByTrigger`,g),y=h.useState(`floatingRootContext`),b=l.useRef(null),x=d??0,{registerTrigger:S,isMountedByThisTrigger:C}=ks(g,b,h,{payload:o,closeOnClick:u,closeDelay:x}),w=gl(),{activeIdRef:T,delayRef:E,isInstantPhase:D,hasProvider:O}=In(y,{open:v}),k=Qs(y);h.useSyncedValue(`isInstantPhase`,D);let A=h.useState(`disabled`),j=s??A,M=Wn(j),N=h.useState(`trackCursorAxis`),P=h.useState(`disableHoverablePopup`),F=l.useRef(!1),I=it(),L=l.useRef(void 0);function R(){return O&&T.current!=null?0:c??w??600}function z(e){let t=b.current;if(!t||!e)return!1;let n=yl(e);return n!==null&&n!==t&&X(t,n)}function ee(e){let t=z(e);return F.current=t,t&&(k.openChangeTimeout.clear(),k.restTimeout.clear(),k.restTimeoutPending=!1,I.clear()),t}let B=tc(y,{enabled:!j,mouseOnly:!0,move:!1,handleClose:!P&&N!==`both`?vc():null,restMs:R,delay(){return d==null&&O?{close:ln(E.current,`close`)}:{close:x}},triggerElementRef:b,isActiveTrigger:_,isClosing:()=>h.select(`transitionStatus`)===`ending`,shouldOpen(){return!F.current}}),te=qs(y,{enabled:!j}).reference,ne=e=>{let t=F.current,n=vl(e),r=ee(n),i=b.current,a=i&&n&&X(i,n);if(r&&h.select(`open`)&&h.select(`lastOpenChangeReason`)===`trigger-hover`){h.setOpen(!1,Z(hn,e));return}if(t&&!r&&a&&!M.current&&!h.select(`open`)&&i&&Ct(L.current)){let t=()=>{!F.current&&!M.current&&!h.select(`open`)&&h.setOpen(!0,Z(hn,e,i))},n=R();n===0?(I.clear(),t()):I.start(n,t)}},re=h.useState(`triggerProps`,C);return $i(`button`,e,{state:{open:v},ref:[t,S,b],props:[B,te,C||N!==`none`?re:void 0,{onMouseOver(e){ne(e.nativeEvent)},onFocus(e){z(vl(e.nativeEvent))&&e.preventBaseUIHandler()},onMouseLeave(){F.current=!1,I.clear(),L.current=void 0},onPointerEnter(e){L.current=e.pointerType},onPointerDown(e){L.current=e.pointerType,h.set(`closeOnClick`,u),u&&!h.select(`open`)&&h.cancelPendingOpen(e.nativeEvent)},onClick(e){u&&!h.select(`open`)&&h.cancelPendingOpen(e.nativeEvent)},id:g,[Qt]:j?``:void 0,[_l]:j?void 0:``},p],stateAttributesMapping:Jt})}),xl=l.createContext(void 0);function Sl(){let e=l.useContext(xl);if(e===void 0)throw Error(Ai(70));return e}var Cl=l.forwardRef(function(e,t){let{children:n,container:r,className:i,render:a,style:o,...s}=e,{node:c,subtree:u}=ma({container:r,ref:t,componentProps:e,elementProps:s});return!u&&!c?null:(0,Q.jsxs)(l.Fragment,{children:[u,c&&ua.createPortal(n,c)]})}),wl=l.forwardRef(function(e,t){let{keepMounted:n=!1,...r}=e;return cl().useState(`mounted`)||n?(0,Q.jsx)(xl.Provider,{value:n,children:(0,Q.jsx)(Cl,{ref:t,...r})}):null}),Tl=l.createContext(void 0);function El(){let e=l.useContext(Tl);if(e===void 0)throw Error(Ai(71));return e}var Dl=l.createContext(void 0);function Ol(){return l.useContext(Dl)?.direction??`ltr`}var kl=e=>({name:`arrow`,options:e,async fn(t){let{x:n,y:r,placement:i,rects:a,platform:o,elements:s,middlewareData:c}=t,{element:l,padding:u=0,offsetParent:d=`real`}=cr(e,t)||{};if(l==null)return{};let f=Er(u),p={x:n,y:r},m=mr(i),h=fr(m),g=await o.getDimensions(l),_=m===`y`,v=_?`top`:`left`,y=_?`bottom`:`right`,b=_?`clientHeight`:`clientWidth`,x=a.reference[h]+a.reference[m]-p[m]-a.floating[h],S=p[m]-a.reference[m],C=d===`real`?await o.getOffsetParent?.(l):s.floating,w=s.floating[b]||a.floating[h];(!w||!await o.isElement?.(C))&&(w=s.floating[b]||a.floating[h]);let T=x/2-S/2,E=w/2-g[h]/2-1,D=Math.min(f[v],E),O=Math.min(f[y],E),k=D,A=w-g[h]-O,j=w/2-g[h]/2+T,M=sr(k,j,A),N=!c.arrow&&ur(i)!=null&&j!==M&&a.reference[h]/2-(j<k?D:O)-g[h]/2<0,P=N?j<k?j-k:j-A:0;return{[m]:p[m]+P,data:{[m]:M,centerOffset:j-M-P,...N&&{alignmentOffset:P}},reset:N}}}),Al=(e,t)=>{let{name:n,fn:r}=kl(e);return{name:n,fn:r,options:[e,t]}},jl={name:`hide`,async fn(e){let{width:t,height:n,x:r,y:i}=e.rects.reference,a=t===0&&n===0&&r===0&&i===0,o=await e.platform.detectOverflow(e,{elementContext:`reference`});return{data:{referenceHidden:o.top-n>=0||o.right-t>=0||o.bottom-n>=0||o.left-t>=0||a}}}},Ml={sideX:`left`,sideY:`top`},Nl=`--available-width`,Pl=`--available-height`,Fl=`--anchor-width`,Il=`--anchor-height`,Ll=`--transform-origin`,Rl=Nl,zl=Pl;function Bl(e,t,n){let r=e===`inline-start`||e===`inline-end`;return{top:`top`,right:r?n?`inline-start`:`inline-end`:`right`,bottom:`bottom`,left:r?n?`inline-end`:`inline-start`:`left`}[t]}function Vl(e,t,n){let{rects:r,placement:i}=e;return{side:Bl(t,lr(i),n),align:ur(i)||`center`,anchor:{width:r.reference.width,height:r.reference.height},positioner:{width:r.floating.width,height:r.floating.height}}}function Hl(e){return Ul(e,Ws)}function Ul(e,t){let{anchor:n,positionMethod:r=`absolute`,side:i=`bottom`,sideOffset:a=0,align:o=`center`,alignOffset:s=0,collisionBoundary:c,collisionPadding:u=5,sticky:d=!1,arrowPadding:f=5,disableAnchorTracking:p=!1,inline:m,keepMounted:h=!1,floatingRootContext:g,mounted:_,collisionAvoidance:v,shift:y,nodeId:b,adaptiveOrigin:x,lazyFlip:S=!1,externalTree:C}=e,[w,T]=l.useState(null);!_&&w!==null&&T(null);let E=v.side||`flip`,D=v.align||`flip`,O=v.fallbackAxisSide||`end`,k=y?.crossAxis??!1,A=y?.rootBoundary,j=typeof n==`function`?n:void 0,M=$(j),N=j?M:n,P=Wn(n),F=Wn(_),I=Ol()===`rtl`,L=w||{top:`top`,right:`right`,bottom:`bottom`,left:`left`,"inline-end":I?`left`:`right`,"inline-start":I?`right`:`left`}[i],R=o===`center`?L:`${L}-${o}`,z=u;typeof z==`number`?z={top:z,right:z,bottom:z,left:z}:z&&={top:z.top||0,right:z.right||0,bottom:z.bottom||0,left:z.left||0};let ee=+(i===`bottom`),B=+(i===`top`),te=+(i===`right`),ne=+(i===`left`),re={boundary:c===`clipping-ancestors`?`clippingAncestors`:c,padding:z},V=l.useRef(null),H=Wn(a),ie=Wn(s),ae=typeof a==`function`?0:a,oe=typeof s==`function`?0:s,se=[];m&&se.push(m),se.push(Vo(e=>{let t=Vl(e,i,I),n=typeof H.current==`function`?H.current(t):H.current,r=typeof ie.current==`function`?ie.current(t):ie.current;return{mainAxis:n,crossAxis:r,alignmentAxis:r}},[ae,oe,I,i]));let ce=D===`none`&&E!==`shift`,le=!ce&&(d||k||E===`shift`),ue=E===`none`?null:Wo({...re,padding:{top:z.top+1+ee,right:z.right+1+ne,bottom:z.bottom+1+B,left:z.left+1+te},mainAxis:!k&&E===`flip`,crossAxis:D===`flip`&&`alignment`,fallbackAxisSideDirection:O}),de=ce?null:Ho({...re,rootBoundary:A,mainAxis:D!==`none`,crossAxis:le,limiter:d||k?void 0:Uo(e=>{if(!V.current)return{};let{width:t,height:n}=V.current.getBoundingClientRect(),r=pr(lr(e.placement)),i=r===`y`?t:n,a=r===`y`?z.left+z.right:z.top+z.bottom;return{offset:i/2+a/2}})},[re,d,k,A,z,D]);E===`shift`||D===`shift`||o===`center`?se.push(de,ue):se.push(ue,de),se.push(Go({...re,apply({elements:{floating:e},availableWidth:t,availableHeight:n,rects:r}){if(!F.current)return;let i=e.style;i.setProperty(Rl,`${t}px`),i.setProperty(zl,`${n}px`);let a=me(e).devicePixelRatio||1,{x:o,y:s,width:c,height:l}=r.reference,u=(Math.round((o+c)*a)-Math.round(o*a))/a,d=(Math.round((s+l)*a)-Math.round(s*a))/a;i.setProperty(Fl,`${u}px`),i.setProperty(Il,`${d}px`)}}),Al(e=>({element:V.current||J(e.elements.floating).createElement(`div`),padding:V.current?f:0,offsetParent:`floating`}),[f]),{name:`transformOrigin`,fn(e){let{elements:{floating:t},middlewareData:n,placement:r,platform:o,rects:s,y:c}=e,l=lr(r),u=ur(r),d=pr(l)===`y`,f=V.current,p=typeof a==`function`?a(Vl(e,i,I)):a,m;m=!f&&u&&Math.abs(d?n.shift?.x||0:n.shift?.y||0)<=1?u===`start`===(d&&o.isRTL?.(t)===!0)?`100%`:`0%`:`${(d?n.arrow?.x||0:n.arrow?.y||0)+(d?f?.clientWidth||0:f?.clientHeight||0)/2}px`;let h=l===`top`||l===`left`?`calc(100% + ${p}px)`:`${-p}px`;return le&&d&&Math.abs(n.shift?.y||0)>p&&(h=`${s.reference.y+s.reference.height/2-c}px`),t.style.setProperty(Ll,d?`${m} ${h}`:`${h} ${m}`),{}}},jl,x),U(()=>{!_&&g&&g.update({referenceElement:null,floatingElement:null,domReferenceElement:null,positionReference:null})},[_,g]);let fe=l.useMemo(()=>({ancestorScroll:!p,elementResize:!p&&typeof ResizeObserver<`u`,layoutShift:!p&&typeof IntersectionObserver<`u`}),[p]),{refs:pe,elements:W,x:he,y:ge,middlewareData:G,update:K,placement:_e,context:ve,isPositioned:ye,floatingStyles:be}=t({rootContext:g,open:h?_:void 0,placement:R,middleware:se,strategy:r,whileElementsMounted:h?void 0:(...e)=>Oo(...e,fe),nodeId:b,externalTree:C}),{sideX:xe,sideY:Se}=G.adaptiveOrigin||Ml,Ce=ye?r:`fixed`,we=l.useMemo(()=>{let e;return e=ye?x?{position:Ce,[xe]:he,[Se]:ge}:{...be,position:Ce}:{position:Ce,top:0,left:0},e[Rl]=`100vw`,e[zl]=`100vh`,ye||(e.opacity=0),e},[x,Ce,xe,he,Se,ge,be,ye]),Te=l.useRef(null);U(()=>{if(!_)return;let e=P.current,t=typeof e==`function`?e():e,n=(Wl(t)?t.current:t)||null;n!==Te.current&&(pe.setPositionReference(n),Te.current=n)},[_,pe,N,P]),l.useEffect(()=>{if(!_)return;let e=P.current;typeof e!=`function`&&Wl(e)&&e.current!==Te.current&&(pe.setPositionReference(e.current),Te.current=e.current)},[_,pe,N,P]),l.useEffect(()=>{if(h&&_&&W.reference&&W.floating)return Oo(W.reference,W.floating,K,fe)},[h,_,W,K,fe]);let Ee=lr(_e),De=Bl(i,Ee,I),Oe=ur(_e)||`center`,ke=!!G.hide?.referenceHidden;U(()=>{S&&_&&ye&&Ee!==L&&T(Ee)},[S,_,ye,Ee,L]);let Ae=l.useMemo(()=>({position:`absolute`,top:G.arrow?.y,left:G.arrow?.x}),[G.arrow]),je=G.arrow?.centerOffset!==0;return l.useMemo(()=>({positionerStyles:we,arrowStyles:Ae,arrowRef:V,arrowUncentered:je,side:De,align:Oe,physicalSide:Ee,anchorHidden:ke,refs:pe,context:ve,isPositioned:ye,update:K}),[we,Ae,V,je,De,Oe,Ee,ke,pe,ve,ye,K])}function Wl(e){return e!=null&&`current`in e}function Gl(e){return e===`starting`?oa:et}function Kl(e,t,{styles:n,transitionStatus:r,props:i,refs:a,hidden:o,inert:s=!1}){let c={...n};return s&&(c.pointerEvents=`none`),$i(`div`,e,{state:t,ref:a,props:[{role:`presentation`,hidden:o,style:c},Gl(r),i],stateAttributesMapping:Xt})}var ql=l.forwardRef(function(e,t){let{render:n,className:r,anchor:i,positionMethod:a=`absolute`,side:o=`top`,align:s=`center`,sideOffset:c=0,alignOffset:u=0,collisionBoundary:d=`clipping-ancestors`,collisionPadding:f=5,arrowPadding:p=5,sticky:m=!1,disableAnchorTracking:h=!1,collisionAvoidance:g=ca,style:_,...v}=e,y=cl(),b=Sl(),x=y.useState(`open`),S=y.useState(`mounted`),C=y.useState(`trackCursorAxis`),w=y.useState(`disableHoverablePopup`),T=y.useState(`floatingRootContext`),E=y.useState(`instantType`),D=y.useState(`transitionStatus`),O=Hl({anchor:i,positionMethod:a,floatingRootContext:T,mounted:S,side:o,sideOffset:c,align:s,alignOffset:u,collisionBoundary:d,collisionPadding:f,sticky:m,arrowPadding:p,disableAnchorTracking:h,keepMounted:b,collisionAvoidance:g,adaptiveOrigin:y.useState(`adaptiveOrigin`)}),k=Kl(e,l.useMemo(()=>({open:x,side:O.side,align:O.align,anchorHidden:O.anchorHidden,instant:C===`none`?E:`tracking-cursor`}),[x,O.side,O.align,O.anchorHidden,C,E]),{styles:O.positionerStyles,transitionStatus:D,props:v,refs:[t,y.useStateSetter(`positionerElement`)],hidden:!S,inert:!x||C===`both`||w});return(0,Q.jsx)(Tl.Provider,{value:O,children:k})}),Jl=l.forwardRef(function(e,t){let{render:n,className:r,style:i,...a}=e,o=cl(),{side:s,align:c}=El(),l=o.useState(`open`),u=o.useState(`instantType`),d=o.useState(`transitionStatus`),f=o.useState(`popupProps`),p=o.useState(`floatingRootContext`),m=o.useState(`disabled`),h=o.useState(`closeDelay`);ys({open:l,ref:o.context.popupRef,onComplete(){l&&o.context.onOpenChangeComplete?.(!0)}}),$s(p,{enabled:!m,closeDelay:h});let g=o.useStateSetter(`popupElement`);return $i(`div`,e,{state:{open:l,side:s,align:c,instant:u,transitionStatus:d},ref:[t,o.context.popupRef,g],props:[bs,f,Gl(d),a],stateAttributesMapping:Zt})});function Yl({label:e,side:t=`top`,children:n}){return(0,Q.jsxs)(pl,{children:[(0,Q.jsx)(bl,{render:n}),(0,Q.jsx)(wl,{children:(0,Q.jsx)(ql,{className:`tooltip-positioner`,side:t,sideOffset:8,collisionPadding:8,children:(0,Q.jsx)(Jl,{className:`tooltip-popup`,children:e})})})]})}var Xl={clover:{label:`Clover`,color:`#35B8FF`,face:`eyes`,faceX:50,faceY:50,faceScale:1},flower:{label:`Flower`,color:`#2FCB7A`,face:`eyes`,faceX:50,faceY:51,faceScale:.95},triangle:{label:`Triangle`,color:`#DC48FF`,face:`eyes`,faceX:50,faceY:61,faceScale:.9},square:{label:`Square`,color:`#35B8FF`,face:`eyes`,faceX:50,faceY:50,faceScale:1},blob:{label:`Blob`,color:`#2FCB7A`,face:`eyes`,faceX:49.5,faceY:50,faceScale:1},ghost:{label:`Ghost`,color:`#F4F2FA`,face:`eyes`,faceX:50,faceY:48,faceScale:.95},circle:{label:`Circle`,color:`#9A62FF`,face:`eyes`,faceX:50,faceY:50,faceScale:1},drop:{label:`Drop`,color:`#1ED3C6`,face:`eyes`,faceX:50,faceY:62,faceScale:.9},star:{label:`Star`,color:`#FFD32B`,face:`eyes`,faceX:50,faceY:52,faceScale:.82},droid:{label:`Droid`,color:`#D5DBEA`,face:`eyes`,faceX:50,faceY:60,faceScale:.95},mech:{label:`Mech`,color:`#95A6C4`,face:`eyes`,faceX:50,faceY:59,faceScale:1},alien:{label:`Alien`,color:`#9BE85A`,face:`eyes`,faceX:50,faceY:45,faceScale:1.05},hexagon:{label:`Hexagon`,color:`#FF2A2A`,face:`eyes`,faceX:50,faceY:50,faceScale:.95},cat:{label:`Cat`,color:`#FF8C42`,face:`eyes`,faceX:50,faceY:58,faceScale:1},cloud:{label:`Cloud`,color:`#CFE6FF`,face:`eyes`,faceX:50,faceY:58,faceScale:.95},pill:{label:`Pill`,color:`#7B77F0`,face:`eyes`,faceX:50,faceY:50,faceScale:.9},pebble:{label:`Pebble`,color:`#2FCB7A`,face:`eyes`,faceX:50,faceY:50,faceScale:.95},puddle:{label:`Puddle`,color:`#FF2A2A`,face:`eyes`,faceX:50,faceY:50,faceScale:.95}},Zl=Object.keys(Xl);Object.fromEntries(Zl.map(e=>[e,Xl[e].color]));var Ql={default:`idle`,working:`working`,sleeping:`sleeping`},$l={clover:`M26.53 22.38A25 25 0 0 1 73.47 22.38A7 7 0 0 0 77.62 26.53A25 25 0 0 1 77.62 73.47A7 7 0 0 0 73.47 77.62A25 25 0 0 1 26.53 77.62A7 7 0 0 0 22.38 73.47A25 25 0 0 1 22.38 26.53A7 7 0 0 0 26.53 22.38Z`,flower:`M31.2 19.82A20.5 20.5 0 0 1 68.8 19.82A5 5 0 0 0 72.9 22.8A20.5 20.5 0 0 1 84.51 58.55A5 5 0 0 0 82.95 63.37A20.5 20.5 0 0 1 52.54 85.47A5 5 0 0 0 47.46 85.47A20.5 20.5 0 0 1 17.05 63.37A5 5 0 0 0 15.49 58.55A20.5 20.5 0 0 1 27.1 22.8A5 5 0 0 0 31.2 19.82Z`,triangle:`M38.75 27.43A13 13 0 0 1 61.25 27.43L82.7 64.49A13 13 0 0 1 71.45 84L28.55 84A13 13 0 0 1 17.3 64.49L38.75 27.43Z`,square:`M93 50C93 53.66 92.96 58.23 92.88 60.97C92.8 63.71 92.67 64.81 92.51 66.44C92.35 68.08 92.15 69.44 91.9 70.77C91.66 72.1 91.37 73.3 91.04 74.44C90.72 75.58 90.35 76.63 89.94 77.63C89.53 78.63 89.07 79.55 88.58 80.43C88.08 81.31 87.54 82.13 86.96 82.9C86.37 83.67 85.75 84.39 85.07 85.07C84.39 85.75 83.67 86.37 82.9 86.96C82.13 87.54 81.31 88.08 80.43 88.58C79.55 89.07 78.63 89.53 77.63 89.94C76.63 90.35 75.58 90.72 74.44 91.04C73.3 91.37 72.1 91.66 70.77 91.9C69.44 92.15 68.08 92.35 66.44 92.51C64.81 92.67 63.71 92.8 60.97 92.88C58.23 92.96 53.66 93 50 93C46.34 93 41.77 92.96 39.03 92.88C36.29 92.8 35.19 92.67 33.56 92.51C31.92 92.35 30.56 92.15 29.23 91.9C27.9 91.66 26.7 91.37 25.56 91.04C24.42 90.72 23.37 90.35 22.37 89.94C21.37 89.53 20.45 89.07 19.57 88.58C18.69 88.08 17.87 87.54 17.1 86.96C16.33 86.37 15.61 85.75 14.93 85.07C14.25 84.39 13.63 83.67 13.04 82.9C12.46 82.13 11.92 81.31 11.42 80.43C10.93 79.55 10.47 78.63 10.06 77.63C9.65 76.63 9.28 75.58 8.96 74.44C8.63 73.3 8.34 72.1 8.1 70.77C7.85 69.44 7.65 68.08 7.49 66.44C7.33 64.81 7.2 63.71 7.12 60.97C7.04 58.23 7 53.66 7 50C7 46.34 7.04 41.77 7.12 39.03C7.2 36.29 7.33 35.19 7.49 33.56C7.65 31.92 7.85 30.56 8.1 29.23C8.34 27.9 8.63 26.7 8.96 25.56C9.28 24.42 9.65 23.37 10.06 22.37C10.47 21.37 10.93 20.45 11.42 19.57C11.92 18.69 12.46 17.87 13.04 17.1C13.63 16.33 14.25 15.61 14.93 14.93C15.61 14.25 16.33 13.63 17.1 13.04C17.87 12.46 18.69 11.92 19.57 11.42C20.45 10.93 21.37 10.47 22.37 10.06C23.37 9.65 24.42 9.28 25.56 8.96C26.7 8.63 27.9 8.34 29.23 8.1C30.56 7.85 31.92 7.65 33.56 7.49C35.19 7.33 36.29 7.2 39.03 7.12C41.77 7.04 46.34 7 50 7C53.66 7 58.23 7.04 60.97 7.12C63.71 7.2 64.81 7.33 66.44 7.49C68.08 7.65 69.44 7.85 70.77 8.1C72.1 8.34 73.3 8.63 74.44 8.96C75.58 9.28 76.63 9.65 77.63 10.06C78.63 10.47 79.55 10.93 80.43 11.42C81.31 11.92 82.13 12.46 82.9 13.04C83.67 13.63 84.39 14.25 85.07 14.93C85.75 15.61 86.37 16.33 86.96 17.1C87.54 17.87 88.08 18.69 88.58 19.57C89.07 20.45 89.53 21.37 89.94 22.37C90.35 23.37 90.72 24.42 91.04 25.56C91.37 26.7 91.66 27.9 91.9 29.23C92.15 30.56 92.35 31.92 92.51 33.56C92.67 35.19 92.8 36.29 92.88 39.03C92.96 41.77 93 46.34 93 50Z`,blob:`M93.92 50C94.18 51.9 94.24 53.9 93.99 55.79C93.73 57.68 93.18 59.61 92.39 61.36C91.6 63.1 90.48 64.78 89.27 66.27C88.07 67.76 86.58 69.08 85.14 70.29C83.7 71.49 82.1 72.5 80.62 73.5C79.14 74.49 77.64 75.34 76.24 76.24C74.84 77.15 73.51 78 72.2 78.93C70.88 79.86 69.66 80.83 68.36 81.8C67.06 82.76 65.78 83.82 64.39 84.74C63 85.67 61.55 86.63 60.01 87.35C58.47 88.08 56.82 88.73 55.15 89.1C53.48 89.47 51.71 89.64 50 89.57C48.29 89.5 46.55 89.16 44.91 88.68C43.27 88.21 41.67 87.47 40.16 86.72C38.65 85.96 37.24 85.02 35.86 84.13C34.48 83.24 33.19 82.29 31.89 81.37C30.58 80.46 29.32 79.56 28.03 78.63C26.74 77.71 25.44 76.82 24.16 75.84C22.88 74.86 21.57 73.87 20.36 72.74C19.15 71.62 17.95 70.42 16.91 69.1C15.88 67.79 14.92 66.35 14.15 64.85C13.38 63.35 12.76 61.73 12.29 60.1C11.81 58.48 11.52 56.78 11.29 55.1C11.06 53.41 10.98 51.71 10.91 50C10.83 48.29 10.83 46.59 10.83 44.84C10.84 43.1 10.85 41.34 10.93 39.53C11.02 37.72 11.09 35.86 11.34 33.99C11.59 32.12 11.88 30.16 12.43 28.31C12.99 26.46 13.69 24.56 14.66 22.88C15.64 21.21 16.86 19.58 18.27 18.27C19.69 16.96 21.4 15.84 23.17 15.03C24.93 14.22 26.95 13.71 28.89 13.43C30.83 13.15 32.9 13.21 34.82 13.36C36.74 13.5 38.66 13.92 40.43 14.28C42.2 14.65 43.87 15.16 45.46 15.54C47.06 15.93 48.52 16.31 50 16.58C51.48 16.85 52.87 17.02 54.32 17.17C55.77 17.32 57.22 17.36 58.71 17.49C60.2 17.62 61.74 17.7 63.28 17.95C64.81 18.19 66.39 18.5 67.91 18.98C69.43 19.46 70.95 20.08 72.38 20.83C73.81 21.58 75.19 22.5 76.5 23.5C77.81 24.5 79.03 25.63 80.22 26.81C81.41 27.99 82.54 29.25 83.65 30.57C84.76 31.89 85.85 33.26 86.89 34.72C87.93 36.18 88.98 37.69 89.9 39.31C90.82 40.92 91.73 42.64 92.4 44.42C93.07 46.2 93.66 48.1 93.92 50Z`,ghost:`M17 50C17 31.78 31.78 17 50 17C68.22 17 83 31.78 83 50V81.5Q72 93.5 61 81.5Q50 93.5 39 81.5Q28 93.5 17 81.5Z`,circle:`M50 8A42 42 0 1 1 50 92A42 42 0 1 1 50 8Z`,drop:`M50 8.5C52.2 8.5 53.4 10.3 56.4 15.2C62.9 25.5 84 44.6 84 61.5C84 80.3 68.8 92 50 92C31.2 92 16 80.3 16 61.5C16 44.6 37.1 25.5 43.6 15.2C46.6 10.3 47.8 8.5 50 8.5Z`,star:`M45.77 9.7A5 5 0 0 1 54.23 9.7L65.02 26.81A4 4 0 0 0 67.42 28.55L87.02 33.53A5 5 0 0 1 89.63 41.57L76.7 57.12A4 4 0 0 0 75.78 59.94L77.11 80.12A5 5 0 0 1 70.26 85.09L51.48 77.59A4 4 0 0 0 48.52 77.59L29.74 85.09A5 5 0 0 1 22.89 80.12L24.22 59.94A4 4 0 0 0 23.3 57.12L10.37 41.57A5 5 0 0 1 12.98 33.53L32.58 28.55A4 4 0 0 0 34.98 26.81L45.77 9.7Z`,droid:`M16 50C16 38.95 24.95 30 36 30H64C75.05 30 84 38.95 84 50V70C84 81.05 75.05 90 64 90H36C24.95 90 16 81.05 16 70ZM4 62A7 7 0 1 1 18 62A7 7 0 1 1 4 62ZM82 62A7 7 0 1 1 96 62A7 7 0 1 1 82 62Z`,mech:`M10 48C10 38.06 18.06 30 28 30H72C81.94 30 90 38.06 90 48V70C90 79.94 81.94 88 72 88H28C18.06 88 10 79.94 10 70ZM3 54C3 51.79 4.79 50 7 50H11V72H7C4.79 72 3 70.21 3 68ZM89 50H93C95.21 50 97 51.79 97 54V68C97 70.21 95.21 72 93 72H89Z`,alien:`M50 10C70 10 83 27 83 46C83 65 64 92 50 92C36 92 17 65 17 46C17 27 30 10 50 10Z`,hexagon:`M91.4 45.5A9 9 0 0 1 91.4 54.5L74.6 83.61A9 9 0 0 1 66.8 88.11L33.2 88.11A9 9 0 0 1 25.4 83.61L8.6 54.5A9 9 0 0 1 8.6 45.5L25.4 16.39A9 9 0 0 1 33.2 11.89L66.8 11.89A9 9 0 0 1 74.6 16.39L91.4 45.5Z`,cat:`M50 20A36 36 0 1 1 50 92A36 36 0 1 1 50 20ZM24.72 44.64A4.5 4.5 0 0 1 17.35 40.67L20.21 16.66A4.5 4.5 0 0 1 26.86 13.26L42.3 21.83A4.5 4.5 0 0 1 43.02 29.21L24.72 44.64ZM82.65 40.67A4.5 4.5 0 0 1 75.28 44.64L56.98 29.21A4.5 4.5 0 0 1 57.7 21.83L73.14 13.26A4.5 4.5 0 0 1 79.79 16.66L82.65 40.67Z`,cloud:`M19 44A25 25 0 1 1 69 44A25 25 0 1 1 19 44ZM47 50A21 21 0 1 1 89 50A21 21 0 1 1 47 50ZM7 68A17 17 0 1 1 41 68A17 17 0 1 1 7 68ZM32 73A18 18 0 1 1 68 73A18 18 0 1 1 32 73ZM60 70A16 16 0 1 1 92 70A16 16 0 1 1 60 70Z`,pill:`M28 28H72C84.15 28 94 37.85 94 50C94 62.15 84.15 72 72 72H28C15.85 72 6 62.15 6 50C6 37.85 15.85 28 28 28Z`,pebble:`M94.6 50C94.71 51.92 94.56 53.93 94.17 55.82C93.79 57.7 93.13 59.6 92.28 61.33C91.44 63.06 90.32 64.72 89.1 66.19C87.87 67.67 86.41 69.01 84.92 70.16C83.42 71.31 81.75 72.29 80.11 73.1C78.47 73.92 76.73 74.55 75.06 75.06C73.39 75.58 71.7 75.91 70.1 76.2C68.5 76.48 66.93 76.62 65.45 76.76C63.96 76.9 62.55 76.94 61.2 77.03C59.84 77.11 58.57 77.16 57.31 77.26C56.05 77.36 54.86 77.48 53.64 77.63C52.42 77.79 51.24 77.98 50 78.18C48.76 78.39 47.52 78.64 46.2 78.85C44.89 79.06 43.53 79.3 42.11 79.46C40.69 79.61 39.2 79.75 37.67 79.77C36.14 79.78 34.54 79.74 32.95 79.54C31.35 79.33 29.7 79.03 28.1 78.55C26.49 78.07 24.86 77.45 23.33 76.67C21.8 75.88 20.29 74.94 18.92 73.85C17.54 72.77 16.23 71.51 15.08 70.16C13.94 68.8 12.9 67.29 12.04 65.72C11.17 64.16 10.45 62.46 9.91 60.74C9.36 59.03 8.98 57.22 8.76 55.43C8.55 53.64 8.5 51.8 8.6 50C8.71 48.2 8.98 46.39 9.38 44.65C9.79 42.91 10.35 41.19 11.02 39.56C11.7 37.92 12.52 36.34 13.43 34.85C14.34 33.37 15.39 31.96 16.5 30.66C17.61 29.36 18.84 28.15 20.11 27.07C21.39 25.98 22.76 25 24.15 24.15C25.54 23.3 27.01 22.56 28.48 21.95C29.94 21.33 31.46 20.85 32.95 20.46C34.44 20.08 35.95 19.83 37.43 19.66C38.91 19.48 40.38 19.43 41.81 19.43C43.24 19.43 44.64 19.53 46.01 19.66C47.37 19.78 48.7 19.98 50 20.18C51.3 20.39 52.57 20.63 53.83 20.87C55.1 21.11 56.34 21.37 57.6 21.62C58.87 21.87 60.13 22.12 61.43 22.39C62.74 22.66 64.07 22.93 65.45 23.24C66.83 23.56 68.25 23.88 69.72 24.3C71.19 24.72 72.71 25.17 74.25 25.75C75.78 26.34 77.37 27 78.91 27.81C80.46 28.63 82.04 29.56 83.5 30.66C84.97 31.75 86.43 33 87.7 34.38C88.98 35.77 90.19 37.32 91.17 38.97C92.14 40.62 92.98 42.43 93.56 44.27C94.13 46.1 94.5 48.08 94.6 50Z`,puddle:`M85.34 50C85.65 51.54 85.9 53.13 86.01 54.74C86.11 56.35 86.11 58 85.95 59.63C85.8 61.26 85.51 62.93 85.07 64.52C84.62 66.12 84.03 67.72 83.3 69.23C82.58 70.74 81.7 72.21 80.72 73.57C79.74 74.94 78.62 76.23 77.43 77.43C76.24 78.62 74.93 79.72 73.58 80.73C72.23 81.74 70.79 82.65 69.33 83.48C67.86 84.31 66.34 85.04 64.79 85.71C63.24 86.37 61.65 86.95 60.04 87.46C58.42 87.96 56.77 88.4 55.1 88.75C53.43 89.09 51.72 89.37 50 89.54C48.28 89.71 46.52 89.81 44.76 89.76C43.01 89.72 41.22 89.58 39.47 89.29C37.72 89 35.95 88.58 34.26 88C32.57 87.42 30.89 86.69 29.33 85.8C27.77 84.92 26.26 83.87 24.91 82.7C23.56 81.53 22.3 80.19 21.23 78.77C20.16 77.35 19.22 75.79 18.47 74.2C17.71 72.61 17.13 70.91 16.7 69.23C16.26 67.55 16.02 65.81 15.88 64.13C15.75 62.45 15.78 60.76 15.88 59.14C15.97 57.52 16.21 55.94 16.45 54.42C16.7 52.89 17.03 51.43 17.34 50C17.65 48.57 18 47.2 18.32 45.83C18.63 44.46 18.94 43.13 19.24 41.76C19.53 40.39 19.79 39.03 20.08 37.61C20.36 36.18 20.62 34.74 20.95 33.23C21.28 31.72 21.61 30.16 22.07 28.57C22.52 26.98 23.02 25.32 23.69 23.69C24.35 22.06 25.11 20.38 26.05 18.79C26.99 17.21 28.08 15.62 29.33 14.2C30.58 12.78 32 11.41 33.54 10.26C35.08 9.12 36.8 8.11 38.57 7.35C40.34 6.6 42.27 6.04 44.17 5.73C46.08 5.43 48.08 5.37 50 5.54C51.92 5.71 53.87 6.15 55.69 6.75C57.52 7.36 59.3 8.22 60.94 9.19C62.57 10.15 64.11 11.33 65.51 12.56C66.91 13.78 68.17 15.15 69.33 16.52C70.48 17.89 71.5 19.34 72.44 20.76C73.38 22.18 74.19 23.62 74.97 25.03C75.75 26.43 76.44 27.83 77.12 29.19C77.8 30.56 78.42 31.89 79.05 33.23C79.67 34.57 80.28 35.87 80.87 37.21C81.46 38.55 82.05 39.88 82.6 41.27C83.14 42.65 83.68 44.05 84.14 45.51C84.6 46.96 85.03 48.46 85.34 50Z`},eu={droid:`M47.5 14H52.5V32H47.5ZM43 11A7 7 0 1 1 57 11A7 7 0 1 1 43 11Z`,mech:`M19.5 32L24.5 32L17 13L12 13ZM75.5 32L80.5 32L88 13L83 13ZM10 11.5A4.5 4.5 0 1 1 19 11.5A4.5 4.5 0 1 1 10 11.5ZM81 11.5A4.5 4.5 0 1 1 90 11.5A4.5 4.5 0 1 1 81 11.5Z`};function tu(e){let t=e.trim(),n=t.match(/^hsla?\(\s*([\d.]+)(?:deg)?[,\s]+([\d.]+)%[,\s]+([\d.]+)%/i);if(n)return su([Number(n[1])/360,Number(n[2])/100,Number(n[3])/100]);let r=t.match(/^#([0-9a-f]{3}|[0-9a-f]{6})$/i);if(r){let e=r[1];e.length===3&&(e=e.split(``).map(e=>e+e).join(``));let t=parseInt(e,16);return[t>>16&255,t>>8&255,t&255]}let i=t.match(/^rgba?\(\s*([\d.]+)[,\s]+([\d.]+)[,\s]+([\d.]+)/i);return i?[Number(i[1]),Number(i[2]),Number(i[3])]:null}function nu(e){let t=tu(e);if(!t)return .5;let n=e=>{let t=e/255;return t<=.03928?t/12.92:((t+.055)/1.055)**2.4};return .2126*n(t[0])+.7152*n(t[1])+.0722*n(t[2])}var ru=`#1E1A33`,iu=`#F7F5F2`;function au(e){return nu(e)<.13?iu:ru}function ou([e,t,n]){e/=255,t/=255,n/=255;let r=Math.max(e,t,n),i=Math.min(e,t,n),a=(r+i)/2;if(r===i)return[0,0,a];let o=r-i,s=a>.5?o/(2-r-i):o/(r+i),c=0;return c=r===e?(t-n)/o+(t<n?6:0):r===t?(n-e)/o+2:(e-t)/o+4,[c/6,s,a]}function su([e,t,n]){if(t===0)return[n*255,n*255,n*255];let r=n<.5?n*(1+t):n+t-n*t,i=2*n-r,a=e=>(e=(e%1+1)%1,e<1/6?i+(r-i)*6*e:e<1/2?r:e<2/3?i+(r-i)*(2/3-e)*6:i);return[a(e+1/3)*255,a(e)*255,a(e-1/3)*255]}function cu([e,t,n]){return`hsl(${(e*360).toFixed(1)} ${(t*100).toFixed(1)}% ${(n*100).toFixed(1)}%)`}var lu=e=>Math.min(1,Math.max(0,e));function uu(e,t,n=0){let r=tu(e);if(!r)return e;let[i,a,o]=ou(r);return cu([i,lu(a+n+(t<0?-t*.25:0)),lu(o+t)])}var du=[`default`,`working`,`sleeping`],fu=.68,pu=26,mu=.2,hu={height:pu,time:fu,stretch:1,squash:1.15,squashTime:.37,squashEase:`pulse`,groundTime:.11,groundEase:`pulse`,riseTime:.33,riseEase:`pulse`,clickSquashTime:.24,spin:1,lean:6,every:8,land:0},gu=(e,t)=>t?e.clickSquashTime:mu*e.time,_u=(e,t)=>gu(e,t)+e.time+vu[e.squashEase]*(t?e.clickSquashTime:e.squashTime)+Math.max(0,e.groundTime)+e.riseTime+Math.max(0,e.land)+.05,vu={sharp:0,pulse:2/7,soft:.5,bouncy:.144},yu=(e,t)=>{if(e<=0)return 1;if(e>=1)return 0;switch(t){case`sharp`:return(1-e)*(1-e);case`soft`:return .5+.5*Math.cos(Math.PI*e);case`bouncy`:return Math.exp(-3.2*e)*Math.cos(5.4*e)-e*e*e*.026;default:{let t=4.2*e;return(1+t)*Math.exp(-t)-e*e*e*.078}}},bu=(e,t)=>1+.25*xu(e,t),xu=(e,t)=>{if(e<=0||e>=1)return 0;let n;switch(t){case`sharp`:n=(1-e)*(1-e);break;case`soft`:n=Math.sin(Math.PI*e)**2;break;case`bouncy`:n=Math.exp(-3.15*e)*Math.sin(8.43*e)/.596;break;default:{let t=7*e;n=t*t*Math.exp(2-t)/4}}let r=e>.85?1-(e-.85)/.15:1;return n*r*r*(3-2*r)},Su=e=>Math.exp(-((Math.min(Math.abs(e),Math.abs(e-1))/.11)**2)),Cu=Math.PI/180,wu=Math.PI*2,Tu={default:1.2,working:.7,sleeping:1.4},Eu=1;function Du(e){let t=e*2654435761>>>0||1;return()=>{t=t+1831565813>>>0;let e=t;return e=Math.imul(e^e>>>15,e|1),e^=e+Math.imul(e^e>>>7,e|61),((e^e>>>14)>>>0)/4294967296}}function Ou(e,t,n,r){return e+(t-e)*(1-Math.exp(-n*r))}var ku=e=>e<.5?4*e*e*e:1-(-2*e+2)**3/2,Au=e=>.5-.5*Math.cos(Math.PI*e),ju=class{constructor(e,t,n,r,i,a=!1){this.rand=e,this.amp=t,this.holdMin=n,this.holdMax=r,this.rate=i,this.spring=a,this.value=0,this.vel=0,this.target=0,this.next=0}update(e,t){if(e>=this.next&&(this.target=(this.rand()*2-1)*this.amp,this.next=e+this.holdMin+this.rand()*(this.holdMax-this.holdMin)),this.spring){let e=this.rate*1.6;this.vel+=(e*e*(this.target-this.value)-1.8*e*this.vel)*t,this.value+=this.vel*t}else this.value=Ou(this.value,this.target,this.rate,t)}aim(e){this.target=e,this.next=1/0}set(e,t,n,r){this.amp=e,this.holdMin=t,this.holdMax=n,this.rate=r,this.next=0}},Mu=class{constructor(e){this.duration=e,this.p=-1}fire(){this.p=0}get active(){return this.p>=0}update(e){this.p<0||(this.p+=e/this.duration,this.p>=1&&(this.p=-1))}},Nu=35*Cu,Pu=14*Cu,Fu=3.2*Cu,Iu=2.6,Lu={default:{pitch:0,roll:0,y:0,lookX:0,lookY:0},working:{pitch:5*Cu,roll:0,y:0,lookX:0,lookY:0},sleeping:{pitch:-16*Cu,roll:6*Cu,y:3,lookX:0,lookY:1}},Ru=class{constructor(e,t=`default`){this.pose={yaw:0,pitch:0,roll:0,x:0,y:0,sx:1,sy:1,eyeOpen:1,blinkL:0,blinkR:0,lookX:0,lookY:0,breath:0,laugh:0,whirl:0,whirlAngle:0,w:[1,0,0]},this.state=`default`,this.t=0,this.wFrom=[1,0,0],this.tr=1,this.trDuration=1.2,this.blink=new Mu(.17),this.blinkAgain=!1,this.dart=new Mu(.12),this.dartX=0,this.dartY=0,this.flip=new Mu(_u(hu,!1)),this.flipPoked=!1,this.jump={...hu},this.flipSide=1,this.nod=new Mu(1.7),this.hopPhase=0,this.hopCount=0,this.hopGain=0,this.laughEv=new Mu(.8),this.prevYaw=0,this.jelly=0,this.jellyV=0,this.gazeLead=0,this.gazeDir=[0,0],this.gazeAt=0,this.turnK=1,this.breathPhase=0,this.ptrX=0,this.ptrY=0,this.ptrS=0,this.ptrTargetX=0,this.ptrTargetY=0,this.ptrTargetS=0,this.baseYaw=0,this.rand=Du(Math.floor(e*1e6)+1);let n=this.rand;this.yawW=new ju(n,36*Cu,1.1,2.6,3,!0),this.pitchW=new ju(n,10*Cu,1.1,2.6,2.6,!0),this.rollW=new ju(n,5*Cu,1.6,3.2,2,!0),this.lookXW=new ju(n,3.6,.5,2,14),this.lookYW=new ju(n,2.4,.5,2,14),this.t=n()*10,this.hopPhase=n(),this.breathPhase=n(),this.blinkAt=this.t+1+n()*3,this.flipAt=this.nextFlip(this.t,1),this.nodAt=this.t+3+n()*4,this.dartAt=this.t+1+n()*2,this.laughAt=this.t+.6+n()*1.5,this.setState(t,!0)}setState(e,t=!1){if(e===this.state&&!t)return;let n=this.state;this.state=e;let r=this.pose.w;if(t){for(let t=0;t<3;t++)r[t]=+(du[t]===e);this.tr=1}else this.wFrom=[r[0],r[1],r[2]],this.tr=0,this.trDuration=n===`sleeping`?Eu:Tu[e];switch(e){case`default`:this.yawW.set(Nu,2.6,5.4,2),this.pitchW.set(Pu,2.8,5.8,1.8),this.rollW.set(Fu,3.4,6.6,1.5),this.gazeAt=0,this.gazeDir=[0,0],this.lookXW.set(3.6,.6,2.2,13),this.lookYW.set(2.4,.6,2.2,13),this.flipAt=this.nextFlip(this.t,.6);break;case`working`:this.yawW.set(16*Cu,.9,1.8,4),this.pitchW.set(3*Cu,1.2,2.4,3),this.rollW.set(0,1,2,3),this.lookXW.set(2,.5,1.2,12),this.lookYW.set(1,.5,1.2,12),this.hopPhase=0,this.hopCount=0,this.laughAt=this.t+.5+this.rand()*1.2;break;case`sleeping`:this.yawW.set(7*Cu,3,6,.7),this.pitchW.set(3*Cu,3,6,.7),this.rollW.set(2*Cu,3,6,.6),this.lookXW.set(0,2,4,2),this.lookYW.set(0,2,4,2),this.nodAt=this.t+2.5+this.rand()*4}}setPointer(e,t,n){this.ptrTargetX=Math.max(-1.2,Math.min(1.2,e)),this.ptrTargetY=Math.max(-1.2,Math.min(1.2,t)),this.ptrTargetS=Math.max(0,Math.min(1,n))}poke(){this.flip.active&&this.flip.p<.6||(this.flipPoked=!0,this.flip.duration=_u(this.jump,!0),this.flipSide=this.rand()<.5?-1:1,this.flip.fire(),this.flipAt=this.nextFlip(this.t,1.1))}setTurn(e){let t=Math.max(0,e);t!==this.turnK&&(this.turnK=t,this.state==="default"&&(this.gazeAt=0))}setJump(e){let t=this.jump.every;Object.assign(this.jump,e),e.every!==void 0&&e.every!==t&&(this.flipAt=this.nextFlip(this.t,1))}nextGaze(){let e=this.rand,[t,n]=this.gazeDir;if(t!==0||n!==0){let r=e();return r<.66?[-t,-n]:r<.85?[-t,n]:[0,0]}let r=[[1,-1],[-1,1],[-1,-1],[1,1]];return r[Math.floor(e()*r.length)]}nextFlip(e,t){let n=this.jump.every;return n>0?e+n*t*(.625+this.rand()*.75):1/0}update(e){e=Math.min(e,.05),this.t+=e;let t=this.t,n=this.pose,r=n.w;if(this.tr<1){this.tr=Math.min(1,this.tr+e/this.trDuration);let t=Au(this.tr);for(let e=0;e<3;e++){let n=+(du[e]===this.state);r[e]=this.wFrom[e]+(n-this.wFrom[e])*t}}let[i,a,o]=r,s={pitch:0,roll:0,y:0,lookX:0,lookY:0};for(let e=0;e<3;e++){let t=Lu[du[e]];s.pitch+=t.pitch*r[e],s.roll+=t.roll*r[e],s.y+=t.y*r[e],s.lookX+=t.lookX*r[e],s.lookY+=t.lookY*r[e]}if(this.state==="default"&&t>=this.gazeAt){let[e,n]=this.nextGaze();this.gazeDir=[e,n];let r=.84+this.rand()*.16;this.yawW.aim(e*Nu*r*this.turnK),this.pitchW.aim(n*Pu*r),this.rollW.aim(e*Fu*r*this.turnK),this.gazeAt=t+Iu+this.rand()*1.8000000000000003}this.yawW.update(t,e),this.pitchW.update(t,e),this.rollW.update(t,e),this.lookXW.update(t,e),this.lookYW.update(t,e),this.ptrS=Ou(this.ptrS,this.ptrTargetS,8,e),this.ptrX=Ou(this.ptrX,this.ptrTargetX,14,e),this.ptrY=Ou(this.ptrY,this.ptrTargetY,14,e);let c=this.ptrS,l=1-.75*c;this.baseYaw=Ou(this.baseYaw,this.yawW.value*l+22*Cu*this.ptrX*c,5,e);let u=s.pitch+this.pitchW.value*l-12*Cu*this.ptrY*c,d=s.roll+this.rollW.value*l,f=s.y,p=s.lookX+this.lookXW.value*l+4.5*this.ptrX*c,m=s.lookY+this.lookYW.value*l+3*this.ptrY*c,h=0,g=0,_=1,v=1,y=0,b=0,x=0,S=0,C=0,w=0,T=0,E=0,D=(e,t,n)=>{let r=Math.min(1,Math.max(0,(n-e)/(t-e)));return r*r*(3-2*r)},O=e=>D(.1,.26,e)*(1-D(.66,.9,e)),k=e=>wu*(1.5*e+.9*ku(e));if(t>=this.blinkAt&&!this.blink.active&&i+a>.5&&(this.blink.fire(),this.blinkAgain=!this.blinkAgain&&this.rand()<.22,this.blinkAt=t+(this.blinkAgain?.28:2.2+this.rand()*2.6)),this.blink.update(e),this.blink.active&&(x=Math.sin(Math.PI*this.blink.p)),t>=this.dartAt&&!this.dart.active&&i+a>.5&&(this.dart.fire(),this.dartX=(this.rand()*2-1)*4,this.dartY=(this.rand()*2-1)*2,this.dart.duration=.25+this.rand()*.45,this.dartAt=t+1.2+this.rand()*2.6),this.dart.update(e),this.dart.active){let e=this.dart.p,t=e<.15?e/.15:e>.8?(1-e)/.2:1;S+=this.dartX*t*(i+a),C+=this.dartY*t*(i+a)}if(this.state==="default"&&t>=this.flipAt&&!this.flip.active&&(this.flipPoked=!1,this.flip.duration=_u(this.jump,!1),this.flipSide=this.rand()<.5?-1:1,this.flip.fire(),this.flipAt=this.nextFlip(t,1)),this.flip.update(e),this.flip.active){let e=this.jump,t=gu(e,this.flipPoked),n=(this.flip.p*this.flip.duration-t)/e.time,r=Math.min(1,Math.max(0,n)),i=Math.sin(Math.PI*r);h+=wu*e.spin*ku(r),g-=e.height*i;let a=(n-1)*e.time-e.land,o=this.flipPoked?e.clickSquashTime:e.squashTime,s=e=>this.flipPoked?e*e*(3-2*e):Su(e-1),c=Math.max(0,e.groundTime),l=vu[e.squashEase]*o,u=a-l-c,d=a<=l?xu(a/o,e.squashEase):u<=0?bu((a-l)/c,e.groundEase):yu(u/e.riseTime,e.riseEase),f=(n<0?s(Math.max(0,1+n*e.time/t)):a>0?d:n<.2?Su(n):0)*e.squash;_+=.16*f-.06*i*e.stretch,v+=-.18*f+.09*i*e.stretch,b+=this.flipSide*e.lean*Cu*i,e.spin>0&&(w=Math.max(w,i),T=Math.max(T,O(r)),E=k(r))}let A=this.jump,j=Math.max(0,A.groundTime),M=j+A.riseTime;if(this.state===`working`&&(this.hopGain=a),this.hopGain>.02&&(this.state===`working`||this.hopPhase>0)){this.hopPhase+=e/fu,this.hopPhase>=1&&(this.state===`working`?(--this.hopPhase,this.hopCount+=1):(this.hopPhase-1)*fu>=M&&(this.hopPhase=0,this.hopGain=0));let t=this.hopGain,n=Math.min(1,this.hopPhase),r=Math.sin(Math.PI*n),i=this.hopCount%3==2;g-=(i?pu:18)*r*t;let a=this.state!==`working`&&this.hopPhase>1?(this.hopPhase-1)*fu:-1,o=a<0?Su(this.hopPhase):a<j?bu(a/j,A.groundEase):yu((a-j)/A.riseTime,A.riseEase);_+=(.16*o-.06*r)*t,v+=(-.18*o+.09*r)*t,i&&(h+=wu*ku(n)*t,w=Math.max(w,r*t),O(n)*t>T&&(T=O(n)*t,E=k(n))),b+=(this.hopCount%2==0?1:-1)*6*Cu*r*t}if(this.state===`working`&&t>=this.laughAt&&!this.laughEv.active&&(this.laughEv.fire(),this.laughEv.duration=.6+this.rand()*.5,this.laughAt=t+1.6+this.rand()*2.2),this.laughEv.update(e),this.laughEv.active){let e=this.laughEv.p;w=Math.max(w,e<.18?e/.18:e>.78?(1-e)/.22:1)}if(this.state===`sleeping`&&t>=this.nodAt&&!this.nod.active&&(this.nod.fire(),this.nodAt=t+4+this.rand()*4),this.nod.update(e),this.nod.active){let e=this.nod.p,t=e<.72?ku(e/.72):1-ku((e-.72)/.28);y-=13*Cu*t*o}this.breathPhase+=e/(3.6+1.2*o);let N=Math.sin(this.breathPhase*wu);n.breath=N,_+=N*(.008+.014*o),v+=N*(.012+.02*o);let P=Math.sin(t*wu/3.4)*2*(1-o);n.yaw=this.baseYaw+h;let F=this.baseYaw-this.prevYaw;F=((F+Math.PI)%wu+wu)%wu-Math.PI,this.prevYaw=this.baseYaw;let I=e>0?Math.abs(F)/e:0,L=e>0?Math.max(-2.2,Math.min(2.2,F/e*2.4)):0;this.gazeLead=Ou(this.gazeLead,L,9,e);let R=Math.min(.22,.055*I);this.jellyV+=(256*(R-this.jelly)-14.4*this.jellyV)*e,this.jelly+=this.jellyV*e;let z=Math.max(-.08,Math.min(.28,this.jelly))*.6;_*=1+z,v*=1-.55*z,n.pitch=u+y,n.roll=d+b,n.x=0,n.y=f+g+P,n.sx=_,n.sy=v,n.eyeOpen=1,n.laugh=Ou(n.laugh,w,30,e),n.blinkL=x,n.blinkR=x,n.lookX=p+S+this.gazeLead,n.lookY=m+C,n.whirl=T,n.whirlAngle=E}};function zu(e){let t=Lu[e];return{yaw:0,pitch:t.pitch,roll:t.roll,x:0,y:t.y,sx:1,sy:1,eyeOpen:1,blinkL:0,blinkR:0,lookX:t.lookX,lookY:t.lookY,breath:0,laugh:0,whirl:0,whirlAngle:0,w:du.map(t=>+(t===e))}}var Bu=64,Vu=4096,Hu=24,Uu=0xe8d4a51000,Wu=48*Math.PI/180,Gu=Math.cos(Wu),Ku=Math.sin(Wu),qu=(e,t)=>t+(1-t)*Math.sqrt(Math.max(0,1-e*e));function Ju(e,t,n,r,i,a){let o=0;i[0]=0,a[0]=-1e30,a[1]=1e30;for(let n=1;n<t;n++){let t=0;for(;;){let r=i[o];if(t=(e[n]+n*n-e[r]-r*r)/(2*(n-r)),t>a[o])break;o--}o++,i[o]=n,a[o]=t,a[o+1]=1e30}o=0;for(let s=0;s<t;s++){for(;a[o+1]<s;)o++;let t=i[o];n[s]=(s-t)*(s-t)+e[t],r[s]=t}}function Yu(e,t,n,r,i){let a=new Float32Array(n),o=new Float32Array(n),s=new Int32Array(n),c=new Int32Array(n),l=new Float32Array(n+1),u=new Float32Array(n*n),d=new Int32Array(n*n);for(let r=0;r<n;r++){for(let i=0;i<n;i++)a[i]=e[i*n+r]===t?0:Uu;Ju(a,n,o,s,c,l);for(let e=0;e<n;e++)u[e*n+r]=o[e],d[e*n+r]=s[e]}for(let e=0;e<n;e++){let t=e*n;for(let e=0;e<n;e++)a[e]=u[t+e];Ju(a,n,o,s,c,l);for(let e=0;e<n;e++)r[t+e]=o[e],i&&(i[t+e]=d[t+s[e]]*n+s[e])}}function Xu(e,t,n){for(let r=0;r<t;r++){let i=r*t;for(let r=0;r<t;r++){let a=r<2?0:r-2,o=r<1?0:r-1,s=r>t-2?t-1:r+1,c=r>t-3?t-1:r+2;n[i+r]=(e[i+a]+4*e[i+o]+6*e[i+r]+4*e[i+s]+e[i+c])*.0625}}for(let r=0;r<t;r++)for(let i=0;i<t;i++){let a=i<2?0:i-2,o=i<1?0:i-1,s=i>t-2?t-1:i+1,c=i>t-3?t-1:i+2;e[i*t+r]=(n[a*t+r]+4*n[o*t+r]+6*n[i*t+r]+4*n[s*t+r]+n[c*t+r])*.0625}}function Zu(e,t,n){let r=[];for(let n=t,i=1;i<=4&&n%2==0||i===1;n>>=1,i<<=1){let a=new Uint8Array(n*n);for(let r=0;r<n;r++)for(let o=0;o<n;o++){let s=0;for(let n=0;n<i;n++)for(let a=0;a<i;a++)s+=e[(r*i+n)*t+o*i+a];a[r*n+o]=+(s>=128*i*i)}if(r.push({n,mask:a,phi:new Float32Array(n*n)}),i===4)break}let i=(e,t,n,r)=>{let{n:i,mask:a,phi:o}=e,s=t*t;for(let e=0;e<n;e++)for(let e=1;e<i-1;e++){let t=e*i;for(let e=1;e<i-1;e++){let n=t+e;if(!a[n])continue;let c=(o[n-1]+o[n+1]+o[n-i]+o[n+i]+s)*.25;o[n]+=r*(c-o[n])}}};for(let e=r.length-1;e>=0;e--){let t=r[e],a=1<<e;if(e<r.length-1){let n=r[e+1],i=t.n,a=n.n;for(let e=0;e<i;e++){let r=Math.min(a-1,Math.max(0,(e+.5)/2-.5)),o=r|0,s=Math.min(a-1,o+1),c=r-o;for(let r=0;r<i;r++){let l=e*i+r;if(!t.mask[l])continue;let u=Math.min(a-1,Math.max(0,(r+.5)/2-.5)),d=u|0,f=Math.min(a-1,d+1),p=u-d;t.phi[l]=(n.phi[o*a+d]*(1-p)+n.phi[o*a+f]*p)*(1-c)+(n.phi[s*a+d]*(1-p)+n.phi[s*a+f]*p)*c}}}let o=Math.min(1.9,2/(1+Math.sin(Math.PI/t.n))-.05);i(t,n*a,4,1),i(t,n*a,e===2?100:e===1?30:16,o),i(t,n*a,8,1)}return r[0].phi}var Qu=[1,1,0,-1,-1,-1,0,1],$u=[0,1,1,1,0,-1,-1,-1],ed=[1,Math.SQRT2,1,Math.SQRT2,1,Math.SQRT2,1,Math.SQRT2];function td(e,t,n){let r=106/t,i=t*t,a=new Uint8Array(i);for(let t=0;t<i;t++)a[t]=+(e[t]>=128);let o=new Float32Array(i),s=new Float32Array(i),c=new Int32Array(i);Yu(a,0,t,o,null),Yu(a,1,t,s,c);let l=new Float32Array(i),u=new Float32Array(i);for(let t=0;t<i;t++){let n=e[t]/255;l[t]=r*(n>0&&n<1?n-.5:a[t]?Math.sqrt(o[t])-.5:.5-Math.sqrt(s[t]))}Xu(l,t,u),Xu(l,t,u);let d=Zu(e,t,r),f=0;for(let e=0;e<i;e++)d[e]>f&&(f=d[e]);let p=2*Math.sqrt(f),m=Math.min(.9*n+.12*p,1.2*p),h=f>0?m/Math.sqrt(f):0,g=new Float32Array(i);for(let e=0;e<i;e++)g[e]=d[e]>0?h*Math.sqrt(d[e]):0;Xu(g,t,u);let _={N:t,i00:new Uint16Array(i),wx:new Uint8Array(i),wy:new Uint8Array(i),ao:new Uint8Array(i)},{i00:v,wx:y,wy:b,ao:x}=_,S=t<=64?[1,2,3,5,8]:t<=96?[1,2,4,7,11]:[1,2,4,7,11,15],C=t-1;for(let e=0;e<t;e++)for(let n=0;n<t;n++){let i=e*t+n,o=a[i]?i:s[i]<=9?c[i]:-1;if(o<0)continue;let u=o%t,d=(o-u)/t,f=u>0?u-1:0,p=u<C?u+1:C,m=d>0?d-1:0,h=d<C?d+1:C,_=-(g[d*t+p]-g[d*t+f])/(2*r),w=-(g[h*t+u]-g[m*t+u])/(2*r),T=1,E=Math.sqrt(_*_+w*w+1);_/=E,w/=E,T/=E;let D=Math.max(0,l[o]);if(D<2){let e=l[d*t+p]-l[d*t+f],n=l[h*t+u]-l[m*t+u],r=Math.hypot(e,n)||1;e/=r,n/=r;let i=.7*(1-D/2);_+=i*(-e-_),w+=i*(-n-w),T+=i*(0-T),E=Math.sqrt(_*_+w*w+T*T)||1,_/=E,w/=E,T/=E}let O=g[o],k=0;for(let e=0;e<8;e++){let n=0;for(let i=0;i<S.length;i++){let a=S[i],o=u+Qu[e]*a,s=d+$u[e]*a;o<0?o=0:o>C&&(o=C),s<0?s=0:s>C&&(s=C);let c=(g[s*t+o]-O)/(a*r*ed[e]);c>n&&(n=c)}k+=n/Math.sqrt(1+n*n)}let A=1-Math.min(1,D/3),j=1-.2*A*A,M=(1-.9*k/8)**1.5*j;x[i]=Math.max(1,Math.round(255*M**(1/2.2)));let N=(_*.5+.5)*63,P=(w*.5+.5)*63,F=Math.min(62,Math.max(0,N|0)),I=Math.min(62,Math.max(0,P|0));v[i]=I*Bu+F,y[i]=Math.round(255*Math.min(1,Math.max(0,N-F))),b[i]=Math.round(255*Math.min(1,Math.max(0,P-I)))}return _}function nd(e){if(typeof OffscreenCanvas==`function`)return new OffscreenCanvas(e,e);if(typeof document<`u`){let t=document.createElement(`canvas`);return t.width=t.height=e,t}return null}function rd(e,t){return e.getContext(`2d`,t?{willReadFrequently:!0}:void 0)}function id(e,t){let n=nd(t),r=n&&rd(n,!0);if(!r)return null;let i=106/t;r.setTransform(1/i,0,0,1/i,3/i,3/i),r.fillStyle=`#fff`,r.fill(e);let a=r.getImageData(0,0,t,t).data,o=new Uint8ClampedArray(t*t);for(let e=0;e<t*t;e++)o[e]=a[e*4+3];return o}var ad=new Map,od=new Set,sd=new WeakMap,cd=0;function ld(e){let t=sd.get(e);return t||sd.set(e,t=`p${cd++}`),t}var ud=[],dd=!1;function fd(){dd=!1;let e=ud.shift();e&&e(),ud.length&&pd()}function pd(){if(dd)return;dd=!0;let e=globalThis.requestIdleCallback;e?e(fd,{timeout:120}):setTimeout(fd,16)}function md(e){ud.push(e),pd()}function hd(e,t,n,r,i){let a=`${e}|${n}|${Math.round(r)}`,o=ad.get(a);if(o)return o;let s=()=>{if(od.delete(a),ad.has(a))return;let e=id(t,n);e&&(ad.size>=48&&ad.clear(),ad.set(a,td(e,n,r)))};return i?(s(),ad.get(a)??null):(od.has(a)||(od.add(a),md(s)),null)}function gd(e,t,n=192,r=.65){hd(e,t,_d(n),15*r,!0)}function _d(e){return e<=100?64:e<=224?96:128}var vd=e=>e<=.04045?e/12.92:((e+.055)/1.055)**2.4,yd=new Map;function bd(e){let t=yd.get(e);if(!t){let n=tu(e);if(!n){let t=nd(1),r=t&&rd(t,!0);if(r){r.fillStyle=e,r.fillRect(0,0,1,1);let t=r.getImageData(0,0,1,1).data;n=[t[0],t[1],t[2]]}else n=[128,128,128]}t=[vd(n[0]/255),vd(n[1]/255),vd(n[2]/255)],yd.size>200&&yd.clear(),yd.set(e,t)}return t}var xd=2048,Sd=2.5,Cd=xd/Sd,wd=new Float32Array(xd);for(let e=0;e<xd;e++){let t=(e+.5)/Cd,n=t<=.75?t:.75+.25*(1-Math.exp(-(t-.75)/.25));wd[e]=255*(n<=.0031308?12.92*n:1.055*n**(1/2.4)-.055)}var Td=e=>wd[e<=0?0:e>=Sd?2047:e*Cd|0],Ed=1024,Dd=new Map;function Od(e){let t=Dd.get(e);if(!t){t=new Float32Array(1025);for(let n=0;n<=Ed;n++)t[n]=(n/Ed)**+e;Dd.size>16&&Dd.clear(),Dd.set(e,t)}return t}var kd=[.92,.96,1],Ad=[1,.98,.95],jd=(e,t,n)=>{let r=n<=e?0:n>=t?1:(n-e)/(t-e);return r*r*(3-2*r)},Md=(e,t,n)=>1-jd(e-t,e+t,n);function Nd(e,t,n,r){let{L:i,V:a,H:o,U:s,W:c,A:l,B:u}=n,d=Math.max(t[0],t[1],t[2],.05),f=[t[0]/d,t[1]/d,t[2]/d],p=Math.max(.03,.3-.15*r.shadow),m=.15+.14*r.spread,h=.85,g=Math.min(90,Math.round(110/r.spread**1.3)),_=Math.max(2,Math.round(8/r.spread)),v=Od(g),y=Od(_),b=.45*r.highlight,x=.1*r.highlight,S=.11*r.highlight,C=.3*r.rim,w=[p*f[0],p*f[1],p*f[2]];for(let n=0;n<Bu;n++)for(let r=0;r<Bu;r++){let d=r/63*2-1,f=n/63*2-1,p=d*d+f*f;if(p>1.14)continue;if(p>1){let e=1/Math.sqrt(p);d*=e,f*=e,p=1}let g=Math.sqrt(1-p),_=d*i[0]+f*i[1]+g*i[2],T=Math.max(0,d*a[0]+f*a[1]+g*a[2]),E=Math.max(0,d*o[0]+f*o[1]+g*o[2]),D=Math.min(1,Math.max(0,(_+m)/(1+m))),O=1-T,k=O*O,A=k*O,j=A*k,M=E*Ed|0,N=(b*v[M]+x*y[M])*(1+3*j),P=2*T*d-a[0],F=2*T*f-a[1],I=2*T*g-a[2],L=.45+.55*jd(-.4,.6,P*s[0]+F*s[1]+I*s[2]),R=P*c[0]+F*c[1]+I*c[2],z=0;if(R>.5){let e=(P*l[0]+F*l[1]+I*l[2])/R,t=(P*u[0]+F*u[1]+I*u[2])/R;z=Md(.34,.12,Math.abs(e))*Md(.12,.06,Math.abs(t))}let ee=C*A*L+S*z,B=(n*Bu+r)*3;e[B]=Td(t[0]*(w[0]+h*D)+N*Ad[0]+ee*kd[0]),e[B+1]=Td(t[1]*(w[1]+h*D)+N*Ad[1]+ee*kd[1]),e[B+2]=Td(t[2]*(w[2]+h*D)+N*Ad[2]+ee*kd[2])}}function Pd(e,t,n,r){let i=(t*.5+.5)*63,a=(n*.5+.5)*63,o=Math.min(62,Math.max(0,i|0)),s=Math.min(62,Math.max(0,a|0)),c=i-o,l=a-s,u=(s*Bu+o)*3,d=(1-c)*(1-l),f=c*(1-l),p=(1-c)*l,m=c*l;for(let t=0;t<3;t++)r[t]=e[u+t]*d+e[u+3+t]*f+e[u+192+t]*p+e[u+192+3+t]*m}function Fd(e,t,n,r){let{N:i,i00:a,wx:o,wy:s,ao:c}=e;for(let e=0,l=0;e<i*i;e++,l+=4){let i=c[e];if(i===0){n[l+3]=0;continue}let u=r[i],d=a[e]*3,f=o[e]*(1/255),p=s[e]*(1/255),m=(1-f)*(1-p)*u,h=f*(1-p)*u,g=(1-f)*p*u,_=f*p*u;n[l]=t[d]*m+t[d+3]*h+t[d+192]*g+t[d+192+3]*_,n[l+1]=t[d+1]*m+t[d+4]*h+t[d+192+1]*g+t[d+192+4]*_,n[l+2]=t[d+2]*m+t[d+5]*h+t[d+192+2]*g+t[d+192+5]*_,n[l+3]=255}}var Id=e=>{let t=Math.hypot(e[0],e[1],e[2])||1;return[e[0]/t,e[1]/t,e[2]/t]};function Ld(e){let t=Math.cos(e.roll),n=Math.sin(e.roll),r=t*e.lx+n*e.ly,i=-n*e.lx+t*e.ly,a=e.facing<0?-1:1,o=a*Math.min(1,Math.abs(e.facing)/.16),{cy:s,sy:c,cp:l,sp:u}=e,d=(e,t,n,r=o)=>Id([s*e+c*u*t-c*l*n,l*t+u*n,r*(c*e-s*u*t+s*l*n)]),f=d(Gu*r,Gu*i,Ku),p=d(0,0,1,a),m=Id([f[0]+p[0],f[1]+p[1],f[2]+p[2]]),h=d(r,i,0,a),g=Math.cos(80*Math.PI/180),_=Math.sin(80*Math.PI/180),v=g*r-_*i,y=_*r+g*i,b=Id([.55*v,.55*y,.83]),x=Id([b[1],-b[0],0]),S=[b[1]*x[2]-b[2]*x[1],b[2]*x[0]-b[0]*x[2],b[0]*x[1]-b[1]*x[0]];return{L:f,V:p,H:m,U:h,W:d(b[0],b[1],b[2],a),A:d(x[0],x[1],x[2],a),B:d(S[0],S[1],S[2],a)}}var Rd=new WeakMap;function zd(e,t){let n=e.canvas??e,r=Rd.get(n);r||(r=new Map,Rd.set(n,r));let i=r.get(t);return i||(i={N:0,img:null,mc:new Float32Array(Vu*3),mcPrev:new Float32Array(Vu*3),mcMix:new Float32Array(Vu*3),mixVersion:0,blendT:1,blendFrames:1,sinceBuild:0,L:null,V:null,lx:NaN,ly:NaN,base:``,shadow:NaN,highlight:NaN,spread:NaN,rim:NaN,version:0,imgVersion:-1,imgAoK:NaN,imgForm:null,aoK:-1,aoMul:new Float32Array(256),near:null,rimG:null,far:null,scratch:[null,null],scratchIdx:0,scratchN:0,scratchStale:!0,sprites:[null,null,null],spriteVersion:-1,spritePx:0},r.size>4&&r.clear(),r.set(t,i)),i}var Bd=1/48,Vd=(e,t)=>!t||Math.abs(e[0]-t[0])>=Bd||Math.abs(e[1]-t[1])>=Bd||Math.abs(e[2]-t[2])>=Bd;function Hd(e,t){return[e[0]*t[0]+e[2]*t[1],e[1]*t[0]+e[3]*t[1],e[0]*t[2]+e[2]*t[3],e[1]*t[2]+e[3]*t[3],e[0]*t[4]+e[2]*t[5]+e[4],e[1]*t[4]+e[3]*t[5]+e[5]]}function Ud(e,t,n,r,i){let a=Math.sqrt(1-n*n),o=[0,0,0],s=1-r;if(typeof e.createConicGradient==`function`){let n=e.createConicGradient(0,50,50);for(let e=0;e<=Hu;e++){let r=e/Hu*Math.PI*2;Pd(t,a*Math.cos(r),a*Math.sin(r),o),n.addColorStop(e/Hu,`rgb(${o[0]*s|0} ${o[1]*s|0} ${o[2]*s|0})`)}return n}let c=e.createLinearGradient(50+i[0]*50,50+i[1]*50,50-i[0]*50,50-i[1]*50),l=(e,n,r)=>{Pd(t,e,n,o),c.addColorStop(r,`rgb(${o[0]*s|0} ${o[1]*s|0} ${o[2]*s|0})`)};return l(a*i[0],a*i[1],0),l(-a*i[1],a*i[0],.5),l(-a*i[0],-a*i[1],1),c}var Wd=typeof navigator<`u`&&/AppleWebKit\//.test(navigator.userAgent)&&!/Chrome\/|Chromium\/|Edg\//.test(navigator.userAgent),Gd=[[.55,()=>0],[0,()=>0],[0,e=>Math.min(.6,.25*e.shadow)]];function Kd(e,t,n,r,i,a){let o=_d(n.dev),s=hd(t.typeKey??ld(t.path),t.path,o,n.halfDepth,!!n.still);if(!s)return!1;let c=zd(e,t.typeKey??ld(t.path)),l=Ld(n),u=(()=>{let e=Math.hypot(l.L[0],l.L[1]);return e<.05?[0,-1]:[l.L[0]/e,l.L[1]/e]})();if((Vd(l.L,c.L)||Vd(l.V,c.V)||n.lx!==c.lx||n.ly!==c.ly||r.base!==c.base||a.shadow!==c.shadow||a.highlight!==c.highlight||a.spread!==c.spread||a.rim!==c.rim)&&(c.version>0&&c.mcPrev.set(c.mcMix),Nd(c.mc,bd(r.base),l,a),c.version===0?(c.mcMix.set(c.mc),c.blendT=1):(c.blendFrames=Math.min(10,Math.max(1,c.sinceBuild)),c.blendT=0),c.sinceBuild=0,c.mixVersion++,c.L=l.L,c.V=l.V,c.lx=n.lx,c.ly=n.ly,c.base=r.base,c.shadow=a.shadow,c.highlight=a.highlight,c.spread=a.spread,c.rim=a.rim,c.version++,c.near=c.rimG=c.far=null),c.sinceBuild++,c.blendT<1){c.blendT=Math.min(1,c.blendT+1/c.blendFrames);let e=c.blendT>=1?1:c.blendT*c.blendT*(3-2*c.blendT),t=c.mcPrev,n=c.mc,r=c.mcMix;for(let i=0;i<Vu*3;i++)r[i]=t[i]+(n[i]-t[i])*e;c.mixVersion++}let d=Math.min(1.3,1.2*a.shadow);if(d!==c.aoK){for(let e=0;e<256;e++)c.aoMul[e]=Math.max(0,1-d*(1-e/255));c.aoK=d}if((!c.img||c.N!==o)&&(c.img=new ImageData(o,o),c.N=o,c.imgVersion=-1),(c.imgVersion!==c.mixVersion||c.imgAoK!==d||c.imgForm!==s)&&(Fd(s,c.mcMix,c.img.data,c.aoMul),c.imgVersion=c.mixVersion,c.imgAoK=d,c.imgForm=s,c.scratchStale=!0),c.scratchN!==o&&(c.scratch=[null,null],c.scratchN=o,c.scratchStale=!0),c.scratchStale){c.scratchIdx^=1;let e=c.scratch[c.scratchIdx];if(!e){let t=nd(o),n=t&&rd(t,!1);if(!t||!n)return!1;e=c.scratch[c.scratchIdx]={c:t,g:n}}e.g.putImageData(c.img,0,0),c.scratchStale=!1}let f=c.scratch[c.scratchIdx],p=t.sides===`sprite`||t.sides!==`vector`&&Wd;if(p){let e=Math.ceil(106*n.dev/100);if(c.spritePx!==e&&(c.sprites=[null,null,null],c.spritePx=e,c.spriteVersion=-1),c.spriteVersion!==c.version){let n=e/106;for(let r=0;r<3&&p;r++){let i=c.sprites[r];if(!i){let t=nd(e),n=t&&rd(t,!1);if(!t||!n){p=!1;break}i=c.sprites[r]={c:t,g:n}}i.g.setTransform(1,0,0,1,0,0),i.g.clearRect(0,0,e,e),i.g.setTransform(n,0,0,n,3*n,3*n),i.g.fillStyle=Ud(i.g,c.mc,Gd[r][0],Gd[r][1](a),u),i.g.fill(t.path)}p&&(c.spriteVersion=c.version)}}!p&&!c.near&&(c.near=Ud(e,c.mc,.55,0,u),c.rimG=Ud(e,c.mc,0,0,u),c.far=Ud(e,c.mc,0,Math.min(.6,.25*a.shadow),u));let{cy:m,sy:h,cp:g,sp:_,halfDepth:v,cap:y}=n,b=n.facing>=0?1:-1,[x,S,C,w,T,E]=n.ctm,D=null;p&&(e.imageSmoothingEnabled=!0,e.imageSmoothingQuality=`high`);let O=1,k=0,A=0,j=1,M=0,N=0;for(let n=0;n<16;n++){let r=-1+2*(b>0?n:16-n)/16,i=qu(r,y),a=r*b,o=m*i,s=h*_*i,l=g*i,u=r*h*v-50*o,d=-r*m*_*v-50*s-50*l,f=O*j-k*A,x=j/f,S=-k/f,C=-A/f,w=O/f,T=(A*N-j*M)/f,E=(k*M-O*N)/f;e.transform(x*o+C*s,S*o+w*s,C*l,w*l,x*u+C*d+T,S*u+w*d+E),O=o,k=s,A=0,j=l,M=u,N=d;let P=a>.4?0:a>=0?1:2;if(p)e.drawImage(c.sprites[P].c,-3,-3,106,106);else{let n=P===0?c.near:P===1?c.rimG:c.far;n!==D&&(e.fillStyle=D=n),e.fill(t.path)}}e.setTransform(x,S,C,w,T,E);let P=1/(m*g),F=h*v/m,I=-_*v*P,L=Math.hypot(F,I),R=L>1e-6?b*F/L:1,z=L>1e-6?b*I/L:0,ee=50*y+Math.hypot(50*(1-y),L),B=(ee+50)/100,te=(ee-50)/2,ne=1+(B-1)*R*R,re=(B-1)*R*z,V=1+(B-1)*z*z,H=Hd(Hd(n.ctm,[m,h*_,0,g,0,0]),[ne,re,re,V,te*R-50*ne-50*re,te*z-50*re-50*V]);if(e.save(),e.setTransform(H[0],H[1],H[2],H[3],H[4],H[5]),e.clip(t.path),e.imageSmoothingEnabled=!0,e.imageSmoothingQuality=`high`,e.drawImage(f.c,-3,-3,106,106),e.restore(),n.dev>=256&&a.rim>0&&a.highlight>0){e.save(),e.globalCompositeOperation=`source-atop`,e.setTransform(H[0],H[1],H[2],H[3],H[4],H[5]);let n=Math.min(.5,.3*a.rim*Math.min(1.4,a.highlight)),r=e.createLinearGradient(50+u[0]*50,50+u[1]*50,50-u[0]*50,50-u[1]*50);r.addColorStop(0,`rgba(235,244,255,${n.toFixed(3)})`),r.addColorStop(.45,`rgba(235,244,255,${(.35*n).toFixed(3)})`),r.addColorStop(.75,`rgba(235,244,255,0)`),e.strokeStyle=r,e.lineJoin=`round`,e.lineWidth=1.3,e.stroke(t.path),e.restore()}return!0}var qd=1.5,Jd=.1,Yd=17,Xd=15,Zd=(e,t)=>t+(1-t)*Math.sqrt(Math.max(0,1-e*e)),Qd=25,$d=6.3,ef={eyes:1,mouth:-3.5},tf=new Map;function nf(e,t,n){let r=`${e}|${t}|${n}`,i=tf.get(r);if(!i){let a=uu(e,-.3*t,.05*t),o=uu(e,-.12*t,.03*t),s=[],c=[];for(let t=0;t<Yd;t++){let n=t/16;s.push(n>.6?``:af(a,o,n/.6)),c.push(n>=.5?e:af(a,e,n/.5))}i={base:e,far:a,near:o,light:uu(e,.04*n),dark:uu(e,-.3*t,.05*t),capTop:uu(e,.035*n),capBottom:uu(e,-.035*t),crispMix:s,smoothMix:c,grad:null},tf.size>200&&tf.clear(),tf.set(r,i)}return i}var rf=e=>(e.startsWith(`hsl(`)?e:uu(e,0)).match(/[\d.]+/g).map(Number);function af(e,t,n){let r=rf(e),i=rf(t),a=r.map((e,t)=>e+(i[t]-e)*n);return`hsl(${a[0].toFixed(1)} ${a[1].toFixed(1)}% ${a[2].toFixed(1)}%)`}var of=34,sf=Math.PI*1.55,cf=57,lf=.4,uf=-.28,df=new Map;function ff(e){let t=df.get(e);return t||(t={base:uu(e,.1,.02),light:uu(e,.3,.04),dark:uu(e,-.22,.08),halo:uu(e,.2)},df.size>200&&df.clear(),df.set(e,t)),t}var pf=(e,t)=>e.replace(`)`,` / ${Math.max(0,Math.min(1,t)).toFixed(3)})`);function mf(e,t,n,r,i,a,o){let s=o?.strength??0,c=Math.min(1,t.whirl*s);if(c<=.01)return;let l=o?.size??1,u=o?.width??1,d=o?.length??1,f=o?.tilt??1,p=sf*d,m=ff(n),h=-t.whirlAngle,g=cf*l,_=g*lf*f*(a?1.14:.86),v=Math.atan2(i,r)-uf;e.save(),e.rotate(uf),e.translate(0,5),e.lineCap=`butt`;let y=(t,n,r,i,a)=>{e.strokeStyle=i,e.lineWidth=r,e.beginPath(),e.ellipse(0,a,g,_,0,t,n,!1),e.stroke()};if(a)for(let e=0;e<of;e++){let t=e/of,n=h+t*p,r=n+p/of+.012;if(Math.sin((r+n)/2)<=0)continue;let i=(1-t)**1.3;y(n,r,(2+8*i)*1.5*u,`rgba(0,0,0,${(.2*c*i).toFixed(3)})`,3.5)}for(let e=0;e<of;e++){let t=e/of,n=h+t*p,r=n+p/of+.012,i=(r+n)/2;if(Math.sin(i)>0!==a)continue;let o=.6+.4*Math.sin(i),s=(1-t)**1.3,l=1+.18*Math.sin(t*9+1.2),d=(2+8*s)*o*u*l,f=c*(.3+.7*s)*o,g=.5+.5*Math.cos(i-v);y(n,r,d*2.6,pf(m.halo,f*.2),0),y(n,r,d*.8,pf(m.dark,f*.45),d*.32),y(n,r,d,pf(m.base,f*.72),0),y(n,r,d*.62,pf(m.light,f*.78*(.4+.6*g)),-d*.16),y(n,r,d*.24,`rgba(255,255,255,${(f*.9*(.15+.85*g*g)).toFixed(3)})`,-d*.3)}e.restore()}function hf(e,t,n,r){let i=t*qd;e.clearRect(0,0,i,i);let a=t/100,o,s;if(r.dpr!==void 0)o=r.dpr,s=[o,0,0,o,0,0];else if(e.getTransform){let t=e.getTransform();s=[t.a,t.b,t.c,t.d,t.e,t.f],o=t.a||1}else o=1,s=[1,0,0,1,0,0];let c=r.shadow??.35,l=r.highlight??1.3,u=Xd*(r.depth??.65),d=1-.09999999999999998*(r.rim??.5),f=r.spread??1.55,p=(r.light??265)*Math.PI/180,m=Math.sin(p),h=-Math.cos(p),g=nf(r.color,c,l),_=Math.cos(n.yaw),v=Math.sin(n.yaw),y=Math.cos(n.pitch),b=Math.sin(n.pitch),x=_*y,S=e=>Math.abs(e)<.22?e<0?-.22:.22:e,C=S(_),w=S(y),T=Math.cos(n.roll),E=Math.sin(n.roll),D=n.sx*a,O=n.sy*a,k=50*(1-n.sy)*a,A=Hd(s,[T*D,E*D,-E*O,T*O,i/2+n.x*a-E*k,i/2+Jd*t+n.y*a+T*k]);e.save(),e.setTransform(A[0],A[1],A[2],A[3],A[4],A[5]),e.lineCap=`round`,e.lineJoin=`round`;let j=r.shading,M=(i,a,s)=>{let u=g.near,p=g.base;if(j===`crisp`){if(!g.grad||g.grad.lx!==m||g.grad.ly!==h){let t=e.createLinearGradient(m*56,h*56,-m*56,-h*56);t.addColorStop(0,g.light),t.addColorStop(.45,g.near),t.addColorStop(1,g.dark);let n=e.createLinearGradient(m*46,h*46,-m*46,-h*46);n.addColorStop(0,g.capTop),n.addColorStop(1,g.capBottom),g.grad={lx:m,ly:h,lit:t,cap:n}}u=g.grad.lit,p=g.grad.cap}let _=!1;j===`plastic`&&(_=Kd(e,{...r,path:i,typeKey:a},{cy:C,sy:v,cp:w,sp:b,facing:x,roll:n.roll,halfDepth:s,cap:d,lx:m,ly:h,dev:t*o,ctm:A,still:r.still},g,null,{shadow:c,highlight:l,spread:f,rim:r.rim??.5}));let y=j===`plastic`&&!_?`smooth`:j,S=y===`smooth`,T=S&&typeof Path2D==`function`?new Path2D:null,E=x>=0?1:-1,[D,O,k,M,N,P]=A,F=null,I=1,L=0,R=0,z=1,ee=0,B=0;for(let t=0;t<Yd&&!_;t++){let n=-1+2*(E>0?t:16-t)/16,r=Zd(n,d),a=t/16,o=C*r,c=v*b*r,l=w*r,f=n*v*s-50*o,m=-n*C*b*s-50*c-50*l,h=I*z-L*R,_=z/h,y=-L/h,x=-R/h,D=I/h,O=(R*B-z*ee)/h,k=(L*ee-I*B)/h;e.transform(_*o+x*c,y*o+D*c,x*l,D*l,_*f+x*m+O,y*f+D*m+k),I=o,L=c,R=0,z=l,ee=f,B=m;let A;A=S?g.smoothMix[t]:t===16?p:a>.6?u:g.crispMix[t],A!==F&&(e.fillStyle=F=A),e.fill(i),T&&T.addPath(i,{a:o,b:c,c:0,d:l,e:f,f:m})}if(_||e.setTransform(D,O,k,M,N,P),T&&y===`smooth`){e.save(),e.clip(T);let t=Math.min(1,.34*c),n=e.createRadialGradient(-m*45,-h*45,4*f,-m*45,-h*45,84*f);n.addColorStop(0,`rgba(0,0,0,${t})`),n.addColorStop(.5,`rgba(0,0,0,${t*.35})`),n.addColorStop(1,`rgba(0,0,0,0)`),e.globalCompositeOperation=`multiply`,e.fillStyle=n,e.fillRect(-120,-120,240,240),e.globalCompositeOperation=`source-over`;let r=Math.min(1,.22*l),i=e.createRadialGradient(m*37,h*37,0,m*37,h*37,62*f);i.addColorStop(0,`rgba(255,255,255,${r})`),i.addColorStop(.6,`rgba(255,255,255,${r*.23})`),i.addColorStop(1,`rgba(255,255,255,0)`),e.fillStyle=i,e.fillRect(-120,-120,240,240),e.restore()}return _};mf(e,n,r.color,m,h,!1,r.whirl),r.parts&&M(r.parts,`${r.typeKey??`custom`}:parts`,u*(r.partsDepth??.4));let N=M(r.path,r.typeKey??`custom`,u);if(x>-.2){e.save();{let t=x>=0?1:-1,n=Zd(t,d),i=C*n,a=v*b*n,o=w*n,s=t*v*u-50*i,c=-t*C*b*u-50*a-50*o,[l,f,p,m,h,g]=A;e.setTransform(l*i+p*a,f*i+m*a,p*o,m*o,l*s+p*c+h,f*s+m*c+g),e.clip(r.path),e.setTransform(l,f,p,m,h,g)}e.translate(r.faceX-50,r.faceY-50),e.scale(r.faceScale,r.faceScale),N&&(e.globalAlpha=.93),Tf(e,n,r),e.restore()}mf(e,n,r.color,m,h,!0,r.whirl),e.restore()}var gf=30;function _f(e,t,n,r){let i=Math.asin(Math.max(-1,Math.min(1,e/gf)))+n,a=Math.asin(Math.max(-1,Math.min(1,-t/gf)))+r,o=Math.cos(a);return{x:gf*Math.sin(i)*o,y:-30*Math.sin(a),sx:Math.cos(i),sy:o,z:Math.cos(i)*o}}var vf=8,yf=new Map;function bf(e,t,n){let r=Math.round(e*50),i=Math.round(t*50),a=Math.round(n*50),o=r+2e3*i+4e6*a,s=yf.get(o);if(!s){let e=r/50,t=i/50,n=a/50,c=`M${-e} ${t}`;for(let r=1;r<=vf;r++){let i=r/vf,a=1-i;c+=` L${(a*a*-e+i*i*e).toFixed(3)} ${((a*a+i*i)*t+2*a*i*n).toFixed(3)}`}s=new Path2D(c),yf.size>256&&yf.clear(),yf.set(o,s)}return s}var xf=Math.sin(.684),Sf=Math.cos(.684),Cf=new Map;function wf(e){let t=e=>Math.round(e*50)/50,n=t(e.hw),r=t(e.t0),i=t(e.a),a=t(e.yt),o=t(e.ab),s=t(e.yb),c=`${n},${r},${i},${a},${o},${s}`,l=Cf.get(c);if(l)return l;let u=e=>e.toFixed(3),d=r*xf,f=r*Sf,p=-n+d,m=-f,h=n-d,g=-f,_=-n-d,v=f,y=n+d,b=f,x=4/3*r*Sf,S=4/3*r*xf,C=`M${u(p)} ${u(m)}C${u(-n+i*n)} ${u(a-r)} ${u(n-i*n)} ${u(a-r)} ${u(h)} ${u(g)}C${u(h+x)} ${u(g-S)} ${u(y+x)} ${u(b-S)} ${u(y)} ${u(b)}C${u(n-o*n)} ${u(s+r)} ${u(-n+o*n)} ${u(s+r)} ${u(_)} ${u(v)}C${u(_-x)} ${u(v-S)} ${u(p-x)} ${u(m-S)} ${u(p)} ${u(m)}Z`;return l=new Path2D(C),Cf.size>256&&Cf.clear(),Cf.set(c,l),l}function Tf(e,t,n){let[r,i,a]=t.w,o=n.ink,s=ef[n.face],c=Qd/2,l=t.lookX,u=t.lookY,{yaw:d,pitch:f}=t,p=(t,n,r,i=1)=>{let a=_f(t,n,d,f);a.z<=.02||i<=.01||(e.save(),e.globalAlpha=i*Math.min(1,a.z*5),e.translate(a.x,a.y),e.scale(Math.max(.02,a.sx),Math.max(.02,a.sy)),r(),e.restore())},m=(e,t)=>Math.abs(e)<=t?0:Math.sign(e)*(Math.abs(e)-t)/(1-t),h=e=>Math.max(-1,Math.min(1,e)),g=m(h(-t.pitch/.26-t.lookY/7),.34),_=Math.abs(m(h(t.lookX/4.5),.4)),v=Math.max(.3,1+.55*g-.1*_),y=1-.05*g+.12*_,b=r+i*(1-t.laugh),x=i*t.laugh,S=Math.max(0,-t.y)/26,C=.5+.5*t.breath;for(let n of[-1,1]){let r=n<0?t.blinkL:t.blinkR,i=Math.max(0,Math.min(1,t.eyeOpen*(1-r))),d=b*i,f=b*(1-i),m=x,h=a,g=d*.01+f*5.4+m*6.2+h*6,_=d*1.1*v+f*.6+m*(2.2-S*1.5)+h*(-1.4+C),w=d*-3.3*v+f*.6+m*(-11.4-4*S)+h*(5.4+2*C),T=d*$d*2*y+f*2.8+m*4.4+h*4,E=l*(d+.5*(f+m)),D=u*(d+.5*f);p(n*c+E,s+D,()=>{e.strokeStyle=o,e.lineWidth=T,e.stroke(bf(g,_,w))})}if(n.face===`mouth`){let n=l*.35,s=(.6+.4*r)*(1+.06*t.breath),c=(.6+.4*i)*(1+.25*Math.max(0,-t.y)/26),u=2.7*a*(1+.25*t.breath),d=(e,t,n)=>r*e+i*t+a*n,f={hw:d(6.5*s,9.5*c,u),t0:d(1.9,0,0),a:d(2/3,2/3,0),yt:d(3.53*s,1.6*c,-4*u/3),ab:d(2/3,0,0),yb:d(3.53*s,17.3*c,4*u/3)};p(n,d(12.5,11.6,15.5),()=>{e.fillStyle=o,e.fill(wf(f))})}}var Ef={x:NaN,y:NaN},Df=new Set,Of=0,kf=0;function Af(e){Of=0;let t=kf?Math.min(.1,(e-kf)/1e3):0;kf=e,Df.forEach(e=>e(t)),Df.size&&(Of=requestAnimationFrame(Af))}function jf(){Of||typeof document>`u`||document.hidden||(kf=0,Of=requestAnimationFrame(Af))}var Mf=!1;function Nf(){Mf||typeof document>`u`||(Mf=!0,document.addEventListener(`pointermove`,e=>{Ef.x=e.clientX,Ef.y=e.clientY},{passive:!0}),document.addEventListener(`pointerleave`,()=>{Ef.x=NaN,Ef.y=NaN}),window.addEventListener(`blur`,()=>{Ef.x=NaN,Ef.y=NaN}),document.addEventListener(`visibilitychange`,()=>{document.hidden?(Of&&cancelAnimationFrame(Of),Of=0):Df.size&&jf()}))}function Pf(e){return Nf(),Df.add(e),jf(),()=>{Df.delete(e),!Df.size&&Of&&(cancelAnimationFrame(Of),Of=0)}}function Ff(e){let t=2166136261;for(let n=0;n<e.length;n++)t=Math.imul(t^e.charCodeAt(n),16777619);return(t>>>0)%1e3/1e3}var If=(e,t,n)=>Math.min(n,Math.max(t,Number.isFinite(e)?e:1)),Lf=new Map;function Rf(e){let t=Lf.get(e);return t||(t=new Path2D(e),Lf.set(e,t)),t}var zf=()=>typeof matchMedia==`function`&&matchMedia(`(prefers-reduced-motion: reduce)`).matches,Bf=(0,l.forwardRef)(function({type:e=`clover`,path:t,face:n,state:r=`default`,size:i=64,color:a,ink:o,brightness:s=1,saturation:c=1.5,speed:u=1,paused:d=!1,seed:f,shading:p=`plastic`,shadow:m=.35,highlight:h=1.3,depth:g=.65,light:_=265,rim:v=.5,spread:y=1.55,interactive:b=!0,turn:x=1,theme:S=`auto`,whirl:C=0,whirlSize:w=1,whirlWidth:T=1,whirlLength:E=1,whirlTilt:D=1,jumpHeight:O=26,jumpTime:k=.68,jumpStretch:A=1,jumpSpin:j=1,jumpLean:M=6,jumpEvery:N=8,jumpLand:P=0,jumpSquash:F=1.15,jumpSquashTime:I=.37,jumpSquashEase:L=`pulse`,jumpGroundTime:R=.11,jumpGroundEase:z=`pulse`,jumpRiseTime:ee=.33,jumpRiseEase:B=`pulse`,jumpClickSquashTime:te=.24,className:ne,style:re,"aria-label":V,...H},ie){let ae=(0,l.useRef)(null);(0,l.useImperativeHandle)(ie,()=>ae.current);let oe=(0,l.useId)(),se=Xl[e]??Xl.clover,ce=n??se.face,le=a??se.color,ue=s===1&&c===1?le:uu(le,(Math.min(2,Math.max(0,s))-1)*.35,(Math.min(2,Math.max(0,c))-1)*.5),de=o??au(ue),fe=Math.min(1,Math.max(0,f??Ff(oe))),U=r in Ql?r:`default`,pe=d||!(u>0),W=p===!0?`crisp`:p===!1?`flat`:p,me=typeof t==`string`&&t.trim()?t.trim():null,he=me?`path:${Ff(me)}:${me.length}`:e,ge=(0,l.useRef)(null),G=(0,l.useRef)(null),K=(0,l.useRef)(0),_e=(0,l.useRef)(u);_e.current=u;let ve=(0,l.useRef)(b);ve.current=b,G.current={path:typeof Path2D>`u`?null:Rf(me??$l[e]??$l.clover),face:ce,faceX:se.faceX,faceY:se.faceY,faceScale:se.faceScale,color:ue,ink:de,shading:W,shadow:If(m,0,2),highlight:If(h,0,2),depth:If(g,.2,2),light:_,rim:If(v,0,2),spread:If(y,.4,2.5),typeKey:he,still:pe||zf(),whirl:{strength:If(C,0,2),size:If(w,.6,1.6),width:If(T,.4,2),length:If(E,.4,1.6),tilt:If(D,.5,1.8)},parts:typeof Path2D<`u`&&!me&&eu[e]?Rf(eu[e]):void 0};let ye=e=>{if(S!==`auto`)return S;let t=e?.closest(`[data-theme], .dark, .light`);if(t){let e=t.getAttribute(`data-theme`);if(e===`dark`||e===`light`)return e;if(t.classList.contains(`dark`))return`dark`;if(t.classList.contains(`light`))return`light`}return typeof matchMedia==`function`&&matchMedia(`(prefers-color-scheme: light)`).matches?`light`:`dark`},be=()=>{let e=ae.current,t=G.current;if(!e||!t||!t.path)return;let n=e.clientWidth/1.5||K.current||(typeof i==`number`?i:64);if(!n)return;let r=Math.min(2,typeof devicePixelRatio==`number`&&devicePixelRatio||1),a=Math.round(n*qd*r);(e.width!==a||e.height!==a)&&(e.width=a,e.height=a),K.current=n;let o=e.getContext(`2d`);o&&(o.setTransform(r,0,0,r,0,0),t.dpr=r,hf(o,n,ge.current?ge.current.pose:zu(U),t))};(0,l.useLayoutEffect)(()=>{if(ge.current?ge.current.setState(U):ge.current=new Ru(fe,U),ge.current.setTurn(If(x,0,2)),ge.current.setJump({height:O,time:Math.max(.2,k),stretch:A,spin:Math.max(0,Math.round(j)),lean:M,every:N,land:P,squash:F,squashTime:Math.max(.05,I),squashEase:L,groundTime:Math.max(0,R),groundEase:z,riseTime:Math.max(.05,ee),riseEase:B,clickSquashTime:Math.max(.05,te)}),zf()){let e=ae.current;if(e&&G.current&&G.current.path){let t=e.clientWidth/1.5||K.current||(typeof i==`number`?i:64);if(!t)return;K.current=t;let n=Math.min(2,typeof devicePixelRatio==`number`&&devicePixelRatio||1);e.width=e.height=Math.round(t*qd*n);let r=e.getContext(`2d`);r&&(G.current.theme=ye(e),G.current.dpr=n,r.setTransform(n,0,0,n,0,0),hf(r,t,zu(U),G.current))}return}G.current&&ae.current&&(G.current.theme=ye(ae.current)),be()}),(0,l.useEffect)(()=>{var e;if(W!==`plastic`||!((e=G.current)!=null&&e.path))return;let t=G.current.path,n=(typeof i==`number`?i:64)*Math.min(2,typeof devicePixelRatio==`number`&&devicePixelRatio||1),r=(typeof requestIdleCallback==`function`?requestIdleCallback:e=>setTimeout(e,1))(()=>gd(he,t,n,g));return()=>{typeof cancelIdleCallback==`function`?cancelIdleCallback(r):clearTimeout(r)}},[W,he,i,g]),(0,l.useEffect)(()=>{if(pe||zf())return;let e=ae.current;if(!e)return;let t=!0,n=null,r=t=>{let n=ge.current;if(n){if(ve.current&&!Number.isNaN(Ef.x)){let t=e.getBoundingClientRect(),r=t.width/1.5||1,i=(Ef.x-(t.left+t.width/2))/r,a=(Ef.y-(t.top+t.height/2+Jd*r))/r,o=Math.hypot(i,a),s=o<1?1:o>3?0:1-(o-1)/2;n.setPointer(i/Math.max(1,o),a/Math.max(1,o),s)}else n.setPointer(0,0,0);n.update(t*_e.current),be()}},i=()=>{n||=Pf(r)},a=()=>{n&&n(),n=null},o=null;return typeof IntersectionObserver==`function`?(o=new IntersectionObserver(e=>{t=e[0]?.isIntersecting??!0,t?i():a()}),o.observe(e)):i(),()=>{a(),o&&o.disconnect()}},[pe]);let xe=typeof i==`number`?`${i*qd}px`:`calc(${i} * ${qd})`,Se=e=>typeof i==`number`?`${-i*e}px`:`calc(${i} * ${-e})`,Ce=.5/2,we={display:`inline-block`,verticalAlign:`middle`,width:xe,height:xe,marginLeft:Se(Ce),marginRight:Se(Ce),marginTop:Se(.35),marginBottom:Se(.15),flex:`none`,...re},Te=e=>{var t,n;b&&!pe&&((t=ge.current)==null||t.poke()),(n=H.onClick)==null||n.call(H,e)};return(0,Q.jsx)(`canvas`,{ref:ae,className:ne?`ba ${ne}`:`ba`,"data-bot-avatar":e,"data-face":ce,"data-state":U,role:`img`,"aria-label":V??`${se.label} bot, ${Ql[U]}`,style:we,...H,onClick:Te})}),Vf=137.508,Hf=e=>(e*Vf%360).toFixed(3);function Uf(e){let t=e.avatarIndex;return{type:Zl[t%Zl.length],color:`hsl(${Hf(t)} 72% 58%)`,seed:t*.61803398875%1}}var Wf=2e3,Gf=0;function Kf(e){let[t,n]=(0,l.useState)(!e);return(0,l.useEffect)(()=>{if(e){n(!1);return}let t=setTimeout(()=>n(!0),Wf);return()=>clearTimeout(t)},[e]),t}function qf({thread:e,working:t,size:n}){let r=Kf(t),i=r?`rest`:`moving`;return(0,Q.jsx)(Bf,{...Uf(e),state:t?`working`:`default`,size:n,paused:r,turn:t?void 0:Gf},i)}var Jf={nextThread:`Next thread`,previousThread:`Previous thread`,nextPane:`Next pane`,previousPane:`Previous pane`,toggleSidebar:`Toggle sidebar`,newThread:`New thread`,openTerminal:`New terminal`,closePane:`Close pane`},Yf={nextThread:`ctrl+j`,previousThread:`ctrl+k`,nextPane:`ctrl+l`,previousPane:`ctrl+h`,toggleSidebar:`meta+b`,newThread:`ctrl+x`,openTerminal:`ctrl+e`,closePane:`ctrl+q`};function Xf(){try{let e=JSON.parse(localStorage.getItem(`webr-shortcuts`)??`{}`);return{...Yf,...Object.fromEntries(Object.entries(e).filter(([e])=>Object.hasOwn(Yf,e)))}}catch{return Yf}}function Zf(e){let t={ctrl:`⌃`,alt:`⌥`,meta:`⌘`,shift:`⇧`,space:`Space`,escape:`Esc`};return e.split(`+`).map(e=>t[e]??e.toUpperCase())}function Qf(e){return Zf(e).join(``)}function $f(e){let t=[e.ctrlKey&&`ctrl`,e.altKey&&`alt`,e.metaKey&&`meta`,e.shiftKey&&`shift`].filter(Boolean),n=e.key.toLowerCase()===` `?`space`:e.key.toLowerCase();return[`control`,`alt`,`meta`,`shift`].includes(n)?``:[...t,n].join(`+`)}function ep(e){return/^(meta\+(w|t|r|l|n)|ctrl\+(w|t|r|n))$/.test(e)||!/(ctrl|alt|meta)\+/.test(e)}function tp(e){let t=window.matchMedia(`(prefers-color-scheme: dark)`).matches;document.documentElement.dataset.theme=e===`system`?t?`dark`:`light`:e}function np({expanded:e=!1}){let[t,n]=(0,l.useState)(`system`);(0,l.useEffect)(()=>{let e=localStorage.getItem(`webr-theme`),t=e===`light`||e===`dark`?e:`system`;n(t),tp(t);let r=window.matchMedia(`(prefers-color-scheme: dark)`),i=()=>{let e=localStorage.getItem(`webr-theme`)||`system`;n(e),tp(e)};return r.addEventListener(`change`,i),window.addEventListener(`webr-theme-change`,i),()=>{r.removeEventListener(`change`,i),window.removeEventListener(`webr-theme-change`,i)}},[]);let r=e=>{n(e),localStorage.setItem(`webr-theme`,e),tp(e)};return(0,Q.jsx)(`div`,{className:e?`theme-control theme-control--expanded`:`theme-control`,role:`group`,"aria-label":`Color theme`,children:[[`system`,z],[`light`,le],[`dark`,ee]].map(([n,i])=>(0,Q.jsx)(Yl,{label:`${n[0].toUpperCase()}${n.slice(1)} theme`,children:(0,Q.jsxs)(`button`,{type:`button`,"aria-label":`${n} theme`,"aria-pressed":t===n,className:t===n?`theme-option is-selected`:`theme-option`,onClick:()=>r(n),children:[(0,Q.jsx)(i,{size:15,strokeWidth:1.8}),e&&(0,Q.jsx)(`span`,{children:n})]})},n))})}var rp={machine_disconnected:`The machine is not connected.`,launch_in_progress:`Wait for the launch to finish, then try again.`,thread_not_found:`This thread does not exist anymore.`};async function ip(e,t={}){let n=await fetch(e,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)}),r=await n.json().catch(()=>({}));if(!n.ok)throw Error(rp[r.error??``]??`Herdr could not complete this action.`);return r}var ap=(e,t)=>ip(`/api/threads/${encodeURIComponent(e.id)}/archive`,{machineId:e.machineId,archived:t}),op=(e,t)=>ip(`/api/threads/${encodeURIComponent(e.id)}/rename`,{machineId:e.machineId,title:t}),sp=(e,t)=>ip(`/api/projects/rename`,{machineId:e.machineId??`local`,logicalId:e.logicalId??e.id,name:t}),cp=e=>`/api/projects/icon?machineId=${encodeURIComponent(e.machineId??`local`)}&logicalId=${encodeURIComponent(e.logicalId??e.id)}`;async function lp(e,t){if(!(await fetch(cp(e),{method:`PUT`,headers:{"Content-Type":`image/png`},body:t})).ok)throw Error(`Could not save this icon.`)}async function up(e){if(!(await fetch(cp(e),{method:`DELETE`})).ok)throw Error(`Could not reset this icon.`)}var dp=(e,t)=>ip(`/api/threads/${encodeURIComponent(e.id)}/panes/terminal`,{machineId:e.machineId,afterPaneId:t}),fp=(e,t,n)=>ip(`/api/threads/${encodeURIComponent(e.id)}/panes/close`,{machineId:e.machineId,paneId:t,force:n}),pp=e=>ip(`/api/threads/${encodeURIComponent(e.id)}/delete`,{machineId:e.machineId}),mp=()=>ip(`/api/archive/delete`),hp=(e,t,n)=>e===1?t:n;function gp(e){let t=e.length,n=e.filter(e=>e.ownsWorktree).length,r=hp(t,`Delete this thread`,`Delete ${t} threads`),i=hp(t,`its terminal`,`their terminals`);return n?`${r} permanently? This closes ${i} and removes ${n===t?hp(t,`its worktree`,`their worktrees`):`${n} ${hp(n,`worktree`,`worktrees`)}`}, including uncommitted changes.`:`${r} permanently? This closes ${i}. Your project files stay untouched.`}var _p=(e,t)=>e.panes.length>1&&e.panes.some(e=>e.id===t&&e.kind!==`agent`),vp=(e,t)=>e[t-1]??e[t+1];function yp(e,t,n){let r=e.findIndex(e=>e.id===n);return e.slice(t,t+2).find(e=>e.id!==n)??vp(e,r)}function bp(e,t,n,r=2){let i=n<0?t:n<t?n:n>=t+r?n-r+1:t;return Math.max(0,Math.min(i,e-r))}function xp(e){let t=performance.now();return()=>performance.now()-t}var Sp=()=>performance.now();function Cp(){}var wp=e=>ol(e instanceof Error?e.message:`Herdr could not complete this action.`);function Tp({open:e,onClose:t,projects:n,threads:r,thread:i,focusedPane:o,mode:s,onModeChange:c,onToggleSidebar:u,onFocusPane:d,onTerminalAction:v,onOpenTerminal:y,onClosePane:b}){let[x,S]=(0,l.useState)(``),[C,w]=(0,l.useState)(0),[T,E]=(0,l.useState)(Yf),O=(0,l.useRef)(null);(0,l.useEffect)(()=>{e&&(S(``),w(0),E(Xf()),requestAnimationFrame(()=>O.current?.focus()))},[e]);let k=e=>{let t=r.findIndex(e=>e.id===i?.id),n=r[((t===-1&&e<0?0:t)+e+r.length)%r.length];n&&a(`/threads/${encodeURIComponent(n.id)}`)},j=e=>{i?.panes.length&&d(i.panes[(i.panes.findIndex(e=>e.id===o)+e+i.panes.length)%i.panes.length].id)},M=(0,l.useMemo)(()=>[{label:`New thread`,icon:(0,Q.jsx)(oe,{size:16}),shortcut:`newThread`,run:()=>{a(`/new${i?`?project=${encodeURIComponent(i.projectId)}`:``}`)}},{label:`Settings`,icon:(0,Q.jsx)(ae,{size:16}),run:()=>{a(`/settings`)}},{label:`Toggle sidebar`,icon:(0,Q.jsx)(ne,{size:16}),shortcut:`toggleSidebar`,run:u},...r.length?[{label:`Next thread`,icon:(0,Q.jsx)(m,{size:16}),shortcut:`nextThread`,run:()=>k(1)},{label:`Previous thread`,icon:(0,Q.jsx)(_,{size:16}),shortcut:`previousThread`,run:()=>k(-1)}]:[],{label:`Group threads by project`,icon:(0,Q.jsx)(A,{size:16}),detail:s===`projects`?`Selected`:void 0,run:()=>c(`projects`)},{label:`Show all threads`,icon:(0,Q.jsx)(F,{size:16}),detail:s===`threads`?`Selected`:void 0,run:()=>c(`threads`)},...[`system`,`light`,`dark`].map(e=>({label:`${e[0].toUpperCase()}${e.slice(1)} theme`,icon:e===`system`?(0,Q.jsx)(z,{size:16}):e===`light`?(0,Q.jsx)(le,{size:16}):(0,Q.jsx)(ee,{size:16}),run:()=>{localStorage.setItem(`webr-theme`,e),tp(e),window.dispatchEvent(new Event(`webr-theme-change`))}})),...i?[{label:i.archivedAt?`Unarchive thread`:`Archive thread`,icon:i.archivedAt?(0,Q.jsx)(f,{size:16}):(0,Q.jsx)(p,{size:16}),run:()=>{ap(i,!i.archivedAt).catch(wp)}},{label:`Copy thread link`,icon:(0,Q.jsx)(D,{size:16}),run:()=>{navigator.clipboard.writeText(location.href)}},...i.bindingState===`attached`?[{label:`New terminal`,icon:(0,Q.jsx)(se,{size:16}),shortcut:`openTerminal`,run:y},..._p(i,o)?[{label:`Close pane`,icon:(0,Q.jsx)(fe,{size:16}),shortcut:`closePane`,run:b}]:[]]:[],...i.bindingState===`attached`?[{label:`Request terminal control`,icon:(0,Q.jsx)(se,{size:16}),run:()=>v(`control`)},{label:`Release terminal control`,icon:(0,Q.jsx)(se,{size:16}),run:()=>v(`release`)},{label:`Take over terminal control`,icon:(0,Q.jsx)(se,{size:16}),run:()=>{al(`Replace the active controller of this terminal?`,{confirmLabel:`Take over`}).then(e=>{e&&v(`takeover`)})}}]:[],{label:`Next pane`,icon:(0,Q.jsx)(g,{size:16}),shortcut:`nextPane`,run:()=>j(1)},{label:`Previous pane`,icon:(0,Q.jsx)(h,{size:16}),shortcut:`previousPane`,run:()=>j(-1)},...i.panes.map((e,t)=>({label:`Focus ${e.title}`,icon:(0,Q.jsx)(se,{size:16}),detail:`Pane ${t+1}`,run:()=>d(e.id)}))]:[],...r.map(e=>({label:e.title,icon:(0,Q.jsx)(qf,{thread:e,working:e.status===`working`,size:22}),detail:n.find(t=>t.id===e.projectId)?.name,run:()=>{a(`/threads/${encodeURIComponent(e.id)}`)}}))],[n,r,i,o,s,c,u,d,v,y,b]).filter(e=>`${e.label} ${e.detail??``}`.toLowerCase().includes(x.toLowerCase().trim()));if(!e)return null;let N=e=>{t(),e.run()};return(0,Q.jsx)(`div`,{className:`palette-overlay`,onMouseDown:e=>{e.target===e.currentTarget&&t()},children:(0,Q.jsxs)(`div`,{className:`palette`,role:`dialog`,"aria-modal":`true`,"aria-label":`Command palette`,onKeyDown:e=>{e.key===`Escape`&&(e.preventDefault(),t()),e.key===`ArrowDown`&&(e.preventDefault(),w(e=>(e+1)%(M.length||1))),e.key===`ArrowUp`&&(e.preventDefault(),w(e=>(e-1+(M.length||1))%(M.length||1))),e.key===`Enter`&&M.length&&(e.preventDefault(),N(M[Math.min(C,M.length-1)])),e.key===`Tab`&&(e.preventDefault(),O.current?.focus())},children:[(0,Q.jsx)(`input`,{ref:O,"aria-label":`Search commands and threads`,placeholder:`Search threads and actions…`,value:x,onChange:e=>{S(e.target.value),w(0)}}),(0,Q.jsxs)(`div`,{className:`palette-results`,role:`listbox`,"aria-label":`Results`,children:[M.map((e,t)=>(0,Q.jsxs)(`button`,{role:`option`,"aria-selected":C===t,className:C===t?`is-selected`:``,onMouseEnter:()=>w(t),onClick:()=>N(e),children:[(0,Q.jsx)(`span`,{className:`palette-icon`,"aria-hidden":`true`,children:e.icon}),(0,Q.jsx)(`span`,{className:`palette-label`,children:e.label}),e.detail&&(0,Q.jsx)(`small`,{children:e.detail}),e.shortcut&&(0,Q.jsx)(Yl,{label:T[e.shortcut],children:(0,Q.jsx)(`kbd`,{children:Qf(T[e.shortcut])})})]},`${e.label}-${t}`)),!M.length&&(0,Q.jsx)(`p`,{children:`No results`})]}),(0,Q.jsxs)(`div`,{className:`palette-help`,children:[`↑↓ Navigate `,(0,Q.jsx)(`span`,{children:`↵ Select`}),` `,(0,Q.jsx)(`span`,{children:`Esc Close`})]})]})})}var Ep=2e3,Dp=e=>fetch(e,{method:`POST`,headers:{"Content-Type":`application/json`},body:`{}`});async function Op(){let e=await Dp(`/api/pair/invites`);if(!e.ok)throw Error(`Webr could not create a code.`);return e.json()}async function kp(){let e=await fetch(`/api/devices`);if(!e.ok)throw Error(`Webr could not list devices.`);return e.json()}async function Ap(){let e=await fetch(`/api/audit`);if(!e.ok)throw Error(`Webr could not load recent activity.`);return e.json()}async function jp(){let e=await fetch(`/api/remote/tailscale`);return e.ok?(await e.json()).status:`unavailable`}var Mp=e=>Dp(`/api/devices/${encodeURIComponent(e)}/revoke`),Np=(e,t)=>Dp(`/api/pair/${encodeURIComponent(e)}/${t}`);async function Pp(){try{let e=await fetch(`/api/pair/pending`);return e.ok?await e.json():[]}catch{return[]}}var Fp=()=>typeof Notification<`u`&&Notification.permission===`granted`,Ip=()=>document.visibilityState===`visible`||Fp();function Lp(e,t){if(document.visibilityState!==`visible`&&Fp())for(let n of e)t.has(n.id)||(t.add(n.id),new Notification(`A device wants to connect to Webr`,{body:`${n.deviceName} · ${n.source}`,tag:n.id}))}function Rp(){let[e,t]=(0,l.useState)([]),n=(0,l.useRef)(new Set),r=(0,l.useCallback)(async()=>{if(!Ip())return;let e=await Pp();Lp(e,n.current),t(e)},[]);return(0,l.useEffect)(()=>{r();let e=setInterval(()=>void r(),Ep);return document.addEventListener(`visibilitychange`,r),()=>{clearInterval(e),document.removeEventListener(`visibilitychange`,r)}},[r]),{pending:e,decide:(0,l.useCallback)(async(e,n)=>{t(t=>t.filter(t=>t.id!==e)),await Np(e,n).catch(()=>void 0),await r()},[r])}}function zp(e,t=Date.now()){let n=Math.round((e-t)/1e3),[r,i]=[[`day`,86400],[`hour`,3600],[`minute`,60]].find(([,e])=>Math.abs(n)>=e)??[`second`,1];return Math.abs(n)<45?`just now`:new Intl.RelativeTimeFormat(`en`,{numeric:`auto`}).format(Math.round(n/i),r)}var Bp=()=>typeof Notification<`u`,Vp=()=>Bp()?Notification.permission:`denied`,Hp=()=>Notification.requestPermission();function Up({kind:e,deviceName:t,source:n}){let r=t??`A device`,i=n?` from ${n}`:``;return{pair_requested:`${r} asked to connect${i}`,pair_approved:`${r} was approved${i}`,pair_denied:`${r} was declined${i}`,invite_created:`A connection code was created${i}`,invite_redeemed:`${r} connected with a code${i}`,device_revoked:`${r} was disconnected`,session_expired:`${r} was signed out after being idle`}[e]}function Wp(e,t=Date.now()){return e<=t?`expired`:new Intl.RelativeTimeFormat(`en`,{numeric:`auto`}).format(...Gp(e-t))}function Gp(e){let t=Math.round(e/864e5);return t>=1?[t,`day`]:[Math.max(1,Math.round(e/36e5)),`hour`]}function Kp(){let{pending:e,decide:t}=Rp(),n=e[0];return(0,Q.jsx)(Dc,{open:!!n,onOpenChange:e=>{!e&&n&&t(n.id,`deny`)},children:(0,Q.jsxs)(Jc,{children:[(0,Q.jsx)(Oc,{className:`dialog-backdrop`}),(0,Q.jsx)(Gc,{className:`dialog pairing-prompt`,children:n&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(Yc,{className:`pairing-title`,children:[`Allow `,n.deviceName,` to connect?`]}),(0,Q.jsxs)(Rc,{className:`dialog-message`,children:[`Requested from `,n.source,`. Only approve if this code matches the one shown on that device.`]}),(0,Q.jsx)(`div`,{className:`pairing-code`,"aria-label":`Code ${n.code}`,children:n.code}),e.length>1&&(0,Q.jsxs)(`p`,{className:`settings-note`,children:[e.length-1,` more waiting`]}),(0,Q.jsxs)(`div`,{className:`dialog-actions`,children:[(0,Q.jsx)(`button`,{type:`button`,className:`dialog-button`,onClick:()=>void t(n.id,`deny`),children:`Deny`}),(0,Q.jsx)(`button`,{type:`button`,autoFocus:!0,className:`dialog-button is-primary`,onClick:()=>void t(n.id,`approve`),children:`Approve`})]})]})})]})})}var qp=({children:e})=>(0,Q.jsx)(Q.Fragment,{children:e}),Jp=[`image/png`,`image/jpeg`,`image/gif`,`image/webp`],Yp={image_too_large:`This image is larger than 20 MB.`,file_too_large:`This file is larger than 5 MB.`,empty_file:`This file is empty.`,unsupported_image:`Only PNG, JPEG, GIF and WebP images can be attached.`,uploads_unsupported_target:`Images can be attached only on the Local machine for now.`,machine_disconnected:`The machine is not connected.`},Xp=e=>Jp.includes(e.type),Zp=e=>e?.files?[...e.files].filter(Xp):[],Qp=e=>e?.files?[...e.files]:[],$p=e=>!!e?.types&&[...e.types].includes(`Files`),em=e=>e.replace(/([\s\\'"()&;$`!*?[\]{}<>|#~])/g,`\\$1`);async function tm(e,t){if(!Xp(t))throw Error(Yp.unsupported_image);if(t.size>20971520)throw Error(Yp.image_too_large);let n=await fetch(`/api/uploads?machineId=${encodeURIComponent(e)}`,{method:`POST`,headers:{"Content-Type":t.type},body:t}),r=await n.json().catch(()=>({}));if(!n.ok||!r.path)throw Error(Yp[r.error??``]??`The image could not be attached.`);return r.path}async function nm(e,t){if(Xp(t))return tm(e,t);if(t.size>5242880)throw Error(Yp.file_too_large);let n=await fetch(`/api/uploads?machineId=${encodeURIComponent(e)}&name=${encodeURIComponent(t.name)}`,{method:`POST`,headers:{"Content-Type":`application/octet-stream`},body:t}),r=await n.json().catch(()=>({}));if(!n.ok||!r.path)throw Error(Yp[r.error??``]??`The file could not be attached.`);return r.path}var rm=160,im=e=>new Promise((t,n)=>{let r=new FileReader;r.onload=()=>t(String(r.result)),r.onerror=()=>n(r.error),r.readAsDataURL(e)});async function am(e){if(typeof createImageBitmap!=`function`)return im(e);let t=await createImageBitmap(e),n=Math.min(1,rm/Math.max(t.width,t.height)),r=document.createElement(`canvas`);return r.width=Math.max(1,Math.round(t.width*n)),r.height=Math.max(1,Math.round(t.height*n)),r.getContext(`2d`)?.drawImage(t,0,0,r.width,r.height),t.close(),r.toDataURL(`image/jpeg`,.8)}async function om(e,t){let n=[];for(let r of t)n.push(await nm(e,r));return n.map(em).join(` `)+` `}var sm=e=>Array.from(e,e=>e.toString(16).padStart(2,`0`)).join(``);function cm(){if(typeof crypto.randomUUID==`function`)return crypto.randomUUID();let e=crypto.getRandomValues(new Uint8Array(16));e[6]=e[6]&15|64,e[8]=e[8]&63|128;let t=sm(e);return`${t.slice(0,8)}-${t.slice(8,12)}-${t.slice(12,16)}-${t.slice(16,20)}-${t.slice(20)}`}var lm=`Nothing to attach.`,um=e=>Xp(e)?am(e):Promise.resolve(``),dm=(e,t)=>[e.trim(),...t.map(e=>em(e.path))].filter(Boolean).join(` `);function fm({machineId:e}){let[t,n]=(0,l.useState)(!1),[r,i]=(0,l.useState)([]),[a,o]=(0,l.useState)(0),[s,c]=(0,l.useState)(``),u=(0,l.useRef)(0),d=async t=>{if(!t.length){c(lm);return}c(``),o(e=>e+t.length);for(let n of t)try{let t=await nm(e,n),r=await um(n);i(e=>[...e,{id:cm(),name:n.name||`file`,preview:r,path:t}])}catch(e){c(e instanceof Error?e.message:`The file could not be attached.`)}finally{o(e=>e-1)}};return{dragging:t,attachments:r,setAttachments:i,uploading:a,error:s,remove:e=>i(t=>t.filter(t=>t.id!==e)),handlers:{onDragEnter:e=>{$p(e.dataTransfer)&&(e.preventDefault(),u.current+=1,n(!0))},onDragOver:e=>{$p(e.dataTransfer)&&(e.preventDefault(),e.dataTransfer.dropEffect=`copy`)},onDragLeave:e=>{$p(e.dataTransfer)&&(u.current=Math.max(0,u.current-1),u.current||n(!1))},onDrop:e=>{$p(e.dataTransfer)&&(e.preventDefault(),u.current=0,n(!1),d(Qp(e.dataTransfer)))},onPaste:e=>{let t=Zp(e.clipboardData);t.length&&(e.preventDefault(),d(t))}}}}function pm({controlled:e,default:t,name:n,state:r=`value`}){let{current:i}=l.useRef(e!==void 0),[a,o]=l.useState(t);return[i&&e!==void 0?e:a,l.useCallback(e=>{i||o(e)},[])]}function mm(e){let t=l.useRef(!0);t.current&&(t.current=!1,e())}function hm(e,t,n,r,i,a,o,s,c,l=2){let u=Nr(n.current,{event:e,orientation:r,loopFocus:i,rtl:a,cols:l,disabledIndices:o,minIndex:s,maxIndex:c,prevIndex:t>c?s:t,stopEvent:!0});return kr(n.current,u)?void 0:u}var gm=l.createContext(void 0),_m=l.createContext(void 0),vm=l.createContext(void 0),ym=l.createContext(!1),bm=l.createContext(``);function xm(){let e=l.useContext(gm);if(!e)throw Error(Ai(22));return e}function Sm(){let e=l.useContext(_m);if(!e)throw Error(Ai(23));return e}function Cm(){let e=l.useContext(vm);if(!e)throw Error(Ai(24));return e}function wm(){return l.useContext(bm)}function Tm(){return l.useContext(ym)}function Em(e,t,n=Object.is){let{length:r}=e;if(r!==t.length)return!1;for(let i=0;i<r;i+=1)if(!n(e[i],t[i]))return!1;return!0}var Dm=(e,t)=>Object.is(e,t);function Om(e,t,n){return e==null||t==null?Object.is(e,t):n(e,t)}function km(e,t,n){return Array.isArray(e)&&Array.isArray(t)?!Em(e,t,(e,t)=>Om(e,t,n)):e!==t}function Am(e,t,n){return e?e.some(e=>e!==void 0&&Om(t,e,n)):!1}function jm(e,t,n){return e?e.findIndex(e=>e!==void 0&&Om(e,t,n)):-1}function Mm(e,t){if(t!==Dm)return n=>Am(e,n,t);let n=new Set(e);return n.delete(void 0),t=>n.has(t)&&(t!==0||e.some(e=>Object.is(t,e)))}function Nm(e,t,n,r){let i=r&&Array.isArray(t)?e.findIndex(Mm(t,n)):jm(e,t,n);return i===-1?null:i}function Pm(e,t,n,r,i,a){return Am(r,t,i)?a!=null&&e>a&&Am(r,n[a],i)?a:e:e===a?Nm(n,r,i,!0):a}function Fm(e,t,n){return e.filter(e=>!Om(t,e,n))}function Im(e){if(e==null)return``;if(typeof e==`string`)return e;try{return JSON.stringify(e)}catch{return String(e)}}function Lm(e){return typeof e==`object`&&!!e&&Array.isArray(e.items)}function Rm(e){return Lm(e?.[0])}function zm(e){return Rm(e)?e.flatMap(e=>e.items):e}function Bm(e){if(!Array.isArray(e))return e!=null&&`null`in e;let t=e;if(Rm(t)){for(let e of t)for(let t of e.items)if(t&&t.value==null&&t.label!=null)return!0;return!1}for(let e of t)if(e&&e.value==null&&e.label!=null)return!0;return!1}function Vm(e,t){if(t&&e!=null)return t(e)??``;if(e&&typeof e==`object`){if(`label`in e&&e.label!=null)return String(e.label);if(`value`in e)return String(e.value)}return Im(e)}function Hm(e,t){return t&&e!=null?t(e)??``:e&&typeof e==`object`&&`value`in e&&`label`in e?Im(e.value):Im(e)}var Um={id:e=>e.id,labelId:e=>e.labelId,items:e=>e.items,selectedValue:e=>e.selectedValue,hasSelectionChips:e=>{let t=e.selectedValue;return Array.isArray(t)&&t.length>0},hasSelectedValue:e=>{let{selectedValue:t,selectionMode:n}=e;return t==null?!1:n===`multiple`&&Array.isArray(t)?t.length>0:!0},hasNullItemLabel:(e,t)=>t?Bm(e.items):!1,open:e=>e.open,mounted:e=>e.mounted,forceMounted:e=>e.forceMounted,inline:e=>e.inline,activeIndex:e=>e.activeIndex,selectedIndex:e=>e.selectedIndex,isActive:(e,t)=>e.activeIndex===t,isSelected:(e,t)=>{let n=e.isItemEqualToValue,r=e.selectedValue;return Array.isArray(r)?r.some(e=>Om(t,e,n)):Om(t,r,n)},transitionStatus:e=>e.transitionStatus,popupProps:e=>e.popupProps,listProps:e=>e.listProps,inputProps:e=>e.inputProps,triggerProps:e=>e.triggerProps,itemProps:e=>e.itemProps,positionerElement:e=>e.positionerElement,listElement:e=>e.listElement,popupId:e=>e.popupId,triggerElement:e=>e.triggerElement,inputElement:e=>e.inputElement,inputGroupElement:e=>e.inputGroupElement,popupSide:e=>e.popupSide,openMethod:e=>e.openMethod,inputInsidePopup:e=>e.inputInsidePopup,inputOwnsFormValue:e=>e.inputOwnsFormValue,selectionMode:e=>e.selectionMode,name:e=>e.name,form:e=>e.form,disabled:e=>e.disabled,readOnly:e=>e.readOnly,required:e=>e.required,grid:e=>e.grid,virtualized:e=>e.virtualized,itemToStringLabel:e=>e.itemToStringLabel,isItemEqualToValue:e=>e.isItemEqualToValue,modal:e=>e.modal,autoHighlight:e=>e.autoHighlight},Wm=`data-valid`,Gm=`data-invalid`,Km={badInput:!1,customError:!1,patternMismatch:!1,rangeOverflow:!1,rangeUnderflow:!1,stepMismatch:!1,tooLong:!1,tooShort:!1,typeMismatch:!1,valid:null,valueMissing:!1},qm={valid:null,touched:!1,dirty:!1,filled:!1,focused:!1},Jm={disabled:!1,...qm},Ym={valid(e){return e===null?null:e?{[Wm]:``}:{[Gm]:``}}},Xm={invalid:void 0,name:void 0,validityData:{state:Km,errors:[],error:``,value:``,initialValue:null},setValidityData:Qe,disabled:void 0,setTouched:Qe,setDirty:Qe,setFilled:Qe,setFocused:Qe,validationMode:`onSubmit`,shouldValidateOnChange:()=>!1,state:Jm,registerFieldControl:Qe,validation:{getValidationProps:(e,t=et)=>t,inputRef:{current:null},registeredInputs:new Map,registerInput:Qe,getInputControl:()=>null,commit:async()=>{},change:Qe}},Zm=l.createContext(Xm);function Qm(e=!0){let t=l.useContext(Zm);if(t.setValidityData===Qe&&!e)throw Error(Ai(28));return t}function $m(e,t,n,r,i=!0,a){let{registerFieldControl:o}=Qm(),s=Ze(()=>Symbol());U(()=>{let c=s.current;if(!i){o(c,void 0);return}o(c,{controlRef:e,getValue:r,id:t,name:a,value:n})},[e,i,r,t,a,o,s,n]),U(()=>{let e=s.current;return()=>{o(e,void 0)}},[o,s])}var eh=l.createContext({elementRef:{current:null},formRef:{current:{fields:new Map}},errors:{},clearErrors:Qe,validationMode:`onSubmit`,submitCountRef:{current:0}});function th(){return l.useContext(eh)}var nh=l.createContext({controlId:void 0,registerControlId:Qe,resetControlId:Qe,labelId:void 0,setLabelId:Qe,messageIds:[],setMessageIds:Qe,getDescriptionProps:e=>e});function rh(){return l.useContext(nh)}function ih(e={}){let{id:t,enabled:n=!0}=e,{controlId:r,registerControlId:i,resetControlId:a}=rh(),o=Lc(),s=Ze(()=>Symbol()),c=l.useRef(!1),u=l.useRef(!1),d=$(()=>{c.current&&i!==Qe&&(c.current=!1,i(s.current,void 0))});return U(()=>{if(!n||i===Qe){d();return}let e;if(t!==void 0)u.current=!0,e=t;else if(u.current)e=o;else{a();return}if(e===void 0){d();return}c.current=!0,i(s.current,e)},[t,n,i,a,o,s,d]),U(()=>d,[d]),(n?r:void 0)??t??o}function ah(e){return e==null?void 0:`${e}-popup`}function oh(e,t){return(n,r)=>n!=null&&e.contains(n,r,t)}function sh(e){return Array.isArray(e)?e.map(e=>sh(e)).join(`,`):e==null?``:String(e)}var ch=new Map;function lh(e={}){let t={usage:`search`,sensitivity:`base`,ignorePunctuation:!0,...e},n=`${sh(e.locale)}|${JSON.stringify(t)}`,r=ch.get(n);if(r)return r;let i=new Intl.Collator(e.locale,t),a={contains(e,t,n){if(!t)return!0;let r=Vm(e,n);for(let e=0;e<=r.length-t.length;e+=1)if(i.compare(r.slice(e,e+t.length),t)===0)return!0;return!1},startsWith(e,t,n){if(!t)return!0;let r=Vm(e,n);return i.compare(r.slice(0,t.length),t)===0},endsWith(e,t,n){if(!t)return!0;let r=Vm(e,n),a=t.length;return r.length>=a&&i.compare(r.slice(r.length-a),t)===0}};return ch.set(n,a),a}var uh=lh;function dh(e,t=!1){let{overflowY:n}=ke(e);return n!==`auto`&&n!==`scroll`?!1:t?e.clientHeight>0:e.scrollHeight>e.clientHeight}var fh=Symbol(`none`),ph={value:fh,index:-1};function mh(e,t,n){let r=e.get(t);if(r!==void 0||n===Dm)return r;for(let[r,i]of e)if(Om(r,t,n))return i}function hh(e){let{id:t,onOpenChangeComplete:n,defaultSelectedValue:r=null,selectedValue:i,onSelectedValueChange:a,defaultInputValue:o,inputValue:s,open:c,defaultOpen:u=!1,selectionMode:d,onItemHighlighted:f,name:p,form:m,disabled:h=!1,readOnly:g=!1,required:_=!1,inputRef:v,grid:y=!1,items:b,filteredItems:x,filter:S,filterQuery:C,openOnInputClick:w=!0,autoHighlight:T=!1,keepHighlight:E=!1,highlightItemOnHover:D=!0,loopFocus:O=!0,itemToStringLabel:k,itemToStringValue:A,isItemEqualToValue:j=Dm,virtualized:M=!1,inline:N=!1,fillInputOnItemPress:P=!0,modal:F=!1,limit:I=-1,autoComplete:L=`list`,formAutoComplete:R,locale:z,submitOnItemClick:ee=!1}=e,{clearErrors:B}=th(),{setDirty:te,validityData:ne,setFilled:re,name:V,disabled:H,setTouched:ie,setFocused:ae,validationMode:oe,validation:se}=Qm(),ce=Ol(),le=ih({id:t}),ue=uh({locale:z}),de=Array.isArray(b)?null:b;if(de&&typeof de.label!=`function`)throw Error(Ai(100));let fe=de?de.data:b,pe=de?.value,W=pe?void 0:fe,me=l.useMemo(()=>{if(!x||!pe)return;let e=zm(x),t=e.map(pe),n;return{values:t,findItem(r,i){if(!n){n=new Map;for(let r=0;r<t.length;r+=1)n.has(t[r])||n.set(t[r],e[r])}return mh(n,r,i)}}},[x,pe]),he=l.useMemo(()=>de?e=>de.label(e,j,e=>{let t=me?.findItem(e,j);return t==null?Vm(e,k):de.itemLabel(t)}):k,[de,k,me,j]),ge=l.useMemo(()=>de?Object.assign(e=>de.itemLabel(e),{selected:e=>Vm(e,he)}):k,[de,he,k]);function G(e){return Vm(e,he)}let[_e,ve]=l.useState(!1),[ye,be]=l.useState(null),xe=l.useRef(ye),Se=l.useRef([]),Ce=l.useRef([]),we=l.useRef(null),Te=l.useRef(null),Ee=l.useRef(null),De=l.useRef(null),Oe=l.useRef(null),ke=l.useRef(!0),Ae=l.useRef(!1),je=l.useRef(null),Me=l.useRef(null),Pe=l.useRef(null),q=l.useRef(ph),Fe=l.useRef(null),Ie=l.useRef([]),Le=l.useRef(null),Re=H||h,ze=V??p,Be=d===`multiple`,Ve=d===`single`,He=s!==void 0||o!==void 0,Ue=fe!==void 0,We=x!==void 0,Ge;Ge=T===`always`?`always`:T?`input-change`:!1;let[Ke,qe]=pm({controlled:i,default:Be?r??$e:r,name:`Combobox`,state:`selectedValue`}),Je=l.useMemo(()=>S===null?()=>!0:S===void 0?oh(ue,ge):S,[S,ue,ge]),Ye=Ze(()=>He?o??``:Ve?G(Ke):``).current,[J,Xe]=pm({controlled:s,default:Ye,name:`Combobox`,state:`inputValue`}),[tt,nt]=pm({controlled:c,default:u,name:`Combobox`,state:`open`}),rt=Rm(fe),it=!tt&&ye!==null?ye:String(J).trim(),at=Ve?G(Ke):``,ot=Ve&&!_e&&it!==``&&at.length===it.length&&ue.contains(at,it),st=ot?``:C??it,ct=Ue&&We&&ot&&(!de||de.hasValue(Ke,j)),lt=l.useMemo(()=>fe?zm(fe):$e,[fe]),ut=l.useMemo(()=>{if(x&&!ct)return x;if(!fe)return $e;if(rt){let e=fe,t=[],n=0;for(let r of e){if(I>-1&&n>=I)break;let e=I>-1?I-n:1/0,i=st===``?r.items.slice(0,e):[];if(st!==``)for(let t of r.items){if(i.length>=e)break;Je(t,st,ge)&&i.push(t)}if(i.length>0){let e={...r,items:i};t.push(e),n+=i.length}}return t}if(st===``)return I>-1?lt.slice(0,I):lt;let e=[];for(let t of lt){if(I>-1&&e.length>=I)break;Je(t,st,ge)&&e.push(t)}return e},[x,ct,fe,rt,st,I,Je,ge,lt]),dt=l.useMemo(()=>{if(me&&ut===x)return me.values;let e=zm(ut);return pe?e.map(e=>pe(e)):e},[ut,x,me,pe]),Y=Ze(()=>{let e=null;return N&&tt&&Ue&&d!==`none`&&(e=Nm(dt,Ke,j,Be)),new ds({id:le,labelId:void 0,selectedValue:Ke,open:tt,items:W,selectionMode:d,name:ze,form:m,disabled:Re,readOnly:g,required:_,grid:y,virtualized:M,openOnInputClick:w,itemToStringLabel:he,isItemEqualToValue:j,modal:F,autoHighlight:Ge,submitOnItemClick:ee,hasInputValue:He,mounted:!1,forceMounted:!1,transitionStatus:`idle`,inline:N,activeIndex:null,selectedIndex:e,popupProps:{},listProps:{},inputProps:{},triggerProps:{},itemProps:et,positionerElement:null,listElement:null,popupId:void 0,triggerElement:null,inputElement:null,inputGroupElement:null,popupSide:null,openMethod:null,inputInsidePopup:!0,inputOwnsFormValue:d===`none`},{onOpenChangeComplete:Qe,setOpen:Qe,setInputValue:Qe,setSelectedValue:Qe,setIndices:Qe,handleSelection:Qe,forceMount:Qe,requestSubmit:Qe,listRef:Se,labelsRef:Ce,popupRef:we,emptyRef:Oe,inputRef:Te,startDismissRef:Ee,endDismissRef:De,keyboardActiveRef:ke,chipsContainerRef:je,clearRef:Me,valuesRef:Ie,pointerDownItemRef:Le,selectionEventRef:Pe},Um)}).current,ft=d===`none`?J:Ke,pt=l.useMemo(()=>d===`none`?ft:Array.isArray(Ke)?Ke.map(e=>Hm(e,A)):Hm(Ke,A),[ft,A,d,Ke]),mt=$(f),ht=$(n),gt=Y.useState(`activeIndex`),_t=Y.useState(`selectedIndex`),vt=Y.useState(`positionerElement`),yt=Y.useState(`listElement`),bt=Y.useState(`triggerElement`),xt=Y.useState(`inputElement`),St=Y.useState(`inputGroupElement`),Ct=Y.useState(`inline`),wt=Y.useState(`inputInsidePopup`),Tt=Y.useState(`inputOwnsFormValue`),Dt=Ve&&!wt&&J===at,Ot=Wn(bt),{mounted:kt,setMounted:At,transitionStatus:jt}=hs(tt),{openMethod:Mt,triggerProps:Nt}=$c(tt),Pt=$(()=>pt);$m(wt?Ot:Te,le,ft,Pt,!Re,p);let Ft=$(()=>{fe?Ce.current=dt.map(G):Y.set(`forceMounted`,!0)}),It=$((e,t,n)=>{if(t===-1){if(q.current===ph)return;q.current=ph}else q.current={value:e,index:t};mt(e,Mn(n,void 0,{index:t}))}),Lt=$(e=>{let t={};e.activeIndex!==void 0&&(t.activeIndex=e.activeIndex),e.selectedIndex!==void 0&&(t.selectedIndex=e.selectedIndex),Y.update(t);let n=e.activeIndex;if(n===void 0)return;let r=e.type||`none`;n===null?It(void 0,-1,r):It(Ie.current[n],n,r)}),Rt=$((t,n)=>{if(e.onInputValueChange?.(t,n),!n.isCanceled){if(Ae.current=n.reason===xn,n.reason===`input-change`){tt&&ye!==null&&be(null);let e=n.event,r=e.inputType;if(e.type===`compositionend`||r!=null&&r!==``&&r!==`insertReplacementText`){let e=t.trim()!==``;e&&ve(!0),Fe.current={hasQuery:e};let n=Y.state.listElement;if(!Y.state.virtualized&&n){let e=we.current;for(let t of Ne(n.firstElementChild??n)){if(!K(t)||(e?!X(e,t):t.getAttribute(`role`)===`dialog`))break;if(dh(t)){t.scrollTop=0;break}}}e&&Ge&&Y.state.activeIndex==null&&(tt||Ct)&&Y.set(`activeIndex`,0)}}else n.reason===`input-clear`&&t===``&&Y.state.inputInsidePopup&&(Fe.current={hasQuery:!1,selection:!0});Xe(t)}}),zt=$(e=>{let t=!e&&wt&&!Ct&&J!==``&&(String(J).trim()===ye||J===at);!e&&(t||J===``||Dt)&&ve(!1),be(null),t&&Rt(``,Z(xn))}),Bt=$((t,n)=>{if(tt!==t&&(n.reason===`escape-key`&&Ue&&dt.length===0&&!Oe.current&&n.allowPropagation(),e.onOpenChange?.(t,n),!n.isCanceled&&(t&&ye!==null&&zt(n.reason===bn),!t&&_e&&(Ve?(Ct||be(it),it===``&&ve(!1)):Be&&(Ct||be(it),wt&&Lt({activeIndex:null}),(!wt||Ct)&&Rt(``,Z(xn,n.event,void 0,{isItemPress:n.reason===vn})))),nt(t),!t&&wt&&(n.reason===`focus-out`||n.reason===`outside-press`)&&(ie(!0),ae(!1),oe===`onBlur`)))){let e=d===`none`?J:Ke;se.commit(e)}}),Vt=$((e,t)=>{a?.(e,t),!t.isCanceled&&(qe(e),(d===`none`&&we.current&&P||Ve&&!Y.state.inputInsidePopup)&&Rt(G(e),Z(t.reason,t.event)))}),Ht=$((e,t)=>{let n=Et(e),r=Pe.current??e;Pe.current=null;let i=Z(vn,r),a=n?.closest(`a`)?.getAttribute(`href`);if(a){a.startsWith(`#`)&&Bt(!1,i);return}if(Be){let e=Array.isArray(Ke)?Ke:[],n=Am(e,t,j),r=n?Fm(e,t,j):[...e,t];if(Vt(r,i),i.isCanceled||!(Te.current&&Te.current.value.trim()!==``))return;if(Y.state.inputInsidePopup){Rt(``,Z(xn,i.event,void 0,{isItemPress:!0}));let e=Fe.current;e&&!n&&(e.toggledValue=t)}else Bt(!1,i)}else{if(Vt(t,i),i.isCanceled)return;Bt(!1,i)}}),Ut=$(()=>{let e=se.inputRef.current?.form??Y.state.inputElement?.form;e&&typeof e.requestSubmit==`function`&&e.requestSubmit()}),Wt=$(()=>{if(At(!1),ht?.(!1),ve(!1),be(null),Lt(d===`none`?{activeIndex:null,selectedIndex:null}:{activeIndex:null}),Be&&Te.current&&Te.current.value!==``&&!Ae.current&&Rt(``,Z(xn)),Ve){if(Y.state.inputInsidePopup)Te.current&&Te.current.value!==``&&Rt(``,Z(xn));else{let e=G(Ke);Te.current&&Te.current.value!==e&&Rt(e,Z(e===``?xn:pn))}}}),Gt=l.useMemo(()=>Ct&&vt?{current:vt.closest(`[role="dialog"]`)}:we,[Ct,vt]);ys({enabled:!e.actionsRef,open:tt,ref:Gt,onComplete(){tt||Wt()}}),l.useImperativeHandle(e.actionsRef,()=>({unmount:Wt}),[Wt]),U(function(){let e=xe.current!==null&&ye===null;if(xe.current=ye,tt&&(!e||!Ue)||(tt||(Le.current=null),d===`none`))return;let t=Ue?dt:Ie.current;Lt({selectedIndex:Nm(t,Ke,j,Be)})},[tt,ye,Ke,d,Be,Ue,dt,j,Lt]),U(()=>{fe&&(Ie.current=dt,Se.current.length=dt.length)},[fe,dt]),U(()=>{let e=Fe.current;if(e){let t=tt||Ct||Y.state.positionerElement?.hidden===!1;if(e.hasQuery)Ge&&t&&Y.set(`activeIndex`,0),Fe.current=null;else if(String(J).trim()===``&&(Fe.current=null,t)){let t=e.selection;Ge===`always`&&!t&&Y.state.selectionMode===`none`&&Y.set(`activeIndex`,0),queueMicrotask(()=>{if(!Y.state.open&&!Y.state.inline||Te.current&&Te.current.value.trim()!==``)return;let n=Y.state.selectedValue,r=Y.state.selectionMode===`multiple`;if(r&&Array.isArray(n)?n.length>0:Y.state.selectionMode!==`none`&&n!=null){let t=Ue||We?dt:Ie.current,i=jm(t,e.toggledValue,Y.state.isItemEqualToValue);Y.set(`activeIndex`,i===-1?Nm(t,n,Y.state.isItemEqualToValue,r):i)}else t?Y.set(`activeIndex`,null):Ge===`always`&&Y.set(`activeIndex`,0)})}}if(!tt&&!Ct)return;let t=Ue||We?dt:Ie.current,n=Y.state.activeIndex;if(n==null){if(Ge===`always`&&t.length>0){Y.set(`activeIndex`,0);return}It(void 0,-1,pn);return}if(n>=t.length){It(void 0,-1,pn),Y.set(`activeIndex`,null);return}let r=t[n],i=q.current.value,a=i!==fh&&Om(r,i,Y.state.isItemEqualToValue);(q.current.index!==n||!a)&&It(r,n,pn)},[gt,Ge,It,We,Ue,dt,Ct,tt,Y,J]),U(()=>{if(d===`none`){re(String(J)!==``);return}re(Be?Array.isArray(Ke)&&Ke.length>0:Ke!=null)},[re,d,J,Ke,Be]),l.useEffect(()=>{Ue&&Ge&&dt.length===0&&Lt({activeIndex:null})},[Ue,Ge,dt.length,Lt]);function Kt(){tt&&it!==``&&it!==String(Ye)&&!Dt&&ve(!0)}function qt(){tt&&ye!==null&&zt(!1)}let Jt=!1;function Yt(){!Jt&&J!==at&&(Jt=!0,Rt(at,Z(pn)))}function Xt(){d!==`none`&&(B(ze),te(km(Ke,ne.initialValue,j)),se.change(Ke),Ve&&!He&&!wt&&Yt())}function Zt(){Ve&&!He&&!wt&&!_e&&Yt()}function Qt(){d===`none`&&(B(ze),te(J!==ne.initialValue),se.change(J))}Zc(it,Kt),Zc(tt,qt),Zc(Ke,Xt),Zc(at,Zt),Zc(fe,Zt),Zc(J,Qt);let $t=Us({open:Ct?!0:tt,onOpenChange:Bt,elements:{reference:wt?bt:xt,floating:vt}}),en=y?`grid`:`listbox`,tn=tt||Ct,nn=tn?`true`:`false`,rn=l.useMemo(()=>{let e=xt?.tagName===`INPUT`,t=xt==null||e,n=t||tn,r=t?{autoComplete:`off`,spellCheck:`false`,autoCorrect:`off`,autoCapitalize:`none`}:{};return n&&(r.role=`combobox`,r[`aria-expanded`]=nn,r[`aria-haspopup`]=en,r[`aria-controls`]=tn?yt?.id:void 0,r[`aria-autocomplete`]=g?`none`:L),{reference:r,floating:{role:`presentation`}}},[xt,tn,nn,en,yt?.id,L,g]),an=Fa($t,{enabled:!Re&&w,event:`mousedown-only`,toggle:!1,touchOpenDelay:wt?0:100,reason:Sn}),on=Va($t,{enabled:!Re&&!Ct,outsidePressEvent:{mouse:`sloppy`,touch:`intentional`},bubbles:Ct?!0:void 0,outsidePress(e){let t=Et(e);return!X(bt,t)&&!X(Me.current,t)&&!X(je.current,t)&&!X(St,t)}}),sn=lc($t,{enabled:!Re,id:le,listRef:Se,activeIndex:gt,selectedIndex:_t,virtual:!0,loopFocus:O,allowEscape:O&&!Ge,focusItemOnOpen:_e||d===`none`&&!Ge?!1:`auto`,focusItemOnHover:D,resetOnPointerLeave:!E,orientation:y?`horizontal`:void 0,rtl:ce===`rtl`,disabledIndices:$e,grid:y?hm:void 0,onNavigate(e,t){(t||tt)&&jt!==`ending`&&Lt(t?{activeIndex:e,type:ke.current?En:Dn}:{activeIndex:e})}}),cn=l.useMemo(()=>zi(sn.reference,{onKeyDown(e){y&&Y.state.activeIndex==null&&(e.key===`ArrowLeft`||e.key===`ArrowRight`)&&e.preventBaseUIHandler()}},on.reference,an.reference,rn.reference),[sn.reference,on.reference,an.reference,rn.reference,y,Y]),ln=l.useMemo(()=>zi(bs,on.floating),[on.floating]),un=l.useMemo(()=>zi(sn.floating,rn.floating),[sn.floating,rn.floating]),dn=l.useMemo(()=>{let e=sn.item;return e?{...e,onFocus:void 0}:et},[sn.item]);Y.useContextCallback(`setOpen`,Bt),Y.useContextCallback(`setInputValue`,Rt),Y.useContextCallback(`setSelectedValue`,Vt),Y.useContextCallback(`setIndices`,Lt),Y.useContextCallback(`handleSelection`,Ht),Y.useContextCallback(`forceMount`,Ft),Y.useContextCallback(`requestSubmit`,Ut),Y.useContextCallback(`onOpenChangeComplete`,n),mm(()=>{Y.update({inline:N,popupProps:ln,listProps:un,inputProps:cn,triggerProps:Nt,itemProps:dn})});let fn={id:le,selectedValue:Ke,open:tt,mounted:kt,transitionStatus:jt,items:W,inline:N,popupProps:ln,listProps:un,inputProps:cn,triggerProps:Nt,itemProps:dn,openMethod:Mt,selectionMode:d,name:ze,form:m,disabled:Re,readOnly:g,required:_,grid:y,virtualized:M,openOnInputClick:w,itemToStringLabel:he,modal:F,autoHighlight:Ge,isItemEqualToValue:j,submitOnItemClick:ee,hasInputValue:He};U(()=>{Y.update({...fn,inputOwnsFormValue:d===`none`&&(N||!Y.state.inputInsidePopup)})},[Y,...Object.values(fn)]);let mn=Rn(v,se.inputRef),hn=l.useMemo(()=>({query:it,hasItems:Ue,filteredItems:ut,flatFilteredValues:dt}),[it,Ue,ut,dt]),gn=l.useMemo(()=>Array.isArray(ft)?``:Hm(ft,A),[ft,A]),_n=Be&&Array.isArray(Ke)&&Ke.length>0,yn=Be||d===`none`&&Tt?void 0:ze,Cn=l.useMemo(()=>!Be||!Array.isArray(Ke)||!ze?null:Ke.map(e=>{let t=Hm(e,A);return(0,Q.jsx)(`input`,{type:`hidden`,form:m,name:ze,value:t,disabled:Re},t)}),[Be,Ke,m,ze,A,Re]),wn=(0,Q.jsxs)(l.Fragment,{children:[e.children,(0,Q.jsx)(`input`,{...se.getValidationProps(Re,{onFocus(){if(wt){bt?.focus();return}(Te.current||bt)?.focus()},onChange(e){if(e.nativeEvent.defaultPrevented||Re||g)return;let t=e.currentTarget.value,n=t.toLowerCase(),r=Z(pn,e.nativeEvent),i=()=>Ie.current.findIndex(e=>Hm(e,A).toLowerCase()===n||G(e).toLowerCase()===n);function a(){if(Be)return;if(d===`none`){Rt(t,r);return}let e=i();e===-1&&(e=Ie.current.findIndex((e,t)=>{let r=Ce.current[t];return r!=null&&r.toLowerCase()===n}));let a=e===-1?void 0:Ie.current[e];a!=null&&Vt?.(a,r)}Ve&&(Ft(),fe&&i()===-1&&Y.set(`forceMounted`,!0)),queueMicrotask(a)}}),id:le&&yn==null?`${le}-hidden-input`:void 0,form:m,name:yn,autoComplete:R,disabled:Re,required:_&&!_n,readOnly:g,value:gn,ref:mn,style:yn?$n:Qn,tabIndex:-1,"aria-hidden":!0,suppressHydrationWarning:!0}),Cn]});return(0,Q.jsx)(gm.Provider,{value:Y,children:(0,Q.jsx)(_m.Provider,{value:$t,children:(0,Q.jsx)(ym.Provider,{value:Ue,children:(0,Q.jsx)(vm.Provider,{value:hn,children:(0,Q.jsx)(bm.Provider,{value:J,children:wn})})})})})}function gh(e){let{multiple:t=!1,defaultValue:n,value:r,onValueChange:i,autoComplete:a,...o}=e;return(0,Q.jsx)(hh,{...o,selectionMode:t?`multiple`:`single`,selectedValue:r,defaultSelectedValue:n,onSelectedValueChange:i,formAutoComplete:a})}function _h(e,t){return e??t}var vh=`data-popup-side`,yh=`data-list-empty`,bh={...Yt,...Ym,popupSide:e=>e?{[vh]:e}:null,listEmpty:e=>e?{[yh]:``}:null},xh=l.createContext(void 0);function Sh(){return l.useContext(xh)}var Ch=l.createContext(void 0);function wh(e){let t=l.useContext(Ch);if(t===void 0&&!e)throw Error(Ai(21));return t}var Th=l.forwardRef(function(e,t){let n=xm(),{buttonRef:r,getButtonProps:i}=Nc({native:!1}),a=Rn(t,r);function o(e){n.context.setOpen(!1,Z(yn,e.nativeEvent,e.currentTarget))}let s=i({onClick:o});return(0,Q.jsx)(`span`,{ref:a,...s,"aria-label":`Dismiss`,tabIndex:void 0,style:$n})});function Eh(e){let t=e.useState(`mounted`),n=e.useState(`popupSide`),r=e.useState(`positionerElement`);return t&&r?n:null}function Dh(){return Cm().filteredItems.length===0}function Oh(e){return e===`rtl`?[`ArrowRight`,`ArrowLeft`]:[`ArrowLeft`,`ArrowRight`]}function kh(e,t){let n=e>=t-1?t-2:e;return n>=0?n:void 0}function Ah(e,t,n){let r=e.context.listRef.current[t];r&&(e.context.selectionEventRef.current=n,r.click(),e.context.selectionEventRef.current=null)}var jh=l.forwardRef(function(e,t){let{render:n,className:r,disabled:i=!1,id:a,style:o,...s}=e,{state:c,disabled:u,setTouched:d,setFocused:f,validationMode:p,validation:m}=Qm(),{labelId:h}=rh(),g=Sh(),_=!!wh(!0),v=xm(),y=wm(),b=Ol(),x=v.useState(`required`),S=v.useState(`disabled`),C=v.useState(`readOnly`),w=v.useState(`name`),T=v.useState(`form`),E=v.useState(`selectionMode`),D=v.useState(`autoHighlight`),O=v.useState(`inputProps`),k=v.useState(`triggerProps`),A=v.useState(`open`),j=v.useState(`mounted`),M=v.useState(`selectedValue`),N=v.useState(`id`),P=v.useState(`inline`),F=v.useState(`modal`),I=!!D,L=Eh(v),R=u||S||i,z=Dh(),ee=_||P,B=!ee||F,te=Lc(a??(ee?void 0:N)),ne=_?qm:c,[re,V]=l.useState(null),H=l.useRef(!1),ie=l.useRef(null),ae=l.useRef(!1),oe=E===`none`&&!_,se=$(e=>{let t=_||v.state.inline;t&&!v.state.hasInputValue&&v.context.setInputValue(``,Z(pn)),v.update({inputElement:e,inputInsidePopup:t,inputOwnsFormValue:oe})}),ce=_?s:m.getValidationProps(R,s);function le(){v.context.setIndices({activeIndex:null,selectedIndex:null,type:v.context.keyboardActiveRef.current?En:Dn})}function ue(){v.context.keyboardActiveRef.current=!1}let de={...ne,open:A,disabled:R,readOnly:C,popupSide:L,listEmpty:z};function fe(e){if(!g)return;let t,{highlightedChipIndex:n}=g,r=g.chipsRef.current.length,[i,a]=Oh(b);return n===void 0?(e.key===i&&(e.currentTarget.selectionStart??0)===0&&M.length>0&&(e.preventDefault(),t=r>0?r-1:void 0),t):(e.key===i?(e.preventDefault(),t=n>0?n-1:void 0):e.key===a?(e.preventDefault(),t=n<r-1?n+1:void 0):(e.key===`Backspace`||e.key===`Delete`)&&(e.preventDefault(),t=kh(n,M.length),le()),t)}let U=$i(`input`,e,{state:de,ref:[t,v.context.inputRef,se],props:[O,k,{value:re??y,"aria-readonly":C||void 0,"aria-required":x||void 0,"aria-labelledby":h,disabled:R,readOnly:C,required:E===`none`?x:void 0,form:T,...oe&&w&&{name:w},id:te,onFocus(){if(f(!0),!P||!ae.current)return;ae.current=!1;let e=ie.current;e!=null&&Object.hasOwn(v.context.valuesRef.current,e)&&v.context.setIndices({activeIndex:e})},onBlur(){d(!0),f(!1);let e=v.state.activeIndex;if(P&&e!==null&&D!==`always`&&(ie.current=e,ae.current=!0,v.context.setIndices({activeIndex:null})),p===`onBlur`){let e=E===`none`?y:M;m.commit(e)}},onCompositionStart(e){Ue||(H.current=!0,V(e.currentTarget.value))},onCompositionEnd(e){H.current=!1;let t=e.currentTarget.value;V(null),v.context.setInputValue(t,Z(bn,e.nativeEvent))},onChange(e){let t=e.nativeEvent,n=t.inputType,r=!n||n===`insertReplacementText`,i=H.current||!r;function a(e){!C&&!R&&e&&i&&(v.context.setOpen(!0,Z(bn,t)),I||le())}if(H.current){let n=e.currentTarget.value;V(n),n===``&&!v.state.openOnInputClick&&!v.state.inputInsidePopup&&v.context.setOpen(!1,Z(xn,t));let r=n.trim(),i=I&&r!==``;a(r),A&&v.state.activeIndex!==null&&!i&&le();return}let o=Z(bn,t);if(v.context.setInputValue(e.currentTarget.value,o),o.isCanceled)return;let s=e.currentTarget.value===``,c=Z(xn,t);s&&!v.state.inputInsidePopup&&(E===`single`&&v.context.setSelectedValue(null,c),v.state.openOnInputClick||v.context.setOpen(!1,c)),a(e.currentTarget.value.trim()),A&&v.state.activeIndex!==null&&!I&&le()},onKeyDown(e){if(e.ctrlKey||e.shiftKey||e.altKey||e.metaKey)return;if(v.context.keyboardActiveRef.current=!0,R||C){C&&e.key===`Enter`&&A&&v.state.activeIndex!==null&&yt(e);return}let t=e.currentTarget,n=t.scrollWidth-t.clientWidth,r=b===`rtl`;if(e.key===`Home`){yt(e);let n=qe&&r?t.value.length:0;t.setSelectionRange(n,n),t.scrollLeft=0;return}if(e.key===`End`){yt(e);let i=qe&&r?0:t.value.length;t.setSelectionRange(i,i),t.scrollLeft=r?-n:n;return}if(!j&&e.key===`Escape`){let t=E===`multiple`&&Array.isArray(M)?M.length===0:M===null,n=Z(wn,e.nativeEvent),r=E===`multiple`?[]:null;v.context.setInputValue(``,n),v.context.setSelectedValue(r,n),!t&&!v.state.inline&&!n.isPropagationAllowed&&e.stopPropagation();return}if(g&&e.key===`Backspace`&&t.value===``&&g.highlightedChipIndex===void 0&&Array.isArray(M)&&M.length>0){let t=g.chipsRef.current.length,n=t>0?t-1:M.length-1,r=M.filter((e,t)=>t!==n);le(),v.context.setSelectedValue(r,Z(pn,e.nativeEvent));return}let i=g?.highlightedChipIndex!==void 0,a=fe(e);if(g?.setHighlightedChipIndex(a),a===void 0?i&&v.context.inputRef.current?.focus():g?.chipsRef.current[a]?.focus(),e.which!==229&&e.key===`Enter`&&A){let t=v.state.activeIndex,n=e.nativeEvent;if(t===null){if(P)return;v.context.setOpen(!1,Z(pn,n));return}yt(e),Ah(v,t,n)}},onPointerMove:ue,onPointerDown:ue},ce],stateAttributesMapping:bh}),pe=_?(0,Q.jsx)(Zm.Provider,{value:Xm,children:U}):U;return(0,Q.jsxs)(l.Fragment,{children:[A&&B&&(0,Q.jsx)(Th,{ref:v.context.startDismissRef}),pe]})}),Mh=5;function Nh(e,t){let n=Ph(t);return e.clientX>=n.left-Mh&&e.clientX<=n.right+Mh&&e.clientY>=n.top-Mh&&e.clientY<=n.bottom+Mh}function Ph(e){let t=e.getBoundingClientRect(),n=me(e);if(Ye)return t;let r=n.getComputedStyle(e,`::before`),i=n.getComputedStyle(e,`::after`);if(r.content===`none`&&i.content===`none`)return t;let a=parseFloat(r.width)||0,o=parseFloat(r.height)||0,s=parseFloat(i.width)||0,c=parseFloat(i.height)||0,l=Math.max(t.width,a,s),u=Math.max(t.height,o,c),d=l-t.width,f=u-t.height;return{left:t.left-d/2,right:t.right+d/2,top:t.top-f/2,bottom:t.bottom+f/2}}var Fh=l.forwardRef(function(e,t){let{render:n,className:r,nativeButton:i=!0,disabled:a=!1,id:o,style:s,...c}=e,{state:u,disabled:d,setTouched:f,setFocused:p,validationMode:m,validation:h}=Qm(),{labelId:g}=rh(),_=xm(),v=_.useState(`selectionMode`),y=_.useState(`disabled`),b=_.useState(`readOnly`),x=_.useState(`required`),S=_.useState(`positionerElement`),C=_.useState(`listElement`),w=_.useState(`popupId`),T=_.useState(`triggerProps`),E=_.useState(`inputInsidePopup`),D=_.useState(`id`),O=_.useState(`labelId`),k=_.useState(`open`),A=_.useState(`selectedValue`),j=_.useState(`activeIndex`),M=_.useState(`selectedIndex`),N=_.useState(`hasSelectedValue`),P=Sm(),F=wm(),I=it(),L=d||y||a,R=Dh(),z=Eh(_);ih({id:E?o:void 0});let ee=E?o??D:o,B=_h(g,O),te;k&&E?te=w??ah(D):k&&(te=C?.id);let ne=l.useRef(``);function re(e){ne.current=e.pointerType}let{reference:V}=uc(P,{enabled:!k&&!b&&!y&&v===`single`,listRef:_.context.labelsRef,activeIndex:j,selectedIndex:M,onMatch(e){let t=_.context.valuesRef.current[e];t!==void 0&&_.context.setSelectedValue(t,Z(pn))}}),{reference:H}=Fa(P,{enabled:!y,event:`mousedown`}),{buttonRef:ie,getButtonProps:ae}=Nc({native:i,disabled:L}),oe={...u,readOnly:b,open:k,disabled:L,popupSide:z,listEmpty:R,placeholder:v!==`none`&&!N};return $i(`button`,e,{ref:[t,ie,$(e=>{_.set(`triggerElement`,e)})],state:oe,props:[T,H,V,{id:ee,tabIndex:E?0:-1,role:E?`combobox`:void 0,"aria-expanded":k,"aria-haspopup":E?`dialog`:`listbox`,"aria-controls":te,"aria-required":E&&x||void 0,"aria-readonly":E&&b||void 0,"aria-labelledby":B,onPointerDown:re,onPointerEnter:re,onFocus(){p(!0),!L&&I.start(0,_.context.forceMount)},onBlur(e){if(!X(S,e.relatedTarget)&&(f(!0),p(!1),m===`onBlur`)){let e=v===`none`?F:A;h.commit(e)}},onMouseDown(e){if(L||(E||P.set(`domReferenceElement`,e.currentTarget),_.context.forceMount(),ne.current!==`touch`&&(_.context.inputRef.current?.focus(),E||e.preventDefault()),k))return;let t=J(e.currentTarget);function n(e){let t=_.state.triggerElement;if(!t)return;let n=Et(e),r=_.state.positionerElement,i=_.state.listElement;X(t,n)||X(r,n)||X(i,n)||Nh(e,t)||_.context.setOpen(!1,Z(On,e))}E&&t.addEventListener(`mouseup`,n,{once:!0})},onKeyDown(e){(e.key===`ArrowDown`||e.key===`ArrowUp`)&&(yt(e),_.context.setOpen(!0,Z(Tn,e.nativeEvent)),_.context.inputRef.current?.focus())}},h.getValidationProps(L,c),ae],stateAttributesMapping:bh})}),Ih=l.createContext(null);function Lh(){return l.useContext(Ih)}function Rh(e){let{children:t}=e,{filteredItems:n}=Cm(),r=Lh(),i=r?r.items:n;return(0,Q.jsx)(l.Fragment,{children:i.map(t)})}var zh=l.createContext({register:()=>{},unregister:()=>{},subscribeMapChange:()=>()=>{},nextIndexRef:{current:0}});function Bh(){return l.useContext(zh)}function Vh(e){let{children:t,elementsRef:n,labelsRef:r,onMapChange:i}=e,a=$(i),[,o]=l.useState(!1),s=Ze(Uh).current,c=Ze(Hh).current,u=l.useRef(0),d=l.useRef(!0),f=l.useRef(null),p=l.useRef(null),m=$(()=>{d.current||(d.current=!0,o(e=>!e))}),h=$((e,t)=>{c.set(e,t),m()}),g=$(e=>{c.delete(e),m()}),_=$(e=>{let t=new Map;return n.current.length=0,r&&(r.current.length=0),e.forEach(e=>{t.set(e.element,{...e.registration.metadata??{},index:e.index}),n.current[e.index]=e.element,r&&(r.current[e.index]=e.registration.label===void 0?e.registration.textRef?.current?.textContent??e.element.textContent:e.registration.label)}),u.current=n.current.length,t});function v(e){if(p.current?.disconnect(),p.current=null,typeof MutationObserver!=`function`||e.length<2)return;let t=new MutationObserver(n=>{if(!Kh(n))return;let r=null;for(let n of e)if(n.isConnected){if(r&&qh(r,n)>0){t.disconnect(),m();return}r=n}});p.current=t;let n=new Set;for(let t=1;t<e.length;t+=1){let r=Gh(e[t-1],e[t]);r&&n.add(r)}n.forEach(e=>t.observe(e,{childList:!0}))}let y=$(()=>{let[e,t]=Wh(c),n=_(e),r=f.current,i=!r||r.length!==e.length||e.some((e,t)=>{let n=r[t];return e.index!==n.index||e.element!==n.element||e.registration.index!==n.registration.index||e.registration.metadata!==n.registration.metadata});v(t),f.current=e,d.current=!1,i&&(s.forEach(e=>e(n)),a(n))});U(()=>(!d.current&&f.current&&_(f.current),()=>{n.current=[],r&&(r.current=[])}),[n,r,_]),U(()=>{d.current&&y()}),U(()=>()=>{p.current?.disconnect(),d.current=!0},[]);let b=$(e=>(s.add(e),()=>{s.delete(e)})),x=l.useMemo(()=>({register:h,unregister:g,subscribeMapChange:b,nextIndexRef:u}),[h,g,b,u]);return(0,Q.jsx)(zh.Provider,{value:x,children:t})}function Hh(){return new Map}function Uh(){return new Set}function Wh(e){let t=new Set,n=[],r=[];e.forEach((e,i)=>{if(!i.isConnected)return;let a=e.index,o={index:a??-1,element:i,registration:e};a===null?r.push(o):a>=0&&(t.add(a),n.push(o))});let i=0;return r.sort((e,t)=>qh(e.element,t.element)),r.forEach(e=>{for(;t.has(i);)i+=1;e.index=i,n.push(e),i+=1}),t.size>0&&n.sort((e,t)=>e.index-t.index),[n,r.map(e=>e.element)]}function Gh(e,t){let n=e.parentElement;for(;n&&!n.contains(t);)n=n.parentElement;return n}function Kh(e){for(let t of e)for(let e=0;e<t.removedNodes.length;e+=1)if(t.removedNodes[e].isConnected)return!0;return!1}function qh(e,t){return e.compareDocumentPosition(t)&Node.DOCUMENT_POSITION_FOLLOWING?-1:1}var Jh=l.forwardRef(function(e,t){var n;let{render:r,className:i,style:a,children:o,...s}=e,c=xm(),u=Sm(),d=!!wh(!0),{filteredItems:f,hasItems:p}=Cm(),m=c.useState(`selectionMode`),h=c.useState(`grid`),g=c.useState(`readOnly`),_=c.useState(`listProps`),v=c.useState(`virtualized`),y=c.useState(`forceMounted`),b=m===`multiple`,x=f.length===0,S=$(e=>{c.set(`positionerElement`,e)}),C=$(e=>{c.set(`listElement`,e)}),w=l.useMemo(()=>typeof o==`function`?n||=(0,Q.jsx)(Rh,{children:o}):o,[o]),T={empty:x},E=u.useState(`floatingId`),D=$i(`div`,e,{state:T,ref:[t,C,d?null:S],props:[_,{children:w,tabIndex:-1,id:E,role:h?`grid`:`listbox`,"aria-multiselectable":b?`true`:void 0,"aria-readonly":!h&&g?!0:void 0,onKeyDown(e){if(!(c.state.disabled||c.state.readOnly)&&e.key===`Enter`){let t=c.state.activeIndex;if(t==null)return;yt(e),Ah(c,t,e.nativeEvent)}},onKeyDownCapture(){c.context.keyboardActiveRef.current=!0},onPointerMoveCapture(){c.context.keyboardActiveRef.current=!1}},s]});if(v)return D;let O=p&&!y?void 0:c.context.labelsRef;return(0,Q.jsx)(Vh,{elementsRef:c.context.listRef,labelsRef:O,children:D})}),Yh=`⁠`;function Xh(e){let t=e.ownerDocument.createTreeWalker(e,NodeFilter.SHOW_TEXT),n=null;for(;t.nextNode();){let e=t.currentNode;e.nodeValue!==``&&(n=e)}return n}function Zh(){let e=it(),t=l.useRef(null);return l.useEffect(()=>{if(Ve)return;let n=t.current;if(n==null)return;let r=Xh(n);if(r==null)return;let i=r.data,a=`${i}${Yh}`;return r.nodeValue=a,e.start(200,()=>{r.nodeValue===a&&(r.nodeValue=i)}),()=>{e.clear(),r.nodeValue===a&&(r.nodeValue=i)}},[t,e]),t}var Qh=l.createContext(void 0);function $h(){let e=l.useContext(Qh);if(e===void 0)throw Error(Ai(20));return e}var eg=l.forwardRef(function(e,t){let{keepMounted:n=!1,...r}=e,i=xm(),a=i.useState(`mounted`),o=i.useState(`forceMounted`);return a||n||o?(0,Q.jsx)(Qh.Provider,{value:n,children:(0,Q.jsx)(ha,{ref:t,...r})}):null}),tg=20;function ng(e,t,n,r){let[i,a]=l.useState(!1);U(()=>{if(!e||!t||n==null){a(!1);return}let r=J(n).documentElement.clientWidth,i=n.offsetWidth;a(r>0&&i>0&&i>=r-tg)},[e,t,n]),vt(e&&(!t||i),r)}var rg=l.forwardRef(function(e,t){let{render:n,className:r,anchor:i,positionMethod:a,side:o,align:s,sideOffset:c,alignOffset:l,collisionBoundary:u=`clipping-ancestors`,collisionPadding:d,arrowPadding:f,sticky:p,disableAnchorTracking:m=!1,collisionAvoidance:h=sa,style:g,..._}=e,v=xm(),y=Sm(),b=$h(),x=v.useState(`modal`),S=v.useState(`open`),C=v.useState(`mounted`),w=v.useState(`openMethod`),T=v.useState(`positionerElement`),E=v.useState(`triggerElement`),D=v.useState(`inputElement`),O=v.useState(`inputGroupElement`),k=v.useState(`inputInsidePopup`),A=v.useState(`transitionStatus`),j=Dh(),M=Hl({anchor:i??(k?E:O??D),floatingRootContext:y,positionMethod:a,mounted:C,side:o,sideOffset:c,align:s,alignOffset:l,arrowPadding:f,collisionBoundary:u,collisionPadding:d,sticky:p,disableAnchorTracking:m,keepMounted:b,collisionAvoidance:h,lazyFlip:!0});ng(S&&x,w===`touch`,T,E);let N={open:S,side:M.side,align:M.align,anchorHidden:M.anchorHidden,empty:j};U(()=>{v.set(`popupSide`,M.side)},[v,M.side]);let P=$(e=>{v.set(`positionerElement`,e)}),F=Kl(e,N,{styles:M.positionerStyles,transitionStatus:A,props:_,refs:[t,P],hidden:!C,inert:!S});return(0,Q.jsxs)(Ch.Provider,{value:M,children:[C&&x&&(0,Q.jsx)(qc,{inert:Kc(!S),cutout:O??D??E}),F]})}),ig={...Xt,...Lt},ag=l.forwardRef(function(e,t){let{render:n,className:r,style:i,initialFocus:a,finalFocus:o,...s}=e,c=xm(),u=wh(),d=Sm(),f=c.useState(`mounted`),p=c.useState(`open`),m=c.useState(`openMethod`),h=c.useState(`popupProps`),g=c.useState(`transitionStatus`),_=c.useState(`inputInsidePopup`),v=c.useState(`inputElement`),y=c.useState(`modal`),b=c.useState(`id`),x=Dh(),S=s.id??(_?ah(b):void 0);U(()=>(c.set(`popupId`,c.context.popupRef.current?.id||S),()=>{c.set(`popupId`,void 0)}),[c,S]),ys({open:p,ref:c.context.popupRef,onComplete(){p&&c.context.onOpenChangeComplete(!0)}});let C=$i(`div`,e,{state:{open:p,side:u.side,align:u.align,anchorHidden:u.anchorHidden,transitionStatus:g,empty:x},ref:[t,c.context.popupRef],props:[h,{id:S,role:_?`dialog`:`presentation`,onFocus(e){let t=Et(e.nativeEvent);m!==`touch`&&(X(c.state.listElement,t)||t===e.currentTarget)&&c.context.inputRef.current?.focus()}},Gl(g),s],stateAttributesMapping:ig}),w=a===void 0?_?e=>e===`touch`?c.context.popupRef.current:v:!1:a,T;T=o??(_?void 0:!1);let E=!_||y;return(0,Q.jsx)(Pa,{context:d,disabled:!f,modal:E,openInteractionType:m,initialFocus:w,returnFocus:T,getInsideElements:()=>[c.context.startDismissRef.current,c.context.endDismissRef.current],children:(0,Q.jsxs)(l.Fragment,{children:[C,E&&(0,Q.jsx)(Th,{ref:c.context.endDismissRef})]})})});function og(e={}){let{guess:t,label:n,metadata:r,textRef:i,index:a}=e,{register:o,unregister:s,subscribeMapChange:c,nextIndexRef:u}=Bh(),d=l.useRef(-1),[f,p]=l.useState(a==null&&t?()=>{if(d.current===-1){let e=u.current;u.current+=1,d.current=e}return d.current}:-1),m=a??f,h=l.useRef(null),g=l.useCallback(e=>{let t=h.current;t&&s(t),h.current=e,e&&o(e,{metadata:r??null,index:a??null,label:n,textRef:i})},[a,o,s,r,n,i]);return U(()=>{if(a==null)return c(e=>{let t=h.current?e.get(h.current)?.index:null;t!=null&&p(t)})},[a,c]),{ref:g,index:m}}var sg=l.createContext(void 0);function cg(){let e=l.useContext(sg);if(!e)throw Error(Ai(19));return e}var lg=l.createContext(!1);function ug(){return l.useContext(lg)}function dg(e){let{componentProps:t,forwardedRef:n,virtualized:r,indexFromFilter:i}=e,{render:a,className:o,style:s,value:c=null,index:u,disabled:d=!1,nativeButton:f=!1,...p}=t,m=l.useRef(null),h=og({guess:!0,index:u,textRef:m}),g=xm(),_=ug(),v=Tm(),y=g.useState(`selectionMode`),b=g.useState(`disabled`),x=g.useState(`readOnly`),S=g.useState(`isItemEqualToValue`),C=b||d,w=y!==`none`,T=u??i??h.index,E=T!==-1,D=g.useState(`id`),O=g.useState(`isActive`,T),k=g.useState(`isSelected`,c),A=g.useState(`itemProps`),j=l.useRef(null),M=D!=null&&E?`${D}-${T}`:void 0,N=k&&w;U(()=>{if(!E||!r&&u==null)return;let e=g.context.listRef.current;return e[T]=j.current,()=>{delete e[T]}},[E,r,T,u,g]),U(()=>{if(!E||v)return;let e=g.context.valuesRef.current;return e[T]=c,()=>{delete e[T]}},[E,v,T,c,g]),U(()=>{if(!E||v)return;let e=g.state.selectedValue,t=g.state.selectedIndex;g.state.selectionMode===`multiple`&&Array.isArray(e)?t=Pm(T,c,g.context.valuesRef.current,e,S,t):Om(c,e,S)&&(t=T),g.set(`selectedIndex`,t)},[E,v,g,T,c,S]);let{getButtonProps:P,buttonRef:F}=Nc({disabled:C,focusableWhenDisabled:!0,native:f,composite:!0}),I={disabled:C,selected:N,highlighted:O};function L(e){function t(){g.context.handleSelection(e,c)}g.state.submitOnItemClick?(ua.flushSync(t),g.context.requestSubmit()):t()}let R={id:M,role:_?`gridcell`:`option`,"aria-selected":w?N:void 0,tabIndex:void 0,onPointerDownCapture(e){e.isPrimary&&(g.context.pointerDownItemRef.current=e.currentTarget),e.preventDefault()},onMouseDown(e){e.preventDefault()},onClick(e){C||x||L(e.nativeEvent)},onMouseUp(e){let t=g.context.pointerDownItemRef.current===e.currentTarget;g.context.pointerDownItemRef.current=null,!(C||x||e.button!==0||t||!O)&&L(e.nativeEvent)}},z=$i(`div`,t,{ref:[F,n,h.ref,j],state:I,props:[A,R,p,P]}),ee=l.useMemo(()=>({selected:N,textRef:m}),[N,m]);return(0,Q.jsx)(sg.Provider,{value:ee,children:z})}function fg(e){let{componentProps:t,forwardedRef:n}=e,r=xm().useState(`isItemEqualToValue`),{flatFilteredValues:i}=Cm(),a=jm(i,t.value??null,r);return(0,Q.jsx)(dg,{componentProps:t,forwardedRef:n,virtualized:!0,indexFromFilter:a})}var pg=l.memo(l.forwardRef(function(e,t){let n=xm().useState(`virtualized`);return n&&e.index==null?(0,Q.jsx)(fg,{componentProps:e,forwardedRef:t}):(0,Q.jsx)(dg,{componentProps:e,forwardedRef:t,virtualized:n,indexFromFilter:void 0})})),mg=l.forwardRef(function(e,t){let{selected:n}=cg();return e.keepMounted||n?(0,Q.jsx)(hg,{...e,ref:t}):null}),hg=l.memo(l.forwardRef((e,t)=>{let{render:n,className:r,style:i,keepMounted:a,...o}=e,{selected:s}=cg(),c=l.useRef(null),{transitionStatus:u,setMounted:d}=hs(s),f=$i(`span`,e,{ref:[t,c],state:{selected:s,transitionStatus:u},props:[{"aria-hidden":!0,children:`✔️`},o],stateAttributesMapping:Lt});return ys({batch:!0,enabled:!s,open:s,ref:c,onComplete(){s||d(!1)}}),f})),gg=l.forwardRef(function(e,t){let{render:n,className:r,style:i,children:a,...o}=e,{filteredItems:s}=Cm(),c=xm(),l=Zh(),u=s.length===0?a:null;return $i(`div`,e,{ref:[t,c.context.emptyRef,l],props:[{children:u,role:`status`,"aria-live":`polite`,"aria-atomic":!0},o]})});function _g({label:e,value:t,options:n,onChange:r,icon:i,allowCustom:a=!1,action:o}){let[s,c]=(0,l.useState)(``),u=n.find(e=>e.value===t)??{value:t,label:t},d=s.trim(),f=n.filter(e=>e.label.toLowerCase().includes(d.toLowerCase())),p=a&&d&&!n.some(e=>e.value===d)?{value:d,label:`Use “${d}”`}:null;return(0,Q.jsxs)(gh,{items:p?[...f,p]:f,value:u,filter:null,inputValue:s,onInputValueChange:c,onOpenChange:()=>c(``),itemToStringLabel:e=>e.label,isItemEqualToValue:(e,t)=>e.value===t.value,onValueChange:e=>{e&&!e.disabled&&r(e.value)},children:[(0,Q.jsx)(Yl,{label:`${e}: ${u.label}`,children:(0,Q.jsxs)(Fh,{className:`composer-select`,"aria-label":`${e}: ${u.label}`,children:[(0,Q.jsx)(`span`,{className:`composer-select-icon`,"aria-hidden":`true`,children:u.icon??i}),(0,Q.jsx)(`span`,{className:`composer-select-label`,children:u.shortLabel??(u.label||e)}),(0,Q.jsx)(b,{className:`composer-select-caret`,size:11,"aria-hidden":`true`})]})}),(0,Q.jsx)(eg,{children:(0,Q.jsx)(rg,{className:`composer-select-positioner`,sideOffset:6,align:`start`,collisionPadding:12,children:(0,Q.jsxs)(ag,{className:`composer-select-popup`,"aria-label":`${e} options`,children:[(0,Q.jsxs)(`div`,{className:`composer-select-search`,children:[(0,Q.jsx)(H,{size:14,"aria-hidden":`true`}),(0,Q.jsx)(jh,{"aria-label":`Search ${e.toLowerCase()}`,placeholder:`Search ${e.toLowerCase()}…`,maxLength:a?120:void 0})]}),(0,Q.jsx)(gg,{className:`composer-select-empty`,children:`No matches`}),(0,Q.jsx)(Jh,{className:`composer-select-list`,children:e=>(0,Q.jsxs)(pg,{value:e,disabled:e.disabled,className:`composer-select-option`,children:[e.icon&&(0,Q.jsx)(`span`,{className:`composer-select-option-icon`,"aria-hidden":`true`,children:e.icon}),(0,Q.jsx)(`span`,{className:`composer-select-option-label`,children:e.label}),(0,Q.jsx)(mg,{className:`composer-select-check`,children:(0,Q.jsx)(y,{size:14})})]},e.value)}),o&&(0,Q.jsxs)(`button`,{type:`button`,className:`composer-select-action`,onClick:o.onClick,children:[o.icon,(0,Q.jsx)(`span`,{children:o.label})]})]})})})]})}var vg={claude:(0,Q.jsx)(`svg`,{viewBox:`0 0 256 257`,fill:`#D97757`,children:(0,Q.jsx)(`path`,{d:`m50.228 170.321 50.357-28.257.843-2.463-.843-1.361h-2.462l-8.426-.518-28.775-.778-24.952-1.037-24.175-1.296-6.092-1.297L0 125.796l.583-3.759 5.12-3.434 7.324.648 16.202 1.101 24.304 1.685 17.629 1.037 26.118 2.722h4.148l.583-1.685-1.426-1.037-1.101-1.037-25.147-17.045-27.22-18.017-14.258-10.37-7.713-5.25-3.888-4.925-1.685-10.758 7-7.713 9.397.649 2.398.648 9.527 7.323 20.35 15.75L94.817 91.9l3.889 3.24 1.555-1.102.195-.777-1.75-2.917-14.453-26.118-15.425-26.572-6.87-11.018-1.814-6.61c-.648-2.723-1.102-4.991-1.102-7.778l7.972-10.823L71.42 0 82.05 1.426l4.472 3.888 6.61 15.101 10.694 23.786 16.591 32.34 4.861 9.592 2.592 8.879.973 2.722h1.685v-1.556l1.36-18.211 2.528-22.36 2.463-28.776.843-8.1 4.018-9.722 7.971-5.25 6.222 2.981 5.12 7.324-.713 4.73-3.046 19.768-5.962 30.98-3.889 20.739h2.268l2.593-2.593 10.499-13.934 17.628-22.036 7.778-8.749 9.073-9.657 5.833-4.601h11.018l8.1 12.055-3.628 12.443-11.342 14.388-9.398 12.184-13.48 18.147-8.426 14.518.778 1.166 2.01-.194 30.46-6.481 16.462-2.982 19.637-3.37 8.88 4.148.971 4.213-3.5 8.62-20.998 5.184-24.628 4.926-36.682 8.685-.454.324.519.648 16.526 1.555 7.065.389h17.304l32.21 2.398 8.426 5.574 5.055 6.805-.843 5.184-12.962 6.611-17.498-4.148-40.83-9.721-14-3.5h-1.944v1.167l11.666 11.406 21.387 19.314 26.767 24.887 1.36 6.157-3.434 4.86-3.63-.518-23.526-17.693-9.073-7.972-20.545-17.304h-1.36v1.814l4.73 6.935 25.017 37.59 1.296 11.536-1.814 3.76-6.481 2.268-7.13-1.297-14.647-20.544-15.1-23.138-12.185-20.739-1.49.843-7.194 77.448-3.37 3.953-7.778 2.981-6.48-4.925-3.436-7.972 3.435-15.749 4.148-20.544 3.37-16.333 3.046-20.285 1.815-6.74-.13-.454-1.49.194-15.295 20.999-23.267 31.433-18.406 19.702-4.407 1.75-7.648-3.954.713-7.064 4.277-6.286 25.47-32.405 15.36-20.092 9.917-11.6-.065-1.686h-.583L44.07 198.125l-12.055 1.555-5.185-4.86.648-7.972 2.463-2.593 20.35-13.999-.064.065Z`})}),codex:(0,Q.jsx)(`svg`,{viewBox:`0 0 24 24`,fill:`currentColor`,fillRule:`evenodd`,children:(0,Q.jsx)(`path`,{d:`M8.086.457a6.105 6.105 0 013.046-.415c1.333.153 2.521.72 3.564 1.7a.117.117 0 00.107.029c1.408-.346 2.762-.224 4.061.366l.063.03.154.076c1.357.703 2.33 1.77 2.918 3.198.278.679.418 1.388.421 2.126a5.655 5.655 0 01-.18 1.631.167.167 0 00.04.155 5.982 5.982 0 011.578 2.891c.385 1.901-.01 3.615-1.183 5.14l-.182.22a6.063 6.063 0 01-2.934 1.851.162.162 0 00-.108.102c-.255.736-.511 1.364-.987 1.992-1.199 1.582-2.962 2.462-4.948 2.451-1.583-.008-2.986-.587-4.21-1.736a.145.145 0 00-.14-.032c-.518.167-1.04.191-1.604.185a5.924 5.924 0 01-2.595-.622 6.058 6.058 0 01-2.146-1.781c-.203-.269-.404-.522-.551-.821a7.74 7.74 0 01-.495-1.283 6.11 6.11 0 01-.017-3.064.166.166 0 00.008-.074.115.115 0 00-.037-.064 5.958 5.958 0 01-1.38-2.202 5.196 5.196 0 01-.333-1.589 6.915 6.915 0 01.188-2.132c.45-1.484 1.309-2.648 2.577-3.493.282-.188.55-.334.802-.438.286-.12.573-.22.861-.304a.129.129 0 00.087-.087A6.016 6.016 0 015.635 2.31C6.315 1.464 7.132.846 8.086.457zm-.804 7.85a.848.848 0 00-1.473.842l1.694 2.965-1.688 2.848a.849.849 0 001.46.864l1.94-3.272a.849.849 0 00.007-.854l-1.94-3.393zm5.446 6.24a.849.849 0 000 1.695h4.848a.849.849 0 000-1.696h-4.848z`})}),opencode:(0,Q.jsxs)(`svg`,{viewBox:`96 96 320 320`,fill:`currentColor`,fillRule:`evenodd`,children:[(0,Q.jsx)(`path`,{d:`M320 224V352H192V224H320Z`,opacity:`.4`}),(0,Q.jsx)(`path`,{d:`M384 416H128V96H384V416ZM320 160H192V352H320V160Z`})]}),pi:(0,Q.jsx)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.4`,strokeLinecap:`round`,children:(0,Q.jsx)(`path`,{d:`M4 7h16M9 7v11M15 7v9.5a1.5 1.5 0 0 0 1.5 1.5H18`})})};function yg({harness:e,size:t=14}){return(0,Q.jsx)(`span`,{className:`harness-icon`,style:{width:t,height:t},"aria-hidden":`true`,children:vg[e]??(0,Q.jsx)(`span`,{className:`harness-icon-letter`,children:e.charAt(0).toUpperCase()})})}var bg={macos:`M12.152 6.896c-.948 0-2.415-1.078-3.96-1.04-2.04.027-3.91 1.183-4.961 3.014-2.117 3.675-.546 9.103 1.519 12.09 1.013 1.454 2.208 3.09 3.792 3.039 1.52-.065 2.09-.987 3.935-.987 1.831 0 2.35.987 3.96.948 1.637-.026 2.676-1.48 3.676-2.948 1.156-1.688 1.636-3.325 1.662-3.415-.039-.013-3.182-1.221-3.22-4.857-.026-3.04 2.48-4.494 2.597-4.559-1.429-2.09-3.623-2.324-4.39-2.376-2-.156-3.675 1.09-4.61 1.09zM15.53 3.83c.843-1.012 1.4-2.427 1.245-3.83-1.207.052-2.662.805-3.532 1.818-.78.896-1.454 2.338-1.273 3.714 1.338.104 2.715-.688 3.559-1.701`,linux:`M12.504 0c-.155 0-.315.008-.48.021-4.226.333-3.105 4.807-3.17 6.298-.076 1.092-.3 1.953-1.05 3.02-.885 1.051-2.127 2.75-2.716 4.521-.278.832-.41 1.684-.287 2.489a.424.424 0 00-.11.135c-.26.268-.45.6-.663.839-.199.199-.485.267-.797.4-.313.136-.658.269-.864.68-.09.189-.136.394-.132.602 0 .199.027.4.055.536.058.399.116.728.04.97-.249.68-.28 1.145-.106 1.484.174.334.535.47.94.601.81.2 1.91.135 2.774.6.926.466 1.866.67 2.616.47.526-.116.97-.464 1.208-.946.587-.003 1.23-.269 2.26-.334.699-.058 1.574.267 2.577.2.025.134.063.198.114.333l.003.003c.391.778 1.113 1.132 1.884 1.071.771-.06 1.592-.536 2.257-1.306.631-.765 1.683-1.084 2.378-1.503.348-.199.629-.469.649-.853.023-.4-.2-.811-.714-1.376v-.097l-.003-.003c-.17-.2-.25-.535-.338-.926-.085-.401-.182-.786-.492-1.046h-.003c-.059-.054-.123-.067-.188-.135a.357.357 0 00-.19-.064c.431-1.278.264-2.55-.173-3.694-.533-1.41-1.465-2.638-2.175-3.483-.796-1.005-1.576-1.957-1.56-3.368.026-2.152.236-6.133-3.544-6.139zm.529 3.405h.013c.213 0 .396.062.584.198.19.135.33.332.438.533.105.259.158.459.166.724 0-.02.006-.04.006-.06v.105a.086.086 0 01-.004-.021l-.004-.024a1.807 1.807 0 01-.15.706.953.953 0 01-.213.335.71.71 0 00-.088-.042c-.104-.045-.198-.064-.284-.133a1.312 1.312 0 00-.22-.066c.05-.06.146-.133.183-.198.053-.128.082-.264.088-.402v-.02a1.21 1.21 0 00-.061-.4c-.045-.134-.101-.2-.183-.333-.084-.066-.167-.132-.267-.132h-.016c-.093 0-.176.03-.262.132a.8.8 0 00-.205.334 1.18 1.18 0 00-.09.4v.019c.002.089.008.179.02.267-.193-.067-.438-.135-.607-.202a1.635 1.635 0 01-.018-.2v-.02a1.772 1.772 0 01.15-.768c.082-.22.232-.406.43-.533a.985.985 0 01.594-.2zm-2.962.059h.036c.142 0 .27.048.399.135.146.129.264.288.344.465.09.199.14.4.153.667v.004c.007.134.006.2-.002.266v.08c-.03.007-.056.018-.083.024-.152.055-.274.135-.393.2.012-.09.013-.18.003-.267v-.015c-.012-.133-.04-.2-.082-.333a.613.613 0 00-.166-.267.248.248 0 00-.183-.064h-.021c-.071.006-.13.04-.186.132a.552.552 0 00-.12.27.944.944 0 00-.023.33v.015c.012.135.037.2.08.334.046.134.098.2.166.268.01.009.02.018.034.024-.07.057-.117.07-.176.136a.304.304 0 01-.131.068 2.62 2.62 0 01-.275-.402 1.772 1.772 0 01-.155-.667 1.759 1.759 0 01.08-.668 1.43 1.43 0 01.283-.535c.128-.133.26-.2.418-.2zm1.37 1.706c.332 0 .733.065 1.216.399.293.2.523.269 1.052.468h.003c.255.136.405.266.478.399v-.131a.571.571 0 01.016.47c-.123.31-.516.643-1.063.842v.002c-.268.135-.501.333-.775.465-.276.135-.588.292-1.012.267a1.139 1.139 0 01-.448-.067 3.566 3.566 0 01-.322-.198c-.195-.135-.363-.332-.612-.465v-.005h-.005c-.4-.246-.616-.512-.686-.71-.07-.268-.005-.47.193-.6.224-.135.38-.271.483-.336.104-.074.143-.102.176-.131h.002v-.003c.169-.202.436-.47.839-.601.139-.036.294-.065.466-.065zm2.8 2.142c.358 1.417 1.196 3.475 1.735 4.473.286.534.855 1.659 1.102 3.024.156-.005.33.018.513.064.646-1.671-.546-3.467-1.089-3.966-.22-.2-.232-.335-.123-.335.59.534 1.365 1.572 1.646 2.757.13.535.16 1.104.021 1.67.067.028.135.06.205.067 1.032.534 1.413.938 1.23 1.537v-.043c-.06-.003-.12 0-.18 0h-.016c.151-.467-.182-.825-1.065-1.224-.915-.4-1.646-.336-1.77.465-.008.043-.013.066-.018.135-.068.023-.139.053-.209.064-.43.268-.662.669-.793 1.187-.13.533-.17 1.156-.205 1.869v.003c-.02.334-.17.838-.319 1.35-1.5 1.072-3.58 1.538-5.348.334a2.645 2.645 0 00-.402-.533 1.45 1.45 0 00-.275-.333c.182 0 .338-.03.465-.067a.615.615 0 00.314-.334c.108-.267 0-.697-.345-1.163-.345-.467-.931-.995-1.788-1.521-.63-.4-.986-.87-1.15-1.396-.165-.534-.143-1.085-.015-1.645.245-1.07.873-2.11 1.274-2.763.107-.065.037.135-.408.974-.396.751-1.14 2.497-.122 3.854a8.123 8.123 0 01.647-2.876c.564-1.278 1.743-3.504 1.836-5.268.048.036.217.135.289.202.218.133.38.333.59.465.21.201.477.335.876.335.039.003.075.006.11.006.412 0 .73-.134.997-.268.29-.134.52-.334.74-.4h.005c.467-.135.835-.402 1.044-.7zm2.185 8.958c.037.6.343 1.245.882 1.377.588.134 1.434-.333 1.791-.765l.211-.01c.315-.007.577.01.847.268l.003.003c.208.199.305.53.391.876.085.4.154.78.409 1.066.486.527.645.906.636 1.14l.003-.007v.018l-.003-.012c-.015.262-.185.396-.498.595-.63.401-1.746.712-2.457 1.57-.618.737-1.37 1.14-2.036 1.191-.664.053-1.237-.2-1.574-.898l-.005-.003c-.21-.4-.12-1.025.056-1.69.176-.668.428-1.344.463-1.897.037-.714.076-1.335.195-1.814.12-.465.308-.797.641-.984l.045-.022zm-10.814.049h.01c.053 0 .105.005.157.014.376.055.706.333 1.023.752l.91 1.664.003.003c.243.533.754 1.064 1.189 1.637.434.598.77 1.131.729 1.57v.006c-.057.744-.48 1.148-1.125 1.294-.645.135-1.52.002-2.395-.464-.968-.536-2.118-.469-2.857-.602-.369-.066-.61-.2-.723-.4-.11-.2-.113-.602.123-1.23v-.004l.002-.003c.117-.334.03-.752-.027-1.118-.055-.401-.083-.71.043-.94.16-.334.396-.4.69-.533.294-.135.64-.202.915-.47h.002v-.002c.256-.268.445-.601.668-.838.19-.201.38-.336.663-.336zm7.159-9.074c-.435.201-.945.535-1.488.535-.542 0-.97-.267-1.28-.466-.154-.134-.28-.268-.373-.335-.164-.134-.144-.333-.074-.333.109.016.129.134.199.2.096.066.215.2.36.333.292.2.68.467 1.167.467.485 0 1.053-.267 1.398-.466.195-.135.445-.334.648-.467.156-.136.149-.267.279-.267.128.016.034.134-.147.332a8.097 8.097 0 01-.69.468zm-1.082-1.583V5.64c-.006-.02.013-.042.029-.05.074-.043.18-.027.26.004.063 0 .16.067.15.135-.006.049-.085.066-.135.066-.055 0-.092-.043-.141-.068-.052-.018-.146-.008-.163-.065zm-.551 0c-.02.058-.113.049-.166.066-.047.025-.086.068-.14.068-.05 0-.13-.02-.136-.068-.01-.066.088-.133.15-.133.08-.031.184-.047.259-.005.019.009.036.03.03.05v.02h.003z`,windows:`M0,0H11.377V11.372H0ZM12.623,0H24V11.372H12.623ZM0,12.623H11.377V24H0Zm12.623,0H24V24H12.623`},xg={macos:`0 2 24 24`,linux:`0 0 24 24`,windows:`0 0 24 24`};function Sg({os:e,size:t=14}){return(0,Q.jsx)(`svg`,{viewBox:xg[e],width:t,height:t,fill:`currentColor`,"aria-hidden":`true`,children:(0,Q.jsx)(`path`,{d:bg[e]})})}function Cg({project:e}){let t=(0,l.useRef)(null),[n,r]=(0,l.useState)(!1),[i,a]=(0,l.useState)(!1);return(0,l.useEffect)(()=>{a(!1),t.current?.complete&&(r(t.current.naturalWidth>0),a(t.current.naturalWidth===0))},[e.iconUrl]),(0,Q.jsxs)(`span`,{className:`thread-project ${n?`has-icon`:``}`,style:{"--project-color":e.color},"aria-hidden":`true`,children:[(0,Q.jsx)(`span`,{className:`thread-project-letter`,children:e.initial}),e.iconUrl&&!i&&(0,Q.jsx)(`img`,{ref:t,src:e.iconUrl,alt:``,decoding:`async`,onLoad:()=>r(!0),onError:()=>a(!0)})]})}function wg({projects:e,projectId:t,onChange:n,onAddProject:r}){return(0,Q.jsx)(_g,{label:`Project`,value:t,onChange:n,icon:(0,Q.jsx)(j,{size:14}),action:r?{label:`Add project`,icon:(0,Q.jsx)(V,{size:14}),onClick:r}:void 0,options:e.map(e=>({value:e.id,label:e.name,icon:(0,Q.jsx)(Cg,{project:e},e.id)}))})}var Tg=e=>e.os?(0,Q.jsx)(Sg,{os:e.os}):e.id===`local`?(0,Q.jsx)(z,{size:14}):(0,Q.jsx)(ie,{size:14});function Eg({machine:e,machines:t,projects:n,projectId:r,harness:i,model:a,onMachineChange:o,onProjectChange:s,onHarnessChange:c,onModelChange:l,onAddProject:u}){let d=e.harnesses.find(e=>e.id===i)?.models??[];return(0,Q.jsxs)(`div`,{className:`composer-selectors`,children:[(0,Q.jsx)(_g,{label:`Machine`,value:e.id,onChange:o,icon:Tg(e),options:t.map(e=>({icon:Tg(e),value:e.id,label:`${e.name}${e.connected?``:` · Not connected`}`,shortLabel:e.name,disabled:!e.connected}))}),(0,Q.jsx)(wg,{projects:n,projectId:r,onChange:s,onAddProject:u},e.id),(0,Q.jsx)(_g,{label:`Harness`,value:i,onChange:c,icon:(0,Q.jsx)(se,{size:14}),options:e.harnesses.map(e=>({value:e.id,label:e.name,shortLabel:e.name===`Claude Code`?`Claude`:e.name,icon:(0,Q.jsx)(yg,{harness:e.id})}))}),(0,Q.jsx)(_g,{label:`Model`,value:a,onChange:l,icon:(0,Q.jsx)(O,{size:14}),allowCustom:e.harnesses.find(e=>e.id===i)?.customModels??!1,options:d.map(e=>({value:e,label:e,shortLabel:e.split(`/`).at(-1)}))},`${e.id}:${i}`)]})}var Dg=l.createContext(void 0),Og=e=>{let t=l.useContext(Dg);if(e)return e;if(!t)throw Error(`No QueryClient set, use QueryClientProvider to set one`);return t},kg=({client:e,children:t})=>(l.useEffect(()=>(e.mount(),()=>{e.unmount()}),[e]),(0,Q.jsx)(Dg.Provider,{value:e,children:t})),Ag={setTimeout:(e,t)=>setTimeout(e,t),clearTimeout:e=>clearTimeout(e),setInterval:(e,t)=>setInterval(e,t),clearInterval:e=>clearInterval(e)},jg=new class{#e=Ag;setTimeoutProvider(e){this.#e=e}setTimeout(e,t){return this.#e.setTimeout(e,t)}clearTimeout(e){this.#e.clearTimeout(e)}setInterval(e,t){return this.#e.setInterval(e,t)}clearInterval(e){this.#e.clearInterval(e)}};function Mg(e){setTimeout(e,0)}var Ng=typeof window>`u`||`Deno`in globalThis;function Pg(){}function Fg(e,t){return typeof e==`function`?e(t):e}function Ig(e){return typeof e==`number`&&e>=0&&e!==1/0}function Lg(e,t){return Math.max(e+(t||0)-Date.now(),0)}function Rg(e,t){return typeof e==`function`?e(t):e}function zg(e,t){let{type:n=`all`,exact:r,fetchStatus:i,predicate:a,queryKey:o,stale:s}=e;if(o){if(r){if(t.queryHash!==Vg(o,t.options))return!1}else if(!Ug(t.queryKey,o))return!1}if(n!==`all`){let e=t.isActive();if(n===`active`&&!e||n===`inactive`&&e)return!1}return!(typeof s==`boolean`&&t.isStale()!==s||i&&i!==t.state.fetchStatus||a&&!a(t))}function Bg(e,t){let{exact:n,status:r,predicate:i,mutationKey:a}=e;if(a){if(!t.options.mutationKey)return!1;if(n){if(Hg(t.options.mutationKey)!==Hg(a))return!1}else if(!Ug(t.options.mutationKey,a))return!1}return!(r&&t.state.status!==r||i&&!i(t))}function Vg(e,t){return(t?.queryKeyHashFn||Hg)(e)}function Hg(e){return JSON.stringify(e,(e,t)=>Jg(t)?Object.keys(t).sort().reduce((e,n)=>(e[n]=t[n],e),{}):t)}function Ug(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(e&&t&&typeof e==`object`&&typeof t==`object`){if(Array.isArray(e)&&Array.isArray(t)){if(t.length>e.length)return!1;for(let n=0;n<t.length;n++)if(!Ug(e[n],t[n]))return!1;return!0}let n=Object.keys(t);for(let r of n)if(!Ug(e[r],t[r]))return!1;return!0}return!1}var Wg=Object.prototype.hasOwnProperty;function Gg(e,t,n=0){if(e===t)return e;if(n>500)return t;let r=qg(e)&&qg(t);if(!r&&!(Jg(e)&&Jg(t)))return t;let i=(r?e:Object.keys(e)).length,a=r?t:Object.keys(t),o=a.length,s=r?Array(o):{},c=0;for(let l=0;l<o;l++){let o=r?l:a[l],u=e[o],d=t[o];if(u===d){s[o]=u,(r?l<i:Wg.call(e,o))&&c++;continue}if(u===null||d===null||typeof u!=`object`||typeof d!=`object`){s[o]=d;continue}let f=Gg(u,d,n+1);s[o]=f,f===u&&c++}return i===o&&c===i?e:s}function Kg(e,t){if(!t||Object.keys(e).length!==Object.keys(t).length)return!1;for(let n in e)if(e[n]!==t[n])return!1;return!0}function qg(e){return Array.isArray(e)&&e.length===Object.keys(e).length}function Jg(e){if(!Yg(e))return!1;let t=Object.getPrototypeOf(e),n=t?.constructor;if(n===void 0)return!0;if(typeof n!=`function`)return!1;let r=n.prototype;return!(!Yg(r)||!r.hasOwnProperty(`isPrototypeOf`)||t!==Object.prototype)}function Yg(e){return Object.prototype.toString.call(e)===`[object Object]`}function Xg(e){return new Promise(t=>{jg.setTimeout(t,e)})}function Zg(e,t,n){return typeof n.structuralSharing==`function`?n.structuralSharing(e,t):n.structuralSharing===!1?t:Gg(e,t)}function Qg(e,t,n=0){let r=[...e,t];return n&&r.length>n?r.slice(1):r}function $g(e,t,n=0){let r=[t,...e];return n&&r.length>n?r.slice(0,-1):r}var e_=Symbol();function t_(e,t){return!e.queryFn&&t?.initialPromise?()=>t.initialPromise:!e.queryFn||e.queryFn===e_?()=>Promise.reject(Error(`Missing queryFn: '${e.queryHash}'`)):e.queryFn}function n_(e,t){return typeof e==`function`?e(...t):!!e}function r_(e,t,n){let r=!1,i;return Object.defineProperty(e,"signal",{enumerable:!0,get:()=>(i??=t(),r?i:(r=!0,i.aborted?n():i.addEventListener(`abort`,n,{once:!0}),i))}),e}var i_=()=>Ng,a_=()=>i_(),o_=class{constructor(){this.listeners=new Set,this.subscribe=this.subscribe.bind(this)}subscribe(e){return this.listeners.add(e),this.onSubscribe(),()=>{this.listeners.delete(e),this.onUnsubscribe()}}hasListeners(){return this.listeners.size>0}onSubscribe(){}onUnsubscribe(){}},s_=new class extends o_{#e;#t;#n;constructor(){super(),this.#n=e=>{if(typeof window<`u`&&window.addEventListener){let t=()=>e();return window.addEventListener(`visibilitychange`,t,!1),()=>{window.removeEventListener(`visibilitychange`,t)}}}}onSubscribe(){this.#t||this.setEventListener(this.#n)}onUnsubscribe(){this.hasListeners()||(this.#t?.(),this.#t=void 0)}setEventListener(e){this.#n=e,this.#t?.(),this.#t=e(e=>{typeof e==`boolean`?this.setFocused(e):this.onFocus()})}setFocused(e){this.#e!==e&&(this.#e=e,this.onFocus())}onFocus(){let e=this.isFocused();this.listeners.forEach(t=>{t(e)})}isFocused(){return typeof this.#e==`boolean`?this.#e:globalThis.document?.visibilityState!==`hidden`}},c_=Mg;function l_(){let e=[],t=0,n=e=>{e()},r=e=>{e()},i=c_,a=r=>{t?e.push(r):i(()=>{n(r)})},o=()=>{let t=e;e=[],t.length&&i(()=>{r(()=>{t.forEach(e=>{n(e)})})})};return{batch:e=>{let n;t++;try{n=e()}finally{t--,t||o()}return n},batchCalls:e=>(...t)=>{a(()=>{e(...t)})},schedule:a,setNotifyFunction:e=>{n=e},setBatchNotifyFunction:e=>{r=e},setScheduler:e=>{i=e}}}var u_=l_(),d_=new class extends o_{#e=!0;#t;#n;constructor(){super(),this.#n=e=>{if(typeof window<`u`&&window.addEventListener){let t=()=>e(!0),n=()=>e(!1);return window.addEventListener(`online`,t,!1),window.addEventListener(`offline`,n,!1),()=>{window.removeEventListener(`online`,t),window.removeEventListener(`offline`,n)}}}}onSubscribe(){this.#t||this.setEventListener(this.#n)}onUnsubscribe(){this.hasListeners()||(this.#t?.(),this.#t=void 0)}setEventListener(e){this.#n=e,this.#t?.(),this.#t=e(this.setOnline.bind(this))}setOnline(e){this.#e!==e&&(this.#e=e,this.listeners.forEach(t=>{t(e)}))}isOnline(){return this.#e}};function f_(e){return Math.min(1e3*2**e,3e4)}function p_(e){return(e??`online`)!==`online`||d_.isOnline()}var m_=class extends Error{constructor(e){super(`CancelledError`),this.revert=e?.revert,this.silent=e?.silent}};function h_(e){let t=!1,n=0,r,i=`pending`,a,o,s=new Promise((e,t)=>{a=e,o=t});s.catch(Pg);let c=()=>i!==`pending`,l=t=>{if(!c()){let n=new m_(t);h(n),e.onCancel?.(n)}},u=()=>{t=!0},d=()=>{t=!1},f=()=>s_.isFocused()&&(e.networkMode===`always`||d_.isOnline())&&e.canRun(),p=()=>p_(e.networkMode)&&e.canRun(),m=e=>{c()||(r?.(),i=`resolved`,a(e))},h=e=>{c()||(r?.(),i=`rejected`,o(e))},g=()=>new Promise(t=>{r=e=>{(c()||f())&&t(e)},e.onPause?.()}).then(()=>{r=void 0,c()||e.onContinue?.()}),_=()=>{if(c())return;let r,i=n===0?e.initialPromise:void 0;try{r=i??e.fn()}catch(e){r=Promise.reject(e)}Promise.resolve(r).then(m).catch(r=>{if(c())return;let i=e.retry??(a_()?0:3),a=e.retryDelay??f_,o=typeof a==`function`?a(n,r):a,s=i===!0||typeof i==`number`&&n<i||typeof i==`function`&&i(n,r);if(t||!s){h(r);return}n++,e.onFail?.(n,r),Xg(o).then(()=>f()?void 0:g()).then(()=>{t?h(r):_()})})};return{promise:s,status:()=>i,cancel:l,continue:()=>(r?.(),s),cancelRetry:u,continueRetry:d,canStart:p,start:()=>(p()?_():g().then(_),s)}}var g_=class{#e;destroy(){this.clearGcTimeout()}scheduleGc(){this.clearGcTimeout(),Ig(this.gcTime)&&(this.#e=jg.setTimeout(()=>{this.optionalRemove()},this.gcTime))}updateGcTime(e){this.gcTime=Math.max(this.gcTime||0,e??(a_()?1/0:3e5))}clearGcTimeout(){this.#e!==void 0&&(jg.clearTimeout(this.#e),this.#e=void 0)}};function __(e){return{onFetch:(t,n)=>{let r=t.options,i=t.fetchOptions?.meta?.fetchMore?.direction,a=t.state.data?.pages||[],o=t.state.data?.pageParams||[],s={pages:[],pageParams:[]},c=0,l=async()=>{let n=!1,l=e=>{r_(e,()=>t.signal,()=>n=!0)},u=t_(t.options,t.fetchOptions),d=async(e,r,i)=>{if(n)return Promise.reject(t.signal.reason);if(r==null&&e.pages.length)return Promise.resolve(e);let a=(()=>{let e={client:t.client,queryKey:t.queryKey,pageParam:r,direction:i?`backward`:`forward`,meta:t.options.meta};return l(e),e})(),o=await u(a),{maxPages:s}=t.options,c=i?$g:Qg;return{pages:c(e.pages,o,s),pageParams:c(e.pageParams,r,s)}};if(i&&a.length){let e=i===`backward`,t=e?y_:v_,n={pages:a,pageParams:o};s=await d(n,t(r,n),e)}else{let t=e??a.length;do{let e=c===0?o[0]??r.initialPageParam:v_(r,s);if(c>0&&e==null)break;s=await d(s,e),c++}while(c<t)}return s};t.fetchFn=t.options.persister?()=>t.options.persister?.(l,{client:t.client,queryKey:t.queryKey,meta:t.options.meta,signal:t.signal},n):l}}}function v_(e,{pages:t,pageParams:n}){let r=t.length-1;return t.length>0?e.getNextPageParam(t[r],t,n[r],n):void 0}function y_(e,{pages:t,pageParams:n}){return t.length>0?e.getPreviousPageParam?.(t[0],t,n[0],n):void 0}var b_=class extends g_{#e;#t;#n;#r;#i;#a;#o;#s;constructor(e){super(),this.#s=!1,this.#o=e.defaultOptions,this.setOptions(e.options),this.observers=[],this.#i=e.client,this.#r=this.#i.getQueryCache(),this.queryKey=e.queryKey,this.queryHash=e.queryHash,this.#t=C_(this.options),this.state=e.state??this.#t,this.scheduleGc()}get meta(){return this.options.meta}get queryType(){return this.#e}get promise(){return this.#a?.promise}setOptions(e){if(this.options={...this.#o,...e},e?._type&&(this.#e=e._type),this.updateGcTime(this.options.gcTime),this.state&&this.state.data===void 0){let e=C_(this.options);e.data!==void 0&&(this.setState(S_(e.data,e.dataUpdatedAt)),this.#t=e)}}optionalRemove(){!this.observers.length&&this.state.fetchStatus===`idle`&&this.#r.remove(this)}setData(e,t){let n=Zg(this.state.data,e,this.options);return this.#c({data:n,type:`success`,dataUpdatedAt:t?.updatedAt,manual:t?.manual}),n}setState(e){this.#c({type:`setState`,state:e})}cancel(e){let t=this.#a?.promise;return this.#a?.cancel(e),t?t.then(Pg).catch(Pg):Promise.resolve()}destroy(){super.destroy(),this.cancel({silent:!0})}get resetState(){return this.#t}reset(){this.destroy(),this.setState(this.resetState)}isActive(){return this.observers.some(e=>Rg(e.options.enabled,this)!==!1)}isDisabled(){return this.getObserversCount()>0?!this.isActive():this.options.queryFn===e_||!this.isFetched()}isFetched(){return this.state.dataUpdateCount+this.state.errorUpdateCount>0}isStatic(){return this.getObserversCount()>0&&this.observers.some(e=>Rg(e.options.staleTime,this)===`static`)}isStale(){return this.getObserversCount()>0?this.observers.some(e=>e.getCurrentResult().isStale):this.state.data===void 0||this.state.isInvalidated}isStaleByTime(e=0){return this.state.data===void 0?!0:e===`static`?!1:this.state.isInvalidated?!0:!Lg(this.state.dataUpdatedAt,e)}onFocus(){this.observers.find(e=>e.shouldFetchOnWindowFocus())?.refetch({cancelRefetch:!1}),this.#a?.continue()}onOnline(){this.observers.find(e=>e.shouldFetchOnReconnect())?.refetch({cancelRefetch:!1}),this.#a?.continue()}addObserver(e){this.observers.includes(e)||(this.observers.push(e),this.clearGcTimeout(),this.#r.notify({type:`observerAdded`,query:this,observer:e}))}removeObserver(e){let t=this.observers.indexOf(e);t!==-1&&(this.observers.splice(t,1),this.observers.length||(this.#a&&(this.#s||this.state.fetchStatus===`paused`&&this.state.status===`pending`?this.#a.cancel({revert:!0}):this.#a.cancelRetry()),this.scheduleGc()),this.#r.notify({type:`observerRemoved`,query:this,observer:e}))}getObserversCount(){return this.observers.length}invalidate(){this.state.isInvalidated||this.#c({type:`invalidate`})}async fetch(e,t){if(this.state.fetchStatus!==`idle`&&this.#a?.status()!==`rejected`){if(this.state.data!==void 0&&t?.cancelRefetch)this.cancel({silent:!0});else if(this.#a)return this.#a.continueRetry(),this.#a.promise}if(e&&this.setOptions(e),!this.options.queryFn){let e=this.observers.find(e=>e.options.queryFn);e&&this.setOptions(e.options)}let n=new AbortController,r=e=>{Object.defineProperty(e,"signal",{enumerable:!0,get:()=>(this.#s=!0,n.signal)})},i=()=>{let e=t_(this.options,t),n=(()=>{let e={client:this.#i,queryKey:this.queryKey,meta:this.meta};return r(e),e})();return this.#s=!1,this.options.persister?this.options.persister(e,n,this):e(n)},a=(()=>{let e={fetchOptions:t,options:this.options,queryKey:this.queryKey,client:this.#i,state:this.state,fetchFn:i};return r(e),e})();(this.#e===`infinite`?__(this.options.pages):this.options.behavior)?.onFetch(a,this),this.#n=this.state,(this.state.fetchStatus===`idle`||this.state.fetchMeta!==a.fetchOptions?.meta)&&this.#c({type:`fetch`,meta:a.fetchOptions?.meta});let o=this.#a=h_({initialPromise:t?.initialPromise,fn:a.fetchFn,onCancel:e=>{e instanceof m_&&e.revert&&this.setState({...this.#n,fetchStatus:`idle`}),n.abort()},onFail:(e,t)=>{this.#c({type:`failed`,failureCount:e,error:t})},onPause:()=>{this.#c({type:`pause`})},onContinue:()=>{this.#c({type:`continue`})},retry:a.options.retry,retryDelay:a.options.retryDelay,networkMode:a.options.networkMode,canRun:()=>!0});try{let e=await o.start();if(e===void 0)throw Error(`${this.queryHash} data is undefined`);return this.setData(e),this.#r.config.onSuccess?.(e,this),this.#r.config.onSettled?.(e,this.state.error,this),e}catch(e){if(e instanceof m_){if(e.silent)return this.#a.promise;if(e.revert){if(this.state.data===void 0)throw e;return this.state.data}}throw this.#c({type:`error`,error:e}),this.#r.config.onError?.(e,this),this.#r.config.onSettled?.(this.state.data,e,this),e}finally{this.#a===o&&(this.#a=void 0),this.scheduleGc()}}#c(e){let t=t=>{switch(e.type){case`failed`:return{...t,fetchFailureCount:e.failureCount,fetchFailureReason:e.error};case`pause`:return{...t,fetchStatus:`paused`};case`continue`:return{...t,fetchStatus:`fetching`};case`fetch`:return{...t,...x_(t.data,this.options),fetchMeta:e.meta??null};case`success`:let n={...t,...S_(e.data,e.dataUpdatedAt),dataUpdateCount:t.dataUpdateCount+1,...!e.manual&&{fetchStatus:`idle`,fetchFailureCount:0,fetchFailureReason:null}};return this.#n=e.manual?n:void 0,n;case`error`:let r=e.error;return{...t,error:r,errorUpdateCount:t.errorUpdateCount+1,errorUpdatedAt:Date.now(),fetchFailureCount:t.fetchFailureCount+1,fetchFailureReason:r,fetchStatus:`idle`,status:`error`,isInvalidated:!0};case`invalidate`:return{...t,isInvalidated:!0};case`setState`:return{...t,...e.state}}};this.state=t(this.state),u_.batch(()=>{this.observers.slice().forEach(e=>{e.onQueryUpdate()}),this.#r.notify({query:this,type:`updated`,action:e})})}};function x_(e,t){return{fetchFailureCount:0,fetchFailureReason:null,fetchStatus:p_(t.networkMode)?`fetching`:`paused`,...e===void 0&&{error:null,status:`pending`}}}function S_(e,t){return{data:e,dataUpdatedAt:t??Date.now(),error:null,isInvalidated:!1,status:`success`}}function C_(e){let t=typeof e.initialData==`function`?e.initialData():e.initialData,n=t!==void 0,r=n?typeof e.initialDataUpdatedAt==`function`?e.initialDataUpdatedAt():e.initialDataUpdatedAt:0;return{data:t,dataUpdateCount:0,dataUpdatedAt:n?r??Date.now():0,error:null,errorUpdateCount:0,errorUpdatedAt:0,fetchFailureCount:0,fetchFailureReason:null,fetchMeta:null,isInvalidated:!1,status:n?`success`:`pending`,fetchStatus:`idle`}}var w_=class extends o_{#e;#t=void 0;#n=void 0;#r=void 0;#i;#a;#o;#s;#c;#l;#u;#d;#f;#p=new Set;constructor(e,t){super(),this.options=t,this.#e=e,this.#o=null,this.bindMethods(),this.setOptions(t)}bindMethods(){this.refetch=this.refetch.bind(this)}onSubscribe(){this.listeners.size===1&&(this.#t.addObserver(this),E_(this.#t,this.options)?this.#m():this.updateResult(),this.#y())}onUnsubscribe(){this.hasListeners()||this.destroy()}shouldFetchOnReconnect(){return D_(this.#t,this.options,this.options.refetchOnReconnect)}shouldFetchOnWindowFocus(){return D_(this.#t,this.options,this.options.refetchOnWindowFocus)}destroy(){this.listeners=new Set,this.#b(),this.#x(),this.#t.removeObserver(this)}setOptions(e){let t=this.options,n=this.#t;if(this.options=this.#e.defaultQueryOptions(e),this.options.enabled!==void 0&&typeof this.options.enabled!=`boolean`&&typeof this.options.enabled!=`function`&&typeof Rg(this.options.enabled,this.#t)!=`boolean`)throw Error(`Expected enabled to be a boolean or a callback that returns a boolean`);this.#S(),this.#t.setOptions(this.options),t._defaulted&&!Kg(this.options,t)&&this.#e.getQueryCache().notify({type:`observerOptionsUpdated`,query:this.#t,observer:this});let r=this.hasListeners();r&&O_(this.#t,n,this.options,t)&&this.#m(),this.updateResult(),r&&(this.#t!==n||Rg(this.options.enabled,this.#t)!==Rg(t.enabled,this.#t)||Rg(this.options.staleTime,this.#t)!==Rg(t.staleTime,this.#t))&&this.#g();let i=this.#_();r&&(this.#t!==n||Rg(this.options.enabled,this.#t)!==Rg(t.enabled,this.#t)||i!==this.#f)&&this.#v(i)}getOptimisticResult(e){let t=this.#e.getQueryCache().build(this.#e,e),n=this.createResult(t,e);return Kg(this.getCurrentResult(),n)||(this.#r=n,this.#a=this.options,this.#i=this.#t.state),n}getCurrentResult(){return this.#r}trackResult(e,t){return new Proxy(e,{get:(e,n)=>(this.trackProp(n),t?.(n),Reflect.get(e,n))})}trackProp(e){this.#p.add(e)}getCurrentQuery(){return this.#t}refetch({...e}={}){return this.fetch({...e})}fetchOptimistic(e){let t=this.#e.defaultQueryOptions(e),n=this.#e.getQueryCache().build(this.#e,t),r=()=>{},i,a=new Promise(e=>{i=e,r=this.#e.getQueryCache().subscribe(i=>{i.type===`updated`&&i.query.queryHash===n.queryHash&&n.state.data!==void 0&&(r(),e(this.createResult(n,t)))})});return Promise.race([n.fetch().then(()=>{let e=this.createResult(n,t);return i?.(e),e}).finally(()=>{r()}),a])}fetch(e){return this.#m({...e,cancelRefetch:e.cancelRefetch??!0}).then(()=>(this.updateResult(),this.#r))}#m(e){this.#S();let t=this.#t.fetch(this.options,e);return e?.throwOnError||(t=t.catch(Pg)),t}#h(e){return!a_()&&Rg(this.options.enabled,this.#t)!==!1&&Ig(e)}#g(){this.#b();let e=Rg(this.options.staleTime,this.#t);if(this.#r.isStale||!this.#h(e))return;let t=Lg(this.#r.dataUpdatedAt,e)+1;this.#u=jg.setTimeout(()=>{this.#r.isStale||this.updateResult()},t)}#_(){return Rg(this.options.refetchInterval,this.#t)??!1}#v(e){this.#x(),this.#f=e,this.#f!==0&&this.#h(this.#f)&&(this.#d=jg.setInterval(()=>{(this.options.refetchIntervalInBackground||s_.isFocused())&&this.#m()},this.#f))}#y(){this.#g(),this.#v(this.#_())}#b(){this.#u!==void 0&&(jg.clearTimeout(this.#u),this.#u=void 0)}#x(){this.#d!==void 0&&(jg.clearInterval(this.#d),this.#d=void 0)}createResult(e,t){let n=this.#t,r=this.options,i=this.#r,a=this.#i,o=this.#a,s=e===n?this.#n:e.state,{state:c}=e,l={...c},u=!1,d;if(t._optimisticResults){let i=this.hasListeners(),a=!i&&E_(e,t),o=i&&O_(e,n,t,r);(a||o)&&(l={...l,...x_(c.data,e.options)}),t._optimisticResults===`isRestoring`&&(l.fetchStatus=`idle`)}let{error:f,errorUpdatedAt:p,status:m}=l;d=l.data;let h=!1;if(t.placeholderData!==void 0&&d===void 0&&m===`pending`){let e;i?.isPlaceholderData&&t.placeholderData===o?.placeholderData?(e=i.data,h=!0):e=typeof t.placeholderData==`function`?t.placeholderData(this.#l?.state.data,this.#l):t.placeholderData,e!==void 0&&(m=`success`,d=Zg(i?.data,e,t),u=!0)}if(t.select&&d!==void 0&&!h){if(i&&d===a?.data&&t.select===this.#s)d=this.#c;else try{this.#s=t.select,d=t.select(d),d=Zg(i?.data,d,t),this.#c=d,this.#o=null}catch(e){this.#o=e}}else d===void 0&&(this.#o=null);this.#o&&(f=this.#o,d=this.#c,p=Date.now(),m=`error`,u=!1);let g=l.fetchStatus===`fetching`,_=m===`pending`,v=m===`error`,y=_&&g,b=d!==void 0;return{status:m,fetchStatus:l.fetchStatus,isPending:_,isSuccess:m===`success`,isError:v,isInitialLoading:y,isLoading:y,data:d,dataUpdatedAt:l.dataUpdatedAt,error:f,errorUpdatedAt:p,failureCount:l.fetchFailureCount,failureReason:l.fetchFailureReason,errorUpdateCount:l.errorUpdateCount,isFetched:e.isFetched(),isFetchedAfterMount:l.dataUpdateCount>s.dataUpdateCount||l.errorUpdateCount>s.errorUpdateCount,isFetching:g,isRefetching:g&&!_,isLoadingError:v&&!b,isPaused:l.fetchStatus===`paused`,isPlaceholderData:u,isRefetchError:v&&b,isStale:k_(e,t),refetch:this.refetch,isEnabled:Rg(t.enabled,e)!==!1}}updateResult(){let e=this.#r,t=this.createResult(this.#t,this.options);if(this.#i=this.#t.state,this.#a=this.options,this.#i.data!==void 0&&(this.#l=this.#t),Kg(t,e))return;this.#r=t;let n=(()=>{if(!e)return!0;let{notifyOnChangeProps:t}=this.options,n=typeof t==`function`?t():t;if(n===`all`||!n&&!this.#p.size)return!0;let r=new Set(n??this.#p);return this.options.throwOnError&&r.add(`error`),Object.keys(this.#r).some(t=>{let n=t;return this.#r[n]!==e[n]&&r.has(n)})})();u_.batch(()=>{n&&this.listeners.forEach(e=>{e(this.#r)}),this.#e.getQueryCache().notify({query:this.#t,type:`observerResultsUpdated`})})}#S(){let e=this.#e.getQueryCache().build(this.#e,this.options);if(e===this.#t)return;let t=this.#t;this.#t=e,this.#n=e.state,this.hasListeners()&&(t?.removeObserver(this),e.addObserver(this))}onQueryUpdate(){this.updateResult(),this.hasListeners()&&this.#y()}};function T_(e,t){return Rg(t.enabled,e)!==!1&&e.state.data===void 0&&(e.state.status!==`error`||Rg(t.retryOnMount,e)!==!1)}function E_(e,t){return T_(e,t)||e.state.data!==void 0&&D_(e,t,t.refetchOnMount)}function D_(e,t,n){if(Rg(t.enabled,e)!==!1&&Rg(t.staleTime,e)!==`static`){let r=Rg(n,e);return r===`always`||r!==!1&&k_(e,t)}return!1}function O_(e,t,n,r){return(e!==t||Rg(r.enabled,e)===!1)&&(!n.suspense||e.state.status!==`error`)&&k_(e,n)}function k_(e,t){return Rg(t.enabled,e)!==!1&&e.isStaleByTime(Rg(t.staleTime,e))}var A_=class extends g_{#e;#t;#n;#r;constructor(e){super(),this.#e=e.client,this.mutationId=e.mutationId,this.#n=e.mutationCache,this.#t=[],this.state=e.state||j_(),this.setOptions(e.options),this.scheduleGc()}setOptions(e){this.options=e,this.updateGcTime(this.options.gcTime)}get meta(){return this.options.meta}addObserver(e){this.#t.includes(e)||(this.#t.push(e),this.clearGcTimeout(),this.#n.notify({type:`observerAdded`,mutation:this,observer:e}))}removeObserver(e){this.#t=this.#t.filter(t=>t!==e),this.scheduleGc(),this.#n.notify({type:`observerRemoved`,mutation:this,observer:e})}optionalRemove(){this.#t.length||(this.state.status===`pending`?this.scheduleGc():this.#n.remove(this))}continue(){return this.#r?.continue()??(this.state.status===`pending`?this.execute(this.state.variables):Promise.resolve())}async execute(e){let t=()=>{this.#i({type:`continue`})},n={client:this.#e,meta:this.options.meta,mutationKey:this.options.mutationKey},r=this.#r=h_({fn:()=>this.options.mutationFn?this.options.mutationFn(e,n):Promise.reject(Error(`No mutationFn found`)),onFail:(e,t)=>{this.#i({type:`failed`,failureCount:e,error:t})},onPause:()=>{this.#i({type:`pause`})},onContinue:t,retry:this.options.retry??0,retryDelay:this.options.retryDelay,networkMode:this.options.networkMode,canRun:()=>this.#n.canRun(this)}),i=this.state.status===`pending`,a=!r.canStart();try{if(i)t();else{this.#i({type:`pending`,variables:e,isPaused:a}),this.#n.config.onMutate&&await this.#n.config.onMutate(e,this,n);let t=await this.options.onMutate?.(e,n);t!==this.state.context&&this.#i({type:`pending`,context:t,variables:e,isPaused:a})}let o=await r.start();return await this.#n.config.onSuccess?.(o,e,this.state.context,this,n),await this.options.onSuccess?.(o,e,this.state.context,n),await this.#n.config.onSettled?.(o,null,this.state.variables,this.state.context,this,n),await this.options.onSettled?.(o,null,e,this.state.context,n),this.#i({type:`success`,data:o}),o}catch(t){try{await this.#n.config.onError?.(t,e,this.state.context,this,n)}catch(e){Promise.reject(e)}try{await this.options.onError?.(t,e,this.state.context,n)}catch(e){Promise.reject(e)}try{await this.#n.config.onSettled?.(void 0,t,this.state.variables,this.state.context,this,n)}catch(e){Promise.reject(e)}try{await this.options.onSettled?.(void 0,t,e,this.state.context,n)}catch(e){Promise.reject(e)}throw this.#i({type:`error`,error:t}),t}finally{this.#r===r&&(this.#r=void 0),this.#n.runNext(this)}}#i(e){let t=t=>{switch(e.type){case`failed`:return{...t,failureCount:e.failureCount,failureReason:e.error};case`pause`:return{...t,isPaused:!0};case`continue`:return{...t,isPaused:!1};case`pending`:return{...t,context:e.context,data:void 0,failureCount:0,failureReason:null,error:null,isPaused:e.isPaused,status:`pending`,variables:e.variables,submittedAt:Date.now()};case`success`:return{...t,data:e.data,failureCount:0,failureReason:null,error:null,status:`success`,isPaused:!1};case`error`:return{...t,data:void 0,error:e.error,failureCount:t.failureCount+1,failureReason:e.error,isPaused:!1,status:`error`}}};this.state=t(this.state),u_.batch(()=>{this.#t.forEach(t=>{t.onMutationUpdate(e)}),this.#n.notify({mutation:this,type:`updated`,action:e})})}};function j_(){return{context:void 0,data:void 0,error:null,failureCount:0,failureReason:null,isPaused:!1,status:`idle`,variables:void 0,submittedAt:0}}var M_=class extends o_{#e;#t;#n;constructor(e={}){super(),this.config=e,this.#e=new Set,this.#t=new Map,this.#n=0}build(e,t,n){let r=new A_({client:e,mutationCache:this,mutationId:++this.#n,options:e.defaultMutationOptions(t),state:n});return this.add(r),r}add(e){this.#e.add(e);let t=N_(e);if(typeof t==`string`){let n=this.#t.get(t);n?n.push(e):this.#t.set(t,[e])}this.notify({type:`added`,mutation:e})}remove(e){if(this.#e.delete(e)){let t=N_(e);if(typeof t==`string`){let n=this.#t.get(t);if(n){if(n.length>1){let t=n.indexOf(e);t!==-1&&n.splice(t,1)}else n[0]===e&&this.#t.delete(t)}}}this.notify({type:`removed`,mutation:e})}canRun(e){let t=N_(e);if(typeof t==`string`){let n=this.#t.get(t)?.find(e=>e.state.status===`pending`);return!n||n===e}return!0}runNext(e){let t=N_(e);return typeof t==`string`?(this.#t.get(t)?.find(t=>t!==e&&t.state.isPaused))?.continue()??Promise.resolve():Promise.resolve()}clear(){u_.batch(()=>{this.#e.forEach(e=>{this.notify({type:`removed`,mutation:e})}),this.#e.clear(),this.#t.clear()})}getAll(){return Array.from(this.#e)}find(e){let t={exact:!0,...e};return this.getAll().find(e=>Bg(t,e))}findAll(e={}){return this.getAll().filter(t=>Bg(e,t))}notify(e){u_.batch(()=>{this.listeners.forEach(t=>{t(e)})})}resumePausedMutations(){let e=this.getAll().filter(e=>e.state.isPaused);return u_.batch(()=>Promise.all(e.map(e=>e.continue().catch(Pg))))}};function N_(e){return e.options.scope?.id}var P_=class extends o_{#e;constructor(e={}){super(),this.config=e,this.#e=new Map}build(e,t,n){let r=t.queryKey,i=t.queryHash??Vg(r,t),a=this.get(i);return a||(a=new b_({client:e,queryKey:r,queryHash:i,options:e.defaultQueryOptions(t),state:n,defaultOptions:e.getQueryDefaults(r)}),this.add(a)),a}add(e){this.#e.has(e.queryHash)||(this.#e.set(e.queryHash,e),this.notify({type:`added`,query:e}))}remove(e){this.#e.get(e.queryHash)===e&&(e.destroy(),this.#e.delete(e.queryHash),this.notify({type:`removed`,query:e}))}clear(){u_.batch(()=>{this.getAll().forEach(e=>{this.remove(e)})})}get(e){return this.#e.get(e)}getAll(){return[...this.#e.values()]}find(e){let t={exact:!0,...e};return this.getAll().find(e=>zg(t,e))}findAll(e={}){let t=this.getAll();return Object.keys(e).length>0?t.filter(t=>zg(e,t)):t}notify(e){u_.batch(()=>{this.listeners.forEach(t=>{t(e)})})}onFocus(){u_.batch(()=>{this.getAll().forEach(e=>{e.onFocus()})})}onOnline(){u_.batch(()=>{this.getAll().forEach(e=>{e.onOnline()})})}},F_=class{#e;#t;#n;#r;#i;#a;#o;#s;constructor(e={}){this.#e=e.queryCache||new P_,this.#t=e.mutationCache||new M_,this.#n=e.defaultOptions||{},this.#r=new Map,this.#i=new Map,this.#a=0}mount(){this.#a++,this.#a===1&&(this.#o=s_.subscribe(async e=>{e&&(await this.resumePausedMutations(),this.#e.onFocus())}),this.#s=d_.subscribe(async e=>{e&&(await this.resumePausedMutations(),this.#e.onOnline())}))}unmount(){this.#a--,this.#a===0&&(this.#o?.(),this.#o=void 0,this.#s?.(),this.#s=void 0)}isFetching(e){return this.#e.findAll({...e,fetchStatus:`fetching`}).length}isMutating(e){return this.#t.findAll({...e,status:`pending`}).length}getQueryData(e){let t=this.defaultQueryOptions({queryKey:e});return this.#e.get(t.queryHash)?.state.data}ensureQueryData(e){let t=this.defaultQueryOptions(e),n=this.#e.build(this,t),r=n.state.data;return r===void 0?this.fetchQuery(e):(e.revalidateIfStale&&n.isStaleByTime(Rg(t.staleTime,n))&&this.prefetchQuery(t),Promise.resolve(r))}getQueriesData(e){return this.#e.findAll(e).map(({queryKey:e,state:t})=>[e,t.data])}setQueryData(e,t,n){let r=this.defaultQueryOptions({queryKey:e}),i=this.#e.get(r.queryHash)?.state.data,a=Fg(t,i);if(a!==void 0)return this.#e.build(this,r).setData(a,{...n,manual:!0})}setQueriesData(e,t,n){return u_.batch(()=>this.#e.findAll(e).map(({queryKey:e})=>[e,this.setQueryData(e,t,n)]))}getQueryState(e){let t=this.defaultQueryOptions({queryKey:e});return this.#e.get(t.queryHash)?.state}removeQueries(e){let t=this.#e;u_.batch(()=>{t.findAll(e).forEach(e=>{t.remove(e)})})}resetQueries(e,t){let n=this.#e;return u_.batch(()=>{let r=n.findAll(e),i=new Set(r);return r.forEach(e=>{e.reset()}),this.refetchQueries({type:`active`,predicate:e=>i.has(e)},t)})}cancelQueries(e,t={}){let n={revert:!0,...t},r=u_.batch(()=>this.#e.findAll(e).map(e=>e.cancel(n)));return Promise.all(r).then(Pg).catch(Pg)}invalidateQueries(e,t={}){return u_.batch(()=>(this.#e.findAll(e).forEach(e=>{e.invalidate()}),e?.refetchType===`none`?Promise.resolve():this.refetchQueries({...e,type:e?.refetchType??e?.type??`active`},t)))}refetchQueries(e,t={}){let n={...t,cancelRefetch:t.cancelRefetch??!0},r=u_.batch(()=>this.#e.findAll(e).filter(e=>!e.isDisabled()&&!e.isStatic()).map(e=>{let t=e.fetch(void 0,n);return n.throwOnError||(t=t.catch(Pg)),e.state.fetchStatus===`paused`?Promise.resolve():t}));return Promise.all(r).then(Pg)}async query(e){let t=this.defaultQueryOptions(e);t.retry===void 0&&(t.retry=!1);let n=this.#e.build(this,t),r=n.isStaleByTime(Rg(t.staleTime,n))?await n.fetch(t):n.state.data,i=t.select;return i?i(r):r}fetchQuery(e){let t=this.defaultQueryOptions(e);t.retry===void 0&&(t.retry=!1);let n=this.#e.build(this,t);return n.isStaleByTime(Rg(t.staleTime,n))?n.fetch(t):Promise.resolve(n.state.data)}prefetchQuery(e){return this.fetchQuery(e).then(Pg).catch(Pg)}infiniteQuery(e){return e._type=`infinite`,this.query(e)}fetchInfiniteQuery(e){return e._type=`infinite`,this.fetchQuery(e)}prefetchInfiniteQuery(e){return this.fetchInfiniteQuery(e).then(Pg).catch(Pg)}ensureInfiniteQueryData(e){return e._type=`infinite`,this.ensureQueryData(e)}resumePausedMutations(){return d_.isOnline()?this.#t.resumePausedMutations():Promise.resolve()}getQueryCache(){return this.#e}getMutationCache(){return this.#t}getDefaultOptions(){return this.#n}setDefaultOptions(e){this.#n=e}setQueryDefaults(e,t){this.#r.set(Hg(e),{queryKey:e,defaultOptions:t})}getQueryDefaults(e){let t=[...this.#r.values()],n={};return t.forEach(t=>{Ug(e,t.queryKey)&&Object.assign(n,t.defaultOptions)}),n}setMutationDefaults(e,t){this.#i.set(Hg(e),{mutationKey:e,defaultOptions:t})}getMutationDefaults(e){let t=[...this.#i.values()],n={};return t.forEach(t=>{Ug(e,t.mutationKey)&&Object.assign(n,t.defaultOptions)}),n}defaultQueryOptions(e){if(e._defaulted)return e;let t={...this.#n.queries,...this.getQueryDefaults(e.queryKey),...e,_defaulted:!0};return t.queryHash||=Vg(t.queryKey,t),t.refetchOnReconnect===void 0&&(t.refetchOnReconnect=t.networkMode!==`always`),t.throwOnError===void 0&&(t.throwOnError=!!t.suspense),!t.networkMode&&t.persister&&(t.networkMode=`offlineFirst`),t.queryFn===e_&&(t.enabled=!1),t}defaultMutationOptions(e){return e?._defaulted?e:{...this.#n.mutations,...e?.mutationKey&&this.getMutationDefaults(e.mutationKey),...e,_defaulted:!0}}clear(){this.#e.clear(),this.#t.clear()}},I_=l.createContext(!1),L_=()=>l.useContext(I_);I_.Provider;function R_(){let e=!1;return{clearReset:()=>{e=!1},reset:()=>{e=!0},isReset:()=>e}}var z_=l.createContext(R_()),B_=()=>l.useContext(z_),V_=(e,t,n)=>{let r=n?.state.error&&typeof e.throwOnError==`function`?n_(e.throwOnError,[n.state.error,n]):e.throwOnError;(e.suspense||r)&&(t.isReset()||(e.retryOnMount=!1))},H_=e=>{l.useEffect(()=>{e.clearReset()},[e])},U_=({result:e,errorResetBoundary:t,throwOnError:n,query:r,suspense:i})=>e.isError&&!t.isReset()&&!e.isFetching&&r&&(i&&e.data===void 0||n_(n,[e.error,r])),W_=e=>{if(e.suspense){let t=1e3,n=e=>e===`static`?e:Math.max(e??t,t),r=e.staleTime;e.staleTime=typeof r==`function`?(...e)=>n(r(...e)):n(r),typeof e.gcTime==`number`&&(e.gcTime=Math.max(e.gcTime,t))}},G_=(e,t)=>e?.suspense&&t.isPending,K_=(e,t,n)=>t.fetchOptimistic(e).catch(()=>{n.clearReset()});function q_(e,t,n){let r=L_(),i=B_(),a=Og(n),o=a.defaultQueryOptions(e),s=a.getQueryCache().get(o.queryHash),c=e.subscribed!==!1;o._optimisticResults=r?`isRestoring`:c?`optimistic`:void 0,W_(o),V_(o,i,s),H_(i);let[u]=l.useState(()=>new t(a,o)),d=u.getOptimisticResult(o),f=!r&&c;if(l.useSyncExternalStore(l.useCallback(e=>{let t=f?u.subscribe(u_.batchCalls(e)):Pg;return u.updateResult(),t},[u,f]),()=>u.getCurrentResult(),()=>u.getCurrentResult()),l.useEffect(()=>{u.setOptions(o)},[o,u]),G_(o,d))throw K_(o,u,i);if(U_({result:d,errorResetBoundary:i,throwOnError:o.throwOnError,query:s,suspense:o.suspense}))throw d.error;return o.notifyOnChangeProps?d:u.trackResult(d)}function J_(e,t){return q_(e,w_,t)}var Y_=1e3,X_=e=>`webr-catalog:${e}`,Z_=e=>{try{return JSON.parse(localStorage.getItem(X_(e))??`null`)??void 0}catch{return}},Q_=(e,t)=>{try{localStorage.setItem(X_(e),JSON.stringify(t))}catch{}};function $_(e,t,n=1,r=``,i=``){return J_({queryKey:[`machine-catalog`,e,r,n,i],enabled:!!e&&t,placeholderData:()=>Z_(e),refetchInterval:e=>e.state.data?.modelsPending?Y_:!1,queryFn:async({signal:t})=>{let n=await fetch(`/api/catalog/`+encodeURIComponent(e)+(i?`?projectId=`+encodeURIComponent(i):``),{signal:t});if(!n.ok)throw Error(`Machine catalog is not available.`);let r=await n.json();return Q_(e,r),r}})}var ev=e=>e.startsWith(`/`)||e.startsWith(`~`),tv=e=>Array.isArray(e)?e.filter(e=>typeof e==`string`):[];function nv(e,t){let[n,r]=(0,l.useState)([]);return(0,l.useEffect)(()=>{if(!ev(t)){r([]);return}let n=new AbortController;return fetch(`/api/directories?machineId=${encodeURIComponent(e)}&prefix=${encodeURIComponent(t)}`,{signal:n.signal}).then(e=>e.ok?e.json():[]).then(e=>r(tv(e))).catch(()=>{}),()=>n.abort()},[e,t]),n}var rv=e=>e.startsWith(`/`)||e.startsWith(`~/`);function iv({machineId:e,onCreated:t}){let[n,r]=(0,l.useState)(``),[i,a]=(0,l.useState)(``),[o,s]=(0,l.useState)(!1),[c,u]=(0,l.useState)(``),[d,f]=(0,l.useState)(0),[p,m]=(0,l.useState)(!1),h=nv(e,n),g=p&&h.length>0&&(h.length!==1||h[0]!==n),_=e=>{r(e),f(0),m(!0)},v=e=>{g&&(e.key===`ArrowDown`||e.key===`ArrowUp`?(e.preventDefault(),f(t=>(t+(e.key===`ArrowDown`?1:h.length-1))%h.length)):e.key===`Tab`?(e.preventDefault(),_(h[d]??h[0])):e.key===`Enter`?(e.preventDefault(),_(h[d]??h[0]),m(!1)):e.key===`Escape`&&m(!1))},y=(0,l.useRef)(null);return(0,Q.jsxs)(`form`,{className:`thread-composer workspace-composer`,onSubmit:async r=>{r.preventDefault(),s(!0),u(``);let a=JSON.stringify({machineId:e,path:n,label:i});y.current?.payload!==a&&(y.current={payload:a,key:cm()});try{let e=await fetch(`/api/workspaces`,{method:`POST`,headers:{"Content-Type":`application/json`,"Idempotency-Key":y.current.key},body:a}),n=await e.json();if(!e.ok)throw Error(n.error??`Could not create workspace`);if(n.state===`unknown`)throw Error(`The result is not known; check Herdr before you create another workspace.`);t()}catch(e){u(e instanceof Error?e.message:`Could not create workspace`)}finally{s(!1)}},"aria-label":`Create workspace`,"aria-busy":o,children:[(0,Q.jsxs)(`label`,{className:`path-field`,children:[`Project folder`,(0,Q.jsx)(`input`,{value:n,onChange:e=>{r(e.target.value),f(0),m(!0)},onKeyDown:v,onBlur:()=>m(!1),placeholder:`/absolute/path/to/project`,autoComplete:`off`,spellCheck:!1,role:`combobox`,"aria-expanded":g,"aria-autocomplete":`list`,required:!0,pattern:`(/|~/).*`}),g&&(0,Q.jsx)(`ul`,{className:`path-suggestions`,role:`listbox`,children:h.map((e,t)=>(0,Q.jsx)(`li`,{role:`option`,"aria-selected":t===d,"data-highlighted":t===d||void 0,onMouseDown:t=>{t.preventDefault(),_(e)},children:e},e))})]}),(0,Q.jsxs)(`label`,{children:[`Workspace name`,(0,Q.jsx)(`input`,{value:i,onChange:e=>a(e.target.value),required:!0,maxLength:80})]}),(0,Q.jsx)(`button`,{type:`submit`,disabled:o||!rv(n)||!i.trim(),children:o?`Creating…`:`Create workspace`}),c&&(0,Q.jsx)(`p`,{className:`form-error`,role:`alert`,children:c})]})}var av={main:`Main checkout`,worktree:`New worktree`,remember:`Remember by project`},ov=`webr-new-session-behavior`,sv=`webr-new-worktree`,cv=(e,t)=>`webr-last-worktree:${e}:${t}`,lv=e=>e===`main`||e===`worktree`||e===`remember`,uv=()=>{let e=localStorage.getItem(sv);return e===null?`remember`:e===`false`?`main`:`worktree`};function dv(){let e=localStorage.getItem(ov);return lv(e)?e:uv()}function fv(e){localStorage.setItem(ov,e)}function pv(e,t,n){localStorage.setItem(cv(e,t),String(n))}var mv=(e,t)=>localStorage.getItem(cv(e,t))!==`false`;function hv(e,t){let n=dv();return n===`remember`?mv(e,t):n===`worktree`}var gv=`webr-new-thread-draft`,_v=e=>!!e&&typeof e==`object`&&[`id`,`name`,`preview`,`path`].every(t=>typeof e[t]==`string`);function vv(){try{let e=JSON.parse(localStorage.getItem(gv)??`{}`);return{prompt:typeof e.prompt==`string`?e.prompt:``,images:Array.isArray(e.images)?e.images.filter(_v):[]}}catch{return{prompt:``,images:[]}}}function yv(e){try{!e.prompt&&!e.images.length?localStorage.removeItem(gv):localStorage.setItem(gv,JSON.stringify(e))}catch{}}var bv=()=>yv({prompt:``,images:[]}),xv=(e,t)=>`webr-last-harness:${e}:${t}`;function Sv({projects:e,machines:t,selectedProjectId:n,onOpenSidebar:r}){let[i,o]=(0,l.useState)(e.find(e=>e.id===n)?.id??e[0]?.id??``),[s,c]=(0,l.useState)(t.find(e=>n&&Object.hasOwn(e.projectPaths,n))?.id??t[0]?.id??``),[u,d]=(0,l.useState)(``),[f,p]=(0,l.useState)(`Default`),[m,h]=(0,l.useState)(!0),[g,v]=(0,l.useState)(``),[y,b]=(0,l.useState)(!1),[x,S]=(0,l.useState)(``),[C,w]=(0,l.useState)(!1),T=(0,l.useRef)(null),E=(0,l.useRef)(null),D=fm({machineId:s}),O=t.find(e=>e.id===s)??{id:``,name:`No target`,connected:!1,session:``,projectPaths:{},harnesses:[]},A=$_(s,O.connected,O.configVersion,O.session,i),j={...O,harnesses:O.connected?A.data?.harnesses??[]:[]},N=e.filter(e=>Object.hasOwn(j.projectPaths,e.id)).map(e=>({...e,path:j.projectPaths[e.id],iconUrl:s===`local`?e.iconUrl:void 0})),P=A.data?.isGitRepo===!0,F=j.harnesses.find(e=>e.id===u),I=!!(g.trim()&&!D.uploading&&f.trim()&&j.connected&&N.some(e=>e.id===i)&&F?.launchEnabled)&&!y,L=A.data?.harnesses.map(e=>e.id).join(`,`),R=(0,l.useRef)(!1);(0,l.useEffect)(()=>{let e=vv();v(e.prompt),D.setAttachments(e.images),R.current=!0},[]),(0,l.useEffect)(()=>{R.current&&yv({prompt:g,images:D.attachments})},[g,D.attachments]),(0,l.useEffect)(()=>{h(hv(s,i))},[s,i]),(0,l.useEffect)(()=>{if(!i||!A.data)return;let e=A.data.harnesses,t=localStorage.getItem(xv(s,i));d(e.find(e=>e.id===t)?.id??e.find(e=>e.launchEnabled)?.id??e[0]?.id??``),p(`Default`)},[s,i,L]),(0,l.useEffect)(()=>{let e=T.current,t=e&&N.find(t=>!e.has(t.id));t&&(T.current=null,ee(t.id))},[N]),(0,l.useEffect)(()=>{!s&&t.length&&c(t.find(e=>e.id===`local`)?.id??t[0].id),!i&&N.length&&o(N[0].id)},[t,s,N,i]);let z=n=>{let r=t.find(e=>e.id===n);r?.connected&&(c(n),Object.hasOwn(r.projectPaths,i)||o(e.find(e=>Object.hasOwn(r.projectPaths,e.id))?.id??``),d(``),p(`Default`),S(``))},ee=e=>{o(e),d(``),p(`Default`),S(``)},B=e=>{d(e),p(`Default`),i&&localStorage.setItem(xv(s,i),e)};return(0,Q.jsxs)(`main`,{className:`new-thread-page`,"aria-label":`New thread`,children:[(0,Q.jsx)(`button`,{className:`mobile-menu`,onClick:r,children:`Threads`}),(0,Q.jsx)(`h1`,{children:`What do you want to build today?`}),j.connected&&j.writable&&(!N.length||C)?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`p`,{children:N.length?`Add a project to this Herdr session.`:`This Herdr session has no projects yet.`}),(0,Q.jsx)(iv,{machineId:j.id,onCreated:()=>{T.current=new Set(N.map(e=>e.id)),w(!1)}}),!!N.length&&(0,Q.jsx)(`button`,{className:`workspace-cancel`,onClick:()=>w(!1),children:`Cancel`})]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`form`,{className:`thread-composer ${D.dragging?`is-dropping`:``}`,onSubmit:async e=>{if(e.preventDefault(),!I)return;b(!0),S(``);let t=JSON.stringify({prompt:dm(g,D.attachments),projectId:i,machineId:s,agent:u,model:f.trim(),worktree:m&&P});E.current?.payload!==t&&(E.current={payload:t,key:cm()});try{let e=await fetch(`/api/threads`,{method:`POST`,headers:{"Content-Type":`application/json`,"Idempotency-Key":E.current.key},body:t}),n=await e.json();if(!e.ok)throw Error(n.error||`Could not create thread`);pv(s,i,m),bv(),await a(`/threads/${encodeURIComponent(n.id)}`)}catch(e){S(e instanceof Error?e.message:`Could not create thread`),b(!1)}},"aria-busy":y,...D.handlers,children:[(D.attachments.length>0||D.uploading>0)&&(0,Q.jsxs)(`ul`,{className:`composer-images`,"aria-label":`Attached files`,children:[D.attachments.map(e=>(0,Q.jsxs)(`li`,{className:e.preview?void 0:`is-file`,children:[e.preview?(0,Q.jsx)(`img`,{src:e.preview,alt:e.name}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(k,{size:18,strokeWidth:1.8}),(0,Q.jsx)(`span`,{children:e.name})]}),(0,Q.jsx)(Yl,{label:`Remove file`,children:(0,Q.jsx)(`button`,{type:`button`,"aria-label":`Remove ${e.name}`,onClick:()=>D.remove(e.id),children:(0,Q.jsx)(fe,{size:12,strokeWidth:2.4})})})]},e.id)),Array.from({length:D.uploading},(e,t)=>(0,Q.jsx)(`li`,{className:`is-uploading`,"aria-label":`Uploading file`},`uploading-`+t))]}),(0,Q.jsx)(`textarea`,{autoFocus:!0,required:!0,maxLength:8e3,value:g,onChange:e=>v(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),e.currentTarget.form?.requestSubmit())},"aria-label":`Thread prompt`,placeholder:`Write a prompt, or drop an image…`}),(0,Q.jsxs)(`div`,{className:`composer-toolbar`,children:[(0,Q.jsx)(Eg,{machine:j,machines:t,projects:N,projectId:i,harness:u,model:f,onMachineChange:z,onProjectChange:ee,onHarnessChange:B,onModelChange:p,onAddProject:j.connected&&j.writable?()=>w(!0):void 0}),P&&(0,Q.jsx)(Yl,{label:m?`new worktree`:`current checkout`,children:(0,Q.jsxs)(`label`,{className:`worktree-option`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:m,onChange:e=>h(e.target.checked),"aria-label":`Create a new worktree`}),(0,Q.jsx)(M,{size:15,"aria-hidden":`true`})]})}),(0,Q.jsx)(`div`,{className:`composer-actions`,children:(0,Q.jsx)(Yl,{label:`Create thread`,children:(0,Q.jsx)(`button`,{className:`composer-send`,type:`submit`,disabled:!I,"aria-label":`Create thread`,children:y?`…`:(0,Q.jsx)(_,{size:18,strokeWidth:2.2})})})})]})]}),(F?.reason||!t.length||j.error||A.isError)&&(0,Q.jsx)(`p`,{className:`composer-preview-note`,children:F?.reason??(t.length?j.error?`Machine is not connected: ${j.error.replaceAll(`_`,` `)}.`:`The machine catalog is not available.`:`No target is configured.`)}),D.error&&(0,Q.jsx)(`p`,{className:`form-error`,role:`alert`,children:D.error}),x&&(0,Q.jsx)(`p`,{className:`form-error`,role:`alert`,children:x})]})]})}var Cv=es(function(e){return Ec(`dialog`,e)}),wv=52,Tv=`?`;function Ev(e){let t=e.slice(e.indexOf(`;`)+1);if(e.includes(`;`)&&t&&t!==Tv)try{return new TextDecoder(`utf-8`,{fatal:!0}).decode(Uint8Array.from(atob(t),e=>e.charCodeAt(0)))}catch{return}}function Dv(e){let t=t=>{t.clipboardData?.setData(`text/plain`,e),t.preventDefault()};document.addEventListener(`copy`,t,!0);try{return document.execCommand(`copy`)}catch{return!1}finally{document.removeEventListener(`copy`,t,!0)}}async function Ov(e){try{return await navigator.clipboard.writeText(e),!0}catch{return Dv(e)}}var kv=e=>(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement)&&e.selectionStart!==e.selectionEnd||!!document.getSelection()?.toString();function Av(e,t,n,r){let i=()=>{t.hasSelection()&&Ov(t.getSelection()).then(r)},a=e=>{e.defaultPrevented||!t.hasSelection()||kv(e.target)||(e.clipboardData?.setData(`text/plain`,t.getSelection()),e.preventDefault(),r(!0))},o=t.parser.registerOscHandler(wv,e=>{let t=Ev(e);return t!==void 0&&n()&&Ov(t).then(r),!0});return e.addEventListener(`mouseup`,i),window.addEventListener(`copy`,a),()=>{o.dispose(),e.removeEventListener(`mouseup`,i),window.removeEventListener(`copy`,a)}}var jv=(e=>(e[e.Border=-1]=`Border`,e[e.Data=0]=`Data`,e[e.Function=1]=`Function`,e[e.Position=2]=`Position`,e[e.Timing=3]=`Timing`,e[e.Alignment=4]=`Alignment`,e))(jv||{}),Mv=[0,1],Nv=[1,0],Pv=[2,3],Fv=[3,2],Iv={L:Mv,M:Nv,Q:Pv,H:Fv},Lv=/^\d*$/,Rv=/^[A-Z0-9 $%*+./:-]*$/,zv=`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:`,Bv=1,Vv=40,Hv=3,Uv=3,Wv=40,Gv=10,Kv=[[-1,7,10,15,20,26,18,20,24,30,18,20,24,26,30,22,24,28,30,28,28,28,28,30,30,26,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,10,16,26,18,24,16,18,22,22,26,30,22,22,24,24,28,28,26,26,26,26,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28],[-1,13,22,18,26,18,24,18,22,20,24,28,26,24,20,30,24,28,28,26,30,28,30,30,30,30,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,17,28,22,16,22,28,26,26,24,28,24,28,22,24,24,30,28,28,26,28,30,24,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30]],qv=[[-1,1,1,1,1,1,2,2,2,2,4,4,4,4,4,6,6,6,6,7,8,8,9,9,10,12,12,12,13,14,15,16,17,18,19,19,20,21,22,24,25],[-1,1,1,1,2,2,4,4,4,5,5,5,8,9,9,10,10,11,13,14,16,17,17,18,20,21,23,25,26,28,29,31,33,35,37,38,40,43,45,47,49],[-1,1,1,2,2,4,4,6,6,8,8,8,10,12,16,12,17,16,18,21,20,23,23,25,27,29,34,34,35,38,40,43,45,48,51,53,56,59,62,65,68],[-1,1,1,2,4,4,4,5,6,8,8,11,11,16,16,18,16,19,21,25,25,25,34,30,32,35,37,40,42,45,48,51,54,57,60,63,66,70,74,77,81]],Jv=class{constructor(e,t,n,r){if(this.version=e,this.ecc=t,e<Bv||e>Vv)throw RangeError(`Version value out of range`);if(r<-1||r>7)throw RangeError(`Mask value out of range`);this.size=e*4+17;let i=Array.from({length:this.size}).fill(!1);for(let e=0;e<this.size;e++)this.modules.push(i.slice()),this.types.push(i.map(()=>0));this.drawFunctionPatterns();let a=this.addEccAndInterleave(n);if(this.drawCodewords(a),r===-1){let e=1e9;for(let t=0;t<8;t++){this.applyMask(t),this.drawFormatBits(t);let n=this.getPenaltyScore();n<e&&(r=t,e=n),this.applyMask(t)}}this.mask=r,this.applyMask(r),this.drawFormatBits(r)}size;mask;modules=[];types=[];getModule(e,t){return e>=0&&e<this.size&&t>=0&&t<this.size&&this.modules[t][e]}drawFunctionPatterns(){for(let e=0;e<this.size;e++)this.setFunctionModule(6,e,e%2==0,jv.Timing),this.setFunctionModule(e,6,e%2==0,jv.Timing);this.drawFinderPattern(3,3),this.drawFinderPattern(this.size-4,3),this.drawFinderPattern(3,this.size-4);let e=this.getAlignmentPatternPositions(),t=e.length;for(let n=0;n<t;n++)for(let r=0;r<t;r++)n===0&&r===0||n===0&&r===t-1||n===t-1&&r===0||this.drawAlignmentPattern(e[n],e[r]);this.drawFormatBits(0),this.drawVersion()}drawFormatBits(e){let t=this.ecc[1]<<3|e,n=t;for(let e=0;e<10;e++)n=n<<1^(n>>>9)*1335;let r=(t<<10|n)^21522;for(let e=0;e<=5;e++)this.setFunctionModule(8,e,Xv(r,e));this.setFunctionModule(8,7,Xv(r,6)),this.setFunctionModule(8,8,Xv(r,7)),this.setFunctionModule(7,8,Xv(r,8));for(let e=9;e<15;e++)this.setFunctionModule(14-e,8,Xv(r,e));for(let e=0;e<8;e++)this.setFunctionModule(this.size-1-e,8,Xv(r,e));for(let e=8;e<15;e++)this.setFunctionModule(8,this.size-15+e,Xv(r,e));this.setFunctionModule(8,this.size-8,!0)}drawVersion(){if(this.version<7)return;let e=this.version;for(let t=0;t<12;t++)e=e<<1^(e>>>11)*7973;let t=this.version<<12|e;for(let e=0;e<18;e++){let n=Xv(t,e),r=this.size-11+e%3,i=Math.floor(e/3);this.setFunctionModule(r,i,n),this.setFunctionModule(i,r,n)}}drawFinderPattern(e,t){for(let n=-4;n<=4;n++)for(let r=-4;r<=4;r++){let i=Math.max(Math.abs(r),Math.abs(n)),a=e+r,o=t+n;a>=0&&a<this.size&&o>=0&&o<this.size&&this.setFunctionModule(a,o,i!==2&&i!==4,jv.Position)}}drawAlignmentPattern(e,t){for(let n=-2;n<=2;n++)for(let r=-2;r<=2;r++)this.setFunctionModule(e+r,t+n,Math.max(Math.abs(r),Math.abs(n))!==1,jv.Alignment)}setFunctionModule(e,t,n,r=jv.Function){this.modules[t][e]=n,this.types[t][e]=r}addEccAndInterleave(e){let t=this.version,n=this.ecc;if(e.length!==dy(t,n))throw RangeError(`Invalid argument`);let r=qv[n[0]][t],i=Kv[n[0]][t],a=Math.floor(uy(t)/8),o=r-a%r,s=Math.floor(a/r),c=[],l=fy(i);for(let t=0,n=0;t<r;t++){let r=e.slice(n,n+s-i+(t<o?0:1));n+=r.length;let a=py(r,l);t<o&&r.push(0),c.push(r.concat(a))}let u=[];for(let e=0;e<c[0].length;e++)c.forEach((t,n)=>{(e!==s-i||n>=o)&&u.push(t[e])});return u}drawCodewords(e){if(e.length!==Math.floor(uy(this.version)/8))throw RangeError(`Invalid argument`);let t=0;for(let n=this.size-1;n>=1;n-=2){n===6&&(n=5);for(let r=0;r<this.size;r++)for(let i=0;i<2;i++){let a=n-i,o=n+1&2?r:this.size-1-r;!this.types[o][a]&&t<e.length*8&&(this.modules[o][a]=Xv(e[t>>>3],7-(t&7)),t++)}}}applyMask(e){if(e<0||e>7)throw RangeError(`Mask value out of range`);for(let t=0;t<this.size;t++)for(let n=0;n<this.size;n++){let r;switch(e){case 0:r=(n+t)%2==0;break;case 1:r=t%2==0;break;case 2:r=n%3==0;break;case 3:r=(n+t)%3==0;break;case 4:r=(Math.floor(n/3)+Math.floor(t/2))%2==0;break;case 5:r=n*t%2+n*t%3==0;break;case 6:r=(n*t%2+n*t%3)%2==0;break;case 7:r=((n+t)%2+n*t%3)%2==0;break;default:throw Error(`Unreachable`)}!this.types[t][n]&&r&&(this.modules[t][n]=!this.modules[t][n])}}getPenaltyScore(){let e=0;for(let t=0;t<this.size;t++){let n=!1,r=0,i=[0,0,0,0,0,0,0];for(let a=0;a<this.size;a++)this.modules[t][a]===n?(r++,r===5?e+=Hv:r>5&&e++):(this.finderPenaltyAddHistory(r,i),n||(e+=this.finderPenaltyCountPatterns(i)*Wv),n=this.modules[t][a],r=1);e+=this.finderPenaltyTerminateAndCount(n,r,i)*Wv}for(let t=0;t<this.size;t++){let n=!1,r=0,i=[0,0,0,0,0,0,0];for(let a=0;a<this.size;a++)this.modules[a][t]===n?(r++,r===5?e+=Hv:r>5&&e++):(this.finderPenaltyAddHistory(r,i),n||(e+=this.finderPenaltyCountPatterns(i)*Wv),n=this.modules[a][t],r=1);e+=this.finderPenaltyTerminateAndCount(n,r,i)*Wv}for(let t=0;t<this.size-1;t++)for(let n=0;n<this.size-1;n++){let r=this.modules[t][n];r===this.modules[t][n+1]&&r===this.modules[t+1][n]&&r===this.modules[t+1][n+1]&&(e+=Uv)}let t=0;for(let e of this.modules)t=e.reduce((e,t)=>e+ +!!t,t);let n=this.size*this.size,r=Math.ceil(Math.abs(t*20-n*10)/n)-1;return e+=r*Gv,e}getAlignmentPatternPositions(){if(this.version===1)return[];{let e=Math.floor(this.version/7)+2,t=this.version===32?26:Math.ceil((this.version*4+4)/(e*2-2))*2,n=[6];for(let r=this.size-7;n.length<e;r-=t)n.splice(1,0,r);return n}}finderPenaltyCountPatterns(e){let t=e[1],n=t>0&&e[2]===t&&e[3]===t*3&&e[4]===t&&e[5]===t;return(n&&e[0]>=t*4&&e[6]>=t?1:0)+(n&&e[6]>=t*4&&e[0]>=t?1:0)}finderPenaltyTerminateAndCount(e,t,n){return e&&(this.finderPenaltyAddHistory(t,n),t=0),t+=this.size,this.finderPenaltyAddHistory(t,n),this.finderPenaltyCountPatterns(n)}finderPenaltyAddHistory(e,t){t[0]===0&&(e+=this.size),t.pop(),t.unshift(e)}};function Yv(e,t,n){if(t<0||t>31||e>>>t)throw RangeError(`Value out of range`);for(let r=t-1;r>=0;r--)n.push(e>>>r&1)}function Xv(e,t){return!!(e>>>t&1)}var Zv=class{constructor(e,t,n){if(this.mode=e,this.numChars=t,this.bitData=n,t<0)throw RangeError(`Invalid argument`);this.bitData=n.slice()}getData(){return this.bitData.slice()}},Qv=[1,10,12,14],$v=[2,9,11,13],ey=[4,8,16,16];function ty(e,t){return e[Math.floor((t+7)/17)+1]}function ny(e){let t=[];for(let n of e)Yv(n,8,t);return new Zv(ey,e.length,t)}function ry(e){if(!oy(e))throw RangeError(`String contains non-numeric characters`);let t=[];for(let n=0;n<e.length;){let r=Math.min(e.length-n,3);Yv(Number.parseInt(e.substring(n,n+r),10),r*3+1,t),n+=r}return new Zv(Qv,e.length,t)}function iy(e){if(!sy(e))throw RangeError(`String contains unencodable characters in alphanumeric mode`);let t=[],n=0;for(;n+2<=e.length;n+=2){let r=zv.indexOf(e.charAt(n))*45;r+=zv.indexOf(e.charAt(n+1)),Yv(r,11,t)}return n<e.length&&Yv(zv.indexOf(e.charAt(n)),6,t),new Zv($v,e.length,t)}function ay(e){return e===``?[]:oy(e)?[ry(e)]:sy(e)?[iy(e)]:[ny(ly(e))]}function oy(e){return Lv.test(e)}function sy(e){return Rv.test(e)}function cy(e,t){let n=0;for(let r of e){let e=ty(r.mode,t);if(r.numChars>=1<<e)return 1/0;n+=4+e+r.bitData.length}return n}function ly(e){e=encodeURI(e);let t=[];for(let n=0;n<e.length;n++)e.charAt(n)===`%`?(t.push(Number.parseInt(e.substring(n+1,n+3),16)),n+=2):t.push(e.charCodeAt(n));return t}function uy(e){if(e<Bv||e>Vv)throw RangeError(`Version number out of range`);let t=(16*e+128)*e+64;if(e>=2){let n=Math.floor(e/7)+2;t-=(25*n-10)*n-55,e>=7&&(t-=36)}return t}function dy(e,t){return Math.floor(uy(e)/8)-Kv[t[0]][e]*qv[t[0]][e]}function fy(e){if(e<1||e>255)throw RangeError(`Degree out of range`);let t=[];for(let n=0;n<e-1;n++)t.push(0);t.push(1);let n=1;for(let r=0;r<e;r++){for(let e=0;e<t.length;e++)t[e]=my(t[e],n),e+1<t.length&&(t[e]^=t[e+1]);n=my(n,2)}return t}function py(e,t){let n=t.map(e=>0);for(let r of e){let e=r^n.shift();n.push(0),t.forEach((t,r)=>n[r]^=my(t,e))}return n}function my(e,t){if(e>>>8||t>>>8)throw RangeError(`Byte out of range`);let n=0;for(let r=7;r>=0;r--)n=n<<1^(n>>>7)*285,n^=(t>>>r&1)*e;return n}function hy(e,t,n=1,r=40,i=-1,a=!0){if(!(Bv<=n&&n<=r&&r<=Vv)||i<-1||i>7)throw RangeError(`Invalid value`);let o,s;for(o=n;;o++){let n=dy(o,t)*8,i=cy(e,o);if(i<=n){s=i;break}if(o>=r)throw RangeError(`Data too long`)}for(let e of[Nv,Pv,Fv])a&&s<=dy(o,e)*8&&(t=e);let c=[];for(let t of e){Yv(t.mode[0],4,c),Yv(t.numChars,ty(t.mode,o),c);for(let e of t.getData())c.push(e)}let l=dy(o,t)*8;Yv(0,Math.min(4,l-c.length),c),Yv(0,(8-c.length%8)%8,c);for(let e=236;c.length<l;e^=253)Yv(e,8,c);let u=Array.from({length:Math.ceil(c.length/8)},()=>0);return c.forEach((e,t)=>u[t>>>3]|=e<<7-(t&7)),new Jv(o,t,u,i)}function gy(e,t){let{ecc:n=`L`,boostEcc:r=!1,minVersion:i=1,maxVersion:a=40,maskPattern:o=-1,border:s=1}=t||{},c=typeof e==`string`?ay(e):Array.isArray(e)?[ny(e)]:void 0;if(!c)throw Error(`uqr only supports encoding string and binary data, but got: ${typeof e}`);let l=hy(c,Iv[n],i,a,o,r),u=_y({version:l.version,maskPattern:l.mask,size:l.size,data:l.modules,types:l.types},s);return t?.invert&&(u.data=u.data.map(e=>e.map(e=>!e))),t?.onEncoded?.(u),u}function _y(e,t=1){if(!t)return e;let{size:n}=e,r=n+t*2;e.size=r,e.data.forEach(e=>{for(let n=0;n<t;n++)e.unshift(!1),e.push(!1)});for(let n=0;n<t;n++)e.data.unshift(Array.from({length:r},e=>!1)),e.data.push(Array.from({length:r},e=>!1));let i=jv.Border;e.types.forEach(e=>{for(let n=0;n<t;n++)e.unshift(i),e.push(i)});for(let n=0;n<t;n++)e.types.unshift(Array.from({length:r},e=>i)),e.types.push(Array.from({length:r},e=>i));return e}var vy=2;function yy({value:e,label:t}){let{data:n,size:r}=gy(e),i=n.flatMap((e,t)=>e.flatMap((e,n)=>e?[`M${n+vy} ${t+vy}h1v1h-1z`]:[])),a=r+4;return(0,Q.jsxs)(`svg`,{className:`qr-code`,role:`img`,"aria-label":t,viewBox:`0 0 ${a} ${a}`,shapeRendering:`crispEdges`,children:[(0,Q.jsx)(`rect`,{width:a,height:a,fill:`#fff`}),(0,Q.jsx)(`path`,{d:i.join(``),fill:`#000`})]})}function by(){let[e,t]=(0,l.useState)(Vp);return!Bp()||e!=="default"?null:(0,Q.jsxs)(`div`,{className:`settings-row`,children:[(0,Q.jsxs)(`span`,{children:[`Notify me about new requests`,(0,Q.jsx)(`small`,{className:`device-meta`,children:`Shown when Webr is open in a hidden tab.`})]}),(0,Q.jsx)(`button`,{type:`button`,className:`dialog-button`,onClick:()=>void Hp().then(t),children:`Turn on`})]})}var xy=8;function Sy({refreshKey:e}){let[t,n]=(0,l.useState)([]);return(0,l.useEffect)(()=>{Ap().then(n,()=>void 0)},[e]),t.length?(0,Q.jsxs)(`div`,{className:`remote-activity`,children:[(0,Q.jsx)(`h3`,{className:`settings-subtitle`,children:`Recent activity`}),t.slice(0,xy).map(e=>(0,Q.jsxs)(`p`,{className:`activity-row`,children:[(0,Q.jsx)(`span`,{children:Up(e)}),(0,Q.jsx)(`time`,{dateTime:new Date(e.at).toISOString(),children:zp(e.at)})]},e.id))]}):null}function Cy({invite:e,onClose:t}){let[n,r]=(0,l.useState)(0),[i,a]=(0,l.useState)(!1),o=e.urls[n],s=e=>Ov(e).then(e=>{e&&(a(!0),setTimeout(()=>a(!1),1500))}),c=()=>s(e.token),u=t=>{r(t),s(e.urls[t])};return(0,Q.jsx)(Cv,{open:!0,onOpenChange:e=>{e||t()},children:(0,Q.jsxs)(Jc,{children:[(0,Q.jsx)(Oc,{className:`dialog-backdrop`}),(0,Q.jsxs)(Gc,{className:`dialog pairing-invite`,children:[(0,Q.jsx)(Yc,{className:`pairing-title`,children:`Connect a device`}),o?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(Rc,{className:`dialog-message`,children:`Scan with the device’s camera, or open Webr there and enter the code.`}),(0,Q.jsx)(yy,{value:o,label:`QR code to connect a device`}),e.urls.length>1&&(0,Q.jsx)(`div`,{className:`theme-control theme-control--labels`,role:`group`,"aria-label":`Address`,children:e.urls.map((e,t)=>(0,Q.jsx)(`button`,{type:`button`,"aria-pressed":t===n,className:t===n?`theme-option is-selected`:`theme-option`,onClick:()=>u(t),children:new URL(e).host},e))})]}):(0,Q.jsxs)(Rc,{className:`dialog-message`,children:[`No network address was found for other devices. Start Webr with `,(0,Q.jsx)(`code`,{children:`--origin <url>`}),` if you reach it through a proxy.`]}),(0,Q.jsxs)(`div`,{className:`pairing-token`,children:[(0,Q.jsx)(`code`,{children:e.token}),(0,Q.jsx)(`button`,{type:`button`,className:`dialog-button`,onClick:()=>void c(),"aria-label":`Copy code`,children:i?(0,Q.jsx)(y,{size:14}):(0,Q.jsx)(D,{size:14})})]}),(0,Q.jsx)(`p`,{className:`settings-note`,children:`Works once and expires in 5 minutes.`}),(0,Q.jsx)(`div`,{className:`dialog-actions`,children:(0,Q.jsx)(Ic,{className:`dialog-button is-primary`,children:`Done`})})]})]})})}var wy={unavailable:`Install Tailscale on this computer and your other devices to get a private, secure HTTPS address for Webr. HTTPS unlocks features browsers only allow on secure pages, such as the microphone.`,"https-disabled":`Tailscale is installed, but HTTPS certificates are off. Turn them on in the Tailscale admin console under DNS, then restart Webr to unlock features that need a secure address, such as the microphone.`};function Ty(){let[e,t]=(0,l.useState)(`ready`);return(0,l.useEffect)(()=>{jp().then(t,()=>void 0)},[]),e===`ready`?null:(0,Q.jsx)(`p`,{className:`tailscale-callout`,role:`note`,children:wy[e]})}function Ey(){let[e,t]=(0,l.useState)([]),[n,r]=(0,l.useState)(),[i,a]=(0,l.useState)(``),o=(0,l.useCallback)(()=>kp().then(t,()=>void 0),[]);(0,l.useEffect)(()=>{o()},[o]);let s=()=>Op().then(e=>{a(``),r(e)},e=>a(e.message)),c=async e=>{await al(`Disconnect ${e.name}? It will need to be approved again.`,{confirmLabel:`Disconnect`,danger:!0})&&(await Mp(e.id),e.current?location.reload():await o())};return(0,Q.jsxs)(`section`,{id:`remote-access`,children:[(0,Q.jsx)(`div`,{className:`settings-section-title`,children:(0,Q.jsx)(`h2`,{children:`Remote access`})}),(0,Q.jsx)(`p`,{className:`settings-note`,children:`Other devices ask to connect and you approve them here. This computer never needs a code.`}),(0,Q.jsx)(Ty,{}),(0,Q.jsxs)(`div`,{className:`settings-row`,children:[(0,Q.jsx)(`span`,{children:`Connect a device`}),(0,Q.jsx)(`button`,{type:`button`,className:`dialog-button`,onClick:()=>void s(),children:`Show code`})]}),(0,Q.jsx)(by,{}),i&&(0,Q.jsx)(`p`,{role:`alert`,className:`form-error`,children:i}),e.map(e=>(0,Q.jsxs)(`div`,{className:`settings-row`,children:[(0,Q.jsxs)(`span`,{children:[e.name,e.current&&(0,Q.jsx)(`em`,{className:`device-tag`,children:`This device`}),(0,Q.jsxs)(`small`,{className:`device-meta`,children:[`Active `,zp(e.lastSeenAt),` · Signs out `,Wp(e.expiresAt),` if unused`]})]}),(0,Q.jsx)(`button`,{type:`button`,className:`dialog-button`,onClick:()=>void c(e),children:`Disconnect`})]},e.id)),(0,Q.jsx)(Sy,{refreshKey:e}),n&&(0,Q.jsx)(Cy,{invite:n,onClose:()=>r(void 0)})]})}function Dy({onOpenSidebar:e}){let[t,n]=(0,l.useState)(`worktree`),[r,i]=(0,l.useState)(Yf),[a,o]=(0,l.useState)(null),[s,c]=(0,l.useState)(``);(0,l.useEffect)(()=>{n(dv()),i(Xf())},[]);let u=(e,t)=>{if(e.preventDefault(),e.stopPropagation(),e.key===`Escape`){o(null),c(``);return}let n=$f(e);if(!n)return;if(ep(n)||n===`meta+k`){c(`Choose a shortcut with a modifier that does not conflict with the browser or ⌘K.`);return}if(Object.entries(r).some(([e,r])=>e!==t&&r===n)){c(`That shortcut is already in use.`);return}let a={...r,[t]:n};i(a),localStorage.setItem(`webr-shortcuts`,JSON.stringify(a)),o(null),c(``)};return(0,Q.jsxs)(`main`,{className:`form-page settings-page`,children:[(0,Q.jsx)(`button`,{className:`mobile-menu`,onClick:e,children:`Threads`}),(0,Q.jsx)(`h1`,{children:`Settings`}),(0,Q.jsxs)(`section`,{children:[(0,Q.jsx)(`h2`,{children:`Appearance`}),(0,Q.jsxs)(`div`,{className:`settings-row`,children:[(0,Q.jsx)(`span`,{children:`Theme`}),(0,Q.jsx)(np,{expanded:!0})]})]}),(0,Q.jsxs)(`section`,{children:[(0,Q.jsx)(`h2`,{children:`New threads`}),(0,Q.jsxs)(`div`,{className:`settings-row`,children:[(0,Q.jsx)(`span`,{children:`New session behavior`}),(0,Q.jsx)(`div`,{className:`theme-control theme-control--labels`,role:`group`,"aria-label":`New session behavior`,children:Object.keys(av).map(e=>(0,Q.jsx)(`button`,{type:`button`,"aria-pressed":t===e,className:t===e?`theme-option is-selected`:`theme-option`,onClick:()=>{n(e),fv(e)},children:av[e]},e))})]})]}),(0,Q.jsx)(Ey,{}),(0,Q.jsxs)(`section`,{id:`shortcuts`,children:[(0,Q.jsxs)(`div`,{className:`settings-section-title`,children:[(0,Q.jsx)(`h2`,{children:`Keyboard shortcuts`}),(0,Q.jsx)(`button`,{onClick:()=>{i(Yf),localStorage.removeItem(`webr-shortcuts`),o(null),c(``)},children:`Reset`})]}),(0,Q.jsx)(`p`,{className:`settings-note`,children:`Press ⌘K for all actions and threads.`}),Object.keys(Jf).map(e=>(0,Q.jsxs)(`div`,{className:`settings-row`,children:[(0,Q.jsx)(`span`,{children:Jf[e]}),(0,Q.jsx)(`button`,{className:`shortcut-key`,"data-recording":a===e,onClick:()=>{o(e),c(``)},onKeyDown:t=>a===e&&u(t,e),"aria-label":`Change ${Jf[e]} shortcut`,children:a===e?`Press keys…`:Zf(r[e]).map((e,t)=>(0,Q.jsx)(`kbd`,{children:e},t))})]},e)),s&&(0,Q.jsx)(`p`,{role:`alert`,className:`form-error`,children:s})]})]})}var Oy=l.createContext(void 0);function ky(e=!0){let t=l.useContext(Oy);if(t===void 0&&!e)throw Error(Ai(25));return t}var Ay=l.createContext(void 0);function jy(e){let t=l.useContext(Ay);if(t===void 0&&!e)throw Error(Ai(33));return t}var My=l.createContext(void 0);function Ny(e){let t=l.useContext(My);if(t===void 0&&!e)throw Error(Ai(36));return t}function Py(e){let{closeOnClick:t,highlighted:n,id:r,nodeId:i,store:a,typingRef:o,itemRef:s,itemMetadata:c}=e,{events:u}=a.useState(`floatingTreeRoot`),d=a.useState(`open`),f=ky(!0),p=f!==void 0;return l.useMemo(()=>({id:r,role:`menuitem`,tabIndex:d&&n?0:-1,onKeyDown(e){e.key===` `&&o?.current&&e.preventDefault()},onMouseMove(e){i&&u.emit(`itemhover`,{nodeId:i,target:e.currentTarget})},onClick(e){t&&u.emit(`close`,{domEvent:e,reason:vn})},onMouseUp(e){if(f){let t=f.initialCursorPointRef.current;if(f.initialCursorPointRef.current=null,p&&t&&Math.abs(e.clientX-t.x)<=1&&Math.abs(e.clientY-t.y)<=1||p&&!We&&e.button===2)return}s.current&&a.context.allowMouseUpTriggerRef.current&&(!p||e.button===2)&&c.type===`regular-item`&&Mc(s.current,e,{detail:1})}}),[t,n,r,u,i,d,a,o,s,f,p,c])}var Fy={type:`regular-item`};function Iy(e){let{closeOnClick:t,disabled:n,highlighted:r,id:i,store:a,typingRef:o=a.context.typingRef,nativeButton:s,itemMetadata:c,nodeId:u}=e,d=l.useRef(null),{getButtonProps:f,buttonRef:p}=Nc({disabled:n,focusableWhenDisabled:!0,native:s,composite:!0}),m=Py({closeOnClick:t,highlighted:r,id:i,nodeId:u,store:a,typingRef:o,itemRef:d,itemMetadata:c}),h=l.useCallback(e=>zi(m,{onMouseEnter(){c.type===`submenu-trigger`&&c.setActive()}},e,f),[m,f,c]),g=Rn(d,p);return l.useMemo(()=>({getItemProps:h,itemRef:g}),[h,g])}var Ly=l.forwardRef(function(e,t){let{render:n,className:r,id:i,label:a,nativeButton:o=!1,disabled:s=!1,closeOnClick:c=!0,style:l,...u}=e,d=og({guess:!0,label:a}),f=jy(!0),p=Lc(i),{store:m}=Ny(),h=m.useState(`disabled`),g=s||h,_=m.useState(`isActive`,d.index),v=m.useState(`itemProps`),{getItemProps:y,itemRef:b}=Iy({closeOnClick:c,disabled:g,highlighted:_,id:p,store:m,nativeButton:o,nodeId:f?.context.nodeId,itemMetadata:Fy});return $i(`div`,e,{state:{disabled:g,highlighted:_},props:[v,u,y],ref:[b,t,d.ref]})}),Ry=l.createContext(void 0);function zy(e){let t=l.useContext(Ry);if(t===void 0&&!e)throw Error(Ai(69));return t}var By=l.forwardRef(function(e,t){let{render:n,className:r,style:i,finalFocus:a,...o}=e,{store:s}=Ny(),{side:c,align:u}=jy(),d=zy(!0)!=null,f=s.useState(`open`),p=s.useState(`transitionStatus`),m=s.useState(`popupProps`),h=s.useState(`mounted`),g=s.useState(`instantType`),_=s.useState(`activeTriggerElement`),v=s.useState(`parent`),y=s.useState(`lastOpenChangeReason`),b=s.useState(`rootId`),x=s.useState(`floatingRootContext`),S=s.useState(`floatingTreeRoot`),C=s.useState(`closeDelay`),w=s.useState(`hoverEnabled`),T=s.useState(`disabled`),E=s.useState(`openMethod`),D=v.type===`context-menu`;ys({open:f,ref:s.context.popupRef,onComplete(){f&&s.context.onOpenChangeComplete?.(!0)}}),l.useEffect(()=>{function e(e){s.setOpen(!1,Z(e.reason,e.domEvent))}return S.events.on(`close`,e),()=>{S.events.off(`close`,e)}},[S.events,s]),$s(x,{enabled:w&&!T&&!D&&v.type!==`menubar`,closeDelay:C});let O=s.useStateSetter(`popupElement`),k=$i(`div`,e,{state:{transitionStatus:p,side:c,align:u,open:f,nested:v.type===`menu`,instant:g},ref:[t,s.context.popupRef,O],stateAttributesMapping:Zt,props:[m,{onKeyDown(e){d&&Vc.has(e.key)&&e.stopPropagation()}},Gl(p),o,{"data-rootownerid":b}]}),A=v.type===void 0||D;return(_||v.type===`menubar`&&y!==`outside-press`)&&(A=!0),(0,Q.jsx)(Pa,{context:x,openInteractionType:E,modal:D,disabled:!h,returnFocus:a===void 0?A:a,initialFocus:v.type!==`menu`,restoreFocus:!0,externalTree:v.type===`menubar`?void 0:S,previousFocusableElement:_,nextFocusableElement:v.type===void 0?s.context.triggerFocusTargetRef:void 0,beforeContentFocusGuardRef:v.type===void 0?s.context.beforeContentFocusGuardRef:void 0,children:k})}),Vy=l.createContext(void 0);function Hy(){let e=l.useContext(Vy);if(e===void 0)throw Error(Ai(32));return e}var Uy=l.forwardRef(function(e,t){let{keepMounted:n=!1,...r}=e,{store:i,parent:a}=Ny();if(!(i.useState(`mounted`)||n))return null;let o=a.type===`menu`||a.type===`menubar`?`group`:void 0;return(0,Q.jsx)(Vy.Provider,{value:n,children:(0,Q.jsx)(ha,{ref:t,...r,portalOwnerRole:o})})}),Wy=l.forwardRef(function(e,t){let{anchor:n,positionMethod:r=`absolute`,className:i,render:a,side:o,align:s,sideOffset:c=0,alignOffset:u=0,collisionBoundary:d=`clipping-ancestors`,collisionPadding:f=5,arrowPadding:p=5,sticky:m=!1,disableAnchorTracking:h=!1,collisionAvoidance:g=sa,style:_,...v}=e,{store:y}=Ny(),b=Hy(),x=ky(!0),S=y.useState(`parent`),C=y.useState(`floatingRootContext`),w=y.useState(`floatingTreeRoot`),T=y.useState(`mounted`),E=y.useState(`open`),D=y.useState(`modal`),O=y.useState(`openMethod`),k=y.useState(`activeTriggerElement`),A=y.useState(`transitionStatus`),j=y.useState(`positionerElement`),M=y.useState(`instantType`),N=y.useState(`adaptiveOrigin`),P=y.useState(`lastOpenChangeReason`),F=y.useState(`floatingNodeId`),I=y.useState(`floatingParentNodeId`),L=C.useState(`domReferenceElement`),R=l.useRef(null),z=vs(j),ee=n,B=c,te=u,ne=s,re=g;S.type===`context-menu`&&(ee=n??S.context?.anchor,ne??=`start`,!o&&ne!==`center`&&(te=e.alignOffset??2,B=e.sideOffset??-5));let V=o,H=ne;S.type===`menu`?(V??=`inline-end`,H??=`start`,re=e.collisionAvoidance??ca):S.type===`menubar`&&(V??=S.context.orientation===`vertical`?`inline-end`:`bottom`,H??=`start`);let ie=S.type===`context-menu`,ae=Hl({anchor:ee,floatingRootContext:C,positionMethod:x?`fixed`:r,mounted:T,side:V,sideOffset:B,align:H,alignOffset:te,arrowPadding:ie?0:p,collisionBoundary:d,collisionPadding:f,sticky:m,nodeId:F,keepMounted:b,disableAnchorTracking:h,collisionAvoidance:re,shift:ie?{crossAxis:!(`side`in re&&re.side===`flip`),rootBoundary:`layoutViewport`}:void 0,externalTree:w,adaptiveOrigin:N});l.useEffect(()=>{function e(e){e.open&&(e.parentNodeId===F&&y.set(`hoverEnabled`,!1),e.nodeId!==F&&e.parentNodeId===y.select(`floatingParentNodeId`)&&y.setOpen(!1,Z(kn)))}return w.events.on(`menuopenchange`,e),()=>{w.events.off(`menuopenchange`,e)}},[y,w.events,F]),l.useEffect(()=>{if(y.select(`floatingParentNodeId`)==null)return;function e(e){if(e.open||e.nodeId!==y.select(`floatingParentNodeId`))return;let t=e.reason??`sibling-open`;y.setOpen(!1,Z(t))}return w.events.on(`menuopenchange`,e),()=>{w.events.off(`menuopenchange`,e)}},[w.events,y]);let oe=it();l.useEffect(()=>{E||oe.clear()},[E,oe]),l.useEffect(()=>{function e(e){if(E&&e.nodeId===y.select(`floatingParentNodeId`)){if(e.target&&k&&k!==e.target){let e=y.select(`closeDelay`);e>0?oe.isStarted()||oe.start(e,()=>{y.setOpen(!1,Z(kn))}):y.setOpen(!1,Z(kn))}else oe.clear()}}return w.events.on(`itemhover`,e),()=>{w.events.off(`itemhover`,e)}},[w.events,E,k,y,oe]),l.useEffect(()=>{let e={open:E,nodeId:F,parentNodeId:I,reason:y.select(`lastOpenChangeReason`)};w.events.emit(`menuopenchange`,e)},[w.events,E,y,F,I]),U(()=>{let e=L,t=R.current;if(e&&(R.current=e),t&&e&&e!==t){y.set(`instantType`,void 0);let e=new AbortController;return z(()=>{y.set(`instantType`,`trigger-change`)},e.signal),()=>{e.abort()}}},[L,z,y]);let se={open:E,side:ae.side,align:ae.align,anchorHidden:ae.anchorHidden,nested:S.type===`menu`,instant:M},ce=S.type===`menubar`&&S.context.modal;ng(E&&(ce||D&&P!==`trigger-hover`),O===`touch`,j,k);let le=Kl(e,se,{styles:ae.positionerStyles,transitionStatus:A,props:v,refs:[t,y.useStateSetter(`positionerElement`)],hidden:!T,inert:!E}),ue=T&&S.type!==`menu`&&(S.type!==`menubar`&&D&&P!==`trigger-hover`||S.type===`menubar`&&S.context.modal),de=null;return S.type===`menubar`?de=S.context.contentElement:S.type===void 0&&(de=k),(0,Q.jsxs)(Ay.Provider,{value:ae,children:[ue&&(0,Q.jsx)(qc,{ref:S.type===`context-menu`||S.type===`nested-context-menu`?S.context.internalBackdropRef:null,inert:Kc(!E),cutout:de}),(0,Q.jsx)(Ca,{id:F,children:(0,Q.jsx)(Vh,{elementsRef:y.context.itemDomElements,labelsRef:y.context.itemLabels,children:le})})]})}),Gy=l.createContext(null);function Ky(e){let t=l.useContext(Gy);if(t===null&&!e)throw Error(Ai(5));return t}var qy={...Vs,disabled:e=>e.parent.type===`menubar`&&e.parent.context.disabled||e.disabled,modal:e=>(e.parent.type===void 0||e.parent.type===`context-menu`)&&(e.modal??!0),openMethod:e=>e.openMethod,allowMouseEnter:e=>e.allowMouseEnter,highlightItemOnHover:e=>e.highlightItemOnHover,parent:e=>e.parent,rootId:e=>e.parent.type===`menu`?e.parent.store.select(`rootId`):e.parent.type===void 0?e.rootId:e.parent.context.rootId,activeIndex:e=>e.activeIndex,isActive:(e,t)=>e.activeIndex===t,hoverEnabled:e=>e.hoverEnabled,instantType:e=>e.instantType,lastOpenChangeReason:e=>e.openChangeReason,floatingTreeRoot:e=>e.parent.type===`menu`?e.parent.store.select(`floatingTreeRoot`):e.floatingTreeRoot,floatingNodeId:e=>e.floatingNodeId,floatingParentNodeId:e=>e.floatingParentNodeId,itemProps:e=>e.itemProps,closeDelay:e=>e.closeDelay,adaptiveOrigin:e=>e.adaptiveOrigin,keyboardEventRelay:e=>{if(e.keyboardEventRelay)return e.keyboardEventRelay;if(e.parent.type===`menu`)return e.parent.store.select(`keyboardEventRelay`)}},Jy=class extends ds{constructor(e,t,n=!1){let r=new Ps,i=Xy(r,t,n,e);super(i,Yy(r),qy),this.unsubscribeParentListener=this.observe(`parent`,e=>{if(this.unsubscribeParentListener?.(),e.type===`menu`){let t=e.store.select(`rootId`),n=e.store.select(`floatingTreeRoot`),r=e.store.select(`keyboardEventRelay`);this.unsubscribeParentListener=e.store.subscribe(()=>{let i=e.store.select(`rootId`),a=e.store.select(`floatingTreeRoot`),o=e.store.select(`keyboardEventRelay`);(t!==i||n!==a||r!==o)&&(t=i,n=a,r=o,this.notifyAll())}),this.context.allowMouseUpTriggerRef=e.store.context.allowMouseUpTriggerRef;return}e.type!==void 0&&(this.context.allowMouseUpTriggerRef=e.context.allowMouseUpTriggerRef),this.unsubscribeParentListener=null})}setOpen(e,t){this.state.floatingRootContext.context.events.emit(`setOpen`,{open:e,eventDetails:t})}unsubscribeParentListener=null};function Yy(e){return{positionerRef:l.createRef(),popupRef:l.createRef(),typingRef:{current:!1},itemDomElements:{current:[]},itemLabels:{current:[]},allowMouseUpTriggerRef:{current:!1},triggerFocusTargetRef:l.createRef(),beforeContentFocusGuardRef:l.createRef(),onOpenChangeComplete:void 0,triggerElements:e}}function Xy(e,t,n=!1,r){return{...Fs(e,t,n),disabled:!1,modal:!0,openMethod:null,allowMouseEnter:!1,highlightItemOnHover:!0,parent:{type:void 0},rootId:void 0,activeIndex:null,hoverEnabled:!0,instantType:void 0,openChangeReason:null,floatingTreeRoot:new _a,floatingNodeId:void 0,floatingParentNodeId:null,itemProps:et,keyboardEventRelay:void 0,closeDelay:0,adaptiveOrigin:void 0,...r}}var Zy=l.createContext(void 0);function Qy(){return l.useContext(Zy)}var $y=es(function(e){let{children:t,open:n,onOpenChange:r,onOpenChangeComplete:i,defaultOpen:a=!1,disabled:o=!1,modal:s,loopFocus:c=!0,orientation:u=`vertical`,actionsRef:d,closeParentOnEsc:f=!1,handle:p,triggerId:m,defaultTriggerId:h=null,highlightItemOnHover:g=!0}=e,_=ky(!0),v=Ny(!0),y=Ky(!0),b=Qy(),x=l.useMemo(()=>b&&v?{type:`menu`,store:v.store}:y?{type:`menubar`,context:y}:_&&!v?{type:`context-menu`,context:_}:{type:void 0},[_,v,y,b]),S=Oi(),C=Oi(),w=ba(),T=x.type===`menu`?x.store:void 0,E=(n??a)&&T?.state.transitionStatus===`starting`,D=Ze(()=>E?T?.state.instantType:void 0).current,O=eb({open:a,openProp:n,activeTriggerId:h,triggerIdProp:m,parent:x,disabled:o,highlightItemOnHover:g,modal:x.type===void 0?s:void 0,rootId:S,instantType:D},C,w!=null);O.useControlledProp(`openProp`,n),O.useControlledProp(`triggerIdProp`,m),O.useContextCallback(`onOpenChangeComplete`,i);let k=O.useState(`floatingTreeRoot`),A=Sa(k),j=O.useState(`open`),M=O.useState(`activeTriggerElement`),N=O.useState(`positionerElement`),P=O.useState(`hoverEnabled`),F=O.useState(`disabled`),I=O.useState(`lastOpenChangeReason`),L=O.useState(`parent`),R=O.useState(`activeIndex`),z=O.useState(`payload`),ee=O.useState(`floatingParentNodeId`),B=l.useRef(null),te=l.useRef(L.type!==`context-menu`),ne=it(),re=l.useRef(!0),V=it(),H=ee!=null,{openMethod:ie,triggerProps:ae}=$c(j);O.useSyncedValues({disabled:o,highlightItemOnHover:g,modal:L.type===void 0?s:void 0,openMethod:ie,rootId:S}),As(O);let{forceUnmount:oe,transitionStatus:se}=js(j,O,()=>{O.set(`allowMouseEnter`,!1)},E),ce=vs(O.context.popupRef);l.useEffect(()=>{if(D===void 0)return;let e=()=>{O.state.instantType===D&&O.set(`instantType`,void 0)};if(!j){e();return}if(se!==void 0)return;if(O.context.popupRef.current==null){e();return}let t=new AbortController;return ce(e,t.signal),()=>{t.abort()}},[D,j,se,ce,O]),U(()=>{_&&!v?O.update({parent:{type:`context-menu`,context:_},floatingNodeId:A,floatingParentNodeId:w}):v&&O.update({floatingNodeId:A,floatingParentNodeId:w})},[_,v,A,w,O]),l.useEffect(()=>{if(j||(B.current=null),L.type===`context-menu`){if(!j){ne.clear(),te.current=!1;return}ne.start(500,()=>{te.current=!0})}},[ne,j,L.type]),U(()=>{!j&&!P&&O.set(`hoverEnabled`,!0)},[j,P,O]);let le=$((e,t)=>{let n=t.reason;if(!e&&!O.select(`open`)||j===e&&t.trigger===M&&I===n)return;let i=Ds(t);if(!e&&t.trigger==null&&(t.trigger=M??void 0),r?.(e,t),t.isCanceled)return;O.state.floatingRootContext.dispatchOpenChange(e,t);let a=t.event;if(e===!1&&a?.type===`click`&&a.pointerType===`touch`&&!re.current)return;e&&n===`trigger-focus`?(re.current=!1,V.start(300,()=>{re.current=!0})):(re.current=!0,V.clear());let o=(n===`trigger-press`||n===`item-press`)&&a.detail===0,s=!e&&(n===`escape-key`||n==null);B.current=t.event;let c=Es(O.state,e,t.trigger,i());c.openChangeReason=n,c.instantType=L.type===`menubar`&&(n===`trigger-focus`||n===`focus-out`||n===`trigger-hover`||n===`list-navigation`||n===`sibling-open`)?`group`:o||s?o?`click`:`dismiss`:void 0,O.update(c)}),ue=ms({popupStore:O,floatingRootContext:O.state.floatingRootContext,floatingId:C,nested:w!=null,onOpenChange:le}),de=ue.context.events;U(()=>{let e=({open:e,eventDetails:t})=>le(e,t);return de.on(`setOpen`,e),()=>{de?.off(`setOpen`,e)}},[de,le]);let fe=l.useCallback(()=>{O.setOpen(!1,Z(jn))},[O]);l.useImperativeHandle(d,()=>({unmount:oe,close:fe}),[oe,fe]);let pe;L.type===`context-menu`&&(pe=L.context),l.useImperativeHandle(pe?.positionerRef,()=>N,[N]),l.useImperativeHandle(pe?.actionsRef,()=>({setOpen:le}),[le]);let W=Va(ue,{enabled:!F,bubbles:{escapeKey:f&&L.type===`menu`},outsidePress(){return L.type!==`context-menu`||B.current?.type===`contextmenu`||te.current},externalTree:H?k:void 0}),me=Ol(),he=l.useCallback(e=>{O.select(`activeIndex`)!==e&&O.set(`activeIndex`,e)},[O]),ge=lc(ue,{enabled:!F,listRef:O.context.itemDomElements,activeIndex:R,nested:L.type!==void 0,loopFocus:c,orientation:u,parentOrientation:L.type===`menubar`?L.context.orientation:void 0,rtl:me===`rtl`,disabledIndices:$e,onNavigate:he,openOnArrowKeyDown:L.type!==`context-menu`,externalTree:H?k:void 0,focusItemOnHover:g}),G=l.useCallback(e=>{O.context.typingRef.current=e},[O]),K=uc(ue,{enabled:!F,listRef:O.context.itemLabels,elementsRef:O.context.itemDomElements,activeIndex:R,resetMs:500,onMatch:e=>{j&&e!==R&&O.set(`activeIndex`,e)},onTyping:G}),_e=l.useMemo(()=>{let e=zi(K.reference,ge.reference,W.reference,{onMouseMove(){O.set(`allowMouseEnter`,!0)}},ae);return e[`aria-haspopup`]=`menu`,e[`aria-expanded`]=j,e},[O,K.reference,ge.reference,W.reference,ae,j]),ve=l.useMemo(()=>{let e=zi(ge.trigger,W.trigger,ae);return e[`aria-haspopup`]=`menu`,e[`aria-expanded`]=!1,e},[ge.trigger,W.trigger,ae]);Ze(()=>(O.update({inactiveTriggerProps:ve}),null)),Ms(O,{floatingRootContext:ue,activeTriggerProps:_e,inactiveTriggerProps:ve,popupProps:l.useMemo(()=>zi(bs,{id:C,role:`menu`,"aria-orientation":u===`horizontal`?`horizontal`:void 0,"aria-labelledby":M?.id,onMouseMove(){O.set(`allowMouseEnter`,!0),L.type===`menu`&&O.set(`hoverEnabled`,!1)},onClick(){O.select(`hoverEnabled`)&&O.set(`hoverEnabled`,!1)},onKeyDown(e){let t=O.select(`keyboardEventRelay`);t&&!e.isPropagationStopped()&&t(e)}},K.floating,ge.floating,W.floating),[M,C,u,L.type,O,K.floating,ge.floating,W.floating]),itemProps:ge.item??et});let ye=l.useMemo(()=>({store:O,parent:x}),[O,x]),be=(0,Q.jsxs)(My.Provider,{value:ye,children:[p&&(0,Q.jsx)(Cs,{handle:p,store:O}),typeof t==`function`?t({payload:z}):t]});return L.type===void 0||L.type===`context-menu`?(0,Q.jsx)(wa,{externalTree:k,children:be}):be});function eb(e,t,n){return Ze(()=>new Jy(e,t,n)).current}function tb(e){let t=Ny().store,n=l.useMemo(()=>({parentMenu:t}),[t]);return(0,Q.jsx)(Zy.Provider,{value:n,children:(0,Q.jsx)($y,{...e})})}function nb(e={}){let{highlightItemOnHover:t,highlightedIndex:n,onHighlightedIndexChange:r}=Ac(),{ref:i,index:a}=og(e),o=n===a,s=l.useRef(null),c=Rn(i,s);return{compositeProps:{tabIndex:o?0:-1,onFocus(){r(a)},onMouseMove(){let e=s.current;if(!t||!e)return;let n=e.hasAttribute(`disabled`)||e.ariaDisabled===`true`;!o&&!n&&e.focus()}},compositeRef:c,index:a}}function rb(e){let{render:t,className:n,style:r,state:i=et,props:a=$e,refs:o=$e,metadata:s,stateAttributesMapping:c,tag:l=`div`,...u}=e,{compositeProps:d,compositeRef:f}=nb({metadata:s});return $i(l,e,{state:i,ref:[f,...o],props:[d,...a,u],stateAttributesMapping:c})}function ib(e){if(K(e)&&e.hasAttribute(`data-rootownerid`))return e.getAttribute(`data-rootownerid`);if(!Oe(e))return ib(je(e))}function ab(e,t){let n=l.useRef(null);function r(t){ua.flushSync(()=>{e.setOpen(!1,Z(Cn,t.nativeEvent,t.currentTarget))}),ii(n.current)?.focus()}function i(n){let r=e.select(`positionerElement`);if(r&&ai(n,r))e.context.beforeContentFocusGuardRef.current?.focus();else{ua.flushSync(()=>{e.setOpen(!1,Z(Cn,n.nativeEvent,n.currentTarget))});let i=ri(e.context.triggerFocusTargetRef.current||t.current);for(;i!==null&&X(r,i);){let e=i;if(i=ei(i),i===e)break}i?.focus()}}return{preFocusGuardRef:n,handlePreFocusGuardFocus:r,handleFocusTargetFocus:i}}function ob(e){let{enabled:t=!0,mouseDownAction:n,open:r}=e,i=l.useRef(!1);return l.useMemo(()=>t?{onMouseDown:e=>{(n===`open`&&!r||n===`close`&&r)&&(i.current=!0,J(e.currentTarget).addEventListener(`click`,()=>{i.current=!1},{once:!0}))},onClick:e=>{i.current&&(i.current=!1,e.preventBaseUIHandler())}}:et,[t,n,r])}var sb=ts(function(e,t){let{render:n,className:r,style:i,disabled:a=!1,nativeButton:o=!0,id:s,openOnHover:c,delay:u=100,closeDelay:d=0,handle:f,payload:p,...m}=e,h=Ny(!0),g=Hs(f)??h?.store;if(!g)throw Error(Ai(85));let _=Lc(s),v=g.useState(`isTriggerActive`,_),y=g.useState(`floatingRootContext`),b=g.useState(`isOpenedByTrigger`,_),x=g.useState(`triggerPopupId`,_),S=l.useRef(null),C=lb(),w=Ac(!0),T=xa(),E=l.useMemo(()=>T??new _a,[T]),{registerTrigger:D,isMountedByThisTrigger:O}=ks(_,S,g,{payload:p,closeDelay:d,parent:C,floatingTreeRoot:E,floatingNodeId:Sa(E),floatingParentNodeId:ba(),keyboardEventRelay:w?.relayKeyboardEvent}),k=C.type===`menubar`,A=g.useState(`disabled`),j=a||A||k&&C.context.disabled,{getButtonProps:M,buttonRef:N}=Nc({disabled:j,native:o});l.useEffect(()=>{!b&&C.type===void 0&&(g.context.allowMouseUpTriggerRef.current=!1)},[g,b,C.type]);let P=l.useRef(null),F=it(),I=$(e=>{if(!P.current)return;F.clear(),g.context.allowMouseUpTriggerRef.current=!1;let t=e.target;X(P.current,t)||X(g.select(`positionerElement`),t)||t===P.current||(t==null||ib(t)!==g.select(`rootId`))&&(Nh(e,P.current)||E.events.emit(`close`,{domEvent:e,reason:On}))});l.useEffect(()=>{b&&g.select(`lastOpenChangeReason`)===`trigger-hover`&&J(P.current).addEventListener(`mouseup`,I,{once:!0})},[b,I,g]);let L=k&&C.context.hasSubmenuOpen,R=tc(y,{enabled:(c??L)&&!j&&(!k||L&&!O),handleClose:vc({blockPointerEvents:!k}),mouseOnly:!0,move:!1,restMs:C.type===void 0?u:void 0,delay:{close:d},triggerElementRef:S,externalTree:E,isActiveTrigger:v,isClosing:()=>g.select(`transitionStatus`)===`ending`}),z=cb(b,g.select(`lastOpenChangeReason`)),ee=Fa(y,{enabled:!j,event:b&&k?`click`:`mousedown`,toggle:!0,ignoreMouse:!1,stickIfOpen:C.type===void 0&&z}),B=qs(y,{enabled:!j&&L}),te=ob({open:b,enabled:k,mouseDownAction:`open`}),ne=l.useMemo(()=>zi(B.reference,ee.reference),[B.reference,ee.reference]),re=g.useState(`triggerProps`,O),{preFocusGuardRef:V,handlePreFocusGuardFocus:H,handleFocusTargetFocus:ie}=ab(g,S),ae={disabled:j,open:b},oe=[P,t,N,D,S],se=[ne,R??et,re,{"aria-haspopup":`menu`,"aria-controls":x,id:_,onMouseDown:e=>{g.select(`open`)||(F.start(200,()=>{g.context.allowMouseUpTriggerRef.current=!0}),J(e.currentTarget).addEventListener(`mouseup`,I,{once:!0}))}},k?{role:`menuitem`}:{},te,m,M],ce=$i(`button`,e,{enabled:!k,stateAttributesMapping:Yt,state:ae,ref:oe,props:se});return k?(0,Q.jsx)(rb,{tag:`button`,render:n,className:r,style:i,state:ae,refs:oe,props:se,stateAttributesMapping:Yt}):b?(0,Q.jsxs)(l.Fragment,{children:[(0,Q.jsx)(er,{ref:V,onFocus:H},`${_}-pre-focus-guard`),(0,Q.jsx)(l.Fragment,{children:ce},_),(0,Q.jsx)(er,{ref:g.context.triggerFocusTargetRef,onFocus:ie},`${_}-post-focus-guard`)]}):(0,Q.jsx)(l.Fragment,{children:ce},_)});function cb(e,t){let n=it(),[r,i]=l.useState(!1);return U(()=>{e&&t===`trigger-hover`?(i(!0),n.start(500,()=>{i(!1)})):e||(n.clear(),i(!1))},[e,t,n]),r}function lb(){let e=Ky(!0);return l.useMemo(()=>e?{type:`menubar`,context:e}:{type:void 0},[e])}var ub={"aria-expanded":void 0},db=l.forwardRef(function(e,t){let{render:n,className:r,style:i,label:a,id:o,nativeButton:s=!1,openOnHover:c=!0,delay:u=100,closeDelay:d=0,disabled:f=!1,...p}=e,m=Qy();if(!m?.parentMenu)throw Error(Ai(37));let h=og({guess:!0,label:a}),g=jy(),{store:_}=Ny(),v=Lc(o),y=_.useState(`open`),b=_.useState(`floatingRootContext`),x=_.useState(`floatingTreeRoot`),S=_.useState(`triggerPopupId`,v),C=Ts(v,_),w=$(e=>{C(e),e!==null&&_.select(`open`)&&_.select(`activeTriggerId`)==null&&_.update({activeTriggerId:v??null,activeTriggerElement:e,closeDelay:d})}),T=l.useRef(null),E=l.useCallback(e=>{T.current=e,_.set(`activeTriggerElement`,e)},[_]);U(()=>(w(T.current),()=>w(null)),[w,v,_]),_.useSyncedValue(`closeDelay`,d);let D=m.parentMenu,O=_.useState(`disabled`),k=D.useState(`disabled`),A=f||O||k,j=D.useState(`itemProps`),M=D.useState(`isActive`,h.index),N=l.useMemo(()=>({type:`submenu-trigger`,setActive(){D.select(`highlightItemOnHover`)&&D.set(`activeIndex`,h.index)}}),[D,h.index]),{getItemProps:P,itemRef:F}=Iy({closeOnClick:!1,disabled:A,highlighted:M,id:v,store:_,typingRef:D.context.typingRef,nativeButton:s,itemMetadata:N,nodeId:g?.context.nodeId}),I=tc(b,{enabled:_.useState(`hoverEnabled`)&&c&&!A,handleClose:vc({blockPointerEvents:!0}),mouseOnly:!0,move:!0,restMs:u,delay:{open:u,close:d},shouldOpen:u>0?()=>D.select(`allowMouseEnter`):void 0,triggerElementRef:T,externalTree:x,isClosing:()=>_.select(`transitionStatus`)===`ending`,guardStaleOpen:!0}),L=Fa(b,{enabled:!A,event:`mousedown`,toggle:!c,ignoreMouse:c,stickIfOpen:!1}).reference??et,R=_.useState(`triggerProps`,!0);delete R.id;let z={disabled:A,highlighted:M,open:y},ee=_.useState(`openMethod`),B=_.useState(`lastOpenChangeReason`)===`list-navigation`||ee===`keyboard`;return $i(`div`,e,{state:z,stateAttributesMapping:Jt,props:[L,I,R,j,y&&B&&Je?ub:void 0,{"aria-controls":S,tabIndex:y||M?0:-1,onBlur(){M&&D.set(`activeIndex`,null)}},p,P],ref:[t,h.ref,F,w,E]})});function fb(e){let[t,n]=l.useState({getBoundingClientRect(){return DOMRect.fromRect({width:0,height:0,x:0,y:0})}}),r=l.useRef(null),i=l.useRef(null),a=l.useRef(null),o=l.useRef(null),s=l.useRef(!0),c=l.useRef(null),u=Oi(),d=l.useMemo(()=>({anchor:t,setAnchor:n,actionsRef:a,backdropRef:r,internalBackdropRef:i,positionerRef:o,allowMouseUpTriggerRef:s,initialCursorPointRef:c,rootId:u}),[t,u]);return(0,Q.jsx)(Oy.Provider,{value:d,children:(0,Q.jsx)(My.Provider,{value:void 0,children:(0,Q.jsx)($y,{...e})})})}var pb=500,mb=l.forwardRef(function(e,t){let{render:n,className:r,style:i,...a}=e,{setAnchor:o,actionsRef:s,internalBackdropRef:c,backdropRef:u,positionerRef:d,allowMouseUpTriggerRef:f,initialCursorPointRef:p,rootId:m}=ky(!1),{store:h}=Ny(!1),g=h.useState(`open`),_=h.useState(`disabled`),v=l.useRef(null),y=l.useRef(null),b=it(),x=it(),S=l.useRef(!1),C=l.useRef(null);function w(e,t,n){let r=n.type.startsWith(`touch`);p.current={x:e,y:t},o({getBoundingClientRect(){return DOMRect.fromRect({width:r?10:0,height:r?10:0,x:e,y:t})}}),S.current=!1,s.current?.setOpen(!0,Z(mn,n)),x.start(pb,()=>{S.current=!0})}function T(e){if(_)return;f.current=!0,yt(e),w(e.clientX,e.clientY,e.nativeEvent);let t=J(v.current);C.current?.abort();let n=new AbortController;C.current=n,t.addEventListener(`mouseup`,e=>{if(f.current=!1,!S.current)return;x.clear(),S.current=!1;let t=Et(e);X(d.current,t)||m&&t&&ib(t)===m||s.current?.setOpen(!1,Z(On,e))},{once:!0,signal:n.signal})}function E(){b.clear(),y.current=null}function D(e){if(_){E();return}if(f.current=!1,e.touches.length!==1){E();return}e.stopPropagation();let t=e.touches[0],n={x:t.clientX,y:t.clientY};y.current=n,b.start(pb,()=>{w(n.x,n.y,e.nativeEvent)})}function O(e){if(e.touches.length!==1){E();return}if(b.isStarted()&&y.current){let t=e.touches[0],n=Math.abs(t.clientX-y.current.x),r=Math.abs(t.clientY-y.current.y);(n>10||r>10)&&E()}}return l.useEffect(()=>()=>{C.current?.abort()},[]),l.useEffect(()=>{function e(e){if(_)return;let t=Et(e);(X(v.current,t)||X(c.current,t)||X(u.current,t))&&e.preventDefault()}return q(J(v.current),`contextmenu`,e)},[u,_,c]),$i(`div`,e,{state:{open:g},ref:[v,t],props:[{onContextMenu:T,onTouchStart:D,onTouchMove:O,onTouchEnd:E,onTouchCancel:E,style:{WebkitTouchCallout:`none`}},a],stateAttributesMapping:Yt})}),hb=Wy,gb={claude:`Claude Code`,codex:`Codex`,opencode:`OpenCode`,pi:`Pi`};function _b(e){return Object.hasOwn(gb,e)?gb[e]:e}function vb(e){let t=Math.max(0,Math.floor((Date.now()-new Date(e).getTime())/6e4));return t<1?`now`:t<60?`${t}m`:t<1440?`${Math.floor(t/60)}h`:`${Math.floor(t/1440)}d`}var yb=[{id:`validate`,label:`Checking the machine`,active:`Checking the machine…`},{id:`checkout`,label:`Creating the worktree`,active:`Creating the worktree…`},{id:`start`,label:`Starting the agent`,active:`Starting the agent…`},{id:`prompt`,label:`Sending your prompt`,active:`Sending your prompt…`}],bb=6e5,xb=e=>e===`checkout_complete`?2:Math.max(0,yb.findIndex(t=>t.id===e)),Sb=e=>[`pending`,`running`].includes(e.operation?.state??``)&&!e.panes.some(e=>e.kind===`agent`),Cb=e=>[`failed`,`unknown`].includes(e.operation?.state??``)&&!e.panes.some(e=>e.kind===`agent`),wb=e=>yb[xb(e.operation?.step??`validate`)].active,Tb=(e,t)=>t-Date.parse(e.updatedAt)<bb,Eb=(e,t=Date.now())=>e.panes.some(e=>e.kind===`agent`)||Sb(e)||Cb(e)&&Tb(e,t),Db=e=>new URLSearchParams({machineId:e.machineId??`local`,projectId:e.id}),Ob=e=>e.branch??e.label,kb=e=>e.path.split(`/`).at(-1)??``,Ab=(e,t)=>`${Ob(e)} ${kb(e)}`.toLowerCase().includes(t.trim().toLowerCase()),jb=async(e,t)=>{let n=await fetch(`/api/worktrees?${Db(e)}`,{signal:t});if(!n.ok)throw Error(`Could not list worktrees.`);return await n.json()},Mb=async(e,t)=>{let n=await fetch(`/api/worktrees/open`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({machineId:e.machineId??`local`,projectId:e.id,path:t.path})});if(!n.ok)throw Error(`Could not open this worktree.`);return(await n.json()).id},Nb=async(e,t)=>{try{await a(`/threads/${encodeURIComponent(await Mb(e,t))}`)}catch(e){ol(e instanceof Error?e.message:`Could not open this worktree.`)}},Pb=e=>{(e.key.length===1||e.key===`Backspace`)&&e.stopPropagation()};function Fb({project:e}){let[t,n]=(0,l.useState)(``),r=J_({queryKey:[`worktrees`,e.machineId,e.id],queryFn:({signal:t})=>jb(e,t),staleTime:0,gcTime:0}),i=(r.data??[]).filter(e=>Ab(e,t));return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`composer-select-search`,children:[(0,Q.jsx)(H,{size:14,"aria-hidden":`true`}),(0,Q.jsx)(`input`,{autoFocus:!0,"aria-label":`Search worktrees`,placeholder:`Search worktrees…`,value:t,onChange:e=>n(e.target.value),onKeyDown:Pb})]}),(0,Q.jsxs)(`div`,{className:`worktree-menu-list`,children:[i.map(t=>(0,Q.jsx)(Yl,{label:t.path,side:`right`,children:(0,Q.jsxs)(Ly,{className:`thread-menu-item`,onClick:()=>void Nb(e,t),children:[(0,Q.jsx)(M,{size:14,"aria-hidden":`true`}),(0,Q.jsxs)(`span`,{className:`worktree-menu-name`,children:[Ob(t),(0,Q.jsx)(`small`,{children:kb(t)})]})]})},t.path)),r.isError&&(0,Q.jsx)(`p`,{className:`worktree-menu-note`,role:`alert`,children:`Could not list worktrees.`}),r.data&&!i.length&&(0,Q.jsx)(`p`,{className:`worktree-menu-note`,children:r.data.length?`No matches`:`Every worktree already has a thread`})]})]})}function Ib({projects:e}){return(0,Q.jsxs)($y,{children:[(0,Q.jsx)(Yl,{label:`Open existing worktree`,children:(0,Q.jsx)(sb,{className:`sidebar-open-worktree`,"aria-label":`Open existing worktree`,disabled:!e.length,children:(0,Q.jsx)(H,{size:16,"aria-hidden":`true`})})}),(0,Q.jsx)(Uy,{children:(0,Q.jsx)(Wy,{className:`thread-menu-positioner`,sideOffset:6,align:`start`,children:(0,Q.jsx)(By,{className:`thread-menu`,children:e.map(e=>(0,Q.jsxs)(tb,{children:[(0,Q.jsxs)(db,{className:`thread-menu-item`,children:[(0,Q.jsx)(Cg,{project:e}),(0,Q.jsx)(`span`,{children:e.name}),(0,Q.jsx)(x,{size:14,"aria-hidden":`true`,className:`worktree-menu-chevron`})]}),(0,Q.jsx)(Uy,{children:(0,Q.jsx)(Wy,{className:`thread-menu-positioner`,sideOffset:4,alignOffset:-4,children:(0,Q.jsx)(By,{className:`thread-menu worktree-menu`,children:(0,Q.jsx)(Fb,{project:e})})})})]},`${e.machineId}:${e.id}`))})})})]})}function Lb({thread:e,onDone:t,onError:n}){let[r,i]=(0,l.useState)(e.title),a=(0,l.useRef)(null),o=(0,l.useRef)(!1);(0,l.useEffect)(()=>{a.current?.focus(),a.current?.select()},[]);let s=i=>{if(o.current)return;o.current=!0,t();let a=r.trim();i&&a&&a!==e.title&&op(e,a).catch(n)};return(0,Q.jsx)(`input`,{ref:a,className:`thread-name-input`,"aria-label":`Rename ${e.title}`,value:r,maxLength:90,onChange:e=>i(e.target.value),onBlur:()=>s(!0),onClick:e=>e.stopPropagation(),onKeyDown:e=>{e.stopPropagation(),e.key===`Enter`&&s(!0),e.key===`Escape`&&s(!1)}})}function Rb({project:e,onDone:t,onError:n}){let[r,i]=(0,l.useState)(e.name),a=(0,l.useRef)(null),o=(0,l.useRef)(!1);(0,l.useEffect)(()=>{a.current?.focus(),a.current?.select()},[]);let s=i=>{if(o.current)return;o.current=!0,t();let a=r.trim();i&&a&&a!==e.name&&sp(e,a).catch(n)};return(0,Q.jsx)(`input`,{ref:a,className:`thread-name-input group-name-input`,"aria-label":`Rename ${e.name}`,value:r,maxLength:90,onChange:e=>i(e.target.value),onBlur:()=>s(!0),onClick:e=>e.stopPropagation(),onKeyDown:e=>{e.stopPropagation(),e.key===`Enter`&&s(!0),e.key===`Escape`&&s(!1)}})}var zb=128;async function Bb(e){let t=await createImageBitmap(e),n=document.createElement(`canvas`);n.width=n.height=zb;let r=Math.min(zb/t.width,zb/t.height),i=t.width*r,a=t.height*r;return n.getContext(`2d`).drawImage(t,(zb-i)/2,(zb-a)/2,i,a),new Promise((e,t)=>n.toBlob(n=>n?e(n):t(Error(`Could not read this image.`)),`image/png`))}function Vb({project:e,open:t,onClose:n,onError:r}){let i=(0,l.useRef)(null),[a,o]=(0,l.useState)(!1),[s,c]=(0,l.useState)(!1),u=async e=>{c(!0);try{await e(),n()}catch(e){r(e)}finally{c(!1)}},d=t=>{t&&u(async()=>lp(e,await Bb(t)))};return(0,Q.jsx)(Cv,{open:t,onOpenChange:e=>{e||n()},children:(0,Q.jsxs)(Jc,{children:[(0,Q.jsx)(Oc,{className:`dialog-backdrop`}),(0,Q.jsxs)(Gc,{className:`dialog`,children:[(0,Q.jsxs)(Yc,{className:`dialog-message`,children:[`Change icon for `,e.name]}),(0,Q.jsxs)(`button`,{type:`button`,className:`icon-dropzone ${a?`is-dragging`:``}`,disabled:s,onClick:()=>i.current?.click(),onDragOver:e=>{e.preventDefault(),o(!0)},onDragLeave:()=>o(!1),onDrop:e=>{e.preventDefault(),o(!1),d(e.dataTransfer.files[0])},children:[(0,Q.jsx)(P,{size:22,"aria-hidden":`true`}),`Drop an image here, or click to choose`]}),(0,Q.jsx)(`input`,{ref:i,type:`file`,accept:`image/*`,hidden:!0,onChange:e=>{d(e.target.files?.[0]),e.target.value=``}}),(0,Q.jsxs)(`div`,{className:`dialog-actions`,children:[(0,Q.jsx)(`button`,{type:`button`,className:`dialog-button`,disabled:s,onClick:()=>void u(()=>up(e)),children:`Reset to default`}),(0,Q.jsx)(Ic,{className:`dialog-button`,children:`Cancel`})]})]})]})})}var Hb=220,Ub=`[data-flip-id]`,Wb=e=>{let t=e.getBoundingClientRect().top-e.scrollTop;return new Map([...e.querySelectorAll(Ub)].map(e=>[e.dataset.flipId,{element:e,top:e.getBoundingClientRect().top-t}]))};function Gb(e){let t=(0,l.useRef)(new Map);(0,l.useLayoutEffect)(()=>{if(!e.current)return;let n=Wb(e.current);for(let[e,{element:r,top:i}]of n){let n=t.current.get(e);n===void 0||Math.abs(n-i)<1||r.animate([{transform:`translateY(${n-i}px)`},{transform:`none`}],{duration:Hb,easing:`cubic-bezier(.2, .8, .2, 1)`})}t.current=new Map([...n].map(([e,{top:t}])=>[e,t]))})}function Kb(e,t){let n=new Map;for(let r of e){let e=r.logicalId??r.id,i=n.get(e);i?(i.locations.push(r.id),r.id===t&&(i.project=r)):n.set(e,{id:e,project:r,locations:[r.id]})}return[...n.values()]}var qb=/^\/(?:Users|home)\/[^/]+/,Jb=e=>e.replace(qb,`~`),Yb={working:`Working`,blocked:`Needs input`,done:`Done`,idle:`Idle`,unknown:`Unknown`},Xb={blocked:L,done:C,unknown:w},Zb=e=>ol(e instanceof Error?e.message:`Herdr could not complete this action.`),Qb=async e=>{await al(gp([e]),{confirmLabel:`Delete`,danger:!0})&&await pp(e).catch(Zb)},$b=(0,l.memo)(function({thread:e,project:t,machineName:n,current:r,showProject:i}){let a=!!e.archivedAt,o=a?f:p,s=a?`Unarchive ${e.title}`:`Archive ${e.title}`,[c,u]=(0,l.useState)(!1),d=c?(0,Q.jsx)(Lb,{thread:e,onDone:()=>u(!1),onError:Zb}):void 0;return(0,Q.jsxs)(fb,{children:[(0,Q.jsxs)(mb,{className:`thread-item`,"data-flip-id":e.id,onDoubleClick:e=>{e.preventDefault(),u(!0)},children:[(0,Q.jsx)(ex,{thread:e,project:t,machineName:n,current:r,showProject:i,editor:d}),(0,Q.jsx)(Yl,{label:a?`Unarchive`:`Archive`,children:(0,Q.jsx)(`button`,{type:`button`,className:`thread-archive`,"aria-label":s,onClick:()=>void ap(e,!a).catch(Zb),children:(0,Q.jsx)(o,{size:15,strokeWidth:1.8,"aria-hidden":`true`})})})]}),(0,Q.jsx)(Uy,{children:(0,Q.jsx)(hb,{className:`thread-menu-positioner`,children:(0,Q.jsx)(By,{className:`thread-menu`,children:(0,Q.jsxs)(Ly,{className:`thread-menu-item is-danger`,onClick:()=>void Qb(e),children:[(0,Q.jsx)(ue,{size:14,"aria-hidden":`true`}),`Delete permanently`]})})})})]})});function ex({thread:e,project:t,machineName:n,current:r,showProject:i,editor:a}){let o=Sb(e),s=Cb(e),c=s?de:o?void 0:Xb[e.status],l=s||e.status===`blocked`||e.status===`done`,u=o?wb(e):s?`Launch stopped`:Yb[e.status],d=o||s?u:i?t?.name:_b(e.agent),f=a?`div`:`a`;return(0,Q.jsx)(Yl,{label:`${e.title} · ${t?.name??``} · ${n} · ${_b(e.agent)} · ${e.model} · ${u}`,side:`right`,children:(0,Q.jsxs)(f,{className:`thread-row ${r?`is-current`:``} ${l?`needs-attention status-${s?`blocked`:e.status}`:``}`,href:a?void 0:`/threads/${encodeURIComponent(e.id)}`,"aria-current":r?`page`:void 0,"aria-label":`${e.title} · ${t?.name??``} · ${n} · ${u}`,children:[(0,Q.jsxs)(`span`,{className:`thread-avatar`,"aria-hidden":`true`,children:[(0,Q.jsx)(qf,{thread:e,working:e.status===`working`||o,size:24}),c&&(0,Q.jsx)(c,{className:`thread-status status-${s?`blocked`:e.status}`,size:14,strokeWidth:2.2}),(0,Q.jsx)(`span`,{className:`thread-avatar-harness`,children:(0,Q.jsx)(yg,{harness:e.agent,size:14})})]}),(0,Q.jsxs)(`span`,{className:`thread-copy`,children:[(0,Q.jsxs)(`span`,{className:`thread-context`,children:[i&&t&&!o&&!s&&(0,Q.jsx)(Cg,{project:t}),e.worktree&&!o&&!s&&(0,Q.jsx)(M,{className:`thread-worktree`,size:11,"aria-label":`Worktree`}),d]}),a??(0,Q.jsx)(`span`,{className:`thread-name`,children:e.title})]}),(0,Q.jsx)(`span`,{className:`thread-time`,children:vb(e.updatedAt)})]})})}function tx({project:e,closed:t,onToggle:n}){let[r,i]=(0,l.useState)(!1),[o,s]=(0,l.useState)(!1),c=r?`div`:`button`,u=r?(0,Q.jsx)(Rb,{project:e,onDone:()=>i(!1),onError:Zb}):(0,Q.jsx)(`span`,{className:`group-name`,children:e.name});return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(fb,{children:[(0,Q.jsx)(mb,{className:`group-header`,children:(0,Q.jsxs)(c,{className:`group-title`,onClick:r?void 0:n,"aria-expanded":r?void 0:!t,children:[(0,Q.jsx)(`span`,{className:`group-chevron`,"aria-hidden":`true`,children:t?(0,Q.jsx)(x,{size:14}):(0,Q.jsx)(b,{size:14})}),(0,Q.jsx)(Cg,{project:e}),u]})}),(0,Q.jsx)(Uy,{children:(0,Q.jsx)(hb,{className:`thread-menu-positioner`,children:(0,Q.jsxs)(By,{className:`thread-menu`,children:[(0,Q.jsxs)(Ly,{className:`thread-menu-item`,onClick:()=>void a(`/new?project=${encodeURIComponent(e.id)}`),children:[(0,Q.jsx)(V,{size:14,"aria-hidden":`true`}),`New thread`]}),(0,Q.jsxs)(Ly,{className:`thread-menu-item`,onClick:()=>i(!0),children:[(0,Q.jsx)(re,{size:14,"aria-hidden":`true`}),`Rename project`]}),(0,Q.jsxs)(Ly,{className:`thread-menu-item`,onClick:()=>s(!0),children:[(0,Q.jsx)(P,{size:14,"aria-hidden":`true`}),`Change icon`]}),(0,Q.jsx)(`div`,{className:`thread-menu-path`,title:e.path,children:Jb(e.path)})]})})})]}),(0,Q.jsx)(Vb,{project:e,open:o,onClose:()=>s(!1),onError:Zb})]})}function nx({threads:e,renderThread:t}){let[n,r]=(0,l.useState)(!1),[i,a]=(0,l.useState)(!1),o=async()=>{if(await al(gp(e),{confirmLabel:`Delete all`,danger:!0})){a(!0);try{let e=await mp();e.failed.length&&await ol(`${e.failed.length} archived ${e.failed.length===1?`thread`:`threads`} could not be deleted.`)}catch(e){Zb(e)}finally{a(!1)}}};return(0,Q.jsxs)(`section`,{className:`thread-group archived-threads`,"aria-label":`Archived threads`,children:[(0,Q.jsxs)(`div`,{className:`group-header`,children:[(0,Q.jsxs)(`button`,{className:`group-title`,onClick:()=>r(e=>!e),"aria-expanded":n,children:[(0,Q.jsx)(`span`,{className:`group-chevron`,"aria-hidden":`true`,children:n?(0,Q.jsx)(b,{size:14}):(0,Q.jsx)(x,{size:14})}),(0,Q.jsx)(p,{size:14,"aria-hidden":`true`}),(0,Q.jsx)(`span`,{className:`group-name`,children:`Archived`}),(0,Q.jsx)(`span`,{className:`group-count`,children:e.length})]}),(0,Q.jsx)(`button`,{type:`button`,className:`archived-delete-all`,onClick:()=>void o(),disabled:i,children:i?`Deleting…`:`Delete all`})]}),n&&e.map(t)]})}function rx({projects:e,threads:t,archived:n=[],machines:r,currentId:i,mode:a,onModeChange:o,collapsed:s,mobileOpen:c,onCollapse:u,onCloseMobile:d,onOpenPalette:f}){let[p,m]=(0,l.useState)([]),h=t.find(e=>e.id===i)?.projectId,g=Kb(e,h),_=(0,l.useRef)(null);Gb(_);let v=(t,n)=>{let a=e.find(e=>e.id===t.projectId);return(0,Q.jsx)($b,{thread:t,project:a,machineName:r.find(e=>e.id===t.machineId)?.name??t.machineId,current:i===t.id,showProject:n},t.id)};return(0,Q.jsxs)(Q.Fragment,{children:[c&&(0,Q.jsx)(`button`,{className:`sidebar-scrim`,"aria-label":`Close sidebar`,onClick:d}),(0,Q.jsxs)(`aside`,{className:`sidebar ${s?`is-collapsed`:``} ${c?`is-mobile-open`:``}`,"aria-label":`Threads`,onClick:e=>{c&&e.target.closest(`a[href]`)&&d()},children:[(0,Q.jsxs)(`div`,{className:`sidebar-header`,children:[!s&&(0,Q.jsxs)(`span`,{className:`brand`,children:[(0,Q.jsx)(`img`,{src:`/brand-mark.png`,alt:``,width:20,height:20}),`webr`]}),(0,Q.jsx)(`button`,{className:`icon-button sidebar-collapse`,"aria-label":s?`Expand sidebar`:`Collapse sidebar`,onClick:u,children:s?(0,Q.jsx)(te,{size:16}):(0,Q.jsx)(B,{size:16})}),(0,Q.jsx)(`button`,{className:`icon-button mobile-close`,"aria-label":`Close sidebar`,onClick:d,children:(0,Q.jsx)(fe,{size:16})})]}),(0,Q.jsxs)(`div`,{className:`sidebar-actions`,children:[(0,Q.jsx)(Yl,{label:`New thread`,children:(0,Q.jsxs)(`a`,{className:`sidebar-new-thread`,href:`/new${h?`?project=${encodeURIComponent(h)}`:``}`,"aria-label":`New thread`,children:[(0,Q.jsx)(oe,{size:16,"aria-hidden":`true`}),!s&&(0,Q.jsx)(`span`,{children:`New thread`})]})}),(0,Q.jsx)(Ib,{projects:e}),!s&&(0,Q.jsxs)(`div`,{className:`sidebar-view-switch`,role:`group`,"aria-label":`Sidebar layout`,children:[(0,Q.jsx)(Yl,{label:`Show threads`,children:(0,Q.jsx)(`button`,{type:`button`,"aria-label":`Show threads`,"aria-pressed":a===`threads`,onClick:()=>o(`threads`),children:(0,Q.jsx)(F,{size:16,"aria-hidden":`true`})})}),(0,Q.jsx)(Yl,{label:`Group by project`,children:(0,Q.jsx)(`button`,{type:`button`,"aria-label":`Group by project`,"aria-pressed":a===`projects`,onClick:()=>o(`projects`),children:(0,Q.jsx)(A,{size:16,"aria-hidden":`true`})})})]})]}),!s&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`nav`,{ref:_,className:`thread-navigation`,"aria-label":`Agent threads`,children:[a===`projects`?g.filter(e=>t.some(t=>e.locations.includes(t.projectId))).sort((e,n)=>(t.find(e=>n.locations.includes(e.projectId))?.updatedAt??``).localeCompare(t.find(t=>e.locations.includes(t.projectId))?.updatedAt??``)).map(({id:e,project:n,locations:r})=>(0,Q.jsxs)(`section`,{className:`thread-group`,children:[(0,Q.jsx)(tx,{project:n,closed:p.includes(e),onToggle:()=>m(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])}),!p.includes(e)&&t.filter(e=>r.includes(e.projectId)).map(e=>v(e,!1))]},e)):t.map(e=>v(e,!0)),!t.length&&!n.length&&(0,Q.jsx)(`p`,{className:`sidebar-empty`,children:`No agents yet. Press ⌘K to start one.`})]}),!!n.length&&(0,Q.jsx)(nx,{threads:n,renderThread:e=>v(e,!0)}),(0,Q.jsxs)(`div`,{className:`sidebar-footer`,children:[(0,Q.jsxs)(`a`,{className:`sidebar-settings`,href:`/settings`,children:[(0,Q.jsx)(ae,{size:15}),` Settings`]}),(0,Q.jsx)(Yl,{label:`Open command palette`,children:(0,Q.jsx)(`button`,{type:`button`,className:`sidebar-palette`,"aria-label":`Open command palette`,onClick:f,children:(0,Q.jsx)(`kbd`,{children:`⌘K`})})})]})]})]})]})}var ix=e=>{let t,n=new Set,r=(e,r)=>{let i=typeof e==`function`?e(t):e;if(!Object.is(i,t)){let e=t;t=r??(typeof i!=`object`||!i)?i:Object.assign({},t,i),n.forEach(n=>n(t,e))}},i=()=>t,a={setState:r,getState:i,getInitialState:()=>o,subscribe:e=>(n.add(e),()=>n.delete(e))},o=t=e(r,i,a);return a},ax=(e=>e?ix(e):ix),ox=e=>e;function sx(e,t=ox){let n=l.useSyncExternalStore(e.subscribe,l.useCallback(()=>t(e.getState()),[e,t]),l.useCallback(()=>t(e.getInitialState()),[e,t]));return l.useDebugValue(n),n}var cx=(e,t)=>JSON.stringify(e)===JSON.stringify(t),lx=(e,t)=>e&&cx(e,t)?e:t;function ux(e){let t=new Map,n=new Set,r=ax((e,r)=>({projections:{},threads:{},projects:{},threadIds:[],projectIds:[],connected:!1,connection:t=>e(e=>{if(t)return{connected:t};for(let t of Object.keys(e.projections))n.add(t);return{connected:t,projections:Object.fromEntries(Object.entries(e.projections).map(([e,t])=>[e,{...t,connected:!1,freshAt:null}])),threads:Object.fromEntries(Object.entries(e.threads).map(([e,t])=>[e,{...t,status:`unknown`,bindingState:`detached`}]))}}),install:i=>{let a=r(),o=a.projections[i.machineId],s=t.get(i.machineId)??new Set;if(s.has(i.generation)||!n.has(i.machineId)&&o?.generation===i.generation&&o.revision>=i.revision)return;n.delete(i.machineId),o&&o.generation!==i.generation&&s.add(o.generation),s.size>8&&s.delete(s.values().next().value),t.set(i.machineId,s);let c=Object.fromEntries(Object.entries(a.threads).filter(([,e])=>e.machineId!==i.machineId));for(let e of i.threads)c[e.id]=lx(a.threads[e.id],{...e,panes:e.panes.map(t=>lx(a.threads[e.id]?.panes.find(e=>e.id===t.id&&e.terminalId===t.terminalId),t))});let l={...a.projections,[i.machineId]:i},u={};for(let e of Object.values(l))for(let t of e.projects)u[t.id]=lx(a.projects[t.id],t);let d=Object.values(c).sort((e,t)=>t.updatedAt.localeCompare(e.updatedAt)).map(e=>e.id),f=Object.keys(u);e({projections:l,threads:c,projects:u,threadIds:lx(a.threadIds,d),projectIds:lx(a.projectIds,f)})}}));for(let t of e.projections)r.getState().install(t);return r}var dx=()=>ax(e=>({focusedPanes:{},paneWindows:{},focus:(t,n)=>e(e=>({focusedPanes:{...e.focusedPanes,[t]:n}})),showWindow:(t,n)=>e(e=>({paneWindows:{...e.paneWindows,[t]:n}}))}));function fx(e){if(e.length<32)throw Error(`short_frame`);let t=new DataView(e.buffer,e.byteOffset,e.byteLength),n=Number(t.getBigUint64(12));if(t.getUint32(0)!==1212437041||t.getUint32(24)!==e.length-32||e.length-32>262144||!Number.isSafeInteger(n)||t.getUint8(28)>1||t.getUint8(29)||t.getUint16(30))throw Error(`invalid_frame`);let r={streamId:t.getUint32(4),generation:t.getUint32(8),seq:n,width:t.getUint16(20),height:t.getUint16(22),full:!!t.getUint8(28),bytes:e.subarray(32)};if(!r.streamId||!r.generation||!r.width||r.width>500||!r.height||r.height>300)throw Error(`invalid_dimensions`);return r}var px=class{seq;accept(e){if(this.seq===void 0&&!e.full)throw Error(`baseline_required`);if(this.seq!==void 0&&e.seq!==this.seq+1)throw Error(`sequence_gap`);this.seq=e.seq}},mx=class{terminal;acknowledge;budget;frames=[];bytes=0;writing=!1;closed=!1;constructor(e,t,n=524288){this.terminal=e,this.acknowledge=t,this.budget=n}push(e){if(!this.closed){if(this.bytes+e.bytes.length>this.budget)throw Error(`renderer_overload`);this.bytes+=e.bytes.length,this.frames.push(e),this.frames.length,this.bytes/1024,this.flush()}}close(){this.closed=!0,this.frames=[],this.bytes=0}flush(){if(this.closed||this.writing||!this.frames.length)return;this.writing=!0;let e=this.frames.shift();this.terminal.resize(e.width,e.height);let t=e.full?new Uint8Array(e.bytes.length+2):e.bytes;e.full&&(t.set([27,99]),t.set(e.bytes,2));let n=Sp();this.terminal.write(t,()=>{this.closed||(Sp()-n,this.bytes-=e.bytes.length,this.writing=!1,this.acknowledge(e),this.flush())})}},hx=(e,t=Math.random)=>Math.min(3e4,Math.round(Math.min(25e3,1e3*2**Math.min(e,5))*(.8+t()*.4))),gx=`Another controller owns this terminal.`,_x=class{install;onConnection;metadata;binary;stopped=!0;epoch=0;nextId=1;panes=new Map;reconnect;instance=``;failures=0;connectedAt=0;scrollSentAt=new Map;inputSentAt=new Map;openedAt=new Map;constructor(e,t){this.install=e,this.onConnection=t}start(){this.stopped=!1,this.connect()}stop(){this.stopped=!0,clearTimeout(this.reconnect),this.disconnect()}mount(e){let t=this.nextId++;return this.panes.set(t,{...e,generation:1,sequence:new px,writable:!1,accepted:!1,baseline:!1,pending:0,resizing:!1,attempts:0}),this.open(t),{close:()=>{let e=this.panes.get(t);e&&(this.send({type:`release`,streamId:t,generation:e.generation}),e.renderer?.close()),this.panes.delete(t)},input:(e,n=!1)=>{let r=this.panes.get(t);r?.writable&&(this.inputSentAt.set(t,Sp()),this.send({type:`input`,streamId:t,generation:r.generation,text:e,paste:n}))},control:(e=!1)=>{let n=this.panes.get(t);n&&(n.mode!==`control`||e)&&(this.send({type:`release`,streamId:t,generation:n.generation}),n.reason=void 0,n.mode=`control`,++n.generation,n.sequence=new px,this.open(t,e))},observe:()=>{let e=this.panes.get(t);e&&e.mode!==`observe`&&(this.send({type:`release`,streamId:t,generation:e.generation}),e.mode=`observe`,++e.generation,e.sequence=new px,this.open(t))},resize:(e,n,r=!1)=>{let i=this.panes.get(t);i&&(e!==i.cols||n!==i.rows||r&&i.mode===`control`&&i.accepted)&&(i.cols=e,i.rows=n,i.mode===`control`&&i.accepted?(i.writable=!1,i.baseline=!1,i.resizing=!0,i.onState(`Waiting for the resized full baseline.`,!1),this.send({type:`resize`,streamId:t,generation:i.generation,cols:e,rows:n})):(this.send({type:`release`,streamId:t,generation:i.generation}),++i.generation,i.sequence=new px,this.open(t)))},scroll:(e,n,r,i)=>{let a=this.panes.get(t);a?.writable&&(this.scrollSentAt.set(t,Sp()),this.send({type:`scroll`,streamId:t,generation:a.generation,direction:e,lines:n,column:r,row:i}))},mouse:(e,n,r,i,a)=>{let o=this.panes.get(t);o?.writable&&this.send({type:`mouse`,streamId:t,generation:o.generation,action:e,button:n,column:r,row:i,modifiers:a})}}}command(e,t,n,r){let i=[...this.panes.entries()].find(([,r])=>r.machineId===e&&r.threadId===t&&r.terminalId===n);if(!i)return;let[a,o]=i;o.writable=!1,o.reason=void 0,this.send({type:`release`,streamId:a,generation:o.generation}),o.mode=r===`release`?`observe`:`control`,++o.generation,o.sequence=new px,this.open(a,r===`takeover`)}send(e){return this.binary?.readyState!==WebSocket.OPEN||this.metadata?.readyState!==WebSocket.OPEN?!1:this.binary.bufferedAmount>32768?(this.disconnect(),!1):(this.binary.send(JSON.stringify(e)),!0)}open(e,t=!1){let n=this.panes.get(e);n&&(n.writable=!1,n.accepted=!1,n.baseline=!1,n.pending=0,n.resizing=!1,n.renderer?.close(),n.renderer=new mx(n.terminal,t=>{if(this.panes.get(e)!==n||n.generation!==t.generation||!this.send({type:`ack`,streamId:e,generation:t.generation,seq:t.seq}))return;if(--n.pending,t.full&&(!n.resizing||t.width===n.cols&&t.height===n.rows)){n.baseline=!0,n.resizing=!1;let t=this.openedAt.get(e);t!==void 0&&(Sp()-t,this.openedAt.delete(e))}let r=n.mode===`control`&&n.accepted&&n.baseline;n.writable=r,t.full&&n.onState(r?`Input control is active.`:n.reason??`Read-only`,r)}),n.onState(n.mode===`control`?`Waiting for terminal control.`:n.reason??`Read-only`,!1),this.openedAt.set(e,Sp()),this.send({type:`open`,streamId:e,generation:n.generation,machineId:n.machineId,threadId:n.threadId,terminalId:n.terminalId,mode:n.mode,cols:n.cols,rows:n.rows,takeover:t}))}connect(){if(this.stopped)return;this.instance=cm();let e=++this.epoch,t=(location.protocol===`https:`?`wss://`:`ws://`)+location.host,n=new WebSocket(t+`/api/ws/metadata?instance=`+this.instance),r=new WebSocket(t+`/api/ws/terminal?instance=`+this.instance);this.metadata=n,this.binary=r,r.binaryType=`arraybuffer`;let i=()=>{if(e===this.epoch&&n.readyState===1&&r.readyState===1){this.connectedAt=Date.now(),this.onConnection(!0);for(let[e,t]of this.panes)++t.generation,t.sequence=new px,t.attempts=0,this.open(e)}};n.onopen=i,r.onopen=i,n.onmessage=t=>{if(e===this.epoch)try{let e=JSON.parse(t.data);e.type===`projection`&&this.install(e.projection)}catch{this.disconnect()}},r.onmessage=t=>{if(e===this.epoch)try{if(typeof t.data==`string`){let e=JSON.parse(t.data),n=this.panes.get(e.streamId);if(!n||n.generation!==e.generation)return;if(e.type===`stream.opened`&&(n.accepted=!!e.writable&&n.mode===`control`,n.accepted&&(n.baseline=!1,n.resizing=!0,this.send({type:`resize`,streamId:e.streamId,generation:e.generation,cols:n.cols,rows:n.rows})),n.writable=n.accepted&&n.baseline,n.onState(n.writable?`Input control is active.`:n.reason??(n.accepted?`Waiting for the full baseline; input is disabled.`:`Read-only`),n.writable)),e.type===`stream.closed`||e.type===`stream.error`){if(n.writable=!1,n.accepted=!1,n.baseline=!1,n.renderer?.close(),n.onState(e.reason===`controller_conflict`?gx:String(e.reason).replaceAll(`_`,` `),!1),e.type===`stream.error`&&n.mode===`control`){n.reason=e.reason===`controller_conflict`?gx:String(e.reason).replaceAll(`_`,` `),n.mode=`observe`,++n.generation,n.sequence=new px,this.open(e.streamId);return}e.reason===`stream_resync_required`&&n.attempts++<2&&(++n.generation,n.sequence=new px,n.mode=`observe`,this.open(e.streamId))}return}let e=Sp(),n=fx(new Uint8Array(t.data));t.data.byteLength,Sp()-e;let r=this.inputSentAt.get(n.streamId);r!==void 0&&(Sp()-r,this.inputSentAt.delete(n.streamId));let i=this.scrollSentAt.get(n.streamId);i!==void 0&&(Sp()-i,this.scrollSentAt.delete(n.streamId));let a=this.panes.get(n.streamId);if(!a||a.generation!==n.generation)return;a.sequence.accept(n),++a.pending,a.pending,a.renderer?.push(n)}catch{this.disconnect()}};let a=()=>{e===this.epoch&&this.disconnect()};n.onclose=a,n.onerror=a,r.onclose=a,r.onerror=a}disconnect(){this.connectedAt&&Date.now()-this.connectedAt>=3e4&&(this.failures=0),this.connectedAt=0,++this.epoch,this.metadata?.close(),this.binary?.close(),this.metadata=void 0,this.binary=void 0,this.onConnection(!1);for(let e of this.panes.values())e.renderer?.close(),e.writable=!1,e.mode=`observe`,e.onState(`Disconnected; input was not saved.`,!1);clearTimeout(this.reconnect),this.stopped||(this.reconnect=setTimeout(()=>this.connect(),hx(this.failures++)))}},vx=(0,l.createContext)(null);function yx({bootstrap:e,children:t}){let[n]=(0,l.useState)(()=>{let t=ux(e);return{runtime:t,ui:dx(),terminals:new _x(e=>{let n=xp(`projectionInstallMs`);t.getState().install(e),n()},e=>t.getState().connection(e))}}),[r]=(0,l.useState)(()=>new F_({defaultOptions:{queries:{staleTime:15e3,retry:!1}}}));return(0,l.useEffect)(()=>(n.terminals.start(),()=>n.terminals.stop()),[n]),(0,Q.jsx)(vx.Provider,{value:n,children:(0,Q.jsx)(kg,{client:r,children:t})})}function bx(){let e=(0,l.useContext)(vx);if(!e)throw Error(`Runtime provider is missing`);return e}function xx(e){return sx(bx().runtime,e)}var Sx={Enter:`\r`,Backspace:``,Tab:` `,Escape:`\x1B`,ArrowUp:`\x1B[A`,ArrowDown:`\x1B[B`,ArrowRight:`\x1B[C`,ArrowLeft:`\x1B[D`};function Cx(e){let t=e.ctrlKey&&/^[a-z]$/i.test(e.key)?String.fromCharCode(e.key.toUpperCase().charCodeAt(0)-64):Sx[e.key],n=e.key===`Enter`&&e.shiftKey;return t&&(e.altKey||n?`\x1B`+t:t)}var wx=e=>/^[a-z@\[\\\]^_]$/i.test(e)?String.fromCharCode(e.toUpperCase().charCodeAt(0)&31):void 0;function Tx({onInput:e,onFocusChange:t}){let[n,r]=(0,l.useState)(``),i=(0,l.useRef)(!1),a=(0,l.useRef)(null);return(0,Q.jsx)(`textarea`,{className:`terminal-input-capture`,value:n,"aria-label":`Terminal input`,rows:1,onFocus:()=>t?.(!0),onBlur:()=>t?.(!1),onCompositionStart:()=>{i.current=!0,a.current=null},onCompositionEnd:t=>{i.current=!1;let n=t.data;a.current=n,n&&e(n),r(``),t.currentTarget.value=``},onChange:t=>{if(i.current){r(t.target.value);return}let n=t.target.value;n&&n!==a.current&&e(n),a.current=null,r(``),t.currentTarget.value=``},onPaste:t=>{t.preventDefault(),a.current=null;let n=t.clipboardData.getData(`text/plain`);n&&e(n,!0)},onKeyDown:t=>{if(t.defaultPrevented||t.nativeEvent.isComposing||i.current||t.metaKey)return;a.current=null;let n=Cx(t);n&&(t.preventDefault(),e(n))}})}var Ex=[{label:`Tab`,key:`Tab`},{label:(0,Q.jsx)(h,{size:16}),key:`ArrowLeft`,name:`Left`},{label:(0,Q.jsx)(m,{size:16}),key:`ArrowDown`,name:`Down`},{label:(0,Q.jsx)(_,{size:16}),key:`ArrowUp`,name:`Up`},{label:(0,Q.jsx)(g,{size:16}),key:`ArrowRight`,name:`Right`}],Dx=e=>e.preventDefault(),Ox=e=>({onPointerDown:t=>{Dx(t),e()},onMouseDown:Dx,onTouchStart:Dx,onClick:t=>{t.detail===0&&e()}}),kx={idle:`Dictate`,preparing:`Preparing voice input`,recording:`Stop dictation`,transcribing:`Transcribing`},Ax=e=>e===`recording`?(0,Q.jsx)(ce,{size:14,fill:`currentColor`}):e===`idle`?(0,Q.jsx)(R,{size:16}):(0,Q.jsx)(I,{size:16,className:`is-spinning`});function jx({voice:e}){return(0,Q.jsx)(`button`,{type:`button`,tabIndex:-1,"aria-label":kx[e.phase],"aria-pressed":e.phase===`recording`,className:`terminal-voice is-${e.phase}`,...Ox(e.toggle),children:Ax(e.phase)})}function Mx({ctrl:e,onToggleCtrl:t,onBytes:n,voice:r}){return(0,Q.jsxs)(`div`,{className:`terminal-key-bar`,role:`toolbar`,"aria-label":`Terminal keys`,children:[(0,Q.jsx)(`button`,{type:`button`,tabIndex:-1,"aria-pressed":e,className:e?`is-armed`:``,...Ox(t),children:`Ctrl`}),Ex.map(({label:e,key:t,name:r})=>(0,Q.jsx)(`button`,{type:`button`,tabIndex:-1,"aria-label":r??t,...Ox(()=>{let e=Cx({key:t,ctrlKey:!1,altKey:!1});e&&n(e)}),children:e},t)),r?.available&&(0,Q.jsx)(jx,{voice:r})]})}var Nx=`(pointer: coarse)`,Px=120,Fx=350;function Ix(){let e=window.visualViewport;if(!e||!matchMedia(Nx).matches)return()=>{};let t=document.documentElement,n=e.height,r=()=>{t.style.setProperty(`--app-height`,`${e.height}px`),t.style.setProperty(`--app-top`,`${e.offsetTop}px`)},i=()=>{t.style.removeProperty(`--app-height`),t.style.removeProperty(`--app-top`)},a=()=>{n=Math.max(n,e.height,window.innerHeight);let a=n-e.height>Px;a?r():i(),t.toggleAttribute(`data-keyboard-open`,a)};a();let o,s=()=>{clearTimeout(o),o=setTimeout(a,Fx)},c=()=>{n=0,a()};return e.addEventListener(`resize`,a),e.addEventListener(`scroll`,a),window.addEventListener(`orientationchange`,c),window.addEventListener(`focusout`,s),window.addEventListener(`focusin`,s),()=>{clearTimeout(o),window.removeEventListener(`focusout`,s),window.removeEventListener(`focusin`,s),window.removeEventListener(`orientationchange`,c),e.removeEventListener(`resize`,a),e.removeEventListener(`scroll`,a),i(),t.removeAttribute(`data-keyboard-open`)}}function Lx(){return typeof matchMedia==`function`&&matchMedia(Nx).matches}var Rx=100,zx=20,Bx=10,Vx=e=>Bx*(1+Math.min(2,Math.abs(e)/60));function Hx(e,t,n,r){let i=e=>{if(!r()||!e.altKey||e.shiftKey)return;let{element:i,cols:a,rows:o}=t(),s=i?.getBoundingClientRect();if(!s?.width||!s.height)return;let c=Math.floor((e.clientX-s.left)/s.width*a),l=Math.floor((e.clientY-s.top)/s.height*o);if(c<0||l<0||c>=a||l>=o)return;e.preventDefault();let u=e.button===2||e.buttons&2?`right`:e.button===1||e.buttons&4?`middle`:`left`;n()?.mouse(e.type===`pointerdown`?`down`:e.type===`pointerup`?`up`:e.buttons?`drag`:`move`,u,c,l,e.ctrlKey?2:0)},a=0,o=0,s,c=e=>{let{element:n,cols:r,rows:i}=t(),a=n?.getBoundingClientRect();if(a?.width&&a.height)return{column:Math.min(r,Math.max(1,Math.floor((e.clientX-a.left)/a.width*r)+1)),row:Math.min(i,Math.max(1,Math.floor((e.clientY-a.top)/a.height*i)+1))}},l=()=>{let{element:e,rows:n}=t(),r=e?.getBoundingClientRect().height;return r&&n?r/n:zx},u=()=>{o=0;let e=l(),t=Math.trunc(a/e);t&&(a-=t*e,n()?.scroll(t<0?`up`:`down`,Math.min(Rx,Math.abs(t)),s?.column,s?.row))},d=e=>{if(!r()||!e.deltaY)return;s=c(e),e.preventDefault();let t=e.deltaMode===WheelEvent.DOM_DELTA_LINE?e.deltaY*l():e.deltaY;t*a<0&&(a=0),a+=t*Vx(t),o||=requestAnimationFrame(u)};for(let t of[`pointerdown`,`pointerup`,`pointermove`])e.addEventListener(t,i);return e.addEventListener(`wheel`,d,{passive:!1}),()=>{for(let t of[`pointerdown`,`pointerup`,`pointermove`])e.removeEventListener(t,i);e.removeEventListener(`wheel`,d),cancelAnimationFrame(o)}}var Ux=e=>e.target instanceof Element&&!!e.target.closest(`[role="dialog"]`),Wx=`Nothing to attach.`,Gx=e=>e===1?`Attaching file…`:`Attaching ${e} files…`,Kx=e=>e===1?`File attached`:`${e} files attached`;function qx({machineId:e,active:t,writable:n,send:r,show:i}){let[a,o]=(0,l.useState)(!1),s=(0,l.useRef)(r);s.current=r;let c=(0,l.useCallback)(async t=>{if(!t.length){i(Wx,`error`,4e3);return}if(!n.current){i(`Wait until the terminal accepts input, then attach the file again.`,`error`,4e3);return}i(Gx(t.length),`info`);try{s.current(await om(e,t)),i(Kx(t.length),`info`,1500)}catch(e){i(e instanceof Error?e.message:`The file could not be attached.`,`error`,5e3)}},[e,i,n]);return(0,l.useEffect)(()=>{if(!t)return;let e=0,n=t=>{$p(t.dataTransfer)&&!Ux(t)&&(t.preventDefault(),e+=1,o(!0))},r=e=>{$p(e.dataTransfer)&&!Ux(e)&&(e.preventDefault(),e.dataTransfer&&(e.dataTransfer.dropEffect=`copy`))},i=t=>{$p(t.dataTransfer)&&!Ux(t)&&(e=Math.max(0,e-1),e||o(!1))},a=t=>{$p(t.dataTransfer)&&!Ux(t)&&(t.preventDefault(),e=0,o(!1),c(Qp(t.dataTransfer)))};return window.addEventListener(`dragenter`,n),window.addEventListener(`dragover`,r),window.addEventListener(`dragleave`,i),window.addEventListener(`drop`,a),()=>{window.removeEventListener(`dragenter`,n),window.removeEventListener(`dragover`,r),window.removeEventListener(`dragleave`,i),window.removeEventListener(`drop`,a),o(!1)}},[t,c]),{dragging:a,attach:c}}function Jx(e,t){(e.metaKey||e.ctrlKey)&&window.open(t,`_blank`,`noopener,noreferrer`)}function Yx(){let[e,t]=(0,l.useState)(null),n=(0,l.useRef)(void 0),r=(0,l.useCallback)((e,r,i)=>{clearTimeout(n.current),t({text:e,tone:r}),i&&(n.current=setTimeout(()=>t(null),i))},[]);return(0,l.useEffect)(()=>()=>clearTimeout(n.current),[]),{notice:e,show:r}}var Xx=16e3,Zx=`registerProcessor('webr-capture', class extends AudioWorkletProcessor {
2
+ import{a as e,i as t,n,r,t as i}from"./client.CLSsMr2g.js";import{t as a}from"./client.Bbg9OBwT.js";var o=e=>e.replace(/([a-z0-9])([A-Z])/g,`$1-$2`).toLowerCase(),s=(...e)=>e.filter((e,t,n)=>!!e&&e.trim()!==``&&n.indexOf(e)===t).join(` `).trim(),c={xmlns:`http://www.w3.org/2000/svg`,width:24,height:24,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,strokeLinecap:`round`,strokeLinejoin:`round`},l=e(r()),u=(0,l.forwardRef)(({color:e=`currentColor`,size:t=24,strokeWidth:n=2,absoluteStrokeWidth:r,className:i=``,children:a,iconNode:o,...u},d)=>(0,l.createElement)(`svg`,{ref:d,...c,width:t,height:t,stroke:e,strokeWidth:r?Number(n)*24/Number(t):n,className:s(`lucide`,i),...u},[...o.map(([e,t])=>(0,l.createElement)(e,t)),...Array.isArray(a)?a:[a]])),d=(e,t)=>{let n=(0,l.forwardRef)(({className:n,...r},i)=>(0,l.createElement)(u,{ref:i,iconNode:t,className:s(`lucide-${o(e)}`,n),...r}));return n.displayName=`${e}`,n},f=d(`ArchiveRestore`,[[`rect`,{width:`20`,height:`5`,x:`2`,y:`3`,rx:`1`,key:`1wp1u1`}],[`path`,{d:`M4 8v11a2 2 0 0 0 2 2h2`,key:`tvwodi`}],[`path`,{d:`M20 8v11a2 2 0 0 1-2 2h-2`,key:`1gkqxj`}],[`path`,{d:`m9 15 3-3 3 3`,key:`1pd0qc`}],[`path`,{d:`M12 12v9`,key:`192myk`}]]),p=d(`Archive`,[[`rect`,{width:`20`,height:`5`,x:`2`,y:`3`,rx:`1`,key:`1wp1u1`}],[`path`,{d:`M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8`,key:`1s80jp`}],[`path`,{d:`M10 12h4`,key:`a56b0p`}]]),m=d(`ArrowDown`,[[`path`,{d:`M12 5v14`,key:`s699le`}],[`path`,{d:`m19 12-7 7-7-7`,key:`1idqje`}]]),h=d(`ArrowLeft`,[[`path`,{d:`m12 19-7-7 7-7`,key:`1l729n`}],[`path`,{d:`M19 12H5`,key:`x3x0zl`}]]),g=d(`ArrowRight`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`m12 5 7 7-7 7`,key:`xquz4c`}]]),_=d(`ArrowUp`,[[`path`,{d:`m5 12 7-7 7 7`,key:`hav0vg`}],[`path`,{d:`M12 19V5`,key:`x0mq9r`}]]),v=d(`Bot`,[[`path`,{d:`M12 8V4H8`,key:`hb8ula`}],[`rect`,{width:`16`,height:`12`,x:`4`,y:`8`,rx:`2`,key:`enze0r`}],[`path`,{d:`M2 14h2`,key:`vft8re`}],[`path`,{d:`M20 14h2`,key:`4cs60a`}],[`path`,{d:`M15 13v2`,key:`1xurst`}],[`path`,{d:`M9 13v2`,key:`rq6x2g`}]]),y=d(`Check`,[[`path`,{d:`M20 6 9 17l-5-5`,key:`1gmf2c`}]]),b=d(`ChevronDown`,[[`path`,{d:`m6 9 6 6 6-6`,key:`qrunsl`}]]),x=d(`ChevronRight`,[[`path`,{d:`m9 18 6-6-6-6`,key:`mthhwq`}]]),S=d(`CircleAlert`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`line`,{x1:`12`,x2:`12`,y1:`8`,y2:`12`,key:`1pkeuh`}],[`line`,{x1:`12`,x2:`12.01`,y1:`16`,y2:`16`,key:`4dfq90`}]]),C=d(`CircleCheck`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m9 12 2 2 4-4`,key:`dzmm74`}]]),w=d(`CircleHelp`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3`,key:`1u773s`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),T=d(`Circle`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]),E=d(`Command`,[[`path`,{d:`M15 6v12a3 3 0 1 0 3-3H6a3 3 0 1 0 3 3V6a3 3 0 1 0-3 3h12a3 3 0 1 0-3-3`,key:`11bfej`}]]),D=d(`Copy`,[[`rect`,{width:`14`,height:`14`,x:`8`,y:`8`,rx:`2`,ry:`2`,key:`17jyea`}],[`path`,{d:`M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2`,key:`zix9uf`}]]),O=d(`Cpu`,[[`rect`,{width:`16`,height:`16`,x:`4`,y:`4`,rx:`2`,key:`14l7u7`}],[`rect`,{width:`6`,height:`6`,x:`9`,y:`9`,rx:`1`,key:`5aljv4`}],[`path`,{d:`M15 2v2`,key:`13l42r`}],[`path`,{d:`M15 20v2`,key:`15mkzm`}],[`path`,{d:`M2 15h2`,key:`1gxd5l`}],[`path`,{d:`M2 9h2`,key:`1bbxkp`}],[`path`,{d:`M20 15h2`,key:`19e6y8`}],[`path`,{d:`M20 9h2`,key:`19tzq7`}],[`path`,{d:`M9 2v2`,key:`165o2o`}],[`path`,{d:`M9 20v2`,key:`i2bqo8`}]]),k=d(`FileText`,[[`path`,{d:`M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z`,key:`1rqfz7`}],[`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`,key:`tnqrlb`}],[`path`,{d:`M10 9H8`,key:`b1mrlr`}],[`path`,{d:`M16 13H8`,key:`t4e002`}],[`path`,{d:`M16 17H8`,key:`z1uh3a`}]]),A=d(`FolderTree`,[[`path`,{d:`M20 10a1 1 0 0 0 1-1V6a1 1 0 0 0-1-1h-2.5a1 1 0 0 1-.8-.4l-.9-1.2A1 1 0 0 0 15 3h-2a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1Z`,key:`hod4my`}],[`path`,{d:`M20 21a1 1 0 0 0 1-1v-3a1 1 0 0 0-1-1h-2.9a1 1 0 0 1-.88-.55l-.42-.85a1 1 0 0 0-.92-.6H13a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1Z`,key:`w4yl2u`}],[`path`,{d:`M3 5a2 2 0 0 0 2 2h3`,key:`f2jnh7`}],[`path`,{d:`M3 3v13a2 2 0 0 0 2 2h3`,key:`k8epm1`}]]),j=d(`Folder`,[[`path`,{d:`M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z`,key:`1kt360`}]]);d(`Gauge`,[[`path`,{d:`m12 14 4-4`,key:`9kzdfg`}],[`path`,{d:`M3.34 19a10 10 0 1 1 17.32 0`,key:`19p75a`}]]);var M=d(`GitBranch`,[[`line`,{x1:`6`,x2:`6`,y1:`3`,y2:`15`,key:`17qcm7`}],[`circle`,{cx:`18`,cy:`6`,r:`3`,key:`1h7g24`}],[`circle`,{cx:`6`,cy:`18`,r:`3`,key:`fqmcym`}],[`path`,{d:`M18 9a9 9 0 0 1-9 9`,key:`n2h4wq`}]]),N=d(`ImagePlus`,[[`path`,{d:`M16 5h6`,key:`1vod17`}],[`path`,{d:`M19 2v6`,key:`4bpg5p`}],[`path`,{d:`M21 11.5V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h7.5`,key:`1ue2ih`}],[`path`,{d:`m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21`,key:`1xmnt7`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}]]),P=d(`ImageUp`,[[`path`,{d:`M10.3 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2v10l-3.1-3.1a2 2 0 0 0-2.814.014L6 21`,key:`9csbqa`}],[`path`,{d:`m14 19.5 3-3 3 3`,key:`9vmjn0`}],[`path`,{d:`M17 22v-5.5`,key:`1aa6fl`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}]]),F=d(`LayoutList`,[[`rect`,{width:`7`,height:`7`,x:`3`,y:`3`,rx:`1`,key:`1g98yp`}],[`rect`,{width:`7`,height:`7`,x:`3`,y:`14`,rx:`1`,key:`1bb6yr`}],[`path`,{d:`M14 4h7`,key:`3xa0d5`}],[`path`,{d:`M14 9h7`,key:`1icrd9`}],[`path`,{d:`M14 15h7`,key:`1mj8o2`}],[`path`,{d:`M14 20h7`,key:`11slyb`}]]),I=d(`LoaderCircle`,[[`path`,{d:`M21 12a9 9 0 1 1-6.219-8.56`,key:`13zald`}]]),L=d(`MessageCircleQuestion`,[[`path`,{d:`M7.9 20A9 9 0 1 0 4 16.1L2 22Z`,key:`vv11sd`}],[`path`,{d:`M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3`,key:`1u773s`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),R=d(`Mic`,[[`path`,{d:`M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3Z`,key:`131961`}],[`path`,{d:`M19 10v2a7 7 0 0 1-14 0v-2`,key:`1vc78b`}],[`line`,{x1:`12`,x2:`12`,y1:`19`,y2:`22`,key:`x3vr5v`}]]),z=d(`Monitor`,[[`rect`,{width:`20`,height:`14`,x:`2`,y:`3`,rx:`2`,key:`48i651`}],[`line`,{x1:`8`,x2:`16`,y1:`21`,y2:`21`,key:`1svkeh`}],[`line`,{x1:`12`,x2:`12`,y1:`17`,y2:`21`,key:`vw1qmm`}]]),ee=d(`Moon`,[[`path`,{d:`M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z`,key:`a7tn18`}]]),B=d(`PanelLeftClose`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 3v18`,key:`fh3hqa`}],[`path`,{d:`m16 15-3-3 3-3`,key:`14y99z`}]]),te=d(`PanelLeftOpen`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 3v18`,key:`fh3hqa`}],[`path`,{d:`m14 9 3 3-3 3`,key:`8010ee`}]]),ne=d(`PanelLeft`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 3v18`,key:`fh3hqa`}]]),re=d(`Pencil`,[[`path`,{d:`M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z`,key:`1a8usu`}],[`path`,{d:`m15 5 4 4`,key:`1mk7zo`}]]),V=d(`Plus`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`M12 5v14`,key:`s699le`}]]),H=d(`Search`,[[`circle`,{cx:`11`,cy:`11`,r:`8`,key:`4ej97u`}],[`path`,{d:`m21 21-4.3-4.3`,key:`1qie3q`}]]),ie=d(`Server`,[[`rect`,{width:`20`,height:`8`,x:`2`,y:`2`,rx:`2`,ry:`2`,key:`ngkwjq`}],[`rect`,{width:`20`,height:`8`,x:`2`,y:`14`,rx:`2`,ry:`2`,key:`iecqi9`}],[`line`,{x1:`6`,x2:`6.01`,y1:`6`,y2:`6`,key:`16zg32`}],[`line`,{x1:`6`,x2:`6.01`,y1:`18`,y2:`18`,key:`nzw8ys`}]]),ae=d(`Settings2`,[[`path`,{d:`M20 7h-9`,key:`3s1dr2`}],[`path`,{d:`M14 17H5`,key:`gfn3mx`}],[`circle`,{cx:`17`,cy:`17`,r:`3`,key:`18b49y`}],[`circle`,{cx:`7`,cy:`7`,r:`3`,key:`dfmy0x`}]]),oe=d(`SquarePen`,[[`path`,{d:`M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7`,key:`1m0v6g`}],[`path`,{d:`M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z`,key:`ohrbg2`}]]),se=d(`SquareTerminal`,[[`path`,{d:`m7 11 2-2-2-2`,key:`1lz0vl`}],[`path`,{d:`M11 13h4`,key:`1p7l4v`}],[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,ry:`2`,key:`1m3agn`}]]),ce=d(`Square`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]),le=d(`Sun`,[[`circle`,{cx:`12`,cy:`12`,r:`4`,key:`4exip2`}],[`path`,{d:`M12 2v2`,key:`tus03m`}],[`path`,{d:`M12 20v2`,key:`1lh1kg`}],[`path`,{d:`m4.93 4.93 1.41 1.41`,key:`149t6j`}],[`path`,{d:`m17.66 17.66 1.41 1.41`,key:`ptbguv`}],[`path`,{d:`M2 12h2`,key:`1t8f8n`}],[`path`,{d:`M20 12h2`,key:`1q8mjw`}],[`path`,{d:`m6.34 17.66-1.41 1.41`,key:`1m8zz5`}],[`path`,{d:`m19.07 4.93-1.41 1.41`,key:`1shlcs`}]]),ue=d(`Trash2`,[[`path`,{d:`M3 6h18`,key:`d0wm0j`}],[`path`,{d:`M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6`,key:`4alrt4`}],[`path`,{d:`M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2`,key:`v07s0e`}],[`line`,{x1:`10`,x2:`10`,y1:`11`,y2:`17`,key:`1uufr5`}],[`line`,{x1:`14`,x2:`14`,y1:`11`,y2:`17`,key:`xtxkd`}]]),de=d(`TriangleAlert`,[[`path`,{d:`m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3`,key:`wmoenq`}],[`path`,{d:`M12 9v4`,key:`juzpu7`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),fe=d(`X`,[[`path`,{d:`M18 6 6 18`,key:`1bl5f8`}],[`path`,{d:`m6 6 12 12`,key:`d8bk6v`}]]),U=typeof document<`u`?l.useLayoutEffect:()=>{};function pe(){return typeof window<`u`}function W(e){return ge(e)?(e.nodeName||``).toLowerCase():`#document`}function me(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function he(e){return((ge(e)?e.ownerDocument:e.document)||window.document)?.documentElement}function ge(e){return pe()?e instanceof Node||e instanceof me(e).Node:!1}function G(e){return pe()?e instanceof Element||e instanceof me(e).Element:!1}function K(e){return pe()?e instanceof HTMLElement||e instanceof me(e).HTMLElement:!1}function _e(e){return!pe()||typeof ShadowRoot>`u`?!1:e instanceof ShadowRoot||e instanceof me(e).ShadowRoot}function ve(e){let{overflow:t,overflowX:n,overflowY:r,display:i}=ke(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&i!==`inline`&&i!==`contents`}function ye(e){return/^(table|td|th)$/.test(W(e))}function be(e){try{if(e.matches(`:popover-open`))return!0}catch{}try{return e.matches(`:modal`)}catch{return!1}}var xe=/transform|translate|scale|rotate|perspective|filter/,Se=/paint|layout|strict|content/,Ce=e=>!!e&&e!==`none`,we;function Te(e){let t=G(e)?ke(e):e;return Ce(t.transform)||Ce(t.translate)||Ce(t.scale)||Ce(t.rotate)||Ce(t.perspective)||!De()&&(Ce(t.backdropFilter)||Ce(t.filter))||xe.test(t.willChange||``)||Se.test(t.contain||``)}function Ee(e){let t=je(e);for(;K(t)&&!Oe(t);){if(Te(t))return t;if(be(t))return null;t=je(t)}return null}function De(){return we??=typeof CSS<`u`&&CSS.supports&&CSS.supports(`-webkit-backdrop-filter`,`none`),we}function Oe(e){return/^(html|body|#document)$/.test(W(e))}function ke(e){return me(e).getComputedStyle(e)}function Ae(e){return G(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function je(e){if(W(e)===`html`)return e;let t=e.assignedSlot||e.parentNode||_e(e)&&e.host||he(e);return _e(t)?t.host:t}function Me(e){let t=je(e);return Oe(t)?(e.ownerDocument||e).body:K(t)&&ve(t)?t:Me(t)}function Ne(e,t,n){t===void 0&&(t=[]),n===void 0&&(n=!0);let r=Me(e),i=r===e.ownerDocument?.body,a=me(r);if(i){let e=Pe(a);return t.concat(a,a.visualViewport||[],ve(r)?r:[],e&&n?Ne(e):[])}return t.concat(r,Ne(r,[],n))}function Pe(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function q(e,t,n,r){return e.addEventListener(t,n,r),()=>{e.removeEventListener(t,n,r)}}function Fe(){return typeof navigator>`u`?{userAgent:``,platform:``,maxTouchPoints:0}:{userAgent:navigator.userAgent,platform:navigator.platform??``,maxTouchPoints:navigator.maxTouchPoints??0}}var{userAgent:Ie,platform:Le,maxTouchPoints:Re}=Fe(),ze=Ie.toLowerCase(),Be=Le.toLowerCase(),Ve=/^i(os$|p)/.test(Be)||Be===`macintel`&&Re>1,He=`android`,Ue=Be===He||ze.includes(He),We=!Ve&&Be.startsWith(`mac`);Be.startsWith(`win`),!Ue&&/^(linux|chrome os)/.test(Be);var Ge=We||Ve,Ke=typeof CSS<`u`&&!!CSS.supports?.(`-webkit-backdrop-filter:none`),qe=!Ke&&ze.includes(`firefox`);!Ke&&ze.includes(`chrom`);var Je=Ge,Ye=/jsdom|happydom/.test(ze);function J(e){return e?.ownerDocument||document}var Xe={};function Ze(e,t){let n=l.useRef(Xe);return n.current===Xe&&(n.current=e(t)),n}function Qe(){}var $e=Object.freeze([]),et=Object.freeze({});function tt(e){l.useEffect(e,$e)}var nt=0,rt=class e{static create(){return new e}currentId=nt;start(e,t){this.clear(),this.currentId=setTimeout(()=>{this.currentId=nt,t()},e)}isStarted(){return this.currentId!==nt}clear=()=>{this.currentId!==nt&&(clearTimeout(this.currentId),this.currentId=nt)};disposeEffect=()=>this.clear};function it(){let e=Ze(rt.create).current;return tt(e.disposeEffect),e}var at=null;globalThis.requestAnimationFrame;var ot=new class{callbacks=[];callbacksCount=0;nextId=1;startId=1;isScheduled=!1;tick=e=>{this.isScheduled=!1;let t=this.callbacks,n=this.callbacksCount;if(this.callbacks=[],this.callbacksCount=0,this.startId=this.nextId,n>0)for(let n=0;n<t.length;n+=1)t[n]?.(e)};request(e){let t=this.nextId;return this.nextId+=1,this.callbacks.push(e),this.callbacksCount+=1,this.isScheduled||=(requestAnimationFrame(this.tick),!0),t}cancel(e){let t=e-this.startId;t<0||t>=this.callbacks.length||this.callbacks[t]!==null&&(this.callbacks[t]=null,--this.callbacksCount)}},st=class e{static create(){return new e}static request(e){return ot.request(e)}static cancel(e){return ot.cancel(e)}currentId=at;request(e){this.cancel(),this.currentId=ot.request(()=>{this.currentId=at,e()})}cancel=()=>{this.currentId!==at&&(ot.cancel(this.currentId),this.currentId=at)};disposeEffect=()=>this.cancel};function ct(){let e=Ze(st.create).current;return tt(e.disposeEffect),e}var lt={},ut={},dt=``;function Y(e,t){return ve(e)?e:t}function ft(e,t,n){return/hidden|clip/.test(e.getComputedStyle(Y(t,n)).overflowY)}function pt(e){if(typeof document>`u`)return!1;let t=J(e);return me(t).innerWidth-t.documentElement.clientWidth>0}function mt(e){if(!(typeof CSS<`u`&&CSS.supports&&CSS.supports(`scrollbar-gutter`,`stable`))||typeof document>`u`)return!1;let t=J(e),n=t.documentElement,r=t.body,i=Y(n,r),a=i.style.overflowY,o=n.style.scrollbarGutter;n.style.scrollbarGutter=`stable`,i.style.overflowY=`scroll`;let s=i.offsetWidth;i.style.overflowY=`hidden`;let c=i.offsetWidth;return i.style.overflowY=a,n.style.scrollbarGutter=o,s===c}function ht(e){let t=J(e),n=t.documentElement,r=t.body,i=Y(n,r),a={overflowY:i.style.overflowY,overflowX:i.style.overflowX};return Object.assign(i.style,{overflowY:`hidden`,overflowX:`hidden`}),()=>{Object.assign(i.style,a)}}function gt(e){let t=J(e),n=t.documentElement,r=t.body,i=me(n),a=0,o=0,s=!1,c=st.create();if(Ke&&(i.visualViewport?.scale??1)!==1)return()=>{};function l(){let t=i.getComputedStyle(n),c=i.getComputedStyle(r),l=(t.scrollbarGutter||``).includes(`both-edges`)?`stable both-edges`:`stable`;a=n.scrollTop,o=n.scrollLeft,lt={scrollbarGutter:n.style.scrollbarGutter,overflowY:n.style.overflowY,overflowX:n.style.overflowX},dt=n.style.scrollBehavior,ut={position:r.style.position,height:r.style.height,width:r.style.width,boxSizing:r.style.boxSizing,overflowY:r.style.overflowY,overflowX:r.style.overflowX,scrollBehavior:r.style.scrollBehavior};let u=n.scrollHeight>n.clientHeight,d=n.scrollWidth>n.clientWidth,f=t.overflowY===`scroll`||c.overflowY===`scroll`,p=t.overflowX===`scroll`||c.overflowX===`scroll`,m=Math.max(0,i.innerWidth-r.clientWidth),h=Math.max(0,i.innerHeight-r.clientHeight),g=parseFloat(c.marginTop)+parseFloat(c.marginBottom),_=parseFloat(c.marginLeft)+parseFloat(c.marginRight),v=Y(n,r);if(s=mt(e),s){n.style.scrollbarGutter=l,v.style.overflowY=`hidden`,v.style.overflowX=`hidden`;return}Object.assign(n.style,{scrollbarGutter:l,overflowY:`hidden`,overflowX:`hidden`}),(u||f)&&(n.style.overflowY=`scroll`),(d||p)&&(n.style.overflowX=`scroll`),Object.assign(r.style,{position:`relative`,height:g||h?`calc(100dvh - ${g+h}px)`:`100dvh`,width:_||m?`calc(100vw - ${_+m}px)`:`100vw`,boxSizing:`border-box`,overflowY:`hidden`,overflowX:`hidden`,scrollBehavior:`unset`}),r.scrollTop=a,r.scrollLeft=o,n.setAttribute(`data-base-ui-scroll-locked`,``),n.style.scrollBehavior=`unset`}function u(){Object.assign(n.style,lt),Object.assign(r.style,ut),s||(n.scrollTop=a,n.scrollLeft=o,n.removeAttribute(`data-base-ui-scroll-locked`),n.style.scrollBehavior=dt)}function d(){u(),c.request(l)}l();let f=q(i,`resize`,d);return()=>{c.cancel(),u(),typeof i.removeEventListener==`function`&&f()}}var _t=new class{lockCount=0;restore=null;timeoutLock=rt.create();timeoutUnlock=rt.create();acquire(e){return this.lockCount+=1,this.lockCount===1&&this.restore===null&&this.timeoutLock.start(0,()=>this.lock(e)),this.release}release=()=>{--this.lockCount,this.lockCount===0&&this.restore&&this.timeoutUnlock.start(0,this.unlock)};unlock=()=>{this.lockCount===0&&this.restore&&(this.restore?.(),this.restore=null)};lock(e){if(this.lockCount===0||this.restore!==null)return;let t=J(e),n=t.documentElement,r=t.body,i=me(n);if(ft(i,n,r)){let t=new i.MutationObserver(()=>{ft(i,n,r)||(t.disconnect(),this.restore=null,this.lock(e))}),a={attributes:!0};t.observe(n,a),t.observe(r,a),this.restore=()=>t.disconnect();return}let a=Ve||!pt(e);this.restore=a?ht(e):gt(e)}};function vt(e=!0,t=null){U(()=>{if(e)return _t.acquire(t)},[e,t])}function yt(e){e.preventDefault(),e.stopPropagation()}function bt(e){return`nativeEvent`in e}function xt(e){return e.pointerType===``&&e.isTrusted?!0:Ue&&e.pointerType?e.type===`click`&&e.buttons===1:e.detail===0&&!e.pointerType}function St(e){return Ye?!1:!Ue&&e.width===0&&e.height===0||Ue&&e.width===1&&e.height===1&&e.pressure===0&&e.detail===0&&e.pointerType===`mouse`||e.width<1&&e.height<1&&e.pressure===0&&e.detail===0&&e.pointerType===`touch`}function Ct(e,t){let n=[`mouse`,`pen`];return t||n.push(``,void 0),n.includes(e)}function wt(e){let t=e.type;return t===`click`||t===`mousedown`||t===`keydown`||t===`keyup`}function Tt(e){let t=e.activeElement;for(;t?.shadowRoot?.activeElement!=null;)t=t.shadowRoot.activeElement;return t}function X(e,t){if(!e||!t)return!1;let n=t.getRootNode?.();if(e.contains(t))return!0;if(n&&_e(n)){let n=t;for(;n;){if(e===n)return!0;n=n.parentNode||n.host}}return!1}function Et(e){return`composedPath`in e?e.composedPath()[0]??e.target:e.target}var Dt=`data-base-ui-focusable`,Ot=`input:not([type='hidden']):not([disabled]),[contenteditable]:not([contenteditable='false']),textarea:not([disabled])`,kt=`ArrowLeft`,At=`ArrowRight`,jt=`ArrowUp`,Mt=`ArrowDown`,Nt=`data-starting-style`,Pt=`data-ending-style`,Ft={[Nt]:``},It={[Pt]:``},Lt={transitionStatus(e){return e===`starting`?Ft:e===`ending`?It:null}},Rt=`data-open`,zt=`data-closed`,Bt=`data-anchor-hidden`,Vt=`data-popup-open`,Ht=`data-pressed`,Ut={[Vt]:``},Wt={[Vt]:``,[Ht]:``},Gt={[Rt]:``},Kt={[zt]:``},qt={[Bt]:``},Jt={open(e){return e?Ut:null}},Yt={open(e){return e?Wt:null}},Xt={open(e){return e?Gt:Kt},anchorHidden(e){return e?qt:null}},Zt={...Xt,...Lt},Qt=`data-trigger-disabled`;function $t(e,t){if(!G(e))return!1;let n=e;if(t.hasElement(n))return!n.hasAttribute(Qt);for(let[,e]of t.entries())if(X(e,n))return!e.hasAttribute(Qt);return!1}function en(e,t){if(t==null)return!1;if(`composedPath`in e)return e.composedPath().includes(t);let n=e;return n.target!=null&&t.contains(n.target)}function tn(e){return e.matches(`html,body`)}function nn(e){return K(e)&&e.matches(`input:not([type='hidden']):not([disabled]),[contenteditable]:not([contenteditable='false']),textarea:not([disabled])`)}function rn(e){return e?.closest(`button,a[href],[role="button"],select,[tabindex]:not([tabindex="-1"]),${Ot}`)!=null}function an(e){return e?e.getAttribute(`role`)===`combobox`&&nn(e):!1}function on(e){if(!e||Ye)return!0;try{return e.matches(`:focus-visible`)}catch{return!0}}function sn(e){return e?e.hasAttribute(`data-base-ui-focusable`)?e:e.querySelector(`[data-base-ui-focusable]`)||e:null}function cn(e,t){return t!=null&&!Ct(t)?0:typeof e==`function`?e():e}function ln(e,t,n){let r=cn(e,n);return typeof r==`number`?r:r?.[t]}function un(e){return typeof e==`function`?e():e}function dn(e,t){return t||e===`click`||e===`mousedown`}function fn(e){return e?.includes(`mouse`)&&e!==`mousedown`}var pn=`none`,mn=`trigger-press`,hn=`trigger-hover`,gn=`trigger-focus`,_n=`outside-press`,vn=`item-press`,yn=`close-press`,bn=`input-change`,xn=`input-clear`,Sn=`input-press`,Cn=`focus-out`,wn=`escape-key`,Tn=`list-navigation`,En=`keyboard`,Dn=`pointer`,On=`cancel-open`,kn=`sibling-open`,An=`disabled`,jn=`imperative-action`;function Z(e,t,n,r){let i=!1,a=!1,o=r??et;return{reason:e,event:t??new Event(`base-ui`),cancel(){i=!0},allowPropagation(){a=!0},get isCanceled(){return i},get isPropagationAllowed(){return a},trigger:n,...o}}function Mn(e,t,n){let r=n??et;return{reason:e,event:t??new Event(`base-ui`),...r}}var Nn=t((e=>{var t=Symbol.for(`react.transitional.element`),n=Symbol.for(`react.fragment`);function r(e,n,r){var i=null;if(r!==void 0&&(i=``+r),n.key!==void 0&&(i=``+n.key),`key`in n)for(var a in r={},n)a!==`key`&&(r[a]=n[a]);else r=n;return n=r.ref,{$$typeof:t,type:e,key:i,ref:n===void 0?null:n,props:r}}e.Fragment=n,e.jsx=r,e.jsxs=r})),Q=t(((e,t)=>{t.exports=Nn()}))(),Pn=l.createContext({hasProvider:!1,timeoutMs:0,delayRef:{current:0},initialDelayRef:{current:0},timeout:new rt,currentIdRef:{current:null},currentContextRef:{current:null}});function Fn(e,t){e.current=t.current}function In(e,t={open:!1}){let{open:n}=t,r=`rootStore`in e?e.rootStore:e,i=r.useState(`floatingId`),{currentIdRef:a,delayRef:o,timeoutMs:s,initialDelayRef:c,currentContextRef:u,hasProvider:d,timeout:f}=l.useContext(Pn),[p,m]=l.useState(!1),h=l.useRef(n);return U(()=>{h.current=n},[n]),U(()=>{function e(){u.current?.setIsInstantPhase(!1),a.current=null,u.current=null,o.current=c.current,f.clear()}if(a.current&&!n&&a.current===i){if(m(!1),s){let t=i;return f.start(s,()=>{r.select(`open`)||a.current&&a.current!==t||e()}),()=>{(h.current||a.current!==t)&&f.clear()}}e()}},[n,i,a,o,s,c,u,f,r]),U(()=>{if(!n)return;let e=u.current,t=a.current;f.clear(),u.current={onOpenChange:r.setOpen,setIsInstantPhase:m},a.current=i,o.current={open:0,close:ln(c.current,`close`)},t!==null&&t!==i?(m(!0),e?.setIsInstantPhase(!0),e?.onOpenChange(!1,Z(pn))):(m(!1),e?.setIsInstantPhase(!1))},[n,i,r,a,o,c,u,f]),U(()=>()=>{if(a.current===i){if(u.current=null,!h.current)return;a.current=null,Fn(o,c),f.clear()}},[u,a,o,i,c,f]),l.useMemo(()=>({activeIdRef:a,hasProvider:d,delayRef:o,isInstantPhase:p}),[a,d,o,p])}function Ln(...e){return()=>{for(let t=0;t<e.length;t+=1){let n=e[t];n&&n()}}}function Rn(e,t,n,r){let i=Ze(Bn).current;return Vn(i,e,t,n,r)&&Un(i,[e,t,n,r]),i.callback}function zn(e){let t=Ze(Bn).current;return Hn(t,e)&&Un(t,e),t.callback}function Bn(){return{callback:null,cleanup:null,refs:[]}}function Vn(e,t,n,r,i){return e.refs[0]!==t||e.refs[1]!==n||e.refs[2]!==r||e.refs[3]!==i}function Hn(e,t){return e.refs.length!==t.length||e.refs.some((e,n)=>e!==t[n])}function Un(e,t){if(e.refs=t,t.every(e=>e==null)){e.callback=null;return}e.callback=n=>{if(e.cleanup&&=(e.cleanup(),null),n!=null){let r=Array(t.length).fill(null);for(let e=0;e<t.length;e+=1){let i=t[e];if(i!=null)switch(typeof i){case`function`:{let t=i(n);typeof t==`function`&&(r[e]=t);break}case`object`:i.current=n}}e.cleanup=()=>{for(let e=0;e<t.length;e+=1){let n=t[e];if(n!=null)switch(typeof n){case`function`:{let t=r[e];typeof t==`function`?t():n(null);break}case`object`:n.current=null}}}}}}function Wn(e){let t=Ze(Gn,e).current;return t.next=e,U(t.effect),t}function Gn(e){let t={current:e,next:e,effect:()=>{t.current=t.next}};return t}var Kn={...l},qn=Kn.useInsertionEffect,Jn=qn&&qn!==Kn.useLayoutEffect?qn:e=>e();function $(e){let t=Ze(Yn).current;return t.next=e,Jn(t.effect),t.trampoline}function Yn(){let e={next:void 0,callback:Xn,trampoline:(...t)=>e.callback?.(...t),effect:()=>{e.callback=e.next}};return e}function Xn(){}var Zn={clipPath:`inset(50%)`,overflow:`hidden`,whiteSpace:`nowrap`,border:0,padding:0,width:1,height:1,margin:-1},Qn={...Zn,position:`fixed`,top:0,left:0},$n={...Zn,position:`absolute`},er=l.forwardRef(function(e,t){let[n,r]=l.useState();U(()=>{Je&&Ke&&r(`button`)},[]);let i={tabIndex:0,role:n};return(0,Q.jsx)(`span`,{...e,ref:t,style:Qn,"aria-hidden":!n||void 0,...i,"data-base-ui-focus-guard":``})}),tr=Math.min,nr=Math.max,rr=Math.round,ir=Math.floor,ar=e=>({x:e,y:e}),or={left:`right`,right:`left`,bottom:`top`,top:`bottom`};function sr(e,t,n){return nr(e,tr(t,n))}function cr(e,t){return typeof e==`function`?e(t):e}function lr(e){return e.split(`-`)[0]}function ur(e){return e.split(`-`)[1]}function dr(e){return e===`x`?`y`:`x`}function fr(e){return e===`y`?`height`:`width`}function pr(e){let t=e[0];return t===`t`||t===`b`?`y`:`x`}function mr(e){return dr(pr(e))}function hr(e,t,n){n===void 0&&(n=!1);let r=ur(e),i=mr(e),a=fr(i),o=i===`x`?r===(n?`end`:`start`)?`right`:`left`:r===`start`?`bottom`:`top`;return t.reference[a]>t.floating[a]&&(o=wr(o)),[o,wr(o)]}function gr(e){let t=wr(e);return[_r(e),t,_r(t)]}function _r(e){return e.includes(`start`)?e.replace(`start`,`end`):e.replace(`end`,`start`)}var vr=[`left`,`right`],yr=[`right`,`left`],br=[`top`,`bottom`],xr=[`bottom`,`top`];function Sr(e,t,n){switch(e){case`top`:case`bottom`:return n?t?yr:vr:t?vr:yr;case`left`:case`right`:return t?br:xr;default:return[]}}function Cr(e,t,n,r){let i=ur(e),a=Sr(lr(e),n===`start`,r);return i&&(a=a.map(e=>e+`-`+i),t&&(a=a.concat(a.map(_r)))),a}function wr(e){let t=lr(e);return or[t]+e.slice(t.length)}function Tr(e){return{top:e.top??0,right:e.right??0,bottom:e.bottom??0,left:e.left??0}}function Er(e){return typeof e==`number`?{top:e,right:e,bottom:e,left:e}:Tr(e)}function Dr(e){let{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 Or(e,t,n){return Math.floor(e/t)!==n}function kr(e,t){return t<0||t>=e.length}function Ar(e,t){return Mr(e.current,{disabledIndices:t})}function jr(e,t){return Mr(e.current,{decrement:!0,startingIndex:e.current.length,disabledIndices:t})}function Mr(e,{startingIndex:t=-1,decrement:n=!1,disabledIndices:r,amount:i=1}={}){let a=t;do a+=n?-i:i;while(a>=0&&a<=e.length-1&&Pr(e,a,r));return a}function Nr(e,{event:t,orientation:n,loopFocus:r,onLoop:i,rtl:a,cols:o,disabledIndices:s,minIndex:c,maxIndex:l,prevIndex:u,stopEvent:d=!1}){let f=u,p;if(t.key===`ArrowUp`?p=`up`:t.key===`ArrowDown`&&(p=`down`),p){let n=[],a=[],m=!1,h=0;{let t=null,r=-1;e.forEach((e,i)=>{if(e==null)return;h+=1;let o=e.closest(`[role="row"]`);o&&(m=!0),(o!==t||r===-1)&&(t=o,r+=1,n[r]=[]),n[r].push(i),a[i]=r})}let g=!1,_=0;if(m)for(let e of n){let t=e.length;t>_&&(_=t),t!==o&&(g=!0)}let v=g&&h<e.length,y=_||o,b=o=>{if(!g||u===-1)return;let c=a[u];if(c==null)return;let l=n[c].indexOf(u),d=o===`up`?-1:1;for(let o=c+d,f=0;f<n.length;f+=1,o+=d){if(o<0||o>=n.length){if(!r||v)return;if(o=o<0?n.length-1:0,i){let e=Math.min(l,n[o].length-1),r=i(t,u,n[o][e]??n[o][0]);o=a[r]??o}}let c=n[o];for(let t=Math.min(l,c.length-1);t>=0;--t){let n=c[t];if(!Pr(e,n,s))return n}}},x=t=>{if(!v||u===-1)return;let n=u%y,i=t===`up`?-y:y,a=l-l%y,o=ir(l/y)+1;for(let t=u-n+i,c=0;c<o;c+=1,t+=i){if(t<0||t>l){if(!r)return;t=t<0?a:0}let i=Math.min(t+y-1,l);for(let r=Math.min(t+n,i);r>=t;--r)if(!Pr(e,r,s))return r}};d&&yt(t);let S=b(p)??x(p);if(S!==void 0)f=S;else if(u===-1)f=p===`up`?l:c;else if(f=Mr(e,{startingIndex:u,amount:y,decrement:p===`up`,disabledIndices:s}),r){if(p===`up`&&(u-y<c||f<0)){let e=u%y,n=l%y,r=l-(n-e);f=n===e?l:n>e?r:r-y,i&&(f=i(t,u,f))}p===`down`&&u+y>l&&(f=Mr(e,{startingIndex:u%y-y,amount:y,disabledIndices:s}),i&&(f=i(t,u,f)))}kr(e,f)&&(f=u)}if(n===`both`){let n=ir(u/o);t.key===(a?`ArrowLeft`:`ArrowRight`)&&(d&&yt(t),u%o===o-1?r&&(f=Mr(e,{startingIndex:u-u%o-1,disabledIndices:s}),i&&(f=i(t,u,f))):(f=Mr(e,{startingIndex:u,disabledIndices:s}),r&&Or(f,o,n)&&(f=Mr(e,{startingIndex:u-u%o-1,disabledIndices:s}),i&&(f=i(t,u,f)))),Or(f,o,n)&&(f=u)),t.key===(a?`ArrowRight`:`ArrowLeft`)&&(d&&yt(t),u%o===0?r&&(f=Mr(e,{startingIndex:u+(o-u%o),decrement:!0,disabledIndices:s}),i&&(f=i(t,u,f))):(f=Mr(e,{startingIndex:u,decrement:!0,disabledIndices:s}),r&&Or(f,o,n)&&(f=Mr(e,{startingIndex:u+(o-u%o),decrement:!0,disabledIndices:s}),i&&(f=i(t,u,f)))),Or(f,o,n)&&(f=u));let c=ir(l/o)===n;kr(e,f)&&(r&&c?(f=t.key===(a?`ArrowRight`:`ArrowLeft`)?l:Mr(e,{startingIndex:u-u%o-1,disabledIndices:s}),i&&(f=i(t,u,f))):f=u)}return f}function Pr(e,t,n){if(typeof n==`function`?n(t):n?.includes(t)??!1)return!0;let r=e[t];return r?!Ir(r)||r.matches(`:disabled`)?!0:!n&&(r.hasAttribute(`disabled`)||r.getAttribute(`aria-disabled`)===`true`):!1}function Fr(e){return e.visibility===`hidden`||e.visibility===`collapse`}function Ir(e,t=e?ke(e):null){return!e||!e.isConnected||!t||Fr(t)?!1:typeof e.checkVisibility==`function`?e.checkVisibility():t.display!==`none`&&t.display!==`contents`}var Lr=`a[href],button,input,select,textarea,summary,details,iframe,object,embed,[tabindex],[contenteditable]:not([contenteditable="false"]),audio[controls],video[controls]`;function Rr(e){let t=e.assignedSlot;if(t)return t;if(e.parentElement)return e.parentElement;let n=e.getRootNode();return _e(n)?n.host:null}function zr(e){for(let t of Array.from(e.children))if(W(t)===`summary`)return t;return null}function Br(e,t){let n=zr(t);return!!n&&(e===n||X(n,e))}function Vr(e){let t=e?W(e):``;return e!=null&&e.matches(Lr)&&(t!==`summary`||e.parentElement!=null&&W(e.parentElement)===`details`&&zr(e.parentElement)===e)&&(t!==`details`||zr(e)==null)&&(t!==`input`||e.type!==`hidden`)}function Hr(e){if(!Vr(e)||!e.isConnected||e.matches(`:disabled`))return!1;for(let t=e;t;t=Rr(t)){let n=t!==e,r=W(t)===`slot`;if(t.hasAttribute(`inert`)||n&&W(t)===`details`&&!t.open&&!Br(e,t)||t.hasAttribute(`hidden`)||!r&&!Ur(t,n))return!1}return!0}function Ur(e,t){let n=ke(e);return t?n.display!==`none`:Ir(e,n)}function Wr(e){let t=e.tabIndex;if(t<0){let t=W(e);if(t===`details`||t===`audio`||t===`video`||K(e)&&e.isContentEditable)return 0}return t}function Gr(e){if(W(e)!==`input`)return null;let t=e;return t.type===`radio`&&t.name!==``?t:null}function Kr(e,t){let n=Gr(e);if(!n)return!0;let r=t.find(e=>{let t=Gr(e);return t?.name===n.name&&t.form===n.form&&t.checked});return r?r===n:t.find(e=>{let t=Gr(e);return t?.name===n.name&&t.form===n.form})===n}function qr(e){if(K(e)&&W(e)===`slot`){let t=e.assignedElements({flatten:!0});if(t.length>0)return t}return K(e)&&e.shadowRoot?Array.from(e.shadowRoot.children):Array.from(e.children)}function Jr(e,t){qr(e).forEach(e=>{Vr(e)&&t.push(e),Jr(e,t)})}function Yr(e,t,n){qr(e).forEach(e=>{K(e)&&e.matches(t)&&n.push(e),Yr(e,t,n)})}function Xr(e){return Hr(e)&&Wr(e)>=0}function Zr(e){let t=[];return Jr(e,t),t.filter(Hr)}function Qr(e){let t=Zr(e);return t.filter(e=>Wr(e)>=0&&Kr(e,t))}function $r(e,t){let n=Qr(e),r=n.length;if(r===0)return;let i=Tt(J(e)),a=n.indexOf(i);return n[a===-1?t===1?0:r-1:a+t]}function ei(e){return $r(J(e).body,1)||e}function ti(e){return $r(J(e).body,-1)||e}function ni(e,t){if(!e)return null;let n=Qr(J(e).body),r=n.length;if(r===0)return null;let i=n.indexOf(e);return i===-1?null:n[(i+t+r)%r]}function ri(e){return ni(e,1)}function ii(e){return ni(e,-1)}function ai(e,t){let n=t||e.currentTarget,r=e.relatedTarget;return!r||!X(n,r)}function oi(e){Qr(e).forEach(e=>{e.dataset.tabindex=e.getAttribute(`tabindex`)||``,e.setAttribute(`tabindex`,`-1`)})}function si(e){let t=[];Yr(e,`[data-tabindex]`,t),t.forEach(e=>{let t=e.dataset.tabindex;delete e.dataset.tabindex,t?e.setAttribute(`tabindex`,t):e.removeAttribute(`tabindex`)})}function ci(e,t,n=!0){return e.filter(e=>e.parentId===t).flatMap(t=>[...!n||t.context?.open?[t]:[],...ci(e,t.id,n)])}function li(e,t){let n=[],r=e.find(e=>e.id===t)?.parentId;for(;r;){let t=e.find(e=>e.id===r);r=t?.parentId,t&&(n=n.concat(t))}return n}function ui(e){return`data-base-ui-${e}`}var di=0;function fi(e,t={}){let{preventScroll:n=!1,sync:r=!1,shouldFocus:i}=t;cancelAnimationFrame(di);function a(){(!i||i())&&e?.focus({preventScroll:n})}if(r)return a(),Qe;let o=requestAnimationFrame(a);return di=o,()=>{di===o&&(cancelAnimationFrame(o),di=0)}}var pi={inert:new WeakMap,"aria-hidden":new WeakMap},mi=`data-base-ui-inert`,hi={inert:new WeakSet,"aria-hidden":new WeakSet},gi=new WeakMap,_i=0;function vi(e){return hi[e]}function yi(e){return e?_e(e)?e.host:yi(e.parentNode):null}var bi=(e,t)=>t.map(t=>{if(e.contains(t))return t;let n=yi(t);return e.contains(n)?n:null}).filter(e=>e!=null),xi=e=>{let t=new Set;return e.forEach(e=>{let n=e;for(;n&&!t.has(n);)t.add(n),n=n.parentNode}),t},Si=(e,t,n)=>{let r=[],i=e=>{e&&!n.has(e)&&Array.from(e.children).forEach(e=>{W(e)!==`script`&&(t.has(e)?i(e):r.push(e))})};return i(e),r};function Ci(e,t,n,r,{mark:i=!0}){let a=null;r?a=`inert`:n&&(a=`aria-hidden`);let o=null,s=null,c=bi(t,e),l=i?Si(t,xi(c),new Set(c)):[],u=[],d=[];if(a){let e=pi[a],n=vi(a);s=n,o=e;let r=bi(t,Array.from(t.querySelectorAll(`[aria-live]`))),i=c.concat(r);Si(t,xi(i),new Set(i)).forEach(t=>{let r=t.getAttribute(a),i=r!==null&&r!==`false`,o=(e.get(t)||0)+1;e.set(t,o),u.push(t),o===1&&i&&n.add(t),i||t.setAttribute(a,a===`inert`?``:`true`)})}return i&&l.forEach(e=>{let t=(gi.get(e)||0)+1;gi.set(e,t),d.push(e),t===1&&e.setAttribute(mi,``)}),_i+=1,()=>{o&&u.forEach(e=>{let t=(o.get(e)||0)-1;o.set(e,t),t||(!s?.has(e)&&a&&e.removeAttribute(a),s?.delete(e))}),i&&d.forEach(e=>{let t=(gi.get(e)||0)-1;gi.set(e,t),t||e.removeAttribute(mi)}),--_i,_i||(pi.inert=new WeakMap,pi[`aria-hidden`]=new WeakMap,hi.inert=new WeakSet,hi[`aria-hidden`]=new WeakSet,gi=new WeakMap)}}function wi(e,t={}){let{ariaHidden:n=!1,inert:r=!1,mark:i=!0}=t,a=J(e[0]).body;return Ci(e,a,n,r,{mark:i})}var Ti=0;function Ei(e,t=`mui`){let[n,r]=l.useState(e),i=e||n;return l.useEffect(()=>{n??(Ti+=1,r(`${t}-${Ti}`))},[n,t]),i}var Di=Kn.useId;function Oi(e,t){if(Di!==void 0){let n=Di();return e??(t?`${t}-${n}`:n)}return Ei(e,t)}function ki(e,t){return function(n,...r){let i=new URL(e);return i.searchParams.set(`code`,n.toString()),r.forEach(e=>i.searchParams.append(`args[]`,e)),`${t} error #${n}; visit ${i} for the full message.`}}var Ai=ki(`https://base-ui.com/production-error`,`Base UI`),ji=19;function Mi(e){return ji>=e}function Ni(e){if(!l.isValidElement(e))return null;let t=e,n=t.props;return(Mi(19)?n?.ref:t.ref)??null}function Pi(e,t){if(e&&!t)return e;if(!e&&t)return t;if(e||t)return{...e,...t}}function Fi(e,t){let n={};for(let r in e){let i=e[r];if(t?.hasOwnProperty(r)){let e=t[r](i);e!=null&&Object.assign(n,e);continue}i===!0?n[`data-${r.toLowerCase()}`]=``:i&&(n[`data-${r.toLowerCase()}`]=i.toString())}return n}function Ii(e,t){return typeof e==`function`?e(t):e}function Li(e,t){return typeof e==`function`?e(t):e}var Ri={};function zi(e,t,n,r,i){if(!n&&!r&&!i&&!e)return Vi(t);let a=Vi(e);return t&&(a=Hi(a,t)),n&&(a=Hi(a,n)),r&&(a=Hi(a,r)),i&&(a=Hi(a,i)),a}function Bi(e){if(e.length===0)return Ri;if(e.length===1)return Vi(e[0]);let t=Vi(e[0]);for(let n=1;n<e.length;n+=1)t=Hi(t,e[n]);return t}function Vi(e){return Ki(e)?{...qi(e,Ri)}:Ui(e)}function Hi(e,t){return Ki(t)?qi(t,e):Wi(e,t)}function Ui(e){let t={...e};for(let e in t){let n=t[e];Gi(e,n)&&(t[e]=Yi(n))}return t}function Wi(e,t){if(!t)return e;for(let n in t){let r=t[n];switch(n){case`style`:e[n]=Pi(e.style,r);break;case`className`:e[n]=Zi(e.className,r);break;default:e[n]=Gi(n,r)?Ji(e[n],r):r}}return e}function Gi(e,t){let n=e.charCodeAt(0),r=e.charCodeAt(1),i=e.charCodeAt(2);return n===111&&r===110&&i>=65&&i<=90&&(typeof t==`function`||t===void 0)}function Ki(e){return typeof e==`function`}function qi(e,t){return Ki(e)?e(t):e??Ri}function Ji(e,t){return t?e?(...n)=>{let r=n[0];if(Qi(r)){let i=r;Xi(i);let a=t(...n);return i.baseUIHandlerPrevented||e?.(...n),a}let i=t(...n);return e?.(...n),i}:Yi(t):e}function Yi(e){return e&&((...t)=>{let n=t[0];return Qi(n)&&Xi(n),e(...t)})}function Xi(e){return e.preventBaseUIHandler=()=>{e.baseUIHandlerPrevented=!0},e}function Zi(e,t){return t?e?t+` `+e:t:e}function Qi(e){return typeof e==`object`&&!!e&&`nativeEvent`in e}function $i(e,t,n={}){let r=t.render;n.enabled!==!1&&(r=ra(r));let i=ea(t,n,r);if(n.enabled===!1)return null;let a=n.state??et;return ia(e,r,i,a)}function ea(e,t,n){let{className:r,style:i}=e,{state:a=et,ref:o,props:s,stateAttributesMapping:c,enabled:l=!0}=t,u=l?Ii(r,a):void 0,d=l?Li(i,a):void 0,f=l?Fi(a,c):et,p=l&&s?ta(s):void 0,m=l?Pi(f,p)??{}:et;return typeof document<`u`&&(l?m.ref=Array.isArray(o)?zn([m.ref,Ni(n),...o]):Rn(m.ref,Ni(n),o):Rn(null,null)),l?(u!==void 0&&(m.className=Zi(m.className,u)),d!==void 0&&(m.style=Pi(m.style,d)),m):et}function ta(e){return Array.isArray(e)?Bi(e):zi(void 0,e)}var na=Symbol.for(`react.lazy`);function ra(e){if(e?.$$typeof!==na)return e;let t=l.Children.toArray(e)[0];return l.isValidElement(t)?t:e}function ia(e,t,n,r){if(t){if(typeof t==`function`)return t(n,r);let e=zi(n,t.props);return e.ref=n.ref,l.cloneElement(t,e)}if(e&&typeof e==`string`)return aa(e,n);throw Error(Ai(8))}function aa(e,t){return e===`button`?(0,l.createElement)(`button`,{type:`button`,...t,key:t.key}):e===`img`?(0,l.createElement)(`img`,{alt:``,...t,key:t.key}):l.createElement(e,t)}var oa={style:{transition:`none`}},sa={fallbackAxisSide:`none`},ca={fallbackAxisSide:`end`},la={clipPath:`inset(50%)`,position:`fixed`,top:0,left:0},ua=e(n(),1),da=l.createContext(null),fa=()=>l.useContext(da),pa=ui(`portal`);function ma(e={}){let{ref:t,container:n,componentProps:r=et,elementProps:i}=e,a=Oi(),o=fa()?.portalNode,[s,c]=l.useState(null),[u,d]=l.useState(null),f=$(e=>{e!==null&&d(e)}),p=l.useRef(null);U(()=>{if(n===null){p.current&&(p.current=null,d(null),c(null));return}let e=(n&&(ge(n)?n:n.current))??o??document.body;if(e==null){p.current&&(p.current=null,d(null),c(null));return}p.current!==e&&(p.current=e,d(null),c(e))},[n,o]);let m=$i(`div`,r,{ref:[t,f],props:[{id:a,[pa]:``},i]}),h=s&&m?ua.createPortal(m,s):null;return{node:u,nodeId:l.isValidElement(m)?m.props.id:void 0,subtree:h}}var ha=l.forwardRef(function(e,t){let{render:n,className:r,style:i,children:a,container:o,portalOwnerRole:s,...c}=e,{node:u,nodeId:d,subtree:f}=ma({container:o,ref:t,componentProps:e,elementProps:c}),p=l.useRef(null),m=l.useRef(null),h=l.useRef(null),g=l.useRef(null),[_,v]=l.useState(null),y=l.useRef(!1),b=_?.modal,x=_?.open,S=!!_&&!_.modal&&_.open&&!!u;l.useEffect(()=>{if(!u||b)return;function e(e){u&&e.relatedTarget&&ai(e)&&(e.type===`focusin`?y.current&&=(si(u),!1):(oi(u),y.current=!0))}return Ln(q(u,`focusin`,e,!0),q(u,`focusout`,e,!0))},[u,b]),U(()=>{u&&x===!0&&y.current&&(si(u),y.current=!1)},[x,u]);let C=l.useMemo(()=>({beforeOutsideRef:p,afterOutsideRef:m,beforeInsideRef:h,afterInsideRef:g,portalNode:u,setFocusManagerState:v}),[u]);return(0,Q.jsxs)(l.Fragment,{children:[f,(0,Q.jsxs)(da.Provider,{value:C,children:[S&&u&&(0,Q.jsx)(er,{"data-type":`outside`,ref:p,onFocus:e=>{ai(e,u)?h.current?.focus():ti(_?_.domReference:null)?.focus()}}),S&&u&&(0,Q.jsx)(`span`,{role:s,"aria-owns":d,style:la}),u&&ua.createPortal(a,u),S&&u&&(0,Q.jsx)(er,{"data-type":`outside`,ref:m,onFocus:e=>{ai(e,u)?g.current?.focus():(ei(_?_.domReference:null)?.focus(),_?.closeOnFocusOut&&_?.onOpenChange(!1,Z(`focus-out`,e.nativeEvent)))}})]})]})});function ga(){let e=new Map;return{emit(t,n){e.get(t)?.forEach(e=>e(n))},on(t,n){e.has(t)||e.set(t,new Set),e.get(t).add(n)},off(t,n){e.get(t)?.delete(n)}}}var _a=class{nodesRef={current:[]};events=ga();addNode(e){this.nodesRef.current.push(e)}removeNode(e){let t=this.nodesRef.current.findIndex(t=>t===e);t!==-1&&this.nodesRef.current.splice(t,1)}},va=l.createContext(null),ya=l.createContext(null),ba=()=>l.useContext(va)?.id||null,xa=e=>{let t=l.useContext(ya);return e??t};function Sa(e){let t=Oi(),n=xa(e),r=ba();return U(()=>{if(!t)return;let e={id:t,parentId:r};return n?.addNode(e),()=>{n?.removeNode(e)}},[n,t,r]),t}function Ca(e){let{children:t,id:n}=e,r=ba();return(0,Q.jsx)(va.Provider,{value:l.useMemo(()=>({id:n,parentId:r}),[n,r]),children:t})}function wa(e){let{children:t,externalTree:n}=e,r=Ze(()=>n??new _a).current;return(0,Q.jsx)(ya.Provider,{value:r,children:t})}function Ta(e){return e==null?e:`current`in e?e.current:e}function Ea(e,t){let n=me(Et(e));return e instanceof n.KeyboardEvent?`keyboard`:e instanceof n.FocusEvent?t||`keyboard`:`pointerType`in e?e.pointerType||`keyboard`:`touches`in e?`touch`:e instanceof n.MouseEvent?t||(e.detail===0?`keyboard`:`mouse`):``}var Da=20,Oa=[];function ka(){Oa=Oa.filter(e=>e.deref()?.isConnected)}function Aa(e){ka(),e&&W(e)!==`body`&&(Oa.push(new WeakRef(e)),Oa.length>Da&&(Oa=Oa.slice(-20)))}function ja(){return ka(),Oa[Oa.length-1]?.deref()}function Ma(e){return e?Xr(e)?e:Qr(e)[0]||e:null}function Na(e){if(e.hasAttribute(`tabindex`)&&!e.hasAttribute(`data-tabindex`)||!e.getAttribute(`role`)?.includes(`dialog`))return;let t=Zr(e).filter(e=>{let t=e.getAttribute(`data-tabindex`)||``;return Xr(e)||e.hasAttribute(`data-tabindex`)&&!t.startsWith(`-`)}),n=e.getAttribute(`tabindex`);t.length===0?n!==`0`&&(e.setAttribute(`tabindex`,`0`),e.setAttribute(`data-tabindex`,`0`)):(n!==`-1`||e.hasAttribute(`data-tabindex`)&&e.getAttribute(`data-tabindex`)!==`-1`)&&(e.setAttribute(`tabindex`,`-1`),e.setAttribute(`data-tabindex`,`-1`))}function Pa(e){let{context:t,children:n,disabled:r=!1,initialFocus:i=!0,returnFocus:a=!0,restoreFocus:o=!1,modal:s=!0,closeOnFocusOut:c=!0,openInteractionType:u=``,nextFocusableElement:d,previousFocusableElement:f,beforeContentFocusGuardRef:p,externalTree:m,getInsideElements:h}=e,g=`rootStore`in t?t.rootStore:t,_=g.useState(`open`),v=g.useState(`domReferenceElement`),y=g.useState(`floatingElement`),{events:b,dataRef:x}=g.context,S=$(()=>x.current.floatingContext?.nodeId),C=i===!1,w=an(v)&&C,T=Wn(i),E=Wn(a),D=Wn(u),O=Wn(_),k=xa(m),A=fa(),j=l.useRef(!1),M=l.useRef(!1),N=l.useRef(!1),P=l.useRef(null),F=l.useRef(``),I=l.useRef(``),L=l.useRef(null),R=l.useRef(null),z=Rn(L,p,A?.beforeInsideRef),ee=Rn(R,A?.afterInsideRef),B=it(),te=it(),ne=ct(),re=A!=null,V=sn(y),H=$((e=V)=>e?Qr(e):[]),ie=$(()=>h?.().filter(e=>e!=null)??[]);l.useEffect(()=>{if(r||!s)return;function e(e){e.key===`Tab`&&X(V,Tt(J(V)))&&H().length===0&&!w&&yt(e)}return q(J(V),`keydown`,e)},[r,V,s,w,H]),l.useEffect(()=>{if(r||!_)return;let e=J(V);function t(){N.current=!1}function n(e){let t=Et(e),n=ie(),r=X(y,t)||X(v,t)||X(A?.portalNode,t)||n.some(e=>e===t||X(e,t));N.current=!r,I.current=e.pointerType||`keyboard`,t?.closest(`[data-base-ui-click-trigger]`)&&(M.current=!0,te.start(0,()=>{M.current=!1}))}function i(){I.current=`keyboard`}return Ln(q(e,`pointerdown`,n,!0),q(e,`pointerup`,t,!0),q(e,`pointercancel`,t,!0),q(e,`keydown`,i,!0),t)},[r,y,v,V,_,A,te,ie]),l.useEffect(()=>{if(r||!c)return;let e=J(V);function t(){M.current=!0,te.start(0,()=>{M.current=!1})}function n(e){let t=Et(e);Xr(t)&&(P.current=t)}function i(t){let n=t.relatedTarget,r=t.currentTarget,i=Et(t);s&&n==null&&i!=null&&X(y,i)&&Aa(i),queueMicrotask(()=>{let a=S(),c=g.context.triggerElements,l=ie(),u=n?.hasAttribute(ui(`focus-guard`))&&[L.current,R.current,A?.beforeInsideRef.current,A?.afterInsideRef.current,A?.beforeOutsideRef.current,A?.afterOutsideRef.current,Ta(f),Ta(d)].includes(n),p=!(X(v,n)||X(y,n)||X(n,y)||X(A?.portalNode,n)||l.some(e=>e===n||X(e,n))||c.hasMatchingElement(e=>X(e,n))||u||k&&(ci(k.nodesRef.current,a).find(e=>X(e.context?.elements.floating,n)||X(e.context?.elements.domReference,n))||li(k.nodesRef.current,a).find(e=>[e.context?.elements.floating,sn(e.context?.elements.floating)].includes(n)||e.context?.elements.domReference===n)));if(r===v&&V&&Na(V),o&&r!==v&&!Ir(i)&&Tt(e)===e.body){if(K(V)&&(V.focus(),o===`popup`)){ne.request(()=>{V.focus()});return}let e=H(),t=P.current,n=(t&&e.includes(t)?t:null)||e[e.length-1]||V;K(n)&&n.focus()}if(x.current.insideReactTree){x.current.insideReactTree=!1;return}(w||!s)&&n&&p&&!M.current&&(w||n!==ja())&&(j.current=!0,g.setOpen(!1,Z(Cn,t)))})}function a(){N.current||(x.current.insideReactTree=!0,B.start(0,()=>{x.current.insideReactTree=!1}))}let l=K(v)?v:null;if(y||l)return Ln(l&&q(l,`focusout`,i),l&&q(l,`pointerdown`,t),y&&q(y,`focusin`,n),y&&q(y,`focusout`,i),y&&A&&q(y,`focusout`,a,!0))},[r,v,y,V,s,k,A,g,c,o,H,w,S,x,B,te,ne,d,f,ie]),l.useEffect(()=>{if(r||!y||!_)return;let e=Array.from(A?.portalNode?.querySelectorAll(`[${ui(`portal`)}]`)||[]),t=(k?li(k.nodesRef.current,S()):[]).find(e=>an(e.context?.elements.domReference||null))?.context?.elements.domReference,n=wi([y,...e,L.current,R.current,A?.beforeOutsideRef.current,A?.afterOutsideRef.current,...ie(),t,Ta(f),Ta(d),w?v:null].filter(e=>e!=null),{ariaHidden:s||w,mark:!1}),i=wi([y,...e].filter(e=>e!=null));return()=>{i(),n()}},[_,r,v,y,s,A,w,k,S,d,f,ie]),U(()=>{if(!_||r||!K(V))return;F.current=``,I.current=``;let e=J(V),t=Tt(e);queueMicrotask(()=>{let n=T.current,r=typeof n==`function`?n(D.current||``):n;if(r===void 0||r===!1||X(V,t))return;let i=null,a=()=>(i??=H(V),i[0]||V),o;o=r===!0||r===null?a():Ta(r),o||=a();let s=X(V,Tt(e));fi(o,{preventScroll:o===V,shouldFocus(){if(!O.current)return!1;if(s)return!0;let t=Tt(e);return!(t!==o&&X(V,t))}})})},[r,_,V,H,T,D,O]),U(()=>{if(r||!V)return;let e=J(V),t=Tt(e),n=D.current==null;Aa(t);function i(e){if(e.open||(F.current=Ea(e.nativeEvent,I.current)),e.reason===`trigger-hover`&&e.nativeEvent.type===`mouseleave`&&(j.current=!0),e.reason===`outside-press`){if(e.nested)j.current=!1;else if(xt(e.nativeEvent)||St(e.nativeEvent))j.current=!1;else{let e=!1;J(V).createElement(`div`).focus({get preventScroll(){return e=!0,!1}}),e?j.current=!1:j.current=!0}}}b.on(`openchange`,i);function a(e){let r=E.current,i=typeof r==`function`?r(e):r;if(i===void 0||i===!1)return null;i===null&&(i=!0);let a=v?.isConnected?v:null,o=t?.isConnected&&W(t)!==`body`?t:null,s=n?o||a:a||o;return s||=ja()||null,typeof i==`boolean`?s:Ta(i)||s||null}return()=>{b.off(`openchange`,i);let t=Tt(e),n=ie(),r=X(y,t)||n.some(e=>e===t||X(e,t))||k&&ci(k.nodesRef.current,S(),!1).some(e=>X(e.context?.elements.floating,t)),o=E.current,s=F.current,c=a(s);queueMicrotask(()=>{let n=Ma(c),i=typeof o!=`boolean`;if(o&&!j.current&&K(n)&&(i||n===t||t===e.body||r)){let e={preventScroll:!0};s===`keyboard`&&(e.focusVisible=!0),n.focus(e)}j.current=!1})}},[r,y,V,E,D,b,k,v,S,ie]),U(()=>{if(!Ke||_||!y)return;let e=Tt(J(y));K(e)&&nn(e)&&X(y,e)&&e.blur()},[_,y]),U(()=>{if(!r&&A)return A.setFocusManagerState({modal:s,closeOnFocusOut:c,open:_,onOpenChange:g.setOpen,domReference:v}),()=>{A.setFocusManagerState(null)}},[r,A,s,_,g,c,v]),U(()=>{if(!r&&V)return Na(V),()=>{queueMicrotask(ka)}},[r,V]);let ae=!r&&(!s||!w)&&(re||s);return(0,Q.jsxs)(l.Fragment,{children:[ae&&(0,Q.jsx)(er,{"data-type":`inside`,ref:z,onFocus:e=>{if(s){let e=H();fi(e[e.length-1])}else A?.portalNode&&(j.current=!1,ai(e,A.portalNode)?ei(v)?.focus():Ta(f??A.beforeOutsideRef)?.focus())}}),n,ae&&(0,Q.jsx)(er,{"data-type":`inside`,ref:ee,onFocus:e=>{s?fi(H()[0]):A?.portalNode&&(c&&(j.current=!0),ai(e,A.portalNode)?ti(v)?.focus():Ta(d??A.afterOutsideRef)?.focus())}})]})}function Fa(e,t={}){let{enabled:n=!0,event:r=`click`,toggle:i=!0,ignoreMouse:a=!1,stickIfOpen:o=!0,touchOpenDelay:s=0,reason:c=mn}=t,u=`rootStore`in e?e.rootStore:e,d=u.context.dataRef,f=l.useRef(void 0),p=ct(),m=it(),h=l.useMemo(()=>{function e(e,t,n,r){let i=Z(c,t,n);e&&r===`touch`&&s>0?m.start(s,()=>{u.setOpen(!0,i)}):u.setOpen(e,i)}function t(e,t,n){let r=d.current.openEvent,a=u.select(`domReferenceElement`)!==t;return e&&a||!e||!i?!0:r&&o?!n(r.type):!1}return{onPointerDown(e){f.current=Ct(e.pointerType,!0)&&St(e.nativeEvent)?`virtual`:e.pointerType},onMouseDown(n){let i=f.current,o=n.nativeEvent,s=u.select(`open`);if(n.button!==0||r===`click`||Ct(i,!0)&&a)return;let c=t(s,n.currentTarget,e=>e===`click`||e===`mousedown`),l=Et(o);if(nn(l)){e(c,o,l,i);return}let d=n.currentTarget;p.request(()=>{e(c,o,d,i)})},onClick(n){if(r===`mousedown-only`)return;let i=f.current;if(r===`mousedown`&&i){f.current=void 0;return}Ct(i,!0)&&a||e(t(u.select(`open`),n.currentTarget,e=>e===`click`||e===`mousedown`||e===`keydown`||e===`keyup`),n.nativeEvent,n.currentTarget,i)},onKeyDown(){f.current=void 0}}},[d,r,a,c,u,o,i,p,m,s]);return l.useMemo(()=>n?{reference:h}:et,[n,h])}function Ia(e,t){let n=null,r=null,i=!1;return{contextElement:e||void 0,getBoundingClientRect(){let a=e?.getBoundingClientRect()||{width:0,height:0,x:0,y:0},o=t.axis===`x`||t.axis===`both`,s=t.axis===`y`||t.axis===`both`,c=[`mouseenter`,`mousemove`].includes(t.dataRef.current.openEvent?.type||``)&&t.pointerType!==`touch`,l=a.width,u=a.height,d=a.x,f=a.y;return n==null&&t.x&&o&&(n=a.x-t.x),r==null&&t.y&&s&&(r=a.y-t.y),d-=n||0,f-=r||0,l=0,u=0,!i||c?(l=t.axis===`y`?a.width:0,u=t.axis===`x`?a.height:0,d=o&&t.x!=null?t.x:d,f=s&&t.y!=null?t.y:f):i&&!c&&(u=t.axis===`x`?a.height:u,l=t.axis===`y`?a.width:l),i=!0,{width:l,height:u,x:d,y:f,top:f,right:d+l,bottom:f+u,left:d}}}}function La(e){return e!=null&&e.clientX!=null}function Ra(e,t={}){let{enabled:n=!0,axis:r=`both`}=t,i=`rootStore`in e?e.rootStore:e,a=i.useState(`open`),o=i.useState(`floatingElement`),s=i.useState(`domReferenceElement`),c=i.context.dataRef,u=l.useRef(!1),d=l.useRef(null),[f,p]=l.useState(),[m,h]=l.useState([]),g=$(e=>{i.set(`positionReference`,e)}),_=$((e,t,n)=>{u.current||(!c.current.openEvent||La(c.current.openEvent))&&i.set(`positionReference`,Ia(n??s,{x:e,y:t,axis:r,dataRef:c,pointerType:f}))}),v=$(e=>{a?d.current||(_(e.clientX,e.clientY,e.currentTarget),h([])):_(e.clientX,e.clientY,e.currentTarget)}),y=Ct(f)?o:a;l.useEffect(()=>{if(!n){g(s);return}if(!y)return;function e(){d.current?.(),d.current=null}let t=me(o);function r(t){let n=Et(t);X(o,n)?e():_(t.clientX,t.clientY)}return!c.current.openEvent||La(c.current.openEvent)?d.current=q(t,`mousemove`,r):g(s),e},[y,n,o,c,s,i,_,g,m]),l.useEffect(()=>()=>{i.set(`positionReference`,null)},[i]),l.useEffect(()=>{n&&!o&&(u.current=!1)},[n,o]),l.useEffect(()=>{!n&&a&&(u.current=!0)},[n,a]);let b=l.useMemo(()=>{function e(e){p(e.pointerType)}return{onPointerDown:e,onPointerEnter:e,onMouseMove:v,onMouseEnter:v}},[v]);return l.useMemo(()=>n?{reference:b,trigger:b}:{},[n,b])}function za(){return!1}function Ba(e){return{escapeKey:typeof e==`boolean`?e:e?.escapeKey??!1,outsidePress:typeof e==`boolean`?e:e?.outsidePress??!0}}function Va(e,t={}){let{enabled:n=!0,escapeKey:r=!0,outsidePress:i=!0,outsidePressEvent:a=`sloppy`,referencePress:o=za,bubbles:s,externalTree:c}=t,u=`rootStore`in e?e.rootStore:e,d=u.useState(`open`),f=u.useState(`floatingElement`),{dataRef:p,events:m}=u.context,h=xa(c),g=$(typeof i==`function`?i:()=>!1),_=typeof i==`function`?g:i,v=_!==!1,y=$(()=>a),{escapeKey:b,outsidePress:x}=Ba(s),S=l.useRef(!1),C=l.useRef(!1),w=l.useRef(!1),T=l.useRef(!1),E=l.useRef(!1),D=l.useRef(``),O=l.useRef(null),k=it(),A=it(),j=$(()=>{A.clear(),p.current.insideReactTree=!1}),M=$(e=>{let t=p.current.floatingContext?.nodeId;return(h?ci(h.nodesRef.current,t):[]).some(t=>t.context?.open&&!t.context.dataRef.current[e])}),N=$(e=>en(e,u.select(`floatingElement`))||en(e,u.select(`domReferenceElement`))),P=$(e=>{o()&&u.setOpen(!1,Z(mn,e.nativeEvent))}),F=$(e=>{if(!d||!n||!r||e.key!==`Escape`||E.current||!b&&M(`__escapeKeyBubbles`))return;let t=Z(wn,bt(e)?e.nativeEvent:e);u.setOpen(!1,t),t.isCanceled||e.preventDefault(),!b&&!t.isPropagationAllowed&&e.stopPropagation()}),I=$(()=>{p.current.insideReactTree=!0,A.start(0,j)}),L=$(e=>{if(!d||!n||e.button!==0)return;let t=Et(e.nativeEvent);X(u.select(`floatingElement`),t)&&(S.current||(S.current=!0,C.current=!1))}),R=$(e=>{d&&n&&(e.defaultPrevented||e.nativeEvent.defaultPrevented)&&S.current&&(C.current=!0)});l.useEffect(()=>{function e(e){e.open||(T.current=!1)}return m.on(`openchange`,e),()=>{m.off(`openchange`,e)}},[m]),l.useEffect(()=>{if(!d||!n)return d||(T.current=!1),j;p.current.__escapeKeyBubbles=b,p.current.__outsidePressBubbles=x;let e=new rt,t=new rt,i=J(f);function a(){e.clear(),E.current=!0}function o(){e.start(Ke?5:0,()=>{E.current=!1})}function s(){w.current=!0,t.start(0,()=>{w.current=!1})}function c(){S.current=!1,C.current=!1}function l(){let e=D.current,t=e===`pen`||!e?`mouse`:e,n=y(),r=typeof n==`function`?n():n;return typeof r==`string`?r:r[t]}function m(e){let t=l();return t===`intentional`&&e.type!==`click`||t===`sloppy`&&e.type===`click`}function g(e){let t=p.current.floatingContext?.nodeId,n=h&&ci(h.nodesRef.current,t).some(t=>en(e,t.context?.elements.floating));return N(e)||n}function A(e){if(m(e)){e.type!==`click`&&!N(e)&&(t.clear(),w.current=!1),j();return}if(p.current.insideReactTree){j();return}let n=Et(e),r=`[${ui(`inert`)}]`,i=G(n)?n.getRootNode():null,a=Array.from((_e(i)?i:J(u.select(`floatingElement`))).querySelectorAll(r)),o=u.context.triggerElements;if(n&&(o.hasElement(n)||o.hasMatchingElement(e=>X(e,n))))return;let s=G(n)?n:null;for(;s&&!Oe(s);){let e=je(s);if(Oe(e)||!G(e))break;s=e}if(!(a.length&&G(n)&&!tn(n)&&!X(n,u.select(`floatingElement`))&&a.every(e=>!X(s,e)))){if(K(n)&&!(`touches`in e)){let t=Oe(n),r=ke(n),i=/auto|scroll/,a=t||i.test(r.overflowX),o=t||i.test(r.overflowY),s=a&&n.clientWidth>0&&n.scrollWidth>n.clientWidth,c=o&&n.clientHeight>0&&n.scrollHeight>n.clientHeight,l=r.direction===`rtl`,u=c&&(l?e.offsetX<=n.offsetWidth-n.clientWidth:e.offsetX>n.clientWidth),d=s&&e.offsetY>n.clientHeight;if(u||d)return}if(!g(e)){if(l()===`intentional`){if(e.detail!==0&&!xt(e)&&!T.current)return;if(w.current){t.clear(),w.current=!1;return}}(typeof _!=`function`||_(e))&&(M(`__outsidePressBubbles`)||(u.setOpen(!1,Z(_n,e)),j()))}}}function P(e){l()===`sloppy`&&e.pointerType!==`touch`&&u.select(`open`)&&n&&!N(e)&&A(e)}function I(e){if(l()!==`sloppy`||!u.select(`open`)||!n||N(e))return;let t=e.touches[0];t&&(O.current={startTime:Date.now(),startX:t.clientX,startY:t.clientY,dismissOnTouchEnd:!1,dismissOnMouseDown:!0},k.start(1e3,()=>{O.current&&(O.current.dismissOnTouchEnd=!1,O.current.dismissOnMouseDown=!1)}))}function L(e,t){let n=Et(e);if(!n)return;let r=q(n,e.type,()=>{t(e),r()})}function R(e){D.current=`touch`,L(e,I)}function z(e){k.clear(),e.type===`pointerdown`&&(e.button===0&&(T.current=!0),D.current=e.pointerType),(e.type!==`mousedown`||!O.current||O.current.dismissOnMouseDown)&&L(e,e=>{e.type===`pointerdown`?P(e):A(e)})}function ee(e){if(e.type===`pointercancel`&&(T.current=!1),!S.current)return;let n=C.current;if(c(),l()===`intentional`){if(e.type===`pointercancel`){n&&s();return}if(!g(e)){if(n){s();return}(typeof _!=`function`||_(e))&&(t.clear(),w.current=!0,j())}}}function B(e){if(l()!==`sloppy`||!O.current||N(e))return;let t=e.touches[0];if(!t)return;let n=Math.abs(t.clientX-O.current.startX),r=Math.abs(t.clientY-O.current.startY),i=Math.sqrt(n*n+r*r);i>5&&(O.current.dismissOnTouchEnd=!0),i>10&&(A(e),k.clear(),O.current=null)}function te(e){L(e,B)}function ne(e){l()===`sloppy`&&O.current&&!N(e)&&(O.current.dismissOnTouchEnd&&A(e),k.clear(),O.current=null)}function re(e){L(e,ne)}let V=Ln(r&&Ln(q(i,`keydown`,F),q(i,`compositionstart`,a),q(i,`compositionend`,o)),v&&Ln(q(i,`click`,z,!0),q(i,`pointerdown`,z,!0),q(i,`pointerup`,ee,!0),q(i,`pointercancel`,ee,!0),q(i,`mousedown`,z,!0),q(i,`mouseup`,ee,!0),q(i,`touchstart`,R,{capture:!0,passive:!0}),q(i,`touchmove`,te,{capture:!0,passive:!0}),q(i,`touchend`,re,{capture:!0,passive:!0})));return()=>{V(),e.clear(),t.clear(),c(),w.current=!1,j()}},[p,f,r,v,_,d,n,b,x,F,j,y,M,N,h,u,k]);let z=l.useMemo(()=>({onKeyDown:F,onPointerDown:P,onClick:P}),[F,P]),ee=l.useMemo(()=>({onKeyDown:F,onPointerDown:R,onMouseDown:R,onClickCapture:I,onMouseDownCapture(e){I(),L(e)},onPointerDownCapture(e){I(),L(e)},onMouseUpCapture:I,onTouchEndCapture:I,onTouchMoveCapture:I}),[F,I,L,R]);return l.useMemo(()=>n?{reference:z,floating:ee,trigger:z}:{},[n,z,ee])}function Ha(e,t,n){let{reference:r,floating:i}=e,a=pr(t),o=mr(t),s=fr(o),c=lr(t),l=a===`y`,u=r.x+r.width/2-i.width/2,d=r.y+r.height/2-i.height/2,f=r[s]/2-i[s]/2,p;switch(c){case`top`:p={x:u,y:r.y-i.height};break;case`bottom`:p={x:u,y:r.y+r.height};break;case`right`:p={x:r.x+r.width,y:d};break;case`left`:p={x:r.x-i.width,y:d};break;default:p={x:r.x,y:r.y}}let m=ur(t);return m&&(p[o]+=f*(m===`end`?1:-1)*(n&&l?-1:1)),p}async function Ua(e,t){t===void 0&&(t={});let{x:n,y:r,platform:i,rects:a,elements:o,strategy:s}=e,{boundary:c=`clippingAncestors`,rootBoundary:l=`viewport`,elementContext:u=`floating`,altBoundary:d=!1,padding:f=0}=cr(t,e),p=Er(f),m=o[d?u===`floating`?`reference`:`floating`:u],h=Dr(await i.getClippingRect({element:await(i.isElement==null?void 0:i.isElement(m))??!0?m:m.contextElement||await(i.getDocumentElement==null?void 0:i.getDocumentElement(o.floating)),boundary:c,rootBoundary:l,strategy:s})),g=u===`floating`?{x:n,y:r,width:a.floating.width,height:a.floating.height}:a.reference,_=await(i.getOffsetParent==null?void 0:i.getOffsetParent(o.floating)),v=await(i.isElement==null?void 0:i.isElement(_))&&await(i.getScale==null?void 0:i.getScale(_))||{x:1,y:1},y=Dr(i.convertOffsetParentRelativeRectToViewportRelativeRect?await i.convertOffsetParentRelativeRectToViewportRelativeRect({elements:o,rect:g,offsetParent:_,strategy:s}):g);return{top:(h.top-y.top+p.top)/v.y,bottom:(y.bottom-h.bottom+p.bottom)/v.y,left:(h.left-y.left+p.left)/v.x,right:(y.right-h.right+p.right)/v.x}}var Wa=50,Ga=async(e,t,n)=>{let{placement:r=`bottom`,strategy:i=`absolute`,middleware:a=[],platform:o}=n,s=o.detectOverflow?o:{...o,detectOverflow:Ua},c=await(o.isRTL==null?void 0:o.isRTL(t)),l=await o.getElementRects({reference:e,floating:t,strategy:i}),{x:u,y:d}=Ha(l,r,c),f=r,p=0,m={};for(let n=0;n<a.length;n++){let h=a[n];if(!h)continue;let{name:g,fn:_}=h,{x:v,y,data:b,reset:x}=await _({x:u,y:d,initialPlacement:r,placement:f,strategy:i,middlewareData:m,rects:l,platform:s,elements:{reference:e,floating:t}});u=v??u,d=y??d,m[g]={...m[g],...b},x&&p<Wa&&(p++,typeof x==`object`&&(x.placement&&(f=x.placement),x.rects&&(l=x.rects===!0?await o.getElementRects({reference:e,floating:t,strategy:i}):x.rects),{x:u,y:d}=Ha(l,f,c)),n=-1)}return{x:u,y:d,placement:f,strategy:i,middlewareData:m}},Ka=function(e){return e===void 0&&(e={}),{name:`flip`,options:e,async fn(t){var n;let{placement:r,middlewareData:i,rects:a,initialPlacement:o,platform:s,elements:c}=t,{mainAxis:l=!0,crossAxis:u=!0,fallbackPlacements:d,fallbackStrategy:f=`bestFit`,fallbackAxisSideDirection:p=`none`,flipAlignment:m=!0,...h}=cr(e,t);if((n=i.arrow)!=null&&n.alignmentOffset)return{};let g=lr(r),_=pr(o),v=lr(o)===o,y=await(s.isRTL==null?void 0:s.isRTL(c.floating)),b=d||(v||!m?[wr(o)]:gr(o)),x=p!==`none`;!d&&x&&b.push(...Cr(o,m,p,y));let S=[o,...b],C=await s.detectOverflow(t,h),w=[],T=i.flip?.overflows||[];if(l&&w.push(C[g]),u){let e=hr(r,a,y);w.push(C[e[0]],C[e[1]])}if(T=[...T,{placement:r,overflows:w}],!w.every(e=>e<=0)){let e=(i.flip?.index||0)+1,t=S[e];if(t&&(u!==`alignment`||_===pr(t)||T.every(e=>pr(e.placement)!==_||e.overflows[0]>0)))return{data:{index:e,overflows:T},reset:{placement:t}};let n=T.filter(e=>e.overflows[0]<=0).sort((e,t)=>e.overflows[1]-t.overflows[1])[0]?.placement;if(!n)switch(f){case`bestFit`:{let e=T.filter(e=>{if(x){let t=pr(e.placement);return t===_||t===`y`}return!0}).map(e=>[e.placement,e.overflows.filter(e=>e>0).reduce((e,t)=>e+t,0)]).sort((e,t)=>e[1]-t[1])[0]?.[0];e&&(n=e);break}case`initialPlacement`:n=o}if(r!==n)return{reset:{placement:n}}}return{}}}},qa=new Set([`left`,`top`]);async function Ja(e,t){let{placement:n,platform:r,elements:i}=e,a=await(r.isRTL==null?void 0:r.isRTL(i.floating)),o=lr(n),s=ur(n),c=pr(n)===`y`,l=qa.has(o)?-1:1,u=a&&c?-1:1,d=cr(t,e),{mainAxis:f,crossAxis:p,alignmentAxis:m}=typeof d==`number`?{mainAxis:d,crossAxis:0,alignmentAxis:null}:{mainAxis:d.mainAxis||0,crossAxis:d.crossAxis||0,alignmentAxis:d.alignmentAxis};return s&&typeof m==`number`&&(p=s===`end`?m*-1:m),c?{x:p*u,y:f*l}:{x:f*l,y:p*u}}var Ya=function(e){return e===void 0&&(e=0),{name:`offset`,options:e,async fn(t){var n;let{x:r,y:i,placement:a,middlewareData:o}=t,s=await Ja(t,e);return a===o.offset?.placement&&(n=o.arrow)!=null&&n.alignmentOffset?{}:{x:r+s.x,y:i+s.y,data:{...s,placement:a}}}}},Xa=function(e){return e===void 0&&(e={}),{name:`shift`,options:e,async fn(t){let{x:n,y:r,placement:i,platform:a}=t,{mainAxis:o=!0,crossAxis:s=!1,limiter:c={fn:e=>{let{x:t,y:n}=e;return{x:t,y:n}}},...l}=cr(e,t),u={x:n,y:r},d=await a.detectOverflow(t,l),f=pr(i),p=dr(f),m=u[p],h=u[f],g=(e,t)=>sr(t+d[e===`y`?`top`:`left`],t,t-d[e===`y`?`bottom`:`right`]);o&&(m=g(p,m)),s&&(h=g(f,h));let _=c.fn({...t,[p]:m,[f]:h});return{..._,data:{x:_.x-n,y:_.y-r,enabled:{[p]:o,[f]:s}}}}}},Za=function(e){return e===void 0&&(e={}),{options:e,fn(t){let{x:n,y:r,placement:i,rects:a,middlewareData:o}=t,{offset:s=0,mainAxis:c=!0,crossAxis:l=!0}=cr(e,t),u={x:n,y:r},d=pr(i),f=dr(d),p=u[f],m=u[d],h=cr(s,t),g=typeof h==`number`?{mainAxis:h,crossAxis:0}:{mainAxis:h.mainAxis??0,crossAxis:h.crossAxis??0};if(c){let e=f===`y`?`height`:`width`,t=a.reference[f]-a.floating[e]+g.mainAxis,n=a.reference[f]+a.reference[e]-g.mainAxis;p<t?p=t:p>n&&(p=n)}if(l){let e=f===`y`?`width`:`height`,t=qa.has(lr(i)),n=a.reference[d]-a.floating[e]+(t&&o.offset?.[d]||0)+(t?0:g.crossAxis),r=a.reference[d]+a.reference[e]+(t?0:o.offset?.[d]||0)-(t?g.crossAxis:0);m<n?m=n:m>r&&(m=r)}return{[f]:p,[d]:m}}}},Qa=function(e){return e===void 0&&(e={}),{name:`size`,options:e,async fn(t){let{placement:n,rects:r,platform:i,elements:a}=t,{apply:o=()=>{},...s}=cr(e,t),c=await i.detectOverflow(t,s),l=lr(n),u=ur(n),d=pr(n)===`y`,{width:f,height:p}=r.floating,m,h;l===`top`||l===`bottom`?(m=l,h=u===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?`start`:`end`)?`left`:`right`):(h=l,m=u===`end`?`top`:`bottom`);let g=p-c.top-c.bottom,_=f-c.left-c.right,v=tr(p-c[m],g),y=tr(f-c[h],_),b=t.middlewareData.shift,x=!b,S=v,C=y;b!=null&&b.enabled.x&&(C=_),b!=null&&b.enabled.y&&(S=g),x&&!u&&(d?C=f-2*nr(c.left,c.right):S=p-2*nr(c.top,c.bottom)),await o({...t,availableWidth:C,availableHeight:S});let w=await i.getDimensions(a.floating);return f!==w.width||p!==w.height?{reset:{rects:!0}}:{}}}};function $a(e){let t=ke(e),n=parseFloat(t.width)||0,r=parseFloat(t.height)||0,i=K(e),a=i?e.offsetWidth:n,o=i?e.offsetHeight:r,s=rr(n)!==a||rr(r)!==o;return s&&(n=a,r=o),{width:n,height:r,$:s}}function eo(e){return G(e)?e:e.contextElement}function to(e){let t=eo(e);if(!K(t))return ar(1);let n=t.getBoundingClientRect(),{width:r,height:i,$:a}=$a(t),o=(a?rr(n.width):n.width)/r,s=(a?rr(n.height):n.height)/i;return(!o||!Number.isFinite(o))&&(o=1),(!s||!Number.isFinite(s))&&(s=1),{x:o,y:s}}var no=ar(0);function ro(e){let t=me(e);return!De()||!t.visualViewport?no:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function io(e,t,n){return t===void 0&&(t=!1),!!n&&t&&n===me(e)}function ao(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);let i=e.getBoundingClientRect(),a=eo(e),o=ar(1);t&&(r?G(r)&&(o=to(r)):o=to(e));let s=io(a,n,r)?ro(a):ar(0),c=(i.left+s.x)/o.x,l=(i.top+s.y)/o.y,u=i.width/o.x,d=i.height/o.y;if(a&&r){let e=me(a),t=G(r)?me(r):r,n=e,i=Pe(n);for(;i&&t!==n;){let e=to(i),t=i.getBoundingClientRect(),r=ke(i),a=t.left+(i.clientLeft+parseFloat(r.paddingLeft))*e.x,o=t.top+(i.clientTop+parseFloat(r.paddingTop))*e.y;c*=e.x,l*=e.y,u*=e.x,d*=e.y,c+=a,l+=o,n=me(i),i=Pe(n)}}return Dr({width:u,height:d,x:c,y:l})}function oo(e,t){let n=Ae(e).scrollLeft;return t?t.left+n:ao(he(e)).left+n}function so(e,t){let n=e.getBoundingClientRect();return{x:n.left+t.scrollLeft-oo(e,n),y:n.top+t.scrollTop}}function co(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e,a=i===`fixed`,o=he(r),s=t?be(t.floating):!1;if(r===o||s&&a)return n;let c={scrollLeft:0,scrollTop:0},l=ar(1),u=ar(0),d=K(r);if((d||!a)&&((W(r)!==`body`||ve(o))&&(c=Ae(r)),d)){let e=ao(r);l=to(r),u.x=e.x+r.clientLeft,u.y=e.y+r.clientTop}let f=o&&!d&&!a?so(o,c):ar(0);return{width:n.width*l.x,height:n.height*l.y,x:n.x*l.x-c.scrollLeft*l.x+u.x+f.x,y:n.y*l.y-c.scrollTop*l.y+u.y+f.y}}function lo(e){return e.getClientRects?Array.from(e.getClientRects()):[]}function uo(e){let t=Ae(e),n=e.ownerDocument.body,r=nr(e.scrollWidth,e.clientWidth,n.scrollWidth,n.clientWidth),i=nr(e.scrollHeight,e.clientHeight,n.scrollHeight,n.clientHeight),a=-t.scrollLeft+oo(e),o=-t.scrollTop;return ke(n).direction===`rtl`&&(a+=nr(e.clientWidth,n.clientWidth)-r),{width:r,height:i,x:a,y:o}}var fo=25;function po(e,t,n){n===void 0&&(n=`viewport`);let r=n===`layoutViewport`,i=me(e),a=he(e),o=i.visualViewport,s=a.clientWidth,c=a.clientHeight,l=0,u=0;if(o){let e=!De()||t===`fixed`;r?e||(l=-o.offsetLeft,u=-o.offsetTop):(s=o.width,c=o.height,e&&(l=o.offsetLeft,u=o.offsetTop))}if(oo(a)<=0){let e=a.ownerDocument,t=e.body,n=getComputedStyle(t),r=e.compatMode===`CSS1Compat`&&parseFloat(n.marginLeft)+parseFloat(n.marginRight)||0,i=Math.abs(a.clientWidth-t.clientWidth-r),o=getComputedStyle(a).scrollbarGutter===`stable both-edges`?i/2:i;o<=fo&&(s-=o)}return{width:s,height:c,x:l,y:u}}function mo(e,t){let n=ao(e,!0,t===`fixed`),r=n.top+e.clientTop,i=n.left+e.clientLeft,a=to(e);return{width:e.clientWidth*a.x,height:e.clientHeight*a.y,x:i*a.x,y:r*a.y}}function ho(e,t,n){let r;if(t===`viewport`||t===`layoutViewport`)r=po(e,n,t);else if(t===`document`)r=uo(he(e));else if(G(t))r=mo(t,n);else{let n=ro(e);r={x:t.x-n.x,y:t.y-n.y,width:t.width,height:t.height}}return Dr(r)}function go(e,t){let n=t.get(e);if(n)return n;let r=Ne(e,[],!1).filter(e=>G(e)&&W(e)!==`body`),i=null,a=ke(e).position===`fixed`,o=a?je(e):e;for(;G(o)&&!Oe(o);){let e=ke(o),t=Te(o),n=i?i.position:a?`fixed`:``;!t&&(n===`fixed`||n===`absolute`&&e.position===`static`)?r=r.filter(e=>e!==o):i=e,o=je(o)}return t.set(e,r),r}function _o(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e,a=[...n===`clippingAncestors`?be(t)?[]:go(t,this._c):[].concat(n),r],o=ho(t,a[0],i),s=o.top,c=o.right,l=o.bottom,u=o.left;for(let e=1;e<a.length;e++){let n=ho(t,a[e],i);s=nr(n.top,s),c=tr(n.right,c),l=tr(n.bottom,l),u=nr(n.left,u)}return{width:c-u,height:l-s,x:u,y:s}}function vo(e){let{width:t,height:n}=$a(e);return{width:t,height:n}}function yo(e,t,n){let r=K(t),i=he(t),a=n===`fixed`,o=ao(e,!0,a,t),s={scrollLeft:0,scrollTop:0},c=ar(0);if((r||!a)&&((W(t)!==`body`||ve(i))&&(s=Ae(t)),r)){let e=ao(t,!0,a,t);c.x=e.x+t.clientLeft,c.y=e.y+t.clientTop}!r&&i&&(c.x=oo(i));let l=i&&!r&&!a?so(i,s):ar(0);return{x:o.left+s.scrollLeft-c.x-l.x,y:o.top+s.scrollTop-c.y-l.y,width:o.width,height:o.height}}function bo(e){return ke(e).position===`static`}function xo(e,t){if(!K(e)||ke(e).position===`fixed`)return null;if(t)return t(e);let n=e.offsetParent;return he(e)===n&&(n=n.ownerDocument.body),n}function So(e,t){let n=me(e);if(be(e))return n;if(!K(e)){let t=je(e);for(;t&&!Oe(t);){if(G(t)&&!bo(t))return t;t=je(t)}return n}let r=xo(e,t);for(;r&&ye(r)&&bo(r);)r=xo(r,t);return r&&Oe(r)&&bo(r)&&!Te(r)?n:r||Ee(e)||n}var Co=async function(e){let t=this.getOffsetParent||So,n=this.getDimensions,r=await n(e.floating);return{reference:yo(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function wo(e){return ke(e).direction===`rtl`}var To={convertOffsetParentRelativeRectToViewportRelativeRect:co,getDocumentElement:he,getClippingRect:_o,getOffsetParent:So,getElementRects:Co,getClientRects:lo,getDimensions:vo,getScale:to,isElement:G,isRTL:wo};function Eo(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function Do(e,t,n){let r=null,i,a=he(e);function o(){var e;clearTimeout(i),(e=r)==null||e.disconnect(),r=null}function s(n,c){n===void 0&&(n=!1),c===void 0&&(c=1),o();let l=e.getBoundingClientRect(),{left:u,top:d,width:f,height:p}=l;if(n||t(),!f||!p)return;let m=ir(d),h=ir(a.clientWidth-(u+f)),g=ir(a.clientHeight-(d+p)),_=ir(u),v={rootMargin:-m+`px `+-h+`px `+-g+`px `+-_+`px`,threshold:nr(0,tr(1,c))||1},y=!0;function b(t){let n=t[0].intersectionRatio;if(!Eo(l,e.getBoundingClientRect()))return s();if(n!==c){if(!y)return s();n?s(!1,n):i=setTimeout(()=>{s(!1,1e-7)},1e3)}y=!1}try{r=new IntersectionObserver(b,{...v,root:a.ownerDocument})}catch{r=new IntersectionObserver(b,v)}r.observe(e)}let c=me(e),l=()=>s(n);return c.addEventListener(`resize`,l),s(!0),()=>{c.removeEventListener(`resize`,l),o()}}function Oo(e,t,n,r){r===void 0&&(r={});let{ancestorScroll:i=!0,ancestorResize:a=!0,elementResize:o=typeof ResizeObserver==`function`,layoutShift:s=typeof IntersectionObserver==`function`,animationFrame:c=!1}=r,l=eo(e),u=i||a?[...l?Ne(l):[],...t?Ne(t):[]]:[];u.forEach(e=>{i&&e.addEventListener(`scroll`,n),a&&e.addEventListener(`resize`,n)});let d=l&&s?Do(l,n,a):null,f=-1,p=null;o&&(p=new ResizeObserver(e=>{let[r]=e;r&&r.target===l&&p&&t&&(p.unobserve(t),cancelAnimationFrame(f),f=requestAnimationFrame(()=>{var e;(e=p)==null||e.observe(t)})),n()}),l&&!c&&p.observe(l),t&&p.observe(t));let m,h=c?ao(e):null;c&&g();function g(){let t=ao(e);h&&!Eo(h,t)&&n(),h=t,m=requestAnimationFrame(g)}return n(),()=>{var e;u.forEach(e=>{i&&e.removeEventListener(`scroll`,n),a&&e.removeEventListener(`resize`,n)}),d?.(),(e=p)==null||e.disconnect(),p=null,c&&cancelAnimationFrame(m)}}var ko=Ya,Ao=Xa,jo=Ka,Mo=Qa,No=Za,Po=(e,t,n)=>{let r=new Map,i=n??{},a={...To,...i.platform,_c:r};return Ga(e,t,{...i,platform:a})},Fo=typeof document<`u`?l.useLayoutEffect:function(){};function Io(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(!Io(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;){let n=i[r];if(!(n===`_owner`&&e.$$typeof)&&!Io(e[n],t[n]))return!1}return!0}return e!==e&&t!==t}function Lo(e){return typeof window>`u`?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function Ro(e,t){let n=Lo(e);return Math.round(t*n)/n}function zo(e){let t=l.useRef(e);return Fo(()=>{t.current=e}),t}function Bo(e){e===void 0&&(e={});let{placement:t=`bottom`,strategy:n=`absolute`,middleware:r=[],platform:i,elements:{reference:a,floating:o}={},transform:s=!0,whileElementsMounted:c,open:u}=e,[d,f]=l.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[p,m]=l.useState(r);Io(p,r)||m(r);let[h,g]=l.useState(null),[_,v]=l.useState(null),y=l.useCallback(e=>{e!==C.current&&(C.current=e,g(e))},[]),b=l.useCallback(e=>{e!==w.current&&(w.current=e,v(e))},[]),x=a||h,S=o||_,C=l.useRef(null),w=l.useRef(null),T=l.useRef(d),E=c!=null,D=zo(c),O=zo(i),k=zo(u),A=l.useCallback(()=>{if(!C.current||!w.current)return;let e={placement:t,strategy:n,middleware:p};O.current&&(e.platform=O.current),Po(C.current,w.current,e).then(e=>{let t={...e,isPositioned:k.current!==!1};j.current&&!Io(T.current,t)&&(T.current=t,ua.flushSync(()=>{f(t)}))})},[p,t,n,O,k]);Fo(()=>{u===!1&&T.current.isPositioned&&(T.current.isPositioned=!1,f(e=>({...e,isPositioned:!1})))},[u]);let j=l.useRef(!1);Fo(()=>(j.current=!0,()=>{j.current=!1}),[]),Fo(()=>{if(x&&(C.current=x),S&&(w.current=S),x&&S){if(D.current)return D.current(x,S,A);A()}},[x,S,A,D,E]);let M=l.useMemo(()=>({reference:C,floating:w,setReference:y,setFloating:b}),[y,b]),N=l.useMemo(()=>({reference:x,floating:S}),[x,S]),P=l.useMemo(()=>{let e={position:n,left:0,top:0};if(!N.floating)return e;let t=Ro(N.floating,d.x),r=Ro(N.floating,d.y);return s?{...e,transform:`translate(`+t+`px, `+r+`px)`,...Lo(N.floating)>=1.5&&{willChange:`transform`}}:{position:n,left:t,top:r}},[n,s,N.floating,d.x,d.y]);return l.useMemo(()=>({...d,update:A,refs:M,elements:N,floatingStyles:P}),[d,A,M,N,P])}var Vo=(e,t)=>{let n=ko(e);return{name:n.name,fn:n.fn,options:[e,t]}},Ho=(e,t)=>{let n=Ao(e);return{name:n.name,fn:n.fn,options:[e,t]}},Uo=(e,t)=>({fn:No(e).fn,options:[e,t]}),Wo=(e,t)=>{let n=jo(e);return{name:n.name,fn:n.fn,options:[e,t]}},Go=(e,t)=>{let n=Mo(e);return{name:n.name,fn:n.fn,options:[e,t]}},Ko=t((e=>{var t=r();function n(e,t){return e===t&&(e!==0||1/e==1/t)||e!==e&&t!==t}var i=typeof Object.is==`function`?Object.is:n,a=t.useState,o=t.useEffect,s=t.useLayoutEffect,c=t.useDebugValue;function l(e,t){var n=t(),r=a({inst:{value:n,getSnapshot:t}}),i=r[0].inst,l=r[1];return s(function(){i.value=n,i.getSnapshot=t,u(i)&&l({inst:i})},[e,n,t]),o(function(){return u(i)&&l({inst:i}),e(function(){u(i)&&l({inst:i})})},[e]),c(n),n}function u(e){var t=e.getSnapshot;e=e.value;try{var n=t();return!i(e,n)}catch{return!0}}function d(e,t){return t()}var f=typeof window>`u`||window.document===void 0||window.document.createElement===void 0?d:l;e.useSyncExternalStore=t.useSyncExternalStore===void 0?f:t.useSyncExternalStore})),qo=t(((e,t)=>{t.exports=Ko()})),Jo=t((e=>{var t=r(),n=qo();function i(e,t){return e===t&&(e!==0||1/e==1/t)||e!==e&&t!==t}var a=typeof Object.is==`function`?Object.is:i,o=n.useSyncExternalStore,s=t.useRef,c=t.useEffect,l=t.useMemo,u=t.useDebugValue;e.useSyncExternalStoreWithSelector=function(e,t,n,r,i){var d=s(null);if(d.current===null){var f={hasValue:!1,value:null};d.current=f}else f=d.current;d=l(function(){function e(e){if(!o){if(o=!0,s=e,e=r(e),i!==void 0&&f.hasValue){var t=f.value;if(i(t,e))return c=t}return c=e}if(t=c,a(s,e))return t;var n=r(e);return i!==void 0&&i(t,n)?(s=e,t):(s=e,c=n)}var o=!1,s,c,l=n===void 0?null:n;return[function(){return e(t())},l===null?void 0:function(){return e(l())}]},[t,n,r,i]);var p=o(e,d[0],d[1]);return c(function(){f.hasValue=!0,f.value=p},[p]),u(p),p}})),Yo=t(((e,t)=>{t.exports=Jo()})),Xo=[],Zo=void 0;function Qo(){return Zo}function $o(e){Xo.push(e)}function es(e){let t=(t,n)=>{let r=Ze(ns).current,i;try{Zo=r;for(let e of Xo)e.before(r);i=e(t,n);for(let e of Xo)e.after(r);r.didInitialize=!0}finally{Zo=void 0}return i};return t.displayName=e.displayName||e.name,t}function ts(e){return l.forwardRef(es(e))}function ns(){return{didInitialize:!1}}var rs=qo(),is=Yo(),as=Mi(19)?cs:ls;function os(e,t,n,r,i){return as(e,t,n,r,i)}function ss(e,t,n,r,i){let a=l.useCallback(()=>t(e.getSnapshot(),n,r,i),[e,t,n,r,i]);return(0,rs.useSyncExternalStore)(e.subscribe,a,a)}$o({before(e){e.syncIndex=0,e.didInitialize||(e.syncTick=1,e.syncHooks=[],e.didChangeStore=!0,e.getSnapshot=()=>{let t=!1;for(let n=0;n<e.syncHooks.length;n+=1){let r=e.syncHooks[n],i=r.selector(r.store.state,r.a1,r.a2,r.a3);Object.is(r.value,i)||(t=!0,r.value=i)}return t&&(e.syncTick+=1),e.syncTick})},after(e){e.syncHooks.length>0&&(e.didChangeStore&&(e.didChangeStore=!1,e.subscribe=t=>{let n=new Set;for(let t of e.syncHooks)n.add(t.store);let r=[];for(let e of n)r.push(e.subscribe(t));return()=>{for(let e of r)e()}}),(0,rs.useSyncExternalStore)(e.subscribe,e.getSnapshot,e.getSnapshot))}});function cs(e,t,n,r,i){let a=Qo();if(!a)return ss(e,t,n,r,i);let o=a.syncIndex;a.syncIndex+=1;let s;return a.didInitialize?(s=a.syncHooks[o],(s.store!==e||s.selector!==t||!Object.is(s.a1,n)||!Object.is(s.a2,r)||!Object.is(s.a3,i))&&(s.store!==e&&(a.didChangeStore=!0),s.store=e,s.selector=t,s.a1=n,s.a2=r,s.a3=i,s.value=t(e.getSnapshot(),n,r,i))):(s={store:e,selector:t,a1:n,a2:r,a3:i,value:t(e.getSnapshot(),n,r,i)},a.syncHooks.push(s)),s.value}function ls(e,t,n,r,i){return(0,is.useSyncExternalStoreWithSelector)(e.subscribe,e.getSnapshot,e.getSnapshot,e=>t(e,n,r,i))}var us=class{static create(e){return new this(e)}constructor(e){this.state=e,this.listeners=new Set,this.updateTick=0}subscribe=e=>(this.listeners.add(e),()=>{this.listeners.delete(e)});getSnapshot=()=>this.state;setState(e){if(this.state===e)return;this.state=e,this.updateTick+=1;let t=this.updateTick;for(let n of this.listeners){if(t!==this.updateTick)return;n(e)}}update(e){for(let t in e)if(!Object.is(this.state[t],e[t])){this.setState({...this.state,...e});return}}set(e,t){Object.is(this.state[e],t)||this.setState({...this.state,[e]:t})}notifyAll(){let e={...this.state};this.setState(e)}use(e,t,n,r){return os(this,e,t,n,r)}},ds=class extends us{constructor(e,t={},n){super(e),this.context=t,this.selectors=n}useSyncedValue(e,t){l.useDebugValue(e);let n=this;U(()=>{n.state[e]!==t&&n.set(e,t)},[n,e,t])}useSyncedValueWithCleanup(e,t){let n=this;U(()=>(n.state[e]!==t&&n.set(e,t),()=>{n.set(e,void 0)}),[n,e,t])}useSyncedValues(e){let t=this;U(()=>{t.update(e)},[t,...Object.values(e)])}useControlledProp(e,t){l.useDebugValue(e);let n=this,r=t!==void 0;U(()=>{r&&!Object.is(n.state[e],t)&&n.setState({...n.state,[e]:t})},[n,e,t,r])}select(e,t,n,r){let i=this.selectors[e];return i(this.state,t,n,r)}useState(e,t,n,r){return l.useDebugValue(e),os(this,this.selectors[e],t,n,r)}useContextCallback(e,t){l.useDebugValue(e);let n=$(t??Qe);this.context[e]=n}useStateSetter(e){let t=l.useRef(void 0);return t.current===void 0&&(t.current=t=>{this.set(e,t)}),t.current}observe(e,t){let n;n=typeof e==`function`?e:this.selectors[e];let r=n(this.state);return t(r,r,this),this.subscribe(e=>{let i=n(e);if(!Object.is(r,i)){let e=r;r=i,t(i,e,this)}})}},fs={open:e=>e.open,transitionStatus:e=>e.transitionStatus,domReferenceElement:e=>e.domReferenceElement,referenceElement:e=>e.positionReference??e.referenceElement,floatingElement:e=>e.floatingElement,floatingId:e=>e.floatingId},ps=class extends ds{constructor(e){let{syncOnly:t,nested:n,onOpenChange:r,triggerElements:i,...a}=e;super({...a,positionReference:a.referenceElement,domReferenceElement:a.referenceElement},{onOpenChange:r,dataRef:{current:{}},events:ga(),nested:n,triggerElements:i},fs),this.syncOnly=t}syncOpenEvent=(e,t)=>{(!e||!this.state.open||t!=null&&wt(t))&&(this.context.dataRef.current.openEvent=e?t:void 0)};dispatchOpenChange=(e,t)=>{this.syncOpenEvent(e,t.event);let n={open:e,reason:t.reason,nativeEvent:t.event,nested:this.context.nested,triggerElement:t.trigger};this.context.events.emit(`openchange`,n)};setOpen=(e,t)=>{if(this.syncOnly){this.context.onOpenChange?.(e,t);return}this.dispatchOpenChange(e,t),this.context.onOpenChange?.(e,t)}};function ms(e){let{popupStore:t,treatPopupAsFloatingElement:n=!1,floatingRootContext:r,floatingId:i,nested:a,onOpenChange:o}=e,s=t.useState(`open`),c=t.useState(`activeTriggerElement`),u=t.useState(n?`popupElement`:`positionerElement`),d=t.context.triggerElements,f=o,p=l.useRef(null);r===void 0&&p.current===null&&(p.current=new ps({open:s,transitionStatus:void 0,referenceElement:c,floatingElement:u,triggerElements:d,onOpenChange:f,floatingId:i,syncOnly:!0,nested:a}));let m=r??p.current;return t.useSyncedValue(`floatingId`,i),U(()=>{let e={open:s,floatingId:i,referenceElement:c,floatingElement:u};G(c)&&(e.domReferenceElement=c),m.state.positionReference===m.state.referenceElement&&(e.positionReference=c),m.update(e)},[s,i,c,u,m]),m.context.onOpenChange=f,m.context.nested=a,m}function hs(e,t=!1,n=!1,r=!1){let[i,a]=l.useState(e&&t?`idle`:void 0),[o,s]=l.useState(e&&!r);return e&&!o&&(s(!0),a(`starting`)),!e&&o&&i!==`ending`&&!n&&a(`ending`),!e&&!o&&i===`ending`&&a(void 0),U(()=>{if(!e&&o&&i!==`ending`&&n){let e=st.request(()=>{a(`ending`)});return()=>{st.cancel(e)}}},[e,o,i,n]),U(()=>{if(!e||t)return;let n=st.request(()=>{a(void 0)});return()=>{st.cancel(n)}},[t,e]),U(()=>{if(!e||!t)return;e&&o&&i!==`idle`&&a(`starting`);let n=st.request(()=>{a(`idle`)});return()=>{st.cancel(n)}},[t,e,o,i]),{mounted:o,setMounted:s,transitionStatus:i}}var gs=null;function _s(e){if(!gs){let e=[];gs=e,queueMicrotask(()=>{gs=null,ua.flushSync(()=>{for(let t of e)t()})})}gs.push(e)}function vs(e,t=!1,n=!1){let r=ct();return $((i,a=null)=>{r.cancel();let o=Ta(e);if(o==null)return;let s=o,c=()=>{if(!n){ua.flushSync(i);return}_s(()=>{a?.aborted||i()})};if(typeof s.getAnimations!=`function`||globalThis.BASE_UI_ANIMATIONS_DISABLED){i();return}function l(){Promise.all(s.getAnimations().map(e=>e.finished)).then(()=>{a?.aborted||c()},()=>{if(!a?.aborted){if(s.getAnimations().some(e=>e.pending||e.playState!==`finished`)){l();return}c()}})}if(t){let e=Nt;if(!s.hasAttribute(e)){r.request(l);return}let t=new MutationObserver(()=>{s.hasAttribute(e)||(t.disconnect(),l())});t.observe(s,{attributes:!0,attributeFilter:[e]}),a?.addEventListener(`abort`,()=>t.disconnect(),{once:!0});return}r.request(l)})}function ys(e){let{enabled:t=!0,open:n,ref:r,batch:i=!1,onComplete:a}=e,o=$(a),s=vs(r,n,i);l.useEffect(()=>{if(!t)return;let e=new AbortController;return s(o,e.signal),()=>{e.abort()}},[t,n,o,s])}var bs={tabIndex:-1,[Dt]:``};function xs(e){return t=>t!==`touch`||e.current}function Ss(e,t=!1){let n=Oi(),r=ba()!=null,i=Ze(()=>e(n,r)).current;return ms({popupStore:i,treatPopupAsFloatingElement:t,floatingRootContext:i.state.floatingRootContext,floatingId:n,nested:r,onOpenChange:i.setOpen}),i}function Cs({handle:e,store:t}){return U(()=>e.attachStore(t),[e,t]),null}function ws(e){let t=e.context.triggerElements.size;e.select(`open`)&&e.state.triggerCount!==t&&e.set(`triggerCount`,t)}function Ts(e,t){let n=l.useRef(null);return $(r=>{let i=n.current;if(i!==null){if(i.element===r&&i.store===t&&i.id===e)return;n.current=null;let a=i.store;a.context.triggerElements.getById(i.id)===i.element&&(a.context.triggerElements.delete(i.id),ws(a))}r!==null&&e!==void 0&&(n.current={store:t,id:e,element:r},t.context.triggerElements.add(e,r),ws(t))})}function Es(e,t,n,r=!1){let i=e.preventUnmountingOnClose;t?i=!1:r&&(i=!0);let a=n?.id??null,o=e.activeTriggerId,s=e.activeTriggerElement;return(a||t)&&(o=a,s=n??null),{open:t,preventUnmountingOnClose:i,activeTriggerId:o,activeTriggerElement:s}}function Ds(e){let t=!1;return e.preventUnmountOnClose=()=>{t=!0},()=>t}function Os(e,t,n,r={}){let i=n.reason,a=i===hn,o=t&&i===`trigger-focus`,s=!t&&(i===`trigger-press`||i===`escape-key`),c=Ds(n);if(e.context.onOpenChange?.(t,n),n.isCanceled)return;r.onBeforeDispatch?.(),e.state.floatingRootContext.dispatchOpenChange(t,n);let l=()=>{let i=Es(e.state,t,n.trigger,c()),l={...r.extraState,...i};o?l.instantType=`focus`:s?l.instantType=`dismiss`:a&&(l.instantType=void 0),e.update(l)};a?ua.flushSync(l):l()}function ks(e,t,n,r){let i=n.useState(`isMountedByTrigger`,e),a=Ts(e,n),o=$(t=>{let i=n.select(`open`),a=n.select(`activeTriggerId`);if(a===e){let e={activeTriggerElement:t,...i?r:null};n.update(e);return}if(a==null&&i){let i={activeTriggerId:e??null,activeTriggerElement:t,...r};n.update(i)}}),s=$(e=>{a(e),e&&o(e)});return U(()=>(s(t.current),()=>s(null)),[s,t,n,e]),U(()=>{if(i){let e={activeTriggerElement:t.current,...r};n.update(e)}},[i,n,t,...Object.values(r)]),{registerTrigger:s,isMountedByThisTrigger:i}}function As(e,t={}){let{closeOnActiveTriggerUnmount:n=!1}=t,r=l.useRef(null),i=e.useState(`open`);U(()=>{if(!i){r.current=null,e.state.triggerCount!==0&&e.set(`triggerCount`,0);return}let t=e.context.triggerElements.size,a={};e.state.triggerCount!==t&&(a.triggerCount=t);let o=e.select(`activeTriggerId`),s=null;if(o){let t=e.context.triggerElements.getById(o);if(t)r.current=o,t!==e.state.activeTriggerElement&&(a.activeTriggerElement=t);else{for(let[t,n]of e.context.triggerElements.entries())if(n===e.state.activeTriggerElement){a.activeTriggerId=t,a.activeTriggerElement=n,r.current=t;break}a.activeTriggerId===void 0&&(r.current===o?s=o:r.current=null)}}else r.current=null;if(!s&&!o&&t===1){let t=e.context.triggerElements.entries().next();if(!t.done){let[e,n]=t.value;a.activeTriggerId=e,a.activeTriggerElement=n,r.current=e}}(a.triggerCount!==void 0||a.activeTriggerId!==void 0||a.activeTriggerElement!==void 0)&&e.update(a),s&&n&&queueMicrotask(()=>{if(e.select(`open`)&&e.select(`activeTriggerId`)===s&&!e.context.triggerElements.getById(s)){let t=Z(pn);e.setOpen(!1,t),t.isCanceled||e.update({activeTriggerId:null,activeTriggerElement:null})}})},[i,e,e.useState(`triggerCount`),e.useState(`activeTriggerId`),e.useState(`activeTriggerElement`),n])}function js(e,t,n,r){let{mounted:i,setMounted:a,transitionStatus:o}=hs(e,!1,!1,r),s=t.useState(`preventUnmountingOnClose`),c=!e&&s;t.useSyncedValues({mounted:i,transitionStatus:o,preventUnmountingOnClose:c});let l=$(()=>{a(!1),t.update({activeTriggerId:null,activeTriggerElement:null,mounted:!1,preventUnmountingOnClose:!1}),n?.(),t.context.onOpenChangeComplete?.(!1)});return ys({enabled:i&&!e&&!c,open:e,ref:t.context.popupRef,onComplete(){e||l()}}),{forceUnmount:l,transitionStatus:o}}function Ms(e,t){e.useSyncedValues(t),U(()=>()=>{e.update({activeTriggerProps:et,inactiveTriggerProps:et,popupProps:et})},[e])}function Ns(e,t){U(()=>{!t&&e.state.openMethod!==null&&e.set(`openMethod`,null)},[t,e]),U(()=>()=>{e.state.openMethod!==null&&e.set(`openMethod`,null)},[e])}var Ps=class{constructor(){this.idMap=new Map}add(e,t){this.idMap.set(e,t)}delete(e){this.idMap.delete(e)}hasElement(e){for(let t of this.idMap.values())if(t===e)return!0;return!1}hasMatchingElement(e){for(let t of this.idMap.values())if(e(t))return!0;return!1}getById(e){return this.idMap.get(e)}entries(){return this.idMap.entries()}elements(){return this.idMap.values()}get size(){return this.idMap.size}};function Fs(e,t,n=!1){return{open:!1,openProp:void 0,mounted:!1,transitionStatus:void 0,floatingRootContext:new ps({open:!1,transitionStatus:void 0,floatingElement:null,referenceElement:null,triggerElements:e,floatingId:t,syncOnly:!0,nested:n,onOpenChange:void 0}),floatingId:t,triggerCount:0,preventUnmountingOnClose:!1,payload:void 0,activeTriggerId:null,activeTriggerElement:null,triggerIdProp:void 0,popupElement:null,positionerElement:null,activeTriggerProps:et,inactiveTriggerProps:et,popupProps:et}}var Is=e=>e.triggerIdProp??e.activeTriggerId,Ls=e=>e.openProp??e.open,Rs=e=>(e.popupElement?.id??e.floatingId)||void 0;function zs(e,t){return t!==void 0&&Ls(e)&&Is(e)===t}function Bs(e,t){return zs(e,t)?!0:t!==void 0&&Ls(e)&&Is(e)==null&&e.triggerCount===1}var Vs={open:Ls,mounted:e=>e.mounted,transitionStatus:e=>e.transitionStatus,floatingRootContext:e=>e.floatingRootContext,triggerCount:e=>e.triggerCount,preventUnmountingOnClose:e=>e.preventUnmountingOnClose,payload:e=>e.payload,activeTriggerId:Is,activeTriggerElement:e=>e.mounted?e.activeTriggerElement:null,popupId:Rs,isTriggerActive:(e,t)=>t!==void 0&&Is(e)===t,isOpenedByTrigger:(e,t)=>zs(e,t),isMountedByTrigger:(e,t)=>t!==void 0&&Is(e)===t&&e.mounted,triggerProps:(e,t)=>t?e.activeTriggerProps:e.inactiveTriggerProps,triggerPopupId:(e,t)=>Bs(e,t)?Rs(e):void 0,popupProps:e=>e.popupProps,popupElement:e=>e.popupElement,positionerElement:e=>e.positionerElement};function Hs(e){let t=l.useCallback(t=>e===void 0?Qe:e.subscribeStore(t),[e]),n=l.useCallback(()=>e===void 0?void 0:e.store,[e]);return(0,rs.useSyncExternalStore)(t,n,()=>e?.serverStore)}function Us(e){let{open:t=!1,onOpenChange:n,elements:r={}}=e,i=Oi(),a=ba()!=null,o=Ze(()=>new ps({open:t,transitionStatus:void 0,onOpenChange:n,referenceElement:r.reference??null,floatingElement:r.floating??null,triggerElements:new Ps,floatingId:i,syncOnly:!1,nested:a})).current;return U(()=>{let e={open:t,floatingId:i};r.reference!==void 0&&(e.referenceElement=r.reference,e.domReferenceElement=G(r.reference)?r.reference:null),r.floating!==void 0&&(e.floatingElement=r.floating),o.update(e)},[t,i,r.reference,r.floating,o]),o.context.onOpenChange=n,o.context.nested=a,o}function Ws(e){return Gs(e,e.rootContext)}function Gs(e,t){let{nodeId:n,externalTree:r}=e,i=t.useState(`referenceElement`),a=t.useState(`floatingElement`),o=t.useState(`domReferenceElement`),s=t.useState(`open`),c=t.useState(`floatingId`),[u,d]=l.useState(null),[f,p]=l.useState(void 0),[m,h]=l.useState(void 0),g=l.useRef(null),_=xa(r),v=l.useMemo(()=>({reference:i,floating:a,domReference:o}),[i,a,o]),y=Bo({...e,elements:{...v,...u&&{reference:u}}}),b=G(f)?f:null,x=m===void 0?t.state.floatingElement:m;t.useSyncedValue(`referenceElement`,f??null),t.useSyncedValue(`domReferenceElement`,f===void 0?o:b),t.useSyncedValue(`floatingElement`,x);let S=l.useCallback(e=>{let t=G(e)?{getBoundingClientRect:()=>e.getBoundingClientRect(),getClientRects:()=>e.getClientRects(),contextElement:e}:e;d(t),y.refs.setReference(t)},[y.refs]),C=l.useCallback(e=>{(G(e)||e===null)&&(g.current=e,p(e)),(G(y.refs.reference.current)||y.refs.reference.current===null||e!==null&&!G(e))&&y.refs.setReference(e)},[y.refs,p]),w=l.useCallback(e=>{h(e),y.refs.setFloating(e)},[y.refs]),T=l.useMemo(()=>({...y.refs,setReference:C,setFloating:w,setPositionReference:S,domReference:g}),[y.refs,C,w,S]),E=l.useMemo(()=>({...y.elements,domReference:o}),[y.elements,o]),D=l.useMemo(()=>({...y,dataRef:t.context.dataRef,open:s,onOpenChange:t.setOpen,events:t.context.events,floatingId:c,refs:T,elements:E,nodeId:n,rootStore:t}),[y,T,E,n,t,s,c]);return U(()=>{o&&(g.current=o)},[o]),U(()=>{t.context.dataRef.current.floatingContext=D;let e=_?.nodesRef.current.find(e=>e.id===n);e&&(e.context=D)}),l.useMemo(()=>({...y,context:D,refs:T,elements:E,rootStore:t}),[y,T,E,D,t])}var Ks=We&&Ke;function qs(e,t={}){let{enabled:n=!0,delay:r}=t,i=`rootStore`in e?e.rootStore:e,{events:a,dataRef:o}=i.context,s=l.useRef(!1),c=l.useRef(null),u=l.useRef(!0),d=it();l.useEffect(()=>{let e=i.select(`domReferenceElement`);if(!n)return;let t=me(e);function r(){let e=i.select(`domReferenceElement`);!i.select(`open`)&&K(e)&&e===Tt(J(e))&&(s.current=!0,c.current=e)}function a(){u.current=!0}function o(){u.current=!1}return Ln(q(t,`blur`,r),Ks&&q(t,`keydown`,a,!0),Ks&&q(t,`pointerdown`,o,!0))},[i,n]),l.useEffect(()=>{if(!n)return;function e(e){if(e.reason===`trigger-press`||e.reason===`escape-key`){let e=i.select(`domReferenceElement`);G(e)&&(c.current=e,s.current=!0)}}return a.on(`openchange`,e),()=>{a.off(`openchange`,e)}},[a,n,i]);let f=l.useMemo(()=>{function e(){s.current=!1,c.current=null}return{onMouseLeave(){e()},onFocus(t){let n=t.currentTarget;if(s.current){if(c.current===n)return;e()}let a=Et(t.nativeEvent);if(G(a)){if(Ks&&!t.relatedTarget){if(!u.current&&!nn(a))return}else if(!on(a))return}let o=$t(t.relatedTarget,i.context.triggerElements),{nativeEvent:l,currentTarget:f}=t,p=typeof r==`function`?r():r;if(i.select(`open`)&&o||p===0||p===void 0){i.setOpen(!0,Z(gn,l,f));return}d.start(p,()=>{s.current||i.setOpen(!0,Z(gn,l,f))})},onBlur(t){e();let n=t.relatedTarget,r=t.nativeEvent,a=G(n)&&n.hasAttribute(ui(`focus-guard`))&&n.getAttribute(`data-type`)===`outside`;d.start(0,()=>{let e=i.select(`domReferenceElement`),t=Tt(J(e));(n||t!==e)&&(X(o.current.floatingContext?.refs.floating.current,t)||X(e,t)||a||$t(n??t,i.context.triggerElements)||i.setOpen(!1,Z(gn,r)))})}}},[o,r,i,d]);return l.useMemo(()=>n?{reference:f,trigger:f}:{},[n,f])}var Js=class e{constructor(){this.pointerType=void 0,this.interactedInside=!1,this.handler=void 0,this.blockMouseMove=!0,this.performedPointerEventsMutation=!1,this.pointerEventsScopeElement=null,this.pointerEventsReferenceElement=null,this.pointerEventsFloatingElement=null,this.restTimeoutPending=!1,this.openChangeTimeout=new rt,this.restTimeout=new rt,this.handleCloseOptions=void 0}static create(){return new e}dispose=()=>{this.openChangeTimeout.clear(),this.restTimeout.clear()};disposeEffect=()=>this.dispose},Ys=new WeakMap;function Xs(e){if(!e.performedPointerEventsMutation)return;let t=e.pointerEventsScopeElement;t&&Ys.get(t)===e&&(e.pointerEventsScopeElement?.style.removeProperty(`pointer-events`),e.pointerEventsReferenceElement?.style.removeProperty(`pointer-events`),e.pointerEventsFloatingElement?.style.removeProperty(`pointer-events`),Ys.delete(t)),e.performedPointerEventsMutation=!1,e.pointerEventsScopeElement=null,e.pointerEventsReferenceElement=null,e.pointerEventsFloatingElement=null}function Zs(e,t){let{scopeElement:n,referenceElement:r,floatingElement:i}=t,a=Ys.get(n);a&&a!==e&&Xs(a),Xs(e),e.performedPointerEventsMutation=!0,e.pointerEventsScopeElement=n,e.pointerEventsReferenceElement=r,e.pointerEventsFloatingElement=i,Ys.set(n,e),n.style.pointerEvents=`none`,r.style.pointerEvents=`auto`,i.style.pointerEvents=`auto`}function Qs(e){let t=e.context.dataRef.current,n=Ze(()=>t.hoverInteractionState??Js.create()).current;return t.hoverInteractionState||=n,tt(t.hoverInteractionState.disposeEffect),t.hoverInteractionState}function $s(e,t={}){let{enabled:n=!0,closeDelay:r=0,nodeId:i}=t,a=`rootStore`in e?e.rootStore:e,o=a.useState(`open`),s=a.useState(`floatingElement`),c=a.useState(`domReferenceElement`),{dataRef:u}=a.context,d=xa(),f=ba(),p=Qs(a),m=it(),h=$(()=>dn(u.current.openEvent?.type,p.interactedInside)),g=$(()=>fn(u.current.openEvent?.type)),_=$(()=>{Xs(p)});U(()=>{o||(p.pointerType=void 0,p.restTimeoutPending=!1,p.interactedInside=!1,_())},[o,p,_]),l.useEffect(()=>_,[_]),U(()=>{if(n&&o&&p.handleCloseOptions?.blockPointerEvents&&g()&&G(c)&&s){let e=c,t=s,n=J(s),r=d?.nodesRef.current.find(e=>e.id===f)?.context?.elements.floating;r&&(r.style.pointerEvents=``);let i=p.pointerEventsScopeElement===t?null:p.pointerEventsScopeElement,a=r===t?null:r,o=p.handleCloseOptions?.getScope?.()??i??a??e.closest(`[data-rootownerid]`)??n.body;return Zs(p,{scopeElement:o,referenceElement:e,floatingElement:t}),()=>{_()}}},[n,o,c,s,p,g,d,f,_]),l.useEffect(()=>{if(!n)return;function e(){return!!(d&&f&&ci(d.nodesRef.current,f).length>0)}function t(e){let t=ln(r,`close`,p.pointerType),n=()=>{a.setOpen(!1,Z(hn,e)),d?.events.emit(`floating.closed`,e)};t?p.openChangeTimeout.start(t,n):(p.openChangeTimeout.clear(),n())}function o(e){let t=Et(e);if(!rn(t)){p.interactedInside=!1;return}p.interactedInside=t?.closest(`[aria-haspopup]`)!=null}function c(){p.openChangeTimeout.clear(),m.clear(),d?.events.off(`floating.closed`,v),_()}function l(n){if(e()&&d){d.events.on(`floating.closed`,v);return}if($t(n.relatedTarget,a.context.triggerElements))return;let r=u.current.floatingContext?.nodeId??i,o=n.relatedTarget;if(!(d&&r&&G(o)&&ci(d.nodesRef.current,r,!1).some(e=>X(e.context?.elements.floating,o)))){if(p.handler){p.handler(n);return}_(),g()&&!h()&&t(n)}}function v(t){d&&f&&!e()&&m.start(0,()=>{d.events.off(`floating.closed`,v),a.setOpen(!1,Z(hn,t)),d.events.emit(`floating.closed`,t)})}let y=s;return Ln(y&&q(y,`mouseenter`,c),y&&q(y,`mouseleave`,l),y&&q(y,`pointerdown`,o,!0),()=>{d?.events.off(`floating.closed`,v)})},[n,s,a,u,r,i,g,h,_,p,d,f,m])}var ec={current:null};function tc(e,t={}){let{enabled:n=!0,delay:r=0,handleClose:i=null,mouseOnly:a=!1,restMs:o=0,move:s=!0,triggerElementRef:c=ec,externalTree:u,isActiveTrigger:d=!0,getHandleCloseContext:f,isClosing:p,shouldOpen:m,guardStaleOpen:h=!1}=t,g=`rootStore`in e?e.rootStore:e,{dataRef:_,events:v}=g.context,y=xa(u),b=Qs(g),x=l.useRef(!1),S=Wn(i),C=Wn(r),w=Wn(o),T=Wn(n),E=Wn(m),D=Wn(p),O=$(()=>dn(_.current.openEvent?.type,b.interactedInside)),k=$(()=>E.current?.()!==!1),A=$((e,t,n)=>{let r=g.context.triggerElements;if(r.hasElement(t))return!e||!X(e,t);if(!G(n))return!1;let i=n;return r.hasMatchingElement(e=>X(e,i))&&(!e||!X(e,i))}),j=$(()=>{b.handler&&=(J(g.select(`domReferenceElement`)).removeEventListener(`mousemove`,b.handler),void 0)}),M=$(()=>{Xs(b)});return d&&(b.handleCloseOptions=i?.__options),l.useEffect(()=>j,[j]),l.useEffect(()=>{if(!n)return;function e(e){e.open?x.current=!1:(x.current=e.reason===hn,j(),b.openChangeTimeout.clear(),b.restTimeout.clear(),b.blockMouseMove=!0,b.restTimeoutPending=!1)}return v.on(`openchange`,e),()=>{v.off(`openchange`,e)}},[n,v,b,j]),l.useEffect(()=>{if(!n)return;function e(e,t=!0){let n=ln(C.current,`close`,b.pointerType);n?b.openChangeTimeout.start(n,()=>{g.setOpen(!1,Z(hn,e)),y?.events.emit(`floating.closed`,e)}):t&&(b.openChangeTimeout.clear(),g.setOpen(!1,Z(hn,e)),y?.events.emit(`floating.closed`,e))}let t=c.current??(d?g.select(`domReferenceElement`):null);if(!G(t))return;function r(e){if(b.openChangeTimeout.clear(),b.blockMouseMove=!1,a&&!Ct(b.pointerType))return;let t=un(w.current),n=ln(C.current,`open`,b.pointerType),r=Et(e),i=e.currentTarget??null,o=g.select(`domReferenceElement`),s=i;if(G(r)&&!g.context.triggerElements.hasElement(r)){for(let e of g.context.triggerElements.elements())if(X(e,r)){s=e;break}}G(i)&&G(o)&&!g.context.triggerElements.hasElement(i)&&X(i,o)&&(s=o);let c=s!=null&&A(o,s,r),l=g.select(`open`),u=D.current?.()??g.select(`transitionStatus`)===`ending`,d=!l&&u&&x.current,f=!c&&G(s)&&G(o)&&X(o,s)&&d,p=t>0&&!n,m=c&&(l||d)||f,h=!l||c;if(m){k()&&g.setOpen(!0,Z(hn,e,s));return}p||(n?b.openChangeTimeout.start(n,()=>{h&&k()&&g.setOpen(!0,Z(hn,e,s))}):h&&k()&&g.setOpen(!0,Z(hn,e,s)))}function i(t){if(O()){M();return}j();let n=J(g.select(`domReferenceElement`));b.restTimeout.clear(),b.restTimeoutPending=!1;let r=_.current.floatingContext??f?.();if(!$t(t.relatedTarget,g.context.triggerElements)){if(S.current&&r){g.select(`open`)||b.openChangeTimeout.clear();let i=c.current;b.handler=S.current({...r,tree:y,x:t.clientX,y:t.clientY,onClose(){M(),j(),T.current&&!O()&&i===g.select(`domReferenceElement`)&&e(t,!0)}}),n.addEventListener(`mousemove`,b.handler),b.handler(t);return}(b.pointerType!==`touch`||!X(g.select(`floatingElement`),t.relatedTarget))&&e(t)}}function o(e){X(t,e.relatedTarget)||(b.openChangeTimeout.clear(),b.restTimeout.clear(),b.restTimeoutPending=!1)}let l=h?q(t,`mouseout`,o):void 0;return s?Ln(q(t,`mousemove`,r,{once:!0}),q(t,`mouseenter`,r),q(t,`mouseleave`,i),l):Ln(q(t,`mouseenter`,r),q(t,`mouseleave`,i),l)},[j,M,_,C,g,n,S,b,d,A,O,a,s,w,c,y,T,f,D,k,h]),l.useMemo(()=>{if(!n)return;function e(e){b.pointerType=e.pointerType}return{onPointerDown:e,onPointerEnter:e,onMouseMove(e){let{nativeEvent:t}=e,n=e.currentTarget,r=g.select(`domReferenceElement`),i=g.select(`open`),o=A(r,n,e.target);if(a&&!Ct(b.pointerType))return;if(i&&o&&b.handleCloseOptions?.blockPointerEvents){let e=g.select(`floatingElement`);if(e){let t=b.handleCloseOptions?.getScope?.()??n.ownerDocument.body;Zs(b,{scopeElement:t,referenceElement:n,floatingElement:e})}}let s=un(w.current);if(i&&!o||s===0||!o&&b.restTimeoutPending&&e.movementX**2+e.movementY**2<2)return;b.restTimeout.clear();function c(){if(b.restTimeoutPending=!1,O())return;let e=g.select(`open`);!b.blockMouseMove&&(!e||o)&&k()&&g.setOpen(!0,Z(hn,t,n))}b.pointerType===`touch`?ua.flushSync(()=>{c()}):o&&i?c():(b.restTimeoutPending=!0,b.restTimeout.start(s,c))}}},[n,b,O,A,a,g,w,k])}var nc=`Escape`;function rc(e){return Ke&&e.movementX===0&&e.movementY===0}function ic(e,t,n){switch(e){case`vertical`:return t;case`horizontal`:return n;default:return t||n}}function ac(e,t){return ic(t,e===`ArrowUp`||e===`ArrowDown`,e===`ArrowLeft`||e===`ArrowRight`)}function oc(e,t,n){return ic(t,e===`ArrowDown`,n?e===`ArrowLeft`:e===`ArrowRight`)||e===`Enter`||e===` `||e===``}function sc(e,t,n){return ic(t,n?e===kt:e===At,e===Mt)}function cc(e,t,n,r){return t===`both`||t===`horizontal`&&r?e===nc:ic(t,n?e===At:e===kt,e===jt)}function lc(e,t){let{listRef:n,activeIndex:r,onNavigate:i=()=>{},enabled:a=!0,selectedIndex:o=null,allowEscape:s=!1,loopFocus:c=!1,nested:u=!1,rtl:d=!1,virtual:f=!1,focusItemOnOpen:p=`auto`,focusItemOnHover:m=!0,openOnArrowKeyDown:h=!0,disabledIndices:g=void 0,orientation:_=`vertical`,parentOrientation:v,id:y,resetOnPointerLeave:b=!0,externalTree:x,grid:S}=t,C=S!=null,w=`rootStore`in e?e.rootStore:e,T=w.useState(`open`),E=w.useState(`floatingElement`),D=w.useState(`domReferenceElement`),O=w.context.dataRef,k=sn(E),A=an(D),j=Wn(k),M=ba(),N=xa(x),P=l.useRef(p),F=l.useRef(o??-1),I=l.useRef(null),L=l.useRef(!0),R=$(e=>{i(F.current===-1?null:F.current,e)}),z=l.useRef(!!E),ee=l.useRef(T),B=l.useRef(!1),te=l.useRef(!1),ne=l.useRef(null),re=Wn(g),V=Wn(T),H=Wn(o),ie=Wn(b),ae=ct(),oe=ct(),se=$(()=>{function e(e){f?N?.events.emit(`virtualfocus`,e):ne.current=fi(e,{sync:B.current,preventScroll:!0})}let t=n.current[F.current],r=te.current;t&&e(t),(B.current?e=>e():e=>ae.request(e))(()=>{let i=n.current[F.current]||t;i&&(t||e(i),pe&&(r||!L.current)&&i.scrollIntoView?.({block:`nearest`,inline:`nearest`}))})});U(()=>{O.current.orientation=_},[O,_]),U(()=>{a&&(T&&E?(F.current=o??-1,P.current&&o!=null&&(te.current=!0,R())):z.current&&(F.current=-1,R()))},[a,T,E,o,R]),U(()=>{if(a){if(!T){B.current=!1;return}if(E){if(r==null){if(B.current=!1,H.current!=null)return;if(z.current&&(F.current=-1,se()),(!ee.current||!z.current)&&P.current&&(I.current!=null||P.current===!0&&I.current==null)){let e=0,t=()=>{n.current[0]==null?(e<2&&(e?e=>oe.request(e):queueMicrotask)(t),e+=1):(F.current=I.current==null||oc(I.current,_,d)||u?Ar(n):jr(n),I.current=null,R())};t()}}else kr(n.current,r)||(F.current=r,se(),te.current=!1)}}},[a,T,E,r,H,u,n,_,d,R,se,oe]),U(()=>{if(!a||E||!N||f||!z.current)return;let e=N.nodesRef.current,t=e.find(e=>e.id===M)?.context?.elements.floating,n=Tt(J(D??t??null)),r=e.some(e=>e.context&&X(e.context.elements.floating,n));t&&!r&&L.current&&t.focus({preventScroll:!0})},[a,E,D,N,M,f]),U(()=>{ee.current=T,z.current=!!E}),U(()=>{T||(I.current=null,P.current=p)},[T,p]);let ce=r!=null,le=$(e=>{if(!V.current)return;let t=n.current.indexOf(e.currentTarget);t!==-1&&(F.current!==t||r!==t)&&(F.current=t,R(e))}),ue=$(()=>v??N?.nodesRef.current.find(e=>e.id===M)?.context?.dataRef?.current.orientation),de=$(()=>Ar(n,re.current)),fe=$(e=>{if(L.current=!1,B.current=!0,e.which===229||!V.current&&e.currentTarget===j.current)return;if(u&&cc(e.key,_,d,C)){ac(e.key,ue())||yt(e),w.setOpen(!1,Z(Tn,e.nativeEvent)),K(D)&&(f?N?.events.emit(`virtualfocus`,D):D.focus());return}let t=F.current,r=Ar(n,g),i=jr(n,g);if(A||(e.key===`Home`&&(yt(e),F.current=r,R(e)),e.key===`End`&&(yt(e),F.current=i,R(e))),S!=null){let t=S(e,F.current,n,_,c,d,g,r,i);if(t!=null&&(F.current=t,R(e)),_===`both`)return}if(ac(e.key,_)){if(yt(e),T&&!f&&Tt(e.currentTarget.ownerDocument)===e.currentTarget){F.current=oc(e.key,_,d)?r:i,R(e);return}oc(e.key,_,d)?c?t>=i?s&&t!==n.current.length?F.current=-1:(B.current=!1,F.current=r):F.current=Mr(n.current,{startingIndex:t,disabledIndices:g}):F.current=Math.min(i,Mr(n.current,{startingIndex:t,disabledIndices:g})):c?t<=r?s&&t!==-1?F.current=n.current.length:(B.current=!1,F.current=i):F.current=Mr(n.current,{startingIndex:t,decrement:!0,disabledIndices:g}):F.current=Math.max(r,Mr(n.current,{startingIndex:t,decrement:!0,disabledIndices:g})),kr(n.current,F.current)&&(F.current=-1),R(e)}}),pe=l.useMemo(()=>({onFocus(e){B.current=!0,le(e)},onClick:({currentTarget:e})=>e.focus({preventScroll:!0}),onMouseMove(e){rc(e)||(B.current=!0,te.current=!1,m&&le(e))},onPointerLeave(e){if(!V.current||!L.current||e.pointerType===`touch`)return;B.current=!0;let t=e.relatedTarget;if(m&&!n.current.includes(t)&&ie.current&&(ne.current?.(),ne.current=null,F.current=-1,R(e),!f)){let e=j.current,t=Tt(J(e));e&&X(e,t)&&e.focus({preventScroll:!0})}}}),[le,V,j,m,n,R,ie,f]),W=l.useMemo(()=>f&&T&&ce&&{"aria-activedescendant":`${y}-${r}`},[f,T,ce,y,r]),me=l.useMemo(()=>({...A?{}:W,onKeyDown(e){if(e.key===`Tab`&&e.shiftKey&&T&&!f){let t=Et(e.nativeEvent);if(t&&!X(j.current,t))return;yt(e),w.setOpen(!1,Z(Cn,e.nativeEvent)),K(D)&&D.focus();return}fe(e)},onPointerMove(e){rc(e)||(L.current=!0)}}),[W,fe,j,A,w,T,f,D]),he=l.useMemo(()=>{function e(e){w.setOpen(!0,Z(Tn,e.nativeEvent,e.currentTarget))}function t(e){p===`auto`&&xt(e.nativeEvent)&&(P.current=!f)}function n(e){P.current=p,p===`auto`&&St(e.nativeEvent)&&(P.current=!0)}return{onKeyDown(t){let n=w.select(`open`);L.current=!1;let r=t.key.startsWith(`Arrow`),i=sc(t.key,ue(),d),a=ac(t.key,_),o=(u?i:a)||t.key===`Enter`||t.key.trim()===``;if(f&&n)return fe(t);if(n||h||!r){if(o){let e=ac(t.key,ue());I.current=u&&e?null:t.key}if(u){i&&(yt(t),n?(F.current=de(),R(t)):e(t));return}a&&(H.current!=null&&(F.current=H.current),yt(t),!n&&h?e(t):fe(t),n&&R(t))}},onFocus(e){w.select(`open`)&&!f&&(F.current=-1,R(e))},onPointerDown:n,onPointerEnter:n,onMouseDown:t,onClick:t}},[fe,p,de,u,R,w,h,_,ue,d,H,f]),ge=l.useMemo(()=>({...W,...he}),[W,he]);return l.useMemo(()=>a?{reference:ge,floating:me,item:pe,trigger:he}:{},[a,ge,me,he,pe])}function uc(e,t){let{listRef:n,elementsRef:r,activeIndex:i,onMatch:a,disabledIndices:o,onTyping:s,enabled:c=!0,resetMs:u=750,selectedIndex:d=null}=t,f=`rootStore`in e?e.rootStore:e,p=f.useState(`open`),m=it(),h=l.useRef(``),g=l.useRef(d??i??-1),_=l.useRef(null),v=$(e=>{function t(e){return r?.current[e]}function c(e){let n=t(e);return n&&!Ir(n)||n?.matches(`:disabled`)?!1:o==null||!Pr($e,e,o)}function l(e,t,n=0){if(e.length===0)return-1;let r=(n%e.length+e.length)%e.length,i=t.toLowerCase();for(let t=0;t<e.length;t+=1){let n=(r+t)%e.length;if(e[n]?.toLowerCase().startsWith(i)&&c(n))return n}return-1}let f=n.current;if(h.current.length>0&&e.key===` `&&(yt(e),s?.(!0)),h.current.length>0&&h.current[0]!==` `&&l(f,h.current)===-1&&e.key!==` `&&s?.(!1),f==null||e.key.length!==1||e.ctrlKey||e.metaKey||e.altKey)return;p&&e.key!==` `&&(yt(e),s?.(!0));let v=h.current===``;v&&(g.current=d??i??-1),f.every((e,t)=>e&&c(t)?e[0]?.toLowerCase()!==e[1]?.toLowerCase():!0)&&h.current===e.key&&(h.current=``,g.current=_.current),h.current+=e.key,m.start(u,()=>{h.current=``,g.current=_.current,s?.(!1)});let y=((v?d??i??-1:g.current)??0)+1,b=l(f,h.current,y);b===-1?e.key!==` `&&(h.current=``,s?.(!1)):(a?.(b),_.current=b)}),y=$(e=>{let t=e.relatedTarget,n=f.select(`domReferenceElement`),r=f.select(`floatingElement`);X(n,t)||X(r,t)||(m.clear(),h.current=``,g.current=_.current,s?.(!1))});U(()=>{(p||d===null)&&(m.clear(),_.current=null,h.current!==``&&(h.current=``))},[p,d,m]);let b=l.useMemo(()=>({onKeyDown:v,onBlur:y}),[v,y]);return l.useMemo(()=>c?{reference:b,floating:b}:{},[c,b])}var dc=.1,fc=dc*dc,pc=.5;function mc(e,t,n,r,i,a){return r>=t!=a>=t&&e<=(i-n)*(t-r)/(a-r)+n}function hc(e,t,n,r,i,a,o,s,c,l){let u=!1;return mc(e,t,n,r,i,a)&&(u=!u),mc(e,t,i,a,o,s)&&(u=!u),mc(e,t,o,s,c,l)&&(u=!u),mc(e,t,c,l,n,r)&&(u=!u),u}function gc(e,t,n){return e>=n.x&&e<=n.x+n.width&&t>=n.y&&t<=n.y+n.height}function _c(e,t,n,r,i,a){return e>=Math.min(n,i)&&e<=Math.max(n,i)&&t>=Math.min(r,a)&&t<=Math.max(r,a)}function vc(e={}){let{blockPointerEvents:t=!1}=e,n=new rt,r=({x:e,y:t,placement:r,elements:i,onClose:a,nodeId:o,tree:s})=>{let c=r?.split(`-`)[0],l=!1,u=null,d=null,f=typeof performance<`u`?performance.now():0;function p(e,t){let n=performance.now(),r=n-f;if(u===null||d===null||r===0)return u=e,d=t,f=n,!1;let i=e-u,a=t-d,o=i*i+a*a,s=r*r*fc;return u=e,d=t,f=n,o<s}function m(){n.clear(),a()}return function(r){n.clear();let a=i.domReference,u=i.floating;if(!a||!u||c==null||e==null||t==null)return;let{clientX:d,clientY:f}=r,h=Et(r),g=r.type===`mouseleave`,_=X(u,h),v=X(a,h);if(_&&(l=!0,!g))return;if(v&&(l=!1,!g)){l=!0;return}if(g&&G(r.relatedTarget)&&X(u,r.relatedTarget))return;function y(){return!!(s&&ci(s.nodesRef.current,o).length>0)}function b(){y()||m()}if(y())return;let x=a.getBoundingClientRect(),S=u.getBoundingClientRect(),C=e>S.right-S.width/2,w=t>S.bottom-S.height/2,T=S.width>x.width,E=S.height>x.height,D=(T?x:S).left,O=(T?x:S).right,k=(E?x:S).top,A=(E?x:S).bottom;if(c===`top`&&t>=x.bottom-1||c===`bottom`&&t<=x.top+1||c===`left`&&e>=x.right-1||c===`right`&&e<=x.left+1){b();return}let j=!1;switch(c){case`top`:j=_c(d,f,D,x.top+1,O,S.bottom-1);break;case`bottom`:j=_c(d,f,D,S.top+1,O,x.bottom-1);break;case`left`:j=_c(d,f,S.right-1,A,x.left+1,k);break;case`right`:j=_c(d,f,x.right-1,A,S.left+1,k)}if(j)return;if(l&&!gc(d,f,x)){b();return}if(!g&&p(d,f)){b();return}let M=!1;switch(c){case`top`:{let n=T?pc/2:pc*4,r=T||C?e+n:e-n,i=T?e-n:C?e+n:e-n,a=t+pc+1,o=C||T?S.bottom-pc:S.top,s=C?T?S.bottom-pc:S.top:S.bottom-pc;M=hc(d,f,r,a,i,a,S.left,o,S.right,s);break}case`bottom`:{let n=T?pc/2:pc*4,r=T||C?e+n:e-n,i=T?e-n:C?e+n:e-n,a=t-pc,o=C||T?S.top+pc:S.bottom,s=C?T?S.top+pc:S.bottom:S.top+pc;M=hc(d,f,r,a,i,a,S.left,o,S.right,s);break}case`left`:{let n=E?pc/2:pc*4,r=E||w?t+n:t-n,i=E?t-n:w?t+n:t-n,a=e+pc+1,o=w||E?S.right-pc:S.left,s=w?E?S.right-pc:S.left:S.right-pc;M=hc(d,f,o,S.top,s,S.bottom,a,r,a,i);break}case`right`:{let n=E?pc/2:pc*4,r=E||w?t+n:t-n,i=E?t-n:w?t+n:t-n,a=e-pc,o=w||E?S.left+pc:S.right,s=w?E?S.left+pc:S.right:S.left+pc;M=hc(d,f,a,r,a,i,o,S.top,s,S.bottom);break}}M?l||n.start(40,b):b()}};return r.__options={...e,blockPointerEvents:t},r}function yc({store:e,parentContext:t,isDrawer:n}){let r=e.useState(`open`),i=e.useState(`disablePointerDismissal`),a=e.useState(`modal`),o=e.useState(`popupElement`),s=e.useState(`floatingRootContext`),[c,u]=l.useState(0),[d,f]=l.useState(0),p=c===0,m=Va(s,{outsidePressEvent(){return e.context.internalBackdropRef.current||e.context.backdropRef.current?`intentional`:{mouse:a===`trap-focus`?`sloppy`:`intentional`,touch:`sloppy`}},outsidePress(t){if(!e.context.outsidePressEnabledRef.current||`button`in t&&t.button!==0)return!1;if(`touches`in t){if(t.type===`touchend`){if(t.changedTouches.length!==1||t.touches.length!==0)return!1}else if(t.touches.length!==1)return!1}let n=Et(t);if(p&&!i){if(a){let t=e.context.internalBackdropRef.current,r=e.context.backdropRef.current;return t||r?t===n||r===n||X(n,o)&&!n?.hasAttribute(`data-base-ui-portal`):!0}return!0}return!1},escapeKey:p});return vt(r&&a===!0,o),e.useContextCallback(`onNestedDialogOpen`,(e,t)=>{u(e),f(t)}),U(()=>(t?.onNestedDialogOpen&&(r?t.onNestedDialogOpen(c+1,d+ +!!n):t.onNestedDialogOpen(0,0)),()=>{t?.onNestedDialogOpen&&r&&t.onNestedDialogOpen(0,0)}),[n,r,c,d,t]),Ms(e,{activeTriggerProps:m.reference,inactiveTriggerProps:m.trigger,popupProps:m.floating,nestedOpenDialogCount:c,nestedOpenDrawerCount:d}),null}var bc=l.createContext(void 0);function xc(e){let t=l.useContext(bc);if(!e&&t===void 0)throw Error(Ai(27));return t}var Sc={...Vs,modal:e=>e.modal,nested:e=>e.nested,nestedOpenDialogCount:e=>e.nestedOpenDialogCount,nestedOpenDrawerCount:e=>e.nestedOpenDrawerCount,disablePointerDismissal:e=>e.disablePointerDismissal,openMethod:e=>e.openMethod,descriptionElementId:e=>e.descriptionElementId,titleElementId:e=>e.titleElementId,viewportElement:e=>e.viewportElement,role:e=>e.role},Cc=class extends ds{constructor(e,t,n){let r=new Ps,i=wc(e,r,t,n);super(i,Tc(r),Sc)}setOpen=(e,t)=>{t.preventUnmountOnClose=()=>{this.set(`preventUnmountingOnClose`,!0)},!e&&t.trigger==null&&this.state.activeTriggerId!=null&&(t.trigger=this.state.activeTriggerElement??void 0),this.context.onOpenChange?.(e,t),!t.isCanceled&&(this.state.floatingRootContext.dispatchOpenChange(e,t),this.update(Es(this.state,e,t.trigger)))}};function wc(e,t,n,r=!1){return{...Fs(t,n,r),modal:!0,disablePointerDismissal:!1,viewportElement:null,descriptionElementId:void 0,titleElementId:void 0,openMethod:null,nested:!1,nestedOpenDialogCount:0,nestedOpenDrawerCount:0,role:`dialog`,...e}}function Tc(e){return{popupRef:l.createRef(),backdropRef:l.createRef(),internalBackdropRef:l.createRef(),outsidePressEnabledRef:{current:!0},triggerElements:e,onOpenChange:void 0,onOpenChangeComplete:void 0}}function Ec(e,t){let{children:n,open:r,defaultOpen:i=!1,onOpenChange:a,onOpenChangeComplete:o,disablePointerDismissal:s=!1,modal:c=!0,actionsRef:u,handle:d,triggerId:f,defaultTriggerId:p=null}=t,m=e===`drawer`,h=e===`alert-dialog`,g=h?!0:c,_=h||s,v=h?`alertdialog`:`dialog`,y=xc(!0),b={modal:g,disablePointerDismissal:_,nested:y!=null,role:v},x=Ss((e,t)=>new Cc({open:i,openProp:r,activeTriggerId:p,triggerIdProp:f,...b},e,t),!0);x.useControlledProp(`openProp`,r),x.useControlledProp(`triggerIdProp`,f),x.useSyncedValues(b),x.useContextCallback(`onOpenChange`,a),x.useContextCallback(`onOpenChangeComplete`,o);let S=x.useState(`open`),C=x.useState(`mounted`),w=x.useState(`payload`);Ns(x,S),As(x);let{forceUnmount:T}=js(S,x);l.useImperativeHandle(u,()=>({unmount:T,close:()=>x.setOpen(!1,Z(jn))}),[T,x]);let E=S||C;return(0,Q.jsxs)(bc.Provider,{value:x,children:[d&&(0,Q.jsx)(Cs,{handle:d,store:x}),E&&(0,Q.jsx)(yc,{store:x,parentContext:y?.context,isDrawer:m}),typeof n==`function`?n({payload:w}):n]})}function Dc(e){return Ec(`alert-dialog`,e)}var Oc=l.forwardRef(function(e,t){let{render:n,className:r,style:i,forceRender:a=!1,...o}=e,s=xc(),c=s.useState(`open`),l=s.useState(`nested`),u=s.useState(`mounted`);return $i(`div`,e,{state:{open:c,transitionStatus:s.useState(`transitionStatus`)},ref:[s.context.backdropRef,t],stateAttributesMapping:Zt,props:[{role:`presentation`,hidden:!u,style:{userSelect:`none`,WebkitUserSelect:`none`}},o],enabled:a||!l})}),kc=l.createContext(void 0);function Ac(e=!1){let t=l.useContext(kc);if(t===void 0&&!e)throw Error(Ai(16));return t}function jc(e){let{focusableWhenDisabled:t,disabled:n,composite:r=!1,tabIndex:i=0,isNativeButton:a}=e,o=r&&t!==!1,s=r&&t===!1;return{props:l.useMemo(()=>{let e={onKeyDown(e){n&&t&&e.key!==`Tab`&&e.preventDefault()}};return r||(e.tabIndex=i,!a&&n&&(e.tabIndex=t?i:-1)),(a&&(t||o)||!a&&n)&&(e[`aria-disabled`]=n),a&&(!t||s)&&(e.disabled=n),e},[r,n,t,o,s,a,i])}}function Mc(e,t,{detail:n=0}={}){e.dispatchEvent(new(me(e)).PointerEvent(`click`,{bubbles:!0,cancelable:!0,composed:!0,detail:n,shiftKey:t.shiftKey,ctrlKey:t.ctrlKey,altKey:t.altKey,metaKey:t.metaKey}))}function Nc(e={}){let{disabled:t=!1,focusableWhenDisabled:n,tabIndex:r=0,native:i=!0,composite:a}=e,o=l.useRef(null),s=Ac(!0),c=a??s!==void 0,{props:u}=jc({focusableWhenDisabled:n,disabled:t,composite:c,tabIndex:r,isNativeButton:i}),d=l.useCallback(()=>{let e=o.current;Pc(e)&&c&&t&&u.disabled===void 0&&e.disabled&&(e.disabled=!1)},[t,u.disabled,c]);return U(d,[d]),{getButtonProps:l.useCallback((e={})=>{let{onClick:n,onMouseDown:r,onKeyUp:a,onKeyDown:o,onPointerDown:s,...l}=e;return zi({onClick(e){if(t){e.preventDefault();return}n?.(e)},onMouseDown(e){t||r?.(e)},onKeyDown(e){if(t||(Xi(e),o?.(e),e.baseUIHandlerPrevented))return;let n=e.target===e.currentTarget,r=e.currentTarget,a=Pc(r),s=!i&&Fc(r),l=n&&(i?a:!s),u=e.key===`Enter`,d=e.key===` `,f=r.getAttribute(`role`),p=f?.startsWith(`menuitem`)||f===`option`||f===`gridcell`;if(n&&c&&d){if(e.defaultPrevented&&p)return;e.preventDefault(),(!i||a)&&(e.preventBaseUIHandler(),Mc(r,e));return}if(!l||i||!d&&!u){n&&s&&d&&e.preventDefault();return}e.defaultPrevented||(e.preventDefault(),u&&(e.preventBaseUIHandler(),Mc(r,e)))},onKeyUp(e){if(!t){if(Xi(e),a?.(e),e.target===e.currentTarget&&i&&c&&Pc(e.currentTarget)&&e.key===` `){e.preventDefault();return}e.baseUIHandlerPrevented||e.target===e.currentTarget&&!i&&!c&&!e.defaultPrevented&&e.key===` `&&(e.preventBaseUIHandler(),Mc(e.currentTarget,e))}},onPointerDown(e){if(t){e.preventDefault();return}s?.(e)}},i?{type:`button`}:{role:`button`},u,l)},[t,u,c,i]),buttonRef:$(e=>{o.current=e,d()})}}function Pc(e){return K(e)&&e.tagName===`BUTTON`}function Fc(e){return K(e)&&e.tagName===`A`&&!!e.href}var Ic=l.forwardRef(function(e,t){let{render:n,className:r,style:i,disabled:a=!1,nativeButton:o=!0,...s}=e,c=xc(),l=c.useState(`open`),{getButtonProps:u,buttonRef:d}=Nc({disabled:a,native:o}),f={disabled:a};function p(e){l&&c.setOpen(!1,Z(yn,e.nativeEvent))}return $i(`button`,e,{state:f,ref:[t,d],props:[{onClick:p},s,u]})});function Lc(e){return Oi(e,`base-ui`)}var Rc=l.forwardRef(function(e,t){let{render:n,className:r,style:i,id:a,...o}=e,s=xc(),c=Lc(a);return s.useSyncedValueWithCleanup(`descriptionElementId`,c),$i(`p`,e,{ref:t,props:[{id:c},o]})}),zc=l.createContext(void 0);function Bc(){let e=l.useContext(zc);if(e===void 0)throw Error(Ai(26));return e}var Vc=new Set([`ArrowUp`,`ArrowDown`,`ArrowLeft`,`ArrowRight`,`Home`,`End`]),Hc=`--nested-dialogs`,Uc=`data-nested-dialog-open`,Wc={...Xt,...Lt,nestedDialogOpen(e){return e?{[Uc]:``}:null}},Gc=l.forwardRef(function(e,t){let{render:n,className:r,style:i,finalFocus:a,initialFocus:o,...s}=e,c=xc(),l=c.useState(`descriptionElementId`),u=c.useState(`disablePointerDismissal`),d=c.useState(`floatingRootContext`),f=c.useState(`popupProps`),p=c.useState(`modal`),m=c.useState(`mounted`),h=c.useState(`nested`),g=c.useState(`nestedOpenDialogCount`),_=c.useState(`open`),v=c.useState(`openMethod`),y=c.useState(`titleElementId`),b=c.useState(`transitionStatus`),x=c.useState(`role`),S=d.useState(`floatingId`);Bc(),ys({open:_,ref:c.context.popupRef,onComplete(){_&&c.context.onOpenChangeComplete?.(!0)}});let C=o===void 0?xs(c.context.popupRef):o,w=g>0,T=c.useStateSetter(`popupElement`),E=$i(`div`,e,{state:{open:_,nested:h,transitionStatus:b,nestedDialogOpen:w},props:[f,{id:S,"aria-labelledby":y,"aria-describedby":l,role:x,...bs,hidden:!m,onKeyDown(e){Vc.has(e.key)&&e.stopPropagation()},style:{[Hc]:g}},s],ref:[t,c.context.popupRef,T],stateAttributesMapping:Wc});return(0,Q.jsx)(Pa,{context:d,openInteractionType:v,disabled:!m,closeOnFocusOut:!u,initialFocus:C,returnFocus:a,modal:p!==!1,restoreFocus:`popup`,children:E})});function Kc(e){return Mi(19)?e:e?`true`:void 0}var qc=l.forwardRef(function(e,t){let{cutout:n,...r}=e,i;if(n){let e=n.getBoundingClientRect();i=`polygon(0% 0%,100% 0%,100% 100%,0% 100%,0% 0%,${e.left}px ${e.top}px,${e.left}px ${e.bottom}px,${e.right}px ${e.bottom}px,${e.right}px ${e.top}px,${e.left}px ${e.top}px)`}return(0,Q.jsx)(`div`,{ref:t,role:`presentation`,"data-base-ui-inert":``,...r,style:{position:`fixed`,inset:0,userSelect:`none`,WebkitUserSelect:`none`,clipPath:i}})}),Jc=l.forwardRef(function(e,t){let{keepMounted:n=!1,...r}=e,i=xc(),a=i.useState(`mounted`),o=i.useState(`modal`),s=i.useState(`open`);return a||n?(0,Q.jsx)(zc.Provider,{value:n,children:(0,Q.jsxs)(ha,{ref:t,...r,children:[a&&o===!0&&(0,Q.jsx)(qc,{ref:i.context.internalBackdropRef,inert:Kc(!s)}),e.children]})}):null}),Yc=l.forwardRef(function(e,t){let{render:n,className:r,style:i,id:a,...o}=e,s=xc(),c=Lc(a);return s.useSyncedValueWithCleanup(`titleElementId`,c),$i(`h2`,e,{ref:t,props:[{id:c},o]})});function Xc(e){let t=l.useRef(``),n=l.useCallback(n=>{n.defaultPrevented||(t.current=n.pointerType,e(n,n.pointerType))},[e]);return{onClick:l.useCallback(n=>{if(n.detail===0){e(n,`keyboard`);return}`pointerType`in n?e(n,n.pointerType):e(n,t.current),t.current=``},[e]),onPointerDown:n}}function Zc(e,t){let n=l.useRef(e),r=$(t);U(()=>{n.current!==e&&r(n.current),n.current=e},[e,r])}function Qc(e,t){let{onClick:n,onPointerDown:r}=Xc($((n,r)=>{(typeof e==`function`?e():e)||t(r||(Ve?`touch`:``))}));return l.useMemo(()=>({onClick:n,onPointerDown:r}),[n,r])}function $c(e){let[t,n]=l.useState(null),r=Qc(e,n);return Zc(e,t=>{t&&!e&&n(null)}),l.useMemo(()=>({openMethod:t,triggerProps:r}),[t,r])}var el=i(),tl,nl,rl=e=>{tl??=(0,el.createRoot)(document.body.appendChild(document.createElement(`div`))),nl?.resolve(!1),nl=e,tl.render((0,Q.jsx)(il,{request:e,settle:t=>{nl===e&&(nl=void 0,tl?.render(null),e.resolve(t))}}))};function il({request:e,settle:t}){return(0,Q.jsx)(Dc,{open:!0,onOpenChange:e=>{e||t(!1)},children:(0,Q.jsxs)(Jc,{children:[(0,Q.jsx)(Oc,{className:`dialog-backdrop`}),(0,Q.jsxs)(Gc,{className:`dialog`,children:[(0,Q.jsx)(Rc,{className:`dialog-message`,children:e.message}),(0,Q.jsxs)(`div`,{className:`dialog-actions`,children:[e.cancelLabel&&(0,Q.jsx)(Ic,{className:`dialog-button`,children:e.cancelLabel}),(0,Q.jsx)(`button`,{type:`button`,autoFocus:!0,className:`dialog-button is-primary ${e.danger?`is-danger`:``}`,onClick:()=>t(!0),children:e.confirmLabel})]})]})]})})}var al=(e,{confirmLabel:t=`Confirm`,danger:n=!1}={})=>new Promise(r=>rl({message:e,confirmLabel:t,cancelLabel:`Cancel`,danger:n,resolve:r})),ol=e=>new Promise(t=>rl({message:e,confirmLabel:`OK`,resolve:()=>t()})),sl=l.createContext(void 0);function cl(e){let t=l.useContext(sl);if(t===void 0&&!e)throw Error(Ai(72));return t}var ll={...Vs,disabled:e=>e.disabled,instantType:e=>e.instantType,isInstantPhase:e=>e.isInstantPhase,trackCursorAxis:e=>e.trackCursorAxis,disableHoverablePopup:e=>e.disableHoverablePopup,lastOpenChangeReason:e=>e.openChangeReason,closeOnClick:e=>e.closeOnClick,closeDelay:e=>e.closeDelay,adaptiveOrigin:e=>e.adaptiveOrigin},ul=class extends ds{constructor(e,t,n){let r=new Ps;super(dl(e,r,t,n),fl(r),ll)}setOpen=(e,t)=>{Os(this,e,t,{extraState:{openChangeReason:t.reason}})};cancelPendingOpen(e){this.state.floatingRootContext.dispatchOpenChange(!1,Z(mn,e))}};function dl(e,t,n,r=!1){return{...Fs(t,n,r),disabled:!1,instantType:void 0,isInstantPhase:!1,trackCursorAxis:`none`,disableHoverablePopup:!1,openChangeReason:null,closeOnClick:!0,closeDelay:0,adaptiveOrigin:void 0,...e}}function fl(e){return{popupRef:l.createRef(),onOpenChange:void 0,onOpenChangeComplete:void 0,triggerElements:e}}var pl=es(function(e){let{disabled:t=!1,defaultOpen:n=!1,open:r,disableHoverablePopup:i=!1,trackCursorAxis:a=`none`,actionsRef:o,onOpenChange:s,onOpenChangeComplete:c,handle:u,triggerId:d,defaultTriggerId:f=null,children:p}=e,m=Ss((e,t)=>new ul({open:n,openProp:r,activeTriggerId:f,triggerIdProp:d},e,t));m.useControlledProp(`openProp`,r),m.useControlledProp(`triggerIdProp`,d),m.useContextCallback(`onOpenChange`,s),m.useContextCallback(`onOpenChangeComplete`,c);let h=m.useState(`open`),g=!t&&h,_=m.useState(`activeTriggerId`),v=m.useState(`mounted`),y=m.useState(`payload`);m.useSyncedValues({trackCursorAxis:a,disableHoverablePopup:i,disabled:t}),As(m,{closeOnActiveTriggerUnmount:!0});let{forceUnmount:b,transitionStatus:x}=js(g,m),S=m.useState(`isInstantPhase`),C=m.useState(`instantType`),w=m.useState(`lastOpenChangeReason`),T=l.useRef(null);U(()=>{h&&t&&m.setOpen(!1,Z(An))},[h,t,m]),U(()=>{x===`ending`&&w===`none`||x!==`ending`&&S?(C!==`delay`&&(T.current=C),m.set(`instantType`,`delay`)):T.current!==null&&(m.set(`instantType`,T.current),T.current=null)},[x,S,w,C,m]),U(()=>{g&&(_??m.set(`payload`,void 0))},[m,_,g]),l.useImperativeHandle(o,()=>({unmount:b,close:()=>m.setOpen(!1,Z(jn))}),[b,m]);let E=g||v||!t&&a!==`none`;return(0,Q.jsxs)(sl.Provider,{value:m,children:[u&&(0,Q.jsx)(Cs,{handle:u,store:m}),E&&(0,Q.jsx)(ml,{store:m,disabled:t,trackCursorAxis:a}),typeof p==`function`?p({payload:y}):p]})});function ml({store:e,disabled:t,trackCursorAxis:n}){let r=e.useState(`floatingRootContext`),i=Va(r,{enabled:!t,referencePress:()=>e.select(`closeOnClick`)}),a=Ra(r,{enabled:!t&&n!==`none`,axis:n===`none`?void 0:n}),o=l.useMemo(()=>zi(a.reference,i.reference),[a.reference,i.reference]);return Ms(e,{activeTriggerProps:o,inactiveTriggerProps:o,popupProps:i.floating??et}),null}var hl=l.createContext(void 0);function gl(){return l.useContext(hl)}var _l=`data-base-ui-tooltip-trigger`;function vl(e){if(`composedPath`in e){let t=e.composedPath();for(let e=0;e<t.length;e+=1){let n=t[e];if(G(n))return n}}let t=e.target;return G(t)?t:null}function yl(e){let t=e;for(;t;){let e=t.closest(`[${_l}]`);if(e)return e;let n=t.getRootNode();t=`host`in n&&G(n.host)?n.host:null}return null}var bl=ts(function(e,t){let{render:n,className:r,style:i,handle:a,payload:o,disabled:s,delay:c,closeOnClick:u=!0,closeDelay:d,id:f,...p}=e,m=cl(!0),h=Hs(a)??m;if(!h)throw Error(Ai(82));let g=Lc(f),_=h.useState(`isTriggerActive`,g),v=h.useState(`isOpenedByTrigger`,g),y=h.useState(`floatingRootContext`),b=l.useRef(null),x=d??0,{registerTrigger:S,isMountedByThisTrigger:C}=ks(g,b,h,{payload:o,closeOnClick:u,closeDelay:x}),w=gl(),{activeIdRef:T,delayRef:E,isInstantPhase:D,hasProvider:O}=In(y,{open:v}),k=Qs(y);h.useSyncedValue(`isInstantPhase`,D);let A=h.useState(`disabled`),j=s??A,M=Wn(j),N=h.useState(`trackCursorAxis`),P=h.useState(`disableHoverablePopup`),F=l.useRef(!1),I=it(),L=l.useRef(void 0);function R(){return O&&T.current!=null?0:c??w??600}function z(e){let t=b.current;if(!t||!e)return!1;let n=yl(e);return n!==null&&n!==t&&X(t,n)}function ee(e){let t=z(e);return F.current=t,t&&(k.openChangeTimeout.clear(),k.restTimeout.clear(),k.restTimeoutPending=!1,I.clear()),t}let B=tc(y,{enabled:!j,mouseOnly:!0,move:!1,handleClose:!P&&N!==`both`?vc():null,restMs:R,delay(){return d==null&&O?{close:ln(E.current,`close`)}:{close:x}},triggerElementRef:b,isActiveTrigger:_,isClosing:()=>h.select(`transitionStatus`)===`ending`,shouldOpen(){return!F.current}}),te=qs(y,{enabled:!j}).reference,ne=e=>{let t=F.current,n=vl(e),r=ee(n),i=b.current,a=i&&n&&X(i,n);if(r&&h.select(`open`)&&h.select(`lastOpenChangeReason`)===`trigger-hover`){h.setOpen(!1,Z(hn,e));return}if(t&&!r&&a&&!M.current&&!h.select(`open`)&&i&&Ct(L.current)){let t=()=>{!F.current&&!M.current&&!h.select(`open`)&&h.setOpen(!0,Z(hn,e,i))},n=R();n===0?(I.clear(),t()):I.start(n,t)}},re=h.useState(`triggerProps`,C);return $i(`button`,e,{state:{open:v},ref:[t,S,b],props:[B,te,C||N!==`none`?re:void 0,{onMouseOver(e){ne(e.nativeEvent)},onFocus(e){z(vl(e.nativeEvent))&&e.preventBaseUIHandler()},onMouseLeave(){F.current=!1,I.clear(),L.current=void 0},onPointerEnter(e){L.current=e.pointerType},onPointerDown(e){L.current=e.pointerType,h.set(`closeOnClick`,u),u&&!h.select(`open`)&&h.cancelPendingOpen(e.nativeEvent)},onClick(e){u&&!h.select(`open`)&&h.cancelPendingOpen(e.nativeEvent)},id:g,[Qt]:j?``:void 0,[_l]:j?void 0:``},p],stateAttributesMapping:Jt})}),xl=l.createContext(void 0);function Sl(){let e=l.useContext(xl);if(e===void 0)throw Error(Ai(70));return e}var Cl=l.forwardRef(function(e,t){let{children:n,container:r,className:i,render:a,style:o,...s}=e,{node:c,subtree:u}=ma({container:r,ref:t,componentProps:e,elementProps:s});return!u&&!c?null:(0,Q.jsxs)(l.Fragment,{children:[u,c&&ua.createPortal(n,c)]})}),wl=l.forwardRef(function(e,t){let{keepMounted:n=!1,...r}=e;return cl().useState(`mounted`)||n?(0,Q.jsx)(xl.Provider,{value:n,children:(0,Q.jsx)(Cl,{ref:t,...r})}):null}),Tl=l.createContext(void 0);function El(){let e=l.useContext(Tl);if(e===void 0)throw Error(Ai(71));return e}var Dl=l.createContext(void 0);function Ol(){return l.useContext(Dl)?.direction??`ltr`}var kl=e=>({name:`arrow`,options:e,async fn(t){let{x:n,y:r,placement:i,rects:a,platform:o,elements:s,middlewareData:c}=t,{element:l,padding:u=0,offsetParent:d=`real`}=cr(e,t)||{};if(l==null)return{};let f=Er(u),p={x:n,y:r},m=mr(i),h=fr(m),g=await o.getDimensions(l),_=m===`y`,v=_?`top`:`left`,y=_?`bottom`:`right`,b=_?`clientHeight`:`clientWidth`,x=a.reference[h]+a.reference[m]-p[m]-a.floating[h],S=p[m]-a.reference[m],C=d===`real`?await o.getOffsetParent?.(l):s.floating,w=s.floating[b]||a.floating[h];(!w||!await o.isElement?.(C))&&(w=s.floating[b]||a.floating[h]);let T=x/2-S/2,E=w/2-g[h]/2-1,D=Math.min(f[v],E),O=Math.min(f[y],E),k=D,A=w-g[h]-O,j=w/2-g[h]/2+T,M=sr(k,j,A),N=!c.arrow&&ur(i)!=null&&j!==M&&a.reference[h]/2-(j<k?D:O)-g[h]/2<0,P=N?j<k?j-k:j-A:0;return{[m]:p[m]+P,data:{[m]:M,centerOffset:j-M-P,...N&&{alignmentOffset:P}},reset:N}}}),Al=(e,t)=>{let{name:n,fn:r}=kl(e);return{name:n,fn:r,options:[e,t]}},jl={name:`hide`,async fn(e){let{width:t,height:n,x:r,y:i}=e.rects.reference,a=t===0&&n===0&&r===0&&i===0,o=await e.platform.detectOverflow(e,{elementContext:`reference`});return{data:{referenceHidden:o.top-n>=0||o.right-t>=0||o.bottom-n>=0||o.left-t>=0||a}}}},Ml={sideX:`left`,sideY:`top`},Nl=`--available-width`,Pl=`--available-height`,Fl=`--anchor-width`,Il=`--anchor-height`,Ll=`--transform-origin`,Rl=Nl,zl=Pl;function Bl(e,t,n){let r=e===`inline-start`||e===`inline-end`;return{top:`top`,right:r?n?`inline-start`:`inline-end`:`right`,bottom:`bottom`,left:r?n?`inline-end`:`inline-start`:`left`}[t]}function Vl(e,t,n){let{rects:r,placement:i}=e;return{side:Bl(t,lr(i),n),align:ur(i)||`center`,anchor:{width:r.reference.width,height:r.reference.height},positioner:{width:r.floating.width,height:r.floating.height}}}function Hl(e){return Ul(e,Ws)}function Ul(e,t){let{anchor:n,positionMethod:r=`absolute`,side:i=`bottom`,sideOffset:a=0,align:o=`center`,alignOffset:s=0,collisionBoundary:c,collisionPadding:u=5,sticky:d=!1,arrowPadding:f=5,disableAnchorTracking:p=!1,inline:m,keepMounted:h=!1,floatingRootContext:g,mounted:_,collisionAvoidance:v,shift:y,nodeId:b,adaptiveOrigin:x,lazyFlip:S=!1,externalTree:C}=e,[w,T]=l.useState(null);!_&&w!==null&&T(null);let E=v.side||`flip`,D=v.align||`flip`,O=v.fallbackAxisSide||`end`,k=y?.crossAxis??!1,A=y?.rootBoundary,j=typeof n==`function`?n:void 0,M=$(j),N=j?M:n,P=Wn(n),F=Wn(_),I=Ol()===`rtl`,L=w||{top:`top`,right:`right`,bottom:`bottom`,left:`left`,"inline-end":I?`left`:`right`,"inline-start":I?`right`:`left`}[i],R=o===`center`?L:`${L}-${o}`,z=u;typeof z==`number`?z={top:z,right:z,bottom:z,left:z}:z&&={top:z.top||0,right:z.right||0,bottom:z.bottom||0,left:z.left||0};let ee=+(i===`bottom`),B=+(i===`top`),te=+(i===`right`),ne=+(i===`left`),re={boundary:c===`clipping-ancestors`?`clippingAncestors`:c,padding:z},V=l.useRef(null),H=Wn(a),ie=Wn(s),ae=typeof a==`function`?0:a,oe=typeof s==`function`?0:s,se=[];m&&se.push(m),se.push(Vo(e=>{let t=Vl(e,i,I),n=typeof H.current==`function`?H.current(t):H.current,r=typeof ie.current==`function`?ie.current(t):ie.current;return{mainAxis:n,crossAxis:r,alignmentAxis:r}},[ae,oe,I,i]));let ce=D===`none`&&E!==`shift`,le=!ce&&(d||k||E===`shift`),ue=E===`none`?null:Wo({...re,padding:{top:z.top+1+ee,right:z.right+1+ne,bottom:z.bottom+1+B,left:z.left+1+te},mainAxis:!k&&E===`flip`,crossAxis:D===`flip`&&`alignment`,fallbackAxisSideDirection:O}),de=ce?null:Ho({...re,rootBoundary:A,mainAxis:D!==`none`,crossAxis:le,limiter:d||k?void 0:Uo(e=>{if(!V.current)return{};let{width:t,height:n}=V.current.getBoundingClientRect(),r=pr(lr(e.placement)),i=r===`y`?t:n,a=r===`y`?z.left+z.right:z.top+z.bottom;return{offset:i/2+a/2}})},[re,d,k,A,z,D]);E===`shift`||D===`shift`||o===`center`?se.push(de,ue):se.push(ue,de),se.push(Go({...re,apply({elements:{floating:e},availableWidth:t,availableHeight:n,rects:r}){if(!F.current)return;let i=e.style;i.setProperty(Rl,`${t}px`),i.setProperty(zl,`${n}px`);let a=me(e).devicePixelRatio||1,{x:o,y:s,width:c,height:l}=r.reference,u=(Math.round((o+c)*a)-Math.round(o*a))/a,d=(Math.round((s+l)*a)-Math.round(s*a))/a;i.setProperty(Fl,`${u}px`),i.setProperty(Il,`${d}px`)}}),Al(e=>({element:V.current||J(e.elements.floating).createElement(`div`),padding:V.current?f:0,offsetParent:`floating`}),[f]),{name:`transformOrigin`,fn(e){let{elements:{floating:t},middlewareData:n,placement:r,platform:o,rects:s,y:c}=e,l=lr(r),u=ur(r),d=pr(l)===`y`,f=V.current,p=typeof a==`function`?a(Vl(e,i,I)):a,m;m=!f&&u&&Math.abs(d?n.shift?.x||0:n.shift?.y||0)<=1?u===`start`===(d&&o.isRTL?.(t)===!0)?`100%`:`0%`:`${(d?n.arrow?.x||0:n.arrow?.y||0)+(d?f?.clientWidth||0:f?.clientHeight||0)/2}px`;let h=l===`top`||l===`left`?`calc(100% + ${p}px)`:`${-p}px`;return le&&d&&Math.abs(n.shift?.y||0)>p&&(h=`${s.reference.y+s.reference.height/2-c}px`),t.style.setProperty(Ll,d?`${m} ${h}`:`${h} ${m}`),{}}},jl,x),U(()=>{!_&&g&&g.update({referenceElement:null,floatingElement:null,domReferenceElement:null,positionReference:null})},[_,g]);let fe=l.useMemo(()=>({ancestorScroll:!p,elementResize:!p&&typeof ResizeObserver<`u`,layoutShift:!p&&typeof IntersectionObserver<`u`}),[p]),{refs:pe,elements:W,x:he,y:ge,middlewareData:G,update:K,placement:_e,context:ve,isPositioned:ye,floatingStyles:be}=t({rootContext:g,open:h?_:void 0,placement:R,middleware:se,strategy:r,whileElementsMounted:h?void 0:(...e)=>Oo(...e,fe),nodeId:b,externalTree:C}),{sideX:xe,sideY:Se}=G.adaptiveOrigin||Ml,Ce=ye?r:`fixed`,we=l.useMemo(()=>{let e;return e=ye?x?{position:Ce,[xe]:he,[Se]:ge}:{...be,position:Ce}:{position:Ce,top:0,left:0},e[Rl]=`100vw`,e[zl]=`100vh`,ye||(e.opacity=0),e},[x,Ce,xe,he,Se,ge,be,ye]),Te=l.useRef(null);U(()=>{if(!_)return;let e=P.current,t=typeof e==`function`?e():e,n=(Wl(t)?t.current:t)||null;n!==Te.current&&(pe.setPositionReference(n),Te.current=n)},[_,pe,N,P]),l.useEffect(()=>{if(!_)return;let e=P.current;typeof e!=`function`&&Wl(e)&&e.current!==Te.current&&(pe.setPositionReference(e.current),Te.current=e.current)},[_,pe,N,P]),l.useEffect(()=>{if(h&&_&&W.reference&&W.floating)return Oo(W.reference,W.floating,K,fe)},[h,_,W,K,fe]);let Ee=lr(_e),De=Bl(i,Ee,I),Oe=ur(_e)||`center`,ke=!!G.hide?.referenceHidden;U(()=>{S&&_&&ye&&Ee!==L&&T(Ee)},[S,_,ye,Ee,L]);let Ae=l.useMemo(()=>({position:`absolute`,top:G.arrow?.y,left:G.arrow?.x}),[G.arrow]),je=G.arrow?.centerOffset!==0;return l.useMemo(()=>({positionerStyles:we,arrowStyles:Ae,arrowRef:V,arrowUncentered:je,side:De,align:Oe,physicalSide:Ee,anchorHidden:ke,refs:pe,context:ve,isPositioned:ye,update:K}),[we,Ae,V,je,De,Oe,Ee,ke,pe,ve,ye,K])}function Wl(e){return e!=null&&`current`in e}function Gl(e){return e===`starting`?oa:et}function Kl(e,t,{styles:n,transitionStatus:r,props:i,refs:a,hidden:o,inert:s=!1}){let c={...n};return s&&(c.pointerEvents=`none`),$i(`div`,e,{state:t,ref:a,props:[{role:`presentation`,hidden:o,style:c},Gl(r),i],stateAttributesMapping:Xt})}var ql=l.forwardRef(function(e,t){let{render:n,className:r,anchor:i,positionMethod:a=`absolute`,side:o=`top`,align:s=`center`,sideOffset:c=0,alignOffset:u=0,collisionBoundary:d=`clipping-ancestors`,collisionPadding:f=5,arrowPadding:p=5,sticky:m=!1,disableAnchorTracking:h=!1,collisionAvoidance:g=ca,style:_,...v}=e,y=cl(),b=Sl(),x=y.useState(`open`),S=y.useState(`mounted`),C=y.useState(`trackCursorAxis`),w=y.useState(`disableHoverablePopup`),T=y.useState(`floatingRootContext`),E=y.useState(`instantType`),D=y.useState(`transitionStatus`),O=Hl({anchor:i,positionMethod:a,floatingRootContext:T,mounted:S,side:o,sideOffset:c,align:s,alignOffset:u,collisionBoundary:d,collisionPadding:f,sticky:m,arrowPadding:p,disableAnchorTracking:h,keepMounted:b,collisionAvoidance:g,adaptiveOrigin:y.useState(`adaptiveOrigin`)}),k=Kl(e,l.useMemo(()=>({open:x,side:O.side,align:O.align,anchorHidden:O.anchorHidden,instant:C===`none`?E:`tracking-cursor`}),[x,O.side,O.align,O.anchorHidden,C,E]),{styles:O.positionerStyles,transitionStatus:D,props:v,refs:[t,y.useStateSetter(`positionerElement`)],hidden:!S,inert:!x||C===`both`||w});return(0,Q.jsx)(Tl.Provider,{value:O,children:k})}),Jl=l.forwardRef(function(e,t){let{render:n,className:r,style:i,...a}=e,o=cl(),{side:s,align:c}=El(),l=o.useState(`open`),u=o.useState(`instantType`),d=o.useState(`transitionStatus`),f=o.useState(`popupProps`),p=o.useState(`floatingRootContext`),m=o.useState(`disabled`),h=o.useState(`closeDelay`);ys({open:l,ref:o.context.popupRef,onComplete(){l&&o.context.onOpenChangeComplete?.(!0)}}),$s(p,{enabled:!m,closeDelay:h});let g=o.useStateSetter(`popupElement`);return $i(`div`,e,{state:{open:l,side:s,align:c,instant:u,transitionStatus:d},ref:[t,o.context.popupRef,g],props:[bs,f,Gl(d),a],stateAttributesMapping:Zt})});function Yl({label:e,side:t=`top`,children:n}){return(0,Q.jsxs)(pl,{children:[(0,Q.jsx)(bl,{render:n}),(0,Q.jsx)(wl,{children:(0,Q.jsx)(ql,{className:`tooltip-positioner`,side:t,sideOffset:8,collisionPadding:8,children:(0,Q.jsx)(Jl,{className:`tooltip-popup`,children:e})})})]})}var Xl={clover:{label:`Clover`,color:`#35B8FF`,face:`eyes`,faceX:50,faceY:50,faceScale:1},flower:{label:`Flower`,color:`#2FCB7A`,face:`eyes`,faceX:50,faceY:51,faceScale:.95},triangle:{label:`Triangle`,color:`#DC48FF`,face:`eyes`,faceX:50,faceY:61,faceScale:.9},square:{label:`Square`,color:`#35B8FF`,face:`eyes`,faceX:50,faceY:50,faceScale:1},blob:{label:`Blob`,color:`#2FCB7A`,face:`eyes`,faceX:49.5,faceY:50,faceScale:1},ghost:{label:`Ghost`,color:`#F4F2FA`,face:`eyes`,faceX:50,faceY:48,faceScale:.95},circle:{label:`Circle`,color:`#9A62FF`,face:`eyes`,faceX:50,faceY:50,faceScale:1},drop:{label:`Drop`,color:`#1ED3C6`,face:`eyes`,faceX:50,faceY:62,faceScale:.9},star:{label:`Star`,color:`#FFD32B`,face:`eyes`,faceX:50,faceY:52,faceScale:.82},droid:{label:`Droid`,color:`#D5DBEA`,face:`eyes`,faceX:50,faceY:60,faceScale:.95},mech:{label:`Mech`,color:`#95A6C4`,face:`eyes`,faceX:50,faceY:59,faceScale:1},alien:{label:`Alien`,color:`#9BE85A`,face:`eyes`,faceX:50,faceY:45,faceScale:1.05},hexagon:{label:`Hexagon`,color:`#FF2A2A`,face:`eyes`,faceX:50,faceY:50,faceScale:.95},cat:{label:`Cat`,color:`#FF8C42`,face:`eyes`,faceX:50,faceY:58,faceScale:1},cloud:{label:`Cloud`,color:`#CFE6FF`,face:`eyes`,faceX:50,faceY:58,faceScale:.95},pill:{label:`Pill`,color:`#7B77F0`,face:`eyes`,faceX:50,faceY:50,faceScale:.9},pebble:{label:`Pebble`,color:`#2FCB7A`,face:`eyes`,faceX:50,faceY:50,faceScale:.95},puddle:{label:`Puddle`,color:`#FF2A2A`,face:`eyes`,faceX:50,faceY:50,faceScale:.95}},Zl=Object.keys(Xl);Object.fromEntries(Zl.map(e=>[e,Xl[e].color]));var Ql={default:`idle`,working:`working`,sleeping:`sleeping`},$l={clover:`M26.53 22.38A25 25 0 0 1 73.47 22.38A7 7 0 0 0 77.62 26.53A25 25 0 0 1 77.62 73.47A7 7 0 0 0 73.47 77.62A25 25 0 0 1 26.53 77.62A7 7 0 0 0 22.38 73.47A25 25 0 0 1 22.38 26.53A7 7 0 0 0 26.53 22.38Z`,flower:`M31.2 19.82A20.5 20.5 0 0 1 68.8 19.82A5 5 0 0 0 72.9 22.8A20.5 20.5 0 0 1 84.51 58.55A5 5 0 0 0 82.95 63.37A20.5 20.5 0 0 1 52.54 85.47A5 5 0 0 0 47.46 85.47A20.5 20.5 0 0 1 17.05 63.37A5 5 0 0 0 15.49 58.55A20.5 20.5 0 0 1 27.1 22.8A5 5 0 0 0 31.2 19.82Z`,triangle:`M38.75 27.43A13 13 0 0 1 61.25 27.43L82.7 64.49A13 13 0 0 1 71.45 84L28.55 84A13 13 0 0 1 17.3 64.49L38.75 27.43Z`,square:`M93 50C93 53.66 92.96 58.23 92.88 60.97C92.8 63.71 92.67 64.81 92.51 66.44C92.35 68.08 92.15 69.44 91.9 70.77C91.66 72.1 91.37 73.3 91.04 74.44C90.72 75.58 90.35 76.63 89.94 77.63C89.53 78.63 89.07 79.55 88.58 80.43C88.08 81.31 87.54 82.13 86.96 82.9C86.37 83.67 85.75 84.39 85.07 85.07C84.39 85.75 83.67 86.37 82.9 86.96C82.13 87.54 81.31 88.08 80.43 88.58C79.55 89.07 78.63 89.53 77.63 89.94C76.63 90.35 75.58 90.72 74.44 91.04C73.3 91.37 72.1 91.66 70.77 91.9C69.44 92.15 68.08 92.35 66.44 92.51C64.81 92.67 63.71 92.8 60.97 92.88C58.23 92.96 53.66 93 50 93C46.34 93 41.77 92.96 39.03 92.88C36.29 92.8 35.19 92.67 33.56 92.51C31.92 92.35 30.56 92.15 29.23 91.9C27.9 91.66 26.7 91.37 25.56 91.04C24.42 90.72 23.37 90.35 22.37 89.94C21.37 89.53 20.45 89.07 19.57 88.58C18.69 88.08 17.87 87.54 17.1 86.96C16.33 86.37 15.61 85.75 14.93 85.07C14.25 84.39 13.63 83.67 13.04 82.9C12.46 82.13 11.92 81.31 11.42 80.43C10.93 79.55 10.47 78.63 10.06 77.63C9.65 76.63 9.28 75.58 8.96 74.44C8.63 73.3 8.34 72.1 8.1 70.77C7.85 69.44 7.65 68.08 7.49 66.44C7.33 64.81 7.2 63.71 7.12 60.97C7.04 58.23 7 53.66 7 50C7 46.34 7.04 41.77 7.12 39.03C7.2 36.29 7.33 35.19 7.49 33.56C7.65 31.92 7.85 30.56 8.1 29.23C8.34 27.9 8.63 26.7 8.96 25.56C9.28 24.42 9.65 23.37 10.06 22.37C10.47 21.37 10.93 20.45 11.42 19.57C11.92 18.69 12.46 17.87 13.04 17.1C13.63 16.33 14.25 15.61 14.93 14.93C15.61 14.25 16.33 13.63 17.1 13.04C17.87 12.46 18.69 11.92 19.57 11.42C20.45 10.93 21.37 10.47 22.37 10.06C23.37 9.65 24.42 9.28 25.56 8.96C26.7 8.63 27.9 8.34 29.23 8.1C30.56 7.85 31.92 7.65 33.56 7.49C35.19 7.33 36.29 7.2 39.03 7.12C41.77 7.04 46.34 7 50 7C53.66 7 58.23 7.04 60.97 7.12C63.71 7.2 64.81 7.33 66.44 7.49C68.08 7.65 69.44 7.85 70.77 8.1C72.1 8.34 73.3 8.63 74.44 8.96C75.58 9.28 76.63 9.65 77.63 10.06C78.63 10.47 79.55 10.93 80.43 11.42C81.31 11.92 82.13 12.46 82.9 13.04C83.67 13.63 84.39 14.25 85.07 14.93C85.75 15.61 86.37 16.33 86.96 17.1C87.54 17.87 88.08 18.69 88.58 19.57C89.07 20.45 89.53 21.37 89.94 22.37C90.35 23.37 90.72 24.42 91.04 25.56C91.37 26.7 91.66 27.9 91.9 29.23C92.15 30.56 92.35 31.92 92.51 33.56C92.67 35.19 92.8 36.29 92.88 39.03C92.96 41.77 93 46.34 93 50Z`,blob:`M93.92 50C94.18 51.9 94.24 53.9 93.99 55.79C93.73 57.68 93.18 59.61 92.39 61.36C91.6 63.1 90.48 64.78 89.27 66.27C88.07 67.76 86.58 69.08 85.14 70.29C83.7 71.49 82.1 72.5 80.62 73.5C79.14 74.49 77.64 75.34 76.24 76.24C74.84 77.15 73.51 78 72.2 78.93C70.88 79.86 69.66 80.83 68.36 81.8C67.06 82.76 65.78 83.82 64.39 84.74C63 85.67 61.55 86.63 60.01 87.35C58.47 88.08 56.82 88.73 55.15 89.1C53.48 89.47 51.71 89.64 50 89.57C48.29 89.5 46.55 89.16 44.91 88.68C43.27 88.21 41.67 87.47 40.16 86.72C38.65 85.96 37.24 85.02 35.86 84.13C34.48 83.24 33.19 82.29 31.89 81.37C30.58 80.46 29.32 79.56 28.03 78.63C26.74 77.71 25.44 76.82 24.16 75.84C22.88 74.86 21.57 73.87 20.36 72.74C19.15 71.62 17.95 70.42 16.91 69.1C15.88 67.79 14.92 66.35 14.15 64.85C13.38 63.35 12.76 61.73 12.29 60.1C11.81 58.48 11.52 56.78 11.29 55.1C11.06 53.41 10.98 51.71 10.91 50C10.83 48.29 10.83 46.59 10.83 44.84C10.84 43.1 10.85 41.34 10.93 39.53C11.02 37.72 11.09 35.86 11.34 33.99C11.59 32.12 11.88 30.16 12.43 28.31C12.99 26.46 13.69 24.56 14.66 22.88C15.64 21.21 16.86 19.58 18.27 18.27C19.69 16.96 21.4 15.84 23.17 15.03C24.93 14.22 26.95 13.71 28.89 13.43C30.83 13.15 32.9 13.21 34.82 13.36C36.74 13.5 38.66 13.92 40.43 14.28C42.2 14.65 43.87 15.16 45.46 15.54C47.06 15.93 48.52 16.31 50 16.58C51.48 16.85 52.87 17.02 54.32 17.17C55.77 17.32 57.22 17.36 58.71 17.49C60.2 17.62 61.74 17.7 63.28 17.95C64.81 18.19 66.39 18.5 67.91 18.98C69.43 19.46 70.95 20.08 72.38 20.83C73.81 21.58 75.19 22.5 76.5 23.5C77.81 24.5 79.03 25.63 80.22 26.81C81.41 27.99 82.54 29.25 83.65 30.57C84.76 31.89 85.85 33.26 86.89 34.72C87.93 36.18 88.98 37.69 89.9 39.31C90.82 40.92 91.73 42.64 92.4 44.42C93.07 46.2 93.66 48.1 93.92 50Z`,ghost:`M17 50C17 31.78 31.78 17 50 17C68.22 17 83 31.78 83 50V81.5Q72 93.5 61 81.5Q50 93.5 39 81.5Q28 93.5 17 81.5Z`,circle:`M50 8A42 42 0 1 1 50 92A42 42 0 1 1 50 8Z`,drop:`M50 8.5C52.2 8.5 53.4 10.3 56.4 15.2C62.9 25.5 84 44.6 84 61.5C84 80.3 68.8 92 50 92C31.2 92 16 80.3 16 61.5C16 44.6 37.1 25.5 43.6 15.2C46.6 10.3 47.8 8.5 50 8.5Z`,star:`M45.77 9.7A5 5 0 0 1 54.23 9.7L65.02 26.81A4 4 0 0 0 67.42 28.55L87.02 33.53A5 5 0 0 1 89.63 41.57L76.7 57.12A4 4 0 0 0 75.78 59.94L77.11 80.12A5 5 0 0 1 70.26 85.09L51.48 77.59A4 4 0 0 0 48.52 77.59L29.74 85.09A5 5 0 0 1 22.89 80.12L24.22 59.94A4 4 0 0 0 23.3 57.12L10.37 41.57A5 5 0 0 1 12.98 33.53L32.58 28.55A4 4 0 0 0 34.98 26.81L45.77 9.7Z`,droid:`M16 50C16 38.95 24.95 30 36 30H64C75.05 30 84 38.95 84 50V70C84 81.05 75.05 90 64 90H36C24.95 90 16 81.05 16 70ZM4 62A7 7 0 1 1 18 62A7 7 0 1 1 4 62ZM82 62A7 7 0 1 1 96 62A7 7 0 1 1 82 62Z`,mech:`M10 48C10 38.06 18.06 30 28 30H72C81.94 30 90 38.06 90 48V70C90 79.94 81.94 88 72 88H28C18.06 88 10 79.94 10 70ZM3 54C3 51.79 4.79 50 7 50H11V72H7C4.79 72 3 70.21 3 68ZM89 50H93C95.21 50 97 51.79 97 54V68C97 70.21 95.21 72 93 72H89Z`,alien:`M50 10C70 10 83 27 83 46C83 65 64 92 50 92C36 92 17 65 17 46C17 27 30 10 50 10Z`,hexagon:`M91.4 45.5A9 9 0 0 1 91.4 54.5L74.6 83.61A9 9 0 0 1 66.8 88.11L33.2 88.11A9 9 0 0 1 25.4 83.61L8.6 54.5A9 9 0 0 1 8.6 45.5L25.4 16.39A9 9 0 0 1 33.2 11.89L66.8 11.89A9 9 0 0 1 74.6 16.39L91.4 45.5Z`,cat:`M50 20A36 36 0 1 1 50 92A36 36 0 1 1 50 20ZM24.72 44.64A4.5 4.5 0 0 1 17.35 40.67L20.21 16.66A4.5 4.5 0 0 1 26.86 13.26L42.3 21.83A4.5 4.5 0 0 1 43.02 29.21L24.72 44.64ZM82.65 40.67A4.5 4.5 0 0 1 75.28 44.64L56.98 29.21A4.5 4.5 0 0 1 57.7 21.83L73.14 13.26A4.5 4.5 0 0 1 79.79 16.66L82.65 40.67Z`,cloud:`M19 44A25 25 0 1 1 69 44A25 25 0 1 1 19 44ZM47 50A21 21 0 1 1 89 50A21 21 0 1 1 47 50ZM7 68A17 17 0 1 1 41 68A17 17 0 1 1 7 68ZM32 73A18 18 0 1 1 68 73A18 18 0 1 1 32 73ZM60 70A16 16 0 1 1 92 70A16 16 0 1 1 60 70Z`,pill:`M28 28H72C84.15 28 94 37.85 94 50C94 62.15 84.15 72 72 72H28C15.85 72 6 62.15 6 50C6 37.85 15.85 28 28 28Z`,pebble:`M94.6 50C94.71 51.92 94.56 53.93 94.17 55.82C93.79 57.7 93.13 59.6 92.28 61.33C91.44 63.06 90.32 64.72 89.1 66.19C87.87 67.67 86.41 69.01 84.92 70.16C83.42 71.31 81.75 72.29 80.11 73.1C78.47 73.92 76.73 74.55 75.06 75.06C73.39 75.58 71.7 75.91 70.1 76.2C68.5 76.48 66.93 76.62 65.45 76.76C63.96 76.9 62.55 76.94 61.2 77.03C59.84 77.11 58.57 77.16 57.31 77.26C56.05 77.36 54.86 77.48 53.64 77.63C52.42 77.79 51.24 77.98 50 78.18C48.76 78.39 47.52 78.64 46.2 78.85C44.89 79.06 43.53 79.3 42.11 79.46C40.69 79.61 39.2 79.75 37.67 79.77C36.14 79.78 34.54 79.74 32.95 79.54C31.35 79.33 29.7 79.03 28.1 78.55C26.49 78.07 24.86 77.45 23.33 76.67C21.8 75.88 20.29 74.94 18.92 73.85C17.54 72.77 16.23 71.51 15.08 70.16C13.94 68.8 12.9 67.29 12.04 65.72C11.17 64.16 10.45 62.46 9.91 60.74C9.36 59.03 8.98 57.22 8.76 55.43C8.55 53.64 8.5 51.8 8.6 50C8.71 48.2 8.98 46.39 9.38 44.65C9.79 42.91 10.35 41.19 11.02 39.56C11.7 37.92 12.52 36.34 13.43 34.85C14.34 33.37 15.39 31.96 16.5 30.66C17.61 29.36 18.84 28.15 20.11 27.07C21.39 25.98 22.76 25 24.15 24.15C25.54 23.3 27.01 22.56 28.48 21.95C29.94 21.33 31.46 20.85 32.95 20.46C34.44 20.08 35.95 19.83 37.43 19.66C38.91 19.48 40.38 19.43 41.81 19.43C43.24 19.43 44.64 19.53 46.01 19.66C47.37 19.78 48.7 19.98 50 20.18C51.3 20.39 52.57 20.63 53.83 20.87C55.1 21.11 56.34 21.37 57.6 21.62C58.87 21.87 60.13 22.12 61.43 22.39C62.74 22.66 64.07 22.93 65.45 23.24C66.83 23.56 68.25 23.88 69.72 24.3C71.19 24.72 72.71 25.17 74.25 25.75C75.78 26.34 77.37 27 78.91 27.81C80.46 28.63 82.04 29.56 83.5 30.66C84.97 31.75 86.43 33 87.7 34.38C88.98 35.77 90.19 37.32 91.17 38.97C92.14 40.62 92.98 42.43 93.56 44.27C94.13 46.1 94.5 48.08 94.6 50Z`,puddle:`M85.34 50C85.65 51.54 85.9 53.13 86.01 54.74C86.11 56.35 86.11 58 85.95 59.63C85.8 61.26 85.51 62.93 85.07 64.52C84.62 66.12 84.03 67.72 83.3 69.23C82.58 70.74 81.7 72.21 80.72 73.57C79.74 74.94 78.62 76.23 77.43 77.43C76.24 78.62 74.93 79.72 73.58 80.73C72.23 81.74 70.79 82.65 69.33 83.48C67.86 84.31 66.34 85.04 64.79 85.71C63.24 86.37 61.65 86.95 60.04 87.46C58.42 87.96 56.77 88.4 55.1 88.75C53.43 89.09 51.72 89.37 50 89.54C48.28 89.71 46.52 89.81 44.76 89.76C43.01 89.72 41.22 89.58 39.47 89.29C37.72 89 35.95 88.58 34.26 88C32.57 87.42 30.89 86.69 29.33 85.8C27.77 84.92 26.26 83.87 24.91 82.7C23.56 81.53 22.3 80.19 21.23 78.77C20.16 77.35 19.22 75.79 18.47 74.2C17.71 72.61 17.13 70.91 16.7 69.23C16.26 67.55 16.02 65.81 15.88 64.13C15.75 62.45 15.78 60.76 15.88 59.14C15.97 57.52 16.21 55.94 16.45 54.42C16.7 52.89 17.03 51.43 17.34 50C17.65 48.57 18 47.2 18.32 45.83C18.63 44.46 18.94 43.13 19.24 41.76C19.53 40.39 19.79 39.03 20.08 37.61C20.36 36.18 20.62 34.74 20.95 33.23C21.28 31.72 21.61 30.16 22.07 28.57C22.52 26.98 23.02 25.32 23.69 23.69C24.35 22.06 25.11 20.38 26.05 18.79C26.99 17.21 28.08 15.62 29.33 14.2C30.58 12.78 32 11.41 33.54 10.26C35.08 9.12 36.8 8.11 38.57 7.35C40.34 6.6 42.27 6.04 44.17 5.73C46.08 5.43 48.08 5.37 50 5.54C51.92 5.71 53.87 6.15 55.69 6.75C57.52 7.36 59.3 8.22 60.94 9.19C62.57 10.15 64.11 11.33 65.51 12.56C66.91 13.78 68.17 15.15 69.33 16.52C70.48 17.89 71.5 19.34 72.44 20.76C73.38 22.18 74.19 23.62 74.97 25.03C75.75 26.43 76.44 27.83 77.12 29.19C77.8 30.56 78.42 31.89 79.05 33.23C79.67 34.57 80.28 35.87 80.87 37.21C81.46 38.55 82.05 39.88 82.6 41.27C83.14 42.65 83.68 44.05 84.14 45.51C84.6 46.96 85.03 48.46 85.34 50Z`},eu={droid:`M47.5 14H52.5V32H47.5ZM43 11A7 7 0 1 1 57 11A7 7 0 1 1 43 11Z`,mech:`M19.5 32L24.5 32L17 13L12 13ZM75.5 32L80.5 32L88 13L83 13ZM10 11.5A4.5 4.5 0 1 1 19 11.5A4.5 4.5 0 1 1 10 11.5ZM81 11.5A4.5 4.5 0 1 1 90 11.5A4.5 4.5 0 1 1 81 11.5Z`};function tu(e){let t=e.trim(),n=t.match(/^hsla?\(\s*([\d.]+)(?:deg)?[,\s]+([\d.]+)%[,\s]+([\d.]+)%/i);if(n)return su([Number(n[1])/360,Number(n[2])/100,Number(n[3])/100]);let r=t.match(/^#([0-9a-f]{3}|[0-9a-f]{6})$/i);if(r){let e=r[1];e.length===3&&(e=e.split(``).map(e=>e+e).join(``));let t=parseInt(e,16);return[t>>16&255,t>>8&255,t&255]}let i=t.match(/^rgba?\(\s*([\d.]+)[,\s]+([\d.]+)[,\s]+([\d.]+)/i);return i?[Number(i[1]),Number(i[2]),Number(i[3])]:null}function nu(e){let t=tu(e);if(!t)return .5;let n=e=>{let t=e/255;return t<=.03928?t/12.92:((t+.055)/1.055)**2.4};return .2126*n(t[0])+.7152*n(t[1])+.0722*n(t[2])}var ru=`#1E1A33`,iu=`#F7F5F2`;function au(e){return nu(e)<.13?iu:ru}function ou([e,t,n]){e/=255,t/=255,n/=255;let r=Math.max(e,t,n),i=Math.min(e,t,n),a=(r+i)/2;if(r===i)return[0,0,a];let o=r-i,s=a>.5?o/(2-r-i):o/(r+i),c=0;return c=r===e?(t-n)/o+(t<n?6:0):r===t?(n-e)/o+2:(e-t)/o+4,[c/6,s,a]}function su([e,t,n]){if(t===0)return[n*255,n*255,n*255];let r=n<.5?n*(1+t):n+t-n*t,i=2*n-r,a=e=>(e=(e%1+1)%1,e<1/6?i+(r-i)*6*e:e<1/2?r:e<2/3?i+(r-i)*(2/3-e)*6:i);return[a(e+1/3)*255,a(e)*255,a(e-1/3)*255]}function cu([e,t,n]){return`hsl(${(e*360).toFixed(1)} ${(t*100).toFixed(1)}% ${(n*100).toFixed(1)}%)`}var lu=e=>Math.min(1,Math.max(0,e));function uu(e,t,n=0){let r=tu(e);if(!r)return e;let[i,a,o]=ou(r);return cu([i,lu(a+n+(t<0?-t*.25:0)),lu(o+t)])}var du=[`default`,`working`,`sleeping`],fu=.68,pu=26,mu=.2,hu={height:pu,time:fu,stretch:1,squash:1.15,squashTime:.37,squashEase:`pulse`,groundTime:.11,groundEase:`pulse`,riseTime:.33,riseEase:`pulse`,clickSquashTime:.24,spin:1,lean:6,every:8,land:0},gu=(e,t)=>t?e.clickSquashTime:mu*e.time,_u=(e,t)=>gu(e,t)+e.time+vu[e.squashEase]*(t?e.clickSquashTime:e.squashTime)+Math.max(0,e.groundTime)+e.riseTime+Math.max(0,e.land)+.05,vu={sharp:0,pulse:2/7,soft:.5,bouncy:.144},yu=(e,t)=>{if(e<=0)return 1;if(e>=1)return 0;switch(t){case`sharp`:return(1-e)*(1-e);case`soft`:return .5+.5*Math.cos(Math.PI*e);case`bouncy`:return Math.exp(-3.2*e)*Math.cos(5.4*e)-e*e*e*.026;default:{let t=4.2*e;return(1+t)*Math.exp(-t)-e*e*e*.078}}},bu=(e,t)=>1+.25*xu(e,t),xu=(e,t)=>{if(e<=0||e>=1)return 0;let n;switch(t){case`sharp`:n=(1-e)*(1-e);break;case`soft`:n=Math.sin(Math.PI*e)**2;break;case`bouncy`:n=Math.exp(-3.15*e)*Math.sin(8.43*e)/.596;break;default:{let t=7*e;n=t*t*Math.exp(2-t)/4}}let r=e>.85?1-(e-.85)/.15:1;return n*r*r*(3-2*r)},Su=e=>Math.exp(-((Math.min(Math.abs(e),Math.abs(e-1))/.11)**2)),Cu=Math.PI/180,wu=Math.PI*2,Tu={default:1.2,working:.7,sleeping:1.4},Eu=1;function Du(e){let t=e*2654435761>>>0||1;return()=>{t=t+1831565813>>>0;let e=t;return e=Math.imul(e^e>>>15,e|1),e^=e+Math.imul(e^e>>>7,e|61),((e^e>>>14)>>>0)/4294967296}}function Ou(e,t,n,r){return e+(t-e)*(1-Math.exp(-n*r))}var ku=e=>e<.5?4*e*e*e:1-(-2*e+2)**3/2,Au=e=>.5-.5*Math.cos(Math.PI*e),ju=class{constructor(e,t,n,r,i,a=!1){this.rand=e,this.amp=t,this.holdMin=n,this.holdMax=r,this.rate=i,this.spring=a,this.value=0,this.vel=0,this.target=0,this.next=0}update(e,t){if(e>=this.next&&(this.target=(this.rand()*2-1)*this.amp,this.next=e+this.holdMin+this.rand()*(this.holdMax-this.holdMin)),this.spring){let e=this.rate*1.6;this.vel+=(e*e*(this.target-this.value)-1.8*e*this.vel)*t,this.value+=this.vel*t}else this.value=Ou(this.value,this.target,this.rate,t)}aim(e){this.target=e,this.next=1/0}set(e,t,n,r){this.amp=e,this.holdMin=t,this.holdMax=n,this.rate=r,this.next=0}},Mu=class{constructor(e){this.duration=e,this.p=-1}fire(){this.p=0}get active(){return this.p>=0}update(e){this.p<0||(this.p+=e/this.duration,this.p>=1&&(this.p=-1))}},Nu=35*Cu,Pu=14*Cu,Fu=3.2*Cu,Iu=2.6,Lu={default:{pitch:0,roll:0,y:0,lookX:0,lookY:0},working:{pitch:5*Cu,roll:0,y:0,lookX:0,lookY:0},sleeping:{pitch:-16*Cu,roll:6*Cu,y:3,lookX:0,lookY:1}},Ru=class{constructor(e,t=`default`){this.pose={yaw:0,pitch:0,roll:0,x:0,y:0,sx:1,sy:1,eyeOpen:1,blinkL:0,blinkR:0,lookX:0,lookY:0,breath:0,laugh:0,whirl:0,whirlAngle:0,w:[1,0,0]},this.state=`default`,this.t=0,this.wFrom=[1,0,0],this.tr=1,this.trDuration=1.2,this.blink=new Mu(.17),this.blinkAgain=!1,this.dart=new Mu(.12),this.dartX=0,this.dartY=0,this.flip=new Mu(_u(hu,!1)),this.flipPoked=!1,this.jump={...hu},this.flipSide=1,this.nod=new Mu(1.7),this.hopPhase=0,this.hopCount=0,this.hopGain=0,this.laughEv=new Mu(.8),this.prevYaw=0,this.jelly=0,this.jellyV=0,this.gazeLead=0,this.gazeDir=[0,0],this.gazeAt=0,this.turnK=1,this.breathPhase=0,this.ptrX=0,this.ptrY=0,this.ptrS=0,this.ptrTargetX=0,this.ptrTargetY=0,this.ptrTargetS=0,this.baseYaw=0,this.rand=Du(Math.floor(e*1e6)+1);let n=this.rand;this.yawW=new ju(n,36*Cu,1.1,2.6,3,!0),this.pitchW=new ju(n,10*Cu,1.1,2.6,2.6,!0),this.rollW=new ju(n,5*Cu,1.6,3.2,2,!0),this.lookXW=new ju(n,3.6,.5,2,14),this.lookYW=new ju(n,2.4,.5,2,14),this.t=n()*10,this.hopPhase=n(),this.breathPhase=n(),this.blinkAt=this.t+1+n()*3,this.flipAt=this.nextFlip(this.t,1),this.nodAt=this.t+3+n()*4,this.dartAt=this.t+1+n()*2,this.laughAt=this.t+.6+n()*1.5,this.setState(t,!0)}setState(e,t=!1){if(e===this.state&&!t)return;let n=this.state;this.state=e;let r=this.pose.w;if(t){for(let t=0;t<3;t++)r[t]=+(du[t]===e);this.tr=1}else this.wFrom=[r[0],r[1],r[2]],this.tr=0,this.trDuration=n===`sleeping`?Eu:Tu[e];switch(e){case`default`:this.yawW.set(Nu,2.6,5.4,2),this.pitchW.set(Pu,2.8,5.8,1.8),this.rollW.set(Fu,3.4,6.6,1.5),this.gazeAt=0,this.gazeDir=[0,0],this.lookXW.set(3.6,.6,2.2,13),this.lookYW.set(2.4,.6,2.2,13),this.flipAt=this.nextFlip(this.t,.6);break;case`working`:this.yawW.set(16*Cu,.9,1.8,4),this.pitchW.set(3*Cu,1.2,2.4,3),this.rollW.set(0,1,2,3),this.lookXW.set(2,.5,1.2,12),this.lookYW.set(1,.5,1.2,12),this.hopPhase=0,this.hopCount=0,this.laughAt=this.t+.5+this.rand()*1.2;break;case`sleeping`:this.yawW.set(7*Cu,3,6,.7),this.pitchW.set(3*Cu,3,6,.7),this.rollW.set(2*Cu,3,6,.6),this.lookXW.set(0,2,4,2),this.lookYW.set(0,2,4,2),this.nodAt=this.t+2.5+this.rand()*4}}setPointer(e,t,n){this.ptrTargetX=Math.max(-1.2,Math.min(1.2,e)),this.ptrTargetY=Math.max(-1.2,Math.min(1.2,t)),this.ptrTargetS=Math.max(0,Math.min(1,n))}poke(){this.flip.active&&this.flip.p<.6||(this.flipPoked=!0,this.flip.duration=_u(this.jump,!0),this.flipSide=this.rand()<.5?-1:1,this.flip.fire(),this.flipAt=this.nextFlip(this.t,1.1))}setTurn(e){let t=Math.max(0,e);t!==this.turnK&&(this.turnK=t,this.state==="default"&&(this.gazeAt=0))}setJump(e){let t=this.jump.every;Object.assign(this.jump,e),e.every!==void 0&&e.every!==t&&(this.flipAt=this.nextFlip(this.t,1))}nextGaze(){let e=this.rand,[t,n]=this.gazeDir;if(t!==0||n!==0){let r=e();return r<.66?[-t,-n]:r<.85?[-t,n]:[0,0]}let r=[[1,-1],[-1,1],[-1,-1],[1,1]];return r[Math.floor(e()*r.length)]}nextFlip(e,t){let n=this.jump.every;return n>0?e+n*t*(.625+this.rand()*.75):1/0}update(e){e=Math.min(e,.05),this.t+=e;let t=this.t,n=this.pose,r=n.w;if(this.tr<1){this.tr=Math.min(1,this.tr+e/this.trDuration);let t=Au(this.tr);for(let e=0;e<3;e++){let n=+(du[e]===this.state);r[e]=this.wFrom[e]+(n-this.wFrom[e])*t}}let[i,a,o]=r,s={pitch:0,roll:0,y:0,lookX:0,lookY:0};for(let e=0;e<3;e++){let t=Lu[du[e]];s.pitch+=t.pitch*r[e],s.roll+=t.roll*r[e],s.y+=t.y*r[e],s.lookX+=t.lookX*r[e],s.lookY+=t.lookY*r[e]}if(this.state==="default"&&t>=this.gazeAt){let[e,n]=this.nextGaze();this.gazeDir=[e,n];let r=.84+this.rand()*.16;this.yawW.aim(e*Nu*r*this.turnK),this.pitchW.aim(n*Pu*r),this.rollW.aim(e*Fu*r*this.turnK),this.gazeAt=t+Iu+this.rand()*1.8000000000000003}this.yawW.update(t,e),this.pitchW.update(t,e),this.rollW.update(t,e),this.lookXW.update(t,e),this.lookYW.update(t,e),this.ptrS=Ou(this.ptrS,this.ptrTargetS,8,e),this.ptrX=Ou(this.ptrX,this.ptrTargetX,14,e),this.ptrY=Ou(this.ptrY,this.ptrTargetY,14,e);let c=this.ptrS,l=1-.75*c;this.baseYaw=Ou(this.baseYaw,this.yawW.value*l+22*Cu*this.ptrX*c,5,e);let u=s.pitch+this.pitchW.value*l-12*Cu*this.ptrY*c,d=s.roll+this.rollW.value*l,f=s.y,p=s.lookX+this.lookXW.value*l+4.5*this.ptrX*c,m=s.lookY+this.lookYW.value*l+3*this.ptrY*c,h=0,g=0,_=1,v=1,y=0,b=0,x=0,S=0,C=0,w=0,T=0,E=0,D=(e,t,n)=>{let r=Math.min(1,Math.max(0,(n-e)/(t-e)));return r*r*(3-2*r)},O=e=>D(.1,.26,e)*(1-D(.66,.9,e)),k=e=>wu*(1.5*e+.9*ku(e));if(t>=this.blinkAt&&!this.blink.active&&i+a>.5&&(this.blink.fire(),this.blinkAgain=!this.blinkAgain&&this.rand()<.22,this.blinkAt=t+(this.blinkAgain?.28:2.2+this.rand()*2.6)),this.blink.update(e),this.blink.active&&(x=Math.sin(Math.PI*this.blink.p)),t>=this.dartAt&&!this.dart.active&&i+a>.5&&(this.dart.fire(),this.dartX=(this.rand()*2-1)*4,this.dartY=(this.rand()*2-1)*2,this.dart.duration=.25+this.rand()*.45,this.dartAt=t+1.2+this.rand()*2.6),this.dart.update(e),this.dart.active){let e=this.dart.p,t=e<.15?e/.15:e>.8?(1-e)/.2:1;S+=this.dartX*t*(i+a),C+=this.dartY*t*(i+a)}if(this.state==="default"&&t>=this.flipAt&&!this.flip.active&&(this.flipPoked=!1,this.flip.duration=_u(this.jump,!1),this.flipSide=this.rand()<.5?-1:1,this.flip.fire(),this.flipAt=this.nextFlip(t,1)),this.flip.update(e),this.flip.active){let e=this.jump,t=gu(e,this.flipPoked),n=(this.flip.p*this.flip.duration-t)/e.time,r=Math.min(1,Math.max(0,n)),i=Math.sin(Math.PI*r);h+=wu*e.spin*ku(r),g-=e.height*i;let a=(n-1)*e.time-e.land,o=this.flipPoked?e.clickSquashTime:e.squashTime,s=e=>this.flipPoked?e*e*(3-2*e):Su(e-1),c=Math.max(0,e.groundTime),l=vu[e.squashEase]*o,u=a-l-c,d=a<=l?xu(a/o,e.squashEase):u<=0?bu((a-l)/c,e.groundEase):yu(u/e.riseTime,e.riseEase),f=(n<0?s(Math.max(0,1+n*e.time/t)):a>0?d:n<.2?Su(n):0)*e.squash;_+=.16*f-.06*i*e.stretch,v+=-.18*f+.09*i*e.stretch,b+=this.flipSide*e.lean*Cu*i,e.spin>0&&(w=Math.max(w,i),T=Math.max(T,O(r)),E=k(r))}let A=this.jump,j=Math.max(0,A.groundTime),M=j+A.riseTime;if(this.state===`working`&&(this.hopGain=a),this.hopGain>.02&&(this.state===`working`||this.hopPhase>0)){this.hopPhase+=e/fu,this.hopPhase>=1&&(this.state===`working`?(--this.hopPhase,this.hopCount+=1):(this.hopPhase-1)*fu>=M&&(this.hopPhase=0,this.hopGain=0));let t=this.hopGain,n=Math.min(1,this.hopPhase),r=Math.sin(Math.PI*n),i=this.hopCount%3==2;g-=(i?pu:18)*r*t;let a=this.state!==`working`&&this.hopPhase>1?(this.hopPhase-1)*fu:-1,o=a<0?Su(this.hopPhase):a<j?bu(a/j,A.groundEase):yu((a-j)/A.riseTime,A.riseEase);_+=(.16*o-.06*r)*t,v+=(-.18*o+.09*r)*t,i&&(h+=wu*ku(n)*t,w=Math.max(w,r*t),O(n)*t>T&&(T=O(n)*t,E=k(n))),b+=(this.hopCount%2==0?1:-1)*6*Cu*r*t}if(this.state===`working`&&t>=this.laughAt&&!this.laughEv.active&&(this.laughEv.fire(),this.laughEv.duration=.6+this.rand()*.5,this.laughAt=t+1.6+this.rand()*2.2),this.laughEv.update(e),this.laughEv.active){let e=this.laughEv.p;w=Math.max(w,e<.18?e/.18:e>.78?(1-e)/.22:1)}if(this.state===`sleeping`&&t>=this.nodAt&&!this.nod.active&&(this.nod.fire(),this.nodAt=t+4+this.rand()*4),this.nod.update(e),this.nod.active){let e=this.nod.p,t=e<.72?ku(e/.72):1-ku((e-.72)/.28);y-=13*Cu*t*o}this.breathPhase+=e/(3.6+1.2*o);let N=Math.sin(this.breathPhase*wu);n.breath=N,_+=N*(.008+.014*o),v+=N*(.012+.02*o);let P=Math.sin(t*wu/3.4)*2*(1-o);n.yaw=this.baseYaw+h;let F=this.baseYaw-this.prevYaw;F=((F+Math.PI)%wu+wu)%wu-Math.PI,this.prevYaw=this.baseYaw;let I=e>0?Math.abs(F)/e:0,L=e>0?Math.max(-2.2,Math.min(2.2,F/e*2.4)):0;this.gazeLead=Ou(this.gazeLead,L,9,e);let R=Math.min(.22,.055*I);this.jellyV+=(256*(R-this.jelly)-14.4*this.jellyV)*e,this.jelly+=this.jellyV*e;let z=Math.max(-.08,Math.min(.28,this.jelly))*.6;_*=1+z,v*=1-.55*z,n.pitch=u+y,n.roll=d+b,n.x=0,n.y=f+g+P,n.sx=_,n.sy=v,n.eyeOpen=1,n.laugh=Ou(n.laugh,w,30,e),n.blinkL=x,n.blinkR=x,n.lookX=p+S+this.gazeLead,n.lookY=m+C,n.whirl=T,n.whirlAngle=E}};function zu(e){let t=Lu[e];return{yaw:0,pitch:t.pitch,roll:t.roll,x:0,y:t.y,sx:1,sy:1,eyeOpen:1,blinkL:0,blinkR:0,lookX:t.lookX,lookY:t.lookY,breath:0,laugh:0,whirl:0,whirlAngle:0,w:du.map(t=>+(t===e))}}var Bu=64,Vu=4096,Hu=24,Uu=0xe8d4a51000,Wu=48*Math.PI/180,Gu=Math.cos(Wu),Ku=Math.sin(Wu),qu=(e,t)=>t+(1-t)*Math.sqrt(Math.max(0,1-e*e));function Ju(e,t,n,r,i,a){let o=0;i[0]=0,a[0]=-1e30,a[1]=1e30;for(let n=1;n<t;n++){let t=0;for(;;){let r=i[o];if(t=(e[n]+n*n-e[r]-r*r)/(2*(n-r)),t>a[o])break;o--}o++,i[o]=n,a[o]=t,a[o+1]=1e30}o=0;for(let s=0;s<t;s++){for(;a[o+1]<s;)o++;let t=i[o];n[s]=(s-t)*(s-t)+e[t],r[s]=t}}function Yu(e,t,n,r,i){let a=new Float32Array(n),o=new Float32Array(n),s=new Int32Array(n),c=new Int32Array(n),l=new Float32Array(n+1),u=new Float32Array(n*n),d=new Int32Array(n*n);for(let r=0;r<n;r++){for(let i=0;i<n;i++)a[i]=e[i*n+r]===t?0:Uu;Ju(a,n,o,s,c,l);for(let e=0;e<n;e++)u[e*n+r]=o[e],d[e*n+r]=s[e]}for(let e=0;e<n;e++){let t=e*n;for(let e=0;e<n;e++)a[e]=u[t+e];Ju(a,n,o,s,c,l);for(let e=0;e<n;e++)r[t+e]=o[e],i&&(i[t+e]=d[t+s[e]]*n+s[e])}}function Xu(e,t,n){for(let r=0;r<t;r++){let i=r*t;for(let r=0;r<t;r++){let a=r<2?0:r-2,o=r<1?0:r-1,s=r>t-2?t-1:r+1,c=r>t-3?t-1:r+2;n[i+r]=(e[i+a]+4*e[i+o]+6*e[i+r]+4*e[i+s]+e[i+c])*.0625}}for(let r=0;r<t;r++)for(let i=0;i<t;i++){let a=i<2?0:i-2,o=i<1?0:i-1,s=i>t-2?t-1:i+1,c=i>t-3?t-1:i+2;e[i*t+r]=(n[a*t+r]+4*n[o*t+r]+6*n[i*t+r]+4*n[s*t+r]+n[c*t+r])*.0625}}function Zu(e,t,n){let r=[];for(let n=t,i=1;i<=4&&n%2==0||i===1;n>>=1,i<<=1){let a=new Uint8Array(n*n);for(let r=0;r<n;r++)for(let o=0;o<n;o++){let s=0;for(let n=0;n<i;n++)for(let a=0;a<i;a++)s+=e[(r*i+n)*t+o*i+a];a[r*n+o]=+(s>=128*i*i)}if(r.push({n,mask:a,phi:new Float32Array(n*n)}),i===4)break}let i=(e,t,n,r)=>{let{n:i,mask:a,phi:o}=e,s=t*t;for(let e=0;e<n;e++)for(let e=1;e<i-1;e++){let t=e*i;for(let e=1;e<i-1;e++){let n=t+e;if(!a[n])continue;let c=(o[n-1]+o[n+1]+o[n-i]+o[n+i]+s)*.25;o[n]+=r*(c-o[n])}}};for(let e=r.length-1;e>=0;e--){let t=r[e],a=1<<e;if(e<r.length-1){let n=r[e+1],i=t.n,a=n.n;for(let e=0;e<i;e++){let r=Math.min(a-1,Math.max(0,(e+.5)/2-.5)),o=r|0,s=Math.min(a-1,o+1),c=r-o;for(let r=0;r<i;r++){let l=e*i+r;if(!t.mask[l])continue;let u=Math.min(a-1,Math.max(0,(r+.5)/2-.5)),d=u|0,f=Math.min(a-1,d+1),p=u-d;t.phi[l]=(n.phi[o*a+d]*(1-p)+n.phi[o*a+f]*p)*(1-c)+(n.phi[s*a+d]*(1-p)+n.phi[s*a+f]*p)*c}}}let o=Math.min(1.9,2/(1+Math.sin(Math.PI/t.n))-.05);i(t,n*a,4,1),i(t,n*a,e===2?100:e===1?30:16,o),i(t,n*a,8,1)}return r[0].phi}var Qu=[1,1,0,-1,-1,-1,0,1],$u=[0,1,1,1,0,-1,-1,-1],ed=[1,Math.SQRT2,1,Math.SQRT2,1,Math.SQRT2,1,Math.SQRT2];function td(e,t,n){let r=106/t,i=t*t,a=new Uint8Array(i);for(let t=0;t<i;t++)a[t]=+(e[t]>=128);let o=new Float32Array(i),s=new Float32Array(i),c=new Int32Array(i);Yu(a,0,t,o,null),Yu(a,1,t,s,c);let l=new Float32Array(i),u=new Float32Array(i);for(let t=0;t<i;t++){let n=e[t]/255;l[t]=r*(n>0&&n<1?n-.5:a[t]?Math.sqrt(o[t])-.5:.5-Math.sqrt(s[t]))}Xu(l,t,u),Xu(l,t,u);let d=Zu(e,t,r),f=0;for(let e=0;e<i;e++)d[e]>f&&(f=d[e]);let p=2*Math.sqrt(f),m=Math.min(.9*n+.12*p,1.2*p),h=f>0?m/Math.sqrt(f):0,g=new Float32Array(i);for(let e=0;e<i;e++)g[e]=d[e]>0?h*Math.sqrt(d[e]):0;Xu(g,t,u);let _={N:t,i00:new Uint16Array(i),wx:new Uint8Array(i),wy:new Uint8Array(i),ao:new Uint8Array(i)},{i00:v,wx:y,wy:b,ao:x}=_,S=t<=64?[1,2,3,5,8]:t<=96?[1,2,4,7,11]:[1,2,4,7,11,15],C=t-1;for(let e=0;e<t;e++)for(let n=0;n<t;n++){let i=e*t+n,o=a[i]?i:s[i]<=9?c[i]:-1;if(o<0)continue;let u=o%t,d=(o-u)/t,f=u>0?u-1:0,p=u<C?u+1:C,m=d>0?d-1:0,h=d<C?d+1:C,_=-(g[d*t+p]-g[d*t+f])/(2*r),w=-(g[h*t+u]-g[m*t+u])/(2*r),T=1,E=Math.sqrt(_*_+w*w+1);_/=E,w/=E,T/=E;let D=Math.max(0,l[o]);if(D<2){let e=l[d*t+p]-l[d*t+f],n=l[h*t+u]-l[m*t+u],r=Math.hypot(e,n)||1;e/=r,n/=r;let i=.7*(1-D/2);_+=i*(-e-_),w+=i*(-n-w),T+=i*(0-T),E=Math.sqrt(_*_+w*w+T*T)||1,_/=E,w/=E,T/=E}let O=g[o],k=0;for(let e=0;e<8;e++){let n=0;for(let i=0;i<S.length;i++){let a=S[i],o=u+Qu[e]*a,s=d+$u[e]*a;o<0?o=0:o>C&&(o=C),s<0?s=0:s>C&&(s=C);let c=(g[s*t+o]-O)/(a*r*ed[e]);c>n&&(n=c)}k+=n/Math.sqrt(1+n*n)}let A=1-Math.min(1,D/3),j=1-.2*A*A,M=(1-.9*k/8)**1.5*j;x[i]=Math.max(1,Math.round(255*M**(1/2.2)));let N=(_*.5+.5)*63,P=(w*.5+.5)*63,F=Math.min(62,Math.max(0,N|0)),I=Math.min(62,Math.max(0,P|0));v[i]=I*Bu+F,y[i]=Math.round(255*Math.min(1,Math.max(0,N-F))),b[i]=Math.round(255*Math.min(1,Math.max(0,P-I)))}return _}function nd(e){if(typeof OffscreenCanvas==`function`)return new OffscreenCanvas(e,e);if(typeof document<`u`){let t=document.createElement(`canvas`);return t.width=t.height=e,t}return null}function rd(e,t){return e.getContext(`2d`,t?{willReadFrequently:!0}:void 0)}function id(e,t){let n=nd(t),r=n&&rd(n,!0);if(!r)return null;let i=106/t;r.setTransform(1/i,0,0,1/i,3/i,3/i),r.fillStyle=`#fff`,r.fill(e);let a=r.getImageData(0,0,t,t).data,o=new Uint8ClampedArray(t*t);for(let e=0;e<t*t;e++)o[e]=a[e*4+3];return o}var ad=new Map,od=new Set,sd=new WeakMap,cd=0;function ld(e){let t=sd.get(e);return t||sd.set(e,t=`p${cd++}`),t}var ud=[],dd=!1;function fd(){dd=!1;let e=ud.shift();e&&e(),ud.length&&pd()}function pd(){if(dd)return;dd=!0;let e=globalThis.requestIdleCallback;e?e(fd,{timeout:120}):setTimeout(fd,16)}function md(e){ud.push(e),pd()}function hd(e,t,n,r,i){let a=`${e}|${n}|${Math.round(r)}`,o=ad.get(a);if(o)return o;let s=()=>{if(od.delete(a),ad.has(a))return;let e=id(t,n);e&&(ad.size>=48&&ad.clear(),ad.set(a,td(e,n,r)))};return i?(s(),ad.get(a)??null):(od.has(a)||(od.add(a),md(s)),null)}function gd(e,t,n=192,r=.65){hd(e,t,_d(n),15*r,!0)}function _d(e){return e<=100?64:e<=224?96:128}var vd=e=>e<=.04045?e/12.92:((e+.055)/1.055)**2.4,yd=new Map;function bd(e){let t=yd.get(e);if(!t){let n=tu(e);if(!n){let t=nd(1),r=t&&rd(t,!0);if(r){r.fillStyle=e,r.fillRect(0,0,1,1);let t=r.getImageData(0,0,1,1).data;n=[t[0],t[1],t[2]]}else n=[128,128,128]}t=[vd(n[0]/255),vd(n[1]/255),vd(n[2]/255)],yd.size>200&&yd.clear(),yd.set(e,t)}return t}var xd=2048,Sd=2.5,Cd=xd/Sd,wd=new Float32Array(xd);for(let e=0;e<xd;e++){let t=(e+.5)/Cd,n=t<=.75?t:.75+.25*(1-Math.exp(-(t-.75)/.25));wd[e]=255*(n<=.0031308?12.92*n:1.055*n**(1/2.4)-.055)}var Td=e=>wd[e<=0?0:e>=Sd?2047:e*Cd|0],Ed=1024,Dd=new Map;function Od(e){let t=Dd.get(e);if(!t){t=new Float32Array(1025);for(let n=0;n<=Ed;n++)t[n]=(n/Ed)**+e;Dd.size>16&&Dd.clear(),Dd.set(e,t)}return t}var kd=[.92,.96,1],Ad=[1,.98,.95],jd=(e,t,n)=>{let r=n<=e?0:n>=t?1:(n-e)/(t-e);return r*r*(3-2*r)},Md=(e,t,n)=>1-jd(e-t,e+t,n);function Nd(e,t,n,r){let{L:i,V:a,H:o,U:s,W:c,A:l,B:u}=n,d=Math.max(t[0],t[1],t[2],.05),f=[t[0]/d,t[1]/d,t[2]/d],p=Math.max(.03,.3-.15*r.shadow),m=.15+.14*r.spread,h=.85,g=Math.min(90,Math.round(110/r.spread**1.3)),_=Math.max(2,Math.round(8/r.spread)),v=Od(g),y=Od(_),b=.45*r.highlight,x=.1*r.highlight,S=.11*r.highlight,C=.3*r.rim,w=[p*f[0],p*f[1],p*f[2]];for(let n=0;n<Bu;n++)for(let r=0;r<Bu;r++){let d=r/63*2-1,f=n/63*2-1,p=d*d+f*f;if(p>1.14)continue;if(p>1){let e=1/Math.sqrt(p);d*=e,f*=e,p=1}let g=Math.sqrt(1-p),_=d*i[0]+f*i[1]+g*i[2],T=Math.max(0,d*a[0]+f*a[1]+g*a[2]),E=Math.max(0,d*o[0]+f*o[1]+g*o[2]),D=Math.min(1,Math.max(0,(_+m)/(1+m))),O=1-T,k=O*O,A=k*O,j=A*k,M=E*Ed|0,N=(b*v[M]+x*y[M])*(1+3*j),P=2*T*d-a[0],F=2*T*f-a[1],I=2*T*g-a[2],L=.45+.55*jd(-.4,.6,P*s[0]+F*s[1]+I*s[2]),R=P*c[0]+F*c[1]+I*c[2],z=0;if(R>.5){let e=(P*l[0]+F*l[1]+I*l[2])/R,t=(P*u[0]+F*u[1]+I*u[2])/R;z=Md(.34,.12,Math.abs(e))*Md(.12,.06,Math.abs(t))}let ee=C*A*L+S*z,B=(n*Bu+r)*3;e[B]=Td(t[0]*(w[0]+h*D)+N*Ad[0]+ee*kd[0]),e[B+1]=Td(t[1]*(w[1]+h*D)+N*Ad[1]+ee*kd[1]),e[B+2]=Td(t[2]*(w[2]+h*D)+N*Ad[2]+ee*kd[2])}}function Pd(e,t,n,r){let i=(t*.5+.5)*63,a=(n*.5+.5)*63,o=Math.min(62,Math.max(0,i|0)),s=Math.min(62,Math.max(0,a|0)),c=i-o,l=a-s,u=(s*Bu+o)*3,d=(1-c)*(1-l),f=c*(1-l),p=(1-c)*l,m=c*l;for(let t=0;t<3;t++)r[t]=e[u+t]*d+e[u+3+t]*f+e[u+192+t]*p+e[u+192+3+t]*m}function Fd(e,t,n,r){let{N:i,i00:a,wx:o,wy:s,ao:c}=e;for(let e=0,l=0;e<i*i;e++,l+=4){let i=c[e];if(i===0){n[l+3]=0;continue}let u=r[i],d=a[e]*3,f=o[e]*(1/255),p=s[e]*(1/255),m=(1-f)*(1-p)*u,h=f*(1-p)*u,g=(1-f)*p*u,_=f*p*u;n[l]=t[d]*m+t[d+3]*h+t[d+192]*g+t[d+192+3]*_,n[l+1]=t[d+1]*m+t[d+4]*h+t[d+192+1]*g+t[d+192+4]*_,n[l+2]=t[d+2]*m+t[d+5]*h+t[d+192+2]*g+t[d+192+5]*_,n[l+3]=255}}var Id=e=>{let t=Math.hypot(e[0],e[1],e[2])||1;return[e[0]/t,e[1]/t,e[2]/t]};function Ld(e){let t=Math.cos(e.roll),n=Math.sin(e.roll),r=t*e.lx+n*e.ly,i=-n*e.lx+t*e.ly,a=e.facing<0?-1:1,o=a*Math.min(1,Math.abs(e.facing)/.16),{cy:s,sy:c,cp:l,sp:u}=e,d=(e,t,n,r=o)=>Id([s*e+c*u*t-c*l*n,l*t+u*n,r*(c*e-s*u*t+s*l*n)]),f=d(Gu*r,Gu*i,Ku),p=d(0,0,1,a),m=Id([f[0]+p[0],f[1]+p[1],f[2]+p[2]]),h=d(r,i,0,a),g=Math.cos(80*Math.PI/180),_=Math.sin(80*Math.PI/180),v=g*r-_*i,y=_*r+g*i,b=Id([.55*v,.55*y,.83]),x=Id([b[1],-b[0],0]),S=[b[1]*x[2]-b[2]*x[1],b[2]*x[0]-b[0]*x[2],b[0]*x[1]-b[1]*x[0]];return{L:f,V:p,H:m,U:h,W:d(b[0],b[1],b[2],a),A:d(x[0],x[1],x[2],a),B:d(S[0],S[1],S[2],a)}}var Rd=new WeakMap;function zd(e,t){let n=e.canvas??e,r=Rd.get(n);r||(r=new Map,Rd.set(n,r));let i=r.get(t);return i||(i={N:0,img:null,mc:new Float32Array(Vu*3),mcPrev:new Float32Array(Vu*3),mcMix:new Float32Array(Vu*3),mixVersion:0,blendT:1,blendFrames:1,sinceBuild:0,L:null,V:null,lx:NaN,ly:NaN,base:``,shadow:NaN,highlight:NaN,spread:NaN,rim:NaN,version:0,imgVersion:-1,imgAoK:NaN,imgForm:null,aoK:-1,aoMul:new Float32Array(256),near:null,rimG:null,far:null,scratch:[null,null],scratchIdx:0,scratchN:0,scratchStale:!0,sprites:[null,null,null],spriteVersion:-1,spritePx:0},r.size>4&&r.clear(),r.set(t,i)),i}var Bd=1/48,Vd=(e,t)=>!t||Math.abs(e[0]-t[0])>=Bd||Math.abs(e[1]-t[1])>=Bd||Math.abs(e[2]-t[2])>=Bd;function Hd(e,t){return[e[0]*t[0]+e[2]*t[1],e[1]*t[0]+e[3]*t[1],e[0]*t[2]+e[2]*t[3],e[1]*t[2]+e[3]*t[3],e[0]*t[4]+e[2]*t[5]+e[4],e[1]*t[4]+e[3]*t[5]+e[5]]}function Ud(e,t,n,r,i){let a=Math.sqrt(1-n*n),o=[0,0,0],s=1-r;if(typeof e.createConicGradient==`function`){let n=e.createConicGradient(0,50,50);for(let e=0;e<=Hu;e++){let r=e/Hu*Math.PI*2;Pd(t,a*Math.cos(r),a*Math.sin(r),o),n.addColorStop(e/Hu,`rgb(${o[0]*s|0} ${o[1]*s|0} ${o[2]*s|0})`)}return n}let c=e.createLinearGradient(50+i[0]*50,50+i[1]*50,50-i[0]*50,50-i[1]*50),l=(e,n,r)=>{Pd(t,e,n,o),c.addColorStop(r,`rgb(${o[0]*s|0} ${o[1]*s|0} ${o[2]*s|0})`)};return l(a*i[0],a*i[1],0),l(-a*i[1],a*i[0],.5),l(-a*i[0],-a*i[1],1),c}var Wd=typeof navigator<`u`&&/AppleWebKit\//.test(navigator.userAgent)&&!/Chrome\/|Chromium\/|Edg\//.test(navigator.userAgent),Gd=[[.55,()=>0],[0,()=>0],[0,e=>Math.min(.6,.25*e.shadow)]];function Kd(e,t,n,r,i,a){let o=_d(n.dev),s=hd(t.typeKey??ld(t.path),t.path,o,n.halfDepth,!!n.still);if(!s)return!1;let c=zd(e,t.typeKey??ld(t.path)),l=Ld(n),u=(()=>{let e=Math.hypot(l.L[0],l.L[1]);return e<.05?[0,-1]:[l.L[0]/e,l.L[1]/e]})();if((Vd(l.L,c.L)||Vd(l.V,c.V)||n.lx!==c.lx||n.ly!==c.ly||r.base!==c.base||a.shadow!==c.shadow||a.highlight!==c.highlight||a.spread!==c.spread||a.rim!==c.rim)&&(c.version>0&&c.mcPrev.set(c.mcMix),Nd(c.mc,bd(r.base),l,a),c.version===0?(c.mcMix.set(c.mc),c.blendT=1):(c.blendFrames=Math.min(10,Math.max(1,c.sinceBuild)),c.blendT=0),c.sinceBuild=0,c.mixVersion++,c.L=l.L,c.V=l.V,c.lx=n.lx,c.ly=n.ly,c.base=r.base,c.shadow=a.shadow,c.highlight=a.highlight,c.spread=a.spread,c.rim=a.rim,c.version++,c.near=c.rimG=c.far=null),c.sinceBuild++,c.blendT<1){c.blendT=Math.min(1,c.blendT+1/c.blendFrames);let e=c.blendT>=1?1:c.blendT*c.blendT*(3-2*c.blendT),t=c.mcPrev,n=c.mc,r=c.mcMix;for(let i=0;i<Vu*3;i++)r[i]=t[i]+(n[i]-t[i])*e;c.mixVersion++}let d=Math.min(1.3,1.2*a.shadow);if(d!==c.aoK){for(let e=0;e<256;e++)c.aoMul[e]=Math.max(0,1-d*(1-e/255));c.aoK=d}if((!c.img||c.N!==o)&&(c.img=new ImageData(o,o),c.N=o,c.imgVersion=-1),(c.imgVersion!==c.mixVersion||c.imgAoK!==d||c.imgForm!==s)&&(Fd(s,c.mcMix,c.img.data,c.aoMul),c.imgVersion=c.mixVersion,c.imgAoK=d,c.imgForm=s,c.scratchStale=!0),c.scratchN!==o&&(c.scratch=[null,null],c.scratchN=o,c.scratchStale=!0),c.scratchStale){c.scratchIdx^=1;let e=c.scratch[c.scratchIdx];if(!e){let t=nd(o),n=t&&rd(t,!1);if(!t||!n)return!1;e=c.scratch[c.scratchIdx]={c:t,g:n}}e.g.putImageData(c.img,0,0),c.scratchStale=!1}let f=c.scratch[c.scratchIdx],p=t.sides===`sprite`||t.sides!==`vector`&&Wd;if(p){let e=Math.ceil(106*n.dev/100);if(c.spritePx!==e&&(c.sprites=[null,null,null],c.spritePx=e,c.spriteVersion=-1),c.spriteVersion!==c.version){let n=e/106;for(let r=0;r<3&&p;r++){let i=c.sprites[r];if(!i){let t=nd(e),n=t&&rd(t,!1);if(!t||!n){p=!1;break}i=c.sprites[r]={c:t,g:n}}i.g.setTransform(1,0,0,1,0,0),i.g.clearRect(0,0,e,e),i.g.setTransform(n,0,0,n,3*n,3*n),i.g.fillStyle=Ud(i.g,c.mc,Gd[r][0],Gd[r][1](a),u),i.g.fill(t.path)}p&&(c.spriteVersion=c.version)}}!p&&!c.near&&(c.near=Ud(e,c.mc,.55,0,u),c.rimG=Ud(e,c.mc,0,0,u),c.far=Ud(e,c.mc,0,Math.min(.6,.25*a.shadow),u));let{cy:m,sy:h,cp:g,sp:_,halfDepth:v,cap:y}=n,b=n.facing>=0?1:-1,[x,S,C,w,T,E]=n.ctm,D=null;p&&(e.imageSmoothingEnabled=!0,e.imageSmoothingQuality=`high`);let O=1,k=0,A=0,j=1,M=0,N=0;for(let n=0;n<16;n++){let r=-1+2*(b>0?n:16-n)/16,i=qu(r,y),a=r*b,o=m*i,s=h*_*i,l=g*i,u=r*h*v-50*o,d=-r*m*_*v-50*s-50*l,f=O*j-k*A,x=j/f,S=-k/f,C=-A/f,w=O/f,T=(A*N-j*M)/f,E=(k*M-O*N)/f;e.transform(x*o+C*s,S*o+w*s,C*l,w*l,x*u+C*d+T,S*u+w*d+E),O=o,k=s,A=0,j=l,M=u,N=d;let P=a>.4?0:a>=0?1:2;if(p)e.drawImage(c.sprites[P].c,-3,-3,106,106);else{let n=P===0?c.near:P===1?c.rimG:c.far;n!==D&&(e.fillStyle=D=n),e.fill(t.path)}}e.setTransform(x,S,C,w,T,E);let P=1/(m*g),F=h*v/m,I=-_*v*P,L=Math.hypot(F,I),R=L>1e-6?b*F/L:1,z=L>1e-6?b*I/L:0,ee=50*y+Math.hypot(50*(1-y),L),B=(ee+50)/100,te=(ee-50)/2,ne=1+(B-1)*R*R,re=(B-1)*R*z,V=1+(B-1)*z*z,H=Hd(Hd(n.ctm,[m,h*_,0,g,0,0]),[ne,re,re,V,te*R-50*ne-50*re,te*z-50*re-50*V]);if(e.save(),e.setTransform(H[0],H[1],H[2],H[3],H[4],H[5]),e.clip(t.path),e.imageSmoothingEnabled=!0,e.imageSmoothingQuality=`high`,e.drawImage(f.c,-3,-3,106,106),e.restore(),n.dev>=256&&a.rim>0&&a.highlight>0){e.save(),e.globalCompositeOperation=`source-atop`,e.setTransform(H[0],H[1],H[2],H[3],H[4],H[5]);let n=Math.min(.5,.3*a.rim*Math.min(1.4,a.highlight)),r=e.createLinearGradient(50+u[0]*50,50+u[1]*50,50-u[0]*50,50-u[1]*50);r.addColorStop(0,`rgba(235,244,255,${n.toFixed(3)})`),r.addColorStop(.45,`rgba(235,244,255,${(.35*n).toFixed(3)})`),r.addColorStop(.75,`rgba(235,244,255,0)`),e.strokeStyle=r,e.lineJoin=`round`,e.lineWidth=1.3,e.stroke(t.path),e.restore()}return!0}var qd=1.5,Jd=.1,Yd=17,Xd=15,Zd=(e,t)=>t+(1-t)*Math.sqrt(Math.max(0,1-e*e)),Qd=25,$d=6.3,ef={eyes:1,mouth:-3.5},tf=new Map;function nf(e,t,n){let r=`${e}|${t}|${n}`,i=tf.get(r);if(!i){let a=uu(e,-.3*t,.05*t),o=uu(e,-.12*t,.03*t),s=[],c=[];for(let t=0;t<Yd;t++){let n=t/16;s.push(n>.6?``:af(a,o,n/.6)),c.push(n>=.5?e:af(a,e,n/.5))}i={base:e,far:a,near:o,light:uu(e,.04*n),dark:uu(e,-.3*t,.05*t),capTop:uu(e,.035*n),capBottom:uu(e,-.035*t),crispMix:s,smoothMix:c,grad:null},tf.size>200&&tf.clear(),tf.set(r,i)}return i}var rf=e=>(e.startsWith(`hsl(`)?e:uu(e,0)).match(/[\d.]+/g).map(Number);function af(e,t,n){let r=rf(e),i=rf(t),a=r.map((e,t)=>e+(i[t]-e)*n);return`hsl(${a[0].toFixed(1)} ${a[1].toFixed(1)}% ${a[2].toFixed(1)}%)`}var of=34,sf=Math.PI*1.55,cf=57,lf=.4,uf=-.28,df=new Map;function ff(e){let t=df.get(e);return t||(t={base:uu(e,.1,.02),light:uu(e,.3,.04),dark:uu(e,-.22,.08),halo:uu(e,.2)},df.size>200&&df.clear(),df.set(e,t)),t}var pf=(e,t)=>e.replace(`)`,` / ${Math.max(0,Math.min(1,t)).toFixed(3)})`);function mf(e,t,n,r,i,a,o){let s=o?.strength??0,c=Math.min(1,t.whirl*s);if(c<=.01)return;let l=o?.size??1,u=o?.width??1,d=o?.length??1,f=o?.tilt??1,p=sf*d,m=ff(n),h=-t.whirlAngle,g=cf*l,_=g*lf*f*(a?1.14:.86),v=Math.atan2(i,r)-uf;e.save(),e.rotate(uf),e.translate(0,5),e.lineCap=`butt`;let y=(t,n,r,i,a)=>{e.strokeStyle=i,e.lineWidth=r,e.beginPath(),e.ellipse(0,a,g,_,0,t,n,!1),e.stroke()};if(a)for(let e=0;e<of;e++){let t=e/of,n=h+t*p,r=n+p/of+.012;if(Math.sin((r+n)/2)<=0)continue;let i=(1-t)**1.3;y(n,r,(2+8*i)*1.5*u,`rgba(0,0,0,${(.2*c*i).toFixed(3)})`,3.5)}for(let e=0;e<of;e++){let t=e/of,n=h+t*p,r=n+p/of+.012,i=(r+n)/2;if(Math.sin(i)>0!==a)continue;let o=.6+.4*Math.sin(i),s=(1-t)**1.3,l=1+.18*Math.sin(t*9+1.2),d=(2+8*s)*o*u*l,f=c*(.3+.7*s)*o,g=.5+.5*Math.cos(i-v);y(n,r,d*2.6,pf(m.halo,f*.2),0),y(n,r,d*.8,pf(m.dark,f*.45),d*.32),y(n,r,d,pf(m.base,f*.72),0),y(n,r,d*.62,pf(m.light,f*.78*(.4+.6*g)),-d*.16),y(n,r,d*.24,`rgba(255,255,255,${(f*.9*(.15+.85*g*g)).toFixed(3)})`,-d*.3)}e.restore()}function hf(e,t,n,r){let i=t*qd;e.clearRect(0,0,i,i);let a=t/100,o,s;if(r.dpr!==void 0)o=r.dpr,s=[o,0,0,o,0,0];else if(e.getTransform){let t=e.getTransform();s=[t.a,t.b,t.c,t.d,t.e,t.f],o=t.a||1}else o=1,s=[1,0,0,1,0,0];let c=r.shadow??.35,l=r.highlight??1.3,u=Xd*(r.depth??.65),d=1-.09999999999999998*(r.rim??.5),f=r.spread??1.55,p=(r.light??265)*Math.PI/180,m=Math.sin(p),h=-Math.cos(p),g=nf(r.color,c,l),_=Math.cos(n.yaw),v=Math.sin(n.yaw),y=Math.cos(n.pitch),b=Math.sin(n.pitch),x=_*y,S=e=>Math.abs(e)<.22?e<0?-.22:.22:e,C=S(_),w=S(y),T=Math.cos(n.roll),E=Math.sin(n.roll),D=n.sx*a,O=n.sy*a,k=50*(1-n.sy)*a,A=Hd(s,[T*D,E*D,-E*O,T*O,i/2+n.x*a-E*k,i/2+Jd*t+n.y*a+T*k]);e.save(),e.setTransform(A[0],A[1],A[2],A[3],A[4],A[5]),e.lineCap=`round`,e.lineJoin=`round`;let j=r.shading,M=(i,a,s)=>{let u=g.near,p=g.base;if(j===`crisp`){if(!g.grad||g.grad.lx!==m||g.grad.ly!==h){let t=e.createLinearGradient(m*56,h*56,-m*56,-h*56);t.addColorStop(0,g.light),t.addColorStop(.45,g.near),t.addColorStop(1,g.dark);let n=e.createLinearGradient(m*46,h*46,-m*46,-h*46);n.addColorStop(0,g.capTop),n.addColorStop(1,g.capBottom),g.grad={lx:m,ly:h,lit:t,cap:n}}u=g.grad.lit,p=g.grad.cap}let _=!1;j===`plastic`&&(_=Kd(e,{...r,path:i,typeKey:a},{cy:C,sy:v,cp:w,sp:b,facing:x,roll:n.roll,halfDepth:s,cap:d,lx:m,ly:h,dev:t*o,ctm:A,still:r.still},g,null,{shadow:c,highlight:l,spread:f,rim:r.rim??.5}));let y=j===`plastic`&&!_?`smooth`:j,S=y===`smooth`,T=S&&typeof Path2D==`function`?new Path2D:null,E=x>=0?1:-1,[D,O,k,M,N,P]=A,F=null,I=1,L=0,R=0,z=1,ee=0,B=0;for(let t=0;t<Yd&&!_;t++){let n=-1+2*(E>0?t:16-t)/16,r=Zd(n,d),a=t/16,o=C*r,c=v*b*r,l=w*r,f=n*v*s-50*o,m=-n*C*b*s-50*c-50*l,h=I*z-L*R,_=z/h,y=-L/h,x=-R/h,D=I/h,O=(R*B-z*ee)/h,k=(L*ee-I*B)/h;e.transform(_*o+x*c,y*o+D*c,x*l,D*l,_*f+x*m+O,y*f+D*m+k),I=o,L=c,R=0,z=l,ee=f,B=m;let A;A=S?g.smoothMix[t]:t===16?p:a>.6?u:g.crispMix[t],A!==F&&(e.fillStyle=F=A),e.fill(i),T&&T.addPath(i,{a:o,b:c,c:0,d:l,e:f,f:m})}if(_||e.setTransform(D,O,k,M,N,P),T&&y===`smooth`){e.save(),e.clip(T);let t=Math.min(1,.34*c),n=e.createRadialGradient(-m*45,-h*45,4*f,-m*45,-h*45,84*f);n.addColorStop(0,`rgba(0,0,0,${t})`),n.addColorStop(.5,`rgba(0,0,0,${t*.35})`),n.addColorStop(1,`rgba(0,0,0,0)`),e.globalCompositeOperation=`multiply`,e.fillStyle=n,e.fillRect(-120,-120,240,240),e.globalCompositeOperation=`source-over`;let r=Math.min(1,.22*l),i=e.createRadialGradient(m*37,h*37,0,m*37,h*37,62*f);i.addColorStop(0,`rgba(255,255,255,${r})`),i.addColorStop(.6,`rgba(255,255,255,${r*.23})`),i.addColorStop(1,`rgba(255,255,255,0)`),e.fillStyle=i,e.fillRect(-120,-120,240,240),e.restore()}return _};mf(e,n,r.color,m,h,!1,r.whirl),r.parts&&M(r.parts,`${r.typeKey??`custom`}:parts`,u*(r.partsDepth??.4));let N=M(r.path,r.typeKey??`custom`,u);if(x>-.2){e.save();{let t=x>=0?1:-1,n=Zd(t,d),i=C*n,a=v*b*n,o=w*n,s=t*v*u-50*i,c=-t*C*b*u-50*a-50*o,[l,f,p,m,h,g]=A;e.setTransform(l*i+p*a,f*i+m*a,p*o,m*o,l*s+p*c+h,f*s+m*c+g),e.clip(r.path),e.setTransform(l,f,p,m,h,g)}e.translate(r.faceX-50,r.faceY-50),e.scale(r.faceScale,r.faceScale),N&&(e.globalAlpha=.93),Tf(e,n,r),e.restore()}mf(e,n,r.color,m,h,!0,r.whirl),e.restore()}var gf=30;function _f(e,t,n,r){let i=Math.asin(Math.max(-1,Math.min(1,e/gf)))+n,a=Math.asin(Math.max(-1,Math.min(1,-t/gf)))+r,o=Math.cos(a);return{x:gf*Math.sin(i)*o,y:-30*Math.sin(a),sx:Math.cos(i),sy:o,z:Math.cos(i)*o}}var vf=8,yf=new Map;function bf(e,t,n){let r=Math.round(e*50),i=Math.round(t*50),a=Math.round(n*50),o=r+2e3*i+4e6*a,s=yf.get(o);if(!s){let e=r/50,t=i/50,n=a/50,c=`M${-e} ${t}`;for(let r=1;r<=vf;r++){let i=r/vf,a=1-i;c+=` L${(a*a*-e+i*i*e).toFixed(3)} ${((a*a+i*i)*t+2*a*i*n).toFixed(3)}`}s=new Path2D(c),yf.size>256&&yf.clear(),yf.set(o,s)}return s}var xf=Math.sin(.684),Sf=Math.cos(.684),Cf=new Map;function wf(e){let t=e=>Math.round(e*50)/50,n=t(e.hw),r=t(e.t0),i=t(e.a),a=t(e.yt),o=t(e.ab),s=t(e.yb),c=`${n},${r},${i},${a},${o},${s}`,l=Cf.get(c);if(l)return l;let u=e=>e.toFixed(3),d=r*xf,f=r*Sf,p=-n+d,m=-f,h=n-d,g=-f,_=-n-d,v=f,y=n+d,b=f,x=4/3*r*Sf,S=4/3*r*xf,C=`M${u(p)} ${u(m)}C${u(-n+i*n)} ${u(a-r)} ${u(n-i*n)} ${u(a-r)} ${u(h)} ${u(g)}C${u(h+x)} ${u(g-S)} ${u(y+x)} ${u(b-S)} ${u(y)} ${u(b)}C${u(n-o*n)} ${u(s+r)} ${u(-n+o*n)} ${u(s+r)} ${u(_)} ${u(v)}C${u(_-x)} ${u(v-S)} ${u(p-x)} ${u(m-S)} ${u(p)} ${u(m)}Z`;return l=new Path2D(C),Cf.size>256&&Cf.clear(),Cf.set(c,l),l}function Tf(e,t,n){let[r,i,a]=t.w,o=n.ink,s=ef[n.face],c=Qd/2,l=t.lookX,u=t.lookY,{yaw:d,pitch:f}=t,p=(t,n,r,i=1)=>{let a=_f(t,n,d,f);a.z<=.02||i<=.01||(e.save(),e.globalAlpha=i*Math.min(1,a.z*5),e.translate(a.x,a.y),e.scale(Math.max(.02,a.sx),Math.max(.02,a.sy)),r(),e.restore())},m=(e,t)=>Math.abs(e)<=t?0:Math.sign(e)*(Math.abs(e)-t)/(1-t),h=e=>Math.max(-1,Math.min(1,e)),g=m(h(-t.pitch/.26-t.lookY/7),.34),_=Math.abs(m(h(t.lookX/4.5),.4)),v=Math.max(.3,1+.55*g-.1*_),y=1-.05*g+.12*_,b=r+i*(1-t.laugh),x=i*t.laugh,S=Math.max(0,-t.y)/26,C=.5+.5*t.breath;for(let n of[-1,1]){let r=n<0?t.blinkL:t.blinkR,i=Math.max(0,Math.min(1,t.eyeOpen*(1-r))),d=b*i,f=b*(1-i),m=x,h=a,g=d*.01+f*5.4+m*6.2+h*6,_=d*1.1*v+f*.6+m*(2.2-S*1.5)+h*(-1.4+C),w=d*-3.3*v+f*.6+m*(-11.4-4*S)+h*(5.4+2*C),T=d*$d*2*y+f*2.8+m*4.4+h*4,E=l*(d+.5*(f+m)),D=u*(d+.5*f);p(n*c+E,s+D,()=>{e.strokeStyle=o,e.lineWidth=T,e.stroke(bf(g,_,w))})}if(n.face===`mouth`){let n=l*.35,s=(.6+.4*r)*(1+.06*t.breath),c=(.6+.4*i)*(1+.25*Math.max(0,-t.y)/26),u=2.7*a*(1+.25*t.breath),d=(e,t,n)=>r*e+i*t+a*n,f={hw:d(6.5*s,9.5*c,u),t0:d(1.9,0,0),a:d(2/3,2/3,0),yt:d(3.53*s,1.6*c,-4*u/3),ab:d(2/3,0,0),yb:d(3.53*s,17.3*c,4*u/3)};p(n,d(12.5,11.6,15.5),()=>{e.fillStyle=o,e.fill(wf(f))})}}var Ef={x:NaN,y:NaN},Df=new Set,Of=0,kf=0;function Af(e){Of=0;let t=kf?Math.min(.1,(e-kf)/1e3):0;kf=e,Df.forEach(e=>e(t)),Df.size&&(Of=requestAnimationFrame(Af))}function jf(){Of||typeof document>`u`||document.hidden||(kf=0,Of=requestAnimationFrame(Af))}var Mf=!1;function Nf(){Mf||typeof document>`u`||(Mf=!0,document.addEventListener(`pointermove`,e=>{Ef.x=e.clientX,Ef.y=e.clientY},{passive:!0}),document.addEventListener(`pointerleave`,()=>{Ef.x=NaN,Ef.y=NaN}),window.addEventListener(`blur`,()=>{Ef.x=NaN,Ef.y=NaN}),document.addEventListener(`visibilitychange`,()=>{document.hidden?(Of&&cancelAnimationFrame(Of),Of=0):Df.size&&jf()}))}function Pf(e){return Nf(),Df.add(e),jf(),()=>{Df.delete(e),!Df.size&&Of&&(cancelAnimationFrame(Of),Of=0)}}function Ff(e){let t=2166136261;for(let n=0;n<e.length;n++)t=Math.imul(t^e.charCodeAt(n),16777619);return(t>>>0)%1e3/1e3}var If=(e,t,n)=>Math.min(n,Math.max(t,Number.isFinite(e)?e:1)),Lf=new Map;function Rf(e){let t=Lf.get(e);return t||(t=new Path2D(e),Lf.set(e,t)),t}var zf=()=>typeof matchMedia==`function`&&matchMedia(`(prefers-reduced-motion: reduce)`).matches,Bf=(0,l.forwardRef)(function({type:e=`clover`,path:t,face:n,state:r=`default`,size:i=64,color:a,ink:o,brightness:s=1,saturation:c=1.5,speed:u=1,paused:d=!1,seed:f,shading:p=`plastic`,shadow:m=.35,highlight:h=1.3,depth:g=.65,light:_=265,rim:v=.5,spread:y=1.55,interactive:b=!0,turn:x=1,theme:S=`auto`,whirl:C=0,whirlSize:w=1,whirlWidth:T=1,whirlLength:E=1,whirlTilt:D=1,jumpHeight:O=26,jumpTime:k=.68,jumpStretch:A=1,jumpSpin:j=1,jumpLean:M=6,jumpEvery:N=8,jumpLand:P=0,jumpSquash:F=1.15,jumpSquashTime:I=.37,jumpSquashEase:L=`pulse`,jumpGroundTime:R=.11,jumpGroundEase:z=`pulse`,jumpRiseTime:ee=.33,jumpRiseEase:B=`pulse`,jumpClickSquashTime:te=.24,className:ne,style:re,"aria-label":V,...H},ie){let ae=(0,l.useRef)(null);(0,l.useImperativeHandle)(ie,()=>ae.current);let oe=(0,l.useId)(),se=Xl[e]??Xl.clover,ce=n??se.face,le=a??se.color,ue=s===1&&c===1?le:uu(le,(Math.min(2,Math.max(0,s))-1)*.35,(Math.min(2,Math.max(0,c))-1)*.5),de=o??au(ue),fe=Math.min(1,Math.max(0,f??Ff(oe))),U=r in Ql?r:`default`,pe=d||!(u>0),W=p===!0?`crisp`:p===!1?`flat`:p,me=typeof t==`string`&&t.trim()?t.trim():null,he=me?`path:${Ff(me)}:${me.length}`:e,ge=(0,l.useRef)(null),G=(0,l.useRef)(null),K=(0,l.useRef)(0),_e=(0,l.useRef)(u);_e.current=u;let ve=(0,l.useRef)(b);ve.current=b,G.current={path:typeof Path2D>`u`?null:Rf(me??$l[e]??$l.clover),face:ce,faceX:se.faceX,faceY:se.faceY,faceScale:se.faceScale,color:ue,ink:de,shading:W,shadow:If(m,0,2),highlight:If(h,0,2),depth:If(g,.2,2),light:_,rim:If(v,0,2),spread:If(y,.4,2.5),typeKey:he,still:pe||zf(),whirl:{strength:If(C,0,2),size:If(w,.6,1.6),width:If(T,.4,2),length:If(E,.4,1.6),tilt:If(D,.5,1.8)},parts:typeof Path2D<`u`&&!me&&eu[e]?Rf(eu[e]):void 0};let ye=e=>{if(S!==`auto`)return S;let t=e?.closest(`[data-theme], .dark, .light`);if(t){let e=t.getAttribute(`data-theme`);if(e===`dark`||e===`light`)return e;if(t.classList.contains(`dark`))return`dark`;if(t.classList.contains(`light`))return`light`}return typeof matchMedia==`function`&&matchMedia(`(prefers-color-scheme: light)`).matches?`light`:`dark`},be=()=>{let e=ae.current,t=G.current;if(!e||!t||!t.path)return;let n=e.clientWidth/1.5||K.current||(typeof i==`number`?i:64);if(!n)return;let r=Math.min(2,typeof devicePixelRatio==`number`&&devicePixelRatio||1),a=Math.round(n*qd*r);(e.width!==a||e.height!==a)&&(e.width=a,e.height=a),K.current=n;let o=e.getContext(`2d`);o&&(o.setTransform(r,0,0,r,0,0),t.dpr=r,hf(o,n,ge.current?ge.current.pose:zu(U),t))};(0,l.useLayoutEffect)(()=>{if(ge.current?ge.current.setState(U):ge.current=new Ru(fe,U),ge.current.setTurn(If(x,0,2)),ge.current.setJump({height:O,time:Math.max(.2,k),stretch:A,spin:Math.max(0,Math.round(j)),lean:M,every:N,land:P,squash:F,squashTime:Math.max(.05,I),squashEase:L,groundTime:Math.max(0,R),groundEase:z,riseTime:Math.max(.05,ee),riseEase:B,clickSquashTime:Math.max(.05,te)}),zf()){let e=ae.current;if(e&&G.current&&G.current.path){let t=e.clientWidth/1.5||K.current||(typeof i==`number`?i:64);if(!t)return;K.current=t;let n=Math.min(2,typeof devicePixelRatio==`number`&&devicePixelRatio||1);e.width=e.height=Math.round(t*qd*n);let r=e.getContext(`2d`);r&&(G.current.theme=ye(e),G.current.dpr=n,r.setTransform(n,0,0,n,0,0),hf(r,t,zu(U),G.current))}return}G.current&&ae.current&&(G.current.theme=ye(ae.current)),be()}),(0,l.useEffect)(()=>{var e;if(W!==`plastic`||!((e=G.current)!=null&&e.path))return;let t=G.current.path,n=(typeof i==`number`?i:64)*Math.min(2,typeof devicePixelRatio==`number`&&devicePixelRatio||1),r=(typeof requestIdleCallback==`function`?requestIdleCallback:e=>setTimeout(e,1))(()=>gd(he,t,n,g));return()=>{typeof cancelIdleCallback==`function`?cancelIdleCallback(r):clearTimeout(r)}},[W,he,i,g]),(0,l.useEffect)(()=>{if(pe||zf())return;let e=ae.current;if(!e)return;let t=!0,n=null,r=t=>{let n=ge.current;if(n){if(ve.current&&!Number.isNaN(Ef.x)){let t=e.getBoundingClientRect(),r=t.width/1.5||1,i=(Ef.x-(t.left+t.width/2))/r,a=(Ef.y-(t.top+t.height/2+Jd*r))/r,o=Math.hypot(i,a),s=o<1?1:o>3?0:1-(o-1)/2;n.setPointer(i/Math.max(1,o),a/Math.max(1,o),s)}else n.setPointer(0,0,0);n.update(t*_e.current),be()}},i=()=>{n||=Pf(r)},a=()=>{n&&n(),n=null},o=null;return typeof IntersectionObserver==`function`?(o=new IntersectionObserver(e=>{t=e[0]?.isIntersecting??!0,t?i():a()}),o.observe(e)):i(),()=>{a(),o&&o.disconnect()}},[pe]);let xe=typeof i==`number`?`${i*qd}px`:`calc(${i} * ${qd})`,Se=e=>typeof i==`number`?`${-i*e}px`:`calc(${i} * ${-e})`,Ce=.5/2,we={display:`inline-block`,verticalAlign:`middle`,width:xe,height:xe,marginLeft:Se(Ce),marginRight:Se(Ce),marginTop:Se(.35),marginBottom:Se(.15),flex:`none`,...re},Te=e=>{var t,n;b&&!pe&&((t=ge.current)==null||t.poke()),(n=H.onClick)==null||n.call(H,e)};return(0,Q.jsx)(`canvas`,{ref:ae,className:ne?`ba ${ne}`:`ba`,"data-bot-avatar":e,"data-face":ce,"data-state":U,role:`img`,"aria-label":V??`${se.label} bot, ${Ql[U]}`,style:we,...H,onClick:Te})}),Vf=137.508,Hf=e=>(e*Vf%360).toFixed(3);function Uf(e){let t=e.avatarIndex;return{type:Zl[t%Zl.length],color:`hsl(${Hf(t)} 72% 58%)`,seed:t*.61803398875%1}}var Wf=2e3,Gf=0;function Kf(e){let[t,n]=(0,l.useState)(!e);return(0,l.useEffect)(()=>{if(e){n(!1);return}let t=setTimeout(()=>n(!0),Wf);return()=>clearTimeout(t)},[e]),t}function qf({thread:e,working:t,size:n}){let r=Kf(t),i=r?`rest`:`moving`;return(0,Q.jsx)(Bf,{...Uf(e),state:t?`working`:`default`,size:n,paused:r,turn:t?void 0:Gf},i)}var Jf={nextThread:`Next thread`,previousThread:`Previous thread`,nextPane:`Next pane`,previousPane:`Previous pane`,toggleSidebar:`Toggle sidebar`,newThread:`New thread`,openTerminal:`New terminal`,closePane:`Close pane`},Yf={nextThread:`ctrl+j`,previousThread:`ctrl+k`,nextPane:`ctrl+l`,previousPane:`ctrl+h`,toggleSidebar:`meta+b`,newThread:`ctrl+x`,openTerminal:`ctrl+e`,closePane:`ctrl+q`};function Xf(){try{let e=JSON.parse(localStorage.getItem(`webr-shortcuts`)??`{}`);return{...Yf,...Object.fromEntries(Object.entries(e).filter(([e])=>Object.hasOwn(Yf,e)))}}catch{return Yf}}function Zf(e){let t={ctrl:`⌃`,alt:`⌥`,meta:`⌘`,shift:`⇧`,space:`Space`,escape:`Esc`};return e.split(`+`).map(e=>t[e]??e.toUpperCase())}function Qf(e){return Zf(e).join(``)}function $f(e){let t=[e.ctrlKey&&`ctrl`,e.altKey&&`alt`,e.metaKey&&`meta`,e.shiftKey&&`shift`].filter(Boolean),n=e.key.toLowerCase()===` `?`space`:e.key.toLowerCase();return[`control`,`alt`,`meta`,`shift`].includes(n)?``:[...t,n].join(`+`)}function ep(e){return/^(meta\+(w|t|r|l|n)|ctrl\+(w|t|r|n))$/.test(e)||!/(ctrl|alt|meta)\+/.test(e)}function tp(e){let t=window.matchMedia(`(prefers-color-scheme: dark)`).matches;document.documentElement.dataset.theme=e===`system`?t?`dark`:`light`:e}function np({expanded:e=!1}){let[t,n]=(0,l.useState)(`system`);(0,l.useEffect)(()=>{let e=localStorage.getItem(`webr-theme`),t=e===`light`||e===`dark`?e:`system`;n(t),tp(t);let r=window.matchMedia(`(prefers-color-scheme: dark)`),i=()=>{let e=localStorage.getItem(`webr-theme`)||`system`;n(e),tp(e)};return r.addEventListener(`change`,i),window.addEventListener(`webr-theme-change`,i),()=>{r.removeEventListener(`change`,i),window.removeEventListener(`webr-theme-change`,i)}},[]);let r=e=>{n(e),localStorage.setItem(`webr-theme`,e),tp(e)};return(0,Q.jsx)(`div`,{className:e?`theme-control theme-control--expanded`:`theme-control`,role:`group`,"aria-label":`Color theme`,children:[[`system`,z],[`light`,le],[`dark`,ee]].map(([n,i])=>(0,Q.jsx)(Yl,{label:`${n[0].toUpperCase()}${n.slice(1)} theme`,children:(0,Q.jsxs)(`button`,{type:`button`,"aria-label":`${n} theme`,"aria-pressed":t===n,className:t===n?`theme-option is-selected`:`theme-option`,onClick:()=>r(n),children:[(0,Q.jsx)(i,{size:15,strokeWidth:1.8}),e&&(0,Q.jsx)(`span`,{children:n})]})},n))})}var rp={machine_disconnected:`The machine is not connected.`,launch_in_progress:`Wait for the launch to finish, then try again.`,thread_not_found:`This thread does not exist anymore.`};async function ip(e,t={}){let n=await fetch(e,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)}),r=await n.json().catch(()=>({}));if(!n.ok)throw Error(rp[r.error??``]??`Herdr could not complete this action.`);return r}var ap=(e,t)=>ip(`/api/threads/${encodeURIComponent(e.id)}/archive`,{machineId:e.machineId,archived:t}),op=(e,t)=>ip(`/api/threads/${encodeURIComponent(e.id)}/rename`,{machineId:e.machineId,title:t}),sp=(e,t)=>ip(`/api/projects/rename`,{machineId:e.machineId??`local`,logicalId:e.logicalId??e.id,name:t}),cp=e=>`/api/projects/icon?machineId=${encodeURIComponent(e.machineId??`local`)}&logicalId=${encodeURIComponent(e.logicalId??e.id)}`;async function lp(e,t){if(!(await fetch(cp(e),{method:`PUT`,headers:{"Content-Type":`image/png`},body:t})).ok)throw Error(`Could not save this icon.`)}async function up(e){if(!(await fetch(cp(e),{method:`DELETE`})).ok)throw Error(`Could not reset this icon.`)}var dp=(e,t)=>ip(`/api/threads/${encodeURIComponent(e.id)}/panes/terminal`,{machineId:e.machineId,afterPaneId:t}),fp=(e,t,n)=>ip(`/api/threads/${encodeURIComponent(e.id)}/panes/close`,{machineId:e.machineId,paneId:t,force:n}),pp=e=>ip(`/api/threads/${encodeURIComponent(e.id)}/delete`,{machineId:e.machineId}),mp=()=>ip(`/api/archive/delete`),hp=(e,t,n)=>e===1?t:n;function gp(e){let t=e.length,n=e.filter(e=>e.ownsWorktree).length,r=hp(t,`Delete this thread`,`Delete ${t} threads`),i=hp(t,`its terminal`,`their terminals`);return n?`${r} permanently? This closes ${i} and removes ${n===t?hp(t,`its worktree`,`their worktrees`):`${n} ${hp(n,`worktree`,`worktrees`)}`}, including uncommitted changes.`:`${r} permanently? This closes ${i}. Your project files stay untouched.`}var _p=(e,t)=>e.panes.length>1&&e.panes.some(e=>e.id===t&&e.kind!==`agent`),vp=(e,t)=>e[t-1]??e[t+1];function yp(e,t,n){let r=e.findIndex(e=>e.id===n);return e.slice(t,t+2).find(e=>e.id!==n)??vp(e,r)}function bp(e,t,n,r=2){let i=n<0?t:n<t?n:n>=t+r?n-r+1:t;return Math.max(0,Math.min(i,e-r))}function xp(e){let t=performance.now();return()=>performance.now()-t}var Sp=()=>performance.now();function Cp(){}var wp=e=>ol(e instanceof Error?e.message:`Herdr could not complete this action.`);function Tp({open:e,onClose:t,projects:n,threads:r,thread:i,focusedPane:o,mode:s,onModeChange:c,onToggleSidebar:u,onFocusPane:d,onTerminalAction:v,onOpenTerminal:y,onClosePane:b}){let[x,S]=(0,l.useState)(``),[C,w]=(0,l.useState)(0),[T,E]=(0,l.useState)(Yf),O=(0,l.useRef)(null);(0,l.useEffect)(()=>{e&&(S(``),w(0),E(Xf()),requestAnimationFrame(()=>O.current?.focus()))},[e]);let k=e=>{let t=r.findIndex(e=>e.id===i?.id),n=r[((t===-1&&e<0?0:t)+e+r.length)%r.length];n&&a(`/threads/${encodeURIComponent(n.id)}`)},j=e=>{i?.panes.length&&d(i.panes[(i.panes.findIndex(e=>e.id===o)+e+i.panes.length)%i.panes.length].id)},M=(0,l.useMemo)(()=>[{label:`New thread`,icon:(0,Q.jsx)(oe,{size:16}),shortcut:`newThread`,run:()=>{a(`/new${i?`?project=${encodeURIComponent(i.projectId)}`:``}`)}},{label:`Settings`,icon:(0,Q.jsx)(ae,{size:16}),run:()=>{a(`/settings`)}},{label:`Toggle sidebar`,icon:(0,Q.jsx)(ne,{size:16}),shortcut:`toggleSidebar`,run:u},...r.length?[{label:`Next thread`,icon:(0,Q.jsx)(m,{size:16}),shortcut:`nextThread`,run:()=>k(1)},{label:`Previous thread`,icon:(0,Q.jsx)(_,{size:16}),shortcut:`previousThread`,run:()=>k(-1)}]:[],{label:`Group threads by project`,icon:(0,Q.jsx)(A,{size:16}),detail:s===`projects`?`Selected`:void 0,run:()=>c(`projects`)},{label:`Show all threads`,icon:(0,Q.jsx)(F,{size:16}),detail:s===`threads`?`Selected`:void 0,run:()=>c(`threads`)},...[`system`,`light`,`dark`].map(e=>({label:`${e[0].toUpperCase()}${e.slice(1)} theme`,icon:e===`system`?(0,Q.jsx)(z,{size:16}):e===`light`?(0,Q.jsx)(le,{size:16}):(0,Q.jsx)(ee,{size:16}),run:()=>{localStorage.setItem(`webr-theme`,e),tp(e),window.dispatchEvent(new Event(`webr-theme-change`))}})),...i?[{label:i.archivedAt?`Unarchive thread`:`Archive thread`,icon:i.archivedAt?(0,Q.jsx)(f,{size:16}):(0,Q.jsx)(p,{size:16}),run:()=>{ap(i,!i.archivedAt).catch(wp)}},{label:`Copy thread link`,icon:(0,Q.jsx)(D,{size:16}),run:()=>{navigator.clipboard.writeText(location.href)}},...i.bindingState===`attached`?[{label:`New terminal`,icon:(0,Q.jsx)(se,{size:16}),shortcut:`openTerminal`,run:y},..._p(i,o)?[{label:`Close pane`,icon:(0,Q.jsx)(fe,{size:16}),shortcut:`closePane`,run:b}]:[]]:[],...i.bindingState===`attached`?[{label:`Request terminal control`,icon:(0,Q.jsx)(se,{size:16}),run:()=>v(`control`)},{label:`Release terminal control`,icon:(0,Q.jsx)(se,{size:16}),run:()=>v(`release`)},{label:`Take over terminal control`,icon:(0,Q.jsx)(se,{size:16}),run:()=>{al(`Replace the active controller of this terminal?`,{confirmLabel:`Take over`}).then(e=>{e&&v(`takeover`)})}}]:[],{label:`Next pane`,icon:(0,Q.jsx)(g,{size:16}),shortcut:`nextPane`,run:()=>j(1)},{label:`Previous pane`,icon:(0,Q.jsx)(h,{size:16}),shortcut:`previousPane`,run:()=>j(-1)},...i.panes.map((e,t)=>({label:`Focus ${e.title}`,icon:(0,Q.jsx)(se,{size:16}),detail:`Pane ${t+1}`,run:()=>d(e.id)}))]:[],...r.map(e=>({label:e.title,icon:(0,Q.jsx)(qf,{thread:e,working:e.status===`working`,size:22}),detail:n.find(t=>t.id===e.projectId)?.name,run:()=>{a(`/threads/${encodeURIComponent(e.id)}`)}}))],[n,r,i,o,s,c,u,d,v,y,b]).filter(e=>`${e.label} ${e.detail??``}`.toLowerCase().includes(x.toLowerCase().trim()));if(!e)return null;let N=e=>{t(),e.run()};return(0,Q.jsx)(`div`,{className:`palette-overlay`,onMouseDown:e=>{e.target===e.currentTarget&&t()},children:(0,Q.jsxs)(`div`,{className:`palette`,role:`dialog`,"aria-modal":`true`,"aria-label":`Command palette`,onKeyDown:e=>{e.key===`Escape`&&(e.preventDefault(),t()),e.key===`ArrowDown`&&(e.preventDefault(),w(e=>(e+1)%(M.length||1))),e.key===`ArrowUp`&&(e.preventDefault(),w(e=>(e-1+(M.length||1))%(M.length||1))),e.key===`Enter`&&M.length&&(e.preventDefault(),N(M[Math.min(C,M.length-1)])),e.key===`Tab`&&(e.preventDefault(),O.current?.focus())},children:[(0,Q.jsx)(`input`,{ref:O,"aria-label":`Search commands and threads`,placeholder:`Search threads and actions…`,value:x,onChange:e=>{S(e.target.value),w(0)}}),(0,Q.jsxs)(`div`,{className:`palette-results`,role:`listbox`,"aria-label":`Results`,children:[M.map((e,t)=>(0,Q.jsxs)(`button`,{role:`option`,"aria-selected":C===t,className:C===t?`is-selected`:``,onMouseEnter:()=>w(t),onClick:()=>N(e),children:[(0,Q.jsx)(`span`,{className:`palette-icon`,"aria-hidden":`true`,children:e.icon}),(0,Q.jsx)(`span`,{className:`palette-label`,children:e.label}),e.detail&&(0,Q.jsx)(`small`,{children:e.detail}),e.shortcut&&(0,Q.jsx)(Yl,{label:T[e.shortcut],children:(0,Q.jsx)(`kbd`,{children:Qf(T[e.shortcut])})})]},`${e.label}-${t}`)),!M.length&&(0,Q.jsx)(`p`,{children:`No results`})]}),(0,Q.jsxs)(`div`,{className:`palette-help`,children:[`↑↓ Navigate `,(0,Q.jsx)(`span`,{children:`↵ Select`}),` `,(0,Q.jsx)(`span`,{children:`Esc Close`})]})]})})}var Ep=2e3,Dp=e=>fetch(e,{method:`POST`,headers:{"Content-Type":`application/json`},body:`{}`});async function Op(){let e=await Dp(`/api/pair/invites`);if(!e.ok)throw Error(`Webr could not create a code.`);return e.json()}async function kp(){let e=await fetch(`/api/devices`);if(!e.ok)throw Error(`Webr could not list devices.`);return e.json()}async function Ap(){let e=await fetch(`/api/audit`);if(!e.ok)throw Error(`Webr could not load recent activity.`);return e.json()}async function jp(){let e=await fetch(`/api/remote/tailscale`);return e.ok?(await e.json()).status:`unavailable`}var Mp=e=>Dp(`/api/devices/${encodeURIComponent(e)}/revoke`),Np=(e,t)=>Dp(`/api/pair/${encodeURIComponent(e)}/${t}`);async function Pp(){try{let e=await fetch(`/api/pair/pending`);return e.ok?await e.json():[]}catch{return[]}}var Fp=()=>typeof Notification<`u`&&Notification.permission===`granted`,Ip=()=>document.visibilityState===`visible`||Fp();function Lp(e,t){if(document.visibilityState!==`visible`&&Fp())for(let n of e)t.has(n.id)||(t.add(n.id),new Notification(`A device wants to connect to Webr`,{body:`${n.deviceName} · ${n.source}`,tag:n.id}))}function Rp(){let[e,t]=(0,l.useState)([]),n=(0,l.useRef)(new Set),r=(0,l.useCallback)(async()=>{if(!Ip())return;let e=await Pp();Lp(e,n.current),t(e)},[]);return(0,l.useEffect)(()=>{r();let e=setInterval(()=>void r(),Ep);return document.addEventListener(`visibilitychange`,r),()=>{clearInterval(e),document.removeEventListener(`visibilitychange`,r)}},[r]),{pending:e,decide:(0,l.useCallback)(async(e,n)=>{t(t=>t.filter(t=>t.id!==e)),await Np(e,n).catch(()=>void 0),await r()},[r])}}function zp(e,t=Date.now()){let n=Math.round((e-t)/1e3),[r,i]=[[`day`,86400],[`hour`,3600],[`minute`,60]].find(([,e])=>Math.abs(n)>=e)??[`second`,1];return Math.abs(n)<45?`just now`:new Intl.RelativeTimeFormat(`en`,{numeric:`auto`}).format(Math.round(n/i),r)}var Bp=()=>typeof Notification<`u`,Vp=()=>Bp()?Notification.permission:`denied`,Hp=()=>Notification.requestPermission();function Up({kind:e,deviceName:t,source:n}){let r=t??`A device`,i=n?` from ${n}`:``;return{pair_requested:`${r} asked to connect${i}`,pair_approved:`${r} was approved${i}`,pair_denied:`${r} was declined${i}`,invite_created:`A connection code was created${i}`,invite_redeemed:`${r} connected with a code${i}`,device_revoked:`${r} was disconnected`,session_expired:`${r} was signed out after being idle`}[e]}function Wp(e,t=Date.now()){return e<=t?`expired`:new Intl.RelativeTimeFormat(`en`,{numeric:`auto`}).format(...Gp(e-t))}function Gp(e){let t=Math.round(e/864e5);return t>=1?[t,`day`]:[Math.max(1,Math.round(e/36e5)),`hour`]}function Kp(){let{pending:e,decide:t}=Rp(),n=e[0];return(0,Q.jsx)(Dc,{open:!!n,onOpenChange:e=>{!e&&n&&t(n.id,`deny`)},children:(0,Q.jsxs)(Jc,{children:[(0,Q.jsx)(Oc,{className:`dialog-backdrop`}),(0,Q.jsx)(Gc,{className:`dialog pairing-prompt`,children:n&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(Yc,{className:`pairing-title`,children:[`Allow `,n.deviceName,` to connect?`]}),(0,Q.jsxs)(Rc,{className:`dialog-message`,children:[`Requested from `,n.source,`. Only approve if this code matches the one shown on that device.`]}),(0,Q.jsx)(`div`,{className:`pairing-code`,"aria-label":`Code ${n.code}`,children:n.code}),e.length>1&&(0,Q.jsxs)(`p`,{className:`settings-note`,children:[e.length-1,` more waiting`]}),(0,Q.jsxs)(`div`,{className:`dialog-actions`,children:[(0,Q.jsx)(`button`,{type:`button`,className:`dialog-button`,onClick:()=>void t(n.id,`deny`),children:`Deny`}),(0,Q.jsx)(`button`,{type:`button`,autoFocus:!0,className:`dialog-button is-primary`,onClick:()=>void t(n.id,`approve`),children:`Approve`})]})]})})]})})}var qp=({children:e})=>(0,Q.jsx)(Q.Fragment,{children:e}),Jp=[`image/png`,`image/jpeg`,`image/gif`,`image/webp`],Yp={image_too_large:`This image is larger than 20 MB.`,file_too_large:`This file is larger than 5 MB.`,empty_file:`This file is empty.`,unsupported_image:`Only PNG, JPEG, GIF and WebP images can be attached.`,uploads_unsupported_target:`Files cannot be attached on this machine yet.`,upload_failed:`The file could not be sent to the machine.`,machine_disconnected:`The machine is not connected.`},Xp=e=>Jp.includes(e.type),Zp=e=>e?.files?[...e.files].filter(Xp):[],Qp=e=>e?.files?[...e.files]:[],$p=e=>!!e?.types&&[...e.types].includes(`Files`),em=e=>e.replace(/([\s\\'"()&;$`!*?[\]{}<>|#~])/g,`\\$1`);async function tm(e,t){if(!Xp(t))throw Error(Yp.unsupported_image);if(t.size>20971520)throw Error(Yp.image_too_large);let n=await fetch(`/api/uploads?machineId=${encodeURIComponent(e)}`,{method:`POST`,headers:{"Content-Type":t.type},body:t}),r=await n.json().catch(()=>({}));if(!n.ok||!r.path)throw Error(Yp[r.error??``]??`The image could not be attached.`);return r.path}async function nm(e,t){if(Xp(t))return tm(e,t);if(t.size>5242880)throw Error(Yp.file_too_large);let n=await fetch(`/api/uploads?machineId=${encodeURIComponent(e)}&name=${encodeURIComponent(t.name)}`,{method:`POST`,headers:{"Content-Type":`application/octet-stream`},body:t}),r=await n.json().catch(()=>({}));if(!n.ok||!r.path)throw Error(Yp[r.error??``]??`The file could not be attached.`);return r.path}var rm=160,im=e=>new Promise((t,n)=>{let r=new FileReader;r.onload=()=>t(String(r.result)),r.onerror=()=>n(r.error),r.readAsDataURL(e)});async function am(e){if(typeof createImageBitmap!=`function`)return im(e);let t=await createImageBitmap(e),n=Math.min(1,rm/Math.max(t.width,t.height)),r=document.createElement(`canvas`);return r.width=Math.max(1,Math.round(t.width*n)),r.height=Math.max(1,Math.round(t.height*n)),r.getContext(`2d`)?.drawImage(t,0,0,r.width,r.height),t.close(),r.toDataURL(`image/jpeg`,.8)}async function om(e,t){let n=[];for(let r of t)n.push(await nm(e,r));return n.map(em).join(` `)+` `}var sm=e=>Array.from(e,e=>e.toString(16).padStart(2,`0`)).join(``);function cm(){if(typeof crypto.randomUUID==`function`)return crypto.randomUUID();let e=crypto.getRandomValues(new Uint8Array(16));e[6]=e[6]&15|64,e[8]=e[8]&63|128;let t=sm(e);return`${t.slice(0,8)}-${t.slice(8,12)}-${t.slice(12,16)}-${t.slice(16,20)}-${t.slice(20)}`}var lm=`Nothing to attach.`,um=e=>Xp(e)?am(e):Promise.resolve(``),dm=(e,t)=>[e.trim(),...t.map(e=>em(e.path))].filter(Boolean).join(` `);function fm({machineId:e}){let[t,n]=(0,l.useState)(!1),[r,i]=(0,l.useState)([]),[a,o]=(0,l.useState)(0),[s,c]=(0,l.useState)(``),u=(0,l.useRef)(0),d=async t=>{if(!t.length){c(lm);return}c(``),o(e=>e+t.length);for(let n of t)try{let t=await nm(e,n),r=await um(n);i(e=>[...e,{id:cm(),name:n.name||`file`,preview:r,path:t}])}catch(e){c(e instanceof Error?e.message:`The file could not be attached.`)}finally{o(e=>e-1)}};return{dragging:t,attachments:r,setAttachments:i,uploading:a,error:s,remove:e=>i(t=>t.filter(t=>t.id!==e)),handlers:{onDragEnter:e=>{$p(e.dataTransfer)&&(e.preventDefault(),u.current+=1,n(!0))},onDragOver:e=>{$p(e.dataTransfer)&&(e.preventDefault(),e.dataTransfer.dropEffect=`copy`)},onDragLeave:e=>{$p(e.dataTransfer)&&(u.current=Math.max(0,u.current-1),u.current||n(!1))},onDrop:e=>{$p(e.dataTransfer)&&(e.preventDefault(),u.current=0,n(!1),d(Qp(e.dataTransfer)))},onPaste:e=>{let t=Zp(e.clipboardData);t.length&&(e.preventDefault(),d(t))}}}}function pm({controlled:e,default:t,name:n,state:r=`value`}){let{current:i}=l.useRef(e!==void 0),[a,o]=l.useState(t);return[i&&e!==void 0?e:a,l.useCallback(e=>{i||o(e)},[])]}function mm(e){let t=l.useRef(!0);t.current&&(t.current=!1,e())}function hm(e,t,n,r,i,a,o,s,c,l=2){let u=Nr(n.current,{event:e,orientation:r,loopFocus:i,rtl:a,cols:l,disabledIndices:o,minIndex:s,maxIndex:c,prevIndex:t>c?s:t,stopEvent:!0});return kr(n.current,u)?void 0:u}var gm=l.createContext(void 0),_m=l.createContext(void 0),vm=l.createContext(void 0),ym=l.createContext(!1),bm=l.createContext(``);function xm(){let e=l.useContext(gm);if(!e)throw Error(Ai(22));return e}function Sm(){let e=l.useContext(_m);if(!e)throw Error(Ai(23));return e}function Cm(){let e=l.useContext(vm);if(!e)throw Error(Ai(24));return e}function wm(){return l.useContext(bm)}function Tm(){return l.useContext(ym)}function Em(e,t,n=Object.is){let{length:r}=e;if(r!==t.length)return!1;for(let i=0;i<r;i+=1)if(!n(e[i],t[i]))return!1;return!0}var Dm=(e,t)=>Object.is(e,t);function Om(e,t,n){return e==null||t==null?Object.is(e,t):n(e,t)}function km(e,t,n){return Array.isArray(e)&&Array.isArray(t)?!Em(e,t,(e,t)=>Om(e,t,n)):e!==t}function Am(e,t,n){return e?e.some(e=>e!==void 0&&Om(t,e,n)):!1}function jm(e,t,n){return e?e.findIndex(e=>e!==void 0&&Om(e,t,n)):-1}function Mm(e,t){if(t!==Dm)return n=>Am(e,n,t);let n=new Set(e);return n.delete(void 0),t=>n.has(t)&&(t!==0||e.some(e=>Object.is(t,e)))}function Nm(e,t,n,r){let i=r&&Array.isArray(t)?e.findIndex(Mm(t,n)):jm(e,t,n);return i===-1?null:i}function Pm(e,t,n,r,i,a){return Am(r,t,i)?a!=null&&e>a&&Am(r,n[a],i)?a:e:e===a?Nm(n,r,i,!0):a}function Fm(e,t,n){return e.filter(e=>!Om(t,e,n))}function Im(e){if(e==null)return``;if(typeof e==`string`)return e;try{return JSON.stringify(e)}catch{return String(e)}}function Lm(e){return typeof e==`object`&&!!e&&Array.isArray(e.items)}function Rm(e){return Lm(e?.[0])}function zm(e){return Rm(e)?e.flatMap(e=>e.items):e}function Bm(e){if(!Array.isArray(e))return e!=null&&`null`in e;let t=e;if(Rm(t)){for(let e of t)for(let t of e.items)if(t&&t.value==null&&t.label!=null)return!0;return!1}for(let e of t)if(e&&e.value==null&&e.label!=null)return!0;return!1}function Vm(e,t){if(t&&e!=null)return t(e)??``;if(e&&typeof e==`object`){if(`label`in e&&e.label!=null)return String(e.label);if(`value`in e)return String(e.value)}return Im(e)}function Hm(e,t){return t&&e!=null?t(e)??``:e&&typeof e==`object`&&`value`in e&&`label`in e?Im(e.value):Im(e)}var Um={id:e=>e.id,labelId:e=>e.labelId,items:e=>e.items,selectedValue:e=>e.selectedValue,hasSelectionChips:e=>{let t=e.selectedValue;return Array.isArray(t)&&t.length>0},hasSelectedValue:e=>{let{selectedValue:t,selectionMode:n}=e;return t==null?!1:n===`multiple`&&Array.isArray(t)?t.length>0:!0},hasNullItemLabel:(e,t)=>t?Bm(e.items):!1,open:e=>e.open,mounted:e=>e.mounted,forceMounted:e=>e.forceMounted,inline:e=>e.inline,activeIndex:e=>e.activeIndex,selectedIndex:e=>e.selectedIndex,isActive:(e,t)=>e.activeIndex===t,isSelected:(e,t)=>{let n=e.isItemEqualToValue,r=e.selectedValue;return Array.isArray(r)?r.some(e=>Om(t,e,n)):Om(t,r,n)},transitionStatus:e=>e.transitionStatus,popupProps:e=>e.popupProps,listProps:e=>e.listProps,inputProps:e=>e.inputProps,triggerProps:e=>e.triggerProps,itemProps:e=>e.itemProps,positionerElement:e=>e.positionerElement,listElement:e=>e.listElement,popupId:e=>e.popupId,triggerElement:e=>e.triggerElement,inputElement:e=>e.inputElement,inputGroupElement:e=>e.inputGroupElement,popupSide:e=>e.popupSide,openMethod:e=>e.openMethod,inputInsidePopup:e=>e.inputInsidePopup,inputOwnsFormValue:e=>e.inputOwnsFormValue,selectionMode:e=>e.selectionMode,name:e=>e.name,form:e=>e.form,disabled:e=>e.disabled,readOnly:e=>e.readOnly,required:e=>e.required,grid:e=>e.grid,virtualized:e=>e.virtualized,itemToStringLabel:e=>e.itemToStringLabel,isItemEqualToValue:e=>e.isItemEqualToValue,modal:e=>e.modal,autoHighlight:e=>e.autoHighlight},Wm=`data-valid`,Gm=`data-invalid`,Km={badInput:!1,customError:!1,patternMismatch:!1,rangeOverflow:!1,rangeUnderflow:!1,stepMismatch:!1,tooLong:!1,tooShort:!1,typeMismatch:!1,valid:null,valueMissing:!1},qm={valid:null,touched:!1,dirty:!1,filled:!1,focused:!1},Jm={disabled:!1,...qm},Ym={valid(e){return e===null?null:e?{[Wm]:``}:{[Gm]:``}}},Xm={invalid:void 0,name:void 0,validityData:{state:Km,errors:[],error:``,value:``,initialValue:null},setValidityData:Qe,disabled:void 0,setTouched:Qe,setDirty:Qe,setFilled:Qe,setFocused:Qe,validationMode:`onSubmit`,shouldValidateOnChange:()=>!1,state:Jm,registerFieldControl:Qe,validation:{getValidationProps:(e,t=et)=>t,inputRef:{current:null},registeredInputs:new Map,registerInput:Qe,getInputControl:()=>null,commit:async()=>{},change:Qe}},Zm=l.createContext(Xm);function Qm(e=!0){let t=l.useContext(Zm);if(t.setValidityData===Qe&&!e)throw Error(Ai(28));return t}function $m(e,t,n,r,i=!0,a){let{registerFieldControl:o}=Qm(),s=Ze(()=>Symbol());U(()=>{let c=s.current;if(!i){o(c,void 0);return}o(c,{controlRef:e,getValue:r,id:t,name:a,value:n})},[e,i,r,t,a,o,s,n]),U(()=>{let e=s.current;return()=>{o(e,void 0)}},[o,s])}var eh=l.createContext({elementRef:{current:null},formRef:{current:{fields:new Map}},errors:{},clearErrors:Qe,validationMode:`onSubmit`,submitCountRef:{current:0}});function th(){return l.useContext(eh)}var nh=l.createContext({controlId:void 0,registerControlId:Qe,resetControlId:Qe,labelId:void 0,setLabelId:Qe,messageIds:[],setMessageIds:Qe,getDescriptionProps:e=>e});function rh(){return l.useContext(nh)}function ih(e={}){let{id:t,enabled:n=!0}=e,{controlId:r,registerControlId:i,resetControlId:a}=rh(),o=Lc(),s=Ze(()=>Symbol()),c=l.useRef(!1),u=l.useRef(!1),d=$(()=>{c.current&&i!==Qe&&(c.current=!1,i(s.current,void 0))});return U(()=>{if(!n||i===Qe){d();return}let e;if(t!==void 0)u.current=!0,e=t;else if(u.current)e=o;else{a();return}if(e===void 0){d();return}c.current=!0,i(s.current,e)},[t,n,i,a,o,s,d]),U(()=>d,[d]),(n?r:void 0)??t??o}function ah(e){return e==null?void 0:`${e}-popup`}function oh(e,t){return(n,r)=>n!=null&&e.contains(n,r,t)}function sh(e){return Array.isArray(e)?e.map(e=>sh(e)).join(`,`):e==null?``:String(e)}var ch=new Map;function lh(e={}){let t={usage:`search`,sensitivity:`base`,ignorePunctuation:!0,...e},n=`${sh(e.locale)}|${JSON.stringify(t)}`,r=ch.get(n);if(r)return r;let i=new Intl.Collator(e.locale,t),a={contains(e,t,n){if(!t)return!0;let r=Vm(e,n);for(let e=0;e<=r.length-t.length;e+=1)if(i.compare(r.slice(e,e+t.length),t)===0)return!0;return!1},startsWith(e,t,n){if(!t)return!0;let r=Vm(e,n);return i.compare(r.slice(0,t.length),t)===0},endsWith(e,t,n){if(!t)return!0;let r=Vm(e,n),a=t.length;return r.length>=a&&i.compare(r.slice(r.length-a),t)===0}};return ch.set(n,a),a}var uh=lh;function dh(e,t=!1){let{overflowY:n}=ke(e);return n!==`auto`&&n!==`scroll`?!1:t?e.clientHeight>0:e.scrollHeight>e.clientHeight}var fh=Symbol(`none`),ph={value:fh,index:-1};function mh(e,t,n){let r=e.get(t);if(r!==void 0||n===Dm)return r;for(let[r,i]of e)if(Om(r,t,n))return i}function hh(e){let{id:t,onOpenChangeComplete:n,defaultSelectedValue:r=null,selectedValue:i,onSelectedValueChange:a,defaultInputValue:o,inputValue:s,open:c,defaultOpen:u=!1,selectionMode:d,onItemHighlighted:f,name:p,form:m,disabled:h=!1,readOnly:g=!1,required:_=!1,inputRef:v,grid:y=!1,items:b,filteredItems:x,filter:S,filterQuery:C,openOnInputClick:w=!0,autoHighlight:T=!1,keepHighlight:E=!1,highlightItemOnHover:D=!0,loopFocus:O=!0,itemToStringLabel:k,itemToStringValue:A,isItemEqualToValue:j=Dm,virtualized:M=!1,inline:N=!1,fillInputOnItemPress:P=!0,modal:F=!1,limit:I=-1,autoComplete:L=`list`,formAutoComplete:R,locale:z,submitOnItemClick:ee=!1}=e,{clearErrors:B}=th(),{setDirty:te,validityData:ne,setFilled:re,name:V,disabled:H,setTouched:ie,setFocused:ae,validationMode:oe,validation:se}=Qm(),ce=Ol(),le=ih({id:t}),ue=uh({locale:z}),de=Array.isArray(b)?null:b;if(de&&typeof de.label!=`function`)throw Error(Ai(100));let fe=de?de.data:b,pe=de?.value,W=pe?void 0:fe,me=l.useMemo(()=>{if(!x||!pe)return;let e=zm(x),t=e.map(pe),n;return{values:t,findItem(r,i){if(!n){n=new Map;for(let r=0;r<t.length;r+=1)n.has(t[r])||n.set(t[r],e[r])}return mh(n,r,i)}}},[x,pe]),he=l.useMemo(()=>de?e=>de.label(e,j,e=>{let t=me?.findItem(e,j);return t==null?Vm(e,k):de.itemLabel(t)}):k,[de,k,me,j]),ge=l.useMemo(()=>de?Object.assign(e=>de.itemLabel(e),{selected:e=>Vm(e,he)}):k,[de,he,k]);function G(e){return Vm(e,he)}let[_e,ve]=l.useState(!1),[ye,be]=l.useState(null),xe=l.useRef(ye),Se=l.useRef([]),Ce=l.useRef([]),we=l.useRef(null),Te=l.useRef(null),Ee=l.useRef(null),De=l.useRef(null),Oe=l.useRef(null),ke=l.useRef(!0),Ae=l.useRef(!1),je=l.useRef(null),Me=l.useRef(null),Pe=l.useRef(null),q=l.useRef(ph),Fe=l.useRef(null),Ie=l.useRef([]),Le=l.useRef(null),Re=H||h,ze=V??p,Be=d===`multiple`,Ve=d===`single`,He=s!==void 0||o!==void 0,Ue=fe!==void 0,We=x!==void 0,Ge;Ge=T===`always`?`always`:T?`input-change`:!1;let[Ke,qe]=pm({controlled:i,default:Be?r??$e:r,name:`Combobox`,state:`selectedValue`}),Je=l.useMemo(()=>S===null?()=>!0:S===void 0?oh(ue,ge):S,[S,ue,ge]),Ye=Ze(()=>He?o??``:Ve?G(Ke):``).current,[J,Xe]=pm({controlled:s,default:Ye,name:`Combobox`,state:`inputValue`}),[tt,nt]=pm({controlled:c,default:u,name:`Combobox`,state:`open`}),rt=Rm(fe),it=!tt&&ye!==null?ye:String(J).trim(),at=Ve?G(Ke):``,ot=Ve&&!_e&&it!==``&&at.length===it.length&&ue.contains(at,it),st=ot?``:C??it,ct=Ue&&We&&ot&&(!de||de.hasValue(Ke,j)),lt=l.useMemo(()=>fe?zm(fe):$e,[fe]),ut=l.useMemo(()=>{if(x&&!ct)return x;if(!fe)return $e;if(rt){let e=fe,t=[],n=0;for(let r of e){if(I>-1&&n>=I)break;let e=I>-1?I-n:1/0,i=st===``?r.items.slice(0,e):[];if(st!==``)for(let t of r.items){if(i.length>=e)break;Je(t,st,ge)&&i.push(t)}if(i.length>0){let e={...r,items:i};t.push(e),n+=i.length}}return t}if(st===``)return I>-1?lt.slice(0,I):lt;let e=[];for(let t of lt){if(I>-1&&e.length>=I)break;Je(t,st,ge)&&e.push(t)}return e},[x,ct,fe,rt,st,I,Je,ge,lt]),dt=l.useMemo(()=>{if(me&&ut===x)return me.values;let e=zm(ut);return pe?e.map(e=>pe(e)):e},[ut,x,me,pe]),Y=Ze(()=>{let e=null;return N&&tt&&Ue&&d!==`none`&&(e=Nm(dt,Ke,j,Be)),new ds({id:le,labelId:void 0,selectedValue:Ke,open:tt,items:W,selectionMode:d,name:ze,form:m,disabled:Re,readOnly:g,required:_,grid:y,virtualized:M,openOnInputClick:w,itemToStringLabel:he,isItemEqualToValue:j,modal:F,autoHighlight:Ge,submitOnItemClick:ee,hasInputValue:He,mounted:!1,forceMounted:!1,transitionStatus:`idle`,inline:N,activeIndex:null,selectedIndex:e,popupProps:{},listProps:{},inputProps:{},triggerProps:{},itemProps:et,positionerElement:null,listElement:null,popupId:void 0,triggerElement:null,inputElement:null,inputGroupElement:null,popupSide:null,openMethod:null,inputInsidePopup:!0,inputOwnsFormValue:d===`none`},{onOpenChangeComplete:Qe,setOpen:Qe,setInputValue:Qe,setSelectedValue:Qe,setIndices:Qe,handleSelection:Qe,forceMount:Qe,requestSubmit:Qe,listRef:Se,labelsRef:Ce,popupRef:we,emptyRef:Oe,inputRef:Te,startDismissRef:Ee,endDismissRef:De,keyboardActiveRef:ke,chipsContainerRef:je,clearRef:Me,valuesRef:Ie,pointerDownItemRef:Le,selectionEventRef:Pe},Um)}).current,ft=d===`none`?J:Ke,pt=l.useMemo(()=>d===`none`?ft:Array.isArray(Ke)?Ke.map(e=>Hm(e,A)):Hm(Ke,A),[ft,A,d,Ke]),mt=$(f),ht=$(n),gt=Y.useState(`activeIndex`),_t=Y.useState(`selectedIndex`),vt=Y.useState(`positionerElement`),yt=Y.useState(`listElement`),bt=Y.useState(`triggerElement`),xt=Y.useState(`inputElement`),St=Y.useState(`inputGroupElement`),Ct=Y.useState(`inline`),wt=Y.useState(`inputInsidePopup`),Tt=Y.useState(`inputOwnsFormValue`),Dt=Ve&&!wt&&J===at,Ot=Wn(bt),{mounted:kt,setMounted:At,transitionStatus:jt}=hs(tt),{openMethod:Mt,triggerProps:Nt}=$c(tt),Pt=$(()=>pt);$m(wt?Ot:Te,le,ft,Pt,!Re,p);let Ft=$(()=>{fe?Ce.current=dt.map(G):Y.set(`forceMounted`,!0)}),It=$((e,t,n)=>{if(t===-1){if(q.current===ph)return;q.current=ph}else q.current={value:e,index:t};mt(e,Mn(n,void 0,{index:t}))}),Lt=$(e=>{let t={};e.activeIndex!==void 0&&(t.activeIndex=e.activeIndex),e.selectedIndex!==void 0&&(t.selectedIndex=e.selectedIndex),Y.update(t);let n=e.activeIndex;if(n===void 0)return;let r=e.type||`none`;n===null?It(void 0,-1,r):It(Ie.current[n],n,r)}),Rt=$((t,n)=>{if(e.onInputValueChange?.(t,n),!n.isCanceled){if(Ae.current=n.reason===xn,n.reason===`input-change`){tt&&ye!==null&&be(null);let e=n.event,r=e.inputType;if(e.type===`compositionend`||r!=null&&r!==``&&r!==`insertReplacementText`){let e=t.trim()!==``;e&&ve(!0),Fe.current={hasQuery:e};let n=Y.state.listElement;if(!Y.state.virtualized&&n){let e=we.current;for(let t of Ne(n.firstElementChild??n)){if(!K(t)||(e?!X(e,t):t.getAttribute(`role`)===`dialog`))break;if(dh(t)){t.scrollTop=0;break}}}e&&Ge&&Y.state.activeIndex==null&&(tt||Ct)&&Y.set(`activeIndex`,0)}}else n.reason===`input-clear`&&t===``&&Y.state.inputInsidePopup&&(Fe.current={hasQuery:!1,selection:!0});Xe(t)}}),zt=$(e=>{let t=!e&&wt&&!Ct&&J!==``&&(String(J).trim()===ye||J===at);!e&&(t||J===``||Dt)&&ve(!1),be(null),t&&Rt(``,Z(xn))}),Bt=$((t,n)=>{if(tt!==t&&(n.reason===`escape-key`&&Ue&&dt.length===0&&!Oe.current&&n.allowPropagation(),e.onOpenChange?.(t,n),!n.isCanceled&&(t&&ye!==null&&zt(n.reason===bn),!t&&_e&&(Ve?(Ct||be(it),it===``&&ve(!1)):Be&&(Ct||be(it),wt&&Lt({activeIndex:null}),(!wt||Ct)&&Rt(``,Z(xn,n.event,void 0,{isItemPress:n.reason===vn})))),nt(t),!t&&wt&&(n.reason===`focus-out`||n.reason===`outside-press`)&&(ie(!0),ae(!1),oe===`onBlur`)))){let e=d===`none`?J:Ke;se.commit(e)}}),Vt=$((e,t)=>{a?.(e,t),!t.isCanceled&&(qe(e),(d===`none`&&we.current&&P||Ve&&!Y.state.inputInsidePopup)&&Rt(G(e),Z(t.reason,t.event)))}),Ht=$((e,t)=>{let n=Et(e),r=Pe.current??e;Pe.current=null;let i=Z(vn,r),a=n?.closest(`a`)?.getAttribute(`href`);if(a){a.startsWith(`#`)&&Bt(!1,i);return}if(Be){let e=Array.isArray(Ke)?Ke:[],n=Am(e,t,j),r=n?Fm(e,t,j):[...e,t];if(Vt(r,i),i.isCanceled||!(Te.current&&Te.current.value.trim()!==``))return;if(Y.state.inputInsidePopup){Rt(``,Z(xn,i.event,void 0,{isItemPress:!0}));let e=Fe.current;e&&!n&&(e.toggledValue=t)}else Bt(!1,i)}else{if(Vt(t,i),i.isCanceled)return;Bt(!1,i)}}),Ut=$(()=>{let e=se.inputRef.current?.form??Y.state.inputElement?.form;e&&typeof e.requestSubmit==`function`&&e.requestSubmit()}),Wt=$(()=>{if(At(!1),ht?.(!1),ve(!1),be(null),Lt(d===`none`?{activeIndex:null,selectedIndex:null}:{activeIndex:null}),Be&&Te.current&&Te.current.value!==``&&!Ae.current&&Rt(``,Z(xn)),Ve){if(Y.state.inputInsidePopup)Te.current&&Te.current.value!==``&&Rt(``,Z(xn));else{let e=G(Ke);Te.current&&Te.current.value!==e&&Rt(e,Z(e===``?xn:pn))}}}),Gt=l.useMemo(()=>Ct&&vt?{current:vt.closest(`[role="dialog"]`)}:we,[Ct,vt]);ys({enabled:!e.actionsRef,open:tt,ref:Gt,onComplete(){tt||Wt()}}),l.useImperativeHandle(e.actionsRef,()=>({unmount:Wt}),[Wt]),U(function(){let e=xe.current!==null&&ye===null;if(xe.current=ye,tt&&(!e||!Ue)||(tt||(Le.current=null),d===`none`))return;let t=Ue?dt:Ie.current;Lt({selectedIndex:Nm(t,Ke,j,Be)})},[tt,ye,Ke,d,Be,Ue,dt,j,Lt]),U(()=>{fe&&(Ie.current=dt,Se.current.length=dt.length)},[fe,dt]),U(()=>{let e=Fe.current;if(e){let t=tt||Ct||Y.state.positionerElement?.hidden===!1;if(e.hasQuery)Ge&&t&&Y.set(`activeIndex`,0),Fe.current=null;else if(String(J).trim()===``&&(Fe.current=null,t)){let t=e.selection;Ge===`always`&&!t&&Y.state.selectionMode===`none`&&Y.set(`activeIndex`,0),queueMicrotask(()=>{if(!Y.state.open&&!Y.state.inline||Te.current&&Te.current.value.trim()!==``)return;let n=Y.state.selectedValue,r=Y.state.selectionMode===`multiple`;if(r&&Array.isArray(n)?n.length>0:Y.state.selectionMode!==`none`&&n!=null){let t=Ue||We?dt:Ie.current,i=jm(t,e.toggledValue,Y.state.isItemEqualToValue);Y.set(`activeIndex`,i===-1?Nm(t,n,Y.state.isItemEqualToValue,r):i)}else t?Y.set(`activeIndex`,null):Ge===`always`&&Y.set(`activeIndex`,0)})}}if(!tt&&!Ct)return;let t=Ue||We?dt:Ie.current,n=Y.state.activeIndex;if(n==null){if(Ge===`always`&&t.length>0){Y.set(`activeIndex`,0);return}It(void 0,-1,pn);return}if(n>=t.length){It(void 0,-1,pn),Y.set(`activeIndex`,null);return}let r=t[n],i=q.current.value,a=i!==fh&&Om(r,i,Y.state.isItemEqualToValue);(q.current.index!==n||!a)&&It(r,n,pn)},[gt,Ge,It,We,Ue,dt,Ct,tt,Y,J]),U(()=>{if(d===`none`){re(String(J)!==``);return}re(Be?Array.isArray(Ke)&&Ke.length>0:Ke!=null)},[re,d,J,Ke,Be]),l.useEffect(()=>{Ue&&Ge&&dt.length===0&&Lt({activeIndex:null})},[Ue,Ge,dt.length,Lt]);function Kt(){tt&&it!==``&&it!==String(Ye)&&!Dt&&ve(!0)}function qt(){tt&&ye!==null&&zt(!1)}let Jt=!1;function Yt(){!Jt&&J!==at&&(Jt=!0,Rt(at,Z(pn)))}function Xt(){d!==`none`&&(B(ze),te(km(Ke,ne.initialValue,j)),se.change(Ke),Ve&&!He&&!wt&&Yt())}function Zt(){Ve&&!He&&!wt&&!_e&&Yt()}function Qt(){d===`none`&&(B(ze),te(J!==ne.initialValue),se.change(J))}Zc(it,Kt),Zc(tt,qt),Zc(Ke,Xt),Zc(at,Zt),Zc(fe,Zt),Zc(J,Qt);let $t=Us({open:Ct?!0:tt,onOpenChange:Bt,elements:{reference:wt?bt:xt,floating:vt}}),en=y?`grid`:`listbox`,tn=tt||Ct,nn=tn?`true`:`false`,rn=l.useMemo(()=>{let e=xt?.tagName===`INPUT`,t=xt==null||e,n=t||tn,r=t?{autoComplete:`off`,spellCheck:`false`,autoCorrect:`off`,autoCapitalize:`none`}:{};return n&&(r.role=`combobox`,r[`aria-expanded`]=nn,r[`aria-haspopup`]=en,r[`aria-controls`]=tn?yt?.id:void 0,r[`aria-autocomplete`]=g?`none`:L),{reference:r,floating:{role:`presentation`}}},[xt,tn,nn,en,yt?.id,L,g]),an=Fa($t,{enabled:!Re&&w,event:`mousedown-only`,toggle:!1,touchOpenDelay:wt?0:100,reason:Sn}),on=Va($t,{enabled:!Re&&!Ct,outsidePressEvent:{mouse:`sloppy`,touch:`intentional`},bubbles:Ct?!0:void 0,outsidePress(e){let t=Et(e);return!X(bt,t)&&!X(Me.current,t)&&!X(je.current,t)&&!X(St,t)}}),sn=lc($t,{enabled:!Re,id:le,listRef:Se,activeIndex:gt,selectedIndex:_t,virtual:!0,loopFocus:O,allowEscape:O&&!Ge,focusItemOnOpen:_e||d===`none`&&!Ge?!1:`auto`,focusItemOnHover:D,resetOnPointerLeave:!E,orientation:y?`horizontal`:void 0,rtl:ce===`rtl`,disabledIndices:$e,grid:y?hm:void 0,onNavigate(e,t){(t||tt)&&jt!==`ending`&&Lt(t?{activeIndex:e,type:ke.current?En:Dn}:{activeIndex:e})}}),cn=l.useMemo(()=>zi(sn.reference,{onKeyDown(e){y&&Y.state.activeIndex==null&&(e.key===`ArrowLeft`||e.key===`ArrowRight`)&&e.preventBaseUIHandler()}},on.reference,an.reference,rn.reference),[sn.reference,on.reference,an.reference,rn.reference,y,Y]),ln=l.useMemo(()=>zi(bs,on.floating),[on.floating]),un=l.useMemo(()=>zi(sn.floating,rn.floating),[sn.floating,rn.floating]),dn=l.useMemo(()=>{let e=sn.item;return e?{...e,onFocus:void 0}:et},[sn.item]);Y.useContextCallback(`setOpen`,Bt),Y.useContextCallback(`setInputValue`,Rt),Y.useContextCallback(`setSelectedValue`,Vt),Y.useContextCallback(`setIndices`,Lt),Y.useContextCallback(`handleSelection`,Ht),Y.useContextCallback(`forceMount`,Ft),Y.useContextCallback(`requestSubmit`,Ut),Y.useContextCallback(`onOpenChangeComplete`,n),mm(()=>{Y.update({inline:N,popupProps:ln,listProps:un,inputProps:cn,triggerProps:Nt,itemProps:dn})});let fn={id:le,selectedValue:Ke,open:tt,mounted:kt,transitionStatus:jt,items:W,inline:N,popupProps:ln,listProps:un,inputProps:cn,triggerProps:Nt,itemProps:dn,openMethod:Mt,selectionMode:d,name:ze,form:m,disabled:Re,readOnly:g,required:_,grid:y,virtualized:M,openOnInputClick:w,itemToStringLabel:he,modal:F,autoHighlight:Ge,isItemEqualToValue:j,submitOnItemClick:ee,hasInputValue:He};U(()=>{Y.update({...fn,inputOwnsFormValue:d===`none`&&(N||!Y.state.inputInsidePopup)})},[Y,...Object.values(fn)]);let mn=Rn(v,se.inputRef),hn=l.useMemo(()=>({query:it,hasItems:Ue,filteredItems:ut,flatFilteredValues:dt}),[it,Ue,ut,dt]),gn=l.useMemo(()=>Array.isArray(ft)?``:Hm(ft,A),[ft,A]),_n=Be&&Array.isArray(Ke)&&Ke.length>0,yn=Be||d===`none`&&Tt?void 0:ze,Cn=l.useMemo(()=>!Be||!Array.isArray(Ke)||!ze?null:Ke.map(e=>{let t=Hm(e,A);return(0,Q.jsx)(`input`,{type:`hidden`,form:m,name:ze,value:t,disabled:Re},t)}),[Be,Ke,m,ze,A,Re]),wn=(0,Q.jsxs)(l.Fragment,{children:[e.children,(0,Q.jsx)(`input`,{...se.getValidationProps(Re,{onFocus(){if(wt){bt?.focus();return}(Te.current||bt)?.focus()},onChange(e){if(e.nativeEvent.defaultPrevented||Re||g)return;let t=e.currentTarget.value,n=t.toLowerCase(),r=Z(pn,e.nativeEvent),i=()=>Ie.current.findIndex(e=>Hm(e,A).toLowerCase()===n||G(e).toLowerCase()===n);function a(){if(Be)return;if(d===`none`){Rt(t,r);return}let e=i();e===-1&&(e=Ie.current.findIndex((e,t)=>{let r=Ce.current[t];return r!=null&&r.toLowerCase()===n}));let a=e===-1?void 0:Ie.current[e];a!=null&&Vt?.(a,r)}Ve&&(Ft(),fe&&i()===-1&&Y.set(`forceMounted`,!0)),queueMicrotask(a)}}),id:le&&yn==null?`${le}-hidden-input`:void 0,form:m,name:yn,autoComplete:R,disabled:Re,required:_&&!_n,readOnly:g,value:gn,ref:mn,style:yn?$n:Qn,tabIndex:-1,"aria-hidden":!0,suppressHydrationWarning:!0}),Cn]});return(0,Q.jsx)(gm.Provider,{value:Y,children:(0,Q.jsx)(_m.Provider,{value:$t,children:(0,Q.jsx)(ym.Provider,{value:Ue,children:(0,Q.jsx)(vm.Provider,{value:hn,children:(0,Q.jsx)(bm.Provider,{value:J,children:wn})})})})})}function gh(e){let{multiple:t=!1,defaultValue:n,value:r,onValueChange:i,autoComplete:a,...o}=e;return(0,Q.jsx)(hh,{...o,selectionMode:t?`multiple`:`single`,selectedValue:r,defaultSelectedValue:n,onSelectedValueChange:i,formAutoComplete:a})}function _h(e,t){return e??t}var vh=`data-popup-side`,yh=`data-list-empty`,bh={...Yt,...Ym,popupSide:e=>e?{[vh]:e}:null,listEmpty:e=>e?{[yh]:``}:null},xh=l.createContext(void 0);function Sh(){return l.useContext(xh)}var Ch=l.createContext(void 0);function wh(e){let t=l.useContext(Ch);if(t===void 0&&!e)throw Error(Ai(21));return t}var Th=l.forwardRef(function(e,t){let n=xm(),{buttonRef:r,getButtonProps:i}=Nc({native:!1}),a=Rn(t,r);function o(e){n.context.setOpen(!1,Z(yn,e.nativeEvent,e.currentTarget))}let s=i({onClick:o});return(0,Q.jsx)(`span`,{ref:a,...s,"aria-label":`Dismiss`,tabIndex:void 0,style:$n})});function Eh(e){let t=e.useState(`mounted`),n=e.useState(`popupSide`),r=e.useState(`positionerElement`);return t&&r?n:null}function Dh(){return Cm().filteredItems.length===0}function Oh(e){return e===`rtl`?[`ArrowRight`,`ArrowLeft`]:[`ArrowLeft`,`ArrowRight`]}function kh(e,t){let n=e>=t-1?t-2:e;return n>=0?n:void 0}function Ah(e,t,n){let r=e.context.listRef.current[t];r&&(e.context.selectionEventRef.current=n,r.click(),e.context.selectionEventRef.current=null)}var jh=l.forwardRef(function(e,t){let{render:n,className:r,disabled:i=!1,id:a,style:o,...s}=e,{state:c,disabled:u,setTouched:d,setFocused:f,validationMode:p,validation:m}=Qm(),{labelId:h}=rh(),g=Sh(),_=!!wh(!0),v=xm(),y=wm(),b=Ol(),x=v.useState(`required`),S=v.useState(`disabled`),C=v.useState(`readOnly`),w=v.useState(`name`),T=v.useState(`form`),E=v.useState(`selectionMode`),D=v.useState(`autoHighlight`),O=v.useState(`inputProps`),k=v.useState(`triggerProps`),A=v.useState(`open`),j=v.useState(`mounted`),M=v.useState(`selectedValue`),N=v.useState(`id`),P=v.useState(`inline`),F=v.useState(`modal`),I=!!D,L=Eh(v),R=u||S||i,z=Dh(),ee=_||P,B=!ee||F,te=Lc(a??(ee?void 0:N)),ne=_?qm:c,[re,V]=l.useState(null),H=l.useRef(!1),ie=l.useRef(null),ae=l.useRef(!1),oe=E===`none`&&!_,se=$(e=>{let t=_||v.state.inline;t&&!v.state.hasInputValue&&v.context.setInputValue(``,Z(pn)),v.update({inputElement:e,inputInsidePopup:t,inputOwnsFormValue:oe})}),ce=_?s:m.getValidationProps(R,s);function le(){v.context.setIndices({activeIndex:null,selectedIndex:null,type:v.context.keyboardActiveRef.current?En:Dn})}function ue(){v.context.keyboardActiveRef.current=!1}let de={...ne,open:A,disabled:R,readOnly:C,popupSide:L,listEmpty:z};function fe(e){if(!g)return;let t,{highlightedChipIndex:n}=g,r=g.chipsRef.current.length,[i,a]=Oh(b);return n===void 0?(e.key===i&&(e.currentTarget.selectionStart??0)===0&&M.length>0&&(e.preventDefault(),t=r>0?r-1:void 0),t):(e.key===i?(e.preventDefault(),t=n>0?n-1:void 0):e.key===a?(e.preventDefault(),t=n<r-1?n+1:void 0):(e.key===`Backspace`||e.key===`Delete`)&&(e.preventDefault(),t=kh(n,M.length),le()),t)}let U=$i(`input`,e,{state:de,ref:[t,v.context.inputRef,se],props:[O,k,{value:re??y,"aria-readonly":C||void 0,"aria-required":x||void 0,"aria-labelledby":h,disabled:R,readOnly:C,required:E===`none`?x:void 0,form:T,...oe&&w&&{name:w},id:te,onFocus(){if(f(!0),!P||!ae.current)return;ae.current=!1;let e=ie.current;e!=null&&Object.hasOwn(v.context.valuesRef.current,e)&&v.context.setIndices({activeIndex:e})},onBlur(){d(!0),f(!1);let e=v.state.activeIndex;if(P&&e!==null&&D!==`always`&&(ie.current=e,ae.current=!0,v.context.setIndices({activeIndex:null})),p===`onBlur`){let e=E===`none`?y:M;m.commit(e)}},onCompositionStart(e){Ue||(H.current=!0,V(e.currentTarget.value))},onCompositionEnd(e){H.current=!1;let t=e.currentTarget.value;V(null),v.context.setInputValue(t,Z(bn,e.nativeEvent))},onChange(e){let t=e.nativeEvent,n=t.inputType,r=!n||n===`insertReplacementText`,i=H.current||!r;function a(e){!C&&!R&&e&&i&&(v.context.setOpen(!0,Z(bn,t)),I||le())}if(H.current){let n=e.currentTarget.value;V(n),n===``&&!v.state.openOnInputClick&&!v.state.inputInsidePopup&&v.context.setOpen(!1,Z(xn,t));let r=n.trim(),i=I&&r!==``;a(r),A&&v.state.activeIndex!==null&&!i&&le();return}let o=Z(bn,t);if(v.context.setInputValue(e.currentTarget.value,o),o.isCanceled)return;let s=e.currentTarget.value===``,c=Z(xn,t);s&&!v.state.inputInsidePopup&&(E===`single`&&v.context.setSelectedValue(null,c),v.state.openOnInputClick||v.context.setOpen(!1,c)),a(e.currentTarget.value.trim()),A&&v.state.activeIndex!==null&&!I&&le()},onKeyDown(e){if(e.ctrlKey||e.shiftKey||e.altKey||e.metaKey)return;if(v.context.keyboardActiveRef.current=!0,R||C){C&&e.key===`Enter`&&A&&v.state.activeIndex!==null&&yt(e);return}let t=e.currentTarget,n=t.scrollWidth-t.clientWidth,r=b===`rtl`;if(e.key===`Home`){yt(e);let n=qe&&r?t.value.length:0;t.setSelectionRange(n,n),t.scrollLeft=0;return}if(e.key===`End`){yt(e);let i=qe&&r?0:t.value.length;t.setSelectionRange(i,i),t.scrollLeft=r?-n:n;return}if(!j&&e.key===`Escape`){let t=E===`multiple`&&Array.isArray(M)?M.length===0:M===null,n=Z(wn,e.nativeEvent),r=E===`multiple`?[]:null;v.context.setInputValue(``,n),v.context.setSelectedValue(r,n),!t&&!v.state.inline&&!n.isPropagationAllowed&&e.stopPropagation();return}if(g&&e.key===`Backspace`&&t.value===``&&g.highlightedChipIndex===void 0&&Array.isArray(M)&&M.length>0){let t=g.chipsRef.current.length,n=t>0?t-1:M.length-1,r=M.filter((e,t)=>t!==n);le(),v.context.setSelectedValue(r,Z(pn,e.nativeEvent));return}let i=g?.highlightedChipIndex!==void 0,a=fe(e);if(g?.setHighlightedChipIndex(a),a===void 0?i&&v.context.inputRef.current?.focus():g?.chipsRef.current[a]?.focus(),e.which!==229&&e.key===`Enter`&&A){let t=v.state.activeIndex,n=e.nativeEvent;if(t===null){if(P)return;v.context.setOpen(!1,Z(pn,n));return}yt(e),Ah(v,t,n)}},onPointerMove:ue,onPointerDown:ue},ce],stateAttributesMapping:bh}),pe=_?(0,Q.jsx)(Zm.Provider,{value:Xm,children:U}):U;return(0,Q.jsxs)(l.Fragment,{children:[A&&B&&(0,Q.jsx)(Th,{ref:v.context.startDismissRef}),pe]})}),Mh=5;function Nh(e,t){let n=Ph(t);return e.clientX>=n.left-Mh&&e.clientX<=n.right+Mh&&e.clientY>=n.top-Mh&&e.clientY<=n.bottom+Mh}function Ph(e){let t=e.getBoundingClientRect(),n=me(e);if(Ye)return t;let r=n.getComputedStyle(e,`::before`),i=n.getComputedStyle(e,`::after`);if(r.content===`none`&&i.content===`none`)return t;let a=parseFloat(r.width)||0,o=parseFloat(r.height)||0,s=parseFloat(i.width)||0,c=parseFloat(i.height)||0,l=Math.max(t.width,a,s),u=Math.max(t.height,o,c),d=l-t.width,f=u-t.height;return{left:t.left-d/2,right:t.right+d/2,top:t.top-f/2,bottom:t.bottom+f/2}}var Fh=l.forwardRef(function(e,t){let{render:n,className:r,nativeButton:i=!0,disabled:a=!1,id:o,style:s,...c}=e,{state:u,disabled:d,setTouched:f,setFocused:p,validationMode:m,validation:h}=Qm(),{labelId:g}=rh(),_=xm(),v=_.useState(`selectionMode`),y=_.useState(`disabled`),b=_.useState(`readOnly`),x=_.useState(`required`),S=_.useState(`positionerElement`),C=_.useState(`listElement`),w=_.useState(`popupId`),T=_.useState(`triggerProps`),E=_.useState(`inputInsidePopup`),D=_.useState(`id`),O=_.useState(`labelId`),k=_.useState(`open`),A=_.useState(`selectedValue`),j=_.useState(`activeIndex`),M=_.useState(`selectedIndex`),N=_.useState(`hasSelectedValue`),P=Sm(),F=wm(),I=it(),L=d||y||a,R=Dh(),z=Eh(_);ih({id:E?o:void 0});let ee=E?o??D:o,B=_h(g,O),te;k&&E?te=w??ah(D):k&&(te=C?.id);let ne=l.useRef(``);function re(e){ne.current=e.pointerType}let{reference:V}=uc(P,{enabled:!k&&!b&&!y&&v===`single`,listRef:_.context.labelsRef,activeIndex:j,selectedIndex:M,onMatch(e){let t=_.context.valuesRef.current[e];t!==void 0&&_.context.setSelectedValue(t,Z(pn))}}),{reference:H}=Fa(P,{enabled:!y,event:`mousedown`}),{buttonRef:ie,getButtonProps:ae}=Nc({native:i,disabled:L}),oe={...u,readOnly:b,open:k,disabled:L,popupSide:z,listEmpty:R,placeholder:v!==`none`&&!N};return $i(`button`,e,{ref:[t,ie,$(e=>{_.set(`triggerElement`,e)})],state:oe,props:[T,H,V,{id:ee,tabIndex:E?0:-1,role:E?`combobox`:void 0,"aria-expanded":k,"aria-haspopup":E?`dialog`:`listbox`,"aria-controls":te,"aria-required":E&&x||void 0,"aria-readonly":E&&b||void 0,"aria-labelledby":B,onPointerDown:re,onPointerEnter:re,onFocus(){p(!0),!L&&I.start(0,_.context.forceMount)},onBlur(e){if(!X(S,e.relatedTarget)&&(f(!0),p(!1),m===`onBlur`)){let e=v===`none`?F:A;h.commit(e)}},onMouseDown(e){if(L||(E||P.set(`domReferenceElement`,e.currentTarget),_.context.forceMount(),ne.current!==`touch`&&(_.context.inputRef.current?.focus(),E||e.preventDefault()),k))return;let t=J(e.currentTarget);function n(e){let t=_.state.triggerElement;if(!t)return;let n=Et(e),r=_.state.positionerElement,i=_.state.listElement;X(t,n)||X(r,n)||X(i,n)||Nh(e,t)||_.context.setOpen(!1,Z(On,e))}E&&t.addEventListener(`mouseup`,n,{once:!0})},onKeyDown(e){(e.key===`ArrowDown`||e.key===`ArrowUp`)&&(yt(e),_.context.setOpen(!0,Z(Tn,e.nativeEvent)),_.context.inputRef.current?.focus())}},h.getValidationProps(L,c),ae],stateAttributesMapping:bh})}),Ih=l.createContext(null);function Lh(){return l.useContext(Ih)}function Rh(e){let{children:t}=e,{filteredItems:n}=Cm(),r=Lh(),i=r?r.items:n;return(0,Q.jsx)(l.Fragment,{children:i.map(t)})}var zh=l.createContext({register:()=>{},unregister:()=>{},subscribeMapChange:()=>()=>{},nextIndexRef:{current:0}});function Bh(){return l.useContext(zh)}function Vh(e){let{children:t,elementsRef:n,labelsRef:r,onMapChange:i}=e,a=$(i),[,o]=l.useState(!1),s=Ze(Uh).current,c=Ze(Hh).current,u=l.useRef(0),d=l.useRef(!0),f=l.useRef(null),p=l.useRef(null),m=$(()=>{d.current||(d.current=!0,o(e=>!e))}),h=$((e,t)=>{c.set(e,t),m()}),g=$(e=>{c.delete(e),m()}),_=$(e=>{let t=new Map;return n.current.length=0,r&&(r.current.length=0),e.forEach(e=>{t.set(e.element,{...e.registration.metadata??{},index:e.index}),n.current[e.index]=e.element,r&&(r.current[e.index]=e.registration.label===void 0?e.registration.textRef?.current?.textContent??e.element.textContent:e.registration.label)}),u.current=n.current.length,t});function v(e){if(p.current?.disconnect(),p.current=null,typeof MutationObserver!=`function`||e.length<2)return;let t=new MutationObserver(n=>{if(!Kh(n))return;let r=null;for(let n of e)if(n.isConnected){if(r&&qh(r,n)>0){t.disconnect(),m();return}r=n}});p.current=t;let n=new Set;for(let t=1;t<e.length;t+=1){let r=Gh(e[t-1],e[t]);r&&n.add(r)}n.forEach(e=>t.observe(e,{childList:!0}))}let y=$(()=>{let[e,t]=Wh(c),n=_(e),r=f.current,i=!r||r.length!==e.length||e.some((e,t)=>{let n=r[t];return e.index!==n.index||e.element!==n.element||e.registration.index!==n.registration.index||e.registration.metadata!==n.registration.metadata});v(t),f.current=e,d.current=!1,i&&(s.forEach(e=>e(n)),a(n))});U(()=>(!d.current&&f.current&&_(f.current),()=>{n.current=[],r&&(r.current=[])}),[n,r,_]),U(()=>{d.current&&y()}),U(()=>()=>{p.current?.disconnect(),d.current=!0},[]);let b=$(e=>(s.add(e),()=>{s.delete(e)})),x=l.useMemo(()=>({register:h,unregister:g,subscribeMapChange:b,nextIndexRef:u}),[h,g,b,u]);return(0,Q.jsx)(zh.Provider,{value:x,children:t})}function Hh(){return new Map}function Uh(){return new Set}function Wh(e){let t=new Set,n=[],r=[];e.forEach((e,i)=>{if(!i.isConnected)return;let a=e.index,o={index:a??-1,element:i,registration:e};a===null?r.push(o):a>=0&&(t.add(a),n.push(o))});let i=0;return r.sort((e,t)=>qh(e.element,t.element)),r.forEach(e=>{for(;t.has(i);)i+=1;e.index=i,n.push(e),i+=1}),t.size>0&&n.sort((e,t)=>e.index-t.index),[n,r.map(e=>e.element)]}function Gh(e,t){let n=e.parentElement;for(;n&&!n.contains(t);)n=n.parentElement;return n}function Kh(e){for(let t of e)for(let e=0;e<t.removedNodes.length;e+=1)if(t.removedNodes[e].isConnected)return!0;return!1}function qh(e,t){return e.compareDocumentPosition(t)&Node.DOCUMENT_POSITION_FOLLOWING?-1:1}var Jh=l.forwardRef(function(e,t){var n;let{render:r,className:i,style:a,children:o,...s}=e,c=xm(),u=Sm(),d=!!wh(!0),{filteredItems:f,hasItems:p}=Cm(),m=c.useState(`selectionMode`),h=c.useState(`grid`),g=c.useState(`readOnly`),_=c.useState(`listProps`),v=c.useState(`virtualized`),y=c.useState(`forceMounted`),b=m===`multiple`,x=f.length===0,S=$(e=>{c.set(`positionerElement`,e)}),C=$(e=>{c.set(`listElement`,e)}),w=l.useMemo(()=>typeof o==`function`?n||=(0,Q.jsx)(Rh,{children:o}):o,[o]),T={empty:x},E=u.useState(`floatingId`),D=$i(`div`,e,{state:T,ref:[t,C,d?null:S],props:[_,{children:w,tabIndex:-1,id:E,role:h?`grid`:`listbox`,"aria-multiselectable":b?`true`:void 0,"aria-readonly":!h&&g?!0:void 0,onKeyDown(e){if(!(c.state.disabled||c.state.readOnly)&&e.key===`Enter`){let t=c.state.activeIndex;if(t==null)return;yt(e),Ah(c,t,e.nativeEvent)}},onKeyDownCapture(){c.context.keyboardActiveRef.current=!0},onPointerMoveCapture(){c.context.keyboardActiveRef.current=!1}},s]});if(v)return D;let O=p&&!y?void 0:c.context.labelsRef;return(0,Q.jsx)(Vh,{elementsRef:c.context.listRef,labelsRef:O,children:D})}),Yh=`⁠`;function Xh(e){let t=e.ownerDocument.createTreeWalker(e,NodeFilter.SHOW_TEXT),n=null;for(;t.nextNode();){let e=t.currentNode;e.nodeValue!==``&&(n=e)}return n}function Zh(){let e=it(),t=l.useRef(null);return l.useEffect(()=>{if(Ve)return;let n=t.current;if(n==null)return;let r=Xh(n);if(r==null)return;let i=r.data,a=`${i}${Yh}`;return r.nodeValue=a,e.start(200,()=>{r.nodeValue===a&&(r.nodeValue=i)}),()=>{e.clear(),r.nodeValue===a&&(r.nodeValue=i)}},[t,e]),t}var Qh=l.createContext(void 0);function $h(){let e=l.useContext(Qh);if(e===void 0)throw Error(Ai(20));return e}var eg=l.forwardRef(function(e,t){let{keepMounted:n=!1,...r}=e,i=xm(),a=i.useState(`mounted`),o=i.useState(`forceMounted`);return a||n||o?(0,Q.jsx)(Qh.Provider,{value:n,children:(0,Q.jsx)(ha,{ref:t,...r})}):null}),tg=20;function ng(e,t,n,r){let[i,a]=l.useState(!1);U(()=>{if(!e||!t||n==null){a(!1);return}let r=J(n).documentElement.clientWidth,i=n.offsetWidth;a(r>0&&i>0&&i>=r-tg)},[e,t,n]),vt(e&&(!t||i),r)}var rg=l.forwardRef(function(e,t){let{render:n,className:r,anchor:i,positionMethod:a,side:o,align:s,sideOffset:c,alignOffset:l,collisionBoundary:u=`clipping-ancestors`,collisionPadding:d,arrowPadding:f,sticky:p,disableAnchorTracking:m=!1,collisionAvoidance:h=sa,style:g,..._}=e,v=xm(),y=Sm(),b=$h(),x=v.useState(`modal`),S=v.useState(`open`),C=v.useState(`mounted`),w=v.useState(`openMethod`),T=v.useState(`positionerElement`),E=v.useState(`triggerElement`),D=v.useState(`inputElement`),O=v.useState(`inputGroupElement`),k=v.useState(`inputInsidePopup`),A=v.useState(`transitionStatus`),j=Dh(),M=Hl({anchor:i??(k?E:O??D),floatingRootContext:y,positionMethod:a,mounted:C,side:o,sideOffset:c,align:s,alignOffset:l,arrowPadding:f,collisionBoundary:u,collisionPadding:d,sticky:p,disableAnchorTracking:m,keepMounted:b,collisionAvoidance:h,lazyFlip:!0});ng(S&&x,w===`touch`,T,E);let N={open:S,side:M.side,align:M.align,anchorHidden:M.anchorHidden,empty:j};U(()=>{v.set(`popupSide`,M.side)},[v,M.side]);let P=$(e=>{v.set(`positionerElement`,e)}),F=Kl(e,N,{styles:M.positionerStyles,transitionStatus:A,props:_,refs:[t,P],hidden:!C,inert:!S});return(0,Q.jsxs)(Ch.Provider,{value:M,children:[C&&x&&(0,Q.jsx)(qc,{inert:Kc(!S),cutout:O??D??E}),F]})}),ig={...Xt,...Lt},ag=l.forwardRef(function(e,t){let{render:n,className:r,style:i,initialFocus:a,finalFocus:o,...s}=e,c=xm(),u=wh(),d=Sm(),f=c.useState(`mounted`),p=c.useState(`open`),m=c.useState(`openMethod`),h=c.useState(`popupProps`),g=c.useState(`transitionStatus`),_=c.useState(`inputInsidePopup`),v=c.useState(`inputElement`),y=c.useState(`modal`),b=c.useState(`id`),x=Dh(),S=s.id??(_?ah(b):void 0);U(()=>(c.set(`popupId`,c.context.popupRef.current?.id||S),()=>{c.set(`popupId`,void 0)}),[c,S]),ys({open:p,ref:c.context.popupRef,onComplete(){p&&c.context.onOpenChangeComplete(!0)}});let C=$i(`div`,e,{state:{open:p,side:u.side,align:u.align,anchorHidden:u.anchorHidden,transitionStatus:g,empty:x},ref:[t,c.context.popupRef],props:[h,{id:S,role:_?`dialog`:`presentation`,onFocus(e){let t=Et(e.nativeEvent);m!==`touch`&&(X(c.state.listElement,t)||t===e.currentTarget)&&c.context.inputRef.current?.focus()}},Gl(g),s],stateAttributesMapping:ig}),w=a===void 0?_?e=>e===`touch`?c.context.popupRef.current:v:!1:a,T;T=o??(_?void 0:!1);let E=!_||y;return(0,Q.jsx)(Pa,{context:d,disabled:!f,modal:E,openInteractionType:m,initialFocus:w,returnFocus:T,getInsideElements:()=>[c.context.startDismissRef.current,c.context.endDismissRef.current],children:(0,Q.jsxs)(l.Fragment,{children:[C,E&&(0,Q.jsx)(Th,{ref:c.context.endDismissRef})]})})});function og(e={}){let{guess:t,label:n,metadata:r,textRef:i,index:a}=e,{register:o,unregister:s,subscribeMapChange:c,nextIndexRef:u}=Bh(),d=l.useRef(-1),[f,p]=l.useState(a==null&&t?()=>{if(d.current===-1){let e=u.current;u.current+=1,d.current=e}return d.current}:-1),m=a??f,h=l.useRef(null),g=l.useCallback(e=>{let t=h.current;t&&s(t),h.current=e,e&&o(e,{metadata:r??null,index:a??null,label:n,textRef:i})},[a,o,s,r,n,i]);return U(()=>{if(a==null)return c(e=>{let t=h.current?e.get(h.current)?.index:null;t!=null&&p(t)})},[a,c]),{ref:g,index:m}}var sg=l.createContext(void 0);function cg(){let e=l.useContext(sg);if(!e)throw Error(Ai(19));return e}var lg=l.createContext(!1);function ug(){return l.useContext(lg)}function dg(e){let{componentProps:t,forwardedRef:n,virtualized:r,indexFromFilter:i}=e,{render:a,className:o,style:s,value:c=null,index:u,disabled:d=!1,nativeButton:f=!1,...p}=t,m=l.useRef(null),h=og({guess:!0,index:u,textRef:m}),g=xm(),_=ug(),v=Tm(),y=g.useState(`selectionMode`),b=g.useState(`disabled`),x=g.useState(`readOnly`),S=g.useState(`isItemEqualToValue`),C=b||d,w=y!==`none`,T=u??i??h.index,E=T!==-1,D=g.useState(`id`),O=g.useState(`isActive`,T),k=g.useState(`isSelected`,c),A=g.useState(`itemProps`),j=l.useRef(null),M=D!=null&&E?`${D}-${T}`:void 0,N=k&&w;U(()=>{if(!E||!r&&u==null)return;let e=g.context.listRef.current;return e[T]=j.current,()=>{delete e[T]}},[E,r,T,u,g]),U(()=>{if(!E||v)return;let e=g.context.valuesRef.current;return e[T]=c,()=>{delete e[T]}},[E,v,T,c,g]),U(()=>{if(!E||v)return;let e=g.state.selectedValue,t=g.state.selectedIndex;g.state.selectionMode===`multiple`&&Array.isArray(e)?t=Pm(T,c,g.context.valuesRef.current,e,S,t):Om(c,e,S)&&(t=T),g.set(`selectedIndex`,t)},[E,v,g,T,c,S]);let{getButtonProps:P,buttonRef:F}=Nc({disabled:C,focusableWhenDisabled:!0,native:f,composite:!0}),I={disabled:C,selected:N,highlighted:O};function L(e){function t(){g.context.handleSelection(e,c)}g.state.submitOnItemClick?(ua.flushSync(t),g.context.requestSubmit()):t()}let R={id:M,role:_?`gridcell`:`option`,"aria-selected":w?N:void 0,tabIndex:void 0,onPointerDownCapture(e){e.isPrimary&&(g.context.pointerDownItemRef.current=e.currentTarget),e.preventDefault()},onMouseDown(e){e.preventDefault()},onClick(e){C||x||L(e.nativeEvent)},onMouseUp(e){let t=g.context.pointerDownItemRef.current===e.currentTarget;g.context.pointerDownItemRef.current=null,!(C||x||e.button!==0||t||!O)&&L(e.nativeEvent)}},z=$i(`div`,t,{ref:[F,n,h.ref,j],state:I,props:[A,R,p,P]}),ee=l.useMemo(()=>({selected:N,textRef:m}),[N,m]);return(0,Q.jsx)(sg.Provider,{value:ee,children:z})}function fg(e){let{componentProps:t,forwardedRef:n}=e,r=xm().useState(`isItemEqualToValue`),{flatFilteredValues:i}=Cm(),a=jm(i,t.value??null,r);return(0,Q.jsx)(dg,{componentProps:t,forwardedRef:n,virtualized:!0,indexFromFilter:a})}var pg=l.memo(l.forwardRef(function(e,t){let n=xm().useState(`virtualized`);return n&&e.index==null?(0,Q.jsx)(fg,{componentProps:e,forwardedRef:t}):(0,Q.jsx)(dg,{componentProps:e,forwardedRef:t,virtualized:n,indexFromFilter:void 0})})),mg=l.forwardRef(function(e,t){let{selected:n}=cg();return e.keepMounted||n?(0,Q.jsx)(hg,{...e,ref:t}):null}),hg=l.memo(l.forwardRef((e,t)=>{let{render:n,className:r,style:i,keepMounted:a,...o}=e,{selected:s}=cg(),c=l.useRef(null),{transitionStatus:u,setMounted:d}=hs(s),f=$i(`span`,e,{ref:[t,c],state:{selected:s,transitionStatus:u},props:[{"aria-hidden":!0,children:`✔️`},o],stateAttributesMapping:Lt});return ys({batch:!0,enabled:!s,open:s,ref:c,onComplete(){s||d(!1)}}),f})),gg=l.forwardRef(function(e,t){let{render:n,className:r,style:i,children:a,...o}=e,{filteredItems:s}=Cm(),c=xm(),l=Zh(),u=s.length===0?a:null;return $i(`div`,e,{ref:[t,c.context.emptyRef,l],props:[{children:u,role:`status`,"aria-live":`polite`,"aria-atomic":!0},o]})});function _g({label:e,value:t,options:n,onChange:r,icon:i,allowCustom:a=!1,action:o}){let[s,c]=(0,l.useState)(``),u=n.find(e=>e.value===t)??{value:t,label:t},d=s.trim(),f=n.filter(e=>e.label.toLowerCase().includes(d.toLowerCase())),p=a&&d&&!n.some(e=>e.value===d)?{value:d,label:`Use “${d}”`}:null;return(0,Q.jsxs)(gh,{items:p?[...f,p]:f,value:u,filter:null,inputValue:s,onInputValueChange:c,onOpenChange:()=>c(``),itemToStringLabel:e=>e.label,isItemEqualToValue:(e,t)=>e.value===t.value,onValueChange:e=>{e&&!e.disabled&&r(e.value)},children:[(0,Q.jsx)(Yl,{label:`${e}: ${u.label}`,children:(0,Q.jsxs)(Fh,{className:`composer-select`,"aria-label":`${e}: ${u.label}`,children:[(0,Q.jsx)(`span`,{className:`composer-select-icon`,"aria-hidden":`true`,children:u.icon??i}),(0,Q.jsx)(`span`,{className:`composer-select-label`,children:u.shortLabel??(u.label||e)}),(0,Q.jsx)(b,{className:`composer-select-caret`,size:11,"aria-hidden":`true`})]})}),(0,Q.jsx)(eg,{children:(0,Q.jsx)(rg,{className:`composer-select-positioner`,sideOffset:6,align:`start`,collisionPadding:12,children:(0,Q.jsxs)(ag,{className:`composer-select-popup`,"aria-label":`${e} options`,children:[(0,Q.jsxs)(`div`,{className:`composer-select-search`,children:[(0,Q.jsx)(H,{size:14,"aria-hidden":`true`}),(0,Q.jsx)(jh,{"aria-label":`Search ${e.toLowerCase()}`,placeholder:`Search ${e.toLowerCase()}…`,maxLength:a?120:void 0})]}),(0,Q.jsx)(gg,{className:`composer-select-empty`,children:`No matches`}),(0,Q.jsx)(Jh,{className:`composer-select-list`,children:e=>(0,Q.jsxs)(pg,{value:e,disabled:e.disabled,className:`composer-select-option`,children:[e.icon&&(0,Q.jsx)(`span`,{className:`composer-select-option-icon`,"aria-hidden":`true`,children:e.icon}),(0,Q.jsx)(`span`,{className:`composer-select-option-label`,children:e.label}),(0,Q.jsx)(mg,{className:`composer-select-check`,children:(0,Q.jsx)(y,{size:14})})]},e.value)}),o&&(0,Q.jsxs)(`button`,{type:`button`,className:`composer-select-action`,onClick:o.onClick,children:[o.icon,(0,Q.jsx)(`span`,{children:o.label})]})]})})})]})}var vg={claude:(0,Q.jsx)(`svg`,{viewBox:`0 0 256 257`,fill:`#D97757`,children:(0,Q.jsx)(`path`,{d:`m50.228 170.321 50.357-28.257.843-2.463-.843-1.361h-2.462l-8.426-.518-28.775-.778-24.952-1.037-24.175-1.296-6.092-1.297L0 125.796l.583-3.759 5.12-3.434 7.324.648 16.202 1.101 24.304 1.685 17.629 1.037 26.118 2.722h4.148l.583-1.685-1.426-1.037-1.101-1.037-25.147-17.045-27.22-18.017-14.258-10.37-7.713-5.25-3.888-4.925-1.685-10.758 7-7.713 9.397.649 2.398.648 9.527 7.323 20.35 15.75L94.817 91.9l3.889 3.24 1.555-1.102.195-.777-1.75-2.917-14.453-26.118-15.425-26.572-6.87-11.018-1.814-6.61c-.648-2.723-1.102-4.991-1.102-7.778l7.972-10.823L71.42 0 82.05 1.426l4.472 3.888 6.61 15.101 10.694 23.786 16.591 32.34 4.861 9.592 2.592 8.879.973 2.722h1.685v-1.556l1.36-18.211 2.528-22.36 2.463-28.776.843-8.1 4.018-9.722 7.971-5.25 6.222 2.981 5.12 7.324-.713 4.73-3.046 19.768-5.962 30.98-3.889 20.739h2.268l2.593-2.593 10.499-13.934 17.628-22.036 7.778-8.749 9.073-9.657 5.833-4.601h11.018l8.1 12.055-3.628 12.443-11.342 14.388-9.398 12.184-13.48 18.147-8.426 14.518.778 1.166 2.01-.194 30.46-6.481 16.462-2.982 19.637-3.37 8.88 4.148.971 4.213-3.5 8.62-20.998 5.184-24.628 4.926-36.682 8.685-.454.324.519.648 16.526 1.555 7.065.389h17.304l32.21 2.398 8.426 5.574 5.055 6.805-.843 5.184-12.962 6.611-17.498-4.148-40.83-9.721-14-3.5h-1.944v1.167l11.666 11.406 21.387 19.314 26.767 24.887 1.36 6.157-3.434 4.86-3.63-.518-23.526-17.693-9.073-7.972-20.545-17.304h-1.36v1.814l4.73 6.935 25.017 37.59 1.296 11.536-1.814 3.76-6.481 2.268-7.13-1.297-14.647-20.544-15.1-23.138-12.185-20.739-1.49.843-7.194 77.448-3.37 3.953-7.778 2.981-6.48-4.925-3.436-7.972 3.435-15.749 4.148-20.544 3.37-16.333 3.046-20.285 1.815-6.74-.13-.454-1.49.194-15.295 20.999-23.267 31.433-18.406 19.702-4.407 1.75-7.648-3.954.713-7.064 4.277-6.286 25.47-32.405 15.36-20.092 9.917-11.6-.065-1.686h-.583L44.07 198.125l-12.055 1.555-5.185-4.86.648-7.972 2.463-2.593 20.35-13.999-.064.065Z`})}),codex:(0,Q.jsx)(`svg`,{viewBox:`0 0 24 24`,fill:`currentColor`,fillRule:`evenodd`,children:(0,Q.jsx)(`path`,{d:`M8.086.457a6.105 6.105 0 013.046-.415c1.333.153 2.521.72 3.564 1.7a.117.117 0 00.107.029c1.408-.346 2.762-.224 4.061.366l.063.03.154.076c1.357.703 2.33 1.77 2.918 3.198.278.679.418 1.388.421 2.126a5.655 5.655 0 01-.18 1.631.167.167 0 00.04.155 5.982 5.982 0 011.578 2.891c.385 1.901-.01 3.615-1.183 5.14l-.182.22a6.063 6.063 0 01-2.934 1.851.162.162 0 00-.108.102c-.255.736-.511 1.364-.987 1.992-1.199 1.582-2.962 2.462-4.948 2.451-1.583-.008-2.986-.587-4.21-1.736a.145.145 0 00-.14-.032c-.518.167-1.04.191-1.604.185a5.924 5.924 0 01-2.595-.622 6.058 6.058 0 01-2.146-1.781c-.203-.269-.404-.522-.551-.821a7.74 7.74 0 01-.495-1.283 6.11 6.11 0 01-.017-3.064.166.166 0 00.008-.074.115.115 0 00-.037-.064 5.958 5.958 0 01-1.38-2.202 5.196 5.196 0 01-.333-1.589 6.915 6.915 0 01.188-2.132c.45-1.484 1.309-2.648 2.577-3.493.282-.188.55-.334.802-.438.286-.12.573-.22.861-.304a.129.129 0 00.087-.087A6.016 6.016 0 015.635 2.31C6.315 1.464 7.132.846 8.086.457zm-.804 7.85a.848.848 0 00-1.473.842l1.694 2.965-1.688 2.848a.849.849 0 001.46.864l1.94-3.272a.849.849 0 00.007-.854l-1.94-3.393zm5.446 6.24a.849.849 0 000 1.695h4.848a.849.849 0 000-1.696h-4.848z`})}),opencode:(0,Q.jsxs)(`svg`,{viewBox:`96 96 320 320`,fill:`currentColor`,fillRule:`evenodd`,children:[(0,Q.jsx)(`path`,{d:`M320 224V352H192V224H320Z`,opacity:`.4`}),(0,Q.jsx)(`path`,{d:`M384 416H128V96H384V416ZM320 160H192V352H320V160Z`})]}),pi:(0,Q.jsx)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.4`,strokeLinecap:`round`,children:(0,Q.jsx)(`path`,{d:`M4 7h16M9 7v11M15 7v9.5a1.5 1.5 0 0 0 1.5 1.5H18`})})};function yg({harness:e,size:t=14}){return(0,Q.jsx)(`span`,{className:`harness-icon`,style:{width:t,height:t},"aria-hidden":`true`,children:vg[e]??(0,Q.jsx)(`span`,{className:`harness-icon-letter`,children:e.charAt(0).toUpperCase()})})}var bg={macos:`M12.152 6.896c-.948 0-2.415-1.078-3.96-1.04-2.04.027-3.91 1.183-4.961 3.014-2.117 3.675-.546 9.103 1.519 12.09 1.013 1.454 2.208 3.09 3.792 3.039 1.52-.065 2.09-.987 3.935-.987 1.831 0 2.35.987 3.96.948 1.637-.026 2.676-1.48 3.676-2.948 1.156-1.688 1.636-3.325 1.662-3.415-.039-.013-3.182-1.221-3.22-4.857-.026-3.04 2.48-4.494 2.597-4.559-1.429-2.09-3.623-2.324-4.39-2.376-2-.156-3.675 1.09-4.61 1.09zM15.53 3.83c.843-1.012 1.4-2.427 1.245-3.83-1.207.052-2.662.805-3.532 1.818-.78.896-1.454 2.338-1.273 3.714 1.338.104 2.715-.688 3.559-1.701`,linux:`M12.504 0c-.155 0-.315.008-.48.021-4.226.333-3.105 4.807-3.17 6.298-.076 1.092-.3 1.953-1.05 3.02-.885 1.051-2.127 2.75-2.716 4.521-.278.832-.41 1.684-.287 2.489a.424.424 0 00-.11.135c-.26.268-.45.6-.663.839-.199.199-.485.267-.797.4-.313.136-.658.269-.864.68-.09.189-.136.394-.132.602 0 .199.027.4.055.536.058.399.116.728.04.97-.249.68-.28 1.145-.106 1.484.174.334.535.47.94.601.81.2 1.91.135 2.774.6.926.466 1.866.67 2.616.47.526-.116.97-.464 1.208-.946.587-.003 1.23-.269 2.26-.334.699-.058 1.574.267 2.577.2.025.134.063.198.114.333l.003.003c.391.778 1.113 1.132 1.884 1.071.771-.06 1.592-.536 2.257-1.306.631-.765 1.683-1.084 2.378-1.503.348-.199.629-.469.649-.853.023-.4-.2-.811-.714-1.376v-.097l-.003-.003c-.17-.2-.25-.535-.338-.926-.085-.401-.182-.786-.492-1.046h-.003c-.059-.054-.123-.067-.188-.135a.357.357 0 00-.19-.064c.431-1.278.264-2.55-.173-3.694-.533-1.41-1.465-2.638-2.175-3.483-.796-1.005-1.576-1.957-1.56-3.368.026-2.152.236-6.133-3.544-6.139zm.529 3.405h.013c.213 0 .396.062.584.198.19.135.33.332.438.533.105.259.158.459.166.724 0-.02.006-.04.006-.06v.105a.086.086 0 01-.004-.021l-.004-.024a1.807 1.807 0 01-.15.706.953.953 0 01-.213.335.71.71 0 00-.088-.042c-.104-.045-.198-.064-.284-.133a1.312 1.312 0 00-.22-.066c.05-.06.146-.133.183-.198.053-.128.082-.264.088-.402v-.02a1.21 1.21 0 00-.061-.4c-.045-.134-.101-.2-.183-.333-.084-.066-.167-.132-.267-.132h-.016c-.093 0-.176.03-.262.132a.8.8 0 00-.205.334 1.18 1.18 0 00-.09.4v.019c.002.089.008.179.02.267-.193-.067-.438-.135-.607-.202a1.635 1.635 0 01-.018-.2v-.02a1.772 1.772 0 01.15-.768c.082-.22.232-.406.43-.533a.985.985 0 01.594-.2zm-2.962.059h.036c.142 0 .27.048.399.135.146.129.264.288.344.465.09.199.14.4.153.667v.004c.007.134.006.2-.002.266v.08c-.03.007-.056.018-.083.024-.152.055-.274.135-.393.2.012-.09.013-.18.003-.267v-.015c-.012-.133-.04-.2-.082-.333a.613.613 0 00-.166-.267.248.248 0 00-.183-.064h-.021c-.071.006-.13.04-.186.132a.552.552 0 00-.12.27.944.944 0 00-.023.33v.015c.012.135.037.2.08.334.046.134.098.2.166.268.01.009.02.018.034.024-.07.057-.117.07-.176.136a.304.304 0 01-.131.068 2.62 2.62 0 01-.275-.402 1.772 1.772 0 01-.155-.667 1.759 1.759 0 01.08-.668 1.43 1.43 0 01.283-.535c.128-.133.26-.2.418-.2zm1.37 1.706c.332 0 .733.065 1.216.399.293.2.523.269 1.052.468h.003c.255.136.405.266.478.399v-.131a.571.571 0 01.016.47c-.123.31-.516.643-1.063.842v.002c-.268.135-.501.333-.775.465-.276.135-.588.292-1.012.267a1.139 1.139 0 01-.448-.067 3.566 3.566 0 01-.322-.198c-.195-.135-.363-.332-.612-.465v-.005h-.005c-.4-.246-.616-.512-.686-.71-.07-.268-.005-.47.193-.6.224-.135.38-.271.483-.336.104-.074.143-.102.176-.131h.002v-.003c.169-.202.436-.47.839-.601.139-.036.294-.065.466-.065zm2.8 2.142c.358 1.417 1.196 3.475 1.735 4.473.286.534.855 1.659 1.102 3.024.156-.005.33.018.513.064.646-1.671-.546-3.467-1.089-3.966-.22-.2-.232-.335-.123-.335.59.534 1.365 1.572 1.646 2.757.13.535.16 1.104.021 1.67.067.028.135.06.205.067 1.032.534 1.413.938 1.23 1.537v-.043c-.06-.003-.12 0-.18 0h-.016c.151-.467-.182-.825-1.065-1.224-.915-.4-1.646-.336-1.77.465-.008.043-.013.066-.018.135-.068.023-.139.053-.209.064-.43.268-.662.669-.793 1.187-.13.533-.17 1.156-.205 1.869v.003c-.02.334-.17.838-.319 1.35-1.5 1.072-3.58 1.538-5.348.334a2.645 2.645 0 00-.402-.533 1.45 1.45 0 00-.275-.333c.182 0 .338-.03.465-.067a.615.615 0 00.314-.334c.108-.267 0-.697-.345-1.163-.345-.467-.931-.995-1.788-1.521-.63-.4-.986-.87-1.15-1.396-.165-.534-.143-1.085-.015-1.645.245-1.07.873-2.11 1.274-2.763.107-.065.037.135-.408.974-.396.751-1.14 2.497-.122 3.854a8.123 8.123 0 01.647-2.876c.564-1.278 1.743-3.504 1.836-5.268.048.036.217.135.289.202.218.133.38.333.59.465.21.201.477.335.876.335.039.003.075.006.11.006.412 0 .73-.134.997-.268.29-.134.52-.334.74-.4h.005c.467-.135.835-.402 1.044-.7zm2.185 8.958c.037.6.343 1.245.882 1.377.588.134 1.434-.333 1.791-.765l.211-.01c.315-.007.577.01.847.268l.003.003c.208.199.305.53.391.876.085.4.154.78.409 1.066.486.527.645.906.636 1.14l.003-.007v.018l-.003-.012c-.015.262-.185.396-.498.595-.63.401-1.746.712-2.457 1.57-.618.737-1.37 1.14-2.036 1.191-.664.053-1.237-.2-1.574-.898l-.005-.003c-.21-.4-.12-1.025.056-1.69.176-.668.428-1.344.463-1.897.037-.714.076-1.335.195-1.814.12-.465.308-.797.641-.984l.045-.022zm-10.814.049h.01c.053 0 .105.005.157.014.376.055.706.333 1.023.752l.91 1.664.003.003c.243.533.754 1.064 1.189 1.637.434.598.77 1.131.729 1.57v.006c-.057.744-.48 1.148-1.125 1.294-.645.135-1.52.002-2.395-.464-.968-.536-2.118-.469-2.857-.602-.369-.066-.61-.2-.723-.4-.11-.2-.113-.602.123-1.23v-.004l.002-.003c.117-.334.03-.752-.027-1.118-.055-.401-.083-.71.043-.94.16-.334.396-.4.69-.533.294-.135.64-.202.915-.47h.002v-.002c.256-.268.445-.601.668-.838.19-.201.38-.336.663-.336zm7.159-9.074c-.435.201-.945.535-1.488.535-.542 0-.97-.267-1.28-.466-.154-.134-.28-.268-.373-.335-.164-.134-.144-.333-.074-.333.109.016.129.134.199.2.096.066.215.2.36.333.292.2.68.467 1.167.467.485 0 1.053-.267 1.398-.466.195-.135.445-.334.648-.467.156-.136.149-.267.279-.267.128.016.034.134-.147.332a8.097 8.097 0 01-.69.468zm-1.082-1.583V5.64c-.006-.02.013-.042.029-.05.074-.043.18-.027.26.004.063 0 .16.067.15.135-.006.049-.085.066-.135.066-.055 0-.092-.043-.141-.068-.052-.018-.146-.008-.163-.065zm-.551 0c-.02.058-.113.049-.166.066-.047.025-.086.068-.14.068-.05 0-.13-.02-.136-.068-.01-.066.088-.133.15-.133.08-.031.184-.047.259-.005.019.009.036.03.03.05v.02h.003z`,windows:`M0,0H11.377V11.372H0ZM12.623,0H24V11.372H12.623ZM0,12.623H11.377V24H0Zm12.623,0H24V24H12.623`},xg={macos:`0 2 24 24`,linux:`0 0 24 24`,windows:`0 0 24 24`};function Sg({os:e,size:t=14}){return(0,Q.jsx)(`svg`,{viewBox:xg[e],width:t,height:t,fill:`currentColor`,"aria-hidden":`true`,children:(0,Q.jsx)(`path`,{d:bg[e]})})}function Cg({project:e}){let t=(0,l.useRef)(null),[n,r]=(0,l.useState)(!1),[i,a]=(0,l.useState)(!1);return(0,l.useEffect)(()=>{a(!1),t.current?.complete&&(r(t.current.naturalWidth>0),a(t.current.naturalWidth===0))},[e.iconUrl]),(0,Q.jsxs)(`span`,{className:`thread-project ${n?`has-icon`:``}`,style:{"--project-color":e.color},"aria-hidden":`true`,children:[(0,Q.jsx)(`span`,{className:`thread-project-letter`,children:e.initial}),e.iconUrl&&!i&&(0,Q.jsx)(`img`,{ref:t,src:e.iconUrl,alt:``,decoding:`async`,onLoad:()=>r(!0),onError:()=>a(!0)})]})}function wg({projects:e,projectId:t,onChange:n,onAddProject:r}){return(0,Q.jsx)(_g,{label:`Project`,value:t,onChange:n,icon:(0,Q.jsx)(j,{size:14}),action:r?{label:`Add project`,icon:(0,Q.jsx)(V,{size:14}),onClick:r}:void 0,options:e.map(e=>({value:e.id,label:e.name,icon:(0,Q.jsx)(Cg,{project:e},e.id)}))})}var Tg=e=>e.os?(0,Q.jsx)(Sg,{os:e.os}):e.id===`local`?(0,Q.jsx)(z,{size:14}):(0,Q.jsx)(ie,{size:14});function Eg({machine:e,machines:t,projects:n,projectId:r,harness:i,model:a,onMachineChange:o,onProjectChange:s,onHarnessChange:c,onModelChange:l,onAddProject:u}){let d=e.harnesses.find(e=>e.id===i)?.models??[];return(0,Q.jsxs)(`div`,{className:`composer-selectors`,children:[(0,Q.jsx)(_g,{label:`Machine`,value:e.id,onChange:o,icon:Tg(e),options:t.map(e=>({icon:Tg(e),value:e.id,label:`${e.name}${e.connected?``:` · Not connected`}`,shortLabel:e.name,disabled:!e.connected}))}),(0,Q.jsx)(wg,{projects:n,projectId:r,onChange:s,onAddProject:u},e.id),(0,Q.jsx)(_g,{label:`Harness`,value:i,onChange:c,icon:(0,Q.jsx)(se,{size:14}),options:e.harnesses.map(e=>({value:e.id,label:e.name,shortLabel:e.name===`Claude Code`?`Claude`:e.name,icon:(0,Q.jsx)(yg,{harness:e.id})}))}),(0,Q.jsx)(_g,{label:`Model`,value:a,onChange:l,icon:(0,Q.jsx)(O,{size:14}),allowCustom:e.harnesses.find(e=>e.id===i)?.customModels??!1,options:d.map(e=>({value:e,label:e,shortLabel:e.split(`/`).at(-1)}))},`${e.id}:${i}`)]})}var Dg=l.createContext(void 0),Og=e=>{let t=l.useContext(Dg);if(e)return e;if(!t)throw Error(`No QueryClient set, use QueryClientProvider to set one`);return t},kg=({client:e,children:t})=>(l.useEffect(()=>(e.mount(),()=>{e.unmount()}),[e]),(0,Q.jsx)(Dg.Provider,{value:e,children:t})),Ag={setTimeout:(e,t)=>setTimeout(e,t),clearTimeout:e=>clearTimeout(e),setInterval:(e,t)=>setInterval(e,t),clearInterval:e=>clearInterval(e)},jg=new class{#e=Ag;setTimeoutProvider(e){this.#e=e}setTimeout(e,t){return this.#e.setTimeout(e,t)}clearTimeout(e){this.#e.clearTimeout(e)}setInterval(e,t){return this.#e.setInterval(e,t)}clearInterval(e){this.#e.clearInterval(e)}};function Mg(e){setTimeout(e,0)}var Ng=typeof window>`u`||`Deno`in globalThis;function Pg(){}function Fg(e,t){return typeof e==`function`?e(t):e}function Ig(e){return typeof e==`number`&&e>=0&&e!==1/0}function Lg(e,t){return Math.max(e+(t||0)-Date.now(),0)}function Rg(e,t){return typeof e==`function`?e(t):e}function zg(e,t){let{type:n=`all`,exact:r,fetchStatus:i,predicate:a,queryKey:o,stale:s}=e;if(o){if(r){if(t.queryHash!==Vg(o,t.options))return!1}else if(!Ug(t.queryKey,o))return!1}if(n!==`all`){let e=t.isActive();if(n===`active`&&!e||n===`inactive`&&e)return!1}return!(typeof s==`boolean`&&t.isStale()!==s||i&&i!==t.state.fetchStatus||a&&!a(t))}function Bg(e,t){let{exact:n,status:r,predicate:i,mutationKey:a}=e;if(a){if(!t.options.mutationKey)return!1;if(n){if(Hg(t.options.mutationKey)!==Hg(a))return!1}else if(!Ug(t.options.mutationKey,a))return!1}return!(r&&t.state.status!==r||i&&!i(t))}function Vg(e,t){return(t?.queryKeyHashFn||Hg)(e)}function Hg(e){return JSON.stringify(e,(e,t)=>Jg(t)?Object.keys(t).sort().reduce((e,n)=>(e[n]=t[n],e),{}):t)}function Ug(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(e&&t&&typeof e==`object`&&typeof t==`object`){if(Array.isArray(e)&&Array.isArray(t)){if(t.length>e.length)return!1;for(let n=0;n<t.length;n++)if(!Ug(e[n],t[n]))return!1;return!0}let n=Object.keys(t);for(let r of n)if(!Ug(e[r],t[r]))return!1;return!0}return!1}var Wg=Object.prototype.hasOwnProperty;function Gg(e,t,n=0){if(e===t)return e;if(n>500)return t;let r=qg(e)&&qg(t);if(!r&&!(Jg(e)&&Jg(t)))return t;let i=(r?e:Object.keys(e)).length,a=r?t:Object.keys(t),o=a.length,s=r?Array(o):{},c=0;for(let l=0;l<o;l++){let o=r?l:a[l],u=e[o],d=t[o];if(u===d){s[o]=u,(r?l<i:Wg.call(e,o))&&c++;continue}if(u===null||d===null||typeof u!=`object`||typeof d!=`object`){s[o]=d;continue}let f=Gg(u,d,n+1);s[o]=f,f===u&&c++}return i===o&&c===i?e:s}function Kg(e,t){if(!t||Object.keys(e).length!==Object.keys(t).length)return!1;for(let n in e)if(e[n]!==t[n])return!1;return!0}function qg(e){return Array.isArray(e)&&e.length===Object.keys(e).length}function Jg(e){if(!Yg(e))return!1;let t=Object.getPrototypeOf(e),n=t?.constructor;if(n===void 0)return!0;if(typeof n!=`function`)return!1;let r=n.prototype;return!(!Yg(r)||!r.hasOwnProperty(`isPrototypeOf`)||t!==Object.prototype)}function Yg(e){return Object.prototype.toString.call(e)===`[object Object]`}function Xg(e){return new Promise(t=>{jg.setTimeout(t,e)})}function Zg(e,t,n){return typeof n.structuralSharing==`function`?n.structuralSharing(e,t):n.structuralSharing===!1?t:Gg(e,t)}function Qg(e,t,n=0){let r=[...e,t];return n&&r.length>n?r.slice(1):r}function $g(e,t,n=0){let r=[t,...e];return n&&r.length>n?r.slice(0,-1):r}var e_=Symbol();function t_(e,t){return!e.queryFn&&t?.initialPromise?()=>t.initialPromise:!e.queryFn||e.queryFn===e_?()=>Promise.reject(Error(`Missing queryFn: '${e.queryHash}'`)):e.queryFn}function n_(e,t){return typeof e==`function`?e(...t):!!e}function r_(e,t,n){let r=!1,i;return Object.defineProperty(e,"signal",{enumerable:!0,get:()=>(i??=t(),r?i:(r=!0,i.aborted?n():i.addEventListener(`abort`,n,{once:!0}),i))}),e}var i_=()=>Ng,a_=()=>i_(),o_=class{constructor(){this.listeners=new Set,this.subscribe=this.subscribe.bind(this)}subscribe(e){return this.listeners.add(e),this.onSubscribe(),()=>{this.listeners.delete(e),this.onUnsubscribe()}}hasListeners(){return this.listeners.size>0}onSubscribe(){}onUnsubscribe(){}},s_=new class extends o_{#e;#t;#n;constructor(){super(),this.#n=e=>{if(typeof window<`u`&&window.addEventListener){let t=()=>e();return window.addEventListener(`visibilitychange`,t,!1),()=>{window.removeEventListener(`visibilitychange`,t)}}}}onSubscribe(){this.#t||this.setEventListener(this.#n)}onUnsubscribe(){this.hasListeners()||(this.#t?.(),this.#t=void 0)}setEventListener(e){this.#n=e,this.#t?.(),this.#t=e(e=>{typeof e==`boolean`?this.setFocused(e):this.onFocus()})}setFocused(e){this.#e!==e&&(this.#e=e,this.onFocus())}onFocus(){let e=this.isFocused();this.listeners.forEach(t=>{t(e)})}isFocused(){return typeof this.#e==`boolean`?this.#e:globalThis.document?.visibilityState!==`hidden`}},c_=Mg;function l_(){let e=[],t=0,n=e=>{e()},r=e=>{e()},i=c_,a=r=>{t?e.push(r):i(()=>{n(r)})},o=()=>{let t=e;e=[],t.length&&i(()=>{r(()=>{t.forEach(e=>{n(e)})})})};return{batch:e=>{let n;t++;try{n=e()}finally{t--,t||o()}return n},batchCalls:e=>(...t)=>{a(()=>{e(...t)})},schedule:a,setNotifyFunction:e=>{n=e},setBatchNotifyFunction:e=>{r=e},setScheduler:e=>{i=e}}}var u_=l_(),d_=new class extends o_{#e=!0;#t;#n;constructor(){super(),this.#n=e=>{if(typeof window<`u`&&window.addEventListener){let t=()=>e(!0),n=()=>e(!1);return window.addEventListener(`online`,t,!1),window.addEventListener(`offline`,n,!1),()=>{window.removeEventListener(`online`,t),window.removeEventListener(`offline`,n)}}}}onSubscribe(){this.#t||this.setEventListener(this.#n)}onUnsubscribe(){this.hasListeners()||(this.#t?.(),this.#t=void 0)}setEventListener(e){this.#n=e,this.#t?.(),this.#t=e(this.setOnline.bind(this))}setOnline(e){this.#e!==e&&(this.#e=e,this.listeners.forEach(t=>{t(e)}))}isOnline(){return this.#e}};function f_(e){return Math.min(1e3*2**e,3e4)}function p_(e){return(e??`online`)!==`online`||d_.isOnline()}var m_=class extends Error{constructor(e){super(`CancelledError`),this.revert=e?.revert,this.silent=e?.silent}};function h_(e){let t=!1,n=0,r,i=`pending`,a,o,s=new Promise((e,t)=>{a=e,o=t});s.catch(Pg);let c=()=>i!==`pending`,l=t=>{if(!c()){let n=new m_(t);h(n),e.onCancel?.(n)}},u=()=>{t=!0},d=()=>{t=!1},f=()=>s_.isFocused()&&(e.networkMode===`always`||d_.isOnline())&&e.canRun(),p=()=>p_(e.networkMode)&&e.canRun(),m=e=>{c()||(r?.(),i=`resolved`,a(e))},h=e=>{c()||(r?.(),i=`rejected`,o(e))},g=()=>new Promise(t=>{r=e=>{(c()||f())&&t(e)},e.onPause?.()}).then(()=>{r=void 0,c()||e.onContinue?.()}),_=()=>{if(c())return;let r,i=n===0?e.initialPromise:void 0;try{r=i??e.fn()}catch(e){r=Promise.reject(e)}Promise.resolve(r).then(m).catch(r=>{if(c())return;let i=e.retry??(a_()?0:3),a=e.retryDelay??f_,o=typeof a==`function`?a(n,r):a,s=i===!0||typeof i==`number`&&n<i||typeof i==`function`&&i(n,r);if(t||!s){h(r);return}n++,e.onFail?.(n,r),Xg(o).then(()=>f()?void 0:g()).then(()=>{t?h(r):_()})})};return{promise:s,status:()=>i,cancel:l,continue:()=>(r?.(),s),cancelRetry:u,continueRetry:d,canStart:p,start:()=>(p()?_():g().then(_),s)}}var g_=class{#e;destroy(){this.clearGcTimeout()}scheduleGc(){this.clearGcTimeout(),Ig(this.gcTime)&&(this.#e=jg.setTimeout(()=>{this.optionalRemove()},this.gcTime))}updateGcTime(e){this.gcTime=Math.max(this.gcTime||0,e??(a_()?1/0:3e5))}clearGcTimeout(){this.#e!==void 0&&(jg.clearTimeout(this.#e),this.#e=void 0)}};function __(e){return{onFetch:(t,n)=>{let r=t.options,i=t.fetchOptions?.meta?.fetchMore?.direction,a=t.state.data?.pages||[],o=t.state.data?.pageParams||[],s={pages:[],pageParams:[]},c=0,l=async()=>{let n=!1,l=e=>{r_(e,()=>t.signal,()=>n=!0)},u=t_(t.options,t.fetchOptions),d=async(e,r,i)=>{if(n)return Promise.reject(t.signal.reason);if(r==null&&e.pages.length)return Promise.resolve(e);let a=(()=>{let e={client:t.client,queryKey:t.queryKey,pageParam:r,direction:i?`backward`:`forward`,meta:t.options.meta};return l(e),e})(),o=await u(a),{maxPages:s}=t.options,c=i?$g:Qg;return{pages:c(e.pages,o,s),pageParams:c(e.pageParams,r,s)}};if(i&&a.length){let e=i===`backward`,t=e?y_:v_,n={pages:a,pageParams:o};s=await d(n,t(r,n),e)}else{let t=e??a.length;do{let e=c===0?o[0]??r.initialPageParam:v_(r,s);if(c>0&&e==null)break;s=await d(s,e),c++}while(c<t)}return s};t.fetchFn=t.options.persister?()=>t.options.persister?.(l,{client:t.client,queryKey:t.queryKey,meta:t.options.meta,signal:t.signal},n):l}}}function v_(e,{pages:t,pageParams:n}){let r=t.length-1;return t.length>0?e.getNextPageParam(t[r],t,n[r],n):void 0}function y_(e,{pages:t,pageParams:n}){return t.length>0?e.getPreviousPageParam?.(t[0],t,n[0],n):void 0}var b_=class extends g_{#e;#t;#n;#r;#i;#a;#o;#s;constructor(e){super(),this.#s=!1,this.#o=e.defaultOptions,this.setOptions(e.options),this.observers=[],this.#i=e.client,this.#r=this.#i.getQueryCache(),this.queryKey=e.queryKey,this.queryHash=e.queryHash,this.#t=C_(this.options),this.state=e.state??this.#t,this.scheduleGc()}get meta(){return this.options.meta}get queryType(){return this.#e}get promise(){return this.#a?.promise}setOptions(e){if(this.options={...this.#o,...e},e?._type&&(this.#e=e._type),this.updateGcTime(this.options.gcTime),this.state&&this.state.data===void 0){let e=C_(this.options);e.data!==void 0&&(this.setState(S_(e.data,e.dataUpdatedAt)),this.#t=e)}}optionalRemove(){!this.observers.length&&this.state.fetchStatus===`idle`&&this.#r.remove(this)}setData(e,t){let n=Zg(this.state.data,e,this.options);return this.#c({data:n,type:`success`,dataUpdatedAt:t?.updatedAt,manual:t?.manual}),n}setState(e){this.#c({type:`setState`,state:e})}cancel(e){let t=this.#a?.promise;return this.#a?.cancel(e),t?t.then(Pg).catch(Pg):Promise.resolve()}destroy(){super.destroy(),this.cancel({silent:!0})}get resetState(){return this.#t}reset(){this.destroy(),this.setState(this.resetState)}isActive(){return this.observers.some(e=>Rg(e.options.enabled,this)!==!1)}isDisabled(){return this.getObserversCount()>0?!this.isActive():this.options.queryFn===e_||!this.isFetched()}isFetched(){return this.state.dataUpdateCount+this.state.errorUpdateCount>0}isStatic(){return this.getObserversCount()>0&&this.observers.some(e=>Rg(e.options.staleTime,this)===`static`)}isStale(){return this.getObserversCount()>0?this.observers.some(e=>e.getCurrentResult().isStale):this.state.data===void 0||this.state.isInvalidated}isStaleByTime(e=0){return this.state.data===void 0?!0:e===`static`?!1:this.state.isInvalidated?!0:!Lg(this.state.dataUpdatedAt,e)}onFocus(){this.observers.find(e=>e.shouldFetchOnWindowFocus())?.refetch({cancelRefetch:!1}),this.#a?.continue()}onOnline(){this.observers.find(e=>e.shouldFetchOnReconnect())?.refetch({cancelRefetch:!1}),this.#a?.continue()}addObserver(e){this.observers.includes(e)||(this.observers.push(e),this.clearGcTimeout(),this.#r.notify({type:`observerAdded`,query:this,observer:e}))}removeObserver(e){let t=this.observers.indexOf(e);t!==-1&&(this.observers.splice(t,1),this.observers.length||(this.#a&&(this.#s||this.state.fetchStatus===`paused`&&this.state.status===`pending`?this.#a.cancel({revert:!0}):this.#a.cancelRetry()),this.scheduleGc()),this.#r.notify({type:`observerRemoved`,query:this,observer:e}))}getObserversCount(){return this.observers.length}invalidate(){this.state.isInvalidated||this.#c({type:`invalidate`})}async fetch(e,t){if(this.state.fetchStatus!==`idle`&&this.#a?.status()!==`rejected`){if(this.state.data!==void 0&&t?.cancelRefetch)this.cancel({silent:!0});else if(this.#a)return this.#a.continueRetry(),this.#a.promise}if(e&&this.setOptions(e),!this.options.queryFn){let e=this.observers.find(e=>e.options.queryFn);e&&this.setOptions(e.options)}let n=new AbortController,r=e=>{Object.defineProperty(e,"signal",{enumerable:!0,get:()=>(this.#s=!0,n.signal)})},i=()=>{let e=t_(this.options,t),n=(()=>{let e={client:this.#i,queryKey:this.queryKey,meta:this.meta};return r(e),e})();return this.#s=!1,this.options.persister?this.options.persister(e,n,this):e(n)},a=(()=>{let e={fetchOptions:t,options:this.options,queryKey:this.queryKey,client:this.#i,state:this.state,fetchFn:i};return r(e),e})();(this.#e===`infinite`?__(this.options.pages):this.options.behavior)?.onFetch(a,this),this.#n=this.state,(this.state.fetchStatus===`idle`||this.state.fetchMeta!==a.fetchOptions?.meta)&&this.#c({type:`fetch`,meta:a.fetchOptions?.meta});let o=this.#a=h_({initialPromise:t?.initialPromise,fn:a.fetchFn,onCancel:e=>{e instanceof m_&&e.revert&&this.setState({...this.#n,fetchStatus:`idle`}),n.abort()},onFail:(e,t)=>{this.#c({type:`failed`,failureCount:e,error:t})},onPause:()=>{this.#c({type:`pause`})},onContinue:()=>{this.#c({type:`continue`})},retry:a.options.retry,retryDelay:a.options.retryDelay,networkMode:a.options.networkMode,canRun:()=>!0});try{let e=await o.start();if(e===void 0)throw Error(`${this.queryHash} data is undefined`);return this.setData(e),this.#r.config.onSuccess?.(e,this),this.#r.config.onSettled?.(e,this.state.error,this),e}catch(e){if(e instanceof m_){if(e.silent)return this.#a.promise;if(e.revert){if(this.state.data===void 0)throw e;return this.state.data}}throw this.#c({type:`error`,error:e}),this.#r.config.onError?.(e,this),this.#r.config.onSettled?.(this.state.data,e,this),e}finally{this.#a===o&&(this.#a=void 0),this.scheduleGc()}}#c(e){let t=t=>{switch(e.type){case`failed`:return{...t,fetchFailureCount:e.failureCount,fetchFailureReason:e.error};case`pause`:return{...t,fetchStatus:`paused`};case`continue`:return{...t,fetchStatus:`fetching`};case`fetch`:return{...t,...x_(t.data,this.options),fetchMeta:e.meta??null};case`success`:let n={...t,...S_(e.data,e.dataUpdatedAt),dataUpdateCount:t.dataUpdateCount+1,...!e.manual&&{fetchStatus:`idle`,fetchFailureCount:0,fetchFailureReason:null}};return this.#n=e.manual?n:void 0,n;case`error`:let r=e.error;return{...t,error:r,errorUpdateCount:t.errorUpdateCount+1,errorUpdatedAt:Date.now(),fetchFailureCount:t.fetchFailureCount+1,fetchFailureReason:r,fetchStatus:`idle`,status:`error`,isInvalidated:!0};case`invalidate`:return{...t,isInvalidated:!0};case`setState`:return{...t,...e.state}}};this.state=t(this.state),u_.batch(()=>{this.observers.slice().forEach(e=>{e.onQueryUpdate()}),this.#r.notify({query:this,type:`updated`,action:e})})}};function x_(e,t){return{fetchFailureCount:0,fetchFailureReason:null,fetchStatus:p_(t.networkMode)?`fetching`:`paused`,...e===void 0&&{error:null,status:`pending`}}}function S_(e,t){return{data:e,dataUpdatedAt:t??Date.now(),error:null,isInvalidated:!1,status:`success`}}function C_(e){let t=typeof e.initialData==`function`?e.initialData():e.initialData,n=t!==void 0,r=n?typeof e.initialDataUpdatedAt==`function`?e.initialDataUpdatedAt():e.initialDataUpdatedAt:0;return{data:t,dataUpdateCount:0,dataUpdatedAt:n?r??Date.now():0,error:null,errorUpdateCount:0,errorUpdatedAt:0,fetchFailureCount:0,fetchFailureReason:null,fetchMeta:null,isInvalidated:!1,status:n?`success`:`pending`,fetchStatus:`idle`}}var w_=class extends o_{#e;#t=void 0;#n=void 0;#r=void 0;#i;#a;#o;#s;#c;#l;#u;#d;#f;#p=new Set;constructor(e,t){super(),this.options=t,this.#e=e,this.#o=null,this.bindMethods(),this.setOptions(t)}bindMethods(){this.refetch=this.refetch.bind(this)}onSubscribe(){this.listeners.size===1&&(this.#t.addObserver(this),E_(this.#t,this.options)?this.#m():this.updateResult(),this.#y())}onUnsubscribe(){this.hasListeners()||this.destroy()}shouldFetchOnReconnect(){return D_(this.#t,this.options,this.options.refetchOnReconnect)}shouldFetchOnWindowFocus(){return D_(this.#t,this.options,this.options.refetchOnWindowFocus)}destroy(){this.listeners=new Set,this.#b(),this.#x(),this.#t.removeObserver(this)}setOptions(e){let t=this.options,n=this.#t;if(this.options=this.#e.defaultQueryOptions(e),this.options.enabled!==void 0&&typeof this.options.enabled!=`boolean`&&typeof this.options.enabled!=`function`&&typeof Rg(this.options.enabled,this.#t)!=`boolean`)throw Error(`Expected enabled to be a boolean or a callback that returns a boolean`);this.#S(),this.#t.setOptions(this.options),t._defaulted&&!Kg(this.options,t)&&this.#e.getQueryCache().notify({type:`observerOptionsUpdated`,query:this.#t,observer:this});let r=this.hasListeners();r&&O_(this.#t,n,this.options,t)&&this.#m(),this.updateResult(),r&&(this.#t!==n||Rg(this.options.enabled,this.#t)!==Rg(t.enabled,this.#t)||Rg(this.options.staleTime,this.#t)!==Rg(t.staleTime,this.#t))&&this.#g();let i=this.#_();r&&(this.#t!==n||Rg(this.options.enabled,this.#t)!==Rg(t.enabled,this.#t)||i!==this.#f)&&this.#v(i)}getOptimisticResult(e){let t=this.#e.getQueryCache().build(this.#e,e),n=this.createResult(t,e);return Kg(this.getCurrentResult(),n)||(this.#r=n,this.#a=this.options,this.#i=this.#t.state),n}getCurrentResult(){return this.#r}trackResult(e,t){return new Proxy(e,{get:(e,n)=>(this.trackProp(n),t?.(n),Reflect.get(e,n))})}trackProp(e){this.#p.add(e)}getCurrentQuery(){return this.#t}refetch({...e}={}){return this.fetch({...e})}fetchOptimistic(e){let t=this.#e.defaultQueryOptions(e),n=this.#e.getQueryCache().build(this.#e,t),r=()=>{},i,a=new Promise(e=>{i=e,r=this.#e.getQueryCache().subscribe(i=>{i.type===`updated`&&i.query.queryHash===n.queryHash&&n.state.data!==void 0&&(r(),e(this.createResult(n,t)))})});return Promise.race([n.fetch().then(()=>{let e=this.createResult(n,t);return i?.(e),e}).finally(()=>{r()}),a])}fetch(e){return this.#m({...e,cancelRefetch:e.cancelRefetch??!0}).then(()=>(this.updateResult(),this.#r))}#m(e){this.#S();let t=this.#t.fetch(this.options,e);return e?.throwOnError||(t=t.catch(Pg)),t}#h(e){return!a_()&&Rg(this.options.enabled,this.#t)!==!1&&Ig(e)}#g(){this.#b();let e=Rg(this.options.staleTime,this.#t);if(this.#r.isStale||!this.#h(e))return;let t=Lg(this.#r.dataUpdatedAt,e)+1;this.#u=jg.setTimeout(()=>{this.#r.isStale||this.updateResult()},t)}#_(){return Rg(this.options.refetchInterval,this.#t)??!1}#v(e){this.#x(),this.#f=e,this.#f!==0&&this.#h(this.#f)&&(this.#d=jg.setInterval(()=>{(this.options.refetchIntervalInBackground||s_.isFocused())&&this.#m()},this.#f))}#y(){this.#g(),this.#v(this.#_())}#b(){this.#u!==void 0&&(jg.clearTimeout(this.#u),this.#u=void 0)}#x(){this.#d!==void 0&&(jg.clearInterval(this.#d),this.#d=void 0)}createResult(e,t){let n=this.#t,r=this.options,i=this.#r,a=this.#i,o=this.#a,s=e===n?this.#n:e.state,{state:c}=e,l={...c},u=!1,d;if(t._optimisticResults){let i=this.hasListeners(),a=!i&&E_(e,t),o=i&&O_(e,n,t,r);(a||o)&&(l={...l,...x_(c.data,e.options)}),t._optimisticResults===`isRestoring`&&(l.fetchStatus=`idle`)}let{error:f,errorUpdatedAt:p,status:m}=l;d=l.data;let h=!1;if(t.placeholderData!==void 0&&d===void 0&&m===`pending`){let e;i?.isPlaceholderData&&t.placeholderData===o?.placeholderData?(e=i.data,h=!0):e=typeof t.placeholderData==`function`?t.placeholderData(this.#l?.state.data,this.#l):t.placeholderData,e!==void 0&&(m=`success`,d=Zg(i?.data,e,t),u=!0)}if(t.select&&d!==void 0&&!h){if(i&&d===a?.data&&t.select===this.#s)d=this.#c;else try{this.#s=t.select,d=t.select(d),d=Zg(i?.data,d,t),this.#c=d,this.#o=null}catch(e){this.#o=e}}else d===void 0&&(this.#o=null);this.#o&&(f=this.#o,d=this.#c,p=Date.now(),m=`error`,u=!1);let g=l.fetchStatus===`fetching`,_=m===`pending`,v=m===`error`,y=_&&g,b=d!==void 0;return{status:m,fetchStatus:l.fetchStatus,isPending:_,isSuccess:m===`success`,isError:v,isInitialLoading:y,isLoading:y,data:d,dataUpdatedAt:l.dataUpdatedAt,error:f,errorUpdatedAt:p,failureCount:l.fetchFailureCount,failureReason:l.fetchFailureReason,errorUpdateCount:l.errorUpdateCount,isFetched:e.isFetched(),isFetchedAfterMount:l.dataUpdateCount>s.dataUpdateCount||l.errorUpdateCount>s.errorUpdateCount,isFetching:g,isRefetching:g&&!_,isLoadingError:v&&!b,isPaused:l.fetchStatus===`paused`,isPlaceholderData:u,isRefetchError:v&&b,isStale:k_(e,t),refetch:this.refetch,isEnabled:Rg(t.enabled,e)!==!1}}updateResult(){let e=this.#r,t=this.createResult(this.#t,this.options);if(this.#i=this.#t.state,this.#a=this.options,this.#i.data!==void 0&&(this.#l=this.#t),Kg(t,e))return;this.#r=t;let n=(()=>{if(!e)return!0;let{notifyOnChangeProps:t}=this.options,n=typeof t==`function`?t():t;if(n===`all`||!n&&!this.#p.size)return!0;let r=new Set(n??this.#p);return this.options.throwOnError&&r.add(`error`),Object.keys(this.#r).some(t=>{let n=t;return this.#r[n]!==e[n]&&r.has(n)})})();u_.batch(()=>{n&&this.listeners.forEach(e=>{e(this.#r)}),this.#e.getQueryCache().notify({query:this.#t,type:`observerResultsUpdated`})})}#S(){let e=this.#e.getQueryCache().build(this.#e,this.options);if(e===this.#t)return;let t=this.#t;this.#t=e,this.#n=e.state,this.hasListeners()&&(t?.removeObserver(this),e.addObserver(this))}onQueryUpdate(){this.updateResult(),this.hasListeners()&&this.#y()}};function T_(e,t){return Rg(t.enabled,e)!==!1&&e.state.data===void 0&&(e.state.status!==`error`||Rg(t.retryOnMount,e)!==!1)}function E_(e,t){return T_(e,t)||e.state.data!==void 0&&D_(e,t,t.refetchOnMount)}function D_(e,t,n){if(Rg(t.enabled,e)!==!1&&Rg(t.staleTime,e)!==`static`){let r=Rg(n,e);return r===`always`||r!==!1&&k_(e,t)}return!1}function O_(e,t,n,r){return(e!==t||Rg(r.enabled,e)===!1)&&(!n.suspense||e.state.status!==`error`)&&k_(e,n)}function k_(e,t){return Rg(t.enabled,e)!==!1&&e.isStaleByTime(Rg(t.staleTime,e))}var A_=class extends g_{#e;#t;#n;#r;constructor(e){super(),this.#e=e.client,this.mutationId=e.mutationId,this.#n=e.mutationCache,this.#t=[],this.state=e.state||j_(),this.setOptions(e.options),this.scheduleGc()}setOptions(e){this.options=e,this.updateGcTime(this.options.gcTime)}get meta(){return this.options.meta}addObserver(e){this.#t.includes(e)||(this.#t.push(e),this.clearGcTimeout(),this.#n.notify({type:`observerAdded`,mutation:this,observer:e}))}removeObserver(e){this.#t=this.#t.filter(t=>t!==e),this.scheduleGc(),this.#n.notify({type:`observerRemoved`,mutation:this,observer:e})}optionalRemove(){this.#t.length||(this.state.status===`pending`?this.scheduleGc():this.#n.remove(this))}continue(){return this.#r?.continue()??(this.state.status===`pending`?this.execute(this.state.variables):Promise.resolve())}async execute(e){let t=()=>{this.#i({type:`continue`})},n={client:this.#e,meta:this.options.meta,mutationKey:this.options.mutationKey},r=this.#r=h_({fn:()=>this.options.mutationFn?this.options.mutationFn(e,n):Promise.reject(Error(`No mutationFn found`)),onFail:(e,t)=>{this.#i({type:`failed`,failureCount:e,error:t})},onPause:()=>{this.#i({type:`pause`})},onContinue:t,retry:this.options.retry??0,retryDelay:this.options.retryDelay,networkMode:this.options.networkMode,canRun:()=>this.#n.canRun(this)}),i=this.state.status===`pending`,a=!r.canStart();try{if(i)t();else{this.#i({type:`pending`,variables:e,isPaused:a}),this.#n.config.onMutate&&await this.#n.config.onMutate(e,this,n);let t=await this.options.onMutate?.(e,n);t!==this.state.context&&this.#i({type:`pending`,context:t,variables:e,isPaused:a})}let o=await r.start();return await this.#n.config.onSuccess?.(o,e,this.state.context,this,n),await this.options.onSuccess?.(o,e,this.state.context,n),await this.#n.config.onSettled?.(o,null,this.state.variables,this.state.context,this,n),await this.options.onSettled?.(o,null,e,this.state.context,n),this.#i({type:`success`,data:o}),o}catch(t){try{await this.#n.config.onError?.(t,e,this.state.context,this,n)}catch(e){Promise.reject(e)}try{await this.options.onError?.(t,e,this.state.context,n)}catch(e){Promise.reject(e)}try{await this.#n.config.onSettled?.(void 0,t,this.state.variables,this.state.context,this,n)}catch(e){Promise.reject(e)}try{await this.options.onSettled?.(void 0,t,e,this.state.context,n)}catch(e){Promise.reject(e)}throw this.#i({type:`error`,error:t}),t}finally{this.#r===r&&(this.#r=void 0),this.#n.runNext(this)}}#i(e){let t=t=>{switch(e.type){case`failed`:return{...t,failureCount:e.failureCount,failureReason:e.error};case`pause`:return{...t,isPaused:!0};case`continue`:return{...t,isPaused:!1};case`pending`:return{...t,context:e.context,data:void 0,failureCount:0,failureReason:null,error:null,isPaused:e.isPaused,status:`pending`,variables:e.variables,submittedAt:Date.now()};case`success`:return{...t,data:e.data,failureCount:0,failureReason:null,error:null,status:`success`,isPaused:!1};case`error`:return{...t,data:void 0,error:e.error,failureCount:t.failureCount+1,failureReason:e.error,isPaused:!1,status:`error`}}};this.state=t(this.state),u_.batch(()=>{this.#t.forEach(t=>{t.onMutationUpdate(e)}),this.#n.notify({mutation:this,type:`updated`,action:e})})}};function j_(){return{context:void 0,data:void 0,error:null,failureCount:0,failureReason:null,isPaused:!1,status:`idle`,variables:void 0,submittedAt:0}}var M_=class extends o_{#e;#t;#n;constructor(e={}){super(),this.config=e,this.#e=new Set,this.#t=new Map,this.#n=0}build(e,t,n){let r=new A_({client:e,mutationCache:this,mutationId:++this.#n,options:e.defaultMutationOptions(t),state:n});return this.add(r),r}add(e){this.#e.add(e);let t=N_(e);if(typeof t==`string`){let n=this.#t.get(t);n?n.push(e):this.#t.set(t,[e])}this.notify({type:`added`,mutation:e})}remove(e){if(this.#e.delete(e)){let t=N_(e);if(typeof t==`string`){let n=this.#t.get(t);if(n){if(n.length>1){let t=n.indexOf(e);t!==-1&&n.splice(t,1)}else n[0]===e&&this.#t.delete(t)}}}this.notify({type:`removed`,mutation:e})}canRun(e){let t=N_(e);if(typeof t==`string`){let n=this.#t.get(t)?.find(e=>e.state.status===`pending`);return!n||n===e}return!0}runNext(e){let t=N_(e);return typeof t==`string`?(this.#t.get(t)?.find(t=>t!==e&&t.state.isPaused))?.continue()??Promise.resolve():Promise.resolve()}clear(){u_.batch(()=>{this.#e.forEach(e=>{this.notify({type:`removed`,mutation:e})}),this.#e.clear(),this.#t.clear()})}getAll(){return Array.from(this.#e)}find(e){let t={exact:!0,...e};return this.getAll().find(e=>Bg(t,e))}findAll(e={}){return this.getAll().filter(t=>Bg(e,t))}notify(e){u_.batch(()=>{this.listeners.forEach(t=>{t(e)})})}resumePausedMutations(){let e=this.getAll().filter(e=>e.state.isPaused);return u_.batch(()=>Promise.all(e.map(e=>e.continue().catch(Pg))))}};function N_(e){return e.options.scope?.id}var P_=class extends o_{#e;constructor(e={}){super(),this.config=e,this.#e=new Map}build(e,t,n){let r=t.queryKey,i=t.queryHash??Vg(r,t),a=this.get(i);return a||(a=new b_({client:e,queryKey:r,queryHash:i,options:e.defaultQueryOptions(t),state:n,defaultOptions:e.getQueryDefaults(r)}),this.add(a)),a}add(e){this.#e.has(e.queryHash)||(this.#e.set(e.queryHash,e),this.notify({type:`added`,query:e}))}remove(e){this.#e.get(e.queryHash)===e&&(e.destroy(),this.#e.delete(e.queryHash),this.notify({type:`removed`,query:e}))}clear(){u_.batch(()=>{this.getAll().forEach(e=>{this.remove(e)})})}get(e){return this.#e.get(e)}getAll(){return[...this.#e.values()]}find(e){let t={exact:!0,...e};return this.getAll().find(e=>zg(t,e))}findAll(e={}){let t=this.getAll();return Object.keys(e).length>0?t.filter(t=>zg(e,t)):t}notify(e){u_.batch(()=>{this.listeners.forEach(t=>{t(e)})})}onFocus(){u_.batch(()=>{this.getAll().forEach(e=>{e.onFocus()})})}onOnline(){u_.batch(()=>{this.getAll().forEach(e=>{e.onOnline()})})}},F_=class{#e;#t;#n;#r;#i;#a;#o;#s;constructor(e={}){this.#e=e.queryCache||new P_,this.#t=e.mutationCache||new M_,this.#n=e.defaultOptions||{},this.#r=new Map,this.#i=new Map,this.#a=0}mount(){this.#a++,this.#a===1&&(this.#o=s_.subscribe(async e=>{e&&(await this.resumePausedMutations(),this.#e.onFocus())}),this.#s=d_.subscribe(async e=>{e&&(await this.resumePausedMutations(),this.#e.onOnline())}))}unmount(){this.#a--,this.#a===0&&(this.#o?.(),this.#o=void 0,this.#s?.(),this.#s=void 0)}isFetching(e){return this.#e.findAll({...e,fetchStatus:`fetching`}).length}isMutating(e){return this.#t.findAll({...e,status:`pending`}).length}getQueryData(e){let t=this.defaultQueryOptions({queryKey:e});return this.#e.get(t.queryHash)?.state.data}ensureQueryData(e){let t=this.defaultQueryOptions(e),n=this.#e.build(this,t),r=n.state.data;return r===void 0?this.fetchQuery(e):(e.revalidateIfStale&&n.isStaleByTime(Rg(t.staleTime,n))&&this.prefetchQuery(t),Promise.resolve(r))}getQueriesData(e){return this.#e.findAll(e).map(({queryKey:e,state:t})=>[e,t.data])}setQueryData(e,t,n){let r=this.defaultQueryOptions({queryKey:e}),i=this.#e.get(r.queryHash)?.state.data,a=Fg(t,i);if(a!==void 0)return this.#e.build(this,r).setData(a,{...n,manual:!0})}setQueriesData(e,t,n){return u_.batch(()=>this.#e.findAll(e).map(({queryKey:e})=>[e,this.setQueryData(e,t,n)]))}getQueryState(e){let t=this.defaultQueryOptions({queryKey:e});return this.#e.get(t.queryHash)?.state}removeQueries(e){let t=this.#e;u_.batch(()=>{t.findAll(e).forEach(e=>{t.remove(e)})})}resetQueries(e,t){let n=this.#e;return u_.batch(()=>{let r=n.findAll(e),i=new Set(r);return r.forEach(e=>{e.reset()}),this.refetchQueries({type:`active`,predicate:e=>i.has(e)},t)})}cancelQueries(e,t={}){let n={revert:!0,...t},r=u_.batch(()=>this.#e.findAll(e).map(e=>e.cancel(n)));return Promise.all(r).then(Pg).catch(Pg)}invalidateQueries(e,t={}){return u_.batch(()=>(this.#e.findAll(e).forEach(e=>{e.invalidate()}),e?.refetchType===`none`?Promise.resolve():this.refetchQueries({...e,type:e?.refetchType??e?.type??`active`},t)))}refetchQueries(e,t={}){let n={...t,cancelRefetch:t.cancelRefetch??!0},r=u_.batch(()=>this.#e.findAll(e).filter(e=>!e.isDisabled()&&!e.isStatic()).map(e=>{let t=e.fetch(void 0,n);return n.throwOnError||(t=t.catch(Pg)),e.state.fetchStatus===`paused`?Promise.resolve():t}));return Promise.all(r).then(Pg)}async query(e){let t=this.defaultQueryOptions(e);t.retry===void 0&&(t.retry=!1);let n=this.#e.build(this,t),r=n.isStaleByTime(Rg(t.staleTime,n))?await n.fetch(t):n.state.data,i=t.select;return i?i(r):r}fetchQuery(e){let t=this.defaultQueryOptions(e);t.retry===void 0&&(t.retry=!1);let n=this.#e.build(this,t);return n.isStaleByTime(Rg(t.staleTime,n))?n.fetch(t):Promise.resolve(n.state.data)}prefetchQuery(e){return this.fetchQuery(e).then(Pg).catch(Pg)}infiniteQuery(e){return e._type=`infinite`,this.query(e)}fetchInfiniteQuery(e){return e._type=`infinite`,this.fetchQuery(e)}prefetchInfiniteQuery(e){return this.fetchInfiniteQuery(e).then(Pg).catch(Pg)}ensureInfiniteQueryData(e){return e._type=`infinite`,this.ensureQueryData(e)}resumePausedMutations(){return d_.isOnline()?this.#t.resumePausedMutations():Promise.resolve()}getQueryCache(){return this.#e}getMutationCache(){return this.#t}getDefaultOptions(){return this.#n}setDefaultOptions(e){this.#n=e}setQueryDefaults(e,t){this.#r.set(Hg(e),{queryKey:e,defaultOptions:t})}getQueryDefaults(e){let t=[...this.#r.values()],n={};return t.forEach(t=>{Ug(e,t.queryKey)&&Object.assign(n,t.defaultOptions)}),n}setMutationDefaults(e,t){this.#i.set(Hg(e),{mutationKey:e,defaultOptions:t})}getMutationDefaults(e){let t=[...this.#i.values()],n={};return t.forEach(t=>{Ug(e,t.mutationKey)&&Object.assign(n,t.defaultOptions)}),n}defaultQueryOptions(e){if(e._defaulted)return e;let t={...this.#n.queries,...this.getQueryDefaults(e.queryKey),...e,_defaulted:!0};return t.queryHash||=Vg(t.queryKey,t),t.refetchOnReconnect===void 0&&(t.refetchOnReconnect=t.networkMode!==`always`),t.throwOnError===void 0&&(t.throwOnError=!!t.suspense),!t.networkMode&&t.persister&&(t.networkMode=`offlineFirst`),t.queryFn===e_&&(t.enabled=!1),t}defaultMutationOptions(e){return e?._defaulted?e:{...this.#n.mutations,...e?.mutationKey&&this.getMutationDefaults(e.mutationKey),...e,_defaulted:!0}}clear(){this.#e.clear(),this.#t.clear()}},I_=l.createContext(!1),L_=()=>l.useContext(I_);I_.Provider;function R_(){let e=!1;return{clearReset:()=>{e=!1},reset:()=>{e=!0},isReset:()=>e}}var z_=l.createContext(R_()),B_=()=>l.useContext(z_),V_=(e,t,n)=>{let r=n?.state.error&&typeof e.throwOnError==`function`?n_(e.throwOnError,[n.state.error,n]):e.throwOnError;(e.suspense||r)&&(t.isReset()||(e.retryOnMount=!1))},H_=e=>{l.useEffect(()=>{e.clearReset()},[e])},U_=({result:e,errorResetBoundary:t,throwOnError:n,query:r,suspense:i})=>e.isError&&!t.isReset()&&!e.isFetching&&r&&(i&&e.data===void 0||n_(n,[e.error,r])),W_=e=>{if(e.suspense){let t=1e3,n=e=>e===`static`?e:Math.max(e??t,t),r=e.staleTime;e.staleTime=typeof r==`function`?(...e)=>n(r(...e)):n(r),typeof e.gcTime==`number`&&(e.gcTime=Math.max(e.gcTime,t))}},G_=(e,t)=>e?.suspense&&t.isPending,K_=(e,t,n)=>t.fetchOptimistic(e).catch(()=>{n.clearReset()});function q_(e,t,n){let r=L_(),i=B_(),a=Og(n),o=a.defaultQueryOptions(e),s=a.getQueryCache().get(o.queryHash),c=e.subscribed!==!1;o._optimisticResults=r?`isRestoring`:c?`optimistic`:void 0,W_(o),V_(o,i,s),H_(i);let[u]=l.useState(()=>new t(a,o)),d=u.getOptimisticResult(o),f=!r&&c;if(l.useSyncExternalStore(l.useCallback(e=>{let t=f?u.subscribe(u_.batchCalls(e)):Pg;return u.updateResult(),t},[u,f]),()=>u.getCurrentResult(),()=>u.getCurrentResult()),l.useEffect(()=>{u.setOptions(o)},[o,u]),G_(o,d))throw K_(o,u,i);if(U_({result:d,errorResetBoundary:i,throwOnError:o.throwOnError,query:s,suspense:o.suspense}))throw d.error;return o.notifyOnChangeProps?d:u.trackResult(d)}function J_(e,t){return q_(e,w_,t)}var Y_=1e3,X_=e=>`webr-catalog:${e}`,Z_=e=>{try{return JSON.parse(localStorage.getItem(X_(e))??`null`)??void 0}catch{return}},Q_=(e,t)=>{try{localStorage.setItem(X_(e),JSON.stringify(t))}catch{}};function $_(e,t,n=1,r=``,i=``){return J_({queryKey:[`machine-catalog`,e,r,n,i],enabled:!!e&&t,placeholderData:()=>Z_(e),refetchInterval:e=>e.state.data?.modelsPending?Y_:!1,queryFn:async({signal:t})=>{let n=await fetch(`/api/catalog/`+encodeURIComponent(e)+(i?`?projectId=`+encodeURIComponent(i):``),{signal:t});if(!n.ok)throw Error(`Machine catalog is not available.`);let r=await n.json();return Q_(e,r),r}})}var ev=e=>e.startsWith(`/`)||e.startsWith(`~`),tv=e=>Array.isArray(e)?e.filter(e=>typeof e==`string`):[];function nv(e,t){let[n,r]=(0,l.useState)([]);return(0,l.useEffect)(()=>{if(!ev(t)){r([]);return}let n=new AbortController;return fetch(`/api/directories?machineId=${encodeURIComponent(e)}&prefix=${encodeURIComponent(t)}`,{signal:n.signal}).then(e=>e.ok?e.json():[]).then(e=>r(tv(e))).catch(()=>{}),()=>n.abort()},[e,t]),n}var rv=e=>e.startsWith(`/`)||e.startsWith(`~/`);function iv({machineId:e,onCreated:t}){let[n,r]=(0,l.useState)(``),[i,a]=(0,l.useState)(``),[o,s]=(0,l.useState)(!1),[c,u]=(0,l.useState)(``),[d,f]=(0,l.useState)(0),[p,m]=(0,l.useState)(!1),h=nv(e,n),g=p&&h.length>0&&(h.length!==1||h[0]!==n),_=e=>{r(e),f(0),m(!0)},v=e=>{g&&(e.key===`ArrowDown`||e.key===`ArrowUp`?(e.preventDefault(),f(t=>(t+(e.key===`ArrowDown`?1:h.length-1))%h.length)):e.key===`Tab`?(e.preventDefault(),_(h[d]??h[0])):e.key===`Enter`?(e.preventDefault(),_(h[d]??h[0]),m(!1)):e.key===`Escape`&&m(!1))},y=(0,l.useRef)(null);return(0,Q.jsxs)(`form`,{className:`thread-composer workspace-composer`,onSubmit:async r=>{r.preventDefault(),s(!0),u(``);let a=JSON.stringify({machineId:e,path:n,label:i});y.current?.payload!==a&&(y.current={payload:a,key:cm()});try{let e=await fetch(`/api/workspaces`,{method:`POST`,headers:{"Content-Type":`application/json`,"Idempotency-Key":y.current.key},body:a}),n=await e.json();if(!e.ok)throw Error(n.error??`Could not create workspace`);if(n.state===`unknown`)throw Error(`The result is not known; check Herdr before you create another workspace.`);t()}catch(e){u(e instanceof Error?e.message:`Could not create workspace`)}finally{s(!1)}},"aria-label":`Create workspace`,"aria-busy":o,children:[(0,Q.jsxs)(`label`,{className:`path-field`,children:[`Project folder`,(0,Q.jsx)(`input`,{value:n,onChange:e=>{r(e.target.value),f(0),m(!0)},onKeyDown:v,onBlur:()=>m(!1),placeholder:`/absolute/path/to/project`,autoComplete:`off`,spellCheck:!1,role:`combobox`,"aria-expanded":g,"aria-autocomplete":`list`,required:!0,pattern:`(/|~/).*`}),g&&(0,Q.jsx)(`ul`,{className:`path-suggestions`,role:`listbox`,children:h.map((e,t)=>(0,Q.jsx)(`li`,{role:`option`,"aria-selected":t===d,"data-highlighted":t===d||void 0,onMouseDown:t=>{t.preventDefault(),_(e)},children:e},e))})]}),(0,Q.jsxs)(`label`,{children:[`Workspace name`,(0,Q.jsx)(`input`,{value:i,onChange:e=>a(e.target.value),required:!0,maxLength:80})]}),(0,Q.jsx)(`button`,{type:`submit`,disabled:o||!rv(n)||!i.trim(),children:o?`Creating…`:`Create workspace`}),c&&(0,Q.jsx)(`p`,{className:`form-error`,role:`alert`,children:c})]})}var av={main:`Main checkout`,worktree:`New worktree`,remember:`Remember by project`},ov=`webr-new-session-behavior`,sv=`webr-new-worktree`,cv=(e,t)=>`webr-last-worktree:${e}:${t}`,lv=e=>e===`main`||e===`worktree`||e===`remember`,uv=()=>{let e=localStorage.getItem(sv);return e===null?`remember`:e===`false`?`main`:`worktree`};function dv(){let e=localStorage.getItem(ov);return lv(e)?e:uv()}function fv(e){localStorage.setItem(ov,e)}function pv(e,t,n){localStorage.setItem(cv(e,t),String(n))}var mv=(e,t)=>localStorage.getItem(cv(e,t))!==`false`;function hv(e,t){let n=dv();return n===`remember`?mv(e,t):n===`worktree`}var gv=`webr-new-thread-draft`,_v=e=>!!e&&typeof e==`object`&&[`id`,`name`,`preview`,`path`].every(t=>typeof e[t]==`string`);function vv(){try{let e=JSON.parse(localStorage.getItem(gv)??`{}`);return{prompt:typeof e.prompt==`string`?e.prompt:``,images:Array.isArray(e.images)?e.images.filter(_v):[]}}catch{return{prompt:``,images:[]}}}function yv(e){try{!e.prompt&&!e.images.length?localStorage.removeItem(gv):localStorage.setItem(gv,JSON.stringify(e))}catch{}}var bv=()=>yv({prompt:``,images:[]}),xv=(e,t)=>`webr-last-harness:${e}:${t}`;function Sv({projects:e,machines:t,selectedProjectId:n,onOpenSidebar:r}){let[i,o]=(0,l.useState)(e.find(e=>e.id===n)?.id??e[0]?.id??``),[s,c]=(0,l.useState)(t.find(e=>n&&Object.hasOwn(e.projectPaths,n))?.id??t[0]?.id??``),[u,d]=(0,l.useState)(``),[f,p]=(0,l.useState)(`Default`),[m,h]=(0,l.useState)(!0),[g,v]=(0,l.useState)(``),[y,b]=(0,l.useState)(!1),[x,S]=(0,l.useState)(``),[C,w]=(0,l.useState)(!1),T=(0,l.useRef)(null),E=(0,l.useRef)(null),D=fm({machineId:s}),O=t.find(e=>e.id===s)??{id:``,name:`No target`,connected:!1,session:``,projectPaths:{},harnesses:[]},A=$_(s,O.connected,O.configVersion,O.session,i),j={...O,harnesses:O.connected?A.data?.harnesses??[]:[]},N=e.filter(e=>Object.hasOwn(j.projectPaths,e.id)).map(e=>({...e,path:j.projectPaths[e.id],iconUrl:s===`local`?e.iconUrl:void 0})),P=A.data?.isGitRepo===!0,F=j.harnesses.find(e=>e.id===u),I=!!(g.trim()&&!D.uploading&&f.trim()&&j.connected&&N.some(e=>e.id===i)&&F?.launchEnabled)&&!y,L=A.data?.harnesses.map(e=>e.id).join(`,`),R=(0,l.useRef)(!1);(0,l.useEffect)(()=>{let e=vv();v(e.prompt),D.setAttachments(e.images),R.current=!0},[]),(0,l.useEffect)(()=>{R.current&&yv({prompt:g,images:D.attachments})},[g,D.attachments]),(0,l.useEffect)(()=>{h(hv(s,i))},[s,i]),(0,l.useEffect)(()=>{if(!i||!A.data)return;let e=A.data.harnesses,t=localStorage.getItem(xv(s,i));d(e.find(e=>e.id===t)?.id??e.find(e=>e.launchEnabled)?.id??e[0]?.id??``),p(`Default`)},[s,i,L]),(0,l.useEffect)(()=>{let e=T.current,t=e&&N.find(t=>!e.has(t.id));t&&(T.current=null,ee(t.id))},[N]),(0,l.useEffect)(()=>{!s&&t.length&&c(t.find(e=>e.id===`local`)?.id??t[0].id),!i&&N.length&&o(N[0].id)},[t,s,N,i]);let z=n=>{let r=t.find(e=>e.id===n);r?.connected&&(c(n),Object.hasOwn(r.projectPaths,i)||o(e.find(e=>Object.hasOwn(r.projectPaths,e.id))?.id??``),d(``),p(`Default`),S(``))},ee=e=>{o(e),d(``),p(`Default`),S(``)},B=e=>{d(e),p(`Default`),i&&localStorage.setItem(xv(s,i),e)};return(0,Q.jsxs)(`main`,{className:`new-thread-page`,"aria-label":`New thread`,children:[(0,Q.jsx)(`button`,{className:`mobile-menu`,onClick:r,children:`Threads`}),(0,Q.jsx)(`h1`,{children:`What do you want to build today?`}),j.connected&&j.writable&&(!N.length||C)?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`p`,{children:N.length?`Add a project to this Herdr session.`:`This Herdr session has no projects yet.`}),(0,Q.jsx)(iv,{machineId:j.id,onCreated:()=>{T.current=new Set(N.map(e=>e.id)),w(!1)}}),!!N.length&&(0,Q.jsx)(`button`,{className:`workspace-cancel`,onClick:()=>w(!1),children:`Cancel`})]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`form`,{className:`thread-composer ${D.dragging?`is-dropping`:``}`,onSubmit:async e=>{if(e.preventDefault(),!I)return;b(!0),S(``);let t=JSON.stringify({prompt:dm(g,D.attachments),projectId:i,machineId:s,agent:u,model:f.trim(),worktree:m&&P});E.current?.payload!==t&&(E.current={payload:t,key:cm()});try{let e=await fetch(`/api/threads`,{method:`POST`,headers:{"Content-Type":`application/json`,"Idempotency-Key":E.current.key},body:t}),n=await e.json();if(!e.ok)throw Error(n.error||`Could not create thread`);pv(s,i,m),bv(),await a(`/threads/${encodeURIComponent(n.id)}`)}catch(e){S(e instanceof Error?e.message:`Could not create thread`),b(!1)}},"aria-busy":y,...D.handlers,children:[(D.attachments.length>0||D.uploading>0)&&(0,Q.jsxs)(`ul`,{className:`composer-images`,"aria-label":`Attached files`,children:[D.attachments.map(e=>(0,Q.jsxs)(`li`,{className:e.preview?void 0:`is-file`,children:[e.preview?(0,Q.jsx)(`img`,{src:e.preview,alt:e.name}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(k,{size:18,strokeWidth:1.8}),(0,Q.jsx)(`span`,{children:e.name})]}),(0,Q.jsx)(Yl,{label:`Remove file`,children:(0,Q.jsx)(`button`,{type:`button`,"aria-label":`Remove ${e.name}`,onClick:()=>D.remove(e.id),children:(0,Q.jsx)(fe,{size:12,strokeWidth:2.4})})})]},e.id)),Array.from({length:D.uploading},(e,t)=>(0,Q.jsx)(`li`,{className:`is-uploading`,"aria-label":`Uploading file`},`uploading-`+t))]}),(0,Q.jsx)(`textarea`,{autoFocus:!0,required:!0,maxLength:8e3,value:g,onChange:e=>v(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),e.currentTarget.form?.requestSubmit())},"aria-label":`Thread prompt`,placeholder:`Write a prompt, or drop an image…`}),(0,Q.jsxs)(`div`,{className:`composer-toolbar`,children:[(0,Q.jsx)(Eg,{machine:j,machines:t,projects:N,projectId:i,harness:u,model:f,onMachineChange:z,onProjectChange:ee,onHarnessChange:B,onModelChange:p,onAddProject:j.connected&&j.writable?()=>w(!0):void 0}),P&&(0,Q.jsx)(Yl,{label:m?`new worktree`:`current checkout`,children:(0,Q.jsxs)(`label`,{className:`worktree-option`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:m,onChange:e=>h(e.target.checked),"aria-label":`Create a new worktree`}),(0,Q.jsx)(M,{size:15,"aria-hidden":`true`})]})}),(0,Q.jsx)(`div`,{className:`composer-actions`,children:(0,Q.jsx)(Yl,{label:`Create thread`,children:(0,Q.jsx)(`button`,{className:`composer-send`,type:`submit`,disabled:!I,"aria-label":`Create thread`,children:y?`…`:(0,Q.jsx)(_,{size:18,strokeWidth:2.2})})})})]})]}),(F?.reason||!t.length||j.error||A.isError)&&(0,Q.jsx)(`p`,{className:`composer-preview-note`,children:F?.reason??(t.length?j.error?`Machine is not connected: ${j.error.replaceAll(`_`,` `)}.`:`The machine catalog is not available.`:`No target is configured.`)}),D.error&&(0,Q.jsx)(`p`,{className:`form-error`,role:`alert`,children:D.error}),x&&(0,Q.jsx)(`p`,{className:`form-error`,role:`alert`,children:x})]})]})}var Cv=es(function(e){return Ec(`dialog`,e)}),wv=52,Tv=`?`;function Ev(e){let t=e.slice(e.indexOf(`;`)+1);if(e.includes(`;`)&&t&&t!==Tv)try{return new TextDecoder(`utf-8`,{fatal:!0}).decode(Uint8Array.from(atob(t),e=>e.charCodeAt(0)))}catch{return}}function Dv(e){let t=t=>{t.clipboardData?.setData(`text/plain`,e),t.preventDefault()};document.addEventListener(`copy`,t,!0);try{return document.execCommand(`copy`)}catch{return!1}finally{document.removeEventListener(`copy`,t,!0)}}async function Ov(e){try{return await navigator.clipboard.writeText(e),!0}catch{return Dv(e)}}var kv=e=>(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement)&&e.selectionStart!==e.selectionEnd||!!document.getSelection()?.toString();function Av(e,t,n,r){let i=()=>{t.hasSelection()&&Ov(t.getSelection()).then(r)},a=e=>{e.defaultPrevented||!t.hasSelection()||kv(e.target)||(e.clipboardData?.setData(`text/plain`,t.getSelection()),e.preventDefault(),r(!0))},o=t.parser.registerOscHandler(wv,e=>{let t=Ev(e);return t!==void 0&&n()&&Ov(t).then(r),!0});return e.addEventListener(`mouseup`,i),window.addEventListener(`copy`,a),()=>{o.dispose(),e.removeEventListener(`mouseup`,i),window.removeEventListener(`copy`,a)}}var jv=(e=>(e[e.Border=-1]=`Border`,e[e.Data=0]=`Data`,e[e.Function=1]=`Function`,e[e.Position=2]=`Position`,e[e.Timing=3]=`Timing`,e[e.Alignment=4]=`Alignment`,e))(jv||{}),Mv=[0,1],Nv=[1,0],Pv=[2,3],Fv=[3,2],Iv={L:Mv,M:Nv,Q:Pv,H:Fv},Lv=/^\d*$/,Rv=/^[A-Z0-9 $%*+./:-]*$/,zv=`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:`,Bv=1,Vv=40,Hv=3,Uv=3,Wv=40,Gv=10,Kv=[[-1,7,10,15,20,26,18,20,24,30,18,20,24,26,30,22,24,28,30,28,28,28,28,30,30,26,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,10,16,26,18,24,16,18,22,22,26,30,22,22,24,24,28,28,26,26,26,26,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28],[-1,13,22,18,26,18,24,18,22,20,24,28,26,24,20,30,24,28,28,26,30,28,30,30,30,30,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,17,28,22,16,22,28,26,26,24,28,24,28,22,24,24,30,28,28,26,28,30,24,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30]],qv=[[-1,1,1,1,1,1,2,2,2,2,4,4,4,4,4,6,6,6,6,7,8,8,9,9,10,12,12,12,13,14,15,16,17,18,19,19,20,21,22,24,25],[-1,1,1,1,2,2,4,4,4,5,5,5,8,9,9,10,10,11,13,14,16,17,17,18,20,21,23,25,26,28,29,31,33,35,37,38,40,43,45,47,49],[-1,1,1,2,2,4,4,6,6,8,8,8,10,12,16,12,17,16,18,21,20,23,23,25,27,29,34,34,35,38,40,43,45,48,51,53,56,59,62,65,68],[-1,1,1,2,4,4,4,5,6,8,8,11,11,16,16,18,16,19,21,25,25,25,34,30,32,35,37,40,42,45,48,51,54,57,60,63,66,70,74,77,81]],Jv=class{constructor(e,t,n,r){if(this.version=e,this.ecc=t,e<Bv||e>Vv)throw RangeError(`Version value out of range`);if(r<-1||r>7)throw RangeError(`Mask value out of range`);this.size=e*4+17;let i=Array.from({length:this.size}).fill(!1);for(let e=0;e<this.size;e++)this.modules.push(i.slice()),this.types.push(i.map(()=>0));this.drawFunctionPatterns();let a=this.addEccAndInterleave(n);if(this.drawCodewords(a),r===-1){let e=1e9;for(let t=0;t<8;t++){this.applyMask(t),this.drawFormatBits(t);let n=this.getPenaltyScore();n<e&&(r=t,e=n),this.applyMask(t)}}this.mask=r,this.applyMask(r),this.drawFormatBits(r)}size;mask;modules=[];types=[];getModule(e,t){return e>=0&&e<this.size&&t>=0&&t<this.size&&this.modules[t][e]}drawFunctionPatterns(){for(let e=0;e<this.size;e++)this.setFunctionModule(6,e,e%2==0,jv.Timing),this.setFunctionModule(e,6,e%2==0,jv.Timing);this.drawFinderPattern(3,3),this.drawFinderPattern(this.size-4,3),this.drawFinderPattern(3,this.size-4);let e=this.getAlignmentPatternPositions(),t=e.length;for(let n=0;n<t;n++)for(let r=0;r<t;r++)n===0&&r===0||n===0&&r===t-1||n===t-1&&r===0||this.drawAlignmentPattern(e[n],e[r]);this.drawFormatBits(0),this.drawVersion()}drawFormatBits(e){let t=this.ecc[1]<<3|e,n=t;for(let e=0;e<10;e++)n=n<<1^(n>>>9)*1335;let r=(t<<10|n)^21522;for(let e=0;e<=5;e++)this.setFunctionModule(8,e,Xv(r,e));this.setFunctionModule(8,7,Xv(r,6)),this.setFunctionModule(8,8,Xv(r,7)),this.setFunctionModule(7,8,Xv(r,8));for(let e=9;e<15;e++)this.setFunctionModule(14-e,8,Xv(r,e));for(let e=0;e<8;e++)this.setFunctionModule(this.size-1-e,8,Xv(r,e));for(let e=8;e<15;e++)this.setFunctionModule(8,this.size-15+e,Xv(r,e));this.setFunctionModule(8,this.size-8,!0)}drawVersion(){if(this.version<7)return;let e=this.version;for(let t=0;t<12;t++)e=e<<1^(e>>>11)*7973;let t=this.version<<12|e;for(let e=0;e<18;e++){let n=Xv(t,e),r=this.size-11+e%3,i=Math.floor(e/3);this.setFunctionModule(r,i,n),this.setFunctionModule(i,r,n)}}drawFinderPattern(e,t){for(let n=-4;n<=4;n++)for(let r=-4;r<=4;r++){let i=Math.max(Math.abs(r),Math.abs(n)),a=e+r,o=t+n;a>=0&&a<this.size&&o>=0&&o<this.size&&this.setFunctionModule(a,o,i!==2&&i!==4,jv.Position)}}drawAlignmentPattern(e,t){for(let n=-2;n<=2;n++)for(let r=-2;r<=2;r++)this.setFunctionModule(e+r,t+n,Math.max(Math.abs(r),Math.abs(n))!==1,jv.Alignment)}setFunctionModule(e,t,n,r=jv.Function){this.modules[t][e]=n,this.types[t][e]=r}addEccAndInterleave(e){let t=this.version,n=this.ecc;if(e.length!==dy(t,n))throw RangeError(`Invalid argument`);let r=qv[n[0]][t],i=Kv[n[0]][t],a=Math.floor(uy(t)/8),o=r-a%r,s=Math.floor(a/r),c=[],l=fy(i);for(let t=0,n=0;t<r;t++){let r=e.slice(n,n+s-i+(t<o?0:1));n+=r.length;let a=py(r,l);t<o&&r.push(0),c.push(r.concat(a))}let u=[];for(let e=0;e<c[0].length;e++)c.forEach((t,n)=>{(e!==s-i||n>=o)&&u.push(t[e])});return u}drawCodewords(e){if(e.length!==Math.floor(uy(this.version)/8))throw RangeError(`Invalid argument`);let t=0;for(let n=this.size-1;n>=1;n-=2){n===6&&(n=5);for(let r=0;r<this.size;r++)for(let i=0;i<2;i++){let a=n-i,o=n+1&2?r:this.size-1-r;!this.types[o][a]&&t<e.length*8&&(this.modules[o][a]=Xv(e[t>>>3],7-(t&7)),t++)}}}applyMask(e){if(e<0||e>7)throw RangeError(`Mask value out of range`);for(let t=0;t<this.size;t++)for(let n=0;n<this.size;n++){let r;switch(e){case 0:r=(n+t)%2==0;break;case 1:r=t%2==0;break;case 2:r=n%3==0;break;case 3:r=(n+t)%3==0;break;case 4:r=(Math.floor(n/3)+Math.floor(t/2))%2==0;break;case 5:r=n*t%2+n*t%3==0;break;case 6:r=(n*t%2+n*t%3)%2==0;break;case 7:r=((n+t)%2+n*t%3)%2==0;break;default:throw Error(`Unreachable`)}!this.types[t][n]&&r&&(this.modules[t][n]=!this.modules[t][n])}}getPenaltyScore(){let e=0;for(let t=0;t<this.size;t++){let n=!1,r=0,i=[0,0,0,0,0,0,0];for(let a=0;a<this.size;a++)this.modules[t][a]===n?(r++,r===5?e+=Hv:r>5&&e++):(this.finderPenaltyAddHistory(r,i),n||(e+=this.finderPenaltyCountPatterns(i)*Wv),n=this.modules[t][a],r=1);e+=this.finderPenaltyTerminateAndCount(n,r,i)*Wv}for(let t=0;t<this.size;t++){let n=!1,r=0,i=[0,0,0,0,0,0,0];for(let a=0;a<this.size;a++)this.modules[a][t]===n?(r++,r===5?e+=Hv:r>5&&e++):(this.finderPenaltyAddHistory(r,i),n||(e+=this.finderPenaltyCountPatterns(i)*Wv),n=this.modules[a][t],r=1);e+=this.finderPenaltyTerminateAndCount(n,r,i)*Wv}for(let t=0;t<this.size-1;t++)for(let n=0;n<this.size-1;n++){let r=this.modules[t][n];r===this.modules[t][n+1]&&r===this.modules[t+1][n]&&r===this.modules[t+1][n+1]&&(e+=Uv)}let t=0;for(let e of this.modules)t=e.reduce((e,t)=>e+ +!!t,t);let n=this.size*this.size,r=Math.ceil(Math.abs(t*20-n*10)/n)-1;return e+=r*Gv,e}getAlignmentPatternPositions(){if(this.version===1)return[];{let e=Math.floor(this.version/7)+2,t=this.version===32?26:Math.ceil((this.version*4+4)/(e*2-2))*2,n=[6];for(let r=this.size-7;n.length<e;r-=t)n.splice(1,0,r);return n}}finderPenaltyCountPatterns(e){let t=e[1],n=t>0&&e[2]===t&&e[3]===t*3&&e[4]===t&&e[5]===t;return(n&&e[0]>=t*4&&e[6]>=t?1:0)+(n&&e[6]>=t*4&&e[0]>=t?1:0)}finderPenaltyTerminateAndCount(e,t,n){return e&&(this.finderPenaltyAddHistory(t,n),t=0),t+=this.size,this.finderPenaltyAddHistory(t,n),this.finderPenaltyCountPatterns(n)}finderPenaltyAddHistory(e,t){t[0]===0&&(e+=this.size),t.pop(),t.unshift(e)}};function Yv(e,t,n){if(t<0||t>31||e>>>t)throw RangeError(`Value out of range`);for(let r=t-1;r>=0;r--)n.push(e>>>r&1)}function Xv(e,t){return!!(e>>>t&1)}var Zv=class{constructor(e,t,n){if(this.mode=e,this.numChars=t,this.bitData=n,t<0)throw RangeError(`Invalid argument`);this.bitData=n.slice()}getData(){return this.bitData.slice()}},Qv=[1,10,12,14],$v=[2,9,11,13],ey=[4,8,16,16];function ty(e,t){return e[Math.floor((t+7)/17)+1]}function ny(e){let t=[];for(let n of e)Yv(n,8,t);return new Zv(ey,e.length,t)}function ry(e){if(!oy(e))throw RangeError(`String contains non-numeric characters`);let t=[];for(let n=0;n<e.length;){let r=Math.min(e.length-n,3);Yv(Number.parseInt(e.substring(n,n+r),10),r*3+1,t),n+=r}return new Zv(Qv,e.length,t)}function iy(e){if(!sy(e))throw RangeError(`String contains unencodable characters in alphanumeric mode`);let t=[],n=0;for(;n+2<=e.length;n+=2){let r=zv.indexOf(e.charAt(n))*45;r+=zv.indexOf(e.charAt(n+1)),Yv(r,11,t)}return n<e.length&&Yv(zv.indexOf(e.charAt(n)),6,t),new Zv($v,e.length,t)}function ay(e){return e===``?[]:oy(e)?[ry(e)]:sy(e)?[iy(e)]:[ny(ly(e))]}function oy(e){return Lv.test(e)}function sy(e){return Rv.test(e)}function cy(e,t){let n=0;for(let r of e){let e=ty(r.mode,t);if(r.numChars>=1<<e)return 1/0;n+=4+e+r.bitData.length}return n}function ly(e){e=encodeURI(e);let t=[];for(let n=0;n<e.length;n++)e.charAt(n)===`%`?(t.push(Number.parseInt(e.substring(n+1,n+3),16)),n+=2):t.push(e.charCodeAt(n));return t}function uy(e){if(e<Bv||e>Vv)throw RangeError(`Version number out of range`);let t=(16*e+128)*e+64;if(e>=2){let n=Math.floor(e/7)+2;t-=(25*n-10)*n-55,e>=7&&(t-=36)}return t}function dy(e,t){return Math.floor(uy(e)/8)-Kv[t[0]][e]*qv[t[0]][e]}function fy(e){if(e<1||e>255)throw RangeError(`Degree out of range`);let t=[];for(let n=0;n<e-1;n++)t.push(0);t.push(1);let n=1;for(let r=0;r<e;r++){for(let e=0;e<t.length;e++)t[e]=my(t[e],n),e+1<t.length&&(t[e]^=t[e+1]);n=my(n,2)}return t}function py(e,t){let n=t.map(e=>0);for(let r of e){let e=r^n.shift();n.push(0),t.forEach((t,r)=>n[r]^=my(t,e))}return n}function my(e,t){if(e>>>8||t>>>8)throw RangeError(`Byte out of range`);let n=0;for(let r=7;r>=0;r--)n=n<<1^(n>>>7)*285,n^=(t>>>r&1)*e;return n}function hy(e,t,n=1,r=40,i=-1,a=!0){if(!(Bv<=n&&n<=r&&r<=Vv)||i<-1||i>7)throw RangeError(`Invalid value`);let o,s;for(o=n;;o++){let n=dy(o,t)*8,i=cy(e,o);if(i<=n){s=i;break}if(o>=r)throw RangeError(`Data too long`)}for(let e of[Nv,Pv,Fv])a&&s<=dy(o,e)*8&&(t=e);let c=[];for(let t of e){Yv(t.mode[0],4,c),Yv(t.numChars,ty(t.mode,o),c);for(let e of t.getData())c.push(e)}let l=dy(o,t)*8;Yv(0,Math.min(4,l-c.length),c),Yv(0,(8-c.length%8)%8,c);for(let e=236;c.length<l;e^=253)Yv(e,8,c);let u=Array.from({length:Math.ceil(c.length/8)},()=>0);return c.forEach((e,t)=>u[t>>>3]|=e<<7-(t&7)),new Jv(o,t,u,i)}function gy(e,t){let{ecc:n=`L`,boostEcc:r=!1,minVersion:i=1,maxVersion:a=40,maskPattern:o=-1,border:s=1}=t||{},c=typeof e==`string`?ay(e):Array.isArray(e)?[ny(e)]:void 0;if(!c)throw Error(`uqr only supports encoding string and binary data, but got: ${typeof e}`);let l=hy(c,Iv[n],i,a,o,r),u=_y({version:l.version,maskPattern:l.mask,size:l.size,data:l.modules,types:l.types},s);return t?.invert&&(u.data=u.data.map(e=>e.map(e=>!e))),t?.onEncoded?.(u),u}function _y(e,t=1){if(!t)return e;let{size:n}=e,r=n+t*2;e.size=r,e.data.forEach(e=>{for(let n=0;n<t;n++)e.unshift(!1),e.push(!1)});for(let n=0;n<t;n++)e.data.unshift(Array.from({length:r},e=>!1)),e.data.push(Array.from({length:r},e=>!1));let i=jv.Border;e.types.forEach(e=>{for(let n=0;n<t;n++)e.unshift(i),e.push(i)});for(let n=0;n<t;n++)e.types.unshift(Array.from({length:r},e=>i)),e.types.push(Array.from({length:r},e=>i));return e}var vy=2;function yy({value:e,label:t}){let{data:n,size:r}=gy(e),i=n.flatMap((e,t)=>e.flatMap((e,n)=>e?[`M${n+vy} ${t+vy}h1v1h-1z`]:[])),a=r+4;return(0,Q.jsxs)(`svg`,{className:`qr-code`,role:`img`,"aria-label":t,viewBox:`0 0 ${a} ${a}`,shapeRendering:`crispEdges`,children:[(0,Q.jsx)(`rect`,{width:a,height:a,fill:`#fff`}),(0,Q.jsx)(`path`,{d:i.join(``),fill:`#000`})]})}function by(){let[e,t]=(0,l.useState)(Vp);return!Bp()||e!=="default"?null:(0,Q.jsxs)(`div`,{className:`settings-row`,children:[(0,Q.jsxs)(`span`,{children:[`Notify me about new requests`,(0,Q.jsx)(`small`,{className:`device-meta`,children:`Shown when Webr is open in a hidden tab.`})]}),(0,Q.jsx)(`button`,{type:`button`,className:`dialog-button`,onClick:()=>void Hp().then(t),children:`Turn on`})]})}var xy=8;function Sy({refreshKey:e}){let[t,n]=(0,l.useState)([]);return(0,l.useEffect)(()=>{Ap().then(n,()=>void 0)},[e]),t.length?(0,Q.jsxs)(`div`,{className:`remote-activity`,children:[(0,Q.jsx)(`h3`,{className:`settings-subtitle`,children:`Recent activity`}),t.slice(0,xy).map(e=>(0,Q.jsxs)(`p`,{className:`activity-row`,children:[(0,Q.jsx)(`span`,{children:Up(e)}),(0,Q.jsx)(`time`,{dateTime:new Date(e.at).toISOString(),children:zp(e.at)})]},e.id))]}):null}function Cy({invite:e,onClose:t}){let[n,r]=(0,l.useState)(0),[i,a]=(0,l.useState)(!1),o=e.urls[n],s=e=>Ov(e).then(e=>{e&&(a(!0),setTimeout(()=>a(!1),1500))}),c=()=>s(e.token),u=t=>{r(t),s(e.urls[t])};return(0,Q.jsx)(Cv,{open:!0,onOpenChange:e=>{e||t()},children:(0,Q.jsxs)(Jc,{children:[(0,Q.jsx)(Oc,{className:`dialog-backdrop`}),(0,Q.jsxs)(Gc,{className:`dialog pairing-invite`,children:[(0,Q.jsx)(Yc,{className:`pairing-title`,children:`Connect a device`}),o?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(Rc,{className:`dialog-message`,children:`Scan with the device’s camera, or open Webr there and enter the code.`}),(0,Q.jsx)(yy,{value:o,label:`QR code to connect a device`}),e.urls.length>1&&(0,Q.jsx)(`div`,{className:`theme-control theme-control--labels`,role:`group`,"aria-label":`Address`,children:e.urls.map((e,t)=>(0,Q.jsx)(`button`,{type:`button`,"aria-pressed":t===n,className:t===n?`theme-option is-selected`:`theme-option`,onClick:()=>u(t),children:new URL(e).host},e))})]}):(0,Q.jsxs)(Rc,{className:`dialog-message`,children:[`No network address was found for other devices. Start Webr with `,(0,Q.jsx)(`code`,{children:`--origin <url>`}),` if you reach it through a proxy.`]}),(0,Q.jsxs)(`div`,{className:`pairing-token`,children:[(0,Q.jsx)(`code`,{children:e.token}),(0,Q.jsx)(`button`,{type:`button`,className:`dialog-button`,onClick:()=>void c(),"aria-label":`Copy code`,children:i?(0,Q.jsx)(y,{size:14}):(0,Q.jsx)(D,{size:14})})]}),(0,Q.jsx)(`p`,{className:`settings-note`,children:`Works once and expires in 5 minutes.`}),(0,Q.jsx)(`div`,{className:`dialog-actions`,children:(0,Q.jsx)(Ic,{className:`dialog-button is-primary`,children:`Done`})})]})]})})}var wy={unavailable:`Install Tailscale on this computer and your other devices to get a private, secure HTTPS address for Webr. HTTPS unlocks features browsers only allow on secure pages, such as the microphone.`,"https-disabled":`Tailscale is installed, but HTTPS certificates are off. Turn them on in the Tailscale admin console under DNS, then restart Webr to unlock features that need a secure address, such as the microphone.`};function Ty(){let[e,t]=(0,l.useState)(`ready`);return(0,l.useEffect)(()=>{jp().then(t,()=>void 0)},[]),e===`ready`?null:(0,Q.jsx)(`p`,{className:`tailscale-callout`,role:`note`,children:wy[e]})}function Ey(){let[e,t]=(0,l.useState)([]),[n,r]=(0,l.useState)(),[i,a]=(0,l.useState)(``),o=(0,l.useCallback)(()=>kp().then(t,()=>void 0),[]);(0,l.useEffect)(()=>{o()},[o]);let s=()=>Op().then(e=>{a(``),r(e)},e=>a(e.message)),c=async e=>{await al(`Disconnect ${e.name}? It will need to be approved again.`,{confirmLabel:`Disconnect`,danger:!0})&&(await Mp(e.id),e.current?location.reload():await o())};return(0,Q.jsxs)(`section`,{id:`remote-access`,children:[(0,Q.jsx)(`div`,{className:`settings-section-title`,children:(0,Q.jsx)(`h2`,{children:`Remote access`})}),(0,Q.jsx)(`p`,{className:`settings-note`,children:`Other devices ask to connect and you approve them here. This computer never needs a code.`}),(0,Q.jsx)(Ty,{}),(0,Q.jsxs)(`div`,{className:`settings-row`,children:[(0,Q.jsx)(`span`,{children:`Connect a device`}),(0,Q.jsx)(`button`,{type:`button`,className:`dialog-button`,onClick:()=>void s(),children:`Show code`})]}),(0,Q.jsx)(by,{}),i&&(0,Q.jsx)(`p`,{role:`alert`,className:`form-error`,children:i}),e.map(e=>(0,Q.jsxs)(`div`,{className:`settings-row`,children:[(0,Q.jsxs)(`span`,{children:[e.name,e.current&&(0,Q.jsx)(`em`,{className:`device-tag`,children:`This device`}),(0,Q.jsxs)(`small`,{className:`device-meta`,children:[`Active `,zp(e.lastSeenAt),` · Signs out `,Wp(e.expiresAt),` if unused`]})]}),(0,Q.jsx)(`button`,{type:`button`,className:`dialog-button`,onClick:()=>void c(e),children:`Disconnect`})]},e.id)),(0,Q.jsx)(Sy,{refreshKey:e}),n&&(0,Q.jsx)(Cy,{invite:n,onClose:()=>r(void 0)})]})}function Dy({onOpenSidebar:e}){let[t,n]=(0,l.useState)(`worktree`),[r,i]=(0,l.useState)(Yf),[a,o]=(0,l.useState)(null),[s,c]=(0,l.useState)(``);(0,l.useEffect)(()=>{n(dv()),i(Xf())},[]);let u=(e,t)=>{if(e.preventDefault(),e.stopPropagation(),e.key===`Escape`){o(null),c(``);return}let n=$f(e);if(!n)return;if(ep(n)||n===`meta+k`){c(`Choose a shortcut with a modifier that does not conflict with the browser or ⌘K.`);return}if(Object.entries(r).some(([e,r])=>e!==t&&r===n)){c(`That shortcut is already in use.`);return}let a={...r,[t]:n};i(a),localStorage.setItem(`webr-shortcuts`,JSON.stringify(a)),o(null),c(``)};return(0,Q.jsxs)(`main`,{className:`form-page settings-page`,children:[(0,Q.jsx)(`button`,{className:`mobile-menu`,onClick:e,children:`Threads`}),(0,Q.jsx)(`h1`,{children:`Settings`}),(0,Q.jsxs)(`section`,{children:[(0,Q.jsx)(`h2`,{children:`Appearance`}),(0,Q.jsxs)(`div`,{className:`settings-row`,children:[(0,Q.jsx)(`span`,{children:`Theme`}),(0,Q.jsx)(np,{expanded:!0})]})]}),(0,Q.jsxs)(`section`,{children:[(0,Q.jsx)(`h2`,{children:`New threads`}),(0,Q.jsxs)(`div`,{className:`settings-row`,children:[(0,Q.jsx)(`span`,{children:`New session behavior`}),(0,Q.jsx)(`div`,{className:`theme-control theme-control--labels`,role:`group`,"aria-label":`New session behavior`,children:Object.keys(av).map(e=>(0,Q.jsx)(`button`,{type:`button`,"aria-pressed":t===e,className:t===e?`theme-option is-selected`:`theme-option`,onClick:()=>{n(e),fv(e)},children:av[e]},e))})]})]}),(0,Q.jsx)(Ey,{}),(0,Q.jsxs)(`section`,{id:`shortcuts`,children:[(0,Q.jsxs)(`div`,{className:`settings-section-title`,children:[(0,Q.jsx)(`h2`,{children:`Keyboard shortcuts`}),(0,Q.jsx)(`button`,{onClick:()=>{i(Yf),localStorage.removeItem(`webr-shortcuts`),o(null),c(``)},children:`Reset`})]}),(0,Q.jsx)(`p`,{className:`settings-note`,children:`Press ⌘K for all actions and threads.`}),Object.keys(Jf).map(e=>(0,Q.jsxs)(`div`,{className:`settings-row`,children:[(0,Q.jsx)(`span`,{children:Jf[e]}),(0,Q.jsx)(`button`,{className:`shortcut-key`,"data-recording":a===e,onClick:()=>{o(e),c(``)},onKeyDown:t=>a===e&&u(t,e),"aria-label":`Change ${Jf[e]} shortcut`,children:a===e?`Press keys…`:Zf(r[e]).map((e,t)=>(0,Q.jsx)(`kbd`,{children:e},t))})]},e)),s&&(0,Q.jsx)(`p`,{role:`alert`,className:`form-error`,children:s})]})]})}var Oy=l.createContext(void 0);function ky(e=!0){let t=l.useContext(Oy);if(t===void 0&&!e)throw Error(Ai(25));return t}var Ay=l.createContext(void 0);function jy(e){let t=l.useContext(Ay);if(t===void 0&&!e)throw Error(Ai(33));return t}var My=l.createContext(void 0);function Ny(e){let t=l.useContext(My);if(t===void 0&&!e)throw Error(Ai(36));return t}function Py(e){let{closeOnClick:t,highlighted:n,id:r,nodeId:i,store:a,typingRef:o,itemRef:s,itemMetadata:c}=e,{events:u}=a.useState(`floatingTreeRoot`),d=a.useState(`open`),f=ky(!0),p=f!==void 0;return l.useMemo(()=>({id:r,role:`menuitem`,tabIndex:d&&n?0:-1,onKeyDown(e){e.key===` `&&o?.current&&e.preventDefault()},onMouseMove(e){i&&u.emit(`itemhover`,{nodeId:i,target:e.currentTarget})},onClick(e){t&&u.emit(`close`,{domEvent:e,reason:vn})},onMouseUp(e){if(f){let t=f.initialCursorPointRef.current;if(f.initialCursorPointRef.current=null,p&&t&&Math.abs(e.clientX-t.x)<=1&&Math.abs(e.clientY-t.y)<=1||p&&!We&&e.button===2)return}s.current&&a.context.allowMouseUpTriggerRef.current&&(!p||e.button===2)&&c.type===`regular-item`&&Mc(s.current,e,{detail:1})}}),[t,n,r,u,i,d,a,o,s,f,p,c])}var Fy={type:`regular-item`};function Iy(e){let{closeOnClick:t,disabled:n,highlighted:r,id:i,store:a,typingRef:o=a.context.typingRef,nativeButton:s,itemMetadata:c,nodeId:u}=e,d=l.useRef(null),{getButtonProps:f,buttonRef:p}=Nc({disabled:n,focusableWhenDisabled:!0,native:s,composite:!0}),m=Py({closeOnClick:t,highlighted:r,id:i,nodeId:u,store:a,typingRef:o,itemRef:d,itemMetadata:c}),h=l.useCallback(e=>zi(m,{onMouseEnter(){c.type===`submenu-trigger`&&c.setActive()}},e,f),[m,f,c]),g=Rn(d,p);return l.useMemo(()=>({getItemProps:h,itemRef:g}),[h,g])}var Ly=l.forwardRef(function(e,t){let{render:n,className:r,id:i,label:a,nativeButton:o=!1,disabled:s=!1,closeOnClick:c=!0,style:l,...u}=e,d=og({guess:!0,label:a}),f=jy(!0),p=Lc(i),{store:m}=Ny(),h=m.useState(`disabled`),g=s||h,_=m.useState(`isActive`,d.index),v=m.useState(`itemProps`),{getItemProps:y,itemRef:b}=Iy({closeOnClick:c,disabled:g,highlighted:_,id:p,store:m,nativeButton:o,nodeId:f?.context.nodeId,itemMetadata:Fy});return $i(`div`,e,{state:{disabled:g,highlighted:_},props:[v,u,y],ref:[b,t,d.ref]})}),Ry=l.createContext(void 0);function zy(e){let t=l.useContext(Ry);if(t===void 0&&!e)throw Error(Ai(69));return t}var By=l.forwardRef(function(e,t){let{render:n,className:r,style:i,finalFocus:a,...o}=e,{store:s}=Ny(),{side:c,align:u}=jy(),d=zy(!0)!=null,f=s.useState(`open`),p=s.useState(`transitionStatus`),m=s.useState(`popupProps`),h=s.useState(`mounted`),g=s.useState(`instantType`),_=s.useState(`activeTriggerElement`),v=s.useState(`parent`),y=s.useState(`lastOpenChangeReason`),b=s.useState(`rootId`),x=s.useState(`floatingRootContext`),S=s.useState(`floatingTreeRoot`),C=s.useState(`closeDelay`),w=s.useState(`hoverEnabled`),T=s.useState(`disabled`),E=s.useState(`openMethod`),D=v.type===`context-menu`;ys({open:f,ref:s.context.popupRef,onComplete(){f&&s.context.onOpenChangeComplete?.(!0)}}),l.useEffect(()=>{function e(e){s.setOpen(!1,Z(e.reason,e.domEvent))}return S.events.on(`close`,e),()=>{S.events.off(`close`,e)}},[S.events,s]),$s(x,{enabled:w&&!T&&!D&&v.type!==`menubar`,closeDelay:C});let O=s.useStateSetter(`popupElement`),k=$i(`div`,e,{state:{transitionStatus:p,side:c,align:u,open:f,nested:v.type===`menu`,instant:g},ref:[t,s.context.popupRef,O],stateAttributesMapping:Zt,props:[m,{onKeyDown(e){d&&Vc.has(e.key)&&e.stopPropagation()}},Gl(p),o,{"data-rootownerid":b}]}),A=v.type===void 0||D;return(_||v.type===`menubar`&&y!==`outside-press`)&&(A=!0),(0,Q.jsx)(Pa,{context:x,openInteractionType:E,modal:D,disabled:!h,returnFocus:a===void 0?A:a,initialFocus:v.type!==`menu`,restoreFocus:!0,externalTree:v.type===`menubar`?void 0:S,previousFocusableElement:_,nextFocusableElement:v.type===void 0?s.context.triggerFocusTargetRef:void 0,beforeContentFocusGuardRef:v.type===void 0?s.context.beforeContentFocusGuardRef:void 0,children:k})}),Vy=l.createContext(void 0);function Hy(){let e=l.useContext(Vy);if(e===void 0)throw Error(Ai(32));return e}var Uy=l.forwardRef(function(e,t){let{keepMounted:n=!1,...r}=e,{store:i,parent:a}=Ny();if(!(i.useState(`mounted`)||n))return null;let o=a.type===`menu`||a.type===`menubar`?`group`:void 0;return(0,Q.jsx)(Vy.Provider,{value:n,children:(0,Q.jsx)(ha,{ref:t,...r,portalOwnerRole:o})})}),Wy=l.forwardRef(function(e,t){let{anchor:n,positionMethod:r=`absolute`,className:i,render:a,side:o,align:s,sideOffset:c=0,alignOffset:u=0,collisionBoundary:d=`clipping-ancestors`,collisionPadding:f=5,arrowPadding:p=5,sticky:m=!1,disableAnchorTracking:h=!1,collisionAvoidance:g=sa,style:_,...v}=e,{store:y}=Ny(),b=Hy(),x=ky(!0),S=y.useState(`parent`),C=y.useState(`floatingRootContext`),w=y.useState(`floatingTreeRoot`),T=y.useState(`mounted`),E=y.useState(`open`),D=y.useState(`modal`),O=y.useState(`openMethod`),k=y.useState(`activeTriggerElement`),A=y.useState(`transitionStatus`),j=y.useState(`positionerElement`),M=y.useState(`instantType`),N=y.useState(`adaptiveOrigin`),P=y.useState(`lastOpenChangeReason`),F=y.useState(`floatingNodeId`),I=y.useState(`floatingParentNodeId`),L=C.useState(`domReferenceElement`),R=l.useRef(null),z=vs(j),ee=n,B=c,te=u,ne=s,re=g;S.type===`context-menu`&&(ee=n??S.context?.anchor,ne??=`start`,!o&&ne!==`center`&&(te=e.alignOffset??2,B=e.sideOffset??-5));let V=o,H=ne;S.type===`menu`?(V??=`inline-end`,H??=`start`,re=e.collisionAvoidance??ca):S.type===`menubar`&&(V??=S.context.orientation===`vertical`?`inline-end`:`bottom`,H??=`start`);let ie=S.type===`context-menu`,ae=Hl({anchor:ee,floatingRootContext:C,positionMethod:x?`fixed`:r,mounted:T,side:V,sideOffset:B,align:H,alignOffset:te,arrowPadding:ie?0:p,collisionBoundary:d,collisionPadding:f,sticky:m,nodeId:F,keepMounted:b,disableAnchorTracking:h,collisionAvoidance:re,shift:ie?{crossAxis:!(`side`in re&&re.side===`flip`),rootBoundary:`layoutViewport`}:void 0,externalTree:w,adaptiveOrigin:N});l.useEffect(()=>{function e(e){e.open&&(e.parentNodeId===F&&y.set(`hoverEnabled`,!1),e.nodeId!==F&&e.parentNodeId===y.select(`floatingParentNodeId`)&&y.setOpen(!1,Z(kn)))}return w.events.on(`menuopenchange`,e),()=>{w.events.off(`menuopenchange`,e)}},[y,w.events,F]),l.useEffect(()=>{if(y.select(`floatingParentNodeId`)==null)return;function e(e){if(e.open||e.nodeId!==y.select(`floatingParentNodeId`))return;let t=e.reason??`sibling-open`;y.setOpen(!1,Z(t))}return w.events.on(`menuopenchange`,e),()=>{w.events.off(`menuopenchange`,e)}},[w.events,y]);let oe=it();l.useEffect(()=>{E||oe.clear()},[E,oe]),l.useEffect(()=>{function e(e){if(E&&e.nodeId===y.select(`floatingParentNodeId`)){if(e.target&&k&&k!==e.target){let e=y.select(`closeDelay`);e>0?oe.isStarted()||oe.start(e,()=>{y.setOpen(!1,Z(kn))}):y.setOpen(!1,Z(kn))}else oe.clear()}}return w.events.on(`itemhover`,e),()=>{w.events.off(`itemhover`,e)}},[w.events,E,k,y,oe]),l.useEffect(()=>{let e={open:E,nodeId:F,parentNodeId:I,reason:y.select(`lastOpenChangeReason`)};w.events.emit(`menuopenchange`,e)},[w.events,E,y,F,I]),U(()=>{let e=L,t=R.current;if(e&&(R.current=e),t&&e&&e!==t){y.set(`instantType`,void 0);let e=new AbortController;return z(()=>{y.set(`instantType`,`trigger-change`)},e.signal),()=>{e.abort()}}},[L,z,y]);let se={open:E,side:ae.side,align:ae.align,anchorHidden:ae.anchorHidden,nested:S.type===`menu`,instant:M},ce=S.type===`menubar`&&S.context.modal;ng(E&&(ce||D&&P!==`trigger-hover`),O===`touch`,j,k);let le=Kl(e,se,{styles:ae.positionerStyles,transitionStatus:A,props:v,refs:[t,y.useStateSetter(`positionerElement`)],hidden:!T,inert:!E}),ue=T&&S.type!==`menu`&&(S.type!==`menubar`&&D&&P!==`trigger-hover`||S.type===`menubar`&&S.context.modal),de=null;return S.type===`menubar`?de=S.context.contentElement:S.type===void 0&&(de=k),(0,Q.jsxs)(Ay.Provider,{value:ae,children:[ue&&(0,Q.jsx)(qc,{ref:S.type===`context-menu`||S.type===`nested-context-menu`?S.context.internalBackdropRef:null,inert:Kc(!E),cutout:de}),(0,Q.jsx)(Ca,{id:F,children:(0,Q.jsx)(Vh,{elementsRef:y.context.itemDomElements,labelsRef:y.context.itemLabels,children:le})})]})}),Gy=l.createContext(null);function Ky(e){let t=l.useContext(Gy);if(t===null&&!e)throw Error(Ai(5));return t}var qy={...Vs,disabled:e=>e.parent.type===`menubar`&&e.parent.context.disabled||e.disabled,modal:e=>(e.parent.type===void 0||e.parent.type===`context-menu`)&&(e.modal??!0),openMethod:e=>e.openMethod,allowMouseEnter:e=>e.allowMouseEnter,highlightItemOnHover:e=>e.highlightItemOnHover,parent:e=>e.parent,rootId:e=>e.parent.type===`menu`?e.parent.store.select(`rootId`):e.parent.type===void 0?e.rootId:e.parent.context.rootId,activeIndex:e=>e.activeIndex,isActive:(e,t)=>e.activeIndex===t,hoverEnabled:e=>e.hoverEnabled,instantType:e=>e.instantType,lastOpenChangeReason:e=>e.openChangeReason,floatingTreeRoot:e=>e.parent.type===`menu`?e.parent.store.select(`floatingTreeRoot`):e.floatingTreeRoot,floatingNodeId:e=>e.floatingNodeId,floatingParentNodeId:e=>e.floatingParentNodeId,itemProps:e=>e.itemProps,closeDelay:e=>e.closeDelay,adaptiveOrigin:e=>e.adaptiveOrigin,keyboardEventRelay:e=>{if(e.keyboardEventRelay)return e.keyboardEventRelay;if(e.parent.type===`menu`)return e.parent.store.select(`keyboardEventRelay`)}},Jy=class extends ds{constructor(e,t,n=!1){let r=new Ps,i=Xy(r,t,n,e);super(i,Yy(r),qy),this.unsubscribeParentListener=this.observe(`parent`,e=>{if(this.unsubscribeParentListener?.(),e.type===`menu`){let t=e.store.select(`rootId`),n=e.store.select(`floatingTreeRoot`),r=e.store.select(`keyboardEventRelay`);this.unsubscribeParentListener=e.store.subscribe(()=>{let i=e.store.select(`rootId`),a=e.store.select(`floatingTreeRoot`),o=e.store.select(`keyboardEventRelay`);(t!==i||n!==a||r!==o)&&(t=i,n=a,r=o,this.notifyAll())}),this.context.allowMouseUpTriggerRef=e.store.context.allowMouseUpTriggerRef;return}e.type!==void 0&&(this.context.allowMouseUpTriggerRef=e.context.allowMouseUpTriggerRef),this.unsubscribeParentListener=null})}setOpen(e,t){this.state.floatingRootContext.context.events.emit(`setOpen`,{open:e,eventDetails:t})}unsubscribeParentListener=null};function Yy(e){return{positionerRef:l.createRef(),popupRef:l.createRef(),typingRef:{current:!1},itemDomElements:{current:[]},itemLabels:{current:[]},allowMouseUpTriggerRef:{current:!1},triggerFocusTargetRef:l.createRef(),beforeContentFocusGuardRef:l.createRef(),onOpenChangeComplete:void 0,triggerElements:e}}function Xy(e,t,n=!1,r){return{...Fs(e,t,n),disabled:!1,modal:!0,openMethod:null,allowMouseEnter:!1,highlightItemOnHover:!0,parent:{type:void 0},rootId:void 0,activeIndex:null,hoverEnabled:!0,instantType:void 0,openChangeReason:null,floatingTreeRoot:new _a,floatingNodeId:void 0,floatingParentNodeId:null,itemProps:et,keyboardEventRelay:void 0,closeDelay:0,adaptiveOrigin:void 0,...r}}var Zy=l.createContext(void 0);function Qy(){return l.useContext(Zy)}var $y=es(function(e){let{children:t,open:n,onOpenChange:r,onOpenChangeComplete:i,defaultOpen:a=!1,disabled:o=!1,modal:s,loopFocus:c=!0,orientation:u=`vertical`,actionsRef:d,closeParentOnEsc:f=!1,handle:p,triggerId:m,defaultTriggerId:h=null,highlightItemOnHover:g=!0}=e,_=ky(!0),v=Ny(!0),y=Ky(!0),b=Qy(),x=l.useMemo(()=>b&&v?{type:`menu`,store:v.store}:y?{type:`menubar`,context:y}:_&&!v?{type:`context-menu`,context:_}:{type:void 0},[_,v,y,b]),S=Oi(),C=Oi(),w=ba(),T=x.type===`menu`?x.store:void 0,E=(n??a)&&T?.state.transitionStatus===`starting`,D=Ze(()=>E?T?.state.instantType:void 0).current,O=eb({open:a,openProp:n,activeTriggerId:h,triggerIdProp:m,parent:x,disabled:o,highlightItemOnHover:g,modal:x.type===void 0?s:void 0,rootId:S,instantType:D},C,w!=null);O.useControlledProp(`openProp`,n),O.useControlledProp(`triggerIdProp`,m),O.useContextCallback(`onOpenChangeComplete`,i);let k=O.useState(`floatingTreeRoot`),A=Sa(k),j=O.useState(`open`),M=O.useState(`activeTriggerElement`),N=O.useState(`positionerElement`),P=O.useState(`hoverEnabled`),F=O.useState(`disabled`),I=O.useState(`lastOpenChangeReason`),L=O.useState(`parent`),R=O.useState(`activeIndex`),z=O.useState(`payload`),ee=O.useState(`floatingParentNodeId`),B=l.useRef(null),te=l.useRef(L.type!==`context-menu`),ne=it(),re=l.useRef(!0),V=it(),H=ee!=null,{openMethod:ie,triggerProps:ae}=$c(j);O.useSyncedValues({disabled:o,highlightItemOnHover:g,modal:L.type===void 0?s:void 0,openMethod:ie,rootId:S}),As(O);let{forceUnmount:oe,transitionStatus:se}=js(j,O,()=>{O.set(`allowMouseEnter`,!1)},E),ce=vs(O.context.popupRef);l.useEffect(()=>{if(D===void 0)return;let e=()=>{O.state.instantType===D&&O.set(`instantType`,void 0)};if(!j){e();return}if(se!==void 0)return;if(O.context.popupRef.current==null){e();return}let t=new AbortController;return ce(e,t.signal),()=>{t.abort()}},[D,j,se,ce,O]),U(()=>{_&&!v?O.update({parent:{type:`context-menu`,context:_},floatingNodeId:A,floatingParentNodeId:w}):v&&O.update({floatingNodeId:A,floatingParentNodeId:w})},[_,v,A,w,O]),l.useEffect(()=>{if(j||(B.current=null),L.type===`context-menu`){if(!j){ne.clear(),te.current=!1;return}ne.start(500,()=>{te.current=!0})}},[ne,j,L.type]),U(()=>{!j&&!P&&O.set(`hoverEnabled`,!0)},[j,P,O]);let le=$((e,t)=>{let n=t.reason;if(!e&&!O.select(`open`)||j===e&&t.trigger===M&&I===n)return;let i=Ds(t);if(!e&&t.trigger==null&&(t.trigger=M??void 0),r?.(e,t),t.isCanceled)return;O.state.floatingRootContext.dispatchOpenChange(e,t);let a=t.event;if(e===!1&&a?.type===`click`&&a.pointerType===`touch`&&!re.current)return;e&&n===`trigger-focus`?(re.current=!1,V.start(300,()=>{re.current=!0})):(re.current=!0,V.clear());let o=(n===`trigger-press`||n===`item-press`)&&a.detail===0,s=!e&&(n===`escape-key`||n==null);B.current=t.event;let c=Es(O.state,e,t.trigger,i());c.openChangeReason=n,c.instantType=L.type===`menubar`&&(n===`trigger-focus`||n===`focus-out`||n===`trigger-hover`||n===`list-navigation`||n===`sibling-open`)?`group`:o||s?o?`click`:`dismiss`:void 0,O.update(c)}),ue=ms({popupStore:O,floatingRootContext:O.state.floatingRootContext,floatingId:C,nested:w!=null,onOpenChange:le}),de=ue.context.events;U(()=>{let e=({open:e,eventDetails:t})=>le(e,t);return de.on(`setOpen`,e),()=>{de?.off(`setOpen`,e)}},[de,le]);let fe=l.useCallback(()=>{O.setOpen(!1,Z(jn))},[O]);l.useImperativeHandle(d,()=>({unmount:oe,close:fe}),[oe,fe]);let pe;L.type===`context-menu`&&(pe=L.context),l.useImperativeHandle(pe?.positionerRef,()=>N,[N]),l.useImperativeHandle(pe?.actionsRef,()=>({setOpen:le}),[le]);let W=Va(ue,{enabled:!F,bubbles:{escapeKey:f&&L.type===`menu`},outsidePress(){return L.type!==`context-menu`||B.current?.type===`contextmenu`||te.current},externalTree:H?k:void 0}),me=Ol(),he=l.useCallback(e=>{O.select(`activeIndex`)!==e&&O.set(`activeIndex`,e)},[O]),ge=lc(ue,{enabled:!F,listRef:O.context.itemDomElements,activeIndex:R,nested:L.type!==void 0,loopFocus:c,orientation:u,parentOrientation:L.type===`menubar`?L.context.orientation:void 0,rtl:me===`rtl`,disabledIndices:$e,onNavigate:he,openOnArrowKeyDown:L.type!==`context-menu`,externalTree:H?k:void 0,focusItemOnHover:g}),G=l.useCallback(e=>{O.context.typingRef.current=e},[O]),K=uc(ue,{enabled:!F,listRef:O.context.itemLabels,elementsRef:O.context.itemDomElements,activeIndex:R,resetMs:500,onMatch:e=>{j&&e!==R&&O.set(`activeIndex`,e)},onTyping:G}),_e=l.useMemo(()=>{let e=zi(K.reference,ge.reference,W.reference,{onMouseMove(){O.set(`allowMouseEnter`,!0)}},ae);return e[`aria-haspopup`]=`menu`,e[`aria-expanded`]=j,e},[O,K.reference,ge.reference,W.reference,ae,j]),ve=l.useMemo(()=>{let e=zi(ge.trigger,W.trigger,ae);return e[`aria-haspopup`]=`menu`,e[`aria-expanded`]=!1,e},[ge.trigger,W.trigger,ae]);Ze(()=>(O.update({inactiveTriggerProps:ve}),null)),Ms(O,{floatingRootContext:ue,activeTriggerProps:_e,inactiveTriggerProps:ve,popupProps:l.useMemo(()=>zi(bs,{id:C,role:`menu`,"aria-orientation":u===`horizontal`?`horizontal`:void 0,"aria-labelledby":M?.id,onMouseMove(){O.set(`allowMouseEnter`,!0),L.type===`menu`&&O.set(`hoverEnabled`,!1)},onClick(){O.select(`hoverEnabled`)&&O.set(`hoverEnabled`,!1)},onKeyDown(e){let t=O.select(`keyboardEventRelay`);t&&!e.isPropagationStopped()&&t(e)}},K.floating,ge.floating,W.floating),[M,C,u,L.type,O,K.floating,ge.floating,W.floating]),itemProps:ge.item??et});let ye=l.useMemo(()=>({store:O,parent:x}),[O,x]),be=(0,Q.jsxs)(My.Provider,{value:ye,children:[p&&(0,Q.jsx)(Cs,{handle:p,store:O}),typeof t==`function`?t({payload:z}):t]});return L.type===void 0||L.type===`context-menu`?(0,Q.jsx)(wa,{externalTree:k,children:be}):be});function eb(e,t,n){return Ze(()=>new Jy(e,t,n)).current}function tb(e){let t=Ny().store,n=l.useMemo(()=>({parentMenu:t}),[t]);return(0,Q.jsx)(Zy.Provider,{value:n,children:(0,Q.jsx)($y,{...e})})}function nb(e={}){let{highlightItemOnHover:t,highlightedIndex:n,onHighlightedIndexChange:r}=Ac(),{ref:i,index:a}=og(e),o=n===a,s=l.useRef(null),c=Rn(i,s);return{compositeProps:{tabIndex:o?0:-1,onFocus(){r(a)},onMouseMove(){let e=s.current;if(!t||!e)return;let n=e.hasAttribute(`disabled`)||e.ariaDisabled===`true`;!o&&!n&&e.focus()}},compositeRef:c,index:a}}function rb(e){let{render:t,className:n,style:r,state:i=et,props:a=$e,refs:o=$e,metadata:s,stateAttributesMapping:c,tag:l=`div`,...u}=e,{compositeProps:d,compositeRef:f}=nb({metadata:s});return $i(l,e,{state:i,ref:[f,...o],props:[d,...a,u],stateAttributesMapping:c})}function ib(e){if(K(e)&&e.hasAttribute(`data-rootownerid`))return e.getAttribute(`data-rootownerid`);if(!Oe(e))return ib(je(e))}function ab(e,t){let n=l.useRef(null);function r(t){ua.flushSync(()=>{e.setOpen(!1,Z(Cn,t.nativeEvent,t.currentTarget))}),ii(n.current)?.focus()}function i(n){let r=e.select(`positionerElement`);if(r&&ai(n,r))e.context.beforeContentFocusGuardRef.current?.focus();else{ua.flushSync(()=>{e.setOpen(!1,Z(Cn,n.nativeEvent,n.currentTarget))});let i=ri(e.context.triggerFocusTargetRef.current||t.current);for(;i!==null&&X(r,i);){let e=i;if(i=ei(i),i===e)break}i?.focus()}}return{preFocusGuardRef:n,handlePreFocusGuardFocus:r,handleFocusTargetFocus:i}}function ob(e){let{enabled:t=!0,mouseDownAction:n,open:r}=e,i=l.useRef(!1);return l.useMemo(()=>t?{onMouseDown:e=>{(n===`open`&&!r||n===`close`&&r)&&(i.current=!0,J(e.currentTarget).addEventListener(`click`,()=>{i.current=!1},{once:!0}))},onClick:e=>{i.current&&(i.current=!1,e.preventBaseUIHandler())}}:et,[t,n,r])}var sb=ts(function(e,t){let{render:n,className:r,style:i,disabled:a=!1,nativeButton:o=!0,id:s,openOnHover:c,delay:u=100,closeDelay:d=0,handle:f,payload:p,...m}=e,h=Ny(!0),g=Hs(f)??h?.store;if(!g)throw Error(Ai(85));let _=Lc(s),v=g.useState(`isTriggerActive`,_),y=g.useState(`floatingRootContext`),b=g.useState(`isOpenedByTrigger`,_),x=g.useState(`triggerPopupId`,_),S=l.useRef(null),C=lb(),w=Ac(!0),T=xa(),E=l.useMemo(()=>T??new _a,[T]),{registerTrigger:D,isMountedByThisTrigger:O}=ks(_,S,g,{payload:p,closeDelay:d,parent:C,floatingTreeRoot:E,floatingNodeId:Sa(E),floatingParentNodeId:ba(),keyboardEventRelay:w?.relayKeyboardEvent}),k=C.type===`menubar`,A=g.useState(`disabled`),j=a||A||k&&C.context.disabled,{getButtonProps:M,buttonRef:N}=Nc({disabled:j,native:o});l.useEffect(()=>{!b&&C.type===void 0&&(g.context.allowMouseUpTriggerRef.current=!1)},[g,b,C.type]);let P=l.useRef(null),F=it(),I=$(e=>{if(!P.current)return;F.clear(),g.context.allowMouseUpTriggerRef.current=!1;let t=e.target;X(P.current,t)||X(g.select(`positionerElement`),t)||t===P.current||(t==null||ib(t)!==g.select(`rootId`))&&(Nh(e,P.current)||E.events.emit(`close`,{domEvent:e,reason:On}))});l.useEffect(()=>{b&&g.select(`lastOpenChangeReason`)===`trigger-hover`&&J(P.current).addEventListener(`mouseup`,I,{once:!0})},[b,I,g]);let L=k&&C.context.hasSubmenuOpen,R=tc(y,{enabled:(c??L)&&!j&&(!k||L&&!O),handleClose:vc({blockPointerEvents:!k}),mouseOnly:!0,move:!1,restMs:C.type===void 0?u:void 0,delay:{close:d},triggerElementRef:S,externalTree:E,isActiveTrigger:v,isClosing:()=>g.select(`transitionStatus`)===`ending`}),z=cb(b,g.select(`lastOpenChangeReason`)),ee=Fa(y,{enabled:!j,event:b&&k?`click`:`mousedown`,toggle:!0,ignoreMouse:!1,stickIfOpen:C.type===void 0&&z}),B=qs(y,{enabled:!j&&L}),te=ob({open:b,enabled:k,mouseDownAction:`open`}),ne=l.useMemo(()=>zi(B.reference,ee.reference),[B.reference,ee.reference]),re=g.useState(`triggerProps`,O),{preFocusGuardRef:V,handlePreFocusGuardFocus:H,handleFocusTargetFocus:ie}=ab(g,S),ae={disabled:j,open:b},oe=[P,t,N,D,S],se=[ne,R??et,re,{"aria-haspopup":`menu`,"aria-controls":x,id:_,onMouseDown:e=>{g.select(`open`)||(F.start(200,()=>{g.context.allowMouseUpTriggerRef.current=!0}),J(e.currentTarget).addEventListener(`mouseup`,I,{once:!0}))}},k?{role:`menuitem`}:{},te,m,M],ce=$i(`button`,e,{enabled:!k,stateAttributesMapping:Yt,state:ae,ref:oe,props:se});return k?(0,Q.jsx)(rb,{tag:`button`,render:n,className:r,style:i,state:ae,refs:oe,props:se,stateAttributesMapping:Yt}):b?(0,Q.jsxs)(l.Fragment,{children:[(0,Q.jsx)(er,{ref:V,onFocus:H},`${_}-pre-focus-guard`),(0,Q.jsx)(l.Fragment,{children:ce},_),(0,Q.jsx)(er,{ref:g.context.triggerFocusTargetRef,onFocus:ie},`${_}-post-focus-guard`)]}):(0,Q.jsx)(l.Fragment,{children:ce},_)});function cb(e,t){let n=it(),[r,i]=l.useState(!1);return U(()=>{e&&t===`trigger-hover`?(i(!0),n.start(500,()=>{i(!1)})):e||(n.clear(),i(!1))},[e,t,n]),r}function lb(){let e=Ky(!0);return l.useMemo(()=>e?{type:`menubar`,context:e}:{type:void 0},[e])}var ub={"aria-expanded":void 0},db=l.forwardRef(function(e,t){let{render:n,className:r,style:i,label:a,id:o,nativeButton:s=!1,openOnHover:c=!0,delay:u=100,closeDelay:d=0,disabled:f=!1,...p}=e,m=Qy();if(!m?.parentMenu)throw Error(Ai(37));let h=og({guess:!0,label:a}),g=jy(),{store:_}=Ny(),v=Lc(o),y=_.useState(`open`),b=_.useState(`floatingRootContext`),x=_.useState(`floatingTreeRoot`),S=_.useState(`triggerPopupId`,v),C=Ts(v,_),w=$(e=>{C(e),e!==null&&_.select(`open`)&&_.select(`activeTriggerId`)==null&&_.update({activeTriggerId:v??null,activeTriggerElement:e,closeDelay:d})}),T=l.useRef(null),E=l.useCallback(e=>{T.current=e,_.set(`activeTriggerElement`,e)},[_]);U(()=>(w(T.current),()=>w(null)),[w,v,_]),_.useSyncedValue(`closeDelay`,d);let D=m.parentMenu,O=_.useState(`disabled`),k=D.useState(`disabled`),A=f||O||k,j=D.useState(`itemProps`),M=D.useState(`isActive`,h.index),N=l.useMemo(()=>({type:`submenu-trigger`,setActive(){D.select(`highlightItemOnHover`)&&D.set(`activeIndex`,h.index)}}),[D,h.index]),{getItemProps:P,itemRef:F}=Iy({closeOnClick:!1,disabled:A,highlighted:M,id:v,store:_,typingRef:D.context.typingRef,nativeButton:s,itemMetadata:N,nodeId:g?.context.nodeId}),I=tc(b,{enabled:_.useState(`hoverEnabled`)&&c&&!A,handleClose:vc({blockPointerEvents:!0}),mouseOnly:!0,move:!0,restMs:u,delay:{open:u,close:d},shouldOpen:u>0?()=>D.select(`allowMouseEnter`):void 0,triggerElementRef:T,externalTree:x,isClosing:()=>_.select(`transitionStatus`)===`ending`,guardStaleOpen:!0}),L=Fa(b,{enabled:!A,event:`mousedown`,toggle:!c,ignoreMouse:c,stickIfOpen:!1}).reference??et,R=_.useState(`triggerProps`,!0);delete R.id;let z={disabled:A,highlighted:M,open:y},ee=_.useState(`openMethod`),B=_.useState(`lastOpenChangeReason`)===`list-navigation`||ee===`keyboard`;return $i(`div`,e,{state:z,stateAttributesMapping:Jt,props:[L,I,R,j,y&&B&&Je?ub:void 0,{"aria-controls":S,tabIndex:y||M?0:-1,onBlur(){M&&D.set(`activeIndex`,null)}},p,P],ref:[t,h.ref,F,w,E]})});function fb(e){let[t,n]=l.useState({getBoundingClientRect(){return DOMRect.fromRect({width:0,height:0,x:0,y:0})}}),r=l.useRef(null),i=l.useRef(null),a=l.useRef(null),o=l.useRef(null),s=l.useRef(!0),c=l.useRef(null),u=Oi(),d=l.useMemo(()=>({anchor:t,setAnchor:n,actionsRef:a,backdropRef:r,internalBackdropRef:i,positionerRef:o,allowMouseUpTriggerRef:s,initialCursorPointRef:c,rootId:u}),[t,u]);return(0,Q.jsx)(Oy.Provider,{value:d,children:(0,Q.jsx)(My.Provider,{value:void 0,children:(0,Q.jsx)($y,{...e})})})}var pb=500,mb=l.forwardRef(function(e,t){let{render:n,className:r,style:i,...a}=e,{setAnchor:o,actionsRef:s,internalBackdropRef:c,backdropRef:u,positionerRef:d,allowMouseUpTriggerRef:f,initialCursorPointRef:p,rootId:m}=ky(!1),{store:h}=Ny(!1),g=h.useState(`open`),_=h.useState(`disabled`),v=l.useRef(null),y=l.useRef(null),b=it(),x=it(),S=l.useRef(!1),C=l.useRef(null);function w(e,t,n){let r=n.type.startsWith(`touch`);p.current={x:e,y:t},o({getBoundingClientRect(){return DOMRect.fromRect({width:r?10:0,height:r?10:0,x:e,y:t})}}),S.current=!1,s.current?.setOpen(!0,Z(mn,n)),x.start(pb,()=>{S.current=!0})}function T(e){if(_)return;f.current=!0,yt(e),w(e.clientX,e.clientY,e.nativeEvent);let t=J(v.current);C.current?.abort();let n=new AbortController;C.current=n,t.addEventListener(`mouseup`,e=>{if(f.current=!1,!S.current)return;x.clear(),S.current=!1;let t=Et(e);X(d.current,t)||m&&t&&ib(t)===m||s.current?.setOpen(!1,Z(On,e))},{once:!0,signal:n.signal})}function E(){b.clear(),y.current=null}function D(e){if(_){E();return}if(f.current=!1,e.touches.length!==1){E();return}e.stopPropagation();let t=e.touches[0],n={x:t.clientX,y:t.clientY};y.current=n,b.start(pb,()=>{w(n.x,n.y,e.nativeEvent)})}function O(e){if(e.touches.length!==1){E();return}if(b.isStarted()&&y.current){let t=e.touches[0],n=Math.abs(t.clientX-y.current.x),r=Math.abs(t.clientY-y.current.y);(n>10||r>10)&&E()}}return l.useEffect(()=>()=>{C.current?.abort()},[]),l.useEffect(()=>{function e(e){if(_)return;let t=Et(e);(X(v.current,t)||X(c.current,t)||X(u.current,t))&&e.preventDefault()}return q(J(v.current),`contextmenu`,e)},[u,_,c]),$i(`div`,e,{state:{open:g},ref:[v,t],props:[{onContextMenu:T,onTouchStart:D,onTouchMove:O,onTouchEnd:E,onTouchCancel:E,style:{WebkitTouchCallout:`none`}},a],stateAttributesMapping:Yt})}),hb=Wy,gb={claude:`Claude Code`,codex:`Codex`,opencode:`OpenCode`,pi:`Pi`};function _b(e){return Object.hasOwn(gb,e)?gb[e]:e}function vb(e){let t=Math.max(0,Math.floor((Date.now()-new Date(e).getTime())/6e4));return t<1?`now`:t<60?`${t}m`:t<1440?`${Math.floor(t/60)}h`:`${Math.floor(t/1440)}d`}var yb=[{id:`validate`,label:`Checking the machine`,active:`Checking the machine…`},{id:`checkout`,label:`Creating the worktree`,active:`Creating the worktree…`},{id:`start`,label:`Starting the agent`,active:`Starting the agent…`},{id:`prompt`,label:`Sending your prompt`,active:`Sending your prompt…`}],bb=6e5,xb=e=>e===`checkout_complete`?2:Math.max(0,yb.findIndex(t=>t.id===e)),Sb=e=>[`pending`,`running`].includes(e.operation?.state??``)&&!e.panes.some(e=>e.kind===`agent`),Cb=e=>[`failed`,`unknown`].includes(e.operation?.state??``)&&!e.panes.some(e=>e.kind===`agent`),wb=e=>yb[xb(e.operation?.step??`validate`)].active,Tb=(e,t)=>t-Date.parse(e.updatedAt)<bb,Eb=(e,t=Date.now())=>e.panes.some(e=>e.kind===`agent`)||Sb(e)||Cb(e)&&Tb(e,t),Db=e=>new URLSearchParams({machineId:e.machineId??`local`,projectId:e.id}),Ob=e=>e.branch??e.label,kb=e=>e.path.split(`/`).at(-1)??``,Ab=(e,t)=>`${Ob(e)} ${kb(e)}`.toLowerCase().includes(t.trim().toLowerCase()),jb=async(e,t)=>{let n=await fetch(`/api/worktrees?${Db(e)}`,{signal:t});if(!n.ok)throw Error(`Could not list worktrees.`);return await n.json()},Mb=async(e,t)=>{let n=await fetch(`/api/worktrees/open`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({machineId:e.machineId??`local`,projectId:e.id,path:t.path})});if(!n.ok)throw Error(`Could not open this worktree.`);return(await n.json()).id},Nb=async(e,t)=>{try{await a(`/threads/${encodeURIComponent(await Mb(e,t))}`)}catch(e){ol(e instanceof Error?e.message:`Could not open this worktree.`)}},Pb=e=>{(e.key.length===1||e.key===`Backspace`)&&e.stopPropagation()};function Fb({project:e}){let[t,n]=(0,l.useState)(``),r=J_({queryKey:[`worktrees`,e.machineId,e.id],queryFn:({signal:t})=>jb(e,t),staleTime:0,gcTime:0}),i=(r.data??[]).filter(e=>Ab(e,t));return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`composer-select-search`,children:[(0,Q.jsx)(H,{size:14,"aria-hidden":`true`}),(0,Q.jsx)(`input`,{autoFocus:!0,"aria-label":`Search worktrees`,placeholder:`Search worktrees…`,value:t,onChange:e=>n(e.target.value),onKeyDown:Pb})]}),(0,Q.jsxs)(`div`,{className:`worktree-menu-list`,children:[i.map(t=>(0,Q.jsx)(Yl,{label:t.path,side:`right`,children:(0,Q.jsxs)(Ly,{className:`thread-menu-item`,onClick:()=>void Nb(e,t),children:[(0,Q.jsx)(M,{size:14,"aria-hidden":`true`}),(0,Q.jsxs)(`span`,{className:`worktree-menu-name`,children:[Ob(t),(0,Q.jsx)(`small`,{children:kb(t)})]})]})},t.path)),r.isError&&(0,Q.jsx)(`p`,{className:`worktree-menu-note`,role:`alert`,children:`Could not list worktrees.`}),r.data&&!i.length&&(0,Q.jsx)(`p`,{className:`worktree-menu-note`,children:r.data.length?`No matches`:`Every worktree already has a thread`})]})]})}function Ib({projects:e}){return(0,Q.jsxs)($y,{children:[(0,Q.jsx)(Yl,{label:`Open existing worktree`,children:(0,Q.jsx)(sb,{className:`sidebar-open-worktree`,"aria-label":`Open existing worktree`,disabled:!e.length,children:(0,Q.jsx)(H,{size:16,"aria-hidden":`true`})})}),(0,Q.jsx)(Uy,{children:(0,Q.jsx)(Wy,{className:`thread-menu-positioner`,sideOffset:6,align:`start`,children:(0,Q.jsx)(By,{className:`thread-menu`,children:e.map(e=>(0,Q.jsxs)(tb,{children:[(0,Q.jsxs)(db,{className:`thread-menu-item`,children:[(0,Q.jsx)(Cg,{project:e}),(0,Q.jsx)(`span`,{children:e.name}),(0,Q.jsx)(x,{size:14,"aria-hidden":`true`,className:`worktree-menu-chevron`})]}),(0,Q.jsx)(Uy,{children:(0,Q.jsx)(Wy,{className:`thread-menu-positioner`,sideOffset:4,alignOffset:-4,children:(0,Q.jsx)(By,{className:`thread-menu worktree-menu`,children:(0,Q.jsx)(Fb,{project:e})})})})]},`${e.machineId}:${e.id}`))})})})]})}function Lb({thread:e,onDone:t,onError:n}){let[r,i]=(0,l.useState)(e.title),a=(0,l.useRef)(null),o=(0,l.useRef)(!1);(0,l.useEffect)(()=>{a.current?.focus(),a.current?.select()},[]);let s=i=>{if(o.current)return;o.current=!0,t();let a=r.trim();i&&a&&a!==e.title&&op(e,a).catch(n)};return(0,Q.jsx)(`input`,{ref:a,className:`thread-name-input`,"aria-label":`Rename ${e.title}`,value:r,maxLength:90,onChange:e=>i(e.target.value),onBlur:()=>s(!0),onClick:e=>e.stopPropagation(),onKeyDown:e=>{e.stopPropagation(),e.key===`Enter`&&s(!0),e.key===`Escape`&&s(!1)}})}function Rb({project:e,onDone:t,onError:n}){let[r,i]=(0,l.useState)(e.name),a=(0,l.useRef)(null),o=(0,l.useRef)(!1);(0,l.useEffect)(()=>{a.current?.focus(),a.current?.select()},[]);let s=i=>{if(o.current)return;o.current=!0,t();let a=r.trim();i&&a&&a!==e.name&&sp(e,a).catch(n)};return(0,Q.jsx)(`input`,{ref:a,className:`thread-name-input group-name-input`,"aria-label":`Rename ${e.name}`,value:r,maxLength:90,onChange:e=>i(e.target.value),onBlur:()=>s(!0),onClick:e=>e.stopPropagation(),onKeyDown:e=>{e.stopPropagation(),e.key===`Enter`&&s(!0),e.key===`Escape`&&s(!1)}})}var zb=128;async function Bb(e){let t=await createImageBitmap(e),n=document.createElement(`canvas`);n.width=n.height=zb;let r=Math.min(zb/t.width,zb/t.height),i=t.width*r,a=t.height*r;return n.getContext(`2d`).drawImage(t,(zb-i)/2,(zb-a)/2,i,a),new Promise((e,t)=>n.toBlob(n=>n?e(n):t(Error(`Could not read this image.`)),`image/png`))}function Vb({project:e,open:t,onClose:n,onError:r}){let i=(0,l.useRef)(null),[a,o]=(0,l.useState)(!1),[s,c]=(0,l.useState)(!1),u=async e=>{c(!0);try{await e(),n()}catch(e){r(e)}finally{c(!1)}},d=t=>{t&&u(async()=>lp(e,await Bb(t)))};return(0,Q.jsx)(Cv,{open:t,onOpenChange:e=>{e||n()},children:(0,Q.jsxs)(Jc,{children:[(0,Q.jsx)(Oc,{className:`dialog-backdrop`}),(0,Q.jsxs)(Gc,{className:`dialog`,children:[(0,Q.jsxs)(Yc,{className:`dialog-message`,children:[`Change icon for `,e.name]}),(0,Q.jsxs)(`button`,{type:`button`,className:`icon-dropzone ${a?`is-dragging`:``}`,disabled:s,onClick:()=>i.current?.click(),onDragOver:e=>{e.preventDefault(),o(!0)},onDragLeave:()=>o(!1),onDrop:e=>{e.preventDefault(),o(!1),d(e.dataTransfer.files[0])},children:[(0,Q.jsx)(P,{size:22,"aria-hidden":`true`}),`Drop an image here, or click to choose`]}),(0,Q.jsx)(`input`,{ref:i,type:`file`,accept:`image/*`,hidden:!0,onChange:e=>{d(e.target.files?.[0]),e.target.value=``}}),(0,Q.jsxs)(`div`,{className:`dialog-actions`,children:[(0,Q.jsx)(`button`,{type:`button`,className:`dialog-button`,disabled:s,onClick:()=>void u(()=>up(e)),children:`Reset to default`}),(0,Q.jsx)(Ic,{className:`dialog-button`,children:`Cancel`})]})]})]})})}var Hb=220,Ub=`[data-flip-id]`,Wb=e=>{let t=e.getBoundingClientRect().top-e.scrollTop;return new Map([...e.querySelectorAll(Ub)].map(e=>[e.dataset.flipId,{element:e,top:e.getBoundingClientRect().top-t}]))};function Gb(e){let t=(0,l.useRef)(new Map);(0,l.useLayoutEffect)(()=>{if(!e.current)return;let n=Wb(e.current);for(let[e,{element:r,top:i}]of n){let n=t.current.get(e);n===void 0||Math.abs(n-i)<1||r.animate([{transform:`translateY(${n-i}px)`},{transform:`none`}],{duration:Hb,easing:`cubic-bezier(.2, .8, .2, 1)`})}t.current=new Map([...n].map(([e,{top:t}])=>[e,t]))})}function Kb(e,t){let n=new Map;for(let r of e){let e=r.logicalId??r.id,i=n.get(e);i?(i.locations.push(r.id),r.id===t&&(i.project=r)):n.set(e,{id:e,project:r,locations:[r.id]})}return[...n.values()]}var qb=/^\/(?:Users|home)\/[^/]+/,Jb=e=>e.replace(qb,`~`),Yb={working:`Working`,blocked:`Needs input`,done:`Done`,idle:`Idle`,unknown:`Unknown`},Xb={blocked:L,done:C,unknown:w},Zb=e=>ol(e instanceof Error?e.message:`Herdr could not complete this action.`),Qb=async e=>{await al(gp([e]),{confirmLabel:`Delete`,danger:!0})&&await pp(e).catch(Zb)},$b=(0,l.memo)(function({thread:e,project:t,machineName:n,current:r,showProject:i}){let a=!!e.archivedAt,o=a?f:p,s=a?`Unarchive ${e.title}`:`Archive ${e.title}`,[c,u]=(0,l.useState)(!1),d=c?(0,Q.jsx)(Lb,{thread:e,onDone:()=>u(!1),onError:Zb}):void 0;return(0,Q.jsxs)(fb,{children:[(0,Q.jsxs)(mb,{className:`thread-item`,"data-flip-id":e.id,onDoubleClick:e=>{e.preventDefault(),u(!0)},children:[(0,Q.jsx)(ex,{thread:e,project:t,machineName:n,current:r,showProject:i,editor:d}),(0,Q.jsx)(Yl,{label:a?`Unarchive`:`Archive`,children:(0,Q.jsx)(`button`,{type:`button`,className:`thread-archive`,"aria-label":s,onClick:()=>void ap(e,!a).catch(Zb),children:(0,Q.jsx)(o,{size:15,strokeWidth:1.8,"aria-hidden":`true`})})})]}),(0,Q.jsx)(Uy,{children:(0,Q.jsx)(hb,{className:`thread-menu-positioner`,children:(0,Q.jsx)(By,{className:`thread-menu`,children:(0,Q.jsxs)(Ly,{className:`thread-menu-item is-danger`,onClick:()=>void Qb(e),children:[(0,Q.jsx)(ue,{size:14,"aria-hidden":`true`}),`Delete permanently`]})})})})]})});function ex({thread:e,project:t,machineName:n,current:r,showProject:i,editor:a}){let o=Sb(e),s=Cb(e),c=s?de:o?void 0:Xb[e.status],l=s||e.status===`blocked`||e.status===`done`,u=o?wb(e):s?`Launch stopped`:Yb[e.status],d=o||s?u:i?t?.name:_b(e.agent),f=a?`div`:`a`;return(0,Q.jsx)(Yl,{label:`${e.title} · ${t?.name??``} · ${n} · ${_b(e.agent)} · ${e.model} · ${u}`,side:`right`,children:(0,Q.jsxs)(f,{className:`thread-row ${r?`is-current`:``} ${l?`needs-attention status-${s?`blocked`:e.status}`:``}`,href:a?void 0:`/threads/${encodeURIComponent(e.id)}`,"aria-current":r?`page`:void 0,"aria-label":`${e.title} · ${t?.name??``} · ${n} · ${u}`,children:[(0,Q.jsxs)(`span`,{className:`thread-avatar`,"aria-hidden":`true`,children:[(0,Q.jsx)(qf,{thread:e,working:e.status===`working`||o,size:24}),c&&(0,Q.jsx)(c,{className:`thread-status status-${s?`blocked`:e.status}`,size:14,strokeWidth:2.2}),(0,Q.jsx)(`span`,{className:`thread-avatar-harness`,children:(0,Q.jsx)(yg,{harness:e.agent,size:14})})]}),(0,Q.jsxs)(`span`,{className:`thread-copy`,children:[(0,Q.jsxs)(`span`,{className:`thread-context`,children:[i&&t&&!o&&!s&&(0,Q.jsx)(Cg,{project:t}),e.worktree&&!o&&!s&&(0,Q.jsx)(M,{className:`thread-worktree`,size:11,"aria-label":`Worktree`}),d]}),a??(0,Q.jsx)(`span`,{className:`thread-name`,children:e.title})]}),(0,Q.jsx)(`span`,{className:`thread-time`,children:vb(e.updatedAt)})]})})}function tx({project:e,closed:t,onToggle:n}){let[r,i]=(0,l.useState)(!1),[o,s]=(0,l.useState)(!1),c=r?`div`:`button`,u=r?(0,Q.jsx)(Rb,{project:e,onDone:()=>i(!1),onError:Zb}):(0,Q.jsx)(`span`,{className:`group-name`,children:e.name});return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(fb,{children:[(0,Q.jsx)(mb,{className:`group-header`,children:(0,Q.jsxs)(c,{className:`group-title`,onClick:r?void 0:n,"aria-expanded":r?void 0:!t,children:[(0,Q.jsx)(`span`,{className:`group-chevron`,"aria-hidden":`true`,children:t?(0,Q.jsx)(x,{size:14}):(0,Q.jsx)(b,{size:14})}),(0,Q.jsx)(Cg,{project:e}),u]})}),(0,Q.jsx)(Uy,{children:(0,Q.jsx)(hb,{className:`thread-menu-positioner`,children:(0,Q.jsxs)(By,{className:`thread-menu`,children:[(0,Q.jsxs)(Ly,{className:`thread-menu-item`,onClick:()=>void a(`/new?project=${encodeURIComponent(e.id)}`),children:[(0,Q.jsx)(V,{size:14,"aria-hidden":`true`}),`New thread`]}),(0,Q.jsxs)(Ly,{className:`thread-menu-item`,onClick:()=>i(!0),children:[(0,Q.jsx)(re,{size:14,"aria-hidden":`true`}),`Rename project`]}),(0,Q.jsxs)(Ly,{className:`thread-menu-item`,onClick:()=>s(!0),children:[(0,Q.jsx)(P,{size:14,"aria-hidden":`true`}),`Change icon`]}),(0,Q.jsx)(`div`,{className:`thread-menu-path`,title:e.path,children:Jb(e.path)})]})})})]}),(0,Q.jsx)(Vb,{project:e,open:o,onClose:()=>s(!1),onError:Zb})]})}function nx({threads:e,renderThread:t}){let[n,r]=(0,l.useState)(!1),[i,a]=(0,l.useState)(!1),o=async()=>{if(await al(gp(e),{confirmLabel:`Delete all`,danger:!0})){a(!0);try{let e=await mp();e.failed.length&&await ol(`${e.failed.length} archived ${e.failed.length===1?`thread`:`threads`} could not be deleted.`)}catch(e){Zb(e)}finally{a(!1)}}};return(0,Q.jsxs)(`section`,{className:`thread-group archived-threads`,"aria-label":`Archived threads`,children:[(0,Q.jsxs)(`div`,{className:`group-header`,children:[(0,Q.jsxs)(`button`,{className:`group-title`,onClick:()=>r(e=>!e),"aria-expanded":n,children:[(0,Q.jsx)(`span`,{className:`group-chevron`,"aria-hidden":`true`,children:n?(0,Q.jsx)(b,{size:14}):(0,Q.jsx)(x,{size:14})}),(0,Q.jsx)(p,{size:14,"aria-hidden":`true`}),(0,Q.jsx)(`span`,{className:`group-name`,children:`Archived`}),(0,Q.jsx)(`span`,{className:`group-count`,children:e.length})]}),(0,Q.jsx)(`button`,{type:`button`,className:`archived-delete-all`,onClick:()=>void o(),disabled:i,children:i?`Deleting…`:`Delete all`})]}),n&&e.map(t)]})}function rx({projects:e,threads:t,archived:n=[],machines:r,currentId:i,mode:a,onModeChange:o,collapsed:s,mobileOpen:c,onCollapse:u,onCloseMobile:d,onOpenPalette:f}){let[p,m]=(0,l.useState)([]),h=t.find(e=>e.id===i)?.projectId,g=Kb(e,h),_=(0,l.useRef)(null);Gb(_);let v=(t,n)=>{let a=e.find(e=>e.id===t.projectId);return(0,Q.jsx)($b,{thread:t,project:a,machineName:r.find(e=>e.id===t.machineId)?.name??t.machineId,current:i===t.id,showProject:n},t.id)};return(0,Q.jsxs)(Q.Fragment,{children:[c&&(0,Q.jsx)(`button`,{className:`sidebar-scrim`,"aria-label":`Close sidebar`,onClick:d}),(0,Q.jsxs)(`aside`,{className:`sidebar ${s?`is-collapsed`:``} ${c?`is-mobile-open`:``}`,"aria-label":`Threads`,onClick:e=>{c&&e.target.closest(`a[href]`)&&d()},children:[(0,Q.jsxs)(`div`,{className:`sidebar-header`,children:[!s&&(0,Q.jsxs)(`span`,{className:`brand`,children:[(0,Q.jsx)(`img`,{src:`/brand-mark.png`,alt:``,width:20,height:20}),`webr`]}),(0,Q.jsx)(`button`,{className:`icon-button sidebar-collapse`,"aria-label":s?`Expand sidebar`:`Collapse sidebar`,onClick:u,children:s?(0,Q.jsx)(te,{size:16}):(0,Q.jsx)(B,{size:16})}),(0,Q.jsx)(`button`,{className:`icon-button mobile-close`,"aria-label":`Close sidebar`,onClick:d,children:(0,Q.jsx)(fe,{size:16})})]}),(0,Q.jsxs)(`div`,{className:`sidebar-actions`,children:[(0,Q.jsx)(Yl,{label:`New thread`,children:(0,Q.jsxs)(`a`,{className:`sidebar-new-thread`,href:`/new${h?`?project=${encodeURIComponent(h)}`:``}`,"aria-label":`New thread`,children:[(0,Q.jsx)(oe,{size:16,"aria-hidden":`true`}),!s&&(0,Q.jsx)(`span`,{children:`New thread`})]})}),(0,Q.jsx)(Ib,{projects:e}),!s&&(0,Q.jsxs)(`div`,{className:`sidebar-view-switch`,role:`group`,"aria-label":`Sidebar layout`,children:[(0,Q.jsx)(Yl,{label:`Show threads`,children:(0,Q.jsx)(`button`,{type:`button`,"aria-label":`Show threads`,"aria-pressed":a===`threads`,onClick:()=>o(`threads`),children:(0,Q.jsx)(F,{size:16,"aria-hidden":`true`})})}),(0,Q.jsx)(Yl,{label:`Group by project`,children:(0,Q.jsx)(`button`,{type:`button`,"aria-label":`Group by project`,"aria-pressed":a===`projects`,onClick:()=>o(`projects`),children:(0,Q.jsx)(A,{size:16,"aria-hidden":`true`})})})]})]}),!s&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`nav`,{ref:_,className:`thread-navigation`,"aria-label":`Agent threads`,children:[a===`projects`?g.filter(e=>t.some(t=>e.locations.includes(t.projectId))).sort((e,n)=>(t.find(e=>n.locations.includes(e.projectId))?.updatedAt??``).localeCompare(t.find(t=>e.locations.includes(t.projectId))?.updatedAt??``)).map(({id:e,project:n,locations:r})=>(0,Q.jsxs)(`section`,{className:`thread-group`,children:[(0,Q.jsx)(tx,{project:n,closed:p.includes(e),onToggle:()=>m(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])}),!p.includes(e)&&t.filter(e=>r.includes(e.projectId)).map(e=>v(e,!1))]},e)):t.map(e=>v(e,!0)),!t.length&&!n.length&&(0,Q.jsx)(`p`,{className:`sidebar-empty`,children:`No agents yet. Press ⌘K to start one.`})]}),!!n.length&&(0,Q.jsx)(nx,{threads:n,renderThread:e=>v(e,!0)}),(0,Q.jsxs)(`div`,{className:`sidebar-footer`,children:[(0,Q.jsxs)(`a`,{className:`sidebar-settings`,href:`/settings`,children:[(0,Q.jsx)(ae,{size:15}),` Settings`]}),(0,Q.jsx)(Yl,{label:`Open command palette`,children:(0,Q.jsx)(`button`,{type:`button`,className:`sidebar-palette`,"aria-label":`Open command palette`,onClick:f,children:(0,Q.jsx)(`kbd`,{children:`⌘K`})})})]})]})]})]})}var ix=e=>{let t,n=new Set,r=(e,r)=>{let i=typeof e==`function`?e(t):e;if(!Object.is(i,t)){let e=t;t=r??(typeof i!=`object`||!i)?i:Object.assign({},t,i),n.forEach(n=>n(t,e))}},i=()=>t,a={setState:r,getState:i,getInitialState:()=>o,subscribe:e=>(n.add(e),()=>n.delete(e))},o=t=e(r,i,a);return a},ax=(e=>e?ix(e):ix),ox=e=>e;function sx(e,t=ox){let n=l.useSyncExternalStore(e.subscribe,l.useCallback(()=>t(e.getState()),[e,t]),l.useCallback(()=>t(e.getInitialState()),[e,t]));return l.useDebugValue(n),n}var cx=(e,t)=>JSON.stringify(e)===JSON.stringify(t),lx=(e,t)=>e&&cx(e,t)?e:t;function ux(e){let t=new Map,n=new Set,r=ax((e,r)=>({projections:{},threads:{},projects:{},threadIds:[],projectIds:[],connected:!1,connection:t=>e(e=>{if(t)return{connected:t};for(let t of Object.keys(e.projections))n.add(t);return{connected:t,projections:Object.fromEntries(Object.entries(e.projections).map(([e,t])=>[e,{...t,connected:!1,freshAt:null}])),threads:Object.fromEntries(Object.entries(e.threads).map(([e,t])=>[e,{...t,status:`unknown`,bindingState:`detached`}]))}}),install:i=>{let a=r(),o=a.projections[i.machineId],s=t.get(i.machineId)??new Set;if(s.has(i.generation)||!n.has(i.machineId)&&o?.generation===i.generation&&o.revision>=i.revision)return;n.delete(i.machineId),o&&o.generation!==i.generation&&s.add(o.generation),s.size>8&&s.delete(s.values().next().value),t.set(i.machineId,s);let c=Object.fromEntries(Object.entries(a.threads).filter(([,e])=>e.machineId!==i.machineId));for(let e of i.threads)c[e.id]=lx(a.threads[e.id],{...e,panes:e.panes.map(t=>lx(a.threads[e.id]?.panes.find(e=>e.id===t.id&&e.terminalId===t.terminalId),t))});let l={...a.projections,[i.machineId]:i},u={};for(let e of Object.values(l))for(let t of e.projects)u[t.id]=lx(a.projects[t.id],t);let d=Object.values(c).sort((e,t)=>t.updatedAt.localeCompare(e.updatedAt)).map(e=>e.id),f=Object.keys(u);e({projections:l,threads:c,projects:u,threadIds:lx(a.threadIds,d),projectIds:lx(a.projectIds,f)})}}));for(let t of e.projections)r.getState().install(t);return r}var dx=()=>ax(e=>({focusedPanes:{},paneWindows:{},focus:(t,n)=>e(e=>({focusedPanes:{...e.focusedPanes,[t]:n}})),showWindow:(t,n)=>e(e=>({paneWindows:{...e.paneWindows,[t]:n}}))}));function fx(e){if(e.length<32)throw Error(`short_frame`);let t=new DataView(e.buffer,e.byteOffset,e.byteLength),n=Number(t.getBigUint64(12));if(t.getUint32(0)!==1212437041||t.getUint32(24)!==e.length-32||e.length-32>262144||!Number.isSafeInteger(n)||t.getUint8(28)>1||t.getUint8(29)||t.getUint16(30))throw Error(`invalid_frame`);let r={streamId:t.getUint32(4),generation:t.getUint32(8),seq:n,width:t.getUint16(20),height:t.getUint16(22),full:!!t.getUint8(28),bytes:e.subarray(32)};if(!r.streamId||!r.generation||!r.width||r.width>500||!r.height||r.height>300)throw Error(`invalid_dimensions`);return r}var px=class{seq;accept(e){if(this.seq===void 0&&!e.full)throw Error(`baseline_required`);if(this.seq!==void 0&&e.seq!==this.seq+1)throw Error(`sequence_gap`);this.seq=e.seq}},mx=class{terminal;acknowledge;budget;frames=[];bytes=0;writing=!1;closed=!1;constructor(e,t,n=524288){this.terminal=e,this.acknowledge=t,this.budget=n}push(e){if(!this.closed){if(this.bytes+e.bytes.length>this.budget)throw Error(`renderer_overload`);this.bytes+=e.bytes.length,this.frames.push(e),this.frames.length,this.bytes/1024,this.flush()}}close(){this.closed=!0,this.frames=[],this.bytes=0}flush(){if(this.closed||this.writing||!this.frames.length)return;this.writing=!0;let e=this.frames.shift();this.terminal.resize(e.width,e.height);let t=e.full?new Uint8Array(e.bytes.length+2):e.bytes;e.full&&(t.set([27,99]),t.set(e.bytes,2));let n=Sp();this.terminal.write(t,()=>{this.closed||(Sp()-n,this.bytes-=e.bytes.length,this.writing=!1,this.acknowledge(e),this.flush())})}},hx=(e,t=Math.random)=>Math.min(3e4,Math.round(Math.min(25e3,1e3*2**Math.min(e,5))*(.8+t()*.4))),gx=`Another controller owns this terminal.`,_x=class{install;onConnection;metadata;binary;stopped=!0;epoch=0;nextId=1;panes=new Map;reconnect;instance=``;failures=0;connectedAt=0;scrollSentAt=new Map;inputSentAt=new Map;openedAt=new Map;constructor(e,t){this.install=e,this.onConnection=t}start(){this.stopped=!1,this.connect()}stop(){this.stopped=!0,clearTimeout(this.reconnect),this.disconnect()}mount(e){let t=this.nextId++;return this.panes.set(t,{...e,generation:1,sequence:new px,writable:!1,accepted:!1,baseline:!1,pending:0,resizing:!1,attempts:0}),this.open(t),{close:()=>{let e=this.panes.get(t);e&&(this.send({type:`release`,streamId:t,generation:e.generation}),e.renderer?.close()),this.panes.delete(t)},input:(e,n=!1)=>{let r=this.panes.get(t);r?.writable&&(this.inputSentAt.set(t,Sp()),this.send({type:`input`,streamId:t,generation:r.generation,text:e,paste:n}))},control:(e=!1)=>{let n=this.panes.get(t);n&&(n.mode!==`control`||e)&&(this.send({type:`release`,streamId:t,generation:n.generation}),n.reason=void 0,n.mode=`control`,++n.generation,n.sequence=new px,this.open(t,e))},observe:()=>{let e=this.panes.get(t);e&&e.mode!==`observe`&&(this.send({type:`release`,streamId:t,generation:e.generation}),e.mode=`observe`,++e.generation,e.sequence=new px,this.open(t))},resize:(e,n,r=!1)=>{let i=this.panes.get(t);i&&(e!==i.cols||n!==i.rows||r&&i.mode===`control`&&i.accepted)&&(i.cols=e,i.rows=n,i.mode===`control`&&i.accepted?(i.writable=!1,i.baseline=!1,i.resizing=!0,i.onState(`Waiting for the resized full baseline.`,!1),this.send({type:`resize`,streamId:t,generation:i.generation,cols:e,rows:n})):(this.send({type:`release`,streamId:t,generation:i.generation}),++i.generation,i.sequence=new px,this.open(t)))},scroll:(e,n,r,i)=>{let a=this.panes.get(t);a?.writable&&(this.scrollSentAt.set(t,Sp()),this.send({type:`scroll`,streamId:t,generation:a.generation,direction:e,lines:n,column:r,row:i}))},mouse:(e,n,r,i,a)=>{let o=this.panes.get(t);o?.writable&&this.send({type:`mouse`,streamId:t,generation:o.generation,action:e,button:n,column:r,row:i,modifiers:a})}}}command(e,t,n,r){let i=[...this.panes.entries()].find(([,r])=>r.machineId===e&&r.threadId===t&&r.terminalId===n);if(!i)return;let[a,o]=i;o.writable=!1,o.reason=void 0,this.send({type:`release`,streamId:a,generation:o.generation}),o.mode=r===`release`?`observe`:`control`,++o.generation,o.sequence=new px,this.open(a,r===`takeover`)}send(e){return this.binary?.readyState!==WebSocket.OPEN||this.metadata?.readyState!==WebSocket.OPEN?!1:this.binary.bufferedAmount>32768?(this.disconnect(),!1):(this.binary.send(JSON.stringify(e)),!0)}open(e,t=!1){let n=this.panes.get(e);n&&(n.writable=!1,n.accepted=!1,n.baseline=!1,n.pending=0,n.resizing=!1,n.renderer?.close(),n.renderer=new mx(n.terminal,t=>{if(this.panes.get(e)!==n||n.generation!==t.generation||!this.send({type:`ack`,streamId:e,generation:t.generation,seq:t.seq}))return;if(--n.pending,t.full&&(!n.resizing||t.width===n.cols&&t.height===n.rows)){n.baseline=!0,n.resizing=!1;let t=this.openedAt.get(e);t!==void 0&&(Sp()-t,this.openedAt.delete(e))}let r=n.mode===`control`&&n.accepted&&n.baseline;n.writable=r,t.full&&n.onState(r?`Input control is active.`:n.reason??`Read-only`,r)}),n.onState(n.mode===`control`?`Waiting for terminal control.`:n.reason??`Read-only`,!1),this.openedAt.set(e,Sp()),this.send({type:`open`,streamId:e,generation:n.generation,machineId:n.machineId,threadId:n.threadId,terminalId:n.terminalId,mode:n.mode,cols:n.cols,rows:n.rows,takeover:t}))}connect(){if(this.stopped)return;this.instance=cm();let e=++this.epoch,t=(location.protocol===`https:`?`wss://`:`ws://`)+location.host,n=new WebSocket(t+`/api/ws/metadata?instance=`+this.instance),r=new WebSocket(t+`/api/ws/terminal?instance=`+this.instance);this.metadata=n,this.binary=r,r.binaryType=`arraybuffer`;let i=()=>{if(e===this.epoch&&n.readyState===1&&r.readyState===1){this.connectedAt=Date.now(),this.onConnection(!0);for(let[e,t]of this.panes)++t.generation,t.sequence=new px,t.attempts=0,this.open(e)}};n.onopen=i,r.onopen=i,n.onmessage=t=>{if(e===this.epoch)try{let e=JSON.parse(t.data);e.type===`projection`&&this.install(e.projection)}catch{this.disconnect()}},r.onmessage=t=>{if(e===this.epoch)try{if(typeof t.data==`string`){let e=JSON.parse(t.data),n=this.panes.get(e.streamId);if(!n||n.generation!==e.generation)return;if(e.type===`stream.opened`&&(n.accepted=!!e.writable&&n.mode===`control`,n.accepted&&(n.baseline=!1,n.resizing=!0,this.send({type:`resize`,streamId:e.streamId,generation:e.generation,cols:n.cols,rows:n.rows})),n.writable=n.accepted&&n.baseline,n.onState(n.writable?`Input control is active.`:n.reason??(n.accepted?`Waiting for the full baseline; input is disabled.`:`Read-only`),n.writable)),e.type===`stream.closed`||e.type===`stream.error`){if(n.writable=!1,n.accepted=!1,n.baseline=!1,n.renderer?.close(),n.onState(e.reason===`controller_conflict`?gx:String(e.reason).replaceAll(`_`,` `),!1),e.type===`stream.error`&&n.mode===`control`){n.reason=e.reason===`controller_conflict`?gx:String(e.reason).replaceAll(`_`,` `),n.mode=`observe`,++n.generation,n.sequence=new px,this.open(e.streamId);return}e.reason===`stream_resync_required`&&n.attempts++<2&&(++n.generation,n.sequence=new px,n.mode=`observe`,this.open(e.streamId))}return}let e=Sp(),n=fx(new Uint8Array(t.data));t.data.byteLength,Sp()-e;let r=this.inputSentAt.get(n.streamId);r!==void 0&&(Sp()-r,this.inputSentAt.delete(n.streamId));let i=this.scrollSentAt.get(n.streamId);i!==void 0&&(Sp()-i,this.scrollSentAt.delete(n.streamId));let a=this.panes.get(n.streamId);if(!a||a.generation!==n.generation)return;a.sequence.accept(n),++a.pending,a.pending,a.renderer?.push(n)}catch{this.disconnect()}};let a=()=>{e===this.epoch&&this.disconnect()};n.onclose=a,n.onerror=a,r.onclose=a,r.onerror=a}disconnect(){this.connectedAt&&Date.now()-this.connectedAt>=3e4&&(this.failures=0),this.connectedAt=0,++this.epoch,this.metadata?.close(),this.binary?.close(),this.metadata=void 0,this.binary=void 0,this.onConnection(!1);for(let e of this.panes.values())e.renderer?.close(),e.writable=!1,e.mode=`observe`,e.onState(`Disconnected; input was not saved.`,!1);clearTimeout(this.reconnect),this.stopped||(this.reconnect=setTimeout(()=>this.connect(),hx(this.failures++)))}},vx=(0,l.createContext)(null);function yx({bootstrap:e,children:t}){let[n]=(0,l.useState)(()=>{let t=ux(e);return{runtime:t,ui:dx(),terminals:new _x(e=>{let n=xp(`projectionInstallMs`);t.getState().install(e),n()},e=>t.getState().connection(e))}}),[r]=(0,l.useState)(()=>new F_({defaultOptions:{queries:{staleTime:15e3,retry:!1}}}));return(0,l.useEffect)(()=>(n.terminals.start(),()=>n.terminals.stop()),[n]),(0,Q.jsx)(vx.Provider,{value:n,children:(0,Q.jsx)(kg,{client:r,children:t})})}function bx(){let e=(0,l.useContext)(vx);if(!e)throw Error(`Runtime provider is missing`);return e}function xx(e){return sx(bx().runtime,e)}var Sx={Enter:`\r`,Backspace:``,Tab:` `,Escape:`\x1B`,ArrowUp:`\x1B[A`,ArrowDown:`\x1B[B`,ArrowRight:`\x1B[C`,ArrowLeft:`\x1B[D`};function Cx(e){let t=e.ctrlKey&&/^[a-z]$/i.test(e.key)?String.fromCharCode(e.key.toUpperCase().charCodeAt(0)-64):Sx[e.key],n=e.key===`Enter`&&e.shiftKey;return t&&(e.altKey||n?`\x1B`+t:t)}var wx=e=>/^[a-z@\[\\\]^_]$/i.test(e)?String.fromCharCode(e.toUpperCase().charCodeAt(0)&31):void 0;function Tx({onInput:e,onFocusChange:t}){let[n,r]=(0,l.useState)(``),i=(0,l.useRef)(!1),a=(0,l.useRef)(null);return(0,Q.jsx)(`textarea`,{className:`terminal-input-capture`,value:n,"aria-label":`Terminal input`,rows:1,onFocus:()=>t?.(!0),onBlur:()=>t?.(!1),onCompositionStart:()=>{i.current=!0,a.current=null},onCompositionEnd:t=>{i.current=!1;let n=t.data;a.current=n,n&&e(n),r(``),t.currentTarget.value=``},onChange:t=>{if(i.current){r(t.target.value);return}let n=t.target.value;n&&n!==a.current&&e(n),a.current=null,r(``),t.currentTarget.value=``},onPaste:t=>{t.preventDefault(),a.current=null;let n=t.clipboardData.getData(`text/plain`);n&&e(n,!0)},onKeyDown:t=>{if(t.defaultPrevented||t.nativeEvent.isComposing||i.current||t.metaKey)return;a.current=null;let n=Cx(t);n&&(t.preventDefault(),e(n))}})}var Ex=[{label:`Tab`,key:`Tab`},{label:(0,Q.jsx)(h,{size:16}),key:`ArrowLeft`,name:`Left`},{label:(0,Q.jsx)(m,{size:16}),key:`ArrowDown`,name:`Down`},{label:(0,Q.jsx)(_,{size:16}),key:`ArrowUp`,name:`Up`},{label:(0,Q.jsx)(g,{size:16}),key:`ArrowRight`,name:`Right`}],Dx=e=>e.preventDefault(),Ox=e=>({onPointerDown:t=>{Dx(t),e()},onMouseDown:Dx,onTouchStart:Dx,onClick:t=>{t.detail===0&&e()}}),kx={idle:`Dictate`,preparing:`Preparing voice input`,recording:`Stop dictation`,transcribing:`Transcribing`},Ax=e=>e===`recording`?(0,Q.jsx)(ce,{size:14,fill:`currentColor`}):e===`idle`?(0,Q.jsx)(R,{size:16}):(0,Q.jsx)(I,{size:16,className:`is-spinning`});function jx({voice:e}){return(0,Q.jsx)(`button`,{type:`button`,tabIndex:-1,"aria-label":kx[e.phase],"aria-pressed":e.phase===`recording`,className:`terminal-voice is-${e.phase}`,...Ox(e.toggle),children:Ax(e.phase)})}function Mx({ctrl:e,onToggleCtrl:t,onBytes:n,voice:r}){return(0,Q.jsxs)(`div`,{className:`terminal-key-bar`,role:`toolbar`,"aria-label":`Terminal keys`,children:[(0,Q.jsx)(`button`,{type:`button`,tabIndex:-1,"aria-pressed":e,className:e?`is-armed`:``,...Ox(t),children:`Ctrl`}),Ex.map(({label:e,key:t,name:r})=>(0,Q.jsx)(`button`,{type:`button`,tabIndex:-1,"aria-label":r??t,...Ox(()=>{let e=Cx({key:t,ctrlKey:!1,altKey:!1});e&&n(e)}),children:e},t)),r?.available&&(0,Q.jsx)(jx,{voice:r})]})}var Nx=`(pointer: coarse)`,Px=120,Fx=350;function Ix(){let e=window.visualViewport;if(!e||!matchMedia(Nx).matches)return()=>{};let t=document.documentElement,n=e.height,r=()=>{t.style.setProperty(`--app-height`,`${e.height}px`),t.style.setProperty(`--app-top`,`${e.offsetTop}px`)},i=()=>{t.style.removeProperty(`--app-height`),t.style.removeProperty(`--app-top`)},a=()=>{n=Math.max(n,e.height,window.innerHeight);let a=n-e.height>Px;a?r():i(),t.toggleAttribute(`data-keyboard-open`,a)};a();let o,s=()=>{clearTimeout(o),o=setTimeout(a,Fx)},c=()=>{n=0,a()};return e.addEventListener(`resize`,a),e.addEventListener(`scroll`,a),window.addEventListener(`orientationchange`,c),window.addEventListener(`focusout`,s),window.addEventListener(`focusin`,s),()=>{clearTimeout(o),window.removeEventListener(`focusout`,s),window.removeEventListener(`focusin`,s),window.removeEventListener(`orientationchange`,c),e.removeEventListener(`resize`,a),e.removeEventListener(`scroll`,a),i(),t.removeAttribute(`data-keyboard-open`)}}function Lx(){return typeof matchMedia==`function`&&matchMedia(Nx).matches}var Rx=100,zx=20,Bx=10,Vx=e=>Bx*(1+Math.min(2,Math.abs(e)/60));function Hx(e,t,n,r){let i=e=>{if(!r()||!e.altKey||e.shiftKey)return;let{element:i,cols:a,rows:o}=t(),s=i?.getBoundingClientRect();if(!s?.width||!s.height)return;let c=Math.floor((e.clientX-s.left)/s.width*a),l=Math.floor((e.clientY-s.top)/s.height*o);if(c<0||l<0||c>=a||l>=o)return;e.preventDefault();let u=e.button===2||e.buttons&2?`right`:e.button===1||e.buttons&4?`middle`:`left`;n()?.mouse(e.type===`pointerdown`?`down`:e.type===`pointerup`?`up`:e.buttons?`drag`:`move`,u,c,l,e.ctrlKey?2:0)},a=0,o=0,s,c=e=>{let{element:n,cols:r,rows:i}=t(),a=n?.getBoundingClientRect();if(a?.width&&a.height)return{column:Math.min(r,Math.max(1,Math.floor((e.clientX-a.left)/a.width*r)+1)),row:Math.min(i,Math.max(1,Math.floor((e.clientY-a.top)/a.height*i)+1))}},l=()=>{let{element:e,rows:n}=t(),r=e?.getBoundingClientRect().height;return r&&n?r/n:zx},u=()=>{o=0;let e=l(),t=Math.trunc(a/e);t&&(a-=t*e,n()?.scroll(t<0?`up`:`down`,Math.min(Rx,Math.abs(t)),s?.column,s?.row))},d=e=>{if(!r()||!e.deltaY)return;s=c(e),e.preventDefault();let t=e.deltaMode===WheelEvent.DOM_DELTA_LINE?e.deltaY*l():e.deltaY;t*a<0&&(a=0),a+=t*Vx(t),o||=requestAnimationFrame(u)};for(let t of[`pointerdown`,`pointerup`,`pointermove`])e.addEventListener(t,i);return e.addEventListener(`wheel`,d,{passive:!1}),()=>{for(let t of[`pointerdown`,`pointerup`,`pointermove`])e.removeEventListener(t,i);e.removeEventListener(`wheel`,d),cancelAnimationFrame(o)}}var Ux=e=>e.target instanceof Element&&!!e.target.closest(`[role="dialog"]`),Wx=`Nothing to attach.`,Gx=e=>e===1?`Attaching file…`:`Attaching ${e} files…`,Kx=e=>e===1?`File attached`:`${e} files attached`;function qx({machineId:e,active:t,writable:n,send:r,show:i}){let[a,o]=(0,l.useState)(!1),s=(0,l.useRef)(r);s.current=r;let c=(0,l.useCallback)(async t=>{if(!t.length){i(Wx,`error`,4e3);return}if(!n.current){i(`Wait until the terminal accepts input, then attach the file again.`,`error`,4e3);return}i(Gx(t.length),`info`);try{s.current(await om(e,t)),i(Kx(t.length),`info`,1500)}catch(e){i(e instanceof Error?e.message:`The file could not be attached.`,`error`,5e3)}},[e,i,n]);return(0,l.useEffect)(()=>{if(!t)return;let e=0,n=t=>{$p(t.dataTransfer)&&!Ux(t)&&(t.preventDefault(),e+=1,o(!0))},r=e=>{$p(e.dataTransfer)&&!Ux(e)&&(e.preventDefault(),e.dataTransfer&&(e.dataTransfer.dropEffect=`copy`))},i=t=>{$p(t.dataTransfer)&&!Ux(t)&&(e=Math.max(0,e-1),e||o(!1))},a=t=>{$p(t.dataTransfer)&&!Ux(t)&&(t.preventDefault(),e=0,o(!1),c(Qp(t.dataTransfer)))};return window.addEventListener(`dragenter`,n),window.addEventListener(`dragover`,r),window.addEventListener(`dragleave`,i),window.addEventListener(`drop`,a),()=>{window.removeEventListener(`dragenter`,n),window.removeEventListener(`dragover`,r),window.removeEventListener(`dragleave`,i),window.removeEventListener(`drop`,a),o(!1)}},[t,c]),{dragging:a,attach:c}}function Jx(e,t){(e.metaKey||e.ctrlKey)&&window.open(t,`_blank`,`noopener,noreferrer`)}function Yx(){let[e,t]=(0,l.useState)(null),n=(0,l.useRef)(void 0),r=(0,l.useCallback)((e,r,i)=>{clearTimeout(n.current),t({text:e,tone:r}),i&&(n.current=setTimeout(()=>t(null),i))},[]);return(0,l.useEffect)(()=>()=>clearTimeout(n.current),[]),{notice:e,show:r}}var Xx=16e3,Zx=`registerProcessor('webr-capture', class extends AudioWorkletProcessor {
3
3
  process([input]) { if (input?.[0]) this.port.postMessage(input[0].slice()); return true; }
4
4
  });`,Qx=()=>typeof window<`u`&&window.isSecureContext&&!!navigator.mediaDevices?.getUserMedia&&typeof AudioWorkletNode<`u`,$x=()=>{try{return new AudioContext({sampleRate:Xx})}catch{return new AudioContext}};function eS(e){let t=new Int16Array(e.reduce((e,t)=>e+t.length,0)),n=0;for(let r of e)for(let e of r)t[n++]=Math.max(-1,Math.min(1,e))*32767;return t.buffer}async function tS(e){let t=URL.createObjectURL(new Blob([Zx],{type:`text/javascript`}));try{await e.audioWorklet.addModule(t)}finally{URL.revokeObjectURL(t)}}async function nS(){let e=$x();e.resume();let t=t=>{t?.getTracks().forEach(e=>e.stop()),e.close()},n;try{n=await navigator.mediaDevices.getUserMedia({audio:{channelCount:1,echoCancellation:!0,noiseSuppression:!0,autoGainControl:!0}}),await tS(e),await e.resume()}catch(e){throw t(n),e}let r=[],i=e.createMediaStreamSource(n),a=new AudioWorkletNode(e,`webr-capture`);a.port.onmessage=e=>r.push(e.data),i.connect(a);let o=()=>{i.disconnect(),a.disconnect(),t(n)};return{stop:async()=>{let t=e.sampleRate;return o(),{pcm:eS(r),sampleRate:t}},cancel:o}}var rS={voice_unavailable:`Voice input is not available on this Webr server.`,image_too_large:`The recording is too long.`};async function iS(){let e=await fetch(`/api/voice`).catch(()=>void 0);return e?.ok?(await e.json()).state:`unavailable`}async function aS(){let e=await fetch(`/api/voice/warm`,{method:`POST`,headers:{"Content-Type":`application/json`},body:`{}`}).catch(()=>void 0);return e?.ok?(await e.json()).state:`unavailable`}async function oS(e,t){let n=await fetch(`/api/voice/transcribe?sampleRate=${t}`,{method:`POST`,headers:{"Content-Type":`audio/l16`},body:e}),r=await n.json().catch(()=>({}));if(!n.ok||r.text===void 0)throw Error(rS[r.error??``]??`The recording could not be transcribed.`);return r.text}var sS=2e3,cS=`Downloading the voice model (670 MB, one time). The mic works when it finishes.`,lS=e=>e===`needs-download`||e===`downloading`,uS=e=>e instanceof DOMException&&e.name===`NotAllowedError`?`Allow microphone access for Webr in your browser settings.`:`The microphone could not start.`;function dS({send:e,show:t}){let[n,r]=(0,l.useState)(`unavailable`),[i,a]=(0,l.useState)(`idle`),o=(0,l.useRef)(void 0),s=(0,l.useRef)(e);s.current=e,(0,l.useEffect)(()=>{if(!Qx())return;let e=!1;return iS().then(t=>{e||r(t)}),()=>{e=!0,o.current?.cancel()}},[]),(0,l.useEffect)(()=>{if(i!==`preparing`)return;let e=setInterval(()=>void iS().then(e=>{lS(e)||(r(e),a(`idle`),t(e===`ready`?`Voice input is ready. Tap the mic to talk.`:`The voice model could not be downloaded.`,e===`ready`?`info`:`error`,4e3))}),sS);return()=>clearInterval(e)},[i,t]);let c=(0,l.useCallback)(()=>{aS(),a(`preparing`),t(cS,`info`)},[t]),u=(0,l.useCallback)(async()=>{a(`recording`);let e=nS();aS();try{o.current=await e}catch(e){a(`idle`),t(uS(e),`error`,5e3)}},[t]),d=(0,l.useCallback)(async()=>{let e=o.current;if(o.current=void 0,e){a(`transcribing`);try{let{pcm:n,sampleRate:r}=await e.stop(),i=await oS(n,r);i?s.current(i):t(`No speech was heard.`,`info`,2500)}catch(e){t(e instanceof Error?e.message:`The recording could not be transcribed.`,`error`,5e3)}finally{a(`idle`)}}},[t]),f=(0,l.useCallback)(()=>{i===`idle`?lS(n)?c():u():i===`recording`&&d()},[i,n,c,u,d]);return{available:n!==`unavailable`,phase:i,toggle:f}}var fS=(function(){let e=typeof document<`u`&&document.createElement(`link`).relList;return e&&e.supports&&e.supports(`modulepreload`)?`modulepreload`:`preload`})(),pS=function(e){return`/`+e},mS={},hS=function(e){return e.pathname.endsWith(`.css`)},gS=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e,i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?new URL(import.meta.resolve(e)):new URL(e,import.meta.url)}r=o(t.map(t=>{t=pS(t,n);let r=s(t);if(r.href in mS)return;mS[r.href]=!0;let i=hS(r);if(e===void 0){e={all:new Set,styles:new Set};let t=document.getElementsByTagName(`link`);for(let n=t.length-1;n>=0;n--){let r=t[n];e.all.add(r.href),r.rel===`stylesheet`&&e.styles.add(r.href)}}if((i?e.styles:e.all).has(r.href))return;let o=document.createElement(`link`);if(o.rel=i?`stylesheet`:fS,i||(o.as=`script`),o.crossOrigin=``,o.href=r.href,a&&o.setAttribute(`nonce`,a),document.head.appendChild(o),i)return new Promise((e,t)=>{o.addEventListener(`load`,e),o.addEventListener(`error`,()=>t(Error(`Unable to preload CSS for ${r}`)))})}).filter(e=>e!==void 0))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})};function _S(){let e=getComputedStyle(document.documentElement);return{background:e.getPropertyValue(`--terminal-bg`).trim(),foreground:e.getPropertyValue(`--terminal-ink`).trim(),cursor:e.getPropertyValue(`--terminal-cursor`).trim(),selectionBackground:e.getPropertyValue(`--terminal-selection`).trim(),black:`#222222`,red:`#df7774`,green:`#8ebea1`,yellow:`#d4b581`,blue:`#81aee0`,magenta:`#ac9dd5`,cyan:`#8dc6cf`,white:`#d5d5d5`,brightBlack:`#777777`,brightRed:`#f18f89`,brightGreen:`#a1d8b6`,brightYellow:`#eed1a2`,brightBlue:`#a7c7ef`,brightMagenta:`#c6b6e8`,brightCyan:`#abdee4`,brightWhite:`#ffffff`}}var vS=`"JetBrains Mono", "Webr Symbols", ui-monospace, Menlo, monospace`,yS=15,bS=()=>typeof document>`u`||!document.fonts?Promise.resolve():Promise.all([document.fonts.load(`400 ${yS}px "JetBrains Mono"`),document.fonts.load(`700 ${yS}px "JetBrains Mono"`),document.fonts.load(`${yS}px "Webr Symbols"`,``)]).then(()=>void 0,()=>void 0),xS=`\x1B[I`,SS=`\x1B[O`,CS=e=>e&&Number.isFinite(e.cols)&&Number.isFinite(e.rows)?e:void 0;function wS(e,t){try{let n=t();n.onContextLoss(()=>n.dispose()),e.loadAddon(n)}catch{}}function TS({pane:t,machineId:n,threadId:r,active:i,canControl:a,onFocus:o}){let s=(0,l.useRef)(null),c=(0,l.useRef)(null),u=(0,l.useRef)(null),d=(0,l.useRef)(null),{terminals:f}=bx(),[p,m]=(0,l.useState)(`Connecting…`),[h,g]=(0,l.useState)(!1),_=(0,l.useRef)(!1),[v,y]=(0,l.useState)(!1),[b,x]=(0,l.useState)(!1),[S,C]=(0,l.useState)(!1);(0,l.useEffect)(()=>C(Lx()),[]);let{notice:w,show:T}=Yx(),E=qx({machineId:n,active:i,writable:_,show:T,send:e=>{d.current?.input(e,!0)}}),D=dS({show:T,send:e=>{d.current?.input(e,!0)}}),O=(0,l.useRef)(e=>{});O.current=e=>e?T(`Copied to clipboard`,`info`,1200):T(`The browser blocked clipboard access.`,`error`,4e3),(0,l.useEffect)(()=>{if(!s.current)return;let i=!1,o=()=>{};return Promise.all([gS(()=>import(`./xterm.B-l5AIf6.js`).then(t=>e(t.default,1)),__vite__mapDeps([0,1])),gS(()=>import(`./addon-fit.jgKqzwky.js`).then(t=>e(t.default,1)),__vite__mapDeps([2,1])),gS(()=>import(`./addon-web-links.C9lyQRxI.js`).then(t=>e(t.default,1)),__vite__mapDeps([3,1])),gS(()=>import(`./addon-webgl.Bd5ox92E.js`).then(t=>e(t.default,1)),__vite__mapDeps([4,1])),bS()]).then(([e,{FitAddon:c},{WebLinksAddon:l},{WebglAddon:p}])=>{if(i||!s.current)return;let h=new e.Terminal({fontFamily:vS,fontSize:yS,lineHeight:1.2,letterSpacing:0,cursorBlink:!0,cursorInactiveStyle:`block`,allowTransparency:!1,scrollback:0,theme:_S(),disableStdin:!0,linkHandler:{activate:()=>{}}});h.open(s.current),wS(h,()=>new p),h.attachCustomWheelEventHandler(()=>!1),u.current=h;let v=()=>{_.current&&s.current?.parentElement?.querySelector(`.terminal-input-capture`)?.focus()};h.textarea?.addEventListener(`focus`,v);let y=Av(s.current,h,()=>_.current,e=>O.current(e)),b=h.parser.registerOscHandler(8,()=>!0);if(!t.terminalId){y(),h.dispose();return}let x=new c;h.loadAddon(x),h.loadAddon(new l(Jx));let S=()=>({cols:Math.floor((s.current?.clientWidth??640)/8),rows:Math.floor((s.current?.clientHeight??400)/20)}),C=()=>{try{return CS(x.proposeDimensions())}catch{return}},w=()=>!!s.current?.isConnected&&s.current.clientWidth>0&&s.current.clientHeight>0,T=()=>{let{cols:e,rows:t}=C()??S();return{cols:Math.max(2,Math.min(500,e)),rows:Math.max(1,Math.min(300,t))}};d.current=f.mount({machineId:n,threadId:r,terminalId:t.terminalId,terminal:h,mode:a?`control`:`observe`,...T(),onState:(e,t)=>{m(e),g(t),_.current=t}});let E=Hx(s.current,()=>({element:h.element?.querySelector(`.xterm-screen`)??void 0,cols:h.cols,rows:h.rows}),()=>d.current,()=>_.current),D,k=new ResizeObserver(()=>{clearTimeout(D),D=setTimeout(()=>{if(!w())return;let{cols:e,rows:t}=T();d.current?.resize(e,t)},150)});k.observe(s.current);let A=()=>{if(document.visibilityState!==`visible`||!document.hasFocus()||!w())return;let{cols:e,rows:t}=T();d.current?.resize(e,t,!0)};window.addEventListener(`focus`,A),document.addEventListener(`visibilitychange`,A);let j=new MutationObserver(()=>{h.options.theme=_S()});j.observe(document.documentElement,{attributes:!0,attributeFilter:[`data-theme`]}),o=()=>{clearTimeout(D),d.current?.close(),d.current=null,_.current=!1,E(),window.removeEventListener(`focus`,A),document.removeEventListener(`visibilitychange`,A),h.textarea?.removeEventListener(`focus`,v),y(),b.dispose(),k.disconnect(),j.disconnect(),h.dispose(),u.current=null}}).catch(()=>m(`The terminal could not load.`)),()=>{i=!0,o()}},[t.id,t.terminalId,n,r,f,a]);let k=(e,t)=>{if(_.current){if(!b||t){d.current?.input(e,t);return}x(!1),d.current?.input(wx(e)??e)}},A=()=>u.current?.focus(),j=()=>{h&&!u.current?.hasSelection()&&(A(),s.current?.parentElement?.querySelector(`.terminal-input-capture`)?.focus())};return(0,l.useEffect)(()=>{i&&j()},[i,h]),(0,l.useEffect)(()=>{u.current&&(u.current.options.cursorInactiveStyle=i?`block`:`outline`)},[i,h]),(0,l.useEffect)(()=>{if(!i||!h)return;let e=e=>e.target===document.body||e.target===document.documentElement||c.current?.contains(e.target),t=t=>{if(t.defaultPrevented||t.metaKey||t.isComposing||!e(t)||t.target.classList?.contains(`terminal-input-capture`))return;let n=Cx(t);n?(t.preventDefault(),t.stopPropagation(),d.current?.input(n)):t.key.length===1&&!t.ctrlKey&&j()},n=t=>{let n=t.target.classList?.contains(`terminal-input-capture`);if(!e(t)&&!n)return;let r=Zp(t.clipboardData);if(r.length){t.preventDefault(),t.stopPropagation(),E.attach(r);return}let i=t.clipboardData?.getData(`text/plain`);i&&!n&&(t.preventDefault(),t.stopPropagation(),d.current?.input(i,!0))};return window.addEventListener(`keydown`,t,!0),window.addEventListener(`paste`,n,!0),()=>{window.removeEventListener(`keydown`,t,!0),window.removeEventListener(`paste`,n,!0)}},[i,h,E.attach]),(0,l.useEffect)(()=>{let e=()=>{i&&j()};return window.addEventListener(`focus`,e),()=>window.removeEventListener(`focus`,e)},[i,h]),(0,Q.jsxs)(`section`,{ref:c,className:`terminal-pane ${i?`is-active`:``}`,"aria-label":`${t.title} terminal`,onPointerDownCapture:()=>{i||o()},onFocusCapture:()=>{i||o()},onClick:()=>{a&&!_.current&&d.current?.control(),j()},children:[(0,Q.jsx)(`span`,{className:`terminal-status`,role:`status`,children:p}),p===`Another controller owns this terminal.`&&(0,Q.jsxs)(`div`,{className:`terminal-control-conflict`,children:[`Another Herdr client controls this terminal.`,(0,Q.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),al(`Replace the other Herdr client that controls this terminal? Its input stops working.`,{confirmLabel:`Take over`}).then(e=>{e&&d.current?.control(!0)})},children:`Take over`})]}),(0,Q.jsx)(`div`,{ref:s,className:`terminal-host`}),E.dragging&&(0,Q.jsxs)(`div`,{className:`terminal-drop-overlay`,"aria-hidden":`true`,children:[(0,Q.jsx)(N,{size:22,strokeWidth:1.6}),(0,Q.jsx)(`span`,{children:`Drop image to attach`})]}),w&&(0,Q.jsx)(`div`,{className:`terminal-attach-notice is-${w.tone}`,role:w.tone===`error`?`alert`:`status`,children:w.text}),(a||h)&&(0,Q.jsx)(Tx,{onInput:k,onFocusChange:e=>{y(e),u.current?.modes.sendFocusMode&&d.current?.input(e?xS:SS)}}),a&&i&&S&&v&&(0,Q.jsx)(Mx,{ctrl:b,onToggleCtrl:()=>x(e=>!e),onBytes:e=>d.current?.input(e),voice:D})]})}function ES({thread:e}){let t=Cb(e),n=xb(e.operation?.step??`validate`);return(0,Q.jsxs)(`main`,{className:`launch-progress`,"aria-label":`Launch progress`,role:`status`,children:[(0,Q.jsx)(`h1`,{children:t?`The launch stopped`:`Starting your agent`}),(0,Q.jsx)(`blockquote`,{className:`launch-prompt`,children:e.prompt||e.title}),(0,Q.jsx)(`ol`,{className:`launch-steps`,children:yb.map((e,r)=>{let i=r<n?`done`:r===n?t?`failed`:`active`:`waiting`,a=i===`done`?C:i===`failed`?S:i===`active`?I:T;return(0,Q.jsxs)(`li`,{className:`launch-step is-${i}`,"aria-current":i===`active`?`step`:void 0,children:[(0,Q.jsx)(a,{size:16,strokeWidth:1.8,"aria-hidden":`true`}),e.label]},e.id)})}),t&&(0,Q.jsxs)(`div`,{className:`launch-failure`,role:`alert`,children:[(0,Q.jsxs)(`p`,{children:[`Herdr stopped while `,yb[n].label.toLowerCase(),`. The worktree may already exist, so check it in Herdr before you try again.`]}),(0,Q.jsx)(`a`,{className:`launch-retry`,href:`/new?project=${encodeURIComponent(e.projectId)}`,children:`Start a new thread`})]})]})}var DS=({pane:e})=>e.kind===`agent`?(0,Q.jsx)(v,{size:14,strokeWidth:1.8,"aria-hidden":`true`}):(0,Q.jsx)(se,{size:14,strokeWidth:1.8,"aria-hidden":`true`});function OS({pane:e,side:t,onOpen:n}){return(0,Q.jsx)(Yl,{label:`Show ${e.title}`,side:t===`left`?`right`:`left`,children:(0,Q.jsxs)(`button`,{type:`button`,className:`pane-collapsed`,"aria-label":`Show ${e.title}`,onClick:n,children:[(0,Q.jsx)(DS,{pane:e}),(0,Q.jsx)(`span`,{children:e.title})]})})}var kS=(e,t)=>JSON.stringify([t,e.map(e=>e.id)]),AS=(e,t)=>{let[n,r]=JSON.parse(e);return{start:n,panes:r.flatMap(e=>t.filter(t=>t.id===e))}},jS=(e,t)=>AS((0,l.useDeferredValue)(kS(e,t)),e);function MS({panes:e,windowStart:t,onFocusPane:n,renderPane:r}){let{panes:i,start:a}=jS(e,t),o=e=>e>=a&&e<a+2;return(0,Q.jsx)(`div`,{className:`pane-strip ${i.length>1?`is-split`:``}`,children:i.map((e,t)=>(0,Q.jsx)(l.ViewTransition,{default:`pane-move`,enter:`pane-enter`,exit:`pane-exit`,children:o(t)?(0,Q.jsx)(`div`,{className:`pane-slot`,children:r(e)}):(0,Q.jsx)(OS,{pane:e,side:t<a?`left`:`right`,onOpen:()=>n(e.id)})},e.id))})}function NS({panes:e,focusedPane:t,onFocusPane:n,renderPane:r}){let i=(0,l.useDeferredValue)(t),a=e.find(e=>e.id===i)??e[0];return(0,Q.jsxs)(`div`,{className:`pane-tabbed`,children:[e.length>1&&(0,Q.jsx)(`div`,{className:`pane-tabs`,role:`tablist`,"aria-label":`Panes`,children:e.map(e=>(0,Q.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":e.id===a?.id,className:`pane-tab`,onClick:()=>n(e.id),children:[(0,Q.jsx)(DS,{pane:e}),(0,Q.jsx)(`span`,{children:e.title})]},e.id))}),a&&(0,Q.jsx)(l.ViewTransition,{enter:`pane-enter`,exit:`pane-exit`,children:(0,Q.jsx)(`div`,{className:`pane-slot`,role:`tabpanel`,children:r(a)})},a.id)]})}function PS({thread:e,connected:t,canControl:n,onFocusPane:r,focusedPane:i,windowStart:o,narrow:s}){let c=t&&(Sb(e)||Cb(e)),u=t&&e.bindingState===`detached`&&!c;(0,l.useEffect)(()=>{u&&a(`/new?project=${encodeURIComponent(e.projectId)}`)},[u,e.projectId]);let d=t=>t.terminalId?(0,Q.jsx)(TS,{pane:t,machineId:e.machineId,threadId:e.id,active:i===t.id,canControl:n,onFocus:()=>r(t.id)},t.terminalId):null;if(c)return(0,Q.jsx)(ES,{thread:e});let f={panes:e.panes,focusedPane:i,onFocusPane:r,renderPane:d};return(0,Q.jsxs)(`main`,{className:`native-thread-layout`,"aria-label":`${e.title} tab`,children:[(!t||e.bindingState!==`attached`)&&(0,Q.jsx)(`p`,{className:`runtime-notice`,role:`status`,children:t?`Waiting for the terminal to attach…`:`Disconnected; input is disabled.`}),t&&e.bindingState===`attached`&&!n&&(0,Q.jsx)(`p`,{className:`runtime-notice`,role:`status`,children:`Terminal input is unavailable because this Herdr version is not supported.`}),t&&e.bindingState===`attached`&&(s?(0,Q.jsx)(NS,{...f}):(0,Q.jsx)(MS,{...f,windowStart:o}))]})}var FS=e=>Symbol.iterator in e,IS=e=>`entries`in e,LS=(e,t)=>{let n=e instanceof Map?e:new Map(e.entries()),r=t instanceof Map?t:new Map(t.entries());if(n.size!==r.size)return!1;for(let[e,t]of n)if(!r.has(e)||!Object.is(t,r.get(e)))return!1;return!0},RS=(e,t)=>{let n=e[Symbol.iterator](),r=t[Symbol.iterator](),i=n.next(),a=r.next();for(;!i.done&&!a.done;){if(!Object.is(i.value,a.value))return!1;i=n.next(),a=r.next()}return!!i.done&&!!a.done};function zS(e,t){return Object.is(e,t)?!0:typeof e!=`object`||!e||typeof t!=`object`||!t||Object.getPrototypeOf(e)!==Object.getPrototypeOf(t)?!1:FS(e)&&FS(t)?IS(e)&&IS(t)?LS(e,t):RS(e,t):LS({entries:()=>Object.entries(e)},{entries:()=>Object.entries(t)})}function BS(e){let t=l.useRef(void 0);return n=>{let r=e(n);return zS(t.current,r)?t.current:t.current=r}}function VS(e,t){if(e.repeat||e.defaultPrevented||e.isComposing)return;let n=e.target;if(!n?.closest(`[data-recording="true"]`)&&(!n?.closest(`input, textarea, select, [contenteditable="true"]`)||n.closest(`.xterm, .terminal-input-capture`)))return Object.entries(t).find(([,t])=>t===$f(e))?.[0]}var HS=`(max-width: 760px)`;function US(e,t,n,r){let i=sx(e,e=>e.paneWindows[t]??0),a=bp(n.length,i,n.indexOf(r));return(0,l.useEffect)(()=>{a!==i&&e.getState().showWindow(t,a)},[e,t,a,i]),a}var WS=e=>{if(typeof matchMedia!=`function`)return()=>{};let t=matchMedia(HS);return t.addEventListener(`change`,e),()=>t.removeEventListener(`change`,e)},GS=()=>typeof matchMedia==`function`&&matchMedia(HS).matches,KS=()=>(0,l.useSyncExternalStore)(WS,GS,()=>!1);function qS(e,t,n){let r=e?.status===`done`;(0,l.useEffect)(()=>{e&&t&&r&&n&&fetch(`/api/threads/${encodeURIComponent(e.id)}/focus`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({machineId:e.machineId,paneId:t})}).catch(()=>void 0)},[e?.id,e?.machineId,t,r,n])}var JS=e=>e.preventDefault();function YS(e){return(0,Q.jsx)(qp,{children:(0,Q.jsx)(yx,{bootstrap:e.bootstrap,children:(0,Q.jsx)(XS,{...e})})})}function XS({page:e,bootstrap:t,threadId:n,projectId:r}){let{ui:i,terminals:o}=bx(),s=xx(BS(e=>e.projectIds.map(t=>e.projects[t]))),c=xx(BS(e=>e.threadIds.map(t=>e.threads[t]).filter(e=>!e.archivedAt&&Eb(e)))),u=xx(BS(e=>e.threadIds.map(t=>e.threads[t]).filter(e=>!!e.archivedAt))),d=xx(e=>e.threads[n??``]),f=xx(e=>e.projections),p=xx(e=>e.connected),m=Object.values(f).flatMap(e=>{let n=e.machine??t.machines.find(t=>t.id===e.machineId);return n?[{...n,connected:p&&e.connected,error:e.error}]:[]}),[h,g]=(0,l.useState)(!1),[_,v]=(0,l.useState)(!1),[y,b]=(0,l.useState)(!1);(0,l.useEffect)(Cp,[]),(0,l.useEffect)(Ix,[]);let[x,S]=(0,l.useState)(`threads`),C=`${d?.machineId??``}:${d?.id??``}`,w=sx(i,e=>e.focusedPanes[C]),T=d?.panes.some(e=>e.id===w)?w:d?.panes[0]?.id??``,D=(0,l.useCallback)(e=>i.getState().focus(C,e),[i,C]);qS(e===`thread`?d:void 0,T,p&&!!m.find(e=>e.id===d?.machineId)?.writable);let O=(0,l.useRef)(void 0);(0,l.useEffect)(()=>{d?O.current=d.id:e===`thread`&&O.current===n&&a(`/`)},[d,e,n]),(0,l.useEffect)(()=>{let e=e=>{$p(e.dataTransfer)&&e.preventDefault()};return window.addEventListener(`dragover`,e),window.addEventListener(`drop`,e),()=>{window.removeEventListener(`dragover`,e),window.removeEventListener(`drop`,e)}},[]),(0,l.useEffect)(()=>{let e=()=>g(new URLSearchParams(window.location.search).get(`sidebar`)===`collapsed`);e(),window.addEventListener(`popstate`,e),S(localStorage.getItem(`webr-sidebar-mode`)===`projects`?`projects`:`threads`);let t=matchMedia(`(prefers-color-scheme: dark)`),n=()=>{(localStorage.getItem(`webr-theme`)??`system`)===`system`&&tp(`system`)};return t.addEventListener(`change`,n),()=>{t.removeEventListener(`change`,n),window.removeEventListener(`popstate`,e)}},[]);let k=e=>void ol(e instanceof Error?e.message:`Herdr could not change the pane.`),A=US(i,C,d?.panes.map(e=>e.id)??[],T),j=KS(),M=(0,l.useCallback)(()=>{d&&T&&dp(d,T).then(({paneId:e})=>D(e),k)},[d,T,D]),N=(0,l.useCallback)(async(e=T)=>{if(!d||!_p(d,e))return;let t=d.panes.find(t=>t.id===e),n=yp(d.panes,A,e);try{let r=await fp(d,e,!1);r.busy&&await al(`${t.title} is running a process. Close it anyway?`,{confirmLabel:`Close`,danger:!0})&&(r=await fp(d,e,!0)),r.closed&&n&&D(n.id)}catch(e){k(e)}},[d,T,A,D]),P=(0,l.useCallback)(()=>{if(window.matchMedia(`(max-width: 760px)`).matches){v(e=>!e);return}g(e=>{let t=!e,n=new URL(window.location.href);return t?n.searchParams.set(`sidebar`,`collapsed`):n.searchParams.delete(`sidebar`),window.history.replaceState(window.history.state,``,n),t})},[]),F=(0,l.useCallback)(e=>{S(e),localStorage.setItem(`webr-sidebar-mode`,e)},[]);return(0,l.useEffect)(()=>{let e=e=>{if(e.repeat||e.isComposing||e.target?.closest(`[data-recording="true"]`))return;if(e.metaKey&&!e.ctrlKey&&!e.altKey&&!e.shiftKey&&e.key.toLowerCase()===`k`){e.preventDefault(),b(e=>!e);return}if(y||e.defaultPrevented)return;let t=VS(e,Xf());if(t){if(e.preventDefault(),t===`toggleSidebar`&&P(),t===`openTerminal`&&M(),t===`closePane`&&N(),t===`newThread`&&a(`/new${d?`?project=${encodeURIComponent(d.projectId)}`:``}`),(t===`nextPane`||t===`previousPane`)&&d?.panes.length){let e=d.panes.findIndex(e=>e.id===T);D(d.panes[(e+(t===`nextPane`?1:-1)+d.panes.length)%d.panes.length].id)}if((t===`nextThread`||t===`previousThread`)&&c.length){let e=c.findIndex(e=>e.id===d?.id),n=t===`nextThread`?(e+1)%c.length:(e-1+c.length)%c.length;a(`/threads/${encodeURIComponent(c[n].id)}`)}}};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[d,c,y,P,M,N,T,D]),(0,Q.jsxs)(`div`,{className:`app-shell ${e===`thread`?`is-thread`:``}`,children:[(0,Q.jsx)(rx,{projects:s,threads:c,archived:u,machines:m,currentId:d?.id,mode:x,onModeChange:F,collapsed:h,mobileOpen:_,onCollapse:P,onCloseMobile:()=>v(!1),onOpenPalette:()=>b(!0)}),(0,Q.jsxs)(`div`,{className:`main-panel`,children:[e===`thread`&&d&&(0,Q.jsx)(PS,{thread:d,connected:p&&!!f[d.machineId]?.connected,canControl:!!m.find(e=>e.id===d.machineId)?.writable,focusedPane:T,onFocusPane:D,windowStart:A,narrow:j}),e===`new`&&(0,Q.jsx)(Sv,{projects:s,machines:m,selectedProjectId:r,onOpenSidebar:P},r),e===`settings`&&(0,Q.jsx)(Dy,{onOpenSidebar:P}),e===`missing`&&(0,Q.jsxs)(`main`,{className:`not-found`,children:[(0,Q.jsx)(`h1`,{children:`Thread not found`}),(0,Q.jsx)(`a`,{href:`/`,children:`Open a thread`})]})]}),e===`thread`&&(0,Q.jsxs)(`div`,{className:`mobile-controls`,children:[(0,Q.jsx)(`button`,{"aria-label":`Open sidebar`,onPointerDown:JS,onClick:P,children:(0,Q.jsx)(ne,{size:22})}),(0,Q.jsx)(`button`,{"aria-label":`Open command palette`,onPointerDown:JS,onClick:()=>b(!0),children:(0,Q.jsx)(E,{size:22})})]}),!1,(0,Q.jsx)(Kp,{}),(0,Q.jsx)(Tp,{open:y,onClose:()=>b(!1),projects:s,threads:c,thread:d,focusedPane:T,mode:x,onModeChange:F,onToggleSidebar:P,onFocusPane:D,onTerminalAction:e=>{let t=d?.panes.find(e=>e.id===T);d&&t?.terminalId&&o.command(d.machineId,d.id,t.terminalId,e)},onOpenTerminal:M,onClosePane:()=>void N()})]})}export{YS as default};