@pablopunk/webr 0.2.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/dist/client/_astro/{App.1VFY1ClT.css → App.96TkmFyF.css} +1 -1
- package/dist/client/_astro/App.DcDWCCM1.js +4 -0
- package/dist/client/apple-touch-icon.png +0 -0
- package/dist/client/icon-192.png +0 -0
- package/dist/client/icon-512.png +0 -0
- package/dist/server/chunks/{App_C2vmjHiY.mjs → App_DlKdj0Cm.mjs} +207 -214
- package/dist/server/chunks/{_id__BimjoFCd.mjs → _id__yn5rOSmn.mjs} +1 -1
- package/dist/server/chunks/{_tab__WmsbMlfC.mjs → _tab__C9ScWvmu.mjs} +1 -1
- package/dist/server/chunks/{new_bTXSW7C3.mjs → new_DkzcgJw-.mjs} +1 -1
- package/dist/server/chunks/{settings_DwzWmJBe.mjs → settings_DZDiF9cU.mjs} +1 -1
- package/dist/server/entry.mjs +5 -5
- package/package.json +2 -1
- package/server/rebuilt-restart.ts +7 -7
- package/server/run.ts +3 -0
- package/src/lib/models.ts +1 -1
- package/src/lib/pane-strip.ts +19 -0
- package/src/server/host.ts +6 -6
- package/src/server/runtime/herdr-actions.ts +6 -2
- package/src/server/runtime/manager.ts +27 -24
- package/src/server/runtime/reconcile.ts +2 -1
- package/src/server/runtime/target.ts +1 -0
- package/src/server/transport/herdr-target.ts +1 -0
- package/src/server/transport/registry.ts +1 -1
- package/src/server/transport/saved-machines.ts +2 -2
- package/src/server/websockets.ts +5 -9
- package/dist/client/_astro/App.CGyf2WDA.js +0 -4
- package/src/lib/terminal-split.ts +0 -23
|
@@ -0,0 +1,4 @@
|
|
|
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"])))=>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(`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`}]]),A=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 j=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`}]]),M=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`}]]),N=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`}]]),P=d(`LoaderCircle`,[[`path`,{d:`M21 12a9 9 0 1 1-6.219-8.56`,key:`13zald`}]]),F=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`}]]),I=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`}]]),L=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`}]]),R=d(`Moon`,[[`path`,{d:`M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z`,key:`a7tn18`}]]),z=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`}]]),ee=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`}]]),B=d(`PanelLeft`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 3v18`,key:`fh3hqa`}]]),te=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`}]]),ne=d(`Plus`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`M12 5v14`,key:`s699le`}]]),re=d(`Search`,[[`circle`,{cx:`11`,cy:`11`,r:`8`,key:`4ej97u`}],[`path`,{d:`m21 21-4.3-4.3`,key:`1qie3q`}]]),V=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`}]]),H=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`}]]),ie=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`}]]),ae=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`}]]),oe=d(`Square`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]),se=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`}]]),ce=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`}]]),le=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`}]]),ue=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 de(){return typeof window<`u`}function W(e){return pe(e)?(e.nodeName||``).toLowerCase():`#document`}function G(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function fe(e){return((pe(e)?e.ownerDocument:e.document)||window.document)?.documentElement}function pe(e){return de()?e instanceof Node||e instanceof G(e).Node:!1}function K(e){return de()?e instanceof Element||e instanceof G(e).Element:!1}function q(e){return de()?e instanceof HTMLElement||e instanceof G(e).HTMLElement:!1}function me(e){return!de()||typeof ShadowRoot>`u`?!1:e instanceof ShadowRoot||e instanceof G(e).ShadowRoot}function he(e){let{overflow:t,overflowX:n,overflowY:r,display:i}=Ee(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&i!==`inline`&&i!==`contents`}function ge(e){return/^(table|td|th)$/.test(W(e))}function _e(e){try{if(e.matches(`:popover-open`))return!0}catch{}try{return e.matches(`:modal`)}catch{return!1}}var ve=/transform|translate|scale|rotate|perspective|filter/,ye=/paint|layout|strict|content/,be=e=>!!e&&e!==`none`,xe;function Se(e){let t=K(e)?Ee(e):e;return be(t.transform)||be(t.translate)||be(t.scale)||be(t.rotate)||be(t.perspective)||!we()&&(be(t.backdropFilter)||be(t.filter))||ve.test(t.willChange||``)||ye.test(t.contain||``)}function Ce(e){let t=Oe(e);for(;q(t)&&!Te(t);){if(Se(t))return t;if(_e(t))return null;t=Oe(t)}return null}function we(){return xe??=typeof CSS<`u`&&CSS.supports&&CSS.supports(`-webkit-backdrop-filter`,`none`),xe}function Te(e){return/^(html|body|#document)$/.test(W(e))}function Ee(e){return G(e).getComputedStyle(e)}function De(e){return K(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Oe(e){if(W(e)===`html`)return e;let t=e.assignedSlot||e.parentNode||me(e)&&e.host||fe(e);return me(t)?t.host:t}function ke(e){let t=Oe(e);return Te(t)?(e.ownerDocument||e).body:q(t)&&he(t)?t:ke(t)}function Ae(e,t,n){t===void 0&&(t=[]),n===void 0&&(n=!0);let r=ke(e),i=r===e.ownerDocument?.body,a=G(r);if(i){let e=je(a);return t.concat(a,a.visualViewport||[],he(r)?r:[],e&&n?Ae(e):[])}return t.concat(r,Ae(r,[],n))}function je(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function J(e,t,n,r){return e.addEventListener(t,n,r),()=>{e.removeEventListener(t,n,r)}}function Me(){return typeof navigator>`u`?{userAgent:``,platform:``,maxTouchPoints:0}:{userAgent:navigator.userAgent,platform:navigator.platform??``,maxTouchPoints:navigator.maxTouchPoints??0}}var{userAgent:Ne,platform:Pe,maxTouchPoints:Fe}=Me(),Ie=Ne.toLowerCase(),Le=Pe.toLowerCase(),Re=/^i(os$|p)/.test(Le)||Le===`macintel`&&Fe>1,ze=`android`,Be=Le===ze||Ie.includes(ze),Ve=!Re&&Le.startsWith(`mac`);Le.startsWith(`win`),!Be&&/^(linux|chrome os)/.test(Le);var He=Ve||Re,Ue=typeof CSS<`u`&&!!CSS.supports?.(`-webkit-backdrop-filter:none`),We=!Ue&&Ie.includes(`firefox`);!Ue&&Ie.includes(`chrom`);var Ge=He,Ke=/jsdom|happydom/.test(Ie);function qe(e){return e?.ownerDocument||document}var Je={};function Ye(e,t){let n=l.useRef(Je);return n.current===Je&&(n.current=e(t)),n}function Xe(){}var Ze=Object.freeze([]),Qe=Object.freeze({});function $e(e){l.useEffect(e,Ze)}var et=0,tt=class e{static create(){return new e}currentId=et;start(e,t){this.clear(),this.currentId=setTimeout(()=>{this.currentId=et,t()},e)}isStarted(){return this.currentId!==et}clear=()=>{this.currentId!==et&&(clearTimeout(this.currentId),this.currentId=et)};disposeEffect=()=>this.clear};function nt(){let e=Ye(tt.create).current;return $e(e.disposeEffect),e}var rt=null;globalThis.requestAnimationFrame;var it=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)}},at=class e{static create(){return new e}static request(e){return it.request(e)}static cancel(e){return it.cancel(e)}currentId=rt;request(e){this.cancel(),this.currentId=it.request(()=>{this.currentId=rt,e()})}cancel=()=>{this.currentId!==rt&&(it.cancel(this.currentId),this.currentId=rt)};disposeEffect=()=>this.cancel};function ot(){let e=Ye(at.create).current;return $e(e.disposeEffect),e}var st={},ct={},lt=``;function ut(e,t){return he(e)?e:t}function dt(e,t,n){return/hidden|clip/.test(e.getComputedStyle(ut(t,n)).overflowY)}function Y(e){if(typeof document>`u`)return!1;let t=qe(e);return G(t).innerWidth-t.documentElement.clientWidth>0}function ft(e){if(!(typeof CSS<`u`&&CSS.supports&&CSS.supports(`scrollbar-gutter`,`stable`))||typeof document>`u`)return!1;let t=qe(e),n=t.documentElement,r=t.body,i=ut(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 pt(e){let t=qe(e),n=t.documentElement,r=t.body,i=ut(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 mt(e){let t=qe(e),n=t.documentElement,r=t.body,i=G(n),a=0,o=0,s=!1,c=at.create();if(Ue&&(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,st={scrollbarGutter:n.style.scrollbarGutter,overflowY:n.style.overflowY,overflowX:n.style.overflowX},lt=n.style.scrollBehavior,ct={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=ut(n,r);if(s=ft(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,st),Object.assign(r.style,ct),s||(n.scrollTop=a,n.scrollLeft=o,n.removeAttribute(`data-base-ui-scroll-locked`),n.style.scrollBehavior=lt)}function d(){u(),c.request(l)}l();let f=J(i,`resize`,d);return()=>{c.cancel(),u(),typeof i.removeEventListener==`function`&&f()}}var ht=new class{lockCount=0;restore=null;timeoutLock=tt.create();timeoutUnlock=tt.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=qe(e),n=t.documentElement,r=t.body,i=G(n);if(dt(i,n,r)){let t=new i.MutationObserver(()=>{dt(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=Re||!Y(e);this.restore=a?pt(e):mt(e)}};function gt(e=!0,t=null){U(()=>{if(e)return ht.acquire(t)},[e,t])}function _t(e){e.preventDefault(),e.stopPropagation()}function vt(e){return`nativeEvent`in e}function yt(e){return e.pointerType===``&&e.isTrusted?!0:Be&&e.pointerType?e.type===`click`&&e.buttons===1:e.detail===0&&!e.pointerType}function bt(e){return Ke?!1:!Be&&e.width===0&&e.height===0||Be&&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 xt(e,t){let n=[`mouse`,`pen`];return t||n.push(``,void 0),n.includes(e)}function St(e){let t=e.type;return t===`click`||t===`mousedown`||t===`keydown`||t===`keyup`}function Ct(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&&me(n)){let n=t;for(;n;){if(e===n)return!0;n=n.parentNode||n.host}}return!1}function wt(e){return`composedPath`in e?e.composedPath()[0]??e.target:e.target}var Tt=`data-base-ui-focusable`,Et=`input:not([type='hidden']):not([disabled]),[contenteditable]:not([contenteditable='false']),textarea:not([disabled])`,Dt=`ArrowLeft`,Ot=`ArrowRight`,kt=`ArrowUp`,At=`ArrowDown`,jt=`data-starting-style`,Mt=`data-ending-style`,Nt={[jt]:``},Pt={[Mt]:``},Ft={transitionStatus(e){return e===`starting`?Nt:e===`ending`?Pt:null}},It=`data-open`,Lt=`data-closed`,Rt=`data-anchor-hidden`,zt=`data-popup-open`,Bt=`data-pressed`,Vt={[zt]:``},Ht={[zt]:``,[Bt]:``},Ut={[It]:``},Wt={[Lt]:``},Gt={[Rt]:``},Kt={open(e){return e?Vt:null}},qt={open(e){return e?Ht:null}},Jt={open(e){return e?Ut:Wt},anchorHidden(e){return e?Gt:null}},Yt={...Jt,...Ft},Xt=`data-trigger-disabled`;function Zt(e,t){if(!K(e))return!1;let n=e;if(t.hasElement(n))return!n.hasAttribute(Xt);for(let[,e]of t.entries())if(X(e,n))return!e.hasAttribute(Xt);return!1}function Qt(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 $t(e){return e.matches(`html,body`)}function en(e){return q(e)&&e.matches(`input:not([type='hidden']):not([disabled]),[contenteditable]:not([contenteditable='false']),textarea:not([disabled])`)}function tn(e){return e?.closest(`button,a[href],[role="button"],select,[tabindex]:not([tabindex="-1"]),${Et}`)!=null}function nn(e){return e?e.getAttribute(`role`)===`combobox`&&en(e):!1}function rn(e){if(!e||Ke)return!0;try{return e.matches(`:focus-visible`)}catch{return!0}}function an(e){return e?e.hasAttribute(`data-base-ui-focusable`)?e:e.querySelector(`[data-base-ui-focusable]`)||e:null}function on(e,t){return t!=null&&!xt(t)?0:typeof e==`function`?e():e}function sn(e,t,n){let r=on(e,n);return typeof r==`number`?r:r?.[t]}function cn(e){return typeof e==`function`?e():e}function ln(e,t){return t||e===`click`||e===`mousedown`}function un(e){return e?.includes(`mouse`)&&e!==`mousedown`}var dn=`none`,fn=`trigger-press`,pn=`trigger-hover`,mn=`trigger-focus`,hn=`outside-press`,gn=`item-press`,_n=`close-press`,vn=`input-change`,yn=`input-clear`,bn=`input-press`,xn=`focus-out`,Sn=`escape-key`,Cn=`list-navigation`,wn=`keyboard`,Tn=`pointer`,En=`cancel-open`,Dn=`sibling-open`,On=`disabled`,kn=`imperative-action`;function Z(e,t,n,r){let i=!1,a=!1,o=r??Qe;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 An(e,t,n){let r=n??Qe;return{reason:e,event:t??new Event(`base-ui`),...r}}var jn=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=jn()}))(),Mn=l.createContext({hasProvider:!1,timeoutMs:0,delayRef:{current:0},initialDelayRef:{current:0},timeout:new tt,currentIdRef:{current:null},currentContextRef:{current:null}});function Nn(e,t){e.current=t.current}function Pn(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(Mn),[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:sn(c.current,`close`)},t!==null&&t!==i?(m(!0),e?.setIsInstantPhase(!0),e?.onOpenChange(!1,Z(dn))):(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,Nn(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 Fn(...e){return()=>{for(let t=0;t<e.length;t+=1){let n=e[t];n&&n()}}}function In(e,t,n,r){let i=Ye(Rn).current;return zn(i,e,t,n,r)&&Vn(i,[e,t,n,r]),i.callback}function Ln(e){let t=Ye(Rn).current;return Bn(t,e)&&Vn(t,e),t.callback}function Rn(){return{callback:null,cleanup:null,refs:[]}}function zn(e,t,n,r,i){return e.refs[0]!==t||e.refs[1]!==n||e.refs[2]!==r||e.refs[3]!==i}function Bn(e,t){return e.refs.length!==t.length||e.refs.some((e,n)=>e!==t[n])}function Vn(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 Hn(e){let t=Ye(Un,e).current;return t.next=e,U(t.effect),t}function Un(e){let t={current:e,next:e,effect:()=>{t.current=t.next}};return t}var Wn={...l},Gn=Wn.useInsertionEffect,Kn=Gn&&Gn!==Wn.useLayoutEffect?Gn:e=>e();function $(e){let t=Ye(qn).current;return t.next=e,Kn(t.effect),t.trampoline}function qn(){let e={next:void 0,callback:Jn,trampoline:(...t)=>e.callback?.(...t),effect:()=>{e.callback=e.next}};return e}function Jn(){}var Yn={clipPath:`inset(50%)`,overflow:`hidden`,whiteSpace:`nowrap`,border:0,padding:0,width:1,height:1,margin:-1},Xn={...Yn,position:`fixed`,top:0,left:0},Zn={...Yn,position:`absolute`},Qn=l.forwardRef(function(e,t){let[n,r]=l.useState();U(()=>{Ge&&Ue&&r(`button`)},[]);let i={tabIndex:0,role:n};return(0,Q.jsx)(`span`,{...e,ref:t,style:Xn,"aria-hidden":!n||void 0,...i,"data-base-ui-focus-guard":``})}),$n=Math.min,er=Math.max,tr=Math.round,nr=Math.floor,rr=e=>({x:e,y:e}),ir={left:`right`,right:`left`,bottom:`top`,top:`bottom`};function ar(e,t,n){return er(e,$n(t,n))}function or(e,t){return typeof e==`function`?e(t):e}function sr(e){return e.split(`-`)[0]}function cr(e){return e.split(`-`)[1]}function lr(e){return e===`x`?`y`:`x`}function ur(e){return e===`y`?`height`:`width`}function dr(e){let t=e[0];return t===`t`||t===`b`?`y`:`x`}function fr(e){return lr(dr(e))}function pr(e,t,n){n===void 0&&(n=!1);let r=cr(e),i=fr(e),a=ur(i),o=i===`x`?r===(n?`end`:`start`)?`right`:`left`:r===`start`?`bottom`:`top`;return t.reference[a]>t.floating[a]&&(o=Sr(o)),[o,Sr(o)]}function mr(e){let t=Sr(e);return[hr(e),t,hr(t)]}function hr(e){return e.includes(`start`)?e.replace(`start`,`end`):e.replace(`end`,`start`)}var gr=[`left`,`right`],_r=[`right`,`left`],vr=[`top`,`bottom`],yr=[`bottom`,`top`];function br(e,t,n){switch(e){case`top`:case`bottom`:return n?t?_r:gr:t?gr:_r;case`left`:case`right`:return t?vr:yr;default:return[]}}function xr(e,t,n,r){let i=cr(e),a=br(sr(e),n===`start`,r);return i&&(a=a.map(e=>e+`-`+i),t&&(a=a.concat(a.map(hr)))),a}function Sr(e){let t=sr(e);return ir[t]+e.slice(t.length)}function Cr(e){return{top:e.top??0,right:e.right??0,bottom:e.bottom??0,left:e.left??0}}function wr(e){return typeof e==`number`?{top:e,right:e,bottom:e,left:e}:Cr(e)}function Tr(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 Er(e,t,n){return Math.floor(e/t)!==n}function Dr(e,t){return t<0||t>=e.length}function Or(e,t){return Ar(e.current,{disabledIndices:t})}function kr(e,t){return Ar(e.current,{decrement:!0,startingIndex:e.current.length,disabledIndices:t})}function Ar(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&&Mr(e,a,r));return a}function jr(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(!Mr(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=nr(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(!Mr(e,r,s))return r}};d&&_t(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=Ar(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=Ar(e,{startingIndex:u%y-y,amount:y,disabledIndices:s}),i&&(f=i(t,u,f)))}Dr(e,f)&&(f=u)}if(n===`both`){let n=nr(u/o);t.key===(a?`ArrowLeft`:`ArrowRight`)&&(d&&_t(t),u%o===o-1?r&&(f=Ar(e,{startingIndex:u-u%o-1,disabledIndices:s}),i&&(f=i(t,u,f))):(f=Ar(e,{startingIndex:u,disabledIndices:s}),r&&Er(f,o,n)&&(f=Ar(e,{startingIndex:u-u%o-1,disabledIndices:s}),i&&(f=i(t,u,f)))),Er(f,o,n)&&(f=u)),t.key===(a?`ArrowRight`:`ArrowLeft`)&&(d&&_t(t),u%o===0?r&&(f=Ar(e,{startingIndex:u+(o-u%o),decrement:!0,disabledIndices:s}),i&&(f=i(t,u,f))):(f=Ar(e,{startingIndex:u,decrement:!0,disabledIndices:s}),r&&Er(f,o,n)&&(f=Ar(e,{startingIndex:u+(o-u%o),decrement:!0,disabledIndices:s}),i&&(f=i(t,u,f)))),Er(f,o,n)&&(f=u));let c=nr(l/o)===n;Dr(e,f)&&(r&&c?(f=t.key===(a?`ArrowRight`:`ArrowLeft`)?l:Ar(e,{startingIndex:u-u%o-1,disabledIndices:s}),i&&(f=i(t,u,f))):f=u)}return f}function Mr(e,t,n){if(typeof n==`function`?n(t):n?.includes(t)??!1)return!0;let r=e[t];return r?!Pr(r)||r.matches(`:disabled`)?!0:!n&&(r.hasAttribute(`disabled`)||r.getAttribute(`aria-disabled`)===`true`):!1}function Nr(e){return e.visibility===`hidden`||e.visibility===`collapse`}function Pr(e,t=e?Ee(e):null){return!e||!e.isConnected||!t||Nr(t)?!1:typeof e.checkVisibility==`function`?e.checkVisibility():t.display!==`none`&&t.display!==`contents`}var Fr=`a[href],button,input,select,textarea,summary,details,iframe,object,embed,[tabindex],[contenteditable]:not([contenteditable="false"]),audio[controls],video[controls]`;function Ir(e){let t=e.assignedSlot;if(t)return t;if(e.parentElement)return e.parentElement;let n=e.getRootNode();return me(n)?n.host:null}function Lr(e){for(let t of Array.from(e.children))if(W(t)===`summary`)return t;return null}function Rr(e,t){let n=Lr(t);return!!n&&(e===n||X(n,e))}function zr(e){let t=e?W(e):``;return e!=null&&e.matches(Fr)&&(t!==`summary`||e.parentElement!=null&&W(e.parentElement)===`details`&&Lr(e.parentElement)===e)&&(t!==`details`||Lr(e)==null)&&(t!==`input`||e.type!==`hidden`)}function Br(e){if(!zr(e)||!e.isConnected||e.matches(`:disabled`))return!1;for(let t=e;t;t=Ir(t)){let n=t!==e,r=W(t)===`slot`;if(t.hasAttribute(`inert`)||n&&W(t)===`details`&&!t.open&&!Rr(e,t)||t.hasAttribute(`hidden`)||!r&&!Vr(t,n))return!1}return!0}function Vr(e,t){let n=Ee(e);return t?n.display!==`none`:Pr(e,n)}function Hr(e){let t=e.tabIndex;if(t<0){let t=W(e);if(t===`details`||t===`audio`||t===`video`||q(e)&&e.isContentEditable)return 0}return t}function Ur(e){if(W(e)!==`input`)return null;let t=e;return t.type===`radio`&&t.name!==``?t:null}function Wr(e,t){let n=Ur(e);if(!n)return!0;let r=t.find(e=>{let t=Ur(e);return t?.name===n.name&&t.form===n.form&&t.checked});return r?r===n:t.find(e=>{let t=Ur(e);return t?.name===n.name&&t.form===n.form})===n}function Gr(e){if(q(e)&&W(e)===`slot`){let t=e.assignedElements({flatten:!0});if(t.length>0)return t}return q(e)&&e.shadowRoot?Array.from(e.shadowRoot.children):Array.from(e.children)}function Kr(e,t){Gr(e).forEach(e=>{zr(e)&&t.push(e),Kr(e,t)})}function qr(e,t,n){Gr(e).forEach(e=>{q(e)&&e.matches(t)&&n.push(e),qr(e,t,n)})}function Jr(e){return Br(e)&&Hr(e)>=0}function Yr(e){let t=[];return Kr(e,t),t.filter(Br)}function Xr(e){let t=Yr(e);return t.filter(e=>Hr(e)>=0&&Wr(e,t))}function Zr(e,t){let n=Xr(e),r=n.length;if(r===0)return;let i=Ct(qe(e)),a=n.indexOf(i);return n[a===-1?t===1?0:r-1:a+t]}function Qr(e){return Zr(qe(e).body,1)||e}function $r(e){return Zr(qe(e).body,-1)||e}function ei(e,t){if(!e)return null;let n=Xr(qe(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 ti(e){return ei(e,1)}function ni(e){return ei(e,-1)}function ri(e,t){let n=t||e.currentTarget,r=e.relatedTarget;return!r||!X(n,r)}function ii(e){Xr(e).forEach(e=>{e.dataset.tabindex=e.getAttribute(`tabindex`)||``,e.setAttribute(`tabindex`,`-1`)})}function ai(e){let t=[];qr(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 oi(e,t,n=!0){return e.filter(e=>e.parentId===t).flatMap(t=>[...!n||t.context?.open?[t]:[],...oi(e,t.id,n)])}function si(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 ci(e){return`data-base-ui-${e}`}var li=0;function ui(e,t={}){let{preventScroll:n=!1,sync:r=!1,shouldFocus:i}=t;cancelAnimationFrame(li);function a(){(!i||i())&&e?.focus({preventScroll:n})}if(r)return a(),Xe;let o=requestAnimationFrame(a);return li=o,()=>{li===o&&(cancelAnimationFrame(o),li=0)}}var di={inert:new WeakMap,"aria-hidden":new WeakMap},fi=`data-base-ui-inert`,pi={inert:new WeakSet,"aria-hidden":new WeakSet},mi=new WeakMap,hi=0;function gi(e){return pi[e]}function _i(e){return e?me(e)?e.host:_i(e.parentNode):null}var vi=(e,t)=>t.map(t=>{if(e.contains(t))return t;let n=_i(t);return e.contains(n)?n:null}).filter(e=>e!=null),yi=e=>{let t=new Set;return e.forEach(e=>{let n=e;for(;n&&!t.has(n);)t.add(n),n=n.parentNode}),t},bi=(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 xi(e,t,n,r,{mark:i=!0}){let a=null;r?a=`inert`:n&&(a=`aria-hidden`);let o=null,s=null,c=vi(t,e),l=i?bi(t,yi(c),new Set(c)):[],u=[],d=[];if(a){let e=di[a],n=gi(a);s=n,o=e;let r=vi(t,Array.from(t.querySelectorAll(`[aria-live]`))),i=c.concat(r);bi(t,yi(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=(mi.get(e)||0)+1;mi.set(e,t),d.push(e),t===1&&e.setAttribute(fi,``)}),hi+=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=(mi.get(e)||0)-1;mi.set(e,t),t||e.removeAttribute(fi)}),--hi,hi||(di.inert=new WeakMap,di[`aria-hidden`]=new WeakMap,pi.inert=new WeakSet,pi[`aria-hidden`]=new WeakSet,mi=new WeakMap)}}function Si(e,t={}){let{ariaHidden:n=!1,inert:r=!1,mark:i=!0}=t,a=qe(e[0]).body;return xi(e,a,n,r,{mark:i})}var Ci=0;function wi(e,t=`mui`){let[n,r]=l.useState(e),i=e||n;return l.useEffect(()=>{n??(Ci+=1,r(`${t}-${Ci}`))},[n,t]),i}var Ti=Wn.useId;function Ei(e,t){if(Ti!==void 0){let n=Ti();return e??(t?`${t}-${n}`:n)}return wi(e,t)}function Di(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 Oi=Di(`https://base-ui.com/production-error`,`Base UI`),ki=19;function Ai(e){return ki>=e}function ji(e){if(!l.isValidElement(e))return null;let t=e,n=t.props;return(Ai(19)?n?.ref:t.ref)??null}function Mi(e,t){if(e&&!t)return e;if(!e&&t)return t;if(e||t)return{...e,...t}}function Ni(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 Pi(e,t){return typeof e==`function`?e(t):e}function Fi(e,t){return typeof e==`function`?e(t):e}var Ii={};function Li(e,t,n,r,i){if(!n&&!r&&!i&&!e)return zi(t);let a=zi(e);return t&&(a=Bi(a,t)),n&&(a=Bi(a,n)),r&&(a=Bi(a,r)),i&&(a=Bi(a,i)),a}function Ri(e){if(e.length===0)return Ii;if(e.length===1)return zi(e[0]);let t=zi(e[0]);for(let n=1;n<e.length;n+=1)t=Bi(t,e[n]);return t}function zi(e){return Wi(e)?{...Gi(e,Ii)}:Vi(e)}function Bi(e,t){return Wi(t)?Gi(t,e):Hi(e,t)}function Vi(e){let t={...e};for(let e in t){let n=t[e];Ui(e,n)&&(t[e]=qi(n))}return t}function Hi(e,t){if(!t)return e;for(let n in t){let r=t[n];switch(n){case`style`:e[n]=Mi(e.style,r);break;case`className`:e[n]=Yi(e.className,r);break;default:e[n]=Ui(n,r)?Ki(e[n],r):r}}return e}function Ui(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 Wi(e){return typeof e==`function`}function Gi(e,t){return Wi(e)?e(t):e??Ii}function Ki(e,t){return t?e?(...n)=>{let r=n[0];if(Xi(r)){let i=r;Ji(i);let a=t(...n);return i.baseUIHandlerPrevented||e?.(...n),a}let i=t(...n);return e?.(...n),i}:qi(t):e}function qi(e){return e&&((...t)=>{let n=t[0];return Xi(n)&&Ji(n),e(...t)})}function Ji(e){return e.preventBaseUIHandler=()=>{e.baseUIHandlerPrevented=!0},e}function Yi(e,t){return t?e?t+` `+e:t:e}function Xi(e){return typeof e==`object`&&!!e&&`nativeEvent`in e}function Zi(e,t,n={}){let r=t.render;n.enabled!==!1&&(r=ta(r));let i=Qi(t,n,r);if(n.enabled===!1)return null;let a=n.state??Qe;return na(e,r,i,a)}function Qi(e,t,n){let{className:r,style:i}=e,{state:a=Qe,ref:o,props:s,stateAttributesMapping:c,enabled:l=!0}=t,u=l?Pi(r,a):void 0,d=l?Fi(i,a):void 0,f=l?Ni(a,c):Qe,p=l&&s?$i(s):void 0,m=l?Mi(f,p)??{}:Qe;return typeof document<`u`&&(l?m.ref=Array.isArray(o)?Ln([m.ref,ji(n),...o]):In(m.ref,ji(n),o):In(null,null)),l?(u!==void 0&&(m.className=Yi(m.className,u)),d!==void 0&&(m.style=Mi(m.style,d)),m):Qe}function $i(e){return Array.isArray(e)?Ri(e):Li(void 0,e)}var ea=Symbol.for(`react.lazy`);function ta(e){if(e?.$$typeof!==ea)return e;let t=l.Children.toArray(e)[0];return l.isValidElement(t)?t:e}function na(e,t,n,r){if(t){if(typeof t==`function`)return t(n,r);let e=Li(n,t.props);return e.ref=n.ref,l.cloneElement(t,e)}if(e&&typeof e==`string`)return ra(e,n);throw Error(Oi(8))}function ra(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 ia={style:{transition:`none`}},aa={fallbackAxisSide:`none`},oa={fallbackAxisSide:`end`},sa={clipPath:`inset(50%)`,position:`fixed`,top:0,left:0},ca=e(n(),1),la=l.createContext(null),ua=()=>l.useContext(la),da=ci(`portal`);function fa(e={}){let{ref:t,container:n,componentProps:r=Qe,elementProps:i}=e,a=Ei(),o=ua()?.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&&(pe(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=Zi(`div`,r,{ref:[t,f],props:[{id:a,[da]:``},i]}),h=s&&m?ca.createPortal(m,s):null;return{node:u,nodeId:l.isValidElement(m)?m.props.id:void 0,subtree:h}}var pa=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}=fa({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&&ri(e)&&(e.type===`focusin`?y.current&&=(ai(u),!1):(ii(u),y.current=!0))}return Fn(J(u,`focusin`,e,!0),J(u,`focusout`,e,!0))},[u,b]),U(()=>{u&&x===!0&&y.current&&(ai(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)(la.Provider,{value:C,children:[S&&u&&(0,Q.jsx)(Qn,{"data-type":`outside`,ref:p,onFocus:e=>{ri(e,u)?h.current?.focus():$r(_?_.domReference:null)?.focus()}}),S&&u&&(0,Q.jsx)(`span`,{role:s,"aria-owns":d,style:sa}),u&&ca.createPortal(a,u),S&&u&&(0,Q.jsx)(Qn,{"data-type":`outside`,ref:m,onFocus:e=>{ri(e,u)?g.current?.focus():(Qr(_?_.domReference:null)?.focus(),_?.closeOnFocusOut&&_?.onOpenChange(!1,Z(`focus-out`,e.nativeEvent)))}})]})]})});function ma(){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 ha=class{nodesRef={current:[]};events=ma();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)}},ga=l.createContext(null),_a=l.createContext(null),va=()=>l.useContext(ga)?.id||null,ya=e=>{let t=l.useContext(_a);return e??t};function ba(e){let t=Ei(),n=ya(e),r=va();return U(()=>{if(!t)return;let e={id:t,parentId:r};return n?.addNode(e),()=>{n?.removeNode(e)}},[n,t,r]),t}function xa(e){let{children:t,id:n}=e,r=va();return(0,Q.jsx)(ga.Provider,{value:l.useMemo(()=>({id:n,parentId:r}),[n,r]),children:t})}function Sa(e){let{children:t,externalTree:n}=e,r=Ye(()=>n??new ha).current;return(0,Q.jsx)(_a.Provider,{value:r,children:t})}function Ca(e){return e==null?e:`current`in e?e.current:e}function wa(e,t){let n=G(wt(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 Ta=20,Ea=[];function Da(){Ea=Ea.filter(e=>e.deref()?.isConnected)}function Oa(e){Da(),e&&W(e)!==`body`&&(Ea.push(new WeakRef(e)),Ea.length>Ta&&(Ea=Ea.slice(-20)))}function ka(){return Da(),Ea[Ea.length-1]?.deref()}function Aa(e){return e?Jr(e)?e:Xr(e)[0]||e:null}function ja(e){if(e.hasAttribute(`tabindex`)&&!e.hasAttribute(`data-tabindex`)||!e.getAttribute(`role`)?.includes(`dialog`))return;let t=Yr(e).filter(e=>{let t=e.getAttribute(`data-tabindex`)||``;return Jr(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 Ma(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=nn(v)&&C,T=Hn(i),E=Hn(a),D=Hn(u),O=Hn(_),k=ya(m),A=ua(),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=In(L,p,A?.beforeInsideRef),ee=In(R,A?.afterInsideRef),B=nt(),te=nt(),ne=ot(),re=A!=null,V=an(y),H=$((e=V)=>e?Xr(e):[]),ie=$(()=>h?.().filter(e=>e!=null)??[]);l.useEffect(()=>{if(r||!s)return;function e(e){e.key===`Tab`&&X(V,Ct(qe(V)))&&H().length===0&&!w&&_t(e)}return J(qe(V),`keydown`,e)},[r,V,s,w,H]),l.useEffect(()=>{if(r||!_)return;let e=qe(V);function t(){N.current=!1}function n(e){let t=wt(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 Fn(J(e,`pointerdown`,n,!0),J(e,`pointerup`,t,!0),J(e,`pointercancel`,t,!0),J(e,`keydown`,i,!0),t)},[r,y,v,V,_,A,te,ie]),l.useEffect(()=>{if(r||!c)return;let e=qe(V);function t(){M.current=!0,te.start(0,()=>{M.current=!1})}function n(e){let t=wt(e);Jr(t)&&(P.current=t)}function i(t){let n=t.relatedTarget,r=t.currentTarget,i=wt(t);s&&n==null&&i!=null&&X(y,i)&&Oa(i),queueMicrotask(()=>{let a=S(),c=g.context.triggerElements,l=ie(),u=n?.hasAttribute(ci(`focus-guard`))&&[L.current,R.current,A?.beforeInsideRef.current,A?.afterInsideRef.current,A?.beforeOutsideRef.current,A?.afterOutsideRef.current,Ca(f),Ca(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&&(oi(k.nodesRef.current,a).find(e=>X(e.context?.elements.floating,n)||X(e.context?.elements.domReference,n))||si(k.nodesRef.current,a).find(e=>[e.context?.elements.floating,an(e.context?.elements.floating)].includes(n)||e.context?.elements.domReference===n)));if(r===v&&V&&ja(V),o&&r!==v&&!Pr(i)&&Ct(e)===e.body){if(q(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;q(n)&&n.focus()}if(x.current.insideReactTree){x.current.insideReactTree=!1;return}(w||!s)&&n&&p&&!M.current&&(w||n!==ka())&&(j.current=!0,g.setOpen(!1,Z(xn,t)))})}function a(){N.current||(x.current.insideReactTree=!0,B.start(0,()=>{x.current.insideReactTree=!1}))}let l=q(v)?v:null;if(y||l)return Fn(l&&J(l,`focusout`,i),l&&J(l,`pointerdown`,t),y&&J(y,`focusin`,n),y&&J(y,`focusout`,i),y&&A&&J(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(`[${ci(`portal`)}]`)||[]),t=(k?si(k.nodesRef.current,S()):[]).find(e=>nn(e.context?.elements.domReference||null))?.context?.elements.domReference,n=Si([y,...e,L.current,R.current,A?.beforeOutsideRef.current,A?.afterOutsideRef.current,...ie(),t,Ca(f),Ca(d),w?v:null].filter(e=>e!=null),{ariaHidden:s||w,mark:!1}),i=Si([y,...e].filter(e=>e!=null));return()=>{i(),n()}},[_,r,v,y,s,A,w,k,S,d,f,ie]),U(()=>{if(!_||r||!q(V))return;F.current=``,I.current=``;let e=qe(V),t=Ct(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():Ca(r),o||=a();let s=X(V,Ct(e));ui(o,{preventScroll:o===V,shouldFocus(){if(!O.current)return!1;if(s)return!0;let t=Ct(e);return!(t!==o&&X(V,t))}})})},[r,_,V,H,T,D,O]),U(()=>{if(r||!V)return;let e=qe(V),t=Ct(e),n=D.current==null;Oa(t);function i(e){if(e.open||(F.current=wa(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(yt(e.nativeEvent)||bt(e.nativeEvent))j.current=!1;else{let e=!1;qe(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||=ka()||null,typeof i==`boolean`?s:Ca(i)||s||null}return()=>{b.off(`openchange`,i);let t=Ct(e),n=ie(),r=X(y,t)||n.some(e=>e===t||X(e,t))||k&&oi(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=Aa(c),i=typeof o!=`boolean`;if(o&&!j.current&&q(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(!Ue||_||!y)return;let e=Ct(qe(y));q(e)&&en(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 ja(V),()=>{queueMicrotask(Da)}},[r,V]);let ae=!r&&(!s||!w)&&(re||s);return(0,Q.jsxs)(l.Fragment,{children:[ae&&(0,Q.jsx)(Qn,{"data-type":`inside`,ref:z,onFocus:e=>{if(s){let e=H();ui(e[e.length-1])}else A?.portalNode&&(j.current=!1,ri(e,A.portalNode)?Qr(v)?.focus():Ca(f??A.beforeOutsideRef)?.focus())}}),n,ae&&(0,Q.jsx)(Qn,{"data-type":`inside`,ref:ee,onFocus:e=>{s?ui(H()[0]):A?.portalNode&&(c&&(j.current=!0),ri(e,A.portalNode)?$r(v)?.focus():Ca(d??A.afterOutsideRef)?.focus())}})]})}function Na(e,t={}){let{enabled:n=!0,event:r=`click`,toggle:i=!0,ignoreMouse:a=!1,stickIfOpen:o=!0,touchOpenDelay:s=0,reason:c=fn}=t,u=`rootStore`in e?e.rootStore:e,d=u.context.dataRef,f=l.useRef(void 0),p=ot(),m=nt(),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=xt(e.pointerType,!0)&&bt(e.nativeEvent)?`virtual`:e.pointerType},onMouseDown(n){let i=f.current,o=n.nativeEvent,s=u.select(`open`);if(n.button!==0||r===`click`||xt(i,!0)&&a)return;let c=t(s,n.currentTarget,e=>e===`click`||e===`mousedown`),l=wt(o);if(en(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}xt(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}:Qe,[n,h])}function Pa(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 Fa(e){return e!=null&&e.clientX!=null}function Ia(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||Fa(c.current.openEvent))&&i.set(`positionReference`,Pa(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=xt(f)?o:a;l.useEffect(()=>{if(!n){g(s);return}if(!y)return;function e(){d.current?.(),d.current=null}let t=G(o);function r(t){let n=wt(t);X(o,n)?e():_(t.clientX,t.clientY)}return!c.current.openEvent||Fa(c.current.openEvent)?d.current=J(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 La(){return!1}function Ra(e){return{escapeKey:typeof e==`boolean`?e:e?.escapeKey??!1,outsidePress:typeof e==`boolean`?e:e?.outsidePress??!0}}function za(e,t={}){let{enabled:n=!0,escapeKey:r=!0,outsidePress:i=!0,outsidePressEvent:a=`sloppy`,referencePress:o=La,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=ya(c),g=$(typeof i==`function`?i:()=>!1),_=typeof i==`function`?g:i,v=_!==!1,y=$(()=>a),{escapeKey:b,outsidePress:x}=Ra(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=nt(),A=nt(),j=$(()=>{A.clear(),p.current.insideReactTree=!1}),M=$(e=>{let t=p.current.floatingContext?.nodeId;return(h?oi(h.nodesRef.current,t):[]).some(t=>t.context?.open&&!t.context.dataRef.current[e])}),N=$(e=>Qt(e,u.select(`floatingElement`))||Qt(e,u.select(`domReferenceElement`))),P=$(e=>{o()&&u.setOpen(!1,Z(fn,e.nativeEvent))}),F=$(e=>{if(!d||!n||!r||e.key!==`Escape`||E.current||!b&&M(`__escapeKeyBubbles`))return;let t=Z(Sn,vt(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=wt(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 tt,t=new tt,i=qe(f);function a(){e.clear(),E.current=!0}function o(){e.start(Ue?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&&oi(h.nodesRef.current,t).some(t=>Qt(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=wt(e),r=`[${ci(`inert`)}]`,i=K(n)?n.getRootNode():null,a=Array.from((me(i)?i:qe(u.select(`floatingElement`))).querySelectorAll(r)),o=u.context.triggerElements;if(n&&(o.hasElement(n)||o.hasMatchingElement(e=>X(e,n))))return;let s=K(n)?n:null;for(;s&&!Te(s);){let e=Oe(s);if(Te(e)||!K(e))break;s=e}if(!(a.length&&K(n)&&!$t(n)&&!X(n,u.select(`floatingElement`))&&a.every(e=>!X(s,e)))){if(q(n)&&!(`touches`in e)){let t=Te(n),r=Ee(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&&!yt(e)&&!T.current)return;if(w.current){t.clear(),w.current=!1;return}}(typeof _!=`function`||_(e))&&(M(`__outsidePressBubbles`)||(u.setOpen(!1,Z(hn,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=wt(e);if(!n)return;let r=J(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=Fn(r&&Fn(J(i,`keydown`,F),J(i,`compositionstart`,a),J(i,`compositionend`,o)),v&&Fn(J(i,`click`,z,!0),J(i,`pointerdown`,z,!0),J(i,`pointerup`,ee,!0),J(i,`pointercancel`,ee,!0),J(i,`mousedown`,z,!0),J(i,`mouseup`,ee,!0),J(i,`touchstart`,R,{capture:!0,passive:!0}),J(i,`touchmove`,te,{capture:!0,passive:!0}),J(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 Ba(e,t,n){let{reference:r,floating:i}=e,a=dr(t),o=fr(t),s=ur(o),c=sr(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=cr(t);return m&&(p[o]+=f*(m===`end`?1:-1)*(n&&l?-1:1)),p}async function Va(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}=or(t,e),p=wr(f),m=o[d?u===`floating`?`reference`:`floating`:u],h=Tr(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=Tr(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 Ha=50,Ua=async(e,t,n)=>{let{placement:r=`bottom`,strategy:i=`absolute`,middleware:a=[],platform:o}=n,s=o.detectOverflow?o:{...o,detectOverflow:Va},c=await(o.isRTL==null?void 0:o.isRTL(t)),l=await o.getElementRects({reference:e,floating:t,strategy:i}),{x:u,y:d}=Ba(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<Ha&&(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}=Ba(l,f,c)),n=-1)}return{x:u,y:d,placement:f,strategy:i,middlewareData:m}},Wa=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}=or(e,t);if((n=i.arrow)!=null&&n.alignmentOffset)return{};let g=sr(r),_=dr(o),v=sr(o)===o,y=await(s.isRTL==null?void 0:s.isRTL(c.floating)),b=d||(v||!m?[Sr(o)]:mr(o)),x=p!==`none`;!d&&x&&b.push(...xr(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=pr(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`||_===dr(t)||T.every(e=>dr(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=dr(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{}}}},Ga=new Set([`left`,`top`]);async function Ka(e,t){let{placement:n,platform:r,elements:i}=e,a=await(r.isRTL==null?void 0:r.isRTL(i.floating)),o=sr(n),s=cr(n),c=dr(n)===`y`,l=Ga.has(o)?-1:1,u=a&&c?-1:1,d=or(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 qa=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 Ka(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}}}}},Ja=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}=or(e,t),u={x:n,y:r},d=await a.detectOverflow(t,l),f=dr(i),p=lr(f),m=u[p],h=u[f],g=(e,t)=>ar(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}}}}}},Ya=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}=or(e,t),u={x:n,y:r},d=dr(i),f=lr(d),p=u[f],m=u[d],h=or(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=Ga.has(sr(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}}}},Xa=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}=or(e,t),c=await i.detectOverflow(t,s),l=sr(n),u=cr(n),d=dr(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=$n(p-c[m],g),y=$n(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*er(c.left,c.right):S=p-2*er(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 Za(e){let t=Ee(e),n=parseFloat(t.width)||0,r=parseFloat(t.height)||0,i=q(e),a=i?e.offsetWidth:n,o=i?e.offsetHeight:r,s=tr(n)!==a||tr(r)!==o;return s&&(n=a,r=o),{width:n,height:r,$:s}}function Qa(e){return K(e)?e:e.contextElement}function $a(e){let t=Qa(e);if(!q(t))return rr(1);let n=t.getBoundingClientRect(),{width:r,height:i,$:a}=Za(t),o=(a?tr(n.width):n.width)/r,s=(a?tr(n.height):n.height)/i;return(!o||!Number.isFinite(o))&&(o=1),(!s||!Number.isFinite(s))&&(s=1),{x:o,y:s}}var eo=rr(0);function to(e){let t=G(e);return!we()||!t.visualViewport?eo:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function no(e,t,n){return t===void 0&&(t=!1),!!n&&t&&n===G(e)}function ro(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);let i=e.getBoundingClientRect(),a=Qa(e),o=rr(1);t&&(r?K(r)&&(o=$a(r)):o=$a(e));let s=no(a,n,r)?to(a):rr(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=G(a),t=K(r)?G(r):r,n=e,i=je(n);for(;i&&t!==n;){let e=$a(i),t=i.getBoundingClientRect(),r=Ee(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=G(i),i=je(n)}}return Tr({width:u,height:d,x:c,y:l})}function io(e,t){let n=De(e).scrollLeft;return t?t.left+n:ro(fe(e)).left+n}function ao(e,t){let n=e.getBoundingClientRect();return{x:n.left+t.scrollLeft-io(e,n),y:n.top+t.scrollTop}}function oo(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e,a=i===`fixed`,o=fe(r),s=t?_e(t.floating):!1;if(r===o||s&&a)return n;let c={scrollLeft:0,scrollTop:0},l=rr(1),u=rr(0),d=q(r);if((d||!a)&&((W(r)!==`body`||he(o))&&(c=De(r)),d)){let e=ro(r);l=$a(r),u.x=e.x+r.clientLeft,u.y=e.y+r.clientTop}let f=o&&!d&&!a?ao(o,c):rr(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 so(e){return e.getClientRects?Array.from(e.getClientRects()):[]}function co(e){let t=De(e),n=e.ownerDocument.body,r=er(e.scrollWidth,e.clientWidth,n.scrollWidth,n.clientWidth),i=er(e.scrollHeight,e.clientHeight,n.scrollHeight,n.clientHeight),a=-t.scrollLeft+io(e),o=-t.scrollTop;return Ee(n).direction===`rtl`&&(a+=er(e.clientWidth,n.clientWidth)-r),{width:r,height:i,x:a,y:o}}var lo=25;function uo(e,t,n){n===void 0&&(n=`viewport`);let r=n===`layoutViewport`,i=G(e),a=fe(e),o=i.visualViewport,s=a.clientWidth,c=a.clientHeight,l=0,u=0;if(o){let e=!we()||t===`fixed`;r?e||(l=-o.offsetLeft,u=-o.offsetTop):(s=o.width,c=o.height,e&&(l=o.offsetLeft,u=o.offsetTop))}if(io(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<=lo&&(s-=o)}return{width:s,height:c,x:l,y:u}}function fo(e,t){let n=ro(e,!0,t===`fixed`),r=n.top+e.clientTop,i=n.left+e.clientLeft,a=$a(e);return{width:e.clientWidth*a.x,height:e.clientHeight*a.y,x:i*a.x,y:r*a.y}}function po(e,t,n){let r;if(t===`viewport`||t===`layoutViewport`)r=uo(e,n,t);else if(t===`document`)r=co(fe(e));else if(K(t))r=fo(t,n);else{let n=to(e);r={x:t.x-n.x,y:t.y-n.y,width:t.width,height:t.height}}return Tr(r)}function mo(e,t){let n=t.get(e);if(n)return n;let r=Ae(e,[],!1).filter(e=>K(e)&&W(e)!==`body`),i=null,a=Ee(e).position===`fixed`,o=a?Oe(e):e;for(;K(o)&&!Te(o);){let e=Ee(o),t=Se(o),n=i?i.position:a?`fixed`:``;!t&&(n===`fixed`||n===`absolute`&&e.position===`static`)?r=r.filter(e=>e!==o):i=e,o=Oe(o)}return t.set(e,r),r}function ho(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e,a=[...n===`clippingAncestors`?_e(t)?[]:mo(t,this._c):[].concat(n),r],o=po(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=po(t,a[e],i);s=er(n.top,s),c=$n(n.right,c),l=$n(n.bottom,l),u=er(n.left,u)}return{width:c-u,height:l-s,x:u,y:s}}function go(e){let{width:t,height:n}=Za(e);return{width:t,height:n}}function _o(e,t,n){let r=q(t),i=fe(t),a=n===`fixed`,o=ro(e,!0,a,t),s={scrollLeft:0,scrollTop:0},c=rr(0);if((r||!a)&&((W(t)!==`body`||he(i))&&(s=De(t)),r)){let e=ro(t,!0,a,t);c.x=e.x+t.clientLeft,c.y=e.y+t.clientTop}!r&&i&&(c.x=io(i));let l=i&&!r&&!a?ao(i,s):rr(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 vo(e){return Ee(e).position===`static`}function yo(e,t){if(!q(e)||Ee(e).position===`fixed`)return null;if(t)return t(e);let n=e.offsetParent;return fe(e)===n&&(n=n.ownerDocument.body),n}function bo(e,t){let n=G(e);if(_e(e))return n;if(!q(e)){let t=Oe(e);for(;t&&!Te(t);){if(K(t)&&!vo(t))return t;t=Oe(t)}return n}let r=yo(e,t);for(;r&&ge(r)&&vo(r);)r=yo(r,t);return r&&Te(r)&&vo(r)&&!Se(r)?n:r||Ce(e)||n}var xo=async function(e){let t=this.getOffsetParent||bo,n=this.getDimensions,r=await n(e.floating);return{reference:_o(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function So(e){return Ee(e).direction===`rtl`}var Co={convertOffsetParentRelativeRectToViewportRelativeRect:oo,getDocumentElement:fe,getClippingRect:ho,getOffsetParent:bo,getElementRects:xo,getClientRects:so,getDimensions:go,getScale:$a,isElement:K,isRTL:So};function wo(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function To(e,t,n){let r=null,i,a=fe(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=nr(d),h=nr(a.clientWidth-(u+f)),g=nr(a.clientHeight-(d+p)),_=nr(u),v={rootMargin:-m+`px `+-h+`px `+-g+`px `+-_+`px`,threshold:er(0,$n(1,c))||1},y=!0;function b(t){let n=t[0].intersectionRatio;if(!wo(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=G(e),l=()=>s(n);return c.addEventListener(`resize`,l),s(!0),()=>{c.removeEventListener(`resize`,l),o()}}function Eo(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=Qa(e),u=i||a?[...l?Ae(l):[],...t?Ae(t):[]]:[];u.forEach(e=>{i&&e.addEventListener(`scroll`,n),a&&e.addEventListener(`resize`,n)});let d=l&&s?To(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?ro(e):null;c&&g();function g(){let t=ro(e);h&&!wo(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 Do=qa,Oo=Ja,ko=Wa,Ao=Xa,jo=Ya,Mo=(e,t,n)=>{let r=new Map,i=n??{},a={...Co,...i.platform,_c:r};return Ua(e,t,{...i,platform:a})},No=typeof document<`u`?l.useLayoutEffect:function(){};function Po(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(!Po(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)&&!Po(e[n],t[n]))return!1}return!0}return e!==e&&t!==t}function Fo(e){return typeof window>`u`?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function Io(e,t){let n=Fo(e);return Math.round(t*n)/n}function Lo(e){let t=l.useRef(e);return No(()=>{t.current=e}),t}function Ro(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);Po(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=Lo(c),O=Lo(i),k=Lo(u),A=l.useCallback(()=>{if(!C.current||!w.current)return;let e={placement:t,strategy:n,middleware:p};O.current&&(e.platform=O.current),Mo(C.current,w.current,e).then(e=>{let t={...e,isPositioned:k.current!==!1};j.current&&!Po(T.current,t)&&(T.current=t,ca.flushSync(()=>{f(t)}))})},[p,t,n,O,k]);No(()=>{u===!1&&T.current.isPositioned&&(T.current.isPositioned=!1,f(e=>({...e,isPositioned:!1})))},[u]);let j=l.useRef(!1);No(()=>(j.current=!0,()=>{j.current=!1}),[]),No(()=>{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=Io(N.floating,d.x),r=Io(N.floating,d.y);return s?{...e,transform:`translate(`+t+`px, `+r+`px)`,...Fo(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 zo=(e,t)=>{let n=Do(e);return{name:n.name,fn:n.fn,options:[e,t]}},Bo=(e,t)=>{let n=Oo(e);return{name:n.name,fn:n.fn,options:[e,t]}},Vo=(e,t)=>({fn:jo(e).fn,options:[e,t]}),Ho=(e,t)=>{let n=ko(e);return{name:n.name,fn:n.fn,options:[e,t]}},Uo=(e,t)=>{let n=Ao(e);return{name:n.name,fn:n.fn,options:[e,t]}},Wo=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})),Go=t(((e,t)=>{t.exports=Wo()})),Ko=t((e=>{var t=r(),n=Go();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}})),qo=t(((e,t)=>{t.exports=Ko()})),Jo=[],Yo=void 0;function Xo(){return Yo}function Zo(e){Jo.push(e)}function Qo(e){let t=(t,n)=>{let r=Ye(es).current,i;try{Yo=r;for(let e of Jo)e.before(r);i=e(t,n);for(let e of Jo)e.after(r);r.didInitialize=!0}finally{Yo=void 0}return i};return t.displayName=e.displayName||e.name,t}function $o(e){return l.forwardRef(Qo(e))}function es(){return{didInitialize:!1}}var ts=Go(),ns=qo(),rs=Ai(19)?os:ss;function is(e,t,n,r,i){return rs(e,t,n,r,i)}function as(e,t,n,r,i){let a=l.useCallback(()=>t(e.getSnapshot(),n,r,i),[e,t,n,r,i]);return(0,ts.useSyncExternalStore)(e.subscribe,a,a)}Zo({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,ts.useSyncExternalStore)(e.subscribe,e.getSnapshot,e.getSnapshot))}});function os(e,t,n,r,i){let a=Xo();if(!a)return as(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 ss(e,t,n,r,i){return(0,ns.useSyncExternalStoreWithSelector)(e.subscribe,e.getSnapshot,e.getSnapshot,e=>t(e,n,r,i))}var cs=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 is(this,e,t,n,r)}},ls=class extends cs{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),is(this,this.selectors[e],t,n,r)}useContextCallback(e,t){l.useDebugValue(e);let n=$(t??Xe);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)}})}},us={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},ds=class extends ls{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:ma(),nested:n,triggerElements:i},us),this.syncOnly=t}syncOpenEvent=(e,t)=>{(!e||!this.state.open||t!=null&&St(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 fs(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 ds({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};K(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 ps(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=at.request(()=>{a(`ending`)});return()=>{at.cancel(e)}}},[e,o,i,n]),U(()=>{if(!e||t)return;let n=at.request(()=>{a(void 0)});return()=>{at.cancel(n)}},[t,e]),U(()=>{if(!e||!t)return;e&&o&&i!==`idle`&&a(`starting`);let n=at.request(()=>{a(`idle`)});return()=>{at.cancel(n)}},[t,e,o,i]),{mounted:o,setMounted:s,transitionStatus:i}}var ms=null;function hs(e){if(!ms){let e=[];ms=e,queueMicrotask(()=>{ms=null,ca.flushSync(()=>{for(let t of e)t()})})}ms.push(e)}function gs(e,t=!1,n=!1){let r=ot();return $((i,a=null)=>{r.cancel();let o=Ca(e);if(o==null)return;let s=o,c=()=>{if(!n){ca.flushSync(i);return}hs(()=>{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=jt;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 _s(e){let{enabled:t=!0,open:n,ref:r,batch:i=!1,onComplete:a}=e,o=$(a),s=gs(r,n,i);l.useEffect(()=>{if(!t)return;let e=new AbortController;return s(o,e.signal),()=>{e.abort()}},[t,n,o,s])}var vs={tabIndex:-1,[Tt]:``};function ys(e){return t=>t!==`touch`||e.current}function bs(e,t=!1){let n=Ei(),r=va()!=null,i=Ye(()=>e(n,r)).current;return fs({popupStore:i,treatPopupAsFloatingElement:t,floatingRootContext:i.state.floatingRootContext,floatingId:n,nested:r,onOpenChange:i.setOpen}),i}function xs({handle:e,store:t}){return U(()=>e.attachStore(t),[e,t]),null}function Ss(e){let t=e.context.triggerElements.size;e.select(`open`)&&e.state.triggerCount!==t&&e.set(`triggerCount`,t)}function Cs(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),Ss(a))}r!==null&&e!==void 0&&(n.current={store:t,id:e,element:r},t.context.triggerElements.add(e,r),Ss(t))})}function ws(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 Ts(e){let t=!1;return e.preventUnmountOnClose=()=>{t=!0},()=>t}function Es(e,t,n,r={}){let i=n.reason,a=i===pn,o=t&&i===`trigger-focus`,s=!t&&(i===`trigger-press`||i===`escape-key`),c=Ts(n);if(e.context.onOpenChange?.(t,n),n.isCanceled)return;r.onBeforeDispatch?.(),e.state.floatingRootContext.dispatchOpenChange(t,n);let l=()=>{let i=ws(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?ca.flushSync(l):l()}function Ds(e,t,n,r){let i=n.useState(`isMountedByTrigger`,e),a=Cs(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 Os(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(dn);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 ks(e,t,n,r){let{mounted:i,setMounted:a,transitionStatus:o}=ps(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 _s({enabled:i&&!e&&!c,open:e,ref:t.context.popupRef,onComplete(){e||l()}}),{forceUnmount:l,transitionStatus:o}}function As(e,t){e.useSyncedValues(t),U(()=>()=>{e.update({activeTriggerProps:Qe,inactiveTriggerProps:Qe,popupProps:Qe})},[e])}function js(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 Ms=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 Ns(e,t,n=!1){return{open:!1,openProp:void 0,mounted:!1,transitionStatus:void 0,floatingRootContext:new ds({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:Qe,inactiveTriggerProps:Qe,popupProps:Qe}}var Ps=e=>e.triggerIdProp??e.activeTriggerId,Fs=e=>e.openProp??e.open,Is=e=>(e.popupElement?.id??e.floatingId)||void 0;function Ls(e,t){return t!==void 0&&Fs(e)&&Ps(e)===t}function Rs(e,t){return Ls(e,t)?!0:t!==void 0&&Fs(e)&&Ps(e)==null&&e.triggerCount===1}var zs={open:Fs,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:Ps,activeTriggerElement:e=>e.mounted?e.activeTriggerElement:null,popupId:Is,isTriggerActive:(e,t)=>t!==void 0&&Ps(e)===t,isOpenedByTrigger:(e,t)=>Ls(e,t),isMountedByTrigger:(e,t)=>t!==void 0&&Ps(e)===t&&e.mounted,triggerProps:(e,t)=>t?e.activeTriggerProps:e.inactiveTriggerProps,triggerPopupId:(e,t)=>Rs(e,t)?Is(e):void 0,popupProps:e=>e.popupProps,popupElement:e=>e.popupElement,positionerElement:e=>e.positionerElement};function Bs(e){let t=l.useCallback(t=>e===void 0?Xe:e.subscribeStore(t),[e]),n=l.useCallback(()=>e===void 0?void 0:e.store,[e]);return(0,ts.useSyncExternalStore)(t,n,()=>e?.serverStore)}function Vs(e){let{open:t=!1,onOpenChange:n,elements:r={}}=e,i=Ei(),a=va()!=null,o=Ye(()=>new ds({open:t,transitionStatus:void 0,onOpenChange:n,referenceElement:r.reference??null,floatingElement:r.floating??null,triggerElements:new Ms,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=K(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 Hs(e){return Us(e,e.rootContext)}function Us(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),_=ya(r),v=l.useMemo(()=>({reference:i,floating:a,domReference:o}),[i,a,o]),y=Ro({...e,elements:{...v,...u&&{reference:u}}}),b=K(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=K(e)?{getBoundingClientRect:()=>e.getBoundingClientRect(),getClientRects:()=>e.getClientRects(),contextElement:e}:e;d(t),y.refs.setReference(t)},[y.refs]),C=l.useCallback(e=>{(K(e)||e===null)&&(g.current=e,p(e)),(K(y.refs.reference.current)||y.refs.reference.current===null||e!==null&&!K(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 Ws=Ve&&Ue;function Gs(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=nt();l.useEffect(()=>{let e=i.select(`domReferenceElement`);if(!n)return;let t=G(e);function r(){let e=i.select(`domReferenceElement`);!i.select(`open`)&&q(e)&&e===Ct(qe(e))&&(s.current=!0,c.current=e)}function a(){u.current=!0}function o(){u.current=!1}return Fn(J(t,`blur`,r),Ws&&J(t,`keydown`,a,!0),Ws&&J(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`);K(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=wt(t.nativeEvent);if(K(a)){if(Ws&&!t.relatedTarget){if(!u.current&&!en(a))return}else if(!rn(a))return}let o=Zt(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(mn,l,f));return}d.start(p,()=>{s.current||i.setOpen(!0,Z(mn,l,f))})},onBlur(t){e();let n=t.relatedTarget,r=t.nativeEvent,a=K(n)&&n.hasAttribute(ci(`focus-guard`))&&n.getAttribute(`data-type`)===`outside`;d.start(0,()=>{let e=i.select(`domReferenceElement`),t=Ct(qe(e));(n||t!==e)&&(X(o.current.floatingContext?.refs.floating.current,t)||X(e,t)||a||Zt(n??t,i.context.triggerElements)||i.setOpen(!1,Z(mn,r)))})}}},[o,r,i,d]);return l.useMemo(()=>n?{reference:f,trigger:f}:{},[n,f])}var Ks=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 tt,this.restTimeout=new tt,this.handleCloseOptions=void 0}static create(){return new e}dispose=()=>{this.openChangeTimeout.clear(),this.restTimeout.clear()};disposeEffect=()=>this.dispose},qs=new WeakMap;function Js(e){if(!e.performedPointerEventsMutation)return;let t=e.pointerEventsScopeElement;t&&qs.get(t)===e&&(e.pointerEventsScopeElement?.style.removeProperty(`pointer-events`),e.pointerEventsReferenceElement?.style.removeProperty(`pointer-events`),e.pointerEventsFloatingElement?.style.removeProperty(`pointer-events`),qs.delete(t)),e.performedPointerEventsMutation=!1,e.pointerEventsScopeElement=null,e.pointerEventsReferenceElement=null,e.pointerEventsFloatingElement=null}function Ys(e,t){let{scopeElement:n,referenceElement:r,floatingElement:i}=t,a=qs.get(n);a&&a!==e&&Js(a),Js(e),e.performedPointerEventsMutation=!0,e.pointerEventsScopeElement=n,e.pointerEventsReferenceElement=r,e.pointerEventsFloatingElement=i,qs.set(n,e),n.style.pointerEvents=`none`,r.style.pointerEvents=`auto`,i.style.pointerEvents=`auto`}function Xs(e){let t=e.context.dataRef.current,n=Ye(()=>t.hoverInteractionState??Ks.create()).current;return t.hoverInteractionState||=n,$e(t.hoverInteractionState.disposeEffect),t.hoverInteractionState}function Zs(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=ya(),f=va(),p=Xs(a),m=nt(),h=$(()=>ln(u.current.openEvent?.type,p.interactedInside)),g=$(()=>un(u.current.openEvent?.type)),_=$(()=>{Js(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()&&K(c)&&s){let e=c,t=s,n=qe(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 Ys(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&&oi(d.nodesRef.current,f).length>0)}function t(e){let t=sn(r,`close`,p.pointerType),n=()=>{a.setOpen(!1,Z(pn,e)),d?.events.emit(`floating.closed`,e)};t?p.openChangeTimeout.start(t,n):(p.openChangeTimeout.clear(),n())}function o(e){let t=wt(e);if(!tn(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(Zt(n.relatedTarget,a.context.triggerElements))return;let r=u.current.floatingContext?.nodeId??i,o=n.relatedTarget;if(!(d&&r&&K(o)&&oi(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(pn,t)),d.events.emit(`floating.closed`,t)})}let y=s;return Fn(y&&J(y,`mouseenter`,c),y&&J(y,`mouseleave`,l),y&&J(y,`pointerdown`,o,!0),()=>{d?.events.off(`floating.closed`,v)})},[n,s,a,u,r,i,g,h,_,p,d,f,m])}var Qs={current:null};function $s(e,t={}){let{enabled:n=!0,delay:r=0,handleClose:i=null,mouseOnly:a=!1,restMs:o=0,move:s=!0,triggerElementRef:c=Qs,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=ya(u),b=Xs(g),x=l.useRef(!1),S=Hn(i),C=Hn(r),w=Hn(o),T=Hn(n),E=Hn(m),D=Hn(p),O=$(()=>ln(_.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(!K(n))return!1;let i=n;return r.hasMatchingElement(e=>X(e,i))&&(!e||!X(e,i))}),j=$(()=>{b.handler&&=(qe(g.select(`domReferenceElement`)).removeEventListener(`mousemove`,b.handler),void 0)}),M=$(()=>{Js(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===pn,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=sn(C.current,`close`,b.pointerType);n?b.openChangeTimeout.start(n,()=>{g.setOpen(!1,Z(pn,e)),y?.events.emit(`floating.closed`,e)}):t&&(b.openChangeTimeout.clear(),g.setOpen(!1,Z(pn,e)),y?.events.emit(`floating.closed`,e))}let t=c.current??(d?g.select(`domReferenceElement`):null);if(!K(t))return;function r(e){if(b.openChangeTimeout.clear(),b.blockMouseMove=!1,a&&!xt(b.pointerType))return;let t=cn(w.current),n=sn(C.current,`open`,b.pointerType),r=wt(e),i=e.currentTarget??null,o=g.select(`domReferenceElement`),s=i;if(K(r)&&!g.context.triggerElements.hasElement(r)){for(let e of g.context.triggerElements.elements())if(X(e,r)){s=e;break}}K(i)&&K(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&&K(s)&&K(o)&&X(o,s)&&d,p=t>0&&!n,m=c&&(l||d)||f,h=!l||c;if(m){k()&&g.setOpen(!0,Z(pn,e,s));return}p||(n?b.openChangeTimeout.start(n,()=>{h&&k()&&g.setOpen(!0,Z(pn,e,s))}):h&&k()&&g.setOpen(!0,Z(pn,e,s)))}function i(t){if(O()){M();return}j();let n=qe(g.select(`domReferenceElement`));b.restTimeout.clear(),b.restTimeoutPending=!1;let r=_.current.floatingContext??f?.();if(!Zt(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?J(t,`mouseout`,o):void 0;return s?Fn(J(t,`mousemove`,r,{once:!0}),J(t,`mouseenter`,r),J(t,`mouseleave`,i),l):Fn(J(t,`mouseenter`,r),J(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&&!xt(b.pointerType))return;if(i&&o&&b.handleCloseOptions?.blockPointerEvents){let e=g.select(`floatingElement`);if(e){let t=b.handleCloseOptions?.getScope?.()??n.ownerDocument.body;Ys(b,{scopeElement:t,referenceElement:n,floatingElement:e})}}let s=cn(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(pn,t,n))}b.pointerType===`touch`?ca.flushSync(()=>{c()}):o&&i?c():(b.restTimeoutPending=!0,b.restTimeout.start(s,c))}}},[n,b,O,A,a,g,w,k])}var ec=`Escape`;function tc(e){return Ue&&e.movementX===0&&e.movementY===0}function nc(e,t,n){switch(e){case`vertical`:return t;case`horizontal`:return n;default:return t||n}}function rc(e,t){return nc(t,e===`ArrowUp`||e===`ArrowDown`,e===`ArrowLeft`||e===`ArrowRight`)}function ic(e,t,n){return nc(t,e===`ArrowDown`,n?e===`ArrowLeft`:e===`ArrowRight`)||e===`Enter`||e===` `||e===``}function ac(e,t,n){return nc(t,n?e===Dt:e===Ot,e===At)}function oc(e,t,n,r){return t===`both`||t===`horizontal`&&r?e===ec:nc(t,n?e===Ot:e===Dt,e===kt)}function sc(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=an(E),A=nn(D),j=Hn(k),M=va(),N=ya(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=Hn(g),V=Hn(T),H=Hn(o),ie=Hn(b),ae=ot(),oe=ot(),se=$(()=>{function e(e){f?N?.events.emit(`virtualfocus`,e):ne.current=ui(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),G&&(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||ic(I.current,_,d)||u?Or(n):kr(n),I.current=null,R())};t()}}else Dr(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=Ct(qe(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=$(()=>Or(n,re.current)),W=$(e=>{if(L.current=!1,B.current=!0,e.which===229||!V.current&&e.currentTarget===j.current)return;if(u&&oc(e.key,_,d,C)){rc(e.key,ue())||_t(e),w.setOpen(!1,Z(Cn,e.nativeEvent)),q(D)&&(f?N?.events.emit(`virtualfocus`,D):D.focus());return}let t=F.current,r=Or(n,g),i=kr(n,g);if(A||(e.key===`Home`&&(_t(e),F.current=r,R(e)),e.key===`End`&&(_t(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(rc(e.key,_)){if(_t(e),T&&!f&&Ct(e.currentTarget.ownerDocument)===e.currentTarget){F.current=ic(e.key,_,d)?r:i,R(e);return}ic(e.key,_,d)?c?t>=i?s&&t!==n.current.length?F.current=-1:(B.current=!1,F.current=r):F.current=Ar(n.current,{startingIndex:t,disabledIndices:g}):F.current=Math.min(i,Ar(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=Ar(n.current,{startingIndex:t,decrement:!0,disabledIndices:g}):F.current=Math.max(r,Ar(n.current,{startingIndex:t,decrement:!0,disabledIndices:g})),Dr(n.current,F.current)&&(F.current=-1),R(e)}}),G=l.useMemo(()=>({onFocus(e){B.current=!0,le(e)},onClick:({currentTarget:e})=>e.focus({preventScroll:!0}),onMouseMove(e){tc(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=Ct(qe(e));e&&X(e,t)&&e.focus({preventScroll:!0})}}}),[le,V,j,m,n,R,ie,f]),fe=l.useMemo(()=>f&&T&&ce&&{"aria-activedescendant":`${y}-${r}`},[f,T,ce,y,r]),pe=l.useMemo(()=>({...A?{}:fe,onKeyDown(e){if(e.key===`Tab`&&e.shiftKey&&T&&!f){let t=wt(e.nativeEvent);if(t&&!X(j.current,t))return;_t(e),w.setOpen(!1,Z(xn,e.nativeEvent)),q(D)&&D.focus();return}W(e)},onPointerMove(e){tc(e)||(L.current=!0)}}),[fe,W,j,A,w,T,f,D]),K=l.useMemo(()=>{function e(e){w.setOpen(!0,Z(Cn,e.nativeEvent,e.currentTarget))}function t(e){p===`auto`&&yt(e.nativeEvent)&&(P.current=!f)}function n(e){P.current=p,p===`auto`&&bt(e.nativeEvent)&&(P.current=!0)}return{onKeyDown(t){let n=w.select(`open`);L.current=!1;let r=t.key.startsWith(`Arrow`),i=ac(t.key,ue(),d),a=rc(t.key,_),o=(u?i:a)||t.key===`Enter`||t.key.trim()===``;if(f&&n)return W(t);if(n||h||!r){if(o){let e=rc(t.key,ue());I.current=u&&e?null:t.key}if(u){i&&(_t(t),n?(F.current=de(),R(t)):e(t));return}a&&(H.current!=null&&(F.current=H.current),_t(t),!n&&h?e(t):W(t),n&&R(t))}},onFocus(e){w.select(`open`)&&!f&&(F.current=-1,R(e))},onPointerDown:n,onPointerEnter:n,onMouseDown:t,onClick:t}},[W,p,de,u,R,w,h,_,ue,d,H,f]),me=l.useMemo(()=>({...fe,...K}),[fe,K]);return l.useMemo(()=>a?{reference:me,floating:pe,item:G,trigger:K}:{},[a,me,pe,K,G])}function cc(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=nt(),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&&!Pr(n)||n?.matches(`:disabled`)?!1:o==null||!Mr(Ze,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===` `&&(_t(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!==` `&&(_t(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 lc=.1,uc=lc*lc,dc=.5;function fc(e,t,n,r,i,a){return r>=t!=a>=t&&e<=(i-n)*(t-r)/(a-r)+n}function pc(e,t,n,r,i,a,o,s,c,l){let u=!1;return fc(e,t,n,r,i,a)&&(u=!u),fc(e,t,i,a,o,s)&&(u=!u),fc(e,t,o,s,c,l)&&(u=!u),fc(e,t,c,l,n,r)&&(u=!u),u}function mc(e,t,n){return e>=n.x&&e<=n.x+n.width&&t>=n.y&&t<=n.y+n.height}function hc(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 gc(e={}){let{blockPointerEvents:t=!1}=e,n=new tt,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*uc;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=wt(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&&K(r.relatedTarget)&&X(u,r.relatedTarget))return;function y(){return!!(s&&oi(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=hc(d,f,D,x.top+1,O,S.bottom-1);break;case`bottom`:j=hc(d,f,D,S.top+1,O,x.bottom-1);break;case`left`:j=hc(d,f,S.right-1,A,x.left+1,k);break;case`right`:j=hc(d,f,x.right-1,A,S.left+1,k)}if(j)return;if(l&&!mc(d,f,x)){b();return}if(!g&&p(d,f)){b();return}let M=!1;switch(c){case`top`:{let n=T?dc/2:dc*4,r=T||C?e+n:e-n,i=T?e-n:C?e+n:e-n,a=t+dc+1,o=C||T?S.bottom-dc:S.top,s=C?T?S.bottom-dc:S.top:S.bottom-dc;M=pc(d,f,r,a,i,a,S.left,o,S.right,s);break}case`bottom`:{let n=T?dc/2:dc*4,r=T||C?e+n:e-n,i=T?e-n:C?e+n:e-n,a=t-dc,o=C||T?S.top+dc:S.bottom,s=C?T?S.top+dc:S.bottom:S.top+dc;M=pc(d,f,r,a,i,a,S.left,o,S.right,s);break}case`left`:{let n=E?dc/2:dc*4,r=E||w?t+n:t-n,i=E?t-n:w?t+n:t-n,a=e+dc+1,o=w||E?S.right-dc:S.left,s=w?E?S.right-dc:S.left:S.right-dc;M=pc(d,f,o,S.top,s,S.bottom,a,r,a,i);break}case`right`:{let n=E?dc/2:dc*4,r=E||w?t+n:t-n,i=E?t-n:w?t+n:t-n,a=e-dc,o=w||E?S.left+dc:S.right,s=w?E?S.left+dc:S.right:S.left+dc;M=pc(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 _c({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=za(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=wt(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 gt(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]),As(e,{activeTriggerProps:m.reference,inactiveTriggerProps:m.trigger,popupProps:m.floating,nestedOpenDialogCount:c,nestedOpenDrawerCount:d}),null}var vc=l.createContext(void 0);function yc(e){let t=l.useContext(vc);if(!e&&t===void 0)throw Error(Oi(27));return t}var bc={...zs,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},xc=class extends ls{constructor(e,t,n){let r=new Ms,i=Sc(e,r,t,n);super(i,Cc(r),bc)}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(ws(this.state,e,t.trigger)))}};function Sc(e,t,n,r=!1){return{...Ns(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 Cc(e){return{popupRef:l.createRef(),backdropRef:l.createRef(),internalBackdropRef:l.createRef(),outsidePressEnabledRef:{current:!0},triggerElements:e,onOpenChange:void 0,onOpenChangeComplete:void 0}}function wc(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=yc(!0),b={modal:g,disablePointerDismissal:_,nested:y!=null,role:v},x=bs((e,t)=>new xc({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`);js(x,S),Os(x);let{forceUnmount:T}=ks(S,x);l.useImperativeHandle(u,()=>({unmount:T,close:()=>x.setOpen(!1,Z(kn))}),[T,x]);let E=S||C;return(0,Q.jsxs)(vc.Provider,{value:x,children:[d&&(0,Q.jsx)(xs,{handle:d,store:x}),E&&(0,Q.jsx)(_c,{store:x,parentContext:y?.context,isDrawer:m}),typeof n==`function`?n({payload:w}):n]})}function Tc(e){return wc(`alert-dialog`,e)}var Ec=l.forwardRef(function(e,t){let{render:n,className:r,style:i,forceRender:a=!1,...o}=e,s=yc(),c=s.useState(`open`),l=s.useState(`nested`),u=s.useState(`mounted`);return Zi(`div`,e,{state:{open:c,transitionStatus:s.useState(`transitionStatus`)},ref:[s.context.backdropRef,t],stateAttributesMapping:Yt,props:[{role:`presentation`,hidden:!u,style:{userSelect:`none`,WebkitUserSelect:`none`}},o],enabled:a||!l})}),Dc=l.createContext(void 0);function Oc(e=!1){let t=l.useContext(Dc);if(t===void 0&&!e)throw Error(Oi(16));return t}function kc(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 Ac(e,t,{detail:n=0}={}){e.dispatchEvent(new(G(e)).PointerEvent(`click`,{bubbles:!0,cancelable:!0,composed:!0,detail:n,shiftKey:t.shiftKey,ctrlKey:t.ctrlKey,altKey:t.altKey,metaKey:t.metaKey}))}function jc(e={}){let{disabled:t=!1,focusableWhenDisabled:n,tabIndex:r=0,native:i=!0,composite:a}=e,o=l.useRef(null),s=Oc(!0),c=a??s!==void 0,{props:u}=kc({focusableWhenDisabled:n,disabled:t,composite:c,tabIndex:r,isNativeButton:i}),d=l.useCallback(()=>{let e=o.current;Mc(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 Li({onClick(e){if(t){e.preventDefault();return}n?.(e)},onMouseDown(e){t||r?.(e)},onKeyDown(e){if(t||(Ji(e),o?.(e),e.baseUIHandlerPrevented))return;let n=e.target===e.currentTarget,r=e.currentTarget,a=Mc(r),s=!i&&Nc(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(),Ac(r,e));return}if(!l||i||!d&&!u){n&&s&&d&&e.preventDefault();return}e.defaultPrevented||(e.preventDefault(),u&&(e.preventBaseUIHandler(),Ac(r,e)))},onKeyUp(e){if(!t){if(Ji(e),a?.(e),e.target===e.currentTarget&&i&&c&&Mc(e.currentTarget)&&e.key===` `){e.preventDefault();return}e.baseUIHandlerPrevented||e.target===e.currentTarget&&!i&&!c&&!e.defaultPrevented&&e.key===` `&&(e.preventBaseUIHandler(),Ac(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 Mc(e){return q(e)&&e.tagName===`BUTTON`}function Nc(e){return q(e)&&e.tagName===`A`&&!!e.href}var Pc=l.forwardRef(function(e,t){let{render:n,className:r,style:i,disabled:a=!1,nativeButton:o=!0,...s}=e,c=yc(),l=c.useState(`open`),{getButtonProps:u,buttonRef:d}=jc({disabled:a,native:o}),f={disabled:a};function p(e){l&&c.setOpen(!1,Z(_n,e.nativeEvent))}return Zi(`button`,e,{state:f,ref:[t,d],props:[{onClick:p},s,u]})});function Fc(e){return Ei(e,`base-ui`)}var Ic=l.forwardRef(function(e,t){let{render:n,className:r,style:i,id:a,...o}=e,s=yc(),c=Fc(a);return s.useSyncedValueWithCleanup(`descriptionElementId`,c),Zi(`p`,e,{ref:t,props:[{id:c},o]})}),Lc=l.createContext(void 0);function Rc(){let e=l.useContext(Lc);if(e===void 0)throw Error(Oi(26));return e}var zc=new Set([`ArrowUp`,`ArrowDown`,`ArrowLeft`,`ArrowRight`,`Home`,`End`]),Bc=`--nested-dialogs`,Vc=`data-nested-dialog-open`,Hc={...Jt,...Ft,nestedDialogOpen(e){return e?{[Vc]:``}:null}},Uc=l.forwardRef(function(e,t){let{render:n,className:r,style:i,finalFocus:a,initialFocus:o,...s}=e,c=yc(),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`);Rc(),_s({open:_,ref:c.context.popupRef,onComplete(){_&&c.context.onOpenChangeComplete?.(!0)}});let C=o===void 0?ys(c.context.popupRef):o,w=g>0,T=c.useStateSetter(`popupElement`),E=Zi(`div`,e,{state:{open:_,nested:h,transitionStatus:b,nestedDialogOpen:w},props:[f,{id:S,"aria-labelledby":y,"aria-describedby":l,role:x,...vs,hidden:!m,onKeyDown(e){zc.has(e.key)&&e.stopPropagation()},style:{[Bc]:g}},s],ref:[t,c.context.popupRef,T],stateAttributesMapping:Hc});return(0,Q.jsx)(Ma,{context:d,openInteractionType:v,disabled:!m,closeOnFocusOut:!u,initialFocus:C,returnFocus:a,modal:p!==!1,restoreFocus:`popup`,children:E})});function Wc(e){return Ai(19)?e:e?`true`:void 0}var Gc=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}})}),Kc=l.forwardRef(function(e,t){let{keepMounted:n=!1,...r}=e,i=yc(),a=i.useState(`mounted`),o=i.useState(`modal`),s=i.useState(`open`);return a||n?(0,Q.jsx)(Lc.Provider,{value:n,children:(0,Q.jsxs)(pa,{ref:t,...r,children:[a&&o===!0&&(0,Q.jsx)(Gc,{ref:i.context.internalBackdropRef,inert:Wc(!s)}),e.children]})}):null}),qc=l.forwardRef(function(e,t){let{render:n,className:r,style:i,id:a,...o}=e,s=yc(),c=Fc(a);return s.useSyncedValueWithCleanup(`titleElementId`,c),Zi(`h2`,e,{ref:t,props:[{id:c},o]})});function Jc(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 Yc(e,t){let n=l.useRef(e),r=$(t);U(()=>{n.current!==e&&r(n.current),n.current=e},[e,r])}function Xc(e,t){let{onClick:n,onPointerDown:r}=Jc($((n,r)=>{(typeof e==`function`?e():e)||t(r||(Re?`touch`:``))}));return l.useMemo(()=>({onClick:n,onPointerDown:r}),[n,r])}function Zc(e){let[t,n]=l.useState(null),r=Xc(e,n);return Yc(e,t=>{t&&!e&&n(null)}),l.useMemo(()=>({openMethod:t,triggerProps:r}),[t,r])}var Qc=i(),$c,el,tl=e=>{$c??=(0,Qc.createRoot)(document.body.appendChild(document.createElement(`div`))),el?.resolve(!1),el=e,$c.render((0,Q.jsx)(nl,{request:e,settle:t=>{el===e&&(el=void 0,$c?.render(null),e.resolve(t))}}))};function nl({request:e,settle:t}){return(0,Q.jsx)(Tc,{open:!0,onOpenChange:e=>{e||t(!1)},children:(0,Q.jsxs)(Kc,{children:[(0,Q.jsx)(Ec,{className:`dialog-backdrop`}),(0,Q.jsxs)(Uc,{className:`dialog`,children:[(0,Q.jsx)(Ic,{className:`dialog-message`,children:e.message}),(0,Q.jsxs)(`div`,{className:`dialog-actions`,children:[e.cancelLabel&&(0,Q.jsx)(Pc,{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 rl=(e,{confirmLabel:t=`Confirm`,danger:n=!1}={})=>new Promise(r=>tl({message:e,confirmLabel:t,cancelLabel:`Cancel`,danger:n,resolve:r})),il=e=>new Promise(t=>tl({message:e,confirmLabel:`OK`,resolve:()=>t()})),al=l.createContext(void 0);function ol(e){let t=l.useContext(al);if(t===void 0&&!e)throw Error(Oi(72));return t}var sl={...zs,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},cl=class extends ls{constructor(e,t,n){let r=new Ms;super(ll(e,r,t,n),ul(r),sl)}setOpen=(e,t)=>{Es(this,e,t,{extraState:{openChangeReason:t.reason}})};cancelPendingOpen(e){this.state.floatingRootContext.dispatchOpenChange(!1,Z(fn,e))}};function ll(e,t,n,r=!1){return{...Ns(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 ul(e){return{popupRef:l.createRef(),onOpenChange:void 0,onOpenChangeComplete:void 0,triggerElements:e}}var dl=Qo(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=bs((e,t)=>new cl({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}),Os(m,{closeOnActiveTriggerUnmount:!0});let{forceUnmount:b,transitionStatus:x}=ks(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(On))},[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(kn))}),[b,m]);let E=g||v||!t&&a!==`none`;return(0,Q.jsxs)(al.Provider,{value:m,children:[u&&(0,Q.jsx)(xs,{handle:u,store:m}),E&&(0,Q.jsx)(fl,{store:m,disabled:t,trackCursorAxis:a}),typeof p==`function`?p({payload:y}):p]})});function fl({store:e,disabled:t,trackCursorAxis:n}){let r=e.useState(`floatingRootContext`),i=za(r,{enabled:!t,referencePress:()=>e.select(`closeOnClick`)}),a=Ia(r,{enabled:!t&&n!==`none`,axis:n===`none`?void 0:n}),o=l.useMemo(()=>Li(a.reference,i.reference),[a.reference,i.reference]);return As(e,{activeTriggerProps:o,inactiveTriggerProps:o,popupProps:i.floating??Qe}),null}var pl=l.createContext(void 0);function ml(){return l.useContext(pl)}var hl=`data-base-ui-tooltip-trigger`;function gl(e){if(`composedPath`in e){let t=e.composedPath();for(let e=0;e<t.length;e+=1){let n=t[e];if(K(n))return n}}let t=e.target;return K(t)?t:null}function _l(e){let t=e;for(;t;){let e=t.closest(`[${hl}]`);if(e)return e;let n=t.getRootNode();t=`host`in n&&K(n.host)?n.host:null}return null}var vl=$o(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=ol(!0),h=Bs(a)??m;if(!h)throw Error(Oi(82));let g=Fc(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}=Ds(g,b,h,{payload:o,closeOnClick:u,closeDelay:x}),w=ml(),{activeIdRef:T,delayRef:E,isInstantPhase:D,hasProvider:O}=Pn(y,{open:v}),k=Xs(y);h.useSyncedValue(`isInstantPhase`,D);let A=h.useState(`disabled`),j=s??A,M=Hn(j),N=h.useState(`trackCursorAxis`),P=h.useState(`disableHoverablePopup`),F=l.useRef(!1),I=nt(),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=_l(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=$s(y,{enabled:!j,mouseOnly:!0,move:!1,handleClose:!P&&N!==`both`?gc():null,restMs:R,delay(){return d==null&&O?{close:sn(E.current,`close`)}:{close:x}},triggerElementRef:b,isActiveTrigger:_,isClosing:()=>h.select(`transitionStatus`)===`ending`,shouldOpen(){return!F.current}}),te=Gs(y,{enabled:!j}).reference,ne=e=>{let t=F.current,n=gl(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(pn,e));return}if(t&&!r&&a&&!M.current&&!h.select(`open`)&&i&&xt(L.current)){let t=()=>{!F.current&&!M.current&&!h.select(`open`)&&h.setOpen(!0,Z(pn,e,i))},n=R();n===0?(I.clear(),t()):I.start(n,t)}},re=h.useState(`triggerProps`,C);return Zi(`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(gl(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,[Xt]:j?``:void 0,[hl]:j?void 0:``},p],stateAttributesMapping:Kt})}),yl=l.createContext(void 0);function bl(){let e=l.useContext(yl);if(e===void 0)throw Error(Oi(70));return e}var xl=l.forwardRef(function(e,t){let{children:n,container:r,className:i,render:a,style:o,...s}=e,{node:c,subtree:u}=fa({container:r,ref:t,componentProps:e,elementProps:s});return!u&&!c?null:(0,Q.jsxs)(l.Fragment,{children:[u,c&&ca.createPortal(n,c)]})}),Sl=l.forwardRef(function(e,t){let{keepMounted:n=!1,...r}=e;return ol().useState(`mounted`)||n?(0,Q.jsx)(yl.Provider,{value:n,children:(0,Q.jsx)(xl,{ref:t,...r})}):null}),Cl=l.createContext(void 0);function wl(){let e=l.useContext(Cl);if(e===void 0)throw Error(Oi(71));return e}var Tl=l.createContext(void 0);function El(){return l.useContext(Tl)?.direction??`ltr`}var Dl=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`}=or(e,t)||{};if(l==null)return{};let f=wr(u),p={x:n,y:r},m=fr(i),h=ur(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=ar(k,j,A),N=!c.arrow&&cr(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}}}),Ol=(e,t)=>{let{name:n,fn:r}=Dl(e);return{name:n,fn:r,options:[e,t]}},kl={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}}}},Al={sideX:`left`,sideY:`top`},jl=`--available-width`,Ml=`--available-height`,Nl=`--anchor-width`,Pl=`--anchor-height`,Fl=`--transform-origin`,Il=jl,Ll=Ml;function Rl(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 zl(e,t,n){let{rects:r,placement:i}=e;return{side:Rl(t,sr(i),n),align:cr(i)||`center`,anchor:{width:r.reference.width,height:r.reference.height},positioner:{width:r.floating.width,height:r.floating.height}}}function Bl(e){return Vl(e,Hs)}function Vl(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=Hn(n),F=Hn(_),I=El()===`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=Hn(a),ie=Hn(s),ae=typeof a==`function`?0:a,oe=typeof s==`function`?0:s,se=[];m&&se.push(m),se.push(zo(e=>{let t=zl(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:Ho({...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:Bo({...re,rootBoundary:A,mainAxis:D!==`none`,crossAxis:le,limiter:d||k?void 0:Vo(e=>{if(!V.current)return{};let{width:t,height:n}=V.current.getBoundingClientRect(),r=dr(sr(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(Uo({...re,apply({elements:{floating:e},availableWidth:t,availableHeight:n,rects:r}){if(!F.current)return;let i=e.style;i.setProperty(Il,`${t}px`),i.setProperty(Ll,`${n}px`);let a=G(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(Nl,`${u}px`),i.setProperty(Pl,`${d}px`)}}),Ol(e=>({element:V.current||qe(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=sr(r),u=cr(r),d=dr(l)===`y`,f=V.current,p=typeof a==`function`?a(zl(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(Fl,d?`${m} ${h}`:`${h} ${m}`),{}}},kl,x),U(()=>{!_&&g&&g.update({referenceElement:null,floatingElement:null,domReferenceElement:null,positionReference:null})},[_,g]);let W=l.useMemo(()=>({ancestorScroll:!p,elementResize:!p&&typeof ResizeObserver<`u`,layoutShift:!p&&typeof IntersectionObserver<`u`}),[p]),{refs:fe,elements:pe,x:K,y:q,middlewareData:me,update:he,placement:ge,context:_e,isPositioned:ve,floatingStyles:ye}=t({rootContext:g,open:h?_:void 0,placement:R,middleware:se,strategy:r,whileElementsMounted:h?void 0:(...e)=>Eo(...e,W),nodeId:b,externalTree:C}),{sideX:be,sideY:xe}=me.adaptiveOrigin||Al,Se=ve?r:`fixed`,Ce=l.useMemo(()=>{let e;return e=ve?x?{position:Se,[be]:K,[xe]:q}:{...ye,position:Se}:{position:Se,top:0,left:0},e[Il]=`100vw`,e[Ll]=`100vh`,ve||(e.opacity=0),e},[x,Se,be,K,xe,q,ye,ve]),we=l.useRef(null);U(()=>{if(!_)return;let e=P.current,t=typeof e==`function`?e():e,n=(Hl(t)?t.current:t)||null;n!==we.current&&(fe.setPositionReference(n),we.current=n)},[_,fe,N,P]),l.useEffect(()=>{if(!_)return;let e=P.current;typeof e!=`function`&&Hl(e)&&e.current!==we.current&&(fe.setPositionReference(e.current),we.current=e.current)},[_,fe,N,P]),l.useEffect(()=>{if(h&&_&&pe.reference&&pe.floating)return Eo(pe.reference,pe.floating,he,W)},[h,_,pe,he,W]);let Te=sr(ge),Ee=Rl(i,Te,I),De=cr(ge)||`center`,Oe=!!me.hide?.referenceHidden;U(()=>{S&&_&&ve&&Te!==L&&T(Te)},[S,_,ve,Te,L]);let ke=l.useMemo(()=>({position:`absolute`,top:me.arrow?.y,left:me.arrow?.x}),[me.arrow]),Ae=me.arrow?.centerOffset!==0;return l.useMemo(()=>({positionerStyles:Ce,arrowStyles:ke,arrowRef:V,arrowUncentered:Ae,side:Ee,align:De,physicalSide:Te,anchorHidden:Oe,refs:fe,context:_e,isPositioned:ve,update:he}),[Ce,ke,V,Ae,Ee,De,Te,Oe,fe,_e,ve,he])}function Hl(e){return e!=null&&`current`in e}function Ul(e){return e===`starting`?ia:Qe}function Wl(e,t,{styles:n,transitionStatus:r,props:i,refs:a,hidden:o,inert:s=!1}){let c={...n};return s&&(c.pointerEvents=`none`),Zi(`div`,e,{state:t,ref:a,props:[{role:`presentation`,hidden:o,style:c},Ul(r),i],stateAttributesMapping:Jt})}var Gl=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=oa,style:_,...v}=e,y=ol(),b=bl(),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=Bl({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=Wl(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)(Cl.Provider,{value:O,children:k})}),Kl=l.forwardRef(function(e,t){let{render:n,className:r,style:i,...a}=e,o=ol(),{side:s,align:c}=wl(),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`);_s({open:l,ref:o.context.popupRef,onComplete(){l&&o.context.onOpenChangeComplete?.(!0)}}),Zs(p,{enabled:!m,closeDelay:h});let g=o.useStateSetter(`popupElement`);return Zi(`div`,e,{state:{open:l,side:s,align:c,instant:u,transitionStatus:d},ref:[t,o.context.popupRef,g],props:[vs,f,Ul(d),a],stateAttributesMapping:Yt})});function ql({label:e,side:t=`top`,children:n}){return(0,Q.jsxs)(dl,{children:[(0,Q.jsx)(vl,{render:n}),(0,Q.jsx)(Sl,{children:(0,Q.jsx)(Gl,{className:`tooltip-positioner`,side:t,sideOffset:8,collisionPadding:8,children:(0,Q.jsx)(Kl,{className:`tooltip-popup`,children:e})})})]})}var Jl={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}},Yl=Object.keys(Jl);Object.fromEntries(Yl.map(e=>[e,Jl[e].color]));var Xl={default:`idle`,working:`working`,sleeping:`sleeping`},Zl={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`},Ql={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 $l(e){let t=e.trim(),n=t.match(/^hsla?\(\s*([\d.]+)(?:deg)?[,\s]+([\d.]+)%[,\s]+([\d.]+)%/i);if(n)return au([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 eu(e){let t=$l(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 tu=`#1E1A33`,nu=`#F7F5F2`;function ru(e){return eu(e)<.13?nu:tu}function iu([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 au([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 ou([e,t,n]){return`hsl(${(e*360).toFixed(1)} ${(t*100).toFixed(1)}% ${(n*100).toFixed(1)}%)`}var su=e=>Math.min(1,Math.max(0,e));function cu(e,t,n=0){let r=$l(e);if(!r)return e;let[i,a,o]=iu(r);return ou([i,su(a+n+(t<0?-t*.25:0)),su(o+t)])}var lu=[`default`,`working`,`sleeping`],uu=.68,du=26,fu=.2,pu={height:du,time:uu,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},mu=(e,t)=>t?e.clickSquashTime:fu*e.time,hu=(e,t)=>mu(e,t)+e.time+gu[e.squashEase]*(t?e.clickSquashTime:e.squashTime)+Math.max(0,e.groundTime)+e.riseTime+Math.max(0,e.land)+.05,gu={sharp:0,pulse:2/7,soft:.5,bouncy:.144},_u=(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}}},vu=(e,t)=>1+.25*yu(e,t),yu=(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)},bu=e=>Math.exp(-((Math.min(Math.abs(e),Math.abs(e-1))/.11)**2)),xu=Math.PI/180,Su=Math.PI*2,Cu={default:1.2,working:.7,sleeping:1.4},wu=1;function Tu(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 Eu(e,t,n,r){return e+(t-e)*(1-Math.exp(-n*r))}var Du=e=>e<.5?4*e*e*e:1-(-2*e+2)**3/2,Ou=e=>.5-.5*Math.cos(Math.PI*e),ku=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=Eu(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}},Au=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))}},ju=35*xu,Mu=14*xu,Nu=3.2*xu,Pu=2.6,Fu={default:{pitch:0,roll:0,y:0,lookX:0,lookY:0},working:{pitch:5*xu,roll:0,y:0,lookX:0,lookY:0},sleeping:{pitch:-16*xu,roll:6*xu,y:3,lookX:0,lookY:1}},Iu=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 Au(.17),this.blinkAgain=!1,this.dart=new Au(.12),this.dartX=0,this.dartY=0,this.flip=new Au(hu(pu,!1)),this.flipPoked=!1,this.jump={...pu},this.flipSide=1,this.nod=new Au(1.7),this.hopPhase=0,this.hopCount=0,this.hopGain=0,this.laughEv=new Au(.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=Tu(Math.floor(e*1e6)+1);let n=this.rand;this.yawW=new ku(n,36*xu,1.1,2.6,3,!0),this.pitchW=new ku(n,10*xu,1.1,2.6,2.6,!0),this.rollW=new ku(n,5*xu,1.6,3.2,2,!0),this.lookXW=new ku(n,3.6,.5,2,14),this.lookYW=new ku(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]=+(lu[t]===e);this.tr=1}else this.wFrom=[r[0],r[1],r[2]],this.tr=0,this.trDuration=n===`sleeping`?wu:Cu[e];switch(e){case`default`:this.yawW.set(ju,2.6,5.4,2),this.pitchW.set(Mu,2.8,5.8,1.8),this.rollW.set(Nu,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*xu,.9,1.8,4),this.pitchW.set(3*xu,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*xu,3,6,.7),this.pitchW.set(3*xu,3,6,.7),this.rollW.set(2*xu,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=hu(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=Ou(this.tr);for(let e=0;e<3;e++){let n=+(lu[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=Fu[lu[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*ju*r*this.turnK),this.pitchW.aim(n*Mu*r),this.rollW.aim(e*Nu*r*this.turnK),this.gazeAt=t+Pu+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=Eu(this.ptrS,this.ptrTargetS,8,e),this.ptrX=Eu(this.ptrX,this.ptrTargetX,14,e),this.ptrY=Eu(this.ptrY,this.ptrTargetY,14,e);let c=this.ptrS,l=1-.75*c;this.baseYaw=Eu(this.baseYaw,this.yawW.value*l+22*xu*this.ptrX*c,5,e);let u=s.pitch+this.pitchW.value*l-12*xu*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=>Su*(1.5*e+.9*Du(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=hu(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=mu(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+=Su*e.spin*Du(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):bu(e-1),c=Math.max(0,e.groundTime),l=gu[e.squashEase]*o,u=a-l-c,d=a<=l?yu(a/o,e.squashEase):u<=0?vu((a-l)/c,e.groundEase):_u(u/e.riseTime,e.riseEase),f=(n<0?s(Math.max(0,1+n*e.time/t)):a>0?d:n<.2?bu(n):0)*e.squash;_+=.16*f-.06*i*e.stretch,v+=-.18*f+.09*i*e.stretch,b+=this.flipSide*e.lean*xu*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/uu,this.hopPhase>=1&&(this.state===`working`?(--this.hopPhase,this.hopCount+=1):(this.hopPhase-1)*uu>=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?du:18)*r*t;let a=this.state!==`working`&&this.hopPhase>1?(this.hopPhase-1)*uu:-1,o=a<0?bu(this.hopPhase):a<j?vu(a/j,A.groundEase):_u((a-j)/A.riseTime,A.riseEase);_+=(.16*o-.06*r)*t,v+=(-.18*o+.09*r)*t,i&&(h+=Su*Du(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*xu*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?Du(e/.72):1-Du((e-.72)/.28);y-=13*xu*t*o}this.breathPhase+=e/(3.6+1.2*o);let N=Math.sin(this.breathPhase*Su);n.breath=N,_+=N*(.008+.014*o),v+=N*(.012+.02*o);let P=Math.sin(t*Su/3.4)*2*(1-o);n.yaw=this.baseYaw+h;let F=this.baseYaw-this.prevYaw;F=((F+Math.PI)%Su+Su)%Su-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=Eu(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=Eu(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 Lu(e){let t=Fu[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:lu.map(t=>+(t===e))}}var Ru=64,zu=4096,Bu=24,Vu=0xe8d4a51000,Hu=48*Math.PI/180,Uu=Math.cos(Hu),Wu=Math.sin(Hu),Gu=(e,t)=>t+(1-t)*Math.sqrt(Math.max(0,1-e*e));function Ku(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 qu(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:Vu;Ku(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];Ku(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 Ju(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 Yu(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 Xu=[1,1,0,-1,-1,-1,0,1],Zu=[0,1,1,1,0,-1,-1,-1],Qu=[1,Math.SQRT2,1,Math.SQRT2,1,Math.SQRT2,1,Math.SQRT2];function $u(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);qu(a,0,t,o,null),qu(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]))}Ju(l,t,u),Ju(l,t,u);let d=Yu(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;Ju(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+Xu[e]*a,s=d+Zu[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*Qu[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*Ru+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 ed(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 td(e,t){return e.getContext(`2d`,t?{willReadFrequently:!0}:void 0)}function nd(e,t){let n=ed(t),r=n&&td(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 rd=new Map,id=new Set,ad=new WeakMap,od=0;function sd(e){let t=ad.get(e);return t||ad.set(e,t=`p${od++}`),t}var cd=[],ld=!1;function ud(){ld=!1;let e=cd.shift();e&&e(),cd.length&&dd()}function dd(){if(ld)return;ld=!0;let e=globalThis.requestIdleCallback;e?e(ud,{timeout:120}):setTimeout(ud,16)}function fd(e){cd.push(e),dd()}function pd(e,t,n,r,i){let a=`${e}|${n}|${Math.round(r)}`,o=rd.get(a);if(o)return o;let s=()=>{if(id.delete(a),rd.has(a))return;let e=nd(t,n);e&&(rd.size>=48&&rd.clear(),rd.set(a,$u(e,n,r)))};return i?(s(),rd.get(a)??null):(id.has(a)||(id.add(a),fd(s)),null)}function md(e,t,n=192,r=.65){pd(e,t,hd(n),15*r,!0)}function hd(e){return e<=100?64:e<=224?96:128}var gd=e=>e<=.04045?e/12.92:((e+.055)/1.055)**2.4,_d=new Map;function vd(e){let t=_d.get(e);if(!t){let n=$l(e);if(!n){let t=ed(1),r=t&&td(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=[gd(n[0]/255),gd(n[1]/255),gd(n[2]/255)],_d.size>200&&_d.clear(),_d.set(e,t)}return t}var yd=2048,bd=2.5,xd=yd/bd,Sd=new Float32Array(yd);for(let e=0;e<yd;e++){let t=(e+.5)/xd,n=t<=.75?t:.75+.25*(1-Math.exp(-(t-.75)/.25));Sd[e]=255*(n<=.0031308?12.92*n:1.055*n**(1/2.4)-.055)}var Cd=e=>Sd[e<=0?0:e>=bd?2047:e*xd|0],wd=1024,Td=new Map;function Ed(e){let t=Td.get(e);if(!t){t=new Float32Array(1025);for(let n=0;n<=wd;n++)t[n]=(n/wd)**+e;Td.size>16&&Td.clear(),Td.set(e,t)}return t}var Dd=[.92,.96,1],Od=[1,.98,.95],kd=(e,t,n)=>{let r=n<=e?0:n>=t?1:(n-e)/(t-e);return r*r*(3-2*r)},Ad=(e,t,n)=>1-kd(e-t,e+t,n);function jd(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=Ed(g),y=Ed(_),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<Ru;n++)for(let r=0;r<Ru;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*wd|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*kd(-.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=Ad(.34,.12,Math.abs(e))*Ad(.12,.06,Math.abs(t))}let ee=C*A*L+S*z,B=(n*Ru+r)*3;e[B]=Cd(t[0]*(w[0]+h*D)+N*Od[0]+ee*Dd[0]),e[B+1]=Cd(t[1]*(w[1]+h*D)+N*Od[1]+ee*Dd[1]),e[B+2]=Cd(t[2]*(w[2]+h*D)+N*Od[2]+ee*Dd[2])}}function Md(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*Ru+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 Nd(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 Pd=e=>{let t=Math.hypot(e[0],e[1],e[2])||1;return[e[0]/t,e[1]/t,e[2]/t]};function Fd(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)=>Pd([s*e+c*u*t-c*l*n,l*t+u*n,r*(c*e-s*u*t+s*l*n)]),f=d(Uu*r,Uu*i,Wu),p=d(0,0,1,a),m=Pd([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=Pd([.55*v,.55*y,.83]),x=Pd([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 Id=new WeakMap;function Ld(e,t){let n=e.canvas??e,r=Id.get(n);r||(r=new Map,Id.set(n,r));let i=r.get(t);return i||(i={N:0,img:null,mc:new Float32Array(zu*3),mcPrev:new Float32Array(zu*3),mcMix:new Float32Array(zu*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 Rd=1/48,zd=(e,t)=>!t||Math.abs(e[0]-t[0])>=Rd||Math.abs(e[1]-t[1])>=Rd||Math.abs(e[2]-t[2])>=Rd;function Bd(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 Vd(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<=Bu;e++){let r=e/Bu*Math.PI*2;Md(t,a*Math.cos(r),a*Math.sin(r),o),n.addColorStop(e/Bu,`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)=>{Md(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 Hd=typeof navigator<`u`&&/AppleWebKit\//.test(navigator.userAgent)&&!/Chrome\/|Chromium\/|Edg\//.test(navigator.userAgent),Ud=[[.55,()=>0],[0,()=>0],[0,e=>Math.min(.6,.25*e.shadow)]];function Wd(e,t,n,r,i,a){let o=hd(n.dev),s=pd(t.typeKey??sd(t.path),t.path,o,n.halfDepth,!!n.still);if(!s)return!1;let c=Ld(e,t.typeKey??sd(t.path)),l=Fd(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((zd(l.L,c.L)||zd(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),jd(c.mc,vd(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<zu*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)&&(Nd(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=ed(o),n=t&&td(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`&&Hd;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=ed(e),n=t&&td(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=Vd(i.g,c.mc,Ud[r][0],Ud[r][1](a),u),i.g.fill(t.path)}p&&(c.spriteVersion=c.version)}}!p&&!c.near&&(c.near=Vd(e,c.mc,.55,0,u),c.rimG=Vd(e,c.mc,0,0,u),c.far=Vd(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=Gu(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=Bd(Bd(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 Gd=1.5,Kd=.1,qd=17,Jd=15,Yd=(e,t)=>t+(1-t)*Math.sqrt(Math.max(0,1-e*e)),Xd=25,Zd=6.3,Qd={eyes:1,mouth:-3.5},$d=new Map;function ef(e,t,n){let r=`${e}|${t}|${n}`,i=$d.get(r);if(!i){let a=cu(e,-.3*t,.05*t),o=cu(e,-.12*t,.03*t),s=[],c=[];for(let t=0;t<qd;t++){let n=t/16;s.push(n>.6?``:nf(a,o,n/.6)),c.push(n>=.5?e:nf(a,e,n/.5))}i={base:e,far:a,near:o,light:cu(e,.04*n),dark:cu(e,-.3*t,.05*t),capTop:cu(e,.035*n),capBottom:cu(e,-.035*t),crispMix:s,smoothMix:c,grad:null},$d.size>200&&$d.clear(),$d.set(r,i)}return i}var tf=e=>(e.startsWith(`hsl(`)?e:cu(e,0)).match(/[\d.]+/g).map(Number);function nf(e,t,n){let r=tf(e),i=tf(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 rf=34,af=Math.PI*1.55,of=57,sf=.4,cf=-.28,lf=new Map;function uf(e){let t=lf.get(e);return t||(t={base:cu(e,.1,.02),light:cu(e,.3,.04),dark:cu(e,-.22,.08),halo:cu(e,.2)},lf.size>200&&lf.clear(),lf.set(e,t)),t}var df=(e,t)=>e.replace(`)`,` / ${Math.max(0,Math.min(1,t)).toFixed(3)})`);function ff(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=af*d,m=uf(n),h=-t.whirlAngle,g=of*l,_=g*sf*f*(a?1.14:.86),v=Math.atan2(i,r)-cf;e.save(),e.rotate(cf),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<rf;e++){let t=e/rf,n=h+t*p,r=n+p/rf+.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<rf;e++){let t=e/rf,n=h+t*p,r=n+p/rf+.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,df(m.halo,f*.2),0),y(n,r,d*.8,df(m.dark,f*.45),d*.32),y(n,r,d,df(m.base,f*.72),0),y(n,r,d*.62,df(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 pf(e,t,n,r){let i=t*Gd;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=Jd*(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=ef(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=Bd(s,[T*D,E*D,-E*O,T*O,i/2+n.x*a-E*k,i/2+Kd*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`&&(_=Wd(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<qd&&!_;t++){let n=-1+2*(E>0?t:16-t)/16,r=Yd(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 _};ff(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=Yd(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),Cf(e,n,r),e.restore()}ff(e,n,r.color,m,h,!0,r.whirl),e.restore()}var mf=30;function hf(e,t,n,r){let i=Math.asin(Math.max(-1,Math.min(1,e/mf)))+n,a=Math.asin(Math.max(-1,Math.min(1,-t/mf)))+r,o=Math.cos(a);return{x:mf*Math.sin(i)*o,y:-30*Math.sin(a),sx:Math.cos(i),sy:o,z:Math.cos(i)*o}}var gf=8,_f=new Map;function vf(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=_f.get(o);if(!s){let e=r/50,t=i/50,n=a/50,c=`M${-e} ${t}`;for(let r=1;r<=gf;r++){let i=r/gf,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),_f.size>256&&_f.clear(),_f.set(o,s)}return s}var yf=Math.sin(.684),bf=Math.cos(.684),xf=new Map;function Sf(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=xf.get(c);if(l)return l;let u=e=>e.toFixed(3),d=r*yf,f=r*bf,p=-n+d,m=-f,h=n-d,g=-f,_=-n-d,v=f,y=n+d,b=f,x=4/3*r*bf,S=4/3*r*yf,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),xf.size>256&&xf.clear(),xf.set(c,l),l}function Cf(e,t,n){let[r,i,a]=t.w,o=n.ink,s=Qd[n.face],c=Xd/2,l=t.lookX,u=t.lookY,{yaw:d,pitch:f}=t,p=(t,n,r,i=1)=>{let a=hf(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*Zd*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(vf(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(Sf(f))})}}var wf={x:NaN,y:NaN},Tf=new Set,Ef=0,Df=0;function Of(e){Ef=0;let t=Df?Math.min(.1,(e-Df)/1e3):0;Df=e,Tf.forEach(e=>e(t)),Tf.size&&(Ef=requestAnimationFrame(Of))}function kf(){Ef||typeof document>`u`||document.hidden||(Df=0,Ef=requestAnimationFrame(Of))}var Af=!1;function jf(){Af||typeof document>`u`||(Af=!0,document.addEventListener(`pointermove`,e=>{wf.x=e.clientX,wf.y=e.clientY},{passive:!0}),document.addEventListener(`pointerleave`,()=>{wf.x=NaN,wf.y=NaN}),window.addEventListener(`blur`,()=>{wf.x=NaN,wf.y=NaN}),document.addEventListener(`visibilitychange`,()=>{document.hidden?(Ef&&cancelAnimationFrame(Ef),Ef=0):Tf.size&&kf()}))}function Mf(e){return jf(),Tf.add(e),kf(),()=>{Tf.delete(e),!Tf.size&&Ef&&(cancelAnimationFrame(Ef),Ef=0)}}function Nf(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 Pf=(e,t,n)=>Math.min(n,Math.max(t,Number.isFinite(e)?e:1)),Ff=new Map;function If(e){let t=Ff.get(e);return t||(t=new Path2D(e),Ff.set(e,t)),t}var Lf=()=>typeof matchMedia==`function`&&matchMedia(`(prefers-reduced-motion: reduce)`).matches,Rf=(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=Jl[e]??Jl.clover,ce=n??se.face,le=a??se.color,ue=s===1&&c===1?le:cu(le,(Math.min(2,Math.max(0,s))-1)*.35,(Math.min(2,Math.max(0,c))-1)*.5),U=o??ru(ue),de=Math.min(1,Math.max(0,f??Nf(oe))),W=r in Xl?r:`default`,G=d||!(u>0),fe=p===!0?`crisp`:p===!1?`flat`:p,pe=typeof t==`string`&&t.trim()?t.trim():null,K=pe?`path:${Nf(pe)}:${pe.length}`:e,q=(0,l.useRef)(null),me=(0,l.useRef)(null),he=(0,l.useRef)(0),ge=(0,l.useRef)(u);ge.current=u;let _e=(0,l.useRef)(b);_e.current=b,me.current={path:typeof Path2D>`u`?null:If(pe??Zl[e]??Zl.clover),face:ce,faceX:se.faceX,faceY:se.faceY,faceScale:se.faceScale,color:ue,ink:U,shading:fe,shadow:Pf(m,0,2),highlight:Pf(h,0,2),depth:Pf(g,.2,2),light:_,rim:Pf(v,0,2),spread:Pf(y,.4,2.5),typeKey:K,still:G||Lf(),whirl:{strength:Pf(C,0,2),size:Pf(w,.6,1.6),width:Pf(T,.4,2),length:Pf(E,.4,1.6),tilt:Pf(D,.5,1.8)},parts:typeof Path2D<`u`&&!pe&&Ql[e]?If(Ql[e]):void 0};let ve=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`},ye=()=>{let e=ae.current,t=me.current;if(!e||!t||!t.path)return;let n=e.clientWidth/1.5||he.current||(typeof i==`number`?i:64);if(!n)return;let r=Math.min(2,typeof devicePixelRatio==`number`&&devicePixelRatio||1),a=Math.round(n*Gd*r);(e.width!==a||e.height!==a)&&(e.width=a,e.height=a),he.current=n;let o=e.getContext(`2d`);o&&(o.setTransform(r,0,0,r,0,0),t.dpr=r,pf(o,n,q.current?q.current.pose:Lu(W),t))};(0,l.useLayoutEffect)(()=>{if(q.current?q.current.setState(W):q.current=new Iu(de,W),q.current.setTurn(Pf(x,0,2)),q.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)}),Lf()){let e=ae.current;if(e&&me.current&&me.current.path){let t=e.clientWidth/1.5||he.current||(typeof i==`number`?i:64);if(!t)return;he.current=t;let n=Math.min(2,typeof devicePixelRatio==`number`&&devicePixelRatio||1);e.width=e.height=Math.round(t*Gd*n);let r=e.getContext(`2d`);r&&(me.current.theme=ve(e),me.current.dpr=n,r.setTransform(n,0,0,n,0,0),pf(r,t,Lu(W),me.current))}return}me.current&&ae.current&&(me.current.theme=ve(ae.current)),ye()}),(0,l.useEffect)(()=>{var e;if(fe!==`plastic`||!((e=me.current)!=null&&e.path))return;let t=me.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))(()=>md(K,t,n,g));return()=>{typeof cancelIdleCallback==`function`?cancelIdleCallback(r):clearTimeout(r)}},[fe,K,i,g]),(0,l.useEffect)(()=>{if(G||Lf())return;let e=ae.current;if(!e)return;let t=!0,n=null,r=t=>{let n=q.current;if(n){if(_e.current&&!Number.isNaN(wf.x)){let t=e.getBoundingClientRect(),r=t.width/1.5||1,i=(wf.x-(t.left+t.width/2))/r,a=(wf.y-(t.top+t.height/2+Kd*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*ge.current),ye()}},i=()=>{n||=Mf(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()}},[G]);let be=typeof i==`number`?`${i*Gd}px`:`calc(${i} * ${Gd})`,xe=e=>typeof i==`number`?`${-i*e}px`:`calc(${i} * ${-e})`,Se=.5/2,Ce={display:`inline-block`,verticalAlign:`middle`,width:be,height:be,marginLeft:xe(Se),marginRight:xe(Se),marginTop:xe(.35),marginBottom:xe(.15),flex:`none`,...re},we=e=>{var t,n;b&&!G&&((t=q.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":W,role:`img`,"aria-label":V??`${se.label} bot, ${Xl[W]}`,style:Ce,...H,onClick:we})}),zf=137.508,Bf=e=>(e*zf%360).toFixed(3);function Vf(e){let t=e.avatarIndex;return{type:Yl[t%Yl.length],color:`hsl(${Bf(t)} 72% 58%)`,seed:t*.61803398875%1}}var Hf=2e3,Uf=0;function Wf(e){let[t,n]=(0,l.useState)(!e);return(0,l.useEffect)(()=>{if(e){n(!1);return}let t=setTimeout(()=>n(!0),Hf);return()=>clearTimeout(t)},[e]),t}function Gf({thread:e,working:t,size:n}){let r=Wf(t),i=r?`rest`:`moving`;return(0,Q.jsx)(Rf,{...Vf(e),state:t?`working`:`default`,size:n,paused:r,turn:t?void 0:Uf},i)}var Kf={nextThread:`Next thread`,previousThread:`Previous thread`,nextPane:`Next pane`,previousPane:`Previous pane`,toggleSidebar:`Toggle sidebar`,newThread:`New thread`,openTerminal:`New terminal`,closePane:`Close pane`},qf={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 Jf(){try{let e=JSON.parse(localStorage.getItem(`webr-shortcuts`)??`{}`);return{...qf,...Object.fromEntries(Object.entries(e).filter(([e])=>Object.hasOwn(qf,e)))}}catch{return qf}}function Yf(e){let t={ctrl:`⌃`,alt:`⌥`,meta:`⌘`,shift:`⇧`,space:`Space`,escape:`Esc`};return e.split(`+`).map(e=>t[e]??e.toUpperCase())}function Xf(e){return Yf(e).join(``)}function Zf(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 Qf(e){return/^(meta\+(w|t|r|l|n)|ctrl\+(w|t|r|n))$/.test(e)||!/(ctrl|alt|meta)\+/.test(e)}function $f(e){let t=window.matchMedia(`(prefers-color-scheme: dark)`).matches;document.documentElement.dataset.theme=e===`system`?t?`dark`:`light`:e}function ep({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),$f(t);let r=window.matchMedia(`(prefers-color-scheme: dark)`),i=()=>{let e=localStorage.getItem(`webr-theme`)||`system`;n(e),$f(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),$f(e)};return(0,Q.jsx)(`div`,{className:e?`theme-control theme-control--expanded`:`theme-control`,role:`group`,"aria-label":`Color theme`,children:[[`system`,L],[`light`,se],[`dark`,R]].map(([n,i])=>(0,Q.jsx)(ql,{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 tp={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 np(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(tp[r.error??``]??`Herdr could not complete this action.`);return r}var rp=(e,t)=>np(`/api/threads/${encodeURIComponent(e.id)}/archive`,{machineId:e.machineId,archived:t}),ip=(e,t)=>np(`/api/threads/${encodeURIComponent(e.id)}/rename`,{machineId:e.machineId,title:t}),ap=(e,t)=>np(`/api/projects/rename`,{machineId:e.machineId??`local`,logicalId:e.logicalId??e.id,name:t}),op=(e,t)=>np(`/api/threads/${encodeURIComponent(e.id)}/panes/terminal`,{machineId:e.machineId,afterPaneId:t}),sp=(e,t,n)=>np(`/api/threads/${encodeURIComponent(e.id)}/panes/close`,{machineId:e.machineId,paneId:t,force:n}),cp=e=>np(`/api/threads/${encodeURIComponent(e.id)}/delete`,{machineId:e.machineId}),lp=()=>np(`/api/archive/delete`),up=(e,t,n)=>e===1?t:n;function dp(e){let t=e.length,n=e.filter(e=>e.ownsWorktree).length,r=up(t,`Delete this thread`,`Delete ${t} threads`),i=up(t,`its terminal`,`their terminals`);return n?`${r} permanently? This closes ${i} and removes ${n===t?up(t,`its worktree`,`their worktrees`):`${n} ${up(n,`worktree`,`worktrees`)}`}, including uncommitted changes.`:`${r} permanently? This closes ${i}. Your project files stay untouched.`}var fp=(e,t)=>e.panes.length>1&&e.panes.some(e=>e.id===t&&e.kind!==`agent`),pp=(e,t)=>e[t-1]??e[t+1];function mp(e,t,n){let r=e.findIndex(e=>e.id===n);return e.slice(t,t+2).find(e=>e.id!==n)??pp(e,r)}function hp(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 gp(e){let t=performance.now();return()=>performance.now()-t}var _p=()=>performance.now();function vp(){}var yp=e=>il(e instanceof Error?e.message:`Herdr could not complete this action.`);function bp({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)(qf),O=(0,l.useRef)(null);(0,l.useEffect)(()=>{e&&(S(``),w(0),E(Jf()),requestAnimationFrame(()=>O.current?.focus()))},[e]);let A=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)(ie,{size:16}),shortcut:`newThread`,run:()=>{a(`/new${i?`?project=${encodeURIComponent(i.projectId)}`:``}`)}},{label:`Settings`,icon:(0,Q.jsx)(H,{size:16}),run:()=>{a(`/settings`)}},{label:`Toggle sidebar`,icon:(0,Q.jsx)(B,{size:16}),shortcut:`toggleSidebar`,run:u},...r.length?[{label:`Next thread`,icon:(0,Q.jsx)(m,{size:16}),shortcut:`nextThread`,run:()=>A(1)},{label:`Previous thread`,icon:(0,Q.jsx)(_,{size:16}),shortcut:`previousThread`,run:()=>A(-1)}]:[],{label:`Group threads by project`,icon:(0,Q.jsx)(k,{size:16}),detail:s===`projects`?`Selected`:void 0,run:()=>c(`projects`)},{label:`Show all threads`,icon:(0,Q.jsx)(N,{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)(L,{size:16}):e===`light`?(0,Q.jsx)(se,{size:16}):(0,Q.jsx)(R,{size:16}),run:()=>{localStorage.setItem(`webr-theme`,e),$f(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:()=>{rp(i,!i.archivedAt).catch(yp)}},{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)(ae,{size:16}),shortcut:`openTerminal`,run:y},...fp(i,o)?[{label:`Close pane`,icon:(0,Q.jsx)(ue,{size:16}),shortcut:`closePane`,run:b}]:[]]:[],...i.bindingState===`attached`?[{label:`Request terminal control`,icon:(0,Q.jsx)(ae,{size:16}),run:()=>v(`control`)},{label:`Release terminal control`,icon:(0,Q.jsx)(ae,{size:16}),run:()=>v(`release`)},{label:`Take over terminal control`,icon:(0,Q.jsx)(ae,{size:16}),run:()=>{rl(`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)(ae,{size:16}),detail:`Pane ${t+1}`,run:()=>d(e.id)}))]:[],...r.map(e=>({label:e.title,icon:(0,Q.jsx)(Gf,{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 P=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(),P(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:()=>P(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)(ql,{label:T[e.shortcut],children:(0,Q.jsx)(`kbd`,{children:Xf(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 xp=2e3,Sp=e=>fetch(e,{method:`POST`,headers:{"Content-Type":`application/json`},body:`{}`});async function Cp(){let e=await Sp(`/api/pair/invites`);if(!e.ok)throw Error(`Webr could not create a code.`);return e.json()}async function wp(){let e=await fetch(`/api/devices`);if(!e.ok)throw Error(`Webr could not list devices.`);return e.json()}async function Tp(){let e=await fetch(`/api/audit`);if(!e.ok)throw Error(`Webr could not load recent activity.`);return e.json()}async function Ep(){let e=await fetch(`/api/remote/tailscale`);return e.ok?(await e.json()).status:`unavailable`}var Dp=e=>Sp(`/api/devices/${encodeURIComponent(e)}/revoke`),Op=(e,t)=>Sp(`/api/pair/${encodeURIComponent(e)}/${t}`);async function kp(){try{let e=await fetch(`/api/pair/pending`);return e.ok?await e.json():[]}catch{return[]}}var Ap=()=>typeof Notification<`u`&&Notification.permission===`granted`,jp=()=>document.visibilityState===`visible`||Ap();function Mp(e,t){if(document.visibilityState!==`visible`&&Ap())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 Np(){let[e,t]=(0,l.useState)([]),n=(0,l.useRef)(new Set),r=(0,l.useCallback)(async()=>{if(!jp())return;let e=await kp();Mp(e,n.current),t(e)},[]);return(0,l.useEffect)(()=>{r();let e=setInterval(()=>void r(),xp);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 Op(e,n).catch(()=>void 0),await r()},[r])}}function Pp(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 Fp=()=>typeof Notification<`u`,Ip=()=>Fp()?Notification.permission:`denied`,Lp=()=>Notification.requestPermission();function Rp({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 zp(e,t=Date.now()){return e<=t?`expired`:new Intl.RelativeTimeFormat(`en`,{numeric:`auto`}).format(...Bp(e-t))}function Bp(e){let t=Math.round(e/864e5);return t>=1?[t,`day`]:[Math.max(1,Math.round(e/36e5)),`hour`]}function Vp(){let{pending:e,decide:t}=Np(),n=e[0];return(0,Q.jsx)(Tc,{open:!!n,onOpenChange:e=>{!e&&n&&t(n.id,`deny`)},children:(0,Q.jsxs)(Kc,{children:[(0,Q.jsx)(Ec,{className:`dialog-backdrop`}),(0,Q.jsx)(Uc,{className:`dialog pairing-prompt`,children:n&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(qc,{className:`pairing-title`,children:[`Allow `,n.deviceName,` to connect?`]}),(0,Q.jsxs)(Ic,{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 Hp=({children:e})=>(0,Q.jsx)(Q.Fragment,{children:e}),Up=[`image/png`,`image/jpeg`,`image/gif`,`image/webp`],Wp={image_too_large:`This image is larger than 20 MB.`,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.`},Gp=e=>Up.includes(e.type),Kp=e=>e?.files?[...e.files].filter(Gp):[],qp=e=>!!e?.types&&[...e.types].includes(`Files`),Jp=e=>e.replace(/([\s\\'"()&;$`!*?[\]{}<>|#~])/g,`\\$1`);async function Yp(e,t){if(!Gp(t))throw Error(Wp.unsupported_image);if(t.size>20971520)throw Error(Wp.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(Wp[r.error??``]??`The image could not be attached.`);return r.path}var Xp=160,Zp=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 Qp(e){if(typeof createImageBitmap!=`function`)return Zp(e);let t=await createImageBitmap(e),n=Math.min(1,Xp/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 $p(e,t){let n=[];for(let r of t)n.push(await Yp(e,r));return n.map(Jp).join(` `)+` `}var em=e=>Array.from(e,e=>e.toString(16).padStart(2,`0`)).join(``);function tm(){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=em(e);return`${t.slice(0,8)}-${t.slice(8,12)}-${t.slice(12,16)}-${t.slice(16,20)}-${t.slice(20)}`}var nm=`Only PNG, JPEG, GIF and WebP images can be attached.`,rm=(e,t)=>[e.trim(),...t.map(e=>Jp(e.path))].filter(Boolean).join(` `);function im({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(nm);return}c(``),o(e=>e+t.length);for(let n of t)try{let t=await Yp(e,n),r=await Qp(n);i(e=>[...e,{id:tm(),name:n.name||`image`,preview:r,path:t}])}catch(e){c(e instanceof Error?e.message:`The image 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=>{qp(e.dataTransfer)&&(e.preventDefault(),u.current+=1,n(!0))},onDragOver:e=>{qp(e.dataTransfer)&&(e.preventDefault(),e.dataTransfer.dropEffect=`copy`)},onDragLeave:e=>{qp(e.dataTransfer)&&(u.current=Math.max(0,u.current-1),u.current||n(!1))},onDrop:e=>{qp(e.dataTransfer)&&(e.preventDefault(),u.current=0,n(!1),d(Kp(e.dataTransfer)))},onPaste:e=>{let t=Kp(e.clipboardData);t.length&&(e.preventDefault(),d(t))}}}}function am({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 om(e){let t=l.useRef(!0);t.current&&(t.current=!1,e())}function sm(e,t,n,r,i,a,o,s,c,l=2){let u=jr(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 Dr(n.current,u)?void 0:u}var cm=l.createContext(void 0),lm=l.createContext(void 0),um=l.createContext(void 0),dm=l.createContext(!1),fm=l.createContext(``);function pm(){let e=l.useContext(cm);if(!e)throw Error(Oi(22));return e}function mm(){let e=l.useContext(lm);if(!e)throw Error(Oi(23));return e}function hm(){let e=l.useContext(um);if(!e)throw Error(Oi(24));return e}function gm(){return l.useContext(fm)}function _m(){return l.useContext(dm)}function vm(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 ym=(e,t)=>Object.is(e,t);function bm(e,t,n){return e==null||t==null?Object.is(e,t):n(e,t)}function xm(e,t,n){return Array.isArray(e)&&Array.isArray(t)?!vm(e,t,(e,t)=>bm(e,t,n)):e!==t}function Sm(e,t,n){return e?e.some(e=>e!==void 0&&bm(t,e,n)):!1}function Cm(e,t,n){return e?e.findIndex(e=>e!==void 0&&bm(e,t,n)):-1}function wm(e,t){if(t!==ym)return n=>Sm(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 Tm(e,t,n,r){let i=r&&Array.isArray(t)?e.findIndex(wm(t,n)):Cm(e,t,n);return i===-1?null:i}function Em(e,t,n,r,i,a){return Sm(r,t,i)?a!=null&&e>a&&Sm(r,n[a],i)?a:e:e===a?Tm(n,r,i,!0):a}function Dm(e,t,n){return e.filter(e=>!bm(t,e,n))}function Om(e){if(e==null)return``;if(typeof e==`string`)return e;try{return JSON.stringify(e)}catch{return String(e)}}function km(e){return typeof e==`object`&&!!e&&Array.isArray(e.items)}function Am(e){return km(e?.[0])}function jm(e){return Am(e)?e.flatMap(e=>e.items):e}function Mm(e){if(!Array.isArray(e))return e!=null&&`null`in e;let t=e;if(Am(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 Nm(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 Om(e)}function Pm(e,t){return t&&e!=null?t(e)??``:e&&typeof e==`object`&&`value`in e&&`label`in e?Om(e.value):Om(e)}var Fm={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?Mm(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=>bm(t,e,n)):bm(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},Im=`data-valid`,Lm=`data-invalid`,Rm={badInput:!1,customError:!1,patternMismatch:!1,rangeOverflow:!1,rangeUnderflow:!1,stepMismatch:!1,tooLong:!1,tooShort:!1,typeMismatch:!1,valid:null,valueMissing:!1},zm={valid:null,touched:!1,dirty:!1,filled:!1,focused:!1},Bm={disabled:!1,...zm},Vm={valid(e){return e===null?null:e?{[Im]:``}:{[Lm]:``}}},Hm={invalid:void 0,name:void 0,validityData:{state:Rm,errors:[],error:``,value:``,initialValue:null},setValidityData:Xe,disabled:void 0,setTouched:Xe,setDirty:Xe,setFilled:Xe,setFocused:Xe,validationMode:`onSubmit`,shouldValidateOnChange:()=>!1,state:Bm,registerFieldControl:Xe,validation:{getValidationProps:(e,t=Qe)=>t,inputRef:{current:null},registeredInputs:new Map,registerInput:Xe,getInputControl:()=>null,commit:async()=>{},change:Xe}},Um=l.createContext(Hm);function Wm(e=!0){let t=l.useContext(Um);if(t.setValidityData===Xe&&!e)throw Error(Oi(28));return t}function Gm(e,t,n,r,i=!0,a){let{registerFieldControl:o}=Wm(),s=Ye(()=>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 Km=l.createContext({elementRef:{current:null},formRef:{current:{fields:new Map}},errors:{},clearErrors:Xe,validationMode:`onSubmit`,submitCountRef:{current:0}});function qm(){return l.useContext(Km)}var Jm=l.createContext({controlId:void 0,registerControlId:Xe,resetControlId:Xe,labelId:void 0,setLabelId:Xe,messageIds:[],setMessageIds:Xe,getDescriptionProps:e=>e});function Ym(){return l.useContext(Jm)}function Xm(e={}){let{id:t,enabled:n=!0}=e,{controlId:r,registerControlId:i,resetControlId:a}=Ym(),o=Fc(),s=Ye(()=>Symbol()),c=l.useRef(!1),u=l.useRef(!1),d=$(()=>{c.current&&i!==Xe&&(c.current=!1,i(s.current,void 0))});return U(()=>{if(!n||i===Xe){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 Zm(e){return e==null?void 0:`${e}-popup`}function Qm(e,t){return(n,r)=>n!=null&&e.contains(n,r,t)}function $m(e){return Array.isArray(e)?e.map(e=>$m(e)).join(`,`):e==null?``:String(e)}var eh=new Map;function th(e={}){let t={usage:`search`,sensitivity:`base`,ignorePunctuation:!0,...e},n=`${$m(e.locale)}|${JSON.stringify(t)}`,r=eh.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=Nm(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=Nm(e,n);return i.compare(r.slice(0,t.length),t)===0},endsWith(e,t,n){if(!t)return!0;let r=Nm(e,n),a=t.length;return r.length>=a&&i.compare(r.slice(r.length-a),t)===0}};return eh.set(n,a),a}var nh=th;function rh(e,t=!1){let{overflowY:n}=Ee(e);return n!==`auto`&&n!==`scroll`?!1:t?e.clientHeight>0:e.scrollHeight>e.clientHeight}var ih=Symbol(`none`),ah={value:ih,index:-1};function oh(e,t,n){let r=e.get(t);if(r!==void 0||n===ym)return r;for(let[r,i]of e)if(bm(r,t,n))return i}function sh(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=ym,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}=qm(),{setDirty:te,validityData:ne,setFilled:re,name:V,disabled:H,setTouched:ie,setFocused:ae,validationMode:oe,validation:se}=Wm(),ce=El(),le=Xm({id:t}),ue=nh({locale:z}),de=Array.isArray(b)?null:b;if(de&&typeof de.label!=`function`)throw Error(Oi(100));let W=de?de.data:b,G=de?.value,fe=G?void 0:W,pe=l.useMemo(()=>{if(!x||!G)return;let e=jm(x),t=e.map(G),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 oh(n,r,i)}}},[x,G]),K=l.useMemo(()=>de?e=>de.label(e,j,e=>{let t=pe?.findItem(e,j);return t==null?Nm(e,k):de.itemLabel(t)}):k,[de,k,pe,j]),me=l.useMemo(()=>de?Object.assign(e=>de.itemLabel(e),{selected:e=>Nm(e,K)}):k,[de,K,k]);function he(e){return Nm(e,K)}let[ge,_e]=l.useState(!1),[ve,ye]=l.useState(null),be=l.useRef(ve),xe=l.useRef([]),Se=l.useRef([]),Ce=l.useRef(null),we=l.useRef(null),Te=l.useRef(null),Ee=l.useRef(null),De=l.useRef(null),Oe=l.useRef(!0),ke=l.useRef(!1),je=l.useRef(null),J=l.useRef(null),Me=l.useRef(null),Ne=l.useRef(ah),Pe=l.useRef(null),Fe=l.useRef([]),Ie=l.useRef(null),Le=H||h,Re=V??p,ze=d===`multiple`,Be=d===`single`,Ve=s!==void 0||o!==void 0,He=W!==void 0,Ue=x!==void 0,We;We=T===`always`?`always`:T?`input-change`:!1;let[Ge,Ke]=am({controlled:i,default:ze?r??Ze:r,name:`Combobox`,state:`selectedValue`}),qe=l.useMemo(()=>S===null?()=>!0:S===void 0?Qm(ue,me):S,[S,ue,me]),Je=Ye(()=>Ve?o??``:Be?he(Ge):``).current,[$e,et]=am({controlled:s,default:Je,name:`Combobox`,state:`inputValue`}),[tt,nt]=am({controlled:c,default:u,name:`Combobox`,state:`open`}),rt=Am(W),it=!tt&&ve!==null?ve:String($e).trim(),at=Be?he(Ge):``,ot=Be&&!ge&&it!==``&&at.length===it.length&&ue.contains(at,it),st=ot?``:C??it,ct=He&&Ue&&ot&&(!de||de.hasValue(Ge,j)),lt=l.useMemo(()=>W?jm(W):Ze,[W]),ut=l.useMemo(()=>{if(x&&!ct)return x;if(!W)return Ze;if(rt){let e=W,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;qe(t,st,me)&&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;qe(t,st,me)&&e.push(t)}return e},[x,ct,W,rt,st,I,qe,me,lt]),dt=l.useMemo(()=>{if(pe&&ut===x)return pe.values;let e=jm(ut);return G?e.map(e=>G(e)):e},[ut,x,pe,G]),Y=Ye(()=>{let e=null;return N&&tt&&He&&d!==`none`&&(e=Tm(dt,Ge,j,ze)),new ls({id:le,labelId:void 0,selectedValue:Ge,open:tt,items:fe,selectionMode:d,name:Re,form:m,disabled:Le,readOnly:g,required:_,grid:y,virtualized:M,openOnInputClick:w,itemToStringLabel:K,isItemEqualToValue:j,modal:F,autoHighlight:We,submitOnItemClick:ee,hasInputValue:Ve,mounted:!1,forceMounted:!1,transitionStatus:`idle`,inline:N,activeIndex:null,selectedIndex:e,popupProps:{},listProps:{},inputProps:{},triggerProps:{},itemProps:Qe,positionerElement:null,listElement:null,popupId:void 0,triggerElement:null,inputElement:null,inputGroupElement:null,popupSide:null,openMethod:null,inputInsidePopup:!0,inputOwnsFormValue:d===`none`},{onOpenChangeComplete:Xe,setOpen:Xe,setInputValue:Xe,setSelectedValue:Xe,setIndices:Xe,handleSelection:Xe,forceMount:Xe,requestSubmit:Xe,listRef:xe,labelsRef:Se,popupRef:Ce,emptyRef:De,inputRef:we,startDismissRef:Te,endDismissRef:Ee,keyboardActiveRef:Oe,chipsContainerRef:je,clearRef:J,valuesRef:Fe,pointerDownItemRef:Ie,selectionEventRef:Me},Fm)}).current,ft=d===`none`?$e:Ge,pt=l.useMemo(()=>d===`none`?ft:Array.isArray(Ge)?Ge.map(e=>Pm(e,A)):Pm(Ge,A),[ft,A,d,Ge]),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`),Tt=Y.useState(`inputInsidePopup`),Et=Y.useState(`inputOwnsFormValue`),Dt=Be&&!Tt&&$e===at,Ot=Hn(bt),{mounted:kt,setMounted:At,transitionStatus:jt}=ps(tt),{openMethod:Mt,triggerProps:Nt}=Zc(tt),Pt=$(()=>pt);Gm(Tt?Ot:we,le,ft,Pt,!Le,p);let Ft=$(()=>{W?Se.current=dt.map(he):Y.set(`forceMounted`,!0)}),It=$((e,t,n)=>{if(t===-1){if(Ne.current===ah)return;Ne.current=ah}else Ne.current={value:e,index:t};mt(e,An(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(Fe.current[n],n,r)}),Rt=$((t,n)=>{if(e.onInputValueChange?.(t,n),!n.isCanceled){if(ke.current=n.reason===yn,n.reason===`input-change`){tt&&ve!==null&&ye(null);let e=n.event,r=e.inputType;if(e.type===`compositionend`||r!=null&&r!==``&&r!==`insertReplacementText`){let e=t.trim()!==``;e&&_e(!0),Pe.current={hasQuery:e};let n=Y.state.listElement;if(!Y.state.virtualized&&n){let e=Ce.current;for(let t of Ae(n.firstElementChild??n)){if(!q(t)||(e?!X(e,t):t.getAttribute(`role`)===`dialog`))break;if(rh(t)){t.scrollTop=0;break}}}e&&We&&Y.state.activeIndex==null&&(tt||Ct)&&Y.set(`activeIndex`,0)}}else n.reason===`input-clear`&&t===``&&Y.state.inputInsidePopup&&(Pe.current={hasQuery:!1,selection:!0});et(t)}}),zt=$(e=>{let t=!e&&Tt&&!Ct&&$e!==``&&(String($e).trim()===ve||$e===at);!e&&(t||$e===``||Dt)&&_e(!1),ye(null),t&&Rt(``,Z(yn))}),Bt=$((t,n)=>{if(tt!==t&&(n.reason===`escape-key`&&He&&dt.length===0&&!De.current&&n.allowPropagation(),e.onOpenChange?.(t,n),!n.isCanceled&&(t&&ve!==null&&zt(n.reason===vn),!t&&ge&&(Be?(Ct||ye(it),it===``&&_e(!1)):ze&&(Ct||ye(it),Tt&&Lt({activeIndex:null}),(!Tt||Ct)&&Rt(``,Z(yn,n.event,void 0,{isItemPress:n.reason===gn})))),nt(t),!t&&Tt&&(n.reason===`focus-out`||n.reason===`outside-press`)&&(ie(!0),ae(!1),oe===`onBlur`)))){let e=d===`none`?$e:Ge;se.commit(e)}}),Vt=$((e,t)=>{a?.(e,t),!t.isCanceled&&(Ke(e),(d===`none`&&Ce.current&&P||Be&&!Y.state.inputInsidePopup)&&Rt(he(e),Z(t.reason,t.event)))}),Ht=$((e,t)=>{let n=wt(e),r=Me.current??e;Me.current=null;let i=Z(gn,r),a=n?.closest(`a`)?.getAttribute(`href`);if(a){a.startsWith(`#`)&&Bt(!1,i);return}if(ze){let e=Array.isArray(Ge)?Ge:[],n=Sm(e,t,j),r=n?Dm(e,t,j):[...e,t];if(Vt(r,i),i.isCanceled||!(we.current&&we.current.value.trim()!==``))return;if(Y.state.inputInsidePopup){Rt(``,Z(yn,i.event,void 0,{isItemPress:!0}));let e=Pe.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),_e(!1),ye(null),Lt(d===`none`?{activeIndex:null,selectedIndex:null}:{activeIndex:null}),ze&&we.current&&we.current.value!==``&&!ke.current&&Rt(``,Z(yn)),Be){if(Y.state.inputInsidePopup)we.current&&we.current.value!==``&&Rt(``,Z(yn));else{let e=he(Ge);we.current&&we.current.value!==e&&Rt(e,Z(e===``?yn:dn))}}}),Gt=l.useMemo(()=>Ct&&vt?{current:vt.closest(`[role="dialog"]`)}:Ce,[Ct,vt]);_s({enabled:!e.actionsRef,open:tt,ref:Gt,onComplete(){tt||Wt()}}),l.useImperativeHandle(e.actionsRef,()=>({unmount:Wt}),[Wt]),U(function(){let e=be.current!==null&&ve===null;if(be.current=ve,tt&&(!e||!He)||(tt||(Ie.current=null),d===`none`))return;let t=He?dt:Fe.current;Lt({selectedIndex:Tm(t,Ge,j,ze)})},[tt,ve,Ge,d,ze,He,dt,j,Lt]),U(()=>{W&&(Fe.current=dt,xe.current.length=dt.length)},[W,dt]),U(()=>{let e=Pe.current;if(e){let t=tt||Ct||Y.state.positionerElement?.hidden===!1;if(e.hasQuery)We&&t&&Y.set(`activeIndex`,0),Pe.current=null;else if(String($e).trim()===``&&(Pe.current=null,t)){let t=e.selection;We===`always`&&!t&&Y.state.selectionMode===`none`&&Y.set(`activeIndex`,0),queueMicrotask(()=>{if(!Y.state.open&&!Y.state.inline||we.current&&we.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=He||Ue?dt:Fe.current,i=Cm(t,e.toggledValue,Y.state.isItemEqualToValue);Y.set(`activeIndex`,i===-1?Tm(t,n,Y.state.isItemEqualToValue,r):i)}else t?Y.set(`activeIndex`,null):We===`always`&&Y.set(`activeIndex`,0)})}}if(!tt&&!Ct)return;let t=He||Ue?dt:Fe.current,n=Y.state.activeIndex;if(n==null){if(We===`always`&&t.length>0){Y.set(`activeIndex`,0);return}It(void 0,-1,dn);return}if(n>=t.length){It(void 0,-1,dn),Y.set(`activeIndex`,null);return}let r=t[n],i=Ne.current.value,a=i!==ih&&bm(r,i,Y.state.isItemEqualToValue);(Ne.current.index!==n||!a)&&It(r,n,dn)},[gt,We,It,Ue,He,dt,Ct,tt,Y,$e]),U(()=>{if(d===`none`){re(String($e)!==``);return}re(ze?Array.isArray(Ge)&&Ge.length>0:Ge!=null)},[re,d,$e,Ge,ze]),l.useEffect(()=>{He&&We&&dt.length===0&&Lt({activeIndex:null})},[He,We,dt.length,Lt]);function Kt(){tt&&it!==``&&it!==String(Je)&&!Dt&&_e(!0)}function qt(){tt&&ve!==null&&zt(!1)}let Jt=!1;function Yt(){!Jt&&$e!==at&&(Jt=!0,Rt(at,Z(dn)))}function Xt(){d!==`none`&&(B(Re),te(xm(Ge,ne.initialValue,j)),se.change(Ge),Be&&!Ve&&!Tt&&Yt())}function Zt(){Be&&!Ve&&!Tt&&!ge&&Yt()}function Qt(){d===`none`&&(B(Re),te($e!==ne.initialValue),se.change($e))}Yc(it,Kt),Yc(tt,qt),Yc(Ge,Xt),Yc(at,Zt),Yc(W,Zt),Yc($e,Qt);let $t=Vs({open:Ct?!0:tt,onOpenChange:Bt,elements:{reference:Tt?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=Na($t,{enabled:!Le&&w,event:`mousedown-only`,toggle:!1,touchOpenDelay:Tt?0:100,reason:bn}),on=za($t,{enabled:!Le&&!Ct,outsidePressEvent:{mouse:`sloppy`,touch:`intentional`},bubbles:Ct?!0:void 0,outsidePress(e){let t=wt(e);return!X(bt,t)&&!X(J.current,t)&&!X(je.current,t)&&!X(St,t)}}),sn=sc($t,{enabled:!Le,id:le,listRef:xe,activeIndex:gt,selectedIndex:_t,virtual:!0,loopFocus:O,allowEscape:O&&!We,focusItemOnOpen:ge||d===`none`&&!We?!1:`auto`,focusItemOnHover:D,resetOnPointerLeave:!E,orientation:y?`horizontal`:void 0,rtl:ce===`rtl`,disabledIndices:Ze,grid:y?sm:void 0,onNavigate(e,t){(t||tt)&&jt!==`ending`&&Lt(t?{activeIndex:e,type:Oe.current?wn:Tn}:{activeIndex:e})}}),cn=l.useMemo(()=>Li(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(()=>Li(vs,on.floating),[on.floating]),un=l.useMemo(()=>Li(sn.floating,rn.floating),[sn.floating,rn.floating]),fn=l.useMemo(()=>{let e=sn.item;return e?{...e,onFocus:void 0}:Qe},[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),om(()=>{Y.update({inline:N,popupProps:ln,listProps:un,inputProps:cn,triggerProps:Nt,itemProps:fn})});let pn={id:le,selectedValue:Ge,open:tt,mounted:kt,transitionStatus:jt,items:fe,inline:N,popupProps:ln,listProps:un,inputProps:cn,triggerProps:Nt,itemProps:fn,openMethod:Mt,selectionMode:d,name:Re,form:m,disabled:Le,readOnly:g,required:_,grid:y,virtualized:M,openOnInputClick:w,itemToStringLabel:K,modal:F,autoHighlight:We,isItemEqualToValue:j,submitOnItemClick:ee,hasInputValue:Ve};U(()=>{Y.update({...pn,inputOwnsFormValue:d===`none`&&(N||!Y.state.inputInsidePopup)})},[Y,...Object.values(pn)]);let mn=In(v,se.inputRef),hn=l.useMemo(()=>({query:it,hasItems:He,filteredItems:ut,flatFilteredValues:dt}),[it,He,ut,dt]),_n=l.useMemo(()=>Array.isArray(ft)?``:Pm(ft,A),[ft,A]),xn=ze&&Array.isArray(Ge)&&Ge.length>0,Sn=ze||d===`none`&&Et?void 0:Re,Cn=l.useMemo(()=>!ze||!Array.isArray(Ge)||!Re?null:Ge.map(e=>{let t=Pm(e,A);return(0,Q.jsx)(`input`,{type:`hidden`,form:m,name:Re,value:t,disabled:Le},t)}),[ze,Ge,m,Re,A,Le]),En=(0,Q.jsxs)(l.Fragment,{children:[e.children,(0,Q.jsx)(`input`,{...se.getValidationProps(Le,{onFocus(){if(Tt){bt?.focus();return}(we.current||bt)?.focus()},onChange(e){if(e.nativeEvent.defaultPrevented||Le||g)return;let t=e.currentTarget.value,n=t.toLowerCase(),r=Z(dn,e.nativeEvent),i=()=>Fe.current.findIndex(e=>Pm(e,A).toLowerCase()===n||he(e).toLowerCase()===n);function a(){if(ze)return;if(d===`none`){Rt(t,r);return}let e=i();e===-1&&(e=Fe.current.findIndex((e,t)=>{let r=Se.current[t];return r!=null&&r.toLowerCase()===n}));let a=e===-1?void 0:Fe.current[e];a!=null&&Vt?.(a,r)}Be&&(Ft(),W&&i()===-1&&Y.set(`forceMounted`,!0)),queueMicrotask(a)}}),id:le&&Sn==null?`${le}-hidden-input`:void 0,form:m,name:Sn,autoComplete:R,disabled:Le,required:_&&!xn,readOnly:g,value:_n,ref:mn,style:Sn?Zn:Xn,tabIndex:-1,"aria-hidden":!0,suppressHydrationWarning:!0}),Cn]});return(0,Q.jsx)(cm.Provider,{value:Y,children:(0,Q.jsx)(lm.Provider,{value:$t,children:(0,Q.jsx)(dm.Provider,{value:He,children:(0,Q.jsx)(um.Provider,{value:hn,children:(0,Q.jsx)(fm.Provider,{value:$e,children:En})})})})})}function ch(e){let{multiple:t=!1,defaultValue:n,value:r,onValueChange:i,autoComplete:a,...o}=e;return(0,Q.jsx)(sh,{...o,selectionMode:t?`multiple`:`single`,selectedValue:r,defaultSelectedValue:n,onSelectedValueChange:i,formAutoComplete:a})}function lh(e,t){return e??t}var uh=`data-popup-side`,dh=`data-list-empty`,fh={...qt,...Vm,popupSide:e=>e?{[uh]:e}:null,listEmpty:e=>e?{[dh]:``}:null},ph=l.createContext(void 0);function mh(){return l.useContext(ph)}var hh=l.createContext(void 0);function gh(e){let t=l.useContext(hh);if(t===void 0&&!e)throw Error(Oi(21));return t}var _h=l.forwardRef(function(e,t){let n=pm(),{buttonRef:r,getButtonProps:i}=jc({native:!1}),a=In(t,r);function o(e){n.context.setOpen(!1,Z(_n,e.nativeEvent,e.currentTarget))}let s=i({onClick:o});return(0,Q.jsx)(`span`,{ref:a,...s,"aria-label":`Dismiss`,tabIndex:void 0,style:Zn})});function vh(e){let t=e.useState(`mounted`),n=e.useState(`popupSide`),r=e.useState(`positionerElement`);return t&&r?n:null}function yh(){return hm().filteredItems.length===0}function bh(e){return e===`rtl`?[`ArrowRight`,`ArrowLeft`]:[`ArrowLeft`,`ArrowRight`]}function xh(e,t){let n=e>=t-1?t-2:e;return n>=0?n:void 0}function Sh(e,t,n){let r=e.context.listRef.current[t];r&&(e.context.selectionEventRef.current=n,r.click(),e.context.selectionEventRef.current=null)}var Ch=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}=Wm(),{labelId:h}=Ym(),g=mh(),_=!!gh(!0),v=pm(),y=gm(),b=El(),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=vh(v),R=u||S||i,z=yh(),ee=_||P,B=!ee||F,te=Fc(a??(ee?void 0:N)),ne=_?zm: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(dn)),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?wn:Tn})}function ue(){v.context.keyboardActiveRef.current=!1}let U={...ne,open:A,disabled:R,readOnly:C,popupSide:L,listEmpty:z};function de(e){if(!g)return;let t,{highlightedChipIndex:n}=g,r=g.chipsRef.current.length,[i,a]=bh(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=xh(n,M.length),le()),t)}let W=Zi(`input`,e,{state:U,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){Be||(H.current=!0,V(e.currentTarget.value))},onCompositionEnd(e){H.current=!1;let t=e.currentTarget.value;V(null),v.context.setInputValue(t,Z(vn,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(vn,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(yn,t));let r=n.trim(),i=I&&r!==``;a(r),A&&v.state.activeIndex!==null&&!i&&le();return}let o=Z(vn,t);if(v.context.setInputValue(e.currentTarget.value,o),o.isCanceled)return;let s=e.currentTarget.value===``,c=Z(yn,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&&_t(e);return}let t=e.currentTarget,n=t.scrollWidth-t.clientWidth,r=b===`rtl`;if(e.key===`Home`){_t(e);let n=We&&r?t.value.length:0;t.setSelectionRange(n,n),t.scrollLeft=0;return}if(e.key===`End`){_t(e);let i=We&&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(Sn,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(dn,e.nativeEvent));return}let i=g?.highlightedChipIndex!==void 0,a=de(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(dn,n));return}_t(e),Sh(v,t,n)}},onPointerMove:ue,onPointerDown:ue},ce],stateAttributesMapping:fh}),G=_?(0,Q.jsx)(Um.Provider,{value:Hm,children:W}):W;return(0,Q.jsxs)(l.Fragment,{children:[A&&B&&(0,Q.jsx)(_h,{ref:v.context.startDismissRef}),G]})}),wh=5;function Th(e,t){let n=Eh(t);return e.clientX>=n.left-wh&&e.clientX<=n.right+wh&&e.clientY>=n.top-wh&&e.clientY<=n.bottom+wh}function Eh(e){let t=e.getBoundingClientRect(),n=G(e);if(Ke)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 Dh=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}=Wm(),{labelId:g}=Ym(),_=pm(),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=mm(),F=gm(),I=nt(),L=d||y||a,R=yh(),z=vh(_);Xm({id:E?o:void 0});let ee=E?o??D:o,B=lh(g,O),te;k&&E?te=w??Zm(D):k&&(te=C?.id);let ne=l.useRef(``);function re(e){ne.current=e.pointerType}let{reference:V}=cc(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(dn))}}),{reference:H}=Na(P,{enabled:!y,event:`mousedown`}),{buttonRef:ie,getButtonProps:ae}=jc({native:i,disabled:L}),oe={...u,readOnly:b,open:k,disabled:L,popupSide:z,listEmpty:R,placeholder:v!==`none`&&!N};return Zi(`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=qe(e.currentTarget);function n(e){let t=_.state.triggerElement;if(!t)return;let n=wt(e),r=_.state.positionerElement,i=_.state.listElement;X(t,n)||X(r,n)||X(i,n)||Th(e,t)||_.context.setOpen(!1,Z(En,e))}E&&t.addEventListener(`mouseup`,n,{once:!0})},onKeyDown(e){(e.key===`ArrowDown`||e.key===`ArrowUp`)&&(_t(e),_.context.setOpen(!0,Z(Cn,e.nativeEvent)),_.context.inputRef.current?.focus())}},h.getValidationProps(L,c),ae],stateAttributesMapping:fh})}),Oh=l.createContext(null);function kh(){return l.useContext(Oh)}function Ah(e){let{children:t}=e,{filteredItems:n}=hm(),r=kh(),i=r?r.items:n;return(0,Q.jsx)(l.Fragment,{children:i.map(t)})}var jh=l.createContext({register:()=>{},unregister:()=>{},subscribeMapChange:()=>()=>{},nextIndexRef:{current:0}});function Mh(){return l.useContext(jh)}function Nh(e){let{children:t,elementsRef:n,labelsRef:r,onMapChange:i}=e,a=$(i),[,o]=l.useState(!1),s=Ye(Fh).current,c=Ye(Ph).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(!Rh(n))return;let r=null;for(let n of e)if(n.isConnected){if(r&&zh(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=Lh(e[t-1],e[t]);r&&n.add(r)}n.forEach(e=>t.observe(e,{childList:!0}))}let y=$(()=>{let[e,t]=Ih(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)(jh.Provider,{value:x,children:t})}function Ph(){return new Map}function Fh(){return new Set}function Ih(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)=>zh(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 Lh(e,t){let n=e.parentElement;for(;n&&!n.contains(t);)n=n.parentElement;return n}function Rh(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 zh(e,t){return e.compareDocumentPosition(t)&Node.DOCUMENT_POSITION_FOLLOWING?-1:1}var Bh=l.forwardRef(function(e,t){var n;let{render:r,className:i,style:a,children:o,...s}=e,c=pm(),u=mm(),d=!!gh(!0),{filteredItems:f,hasItems:p}=hm(),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)(Ah,{children:o}):o,[o]),T={empty:x},E=u.useState(`floatingId`),D=Zi(`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;_t(e),Sh(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)(Nh,{elementsRef:c.context.listRef,labelsRef:O,children:D})}),Vh=``;function Hh(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 Uh(){let e=nt(),t=l.useRef(null);return l.useEffect(()=>{if(Re)return;let n=t.current;if(n==null)return;let r=Hh(n);if(r==null)return;let i=r.data,a=`${i}${Vh}`;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 Wh=l.createContext(void 0);function Gh(){let e=l.useContext(Wh);if(e===void 0)throw Error(Oi(20));return e}var Kh=l.forwardRef(function(e,t){let{keepMounted:n=!1,...r}=e,i=pm(),a=i.useState(`mounted`),o=i.useState(`forceMounted`);return a||n||o?(0,Q.jsx)(Wh.Provider,{value:n,children:(0,Q.jsx)(pa,{ref:t,...r})}):null}),qh=20;function Jh(e,t,n,r){let[i,a]=l.useState(!1);U(()=>{if(!e||!t||n==null){a(!1);return}let r=qe(n).documentElement.clientWidth,i=n.offsetWidth;a(r>0&&i>0&&i>=r-qh)},[e,t,n]),gt(e&&(!t||i),r)}var Yh=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=aa,style:g,..._}=e,v=pm(),y=mm(),b=Gh(),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=yh(),M=Bl({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});Jh(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=Wl(e,N,{styles:M.positionerStyles,transitionStatus:A,props:_,refs:[t,P],hidden:!C,inert:!S});return(0,Q.jsxs)(hh.Provider,{value:M,children:[C&&x&&(0,Q.jsx)(Gc,{inert:Wc(!S),cutout:O??D??E}),F]})}),Xh={...Jt,...Ft},Zh=l.forwardRef(function(e,t){let{render:n,className:r,style:i,initialFocus:a,finalFocus:o,...s}=e,c=pm(),u=gh(),d=mm(),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=yh(),S=s.id??(_?Zm(b):void 0);U(()=>(c.set(`popupId`,c.context.popupRef.current?.id||S),()=>{c.set(`popupId`,void 0)}),[c,S]),_s({open:p,ref:c.context.popupRef,onComplete(){p&&c.context.onOpenChangeComplete(!0)}});let C=Zi(`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=wt(e.nativeEvent);m!==`touch`&&(X(c.state.listElement,t)||t===e.currentTarget)&&c.context.inputRef.current?.focus()}},Ul(g),s],stateAttributesMapping:Xh}),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)(Ma,{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)(_h,{ref:c.context.endDismissRef})]})})});function Qh(e={}){let{guess:t,label:n,metadata:r,textRef:i,index:a}=e,{register:o,unregister:s,subscribeMapChange:c,nextIndexRef:u}=Mh(),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 $h=l.createContext(void 0);function eg(){let e=l.useContext($h);if(!e)throw Error(Oi(19));return e}var tg=l.createContext(!1);function ng(){return l.useContext(tg)}function rg(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=Qh({guess:!0,index:u,textRef:m}),g=pm(),_=ng(),v=_m(),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=Em(T,c,g.context.valuesRef.current,e,S,t):bm(c,e,S)&&(t=T),g.set(`selectedIndex`,t)},[E,v,g,T,c,S]);let{getButtonProps:P,buttonRef:F}=jc({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?(ca.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=Zi(`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)($h.Provider,{value:ee,children:z})}function ig(e){let{componentProps:t,forwardedRef:n}=e,r=pm().useState(`isItemEqualToValue`),{flatFilteredValues:i}=hm(),a=Cm(i,t.value??null,r);return(0,Q.jsx)(rg,{componentProps:t,forwardedRef:n,virtualized:!0,indexFromFilter:a})}var ag=l.memo(l.forwardRef(function(e,t){let n=pm().useState(`virtualized`);return n&&e.index==null?(0,Q.jsx)(ig,{componentProps:e,forwardedRef:t}):(0,Q.jsx)(rg,{componentProps:e,forwardedRef:t,virtualized:n,indexFromFilter:void 0})})),og=l.forwardRef(function(e,t){let{selected:n}=eg();return e.keepMounted||n?(0,Q.jsx)(sg,{...e,ref:t}):null}),sg=l.memo(l.forwardRef((e,t)=>{let{render:n,className:r,style:i,keepMounted:a,...o}=e,{selected:s}=eg(),c=l.useRef(null),{transitionStatus:u,setMounted:d}=ps(s),f=Zi(`span`,e,{ref:[t,c],state:{selected:s,transitionStatus:u},props:[{"aria-hidden":!0,children:`✔️`},o],stateAttributesMapping:Ft});return _s({batch:!0,enabled:!s,open:s,ref:c,onComplete(){s||d(!1)}}),f})),cg=l.forwardRef(function(e,t){let{render:n,className:r,style:i,children:a,...o}=e,{filteredItems:s}=hm(),c=pm(),l=Uh(),u=s.length===0?a:null;return Zi(`div`,e,{ref:[t,c.context.emptyRef,l],props:[{children:u,role:`status`,"aria-live":`polite`,"aria-atomic":!0},o]})});function lg({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)(ch,{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)(ql,{label:`${e}: ${u.label}`,children:(0,Q.jsxs)(Dh,{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)(Kh,{children:(0,Q.jsx)(Yh,{className:`composer-select-positioner`,sideOffset:6,align:`start`,collisionPadding:12,children:(0,Q.jsxs)(Zh,{className:`composer-select-popup`,"aria-label":`${e} options`,children:[(0,Q.jsxs)(`div`,{className:`composer-select-search`,children:[(0,Q.jsx)(re,{size:14,"aria-hidden":`true`}),(0,Q.jsx)(Ch,{"aria-label":`Search ${e.toLowerCase()}`,placeholder:`Search ${e.toLowerCase()}…`,maxLength:a?120:void 0})]}),(0,Q.jsx)(cg,{className:`composer-select-empty`,children:`No matches`}),(0,Q.jsx)(Bh,{className:`composer-select-list`,children:e=>(0,Q.jsxs)(ag,{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)(og,{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})]})]})})})]})}function ug({project:e}){let t=(0,l.useRef)(null),[n,r]=(0,l.useState)(!1),[i,a]=(0,l.useState)(!1);return(0,l.useEffect)(()=>{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 dg({projects:e,projectId:t,onChange:n,onAddProject:r}){return(0,Q.jsx)(lg,{label:`Project`,value:t,onChange:n,icon:(0,Q.jsx)(A,{size:14}),action:r?{label:`Add project`,icon:(0,Q.jsx)(ne,{size:14}),onClick:r}:void 0,options:e.map(e=>({value:e.id,label:e.name,icon:(0,Q.jsx)(ug,{project:e},e.id)}))})}var fg=e=>e.id===`local`?(0,Q.jsx)(L,{size:14}):(0,Q.jsx)(V,{size:14});function pg({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)(lg,{label:`Machine`,value:e.id,onChange:o,icon:fg(e),options:t.map(e=>({icon:fg(e),value:e.id,label:`${e.name}${e.connected?``:` · Not connected`}`,shortLabel:e.name,disabled:!e.connected}))}),(0,Q.jsx)(dg,{projects:n,projectId:r,onChange:s,onAddProject:u},e.id),(0,Q.jsx)(lg,{label:`Harness`,value:i,onChange:c,icon:(0,Q.jsx)(ae,{size:14}),options:e.harnesses.map(e=>({value:e.id,label:e.name,shortLabel:e.name===`Claude Code`?`Claude`:e.name}))}),(0,Q.jsx)(lg,{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 mg=l.createContext(void 0),hg=e=>{let t=l.useContext(mg);if(e)return e;if(!t)throw Error(`No QueryClient set, use QueryClientProvider to set one`);return t},gg=({client:e,children:t})=>(l.useEffect(()=>(e.mount(),()=>{e.unmount()}),[e]),(0,Q.jsx)(mg.Provider,{value:e,children:t})),_g={setTimeout:(e,t)=>setTimeout(e,t),clearTimeout:e=>clearTimeout(e),setInterval:(e,t)=>setInterval(e,t),clearInterval:e=>clearInterval(e)},vg=new class{#e=_g;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 yg(e){setTimeout(e,0)}var bg=typeof window>`u`||`Deno`in globalThis;function xg(){}function Sg(e,t){return typeof e==`function`?e(t):e}function Cg(e){return typeof e==`number`&&e>=0&&e!==1/0}function wg(e,t){return Math.max(e+(t||0)-Date.now(),0)}function Tg(e,t){return typeof e==`function`?e(t):e}function Eg(e,t){let{type:n=`all`,exact:r,fetchStatus:i,predicate:a,queryKey:o,stale:s}=e;if(o){if(r){if(t.queryHash!==Og(o,t.options))return!1}else if(!Ag(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 Dg(e,t){let{exact:n,status:r,predicate:i,mutationKey:a}=e;if(a){if(!t.options.mutationKey)return!1;if(n){if(kg(t.options.mutationKey)!==kg(a))return!1}else if(!Ag(t.options.mutationKey,a))return!1}return!(r&&t.state.status!==r||i&&!i(t))}function Og(e,t){return(t?.queryKeyHashFn||kg)(e)}function kg(e){return JSON.stringify(e,(e,t)=>Fg(t)?Object.keys(t).sort().reduce((e,n)=>(e[n]=t[n],e),{}):t)}function Ag(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(!Ag(e[n],t[n]))return!1;return!0}let n=Object.keys(t);for(let r of n)if(!Ag(e[r],t[r]))return!1;return!0}return!1}var jg=Object.prototype.hasOwnProperty;function Mg(e,t,n=0){if(e===t)return e;if(n>500)return t;let r=Pg(e)&&Pg(t);if(!r&&!(Fg(e)&&Fg(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:jg.call(e,o))&&c++;continue}if(u===null||d===null||typeof u!=`object`||typeof d!=`object`){s[o]=d;continue}let f=Mg(u,d,n+1);s[o]=f,f===u&&c++}return i===o&&c===i?e:s}function Ng(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 Pg(e){return Array.isArray(e)&&e.length===Object.keys(e).length}function Fg(e){if(!Ig(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!(!Ig(r)||!r.hasOwnProperty(`isPrototypeOf`)||t!==Object.prototype)}function Ig(e){return Object.prototype.toString.call(e)===`[object Object]`}function Lg(e){return new Promise(t=>{vg.setTimeout(t,e)})}function Rg(e,t,n){return typeof n.structuralSharing==`function`?n.structuralSharing(e,t):n.structuralSharing===!1?t:Mg(e,t)}function zg(e,t,n=0){let r=[...e,t];return n&&r.length>n?r.slice(1):r}function Bg(e,t,n=0){let r=[t,...e];return n&&r.length>n?r.slice(0,-1):r}var Vg=Symbol();function Hg(e,t){return!e.queryFn&&t?.initialPromise?()=>t.initialPromise:!e.queryFn||e.queryFn===Vg?()=>Promise.reject(Error(`Missing queryFn: '${e.queryHash}'`)):e.queryFn}function Ug(e,t){return typeof e==`function`?e(...t):!!e}function Wg(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 Gg=()=>bg,Kg=()=>Gg(),qg=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(){}},Jg=new class extends qg{#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`}},Yg=yg;function Xg(){let e=[],t=0,n=e=>{e()},r=e=>{e()},i=Yg,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 Zg=Xg(),Qg=new class extends qg{#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 $g(e){return Math.min(1e3*2**e,3e4)}function e_(e){return(e??`online`)!==`online`||Qg.isOnline()}var t_=class extends Error{constructor(e){super(`CancelledError`),this.revert=e?.revert,this.silent=e?.silent}};function n_(e){let t=!1,n=0,r,i=`pending`,a,o,s=new Promise((e,t)=>{a=e,o=t});s.catch(xg);let c=()=>i!==`pending`,l=t=>{if(!c()){let n=new t_(t);h(n),e.onCancel?.(n)}},u=()=>{t=!0},d=()=>{t=!1},f=()=>Jg.isFocused()&&(e.networkMode===`always`||Qg.isOnline())&&e.canRun(),p=()=>e_(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??(Kg()?0:3),a=e.retryDelay??$g,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),Lg(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 r_=class{#e;destroy(){this.clearGcTimeout()}scheduleGc(){this.clearGcTimeout(),Cg(this.gcTime)&&(this.#e=vg.setTimeout(()=>{this.optionalRemove()},this.gcTime))}updateGcTime(e){this.gcTime=Math.max(this.gcTime||0,e??(Kg()?1/0:3e5))}clearGcTimeout(){this.#e!==void 0&&(vg.clearTimeout(this.#e),this.#e=void 0)}};function i_(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=>{Wg(e,()=>t.signal,()=>n=!0)},u=Hg(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?Bg:zg;return{pages:c(e.pages,o,s),pageParams:c(e.pageParams,r,s)}};if(i&&a.length){let e=i===`backward`,t=e?o_:a_,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:a_(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 a_(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 o_(e,{pages:t,pageParams:n}){return t.length>0?e.getPreviousPageParam?.(t[0],t,n[0],n):void 0}var s_=class extends r_{#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=u_(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=u_(this.options);e.data!==void 0&&(this.setState(l_(e.data,e.dataUpdatedAt)),this.#t=e)}}optionalRemove(){!this.observers.length&&this.state.fetchStatus===`idle`&&this.#r.remove(this)}setData(e,t){let n=Rg(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(xg).catch(xg):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=>Tg(e.options.enabled,this)!==!1)}isDisabled(){return this.getObserversCount()>0?!this.isActive():this.options.queryFn===Vg||!this.isFetched()}isFetched(){return this.state.dataUpdateCount+this.state.errorUpdateCount>0}isStatic(){return this.getObserversCount()>0&&this.observers.some(e=>Tg(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:!wg(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=Hg(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`?i_(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=n_({initialPromise:t?.initialPromise,fn:a.fetchFn,onCancel:e=>{e instanceof t_&&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 t_){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,...c_(t.data,this.options),fetchMeta:e.meta??null};case`success`:let n={...t,...l_(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),Zg.batch(()=>{this.observers.slice().forEach(e=>{e.onQueryUpdate()}),this.#r.notify({query:this,type:`updated`,action:e})})}};function c_(e,t){return{fetchFailureCount:0,fetchFailureReason:null,fetchStatus:e_(t.networkMode)?`fetching`:`paused`,...e===void 0&&{error:null,status:`pending`}}}function l_(e,t){return{data:e,dataUpdatedAt:t??Date.now(),error:null,isInvalidated:!1,status:`success`}}function u_(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 d_=class extends qg{#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),p_(this.#t,this.options)?this.#m():this.updateResult(),this.#y())}onUnsubscribe(){this.hasListeners()||this.destroy()}shouldFetchOnReconnect(){return m_(this.#t,this.options,this.options.refetchOnReconnect)}shouldFetchOnWindowFocus(){return m_(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 Tg(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&&!Ng(this.options,t)&&this.#e.getQueryCache().notify({type:`observerOptionsUpdated`,query:this.#t,observer:this});let r=this.hasListeners();r&&h_(this.#t,n,this.options,t)&&this.#m(),this.updateResult(),r&&(this.#t!==n||Tg(this.options.enabled,this.#t)!==Tg(t.enabled,this.#t)||Tg(this.options.staleTime,this.#t)!==Tg(t.staleTime,this.#t))&&this.#g();let i=this.#_();r&&(this.#t!==n||Tg(this.options.enabled,this.#t)!==Tg(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 Ng(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(xg)),t}#h(e){return!Kg()&&Tg(this.options.enabled,this.#t)!==!1&&Cg(e)}#g(){this.#b();let e=Tg(this.options.staleTime,this.#t);if(this.#r.isStale||!this.#h(e))return;let t=wg(this.#r.dataUpdatedAt,e)+1;this.#u=vg.setTimeout(()=>{this.#r.isStale||this.updateResult()},t)}#_(){return Tg(this.options.refetchInterval,this.#t)??!1}#v(e){this.#x(),this.#f=e,this.#f!==0&&this.#h(this.#f)&&(this.#d=vg.setInterval(()=>{(this.options.refetchIntervalInBackground||Jg.isFocused())&&this.#m()},this.#f))}#y(){this.#g(),this.#v(this.#_())}#b(){this.#u!==void 0&&(vg.clearTimeout(this.#u),this.#u=void 0)}#x(){this.#d!==void 0&&(vg.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&&p_(e,t),o=i&&h_(e,n,t,r);(a||o)&&(l={...l,...c_(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=Rg(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=Rg(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:g_(e,t),refetch:this.refetch,isEnabled:Tg(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),Ng(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)})})();Zg.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 f_(e,t){return Tg(t.enabled,e)!==!1&&e.state.data===void 0&&(e.state.status!==`error`||Tg(t.retryOnMount,e)!==!1)}function p_(e,t){return f_(e,t)||e.state.data!==void 0&&m_(e,t,t.refetchOnMount)}function m_(e,t,n){if(Tg(t.enabled,e)!==!1&&Tg(t.staleTime,e)!==`static`){let r=Tg(n,e);return r===`always`||r!==!1&&g_(e,t)}return!1}function h_(e,t,n,r){return(e!==t||Tg(r.enabled,e)===!1)&&(!n.suspense||e.state.status!==`error`)&&g_(e,n)}function g_(e,t){return Tg(t.enabled,e)!==!1&&e.isStaleByTime(Tg(t.staleTime,e))}var __=class extends r_{#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||v_(),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=n_({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),Zg.batch(()=>{this.#t.forEach(t=>{t.onMutationUpdate(e)}),this.#n.notify({mutation:this,type:`updated`,action:e})})}};function v_(){return{context:void 0,data:void 0,error:null,failureCount:0,failureReason:null,isPaused:!1,status:`idle`,variables:void 0,submittedAt:0}}var y_=class extends qg{#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 __({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=b_(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=b_(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=b_(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=b_(e);return typeof t==`string`?(this.#t.get(t)?.find(t=>t!==e&&t.state.isPaused))?.continue()??Promise.resolve():Promise.resolve()}clear(){Zg.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=>Dg(t,e))}findAll(e={}){return this.getAll().filter(t=>Dg(e,t))}notify(e){Zg.batch(()=>{this.listeners.forEach(t=>{t(e)})})}resumePausedMutations(){let e=this.getAll().filter(e=>e.state.isPaused);return Zg.batch(()=>Promise.all(e.map(e=>e.continue().catch(xg))))}};function b_(e){return e.options.scope?.id}var x_=class extends qg{#e;constructor(e={}){super(),this.config=e,this.#e=new Map}build(e,t,n){let r=t.queryKey,i=t.queryHash??Og(r,t),a=this.get(i);return a||(a=new s_({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(){Zg.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=>Eg(t,e))}findAll(e={}){let t=this.getAll();return Object.keys(e).length>0?t.filter(t=>Eg(e,t)):t}notify(e){Zg.batch(()=>{this.listeners.forEach(t=>{t(e)})})}onFocus(){Zg.batch(()=>{this.getAll().forEach(e=>{e.onFocus()})})}onOnline(){Zg.batch(()=>{this.getAll().forEach(e=>{e.onOnline()})})}},S_=class{#e;#t;#n;#r;#i;#a;#o;#s;constructor(e={}){this.#e=e.queryCache||new x_,this.#t=e.mutationCache||new y_,this.#n=e.defaultOptions||{},this.#r=new Map,this.#i=new Map,this.#a=0}mount(){this.#a++,this.#a===1&&(this.#o=Jg.subscribe(async e=>{e&&(await this.resumePausedMutations(),this.#e.onFocus())}),this.#s=Qg.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(Tg(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=Sg(t,i);if(a!==void 0)return this.#e.build(this,r).setData(a,{...n,manual:!0})}setQueriesData(e,t,n){return Zg.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;Zg.batch(()=>{t.findAll(e).forEach(e=>{t.remove(e)})})}resetQueries(e,t){let n=this.#e;return Zg.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=Zg.batch(()=>this.#e.findAll(e).map(e=>e.cancel(n)));return Promise.all(r).then(xg).catch(xg)}invalidateQueries(e,t={}){return Zg.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=Zg.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(xg)),e.state.fetchStatus===`paused`?Promise.resolve():t}));return Promise.all(r).then(xg)}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(Tg(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(Tg(t.staleTime,n))?n.fetch(t):Promise.resolve(n.state.data)}prefetchQuery(e){return this.fetchQuery(e).then(xg).catch(xg)}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(xg).catch(xg)}ensureInfiniteQueryData(e){return e._type=`infinite`,this.ensureQueryData(e)}resumePausedMutations(){return Qg.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(kg(e),{queryKey:e,defaultOptions:t})}getQueryDefaults(e){let t=[...this.#r.values()],n={};return t.forEach(t=>{Ag(e,t.queryKey)&&Object.assign(n,t.defaultOptions)}),n}setMutationDefaults(e,t){this.#i.set(kg(e),{mutationKey:e,defaultOptions:t})}getMutationDefaults(e){let t=[...this.#i.values()],n={};return t.forEach(t=>{Ag(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||=Og(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===Vg&&(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()}},C_=l.createContext(!1),w_=()=>l.useContext(C_);C_.Provider;function T_(){let e=!1;return{clearReset:()=>{e=!1},reset:()=>{e=!0},isReset:()=>e}}var E_=l.createContext(T_()),D_=()=>l.useContext(E_),O_=(e,t,n)=>{let r=n?.state.error&&typeof e.throwOnError==`function`?Ug(e.throwOnError,[n.state.error,n]):e.throwOnError;(e.suspense||r)&&(t.isReset()||(e.retryOnMount=!1))},k_=e=>{l.useEffect(()=>{e.clearReset()},[e])},A_=({result:e,errorResetBoundary:t,throwOnError:n,query:r,suspense:i})=>e.isError&&!t.isReset()&&!e.isFetching&&r&&(i&&e.data===void 0||Ug(n,[e.error,r])),j_=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))}},M_=(e,t)=>e?.suspense&&t.isPending,N_=(e,t,n)=>t.fetchOptimistic(e).catch(()=>{n.clearReset()});function P_(e,t,n){let r=w_(),i=D_(),a=hg(n),o=a.defaultQueryOptions(e),s=a.getQueryCache().get(o.queryHash),c=e.subscribed!==!1;o._optimisticResults=r?`isRestoring`:c?`optimistic`:void 0,j_(o),O_(o,i,s),k_(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(Zg.batchCalls(e)):xg;return u.updateResult(),t},[u,f]),()=>u.getCurrentResult(),()=>u.getCurrentResult()),l.useEffect(()=>{u.setOptions(o)},[o,u]),M_(o,d))throw N_(o,u,i);if(A_({result:d,errorResetBoundary:i,throwOnError:o.throwOnError,query:s,suspense:o.suspense}))throw d.error;return o.notifyOnChangeProps?d:u.trackResult(d)}function F_(e,t){return P_(e,d_,t)}function I_(e,t,n=1,r=``,i=``){return F_({queryKey:[`machine-catalog`,e,r,n,i],enabled:!!e&&t,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.`);return await n.json()}})}var L_=e=>e.startsWith(`/`)||e.startsWith(`~`),R_=e=>Array.isArray(e)?e.filter(e=>typeof e==`string`):[];function z_(e,t){let[n,r]=(0,l.useState)([]);return(0,l.useEffect)(()=>{if(!L_(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(R_(e))).catch(()=>{}),()=>n.abort()},[e,t]),n}var B_=e=>e.startsWith(`/`)||e.startsWith(`~/`);function V_({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=z_(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:tm()});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||!B_(n)||!i.trim(),children:o?`Creating…`:`Create workspace`}),c&&(0,Q.jsx)(`p`,{className:`form-error`,role:`alert`,children:c})]})}var H_={main:`Main checkout`,worktree:`New worktree`,remember:`Remember by project`},U_=`webr-new-session-behavior`,W_=`webr-new-worktree`,G_=(e,t)=>`webr-last-worktree:${e}:${t}`,K_=e=>e===`main`||e===`worktree`||e===`remember`,q_=()=>{let e=localStorage.getItem(W_);return e===null?`remember`:e===`false`?`main`:`worktree`};function J_(){let e=localStorage.getItem(U_);return K_(e)?e:q_()}function Y_(e){localStorage.setItem(U_,e)}function X_(e,t,n){localStorage.setItem(G_(e,t),String(n))}var Z_=(e,t)=>localStorage.getItem(G_(e,t))!==`false`;function Q_(e,t){let n=J_();return n===`remember`?Z_(e,t):n===`worktree`}var $_=`webr-new-thread-draft`,ev=e=>!!e&&typeof e==`object`&&[`id`,`name`,`preview`,`path`].every(t=>typeof e[t]==`string`);function tv(){try{let e=JSON.parse(localStorage.getItem($_)??`{}`);return{prompt:typeof e.prompt==`string`?e.prompt:``,images:Array.isArray(e.images)?e.images.filter(ev):[]}}catch{return{prompt:``,images:[]}}}function nv(e){try{!e.prompt&&!e.images.length?localStorage.removeItem($_):localStorage.setItem($_,JSON.stringify(e))}catch{}}var rv=()=>nv({prompt:``,images:[]}),iv=(e,t)=>`webr-last-harness:${e}:${t}`;function av({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=im({machineId:s}),O=t.find(e=>e.id===s)??{id:``,name:`No target`,connected:!1,session:``,projectPaths:{},harnesses:[]},k=I_(s,O.connected,O.configVersion,O.session,i),A={...O,harnesses:O.connected?k.data?.harnesses??[]:[]},M=e.filter(e=>Object.hasOwn(A.projectPaths,e.id)).map(e=>({...e,path:A.projectPaths[e.id],iconUrl:s===`local`?e.iconUrl:void 0})),N=A.harnesses.find(e=>e.id===u),P=!!(g.trim()&&!D.uploading&&f.trim()&&A.connected&&M.some(e=>e.id===i)&&N?.launchEnabled)&&!y,F=(0,l.useRef)(!1);(0,l.useEffect)(()=>{let e=tv();v(e.prompt),D.setAttachments(e.images),F.current=!0},[]),(0,l.useEffect)(()=>{F.current&&nv({prompt:g,images:D.attachments})},[g,D.attachments]),(0,l.useEffect)(()=>{h(Q_(s,i))},[s,i]),(0,l.useEffect)(()=>{if(!i||!k.data)return;let e=k.data.harnesses,t=localStorage.getItem(iv(s,i));d(e.find(e=>e.id===t)?.id??e.find(e=>e.launchEnabled)?.id??e[0]?.id??``),p(`Default`)},[s,i,k.data]),(0,l.useEffect)(()=>{let e=T.current,t=e&&M.find(t=>!e.has(t.id));t&&(T.current=null,L(t.id))},[M]),(0,l.useEffect)(()=>{!s&&t.length&&c(t.find(e=>e.id===`local`)?.id??t[0].id),!i&&M.length&&o(M[0].id)},[t,s,M,i]);let I=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(``))},L=e=>{o(e),d(``),p(`Default`),S(``)},R=e=>{d(e),p(`Default`),i&&localStorage.setItem(iv(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?`}),A.connected&&A.writable&&(!M.length||C)?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`p`,{children:M.length?`Add a project to this Herdr session.`:`This Herdr session has no projects yet.`}),(0,Q.jsx)(V_,{machineId:A.id,onCreated:()=>{T.current=new Set(M.map(e=>e.id)),w(!1)}}),!!M.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(),!P)return;b(!0),S(``);let t=JSON.stringify({prompt:rm(g,D.attachments),projectId:i,machineId:s,agent:u,model:f.trim(),worktree:m});E.current?.payload!==t&&(E.current={payload:t,key:tm()});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`);X_(s,i,m),rv(),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 images`,children:[D.attachments.map(e=>(0,Q.jsxs)(`li`,{children:[(0,Q.jsx)(`img`,{src:e.preview,alt:e.name}),(0,Q.jsx)(ql,{label:`Remove image`,children:(0,Q.jsx)(`button`,{type:`button`,"aria-label":`Remove ${e.name}`,onClick:()=>D.remove(e.id),children:(0,Q.jsx)(ue,{size:12,strokeWidth:2.4})})})]},e.id)),Array.from({length:D.uploading},(e,t)=>(0,Q.jsx)(`li`,{className:`is-uploading`,"aria-label":`Uploading image`},`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)(pg,{machine:A,machines:t,projects:M,projectId:i,harness:u,model:f,onMachineChange:I,onProjectChange:L,onHarnessChange:R,onModelChange:p,onAddProject:A.connected&&A.writable?()=>w(!0):void 0}),(0,Q.jsx)(ql,{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)(j,{size:15,"aria-hidden":`true`})]})}),(0,Q.jsx)(`div`,{className:`composer-actions`,children:(0,Q.jsx)(ql,{label:`Create thread`,children:(0,Q.jsx)(`button`,{className:`composer-send`,type:`submit`,disabled:!P,"aria-label":`Create thread`,children:y?`…`:(0,Q.jsx)(_,{size:18,strokeWidth:2.2})})})})]})]}),(N?.reason||!t.length||A.error||k.isError)&&(0,Q.jsx)(`p`,{className:`composer-preview-note`,children:N?.reason??(t.length?A.error?`Machine is not connected: ${A.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 ov=Qo(function(e){return wc(`dialog`,e)}),sv=52,cv=`?`;function lv(e){let t=e.slice(e.indexOf(`;`)+1);if(e.includes(`;`)&&t&&t!==cv)try{return new TextDecoder(`utf-8`,{fatal:!0}).decode(Uint8Array.from(atob(t),e=>e.charCodeAt(0)))}catch{return}}function uv(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 dv(e){try{return await navigator.clipboard.writeText(e),!0}catch{return uv(e)}}var fv=e=>(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement)&&e.selectionStart!==e.selectionEnd||!!document.getSelection()?.toString();function pv(e,t,n,r){let i=()=>{t.hasSelection()&&dv(t.getSelection()).then(r)},a=e=>{e.defaultPrevented||!t.hasSelection()||fv(e.target)||(e.clipboardData?.setData(`text/plain`,t.getSelection()),e.preventDefault(),r(!0))},o=t.parser.registerOscHandler(sv,e=>{let t=lv(e);return t!==void 0&&n()&&dv(t).then(r),!0});return e.addEventListener(`mouseup`,i),window.addEventListener(`copy`,a),()=>{o.dispose(),e.removeEventListener(`mouseup`,i),window.removeEventListener(`copy`,a)}}var mv=(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))(mv||{}),hv=[0,1],gv=[1,0],_v=[2,3],vv=[3,2],yv={L:hv,M:gv,Q:_v,H:vv},bv=/^\d*$/,xv=/^[A-Z0-9 $%*+./:-]*$/,Sv=`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:`,Cv=1,wv=40,Tv=3,Ev=3,Dv=40,Ov=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]],Av=[[-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<Cv||e>wv)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,mv.Timing),this.setFunctionModule(e,6,e%2==0,mv.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,Nv(r,e));this.setFunctionModule(8,7,Nv(r,6)),this.setFunctionModule(8,8,Nv(r,7)),this.setFunctionModule(7,8,Nv(r,8));for(let e=9;e<15;e++)this.setFunctionModule(14-e,8,Nv(r,e));for(let e=0;e<8;e++)this.setFunctionModule(this.size-1-e,8,Nv(r,e));for(let e=8;e<15;e++)this.setFunctionModule(8,this.size-15+e,Nv(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=Nv(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,mv.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,mv.Alignment)}setFunctionModule(e,t,n,r=mv.Function){this.modules[t][e]=n,this.types[t][e]=r}addEccAndInterleave(e){let t=this.version,n=this.ecc;if(e.length!==Jv(t,n))throw RangeError(`Invalid argument`);let r=Av[n[0]][t],i=kv[n[0]][t],a=Math.floor(qv(t)/8),o=r-a%r,s=Math.floor(a/r),c=[],l=Yv(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=Xv(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(qv(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]=Nv(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+=Tv:r>5&&e++):(this.finderPenaltyAddHistory(r,i),n||(e+=this.finderPenaltyCountPatterns(i)*Dv),n=this.modules[t][a],r=1);e+=this.finderPenaltyTerminateAndCount(n,r,i)*Dv}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+=Tv:r>5&&e++):(this.finderPenaltyAddHistory(r,i),n||(e+=this.finderPenaltyCountPatterns(i)*Dv),n=this.modules[a][t],r=1);e+=this.finderPenaltyTerminateAndCount(n,r,i)*Dv}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+=Ev)}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*Ov,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 Mv(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 Nv(e,t){return!!(e>>>t&1)}var Pv=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()}},Fv=[1,10,12,14],Iv=[2,9,11,13],Lv=[4,8,16,16];function Rv(e,t){return e[Math.floor((t+7)/17)+1]}function zv(e){let t=[];for(let n of e)Mv(n,8,t);return new Pv(Lv,e.length,t)}function Bv(e){if(!Uv(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);Mv(Number.parseInt(e.substring(n,n+r),10),r*3+1,t),n+=r}return new Pv(Fv,e.length,t)}function Vv(e){if(!Wv(e))throw RangeError(`String contains unencodable characters in alphanumeric mode`);let t=[],n=0;for(;n+2<=e.length;n+=2){let r=Sv.indexOf(e.charAt(n))*45;r+=Sv.indexOf(e.charAt(n+1)),Mv(r,11,t)}return n<e.length&&Mv(Sv.indexOf(e.charAt(n)),6,t),new Pv(Iv,e.length,t)}function Hv(e){return e===``?[]:Uv(e)?[Bv(e)]:Wv(e)?[Vv(e)]:[zv(Kv(e))]}function Uv(e){return bv.test(e)}function Wv(e){return xv.test(e)}function Gv(e,t){let n=0;for(let r of e){let e=Rv(r.mode,t);if(r.numChars>=1<<e)return 1/0;n+=4+e+r.bitData.length}return n}function Kv(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 qv(e){if(e<Cv||e>wv)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 Jv(e,t){return Math.floor(qv(e)/8)-kv[t[0]][e]*Av[t[0]][e]}function Yv(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]=Zv(t[e],n),e+1<t.length&&(t[e]^=t[e+1]);n=Zv(n,2)}return t}function Xv(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]^=Zv(t,e))}return n}function Zv(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 Qv(e,t,n=1,r=40,i=-1,a=!0){if(!(Cv<=n&&n<=r&&r<=wv)||i<-1||i>7)throw RangeError(`Invalid value`);let o,s;for(o=n;;o++){let n=Jv(o,t)*8,i=Gv(e,o);if(i<=n){s=i;break}if(o>=r)throw RangeError(`Data too long`)}for(let e of[gv,_v,vv])a&&s<=Jv(o,e)*8&&(t=e);let c=[];for(let t of e){Mv(t.mode[0],4,c),Mv(t.numChars,Rv(t.mode,o),c);for(let e of t.getData())c.push(e)}let l=Jv(o,t)*8;Mv(0,Math.min(4,l-c.length),c),Mv(0,(8-c.length%8)%8,c);for(let e=236;c.length<l;e^=253)Mv(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 $v(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`?Hv(e):Array.isArray(e)?[zv(e)]:void 0;if(!c)throw Error(`uqr only supports encoding string and binary data, but got: ${typeof e}`);let l=Qv(c,yv[n],i,a,o,r),u=ey({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 ey(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=mv.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 ty=2;function ny({value:e,label:t}){let{data:n,size:r}=$v(e),i=n.flatMap((e,t)=>e.flatMap((e,n)=>e?[`M${n+ty} ${t+ty}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 ry(){let[e,t]=(0,l.useState)(Ip);return!Fp()||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 Lp().then(t),children:`Turn on`})]})}var iy=8;function ay({refreshKey:e}){let[t,n]=(0,l.useState)([]);return(0,l.useEffect)(()=>{Tp().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,iy).map(e=>(0,Q.jsxs)(`p`,{className:`activity-row`,children:[(0,Q.jsx)(`span`,{children:Rp(e)}),(0,Q.jsx)(`time`,{dateTime:new Date(e.at).toISOString(),children:Pp(e.at)})]},e.id))]}):null}function oy({invite:e,onClose:t}){let[n,r]=(0,l.useState)(0),[i,a]=(0,l.useState)(!1),o=e.urls[n],s=e=>dv(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)(ov,{open:!0,onOpenChange:e=>{e||t()},children:(0,Q.jsxs)(Kc,{children:[(0,Q.jsx)(Ec,{className:`dialog-backdrop`}),(0,Q.jsxs)(Uc,{className:`dialog pairing-invite`,children:[(0,Q.jsx)(qc,{className:`pairing-title`,children:`Connect a device`}),o?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(Ic,{className:`dialog-message`,children:`Scan with the device’s camera, or open Webr there and enter the code.`}),(0,Q.jsx)(ny,{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)(Ic,{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)(Pc,{className:`dialog-button is-primary`,children:`Done`})})]})]})})}var sy={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 cy(){let[e,t]=(0,l.useState)(`ready`);return(0,l.useEffect)(()=>{Ep().then(t,()=>void 0)},[]),e===`ready`?null:(0,Q.jsx)(`p`,{className:`tailscale-callout`,role:`note`,children:sy[e]})}function ly(){let[e,t]=(0,l.useState)([]),[n,r]=(0,l.useState)(),[i,a]=(0,l.useState)(``),o=(0,l.useCallback)(()=>wp().then(t,()=>void 0),[]);(0,l.useEffect)(()=>{o()},[o]);let s=()=>Cp().then(e=>{a(``),r(e)},e=>a(e.message)),c=async e=>{await rl(`Disconnect ${e.name}? It will need to be approved again.`,{confirmLabel:`Disconnect`,danger:!0})&&(await Dp(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)(cy,{}),(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)(ry,{}),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 `,Pp(e.lastSeenAt),` · Signs out `,zp(e.expiresAt),` if unused`]})]}),(0,Q.jsx)(`button`,{type:`button`,className:`dialog-button`,onClick:()=>void c(e),children:`Disconnect`})]},e.id)),(0,Q.jsx)(ay,{refreshKey:e}),n&&(0,Q.jsx)(oy,{invite:n,onClose:()=>r(void 0)})]})}function uy({onOpenSidebar:e}){let[t,n]=(0,l.useState)(`worktree`),[r,i]=(0,l.useState)(qf),[a,o]=(0,l.useState)(null),[s,c]=(0,l.useState)(``);(0,l.useEffect)(()=>{n(J_()),i(Jf())},[]);let u=(e,t)=>{if(e.preventDefault(),e.stopPropagation(),e.key===`Escape`){o(null),c(``);return}let n=Zf(e);if(!n)return;if(Qf(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)(ep,{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(H_).map(e=>(0,Q.jsx)(`button`,{type:`button`,"aria-pressed":t===e,className:t===e?`theme-option is-selected`:`theme-option`,onClick:()=>{n(e),Y_(e)},children:H_[e]},e))})]})]}),(0,Q.jsx)(ly,{}),(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(qf),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(Kf).map(e=>(0,Q.jsxs)(`div`,{className:`settings-row`,children:[(0,Q.jsx)(`span`,{children:Kf[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 ${Kf[e]} shortcut`,children:a===e?`Press keys…`:Yf(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 dy=l.createContext(void 0);function fy(e=!0){let t=l.useContext(dy);if(t===void 0&&!e)throw Error(Oi(25));return t}var py=l.createContext(void 0);function my(e){let t=l.useContext(py);if(t===void 0&&!e)throw Error(Oi(33));return t}var hy=l.createContext(void 0);function gy(e){let t=l.useContext(hy);if(t===void 0&&!e)throw Error(Oi(36));return t}function _y(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=fy(!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:gn})},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&&!Ve&&e.button===2)return}s.current&&a.context.allowMouseUpTriggerRef.current&&(!p||e.button===2)&&c.type===`regular-item`&&Ac(s.current,e,{detail:1})}}),[t,n,r,u,i,d,a,o,s,f,p,c])}var vy={type:`regular-item`};function yy(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}=jc({disabled:n,focusableWhenDisabled:!0,native:s,composite:!0}),m=_y({closeOnClick:t,highlighted:r,id:i,nodeId:u,store:a,typingRef:o,itemRef:d,itemMetadata:c}),h=l.useCallback(e=>Li(m,{onMouseEnter(){c.type===`submenu-trigger`&&c.setActive()}},e,f),[m,f,c]),g=In(d,p);return l.useMemo(()=>({getItemProps:h,itemRef:g}),[h,g])}var by=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=Qh({guess:!0,label:a}),f=my(!0),p=Fc(i),{store:m}=gy(),h=m.useState(`disabled`),g=s||h,_=m.useState(`isActive`,d.index),v=m.useState(`itemProps`),{getItemProps:y,itemRef:b}=yy({closeOnClick:c,disabled:g,highlighted:_,id:p,store:m,nativeButton:o,nodeId:f?.context.nodeId,itemMetadata:vy});return Zi(`div`,e,{state:{disabled:g,highlighted:_},props:[v,u,y],ref:[b,t,d.ref]})}),xy=l.createContext(void 0);function Sy(e){let t=l.useContext(xy);if(t===void 0&&!e)throw Error(Oi(69));return t}var Cy=l.forwardRef(function(e,t){let{render:n,className:r,style:i,finalFocus:a,...o}=e,{store:s}=gy(),{side:c,align:u}=my(),d=Sy(!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`;_s({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]),Zs(x,{enabled:w&&!T&&!D&&v.type!==`menubar`,closeDelay:C});let O=s.useStateSetter(`popupElement`),k=Zi(`div`,e,{state:{transitionStatus:p,side:c,align:u,open:f,nested:v.type===`menu`,instant:g},ref:[t,s.context.popupRef,O],stateAttributesMapping:Yt,props:[m,{onKeyDown(e){d&&zc.has(e.key)&&e.stopPropagation()}},Ul(p),o,{"data-rootownerid":b}]}),A=v.type===void 0||D;return(_||v.type===`menubar`&&y!==`outside-press`)&&(A=!0),(0,Q.jsx)(Ma,{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})}),wy=l.createContext(void 0);function Ty(){let e=l.useContext(wy);if(e===void 0)throw Error(Oi(32));return e}var Ey=l.forwardRef(function(e,t){let{keepMounted:n=!1,...r}=e,{store:i,parent:a}=gy();if(!(i.useState(`mounted`)||n))return null;let o=a.type===`menu`||a.type===`menubar`?`group`:void 0;return(0,Q.jsx)(wy.Provider,{value:n,children:(0,Q.jsx)(pa,{ref:t,...r,portalOwnerRole:o})})}),Dy=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=aa,style:_,...v}=e,{store:y}=gy(),b=Ty(),x=fy(!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=gs(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??oa):S.type===`menubar`&&(V??=S.context.orientation===`vertical`?`inline-end`:`bottom`,H??=`start`);let ie=S.type===`context-menu`,ae=Bl({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(Dn)))}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=nt();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(Dn))}):y.setOpen(!1,Z(Dn))}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;Jh(E&&(ce||D&&P!==`trigger-hover`),O===`touch`,j,k);let le=Wl(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)(py.Provider,{value:ae,children:[ue&&(0,Q.jsx)(Gc,{ref:S.type===`context-menu`||S.type===`nested-context-menu`?S.context.internalBackdropRef:null,inert:Wc(!E),cutout:de}),(0,Q.jsx)(xa,{id:F,children:(0,Q.jsx)(Nh,{elementsRef:y.context.itemDomElements,labelsRef:y.context.itemLabels,children:le})})]})}),Oy=l.createContext(null);function ky(e){let t=l.useContext(Oy);if(t===null&&!e)throw Error(Oi(5));return t}var Ay={...zs,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 ls{constructor(e,t,n=!1){let r=new Ms,i=Ny(r,t,n,e);super(i,My(r),Ay),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 My(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 Ny(e,t,n=!1,r){return{...Ns(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 ha,floatingNodeId:void 0,floatingParentNodeId:null,itemProps:Qe,keyboardEventRelay:void 0,closeDelay:0,adaptiveOrigin:void 0,...r}}var Py=l.createContext(void 0);function Fy(){return l.useContext(Py)}var Iy=Qo(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,_=fy(!0),v=gy(!0),y=ky(!0),b=Fy(),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=Ei(),C=Ei(),w=va(),T=x.type===`menu`?x.store:void 0,E=(n??a)&&T?.state.transitionStatus===`starting`,D=Ye(()=>E?T?.state.instantType:void 0).current,O=Ly({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=ba(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=nt(),re=l.useRef(!0),V=nt(),H=ee!=null,{openMethod:ie,triggerProps:ae}=Zc(j);O.useSyncedValues({disabled:o,highlightItemOnHover:g,modal:L.type===void 0?s:void 0,openMethod:ie,rootId:S}),Os(O);let{forceUnmount:oe,transitionStatus:se}=ks(j,O,()=>{O.set(`allowMouseEnter`,!1)},E),ce=gs(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=Ts(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=ws(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=fs({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 W=l.useCallback(()=>{O.setOpen(!1,Z(kn))},[O]);l.useImperativeHandle(d,()=>({unmount:oe,close:W}),[oe,W]);let G;L.type===`context-menu`&&(G=L.context),l.useImperativeHandle(G?.positionerRef,()=>N,[N]),l.useImperativeHandle(G?.actionsRef,()=>({setOpen:le}),[le]);let fe=za(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}),pe=El(),K=l.useCallback(e=>{O.select(`activeIndex`)!==e&&O.set(`activeIndex`,e)},[O]),q=sc(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:pe===`rtl`,disabledIndices:Ze,onNavigate:K,openOnArrowKeyDown:L.type!==`context-menu`,externalTree:H?k:void 0,focusItemOnHover:g}),me=l.useCallback(e=>{O.context.typingRef.current=e},[O]),he=cc(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:me}),ge=l.useMemo(()=>{let e=Li(he.reference,q.reference,fe.reference,{onMouseMove(){O.set(`allowMouseEnter`,!0)}},ae);return e[`aria-haspopup`]=`menu`,e[`aria-expanded`]=j,e},[O,he.reference,q.reference,fe.reference,ae,j]),_e=l.useMemo(()=>{let e=Li(q.trigger,fe.trigger,ae);return e[`aria-haspopup`]=`menu`,e[`aria-expanded`]=!1,e},[q.trigger,fe.trigger,ae]);Ye(()=>(O.update({inactiveTriggerProps:_e}),null)),As(O,{floatingRootContext:ue,activeTriggerProps:ge,inactiveTriggerProps:_e,popupProps:l.useMemo(()=>Li(vs,{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)}},he.floating,q.floating,fe.floating),[M,C,u,L.type,O,he.floating,q.floating,fe.floating]),itemProps:q.item??Qe});let ve=l.useMemo(()=>({store:O,parent:x}),[O,x]),ye=(0,Q.jsxs)(hy.Provider,{value:ve,children:[p&&(0,Q.jsx)(xs,{handle:p,store:O}),typeof t==`function`?t({payload:z}):t]});return L.type===void 0||L.type===`context-menu`?(0,Q.jsx)(Sa,{externalTree:k,children:ye}):ye});function Ly(e,t,n){return Ye(()=>new jy(e,t,n)).current}function Ry(e){let t=gy().store,n=l.useMemo(()=>({parentMenu:t}),[t]);return(0,Q.jsx)(Py.Provider,{value:n,children:(0,Q.jsx)(Iy,{...e})})}function zy(e={}){let{highlightItemOnHover:t,highlightedIndex:n,onHighlightedIndexChange:r}=Oc(),{ref:i,index:a}=Qh(e),o=n===a,s=l.useRef(null),c=In(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 By(e){let{render:t,className:n,style:r,state:i=Qe,props:a=Ze,refs:o=Ze,metadata:s,stateAttributesMapping:c,tag:l=`div`,...u}=e,{compositeProps:d,compositeRef:f}=zy({metadata:s});return Zi(l,e,{state:i,ref:[f,...o],props:[d,...a,u],stateAttributesMapping:c})}function Vy(e){if(q(e)&&e.hasAttribute(`data-rootownerid`))return e.getAttribute(`data-rootownerid`);if(!Te(e))return Vy(Oe(e))}function Hy(e,t){let n=l.useRef(null);function r(t){ca.flushSync(()=>{e.setOpen(!1,Z(xn,t.nativeEvent,t.currentTarget))}),ni(n.current)?.focus()}function i(n){let r=e.select(`positionerElement`);if(r&&ri(n,r))e.context.beforeContentFocusGuardRef.current?.focus();else{ca.flushSync(()=>{e.setOpen(!1,Z(xn,n.nativeEvent,n.currentTarget))});let i=ti(e.context.triggerFocusTargetRef.current||t.current);for(;i!==null&&X(r,i);){let e=i;if(i=Qr(i),i===e)break}i?.focus()}}return{preFocusGuardRef:n,handlePreFocusGuardFocus:r,handleFocusTargetFocus:i}}function Uy(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,qe(e.currentTarget).addEventListener(`click`,()=>{i.current=!1},{once:!0}))},onClick:e=>{i.current&&(i.current=!1,e.preventBaseUIHandler())}}:Qe,[t,n,r])}var Wy=$o(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=gy(!0),g=Bs(f)??h?.store;if(!g)throw Error(Oi(85));let _=Fc(s),v=g.useState(`isTriggerActive`,_),y=g.useState(`floatingRootContext`),b=g.useState(`isOpenedByTrigger`,_),x=g.useState(`triggerPopupId`,_),S=l.useRef(null),C=Ky(),w=Oc(!0),T=ya(),E=l.useMemo(()=>T??new ha,[T]),{registerTrigger:D,isMountedByThisTrigger:O}=Ds(_,S,g,{payload:p,closeDelay:d,parent:C,floatingTreeRoot:E,floatingNodeId:ba(E),floatingParentNodeId:va(),keyboardEventRelay:w?.relayKeyboardEvent}),k=C.type===`menubar`,A=g.useState(`disabled`),j=a||A||k&&C.context.disabled,{getButtonProps:M,buttonRef:N}=jc({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=nt(),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||Vy(t)!==g.select(`rootId`))&&(Th(e,P.current)||E.events.emit(`close`,{domEvent:e,reason:En}))});l.useEffect(()=>{b&&g.select(`lastOpenChangeReason`)===`trigger-hover`&&qe(P.current).addEventListener(`mouseup`,I,{once:!0})},[b,I,g]);let L=k&&C.context.hasSubmenuOpen,R=$s(y,{enabled:(c??L)&&!j&&(!k||L&&!O),handleClose:gc({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=Gy(b,g.select(`lastOpenChangeReason`)),ee=Na(y,{enabled:!j,event:b&&k?`click`:`mousedown`,toggle:!0,ignoreMouse:!1,stickIfOpen:C.type===void 0&&z}),B=Gs(y,{enabled:!j&&L}),te=Uy({open:b,enabled:k,mouseDownAction:`open`}),ne=l.useMemo(()=>Li(B.reference,ee.reference),[B.reference,ee.reference]),re=g.useState(`triggerProps`,O),{preFocusGuardRef:V,handlePreFocusGuardFocus:H,handleFocusTargetFocus:ie}=Hy(g,S),ae={disabled:j,open:b},oe=[P,t,N,D,S],se=[ne,R??Qe,re,{"aria-haspopup":`menu`,"aria-controls":x,id:_,onMouseDown:e=>{g.select(`open`)||(F.start(200,()=>{g.context.allowMouseUpTriggerRef.current=!0}),qe(e.currentTarget).addEventListener(`mouseup`,I,{once:!0}))}},k?{role:`menuitem`}:{},te,m,M],ce=Zi(`button`,e,{enabled:!k,stateAttributesMapping:qt,state:ae,ref:oe,props:se});return k?(0,Q.jsx)(By,{tag:`button`,render:n,className:r,style:i,state:ae,refs:oe,props:se,stateAttributesMapping:qt}):b?(0,Q.jsxs)(l.Fragment,{children:[(0,Q.jsx)(Qn,{ref:V,onFocus:H},`${_}-pre-focus-guard`),(0,Q.jsx)(l.Fragment,{children:ce},_),(0,Q.jsx)(Qn,{ref:g.context.triggerFocusTargetRef,onFocus:ie},`${_}-post-focus-guard`)]}):(0,Q.jsx)(l.Fragment,{children:ce},_)});function Gy(e,t){let n=nt(),[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 Ky(){let e=ky(!0);return l.useMemo(()=>e?{type:`menubar`,context:e}:{type:void 0},[e])}var qy={"aria-expanded":void 0},Jy=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=Fy();if(!m?.parentMenu)throw Error(Oi(37));let h=Qh({guess:!0,label:a}),g=my(),{store:_}=gy(),v=Fc(o),y=_.useState(`open`),b=_.useState(`floatingRootContext`),x=_.useState(`floatingTreeRoot`),S=_.useState(`triggerPopupId`,v),C=Cs(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}=yy({closeOnClick:!1,disabled:A,highlighted:M,id:v,store:_,typingRef:D.context.typingRef,nativeButton:s,itemMetadata:N,nodeId:g?.context.nodeId}),I=$s(b,{enabled:_.useState(`hoverEnabled`)&&c&&!A,handleClose:gc({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=Na(b,{enabled:!A,event:`mousedown`,toggle:!c,ignoreMouse:c,stickIfOpen:!1}).reference??Qe,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 Zi(`div`,e,{state:z,stateAttributesMapping:Kt,props:[L,I,R,j,y&&B&&Ge?qy: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 Yy(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=Ei(),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)(dy.Provider,{value:d,children:(0,Q.jsx)(hy.Provider,{value:void 0,children:(0,Q.jsx)(Iy,{...e})})})}var Xy=500,Zy=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}=fy(!1),{store:h}=gy(!1),g=h.useState(`open`),_=h.useState(`disabled`),v=l.useRef(null),y=l.useRef(null),b=nt(),x=nt(),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(fn,n)),x.start(Xy,()=>{S.current=!0})}function T(e){if(_)return;f.current=!0,_t(e),w(e.clientX,e.clientY,e.nativeEvent);let t=qe(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=wt(e);X(d.current,t)||m&&t&&Vy(t)===m||s.current?.setOpen(!1,Z(En,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(Xy,()=>{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=wt(e);(X(v.current,t)||X(c.current,t)||X(u.current,t))&&e.preventDefault()}return J(qe(v.current),`contextmenu`,e)},[u,_,c]),Zi(`div`,e,{state:{open:g},ref:[v,t],props:[{onContextMenu:T,onTouchStart:D,onTouchMove:O,onTouchEnd:E,onTouchCancel:E,style:{WebkitTouchCallout:`none`}},a],stateAttributesMapping:qt})}),Qy=Dy,$y={claude:`Claude Code`,codex:`Codex`,opencode:`OpenCode`,pi:`Pi`};function eb(e){return Object.hasOwn($y,e)?$y[e]:e}function tb(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 nb=[{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…`}],rb=6e5,ib=e=>e===`checkout_complete`?2:Math.max(0,nb.findIndex(t=>t.id===e)),ab=e=>[`pending`,`running`].includes(e.operation?.state??``)&&!e.panes.some(e=>e.kind===`agent`),ob=e=>[`failed`,`unknown`].includes(e.operation?.state??``)&&!e.panes.some(e=>e.kind===`agent`),sb=e=>nb[ib(e.operation?.step??`validate`)].active,cb=(e,t)=>t-Date.parse(e.updatedAt)<rb,lb=(e,t=Date.now())=>e.panes.some(e=>e.kind===`agent`)||ab(e)||ob(e)&&cb(e,t),ub=e=>new URLSearchParams({machineId:e.machineId??`local`,projectId:e.id}),db=e=>e.branch??e.label,fb=e=>e.path.split(`/`).at(-1)??``,pb=(e,t)=>`${db(e)} ${fb(e)}`.toLowerCase().includes(t.trim().toLowerCase()),mb=async(e,t)=>{let n=await fetch(`/api/worktrees?${ub(e)}`,{signal:t});if(!n.ok)throw Error(`Could not list worktrees.`);return await n.json()},hb=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},gb=async(e,t)=>{try{await a(`/threads/${encodeURIComponent(await hb(e,t))}`)}catch(e){il(e instanceof Error?e.message:`Could not open this worktree.`)}},_b=e=>{(e.key.length===1||e.key===`Backspace`)&&e.stopPropagation()};function vb({project:e}){let[t,n]=(0,l.useState)(``),r=F_({queryKey:[`worktrees`,e.machineId,e.id],queryFn:({signal:t})=>mb(e,t),staleTime:0,gcTime:0}),i=(r.data??[]).filter(e=>pb(e,t));return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`composer-select-search`,children:[(0,Q.jsx)(re,{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:_b})]}),(0,Q.jsxs)(`div`,{className:`worktree-menu-list`,children:[i.map(t=>(0,Q.jsx)(ql,{label:t.path,side:`right`,children:(0,Q.jsxs)(by,{className:`thread-menu-item`,onClick:()=>void gb(e,t),children:[(0,Q.jsx)(j,{size:14,"aria-hidden":`true`}),(0,Q.jsxs)(`span`,{className:`worktree-menu-name`,children:[db(t),(0,Q.jsx)(`small`,{children:fb(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 yb({projects:e}){return(0,Q.jsxs)(Iy,{children:[(0,Q.jsx)(ql,{label:`Open existing worktree`,children:(0,Q.jsx)(Wy,{className:`sidebar-open-worktree`,"aria-label":`Open existing worktree`,disabled:!e.length,children:(0,Q.jsx)(re,{size:16,"aria-hidden":`true`})})}),(0,Q.jsx)(Ey,{children:(0,Q.jsx)(Dy,{className:`thread-menu-positioner`,sideOffset:6,align:`start`,children:(0,Q.jsx)(Cy,{className:`thread-menu`,children:e.map(e=>(0,Q.jsxs)(Ry,{children:[(0,Q.jsxs)(Jy,{className:`thread-menu-item`,children:[(0,Q.jsx)(ug,{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)(Ey,{children:(0,Q.jsx)(Dy,{className:`thread-menu-positioner`,sideOffset:4,alignOffset:-4,children:(0,Q.jsx)(Cy,{className:`thread-menu worktree-menu`,children:(0,Q.jsx)(vb,{project:e})})})})]},`${e.machineId}:${e.id}`))})})})]})}function bb({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&&ip(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 xb({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&&ap(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 Sb=220,Cb=`[data-flip-id]`,wb=e=>{let t=e.getBoundingClientRect().top-e.scrollTop;return new Map([...e.querySelectorAll(Cb)].map(e=>[e.dataset.flipId,{element:e,top:e.getBoundingClientRect().top-t}]))};function Tb(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:Sb,easing:`cubic-bezier(.2, .8, .2, 1)`})}t.current=new Map([...n].map(([e,{top:t}])=>[e,t]))})}function Eb(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 Db=/^\/(?:Users|home)\/[^/]+/,Ob=e=>e.replace(Db,`~`),kb={working:`Working`,blocked:`Needs input`,done:`Done`,idle:`Idle`,unknown:`Unknown`},Ab={blocked:F,done:C,unknown:w},jb=e=>il(e instanceof Error?e.message:`Herdr could not complete this action.`),Mb=async e=>{await rl(dp([e]),{confirmLabel:`Delete`,danger:!0})&&await cp(e).catch(jb)},Nb=(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)(bb,{thread:e,onDone:()=>u(!1),onError:jb}):void 0;return(0,Q.jsxs)(Yy,{children:[(0,Q.jsxs)(Zy,{className:`thread-item`,"data-flip-id":e.id,onDoubleClick:e=>{e.preventDefault(),u(!0)},children:[(0,Q.jsx)(Pb,{thread:e,project:t,machineName:n,current:r,showProject:i,editor:d}),(0,Q.jsx)(ql,{label:a?`Unarchive`:`Archive`,children:(0,Q.jsx)(`button`,{type:`button`,className:`thread-archive`,"aria-label":s,onClick:()=>void rp(e,!a).catch(jb),children:(0,Q.jsx)(o,{size:15,strokeWidth:1.8,"aria-hidden":`true`})})})]}),(0,Q.jsx)(Ey,{children:(0,Q.jsx)(Qy,{className:`thread-menu-positioner`,children:(0,Q.jsx)(Cy,{className:`thread-menu`,children:(0,Q.jsxs)(by,{className:`thread-menu-item is-danger`,onClick:()=>void Mb(e),children:[(0,Q.jsx)(ce,{size:14,"aria-hidden":`true`}),`Delete permanently`]})})})})]})});function Pb({thread:e,project:t,machineName:n,current:r,showProject:i,editor:a}){let o=ab(e),s=ob(e),c=s?le:o?void 0:Ab[e.status],l=s||e.status===`blocked`||e.status===`done`,u=o?sb(e):s?`Launch stopped`:kb[e.status],d=o||s?u:i?t?.name:eb(e.agent),f=a?`div`:`a`;return(0,Q.jsx)(ql,{label:`${e.title} · ${t?.name??``} · ${n} · ${eb(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)(Gf,{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.jsxs)(`span`,{className:`thread-copy`,children:[(0,Q.jsxs)(`span`,{className:`thread-context`,children:[i&&t&&!o&&!s&&(0,Q.jsx)(ug,{project:t}),e.worktree&&!o&&!s&&(0,Q.jsx)(j,{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:tb(e.updatedAt)})]})})}function Fb({project:e,closed:t,onToggle:n}){let[r,i]=(0,l.useState)(!1),o=r?`div`:`button`,s=r?(0,Q.jsx)(xb,{project:e,onDone:()=>i(!1),onError:jb}):(0,Q.jsx)(`span`,{className:`group-name`,children:e.name});return(0,Q.jsxs)(Yy,{children:[(0,Q.jsx)(Zy,{className:`group-header`,children:(0,Q.jsxs)(o,{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)(ug,{project:e}),s]})}),(0,Q.jsx)(Ey,{children:(0,Q.jsx)(Qy,{className:`thread-menu-positioner`,children:(0,Q.jsxs)(Cy,{className:`thread-menu`,children:[(0,Q.jsxs)(by,{className:`thread-menu-item`,onClick:()=>void a(`/new?project=${encodeURIComponent(e.id)}`),children:[(0,Q.jsx)(ne,{size:14,"aria-hidden":`true`}),`New thread`]}),(0,Q.jsxs)(by,{className:`thread-menu-item`,onClick:()=>i(!0),children:[(0,Q.jsx)(te,{size:14,"aria-hidden":`true`}),`Rename project`]}),(0,Q.jsx)(`div`,{className:`thread-menu-path`,title:e.path,children:Ob(e.path)})]})})})]})}function Ib({threads:e,renderThread:t}){let[n,r]=(0,l.useState)(!1),[i,a]=(0,l.useState)(!1),o=async()=>{if(await rl(dp(e),{confirmLabel:`Delete all`,danger:!0})){a(!0);try{let e=await lp();e.failed.length&&await il(`${e.failed.length} archived ${e.failed.length===1?`thread`:`threads`} could not be deleted.`)}catch(e){jb(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 Lb({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=Eb(e,h),_=(0,l.useRef)(null);Tb(_);let v=(t,n)=>{let a=e.find(e=>e.id===t.projectId);return(0,Q.jsx)(Nb,{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)(ee,{size:16}):(0,Q.jsx)(z,{size:16})}),(0,Q.jsx)(`button`,{className:`icon-button mobile-close`,"aria-label":`Close sidebar`,onClick:d,children:(0,Q.jsx)(ue,{size:16})})]}),(0,Q.jsxs)(`div`,{className:`sidebar-actions`,children:[(0,Q.jsx)(ql,{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)(ie,{size:16,"aria-hidden":`true`}),!s&&(0,Q.jsx)(`span`,{children:`New thread`})]})}),(0,Q.jsx)(yb,{projects:e}),!s&&(0,Q.jsxs)(`div`,{className:`sidebar-view-switch`,role:`group`,"aria-label":`Sidebar layout`,children:[(0,Q.jsx)(ql,{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)(N,{size:16,"aria-hidden":`true`})})}),(0,Q.jsx)(ql,{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)(k,{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)(Fb,{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)(Ib,{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)(H,{size:15}),` Settings`]}),(0,Q.jsx)(ql,{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 Rb=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},zb=(e=>e?Rb(e):Rb),Bb=e=>e;function Vb(e,t=Bb){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 Hb=(e,t)=>JSON.stringify(e)===JSON.stringify(t),Ub=(e,t)=>e&&Hb(e,t)?e:t;function Wb(e){let t=new Map,n=new Set,r=zb((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]=Ub(a.threads[e.id],{...e,panes:e.panes.map(t=>Ub(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]=Ub(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:Ub(a.threadIds,d),projectIds:Ub(a.projectIds,f)})}}));for(let t of e.projections)r.getState().install(t);return r}var Gb=()=>zb(e=>({focusedPanes:{},paneWindows:{},focus:(t,n)=>e(e=>({focusedPanes:{...e.focusedPanes,[t]:n}})),showWindow:(t,n)=>e(e=>({paneWindows:{...e.paneWindows,[t]:n}}))}));function Kb(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 qb=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}},Jb=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=_p();this.terminal.write(t,()=>{this.closed||(_p()-n,this.bytes-=e.bytes.length,this.writing=!1,this.acknowledge(e),this.flush())})}},Yb=(e,t=Math.random)=>Math.min(3e4,Math.round(Math.min(25e3,1e3*2**Math.min(e,5))*(.8+t()*.4))),Xb=`Another controller owns this terminal.`,Zb=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 qb,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,_p()),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 qb,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 qb,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 qb,this.open(t)))},scroll:(e,n,r,i)=>{let a=this.panes.get(t);a?.writable&&(this.scrollSentAt.set(t,_p()),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 qb,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 Jb(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&&(_p()-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,_p()),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=tm();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 qb,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`?Xb:String(e.reason).replaceAll(`_`,` `),!1),e.type===`stream.error`&&n.mode===`control`){n.reason=e.reason===`controller_conflict`?Xb:String(e.reason).replaceAll(`_`,` `),n.mode=`observe`,++n.generation,n.sequence=new qb,this.open(e.streamId);return}e.reason===`stream_resync_required`&&n.attempts++<2&&(++n.generation,n.sequence=new qb,n.mode=`observe`,this.open(e.streamId))}return}let e=_p(),n=Kb(new Uint8Array(t.data));t.data.byteLength,_p()-e;let r=this.inputSentAt.get(n.streamId);r!==void 0&&(_p()-r,this.inputSentAt.delete(n.streamId));let i=this.scrollSentAt.get(n.streamId);i!==void 0&&(_p()-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(),Yb(this.failures++)))}},Qb=(0,l.createContext)(null);function $b({bootstrap:e,children:t}){let[n]=(0,l.useState)(()=>{let t=Wb(e);return{runtime:t,ui:Gb(),terminals:new Zb(e=>{let n=gp(`projectionInstallMs`);t.getState().install(e),n()},e=>t.getState().connection(e))}}),[r]=(0,l.useState)(()=>new S_({defaultOptions:{queries:{staleTime:15e3,retry:!1}}}));return(0,l.useEffect)(()=>(n.terminals.start(),()=>n.terminals.stop()),[n]),(0,Q.jsx)(Qb.Provider,{value:n,children:(0,Q.jsx)(gg,{client:r,children:t})})}function ex(){let e=(0,l.useContext)(Qb);if(!e)throw Error(`Runtime provider is missing`);return e}function tx(e){return Vb(ex().runtime,e)}var nx={Enter:`\r`,Backspace:``,Tab:` `,Escape:`\x1B`,ArrowUp:`\x1B[A`,ArrowDown:`\x1B[B`,ArrowRight:`\x1B[C`,ArrowLeft:`\x1B[D`};function rx(e){let t=e.ctrlKey&&/^[a-z]$/i.test(e.key)?String.fromCharCode(e.key.toUpperCase().charCodeAt(0)-64):nx[e.key],n=e.key===`Enter`&&e.shiftKey;return t&&(e.altKey||n?`\x1B`+t:t)}var ix=e=>/^[a-z@\[\\\]^_]$/i.test(e)?String.fromCharCode(e.toUpperCase().charCodeAt(0)&31):void 0;function ax({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=rx(t);n&&(t.preventDefault(),e(n))}})}var ox=[{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`}],sx=e=>e.preventDefault(),cx=e=>({onPointerDown:t=>{sx(t),e()},onMouseDown:sx,onTouchStart:sx,onClick:t=>{t.detail===0&&e()}}),lx={idle:`Dictate`,preparing:`Preparing voice input`,recording:`Stop dictation`,transcribing:`Transcribing`},ux=e=>e===`recording`?(0,Q.jsx)(oe,{size:14,fill:`currentColor`}):e===`idle`?(0,Q.jsx)(I,{size:16}):(0,Q.jsx)(P,{size:16,className:`is-spinning`});function dx({voice:e}){return(0,Q.jsx)(`button`,{type:`button`,tabIndex:-1,"aria-label":lx[e.phase],"aria-pressed":e.phase===`recording`,className:`terminal-voice is-${e.phase}`,...cx(e.toggle),children:ux(e.phase)})}function fx({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`:``,...cx(t),children:`Ctrl`}),ox.map(({label:e,key:t,name:r})=>(0,Q.jsx)(`button`,{type:`button`,tabIndex:-1,"aria-label":r??t,...cx(()=>{let e=rx({key:t,ctrlKey:!1,altKey:!1});e&&n(e)}),children:e},t)),r?.available&&(0,Q.jsx)(dx,{voice:r})]})}var px=`(pointer: coarse)`,mx=120,hx=350;function gx(){let e=window.visualViewport;if(!e||!matchMedia(px).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>mx;a?r():i(),t.toggleAttribute(`data-keyboard-open`,a)};a();let o,s=()=>{clearTimeout(o),o=setTimeout(a,hx)},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 _x(){return typeof matchMedia==`function`&&matchMedia(px).matches}var vx=100,yx=20,bx=10,xx=e=>bx*(1+Math.min(2,Math.abs(e)/60));function Sx(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:yx},u=()=>{o=0;let e=l(),t=Math.trunc(a/e);t&&(a-=t*e,n()?.scroll(t<0?`up`:`down`,Math.min(vx,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*xx(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 Cx=`Only PNG, JPEG, GIF and WebP images can be attached.`,wx=e=>e===1?`Attaching image…`:`Attaching ${e} images…`,Tx=e=>e===1?`Image attached`:`${e} images attached`;function Ex({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(Cx,`error`,4e3);return}if(!n.current){i(`Wait until the terminal accepts input, then attach the image again.`,`error`,4e3);return}i(wx(t.length),`info`);try{s.current(await $p(e,t)),i(Tx(t.length),`info`,1500)}catch(e){i(e instanceof Error?e.message:`The image could not be attached.`,`error`,5e3)}},[e,i,n]);return(0,l.useEffect)(()=>{if(!t)return;let e=0,n=t=>{qp(t.dataTransfer)&&(t.preventDefault(),e+=1,o(!0))},r=e=>{qp(e.dataTransfer)&&(e.preventDefault(),e.dataTransfer&&(e.dataTransfer.dropEffect=`copy`))},i=t=>{qp(t.dataTransfer)&&(e=Math.max(0,e-1),e||o(!1))},a=t=>{qp(t.dataTransfer)&&(t.preventDefault(),e=0,o(!1),c(Kp(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 Dx(e,t){(e.metaKey||e.ctrlKey)&&window.open(t,`_blank`,`noopener,noreferrer`)}function Ox(){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 kx=16e3,Ax=`registerProcessor('webr-capture', class extends AudioWorkletProcessor {
|
|
3
|
+
process([input]) { if (input?.[0]) this.port.postMessage(input[0].slice()); return true; }
|
|
4
|
+
});`,jx=()=>typeof window<`u`&&window.isSecureContext&&!!navigator.mediaDevices?.getUserMedia&&typeof AudioWorkletNode<`u`,Mx=()=>{try{return new AudioContext({sampleRate:kx})}catch{return new AudioContext}};function Nx(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 Px(e){let t=URL.createObjectURL(new Blob([Ax],{type:`text/javascript`}));try{await e.audioWorklet.addModule(t)}finally{URL.revokeObjectURL(t)}}async function Fx(){let e=Mx();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 Px(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:Nx(r),sampleRate:t}},cancel:o}}var Ix={voice_unavailable:`Voice input is not available on this Webr server.`,image_too_large:`The recording is too long.`};async function Lx(){let e=await fetch(`/api/voice`).catch(()=>void 0);return e?.ok?(await e.json()).state:`unavailable`}async function Rx(){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 zx(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(Ix[r.error??``]??`The recording could not be transcribed.`);return r.text}var Bx=2e3,Vx=`Downloading the voice model (670 MB, one time). The mic works when it finishes.`,Hx=e=>e===`needs-download`||e===`downloading`,Ux=e=>e instanceof DOMException&&e.name===`NotAllowedError`?`Allow microphone access for Webr in your browser settings.`:`The microphone could not start.`;function Wx({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(!jx())return;let e=!1;return Lx().then(t=>{e||r(t)}),()=>{e=!0,o.current?.cancel()}},[]),(0,l.useEffect)(()=>{if(i!==`preparing`)return;let e=setInterval(()=>void Lx().then(e=>{Hx(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))}),Bx);return()=>clearInterval(e)},[i,t]);let c=(0,l.useCallback)(()=>{Rx(),a(`preparing`),t(Vx,`info`)},[t]),u=(0,l.useCallback)(async()=>{a(`recording`);let e=Fx();Rx();try{o.current=await e}catch(e){a(`idle`),t(Ux(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 zx(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`?Hx(n)?c():u():i===`recording`&&d()},[i,n,c,u,d]);return{available:n!==`unavailable`,phase:i,toggle:f}}var Gx=(function(){let e=typeof document<`u`&&document.createElement(`link`).relList;return e&&e.supports&&e.supports(`modulepreload`)?`modulepreload`:`preload`})(),Kx=function(e){return`/`+e},qx={},Jx=function(e){return e.pathname.endsWith(`.css`)},Yx=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=Kx(t,n);let r=s(t);if(r.href in qx)return;qx[r.href]=!0;let i=Jx(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`:Gx,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 Xx(){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 Zx=`"JetBrains Mono", "Webr Symbols", ui-monospace, Menlo, monospace`,Qx=15,$x=()=>typeof document>`u`||!document.fonts?Promise.resolve():Promise.all([document.fonts.load(`400 ${Qx}px "JetBrains Mono"`),document.fonts.load(`700 ${Qx}px "JetBrains Mono"`),document.fonts.load(`${Qx}px "Webr Symbols"`,``)]).then(()=>void 0,()=>void 0),eS=`\x1B[I`,tS=`\x1B[O`,nS=e=>e&&Number.isFinite(e.cols)&&Number.isFinite(e.rows)?e:void 0;function rS({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}=ex(),[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(_x()),[]);let{notice:w,show:T}=Ox(),E=Ex({machineId:n,active:i,writable:_,show:T,send:e=>{d.current?.input(e,!0)}}),D=Wx({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([Yx(()=>import(`./xterm.B-l5AIf6.js`).then(t=>e(t.default,1)),__vite__mapDeps([0,1])),Yx(()=>import(`./addon-fit.jgKqzwky.js`).then(t=>e(t.default,1)),__vite__mapDeps([2,1])),Yx(()=>import(`./addon-web-links.C9lyQRxI.js`).then(t=>e(t.default,1)),__vite__mapDeps([3,1])),$x()]).then(([e,{FitAddon:c},{WebLinksAddon:l}])=>{if(i||!s.current)return;let p=new e.Terminal({fontFamily:Zx,fontSize:Qx,lineHeight:1.2,letterSpacing:0,cursorBlink:!0,cursorInactiveStyle:`block`,allowTransparency:!1,scrollback:0,theme:Xx(),disableStdin:!0,linkHandler:{activate:()=>{}}});p.open(s.current),p.attachCustomWheelEventHandler(()=>!1),u.current=p;let h=()=>{_.current&&s.current?.parentElement?.querySelector(`.terminal-input-capture`)?.focus()};p.textarea?.addEventListener(`focus`,h);let v=pv(s.current,p,()=>_.current,e=>O.current(e)),y=p.parser.registerOscHandler(8,()=>!0);if(!t.terminalId){v(),p.dispose();return}let b=new c;p.loadAddon(b),p.loadAddon(new l(Dx));let x=()=>({cols:Math.floor((s.current?.clientWidth??640)/8),rows:Math.floor((s.current?.clientHeight??400)/20)}),S=()=>{try{return nS(b.proposeDimensions())}catch{return}},C=()=>!!s.current?.isConnected&&s.current.clientWidth>0&&s.current.clientHeight>0,w=()=>{let{cols:e,rows:t}=S()??x();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:p,mode:a?`control`:`observe`,...w(),onState:(e,t)=>{m(e),g(t),_.current=t}});let T=Sx(s.current,()=>({element:p.element?.querySelector(`.xterm-screen`)??void 0,cols:p.cols,rows:p.rows}),()=>d.current,()=>_.current),E,D=new ResizeObserver(()=>{clearTimeout(E),E=setTimeout(()=>{if(!C())return;let{cols:e,rows:t}=w();d.current?.resize(e,t)},150)});D.observe(s.current);let k=()=>{if(document.visibilityState!==`visible`||!document.hasFocus()||!C())return;let{cols:e,rows:t}=w();d.current?.resize(e,t,!0)};window.addEventListener(`focus`,k),document.addEventListener(`visibilitychange`,k);let A=new MutationObserver(()=>{p.options.theme=Xx()});A.observe(document.documentElement,{attributes:!0,attributeFilter:[`data-theme`]}),o=()=>{clearTimeout(E),d.current?.close(),d.current=null,_.current=!1,T(),window.removeEventListener(`focus`,k),document.removeEventListener(`visibilitychange`,k),p.textarea?.removeEventListener(`focus`,h),v(),y.dispose(),D.disconnect(),A.disconnect(),p.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(ix(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=rx(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=Kp(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(),rl(`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)(M,{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)(ax,{onInput:k,onFocusChange:e=>{y(e),u.current?.modes.sendFocusMode&&d.current?.input(e?eS:tS)}}),a&&i&&S&&v&&(0,Q.jsx)(fx,{ctrl:b,onToggleCtrl:()=>x(e=>!e),onBytes:e=>d.current?.input(e),voice:D})]})}function iS({thread:e}){let t=ob(e),n=ib(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:nb.map((e,r)=>{let i=r<n?`done`:r===n?t?`failed`:`active`:`waiting`,a=i===`done`?C:i===`failed`?S:i===`active`?P: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 `,nb[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 aS=({pane:e})=>e.kind===`agent`?(0,Q.jsx)(v,{size:14,strokeWidth:1.8,"aria-hidden":`true`}):(0,Q.jsx)(ae,{size:14,strokeWidth:1.8,"aria-hidden":`true`});function oS({pane:e,side:t,onOpen:n}){return(0,Q.jsx)(ql,{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)(aS,{pane:e}),(0,Q.jsx)(`span`,{children:e.title})]})})}var sS=(e,t)=>JSON.stringify([t,e.map(e=>e.id)]),cS=(e,t)=>{let[n,r]=JSON.parse(e);return{start:n,panes:r.flatMap(e=>t.filter(t=>t.id===e))}},lS=(e,t)=>cS((0,l.useDeferredValue)(sS(e,t)),e);function uS({panes:e,windowStart:t,onFocusPane:n,renderPane:r}){let{panes:i,start:a}=lS(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 dS({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)(aS,{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 fS({thread:e,connected:t,canControl:n,onFocusPane:r,focusedPane:i,windowStart:o,narrow:s}){let c=t&&e.bindingState===`detached`;(0,l.useEffect)(()=>{c&&a(`/new?project=${encodeURIComponent(e.projectId)}`)},[c,e.projectId]);let u=t=>t.terminalId?(0,Q.jsx)(rS,{pane:t,machineId:e.machineId,threadId:e.id,active:i===t.id,canControl:n,onFocus:()=>r(t.id)},t.terminalId):null;if(t&&(ab(e)||ob(e)))return(0,Q.jsx)(iS,{thread:e});let d={panes:e.panes,focusedPane:i,onFocusPane:r,renderPane:u};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)(dS,{...d}):(0,Q.jsx)(uS,{...d,windowStart:o}))]})}var pS=e=>Symbol.iterator in e,mS=e=>`entries`in e,hS=(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},gS=(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 _S(e,t){return Object.is(e,t)?!0:typeof e!=`object`||!e||typeof t!=`object`||!t||Object.getPrototypeOf(e)!==Object.getPrototypeOf(t)?!1:pS(e)&&pS(t)?mS(e)&&mS(t)?hS(e,t):gS(e,t):hS({entries:()=>Object.entries(e)},{entries:()=>Object.entries(t)})}function vS(e){let t=l.useRef(void 0);return n=>{let r=e(n);return _S(t.current,r)?t.current:t.current=r}}function yS(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===Zf(e))?.[0]}var bS=`(max-width: 760px)`;function xS(e,t,n,r){let i=Vb(e,e=>e.paneWindows[t]??0),a=hp(n.length,i,n.indexOf(r));return(0,l.useEffect)(()=>{a!==i&&e.getState().showWindow(t,a)},[e,t,a,i]),a}var SS=e=>{if(typeof matchMedia!=`function`)return()=>{};let t=matchMedia(bS);return t.addEventListener(`change`,e),()=>t.removeEventListener(`change`,e)},CS=()=>typeof matchMedia==`function`&&matchMedia(bS).matches,wS=()=>(0,l.useSyncExternalStore)(SS,CS,()=>!1);function TS(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 ES=e=>e.preventDefault();function DS(e){return(0,Q.jsx)(Hp,{children:(0,Q.jsx)($b,{bootstrap:e.bootstrap,children:(0,Q.jsx)(OS,{...e})})})}function OS({page:e,bootstrap:t,threadId:n,projectId:r}){let{ui:i,terminals:o}=ex(),s=tx(vS(e=>e.projectIds.map(t=>e.projects[t]))),c=tx(vS(e=>e.threadIds.map(t=>e.threads[t]).filter(e=>!e.archivedAt&&lb(e)))),u=tx(vS(e=>e.threadIds.map(t=>e.threads[t]).filter(e=>!!e.archivedAt))),d=tx(e=>e.threads[n??``]),f=tx(e=>e.projections),p=tx(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)(vp,[]),(0,l.useEffect)(gx,[]);let[x,S]=(0,l.useState)(`threads`),C=`${d?.machineId??``}:${d?.id??``}`,w=Vb(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]);TS(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=>{qp(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`&&$f(`system`)};return t.addEventListener(`change`,n),()=>{t.removeEventListener(`change`,n),window.removeEventListener(`popstate`,e)}},[]);let k=e=>void il(e instanceof Error?e.message:`Herdr could not change the pane.`),A=xS(i,C,d?.panes.map(e=>e.id)??[],T),j=wS(),M=(0,l.useCallback)(()=>{d&&T&&op(d,T).then(({paneId:e})=>D(e),k)},[d,T,D]),N=(0,l.useCallback)(async(e=T)=>{if(!d||!fp(d,e))return;let t=d.panes.find(t=>t.id===e),n=mp(d.panes,A,e);try{let r=await sp(d,e,!1);r.busy&&await rl(`${t.title} is running a process. Close it anyway?`,{confirmLabel:`Close`,danger:!0})&&(r=await sp(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=yS(e,Jf());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)(Lb,{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)(fS,{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)(av,{projects:s,machines:m,selectedProjectId:r,onOpenSidebar:P},r),e===`settings`&&(0,Q.jsx)(uy,{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:ES,onClick:P,children:(0,Q.jsx)(B,{size:22})}),(0,Q.jsx)(`button`,{"aria-label":`Open command palette`,onPointerDown:ES,onClick:()=>b(!0),children:(0,Q.jsx)(E,{size:22})})]}),!1,(0,Q.jsx)(Vp,{}),(0,Q.jsx)(bp,{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{DS as default};
|