offsite 0.0.57 → 0.0.59
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/apps/client/dist/assets/{index-BtnFX6Z2.css → index-B7_HRCda.css} +1 -1
- package/apps/client/dist/assets/{index-CfER-bxq.js → index-sMPutCZg.js} +1 -1
- package/apps/client/dist/index.html +2 -2
- package/apps/client/dist/sw.js +1 -1
- package/apps/server/dist/main.mjs +10 -2
- package/apps/server/dist/main.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -11,7 +11,7 @@ Error generating stack: `+e.message+`
|
|
|
11
11
|
`).map((n,r)=>(0,W.jsxs)(`div`,{className:z(`px-2 whitespace-pre-wrap`,e.added&&`bg-diff-addition/10 text-diff-addition`,e.removed&&`bg-diff-deletion/10 text-diff-deletion`,!e.added&&!e.removed&&`text-muted-foreground`),children:[e.added?`+`:e.removed?`-`:` `,` `,n]},`${t}:${r}`)))})}function rd(e){return typeof e==`string`?e:``}function id(e,t){return e.startsWith(t+`/`)||e.startsWith(t+`\\`)?e.slice(t.length+1):e}var ad=`(Recommended)`;function od(e){let t=e.options.map(e=>e.label).filter(e=>e.endsWith(ad));return e.multiSelect?t:t.slice(0,1)}function sd(e){return(0,W.jsxs)(`span`,{className:z(`mt-0.5 grid size-4 shrink-0 place-items-center border transition-colors`,e.multi?`rounded`:`rounded-full`,e.selected&&`border-primary bg-primary text-primary-foreground`,e.suggested&&`border-primary border-dashed`,!e.selected&&!e.suggested&&`border-muted-foreground/40`),children:[e.selected&&e.multi&&(0,W.jsx)(V,{icon:Xn,strokeWidth:3,className:`size-3`}),e.selected&&!e.multi&&(0,W.jsx)(`span`,{className:`bg-primary-foreground size-1.5 rounded-full`})]})}function cd(e){let[t,n]=(0,U.useState)(Date.now);(0,U.useEffect)(()=>{let e=setInterval(()=>n(Date.now()),1e3);return()=>clearInterval(e)},[]);let r=Math.max(0,Math.ceil((e.at-t)/1e3));return(0,W.jsxs)(`span`,{className:`text-muted-foreground text-2xs mr-1 tabular-nums`,children:[e.label,` in`,` `,r<60?`${r}s`:`${Math.ceil(r/60)}m`]})}var ld=`composer-glass relative mx-auto -mb-[calc(1rem+1px)] w-[calc(100%-2.75rem)] rounded-t-2xl border border-b-0 px-1 pt-1 pb-[calc(1rem+1px+0.25rem)] text-xs/4`;function ud(e){let t=e.request;if(t.kind===`question`)return(0,W.jsx)(dd,{machine:e.machine,request:t,draft:e.draft});let n=t.kind===`plan`,r=n?``:$u(t.item,e.cwd);return(0,W.jsx)(`div`,{className:z(ld,`border-warning/28 bg-linear-to-b from-warning/8 to-warning/8`),children:(0,W.jsxs)(`div`,{className:`grid grid-cols-[1.5rem_minmax(0,1fr)_auto] items-start gap-x-2 gap-y-3 px-1 py-1`,children:[(0,W.jsx)(`span`,{className:`text-warning flex justify-center pt-0.5`,children:(0,W.jsx)(V,{icon:Ko,className:`size-4`})}),(0,W.jsxs)(`span`,{className:`flex min-w-0 flex-col items-start gap-1`,children:[(0,W.jsxs)(`span`,{className:`text-muted-foreground text-2xs flex w-full min-w-0 items-center gap-2`,children:[(0,W.jsx)(`span`,{className:`text-warning shrink-0 font-medium`,children:n?`Ready to code?`:t.title}),e.count>1&&(0,W.jsxs)(`span`,{className:`ml-auto shrink-0 tabular-nums`,children:[`1/`,e.count]})]}),r!==``&&(0,W.jsx)(`span`,{className:`text-foreground block max-h-20 w-full min-w-0 overflow-auto font-mono text-xs whitespace-pre`,children:r})]}),(0,W.jsxs)(`span`,{className:`flex shrink-0 items-center gap-1.5`,children:[t.autoResolve!==void 0&&(0,W.jsx)(cd,{label:t.autoResolve.decision===`allow`?`Approve`:`Decline`,at:t.autoResolve.at}),(0,W.jsx)(H,{size:`xs`,variant:`outline`,onClick:()=>Qe(t.id,`deny`,null),children:n?`Keep planning`:`Decline`}),t.kind===`approval`&&t.canAlwaysAllow&&(0,W.jsx)(H,{size:`xs`,variant:`outline`,onClick:()=>Qe(t.id,`always`,null),children:`Always`}),(0,W.jsx)(H,{size:`xs`,onClick:()=>Qe(t.id,`allow`,null),children:n?`Approve plan`:`Approve`})]}),n&&(0,W.jsx)(`div`,{className:`col-span-3 max-h-60 overflow-auto px-1 empty:hidden`,children:(0,W.jsx)(B,{text:t.plan})}),t.kind===`approval`&&t.item.kind!==`command`&&(0,W.jsx)(`div`,{className:`col-span-3 max-h-60 overflow-auto px-1 empty:hidden`,children:(0,W.jsx)(Qu,{item:t.item})})]})})}function dd(e){let t=e.request.questions,[n,r]=(0,U.useState)(0),[i,a]=(0,U.useState)({}),[o,s]=(0,U.useState)({}),c=Object.fromEntries(t.map(e=>[e.question,[...i[e.question]??[],o[e.question]?.trim()??``].filter(e=>e!==``)])),l=Object.fromEntries(t.map(e=>[e.question,(c[e.question].length>0?c[e.question]:od(e)).join(`, `)])),u=t[n],d=t.flatMap((e,t)=>c[e.question].length===0?[t]:[]),f=d.find(e=>e>n)??d[0];function p(e,c){let l=i[e.question]??[];e.multiSelect?a({...i,[e.question]:l.includes(c)?l.filter(e=>e!==c):[...l,c]}):(a({...i,[e.question]:[c]}),s({...o,[e.question]:``}),n<t.length-1&&r(n+1))}function m(e,t){s({...o,[e.question]:t}),!e.multiSelect&&t.trim()!==``&&a({...i,[e.question]:[]})}async function h(t,n){let r=Ku(L().items,[e.draft,...Object.values(o)]);for(let i of n)try{let n=await Hu(e.machine,i),o=n;i.type.startsWith(`image/`)&&(r+=1,o=`[Image #${r}] (saved at ${n})`),s(e=>{let n=e[t.question]??``;return{...e,[t.question]:`${n}${/(^|\s)$/.test(n)?``:` `}${o}`}}),t.multiSelect||a(e=>({...e,[t.question]:[]}))}catch(e){mt(e)}}return(0,W.jsx)(`div`,{className:`composer-glass shadow-composer relative z-10 rounded-3xl border border-(--composer-outline)`,children:(0,W.jsxs)(`div`,{className:`flex flex-col gap-2 p-2.5`,children:[(0,W.jsxs)(`div`,{role:`tabpanel`,className:`flex min-w-0 flex-col gap-2`,children:[(0,W.jsxs)(`div`,{className:`mb-1 flex items-start gap-1.5 pt-1 pr-1 pl-1.5`,children:[(0,W.jsx)(`span`,{className:`bg-primary/18 text-primary grid size-6 shrink-0 place-items-center rounded-md`,children:(0,W.jsx)(V,{icon:ko,className:`size-4`})}),(0,W.jsx)(`p`,{className:`text-foreground min-w-0 flex-1 pt-0.5 text-[15px] leading-5 font-medium`,children:u.question}),(0,W.jsx)(H,{size:`icon-xs`,variant:`ghost`,"aria-label":`Skip questions`,title:`Skip questions`,onClick:()=>Qe(e.request.id,`deny`,null),children:(0,W.jsx)(V,{icon:st})})]}),(0,W.jsxs)(`div`,{role:u.multiSelect?`group`:`radiogroup`,"aria-label":u.question,className:`flex max-h-[min(18rem,32dvh)] flex-col gap-0.5 overflow-y-auto`,children:[u.options.map(e=>{let t=i[u.question]?.includes(e.label)===!0,n=c[u.question].length===0&&od(u).includes(e.label),r=e.label.endsWith(ad);return(0,W.jsxs)(`button`,{role:u.multiSelect?`checkbox`:`radio`,"aria-checked":t,className:z(`flex cursor-pointer items-start gap-2.5 rounded-lg px-2.5 py-2 text-left transition-colors`,t?`bg-muted/70`:`hover:bg-muted/40`),onClick:()=>p(u,e.label),children:[(0,W.jsx)(sd,{multi:u.multiSelect,selected:t,suggested:n}),(0,W.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,W.jsxs)(`span`,{className:`flex items-baseline gap-2`,children:[(0,W.jsx)(`span`,{className:`text-foreground text-sm`,children:r?e.label.slice(0,-13).trim():e.label}),r&&(0,W.jsx)(`span`,{className:`text-muted-foreground/70 text-[11px]`,children:`Recommended`})]}),e.description!==``&&(0,W.jsx)(`span`,{className:`text-secondary-label mt-0.5 block text-xs leading-4`,children:e.description})]})]},e.label)}),(0,W.jsxs)(`label`,{className:z(`flex cursor-text items-start gap-2.5 rounded-lg px-2.5 py-2 transition-colors`,(o[u.question]??``).trim()===``?`focus-within:bg-muted/40 hover:bg-muted/40`:`bg-muted/70`),children:[(0,W.jsx)(sd,{multi:u.multiSelect,selected:(o[u.question]??``).trim()!==``,suggested:!1}),(0,W.jsx)(`textarea`,{value:o[u.question]??``,rows:1,onChange:e=>m(u,e.target.value),onPaste:e=>{let t=e.clipboardData.getData(`text/plain`);if(t!==``){e.preventDefault(),document.execCommand(`insertText`,!1,t);return}let n=[...e.clipboardData.files];n.length!==0&&(e.preventDefault(),h(u,n))},onDragOver:e=>e.preventDefault(),onDrop:e=>{e.preventDefault(),h(u,[...e.dataTransfer.files])},placeholder:`Something else…`,className:`placeholder:text-placeholder/75 [field-sizing:content] max-h-40 min-w-0 flex-1 resize-none bg-transparent text-sm leading-5 outline-none`})]})]})]},u.question),(0,W.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[t.length>1&&(0,W.jsx)(`div`,{role:`tablist`,className:`flex min-w-0 [scrollbar-width:none] gap-1 overflow-x-auto`,children:t.map((e,t)=>(0,W.jsxs)(`button`,{role:`tab`,"aria-selected":t===n,className:z(`flex h-6 shrink-0 cursor-pointer items-center gap-1.5 rounded-md px-2.5 text-xs font-medium transition-colors`,t===n?`bg-muted text-foreground`:`text-muted-foreground hover:bg-muted/50 hover:text-foreground`),onClick:()=>r(t),children:[c[e.question].length>0&&(0,W.jsx)(V,{icon:Za,"aria-label":`Answered`,className:`text-success size-3.5`}),c[e.question].length===0&&l[e.question]!==``&&(0,W.jsx)(V,{icon:Pn,"aria-label":`Using the recommended answer`,className:`text-primary size-3.5`}),l[e.question]===``&&(0,W.jsx)(V,{icon:vo,"aria-label":`Not answered`,className:`text-muted-foreground size-3.5`}),e.header]},e.question))}),(0,W.jsxs)(`div`,{className:`ml-auto flex shrink-0 items-center gap-1.5 pr-1`,children:[e.request.autoResolve!==void 0&&(0,W.jsx)(cd,{label:`Skip`,at:e.request.autoResolve.at}),(0,W.jsx)(H,{size:`xs`,variant:`outline`,onClick:()=>Qe(e.request.id,`allow`,{}),children:`Skip`}),(0,W.jsx)(H,{size:`xs`,variant:f===void 0?`default`:`outline`,onClick:()=>Qe(e.request.id,`allow`,Object.fromEntries(t.flatMap(e=>c[e.question].length===0?[]:[[e.question,c[e.question].join(`, `)]]))),children:`Submit`}),f!==void 0&&(0,W.jsx)(H,{size:`xs`,onClick:()=>{c[u.question].length===0&&a({...i,[u.question]:od(u)}),r(f)},children:`Next`})]})]})]})})}function fd(e,t,n,r,i){let a=pd(e,n,r+Math.asin(.5/n)),o=pd(e,n,i-Math.asin(.5/n)),s=pd(e,t,i-Math.asin(.5/t)),c=pd(e,t,r+Math.asin(.5/t)),l=[a,o,s,c,...r<Math.PI/2&&i>Math.PI/2?[pd(e,n,Math.PI/2)]:[]],u=Math.min(...l.map(e=>e.x)),d=Math.min(...l.map(e=>e.y)),f=pd(e,(t+n)/2,(r+i)/2);return{style:{left:u,top:d,width:Math.max(...l.map(e=>e.x))-u,height:Math.max(...l.map(e=>e.y))-d,clipPath:`path('M${a.x-u} ${a.y-d} A${n} ${n} 0 0 0 ${o.x-u} ${o.y-d} L${s.x-u} ${s.y-d} A${t} ${t} 0 0 1 ${c.x-u} ${c.y-d}Z')`},center:{left:f.x-u,top:f.y-d}}}function pd(e,t,n){return{x:e+t*Math.cos(n),y:e-t*Math.sin(n)}}var md=`relative inline-flex shrink-0 cursor-pointer items-center justify-center whitespace-nowrap rounded-(--control-radius) border border-transparent outline-none hover:bg-accent data-[state=open]:bg-accent focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-64 [&_svg]:pointer-events-none [&_svg]:shrink-0`,hd=`h-7 gap-1.5 px-1.5 text-sm font-medium text-secondary-label hover:text-foreground [&_svg:not([class*=text-])]:text-muted-foreground [&_svg:not([class*=size-])]:size-4`;function gd(){let e=R(e=>e.settings),t=R(e=>e.capabilities)?.models.find(t=>t.value===e.model);return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(_d,{}),(0,W.jsx)(`span`,{className:`bg-border mx-0.5 hidden h-4 w-px shrink-0 sm:block`}),t!==void 0&&t.efforts.length>0&&(0,W.jsx)(vd,{title:`Effort`,trigger:(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(V,{icon:Wa}),(0,W.jsx)(`span`,{className:`capitalize`,children:e.effort??`Default`})]}),value:e.effort??`default`,options:[...e.provider===`opencode`?[{value:`default`,label:`Default`}]:[],...t.efforts.map(e=>({value:e,label:e.charAt(0).toUpperCase()+e.slice(1)}))],onChange:e=>Ge({effort:e==="default"?null:e})})]})}function _d(){let e=R(e=>e.settings),t=R(e=>e.selection),n=R(e=>e.machines.find(t=>t.id===e.selection?.machine)),r=[...[...n?.claudeAccounts??[],...n?.codexAccounts??[]].filter(e=>e.valid).map(e=>({key:e.id,provider:e.provider,accountId:e.id,name:e.name,color:e.color,plan:e.plan,error:e.error})),...n?.openCode.available===!0?[{key:`opencode`,provider:`opencode`,accountId:null,name:`OpenCode`,color:null,plan:null,error:null}]:[]].filter(n=>t?.sessionId===null||n.provider===e.provider),i=e.provider===`opencode`?`opencode`:e.accountId,a=R(e=>e.capabilities),[o,s]=(0,U.useState)(!1),[c,l]=(0,U.useState)(i),[d,f]=(0,U.useState)(``),[p,m]=(0,U.useState)({}),h=(0,U.useRef)(null),g=a?.models.find(t=>t.value===e.model)?.name??e.model??`Choose a model`,_=r.find(e=>e.key===i),v=c===null?[]:c===i?a?.models??null:p[c]??null,y=r.find(e=>e.key===c)?.provider,b=(v??[]).filter(e=>!e.hidden),x=b.length>=5,S=x?d.trim().toLowerCase():``,C=b.filter(e=>`${e.name} ${e.description}`.toLowerCase().includes(S));function w(e){if(s(e),e&&(l(i),f(``),t!==null))for(let e of r)e.key!==i&&e.error===null&&N(t.machine,`capabilities`,{provider:e.provider,accountId:e.accountId,projectId:t.projectId}).then(t=>m(n=>({...n,[e.key]:t.models})),mt)}function T(n,i){let a=r.find(e=>e.key===n);if(a===void 0||t===null)return;let o=a.provider,s={accountId:a.accountId,model:i.value,...i.effort===null?{}:{effort:i.effort}};o===e.provider?Ge(s):Ge({...Fe(I(L(),t.machine).composer,o),...s})}return(0,W.jsxs)($n,{open:o,onOpenChange:w,children:[(0,W.jsx)(Wt,{asChild:!0,children:(0,W.jsxs)(`button`,{className:z(md,hd),title:_===void 0?`Model`:`${_.name} · ${g}`,children:[(0,W.jsxs)(`span`,{className:`relative`,children:[(0,W.jsx)(Vs,{provider:e.provider,className:`size-4`}),r.filter(t=>t.provider===e.provider).length>1&&_!==void 0&&(0,W.jsx)(`span`,{className:z(`pointer-events-none absolute -right-1 -bottom-1 flex h-3 min-w-3 items-center justify-center rounded-full border px-0.5 text-[8px] leading-none font-semibold shadow-sm`,_.color===null?`bg-card text-muted-foreground`:`border-card text-white`),style:_.color===null?void 0:{backgroundColor:_.color},children:_.name.charAt(0).toUpperCase()})]}),(0,W.jsx)(`span`,{className:`max-w-40 truncate`,children:g})]})}),(0,W.jsxs)(sn,{side:`top`,className:`flex max-h-86.5 w-screen max-w-90 flex-row`,onOpenAutoFocus:e=>{e.preventDefault(),h.current?.focus()},onCloseAutoFocus:e=>{e.preventDefault(),document.querySelector(`[data-composer]`)?.focus()},children:[r.length>1&&(0,W.jsxs)(`div`,{className:`bg-muted/30 flex w-11 shrink-0 [scrollbar-width:none] flex-col gap-1 overflow-y-auto p-1`,children:[r.map(t=>(0,W.jsxs)(`div`,{className:`relative w-full`,children:[t.key===c&&(0,W.jsx)(`div`,{className:`bg-primary pointer-events-none absolute top-1/2 -right-1 z-10 h-5 w-0.75 -translate-y-1/2 rounded-l-full`}),(0,W.jsx)(vr,{side:`left`,label:t.error===null?[t.name,t.plan].filter(e=>e!==null).join(` · `):`${t.name} — ${t.error}`,children:(0,W.jsxs)(`button`,{className:z(`hover:bg-foreground/10 focus-visible:bg-foreground/10 relative flex aspect-square w-full cursor-pointer items-center justify-center rounded-md transition-colors focus-visible:outline-none`,t.error!==null&&`cursor-not-allowed opacity-50 hover:bg-transparent`),"aria-label":t.name,"aria-pressed":t.key===c,"aria-disabled":t.error!==null,onClick:()=>{if(t.error!==null)return;let n=p[t.key]?.find(t=>t.value===e.model);t.key!==i&&i!==null&&a!==null&&n!==void 0&&(m(e=>({...e,[i]:a.models})),T(t.key,n)),l(t.key)},children:[(0,W.jsx)(Vs,{provider:t.provider,className:`size-5`}),r.filter(e=>e.provider===t.provider).length>1&&(0,W.jsx)(`span`,{className:z(`text-3xs pointer-events-none absolute right-0.5 bottom-0.5 flex h-3.5 min-w-3.5 items-center justify-center rounded-full border px-0.5 leading-none font-semibold shadow-sm`,t.color===null?`bg-card text-muted-foreground`:`border-card text-white`),style:t.color===null?void 0:{backgroundColor:t.color},children:t.name.charAt(0).toUpperCase()})]})})]},t.key)),(0,W.jsx)(vr,{side:`left`,label:`Manage accounts`,children:(0,W.jsx)(`button`,{className:`text-muted-foreground hover:bg-foreground/10 hover:text-foreground focus-visible:bg-foreground/10 mt-auto flex aspect-square w-full shrink-0 cursor-pointer items-center justify-center rounded-md transition-colors focus-visible:outline-none`,"aria-label":`Manage accounts`,onClick:()=>{s(!1),u(vt[e.provider])},children:(0,W.jsx)(V,{icon:ts,className:`size-4.5`})})})]}),(0,W.jsxs)(`div`,{className:z(`bg-muted/40 flex min-h-0 min-w-0 flex-1 flex-col`,r.length>1&&`border-border/70 border-l`),children:[x&&(0,W.jsx)(`div`,{className:`shrink-0 px-3 pt-2.5`,children:(0,W.jsxs)(`div`,{className:`border-border/70 focus-within:border-ring relative border-b pb-1.5 transition-colors`,children:[(0,W.jsx)(V,{icon:Cn,className:`text-muted-foreground/55 pointer-events-none absolute top-1.5 left-0 size-4`}),(0,W.jsx)(`input`,{ref:h,value:d,placeholder:`Search models...`,className:`placeholder:text-muted-foreground/70 h-6.5 w-full bg-transparent ps-5 text-sm outline-none`,onChange:e=>f(e.target.value),onKeyDown:e=>{if(e.key!==`Enter`||c===null)return;let t=C.at(0);t!==void 0&&(e.preventDefault(),T(c,t),s(!1))}})]})}),(0,W.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-2 py-1.5`,children:C.length===0?(0,W.jsx)(`p`,{className:`text-muted-foreground p-2 text-center text-sm`,children:v===null?`Loading models…`:`No models found`}):C.map(t=>(0,W.jsx)(`button`,{className:z(`hover:bg-accent hover:text-accent-foreground mb-0.5 flex min-h-8 w-full cursor-pointer flex-col justify-center rounded-sm px-2 py-1.5 text-left`,c===i&&t.value===e.model&&`text-foreground bg-foreground/[0.08]`),onClick:()=>{c!==null&&(T(c,t),s(!1))},children:(0,W.jsxs)(`span`,{className:`truncate text-sm leading-snug font-medium`,children:[t.name,y===`opencode`&&(0,W.jsx)(`span`,{className:`text-muted-foreground ml-2 text-xs font-normal`,children:t.description})]})},t.value))})]})]})]})}function vd(e){let t=Math.min(190,(window.innerWidth-16)/2);return(0,W.jsxs)(Qt,{modal:e.options.length>5,children:[(0,W.jsx)(un,{asChild:!0,children:(0,W.jsx)(`button`,{className:z(md,hd),title:e.title,children:e.trigger})}),e.options.length>5&&(0,W.jsx)(tn,{className:`w-72`,side:`top`,align:`start`,onCloseAutoFocus:e=>{e.preventDefault(),document.querySelector(`[data-composer]`)?.focus()},children:(0,W.jsx)(rn,{value:e.value,onValueChange:e.onChange,children:e.options.map(e=>(0,W.jsx)(ir,{value:e.value,children:e.label},e.value))})}),e.options.length<=5&&(0,W.jsx)(Hn,{children:(0,W.jsxs)(Xt,{"data-slot":`dropdown-menu-content`,side:`top`,sideOffset:-28,className:`data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95 pointer-events-none relative z-50 origin-(--radix-dropdown-menu-content-transform-origin) drop-shadow-[0_12px_28px_rgb(0_0_0/45%)] duration-100 outline-none`,style:{width:t*2,height:t},onCloseAutoFocus:e=>{e.preventDefault(),document.querySelector(`[data-composer]`)?.focus()},children:[(0,W.jsx)(`div`,{className:`bg-background pointer-events-auto absolute`,style:fd(t,t*.35,t,0,Math.PI).style}),(0,W.jsx)(Yt,{value:e.value,onValueChange:e.onChange,children:e.options.map((n,r)=>{let i=fd(t,t*.35,t,Math.PI-(r+1)*Math.PI/e.options.length,Math.PI-r*Math.PI/e.options.length);return(0,W.jsx)(fn,{value:n.value,className:z(`pointer-events-auto absolute cursor-pointer transition-colors outline-none`,n.value===e.value&&`text-foreground bg-[color-mix(in_srgb,var(--primary)_30%,var(--popover))]`,n.value!==e.value&&`bg-popover text-secondary-label data-highlighted:bg-accent data-highlighted:text-accent-foreground`),style:i.style,children:(0,W.jsx)(`span`,{className:`absolute -translate-x-1/2 -translate-y-1/2 text-sm font-medium whitespace-nowrap`,style:i.center,children:n.label})},n.value)})})]})})]})}function yd(e){let t=R(e=>e.selection?.sessionId),n=R(t=>ft(t,e.machine,e.projectId)),r=R(e=>e.projects),i=R(e=>e.machines);return(0,W.jsx)(`div`,{className:`absolute inset-x-0 bottom-full pb-4`,children:(0,W.jsxs)(`h1`,{className:`text-foreground w-full text-center text-2xl font-normal tracking-tight sm:text-3xl`,children:[`What should we build in`,` `,t===null?(0,W.jsxs)(Qt,{children:[(0,W.jsx)(un,{asChild:!0,children:(0,W.jsxs)(`button`,{className:`border-muted-foreground/35 hover:border-foreground/60 inline-flex max-w-64 cursor-pointer border-b border-dotted align-bottom outline-none`,title:n?.path,children:[(0,W.jsx)(`span`,{className:`min-w-0 truncate`,children:n?.name}),`?`]})}),(0,W.jsx)(tn,{className:`max-h-80 w-64`,onCloseAutoFocus:t=>{t.preventDefault(),e.onCloseMenu()},children:(0,W.jsx)(rn,{value:_(e.machine,e.projectId),children:i.map(e=>({machine:e,items:r.filter(t=>t.machine===e.id)})).filter(e=>e.items.length>0).map(({machine:e,items:t},n)=>(0,W.jsxs)(U.Fragment,{children:[n>0&&(0,W.jsx)(Ht,{}),i.length>1&&(0,W.jsxs)(Jt,{className:`text-2xs flex items-center gap-1`,children:[(0,W.jsx)(Vu,{icon:e.icon,className:`size-3 shrink-0`}),(0,W.jsx)(`span`,{className:`truncate`,children:e.name})]}),t.map(e=>(0,W.jsxs)(ir,{value:_(e.machine,e.id),title:e.path,onSelect:()=>He({machine:e.machine,projectId:e.id,sessionId:null}),children:[(0,W.jsx)(zs,{machine:e.machine,projectId:e.id,className:`size-4 shrink-0 [&>img]:rounded-[4px] [&>svg]:rounded-[4px]`}),(0,W.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.name})]},_(e.machine,e.id)))]},e.id))})})]}):(0,W.jsx)(`span`,{className:`border-muted-foreground/35 inline-block max-w-64 truncate border-b border-dotted align-bottom`,title:n?.path,children:n?.name}),t!==null&&`?`]})})}function bd(){let e=R(e=>e.queue);return(0,W.jsx)(`div`,{className:`composer-glass relative mx-auto -mb-[calc(1rem+1px)] w-[calc(100%-2.75rem)] rounded-t-2xl border border-b-0 border-(--composer-outline) px-1 pt-1 pb-[calc(1rem+1px+0.25rem)] text-xs/4`,children:e.map(e=>(0,W.jsxs)(`div`,{className:`grid min-h-6 grid-cols-[1.5rem_minmax(0,1fr)_auto_auto] items-center gap-x-1`,children:[(0,W.jsx)(V,{icon:To,className:`text-muted-foreground mx-auto size-3`}),(0,W.jsx)(`span`,{className:`text-secondary-label truncate`,children:e.prompt.text===``?`${e.prompt.images.length} image(s)`:e.prompt.text}),(0,W.jsx)(H,{variant:`ghost-muted`,size:`icon-xs`,title:`Send now`,onClick:()=>Pe(e.id),children:(0,W.jsx)(V,{icon:Sn})}),(0,W.jsx)(H,{variant:`ghost-muted`,size:`icon-xs`,title:`Remove from queue`,onClick:()=>ve(e.id),children:(0,W.jsx)(V,{icon:st})})]},e.id))})}function xd(e){return(0,W.jsxs)(W.Fragment,{children:[e.running&&e.empty&&(0,W.jsx)(`button`,{className:`bg-destructive/90 shadow-destructive/24 hover:bg-destructive flex size-9 shrink-0 cursor-pointer items-center justify-center rounded-full text-white shadow-xs transition-colors`,title:`Stop (Esc)`,"aria-label":`Stop generation`,onClick:e.onStop,children:(0,W.jsx)(`svg`,{width:`12`,height:`12`,viewBox:`0 0 12 12`,fill:`currentColor`,"aria-hidden":`true`,children:(0,W.jsx)(`rect`,{x:`2`,y:`2`,width:`8`,height:`8`,rx:`1.5`})})}),!(e.running&&e.empty)&&(0,W.jsx)(`button`,{className:`bg-message-action text-message-action-foreground shadow-message-action/24 hover:bg-message-action-hover disabled:bg-foreground/12 disabled:text-muted-foreground relative flex size-9 items-center justify-center overflow-hidden rounded-full shadow-xs transition-all duration-150 hover:scale-105 enabled:cursor-pointer disabled:pointer-events-none disabled:shadow-none`,title:e.running&&e.delivery===`steer`?`Send now (Enter) · Queue (${Dt}+Enter)`:e.running?`Queue (Enter) · Send now (${Dt}+Enter)`:`Send (Enter)`,"aria-label":`Send message`,disabled:e.empty,onClick:t=>e.onSubmit(t.metaKey||t.ctrlKey),children:(0,W.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 14 14`,fill:`none`,"aria-hidden":`true`,children:(0,W.jsx)(`path`,{d:`M7 11.5V2.5M7 2.5L3 6.5M7 2.5L11 6.5`,stroke:`currentColor`,strokeWidth:`1.8`,strokeLinecap:`round`,strokeLinejoin:`round`})})})]})}var Sd=[`image/png`,`image/jpeg`,`image/gif`,`image/webp`],Cd=5242880,wd=window.matchMedia(`(pointer: coarse)`);function Td(){let e=R(e=>e.selection),t=R(e=>e.loaded),n=R(e=>e.items.length===0&&e.partial===``),r=R(e=>e.requests),i=R(e=>e.queue),a=R(e=>e.draft),o=R(e=>e.capabilities),c=R(e=>e.settings.provider===`opencode`?e.machines.find(t=>t.id===e.selection?.machine)?.openCode.available!==!0:e.settings.accountId===null),[l,u]=(0,U.useState)(!1),[d,f]=(0,U.useState)(0),[p,h]=(0,U.useState)(!1),[g,_]=(0,U.useState)([]),y=(0,U.useRef)(null),x=(0,U.useRef)(null),S=e?.machine??``,C=e?.projectId??``,w=R(e=>ft(e,S,C)),T=R(e=>I(e,S).status),E=R(e=>I(e,S).config?.delivery??null),D=e===null?``:Ne(e),O=v(D),k=O.text,A=O.images,j=O.files,[M,ee]=(0,U.useState)(k.length),te=R(gt),ne=t&&n&&!te,re=r.at(0);(0,U.useEffect)(()=>{let e=y.current;e===null||wd.matches||(e.focus(),e.setSelectionRange(e.value.length,e.value.length))},[e]),(0,U.useEffect)(()=>{if(a===null)return;let e=qu(a);m(D,t=>({...t,...e})),ee(e.text.length),ae(null),y.current?.focus()},[a,D]),(0,U.useEffect)(()=>{T===`online`&&N(S,`files.list`,{projectId:C}).then(_,mt)},[S,C,T]);let oe=k.slice(0,M),se=/^\/\S*$/.exec(oe)?.[0]??/(?:^|\s)(@\S*)$/.exec(oe)?.[1]??null,ce=se?.slice(1).toLowerCase()??``,le=se===null||p?[]:se.startsWith(`/`)?(o?.commands??[]).filter(e=>e.name.toLowerCase().includes(ce)).sort((e,t)=>Number(!e.name.toLowerCase().startsWith(ce))-Number(!t.name.toLowerCase().startsWith(ce))).map(e=>({key:e.name,label:`/${e.name}${e.hint===``?``:` ${e.hint}`}`,description:e.description,insert:`/${e.name}`})):g.filter(e=>e.toLowerCase().includes(ce)).slice(0,50).map(e=>({key:e,label:e,description:``,insert:`@${e}`})),ue=Math.min(d,le.length-1),de=k.trim()===``&&A.length===0||l||c;function fe(e,t){m(D,t=>({...t,text:e,images:t.images.filter(t=>e.includes(`[Image #${t.number}]`)),files:t.files.filter(t=>e.includes(Ed(t)))})),ee(t),f(0),h(!1)}function pe(e){if(se===null)return;let t=M-se.length,n=t+e.insert.length+1;fe(`${k.slice(0,t)}${e.insert} ${k.slice(M)}`,n),requestAnimationFrame(()=>y.current?.setSelectionRange(n,n))}async function P(e){if(!de){u(!0);try{if(E===null)throw Error(`This machine is not connected`);let t=k.trim();for(let e of j){let n=await ie(e.id);if(n===void 0)throw Error(`${e.name} is no longer saved, attach it again`);let r=await Hu(S,n);t=t.replace(Ed(e),()=>`@${r}`)}await We({text:t,images:A.map(e=>({mediaType:e.mediaType,data:e.data}))},e?E===`queue`?`steer`:`queue`:E),m(D,e=>({...e,text:``,images:[],files:[]})),ee(0)}catch(e){mt(e)}finally{u(!1)}}}async function F(e){let t=M,n=/(^|\s)$/.test(k.slice(0,M))?``:` `;for(let r of e){if(Sd.includes(r.type)&&r.size<=Cd){let e=await Uu(r),i=Ku(L().items,[b(D).text])+1,a={number:i,mediaType:r.type,data:e},o=t,s=`${n}[Image #${i}] `;n=``,m(D,e=>({...e,text:`${e.text.slice(0,o)}${s}${e.text.slice(o)}`,images:[...e.images,a]})),t+=s.length,ee(t),requestAnimationFrame(()=>y.current?.setSelectionRange(t,t));continue}if(r.size>52428800){mt(Error(`${r.name} is larger than 50 MB`));continue}let e=await s(r),i={number:Math.max(0,...b(D).files.map(e=>e.number))+1,id:e,name:r.name},a=t,o=`${n}${Ed(i)} `;n=``,m(D,e=>({...e,text:`${e.text.slice(0,a)}${o}${e.text.slice(a)}`,files:[...e.files,i]})),t+=o.length,ee(t),requestAnimationFrame(()=>y.current?.setSelectionRange(t,t))}}return(0,W.jsx)(`div`,{className:z(`pointer-events-none z-20`,ne?`absolute inset-0 flex items-center pb-3 sm:pb-4`:`relative shrink-0 before:absolute before:right-(--app-scrollbar-width) before:bottom-full before:left-0 before:h-8 before:bg-linear-to-t before:from-background before:to-transparent`),children:(0,W.jsxs)(Wu,{width:`composer`,className:`pointer-events-auto relative z-10`,children:[ne&&(0,W.jsx)(yd,{machine:S,projectId:C,onCloseMenu:()=>y.current?.focus()}),i.length>0&&le.length===0&&(0,W.jsx)(bd,{}),re!==void 0&&le.length===0&&(0,W.jsx)(ud,{request:re,machine:S,cwd:w?.path??``,count:r.length,draft:k},re.id),le.length>0&&(0,W.jsx)(Ju,{items:le,active:ue,onHover:f,onPick:pe}),(0,W.jsxs)(`div`,{className:z(`composer-glass shadow-composer relative z-10 border border-(--composer-outline) transition-[border-color,box-shadow] duration-150 ease-out focus-within:border-[color-mix(in_srgb,var(--text)_16%,transparent)] focus-within:ring-4 focus-within:ring-[color-mix(in_srgb,var(--text)_4%,transparent)] dark:shadow-none`,ne?`rounded-3xl`:`rounded-t-3xl border-b-0`,re?.kind===`question`&&`hidden`),onMouseDown:e=>{e.target instanceof Element&&e.currentTarget.contains(e.target)&&(e.target.closest(`button, a, input, textarea`)||(e.preventDefault(),y.current?.focus()))},onDragOver:e=>e.preventDefault(),onDrop:e=>{e.preventDefault(),F([...e.dataTransfer.files])},children:[(0,W.jsxs)(`div`,{className:z(`pb-2`,A.length>0&&`pt-3.5 sm:pt-4`),children:[A.length>0&&(0,W.jsx)(Gu,{draftKey:D}),(0,W.jsx)(`textarea`,{ref:y,"data-composer":!0,rows:1,spellCheck:!1,autoCorrect:`off`,"data-gramm":`false`,"data-gramm_editor":`false`,"data-enable-grammarly":`false`,"data-lt-active":`false`,value:k,onChange:e=>fe(e.target.value,e.target.selectionStart),onSelect:e=>ee(e.currentTarget.selectionStart),onPaste:e=>{let t=e.clipboardData.getData(`text/plain`);if(t!==``){e.preventDefault(),document.execCommand(`insertText`,!1,t);return}let n=[...e.clipboardData.files];n.length!==0&&(e.preventDefault(),F(n))},onKeyDown:e=>{if(!e.nativeEvent.isComposing){if(le.length>0){if(e.key===`ArrowDown`||e.key===`ArrowUp`){e.preventDefault();let t=e.key===`ArrowDown`?1:-1;f((ue+t+le.length)%le.length);return}if(e.key===`Enter`&&!e.shiftKey||e.key===`Tab`){e.preventDefault(),pe(le[ue]);return}if(e.key===`Escape`){e.preventDefault(),h(!0);return}}if(e.key===`Enter`&&!e.shiftKey&&!wd.matches)e.preventDefault(),P(e.metaKey||e.ctrlKey);else if(e.key===`ArrowUp`&&k===``){let t=Dd(L().items);if(t===null)return;e.preventDefault(),fe(t,t.length)}else e.key===`Escape`&&te&&xe()}},placeholder:c?`Add an account in Settings to start`:te&&E===`steer`?`Steer the agent… (${Dt}+Enter to queue)`:te?`Queue a follow-up… (${Dt}+Enter to send now)`:`Ask anything, @tag files/folders, or / for commands`,className:z(`placeholder:text-placeholder/75 block [field-sizing:content] w-full resize-none bg-transparent px-3 text-sm leading-relaxed outline-none sm:px-4`,A.length>0?`max-h-52 min-h-19.5`:`max-h-55.5 min-h-20 pt-3.5 sm:max-h-56 sm:pt-4 [@media(min-height:840px)]:min-h-23 sm:[@media(min-height:840px)]:min-h-23.5`)})]}),(0,W.jsxs)(`div`,{className:z(`flex min-w-0 items-center justify-between gap-2 px-3 sm:px-3.5`,ne?`pb-2.5 sm:pb-3.5`:`pb-2 sm:pb-3`),children:[(0,W.jsx)(`div`,{className:`-m-1 -ms-3.5 flex min-w-0 flex-1 [scrollbar-width:none] items-center gap-1 overflow-x-auto p-1 ps-3 sm:ps-4`,children:(0,W.jsx)(gd,{})}),(0,W.jsxs)(`div`,{className:`flex shrink-0 items-center justify-end gap-2`,children:[(0,W.jsx)(`input`,{ref:x,type:`file`,multiple:!0,hidden:!0,onChange:e=>{F([...e.target.files??[]]),e.target.value=``}}),l&&j.length>0&&(0,W.jsx)(`span`,{className:`text-muted-foreground text-xs`,children:`Uploading…`}),(0,W.jsx)(Zu,{empty:de,delivery:E,onSubmit:()=>void P(!0)}),(0,W.jsx)(H,{variant:`ghost`,size:`icon-sm`,title:`Attach files`,"aria-label":`Attach files`,onClick:()=>x.current?.click(),children:(0,W.jsx)(V,{icon:Io})}),(0,W.jsx)(xd,{running:te,empty:de,delivery:E,onSubmit:e=>void P(e),onStop:xe})]})]})]})]})})}function Ed(e){return`[File #${e.number}: ${e.name}]`}function Dd(e){for(let t=e.length-1;t>=0;t--){let n=e[t];if(n.kind===`user`&&n.parent===null&&n.format===`text`&&n.text!==``)return n.text}return null}var Od={working:Pn,done:eo,failed:Dn},kd=new Set,Ad=null,jd=0,Md={open:!1,label:``,error:``};function Nd(e){Ad!==null&&Ad.id!==e.id&&Ai.dismiss(Ad.id),Ad=e,Ai.custom(()=>(0,W.jsx)(Bd,{toast:e}),{id:e.id,duration:e.state===`done`?5e3:1/0,onDismiss:()=>{Ad?.id===e.id&&(Ad=null)}})}function Pd(e){Md=e;for(let e of kd)e()}function Fd(e){return kd.add(e),()=>{kd.delete(e)}}function Id(e,t){jd+=1;let n=`git-${jd}`;Nd(`url`in t?{id:n,state:`done`,label:e,error:``,url:t.url}:{id:n,state:`failed`,label:e,error:t.error,url:null})}async function Ld(e){jd+=1;let t=`git-${jd}`;Nd({id:t,state:`working`,label:e.labels.working,error:``,url:null});try{let n=await e.task();Ad?.id===t&&Nd({id:t,state:`done`,label:e.labels.done,error:``,url:n})}catch(n){Ad?.id===t&&Nd({id:t,state:`failed`,label:e.labels.failed,error:Ot(n),url:null})}finally{e.onRefresh()}}function Rd(e,t,n,r){Ld({labels:r?{working:`Committing and pushing…`,done:`Committed and pushed`,failed:`Commit and push failed`}:{working:`Committing…`,done:`Committed`,failed:`Commit failed`},task:async()=>(await N(e.machine,`git.commit`,{projectId:e.projectId,repo:t,message:n,push:r}),null),onRefresh:e.onRefresh})}function zd(e,t,n){Ld({labels:{working:`Creating pull request…`,done:`Pull request created`,failed:`Couldn't create pull request`},task:async()=>(await N(e.machine,`git.createPullRequest`,{projectId:e.projectId,repo:t,base:n.base,head:n.head,title:n.title,body:n.body})).url,onRefresh:e.onRefresh})}function Bd(e){return(0,W.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,W.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-2`,children:[(0,W.jsx)(V,{icon:Od[e.toast.state],className:z(`size-4 shrink-0`,e.toast.state===`working`&&`animate-spin`,e.toast.state===`done`&&`text-success`,e.toast.state===`failed`&&`text-destructive`)}),(0,W.jsx)(`span`,{className:`truncate`,children:e.toast.label})]}),e.toast.url!==null&&(0,W.jsx)(H,{asChild:!0,size:`xs`,variant:`outline`,children:(0,W.jsx)(`a`,{href:e.toast.url,target:`_blank`,rel:`noopener noreferrer`,children:`Open`})}),e.toast.state===`failed`&&(0,W.jsx)(H,{type:`button`,size:`xs`,variant:`outline`,onClick:()=>Pd({open:!0,label:e.toast.label,error:e.toast.error}),children:`View`}),(0,W.jsx)(H,{type:`button`,size:`icon-micro`,variant:`ghost-muted`,"aria-label":`Dismiss`,onClick:()=>Ai.dismiss(e.toast.id),children:(0,W.jsx)(V,{icon:st,className:`size-3.5`})})]})}function Vd(){let e=(0,U.useSyncExternalStore)(Fd,()=>Md);return(0,W.jsx)(Or,{open:e.open,onOpenChange:t=>Pd({...e,open:t}),children:(0,W.jsxs)(xr,{className:`sm:max-w-lg`,children:[(0,W.jsx)(Sr,{children:(0,W.jsx)(Tr,{children:e.label})}),(0,W.jsx)(`pre`,{className:`bg-muted/50 max-h-[60vh] overflow-y-auto rounded-lg border p-3 font-mono text-xs break-words whitespace-pre-wrap`,children:e.error})]})})}function Hd({className:e,type:t,...n}){return(0,W.jsx)(`input`,{type:t,"data-slot":`input`,className:z(`h-9 w-full min-w-0 rounded-lg border border-input bg-transparent px-2.5 py-1 text-base transition-[color,background-color,border-color,box-shadow] duration-200 ease-out outline-none file:inline-flex file:h-6 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/33 disabled:pointer-events-none disabled:cursor-not-allowed disabled:bg-input/50 disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:disabled:bg-input/80 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40`,e),...n})}function Ud({...e}){return(0,W.jsx)(pc,{"data-slot":`select`,...e})}function Wd({...e}){return(0,W.jsx)(_c,{"data-slot":`select-value`,...e})}function Gd({className:e,size:t=`default`,children:n,...r}){return(0,W.jsxs)(hc,{"data-slot":`select-trigger`,"data-size":t,className:z(`flex w-fit items-center justify-between gap-1.5 rounded-lg border border-input bg-transparent py-2 pr-2 pl-2.5 text-sm whitespace-nowrap transition-[color,background-color,border-color,box-shadow] duration-200 ease-out outline-none select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/33 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 data-placeholder:text-muted-foreground data-[size=default]:h-9 data-[size=sm]:h-8 data-[size=sm]:rounded-[min(var(--radius-md),10px)] *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-1.5 dark:bg-input/30 dark:hover:bg-input/50 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,e),...r,children:[n,(0,W.jsx)(vc,{asChild:!0,children:(0,W.jsx)(V,{icon:dr,className:`text-muted-foreground pointer-events-none size-4`})})]})}function Kd({className:e,children:t,position:n=`item-aligned`,align:r=`center`,...i}){return(0,W.jsx)(xc,{children:(0,W.jsxs)(Cc,{"data-slot":`select-content`,"data-align-trigger":n===`item-aligned`,className:z(`relative z-50 max-h-(--radix-select-content-available-height) min-w-36 origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-lg bg-popover text-popover-foreground shadow-md ring-1 ring-foreground/10 duration-100 data-[align-trigger=true]:animate-none data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95`,n===`popper`&&`data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1`,e),position:n,align:r,...i,children:[(0,W.jsx)(qd,{}),(0,W.jsx)(Fc,{"data-position":n,className:z(`data-[position=popper]:h-(--radix-select-trigger-height) data-[position=popper]:w-full data-[position=popper]:min-w-(--radix-select-trigger-width)`,n===`popper`&&``),children:t}),(0,W.jsx)(Jd,{})]})})}function X({className:e,children:t,...n}){return(0,W.jsxs)(Vc,{"data-slot":`select-item`,className:z(`relative flex w-full cursor-default items-center gap-1.5 rounded-md py-1 pr-8 pl-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2`,e),...n,children:[(0,W.jsx)(`span`,{className:`pointer-events-none absolute right-2 flex size-4 items-center justify-center`,children:(0,W.jsx)(Gc,{children:(0,W.jsx)(V,{icon:Xn,className:`pointer-events-none`})})}),(0,W.jsx)(Uc,{children:t})]})}function qd({className:e,...t}){return(0,W.jsx)(qc,{"data-slot":`select-scroll-up-button`,className:z(`z-10 flex cursor-default items-center justify-center bg-popover py-1 [&_svg:not([class*='size-'])]:size-4`,e),...t,children:(0,W.jsx)(V,{icon:$a})})}function Jd({className:e,...t}){return(0,W.jsx)(Yc,{"data-slot":`select-scroll-down-button`,className:z(`z-10 flex cursor-default items-center justify-center bg-popover py-1 [&_svg:not([class*='size-'])]:size-4`,e),...t,children:(0,W.jsx)(V,{icon:cr})})}function Yd(e){return e.target?.kind===`failed`?(0,W.jsx)(`span`,{className:`text-destructive truncate text-xs`,children:e.target.text}):(0,W.jsxs)(`span`,{className:`text-muted-foreground flex min-w-0 items-center gap-1.5 text-xs`,children:[(0,W.jsxs)(`span`,{className:`truncate`,children:[e.head,` →`]}),(0,W.jsxs)(Ud,{value:e.target?.base??``,disabled:e.target===void 0,onValueChange:e.onBase,children:[(0,W.jsx)(Gd,{size:`sm`,className:`max-w-48`,children:(0,W.jsx)(Wd,{placeholder:`Loading branches…`})}),(0,W.jsx)(Kd,{children:(e.target?.branches??[]).map(e=>(0,W.jsx)(X,{value:e,children:e},e))})]})]})}function Xd(e){return(0,W.jsxs)(`div`,{className:`flex flex-col gap-2 ps-6`,children:[(0,W.jsxs)(`span`,{className:`text-muted-foreground truncate text-xs`,children:[e.draft.head,` → `,e.draft.base]}),(0,W.jsx)(Hd,{value:e.draft.title,onChange:t=>e.onChange({...e.draft,title:t.target.value})}),(0,W.jsx)(`textarea`,{value:e.draft.body,onChange:t=>e.onChange({...e.draft,body:t.target.value}),rows:8,className:`bg-background focus-visible:border-ring focus-visible:ring-ring/33 w-full resize-y rounded-lg border px-3 py-2 font-mono text-xs transition-[border-color,box-shadow] duration-200 ease-out outline-none focus-visible:ring-3`}),(0,W.jsxs)(`div`,{className:`flex flex-wrap justify-end gap-2`,children:[e.onSkip!==null&&(0,W.jsx)(H,{variant:`ghost`,size:`sm`,onClick:e.onSkip,children:`Skip`}),(0,W.jsx)(H,{variant:`outline`,size:`sm`,onClick:e.onRegenerate,children:`Regenerate`}),(0,W.jsx)(H,{size:`sm`,disabled:e.draft.title.trim()===``,onClick:e.onCreate,children:`Create PR`})]})]})}var Zd={working:Pn,review:no,done:eo,failed:Dn,skipped:No};function Qd(e){let t=R(t=>ft(t,e.machine,e.projectId)?.name)??``,[n]=(0,U.useState)(()=>$d(e.repos,e.action)),[r,i]=(0,U.useState)(()=>n.map(e=>e.path)),[a,o]=(0,U.useState)(``),[s,c]=(0,U.useState)({}),[l,u]=(0,U.useState)(null),d=n.filter(e=>r.includes(e.path)&&s[e.path]?.kind!==`failed`),f=e.action===`pullRequest`&&d.some(e=>s[e.path]===void 0),p=d.filter(e=>e.changed>0);(0,U.useEffect)(()=>{if(e.action===`pullRequest`)for(let t of n)N(e.machine,`git.branches`,{projectId:e.projectId,repo:t.path}).then(e=>c(n=>({...n,[t.path]:{kind:`ready`,...e}})),e=>c(n=>({...n,[t.path]:{kind:`failed`,text:Ot(e)}})))},[e.machine,e.projectId,e.action,n]);function m(e,t){u(n=>n?.map(n=>n.path===e?{...n,...t}:n)??null)}async function h(t,r){try{await r()}catch(r){if(n.length===1){e.onClose(),Id(`Pull request failed`,{error:Ot(r)});return}m(t,{state:`failed`,text:Ot(r),draft:null})}finally{e.onRefresh()}}function g(e,t){c(n=>{let r=n[e];return r?.kind===`ready`?{...n,[e]:{...r,base:t}}:n})}function _(e,t){u(d.map(t=>({path:t.path,state:`working`,text:e,url:null,draft:null})));for(let e of d)h(e.path,()=>t(e.path))}function v(t){if(n.length===1){e.onClose(),Rd(e,n[0].path,a,t);return}let r=t?`Committed and pushed`:`Committed`;_(t?`Committing and pushing…`:`Committing…`,async n=>{await N(e.machine,`git.commit`,{projectId:e.projectId,repo:n,message:a,push:t}),m(n,{state:`done`,text:r})})}function y(){_(`Pushing…`,async t=>{await N(e.machine,`git.push`,{projectId:e.projectId,repo:t}),m(t,{state:`done`,text:`Pushed`})})}async function b(t,r,i){m(t,{state:`working`,text:r?`Committing local changes and writing pull request…`:`Writing pull request…`,draft:null});let a=await N(e.machine,`git.pullRequest`,{projectId:e.projectId,repo:t,base:i,commit:r});if(a.kind===`open`){if(n.length===1){e.onClose(),Id(`Pull request already open`,{url:a.url});return}m(t,{state:`done`,text:`A pull request is already open`,url:a.url})}else m(t,{state:`review`,text:`Review and create`,draft:{base:a.base,head:a.head,title:a.title,body:a.body}})}function x(e){_(`Starting…`,async t=>{let n=s[t];if(n?.kind!==`ready`)throw Error(`The branches are not loaded`);await b(t,e&&p.some(e=>e.path===t),n.base)})}function S(t,r){n.length===1?(e.onClose(),zd(e,t,r)):h(t,async()=>{m(t,{state:`working`,text:`Creating pull request…`,draft:null}),m(t,{state:`done`,text:`Created pull request`,url:(await N(e.machine,`git.createPullRequest`,{projectId:e.projectId,repo:t,base:r.base,head:r.head,title:r.title,body:r.body})).url})})}return(0,W.jsx)(Or,{open:!0,onOpenChange:()=>e.onClose(),children:(0,W.jsxs)(xr,{className:`top-[12vh] translate-y-0 sm:max-w-lg`,children:[(0,W.jsxs)(Sr,{children:[(0,W.jsxs)(Tr,{children:[e.action===`commit`&&`Commit changes`,e.action===`push`&&`Push`,e.action===`pullRequest`&&`Create pull request`]}),(0,W.jsxs)(Er,{children:[e.action===`commit`&&(n.length===1?`Stages every change and commits it.`:`Stages every change in the selected repositories and commits it.`),e.action===`push`&&`Pushes the selected repositories to their remote.`,e.action===`pullRequest`&&`AI writes the title and description. You review them before the pull request is created.`]})]}),l===null&&(0,W.jsxs)(W.Fragment,{children:[n.length===1&&(0,W.jsxs)(`div`,{className:`text-muted-foreground flex items-center gap-1.5 text-xs`,children:[e.action===`pullRequest`?(0,W.jsx)(Yd,{head:n[0].branch??`detached`,target:s[n[0].path],onBase:e=>g(n[0].path,e)}):n[0].branch??`detached`,(0,W.jsxs)(`span`,{className:`shrink-0`,children:[`· `,n[0].changed,` `,n[0].changed===1?`change`:`changes`]})]}),n.length>1&&(0,W.jsx)(`div`,{className:`flex max-h-60 flex-col gap-0.5 overflow-y-auto`,children:n.map(n=>(0,W.jsxs)(`label`,{className:`hover:bg-accent flex cursor-pointer items-center gap-2 rounded-md px-2 py-1.5`,children:[(0,W.jsx)(`input`,{type:`checkbox`,disabled:s[n.path]?.kind===`failed`,checked:r.includes(n.path)&&s[n.path]?.kind!==`failed`,onChange:e=>i(e.target.checked?[...r,n.path]:r.filter(e=>e!==n.path))}),(0,W.jsx)(`span`,{className:`truncate font-medium`,children:ef(n.path,t)}),e.action===`pullRequest`?(0,W.jsx)(Yd,{head:n.branch??`detached`,target:s[n.path],onBase:e=>g(n.path,e)}):(0,W.jsx)(`span`,{className:`text-muted-foreground truncate text-xs`,children:n.branch??`detached`}),(0,W.jsx)(`span`,{className:`text-muted-foreground ml-auto shrink-0 text-xs tabular-nums`,children:e.action===`push`?n.upstream===null?`not pushed yet`:`↑${n.ahead}`:n.changed>0&&`${n.changed} ${n.changed===1?`change`:`changes`}`})]},n.path))}),e.action===`commit`&&(0,W.jsx)(`textarea`,{value:a,onChange:e=>o(e.target.value),placeholder:`Leave empty to write the message with AI`,rows:5,className:`bg-background focus-visible:border-ring focus-visible:ring-ring/33 w-full resize-none rounded-lg border px-3 py-2 font-mono text-xs transition-[border-color,box-shadow] duration-200 ease-out outline-none focus-visible:ring-3`}),e.action===`pullRequest`&&p.length>0&&(0,W.jsxs)(`p`,{children:[`You have local changes`,n.length>1&&` in ${p.map(e=>ef(e.path,t)).join(`, `)}`,`. Do you want to commit and push them before creating the pull request?`]}),(0,W.jsxs)(`div`,{className:`flex flex-wrap justify-end gap-2`,children:[e.action===`commit`&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(H,{variant:`outline`,size:`sm`,disabled:d.length===0,onClick:()=>v(!1),children:`Commit`}),(0,W.jsx)(H,{size:`sm`,disabled:d.length===0,onClick:()=>v(!0),children:`Commit and Push`})]}),e.action===`push`&&(0,W.jsx)(H,{size:`sm`,disabled:d.length===0,onClick:y,children:`Push`}),e.action===`pullRequest`&&p.length>0&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(H,{variant:`outline`,size:`sm`,disabled:f,onClick:()=>x(!1),children:`Continue without them`}),(0,W.jsx)(H,{size:`sm`,disabled:f,onClick:()=>x(!0),children:`Commit and continue`})]}),e.action===`pullRequest`&&p.length===0&&(0,W.jsx)(H,{size:`sm`,disabled:f||d.length===0,onClick:()=>x(!1),children:`Create pull request`})]})]}),l!==null&&(0,W.jsx)(`div`,{className:`flex max-h-[60vh] flex-col gap-2 overflow-y-auto`,children:l.map(e=>{let r=e.draft;return(0,W.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,W.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,W.jsx)(`span`,{className:`mt-0.5 flex size-4 shrink-0 overflow-hidden`,children:(0,W.jsx)(V,{icon:Zd[e.state],className:z(`size-4`,e.state===`working`&&`animate-spin`,e.state===`review`&&`text-info`,e.state===`done`&&`text-success`,e.state===`failed`&&`text-destructive`,e.state===`skipped`&&`text-muted-foreground`)})}),(0,W.jsx)(`span`,{className:`shrink-0 font-medium`,children:ef(e.path,t)}),(0,W.jsxs)(`span`,{className:z(`min-w-0 text-xs leading-5 break-words whitespace-pre-wrap`,e.state===`failed`?`text-destructive`:`text-muted-foreground`),children:[e.text,e.url!==null&&(0,W.jsxs)(W.Fragment,{children:[` `,(0,W.jsx)(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,className:`text-primary hover:underline hover:underline-offset-2`,children:e.url})]})]})]}),e.state===`review`&&r!==null&&(0,W.jsx)(Xd,{draft:r,onChange:t=>m(e.path,{draft:t}),onSkip:n.length===1?null:()=>m(e.path,{state:`skipped`,text:`Skipped`,draft:null}),onRegenerate:()=>void h(e.path,()=>b(e.path,!1,r.base)),onCreate:()=>S(e.path,r)})]},e.path)})})]})})}function $d(e,t){if(t===`commit`)return e.filter(e=>e.changed>0);if(t===`push`)return e.filter(e=>e.branch!==null&&(e.upstream===null||e.ahead>0));if(t===`pullRequest`)return e.filter(e=>e.branch!==null);throw Error(`Unknown git action ${String(t)}`)}function ef(e,t){return e===``?t:e}var tf=3e3,nf=18e4;function rf(e,t,n){let[r,i]=(0,U.useState)(null),[a,o]=(0,U.useState)(0);(0,U.useEffect)(()=>{if(t===null)return;let n=_(e,t),r={projectId:t},a=!0,o=!1,s=!1;async function c(){if(!o){o=!0;try{let t=await N(e,`git.status`,r);if(!a)return;s=!1,i(e=>e!==null&&e.key===n&&ue(e.repos,t)?e:{key:n,repos:t})}catch(e){a&&!s&&(s=!0,mt(e))}finally{o=!1}}}function l(){document.hidden||c()}c();let u=window.setInterval(l,tf);return window.addEventListener(`focus`,l),()=>{a=!1,window.clearInterval(u),window.removeEventListener(`focus`,l)}},[e,t,n,a]),(0,U.useEffect)(()=>{if(t===null)return;let n={projectId:t},r=!0,i=!1;async function a(){if(!document.hidden)try{await N(e,`git.fetch`,n),r&&(i=!1,o(e=>e+1))}catch(e){r&&!i&&(i=!0,mt(e))}}a();let s=window.setInterval(a,nf);return()=>{r=!1,window.clearInterval(s)}},[e,t]);let s=(0,U.useCallback)(()=>o(e=>e+1),[]);return{repos:r!==null&&t!==null&&r.key===_(e,t)?r.repos:[],refresh:s}}function af(e){let[t,n]=(0,U.useState)(null),[r,i]=(0,U.useState)(!1),[a,o]=(0,U.useState)(null),[s,c]=(0,U.useState)(!1),l=$d(e.repos,`push`),u=$d(e.repos,`commit`);function d(t){Ld({labels:{working:`Pushing…`,done:`Pushed`,failed:`Push failed`},task:async()=>(await N(e.machine,`git.push`,{projectId:e.projectId,repo:t}),null),onRefresh:e.onRefresh})}async function f(){if(u.length===1)i(!1),Rd(e,u[0].path,``,!1);else{c(!0);try{for(let t of u)await N(e.machine,`git.commit`,{projectId:e.projectId,repo:t.path,message:``,push:!1});i(!1)}catch(e){mt(e)}finally{c(!1),e.onRefresh()}}}return{target:e,action:t,setAction:n,menuOpen:r,setMenuOpen:i,branchRepo:a,setBranchRepo:o,committing:s,pushable:l,committable:u,push:d,yoloCommit:f}}function of(e){let t=e.git,n=t.target.repos,r=n.reduce((e,t)=>e+t.ahead,0);return(0,W.jsxs)(W.Fragment,{children:[e.collapsed&&n.map(e=>(0,W.jsxs)(Gt,{onSelect:()=>t.setBranchRepo(e.path),children:[(0,W.jsx)(V,{icon:jn}),(0,W.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.path===``?e.branch??`detached`:`${e.path}: ${e.branch??`detached`}`}),(0,W.jsx)(`span`,{className:`text-muted-foreground flex gap-1 text-xs`,children:(0,W.jsx)(an,{behind:e.behind,ahead:e.ahead})})]},e.path)),e.collapsed&&(0,W.jsx)(Ht,{}),e.collapsed&&(0,W.jsxs)(Gt,{disabled:t.committable.length===0,onSelect:()=>t.setAction(`commit`),children:[(0,W.jsx)(V,{icon:po}),`Commit…`]}),(0,W.jsxs)(Gt,{disabled:t.pushable.length===0||t.committing,onSelect:()=>{t.pushable.length===1?t.push(t.pushable[0].path):t.setAction(`push`)},children:[(0,W.jsx)(V,{icon:Kn}),t.pushable.length>1?`Just Push…`:`Just Push`,r>0&&(0,W.jsxs)(`span`,{className:`text-muted-foreground ml-auto text-xs tabular-nums`,children:[`↑`,r]})]}),(0,W.jsxs)(Gt,{disabled:t.committable.length===0||t.committing,onSelect:e=>{e.preventDefault(),t.yoloCommit()},children:[(0,W.jsx)(V,{icon:t.committing?Pn:po,className:z(t.committing&&`animate-spin`)}),t.committing?`Committing…`:`Yolo Commit`]}),(0,W.jsx)(Ht,{}),(0,W.jsxs)(Gt,{disabled:$d(n,`pullRequest`).length===0,onSelect:()=>t.setAction(`pullRequest`),children:[(0,W.jsx)(V,{icon:go}),`Create pull request…`]})]})}function sf(e){let t=e.git,n=t.target.repos.find(e=>e.path===t.branchRepo);return(0,W.jsxs)(W.Fragment,{children:[t.action!==null&&(0,W.jsx)(Qd,{machine:t.target.machine,projectId:t.target.projectId,action:t.action,repos:t.target.repos,onClose:()=>t.setAction(null),onRefresh:t.target.onRefresh}),t.branchRepo!==null&&n!==void 0&&(0,W.jsx)(vn,{machine:t.target.machine,projectId:t.target.projectId,repo:n,onRefresh:t.target.onRefresh,onClose:()=>t.setBranchRepo(null)})]})}function cf(e){let t=af(e),[n,r]=(0,U.useState)(!1),i=[...new Set(e.repos.map(e=>e.branch??`detached`))],a=e.repos.flatMap(e=>{let t=Ut(e);return t===null?[]:[{repo:e,next:t}]}),o=e.repos.map(e=>e.path===``?e.branch??`detached`:`${e.path}: ${e.branch??`detached`}`).join(`
|
|
12
12
|
`),s=i.length===1?i[0]:`${i.length} branches`;async function c(t){r(!0);try{await N(e.machine,`git.sync`,{projectId:e.projectId,repo:t})}catch(e){mt(e)}finally{r(!1),e.onRefresh()}}return(0,W.jsxs)(W.Fragment,{children:[e.repos.length===1&&(0,W.jsx)(er,{machine:e.machine,projectId:e.projectId,repo:e.repos[0],onRefresh:e.onRefresh}),e.repos.length>1&&a.length===0&&(0,W.jsxs)(`span`,{className:`text-muted-foreground hidden max-w-48 items-center gap-1 text-xs sm:flex`,title:o,children:[(0,W.jsx)(V,{icon:jn,className:`size-3.5 shrink-0`}),(0,W.jsx)(`span`,{className:`truncate`,children:s})]}),e.repos.length>1&&a.length>0&&(0,W.jsxs)(Qt,{children:[(0,W.jsx)(un,{asChild:!0,children:(0,W.jsxs)(`button`,{className:`text-muted-foreground hover:text-foreground hidden max-w-48 cursor-pointer items-center gap-1 text-xs sm:flex`,title:o,children:[(0,W.jsx)(V,{icon:n?Pn:a.length===1?a[0].next.icon:kn,className:z(`size-3.5 shrink-0`,n&&`animate-spin`)}),(0,W.jsx)(`span`,{className:`truncate`,children:s})]})}),(0,W.jsx)(tn,{align:`end`,className:`w-64`,children:a.map(e=>(0,W.jsxs)(Gt,{disabled:n,onSelect:()=>void c(e.repo.path),children:[(0,W.jsx)(V,{icon:e.next.icon}),(0,W.jsxs)(`span`,{className:`min-w-0 flex-1 truncate`,children:[e.next.label,` ·`,` `,e.repo.path===``?e.repo.branch:e.repo.path]}),(0,W.jsx)(`span`,{className:`text-muted-foreground flex gap-1 text-xs`,children:(0,W.jsx)(an,{behind:e.repo.behind,ahead:e.repo.ahead})})]},e.repo.path))})]}),(0,W.jsxs)(`div`,{className:`ml-2.5 flex w-fit`,children:[(0,W.jsxs)(H,{variant:`outline`,size:`xs`,className:`rounded-e-none border-e-0`,disabled:t.committable.length===0,onClick:()=>t.setAction(`commit`),children:[(0,W.jsx)(V,{icon:po}),(0,W.jsx)(`span`,{className:`hidden sm:inline`,children:`Commit`})]}),(0,W.jsxs)(Qt,{open:t.menuOpen,onOpenChange:t.setMenuOpen,children:[(0,W.jsx)(un,{asChild:!0,children:(0,W.jsx)(H,{variant:`outline`,size:`icon-xs`,className:`rounded-s-none`,"aria-label":`Git actions`,children:(0,W.jsx)(V,{icon:t.committing?Pn:cr,className:z(`size-4`,t.committing&&`animate-spin`)})})}),(0,W.jsx)(tn,{align:`end`,className:`w-56`,children:(0,W.jsx)(of,{git:t,collapsed:!1})})]})]}),(0,W.jsx)(sf,{git:t})]})}function lf({className:e,size:t=`default`,...n}){return(0,W.jsx)(ml,{"data-slot":`switch`,"data-size":t,className:z(`peer group/switch relative inline-flex shrink-0 items-center rounded-full border border-transparent transition-all outline-none group-has-[:focus-visible]/field-label:border-transparent group-has-[:focus-visible]/field-label:ring-0 after:absolute after:-inset-x-3 after:-inset-y-2 focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 data-[size=default]:h-[18.4px] data-[size=default]:w-[32px] data-[size=sm]:h-[14px] data-[size=sm]:w-[24px] dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 data-checked:bg-primary data-unchecked:bg-input dark:data-unchecked:bg-input/80 data-disabled:cursor-not-allowed data-disabled:opacity-50`,e),...n,children:(0,W.jsx)(gl,{"data-slot":`switch-thumb`,className:`bg-background dark:data-checked:bg-primary-foreground dark:data-unchecked:bg-foreground pointer-events-none block rounded-full ring-0 transition-transform group-data-[size=default]/switch:size-4 group-data-[size=sm]/switch:size-3 group-data-[size=default]/switch:data-checked:translate-x-[calc(100%-2px)] group-data-[size=sm]/switch:data-checked:translate-x-[calc(100%-2px)] group-data-[size=default]/switch:data-unchecked:translate-x-0 group-data-[size=sm]/switch:data-unchecked:translate-x-0`})})}var uf=`3.6.8`,df=`1.3.1`,ff=[{family:`FiraCode Nerd Font`,label:`Fira Code`},{family:`JetBrainsMono Nerd Font`,label:`JetBrains Mono`},{family:`CaskaydiaCove Nerd Font`,label:`Cascadia Code`},{family:`Hack Nerd Font`,label:`Hack`}],pf=[{value:`macos`,label:`macOS`},{value:`linux`,label:`Linux`},{value:`windows`,label:`Windows`}];async function mf(e){let t=`${e.font.size}px ${e.font.family}`;await Promise.all([document.fonts.load(t),document.fonts.load(`bold ${t}`)]);let n=document.documentElement.style;n.setProperty(`--pad-top`,`${e.padding.top}px`),n.setProperty(`--pad-right`,`${e.padding.right}px`),n.setProperty(`--pad-bottom`,`${e.padding.bottom}px`),n.setProperty(`--pad-left`,`${e.padding.left}px`)}function hf(e,t){let n=k();return{fontFamily:e.font.family,fontSize:e.font.size,lineHeight:e.font.lineHeight,ligatures:e.font.ligatures,cursorStyle:e.cursor.style,cursorBlink:e.cursor.blink,scrollback:e.scrollback,boldIsBright:e.boldIsBright,colors:{background:n.background,foreground:n.foreground,cursor:n.cursor,cursorText:n.background,selectionBackground:n.selectionBackground,selectionForeground:n.foreground,palette:n.palette},version:gf(t),clickToMoveCursor:e.behavior.clickToMoveCursor,optionAsMeta:e.behavior.optionAsMeta,windowsCopyPaste:e.behavior.windowsCopyPaste}}function gf(e){if(e===`offsite`)return`offsite 0.0.0`;if(e===`ghostty`)return`ghostty ${df}`;if(e===`iterm2`)return`iTerm2 ${uf}`;throw Error(`unknown terminal identity ${e}`)}function _f(e){return(0,W.jsxs)(`section`,{children:[(0,W.jsxs)(`h2`,{className:`text-muted-foreground mb-2 px-1 text-xs font-medium`,children:[e.title,e.note&&(0,W.jsxs)(`span`,{className:`font-normal`,children:[` · `,e.note]})]}),(0,W.jsx)(`div`,{className:`@container divide-y overflow-hidden rounded-xl border`,children:e.children})]})}function Z(e){return(0,W.jsxs)(`label`,{className:`flex min-h-13 flex-wrap items-center gap-x-4 gap-y-2 px-4 py-2.5`,children:[(0,W.jsx)(`span`,{className:`min-w-0 flex-1 basis-40 text-sm font-medium`,children:e.label}),(0,W.jsx)(`div`,{className:`max-w-full shrink-0 @max-lg:has-[[data-slot=select-trigger],input:not([type=number])]:w-full @max-lg:has-[[data-slot=select-trigger],input:not([type=number])]:*:w-full @max-lg:**:data-[slot=select-trigger]:w-full`,children:e.children})]})}function vf(e){let[t,n]=(0,U.useState)(e.value);function r(){t!==e.value&&(e.valid&&!e.valid(t)?n(e.value):e.onCommit(t))}return(0,W.jsx)(Hd,{className:z(`w-56`,e.className),type:e.type,min:e.type===`number`?0:void 0,step:e.step,placeholder:e.placeholder,disabled:e.disabled,value:t,onChange:e=>n(e.target.value),onBlur:r,onKeyDown:e=>{e.key===`Enter`&&e.currentTarget.blur()}})}function yf(e){return(0,W.jsx)(vf,{type:`number`,className:`w-24`,step:e.step??1,value:String(e.value),valid:e=>e!==``&&Number(e)>=0,onCommit:t=>e.onCommit(Number(t))},e.value)}function bf(e){let t=e.prefs.editor,[n,r]=(0,U.useState)(!ff.some(e=>e.family===t.font.family));function a(t){i({...e.prefs,editor:t})}function o(e,n){a({...t,[e]:{...t[e],...n}})}return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(_f,{title:`Font`,children:[(0,W.jsx)(Z,{label:`Family`,children:(0,W.jsxs)(Ud,{value:n?`custom`:t.font.family,onValueChange:e=>{r(e===`custom`),e!==`custom`&&o(`font`,{family:e})},children:[(0,W.jsx)(Gd,{className:`w-56`,children:(0,W.jsx)(Wd,{})}),(0,W.jsxs)(Kd,{children:[ff.map(e=>(0,W.jsx)(X,{value:e.family,children:e.label},e.family)),(0,W.jsx)(X,{value:`custom`,children:`Custom`})]})]})}),n&&(0,W.jsx)(Z,{label:`Custom family`,children:(0,W.jsx)(vf,{placeholder:`Installed font name`,value:t.font.family,onCommit:e=>o(`font`,{family:e})})}),(0,W.jsx)(Z,{label:`Size`,children:(0,W.jsx)(yf,{value:t.font.size,step:.5,onCommit:e=>o(`font`,{size:e})})}),(0,W.jsx)(Z,{label:`Line height`,children:(0,W.jsx)(yf,{value:t.font.lineHeight,step:.05,onCommit:e=>o(`font`,{lineHeight:e})})}),(0,W.jsx)(Z,{label:`Ligatures`,children:(0,W.jsx)(lf,{checked:t.font.ligatures,onCheckedChange:e=>o(`font`,{ligatures:e})})}),(0,W.jsx)(Z,{label:`Font features`,children:(0,W.jsx)(vf,{placeholder:`'ss01', 'zero'`,value:t.font.features,onCommit:e=>o(`font`,{features:e})})})]}),(0,W.jsxs)(_f,{title:`Cursor`,children:[(0,W.jsx)(Z,{label:`Style`,children:(0,W.jsxs)(Ud,{value:t.cursor.style,onValueChange:e=>o(`cursor`,{style:e}),children:[(0,W.jsx)(Gd,{className:`w-56`,children:(0,W.jsx)(Wd,{})}),(0,W.jsxs)(Kd,{children:[(0,W.jsx)(X,{value:`block`,children:`Block`}),(0,W.jsx)(X,{value:`bar`,children:`Bar`}),(0,W.jsx)(X,{value:`underline`,children:`Underline`})]})]})}),(0,W.jsx)(Z,{label:`Blink`,children:(0,W.jsx)(lf,{checked:t.cursor.blink,onCheckedChange:e=>o(`cursor`,{blink:e})})})]}),(0,W.jsxs)(_f,{title:`Text`,children:[(0,W.jsx)(Z,{label:`Tab size`,children:(0,W.jsx)(yf,{value:t.tabSize,onCommit:e=>a({...t,tabSize:e})})}),(0,W.jsx)(Z,{label:`Word wrap`,children:(0,W.jsx)(lf,{checked:t.wordWrap,onCheckedChange:e=>a({...t,wordWrap:e})})})]})]})}function xf(e){let t=e.prefs;return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(_f,{title:`Appearance`,children:(0,W.jsx)(Z,{label:`Theme`,children:(0,W.jsxs)(Ud,{value:t.theme,onValueChange:e=>i({...t,theme:e}),children:[(0,W.jsx)(Gd,{className:`w-56`,children:(0,W.jsx)(Wd,{})}),(0,W.jsx)(Kd,{children:T.map(e=>(0,W.jsx)(X,{value:e.id,children:e.name},e.id))})]})})}),(0,W.jsx)(_f,{title:`Sidebar`,children:(0,W.jsx)(Z,{label:`Group active sessions by project in Inbox`,children:(0,W.jsx)(lf,{checked:t.groupActiveByProject,onCheckedChange:e=>i({...t,groupActiveByProject:e})})})}),(0,W.jsx)(Sf,{}),(0,W.jsx)(H,{variant:`outline`,onClick:e.onRestore,children:`Restore browser defaults`})]})}function Sf(){let[e,t]=(0,U.useState)(`idle`),[n,r]=(0,U.useState)(null);async function i(){t(`checking`),r(null);try{let e=`serviceWorker`in navigator?await navigator.serviceWorker.getRegistration():void 0;if(e===void 0){location.reload();return}await e.update(),t(e.installing===null&&e.waiting===null?`current`:`updating`)}catch(e){console.error(`could not check for updates`,e),r(Ot(e)),t(`idle`)}}return(0,W.jsx)(_f,{title:`App`,children:(0,W.jsx)(Z,{label:`Load the newest version of OffSite in this browser`,children:(0,W.jsxs)(`div`,{className:`flex items-center gap-3`,children:[n!==null&&(0,W.jsxs)(`span`,{className:`text-muted-foreground text-xs`,children:[`Could not check: `,n]}),e===`current`&&(0,W.jsx)(`span`,{className:`text-muted-foreground text-xs`,children:`Up to date`}),e===`updating`&&(0,W.jsx)(`span`,{className:`text-muted-foreground text-xs`,children:`Updating, the page reloads when it's ready`}),(0,W.jsx)(H,{size:`sm`,variant:`outline`,disabled:e===`checking`||e===`updating`,onClick:()=>void i(),children:`Check for updates`})]})})})}function Cf(e){for(let t=0;t<e.length;t++){let n=e[t];if(!n.startsWith(`-`)&&!n.startsWith(`+`))return!1;let r=n.startsWith(`-`),i=n.slice(1);if(i===``||i===`-`)return!1;if(i.startsWith(`-`)){if(!wf(i.slice(1),r))return!1}else for(let n=0;n<i.length;n++){let a=i[n];if(a===`o`){let a=i.slice(n+1);if(a===``){if(t++,t===e.length)return!1;a=e[t]}if(!wf(a,r))return!1;break}if(a===`b`||a===`c`||r&&`dfnprvx`.includes(a)||!r&&a===`i`)return!1}}return!0}function wf(e,t){let n=e.toLowerCase().replace(/[-_]/g,``),r=t;return n.startsWith(`no`)&&(n=n.slice(2),r=!t),[`rcs`,`globalrcs`,`interactive`,`exec`].includes(n)?r:![`privileged`,`restricted`,`sourcetrace`,`verbose`,`xtrace`].includes(n)||!r}function Tf(e,t,n){if(t===`windows`)return`Not available on Windows`;if(e!==null&&/[\n"'\\$`;&|<>()*?[\]{}#!]/.test(e))return`Not available for commands with shell syntax`;let r=e===null?[n]:e.split(/[ \t]/).filter(e=>e!==``);if(r.length===0)return`Available for bash, zsh and fish`;let i=r[0],a=i.split(`/`).pop(),o=r.slice(1);return a===`bash`?t===`macos`&&(i===`/bin/bash`||!i.includes(`/`))?`Needs a newer bash than the one macOS includes`:o.every(e=>[`-l`,`--login`,`-i`].includes(e))?null:`Not available with these bash options`:a===`zsh`?Cf(o)?null:`Not available with these zsh options`:a===`fish`?o.every(e=>{if(e.startsWith(`--`)){let t=e.slice(2).split(`=`)[0];return t===``||![`command`,`no-config`,`no-execute`].some(e=>e.startsWith(t))}return!(e.startsWith(`-`)&&/[cNn]/.test(e))})?null:`Not available with these fish options`:`Available for bash, zsh and fish`}var Ef=[10,15,30,45,60,120,180,300,600,900,1800,3600];function Df(e){let t=e.config;function n(n){ut(e.machine,{...t,...n})}return(0,W.jsxs)(_f,{title:`Agents`,children:[(0,W.jsx)(Z,{label:`Send while working`,children:(0,W.jsxs)(Ud,{value:t.delivery,onValueChange:n=>{if(n!==`queue`&&n!==`steer`)throw Error(`Unknown delivery ${n}`);ut(e.machine,{...t,delivery:n})},children:[(0,W.jsx)(Gd,{className:`w-56`,children:(0,W.jsx)(Wd,{})}),(0,W.jsxs)(Kd,{children:[(0,W.jsx)(X,{value:`queue`,children:`Queue messages`}),(0,W.jsx)(X,{value:`steer`,children:`Steer the agent`})]})]})}),(0,W.jsx)(Z,{label:`Auto-skip questions`,children:(0,W.jsx)(Of,{value:t.autoSkipQuestionTimeout,onChange:e=>n({autoSkipQuestionTimeout:e})})}),(0,W.jsx)(Z,{label:`Auto-resolve permissions`,children:(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[t.autoPermissionTimeout!==null&&(0,W.jsxs)(Ud,{value:t.autoPermissionMode,onValueChange:e=>{if(e!==`allow`&&e!==`deny`)throw Error(`Unknown decision ${e}`);n({autoPermissionMode:e})},children:[(0,W.jsx)(Gd,{className:`w-24`,children:(0,W.jsx)(Wd,{})}),(0,W.jsxs)(Kd,{children:[(0,W.jsx)(X,{value:`allow`,children:`Allow`}),(0,W.jsx)(X,{value:`deny`,children:`Deny`})]})]}),(0,W.jsx)(Of,{value:t.autoPermissionTimeout,onChange:e=>n({autoPermissionTimeout:e})})]})})]})}function Of(e){let t=e.value===null||Ef.includes(e.value)?Ef:[...Ef,e.value].sort((e,t)=>e-t);return(0,W.jsxs)(Ud,{value:e.value===null?`off`:String(e.value),onValueChange:t=>e.onChange(t===`off`?null:Number(t)),children:[(0,W.jsx)(Gd,{className:`w-40`,children:(0,W.jsx)(Wd,{})}),(0,W.jsxs)(Kd,{children:[(0,W.jsx)(X,{value:`off`,children:`Off`}),t.map(e=>(0,W.jsx)(X,{value:String(e),children:e===3600?`After 1 hour`:e===60?`After 1 minute`:e%60==0?`After ${e/60} minutes`:`After ${e} seconds`},e))]})]})}function kf(e){let t=e.config[e.setting],[n,r]=(0,U.useState)(null),[i,a]=(0,U.useState)(null);(0,U.useEffect)(()=>{if(t.provider===null)return;let n=!0;return r(null),a(null),N(e.machine,`capabilities`,{provider:t.provider,accountId:t.accountId,projectId:null}).then(e=>{n&&r(e.models)},e=>{n&&a(Ot(e))}),()=>{n=!1}},[e.machine,t.provider,t.accountId]);function o(t){ut(e.machine,{...e.config,[e.setting]:t})}function s(t){if(t===`off`){o({provider:null,accountId:null,model:null});return}if(t===`opencode`){o({provider:`opencode`,accountId:null,model:null});return}let n=[...e.claudeAccounts,...e.codexAccounts].find(e=>e.id===t);if(n===void 0)throw Error(`That account was removed`);o({provider:n.provider,accountId:n.id,model:null})}return(0,W.jsxs)(_f,{title:e.title,children:[(0,W.jsx)(Z,{label:`Account`,children:(0,W.jsxs)(Ud,{value:t.provider===null?`off`:t.provider===`opencode`?`opencode`:t.accountId??`off`,onValueChange:s,children:[(0,W.jsx)(Gd,{className:`w-56`,children:(0,W.jsx)(Wd,{})}),(0,W.jsxs)(Kd,{children:[(0,W.jsx)(X,{value:`off`,children:`Off`}),[...e.claudeAccounts,...e.codexAccounts].map(e=>(0,W.jsxs)(X,{value:e.id,disabled:!e.valid,children:[(0,W.jsx)(Vs,{provider:e.provider,className:`size-4`}),`${tr[e.provider]} · ${e.name}`]},e.id)),e.openCode.available&&(0,W.jsxs)(X,{value:`opencode`,children:[(0,W.jsx)(Vs,{provider:`opencode`,className:`size-4`}),tr.opencode]})]})]})}),t.provider!==null&&(0,W.jsx)(Z,{label:`Model`,children:(0,W.jsxs)(Ud,{value:t.model??void 0,disabled:n===null,onValueChange:e=>o({...t,model:e}),children:[(0,W.jsx)(Gd,{className:`w-56`,children:(0,W.jsx)(Wd,{placeholder:i===null?n===null?`Loading…`:`Choose a model`:`Unavailable`})}),(0,W.jsx)(Kd,{children:(n??[]).map(e=>(0,W.jsx)(X,{value:e.value,children:e.name},e.value))})]})}),i!==null&&(0,W.jsx)(`p`,{className:`text-destructive px-4 py-3 text-xs`,children:i})]})}var Af={zsh:`M11.415 5.038a.58.58 0 0 0-.543.197L.135 18.021a.58.58 0 0 0 .071.814.58.58 0 0 0 .815-.07L11.757 5.979a.58.58 0 0 0-.07-.815.6.6 0 0 0-.272-.126m-8.113.317a3.133 3.133 0 0 0-3.12 3.12 3.13 3.13 0 0 0 3.12 3.119A3.133 3.133 0 0 0 6.42 8.475a3.13 3.13 0 0 0-3.119-3.119m0 1.806a1.3 1.3 0 0 1 1.314 1.313 1.3 1.3 0 0 1-1.314 1.312A1.3 1.3 0 0 1 1.99 8.475a1.3 1.3 0 0 1 1.312-1.314m5.253 5.253a3.13 3.13 0 0 0-3.119 3.119 3.13 3.13 0 0 0 3.12 3.118 3.133 3.133 0 0 0 3.118-3.12 3.133 3.133 0 0 0-3.119-3.118m0 1.805a1.3 1.3 0 0 1 1.313 1.314c0 .735-.577 1.312-1.312 1.312a1.3 1.3 0 0 1-1.314-1.312 1.3 1.3 0 0 1 1.313-1.314m7.201 3.276a.58.58 0 0 0-.578.578.58.58 0 0 0 .578.578h7.666a.58.58 0 0 0 .579-.578.58.58 0 0 0-.579-.578Z`,bash:`M21.038,4.9l-7.577-4.498C13.009,0.134,12.505,0,12,0c-0.505,0-1.009,0.134-1.462,0.403L2.961,4.9 C2.057,5.437,1.5,6.429,1.5,7.503v8.995c0,1.073,0.557,2.066,1.462,2.603l7.577,4.497C10.991,23.866,11.495,24,12,24 c0.505,0,1.009-0.134,1.461-0.402l7.577-4.497c0.904-0.537,1.462-1.529,1.462-2.603V7.503C22.5,6.429,21.943,5.437,21.038,4.9z M15.17,18.946l0.013,0.646c0.001,0.078-0.05,0.167-0.111,0.198l-0.383,0.22c-0.061,0.031-0.111-0.007-0.112-0.085L14.57,19.29 c-0.328,0.136-0.66,0.169-0.872,0.084c-0.04-0.016-0.057-0.075-0.041-0.142l0.139-0.584c0.011-0.046,0.036-0.092,0.069-0.121 c0.012-0.011,0.024-0.02,0.036-0.026c0.022-0.011,0.043-0.014,0.062-0.006c0.229,0.077,0.521,0.041,0.802-0.101 c0.357-0.181,0.596-0.545,0.592-0.907c-0.003-0.328-0.181-0.465-0.613-0.468c-0.55,0.001-1.064-0.107-1.072-0.917 c-0.007-0.667,0.34-1.361,0.889-1.8l-0.007-0.652c-0.001-0.08,0.048-0.168,0.111-0.2l0.37-0.236 c0.061-0.031,0.111,0.007,0.112,0.087l0.006,0.653c0.273-0.109,0.511-0.138,0.726-0.088c0.047,0.012,0.067,0.076,0.048,0.151 l-0.144,0.578c-0.011,0.044-0.036,0.088-0.065,0.116c-0.012,0.012-0.025,0.021-0.038,0.028c-0.019,0.01-0.038,0.013-0.057,0.009 c-0.098-0.022-0.332-0.073-0.699,0.113c-0.385,0.195-0.52,0.53-0.517,0.778c0.003,0.297,0.155,0.387,0.681,0.396 c0.7,0.012,1.003,0.318,1.01,1.023C16.105,17.747,15.736,18.491,15.17,18.946z M19.143,17.859c0,0.06-0.008,0.116-0.058,0.145 l-1.916,1.164c-0.05,0.029-0.09,0.004-0.09-0.056v-0.494c0-0.06,0.037-0.093,0.087-0.122l1.887-1.129 c0.05-0.029,0.09-0.004,0.09,0.056V17.859z M20.459,6.797l-7.168,4.427c-0.894,0.523-1.553,1.109-1.553,2.187v8.833 c0,0.645,0.26,1.063,0.66,1.184c-0.131,0.023-0.264,0.039-0.398,0.039c-0.42,0-0.833-0.114-1.197-0.33L3.226,18.64 c-0.741-0.44-1.201-1.261-1.201-2.142V7.503c0-0.881,0.46-1.702,1.201-2.142l7.577-4.498c0.363-0.216,0.777-0.33,1.197-0.33 c0.419,0,0.833,0.114,1.197,0.33l7.577,4.498c0.624,0.371,1.046,1.013,1.164,1.732C21.686,6.557,21.12,6.411,20.459,6.797z`,fish:`m19.164 9.228-3.016 2.688v.527l3.016 2.688v-1.228l-1.936-1.723 1.936-1.724V9.228m-6.658.046v1.208l1.905 1.696-1.905 1.695v1.209l2.968-2.645v-.518l-2.968-2.645M9.781 7.847a6.519 6.519 0 0 0-2.038-.335c-.672 0-1.349.112-2.03.335a9.23 9.23 0 0 0-2.088 1.017v.723c.69-.4 1.377-.7 2.06-.897a7.388 7.388 0 0 1 2.058-.296c.684 0 1.368.098 2.052.296a9.452 9.452 0 0 1 2.075.897v-.723a9.229 9.229 0 0 0-2.09-1.017m.014 7.78a7.371 7.371 0 0 1-2.052.296 7.388 7.388 0 0 1-2.057-.296 9.18 9.18 0 0 1-2.061-.897v.723a9.228 9.228 0 0 0 2.088 1.017 6.492 6.492 0 0 0 2.03.335c.678 0 1.357-.112 2.038-.335a9.227 9.227 0 0 0 2.089-1.017v-.723c-.7.4-1.391.7-2.075.897m.602-11.23h-.51L7.28 6.92h1.19l1.672-1.62 1.671 1.62h1.191l-2.607-2.525m-2.965 13.68v-.824H6.427v.825l.786 1.527h.614l-.395-1.527M4.127 10.95v1.216H5.13V10.95H4.127m-1.16-1.695L0 11.901v.518l2.967 2.645v-1.208L1.063 12.16l1.904-1.695V9.256m20.68 3.28c-.235-.3-.574-.509-1.017-.626.395-.103.696-.278.902-.525.206-.247.31-.556.31-.926 0-.546-.197-.984-.59-1.314-.393-.33-.919-.495-1.575-.495-.22 0-.473.025-.758.073-.284.048-.61.12-.974.217v.84c.314-.12.613-.21.9-.27a4.05 4.05 0 0 1 .832-.091c.403 0 .714.093.933.278.218.185.328.451.328.798 0 .328-.118.584-.353.768-.235.184-.562.276-.98.276h-.697v.75h.696c.458 0 .821.116 1.09.346.268.23.402.542.402.934 0 .425-.134.75-.402.976-.269.226-.653.339-1.153.339a3.55 3.55 0 0 1-.89-.117 4.395 4.395 0 0 1-.91-.358v.909a6.1 6.1 0 0 0 .95.249c.323.057.639.085.95.085.738 0 1.315-.177 1.733-.53.417-.355.626-.842.626-1.463 0-.449-.118-.823-.353-1.123`,powershell:`M23.181 2.974c.568 0 .923.463.792 1.035l-3.659 15.982c-.13.572-.697 1.035-1.265 1.035H.819c-.568 0-.923-.463-.792-1.035L3.686 4.009c.13-.572.697-1.035 1.265-1.035zm-8.375 9.346c.251-.394.227-.905-.09-1.243L9.122 5.125c-.38-.404-1.037-.407-1.466-.003-.429.402-.468 1.056-.088 1.46l4.662 4.96v.11l-7.42 5.374c-.45.327-.533.977-.187 1.453.346.476.991.597 1.44.27l8.229-5.91c.28-.196.438-.365.514-.52zm-2.796 4.399a.928.928 0 00-.934.923c0 .51.418.923.934.923h4.433a.928.928 0 00.934-.923.928.928 0 00-.934-.923z`,cmd:`M8.165 6V3h7.665v3H8.165zm-.5-3H1c-.55 0-1 .45-1 1v2h7.665V3zM23 3h-6.67v3H24V4c0-.55-.45-1-1-1zM0 6.5h24V20c0 .55-.45 1-1 1H1c-.55 0-1-.45-1-1V6.5zM11.5 18c0 .3.2.5.5.5h8c.3 0 .5-.2.5-.5v-1.5c0-.3-.2-.5-.5-.5h-8c-.3 0-.5.2-.5.5V18zm-5.2-4.55l-3.1 3.1c-.25.25-.25.6 0 .8l.9.9c.25.25.6.25.8 0l4.4-4.4a.52.52 0 0 0 0-.8l-4.4-4.4c-.2-.2-.6-.2-.8 0l-.9.9c-.25.2-.25.55 0 .8l3.1 3.1z`},jf={zsh:`zsh`,bash:`bash`,fish:`fish`,pwsh:`powershell`,powershell:`powershell`,cmd:`cmd`},Mf={macos:[`zsh`,`bash`,`fish`,`pwsh`],linux:[`bash`,`zsh`,`fish`,`pwsh`],windows:[`pwsh`,`powershell`,`cmd`]};function Nf(e){let t=e.trim().split(/[\\/]/).pop()?.toLowerCase().replace(/\.exe$/,``);return t===void 0?void 0:jf[t]}function Pf(e){return e.replace(/[\\/][^\\/]*$/,``)}function Ff(e){return(0,W.jsx)(`svg`,{viewBox:`0 0 24 24`,className:`size-4 flex-none`,fill:`currentColor`,children:(0,W.jsx)(`path`,{d:Af[e.logo]})})}function If(e){let[t,n]=(0,U.useState)(e.value??``),[r,i]=(0,U.useState)(null),[a,o]=(0,U.useState)(null),s=Nf(t),c=e.platform===e.device,l=c?r:Mf[e.platform].map(e=>({name:e,path:null}));(0,U.useEffect)(()=>{c&&N(e.machine,`terminal.shells`,void 0).then(i,e=>o(Ot(e)))},[e.machine,c]);function u(t){n(t),t!==(e.value??``)&&e.onCommit(t===``?null:t)}return(0,W.jsxs)(`div`,{className:`relative w-56`,children:[s&&(0,W.jsx)(`span`,{className:`text-muted-foreground pointer-events-none absolute top-1/2 left-2.5 -translate-y-1/2`,children:(0,W.jsx)(Ff,{logo:s})}),(0,W.jsx)(Hd,{className:s?`pr-9 pl-8`:`pr-9`,placeholder:`System default`,value:t,onChange:e=>n(e.target.value),onBlur:()=>u(t),onKeyDown:e=>{e.key===`Enter`&&e.currentTarget.blur()}}),(0,W.jsxs)(Qt,{children:[(0,W.jsx)(un,{asChild:!0,children:(0,W.jsx)(H,{variant:`ghost`,size:`icon-xs`,"aria-label":`Known shells`,className:`text-muted-foreground absolute top-1/2 right-1.5 -translate-y-1/2`,children:(0,W.jsx)(V,{icon:In})})}),(0,W.jsxs)(tn,{align:`end`,className:`w-72`,children:[a&&(0,W.jsx)(`p`,{className:`text-destructive px-2 py-1.5 text-xs`,children:a}),l?.length===0&&(0,W.jsx)(`p`,{className:`text-muted-foreground px-2 py-1.5 text-xs`,children:`No known shells found`}),l?.map(e=>(0,W.jsxs)(Gt,{onSelect:()=>u(e.path??e.name),children:[(0,W.jsx)(Ff,{logo:jf[e.name]}),e.name,e.path!==null&&(0,W.jsx)(`span`,{className:`text-muted-foreground ml-auto min-w-0 truncate pl-3 text-xs [direction:rtl]`,title:e.path,children:(0,W.jsx)(`bdi`,{children:Pf(e.path)})})]},e.path??e.name)),(0,W.jsx)(Ht,{}),(0,W.jsx)(Gt,{onSelect:()=>u(``),children:`System default`})]})]})]})}function Lf(e){let t=e.config.workingDir[e.platform]??``,n=e.config.newThreads;return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(_f,{title:`Projects`,children:(0,W.jsx)(Z,{label:`Working directory`,children:(0,W.jsx)(vf,{className:`w-72 font-mono`,value:t,placeholder:`Home folder`,onCommit:t=>ut(e.machine,{...e.config,workingDir:{...e.config.workingDir,[e.platform]:t.trim()===``?null:t.trim()}})},`${e.machine}-${t}`)})}),(0,W.jsx)(_f,{title:`New threads`,children:(0,W.jsx)(Z,{label:`Account`,children:(0,W.jsxs)(Ud,{value:n.provider===`opencode`?`opencode`:n.accountId??void 0,onValueChange:t=>{if(t===`opencode`){ut(e.machine,{...e.config,newThreads:{...n,provider:`opencode`,accountId:null}});return}let r=[...e.claudeAccounts,...e.codexAccounts].find(e=>e.id===t);if(r===void 0)throw Error(`That account was removed`);ut(e.machine,{...e.config,newThreads:{...n,provider:r.provider,accountId:r.id}})},children:[(0,W.jsx)(Gd,{className:`w-56`,children:(0,W.jsx)(Wd,{placeholder:`First available`})}),(0,W.jsxs)(Kd,{children:[[...e.claudeAccounts,...e.codexAccounts].map(e=>(0,W.jsxs)(X,{value:e.id,disabled:!e.valid,children:[(0,W.jsx)(Vs,{provider:e.provider,className:`size-4`}),`${tr[e.provider]} · ${e.name}`]},e.id)),e.openCode.available&&(0,W.jsxs)(X,{value:`opencode`,children:[(0,W.jsx)(Vs,{provider:`opencode`,className:`size-4`}),tr.opencode]})]})]})})}),(0,W.jsx)(Rf,{machine:e.machine,config:e.config,platform:e.platform,defaultShell:e.defaultShell},e.machine),(0,W.jsx)(Df,{machine:e.machine,config:e.config}),(0,W.jsx)(kf,{title:`Commit messages and pull requests`,setting:`commitMessage`,machine:e.machine,config:e.config,claudeAccounts:e.claudeAccounts,codexAccounts:e.codexAccounts,openCode:e.openCode},`git-${e.machine}`),(0,W.jsx)(kf,{title:`Session titles`,setting:`titleGeneration`,machine:e.machine,config:e.config,claudeAccounts:e.claudeAccounts,codexAccounts:e.codexAccounts,openCode:e.openCode},`titles-${e.machine}`),(0,W.jsx)(H,{variant:`outline`,onClick:e.onRestore,children:`Restore machine defaults`})]})}function Rf(e){let t=e.config.terminal,[n,r]=(0,U.useState)(e.platform),i=Tf(t.shell[e.platform],e.platform,e.defaultShell);function a(t){ut(e.machine,{...e.config,terminal:t})}return(0,W.jsxs)(_f,{title:`Shell`,note:`Applies to new terminals`,children:[(0,W.jsx)(Z,{label:`Platform`,children:(0,W.jsxs)(Ud,{value:n,onValueChange:e=>r(e),children:[(0,W.jsx)(Gd,{className:`w-56`,children:(0,W.jsx)(Wd,{})}),(0,W.jsx)(Kd,{children:pf.map(t=>(0,W.jsxs)(X,{value:t.value,children:[t.label,t.value===e.platform&&(0,W.jsx)(`span`,{className:`text-muted-foreground`,children:`(this machine)`})]},t.value))})]})}),(0,W.jsx)(Z,{label:`Command`,children:(0,W.jsx)(If,{machine:e.machine,platform:n,device:e.platform,value:t.shell[n],onCommit:e=>a({...t,shell:{...t.shell,[n]:e}})},`${e.machine}-${n}-command`)}),(0,W.jsx)(Z,{label:(0,W.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[`Shell integration`,(0,W.jsx)(vr,{label:(0,W.jsxs)(`div`,{children:[`Tells the terminal where prompts and commands start and end.`,(0,W.jsxs)(`ul`,{className:`mt-1 list-disc pl-4`,children:[(0,W.jsx)(`li`,{children:`Click in the command line to move the cursor`}),(0,W.jsx)(`li`,{children:`Ignore clipboard reads once the command that asked has finished`})]})]}),children:(0,W.jsx)(`span`,{onClick:e=>e.preventDefault(),children:(0,W.jsx)(V,{icon:xo,"aria-label":`About shell integration`,className:`text-muted-foreground size-3.5`})})})]}),children:(0,W.jsxs)(`div`,{className:`flex items-center gap-3`,children:[i!==null&&(0,W.jsx)(`span`,{className:`text-muted-foreground max-w-32 text-right text-xs sm:max-w-none`,children:i}),(0,W.jsx)(lf,{checked:i===null&&t.behavior.shellIntegration,disabled:i!==null,onCheckedChange:e=>a({...t,behavior:{...t.behavior,shellIntegration:e}})})]})}),(0,W.jsx)(zf,{identity:t.behavior.terminalIdentity,onChange:e=>a({...t,behavior:{...t.behavior,terminalIdentity:e}})})]})}function zf(e){return(0,W.jsx)(Z,{label:`Report the terminal as`,children:(0,W.jsxs)(Ud,{value:e.identity,onValueChange:e.onChange,children:[(0,W.jsx)(Gd,{className:`w-56`,children:(0,W.jsx)(Wd,{})}),(0,W.jsxs)(Kd,{children:[(0,W.jsx)(X,{value:`offsite`,children:`OffSite`}),(0,W.jsx)(X,{value:`ghostty`,children:`Ghostty`}),(0,W.jsx)(X,{value:`iterm2`,children:`iTerm2`})]})]})})}var Bf=(0,U.createContext)({});function Vf(e){let t=(0,U.useRef)(null);return t.current===null&&(t.current=e()),t.current}var Q=typeof window<`u`?U.useLayoutEffect:U.useEffect,Hf=(0,U.createContext)(null);function Uf(e,t){e.indexOf(t)===-1&&e.push(t)}function Wf(e,t){let n=e.indexOf(t);n>-1&&e.splice(n,1)}function Gf([...e],t,n){let r=t<0?e.length+t:t;if(r>=0&&r<e.length){let r=n<0?e.length+n:n,[i]=e.splice(t,1);e.splice(r,0,i)}return e}var Kf=(e,t,n)=>n>t?t:n<e?e:n,qf={},Jf=e=>/^-?(?:\d+(?:\.\d+)?|\.\d+)$/u.test(e),Yf=e=>typeof e==`object`&&!!e,Xf=e=>/^0[^.\s]+$/u.test(e);function Zf(e){let t;return()=>(t===void 0&&(t=e()),t)}var Qf=e=>e,$f=(...e)=>e.reduce((e,t)=>n=>t(e(n))),ep=(e,t,n)=>{let r=t-e;return r?(n-e)/r:1},tp=class{constructor(){this.subscriptions=[]}add(e){return Uf(this.subscriptions,e),()=>this.remove(e)}remove(e){Wf(this.subscriptions,e)}notify(e,t,n){let r=this.subscriptions.length;if(r){if(r===1)this.subscriptions[0](e,t,n);else for(let i=0;i<r;i++){let r=this.subscriptions[i];r&&r(e,t,n)}}}getSize(){return this.subscriptions.length}clear(){this.subscriptions.length=0}},np=e=>e*1e3,rp=e=>e/1e3,ip=(e,t)=>t?1e3/t*e:0,ap=(e,t,n)=>e*(3*(1-e)*((1-e)*t+e*n)+e*e);function op(e,t,n,r){return e===t&&n===r?Qf:i=>{let a=0,o=1,s=i;for(let t=0;;t++){s>=a&&s<=o||(s=(a+o)/2);let r=ap(s,e,n)-i;if(r*r<1e-28||t===40)break;r>0?o=s:a=s,s-=r*1e-7/(ap(s+1e-7,e,n)-i-r)}return ap(s,t,r)}}var sp=e=>t=>t<=.5?e(2*t)/2:(2-e(2*(1-t)))/2,cp=e=>t=>1-e(1-t),lp=op(.33,1.53,.69,.99),up=cp(lp),dp=sp(up),fp=e=>e>=1?1:(e*=2)<1?.5*up(e):.5*(2-2**(-10*(e-1))),pp=e=>1-Math.sin(Math.acos(e)),mp=cp(pp),hp=sp(pp),gp=op(.42,0,1,1),_p=op(0,0,.58,1),vp=op(.42,0,.58,1),yp=e=>Array.isArray(e)&&typeof e[0]!=`number`,bp=e=>Array.isArray(e)&&typeof e[0]==`number`,xp={linear:Qf,easeIn:gp,easeInOut:vp,easeOut:_p,circIn:pp,circInOut:hp,circOut:mp,backIn:up,backInOut:dp,backOut:lp,anticipate:fp},Sp=e=>typeof e==`string`,Cp=e=>{if(bp(e)){let[t,n,r,i]=e;return op(t,n,r,i)}return Sp(e)?xp[e]:e},wp={delta:0,timestamp:0,isProcessing:!1},Tp;function Ep(){Tp=void 0}var Dp={now:()=>(Tp===void 0&&Dp.set(wp.isProcessing||qf.useManualTiming?wp.timestamp:performance.now()),Tp),set:e=>{Tp=e,queueMicrotask(Ep)}},Op=e=>Math.round(e*1e5)/1e5,kp=e=>t=>typeof t==`string`&&t.startsWith(e),Ap=kp(`--`),jp=kp(`var(--`),Mp=e=>jp(e)?Np.test(e.split(`/*`)[0].trim()):!1,Np=/var\(--(?:[\w-]+\s*|[\w-]+\s*,(?:\s*[^)(\s]|\s*\((?:[^)(]|\([^)(]*\))*\))+\s*)\)$/iu;function Pp(e){return typeof e==`string`&&e.split(`/*`)[0].includes(`var(--`)}var Fp={test:e=>typeof e==`number`,parse:parseFloat,transform:e=>e},Ip={...Fp,transform:e=>Kf(0,1,e)},Lp={...Fp,default:1},Rp=/-?(?:\d+(?:\.\d+)?|\.\d+)/gu;function zp(e){return e==null}var Bp=/^(?:#[\da-f]{3,8}|(?:rgb|hsl)a?\((?:-?[\d.]+%?[,\s]+){2}-?[\d.]+%?\s*(?:[,/]\s*)?(?:\b\d+(?:\.\d+)?|\.\d+)?%?\))$/iu,Vp=(e,t)=>n=>!!(typeof n==`string`&&Bp.test(n)&&n.startsWith(e)||t&&!zp(n)&&Object.prototype.hasOwnProperty.call(n,t)),Hp=(e,t,n)=>r=>{if(typeof r!=`string`)return r;let[i,a,o,s]=r.match(Rp);return{[e]:parseFloat(i),[t]:parseFloat(a),[n]:parseFloat(o),alpha:s===void 0?1:parseFloat(s)}},Up=e=>Kf(0,255,e),Wp={...Fp,transform:e=>Math.round(Up(e))},Gp={test:Vp(`rgb`,`red`),parse:Hp(`red`,`green`,`blue`),transform:({red:e,green:t,blue:n,alpha:r=1})=>`rgba(`+Wp.transform(e)+`, `+Wp.transform(t)+`, `+Wp.transform(n)+`, `+Op(Ip.transform(r))+`)`},Kp=(e,t,n)=>{let r=e.substring(1+t*n,1+(t+1)*n);return n>1?r:r+r};function qp(e){let t=e.length>5?2:1,n=Kp(e,3,t);return{red:parseInt(Kp(e,0,t),16),green:parseInt(Kp(e,1,t),16),blue:parseInt(Kp(e,2,t),16),alpha:n?parseInt(n,16)/255:1}}var Jp={test:Vp(`#`),parse:qp,transform:Gp.transform},Yp=e=>({test:t=>typeof t==`string`&&t.endsWith(e)&&t.split(` `).length===1,parse:parseFloat,transform:t=>`${t}${e}`}),Xp=Yp(`deg`),Zp=Yp(`%`),$=Yp(`px`),Qp=Yp(`vh`),$p=Yp(`vw`),em={...Zp,parse:e=>Zp.parse(e)/100,transform:e=>Zp.transform(e*100)},tm={test:Vp(`hsl`,`hue`),parse:Hp(`hue`,`saturation`,`lightness`),transform:({hue:e,saturation:t,lightness:n,alpha:r=1})=>`hsla(`+Math.round(e)+`, `+Zp.transform(Op(t))+`, `+Zp.transform(Op(n))+`, `+Op(Ip.transform(r))+`)`},nm={test:e=>Gp.test(e)||Jp.test(e)||tm.test(e),parse:e=>Gp.test(e)?Gp.parse(e):tm.test(e)?tm.parse(e):Jp.parse(e),transform:e=>typeof e==`string`?e:e.hasOwnProperty(`red`)?Gp.transform(e):tm.transform(e),getAnimatableNone:e=>{let t=nm.parse(e);return t.alpha=0,nm.transform(t)}},rm=/(?:#[\da-f]{3,8}|(?:rgb|hsl)a?\((?:-?[\d.]+%?[,\s]+){2}-?[\d.]+%?\s*(?:[,/]\s*)?(?:\b\d+(?:\.\d+)?|\.\d+)?%?\))/giu,im=new RegExp(Rp.source),am=new RegExp(rm.source,`i`);function om(e){return isNaN(e)&&typeof e==`string`&&(im.test(e)||am.test(e))}var sm=`number`,cm=`color`,lm=`var`,um=`var(`,dm="${}",fm=/var\s*\(\s*--(?:[\w-]+\s*|[\w-]+\s*,(?:\s*[^)(\s]|\s*\((?:[^)(]|\([^)(]*\))*\))+\s*)\)|#[\da-f]{3,8}|(?:rgb|hsl)a?\((?:-?[\d.]+%?[,\s]+){2}-?[\d.]+%?\s*(?:[,/]\s*)?(?:\b\d+(?:\.\d+)?|\.\d+)?%?\)|-?(?:\d+(?:\.\d+)?|\.\d+)(?![a-z]*\()/giu;function pm(e){let t=e.toString();return im.test(t)||am.test(t)}function mm(e){let t=e.toString(),n=[],r={color:[],number:[],var:[]},i=[],a=0;return{values:n,split:t.replace(fm,e=>(nm.test(e)?(r.color.push(a),i.push(cm),n.push(nm.parse(e))):e.startsWith(um)?(r.var.push(a),i.push(lm),n.push(e)):(r.number.push(a),i.push(sm),n.push(parseFloat(e))),++a,dm)).split(dm),indexes:r,types:i}}function hm(e){return mm(e).values}function gm({split:e,types:t}){let n=e.length;return r=>{let i=``;for(let a=0;a<n;a++)if(i+=e[a],r[a]!==void 0){let e=t[a];i+=e===sm?Op(r[a]):e===cm?nm.transform(r[a]):r[a]}return i}}function _m(e){return gm(mm(e))}var vm=e=>typeof e==`number`?0:nm.test(e)?nm.getAnimatableNone(e):e,ym=(e,t)=>typeof e==`number`?t?.trim().endsWith(`/`)?e:0:vm(e);function bm(e){let t=mm(e);return gm(t)(t.values.map((e,n)=>ym(e,t.split[n])))}var xm={test:om,parse:hm,createTransformer:_m,getAnimatableNone:bm};function Sm(e,t,n){return n<0&&(n+=1),n>1&&--n,n<1/6?e+(t-e)*6*n:n<1/2?t:n<2/3?e+(t-e)*(2/3-n)*6:e}function Cm({hue:e,saturation:t,lightness:n,alpha:r}){e/=360,t/=100,n/=100;let i=0,a=0,o=0;if(!t)i=a=o=n;else{let r=n<.5?n*(1+t):n+t-n*t,s=2*n-r;i=Sm(s,r,e+1/3),a=Sm(s,r,e),o=Sm(s,r,e-1/3)}return{red:Math.round(i*255),green:Math.round(a*255),blue:Math.round(o*255),alpha:r}}function wm(e,t){return n=>n>0?t:e}var Tm=(e,t,n)=>e+(t-e)*n,Em=(e,t,n)=>{let r=e*e,i=n*(t*t-r)+r;return i<0?0:Math.sqrt(i)},Dm=[Jp,Gp,tm],Om=e=>Dm.find(t=>t.test(e));function km(e){let t=Om(e);if(!t)return!1;let n=t.parse(e);return t===tm&&(n=Cm(n)),n}var Am=(e,t)=>{let n=km(e),r=km(t);if(!n||!r)return wm(e,t);let i={...n};return e=>(i.red=Em(n.red,r.red,e),i.green=Em(n.green,r.green,e),i.blue=Em(n.blue,r.blue,e),i.alpha=Tm(n.alpha,r.alpha,e),Gp.transform(i))},jm=new Set([`none`,`hidden`]);function Mm(e,t){return jm.has(e)?n=>n<=0?e:t:n=>n>=1?t:e}function Nm(e,t){return n=>Tm(e,t,n)}function Pm(e){return typeof e==`number`?Nm:typeof e==`string`?Mp(e)?wm:nm.test(e)?Am:Rm:Array.isArray(e)?Fm:typeof e==`object`?nm.test(e)?Am:Im:wm}function Fm(e,t){let n=[...e],r=n.length,i=e.map((e,n)=>Pm(e)(e,t[n]));return e=>{for(let t=0;t<r;t++)n[t]=i[t](e);return n}}function Im(e,t){let n={...e,...t},r={};for(let i in n)e[i]!==void 0&&t[i]!==void 0&&(r[i]=Pm(e[i])(e[i],t[i]));return e=>{for(let t in r)n[t]=r[t](e);return n}}function Lm(e,t){let n=[],r={color:0,var:0,number:0};for(let i=0;i<t.values.length;i++){let a=t.types[i],o=e.indexes[a][r[a]],s=e.values[o]??0;n[i]=s,r[a]++}return n}var Rm=(e,t)=>{let n=mm(e),r=mm(t);return n.indexes.var.length===r.indexes.var.length&&n.indexes.color.length===r.indexes.color.length&&n.indexes.number.length>=r.indexes.number.length?jm.has(e)&&!r.values.length||jm.has(t)&&!n.values.length?Mm(e,t):$f(Fm(Lm(n,r),r.values),gm(r)):wm(e,t)},zm=/^(-?(?:\d+(?:\.\d*)?|\.\d+))([a-z%]*)$/iu;function Bm(e,t){let n=zm.exec(e);if(!n)return;let r=zm.exec(t);if(!r||n[2]!==r[2])return;let i=n[2],a=parseFloat(n[1]),o=parseFloat(r[1]);return e=>Op(Tm(a,o,e))+i}function Vm(e,t,n){if(typeof e==`number`&&typeof t==`number`&&typeof n==`number`)return Tm(e,t,n);if(typeof e==`string`&&typeof t==`string`){let n=Bm(e,t);if(n)return n}return Pm(e)(e,t)}var Hm=[`setup`,`read`,`resolveKeyframes`,`preUpdate`,`update`,`preRender`,`render`,`postRender`];function Um(e){let t=new Set,n=new Set,r=!1,i=!1,a,o=new Set,s={delta:0,timestamp:0,isProcessing:!1};function c(t){o.has(t)&&(n.add(t),e()),(a=t)(s)}let l={schedule:(e,i=!1,s=!1)=>{let c=s&&r,l=c?t:n;return i&&o.add(e),c&&e!==a&&l.delete(e),l.add(e),e},cancel:e=>{n.delete(e),o.delete(e)},process:e=>{if(s=e,r){i=!0;return}r=!0;let o=t;t=n,n=o,t.forEach(c),t.clear(),a=void 0,r=!1,i&&(i=!1,l.process(e))}};return l}var Wm=40;function Gm(e,t,n={delta:0,timestamp:0,isProcessing:!1}){let r=!1,i=!0,a=()=>r=!0,o=Hm.reduce((e,t)=>(e[t]=Um(a),e),{}),{setup:s,read:c,resolveKeyframes:l,preUpdate:u,update:d,preRender:f,render:p,postRender:m}=o,h=()=>{let a=qf.useManualTiming,o=a?n.timestamp:performance.now();r=!1,a||(n.delta=i?1e3/60:Math.max(Math.min(o-n.timestamp,Wm),1)),n.timestamp=o,n.isProcessing=!0,s.process(n),c.process(n),l.process(n),u.process(n),d.process(n),f.process(n),p.process(n),m.process(n),n.isProcessing=!1,r&&t&&(i=!1,e(h))},g=()=>{r=!0,i=!0,n.isProcessing||e(h)};return{schedule:Hm.reduce((e,t)=>{let n=o[t];return e[t]=(e,t=!1,i=!1)=>(r||g(),n.schedule(e,t,i)),e},{}),cancel:e=>{for(let t=0;t<Hm.length;t++)o[Hm[t]].cancel(e)},state:n,steps:o}}var{schedule:Km,cancel:qm,steps:Jm}=Gm(typeof requestAnimationFrame<`u`?requestAnimationFrame:Qf,!0,wp),Ym=e=>{let t=({timestamp:t})=>e(t);return{start:(e=!0)=>Km.update(t,e),stop:()=>qm(t),now:()=>wp.isProcessing?wp.timestamp:Dp.now()}},Xm=(e,t,n=10)=>{let r=``,i=Math.max(Math.round(t/n),2);for(let t=0;t<i;t++)r+=Math.round(e(t/(i-1))*1e4)/1e4+`, `;return`linear(${r.substring(0,r.length-2)})`},Zm=2e4;function Qm(e,t=50,n=Zm,r){let i=0,a=e.next(i);for(r?.push(a.value);!a.done&&i<n;)i+=t,a=e.next(i),r?.push(a.value);return i>=n?1/0:i}function $m(e,t=100,n){let{keyframes:r,velocity:i}=e,a=r&&r[r.length-1]-r[0],o=n({...e,velocity:i&&a?i*t/a:i,keyframes:[0,t]}),s=Math.min(Qm(o),Zm);return{type:`keyframes`,ease:e=>o.next(s*e).value/t,duration:rp(s)}}var eh=100,th=10,nh=1,rh=800,ih=.3,ah=.3,oh=.01,sh=2,ch=.005,lh=.5,uh=.01,dh=10,fh=.05,ph=e=>e<0?1/Math.max(1+e,fh):Math.max(1-e,fh);function mh(e,t){if(!(e>1))return 1;let n=Math.sqrt(e*e-1),r=e-n,i=e+n,a=2*n*Math.exp(-t)*(1+t);return _h(e=>i*Math.exp(-r*e)-r*Math.exp(-i*e)-a,e=>Math.exp(-i*e)-Math.exp(-r*e),t)/t}function hh(e,t){return e*Math.sqrt(1-t*t)}var gh=12;function _h(e,t,n){let r=n;for(let n=1;n<gh;n++)r-=e(r)/t(r);return r}var vh=.001;function yh({duration:e=rh,bounce:t=ih}){let n,r,i=ph(t);e=Kf(uh,dh,rp(e)),i<1?(n=t=>{let n=t*i,r=n*e,a=hh(t,i),o=Math.exp(-r);return vh-n/a*o},r=t=>{let r=t*i*e,a=i*i*t*t*e,o=Math.exp(-r),s=hh(t*t,i);return(-n(t)+vh>0?-1:1)*-a*o/s}):(n=t=>-.001+Math.exp(-t*e)*(t*e+1),r=t=>Math.exp(-t*e)*(-t*(e*e)));let a=5/e,o=_h(n,r,a),s=o*mh(i,o*e),c=s*s;return{stiffness:c,damping:i*2*Math.sqrt(c),duration:np(e)}}var bh=(e,t)=>(t?e>=0:e>0)&&e<1/0;function xh(e,t){if(bh(e,t))return e}function Sh(e){let t=xh(e.stiffness),n=xh(e.damping,!0),r=xh(e.mass),i={...e,stiffness:t??eh,damping:n??th,mass:r??nh,isResolvedFromDuration:!1,isTimeDefined:(t??n??r)===void 0&&(e.duration!==void 0||e.bounce!==void 0)};if(i.isTimeDefined){if(e.visualDuration){let t=ph(e.bounce||0),n=2*Math.PI/(e.visualDuration*1.2)*mh(t,2*Math.PI/1.2);i.stiffness=n*n,i.damping=2*t*Math.sqrt(i.stiffness)}else Object.assign(i,yh(i)),i.isResolvedFromDuration=!0;bh(i.stiffness)&&bh(i.damping,!0)||(i.stiffness=eh,i.damping=th)}return i}function Ch(e=ah,t=ih){let n=typeof e==`object`?e:{visualDuration:e,keyframes:[0,1],bounce:t},r=n.keyframes[0],i=n.keyframes[n.keyframes.length-1],a={done:!1,value:r},{stiffness:o,damping:s,mass:c,duration:l,isResolvedFromDuration:u,isTimeDefined:d}=Sh({...n}),f=e=>d?0:-rp(e),p=s/(2*Math.sqrt(o*c)),m=rp(Math.sqrt(o/c)),h=p*m,g={target:i,delta:i-r,velocity:f(n.velocity||0)||0,restSpeed:0,restDelta:0},_=()=>{let e=Math.abs(g.delta)<5;g.restSpeed=n.restSpeed||(e?oh:sh),g.restDelta=n.restDelta||(e?ch:lh)};_();let v,y,b;if(p<1){let e=hh(m,p),t={A:0,sinC:0,cosC:0,t:-1,env:0,sin:0,cos:0};b=()=>{t.A=(g.velocity+h*g.delta)/e,t.sinC=h*t.A+g.delta*e,t.cosC=h*g.delta-t.A*e};let n=n=>{n!==t.t&&(t.t=n,t.env=Math.exp(-h*n),t.sin=Math.sin(e*n),t.cos=Math.cos(e*n))};v=e=>(n(e),g.target-t.env*(t.A*t.sin+g.delta*t.cos)),y=e=>(n(e),t.env*(t.sinC*t.sin+t.cosC*t.cos))}else if(p===1){v=e=>g.target-Math.exp(-m*e)*(g.delta+(g.velocity+m*g.delta)*e);let e={C:0};b=()=>{e.C=g.velocity+m*g.delta},y=t=>Math.exp(-m*t)*(m*e.C*t-g.velocity)}else{let e=m*Math.sqrt(p*p-1),t=h-e,n=h+e,r=e<1||d?1/0:300/e,i=(e,t)=>Math.exp(t>r?(h-e)*r-h*t:-e*t),a={S:0,F:0};b=()=>{let t=(g.velocity+h*g.delta)/e;a.S=(g.delta+t)/2,a.F=(g.delta-t)/2},v=e=>g.target-a.S*i(t,e)-a.F*i(n,e),y=e=>t*a.S*i(t,e)+n*a.F*i(n,e)}b();let x=u&&l||null,S={calculatedDuration:x,retarget:(e,t)=>{g.target=e[e.length-1],g.delta=g.target-e[0],g.velocity=f(t),n.restSpeed&&n.restDelta||_(),S.calculatedDuration=x,a.done=!1,b()},velocity:e=>np(y(e)),next:e=>{let t=v(e);if(u)a.done=e>=l;else{let n=np(y(e));a.done=Math.abs(n)<=g.restSpeed&&Math.abs(g.target-t)<=g.restDelta}return a.value=a.done?g.target:t,a},toString:()=>{let e=Math.min(Qm(S),Zm),t=Xm(t=>S.next(e*t).value,e,30);return e+`ms `+t},toTransition:()=>{}};return S}var wh=Object.assign(Ch,{applyToOptions:e=>{let t=$m(e,100,Ch);return e.ease=t.ease,e.duration=np(t.duration),e.type=`keyframes`,e}});function Th({keyframes:e,velocity:t=0,power:n=.8,timeConstant:r=325,bounceDamping:i=10,bounceStiffness:a=500,modifyTarget:o,min:s,max:c,restDelta:l=.5,restSpeed:u}){let d=e[0],f={done:!1,value:d},p=e=>e<s||e>c,m=e=>s===void 0?c:c===void 0||Math.abs(s-e)<Math.abs(c-e)?s:c,h=n*t,g=d+h,_=o?o(g):g;_!==g&&(h=_-d);let v=e=>-h*Math.exp(-e/r),y=e=>{let t=v(e);f.done=Math.abs(t)<=l,f.value=f.done?_:e?_+t:d},b,x,S=e=>{p(f.value)&&(b=e,x=wh({keyframes:[f.value,m(f.value)],velocity:-v(e)/r*1e3,damping:i,stiffness:a,restDelta:l,restSpeed:u}))};return S(0),{calculatedDuration:null,next:e=>{let t=!1;return!x&&b===void 0&&(t=!0,y(e),S(e)),b!==void 0&&e>=b?x.next(e-b):(!t&&y(e),f)}}}function Eh(e,t,n){let r=[],i=qf.mix||Vm,a=e.length-1;for(let o=0;o<a;o++){let a=n?.(e[o],e[o+1])||i(e[o],e[o+1]);t&&(a=$f(Array.isArray(t)?t[o]||Qf:t,a)),r.push(a)}return r}function Dh(e,t,{clamp:n=!0,ease:r,mixer:i}={}){let a=e.length;if(a===1)return()=>t[0];if(a===2&&t[0]===t[1])return()=>t[1];let o=e[0]===e[1];e[0]>e[a-1]&&(e=[...e].reverse(),t=[...t].reverse());let s=Eh(t,r,i),c=s.length,l=n=>{if(o&&n<e[0])return t[0];let r=0;if(c>1)for(;r<e.length-2&&!(n<e[r+1]);r++);let i=ep(e[r],e[r+1],n);return s[r](i)};return n?t=>l(Kf(e[0],e[a-1],t)):l}function Oh(e,t){let n=e[e.length-1];for(let r=1;r<=t;r++){let i=ep(0,t,r);e.push(Tm(n,1,i))}}function kh(e){let t=[0];return Oh(t,e.length-1),t}function Ah(e,t){return e.map(e=>e*t)}function jh(e,t){return e.map(()=>t||vp).splice(0,e.length-1)}function Mh({duration:e=300,keyframes:t,times:n,ease:r=`easeInOut`,mixer:i}){let a=typeof t[0]==`number`?void 0:i,o=yp(r)?r.map(Cp):Cp(r)||vp,s={done:!1,value:t[0]};if(!a&&t.length===2&&!Array.isArray(o)&&(!n||n.length!==2||n[0]===0&&n[1]===1)){let[n,r]=t,i=n===r?void 0:(qf.mix||Vm)(n,r);return{calculatedDuration:e,next:t=>(s.value=i?i(o(e>0?Kf(0,1,t/e):1)):r,s.done=t>=e,s)}}let c=Dh(Ah(n&&n.length===t.length?n:kh(t),e),t,{ease:Array.isArray(o)?o:jh(t,o),mixer:a});return{calculatedDuration:e,next:t=>(s.value=c(t),s.done=t>=e,s)}}var Nh=5;function Ph(e,t,n){let r=Math.max(t-Nh,0);return ip(n-e(r),t-r)}function Fh(e,t,n=0){return t<=0?n:e.velocity?e.velocity(t):Ph(t=>e.next(t).value,t,e.next(t).value)}var Ih=e=>e!==null;function Lh(e,{repeat:t,repeatType:n=`loop`},r,i=1){let a=e.filter(Ih),o=i<0||t&&n!==`loop`&&t%2==1?0:a.length-1;return!o||r===void 0?a[o]:r}var Rh={decay:Th,inertia:Th,tween:Mh,keyframes:Mh,spring:wh};function zh(e){typeof e.type==`string`&&(e.type=Rh[e.type])}var Bh=40,Vh=(e,t)=>t-e>Bh&&!qf.useManualTiming?t:e;function Hh(e,t){return{kind:e,animation:t,timestamp:Dp.now(),frameTimestamp:wp.timestamp,frameIsProcessing:wp.isProcessing}}function Uh(e,t,n){let r=globalThis.__MOTION_INSPECT__;if(r)try{r({...Hh(`animation-start`,e),options:n?{...t,...n}:t})}catch{}}function Wh(e,t){let n=globalThis.__MOTION_INSPECT__;if(n)try{n({...Hh(`layout-animation-start`,e),node:t})}catch{}}var Gh=class{constructor(){this.isResolved=!1}get finished(){return this._finished||=this.isResolved?Promise.resolve():new Promise(e=>{this._resolve=e}),this._finished}updateFinished(){this._finished=this._resolve=void 0,this.isResolved=!1}notifyFinished(){this.isResolved=!0,this._resolve?.()}then(e,t){return this.finished.then(e,t)}},Kh=e=>e/100,qh=e=>Math.round(e*1e4)/1e4,Jh=class extends Gh{constructor(e){super(),this.state=`idle`,this.startTime=null,this.isStopped=!1,this.currentTime=0,this.holdTime=null,this.playbackSpeed=1,this.delayState={done:!1,value:void 0},this.stop=()=>{let{motionValue:e}=this.options;e&&e.updatedAt!==Dp.now()&&this.tick(Dp.now()),this.isStopped=!0,this.state!==`idle`&&(this.teardown(),this.options.onStop?.())},this.options=e,this.initAnimation(),this.play(),e.autoplay===!1&&this.pause(),Uh(this,this.options)}initAnimation(){let{options:e}=this;zh(e);let{type:t=Mh,repeat:n=0,repeatDelay:r=0,repeatType:i,velocity:a=0}=e,{keyframes:o}=e,s=t||Mh;this.mixKeyframes=void 0,s!==Mh&&typeof o[0]!=`number`&&(this.mixKeyframes=$f(Kh,e.mixer?.(o[0],o[1])||Vm(o[0],o[1])),o=[0,100]);let c=s(o===e.keyframes?e:{...e,keyframes:o});i===`mirror`&&(this.mirroredGenerator=s({...e,keyframes:[...o].reverse(),velocity:-a})),c.calculatedDuration===null&&(c.calculatedDuration=Qm(c));let{calculatedDuration:l}=c;this.calculatedDuration=l,this.resolvedDuration=l+r,this.totalDuration=this.resolvedDuration*(n+1)-r,this.generator=c}updateTime(e){this.currentTime=this.holdTime??Math.round(e-this.startTime)*this.playbackSpeed}tick(e,t=!1){let{generator:n,totalDuration:r,calculatedDuration:i}=this;if(this.startTime===null)return n.next(0);let{delay:a=0,keyframes:o,type:s,onUpdate:c,finalKeyframe:l}=this.options;this.startTime===this.pendingStartTime&&(this.startTime=Vh(this.startTime,e)),this.pendingStartTime=void 0,this.speed>0?this.startTime=Math.min(this.startTime,e):this.speed<0&&(this.startTime=Math.min(e-r/this.speed,this.startTime)),t?this.currentTime=e:this.updateTime(e);let u=this.currentTime-a*(this.playbackSpeed>=0?1:-1),d=this.playbackSpeed>=0?u<0:u>r;this.currentTime=Math.max(u,0),this.state===`finished`&&this.holdTime===null&&(this.currentTime=r);let f=this.generate(this.currentTime,d),{done:p}=f;d||(p=this.playbackSpeed>=0?i<1/0?this.currentTime>=r:p:this.currentTime<=0);let m=this.holdTime===null&&(this.state===`finished`||this.state===`running`&&p);return m&&s!==Th&&(f.value=Lh(o,this.options,l,this.speed)),c&&c(f.value),m&&this.finish(),f}at(e){return this.holdTime??qh((e-this.startTime)*this.playbackSpeed)}sampleAt(e,t){let{options:n,totalDuration:r}=this,i=this.at(e)-(n.delay||0);return i>=r&&n.type!==Th?Lh(n.keyframes,n,t?void 0:n.finalKeyframe):this.generate(Math.max(i,0),i<0).value}generate(e,t){let{generator:n,totalDuration:r,mixKeyframes:i,mirroredGenerator:a,resolvedDuration:o}=this,{keyframes:s,repeat:c,repeatType:l,repeatDelay:u}=this.options,d=e,f=n;if(c){let t=Math.min(e,r)/o,n=Math.floor(t),i=t%1;!i&&t>=1&&(i=1),i===1&&n--,n=Math.min(n,c+1),n%2&&(l===`reverse`?(i=1-i,u&&(i-=u/o)):l===`mirror`&&(f=a)),d=Kf(0,1,i)*o}let p;return t?(this.delayState.value=s[0],p=this.delayState):p=f.next(d),i&&!t&&(p.value=i(p.value)),p}get duration(){return rp(this.calculatedDuration)}get iterationDuration(){return this.duration+rp(this.options.delay??0)}get time(){return rp(this.currentTime)}set time(e){e=np(e),this.currentTime=e,this.startTime===null||this.holdTime!==null||this.playbackSpeed===0?this.holdTime=e:this.driver&&(this.startTime=this.driver.now()-e/this.playbackSpeed),this.driver?this.driver.start(!1):(this.startTime=0,this.state=`paused`,this.holdTime=e,this.tick(e))}getGeneratorVelocity(){return Fh(this.generator,this.currentTime,this.options.velocity)}get speed(){return this.playbackSpeed}set speed(e){let t=this.playbackSpeed!==e;t&&this.driver&&this.updateTime(Dp.now()),this.playbackSpeed=e,t&&this.driver&&(this.time=rp(this.currentTime))}play(){if(this.isStopped)return;let{driver:e=Ym,startTime:t}=this.options;this.driver||=e(e=>this.tick(e)),this.options.onPlay?.();let n=this.driver.now();this.state===`finished`?(this.updateFinished(),this.startTime=n):this.holdTime===null?this.startTime||=t??(this.pendingStartTime=n):this.startTime=n-this.holdTime/(this.playbackSpeed||1),this.state===`finished`&&this.speed<0&&(this.startTime+=this.calculatedDuration),this.holdTime=null,this.state=`running`,this.driver.start()}pause(){this.state=`paused`,this.updateTime(Dp.now()),this.holdTime=this.currentTime}complete(){this.state!==`running`&&this.play(),this.state=`finished`,this.holdTime=null}finish(){this.notifyFinished(),this.teardown(),this.state=`finished`,this.options.onComplete?.()}cancel(){this.holdTime=null,this.startTime=0,this.tick(0),this.teardown(),this.options.onCancel?.()}teardown(){this.state=`idle`,this.driver?.stop(),this.driver=void 0,this.startTime=this.holdTime=null}sample(e){return this.startTime=0,this.tick(e,!0)}attachTimeline(e){return this.options.allowFlatten&&(this.options.type=`keyframes`,this.options.ease=`linear`,this.initAnimation()),this.driver?.stop(),e.observe(this)}},Yh=new Set([`brightness`,`contrast`,`saturate`,`opacity`]);function Xh(e){let[t,n]=e.slice(0,-1).split(`(`);if(t===`drop-shadow`)return e;let[r]=n.match(Rp)||[];if(!r)return e;let i=n.replace(r,``),a=+!!Yh.has(t);return r!==n&&(a*=100),t+`(`+a+i+`)`}var Zh=/\b([a-z-]*)\(.*?\)/gu,Qh={...xm,getAnimatableNone:e=>{let t=e.match(Zh);return t?t.map(Xh).join(` `):e}},$h={...xm,getAnimatableNone:e=>{let t=xm.parse(e);return xm.createTransformer(e)(t.map(e=>typeof e==`number`?0:typeof e==`object`?{...e,alpha:1}:e))}},eg={...Fp,transform:Math.round},tg={rotate:Xp,pathRotation:Xp,rotateX:Xp,rotateY:Xp,rotateZ:Xp,scale:Lp,scaleX:Lp,scaleY:Lp,scaleZ:Lp,skew:Xp,skewX:Xp,skewY:Xp,distance:$,translateX:$,translateY:$,translateZ:$,x:$,y:$,z:$,perspective:$,transformPerspective:$,opacity:Ip,originX:em,originY:em,originZ:$},ng={borderWidth:$,borderTopWidth:$,borderRightWidth:$,borderBottomWidth:$,borderLeftWidth:$,borderRadius:$,borderTopLeftRadius:$,borderTopRightRadius:$,borderBottomRightRadius:$,borderBottomLeftRadius:$,width:$,maxWidth:$,height:$,maxHeight:$,top:$,right:$,bottom:$,left:$,inset:$,insetBlock:$,insetBlockStart:$,insetBlockEnd:$,insetInline:$,insetInlineStart:$,insetInlineEnd:$,padding:$,paddingTop:$,paddingRight:$,paddingBottom:$,paddingLeft:$,paddingBlock:$,paddingBlockStart:$,paddingBlockEnd:$,paddingInline:$,paddingInlineStart:$,paddingInlineEnd:$,margin:$,marginTop:$,marginRight:$,marginBottom:$,marginLeft:$,marginBlock:$,marginBlockStart:$,marginBlockEnd:$,marginInline:$,marginInlineStart:$,marginInlineEnd:$,fontSize:$,backgroundPositionX:$,backgroundPositionY:$,...tg,zIndex:eg,fillOpacity:Ip,strokeOpacity:Ip,numOctaves:eg},rg={...ng,color:nm,backgroundColor:nm,outlineColor:nm,fill:nm,stroke:nm,borderColor:nm,borderTopColor:nm,borderRightColor:nm,borderBottomColor:nm,borderLeftColor:nm,filter:Qh,WebkitFilter:Qh,mask:$h,WebkitMask:$h},ig=e=>rg[e],ag=new Set([Qh,$h]);function og(e,t){let n=ig(e);return ag.has(n)||(n=xm),n.getAnimatableNone?n.getAnimatableNone(t):void 0}function sg(e){for(let t=1;t<e.length;t++)e[t]??(e[t]=e[t-1])}var cg=e=>e*180/Math.PI,lg=e=>dg(cg(Math.atan2(e[1],e[0]))),ug={x:4,y:5,translateX:4,translateY:5,scaleX:0,scaleY:3,scaleZ:()=>1,scale:e=>(Math.abs(e[0])+Math.abs(e[3]))/2,rotate:lg,rotateZ:lg,skewX:e=>cg(Math.atan(e[1])),skewY:e=>cg(Math.atan(e[2])),skew:e=>(Math.abs(e[1])+Math.abs(e[2]))/2},dg=e=>(e%=360,e<0&&(e+=360),e),fg=lg,pg=e=>Math.hypot(e[0],e[1]),mg=e=>Math.hypot(e[4],e[5]),hg={x:12,y:13,z:14,translateX:12,translateY:13,translateZ:14,scaleX:pg,scaleY:mg,scaleZ:e=>Math.hypot(e[8],e[9],e[10]),scale:e=>(pg(e)+mg(e))/2,rotateX:e=>dg(cg(Math.atan2(e[6],e[5]))),rotateY:e=>dg(cg(Math.atan2(-e[2],e[0]))),rotateZ:fg,rotate:fg,skewX:e=>cg(Math.atan(e[4])),skewY:e=>cg(Math.atan(e[1])),skew:e=>(Math.abs(e[1])+Math.abs(e[4]))/2};function gg(e){return+!!e.includes(`scale`)}function _g(e,t){if(!e||e===`none`)return gg(t);let n=e.match(/^matrix(3d)?\(([-\d.e\s,]+)\)$/u);if(!n)return gg(t);let r=(n[1]?hg:ug)[t],i=n[2].split(`,`).map(e=>parseFloat(e));return typeof r==`function`?r(i):i[r]}var vg=(e,t)=>{let{transform:n=`none`}=getComputedStyle(e);return _g(n,t)},yg=[`transformPerspective`,`x`,`y`,`z`,`translateX`,`translateY`,`translateZ`,`scale`,`scaleX`,`scaleY`,`scaleZ`,`rotate`,`rotateX`,`rotateY`,`rotateZ`,`skew`,`skewX`,`skewY`],bg=new Set([...yg,`pathRotation`]),xg=e=>e===Fp||e===$,Sg=new Set([`x`,`y`,`z`]),Cg=yg.filter(e=>!Sg.has(e));function wg(e){let t=[];return Cg.forEach(n=>{let r=e.getValue(n);if(r!==void 0){let e=r.get(),i=+!!n.startsWith(`scale`);if(e===i)return;t.push([n,e]),r.set(i)}}),t}var Tg=new Set([`bottom`,`right`]);function Eg(e,t,n,r,i,a){let o=parseFloat(e);if(!isNaN(o))return o;let{min:s,max:c}=t()[n],l=c-s;return a===`border-box`?l:l-parseFloat(r)-parseFloat(i)}var Dg=({transform:e})=>_g(e,`x`),Og=({transform:e})=>_g(e,`y`),kg={width:({width:e,paddingLeft:t=`0`,paddingRight:n=`0`,boxSizing:r},i)=>Eg(e,i,`x`,t,n,r),height:({height:e,paddingTop:t=`0`,paddingBottom:n=`0`,boxSizing:r},i)=>Eg(e,i,`y`,t,n,r),top:({top:e})=>parseFloat(e),left:({left:e})=>parseFloat(e),bottom:({top:e},t)=>{let{y:n}=t();return parseFloat(e)+(n.max-n.min)},right:({left:e},t)=>{let{x:n}=t();return parseFloat(e)+(n.max-n.min)},x:Dg,y:Og,translateX:Dg,translateY:Og},Ag=new Set,jg=!1,Mg=!1,Ng=!1;function Pg(){if(Mg){let e=[],t=new Set,n=new Set;Ag.forEach(r=>{r.needsMeasurement&&(e.push(r),t.add(r.element),Tg.has(r.name)&&n.add(r.element))});let r=new Map;n.forEach(e=>{let t=wg(e);t.length&&(r.set(e,t),e.render())}),e.forEach(e=>e.measureInitialState()),t.forEach(e=>{e.render();let t=r.get(e);t&&t.forEach(([t,n])=>{e.getValue(t)?.set(n)})}),e.forEach(e=>e.measureEndState()),e.forEach(e=>{e.suspendedScrollY!==void 0&&window.scrollTo(0,e.suspendedScrollY)})}Mg=!1,jg=!1,Ag.forEach(e=>e.complete(Ng)),Ag.clear()}function Fg(){Ag.forEach(e=>{e.readKeyframes(),e.needsMeasurement&&(Mg=!0)})}function Ig(){Ng=!0,Fg(),Pg(),Ng=!1}function Lg(e,t,n){if(typeof e==`string`){if(Jf(e)||Xf(e))return parseFloat(e);if(!xm.test(e)&&xm.test(n))return og(t,n)}return e??void 0}var Rg=class{constructor(e,t,n,r,i,a=!1){this.state=`pending`,this.isAsync=!1,this.needsMeasurement=!1,this.unresolvedKeyframes=[...e],this.onComplete=t,this.name=n,this.motionValue=r,this.element=i,this.isAsync=a}scheduleResolve(){this.state=`scheduled`,this.isAsync?(Ag.add(this),jg||(jg=!0,Km.read(Fg),Km.resolveKeyframes(Pg))):(this.readKeyframes(),this.complete())}readKeyframes(){let{unresolvedKeyframes:e,name:t,element:n,motionValue:r}=this;if(e[0]===null){let i=r?.get(),a=e[e.length-1];if(i!==void 0)e[0]=i;else if(n&&t){let r=Lg(n.readValue(t,a),t,a);r!==void 0&&(e[0]=r)}e[0]===void 0&&(e[0]=a),r&&i===void 0&&r.set(e[0])}sg(e)}setFinalKeyframe(){}measureInitialState(){}renderEndStyles(){}measureEndState(){}complete(e=!1){this.state=`complete`,this.onComplete(this.unresolvedKeyframes,this.finalKeyframe,e),Ag.delete(this)}cancel(){this.state===`scheduled`&&(Ag.delete(this),this.state=`pending`)}resume(){this.state===`pending`&&this.scheduleResolve()}},zg=e=>e.startsWith(`--`);function Bg(e,t,n){zg(t)?e.style.setProperty(t,n):e.style[t]=n}var Vg={};function Hg(e,t){let n=Zf(e);return()=>Vg[t]??n()}var Ug=Hg(()=>window.ScrollTimeline!==void 0,`scrollTimeline`),Wg=Hg(()=>{try{document.createElement(`div`).animate({opacity:0},{easing:`linear(0, 1)`})}catch{return!1}return!0},`linearEasing`),Gg=([e,t,n,r])=>`cubic-bezier(${e}, ${t}, ${n}, ${r})`,Kg={linear:`linear`,ease:`ease`,easeIn:`ease-in`,easeOut:`ease-out`,easeInOut:`ease-in-out`,circIn:Gg([0,.65,.55,1]),circOut:Gg([.55,0,1,.45]),backIn:Gg([.31,.01,.66,-.59]),backOut:Gg([.33,1.53,.69,.99])};function qg(e,t){if(e)return typeof e==`function`?Wg()?Xm(e,t):`ease-out`:bp(e)?Gg(e):Array.isArray(e)?e.map(e=>qg(e,t)||Kg.easeOut):Kg[e]}function Jg(e,t,n,{delay:r=0,duration:i=300,repeat:a=0,repeatType:o=`loop`,ease:s=`easeOut`,times:c}={},l=void 0){let u={[t]:n};c&&(u.offset=c);let d=qg(s,i);Array.isArray(d)&&(u.easing=d);let f={delay:r,duration:i,easing:Array.isArray(d)?`linear`:d,fill:`both`,iterations:a+1,direction:o===`reverse`?`alternate`:`normal`};return l&&(f.pseudoElement=l),e.animate(u,f)}function Yg(e){return typeof e==`function`&&`applyToOptions`in e}function Xg({type:e,...t}){return Yg(e)&&Wg()?e.applyToOptions(t):(t.duration??=300,t.ease??=`easeOut`,t)}var Zg=class extends Gh{constructor(e){if(super(),this.finishedTime=null,this.isStopped=!1,this.manualStartTime=null,!e)return;let{element:t,name:n,keyframes:r,pseudoElement:i,allowFlatten:a=!1,finalKeyframe:o,onComplete:s}=e;this.isPseudoElement=!!i,this.allowFlatten=a,this.options=e;let c=Xg(e);this.animation=Jg(t,n,r,c,i),c.autoplay===!1&&this.animation.pause(),this.animation.onfinish=()=>{if(this.finishedTime=this.time,!i){let e=Lh(r,this.options,o,this.speed);this.updateMotionValue?.(e),Bg(t,n,e),this.animation.cancel()}s?.(),this.notifyFinished()},Uh(this,e,c)}play(){this.isStopped||(this.manualStartTime=null,this.animation.play(),this.state===`finished`&&this.updateFinished())}pause(){this.animation.pause()}complete(){this.animation.finish?.()}cancel(){try{this.animation.cancel()}catch{}}stop(){this.isStopped||(this.isStopped=!0,this.state!==`idle`&&this.finishedTime===null&&(this.updateMotionValue?this.updateMotionValue():this.commitStyles(),this.isPseudoElement||(this.animation.onfinish=null,this.cancel())))}commitStyles(){let e=this.options?.element;!this.isPseudoElement&&e?.isConnected&&this.animation.commitStyles?.()}get duration(){let e=this.animation.effect?.getComputedTiming?.().duration||0;return rp(Number(e))}get iterationDuration(){let{delay:e=0}=this.options||{};return this.duration+rp(e)}get time(){return rp(Number(this.animation.currentTime)||0)}set time(e){let t=this.finishedTime!==null;this.manualStartTime=null,this.finishedTime=null,this.animation.currentTime=np(e),t&&this.animation.pause()}get speed(){return this.animation.playbackRate}set speed(e){e<0&&(this.finishedTime=null),this.animation.playbackRate=e}get state(){return this.finishedTime===null?this.animation.playState:`finished`}get startTime(){return this.manualStartTime??Number(this.animation.startTime)}set startTime(e){this.manualStartTime=this.animation.startTime=e}attachTimeline({timeline:e,onAttach:t,observe:n}){return this.allowFlatten&&this.animation.effect?.updateTiming({easing:`linear`}),this.animation.onfinish=null,e&&Ug()?(this.animation.timeline=e,t?.(this.animation),Qf):n(this)}},Qg={anticipate:fp,backInOut:dp,circInOut:hp};function $g(e){return e in Qg}function e_(e){typeof e.ease==`string`&&$g(e.ease)&&(e.ease=Qg[e.ease])}var t_=class extends Zg{constructor(e){e_(e),zh(e),super(e),e.startTime!==void 0&&e.autoplay!==!1&&(this.startTime=e.startTime),this.options=e}elapsed(){return this.state===`running`?(Dp.now()-this.startTime)*this.speed:this.time*1e3}sample(e){if(!this.sampler){let{motionValue:e,onUpdate:t,onComplete:n,onPlay:r,onStop:i,element:a,...o}=this.options;this.sampler=new Jh({...o,autoplay:!1}),this.sampler.stop()}return this.sampler.sample(Math.max(0,e)).value}liveValue(){let{state:e}=this;if(e===`running`||e===`paused`)return this.sample(this.elapsed())}updateMotionValue(e){let{motionValue:t,element:n,name:r}=this.options;if(!t)return;if(e!==void 0){t.set(e);return}let{speed:i}=this,a=this.elapsed(),o=this.state===`running`&&i?Kf(0,10,a):0,s=this.sample(a);n&&r&&Bg(n,r,s),t.setWithVelocity(this.sample(a-o*Math.sign(i)),s,o/Math.abs(i||1))}},n_=(e,t)=>t!==`zIndex`&&!!(typeof e==`number`||Array.isArray(e)||typeof e==`string`&&(xm.test(e)||e===`0`)&&!e.startsWith(`url(`));function r_(e){let t=e[0];if(e.length===1)return!0;for(let n=0;n<e.length;n++)if(e[n]!==t)return!0}function i_(e,t,n,r){let i=e[0];if(i===null)return!1;if(t===`display`||t===`visibility`)return!0;let a=e[e.length-1],o=n_(i,t),s=n_(a,t);return!o||!s?!1:r_(e)||(n===`spring`||Yg(n))&&r}function a_(e){e.duration=0,e.type=`keyframes`}var o_=new Set([`opacity`,`clipPath`,`filter`,`transform`]),s_=/^(?:oklch|oklab|lab|lch|color|color-mix|light-dark)\(/;function c_(e){for(let t=0;t<e.length;t++)if(typeof e[t]==`string`&&s_.test(e[t]))return!0;return!1}var l_=({mixer:e,keyframes:t})=>e&&typeof t[0]!=`number`&&t.some((n,r)=>r&&e(t[r-1],n)),u_=new Set([`color`,`backgroundColor`,`outlineColor`,`fill`,`stroke`,`borderColor`,`borderTopColor`,`borderRightColor`,`borderBottomColor`,`borderLeftColor`]),d_=()=>!qf.useManualTiming&&Object.hasOwnProperty.call(Element.prototype,`animate`);function f_(e){let{motionValue:t,name:n,repeatDelay:r,repeatType:i,damping:a,type:o,keyframes:s}=e;if(!n||!(o_.has(n)||u_.has(n)))return!1;let c=t?.owner?.current;if(!(c instanceof HTMLElement)&&!(c instanceof SVGElement))return!1;let{onUpdate:l,transformTemplate:u}=t.owner.getProps();return d_()&&(o_.has(n)||u_.has(n)&&c_(s))&&(n!==`transform`||!u)&&!l&&!r&&i!==`mirror`&&a!==0&&o!==`inertia`&&!l_(e)}var p_=(e,t)=>t&&typeof e==`number`?t.transform(e):e,m_={x:`translateX`,y:`translateY`,z:`translateZ`,transformPerspective:`perspective`},h_=yg.length,g_={},__=(e,t,n=p_(t,tg[e]))=>(g_[e]||(g_[e]=(m_[e]||e)+`(`))+n+`)`,v_=(e,t)=>(typeof t==`number`?t:parseFloat(t))===+!!e.startsWith(`scale`);function y_(e,t,n){let r=``;for(let i=0;i<h_;i++){let a=yg[i],o=e[a];if(o===void 0)continue;let s=n&&(t[a]=p_(o,ng[a]));v_(a,o)||(r+=__(a,o,s||void 0)+` `)}let i=e.pathRotation;return i&&(r+=__(`rotate`,i)),r=r.trim(),n?n(t,r):r||`none`}var b_=new WeakMap,x_=200,S_=.001,C_=.1,w_=.001,T_=100,E_=e=>/^(linear|ease(In|Out|InOut))$/.test(e),D_=(e,t)=>Math.abs(e-t)<=S_,O_=(e,t)=>e-t,k_=(e,t,n)=>kh(Array(n+1)).map(n=>Tm(e,t,n)),A_=e=>e.motionValue.owner,j_=e=>b_.get(e),M_=({state:e})=>e===`idle`||e===`finished`,N_=(e,t)=>e.latestValues?e.latestValues[t]:e.getValue(t)?.get(),P_=({name:e,motionValue:t})=>e&&yg.includes(e)&&t?.owner?.current instanceof HTMLElement&&d_()&&Wg();function F_(e){let t=A_(e),{onUpdate:n,transformTemplate:r}=t.getProps();return!e.isHandoff&&!n&&!e.hasOnUpdate&&!r&&e.type!==`inertia`&&(N_(t,`transform`)||`none`)===`none`&&!N_(t,`pathRotation`)&&!t.projection?.isProjecting()&&!l_(e)}var I_=class extends Jh{constructor(e){let t=A_(e).current,{driver:n=Ym}=e,r,i=F_(e);e.driver=e=>{let i=n(e);return{js:i,now:i.now,start:(e=!0)=>{let n=j_(t);!n||n.isJS?i.start(e):n.schedule(!1,!e)},stop:()=>{i.stop();let e=j_(t);e&&!e.isFinishing&&e.release(r)}}},super(e),r=this,this.canAccelerate=i;let{stop:a}=this;this.stop=()=>{this.isAccelerated()&&this.sync(),a()}}get group(){return j_(A_(this.options).current)}get js(){return this.driver?.js}get name(){return this.options.name}timing(){let{startTime:e,speed:t,totalDuration:n}=this,{delay:r=0,repeatType:i}=this.options;return this.holdTime===null?n===1/0?[e+r/t,this.resolvedDuration*(i===`loop`?1:2)/t||1]:[e+(r+n)/t,0]:[1/0,0]}isAccelerated(){let{group:e,state:t}=this;return e?.tracks.has(this)&&!e.isJS&&this.canAccelerate&&(t===`running`||t===`paused`)}liveValue(){return this.isAccelerated()?this.sampleAt(Dp.now()):void 0}tween(){let{keyframes:e,type:t,ease:n,times:r,repeat:i,delay:a=0}=this.options,o=bp(n)?Gg(n):E_(n)&&Kg[n];if(o&&!i&&!r&&e.length===2&&t===Mh&&this.holdTime===null){let e=this.startTime+a/this.speed;return[e,e+this.resolvedDuration/this.speed,o]}}boundaries(e,t){let{startTime:n,speed:r,resolvedDuration:i,options:a}=this,{delay:o=0,repeat:s=0,repeatDelay:c=0,repeatType:l,times:u,keyframes:d,type:f}=a,p=(f||Mh)===Mh?u||kh(d):[0,1],m=n+o/r,h=[];if(this.holdTime!==null||!(i>0))return h;for(let n=Math.max(0,Math.floor((e-m)*r/i));n<=s;n++){let a=m+n*i/r;if(a>t)break;for(let o of p){let s=a+(n%2&&l&&l!==`loop`?1-o:o)*(i-c)/r;s>e&&s<t&&h.push(s)}}return h}numberAt(e){return parseFloat(this.sampleAt(e,!0))}sync(){let e=Dp.now();this.options.motionValue.setWithVelocity(this.sampleAt(e-10,!0),this.sampleAt(e,!0),10)}play(){this.isStopped||((this.group||L_(A_(this.options))).tracks.add(this),super.play())}pause(){super.pause(),this.isAccelerated()&&(this.sync(),this.group.schedule(!1))}complete(){super.complete();let{group:e}=this;e&&!e.isJS&&this.canAccelerate&&this.tick(Dp.now())}get time(){return this.isAccelerated()?rp(Kf(0,this.totalDuration,this.at(Dp.now())-(this.options.delay||0))):super.time}set time(e){super.time=e,this.isAccelerated()&&this.sync()}attachTimeline(e){return this.canAccelerate=!1,this.group?.demote(!0),super.attachTimeline(e)}};function L_(e){let t=e.current,n=new Set,r=new Map,i={},a=[],o=new Map,s=[],c=!1,l=!1,u=!1,d=!1,f=-1/0,p=e=>{for(let t of n)if(t.name===e)return!0},m=(t,n)=>{let o={};for(let s of t===void 0?yg:a){let a=r.get(s),c=t===void 0?N_(e,s):a?a.sampleAt(n>t&&!a.timing()[1]?n:t):i[s];c!==void 0&&(o[s]=c)}return o},h=(e,t)=>{let n=``;for(let r in e){let i=e[r];t&&v_(r,i)||(n+=__(r,i)+` `)}return(t?n.trim():n)||`none`},g=(e,t)=>h(m(e,t)),_=(e=m())=>{t.style.transform=h(e,!0)},v=(e=!0)=>{e&&_(),s.forEach(({animation:e})=>e.cancel()),s=[]},y=(e,n)=>new Animation(new KeyframeEffect(t,e,n)),b=(e,t,n=1/0)=>{let r={animation:e,offset:t,end:n};e.startTime=Dp.now()+t,n<1/0&&(e.onfinish=()=>{r.isDone=!0,s.some(e=>e.end===1/0)&&(e.cancel(),s=s.filter(e=>e!==r)),A.schedule(!1)}),e.oncancel=()=>s.includes(r)&&A.demote(),s.push(r)},x=(e,t,n)=>{let r=(t,n)=>Math.abs(e(n)-e(t)),i=r(t,n);for(;n-t>.01;){let e=(t+n)/2;r(t,e)>r(e,n)?n=e:t=e}return r(t,n)>i/2?[t,n]:[]},S=(e,t,n,r)=>{let i=Math.min(x_,Math.max(2,Math.ceil((n-t)/10)));if(r.length*4>i)return;let a=k_(t,n,i).concat(r).sort(O_),o=e=>ep(t,n,e),s,c;for(let n of e){let e=n.numberAt(t),r=a.map(t=>n.numberAt(t)-e),i=r[r.length-1],o=r.some(e=>Math.abs(e)*S_>Math.abs(i))?0:i,l=r.map(e=>o?e/o:e);if(o&&!s)s=l,c=t=>(n.numberAt(t)-e)/o;else if(l.some((e,t)=>!D_(e,o&&s[t])))return}if(!s||s.every((e,t)=>D_(e,o(a[t]))))return`linear`;let l=[],u=(e,t=c(e))=>l.push(qh(t)+` `+qh(o(e)*100)+`%`);return s.forEach((e,t)=>{t&&Math.abs(e-s[t-1])>.2&&x(c,a[t-1],a[t]).forEach(e=>u(e)),u(a[t],e)}),`linear(`+l+`)`},C=(e,t,n,r)=>{let i=[t],a=(t,n)=>e.every(e=>!(Math.abs(e.numberAt((t+n)/2)-(e.numberAt(t)+e.numberAt(n))/2)>(e.name.startsWith(`scale`)?w_:C_))),o=(t,n,r)=>{if(n-t<1||a(t,n))i.push(n);else if(r<4)o(t,(t+n)/2,r+1),o((t+n)/2,n,r+1);else{for(let r of e)i.push(...x(e=>r.numberAt(e),t,n));i.push(n)}},s=k_(t,n,Math.ceil((n-t)/100));for(let e of r)s.push(e,Math.min(e+.01,n));let c=t;for(let e of s.sort(O_))e>c&&o(c,e,0),c=e;return i.sort(O_)},w=e=>{let t;for(let n of e){let e=n.tween();if(!e||t?.some((t,n)=>n<2?Math.abs(e[n]-t)>1:e[n]!==t))return;t=e}return t},T=(e,t,n,r,i={fill:`both`},a)=>{let o=e.flatMap(e=>e.boundaries(t,n)),s=r||S(e,t,n,o),c=s?[t,n]:C(e,t,n,o),l=c.map(e=>g(e,a)),u={transform:l};return s||(u.offset=c.map(e=>ep(t,n,e))),l.every(e=>e===l[0])&&(_(m(t,a)),u=null),y(u,{...i,duration:n-t,easing:s||`linear`})},E=t=>{let c=t,l=0,u=0,d=[],f=[],p=new Set;r.clear(),o=new Map;for(let e of n){r.set(e.name,e);let[n,i]=e.timing(),a=n===1/0;if(o.set(e,[e.at(t),e.speed,a]),a)e.sync();else{if(e.speed<0)return;if(i){if(l){let e=(n-u)/i;if(Math.abs(i-l)>1||Math.abs(e-Math.round(e))*l>1)return}else l=i,u=n;f.push(e)}else p.add(n);d.push(e),c=Math.max(c,n)}}i={},a=yg.filter(t=>{if(r.has(t))return!0;let n=i[t]=N_(e,t);return n!==void 0&&!v_(t,n)}),v(!1);let m=!l&&w(d);try{if(m&&m[1]>t){let[e,n,r]=m;b(T(d,e,n,r),e-t,n-e)}else c>t&&(b(T(d,t,c),0,c-t),p.forEach(e=>e<c-1&&b(y(null,{duration:e-t}),0,e-t)));if(l){let e=u+Math.floor((c-u)/l)*l;b(T(f,e,e+l,void 0,{iterations:1/0,iterationStart:(c-e)/l,fill:`forwards`},c),c-t)}}catch{return}return s.length||v(),!0},D=e=>{let t,r=0;for(let i of n){let n=o.get(i);if(!n)return!1;let[a,s,c]=n,l=i.at(e),u=i.timing()[0]===1/0;if(c){if(u&&l===a)continue;return!1}let d=(l-a)/s,f=u?0:i.speed/s;if(t===void 0)t=d,r=f;else if(Math.abs(d-t)>1||f!==r)return!1}if(t===void 0)return!0;if(!s.length)return!1;for(let{offset:e,end:n,isDone:r}of s){let i=t-e;if(n<1/0&&(r?i<n-1:i<0||i>=n))return!1}for(let{animation:n,offset:i,isDone:a}of s){if(a)continue;let o=t-i;r&&n.updatePlaybackRate&&n.playState===`running`&&Math.abs(Number(n.currentTime)-o)<20?n.playbackRate!==r&&n.updatePlaybackRate(r):r?(n.playbackRate=r,n.startTime=e-o/r):(n.startTime=null,n.currentTime=o)}return!0},O=()=>!n.size&&(u=!0,j_(t)===A&&b_.delete(t),A.isJS||v(),!0),k=()=>{let t=Dp.now();if(A.isJS||(A.isFinishing=!0,n.forEach(n=>{let[r,a]=n.timing();n.state===`running`&&n.speed>0&&!a&&r<=t+1&&(n.complete(),i[n.name]=N_(e,n.name),o.has(n)||(c=!0))}),A.isFinishing=!1),l=!1,u||(n.forEach(e=>M_(e)&&n.delete(e)),O()))return;for(let e of n)if(!e.canAccelerate)return A.demote(!0);A.isJS&&(A.isJS=!1,c=!0,n.forEach(e=>e.js?.stop()));let r=c,a=d;if(c=d=!1,r||!D(t)){if(a){if(t-f<T_)return A.demote();f=t}if(!E(t))return A.demote()}},A={tracks:n,isJS:!1,isFinishing:!1,schedule(e,t){u||(c||=e,d||=!!t,l||(l=!0,wp.isProcessing?Km.render(k,!1,!0):queueMicrotask(k)))},release(e){M_(e)&&n.delete(e),O()||A.schedule(!0)},check(){if(!A.isJS){for(let t in i)if(N_(e,t)!==i[t]&&!p(t))return A.schedule(!0,!0)}},demote(e){if(!(A.isJS||u))return n.forEach(t=>{t.isAccelerated()&&t.sync(),e||(t.canAccelerate=!1)}),A.isJS=!0,o=new Map,v(),n.forEach(e=>e.state===`running`&&e.js?.start()),!0}};return b_.set(t,A),A}var R_=class extends Gh{constructor(e){super(),this.stop=()=>{this._animation&&(this._animation.stop(),this.stopTimeline?.()),this.keyframeResolver?.cancel()},this.createdAt=Dp.now();let{keyframes:t,name:n,motionValue:r,element:i}=e,a=e;a.autoplay??=!0,a.delay??=0,a.type??=`keyframes`,a.repeat??=0,a.repeatDelay??=0,a.repeatType??=`loop`;let o=i?.KeyframeResolver||Rg;this.keyframeResolver=new o(t,(e,t,n)=>this.onKeyframesResolved(e,t,a,!n),n,r,i),this.keyframeResolver?.scheduleResolve()}onKeyframesResolved(e,t,n,r){this.keyframeResolver=void 0;let{name:i,type:a,velocity:o,delay:s,isHandoff:c,onUpdate:l}=n;this.resolvedAt=Dp.now();let u=i_(e,i,a,o);u||((qf.instantAnimations||!s)&&l?.(Lh(e,n,t)),e[0]=e[e.length-1],a_(n),n.repeat=0);let{onComplete:d}=n;n.finalKeyframe=t,n.keyframes=e,n.onComplete=()=>{d?.(),this.notifyFinished()};let f=u&&!c&&f_(n),p=!f&&P_(n);r&&(f||p||this.resolvedAt!==this.createdAt)&&(n.startTime??=Vh(this.createdAt,this.resolvedAt));let m;if(f){n.element=n.motionValue?.owner?.current;try{m=new t_(n)}catch{m=new Jh(n)}}else m=p?new I_(n):new Jh(n);this.pendingTimeline&&=(this.stopTimeline=m.attachTimeline(this.pendingTimeline),void 0),this._animation=m}get finished(){return this._animation?this._animation.finished:super.finished}then(e,t){return this.finished.finally(e).then(()=>{})}liveValue(){return this._animation?.liveValue?.()}get animation(){return this._animation||(this.keyframeResolver?.resume(),Ig()),this._animation}get duration(){return this.animation.duration}get iterationDuration(){return this.animation.iterationDuration}get time(){return this.animation.time}set time(e){this.animation.time=e}get speed(){return this.animation.speed}get state(){return this.animation.state}set speed(e){this.animation.speed=e}get startTime(){return this.animation.startTime}attachTimeline(e){return this._animation?this.stopTimeline=this.animation.attachTimeline(e):this.pendingTimeline=e,()=>this.stop()}play(){this.animation.play()}pause(){this.animation.pause()}complete(){this.animation.complete()}cancel(){this._animation?.cancel(),this.keyframeResolver?.cancel()}};function z_(e,t,n,r=0,i=1){let a=Array.from(e).sort((e,t)=>e.sortNodePosition(t)).indexOf(t),o=e.size,s=(o-1)*r;return typeof n==`function`?n(a,o):i===1?a*r:s-a*r}var B_=30,V_=e=>!isNaN(parseFloat(e)),H_={current:void 0},U_=class{constructor(e,t={}){this.canTrackVelocity=null,this.events={},this.updateAndNotify=e=>{let t=Dp.now();if(this.updatedAt!==t&&this.setPrevFrameValue(),this.prev=this.current,this.setCurrent(e),this.current!==this.prev&&(this.dirty(),this.dependents))for(let e of this.dependents)e.dirty()},this.hasAnimated=!1,this.setCurrent(e),this.owner=t.owner}setCurrent(e){this.current=e,this.updatedAt=Dp.now(),this.canTrackVelocity===null&&e!==void 0&&(this.canTrackVelocity=V_(this.current))}setPrevFrameValue(e=this.current){this.prevFrameValue=e,this.prevUpdatedAt=this.updatedAt}onChange(e){return this.on(`change`,e)}on(e,t){var n;return e===`change`?this.onChangeSubscribe(t):((n=this.events)[e]||(n[e]=new tp)).add(t)}onChangeSubscribe(e){let{events:t}=this;return!t.change&&!this.changeSubscriber?this.changeSubscriber=e:(t.change||(t.change=new tp,t.change.add(this.changeSubscriber),this.changeSubscriber=void 0),t.change.add(e)),()=>{this.changeSubscriber===e?this.changeSubscriber=void 0:t.change?.remove(e),this.stopIfUnobserved()}}stopIfUnobserved(){Km.read(()=>{!this.changeSubscriber&&!this.events.change?.getSize()&&this.stop()})}clearListeners(){this.changeSubscriber=void 0;for(let e in this.events)this.events[e].clear()}attach(e,t){this.passiveEffect=e,this.stopPassiveEffect=t}set(e){this.passiveEffect?this.passiveEffect(e,this.updateAndNotify):this.updateAndNotify(e)}setWithVelocity(e,t,n){this.set(t),this.prev=void 0,this.prevFrameValue=e,this.prevUpdatedAt=this.updatedAt-n}jump(e,t=!0){t&&(this.updatedAt=Dp.now(),this.stop()),this.updateAndNotify(e),this.prev=e,this.prevUpdatedAt=this.prevFrameValue=void 0,this.stopPassiveEffect?.()}dirty(){let{current:e,changeSubscriber:t}=this;t?t(e):this.events.change?.notify(e)}addDependent(e){(this.dependents||=new Set).add(e)}removeDependent(e){this.dependents?.delete(e)}get(){H_.current?.push(this);let e=this.animation?.liveValue?.();return e===void 0?this.current:e}getCurrent(){return this.current}getPrevious(){return this.prev}getVelocity(){let e=Dp.now();if(!this.canTrackVelocity||this.prevFrameValue===void 0||e-this.updatedAt>B_)return 0;let t=Math.min(this.updatedAt-this.prevUpdatedAt,B_);return ip(parseFloat(this.current)-parseFloat(this.prevFrameValue),t)}start(e){return this.stop(),new Promise(t=>{this.hasAnimated=!0;let n=!1,r;r=e(()=>{n=!0,this.events.animationComplete?.notify(),this.animation===r&&(this.animation=void 0),t()}),n||(this.animation=r),this.events.animationStart?.notify()})}stop(){this.animation&&(this.animation.stop(),this.events.animationCancel?.notify()),this.animation=void 0}isAnimating(){return!!this.animation}destroy(){this.dependents?.clear(),this.events.destroy?.notify(),this.clearListeners(),this.stop(),this.stopPassiveEffect?.()}};function W_(e,t){return new U_(e,t)}function G_(e,t){if(e?.inherit&&t){let{inherit:n,...r}=e;return{...t,...r}}return e}function K_(e,t){let n=e?.[t]??e?.default??e;return n===e?n:G_(n,e)}var q_={type:`spring`,stiffness:500,damping:25,restSpeed:10},J_=e=>({type:`spring`,stiffness:550,damping:e===0?2*Math.sqrt(550):30,restSpeed:10}),Y_={type:`keyframes`,duration:.8},X_={type:`keyframes`,ease:[.25,.1,.35,1],duration:.3},Z_=(e,{keyframes:t})=>t.length>2?Y_:bg.has(e)?e.startsWith(`scale`)?J_(t[1]):q_:X_,Q_=new Set([`when`,`delay`,`delayChildren`,`staggerChildren`,`staggerDirection`,`repeat`,`repeatType`,`repeatDelay`,`from`,`elapsed`,`out`,`mixer`]);function $_(e){for(let t in e)if(!Q_.has(t))return!0;return!1}var ev=(e,t,n,r={},i,a)=>o=>{let s=K_(r,e)||{},c=s.delay||r.delay||0,{elapsed:l=0}=r;l-=np(c);let u={keyframes:Array.isArray(n)?n:[null,n],ease:`easeOut`,velocity:t.getVelocity(),...s,delay:-l,onUpdate:e=>{t.set(e),s.onUpdate&&s.onUpdate(e)},onComplete:()=>{o(),s.onComplete&&s.onComplete()},name:e,motionValue:t,element:a?void 0:i,hasOnUpdate:!!s.onUpdate};$_(s)||Object.assign(u,Z_(e,u)),u.duration&&=np(u.duration),u.repeatDelay&&=np(u.repeatDelay),u.from!==void 0&&(u.keyframes[0]=u.from);let d=!1;if((u.type===!1||u.duration===0&&!u.repeatDelay)&&(a_(u),u.delay===0&&(d=!0)),(qf.instantAnimations||qf.skipAnimations||i?.shouldSkipAnimations||s.skipAnimations)&&(d=!0,a_(u),u.delay=0),u.allowFlatten=!s.type&&!s.ease,d&&!a&&t.get()!==void 0){let e=Lh(u.keyframes,s);if(e!==void 0){Km.update(()=>{u.onUpdate(e),u.onComplete()});return}}return s.isSync?new Jh(u):new R_(u)},tv=/^var\(--(?:([\w-]+)|([\w-]+), ?([a-zA-Z\d ()%#.,-]+))\)/u;function nv(e){let t=tv.exec(e);if(!t)return[,];let[,n,r,i]=t;return[`--${n??r}`,i]}function rv(e,t,n=1){let[r,i]=nv(e);if(!r)return;let a=window.getComputedStyle(t).getPropertyValue(r);if(a){let e=a.trim();return Jf(e)?parseFloat(e):e}return Mp(i)?rv(i,t,n+1):i}function iv(e){let t=[{},{}];return e?.values.forEach((e,n)=>{t[0][n]=e.get(),t[1][n]=e.getVelocity()}),t}function av(e,t,n,r){let i=t=>typeof t==`function`?t(n===void 0?e.custom:n,...iv(r)):t;return t=i(t),typeof t==`string`&&(t=e.variants&&e.variants[t]),i(t)}function ov(e,t,n){return av(e.getProps(),t,n,e)}var sv=(e,t)=>t===`exit`?e.presenceContext?.custom:void 0,cv=new Set([`width`,`height`,`top`,`left`,`right`,`bottom`,...yg]),lv=e=>Array.isArray(e);function uv(e,t,n){e.hasValue(t)?e.getValue(t).set(n):e.addValue(t,W_(n))}function dv(e){return lv(e)?e[e.length-1]||0:e}function fv(e,t){let{transitionEnd:n={},transition:r={},...i}=ov(e,t)||{};i={...i,...n};for(let t in i)uv(e,t,dv(i[t]))}var pv=e=>!!(e&&e.getVelocity);function mv(e){return!!(pv(e)&&e.add)}function hv(e,t){let n=e.getValue(`willChange`);if(mv(n))return n.add(t);if(!n&&qf.WillChange){let n=new qf.WillChange(`auto`);e.addValue(`willChange`,n),n.add(t)}}var gv=`data-framer-appear-id`;function _v(e){return e.props[gv]}var vv=typeof window<`u`;function yv({protectedKeys:e,needsAnimating:t},n){let r=n in e&&!t[n];return t[n]=!1,r}function bv(e,t,{delay:n=0,transitionOverride:r,type:i}={}){let{transition:a,transitionEnd:o,...s}=t,c=e.getDefaultTransition();a=a?G_(a,c):c;let l=a?.reduceMotion,u=a?.skipAnimations;r&&(a=r);let d=[],f=i&&e.animationState?.getState()[i],p=a?.path;p&&(p.animateValues?p.animateValues(t=>e.getValue(t,e.latestValues[t]??0),s,a,n,d):p.animateVisualElement?.(e,s,a,n,d));for(let t in s){let r=e.getValue(t,e.latestValues[t]??null),i=s[t];if(i===void 0||f&&yv(f,t))continue;let o={delay:n,...K_(f?.out[t]||a||{},t)};u&&(o.skipAnimations=!0);let c=r.get();if(c!==void 0&&!r.isAnimating()&&!Array.isArray(i)&&i===c&&!o.velocity){Km.update(()=>r.set(i));continue}let p=!1;if(vv&&window.MotionHandoffAnimation){let n=_v(e);if(n){let e=window.MotionHandoffAnimation(n,t,Km);e!==null&&(o.startTime=e,p=!0)}}hv(e,t);let m=l??e.shouldReduceMotion;r.start(ev(t,r,i,m&&cv.has(t)?{type:!1}:o,e,p));let h=r.animation;h&&d.push(h)}if(o){let t=()=>Km.update(()=>{o&&fv(e,o)});d.length?Promise.all(d).then(t):t()}return d}function xv(e,t,n={}){let r=ov(e,t,sv(e,n.type)),i=n.transitionOverride||(r?.transition??(e.getDefaultTransition()||{})),a=()=>Promise.all(r?bv(e,r,n):[]),o=(r=0)=>{let{variantChildren:a}=e,{delayChildren:o=0,staggerChildren:s,staggerDirection:c}=i,l=[];return a?.forEach(e=>{e.notify(`AnimationStart`,t),l.push(xv(e,t,{...n,delay:r+(typeof o==`function`?0:o)+z_(a,e,o,s,c)}).then(()=>e.notify(`AnimationComplete`,t)))}),Promise.all(l)},{when:s}=i;return s?s===`beforeChildren`?a().then(()=>o()):o().then(a):Promise.all([a(),o(n.delay)])}function Sv(e,t,n={}){return e.notify(`AnimationStart`,t),(Array.isArray(t)?Promise.all(t.map(t=>xv(e,t,n))):typeof t==`string`?xv(e,t,n):Promise.all(bv(e,ov(e,t,n.custom),n))).then(()=>{e.notify(`AnimationComplete`,t)})}var Cv={test:e=>e===`auto`,parse:e=>e},wv=e=>t=>t.test(e),Tv=[Fp,$,Zp,Xp,$p,Qp,Cv],Ev=e=>Tv.find(wv(e));function Dv(e){return typeof e==`number`?e===0:e===null||e===`none`||e===`0`||Xf(e)}var Ov=new Set([`auto`,`none`,`0`]);function kv(e,t,n){let r=0,i;for(;r<e.length&&!i;){let t=e[r];typeof t==`string`&&!Ov.has(t)&&pm(t)&&(i=e[r]),r++}if(i&&n)for(let r of t)e[r]!==i&&(e[r]=og(n,i))}var Av=class extends Rg{constructor(){super(...arguments),this.isAsync=!0}scheduleResolve(){if(this.canReadNow()&&(this.readKeyframes(),!this.needsMeasurement))return this.complete();super.scheduleResolve()}canReadNow(){let{unresolvedKeyframes:e,element:t,motionValue:n}=this,r=e[0]??n?.get();if(!t?.current||r===void 0)return!1;for(let t=0;t<e.length;t++)if(Pp(t?e[t]:r))return!1;return!0}readKeyframes(){let{unresolvedKeyframes:e,element:t,name:n}=this;if(!t?.current)return;super.readKeyframes();for(let n=0;n<e.length;n++){let r=e[n];if(typeof r==`string`&&(r=r.trim(),Mp(r))){let i=rv(r,t.current);i!==void 0&&(e[n]=i),n===e.length-1&&(this.finalKeyframe=r)}}if(this.resolveNoneKeyframes(),!cv.has(n)||e.length!==2)return;let[r,i]=e;if(typeof r==`number`&&typeof i==`number`)return;let a=Ev(r),o=Ev(i);if(Pp(r)!==Pp(i)&&kg[n])this.needsMeasurement=!0;else if(a!==o){if(xg(a)&&xg(o))for(let t=0;t<e.length;t++){let n=e[t];typeof n==`string`&&(e[t]=parseFloat(n))}else kg[n]&&(this.needsMeasurement=!0)}}resolveNoneKeyframes(){let{unresolvedKeyframes:e,name:t}=this,n=[];for(let t=0;t<e.length;t++)(e[t]===null||Dv(e[t]))&&n.push(t);n.length&&kv(e,n,t)}measure(){let{element:e,name:t}=this;return kg[t](window.getComputedStyle(e.current),()=>e.measureViewportBox())}measureInitialState(){let{element:e,unresolvedKeyframes:t,name:n}=this;if(!e?.current)return;n===`height`&&(this.suspendedScrollY=window.pageYOffset),this.measuredOrigin=this.measure(),t[0]=this.measuredOrigin;let r=t[t.length-1];r!==void 0&&this.motionValue?.jump(r,!1)}measureEndState(){let{element:e,unresolvedKeyframes:t}=this;if(!e?.current)return;this.motionValue?.jump(this.measuredOrigin,!1);let n=t.length-1,r=t[n];t[n]=this.measure(),r!==null&&this.finalKeyframe===void 0&&(this.finalKeyframe=r),this.resolveNoneKeyframes()}},jv=[`borderTopLeftRadius`,`borderTopRightRadius`,`borderBottomRightRadius`,`borderBottomLeftRadius`];function Mv(e){return Yf(e)&&`offsetHeight`in e&&!(`ownerSVGElement`in e)}function Nv(e){return Yf(e)&&`ownerSVGElement`in e}var Pv={};function Fv(e){return Pv.current?.add(e),e}var Iv=e=>Pv.current?Pv.current.bind(e):e;function Lv(e,t,n){if(e==null)return[];if(e instanceof EventTarget)return[e];if(typeof e==`string`){let r=t?t.current:Pv.current?.root||document,i=n?.[e]??r.querySelectorAll(e);return i?Array.from(i):[]}return Array.from(e).filter(e=>e!=null)}function Rv(e){return e.replace(/([A-Z])/g,e=>`-${e.toLowerCase()}`)}function zv(e,t,n){let{style:r,vars:i,transformOrigin:a}=e,o=!1,s=!1;for(let e in t){let n=t[e];if(bg.has(e))o=!0;else if(Ap(e))i[e]=n;else{let t=p_(n,ng[e]);e.startsWith(`origin`)?(s=!0,a[e]=t):r[e]=t}}if(t.transform||(o||n?r.transform=y_(t,e.transform,n):r.transform&&=`none`),s){let{originX:e=`50%`,originY:t=`50%`,originZ:n=0}=a;r.transformOrigin=`${e} ${t} ${n}`}}var Bv={offset:`stroke-dashoffset`,array:`stroke-dasharray`},Vv={offset:`strokeDashoffset`,array:`strokeDasharray`};function Hv(e,t,n=1,r=0,i=!0){e.pathLength=1;let a=i?Bv:Vv;e[a.offset]=`${-r}`,e[a.array]=`${t} ${n}`}var Uv=[`transform`,`opacity`,`clipPath`,`filter`,`offsetDistance`,`offsetPath`,`offsetRotate`,`offsetAnchor`];function Wv(e,{attrX:t,attrY:n,attrScale:r,pathLength:i,pathSpacing:a=1,pathOffset:o=0,...s},c,l,u){if(zv(e,s,l),c){e.style.viewBox&&(e.attrs.viewBox=e.style.viewBox);return}e.attrs=e.style,e.style={};let{attrs:d,style:f}=e;for(let e of Uv)d[e]!==void 0&&(f[e]=d[e],delete d[e]);(f.transform||d.transformOrigin)&&(f.transformOrigin=d.transformOrigin??`50% 50%`,delete d.transformOrigin),f.transform&&(f.transformBox=u?.transformBox??`fill-box`,delete d.transformBox),t!==void 0&&(d.x=t),n!==void 0&&(d.y=n),r!==void 0&&(d.scale=r),i!==void 0&&Hv(d,i,a,o,!1)}function Gv({top:e,left:t,right:n,bottom:r}){return{x:{min:t,max:n},y:{min:e,max:r}}}function Kv({x:e,y:t}){return{top:t.min,right:e.max,bottom:t.max,left:e.min}}function qv(e,t){if(!t)return e;let n=t({x:e.left,y:e.top}),r=t({x:e.right,y:e.bottom});return{top:n.y,left:n.x,bottom:r.y,right:r.x}}function Jv(e){return e===void 0||e===1}function Yv({scale:e,scaleX:t,scaleY:n}){return!Jv(e)||!Jv(t)||!Jv(n)}var Xv=[`rotate`,`rotateX`,`rotateY`,`rotateZ`,`skewX`,`skewY`];function Zv(e){return Yv(e)||$v(e)||Qv(e)}function Qv(e){return e.z||e.rotate||e.rotateX||e.rotateY||e.rotateZ||e.skewX||e.skewY}function $v(e){return ey(e.x)||ey(e.y)}function ey(e){return e&&e!==`0%`}function ty(e,t,n){return n+t*(e-n)}function ny(e,t,n,r,i){return i!==void 0&&(e=ty(e,i,r)),ty(e,n,r)+t}function ry(e,t=0,n=1,r,i){e.min=ny(e.min,t,n,r,i),e.max=ny(e.max,t,n,r,i)}function iy(e,{x:t,y:n}){ry(e.x,t.translate,t.scale,t.originPoint),ry(e.y,n.translate,n.scale,n.originPoint)}var ay=.999999999999,oy=1.0000000000001;function sy(e,t,n,r=!1){let i=n.length;if(!i)return;t.x=t.y=1;let a,o;for(let s=0;s<i;s++)a=n[s],o=a.projectionDelta,a.options.visualElement?.props.style?.display!==`contents`&&(r===!0&&a.options.layoutScroll&&a.scroll&&a!==a.root&&(cy(e.x,-a.scroll.offset.x),cy(e.y,-a.scroll.offset.y)),o&&(t.x*=o.x.scale,t.y*=o.y.scale,iy(e,o)),r&&(r.path?.[s]||r)!==a&&Zv(a.latestValues)&&dy(e,a.latestValues,a.layout?.layoutBox));t.x<oy&&t.x>ay&&(t.x=1),t.y<oy&&t.y>ay&&(t.y=1)}function cy(e,t){e.min+=t,e.max+=t}function ly(e,t,n,r,i=.5){ry(e,t,n,Tm(e.min,e.max,i),r)}function uy(e,t){return typeof e==`string`?parseFloat(e)/100*(t.max-t.min):e}function dy(e,t,n){let r=n??e;ly(e.x,uy(t.x,r.x),t.scaleX,t.scale,t.originX),ly(e.y,uy(t.y,r.y),t.scaleY,t.scale,t.originY)}function fy(e,t){return Gv(qv(e.getBoundingClientRect(),t))}function py(e,t,n){let r=fy(e,n),{scroll:i}=t;return i&&(cy(r.x,i.offset.x),cy(r.y,i.offset.y)),r}var my=()=>({x:document.documentElement.scrollLeft||document.body?.scrollLeft||0,y:document.documentElement.scrollTop||document.body?.scrollTop||0}),{schedule:hy,cancel:gy}=Gm(queueMicrotask,!1);function _y(e,t,n){let r=pv(e)?e:W_(e);return r.start(ev(``,r,t,n)),r.animation}var vy={},yy={value:null,addProjectionMetrics:null,countProjection:void 0};function by(e,t){let n=Dp.now();e=Iv(e);let r=({timestamp:i})=>{let a=i-n;a>=t&&(qm(r),e(a-t))};return Km.setup(r,!0),Fv(()=>qm(r))}function xy(e){return e&&typeof e==`object`&&Object.prototype.hasOwnProperty.call(e,`current`)}function Sy(e){return Nv(e)&&e.tagName===`svg`}function Cy(e){return pv(e)?e.get():e}var wy=e=>typeof e==`number`?e:parseFloat(e),Ty=jv.length,Ey=e=>typeof e==`number`||$.test(e);function Dy(e,t,n,r,i,a){i?(e.opacity=Tm(0,n.opacity??1,ky(r)),e.opacityExit=Tm(t.opacity??1,0,Ay(r))):a&&(e.opacity=Tm(t.opacity??1,n.opacity??1,r));for(let i=0;i<Ty;i++){let a=jv[i],o=Oy(t,a),s=Oy(n,a);(o!==void 0||s!==void 0)&&(o||=0,s||=0,o===0||s===0||Ey(o)===Ey(s)?(e[a]=Math.max(Tm(wy(o),wy(s),r),0),(Zp.test(s)||Zp.test(o))&&(e[a]+=`%`)):e[a]=s)}for(let i=0;i<Xv.length;i++){let a=Xv[i];(t[a]||n[a])&&(e[a]=Tm(t[a]||0,n[a]||0,r))}}function Oy(e,t){return e[t]===void 0?e.borderRadius:e[t]}var ky=jy(0,.5,mp),Ay=jy(.5,.95,Qf);function jy(e,t,n){return r=>r<e?0:r>t?1:n(ep(e,t,r))}function My(e,t){e.min=t.min,e.max=t.max}function Ny(e,t){My(e.x,t.x),My(e.y,t.y)}function Py(e,t){e.translate=t.translate,e.scale=t.scale,e.originPoint=t.originPoint,e.origin=t.origin}var Fy=.9999,Iy=1.0001,Ly=-.01,Ry=.01;function zy(e){return e.max-e.min}function By(e,t,n){return Math.abs(e-t)<=n}function Vy(e,t,n,r=.5){e.origin=r,e.originPoint=Tm(t.min,t.max,e.origin),e.scale=zy(n)/zy(t),e.translate=Tm(n.min,n.max,e.origin)-e.originPoint,(e.scale>=Fy&&e.scale<=Iy||isNaN(e.scale))&&(e.scale=1),(e.translate>=Ly&&e.translate<=Ry||isNaN(e.translate))&&(e.translate=0)}function Hy(e,t,n,r){Vy(e.x,t.x,n.x,r?.originX),Vy(e.y,t.y,n.y,r?.originY)}function Uy(e,t,n,r=0){e.min=(r?Tm(n.min,n.max,r):n.min)+t.min,e.max=e.min+zy(t)}function Wy(e,t,n,r){Uy(e.x,t.x,n.x,r?.x),Uy(e.y,t.y,n.y,r?.y)}function Gy(e,t,n,r=0){let i=r?Tm(n.min,n.max,r):n.min;e.min=t.min-i,e.max=e.min+zy(t)}function Ky(e,t,n,r){Gy(e.x,t.x,n.x,r?.x),Gy(e.y,t.y,n.y,r?.y)}function qy(e,t,n,r,i){return e-=t,e=ty(e,1/n,r),i!==void 0&&(e=ty(e,1/i,r)),e}function Jy(e,t=0,n=1,r=.5,i,a=e,o=e){if(Zp.test(t)&&(t=parseFloat(t),t=Tm(o.min,o.max,t/100)-o.min),typeof t!=`number`)return;let s=Tm(a.min,a.max,r);e===a&&(s-=t),e.min=qy(e.min,t,n,s,i),e.max=qy(e.max,t,n,s,i)}function Yy(e,t,[n,r,i],a,o){Jy(e,t[n],t[r],t[i],t.scale,a,o)}var Xy=[`x`,`scaleX`,`originX`],Zy=[`y`,`scaleY`,`originY`];function Qy(e,t,n,r){Yy(e.x,t,Xy,n?.x,r?.x),Yy(e.y,t,Zy,n?.y,r?.y)}var $y=e=>typeof navigator<`u`&&navigator.userAgent&&navigator.userAgent.toLowerCase().includes(e),eb=$y(`applewebkit/`)&&!$y(`chrome/`)?Math.round:Qf;function tb(e){e.min=eb(e.min),e.max=eb(e.max)}function nb(e){tb(e.x),tb(e.y)}var rb=()=>({translate:0,scale:1,origin:0,originPoint:0}),ib=()=>({x:rb(),y:rb()}),ab=()=>({min:0,max:0}),ob=()=>({x:ab(),y:ab()});function sb(e){return e.translate===0&&e.scale===1}function cb(e){return sb(e.x)&&sb(e.y)}function lb(e,t){return e.min===t.min&&e.max===t.max}function ub(e,t){return lb(e.x,t.x)&&lb(e.y,t.y)}function db(e,t){return Math.round(e.min)===Math.round(t.min)&&Math.round(e.max)===Math.round(t.max)}function fb(e,t){return db(e.x,t.x)&&db(e.y,t.y)}function pb(e){return zy(e.x)/zy(e.y)}function mb(e,t){return e.translate===t.translate&&e.scale===t.scale&&e.originPoint===t.originPoint}var hb=class{constructor(){this.members=[]}add(e){Uf(this.members,e);for(let t=this.members.length-1;t>=0;t--){let n=this.members[t];if(n===e||n===this.lead||n===this.prevLead)continue;let r=n.instance;r&&r.isConnected!==!1||n.snapshot||(Wf(this.members,n),n.unmount())}e.scheduleRender()}remove(e){if(Wf(this.members,e),e===this.prevLead&&(this.prevLead=void 0),e===this.lead){let e=this.members[this.members.length-1];e&&this.promote(e)}}relegate(e){for(let t=this.members.indexOf(e)-1;t>=0;t--){let e=this.members[t];if(e.isPresent!==!1&&e.instance?.isConnected!==!1)return this.promote(e),!0}return!1}promote(e,t){let n=this.lead;if(e!==n&&(this.prevLead=n,this.lead=e,e.show(),n)){n.updateSnapshot(),e.scheduleRender();let{layoutDependency:r}=n.options,{layoutDependency:i}=e.options;(r===void 0||r!==i)&&(e.resumeFrom=n,t&&(n.preserveOpacity=!0),n.snapshot&&(e.snapshot=n.snapshot,e.snapshot.latestValues=n.animationValues||n.latestValues),e.root?.isUpdating&&(e.isLayoutDirty=!0)),e.options.crossfade===!1&&n.hide()}}exitAnimationComplete(){this.members.forEach(e=>{e.options.onExitComplete?.(),e.resumingFrom?.options.onExitComplete?.()})}scheduleRender(){this.members.forEach(e=>e.instance&&e.scheduleRender(!1))}removeLeadSnapshot(){this.lead?.snapshot&&(this.lead.snapshot=void 0)}};function gb(e,t){return t.max===t.min?0:e/(t.max-t.min)*100}var _b={correct:(e,t)=>{if(!t.target)return e;if(typeof e==`string`){if($.test(e))e=parseFloat(e);else return e}return`${gb(e,t.target.x)}% ${gb(e,t.target.y)}%`}},vb={borderRadius:Object.assign({},_b,{applyTo:jv.slice()}),borderTopLeftRadius:_b,borderTopRightRadius:_b,borderBottomLeftRadius:_b,borderBottomRightRadius:_b,boxShadow:{correct:(e,{treeScale:t,projectionDelta:n})=>{let r=e,i=xm.parse(e);if(i.length>5)return r;let a=xm.createTransformer(e),o=typeof i[0]==`number`?0:1,s=n.x.scale*t.x,c=n.y.scale*t.y;i[0+o]/=s,i[1+o]/=c;let l=Tm(s,c,.5);return typeof i[2+o]==`number`&&(i[2+o]/=l),typeof i[3+o]==`number`&&(i[3+o]/=l),a(i)}}};function yb(e,t,n){let r=``,i=e.x.translate/t.x,a=e.y.translate/t.y,o=n?.z||0;if((i||a||o)&&(r=`translate3d(${i}px, ${a}px, ${o}px) `),(t.x!==1||t.y!==1)&&(r+=`scale(${1/t.x}, ${1/t.y}) `),n){let{transformPerspective:e}=n;e&&(r=`perspective(${e}px) ${r}`);for(let e=0;e<Xv.length;e++){let t=Xv[e],i=n[t];i&&(r+=`${t}(${i}deg) `),!e&&n.pathRotation&&(r+=`rotate(${n.pathRotation}deg) `)}}let s=e.x.scale*t.x,c=e.y.scale*t.y;return(s!==1||c!==1)&&(r+=`scale(${s}, ${c})`),r||`none`}function bb(e){return[e(`x`),e(`y`)]}var xb=(e,t)=>e.depth-t.depth,Sb=class{constructor(){this.children=[],this.isDirty=!1}add(e){Uf(this.children,e),this.isDirty=!0}remove(e){Wf(this.children,e),this.isDirty=!0}forEach(e){this.isDirty&&this.children.sort(xb),this.isDirty=!1,this.children.forEach(e)}},Cb={hasAnimatedSinceResize:!0,hasEverUpdated:!1},wb=[`z`,`skew`,`skewZ`],Tb=1e3,Eb=0;function Db(e,t,n,r){let{latestValues:i}=t;i[e]&&(n[e]=i[e],t.setStaticValue(e,0),r&&(r[e]=0))}var Ob=e=>e.instance&&b_.get(e.instance)?.demote()&&e.resetSkewAndRotation();function kb(e){if(e.hasCheckedOptimisedAppear=!0,e.root===e)return;let{visualElement:t}=e.options;if(!t)return;let n=_v(t);if(window.MotionHasOptimisedAnimation(n,`transform`)){let{layout:t,layoutId:r}=e.options;window.MotionCancelOptimisedAnimation(n,`transform`,Km,!(t||r))}let{parent:r}=e;r&&!r.hasCheckedOptimisedAppear&&kb(r)}function Ab(e){if(e)return e.options.allowProjection===!1?Ab(e.parent):e.projection}function jb({attachResizeListener:e,defaultParent:t,measureScroll:n,checkIsScrollRoot:r,resetTransform:i}){return Object.assign(vy,{...vb,...vy}),class{static create(e,t,n){let{layoutId:r,layout:i,drag:a,dragConstraints:o,layoutScroll:s,layoutRoot:c,layoutAnchor:l,layoutCrossfade:u}=t,d=e.projection=new this(e.latestValues,t[`data-framer-portal-id`]?void 0:Ab(e.parent));d.setOptions({layoutId:r,layout:i,alwaysMeasureLayout:!!a||o&&xy(o),visualElement:e,animationType:typeof i==`string`?i:`both`,initialPromotionConfig:n,crossfade:u,layoutScroll:s,layoutRoot:c,layoutAnchor:l});let f=d.getStack()?.lead;f&&!d.root.isUpdateBlocked()&&(f.willUpdate(),f.scheduleCheckAfterUnmount())}constructor(e={},n=t?.()){this.id=Eb++,this.animationId=0,this.animationCommitId=0,this.children=new Set,this.options={},this.isTreeAnimating=!1,this.isAnimationBlocked=!1,this.isLayoutDirty=!1,this.isProjectionDirty=!1,this.isSharedProjectionDirty=!1,this.isTransformDirty=!1,this.updateManuallyBlocked=!1,this.updateBlockedByResize=!1,this.isUpdating=!1,this.isSVG=!1,this.needsReset=!1,this.shouldResetTransform=!1,this.hasCheckedOptimisedAppear=!1,this.treeScale={x:1,y:1},this.eventHandlers=new Map,this.hasTreeAnimated=!1,this.updateScheduled=!1,this.scheduleUpdate=()=>this.update(),this.projectionUpdateScheduled=!1,this.checkUpdateFailed=()=>{this.isUpdating&&(this.isUpdating=!1,this.clearAllSnapshots())},this.updateProjection=()=>{this.projectionUpdateScheduled=!1,this.nodes.forEach(Pb),this.nodes.forEach(Gb),this.nodes.forEach(Kb),this.nodes.forEach(Fb),yy.countProjection?.()},this.resolvedRelativeTargetAt=0,this.hasProjected=!1,this.isVisible=!0,this.animationProgress=0,this.sharedNodes=new Map,this.latestValues=e,this.root=n?n.root||n:this,this.path=n?[...n.path,n]:[],this.parent=n,this.depth=n?n.depth+1:0;for(let e=0;e<this.path.length;e++)this.path[e].shouldResetTransform=!0;this.root===this&&(this.nodes=new Sb)}addEventListener(e,t){return this.eventHandlers.has(e)||this.eventHandlers.set(e,new tp),this.eventHandlers.get(e).add(t)}notifyListeners(e,...t){this.eventHandlers.get(e)?.notify(...t)}hasListeners(e){return this.eventHandlers.has(e)}mount(t){if(this.instance)return;this.isSVG=Nv(t)&&!Sy(t),this.instance=t;let{layoutId:n,layout:r,visualElement:i}=this.options;if(i&&!i.current&&i.mount(t),this.root.nodes.add(this),this.parent?.children.add(this),this.root.hasTreeAnimated&&(r||n)&&(this.isLayoutDirty=!0),e){let n,r=0,i=()=>this.root.updateBlockedByResize=!1;Km.read(()=>{r=window.innerWidth}),e(t,()=>{let e=window.innerWidth;e!==r&&(r=e,this.root.updateBlockedByResize=!0,n?.(),n=by(i,250),Cb.hasAnimatedSinceResize&&(Cb.hasAnimatedSinceResize=!1,this.nodes.forEach(Wb)))})}n&&this.root.registerSharedNode(n,this),this.addLayoutListener()}addLayoutListener(){let{layoutId:e,layout:t,visualElement:n,animate:r}=this.options;this.instance&&!this.hasLayoutListener&&r!==!1&&n&&(e||t)&&(this.hasLayoutListener=!0,this.addEventListener(`didUpdate`,({delta:e,hasLayoutChanged:t,hasRelativeLayoutChanged:r,layout:i})=>{if(this.isAnimationBlocked){this.target=void 0,this.relativeTarget=void 0;return}let a=this.options.transition||n.getDefaultTransition()||Qb,{onLayoutAnimationStart:o,onLayoutAnimationComplete:s}=n.getProps(),c=!this.targetLayout||!fb(this.targetLayout,i),l=!t&&r;if(this.options.layoutRoot||this.resumeFrom||l||t&&(c||!this.currentAnimation)){this.resumeFrom&&(this.resumingFrom=this.resumeFrom,this.resumingFrom.resumingFrom=void 0);let t={...K_(a,`layout`),onPlay:o,onComplete:s};(n.shouldReduceMotion||this.options.layoutRoot)&&(t.delay=0,t.type=!1),this.startAnimation(t),this.setAnimationOrigin(e,l,t.path)}else t||Wb(this),this.isLead()&&this.options.onExitComplete?.();this.targetLayout=i}))}unmount(){this.options.layoutId&&this.willUpdate(),this.root.nodes.remove(this),this.getStack()?.remove(this),this.parent?.children.delete(this),this.instance=void 0,this.eventHandlers.clear(),this.hasLayoutListener=!1,qm(this.updateProjection)}blockUpdate(){this.updateManuallyBlocked=!0}unblockUpdate(){this.updateManuallyBlocked=!1}isUpdateBlocked(){return this.updateManuallyBlocked||this.updateBlockedByResize}startUpdate(){this.isUpdateBlocked()||(this.isUpdating=!0,this.nodes?.forEach(qb),this.animationId++)}getTransformTemplate(){let{visualElement:e}=this.options;return e&&e.getProps().transformTemplate}willUpdate(e=!0){if(this.root.hasTreeAnimated=!0,this.root.isUpdateBlocked()){this.options.onExitComplete?.();return}if(window.MotionCancelOptimisedAnimation&&!this.hasCheckedOptimisedAppear&&kb(this),!this.root.isUpdating&&this.root.startUpdate(),this.isLayoutDirty)return;Ob(this),this.isLayoutDirty=!0;for(let e=0;e<this.path.length;e++){let t=this.path[e];t.shouldResetTransform=!0,Ob(t),(typeof t.latestValues.x==`string`||typeof t.latestValues.y==`string`)&&(t.isLayoutDirty=!0),t.updateScroll(`snapshot`),t.options.layoutRoot&&t.willUpdate(!1),t.isAnimationBlocked&&(t.dragSnapshot||=t.measure(),this.dragAncestor=t)}let{layoutId:t,layout:n}=this.options;if(t===void 0&&!n)return;let r=this.getTransformTemplate();this.prevTransformTemplateValue=r?r(this.latestValues,``):void 0,this.updateSnapshot(),e&&this.notifyListeners(`willUpdate`)}update(){if(this.updateScheduled=!1,this.isUpdateBlocked()){let e=this.updateBlockedByResize;this.unblockUpdate(),this.updateBlockedByResize=!1,this.clearAllSnapshots(),e&&this.nodes.forEach(Rb),this.nodes.forEach(Lb);return}if(this.animationId<=this.animationCommitId){this.nodes.forEach(zb);return}this.animationCommitId=this.animationId,this.isUpdating?(this.isUpdating=!1,this.nodes.forEach(Vb),this.nodes.forEach(Hb),this.nodes.forEach(Ub),this.nodes.forEach(Mb),this.nodes.forEach(Nb)):this.nodes.forEach(zb),this.clearAllSnapshots();let e=Dp.now();wp.delta=Kf(0,1e3/60,e-wp.timestamp),wp.timestamp=e,wp.isProcessing=!0,Jm.update.process(wp),Jm.preRender.process(wp),Jm.render.process(wp),wp.isProcessing=!1}didUpdate(){this.updateScheduled||(this.updateScheduled=!0,hy.read(this.scheduleUpdate))}clearAllSnapshots(){this.nodes.forEach(Ib),this.sharedNodes.forEach((e,t)=>e.members.length?e.removeLeadSnapshot():this.sharedNodes.delete(t))}scheduleUpdateProjection(){this.projectionUpdateScheduled||(this.projectionUpdateScheduled=!0,Km.preRender(this.updateProjection,!1,!0))}scheduleCheckAfterUnmount(){Km.postRender(()=>{this.isLayoutDirty?this.root.didUpdate():this.root.checkUpdateFailed()})}updateSnapshot(){!this.snapshot&&this.instance&&(this.snapshot=this.measure(),this.snapshot&&!zy(this.snapshot.measuredBox.x)&&!zy(this.snapshot.measuredBox.y)&&(this.snapshot=void 0))}updateLayout(){if(!this.instance||(this.updateScroll(),!(this.options.alwaysMeasureLayout&&this.isLead())&&!this.isLayoutDirty))return;if(this.resumeFrom&&!this.resumeFrom.instance)for(let e=0;e<this.path.length;e++)this.path[e].updateScroll();let e=this.layout;this.layout=this.measure(!1),this.layoutCorrected||=ob(),this.isLayoutDirty=!1,this.projectionDelta=void 0,this.notifyListeners(`measure`,this.layout.layoutBox);let{visualElement:t}=this.options;t?.notify(`LayoutMeasure`,this.layout.layoutBox,e?.layoutBox)}updateScroll(e=`measure`){let{scroll:t,instance:i}=this,{animationId:a}=this.root;if(this.options.layoutScroll&&i&&!(t&&t.animationId===a&&t.phase===e)){let o=r(i);this.scroll={animationId:a,phase:e,isRoot:o,offset:n(i),wasRoot:t?t.isRoot:o}}}resetTransform(){if(!i)return;let e=this.isLayoutDirty||this.shouldResetTransform||this.options.alwaysMeasureLayout;e&&Ob(this);let t=this.projectionDelta&&!cb(this.projectionDelta),n=this.getTransformTemplate(),r=n?n(this.latestValues,``):void 0,a=r!==this.prevTransformTemplateValue;e&&this.instance&&(t||Zv(this.latestValues)||a)&&(i(this.instance,r),this.shouldResetTransform=!1,this.scheduleRender())}measure(e=!0){let t=this.measurePageBox(),n=this.removeElementScroll(t);return e&&(n=this.removeTransform(n)),nb(n),{animationId:this.root.animationId,measuredBox:t,layoutBox:n,latestValues:{},source:this.id}}measurePageBox(){let{visualElement:e}=this.options;if(!e)return ob();let t=e.measureViewportBox();if(!(this.scroll?.wasRoot||this.path.some(tx))){let{scroll:e}=this.root;e&&(cy(t.x,e.offset.x),cy(t.y,e.offset.y))}return t}removeElementScroll(e){let t=ob();if(Ny(t,e),this.scroll?.wasRoot)return t;for(let n=0;n<this.path.length;n++){let r=this.path[n],{scroll:i,options:a}=r;r!==this.root&&i&&a.layoutScroll&&(i.wasRoot&&Ny(t,e),cy(t.x,i.offset.x),cy(t.y,i.offset.y))}return t}applyTransform(e,t=!1,n,r,i=0){let a=n||ob();Ny(a,e);for(let e=i;e<this.path.length;e++){let n=this.path[e];!t&&n.options.layoutScroll&&n.scroll&&n!==n.root&&(cy(a.x,-n.scroll.offset.x),cy(a.y,-n.scroll.offset.y)),Zv(n.latestValues)&&dy(a,n.latestValues,n.layout?.layoutBox)}return!r&&Zv(this.latestValues)&&dy(a,this.latestValues,this.layout?.layoutBox),a}removeTransform(e){let t=ob();Ny(t,e);for(let e=0;e<this.path.length;e++){let n=this.path[e];if(!Zv(n.latestValues))continue;let r;n.instance&&(Yv(n.latestValues)&&n.updateSnapshot(),r=ob(),Ny(r,n.measurePageBox())),Qy(t,n.latestValues,n.snapshot?.layoutBox,r)}return Zv(this.latestValues)&&Qy(t,this.latestValues),t}setTargetDelta(e){this.targetDelta=e,this.root.scheduleUpdateProjection(),this.isProjectionDirty=!0}setOptions(e){this.options={...this.options,...e,crossfade:e.crossfade===void 0||e.crossfade},this.addLayoutListener()}clearMeasurements(){this.scroll=void 0,this.layout=void 0,this.snapshot=void 0,this.prevTransformTemplateValue=void 0,this.targetDelta=void 0,this.target=void 0,this.isLayoutDirty=!1}forceRelativeParentToResolveTarget(){this.relativeParent&&this.relativeParent.resolvedRelativeTargetAt!==wp.timestamp&&this.relativeParent.resolveTargetDelta(!0)}resolveTargetDelta(e=!1){let t=this.getLead();this.isProjectionDirty||=t.isProjectionDirty,this.isTransformDirty||=t.isTransformDirty,this.isSharedProjectionDirty||=t.isSharedProjectionDirty;let n=!!this.resumingFrom||this!==t;if(!(e||n&&this.isSharedProjectionDirty||this.isProjectionDirty||this.parent?.isProjectionDirty||this.attemptToResolveRelativeTarget||this.root.updateBlockedByResize))return;let{layout:r,layoutId:i}=this.options;if(!this.layout||!(r||i))return;this.resolvedRelativeTargetAt=wp.timestamp;let a=this.getClosestProjectingParent();!this.targetDelta&&!this.relativeTarget&&(this.options.layoutAnchor!==!1&&a&&a.layout?this.createRelativeTarget(a,this.layout.layoutBox,a.layout.layoutBox):this.removeRelativeTarget()),(this.relativeTarget||this.targetDelta)&&(this.target||(this.target=ob(),this.targetWithTransforms=ob()),this.relativeTarget&&this.relativeTargetOrigin&&this.relativeParent&&this.relativeParent.target?(this.forceRelativeParentToResolveTarget(),Wy(this.target,this.relativeTarget,this.relativeParent.target,this.options.layoutAnchor||void 0)):this.targetDelta?(this.resumingFrom?this.applyTransform(this.layout.layoutBox,!1,this.target,!0):Ny(this.target,this.layout.layoutBox),iy(this.target,this.targetDelta)):Ny(this.target,this.layout.layoutBox),this.attemptToResolveRelativeTarget&&(this.attemptToResolveRelativeTarget=!1,this.options.layoutAnchor!==!1&&a&&(!a.resumingFrom==!this.resumingFrom||a.options.layoutRoot&&!a.resumingFrom)&&!a.options.layoutScroll&&a.target&&this.animationProgress!==1?this.createRelativeTarget(a,this.target,a.target):this.relativeParent=this.relativeTarget=void 0),yy.countProjection?.(1))}getClosestProjectingParent(){if(!(!this.parent||Yv(this.parent.latestValues)||$v(this.parent.latestValues)))return this.parent.isProjecting()?this.parent:this.parent.getClosestProjectingParent()}isProjecting(){return!!((this.relativeTarget||this.targetDelta||this.options.layoutRoot)&&this.layout)}createRelativeTarget(e,t,n){this.relativeParent=e,this.forceRelativeParentToResolveTarget(),this.relativeTarget=ob(),this.relativeTargetOrigin=ob(),Ky(this.relativeTargetOrigin,t,n,this.options.layoutAnchor||void 0),Ny(this.relativeTarget,this.relativeTargetOrigin)}removeRelativeTarget(){this.relativeParent=this.relativeTarget=void 0}calcProjection(){let e=this.getLead(),t=!!this.resumingFrom||this!==e,n=!0;if((this.isProjectionDirty||this.parent?.isProjectionDirty)&&(n=!1),t&&(this.isSharedProjectionDirty||this.isTransformDirty)&&(n=!1),this.resolvedRelativeTargetAt===wp.timestamp&&(n=!1),n)return;let{layout:r,layoutId:i}=this.options;if(this.isTreeAnimating=!!(this.parent?.isTreeAnimating||this.currentAnimation||this.pendingAnimation),this.isTreeAnimating||(this.targetDelta=this.relativeTarget=void 0),!this.layout||!(r||i))return;Ny(this.layoutCorrected,this.layout.layoutBox);let a=this.treeScale.x,o=this.treeScale.y;sy(this.layoutCorrected,this.treeScale,this.path,t&&(e.relativeTarget&&!e.relativeParent.resumingFrom?e.relativeParent:!0)),e.layout&&!e.target&&(this.treeScale.x!==1||this.treeScale.y!==1)&&(e.target=e.layout.layoutBox,e.targetWithTransforms=ob());let{target:s}=e;s?(!this.projectionDelta||!this.prevProjectionDelta?this.createProjectionDeltas():(Py(this.prevProjectionDelta.x,this.projectionDelta.x),Py(this.prevProjectionDelta.y,this.projectionDelta.y)),Hy(this.projectionDelta,this.layoutCorrected,s,this.latestValues),this.treeScale.x===a&&this.treeScale.y===o&&mb(this.projectionDelta.x,this.prevProjectionDelta.x)&&mb(this.projectionDelta.y,this.prevProjectionDelta.y)||(this.hasProjected=!0,this.scheduleRender(),this.notifyListeners(`projectionUpdate`,s)),yy.countProjection?.(2)):this.prevProjectionDelta&&(this.createProjectionDeltas(),this.scheduleRender())}hide(){this.isVisible=!1}show(){this.isVisible=!0}scheduleRender(e=!0){this.options.visualElement?.scheduleRender(),e&&this.getStack()?.scheduleRender(),this.resumingFrom&&!this.resumingFrom.instance&&(this.resumingFrom=void 0)}createProjectionDeltas(){this.prevProjectionDelta=ib(),this.projectionDelta=ib(),this.projectionDeltaWithTransform=ib()}setAnimationOrigin(e,t=!1,n){let r=this.snapshot,i=r?r.latestValues:{},a={...this.latestValues},o=ib();this.relativeParent&&this.relativeParent.options.layoutRoot||(this.relativeTarget=this.relativeTargetOrigin=void 0),this.attemptToResolveRelativeTarget=!t;let s=ob(),c=r?.source!==this.layout?.source,l=this.getStack(),u=!l||l.members.length<=1,d=!(!c||u||this.options.crossfade!==!0||this.path.some(Zb));this.animationProgress=0;let f,p=n?.interpolateProjection(e);this.mixTargetDelta=t=>{let n=t/1e3,r=p?.(n);Jb(o.x,e.x,n),Jb(o.y,e.y,n),r&&(o.x.translate=r.x,o.y.translate=r.y),this.setTargetDelta(o),this.relativeTarget&&this.relativeTargetOrigin&&this.layout&&this.relativeParent&&this.relativeParent.layout&&(Ky(s,this.layout.layoutBox,this.relativeParent.layout.layoutBox,this.options.layoutAnchor||void 0),Xb(this.relativeTarget,this.relativeTargetOrigin,s,n),f&&ub(this.relativeTarget,f)&&(this.isProjectionDirty=!1),f||=ob(),Ny(f,this.relativeTarget)),c&&(this.animationValues=a,Dy(a,i,this.latestValues,n,d,u)),r?.rotate!==void 0&&(this.animationValues||=a,this.animationValues.pathRotation=r.rotate),this.root.scheduleUpdateProjection(),this.scheduleRender(),this.animationProgress=n},this.mixTargetDelta(this.options.layoutRoot?1e3:0)}startAnimation(e){this.notifyListeners(`animationStart`),this.currentAnimation?.stop(),this.resumingFrom?.currentAnimation?.stop(),this.pendingAnimation&&=(qm(this.pendingAnimation),void 0),this.pendingAnimation=Km.update(()=>{Cb.hasAnimatedSinceResize=!0,this.motionValue||=W_(0),this.motionValue.jump(0,!1),this.currentAnimation=_y(this.motionValue,[0,1e3],{...e,velocity:0,isSync:!0,onUpdate:t=>{this.mixTargetDelta(t),e.onUpdate&&e.onUpdate(t)},onComplete:()=>{e.onComplete&&e.onComplete(),this.completeAnimation()}}),Wh(this.currentAnimation,this),this.resumingFrom&&(this.resumingFrom.currentAnimation=this.currentAnimation),this.pendingAnimation=void 0})}completeAnimation(){this.resumingFrom&&(this.resumingFrom.currentAnimation=void 0,this.resumingFrom.preserveOpacity=void 0);let e=this.getStack();e&&e.exitAnimationComplete(),this.resumingFrom=this.currentAnimation=this.animationValues=void 0,this.notifyListeners(`animationComplete`)}finishAnimation(){this.currentAnimation&&(this.mixTargetDelta?.(Tb),this.currentAnimation.stop()),this.completeAnimation()}applyTransformsToTarget(){let e=this.getLead(),{targetWithTransforms:t,layout:n,latestValues:r}=e,{target:i}=e;if(t&&i&&n){if(this!==e&&this.layout&&n&&ex(this.options.animationType,this.layout.layoutBox,n.layoutBox)){let{layoutBox:e}=this.layout,t=i;i=this.target||ob(),$b(i.x,t.x,e.x),$b(i.y,t.y,e.y)}Ny(t,i),dy(t,r),Hy(this.projectionDeltaWithTransform,this.layoutCorrected,t,r)}}registerSharedNode(e,t){this.sharedNodes.has(e)||this.sharedNodes.set(e,new hb),this.sharedNodes.get(e).add(t);let n=t.options.initialPromotionConfig;t.promote({transition:n?.transition,preserveFollowOpacity:n?.shouldPreserveFollowOpacity?n.shouldPreserveFollowOpacity(t):void 0})}isLead(){let e=this.getStack();return!e||e.lead===this}getLead(){let{layoutId:e}=this.options;return e&&this.getStack()?.lead||this}getPrevLead(){let{layoutId:e}=this.options;return e?this.getStack()?.prevLead:void 0}getStack(){let{layoutId:e}=this.options;if(e)return this.root.sharedNodes.get(e)}promote({needsReset:e,transition:t,preserveFollowOpacity:n}={}){this.getStack()?.promote(this,n),e&&(this.projectionDelta=void 0,this.needsReset=!0),t&&this.setOptions({transition:t})}relegate(){return this.getStack()?.relegate(this)||!1}resetSkewAndRotation(){let{visualElement:e}=this.options;if(!e)return;let{latestValues:t}=e;if(!Qv(t))return;let n={};for(let t=0;t<wb.length;t++)Db(wb[t],e,n,this.animationValues);for(let t=0;t<Xv.length;t++)Db(Xv[t],e,n,this.animationValues);e.render();for(let t in n)e.setStaticValue(t,n[t]),this.animationValues&&(this.animationValues[t]=n[t]);e.scheduleRender()}applyProjectionStyles(e,t){if(!this.instance||this.isSVG)return;let n=this.getLead();if(!this.isVisible&&n!==this){e.visibility=`hidden`;return}let r=this.getTransformTemplate();if(this.needsReset){this.needsReset=!1,e.visibility=``,e.opacity=``,e.pointerEvents=Cy(t?.pointerEvents)||``,e.transform=r?r(this.latestValues,``):`none`;return}if(!this.projectionDelta||!this.layout||!n.target){(this.options.layoutId||this.needsShow)&&(this.needsShow=!1,e.visibility=``,e.opacity=this.latestValues.opacity===void 0?1:this.latestValues.opacity,e.pointerEvents=Cy(t?.pointerEvents)||``),this.hasProjected&&!Zv(this.latestValues)&&(e.transform=r?r({},``):`none`,this.hasProjected=!1);return}e.visibility=``;let i=n.animationValues||n.latestValues;this.applyTransformsToTarget();let a=yb(this.projectionDeltaWithTransform,this.treeScale,i);r&&(a=r(i,a)),e.transform=a;let{x:o,y:s}=this.projectionDelta;e.transformOrigin=`${o.origin*100}% ${s.origin*100}% 0`,e.opacity=n.animationValues?n===this?i.opacity??this.latestValues.opacity??1:this.preserveOpacity?this.latestValues.opacity:i.opacityExit:n===this?i.opacity===void 0?``:i.opacity:i.opacityExit===void 0?0:i.opacityExit;for(let t in vy){if(i[t]===void 0)continue;let{correct:r,applyTo:o,isCSSVariable:s}=vy[t],c=a===`none`?i[t]:r(i[t],n);if(o){let t=o.length;for(let n=0;n<t;n++)e[o[n]]=c}else s?this.options.visualElement.renderState.vars[t]=c:e[t]=c}this.options.layoutId&&(e.pointerEvents=n===this?Cy(t?.pointerEvents)||``:`none`)}clearSnapshot(){this.resumeFrom=this.snapshot=this.dragSnapshot=this.dragAncestor=void 0}resetTree(){this.root.nodes.forEach(e=>e.currentAnimation?.stop()),this.root.nodes.forEach(Lb),this.root.sharedNodes.clear()}}}function Mb(e){e.updateLayout(),Bb(e)}function Nb(e){let t=e.resumeFrom?.snapshot||e.snapshot;if(e.isLead()&&e.layout&&t&&e.hasListeners(`didUpdate`)){let{layoutBox:n,measuredBox:r}=e.layout,{animationType:i}=e.options,a=t.source!==e.layout.source,o=(r,a)=>{if(i===`size`)bb(e=>{let t=zy(r[e]);r[e].min=a[e].min,r[e].max=r[e].min+t});else if(i===`x`||i===`y`){let e=i===`x`?`y`:`x`;My(r[e],a[e])}else ex(i,t.layoutBox,n)&&bb(t=>{let n=zy(a[t]);r[t].max=r[t].min+n,e.relativeTarget&&!e.currentAnimation&&(e.isProjectionDirty=!0,e.relativeTarget[t].max=e.relativeTarget[t].min+n)})},s=a?t.measuredBox:t.layoutBox;o(s,n);let c=ib();Hy(c,n,t.layoutBox);let l=ib();Hy(l,a?e.applyTransform(r,!0):n,s);let u=!cb(c),d=!1,f=e.getClosestProjectingParent();if((!e.resumeFrom||f?.options.layoutRoot&&e.resumeFrom.path.includes(f))&&f&&!f.resumeFrom){let{snapshot:r,layout:i}=f;if(r&&i){let s=e.options.layoutAnchor||void 0,c=ob();Ky(c,a?e.resumeFrom.applyTransform(t.layoutBox,!0,void 0,!0,f.depth+1):t.layoutBox,r.layoutBox,s);let l=ob();Ky(l,n,i.layoutBox,s),a&&o(c,l),fb(c,l)||(d=!0),f.options.layoutRoot&&(e.relativeTarget=l,e.relativeTargetOrigin=c,e.relativeParent=f)}}e.notifyListeners(`didUpdate`,{layout:n,snapshot:t,delta:l,layoutDelta:c,hasLayoutChanged:u,hasRelativeLayoutChanged:d})}else e.isLead()&&e.options.onExitComplete?.();e.options.transition=void 0}function Pb(e){yy.countProjection?.(0),e.parent&&(e.isProjecting()||(e.isProjectionDirty=e.parent.isProjectionDirty),e.isSharedProjectionDirty||=!!(e.isProjectionDirty||e.parent.isProjectionDirty||e.parent.isSharedProjectionDirty),e.isTransformDirty||=e.parent.isTransformDirty)}function Fb(e){e.isProjectionDirty=e.isSharedProjectionDirty=e.isTransformDirty=!1}function Ib(e){e.clearSnapshot()}function Lb(e){e.clearMeasurements()}function Rb(e){e.isLayoutDirty=!0,e.updateLayout()}function zb(e){e.isLayoutDirty=!1}function Bb(e){let{snapshot:t,dragAncestor:n}=e,r=n?.isAnimationBlocked&&n.layout;if(!t||!r||e.resumeFrom||e.isAnimationBlocked)return;let i=n.dragSnapshot;bb(e=>cy(t.layoutBox[e],r.layoutBox[e].min-i.layoutBox[e].min))}function Vb(e){e.isAnimationBlocked&&e.layout&&!e.isLayoutDirty&&(e.snapshot=e.dragSnapshot||e.layout,e.isLayoutDirty=!0)}function Hb(e){e.relativeTarget&&e.relativeParent?.isLayoutDirty&&(e.currentAnimation?e.isLayoutDirty=!0:(e.targetDelta=void 0,e.removeRelativeTarget()))}function Ub(e){let{visualElement:t}=e.options;t?.getProps().onBeforeLayoutMeasure&&t.notify(`BeforeLayoutMeasure`),e.resetTransform()}function Wb(e){e.finishAnimation(),e.targetDelta=e.relativeTarget=e.target=void 0,e.isProjectionDirty=!0}function Gb(e){e.resolveTargetDelta()}function Kb(e){e.calcProjection()}function qb(e){e.resetSkewAndRotation()}function Jb(e,t,n){e.translate=Tm(t.translate,0,n),e.scale=Tm(t.scale,1,n),e.origin=t.origin,e.originPoint=t.originPoint}function Yb(e,t,n,r){e.min=Tm(t.min,n.min,r),e.max=Tm(t.max,n.max,r)}function Xb(e,t,n,r){Yb(e.x,t.x,n.x,r),Yb(e.y,t.y,n.y,r)}function Zb(e){return e.animationValues?.opacityExit!==void 0}var Qb={duration:.45,ease:[.4,0,.1,1]};function $b(e,t,n){e.max=zy(n)+(e.min=t.min)}function ex(e,t,n){return e===`position`||e===`preserve-aspect`&&!By(pb(t),pb(n),.2)}function tx(e){return e!==e.root&&e.scroll?.wasRoot}function nx(e,t,n,r={passive:!0}){return e.addEventListener(t,n,r),()=>e.removeEventListener(t,n,r)}var rx=jb({attachResizeListener:(e,t)=>nx(e,`resize`,t),measureScroll:my,checkIsScrollRoot:()=>!0}),ix={current:void 0},ax=jb({measureScroll:e=>({x:e.scrollLeft,y:e.scrollTop}),defaultParent:()=>{if(!ix.current){let e=new rx({});e.mount(window),e.setOptions({layoutScroll:!0}),ix.current=e}return ix.current},resetTransform:(e,t)=>{e.style.transform=t===void 0?`none`:t},checkIsScrollRoot:e=>window.getComputedStyle(e).position===`fixed`}),ox=new WeakMap;function sx(e){return typeof e==`object`&&!!e&&typeof e.start==`function`}function cx(e){return typeof e==`string`||Array.isArray(e)}var lx=[`animate`,`whileInView`,`whileFocus`,`whileHover`,`whileTap`,`whileDrag`,`exit`],ux=[`initial`].concat(lx);function dx(e){if(sx(e.animate))return!0;for(let t=0;t<ux.length;t++)if(cx(e[ux[t]]))return!0;return!1}function fx(e){return!!(dx(e)||e.variants)}function px(e,t,n){for(let r in t){let i=t[r],a=n[r];if(pv(i))e.addValue(r,i);else if(pv(a))e.addValue(r,W_(i,{owner:e}));else if(a!==i){if(e.hasValue(r)){let t=e.getValue(r);t.liveStyle===!0?t.jump(i):t.hasAnimated||t.set(i)}else{let t=e.getStaticValue(r);e.addValue(r,W_(t===void 0?i:t,{owner:e}))}}}for(let r in n)t[r]===void 0&&e.removeValue(r);return t}var mx={current:null},hx={current:!1},gx=typeof window<`u`;function _x(){if(hx.current=!0,gx){if(window.matchMedia){let e=window.matchMedia(`(prefers-reduced-motion)`),t=()=>mx.current=e.matches;e.addEventListener(`change`,t),t()}else mx.current=!1}}var vx=[`AnimationStart`,`AnimationComplete`,`Update`,`BeforeLayoutMeasure`,`LayoutMeasure`,`LayoutAnimationStart`,`LayoutAnimationComplete`],yx={};function bx(e){yx=e}function xx(){return yx}var Sx=class{scrapeMotionValuesFromProps(e,t,n){return{}}constructor({parent:e,props:t,presenceContext:n,reducedMotionConfig:r,skipAnimations:i,blockInitialAnimation:a,visualState:o},s={}){this.current=null,this.children=new Set,this.isVariantNode=!1,this.isControllingVariants=!1,this.shouldReduceMotion=null,this.shouldSkipAnimations=!1,this.values=new Map,this.KeyframeResolver=Rg,this.features={},this.valueSubscriptions=new Map,this.prevMotionValues={},this.hasBeenMounted=!1,this.events={},this.propEventSubscriptions={},this.notifyUpdate=()=>this.notify(`Update`,this.latestValues),this.render=()=>{this.current&&(this.triggerBuild(),this.renderInstance(this.current,this.renderState,this.props.style,this.projection))},this.renderScheduledAt=0,this.scheduleRender=()=>{let e=Dp.now();this.renderScheduledAt<e&&(this.renderScheduledAt=e,Km.render(this.render,!1,!0))};let{latestValues:c,renderState:l}=o;this.latestValues=c,this.baseTarget={...c},this.initialValues=t.initial?{...c}:{},this.renderState=l,this.parent=e,this.props=t,this.presenceContext=n,this.depth=e?e.depth+1:0,this.reducedMotionConfig=r,this.skipAnimationsConfig=i,this.options=s,this.blockInitialAnimation=!!a,this.isControllingVariants=dx(t),this.isVariantNode=fx(t),this.isVariantNode&&(this.variantChildren=new Set),this.manuallyAnimateOnMount=!!(e&&e.current);let{willChange:u,...d}=this.scrapeMotionValuesFromProps(t,{},this);for(let e in d){let t=d[e];c[e]!==void 0&&pv(t)&&t.set(c[e])}}mount(e){if(this.hasBeenMounted)for(let e in this.initialValues)this.values.get(e)?.jump(this.initialValues[e]),this.latestValues[e]=this.initialValues[e];if(this.current=e,ox.set(e,this),this.projection?.instance||this.projection?.mount(e),this.isVariantNode&&!this.isControllingVariants){let e=this;do e=e.props.inherit!==!1&&e.parent;while(e&&!e.isVariantNode);if(e){let{variantChildren:t}=e;t.add(this),this.removeFromVariantTree=()=>t.delete(this)}}this.values.forEach((e,t)=>this.bindToMotionValue(t,e)),this.reducedMotionConfig===`never`?this.shouldReduceMotion=!1:this.reducedMotionConfig===`always`?this.shouldReduceMotion=!0:(hx.current||_x(),this.shouldReduceMotion=mx.current),this.shouldSkipAnimations=this.skipAnimationsConfig??!1,this.parent?.addChild(this),this.update(this.props,this.presenceContext),this.hasBeenMounted=!0}unmount(){this.projection?.unmount(),qm(this.notifyUpdate),qm(this.render),this.valueSubscriptions.forEach(e=>e()),this.valueSubscriptions.clear(),this.removeFromVariantTree?.(),this.parent?.removeChild(this);for(let e in this.events)this.events[e].clear();for(let e in this.features){let t=this.features[e];t&&(t.unmount(),t.isMounted=!1)}this.current=null}addChild(e){this.children.add(e),(this.enteringChildren||=new Set).add(e)}removeChild(e){this.children.delete(e),this.enteringChildren?.delete(e)}bindToMotionValue(e,t){if(this.valueSubscriptions.get(e)?.(),t.accelerate&&o_.has(e)&&this.current instanceof HTMLElement){let{factory:n,keyframes:r,times:i,ease:a,duration:o}=t.accelerate,s=new Zg({element:this.current,name:e,keyframes:r,times:i,ease:a,duration:np(o)}),c=n(s);this.valueSubscriptions.set(e,()=>{c(),s.cancel()});return}let n=bg.has(e);n&&this.onBindTransform&&this.onBindTransform();let r=t.on(`change`,t=>{this.latestValues[e]=t,this.props.onUpdate&&Km.preRender(this.notifyUpdate),n&&(this.projection&&(this.projection.isTransformDirty=!0),b_.get(this.current)?.check()),this.scheduleRender()}),i;typeof window<`u`&&window.MotionCheckAppearSync&&(i=window.MotionCheckAppearSync(this,e,t)),this.valueSubscriptions.set(e,()=>{r(),i?.()})}sortNodePosition(e){return!this.current||!e.current||!this.sortInstanceNodePosition||this.type!==e.type?0:this.sortInstanceNodePosition(this.current,e.current)}updateFeatures(){let e=`animation`;for(e in yx){let t=yx[e];if(!t)continue;let{isEnabled:n,Feature:r}=t;if(!this.features[e]&&r&&n(this.props)&&(this.features[e]=new r(this)),this.features[e]){let t=this.features[e];t.isMounted?t.update():(t.mount(),t.isMounted=!0)}}}triggerBuild(){this.build(this.renderState,this.latestValues,this.props)}measureViewportBox(){return this.current?this.measureInstanceViewportBox(this.current,this.props):ob()}getStaticValue(e){return this.latestValues[e]}setStaticValue(e,t){this.latestValues[e]=t}update(e,t){let{transformTemplate:n,onUpdate:r}=this.props;(e.transformTemplate||n)&&this.scheduleRender(),(e.transformTemplate&&!n||e.onUpdate&&!r)&&b_.get(this.current)?.demote(),this.prevProps=this.props,this.props=e,this.prevPresenceContext=this.presenceContext,this.presenceContext=t;for(let t=0;t<vx.length;t++){let n=vx[t];this.propEventSubscriptions[n]?.(),delete this.propEventSubscriptions[n];let r=e[`on`+n];r&&(this.propEventSubscriptions[n]=this.on(n,r))}this.prevMotionValues=px(this,this.scrapeMotionValuesFromProps(e,this.prevProps||{},this),this.prevMotionValues),this.handleChildMotionValue?.()}getProps(){return this.props}getVariant(e){return this.props.variants?.[e]}getDefaultTransition(){return this.props.transition}getTransformPagePoint(){return this.props.transformPagePoint}addValue(e,t){let n=this.values.get(e);if(t!==n){n&&this.removeValue(e),this.bindToMotionValue(e,t),this.values.set(e,t);let r=t.get();r!==void 0&&(this.latestValues[e]=r)}}removeValue(e){this.values.delete(e),this.valueSubscriptions.get(e)?.(),this.valueSubscriptions.delete(e),delete this.latestValues[e],this.removeValueFromRenderState(e,this.renderState)}hasValue(e){return this.values.has(e)}getValue(e,t){let n=this.props.values?.[e];return n||(n=this.values.get(e),n===void 0&&t!==void 0&&(n=W_(t??this.getDefaultValue?.(e),{owner:this}),this.addValue(e,n)),n)}readValue(e,t){let n=this.latestValues[e]!==void 0||!this.current?this.latestValues[e]:this.getBaseTargetFromProps(this.props,e)??this.readValueFromInstance(this.current,e,this.options);return n!=null&&(typeof n==`string`&&(Jf(n)||Xf(n))?n=parseFloat(n):typeof n!=`number`&&!xm.test(n)&&xm.test(t)&&(n=og(e,t)),this.setBaseTarget(e,pv(n)?n.get():n)),pv(n)?n.get():n}setBaseTarget(e,t){this.baseTarget[e]=t}on(e,t){return(this.events[e]||(this.events[e]=new tp)).add(t)}notify(e,...t){this.events[e]?.notify(...t)}scheduleRenderMicrotask(){hy.render(this.render)}},Cx=class extends Sx{constructor(){super(...arguments),this.KeyframeResolver=Av}sortInstanceNodePosition(e,t){return e.compareDocumentPosition(t)&2?1:-1}getBaseTargetFromProps(e,t){let n=e.style;return n?n[t]:void 0}removeValueFromRenderState(e,{vars:t,style:n}){delete t[e],delete n[e]}handleChildMotionValue(){this.childSubscription&&(this.childSubscription(),delete this.childSubscription);let{children:e}=this.props;pv(e)&&(this.childSubscription=e.on(`change`,e=>{this.current&&(this.current.textContent=`${e}`)}))}};function wx(e,{style:t,vars:n},r,i){let a=e.style,o;for(o in t)a[o]=t[o];for(o in i?.applyProjectionStyles(a,r),n)a.setProperty(o,n[o])}function Tx(e,{layout:t,layoutId:n}){return bg.has(e)||e.startsWith(`origin`)||(t||n!==void 0)&&(!!vy[e]||e===`opacity`)}function Ex(e,t,n){let r=e.style,i=t?.style,a={};if(!r)return a;for(let t in r)(pv(r[t])||i&&pv(i[t])||Tx(t,e)||n?.getValue(t)?.liveStyle!==void 0)&&(a[t]=r[t]);return a}function Dx(e){return window.getComputedStyle(e)}var Ox=class extends Cx{constructor(){super(...arguments),this.type=`html`,this.renderInstance=wx}mount(e){super.mount(e)}readValueFromInstance(e,t){if(bg.has(t))return this.projection?.isProjecting?gg(t):vg(e,t);{let n=Dx(e),r=(Ap(t)?n.getPropertyValue(t):n[t])||0;return typeof r==`string`?r.trim():r}}measureInstanceViewportBox(e,{transformPagePoint:t}){return fy(e,t)}build(e,t,n){zv(e,t,n.transformTemplate)}scrapeMotionValuesFromProps(e,t,n){return Ex(e,t,n)}},kx=e=>e.pointerType===`mouse`?typeof e.button!=`number`||e.button<=0:e.isPrimary!==!1;function Ax(e){return{point:{x:e.pageX,y:e.pageY}}}var jx=e=>t=>kx(t)&&e(t,Ax(t));function Mx(e,t,n,r){return nx(e,t,jx(n),r)}var Nx=new WeakMap,Px,Fx=(e,t,n)=>(r,i)=>i&&i[0]?i[0][e+`Size`]:Nv(r)&&`getBBox`in r?r.getBBox()[t]:r[n],Ix=Fx(`inline`,`width`,`offsetWidth`),Lx=Fx(`block`,`height`,`offsetHeight`);function Rx({target:e,borderBoxSize:t}){Nx.get(e)?.forEach(n=>{n(e,{get width(){return Ix(e,t)},get height(){return Lx(e,t)}})})}function zx(e){e.forEach(Rx)}function Bx(){typeof ResizeObserver<`u`&&(Px=new ResizeObserver(zx))}function Vx(e,t){Px||Bx();let n=Lv(e);return n.forEach(e=>{let n=Nx.get(e);n||(n=new Set,Nx.set(e,n)),n.add(t),Px?.observe(e)}),()=>{n.forEach(e=>{let n=Nx.get(e);n?.delete(t),n?.size||Px?.unobserve(e)})}}var Hx=new Set,Ux;function Wx(){Ux=()=>{let e={get width(){return window.innerWidth},get height(){return window.innerHeight}};Hx.forEach(t=>t(e))},window.addEventListener(`resize`,Ux)}function Gx(e){return Hx.add(e),Ux||Wx(),()=>{Hx.delete(e),!Hx.size&&typeof Ux==`function`&&(window.removeEventListener(`resize`,Ux),Ux=void 0)}}function Kx(e,t){return Fv(typeof e==`function`?Gx(e):Vx(e,t))}var qx=(e,t)=>Math.abs(e-t);function Jx(e,t){let n=qx(e.x,t.x),r=qx(e.y,t.y);return Math.sqrt(n**2+r**2)}var Yx=new Set([`auto`,`scroll`]),Xx=class{constructor(e,t,{transformPagePoint:n,contextWindow:r=window,dragSnapToOrigin:i=!1,distanceThreshold:a=3,element:o}={}){if(this.startEvent=null,this.lastMoveEvent=null,this.lastMoveEventInfo=null,this.lastRawMoveEventInfo=null,this.handlers={},this.contextWindow=window,this.scrollPositions=new Map,this.onElementScroll=e=>{this.handleScroll(e.target)},this.onWindowScroll=()=>{this.handleScroll(window)},this.updatePoint=()=>{if(!(this.lastMoveEvent&&this.lastMoveEventInfo))return;this.hasPendingMove=!1,this.lastRawMoveEventInfo&&(this.lastMoveEventInfo=Qx(this.lastRawMoveEventInfo,this.transformPagePoint));let e=eS(this.lastMoveEventInfo,this.history),t=this.startEvent!==null,n=Jx(e.offset,{x:0,y:0})>=this.distanceThreshold;if(!t&&!n)return;let{point:r}=e;this.history.push({...r,timestamp:Dp.now()});let{onStart:i,onMove:a}=this.handlers;t||(i?.(this.lastMoveEvent,e),this.startEvent=this.lastMoveEvent),a?.(this.lastMoveEvent,e)},this.handlePointerMove=(e,t)=>{this.handleScroll(window),this.lastMoveEvent=e,this.lastRawMoveEventInfo=t,this.lastMoveEventInfo=Qx(t,this.transformPagePoint),this.hasPendingMove=!0,Km.update(this.updatePoint,!0)},this.handlePointerUp=(e,t)=>{this.hasPendingMove&&this.updatePoint(),this.end();let{onEnd:n,onSessionEnd:r,resumeAnimation:i}=this.handlers;if((this.dragSnapToOrigin||!this.startEvent)&&i?.(),!(this.lastMoveEvent&&this.lastMoveEventInfo))return;let a=eS(e.type===`pointercancel`?this.lastMoveEventInfo:Qx(t,this.transformPagePoint),this.history);this.startEvent&&n?.(e,a),r?.(e,a)},!kx(e))return;this.dragSnapToOrigin=i,this.handlers=t,this.transformPagePoint=n,this.distanceThreshold=a,this.contextWindow=r||window;let s=Qx(Ax(e),this.transformPagePoint),{point:c}=s;this.history=[{...c,timestamp:Dp.now()}];let{onSessionStart:l}=t;l&&l(e,eS(s,this.history));let u={passive:!0,capture:!0};this.removeListeners=$f(Mx(this.contextWindow,`pointermove`,this.handlePointerMove,u),Mx(this.contextWindow,`pointerup`,this.handlePointerUp,u),Mx(this.contextWindow,`pointercancel`,this.handlePointerUp,u)),o&&this.startScrollTracking(o)}startScrollTracking(e){let t=e.parentElement;for(;t;){let e=getComputedStyle(t);(Yx.has(e.overflowX)||Yx.has(e.overflowY))&&this.scrollPositions.set(t,Zx(t)),t=t.parentElement}this.scrollPositions.set(window,Zx(window)),this.removeScrollListeners=$f(nx(window,`scroll`,this.onElementScroll,{capture:!0}),nx(window,`scroll`,this.onWindowScroll,{}))}handleScroll(e){let t=this.scrollPositions.get(e);if(!t)return;let n=e===window,r=Zx(e),i={x:r.x-t.x,y:r.y-t.y};(i.x!==0||i.y!==0)&&(n?this.lastMoveEventInfo&&(this.lastMoveEventInfo.point.x+=i.x,this.lastMoveEventInfo.point.y+=i.y):this.history.length>0&&(this.history[0].x-=i.x,this.history[0].y-=i.y),this.scrollPositions.set(e,r),Km.update(this.updatePoint,!0))}updateHandlers(e){this.handlers=e}end(){this.removeListeners?.(),this.removeScrollListeners?.(),this.scrollPositions.clear(),qm(this.updatePoint)}},Zx=e=>e===window?{x:window.scrollX,y:window.scrollY}:{x:e.scrollLeft,y:e.scrollTop};function Qx(e,t){return t?{point:t(e.point)}:e}function $x(e,t){return{x:e.x-t.x,y:e.y-t.y}}function eS({point:e},t){return{point:e,delta:$x(e,nS(t)),offset:$x(e,tS(t)),velocity:rS(t,.1)}}function tS(e){return e[0]}function nS(e){return e[e.length-1]}function rS(e,t){if(e.length<2)return{x:0,y:0};let n=e.length-1,r=null,i=nS(e);for(;n>=0&&(r=e[n],!(i.timestamp-r.timestamp>np(t)));)n--;if(!r)return{x:0,y:0};r===e[0]&&e.length>2&&i.timestamp-r.timestamp>np(t)*2&&(r=e[1]);let a=rp(i.timestamp-r.timestamp);if(a===0)return{x:0,y:0};let o={x:(i.x-r.x)/a,y:(i.y-r.y)/a};return o.x===1/0&&(o.x=0),o.y===1/0&&(o.y=0),o}var iS=new Set([`BUTTON`,`INPUT`,`SELECT`,`TEXTAREA`,`A`]);function aS(e){return iS.has(e.tagName)||e.isContentEditable===!0}var oS=new Set([`INPUT`,`SELECT`,`TEXTAREA`]);function sS(e){return oS.has(e.tagName)||e.isContentEditable===!0}var cS={x:!1,y:!1};function lS(){return cS.x||cS.y}function uS(e){return e===`x`||e===`y`?cS[e]?null:(cS[e]=!0,()=>{cS[e]=!1}):cS.x||cS.y?null:(cS.x=cS.y=!0,()=>{cS.x=cS.y=!1})}function dS(e,{min:t,max:n},r){return t!==void 0&&e<t?e=r?Tm(t,e,r.min):Math.max(e,t):n!==void 0&&e>n&&(e=r?Tm(n,e,r.max):Math.min(e,n)),e}function fS(e,t,n){return{min:t===void 0?void 0:e.min+t,max:n===void 0?void 0:e.max+n-(e.max-e.min)}}function pS(e,{top:t,left:n,bottom:r,right:i}){return{x:fS(e.x,n,i),y:fS(e.y,t,r)}}function mS(e,t){let n=t.min-e.min,r=t.max-e.max;return t.max-t.min<e.max-e.min&&([n,r]=[r,n]),{min:n,max:r}}function hS(e,t){return{x:mS(e.x,t.x),y:mS(e.y,t.y)}}function gS(e,t){let n=.5,r=zy(e),i=zy(t);return i>r?n=ep(t.min,t.max-r,e.min):r>i&&(n=ep(e.min,e.max-i,t.min)),Kf(0,1,n)}function _S(e,t){let n={};return t.min!==void 0&&(n.min=t.min-e.min),t.max!==void 0&&(n.max=t.max-e.min),n}var vS=.35;function yS(e=vS){return e===!1?e=0:e===!0&&(e=vS),{x:bS(e,`left`,`right`),y:bS(e,`top`,`bottom`)}}function bS(e,t,n){return{min:xS(e,t),max:xS(e,n)}}function xS(e,t){return typeof e==`number`?e:e[t]||0}function SS(e){let t=``;for(let n of e.path){n.scroll=void 0,n.updateScroll();let{scroll:r}=n;n!==e.root&&r&&(t+=r.offset.x+`,`+r.offset.y+`,`)}return t}var CS=new WeakMap,wS=class{constructor(e,t=()=>e.getProps()){this.openDragLock=null,this.isDragging=!1,this.currentDirection=null,this.originPoint={x:0,y:0},this.constraints=!1,this.hasMutatedConstraints=!1,this.elastic=ob(),this.latestPointerEvent=null,this.latestPanInfo=null,this.visualElement=e,this.readProps=t}start(e,{snapToCursor:t=!1,distanceThreshold:n}={}){if(this.visualElement.presenceContext?.isPresent===!1)return;let r=e=>{t&&this.snapToCursor(e),this.stopAnimation()},i=(e,t)=>{let{drag:n,dragPropagation:r,onDragStart:i}=this.getProps();if(n&&!r&&(this.openDragLock?.(),this.openDragLock=uS(n),!this.openDragLock))return;this.latestPointerEvent=e,this.latestPanInfo=t,this.isDragging=!0,this.currentDirection=null,this.resolveConstraints();let{projection:a}=this.visualElement;a&&(a.isAnimationBlocked=!0,a.target=void 0),bb(e=>{let t=this.getAxisMotionValue(e).get()||0;if(Mp(t)&&(t=rv(t,this.visualElement.current)||0),$.test(t))t=parseFloat(t);else if(Zp.test(t)){let n=a?.layout?.layoutBox[e];n&&(t=zy(n)*(parseFloat(t)/100))}this.originPoint[e]=t}),i&&Km.update(()=>i(e,t),!1,!0),hv(this.visualElement,`transform`),this.visualElement.animationState?.setActive(`whileDrag`,!0)},a=(e,t)=>{this.latestPointerEvent=e,this.latestPanInfo=t;let{dragPropagation:n,dragDirectionLock:r,onDirectionLock:i,onDrag:a}=this.getProps();if(!n&&!this.openDragLock)return;let{offset:o}=t;if(r&&this.currentDirection===null){if(this.currentDirection=AS(o),this.currentDirection===null)return;i&&i(this.currentDirection)}this.updateAxis(`x`,o),this.updateAxis(`y`,o),this.visualElement.render(),a&&Km.update(()=>a(e,t),!1,!0)},o=(e,t)=>{this.latestPointerEvent=e,this.latestPanInfo=t,this.stop(e,t),this.latestPointerEvent=null,this.latestPanInfo=null},s=()=>{let{dragSnapToOrigin:e}=this.getProps();(e||this.constraints)&&this.startAnimation({x:0,y:0})},{dragSnapToOrigin:c}=this.getProps();this.panSession=new Xx(e,{onSessionStart:r,onStart:i,onMove:a,onSessionEnd:o,resumeAnimation:s},{transformPagePoint:this.visualElement.getTransformPagePoint(),dragSnapToOrigin:c,distanceThreshold:n,contextWindow:this.visualElement.current?.ownerDocument.defaultView,element:this.visualElement.current})}stop(e,t,n){let r=e||this.latestPointerEvent,i=t||this.latestPanInfo,a=this.isDragging;if(this.cancel(),!a||!i||!r)return;let{velocity:o}=i;this.startAnimation(o,n);let{onDragEnd:s}=this.getProps();s&&Km.postRender(()=>s(r,i))}cancel(){this.isDragging=!1;let{projection:e,animationState:t}=this.visualElement;e&&(e.isAnimationBlocked=!1),this.endPanSession(),!this.getProps().dragPropagation&&this.openDragLock&&(this.openDragLock(),this.openDragLock=null),t?.setActive(`whileDrag`,!1)}endPanSession(){this.panSession?.end(),this.panSession=void 0}updateAxis(e,t){let{drag:n}=this.readProps();if(!t||!kS(e,n,this.currentDirection))return;let r=this.getAxisMotionValue(e),i=this.originPoint[e]+t[e],a=this.constraints&&this.constraints[e];a&&(i=dS(i,a,this.elastic[e])),r.set(i)}resolveConstraints(){let{dragConstraints:e,dragElastic:t}=this.getProps(),{projection:n}=this.visualElement,r=n&&(n.layout||n.measure(!1)),i=this.constraints;TS(e)?this.constraints&&this.scroll===SS(n)||(this.constraints=this.resolveRefConstraints()):this.constraints=e&&r?pS(r.layoutBox,e):!1,this.elastic=yS(t),i!==this.constraints&&!TS(e)&&r&&this.constraints&&!this.hasMutatedConstraints&&bb(e=>{this.constraints!==!1&&this.getAxisMotionValue(e)&&(this.constraints[e]=_S(r.layoutBox[e],this.constraints[e]))})}resolveRefConstraints(){let{dragConstraints:e,onMeasureDragConstraints:t}=this.getProps();if(!TS(e))return!1;let n=ES(e),{projection:r}=this.visualElement;if(!r||!r.layout)return!1;this.scroll=SS(r);let i=py(n,r.root,this.visualElement.getTransformPagePoint()),a=hS(r.layout.layoutBox,r.removeElementScroll(i));if(t){let e=t(Kv(a));this.hasMutatedConstraints=!!e,e&&(a=Gv(e))}return a}startAnimation(e,t){let{drag:n,dragMomentum:r,dragElastic:i,dragTransition:a,dragSnapToOrigin:o,onDragTransitionEnd:s}=this.getProps(),c=this.constraints||{},l=bb(s=>{if(!kS(s,t||n,this.currentDirection))return;let l=c[s]||{};(o===!0||o===s)&&(l={min:0,max:0});let u=i?200:1e6,d=i?40:1e7,f={type:`inertia`,velocity:r?e[s]:0,bounceStiffness:u,bounceDamping:d,timeConstant:750,restDelta:1,restSpeed:10,...a,...l};return this.startAxisValueAnimation(s,f)});return Promise.all(l).then(s)}startAxisValueAnimation(e,t){let n=this.getAxisMotionValue(e);return hv(this.visualElement,e),n.start(ev(e,n,0,t,this.visualElement,!1))}stopAnimation(){bb(e=>this.getAxisMotionValue(e).stop())}getAxisMotionValue(e){let t=`_drag${e.toUpperCase()}`;return this.readProps()[t]||this.visualElement.getValue(e,this.visualElement.latestValues[e]??0)}snapToCursor({clientX:e,clientY:t}){let{drag:n}=this.getProps(),r={x:e,y:t},i=this.visualElement.getTransformPagePoint()?.(r)||r,a=this.visualElement.measureViewportBox();bb(e=>{if(!kS(e,n,this.currentDirection))return;let t=this.getAxisMotionValue(e),{min:r,max:o}=a[e];t.set((t.get()||0)+i[e]-Tm(r,o,.5))})}scalePositionWithinConstraints(){if(!this.visualElement.current)return;let{drag:e,dragConstraints:t}=this.getProps(),{projection:n}=this.visualElement;if(!TS(t)||!n||!this.constraints)return;this.stopAnimation();let r=this.constraints,i={x:0,y:0};bb(e=>{let t=this.getAxisMotionValue(e).get();i[e]=gS({min:t,max:t},r[e])});let{transformTemplate:a}=this.visualElement.getProps();this.visualElement.current.style.transform=a?a({},``):`none`,n.root?.updateScroll(),n.updateLayout(),this.constraints=!1,this.resolveConstraints(),bb(t=>{let n=this.getAxisMotionValue(t);if(!kS(t,e,null)||!n.get())return;let{min:r,max:a}=this.constraints[t];n.set(Tm(r,a,i[t]))}),this.visualElement.render()}addListeners(){if(!this.visualElement.current)return;CS.set(this.visualElement,this);let e=this.visualElement.current,t=Mx(e,`pointerdown`,t=>{let{drag:n,dragListener:r=!0}=this.getProps(),i=t.target,a=i!==e&&sS(i);n&&r&&!a&&this.start(t)}),n,r=()=>{let{dragConstraints:t}=this.getProps(),r=TS(t)&&ES(t);r&&(this.constraints=this.resolveRefConstraints(),n||=OS(e,r,()=>this.scalePositionWithinConstraints()))},{projection:i}=this.visualElement,a=i.addEventListener(`measure`,r);i.layout||(i.root?.updateScroll(),i.updateLayout()),Km.read(r);let o=nx(window,`resize`,()=>this.scalePositionWithinConstraints()),s=i.addEventListener(`didUpdate`,(({delta:e,hasLayoutChanged:t})=>{this.isDragging&&t&&(bb(t=>{if(!kS(t,this.getProps().drag,this.currentDirection))return;let n=this.getAxisMotionValue(t);this.originPoint[t]+=e[t].translate,n.set(n.get()+e[t].translate)}),this.visualElement.render())}));return()=>{o(),t(),a(),s(),n?.()}}getProps(){let e=this.readProps(),{dragElastic:t=vS,dragMomentum:n=!0}=e;return{...e,dragElastic:t,dragMomentum:n}}};function TS(e){return!!e&&typeof e==`object`&&(`current`in e||`nodeType`in e)}var ES=e=>`current`in e?e.current:e;function DS(e){let t=!0;return()=>{t?t=!1:e()}}function OS(e,t,n){let r=Kx(e,DS(n)),i=Kx(t,DS(n));return()=>{r(),i()}}function kS(e,t,n){return(t===!0||t===e)&&(n===null||n===e)}function AS(e,t=10){let n=null;return Math.abs(e.y)>t?n=`y`:Math.abs(e.x)>t&&(n=`x`),n}function jS(e,t){let n=Lv(e),r=new AbortController;return[n,{passive:!0,...t,signal:r.signal},Fv(()=>r.abort())]}function MS(e){return!(e.pointerType===`touch`||lS())}function NS(e,t,n={}){t=Iv(t);let[r,i,a]=jS(e,n);return r.forEach(e=>{let n=!1,r=!1,a,o=()=>{e.removeEventListener(`pointerleave`,u)},s=e=>{a&&=(a(e),void 0),o()},c=e=>{n=!1,window.removeEventListener(`pointerup`,c),window.removeEventListener(`pointercancel`,c),r&&(r=!1,s(e))},l=()=>{n=!0,window.addEventListener(`pointerup`,c,i),window.addEventListener(`pointercancel`,c,i)},u=e=>{e.pointerType!==`touch`&&(n?r=!0:s(e))};e.addEventListener(`pointerenter`,n=>{if(!MS(n))return;r=!1;let o=t(e,n);typeof o==`function`&&(a=o,e.addEventListener(`pointerleave`,u,i))},i),e.addEventListener(`pointerdown`,l,i)}),a}var PS=(e,t)=>t?e===t||PS(e,t.parentElement):!1,FS=new WeakSet;function IS(e){return t=>{t.key===`Enter`&&e(t)}}function LS(e,t){e.dispatchEvent(new PointerEvent(`pointer`+t,{isPrimary:!0,bubbles:!0}))}var RS=(e,t)=>{let n=!1,r=IS(()=>{FS.has(e)||(n=!0,LS(e,`down`))}),i=IS(()=>{n&&(n=!1,LS(e,`up`))});e.addEventListener(`keydown`,r,t),e.addEventListener(`keyup`,i,t),e.addEventListener(`blur`,()=>{e.removeEventListener(`keydown`,r),e.removeEventListener(`keyup`,i),n&&LS(e,`cancel`)},{...t,once:!0})};function zS(e){return kx(e)&&!lS()}var BS=new WeakSet;function VS(e,t,n={}){t=Iv(t);let[r,i,a]=jS(e,n),o=e=>{let r=e.currentTarget;if(!zS(e)||BS.has(e))return;FS.add(r),n.stopPropagation&&BS.add(e);let a=t(r,e),o={...i,capture:!0},s=(e,t)=>{window.removeEventListener(`pointerup`,c,o),window.removeEventListener(`pointercancel`,l,o),FS.has(r)&&FS.delete(r),zS(e)&&typeof a==`function`&&a(e,{success:t})},c=e=>{s(e,r===window||r===document||n.useGlobalTarget||PS(r,e.target))},l=e=>{s(e,!1)};window.addEventListener(`pointerup`,c,o),window.addEventListener(`pointercancel`,l,o)};return r.forEach(e=>{(n.useGlobalTarget?window:e).addEventListener(`pointerdown`,o,i),Mv(e)&&(e.addEventListener(`focus`,()=>RS(e,i),i),!aS(e)&&!e.hasAttribute(`tabindex`)&&(e.tabIndex=0))}),a}function HS(...e){let t=!Array.isArray(e[0]),n=t?0:-1,r=e[0+n],i=e[1+n],a=e[2+n],o=e[3+n],s=Dh(i,a,o);return t?s(r):s}var US=class{constructor(e){this.isMounted=!1,this.node=e}update(){}},WS=new Set([`baseFrequency`,`diffuseConstant`,`kernelMatrix`,`kernelUnitLength`,`keySplines`,`keyTimes`,`limitingConeAngle`,`markerHeight`,`markerWidth`,`numOctaves`,`targetX`,`targetY`,`surfaceScale`,`specularConstant`,`specularExponent`,`stdDeviation`,`tableValues`,`viewBox`,`gradientTransform`,`pathLength`,`startOffset`,`textLength`,`lengthAdjust`]),GS=e=>typeof e==`string`&&e.toLowerCase()===`svg`;function KS(e,t,n,r){wx(e,t,void 0,r);for(let n in t.attrs)e.setAttribute(WS.has(n)?n:Rv(n),t.attrs[n])}function qS(e,t,n){let r=Ex(e,t,n);for(let n in e)if(n!==`children`&&(pv(e[n])||pv(t[n]))){let t=yg.indexOf(n)===-1?n:`attr`+n.charAt(0).toUpperCase()+n.substring(1);r[t]=e[n]}return r}var JS=class extends Cx{constructor(){super(...arguments),this.type=`svg`,this.isSVGTag=!1,this.measureInstanceViewportBox=ob}getBaseTargetFromProps(e,t){return bg.has(t)?super.getBaseTargetFromProps(e,t)??gg(t):e[t]}getDefaultValue(e){return bg.has(e)?this.latestValues[e]??gg(e):void 0}readValueFromInstance(e,t){if(bg.has(t)){let e=ig(t);return e&&e.default||0}if(Uv.includes(t)){let n=getComputedStyle(e)[t];if(typeof n==`string`&&n)return n.trim()}return t=WS.has(t)?t:Rv(t),e.getAttribute(t)}scrapeMotionValuesFromProps(e,t,n){return qS(e,t,n)}build(e,t,n){Wv(e,t,this.isSVGTag,n.transformTemplate,n.style)}renderInstance(e,t,n,r){KS(e,t,n,r)}mount(e){this.isSVGTag=GS(e.tagName),super.mount(e)}};function YS(e,t){if(!Array.isArray(t))return!1;let n=t.length;if(n!==e.length)return!1;for(let r=0;r<n;r++)if(t[r]!==e[r])return!1;return!0}var XS=[...lx].reverse(),ZS=e=>e?.out===!0?e:e?.out;function QS(e){let t=t=>Promise.all(t.map(({animation:t,options:n})=>Sv(e,t,n))),n=eC(),r=!0,i=!1;function a(a){let{props:o,parent:s,manuallyAnimateOnMount:c}=e,{initial:l}=o,u=r||i,d=[],f=(t=l)=>typeof t!=`boolean`&&ov(e,Array.isArray(t)?t[0]:t,e.presenceContext?.custom)||void 0,p=new Map,m={},h=1/0,g=e;do g=g.props.inherit!==!1&&g.parent;while(g&&!g.isControllingVariants);let _=u&&ZS(f(l??(g&&g.props.initial))?.transition);if(XS.forEach((t,r)=>{let i=n[t],l=o[t],f=g&&g.props[t],v=l===void 0?cx(f)||f===!1?f:void 0:l,y=cx(v),b=t===a?i.isActive:null,x=y&&l===void 0&&!(u&&c);if(i.protectedKeys={...m},!i.isActive&&b===null||!v&&!i.prevProp||sx(v)||typeof v==`boolean`)return;if(b===!1&&(h=r),t===`exit`&&i.isActive&&b!==!0){m={...m,...i.prevResolvedValues};return}let S=$S(i.prevProp,v),C=S||y&&(b&&!x||r>h),w=!1,T=Array.isArray(v)?v:[v],E={},D;if(b!==!1)for(let n of T){let{transition:r,transitionEnd:i,...a}=ov(e,n,sv(e,t))||{};E={...E,...a,...i},D=ZS(r)||D}let{prevResolvedValues:O}=i;for(let t in{...O,...E}){if(t in m)continue;let n=E[t],r=O[t],a=Array.isArray(n)&&Array.isArray(r)?!YS(n,r)||S:n!==r,o;if(a&&n==null)p.has(t)||p.set(t,i.prevOut);else if(a||n!==void 0&&p.has(t)){C=!0,o=p.get(t)||_,p.delete(t)&&(w=!0),i.needsAnimating[t]=!0;let n=e.getValue(t);n&&(n.liveStyle=!1)}else i.protectedKeys[t]=!0;i.out[t]=o}if(i.prevProp=v,i.prevResolvedValues=E,i.prevOut=D,i.isActive&&(m={...m,...E}),C&&(!(x&&S)||w))for(let n of T){let r={type:t};if(typeof n==`string`&&u&&c&&s?.enteringChildren){let t=ov(s,n)?.transition?.delayChildren;r.delay=z_(s.enteringChildren,e,t)}d.push({animation:n,options:r})}}),p.size){let t={},n=f(),r=n?.transition;p.forEach((i,a)=>{i&&(r={...r||e.getDefaultTransition(),[a]:i});let s=e.getValue(a);s&&(s.liveStyle=!0);let c=n&&!Array.isArray(l)?n[a]:void 0,u=e.getBaseTargetFromProps(o,a);t[a]=(c===void 0?u!==void 0&&!pv(u)?u:e.initialValues[a]===void 0?e.baseTarget[a]:void 0:c)??null}),r&&(t.transition=r),d.push({animation:t})}let v=u&&e.blockInitialAnimation||r&&!c&&(o.initial===!1||o.initial===o.animate);return r=i=!1,!v&&d.length?t(d):Promise.resolve()}function o(t,r){if(n[t].isActive===r)return Promise.resolve();e.variantChildren?.forEach(e=>e.animationState?.setActive(t,r)),n[t].isActive=r;let i=a(t);for(let e in n)n[e].protectedKeys={};return i}return{animateChanges:a,setActive:o,setAnimateFunction:n=>{t=n(e)},getState:()=>n,reset:()=>{n=eC(),i=!0}}}function $S(e,t){return typeof t==`string`?t!==e:Array.isArray(t)?!YS(t,e):!1}function eC(){let e={};for(let t of lx)e[t]={isActive:t===`animate`,protectedKeys:{},needsAnimating:{},prevResolvedValues:{},out:{}};return e}var tC=(0,U.createContext)({transformPagePoint:e=>e,isStatic:!1,reducedMotion:`never`});function nC(e=!0){let t=(0,U.useContext)(Hf);if(t===null)return[!0,null];let{isPresent:n,onExitComplete:r,register:i}=t,a=(0,U.useId)();(0,U.useEffect)(()=>{if(e)return i(a)},[e]);let o=(0,U.useCallback)(()=>e&&r&&r(a),[a,r,e]);return!n&&r?[!1,o]:[!0]}var rC=(0,U.createContext)({strict:!1}),iC={animation:[`variants`,...lx],exit:[`exit`],drag:[`drag`,`dragControls`],focus:[`whileFocus`],hover:[`whileHover`,`onHoverStart`,`onHoverEnd`],tap:[`whileTap`,`onTap`,`onTapStart`,`onTapCancel`],pan:[`onPan`,`onPanStart`,`onPanSessionStart`,`onPanEnd`],inView:[`whileInView`,`onViewportEnter`,`onViewportLeave`],layout:[`layout`,`layoutId`]},aC=!1;function oC(){if(aC)return;let e={};for(let t in iC)e[t]={isEnabled:e=>iC[t].some(t=>!!e[t])};bx(e),aC=!0}function sC(){return oC(),xx()}function cC(e){let t=sC();for(let n in e)t[n]={...t[n],...e[n]};bx(t)}var lC=(0,U.createContext)({});function uC(e,t){if(dx(e)){let{initial:t,animate:n}=e;return{initial:t===!1||cx(t)?t:void 0,animate:cx(n)?n:void 0}}return e.inherit===!1?{}:t}function dC(e){let{initial:t,animate:n}=uC(e,(0,U.useContext)(lC));return(0,U.useMemo)(()=>({initial:t,animate:n}),[fC(t),fC(n)])}function fC(e){return Array.isArray(e)?e.join(` `):e}var pC=()=>({style:{},transform:{},transformOrigin:{},vars:{}});function mC(e,t,n){for(let r in t)!pv(t[r])&&!Tx(r,n)&&(e[r]=t[r])}function hC({transformTemplate:e},t){return(0,U.useMemo)(()=>{let n=pC();return zv(n,t,e),Object.assign({},n.vars,n.style)},[t])}function gC(e,t){let n=e.style||{},r={};return mC(r,n,e),Object.assign(r,hC(e,t)),r}function _C(e,t){let n={},r=gC(e,t);return e.drag&&e.dragListener!==!1&&(n.draggable=!1,r.userSelect=r.WebkitUserSelect=r.WebkitTouchCallout=`none`,r.touchAction=e.drag===!0?`none`:`pan-${e.drag===`x`?`y`:`x`}`),e.tabIndex===void 0&&(e.onTap||e.onTapStart||e.whileTap)&&(n.tabIndex=0),n.style=r,n}var vC=()=>({...pC(),attrs:{}});function yC(e,t,n,r){let i=(0,U.useMemo)(()=>{let n=vC();return Wv(n,t,GS(r),e.transformTemplate,e.style),{...n.attrs,style:{...n.style}}},[t]);if(e.style){let t={};return mC(t,e.style,e),{...i,style:{...t,...i.style}}}return i}var bC=new Set(`animate.exit.variants.initial.style.values.transition.transformTemplate.custom.inherit.onBeforeLayoutMeasure.onAnimationStart.onAnimationComplete.onUpdate.onDragStart.onDrag.onDragEnd.onMeasureDragConstraints.onDirectionLock.onDragTransitionEnd._dragX._dragY.onHoverStart.onHoverEnd.onViewportEnter.onViewportLeave.globalTapTarget.propagate.ignoreStrict.viewport`.split(`.`));function xC(e){return e.startsWith(`while`)||e.startsWith(`drag`)&&e!==`draggable`||e.startsWith(`layout`)||e.startsWith(`onTap`)||e.startsWith(`onPan`)||e.startsWith(`onLayout`)||bC.has(e)}function SC(e,t){return e.startsWith(`on`)?!xC(e):t?.(e)??!xC(e)}function CC(e,t,n,r){let i={};for(let a in e)a===`values`&&typeof e.values==`object`||pv(e[a])||(SC(a,r)||n===!0&&xC(a)||!t&&!xC(a)||e.draggable&&a.startsWith(`onDrag`))&&(i[a]=e[a]);return i}var wC=[`animate`,`circle`,`defs`,`desc`,`ellipse`,`g`,`image`,`line`,`filter`,`marker`,`mask`,`metadata`,`path`,`pattern`,`polygon`,`polyline`,`rect`,`stop`,`switch`,`symbol`,`svg`,`text`,`tspan`,`use`,`view`];function TC(e){return typeof e!=`string`||e.includes(`-`)?!1:!!(wC.indexOf(e)>-1||/[A-Z]/u.test(e))}function EC(e,t,n,{latestValues:r},i,a=!1,o,s){let c=(o??TC(e)?yC:_C)(t,r,i,e),l=CC(t,typeof e==`string`,a,s),u=e===U.Fragment?{}:{...l,...c,ref:n},{children:d}=t,f=(0,U.useMemo)(()=>pv(d)?d.get():d,[d]);return(0,U.createElement)(e,{...u,children:f})}function DC({scrapeMotionValuesFromProps:e,createRenderState:t},n,r,i){return{latestValues:OC(n,r,i,e),renderState:t()}}function OC(e,t,n,r){let i={},a=r(e,{});for(let e in a)i[e]=Cy(a[e]);let{initial:o,animate:s}=e,c=dx(e),l=fx(e);t&&l&&!c&&e.inherit!==!1&&(o===void 0&&(o=t.initial),s===void 0&&(s=t.animate));let u=n?n.initial===!1:!1;u||=o===!1;let d=u?s:o;if(d&&typeof d!=`boolean`&&!sx(d)){let t=Array.isArray(d)?d:[d];for(let n=0;n<t.length;n++){let r=av(e,t[n]);if(r){let{transitionEnd:e,transition:t,...n}=r;for(let e in n){let t=n[e];if(Array.isArray(t)){let e=u?t.length-1:0;t=t[e]}t!==null&&(i[e]=t)}for(let t in e)i[t]=e[t]}}}return i}var kC=e=>(t,n)=>{let r=(0,U.useContext)(lC),i=(0,U.useContext)(Hf),a=()=>DC(e,t,r,i);return n?a():Vf(a)},AC=kC({scrapeMotionValuesFromProps:Ex,createRenderState:pC}),jC=kC({scrapeMotionValuesFromProps:qS,createRenderState:vC}),MC=Symbol.for(`motionComponentSymbol`);function NC(e,t,n){let r=(0,U.useRef)(n);(0,U.useInsertionEffect)(()=>{r.current=n});let i=(0,U.useRef)(null);return(0,U.useCallback)(n=>{n&&e.onMount?.(n),t&&(n?t.mount(n):t.unmount());let a=r.current;if(typeof a==`function`){if(n){let e=a(n);typeof e==`function`&&(i.current=e)}else i.current?(i.current(),i.current=null):a(n)}else a&&(a.current=n)},[t])}var PC=(0,U.createContext)({});function FC(e,t,n,r,i,a){let{visualElement:o}=(0,U.useContext)(lC),s=(0,U.useContext)(rC),c=(0,U.useContext)(Hf),l=(0,U.useContext)(tC),u=l.reducedMotion,d=l.skipAnimations,f=(0,U.useRef)(null),p=(0,U.useRef)(!1);r||=s.renderer,!f.current&&r&&(f.current=r(e,{visualState:t,parent:o,props:n,presenceContext:c,blockInitialAnimation:c?c.initial===!1:!1,reducedMotionConfig:u,skipAnimations:d,isSVG:a}),p.current&&f.current&&(f.current.manuallyAnimateOnMount=!0));let m=f.current,h=(0,U.useContext)(PC);m&&!m.projection&&i&&(m.type===`html`||m.type===`svg`)&&i.create(m,n,h),(0,U.useInsertionEffect)(()=>{m&&m.props!==n&&m.update(n,c)});let g=n[gv],_=(0,U.useRef)(!!g&&typeof window<`u`&&!window.MotionHandoffIsComplete?.(g)&&window.MotionHasOptimisedAnimation?.(g));return Q(()=>{p.current&&m&&(m.animationState?.animateChanges(),m.enteringChildren=void 0)},[]),Q(()=>{p.current=!0,m&&(window.MotionIsMounted=!0,m.updateFeatures(),m.scheduleRenderMicrotask(),_.current&&m.animationState&&m.animationState.animateChanges())}),(0,U.useEffect)(()=>{m&&(!_.current&&m.animationState&&m.animationState.animateChanges(),_.current&&=(queueMicrotask(()=>{window.MotionHandoffMarkAsComplete?.(g)}),!1),m.enteringChildren=void 0)}),m}function IC(e,{forwardMotionProps:t=!1,type:n}={},r,i){r&&cC(r);let a=n?n===`svg`:TC(e),o=a?jC:AC;function s(n,s){let c,l=LC(n);Vf(()=>!!ix.current?.sharedNodes.get(l)?.lead&&n.initial)&&(n={...n,initial:!1});let u={...(0,U.useContext)(tC),...n,layoutId:l},{isStatic:d,isValidProp:f}=u,p=dC(n),m=o(n,d);if(!d&&typeof window<`u`){RC(u,r);let t=zC(u);p.visualElement=FC(e,m,u,i,t.ProjectionNode,a),(t.isEnabled||p.visualElement?.projection?.options.layoutId)&&(c=t.MeasureLayout)}return(0,W.jsxs)(lC.Provider,{value:p,children:[c&&p.visualElement?(0,W.jsx)(c,{visualElement:p.visualElement,...u}):null,EC(e,n,NC(m,p.visualElement,s),m,d,t,a,f)]})}s.displayName=`motion.${typeof e==`string`?e:`create(${e.displayName??e.name??``})`}`;let c=(0,U.forwardRef)(s);return c[MC]=e,c}function LC({layoutId:e}){let t=(0,U.useContext)(Bf).id;return t&&e!==void 0?t+`-`+e:e}function RC(e,t){(0,U.useContext)(rC).strict}function zC(e){let{drag:t,layout:n}=sC();if(!t&&!n)return{};let r={...t,...n};return{MeasureLayout:r.MeasureLayout,isEnabled:t?.isEnabled(e)||n?.isEnabled(e),ProjectionNode:r.ProjectionNode}}function BC(e,t){if(typeof Proxy>`u`)return IC;let n=new Map,r=(n,r)=>IC(n,r,e,t);return new Proxy((e,t)=>r(e,t),{get:(i,a)=>a===`create`?r:(n.has(a)||n.set(a,IC(a,void 0,e,t)),n.get(a))})}var VC=(e,t)=>t.isSVG??TC(e)?new JS(t):new Ox(t,{allowProjection:e!==U.Fragment}),HC=class extends US{constructor(e){super(e),e.animationState||=QS(e)}updateAnimationControlsSubscription(){let{animate:e}=this.node.getProps();sx(e)&&(this.unmountControls=e.subscribe(this.node))}mount(){this.updateAnimationControlsSubscription()}update(){this.node.getProps().animate!==this.node.prevProps?.animate&&this.updateAnimationControlsSubscription()}unmount(){this.node.animationState.reset(),this.unmountControls?.()}},UC=0,WC={animation:{Feature:HC},exit:{Feature:class extends US{constructor(){super(...arguments),this.id=UC++}update(){let{presenceContext:e,prevPresenceContext:t,animationState:n}=this.node;if(!e||!n)return;let{isPresent:r,onExitComplete:i}=e,a=t?.isPresent;if(r===a)return;if(r&&a===!1){if(this.exit===!0){let{initial:e}=this.node.getProps();if(e&&!Array.isArray(e)){let{transition:t,transitionEnd:n,...r}=ov(this.node,e)||{};for(let e in r)this.node.getValue(e)?.jump(r[e])}this.node.blockInitialAnimation=!1,n.reset(),n.animateChanges()}else n.setActive(`exit`,!1);this.exit=void 0;return}let o=this.exit=n.setActive(`exit`,!r);i&&!r&&o.then(()=>{this.exit===o&&(this.exit=!0,i(this.id))})}mount(){let{register:e,onExitComplete:t}=this.node.presenceContext||{};t&&t(this.id),e&&(this.unmount=e(this.id,this.node))}unmount(){}}}},GC=class extends US{constructor(e){super(e),this.removeGroupControls=Qf,this.removeListeners=Qf,this.controls=new wS(e)}mount(){let{dragControls:e}=this.node.getProps();e&&(this.removeGroupControls=e.subscribe(this.controls)),this.removeListeners=this.controls.addListeners()||Qf}update(){let{dragControls:e,drag:t}=this.node.getProps(),{dragControls:n,drag:r}=this.node.prevProps||{};e!==n&&(this.removeGroupControls(),e&&(this.removeGroupControls=e.subscribe(this.controls))),r&&!t&&this.controls.stop(void 0,void 0,r)}unmount(){this.removeGroupControls(),this.removeListeners(),this.controls.isDragging||this.controls.endPanSession()}},KC=e=>(t,n)=>{e&&Km.update(()=>e(t,n),!1,!0)},qC=class extends US{constructor(){super(...arguments),this.removePointerDownListener=Qf}onPointerDown(e){this.session=new Xx(e,this.createPanHandlers(),{transformPagePoint:this.node.getTransformPagePoint(),contextWindow:this.node.current?.ownerDocument.defaultView})}createPanHandlers(){let{onPanSessionStart:e,onPanStart:t,onPan:n,onPanEnd:r}=this.node.getProps();return{onSessionStart:KC(e),onStart:KC(t),onMove:KC(n),onEnd:(e,t)=>{delete this.session,r&&Km.postRender(()=>r(e,t))}}}mount(){this.removePointerDownListener=Mx(this.node.current,`pointerdown`,e=>this.onPointerDown(e))}update(){this.session?.updateHandlers(this.createPanHandlers())}unmount(){this.removePointerDownListener(),this.session?.end()}},JC=!1,YC=({layout:e,layoutDependency:t,layoutAnchor:n})=>({layout:e,layoutDependency:t,layoutAnchor:n,animationType:typeof e==`string`?e:`both`}),XC=(e,t)=>{let{snapshot:n}=e,r=e.getStack();r?.remove(e);let i=r?.lead;if(r?.prevLead===e&&i.resumeFrom===e&&(i.resumeFrom=i.currentAnimation=e.resumingFrom=void 0),e.options.layoutId=t,!t)e.needsShow=!0;else return e.root.registerSharedNode(t,e),()=>{let{resumeFrom:t}=e;t?.isPresent!==!1&&e.getStack().members.includes(t)&&(t.hide(),e.resumeFrom=void 0,e.snapshot=n)}},ZC=class extends U.Component{componentDidMount(){let{visualElement:e,layoutGroup:t,switchLayoutGroup:n,layoutId:r}=this.props,{projection:i}=e;i&&(t.group?.add(i),r&&n?.register?.(i),JC&&i.root.didUpdate(),i.options.layoutId!==r&&XC(i,r)?.(),i.addEventListener(`animationComplete`,()=>this.safeToRemove()),i.setOptions({...i.options,...YC(this.props),onExitComplete:()=>this.safeToRemove()})),Cb.hasEverUpdated=!0}getSnapshotBeforeUpdate(e){let{layoutDependency:t,layoutId:n,visualElement:r,drag:i,isPresent:a}=this.props,{projection:o}=r;return o&&(o.isPresent=a,this.takeOver=e.layoutId===n?void 0:(o.willUpdate(),XC(o,n)),o.setOptions({...o.options,...YC(this.props)}),JC=!0,i||e.layoutDependency!==t||t===void 0||e.isPresent!==a?o.willUpdate():this.safeToRemove(),e.isPresent!==a&&(a?o.promote():o.relegate()||Km.postRender(()=>{o.getStack()?.members.length||this.safeToRemove()}))),null}componentDidUpdate(){let{projection:e}=this.props.visualElement;e&&(this.takeOver?.(),e.root.didUpdate(),hy.postRender(()=>{!e.currentAnimation&&e.isLead()&&this.safeToRemove()}))}componentWillUnmount(){let{visualElement:e,layoutGroup:t,switchLayoutGroup:n}=this.props,{projection:r}=e;JC=!0,r&&(r.scheduleCheckAfterUnmount(),t.group?.remove(r),n?.deregister?.(r))}safeToRemove(){this.props.safeToRemove?.()}render(){return null}};function QC(e){let[t,n]=nC(),r=(0,U.useContext)(Bf);return(0,W.jsx)(ZC,{...e,layoutGroup:r,switchLayoutGroup:(0,U.useContext)(PC),isPresent:t,safeToRemove:n})}var $C={pan:{Feature:qC},drag:{Feature:GC,ProjectionNode:ax,MeasureLayout:QC}};function ew(e,t,n,r){let{props:i}=e,a=`while`+n;e.animationState&&i[a]&&e.animationState.setActive(a,r===`Start`);let o=i[`on`+n+r];o&&Km.postRender(()=>o(t,Ax(t)))}var tw=class extends US{mount(){let{current:e}=this.node;e&&(this.unmount=NS(e,(e,t)=>(ew(this.node,t,`Hover`,`Start`),e=>ew(this.node,e,`Hover`,`End`))))}unmount(){}},nw=class extends US{constructor(){super(...arguments),this.isActive=!1}onFocus(){let e=!1;try{e=this.node.current.matches(`:focus-visible`)}catch{e=!0}e&&this.node.animationState&&(this.node.animationState.setActive(`whileFocus`,!0),this.isActive=!0)}onBlur(){this.isActive&&this.node.animationState&&(this.node.animationState.setActive(`whileFocus`,!1),this.isActive=!1)}mount(){this.unmount=$f(nx(this.node.current,`focus`,()=>this.onFocus()),nx(this.node.current,`blur`,()=>this.onBlur()))}unmount(){}};function rw(e,t,n){e.current instanceof HTMLButtonElement&&e.current.disabled||ew(e,t,`Tap`,n)}var iw=class extends US{mount(){let{current:e}=this.node;if(!e)return;let{globalTapTarget:t,propagate:n}=this.node.props;this.unmount=VS(e,(e,t)=>(rw(this.node,t,`Start`),(e,{success:t})=>rw(this.node,e,t?``:`Cancel`)),{useGlobalTarget:t,stopPropagation:n?.tap===!1})}unmount(){}},aw=new WeakMap,ow=new WeakMap,sw=e=>{let t=aw.get(e.target);t&&t(e)},cw=e=>{e.forEach(sw)};function lw({root:e,...t}){let n=e||document;ow.has(n)||ow.set(n,{});let r=ow.get(n),i=JSON.stringify(t);return r[i]||(r[i]=new IntersectionObserver(cw,{root:e,...t})),r[i]}function uw(e,t,n){let r=lw(t);return aw.set(e,n),r.observe(e),()=>{aw.delete(e),r.unobserve(e)}}var dw={some:0,all:1},fw=class extends US{constructor(){super(...arguments),this.hasEnteredView=!1,this.isInView=!1}startObserver(){this.stopObserver?.();let{viewport:e={}}=this.node.getProps(),{root:t,margin:n,amount:r=`some`,once:i}=e,a={root:t?t.current:void 0,rootMargin:n,threshold:typeof r==`number`?r:dw[r]},o=e=>{let{isIntersecting:t}=e;if(this.isInView===t||(this.isInView=t,i&&!t&&this.hasEnteredView))return;t&&(this.hasEnteredView=!0),this.node.animationState&&this.node.animationState.setActive(`whileInView`,t);let{onViewportEnter:n,onViewportLeave:r}=this.node.getProps(),a=t?n:r;a&&a(e)};this.stopObserver=uw(this.node.current,a,o)}mount(){this.startObserver()}update(){if(typeof IntersectionObserver>`u`)return;let{props:e,prevProps:t}=this.node;[`amount`,`margin`,`root`].some(pw(e,t))&&this.startObserver()}unmount(){this.stopObserver?.(),this.hasEnteredView=!1,this.isInView=!1}};function pw({viewport:e={}},{viewport:t={}}={}){return n=>e[n]!==t[n]}var mw=BC(Object.assign({},WC,{inView:{Feature:fw},tap:{Feature:iw},focus:{Feature:nw},hover:{Feature:tw}},$C,{layout:{ProjectionNode:ax,MeasureLayout:QC}}),VC);function hw(e){let t=Vf(()=>W_(e)),{isStatic:n}=(0,U.useContext)(tC);if(n){let[,n]=(0,U.useState)(e);(0,U.useEffect)(()=>t.on(`change`,n),[])}return t}function gw(e,t){let n=hw(t()),r=()=>n.set(t());return r(),Q(()=>{let t=()=>Km.preRender(r,!1,!0),n=e.map(e=>e.on(`change`,t));return r(),()=>{n.forEach(e=>e()),qm(r)}}),n}function _w(e){H_.current=[],e();let t=gw(H_.current,e);return H_.current=void 0,t}function vw(e,t,n,r){if(typeof e==`function`)return _w(e);if(n!==void 0&&!Array.isArray(n)&&typeof t!=`function`)return bw(e,t,n,r);let i=typeof t==`function`?t:HS(t,n,r),a=Array.isArray(e)?yw(e,i):yw([e],([e])=>i(e)),o=Array.isArray(e)?void 0:e.accelerate;if(o&&!o.isTransformed&&typeof t!=`function`&&Array.isArray(n)&&r?.clamp!==!1&&!r?.mixer){let e=r?.ease;a.accelerate={...o,times:[0,...t,1],keyframes:[n[0],...n,n[n.length-1]],isTransformed:!0,...e?{ease:Array.isArray(e)?[e[0],...e]:e}:{}}}return a}function yw(e,t){let n=Vf(()=>[]);return gw(e,()=>{n.length=0;let r=e.length;for(let t=0;t<r;t++)n[t]=e[t].get();return t(n)})}function bw(e,t,n,r){let i=Vf(()=>Object.keys(n)),a=Vf(()=>({}));for(let o of i)a[o]=vw(e,t,n[o],r);return a}var xw=class{constructor(){this.componentControls=new Set}subscribe(e){return this.componentControls.add(e),()=>this.componentControls.delete(e)}start(e,t){this.componentControls.forEach(n=>{n.start(e.nativeEvent||e,t)})}cancel(){this.componentControls.forEach(e=>{e.cancel()})}stop(){this.componentControls.forEach(e=>{e.stop()})}},Sw=()=>new xw;function Cw(){return Vf(Sw)}var ww=(0,U.createContext)(null);function Tw(e,t,n,r,i,a=`ltr`){let o=e.findIndex(e=>e.value===t);if(o===-1)return e;if(i===`xy`){let{layout:t}=e[o],r={x:Tm(t.x.min,t.x.max,.5)+n.x,y:Tm(t.y.min,t.y.max,.5)+n.y},i=Ew(e),s=i.find(t=>t.items.includes(e[o])),c=i.reduce((e,t)=>Dw(r.y,t)<Dw(r.y,e)?t:e);if(c!==s)return Ow(e,o,r.x,c,a);let l=kw(r,t),u=-1,d=l;return e.forEach((e,t)=>{if(t===o)return;let n=kw(r,e.layout);n<d&&(u=t,d=n)}),u===-1?e:Gf(e,o,o+Math.sign(u-o))}if(!r[i])return e;let s=r[i]>0?1:-1,c=e[o+s];if(!c)return e;let l=e[o].layout[i],u=c.layout[i],d=Tm(u.min,u.max,.5);return s===1&&l.max+n[i]>d||s===-1&&l.min+n[i]<d?Gf(e,o,o+s):e}function Ew(e){let t=[];return e.forEach(e=>{let{min:n,max:r}=e.layout.y,i=t[t.length-1];!i||n>=i.max||r<=i.min?t.push({items:[e],min:n,max:r}):(i.items.push(e),i.min=Math.min(i.min,n),i.max=Math.max(i.max,r))}),t}function Dw(e,t){return e<t.min?t.min-e:e>t.max?e-t.max:0}function Ow(e,t,n,r,i){let a=e.filter((e,n)=>n!==t),o=r.items.find(e=>{let t=Tm(e.layout.x.min,e.layout.x.max,.5);return i===`ltr`?n<t:n>t}),s=o?a.indexOf(o):a.indexOf(r.items[r.items.length-1])+1,c=[...a];return c.splice(s,0,e[t]),c.every((t,n)=>t===e[n])?e:c}function kw(e,t){let n=Math.max(t.x.min-e.x,0,e.x-t.x.max),r=Math.max(t.y.min-e.y,0,e.y-t.y.max);return n*n+r*r}var Aw=(e,t)=>e.max<=t.min||t.max<=e.min;function jw(e){let t=!1,n=!1;for(let r=0;r<e.length;r++)for(let i=r+1;i<e.length;i++)if(t||=Aw(e[r].x,e[i].x),n||=Aw(e[r].y,e[i].y),t&&n)return`xy`;return t?`x`:`y`}function Mw({children:e,as:t=`ul`,axis:n,onReorder:r,values:i,onPointerDownCapture:a,onClickCapture:o,...s},c,l){let u=Vf(()=>l[t]),d=(0,U.useRef)(new Map),[f,p]=(0,U.useState)(`y`),m=(0,U.useRef)(!1),h=(0,U.useRef)(!1),g=(0,U.useRef)(null),_=n||f,v=new Set(i);d.current.forEach((e,t)=>{v.has(t)||d.current.delete(t)});let y=()=>i.flatMap(e=>{let t=d.current.get(e);return t?[{value:e,layout:t}]:[]}),b=()=>g.current?.ownerDocument.defaultView?.getComputedStyle(g.current).direction===`rtl`,x=(e,t)=>{let n=0,a=i.map(t=>d.current.has(t)?e[n++].value:t);a.some((e,t)=>e!==i[t])&&r(a,t)},S={axis:_,proxy:l,groupRef:g,hasReordered:h,onKeyDown:(e,t,n,r)=>{let{key:a,currentTarget:o}=e;if(e.defaultPrevented||e.target!==o||e.altKey||e.ctrlKey||e.metaKey)return;let s=y(),c=[`ArrowUp`,`ArrowLeft`,`ArrowDown`,`ArrowRight`].indexOf(a),l=c%2;if(a===` `)e.repeat||r(o,n?void 0:i);else if(!n)return;else if(a===`Escape`){let e=n.flatMap(e=>s.filter(t=>t.value===e));x(s.map(t=>n.includes(t.value)?e.shift():t),t),r(o)}else if(c<0||_!==`xy`&&_!==(l?`x`:`y`))return;else{let e=s.findIndex(({value:e})=>e===t),n=e+(c>1==!!(l&&b())?-1:1);e>-1&&s[n]&&x(Gf(s,e,n),t)}e.preventDefault()},registerItem:(e,t)=>{if(d.current.set(e,t),!n){let e=jw(i.flatMap(e=>{let t=d.current.get(e);return t?[t]:[]}));e!==f&&p(e)}},updateOrder:(e,t,n)=>{if(m.current)return;let r=y(),i=Tw(r,e,t,n,_,b()?`rtl`:`ltr`);r!==i&&(m.current=!0,h.current=!0,x(i,e))}};(0,U.useEffect)(()=>{m.current=!1},[i]);let C=e=>{g.current=e,typeof c==`function`?c(e):c&&(c.current=e)},w={overflowAnchor:`none`,...s.style};return(0,W.jsx)(u,{...s,style:w,ref:C,onPointerDownCapture:e=>{h.current=!1,a?.(e)},onClickCapture:e=>{h.current&&e.detail&&(h.current=!1,e.stopPropagation(),e.preventDefault()),o?.(e)},ignoreStrict:!0,children:(0,W.jsx)(ww.Provider,{value:S,children:e})})}var Nw=e=>(0,U.forwardRef)((t,n)=>Mw(t,n,e)),Pw=50,Fw=1.5,Iw=new Set([`auto`,`scroll`]),Lw=new WeakMap,Rw=new WeakMap,zw=null;function Bw(){if(zw){let e=Hw(zw,`y`);e&&(Rw.delete(e),Lw.delete(e));let t=Hw(zw,`x`);t&&t!==e&&(Rw.delete(t),Lw.delete(t)),zw=null}}function Vw(e,t){let n=getComputedStyle(e),r=t===`x`?n.overflowX:n.overflowY,i=e===document.body||e===document.documentElement;return Iw.has(r)||i}function Hw(e,t){let n=e?.parentElement;for(;n;){if(Vw(n,t))return n;n=n.parentElement}return null}function Uw(e){let t=Math.min(1,1-e/Pw);return Fw*t*t*wp.delta}function Ww(e,t,n){let r=t.getBoundingClientRect(),i=n===`x`?Math.max(0,r.left):Math.max(0,r.top),a=n===`x`?Math.min(window.innerWidth,r.right):Math.min(window.innerHeight,r.bottom),o=e-i,s=a-e;return o<Pw?{amount:-Uw(o),edge:`start`}:s<Pw?{amount:Uw(s),edge:`end`}:{amount:0,edge:null}}function Gw(e,t,n,r){if(!e)return;zw=e;let i=Hw(e,n);if(!i)return;let{amount:a,edge:o}=Ww(t-(n===`x`?window.scrollX:window.scrollY),i,n);if(o===null){Rw.delete(i),Lw.delete(i);return}let s=Rw.get(i),c=i===document.body||i===document.documentElement;if(s!==o){if(!(o===`start`&&r<0||o===`end`&&r>0))return;Rw.set(i,o);let e=n===`x`?i.scrollWidth-(c?window.innerWidth:i.clientWidth):i.scrollHeight-(c?window.innerHeight:i.clientHeight);Lw.set(i,e)}if(a>0){let e=Lw.get(i);if((n===`x`?c?window.scrollX:i.scrollLeft:c?window.scrollY:i.scrollTop)>=e)return}n===`x`?c?window.scrollBy({left:a}):i.scrollLeft+=a:c?window.scrollBy({top:a}):i.scrollTop+=a}function Kw(e,t=0){return pv(e)?e:hw(t)}function qw({children:e,style:t={},value:n,as:r=`li`,onDrag:i,onDragEnd:a,onKeyDown:o,onBlur:s,layout:c=!0,...l},u){let d=(0,U.useContext)(ww),f=Vf(()=>d.proxy[r]),[p,m]=(0,U.useState)(),h={x:Kw(t.x),y:Kw(t.y)},g=vw([h.x,h.y],([e,t])=>e||t?1:`unset`),{axis:_,registerItem:v,updateOrder:y,groupRef:b,hasReordered:x,onKeyDown:S}=d,C=_===`xy`||_,w=(e,t)=>{m(t),ox.get(e)?.animationState?.setActive(`whileDrag`,!!t)};return(0,W.jsx)(f,{drag:C,tabIndex:0,...l,dragSnapToOrigin:!0,style:{...t,x:h.x,y:h.y,zIndex:g},layout:c,onDrag:(e,t)=>{let{velocity:r,point:a}=t,o={x:h.x.get(),y:h.y.get()};y(n,o,r);let s=_===`xy`?Math.abs(r.x)>Math.abs(r.y)?`x`:`y`:_;Gw(b.current,a[s],s,r[s]),i&&i(e,t)},onDragEnd:(e,t)=>{x.current=!1,Bw(),a&&a(e,t)},onKeyDown:e=>{o?.(e),S(e,n,p,w)},onBlur:e=>{s?.(e),p&&w(e.currentTarget)},onLayoutMeasure:e=>{v(n,e)},ref:u,ignoreStrict:!0,children:e})}var Jw=(0,U.forwardRef)(qw),Yw=Nw(mw);function Xw(e){let[t,n]=(0,U.useState)(!1),[r,i]=(0,U.useState)(``),[a,o]=(0,U.useState)(``),[s,c]=(0,U.useState)(``),[l,u]=(0,U.useState)(null);return(0,W.jsxs)(`form`,{className:`grid`,onSubmit:async n=>{n.preventDefault(),u(null);try{if(t)await re([C(a).address],s.trim()===``?null:s.trim());else{let e=C(r);await re([e.address],e.code)}e.onAdded?.()}catch(e){u(Ot(e))}},children:[(0,W.jsxs)(`div`,{className:z(`grid gap-2`,e.fieldsClassName),children:[t?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(Hd,{"aria-label":`Server URL`,placeholder:`Server URL, e.g. http://127.0.0.1:47841`,spellCheck:!1,autoComplete:`off`,value:a,onChange:e=>o(e.target.value)}),(0,W.jsx)(Hd,{"aria-label":`Pairing code`,placeholder:`Pairing code, empty if auth is off`,spellCheck:!1,autoComplete:`off`,value:s,onChange:e=>c(e.target.value)})]}):(0,W.jsx)(Hd,{"aria-label":`Pairing link`,placeholder:`Pairing link`,spellCheck:!1,autoComplete:`off`,value:r,onChange:e=>i(e.target.value)}),l!==null&&(0,W.jsx)(`p`,{className:`text-destructive text-sm break-all`,children:l}),(0,W.jsx)(`button`,{type:`button`,className:`text-muted-foreground hover:text-foreground w-fit cursor-pointer text-xs`,onClick:()=>{n(!t),u(null)},children:t?`Paste a pairing link instead`:`Enter the server URL and code separately`})]}),e.actions(t?a.trim()!==``:r.trim()!==``)]})}function Zw(e){return(0,W.jsx)(Or,{open:!0,onOpenChange:()=>e.onClose(),children:(0,W.jsxs)(xr,{className:`gap-0 overflow-hidden p-0 sm:max-w-md`,children:[(0,W.jsxs)(Sr,{className:`gap-1 px-6 pt-4 pr-12`,children:[(0,W.jsx)(Tr,{className:`text-base`,children:`Add machine`}),(0,W.jsx)(Er,{children:`Paste the pairing link that OffSite printed when it started.`})]}),(0,W.jsx)(Xw,{fieldsClassName:`p-6`,onAdded:e.onClose,actions:t=>(0,W.jsxs)(kr,{className:`bg-muted/40 border-t px-6 py-4`,children:[(0,W.jsx)(H,{type:`button`,variant:`outline`,onClick:e.onClose,children:`Cancel`}),(0,W.jsx)(H,{type:`submit`,disabled:!t,children:`Add machine`})]})})]})})}function Qw(e){let t=e.machine,n=t.icon??`computer`,[r,i]=(0,U.useState)(!1);return(0,W.jsxs)(`div`,{className:`flex min-h-13 items-center justify-between gap-4 px-4 py-2.5`,children:[(0,W.jsx)(`span`,{className:`text-sm font-medium`,children:`Icon`}),(0,W.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(Bu.includes(n)?Bu:[n,...Bu]).map(e=>(0,W.jsx)(H,{title:e,size:`icon-sm`,"aria-pressed":e===n,variant:e===n?`default`:`ghost`,onClick:()=>o(t.id,{icon:e}),children:(0,W.jsx)(Vu,{icon:e})},e)),(0,W.jsxs)($n,{open:r,onOpenChange:i,modal:!0,children:[(0,W.jsx)(Wt,{asChild:!0,children:(0,W.jsx)(H,{title:`More icons`,size:`icon-sm`,variant:`ghost`,children:(0,W.jsx)(V,{icon:Rn})})}),(0,W.jsx)(sn,{align:`end`,collisionPadding:12,className:`flex max-h-96 w-80 flex-col gap-3 overflow-y-auto p-3`,children:[...new Set(Object.values(zu).map(e=>e.group))].map(e=>(0,W.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,W.jsx)(`span`,{className:`text-muted-foreground text-xs`,children:e}),(0,W.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(2rem,1fr))] gap-1`,children:Object.keys(zu).filter(t=>zu[t].group===e&&!Bu.includes(t)).map(e=>(0,W.jsx)(H,{title:e,size:`icon-sm`,className:`aspect-square h-auto! w-full!`,"aria-pressed":e===n,variant:e===n?`default`:`ghost`,onClick:()=>{o(t.id,{icon:e}),i(!1)},children:(0,W.jsx)(Vu,{icon:e,className:`block aspect-square! h-auto! w-[66%]! min-w-0! shrink-0!`})},e))})]},e))})]})]})]})}var $w={connecting:`Connecting…`,online:`Online`,offline:`Offline`,unpaired:`Needs pairing`};function eT(){let e=R(e=>e.machines),t=R(e=>e.machines.find(t=>t.id===e.settingsEditedMachine)),[n,r]=(0,U.useState)(!1),[i,a]=(0,U.useState)(null),o=i===null?e:[...e].sort((e,t)=>i.indexOf(e.id)-i.indexOf(t.id));return t===void 0?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(_f,{title:`Machines`,note:`This browser connects to each one directly. The list stays in this browser`,children:(0,W.jsx)(Yw,{as:`div`,axis:`y`,className:`divide-y`,values:o.map(e=>e.id),onReorder:a,children:o.map(e=>(0,W.jsxs)(nT,{value:e.id,disabled:!1,className:`min-h-13 gap-4`,onDragEnd:()=>{i!==null&&P(i),a(null)},children:[(0,W.jsx)(Vu,{icon:e.icon,className:`text-muted-foreground size-5 shrink-0`}),(0,W.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,W.jsx)(`p`,{className:`truncate text-sm font-medium`,children:e.name}),e.addresses.map(e=>(0,W.jsx)(`p`,{className:`text-muted-foreground truncate font-mono text-xs`,children:e},e)),e.providers.filter(e=>e.state===`error`).map(e=>(0,W.jsxs)(`p`,{className:`text-destructive truncate text-xs`,title:e.error??void 0,children:[tr[e.provider],` threads: `,e.error]},e.provider))]}),(0,W.jsxs)(`span`,{className:`text-muted-foreground shrink-0 text-xs`,children:[$w[e.status],e.status===`online`&&e.via!==null&&e.via!==e.addresses[0]&&` · via ${new URL(e.via).host}`]}),(0,W.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[(0,W.jsx)(H,{size:`icon-sm`,variant:`ghost`,title:`Reconnect, trying the first address first`,onClick:()=>x(e.id),children:(0,W.jsx)(V,{icon:Ho})}),(0,W.jsx)(H,{size:`icon-sm`,variant:`ghost-muted`,title:`Open machine`,onClick:()=>ze({settingsEditedMachine:e.id}),children:(0,W.jsx)(V,{icon:Tn})})]})]},e.id))})}),(0,W.jsx)(`div`,{className:`flex gap-2`,children:(0,W.jsx)(H,{variant:`outline`,size:`sm`,onClick:()=>r(!0),children:`Add machine…`})}),n&&(0,W.jsx)(Zw,{onClose:()=>r(!1)})]}):(0,W.jsx)(tT,{machine:t})}function tT(e){let t=e.machine,[n,r]=(0,U.useState)(!1),[i,a]=(0,U.useState)(``),[s,c]=(0,U.useState)(null),[l,u]=(0,U.useState)(null),d=l??t.addresses,f=t.addresses.some(e=>bt!==null&&bt.includes(e)),p=(0,U.useRef)(null);(0,U.useEffect)(()=>{n&&p.current?.focus()},[n]);function m(e){c(null);try{return o(t.id,{addresses:[...new Set(e.map(e=>C(e).address))]}),!0}catch(e){return c(Ot(e)),!1}}async function h(e){c(null);let n=e.trim();if(n===``)return!0;try{let e=n.includes(`#`)?C(n).code:n;if(e===null)throw Error(`That link has no pairing code`);return await le(t.id,e),!0}catch(e){return c(Ot(e)),!1}}return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(_f,{title:`Machine`,children:[(0,W.jsx)(Z,{label:`Name`,children:(0,W.jsx)(vf,{value:t.label??``,placeholder:t.hostname,onCommit:e=>o(t.id,{label:e.trim()===``?null:e.trim()})},t.label)}),(0,W.jsx)(Qw,{machine:t})]}),!f&&(0,W.jsx)(_f,{title:`Pairing`,children:(0,W.jsxs)(`div`,{className:`flex min-h-13 items-center justify-between gap-4 px-4 py-2.5`,children:[t.pairedAt!==null&&t.status!==`unpaired`&&(0,W.jsx)(`span`,{className:`text-sm`,children:t.pairedAt===null?`Paired`:`Paired ${rr(t.pairedAt)}`}),(t.pairedAt===null||t.status===`unpaired`)&&(0,W.jsxs)(`form`,{className:`flex flex-1 items-center gap-3`,onSubmit:async e=>{e.preventDefault(),await h(i)&&a(``)},children:[(0,W.jsx)(Hd,{className:`flex-1 font-mono`,placeholder:`Pairing link or code`,spellCheck:!1,autoComplete:`off`,value:i,onChange:e=>a(e.target.value)}),(0,W.jsxs)(H,{type:`submit`,variant:`outline`,className:`px-4`,disabled:i.trim()===``,children:[(0,W.jsx)(V,{icon:Co}),`Pair`]})]})]})}),(0,W.jsxs)(_f,{title:`Addresses`,note:`OffSite tries them in order whenever it reconnects`,children:[(0,W.jsx)(Yw,{as:`div`,axis:`y`,className:`divide-y`,values:d,onReorder:u,children:d.map((e,t)=>(0,W.jsxs)(nT,{value:e,disabled:f,onDragEnd:()=>{l!==null&&m(l),u(null)},children:[(0,W.jsx)(vf,{className:`flex-1 font-mono`,value:e,disabled:f,onCommit:e=>m(d.map((n,r)=>r===t?e:n))}),(0,W.jsx)(H,{size:`icon-sm`,variant:`ghost`,title:`Remove address`,disabled:f||d.length===1,onClick:()=>m(d.filter((e,n)=>n!==t)),children:(0,W.jsx)(V,{icon:oo})})]},e))}),n&&(0,W.jsx)(`div`,{className:`px-4 py-2.5`,children:(0,W.jsx)(Hd,{ref:p,className:`font-mono`,placeholder:`http://192.168.1.10:47841`,spellCheck:!1,autoComplete:`off`,onBlur:e=>{let n=e.target.value.trim();(n===``||m([...t.addresses,n]))&&r(!1)},onKeyDown:e=>{e.key===`Enter`&&e.currentTarget.blur()}})}),!n&&!f&&(0,W.jsxs)(`button`,{type:`button`,className:`text-muted-foreground hover:bg-muted/50 hover:text-foreground flex w-full items-center gap-2 px-4 py-3 text-sm transition-colors`,onClick:()=>r(!0),children:[(0,W.jsx)(V,{icon:ka,className:`size-4`}),`Add address`]})]}),s!==null&&(0,W.jsx)(`p`,{className:`text-destructive px-1 text-xs break-all`,children:s}),!f&&(0,W.jsxs)(xn,{children:[(0,W.jsx)(nr,{asChild:!0,children:(0,W.jsx)(H,{variant:`outline`,className:`text-destructive`,children:`Remove machine`})}),(0,W.jsxs)(Fn,{children:[(0,W.jsxs)(mn,{children:[(0,W.jsxs)(Zn,{children:[`Remove `,t.name,`?`]}),(0,W.jsx)(On,{children:`This browser forgets the machine. The machine and its threads stay untouched.`})]}),(0,W.jsxs)(En,{children:[(0,W.jsx)(Vn,{children:`Cancel`}),(0,W.jsx)(wn,{variant:`destructive`,onClick:()=>{ze({settingsEditedMachine:null}),me(t.id)},children:`Remove machine`})]})]})]})]})}function nT(e){let t=Cw();return(0,W.jsxs)(Jw,{as:`div`,value:e.value,dragListener:!1,dragControls:t,onDragEnd:e.onDragEnd,className:z(`bg-background relative flex items-center gap-3 px-4 py-2.5`,e.className),children:[(0,W.jsx)(`span`,{className:z(`text-muted-foreground hover:text-foreground cursor-grab touch-none active:cursor-grabbing`,e.disabled&&`pointer-events-none opacity-50`),title:`Drag to reorder`,onPointerDown:e=>t.start(e),children:(0,W.jsx)(V,{icon:so,className:`size-4`})}),e.children]})}var rT=new Map([[`denied`,`Blocked in the browser's site settings`],[`insecure`,`Needs https or localhost`],[`install`,`Add OffSite to the Home Screen first`],[`unsupported`,`Not supported in this browser`]]);function iT(e){let t=e.prefs.terminal,n=t.behavior;function r(r){i({...e.prefs,terminal:{...t,behavior:{...n,...r}}})}return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(_f,{title:`Notifications`,children:[(0,W.jsx)(Z,{label:`Desktop notifications on this device`,children:(0,W.jsx)(aT,{})}),(0,W.jsx)(Z,{label:`Push terminal alerts when no OffSite page is open`,children:(0,W.jsx)(oT,{})})]}),(0,W.jsxs)(_f,{title:`Terminal bell`,children:[(0,W.jsx)(Z,{label:`Flash the screen on bell`,children:(0,W.jsx)(lf,{checked:n.bellFlash,onCheckedChange:e=>r({bellFlash:e})})}),(0,W.jsx)(Z,{label:`Play a sound on bell`,children:(0,W.jsx)(lf,{checked:n.bellSound,onCheckedChange:e=>r({bellSound:e})})})]})]})}function aT(){let[e,t]=(0,U.useState)(Yi),[n,r]=(0,U.useState)(Xi);(0,U.useEffect)(()=>{let e=Yi();if(e===`insecure`||e===`unsupported`)return;let n=new AbortController;return Qi(n.signal,()=>t(Yi())).catch(e=>console.error(`could not watch the notification permission`,e)),()=>n.abort()},[]);async function i(e){await Zi(e),r(e),t(Yi())}return(0,W.jsxs)(`div`,{className:`flex items-center gap-3`,children:[rT.has(e)&&(0,W.jsx)(`span`,{className:`text-muted-foreground text-xs`,children:rT.get(e)}),(0,W.jsx)(lf,{checked:e===`granted`&&n,disabled:e!==`granted`&&e!=="default",onCheckedChange:e=>void i(e)})]})}function oT(){let[e,t]=(0,U.useState)(aa),[n,r]=(0,U.useState)(!1),[i,a]=(0,U.useState)(()=>aa()===`supported`),[o,s]=(0,U.useState)(null);(0,U.useEffect)(()=>{if(aa()!==`supported`)return;let e=!0;async function t(){try{let t=await sa();e&&r(t)}catch(e){console.error(`could not read the push subscription`,e)}e&&a(!1)}return t(),()=>{e=!1}},[]);async function c(e){a(!0),s(null);try{e?r(await ca()):(await la(),r(!1))}catch(e){console.error(`could not change push notifications`,e),s(Ot(e))}t(aa()),a(!1)}return(0,W.jsxs)(`div`,{className:`flex items-center gap-3`,children:[o!==null&&(0,W.jsxs)(`span`,{className:`text-muted-foreground text-xs`,children:[`Could not update: `,o]}),rT.has(e)&&(0,W.jsx)(`span`,{className:`text-muted-foreground text-xs`,children:rT.get(e)}),(0,W.jsx)(lf,{checked:e===`supported`&&n,disabled:e!==`supported`||i,onCheckedChange:e=>void c(e)})]})}var sT={five_hour:`5h`,seven_day:`Week`,seven_day_opus:`Week (Opus)`,seven_day_sonnet:`Week (Sonnet)`};function cT(e){return sT[e.window]??e.window}function lT(e){let t=e.account,[n,r]=(0,U.useState)(null);async function i(n){r(null);try{await N(e.machine,`accounts.update`,{id:t.id,name:t.name,color:t.color,configDir:t.configDir,enabled:t.enabled,...n})}catch(e){r(Ot(e))}}async function a(){r(null);try{await N(e.machine,`accounts.remove`,{id:t.id}),ze({settingsAccount:null})}catch(e){r(Ot(e))}}return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(_f,{title:`Account`,children:[(0,W.jsx)(Z,{label:`Name`,children:(0,W.jsx)(vf,{value:t.name,valid:e=>e.trim()!==``,onCommit:e=>void i({name:e})},t.name)}),(0,W.jsx)(Z,{label:`Color`,children:(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[t.color!==null&&(0,W.jsx)(`span`,{className:`size-5 shrink-0 rounded-full`,style:{backgroundColor:t.color}}),(0,W.jsx)(vf,{className:`w-28 font-mono`,value:t.color??``,placeholder:`#3b82f6`,valid:e=>e===``||/^#[0-9a-f]{6}$/i.test(e),onCommit:e=>void i({color:e===``?null:e})},t.color??``)]})}),(0,W.jsx)(Z,{label:`Config directory`,children:(0,W.jsx)(vf,{className:`w-72 font-mono`,value:t.configDir??``,placeholder:t.provider===`claude`?`~/.claude or empty for default`:`~/.codex or empty for default`,onCommit:e=>void i({configDir:e})},t.configDir??``)})]}),n!==null&&(0,W.jsx)(`p`,{className:`text-destructive px-1 text-xs`,children:n}),(0,W.jsxs)(xn,{children:[(0,W.jsx)(nr,{asChild:!0,children:(0,W.jsx)(H,{variant:`outline`,className:`text-destructive`,children:`Remove account`})}),(0,W.jsxs)(Fn,{children:[(0,W.jsxs)(mn,{children:[(0,W.jsxs)(Zn,{children:[`Remove `,t.name,`?`]}),(0,W.jsx)(On,{children:`OffSite stops using this account. Its config directory and sessions stay untouched.`})]}),(0,W.jsxs)(En,{children:[(0,W.jsx)(Vn,{children:`Cancel`}),(0,W.jsx)(wn,{variant:`destructive`,onClick:()=>void a(),children:`Remove account`})]})]})]})]})}function uT(e){let[t,n]=(0,U.useState)(``),[r,i]=(0,U.useState)(``),[a,o]=(0,U.useState)(!1),[s,c]=(0,U.useState)(null);async function l(){o(!0),c(null);try{await N(e.machine,`accounts.add`,{provider:e.provider,name:t,configDir:r}),ze({settingsAccount:null})}catch(e){c(Ot(e)),o(!1)}}return(0,W.jsxs)(`form`,{className:`space-y-5`,onSubmit:e=>{e.preventDefault(),l()},children:[(0,W.jsxs)(_f,{title:`Account`,children:[(0,W.jsx)(Z,{label:`Name`,children:(0,W.jsx)(Hd,{className:`w-56`,value:t,onChange:e=>n(e.target.value),placeholder:`Work`})}),(0,W.jsx)(Z,{label:`Config directory`,children:(0,W.jsx)(Hd,{className:`w-72 font-mono`,value:r,onChange:e=>i(e.target.value),placeholder:e.provider===`claude`?`~/.claude or empty for default`:`~/.codex or empty for default`})})]}),s!==null&&(0,W.jsx)(`p`,{className:`text-destructive px-1 text-xs`,children:s}),(0,W.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,W.jsx)(H,{type:`button`,variant:`ghost`,onClick:()=>ze({settingsAccount:null}),children:`Cancel`}),(0,W.jsx)(H,{type:`submit`,disabled:a||t.trim()===``,children:`Add account`})]})]})}function dT(e){let t=e.config,n=t.enabledProviders[e.provider],r=e.provider===`claude`?e.claudeAccounts:e.provider===`codex`?e.codexAccounts:[],i=r.find(e=>e.valid),a=t.claudeBaseDir[e.platform]??e.defaultClaudeBaseDir;if(e.selected===`new`){if(e.provider===`opencode`)throw Error(`OpenCode accounts cannot be added`);return(0,W.jsx)(uT,{machine:e.machine,provider:e.provider})}if(e.selected!==null){let t=r.find(t=>t.id===e.selected);return t===void 0?(0,W.jsx)(`p`,{className:`text-muted-foreground text-sm`,children:`This account no longer exists.`}):(0,W.jsx)(lT,{machine:e.machine,account:t})}return(0,W.jsxs)(W.Fragment,{children:[e.provider===`claude`&&(0,W.jsx)(`div`,{className:`divide-y overflow-hidden rounded-xl border`,children:(0,W.jsx)(Z,{label:`Base directory`,children:(0,W.jsx)(vf,{className:`w-72 font-mono`,value:a,valid:e=>e.trim()!==``,onCommit:n=>ut(e.machine,{...t,claudeBaseDir:{...t.claudeBaseDir,[e.platform]:n}})},a)})}),(0,W.jsxs)(`div`,{className:z(`space-y-5 transition-opacity`,!n&&`opacity-50`),children:[e.provider!==`opencode`&&(0,W.jsx)(_f,{title:`Accounts`,children:(0,W.jsx)(pT,{machine:e.machine,accounts:r})}),n&&e.provider===`opencode`&&e.openCode.available&&(0,W.jsx)(fT,{machine:e.machine,config:t,provider:e.provider,accountId:null}),n&&e.provider!==`opencode`&&i!==void 0&&(0,W.jsx)(fT,{machine:e.machine,config:t,provider:e.provider,accountId:i.id})]})]})}function fT(e){let[t,n]=(0,U.useState)(null),[r,i]=(0,U.useState)(null),a=e.config.models[e.provider],o=t===null?null:t.models,s=e.config.newThreads.models[e.provider]??(t===null?null:t.defaultModel);(0,U.useEffect)(()=>{let t=!0;return n(null),i(null),N(e.machine,`capabilities`,{provider:e.provider,accountId:e.accountId,projectId:null}).then(e=>{t&&n(e)},e=>{t&&i(Ot(e))}),()=>{t=!1}},[e.machine,e.provider,e.accountId]);function c(t,n){ut(e.machine,{...e.config,models:{...e.config.models,[e.provider]:{...a,[t]:n}}})}return(0,W.jsxs)(_f,{title:`Models`,children:[o!==null&&(0,W.jsx)(Z,{label:`Default model`,children:(0,W.jsxs)(Ud,{value:s??void 0,onValueChange:t=>void ut(e.machine,{...e.config,newThreads:{...e.config.newThreads,models:{...e.config.newThreads.models,[e.provider]:t}}}),children:[(0,W.jsx)(Gd,{className:`w-56`,children:(0,W.jsx)(Wd,{placeholder:`Choose a model`})}),(0,W.jsx)(Kd,{children:o.filter(e=>!(a[e.value]?.hidden??e.deprecated)||e.value===s).map(e=>(0,W.jsx)(X,{value:e.value,children:e.name},e.value))})]})}),r!==null&&(0,W.jsx)(`p`,{className:`text-destructive px-4 py-3 text-xs`,children:r}),r===null&&o===null&&(0,W.jsx)(`p`,{className:`text-muted-foreground px-4 py-3 text-xs`,children:`Loading…`}),(o??[]).map(t=>{let n=a[t.value]??{hidden:t.deprecated,effort:t.effort};return(0,W.jsxs)(`div`,{className:`flex min-h-11 items-center gap-3 px-4 py-1.5`,children:[(0,W.jsxs)(`div`,{className:z(`min-w-0 flex-1 truncate text-sm`,n.hidden&&`text-muted-foreground`),children:[t.name,e.provider===`opencode`&&(0,W.jsx)(`span`,{className:`text-muted-foreground ml-2 text-xs`,children:t.description})]}),t.efforts.length>0&&(0,W.jsxs)(Ud,{value:n.effort??t.effort??void 0,onValueChange:e=>c(t.value,{...n,effort:e}),children:[(0,W.jsx)(Gd,{size:`sm`,className:`w-28`,children:(0,W.jsx)(Wd,{placeholder:`Effort`})}),(0,W.jsx)(Kd,{children:t.efforts.map(e=>(0,W.jsx)(X,{value:e,children:e.charAt(0).toUpperCase()+e.slice(1)},e))})]}),(0,W.jsx)(lf,{size:`sm`,checked:!n.hidden,onCheckedChange:e=>c(t.value,{...n,hidden:!e}),"aria-label":`Show ${t.name}`})]},t.value)})]})}function pT(e){let[t,n]=(0,U.useState)(!1),[r,i]=(0,U.useState)(null);async function a(e){n(!0),i(null);try{await e()}catch(e){i(Ot(e))}finally{n(!1)}}return(0,W.jsxs)(W.Fragment,{children:[e.accounts.map(n=>(0,W.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3`,children:[(0,W.jsxs)(`div`,{className:z(`min-w-0 flex-1`,!n.enabled&&`opacity-50`),children:[(0,W.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,W.jsx)(`span`,{className:z(`size-2 shrink-0 rounded-full`,!n.enabled&&`bg-muted-foreground/40`,n.enabled&&n.error!==null&&`bg-destructive`,n.enabled&&n.error===null&&!n.linked&&`bg-warning`,n.enabled&&n.error===null&&n.linked&&`bg-success`)}),(0,W.jsx)(`span`,{className:`truncate text-sm font-medium`,children:n.name}),n.plan!==null&&(0,W.jsx)(`span`,{className:`text-muted-foreground shrink-0 text-xs`,children:n.plan})]}),n.error!==null&&(0,W.jsx)(`p`,{className:`text-destructive mt-1 truncate pl-4 text-xs`,children:n.error}),n.error===null&&!n.linked&&(0,W.jsx)(`p`,{className:`text-warning mt-1 truncate pl-4 text-xs`,children:`Not linked to shared threads · hidden in the composer`}),n.error===null&&n.linked&&n.limits.length>0&&(0,W.jsx)(`div`,{className:`mt-1.5 flex flex-wrap gap-x-5 gap-y-1.5 pl-4`,children:n.limits.map(e=>(0,W.jsx)(mT,{limit:e},e.window))})]}),(0,W.jsx)(lf,{size:`sm`,checked:n.enabled,disabled:t,onCheckedChange:t=>void a(()=>N(e.machine,`accounts.update`,{id:n.id,name:n.name,color:n.color,configDir:n.configDir,enabled:t})),"aria-label":`Enable ${n.name}`}),(0,W.jsx)(H,{size:`icon-sm`,variant:`ghost-muted`,title:`Open account`,onClick:()=>ze({settingsAccount:n.id}),children:(0,W.jsx)(V,{icon:Tn})})]},n.id)),(0,W.jsxs)(`button`,{type:`button`,className:`text-muted-foreground hover:bg-muted/50 hover:text-foreground flex w-full items-center gap-2 px-4 py-3 text-sm transition-colors`,onClick:()=>ze({settingsAccount:`new`}),children:[(0,W.jsx)(V,{icon:ka,className:`size-4`}),`Add account`]}),r!==null&&(0,W.jsx)(`p`,{className:`text-destructive px-4 py-3 text-xs`,children:r})]})}function mT(e){let t=e.limit,n=t.rejected?100:t.utilization===null?null:Math.min(100,Math.round(t.utilization*100));return n===null?null:(0,W.jsx)(vr,{label:t.resetsAt===null?`Reset time unknown`:`Resets ${rr(t.resetsAt*1e3)}`,children:(0,W.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs`,children:[(0,W.jsx)(`span`,{className:`text-muted-foreground`,children:cT(t)}),(0,W.jsx)(`div`,{className:`bg-foreground/10 h-1 w-16 overflow-hidden rounded-full`,children:(0,W.jsx)(`div`,{className:z(`h-full rounded-full`,t.rejected&&`bg-destructive`,!t.rejected&&n>=80&&`bg-warning`,!t.rejected&&n<80&&`bg-foreground/50`),style:{width:`${n}%`}})}),(0,W.jsxs)(`span`,{className:z(`tabular-nums`,t.rejected&&`text-destructive`,!t.rejected&&`text-muted-foreground`),children:[n,`%`]})]})})}var hT=wt?`⌘`:`Ctrl+Shift`,gT=[[`Enter`,`Send, or queue or steer while the agent works`],[`${Dt}+Enter`,`Send the other way while the agent works`],[`Shift+Enter`,`New line`],[`↑`,`Recall your last message`],[`Esc`,`Stop the agent`],[`/`,`Slash commands`],[`@`,`Mention a file`],[`${Dt}+K`,`Search sessions and actions`],[`${Dt}+N or ${Dt}+T`,`New thread`],[wt?"⌘+` or Ctrl+`":"Ctrl+`",`Toggle the terminal`],[`${Dt}+B or ${Dt}+Shift+J`,`Toggle the sidebar`],[`${Dt}+J or ${Dt}+Shift+B`,`Toggle the right panel`],[`${hT}+T`,`New terminal tab, in the terminal`],[`${hT}+W`,`Close the terminal tab`],[`${hT}+F`,`Find in the terminal`],[`Ctrl+Tab`,`Next terminal tab`],[`Ctrl+Shift+Tab`,`Previous terminal tab`]];function _T(){return(0,W.jsx)(_f,{title:`Keyboard shortcuts`,children:gT.map(([e,t])=>(0,W.jsx)(Z,{label:t,children:(0,W.jsx)(`kbd`,{className:`bg-muted text-muted-foreground rounded px-1.5 py-0.5 font-sans text-xs`,children:e})},e))})}var vT=1048576;function yT(e){window.isSecureContext?navigator.clipboard.writeText(e).catch(e=>{console.warn(`could not copy to the clipboard`,e),Ai(`Could not copy to the clipboard`)}):console.warn(`copy from the terminal needs https or localhost`)}async function bT(e){if(!window.isSecureContext){console.warn(`programs can read the clipboard only over https or localhost`),Ai(`Programs can read the clipboard only over https or localhost`);return}let t;try{t=await navigator.clipboard.readText()}catch(e){console.warn(`could not read the clipboard`,e),Ai(`Could not read the clipboard`);return}new TextEncoder().encode(t).length>vT?(console.warn(`the clipboard is over 1 MiB, not replying`),Ai(`The clipboard is too large to share (over 1 MiB)`)):e(t)}var xT={macos:{label:`Ctrl+V`,ctrl:!0,alt:!1,data:``},linux:{label:`Ctrl+V`,ctrl:!0,alt:!1,data:``},windows:{label:`Alt+V`,ctrl:!1,alt:!0,data:`\x1Bv`}};function ST(e,t){let n=xT[t];return e.key.toLowerCase()===`v`&&e.ctrlKey===n.ctrl&&e.altKey===n.alt&&!e.shiftKey&&!e.metaKey}async function CT(e,t){let n=[];for(let e of await navigator.clipboard.read()){let t=e.types.find(e=>e.startsWith(`image/`));t&&n.push(await e.getType(t))}return n.length===0?(Ai(`No image in the clipboard`),!1):(await wT(e,t,n),!0)}async function wT(e,t,n){let r=[];for(let t of n){let n=await N(e,`terminal.paste`,{type:t.type,data:await Uu(t)});r.push(/\s/.test(n)?`"${n}"`:n)}t.paste(r.join(` `))}function TT(e){console.error(`could not paste image`,e),Ai(`Could not paste the image`)}function ET(e){let t=e.prefs.terminal,[n,r]=(0,U.useState)(!ff.some(e=>e.family===t.font.family));function a(t){i({...e.prefs,terminal:t})}function o(e,n){a({...t,[e]:{...t[e],...n}})}return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(_f,{title:`Font`,children:[(0,W.jsx)(Z,{label:`Family`,children:(0,W.jsxs)(Ud,{value:n?`custom`:t.font.family,onValueChange:e=>{r(e===`custom`),e!==`custom`&&o(`font`,{family:e})},children:[(0,W.jsx)(Gd,{className:`w-56`,children:(0,W.jsx)(Wd,{})}),(0,W.jsxs)(Kd,{children:[ff.map(e=>(0,W.jsx)(X,{value:e.family,children:e.label},e.family)),(0,W.jsx)(X,{value:`custom`,children:`Custom`})]})]})}),n&&(0,W.jsx)(Z,{label:`Custom family`,children:(0,W.jsx)(vf,{placeholder:`Installed font name`,value:t.font.family,onCommit:e=>o(`font`,{family:e})})}),(0,W.jsx)(Z,{label:`Size`,children:(0,W.jsx)(yf,{value:t.font.size,step:.5,onCommit:e=>o(`font`,{size:e})})}),(0,W.jsx)(Z,{label:`Line height`,children:(0,W.jsx)(yf,{value:t.font.lineHeight,step:.05,onCommit:e=>o(`font`,{lineHeight:e})})}),(0,W.jsx)(Z,{label:`Ligatures`,children:(0,W.jsx)(lf,{checked:t.font.ligatures,onCheckedChange:e=>o(`font`,{ligatures:e})})}),(0,W.jsx)(Z,{label:`Bold text in bright colors`,children:(0,W.jsx)(lf,{checked:t.boldIsBright,onCheckedChange:e=>a({...t,boldIsBright:e})})})]}),(0,W.jsxs)(_f,{title:`Cursor`,children:[(0,W.jsx)(Z,{label:`Style`,children:(0,W.jsxs)(Ud,{value:t.cursor.style,onValueChange:e=>o(`cursor`,{style:e}),children:[(0,W.jsx)(Gd,{className:`w-56`,children:(0,W.jsx)(Wd,{})}),(0,W.jsxs)(Kd,{children:[(0,W.jsx)(X,{value:`block`,children:`Block`}),(0,W.jsx)(X,{value:`bar`,children:`Bar`}),(0,W.jsx)(X,{value:`underline`,children:`Underline`})]})]})}),(0,W.jsx)(Z,{label:`Blink`,children:(0,W.jsx)(lf,{checked:t.cursor.blink,onCheckedChange:e=>o(`cursor`,{blink:e})})})]}),(0,W.jsx)(DT,{behavior:t.behavior,onChange:e=>o(`behavior`,e)}),(0,W.jsx)(OT,{behavior:t.behavior,onChange:e=>o(`behavior`,e)}),(0,W.jsx)(kT,{behavior:t.behavior,onChange:e=>o(`behavior`,e)}),(0,W.jsxs)(_f,{title:`Layout`,children:[[`top`,`right`,`bottom`,`left`].map(e=>(0,W.jsx)(Z,{label:`Padding ${e}`,children:(0,W.jsx)(yf,{value:t.padding[e],onCommit:t=>o(`padding`,{[e]:t})})},e)),(0,W.jsx)(Z,{label:`Scrollback lines`,children:(0,W.jsx)(yf,{value:t.scrollback,step:1e3,onCommit:e=>a({...t,scrollback:e})})})]})]})}function DT(e){return(0,W.jsxs)(_f,{title:`Behavior`,children:[(0,W.jsx)(Z,{label:`Modernize Shift+Enter`,children:(0,W.jsx)(lf,{checked:e.behavior.modernizeShiftEnter,onCheckedChange:t=>e.onChange({modernizeShiftEnter:t})})}),(0,W.jsx)(Z,{label:`${xT.linux.label} (${xT.windows.label} on Windows machines) pastes images from the browser clipboard`,children:(0,W.jsx)(lf,{checked:e.behavior.pasteBrowserImages,onCheckedChange:t=>e.onChange({pasteBrowserImages:t})})}),(0,W.jsx)(Z,{label:`Capture browser shortcuts`,children:(0,W.jsx)(lf,{checked:e.behavior.captureShortcuts,onCheckedChange:t=>e.onChange({captureShortcuts:t})})}),(0,W.jsx)(Z,{label:`Click moves the cursor in the command line`,children:(0,W.jsx)(lf,{checked:e.behavior.clickToMoveCursor,onCheckedChange:t=>e.onChange({clickToMoveCursor:t})})}),(0,W.jsx)(Z,{label:`Ask before closing a tab that is running a program`,children:(0,W.jsx)(lf,{checked:e.behavior.confirmCloseBusyTab,onCheckedChange:t=>e.onChange({confirmCloseBusyTab:t})})})]})}function OT(e){return wt?(0,W.jsx)(_f,{title:`Mac keys`,note:`Meta keeps that Option key from typing @, | and other symbols. Safari and Firefox use US key positions`,children:(0,W.jsx)(Z,{label:`Use Option as Meta`,children:(0,W.jsxs)(Ud,{value:e.behavior.optionAsMeta,onValueChange:t=>e.onChange({optionAsMeta:t}),children:[(0,W.jsx)(Gd,{className:`w-56`,children:(0,W.jsx)(Wd,{})}),(0,W.jsxs)(Kd,{children:[(0,W.jsx)(X,{value:`off`,children:`Off`}),(0,W.jsx)(X,{value:`left`,children:`Left Option`}),(0,W.jsx)(X,{value:`right`,children:`Right Option`}),(0,W.jsx)(X,{value:`both`,children:`Both Options`})]})]})})}):null}function kT(e){return St?(0,W.jsx)(_f,{title:`Windows keys`,note:`Ctrl+C sends an interrupt when nothing is selected. Ctrl+Shift+C and Ctrl+Shift+V always copy and paste`,children:(0,W.jsx)(Z,{label:`Ctrl+C copies the selection and Ctrl+V pastes`,children:(0,W.jsx)(lf,{checked:e.behavior.windowsCopyPaste,onCheckedChange:t=>e.onChange({windowsCopyPaste:t})})})}):null}var AT=[`General`,`Editor`,`Terminal`,`Notifications`,`Shortcuts`,`Machines`],jT=[`Machine`,`Claude`,`Codex`,`OpenCode`];function MT(){let e=R(e=>e.machines),t=R(e=>e.settingsMachine===null?null:I(e,e.settingsMachine)),n=R(e=>e.settingsPage),r=LT(n),i=R(e=>r===null?null:e.settingsAccount),a=R(e=>n===`Machines`?e.machines.find(t=>t.id===e.settingsEditedMachine)??null:null);return{machines:e,machine:t,config:t===null?null:t.config,system:t===null?null:t.system,page:n,provider:r,account:i,editedMachine:a,subpage:i!==null||a!==null,subpageTitle:i===`new`?`New account`:i===null?a?.name:[...t?.claudeAccounts??[],...t?.codexAccounts??[]].find(e=>e.id===i)?.name}}function NT(){let e=R(e=>e.settingsOpen),t=MT(),n=t.page,r=t.machine;function i(e){return(0,W.jsx)(`button`,{className:z(`text-muted-foreground hover:bg-accent hover:text-foreground flex h-9 flex-none items-center rounded-md px-2 text-sm transition-colors`,e===n&&`bg-accent text-foreground`),onClick:()=>u(e),children:(0,W.jsx)(PT,{page:e})},e)}return(0,W.jsx)(Or,{open:e,onOpenChange:d,children:(0,W.jsxs)(xr,{showCloseButton:!1,"aria-describedby":void 0,className:`flex h-[min(44rem,calc(100dvh-2rem))] flex-col gap-0 overflow-hidden p-0 sm:max-w-4xl sm:flex-row`,children:[(0,W.jsxs)(`nav`,{className:`flex flex-none gap-1 overflow-x-auto border-b p-3 sm:w-48 sm:flex-col sm:border-r sm:border-b-0`,children:[(0,W.jsx)(Tr,{className:`hidden px-2 pt-1 pb-3 text-base font-semibold sm:block`,children:`Settings`}),AT.map(i),(0,W.jsxs)(`div`,{className:`flex flex-none items-center gap-1 sm:mt-6 sm:flex-col sm:items-stretch`,children:[r!==null&&t.machines.length>1&&(0,W.jsxs)(Ud,{value:r.id,onValueChange:e=>ze({settingsMachine:e,settingsAccount:null}),children:[(0,W.jsx)(Gd,{className:`mb-1 w-40 sm:w-full`,children:(0,W.jsx)(Wd,{})}),(0,W.jsx)(Kd,{children:t.machines.map(e=>(0,W.jsxs)(X,{value:e.id,children:[(0,W.jsx)(Vu,{icon:e.icon}),e.name]},e.id))})]}),r!==null&&t.machines.length===1&&(0,W.jsxs)(`p`,{className:`text-muted-foreground flex h-9 items-center gap-1.5 px-2 text-xs font-medium [&_svg]:size-4`,children:[(0,W.jsx)(Vu,{icon:r.icon}),(0,W.jsx)(`span`,{className:`truncate`,children:r.name})]}),jT.map(i)]})]}),(0,W.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-6 pt-4 pb-7`,children:[(0,W.jsxs)(`div`,{className:`mb-5 flex h-9 items-center`,children:[t.subpage&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`button`,{className:`text-muted-foreground hover:text-foreground text-xl font-semibold tracking-tight transition-colors`,onClick:()=>ze({settingsAccount:null,settingsEditedMachine:null}),children:n}),(0,W.jsx)(V,{icon:Tn,className:`text-muted-foreground mx-1.5 size-5`}),(0,W.jsx)(`h2`,{className:`truncate text-xl font-semibold tracking-tight`,children:t.subpageTitle})]}),!t.subpage&&(0,W.jsx)(`h2`,{className:`text-xl font-semibold tracking-tight`,children:n===`Machine`?`General`:n}),(0,W.jsx)(FT,{view:t,className:`ml-3`}),(0,W.jsx)(wr,{asChild:!0,children:(0,W.jsx)(H,{variant:`ghost`,size:`icon`,className:`-mr-2 ml-auto`,"aria-label":`Close settings`,children:(0,W.jsx)(V,{icon:Ja})})})]}),(0,W.jsx)(IT,{view:t})]})]})})}function PT(e){let t=LT(e.page);return(0,W.jsxs)(W.Fragment,{children:[t!==null&&(0,W.jsx)(`span`,{className:`mr-2.5 flex size-4 items-center justify-center`,children:(0,W.jsx)(Vs,{provider:t,className:z(t===`claude`&&`size-4`,t===`codex`&&`size-[19px] shrink-0`,t===`opencode`&&`h-3.5`)})}),e.page===`Machine`?`General`:e.page]})}function FT(e){let t=e.view.machine,n=e.view.config,r=e.view.provider;return r===null||e.view.account!==null||t===null||n===null?null:(0,W.jsx)(lf,{className:e.className,checked:n.enabledProviders[r],onCheckedChange:e=>void ut(t.id,{...n,enabledProviders:{...n.enabledProviders,[r]:e}}),"aria-label":`Enable ${e.view.page}`})}function IT(e){let t=R(e=>e.prefs),n=e.view.page,r=e.view.machine,a=e.view.config,o=e.view.system,s=jT.includes(n),[c,l]=(0,U.useState)(null),[u,d]=(0,U.useState)(0);return(0,W.jsxs)(W.Fragment,{children:[s&&r!==null&&r.configError!==null&&(0,W.jsxs)(`p`,{className:`text-destructive mb-5 text-sm whitespace-pre-wrap`,children:[`Not saved: `,r.configError]}),(0,W.jsxs)(`div`,{className:`w-full space-y-5`,children:[n===`General`&&(0,W.jsx)(xf,{prefs:t,onRestore:()=>l(`browser`)}),n===`Machine`&&r!==null&&a!==null&&o!==null&&(0,W.jsx)(Lf,{machine:r.id,config:a,platform:o.platform,defaultShell:o.defaultShell,claudeAccounts:r.claudeAccounts,codexAccounts:r.codexAccounts,openCode:r.openCode,onRestore:()=>l(`machine`)}),s&&r===null&&(0,W.jsx)(`p`,{className:`text-muted-foreground text-sm`,children:`Add a machine to see its settings.`}),s&&r!==null&&(a===null||o===null)&&(0,W.jsxs)(`p`,{className:`text-muted-foreground text-sm`,children:[r.name,` is not connected. Its settings show up once it is.`]}),n===`Editor`&&(0,W.jsx)(bf,{prefs:t}),n===`Terminal`&&(0,W.jsx)(ET,{prefs:t}),n===`Notifications`&&(0,W.jsx)(iT,{prefs:t}),e.view.provider!==null&&r!==null&&a!==null&&o!==null&&(0,W.jsx)(dT,{machine:r.id,config:a,platform:o.platform,defaultClaudeBaseDir:o.defaultClaudeBaseDir,provider:e.view.provider,claudeAccounts:r.claudeAccounts,codexAccounts:r.codexAccounts,openCode:r.openCode,selected:e.view.account},e.view.provider),n===`Machines`&&(0,W.jsx)(eT,{}),n===`Shortcuts`&&(0,W.jsx)(_T,{})]},u),(0,W.jsx)(xn,{open:c!==null,onOpenChange:e=>{e||l(null)},children:(0,W.jsxs)(Fn,{children:[(0,W.jsxs)(mn,{children:[(0,W.jsx)(Zn,{children:c===`browser`?`Restore browser defaults?`:`Restore machine defaults?`}),(0,W.jsx)(On,{children:c===`browser`?`All settings of this browser go back to their defaults.`:`All settings of ${r?.name} go back to their defaults.`})]}),(0,W.jsxs)(En,{children:[(0,W.jsx)(Vn,{children:`Cancel`}),(0,W.jsx)(wn,{variant:`destructive`,onClick:()=>{if(d(u+1),c===`browser`)i(p);else{if(r===null||a===null||o===null)throw Error(`Restoring machine defaults needs a connected machine`);ut(r.id,{...o.defaults,claudeAccounts:a.claudeAccounts,codexAccounts:a.codexAccounts})}},children:`Restore defaults`})]})]})})]})}function LT(e){return e===`Claude`?`claude`:e===`Codex`?`codex`:e===`OpenCode`?`opencode`:null}function RT(){let e=R(e=>e.settingsOpen),t=R(e=>e.settingsListing),n=MT(),r=n.machine;function i(){t?d(!1):n.subpage?ze({settingsAccount:null,settingsEditedMachine:null}):ze({settingsListing:!0})}function a(e){return(0,W.jsxs)(`button`,{className:`active:bg-accent flex min-h-12 w-full items-center px-4 text-left text-sm font-medium`,onClick:()=>u(e),children:[(0,W.jsx)(PT,{page:e}),(0,W.jsx)(V,{icon:Tn,className:`text-muted-foreground ml-auto size-4`})]},e)}return(0,W.jsx)(Dr,{open:e,onOpenChange:d,children:(0,W.jsx)(jr,{children:(0,W.jsxs)(Cr,{"aria-describedby":void 0,className:`bg-background text-foreground data-open:animate-in data-open:slide-in-from-right fixed inset-0 z-50 flex flex-col pt-[env(safe-area-inset-top)] pb-[env(safe-area-inset-bottom)] text-sm duration-200 outline-none [--workspace-topbar-height:44px] motion-reduce:animate-none`,children:[(0,W.jsxs)(`header`,{className:`flex h-(--workspace-topbar-height) shrink-0 items-center gap-1.5 pr-3 pl-1`,children:[(0,W.jsx)(H,{variant:`ghost`,size:`icon`,"aria-label":`Back`,onClick:i,children:(0,W.jsx)(V,{icon:Ba,className:`text-foreground size-5`,strokeWidth:2})}),(0,W.jsxs)(Nr,{className:`min-w-0 flex-1 truncate font-medium`,children:[t&&`Settings`,!t&&n.subpage&&n.subpageTitle,!t&&!n.subpage&&n.page]}),!t&&(0,W.jsx)(FT,{view:n,className:`shrink-0`})]}),(0,W.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-4 pt-2 pb-6`,children:[t&&(0,W.jsxs)(`div`,{className:`space-y-5`,children:[(0,W.jsx)(_f,{title:`This browser`,children:AT.map(a)}),(0,W.jsxs)(_f,{title:`Machine`,children:[r!==null&&(0,W.jsxs)(Z,{label:`Machine`,children:[n.machines.length>1&&(0,W.jsxs)(Ud,{value:r.id,onValueChange:e=>ze({settingsMachine:e,settingsAccount:null}),children:[(0,W.jsx)(Gd,{className:`w-40`,children:(0,W.jsx)(Wd,{})}),(0,W.jsx)(Kd,{children:n.machines.map(e=>(0,W.jsxs)(X,{value:e.id,children:[(0,W.jsx)(Vu,{icon:e.icon}),e.name]},e.id))})]}),n.machines.length===1&&(0,W.jsxs)(`span`,{className:`text-muted-foreground flex items-center gap-1.5 text-sm [&_svg]:size-4`,children:[(0,W.jsx)(Vu,{icon:r.icon}),r.name]})]}),jT.map(a)]})]}),!t&&(0,W.jsx)(IT,{view:n})]})]})})})}function zT(){return(0,W.jsx)(`div`,{className:`grid flex-1 place-items-center p-6`,children:(0,W.jsxs)(`div`,{className:`w-full max-w-md`,children:[(0,W.jsx)(`h1`,{className:`text-foreground text-center text-2xl font-normal tracking-tight sm:text-3xl`,children:`Connect a machine`}),(0,W.jsx)(`p`,{className:`text-muted-foreground mt-2 text-center text-sm`,children:`Run this on the computer you want to use, then open the pairing link it prints.`}),(0,W.jsx)(`pre`,{className:`bg-muted text-foreground mt-5 rounded-lg px-4 py-3 font-mono text-sm select-all`,children:`npx offsite serve`}),(0,W.jsx)(`p`,{className:`text-muted-foreground mt-8 mb-3 text-sm`,children:`Or connect it here.`}),(0,W.jsx)(Xw,{actions:e=>(0,W.jsx)(H,{type:`submit`,className:`mt-4`,disabled:!e,children:`Connect`})})]})})}var BT=.5,VT=.8,HT=.6,UT=.45,WT=.3,GT=.25,KT=.25,qT=4,JT=new Set([`a`,`an`,`and`,`for`,`in`,`of`,`on`,`the`,`to`,`with`]),YT=/[\p{L}\p{N}]/u,XT=/\p{Ll}/u,ZT=/\p{Lu}/u,QT=/\p{N}/u,$T=/\p{L}/u;function eE(e){return e.replace(/[\u0080-]/g,e=>{let t=e.normalize(`NFKD`).replace(/\p{M}/gu,``).toLowerCase();return t.length===1?t:e}).toLowerCase()}function tE(e){return eE(e).replace(/^["'`]+|["'`]+$/g,``).split(/\s+/).filter(Boolean)}function nE(e){return tE(e).some(e=>e.length>=3)}function rE(e,t){let n=e[t],r=e[t-1]??``,i=e[t+1]??``;return YT.test(n)&&(r===``||!YT.test(r)||XT.test(r)&&ZT.test(n)||ZT.test(r)&&ZT.test(n)&&XT.test(i)||QT.test(r)!==QT.test(n))}function iE(e,t){return t>=e.length||!YT.test(e[t])||rE(e,t)}function aE(e,t){let n=t+1;for(;n<e.length&&YT.test(e[n])&&!rE(e,n);)n+=1;return n}function oE(e){return Array.from({length:e.length},(e,t)=>t).filter(t=>rE(e,t))}function sE(e,t,n){let r=0;for(;r<e.length&&r<t.length&&e[r]===t[r];)r+=1;let i=e.slice(r),a=t.slice(r),o=i.length>1&&i[0]===a[1]&&i[1]===a[0]&&i.slice(2)===a.slice(2);return n?o:o||i===a||i.slice(1)===a.slice(1)||i.slice(1)===a||i===a.slice(1)}function cE(e,t,n){for(let r of oE(e)){if(t[r]!==n[0])continue;let i=[],a=r,o=n;for(;o!==``&&a<t.length;){let n=aE(e,a);if(o.length<=n-a&&t.startsWith(o,a))i.push({start:a,end:a+o.length}),o=``;else if(o.startsWith(t.slice(a,n)))for(i.push({start:a,end:n}),o=o.slice(n-a),a=n;a<t.length&&!rE(e,a);)a+=1;else break}if(o===``&&i.length>1)return{score:HT,start:r,end:i[i.length-1].end,pieces:i}}return null}function lE(e,t,n){if(n.length<3||!$T.test(n))return null;let r=n.length<=qT;for(let i of oE(e)){if(!(t[i]===n[0]||!r&&t[i]===n[1]&&t[i+1]===n[0]))continue;let e=i+1;for(;e<t.length&&YT.test(t[e]);)e+=1;let a=r?[n.length,n.length+1]:[n.length,n.length-1,n.length+1];for(let o of a)if(!(o>e-i)&&sE(n,t.slice(i,i+o),r&&o===n.length)){let e={start:i,end:i+o};return{score:UT,...e,pieces:[e]}}}return null}function uE(e,t,n){let r=e.source,i=e.folded,a=null;for(let n=i.indexOf(t);n!==-1;n=i.indexOf(t,n+1)){let i={start:n,end:n+t.length};if(rE(r,n)){let e=iE(r,i.end)?1:VT;if((a===null||e>a.score)&&(a={score:e,...i,pieces:[i]}),e===1)return a}else e.midWord&&t.length>=qT&&a===null&&(a={score:WT,...i,pieces:[i]})}if(a!==null&&a.score>WT)return a;let o=n.primary?cE(r,i,t):null;return o===null?n.typos?lE(r,i,t)??a:a:o}function dE(e){let t=[];for(let n of[...e].sort((e,t)=>e.start-t.start)){let e=t.at(-1);e!==void 0&&n.start<=e.end?e.end=Math.max(e.end,n.end):t.push({...n})}return t}function fE(e,t,n){let r=tE(e);if(r.length===0)return null;let i=t.filter(e=>e.value!==``).map(e=>({...e,source:e.value,folded:eE(e.value)})),a=r.some(e=>!JT.has(e)),o=[],s=0,c=0,l=!0;for(let e of r){let t=0,r=!1;for(let[a,s]of i.entries()){let i=uE(s,e,{primary:a===0,typos:n});i!==null&&(a===0&&o.push(...i.pieces),i.score>=VT&&s.weight>KT&&(r=!0),t=Math.max(t,i.score*s.weight))}if(t===0){if(a&&JT.has(e))continue;return null}l&&=r,s+=t,c+=1}let u=i.at(0)?.folded??``,d=r.join(` `),f=u===d?BT:r.length>1&&u.includes(d)?GT:0;return{quality:s/c+f,strong:l,ranges:dE(o)}}function pE(e,t){let n=eE(t);return dE(tE(e).filter(e=>e.length>=3).flatMap(e=>{let t=[];for(let r=n.indexOf(e);r!==-1;r=n.indexOf(e,r+e.length))t.push({start:r,end:r+e.length});return t}))}var mE=.6,hE=.25,gE=.6,_E=8,vE=3,yE=18144e5,bE=32,xE=12096e5,SE=2.5;function CE(e){return 2**(-Math.max(0,e)/xE)}function wE(e,t){let n=CE(t-e.updatedAt),r=e.opens===null?0:e.opens.score*CE(t-e.opens.openedAt);return Math.min(SE,1+n+.5*Math.log2(1+r))}function TE(e){return tE(e).join(` `).slice(0,bE).trim()}function EE(e,t,n){let r=TE(t),i=(e.opens?.picks??[]).filter(e=>n-e.at<=yE&&(e.query===r||r.length>=vE&&e.query.startsWith(r)));return Math.max(0,...i.map(e=>e.at))}function DE(e,t,n){let r=fE(t,[{value:e.title,weight:1,midWord:!0},{value:e.branch??``,weight:gE,midWord:!1},{value:e.projectName??``,weight:hE,midWord:!1},{value:e.machineName??``,weight:hE,midWord:!1}],n);if(r!==null)return r;let i=t.trim().toLowerCase();return i.length>=_E&&e.id.toLowerCase().includes(i)?{quality:mE,strong:!0,ranges:[]}:null}function OE(e){return e>=1.5?3:e>=.7?2:+(e>=.4)}function kE(e,t,n,r){function i(i){return e.flatMap(e=>{let a=t(e),o=DE(a,n,i);return o===null?[]:[{item:e,match:o,picked:EE(a,n,r),score:o.quality*wE(a,r)}]})}let a=i(!1);return[...a.some(e=>e.match.strong)?a:i(!0)].sort((e,t)=>OE(t.match.quality)-OE(e.match.quality)||t.picked-e.picked||t.score-e.score).map(e=>({item:e.item,ranges:e.match.ranges}))}function AE(e){return Math.max(e.updatedAt,e.opens?.openedAt??0)}function jE(e,t,n){return fE(e,[{value:t,weight:1,midWord:!0},{value:n,weight:gE,midWord:!1}],!1)}function ME(e,t,n,r){return e.flatMap(e=>{let n=t(e);return n===void 0?[]:[{match:e,subject:n}]}).sort((e,t)=>NE(e.match,t.match)||EE(t.subject,n,r)-EE(e.subject,n,r)||wE(t.subject,r)-wE(e.subject,r)).map(e=>e.match)}function NE(e,t){return t.quality-e.quality||Number(t.author===`user`)-Number(e.author===`user`)}function PE(e,t,n){let r=R(e=>e.machines),[i,a]=(0,U.useState)([]),[o,s]=(0,U.useState)([]),c=r.filter(e=>e.status===`online`).map(e=>e.id).join(` `),l=r.filter(e=>n===`all`||e.id===n),u=l.filter(e=>e.status===`online`).map(e=>e.id).join(` `);(0,U.useEffect)(()=>{let e=!0;for(let t of L().machines.filter(e=>e.status===`online`))N(t.id,`sessions.searchable`,void 0).then(n=>{e&&a(e=>FE(e,{machine:t.id,sessions:n.sessions.map(e=>({...e,machine:t.id})),failed:IE(n.failed)}))}).catch(()=>{e&&a(e=>FE(e,{machine:t.id,sessions:[],failed:[t.name]}))});return()=>{e=!1}},[c]),(0,U.useEffect)(()=>{if(t.startsWith(`>`)||!nE(t))return;let e=!0;for(let n of L().machines.filter(e=>e.status===`online`))N(n.id,`sessions.searchMessages`,{query:t}).then(r=>{e&&s(e=>FE(e,{machine:n.id,query:t,matches:r.matches.map(e=>({...e,machine:n.id})),failed:IE(r.failed)}))}).catch(()=>{e&&s(e=>FE(e,{machine:n.id,query:t,matches:[],failed:[n.name]}))});return()=>{e=!1}},[t,c]);let d=o.filter(t=>u.split(` `).includes(t.machine)&&t.query===e);return{threadResults:i,reachable:u,messages:d.flatMap(e=>e.matches),searching:!e.startsWith(`>`)&&nE(e)&&l.some(e=>e.status===`online`&&!d.some(t=>t.machine===e.id)),failures:[...new Set([...l.filter(e=>e.status!==`online`).map(e=>e.name),...i.filter(e=>u.split(` `).includes(e.machine)).flatMap(e=>e.failed),...d.flatMap(e=>e.failed)])]}}function FE(e,t){return[...e.filter(e=>e.machine!==t.machine),t]}function IE(e){return e.map(e=>tr[e])}var LE=20,RE=12,zE=10;function BE(){let e=R(e=>e.paletteOpen);return(0,W.jsx)(Or,{open:e,onOpenChange:se,children:(0,W.jsxs)(xr,{showCloseButton:!1,className:`top-[20%] translate-y-0 gap-0 overflow-hidden p-0 sm:max-w-xl`,children:[(0,W.jsx)(Tr,{className:`sr-only`,children:`Search threads`}),(0,W.jsx)(VE,{})]})})}function VE(){let e=R(e=>e.selection),t=R(e=>e.machines),n=R(e=>e.projects),[r,i]=(0,U.useState)(``),[a]=sr(r,300),[o,s]=(0,U.useState)(`all`),[c,l]=(0,U.useState)(null),[f]=(0,U.useState)(()=>Date.now()),p=(0,U.useRef)(null),m=(0,U.useRef)(null),h=r.startsWith(`>`),g=h?r.slice(1):r,v=PE(r,a,o),y=v.threadResults,b=v.reachable,x=t.find(e=>e.id===o),S=(0,U.useMemo)(()=>y.filter(e=>b.split(` `).includes(e.machine)).flatMap(e=>e.sessions).map(e=>({thread:e,subject:GE(e,t,n)})),[y,b,t,n]),C=new Map(S.map(e=>[_(e.thread.machine,e.thread.id),e.subject])),w=(0,U.useMemo)(()=>g.trim()===``?[]:kE(S,e=>e.subject,g,f).slice(0,LE).map(e=>({item:e.item.thread,ranges:e.ranges})),[S,g,f]),T=(0,U.useMemo)(()=>[...S].sort((e,t)=>AE(t.subject)-AE(e.subject)).slice(0,RE).map(e=>({item:e.thread,ranges:[]})),[S]),E=g.trim()===``?T:w,D=[...e===null?[]:[{key:`new`,label:`New thread`,place:{machine:e.machine,projectId:e.projectId},detail:qE(e.machine,e.projectId,n),run:()=>He({...e,sessionId:null})}],{key:`accounts`,label:`Manage accounts`,detail:``,place:null,run:()=>u(vt[L().settings.provider])},{key:`settings`,label:`Settings`,detail:`Theme, notifications, keyboard shortcuts`,place:null,run:()=>d(!0)}].flatMap(e=>{let t={...e,section:`Actions`,labelRanges:[],detailRanges:[],branch:``,updatedAt:null};if(g.trim()===``)return[t];let n=jE(g,e.label,e.detail);return n===null?[]:[{...t,labelRanges:n.ranges}]}),O=new Set(w.map(e=>_(e.item.machine,e.item.id))),k=h?[]:E.map(e=>{let t=e.item,r=g.trim()!==``&&t.branch!==null?` | ${t.branch}`:``;return{key:_(t.machine,t.id),section:g.trim()===``?`Recent`:`Threads`,label:t.title,labelRanges:e.ranges,detail:KE(t,n),detailRanges:[],branch:r,updatedAt:t.updatedAt,place:{machine:t.machine,projectId:t.projectId},run:()=>He({machine:t.machine,projectId:t.projectId,sessionId:t.id},g.trim()===``?null:g)}}),A=h?[]:ME(v.messages.filter(e=>!O.has(_(e.machine,e.sessionId))),e=>C.get(_(e.machine,e.sessionId)),g,f).slice(0,zE).flatMap(e=>{let t=S.find(t=>t.thread.machine===e.machine&&t.thread.id===e.sessionId)?.thread;if(t===void 0)return[];let n=`${e.author===`user`?`You: `:``}${e.snippet}`;return[{key:`message:${_(e.machine,e.sessionId)}`,section:`In messages`,label:t.title,labelRanges:[],detail:n,detailRanges:pE(g,n),branch:``,updatedAt:t.updatedAt,place:{machine:t.machine,projectId:t.projectId},run:()=>He({machine:t.machine,projectId:t.projectId,sessionId:t.id},g)}]}),j=[...D,...k,...A],M=Math.min(Math.max(0,j.findIndex(e=>e.key===c)),j.length-1);(0,U.useLayoutEffect)(()=>{p.current?.querySelector(`[data-active="true"]`)?.scrollIntoView({block:`nearest`})},[M]);function ee(e){se(!1),e.run()}return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2 border-b pr-2.5`,children:[(0,W.jsxs)(`label`,{className:`flex min-w-0 flex-1 items-center gap-2 pl-4`,children:[(0,W.jsx)(V,{icon:Cn,className:`text-muted-foreground size-4 shrink-0`}),(0,W.jsx)(`input`,{ref:m,value:r,onChange:e=>{i(e.target.value),l(null)},onKeyDown:e=>{if(e.key===`ArrowDown`||e.key===`ArrowUp`){e.preventDefault();let t=e.key===`ArrowDown`?1:-1;j.length>0&&l(j[(M+t+j.length)%j.length].key)}e.key===`Enter`&&M>=0&&(e.preventDefault(),ee(j[M]))},placeholder:`Search threads and actions…`,className:`placeholder:text-placeholder/75 h-11 w-full bg-transparent text-sm outline-none`})]}),t.length>1&&(0,W.jsxs)(Qt,{children:[(0,W.jsx)(un,{asChild:!0,children:(0,W.jsxs)(`button`,{className:`text-secondary-label hover:bg-accent data-[state=open]:bg-accent flex h-7 max-w-40 shrink-0 cursor-pointer items-center gap-1.5 rounded-[var(--control-radius)] px-1.5 text-xs`,children:[x!==void 0&&(0,W.jsx)(Vu,{icon:x.icon,className:`size-3 shrink-0`}),(0,W.jsx)(`span`,{className:`truncate`,children:x?.name??`All machines`}),(0,W.jsx)(V,{icon:cr,className:`size-3 shrink-0`})]})}),(0,W.jsx)(tn,{align:`end`,className:`w-56`,onCloseAutoFocus:e=>{e.preventDefault(),m.current?.focus()},children:(0,W.jsxs)(rn,{value:o,onValueChange:e=>{s(e),l(null)},children:[(0,W.jsx)(ir,{value:`all`,children:`All machines`}),t.map(e=>(0,W.jsxs)(ir,{value:e.id,disabled:e.status!==`online`,children:[(0,W.jsx)(Vu,{icon:e.icon,className:`size-3.5 shrink-0`}),(0,W.jsx)(`span`,{className:`min-w-0 truncate`,children:WE(e)})]},e.id))]})})]})]}),(0,W.jsxs)(`div`,{ref:p,className:`max-h-96 overflow-y-auto p-1`,children:[j.length===0&&!v.searching&&(0,W.jsx)(`p`,{className:`text-muted-foreground px-3 py-6 text-center text-xs`,children:`Nothing matches.`}),j.map((e,n)=>(0,W.jsxs)(`div`,{children:[e.section!==j[n-1]?.section&&(0,W.jsx)(`p`,{className:`text-secondary-label px-2.5 pt-2 pb-1 text-xs`,children:e.section}),(0,W.jsxs)(`button`,{"data-active":n===M,className:z(`flex w-full cursor-pointer flex-col rounded-lg px-2.5 py-1.5 text-left`,n===M&&`bg-accent`),onMouseMove:()=>l(e.key),onClick:()=>ee(e),children:[(0,W.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2 text-sm`,children:[e.place!==null&&(0,W.jsx)(zs,{machine:e.place.machine,projectId:e.place.projectId,className:`size-3.5 shrink-0 grayscale`}),(0,W.jsx)(`span`,{className:`min-w-0 truncate`,children:(0,W.jsx)(UE,{text:e.label,ranges:e.labelRanges})})]}),e.detail!==``&&(0,W.jsxs)(`span`,{className:`text-secondary-label flex min-w-0 items-center gap-1.5 text-xs`,children:[e.place!==null&&t.length>1&&(0,W.jsx)(HE,{id:e.place.machine,machines:t}),(0,W.jsxs)(`span`,{className:`min-w-0 truncate`,children:[(0,W.jsx)(UE,{text:e.detail,ranges:e.detailRanges}),(0,W.jsx)(`span`,{className:`text-muted-foreground/40`,children:e.branch})]}),e.updatedAt!==null&&(0,W.jsx)(`span`,{className:`ml-auto shrink-0 pl-2 tabular-nums`,children:on(e.updatedAt)})]})]})]},e.key)),v.searching&&(0,W.jsx)(`p`,{className:`text-muted-foreground px-2.5 py-2 text-xs`,children:`Searching messages…`})]}),v.failures.length>0&&(0,W.jsxs)(`p`,{className:`text-muted-foreground border-t px-4 py-2 text-xs`,children:[`Couldn't search `,v.failures.join(`, `)]})]})}function HE(e){let t=e.machines.find(t=>t.id===e.id);return(0,W.jsx)(Vu,{icon:t?.icon??null,className:`size-3 shrink-0`})}function UE(e){return(0,W.jsxs)(W.Fragment,{children:[e.ranges.map((t,n)=>(0,W.jsxs)(U.Fragment,{children:[e.text.slice(e.ranges[n-1]?.end??0,t.start),(0,W.jsx)(`mark`,{className:`text-foreground bg-transparent font-medium`,children:e.text.slice(t.start,t.end)})]},t.start)),e.text.slice(e.ranges.at(-1)?.end??0)]})}function WE(e){return e.status===`online`?e.name:e.status===`unpaired`?`${e.name} · needs pairing`:`${e.name} · offline`}function GE(e,t,n){return{id:e.id,title:e.title,branch:e.branch,projectName:n.find(t=>t.machine===e.machine&&t.id===e.projectId)?.name??null,machineName:t.length>1?t.find(t=>t.id===e.machine)?.name??null:null,updatedAt:e.updatedAt,opens:e.opens}}function KE(e,t){return`${e.status===`minimized`?`Minimized · `:``}${qE(e.machine,e.projectId,t)}`}function qE(e,t,n){return n.find(n=>n.machine===e&&n.id===t)?.name??``}function JE(e){let t=e.session,[n,r]=(0,U.useState)(!1),i=R(e=>e.generatingTitles.includes(_(t.machine,t.id))),a=e.mobile?Un:Gt,o=e.mobile?zn:Ht;return(0,W.jsxs)(W.Fragment,{children:[t.status===`inactive`?(0,W.jsxs)(a,{onSelect:()=>void rt(t.machine,t.id,{status:`active`}),children:[(0,W.jsx)(V,{icon:Bo}),`Make active`]}):(0,W.jsxs)(a,{onSelect:e.onDeactivate,children:[(0,W.jsx)(V,{icon:zo}),`Inactive`]}),(0,W.jsxs)(a,{onSelect:()=>void rt(t.machine,t.id,{status:t.status===`snoozed`?`active`:`snoozed`}),children:[(0,W.jsx)(V,{icon:t.status===`snoozed`?ja:Ma}),t.status===`snoozed`?`Unsnooze`:`Snooze`]}),(0,W.jsxs)(a,{onSelect:()=>void rt(t.machine,t.id,{status:t.status===`minimized`?`active`:`minimized`}),children:[(0,W.jsx)(V,{icon:t.status===`minimized`?Do:Mo}),t.status===`minimized`?`Restore`:`Minimize`]}),(0,W.jsxs)(a,{onSelect:()=>void rt(t.machine,t.id,{status:t.status===`pinned`?`active`:`pinned`}),children:[(0,W.jsx)(V,{icon:t.status===`pinned`?K:Ro}),t.status===`pinned`?`Unpin`:`Pin`]}),(0,W.jsx)(o,{}),(0,W.jsxs)(a,{disabled:i,onSelect:()=>void De(t),children:[(0,W.jsx)(V,{icon:Aa}),`Regenerate title`]}),(0,W.jsxs)(a,{onSelect:e.onRename,children:[(0,W.jsx)(V,{icon:Lo}),`Rename`]}),(0,W.jsxs)(a,{variant:`destructive`,title:`Also removes it from ${tr[t.provider]}`,onSelect:e=>{n?je(t.machine,t.id):(e.preventDefault(),r(!0))},children:[(0,W.jsx)(V,{icon:oo}),n?e.mobile?`Tap again to delete`:`Click again to delete`:`Delete`]})]})}function YE(e){return e.activity?.approval===!0&&e.activity?.question===!0?(0,W.jsx)(`span`,{title:`Waiting for approval and an answer`,className:`text-question flex`,children:(0,W.jsx)(V,{icon:Yo,className:`size-4 shrink-0`})}):e.activity?.approval===!0?(0,W.jsx)(`span`,{title:`Waiting for approval`,className:`text-question flex`,children:(0,W.jsx)(V,{icon:Ko,className:`size-4 shrink-0`})}):e.activity?.question===!0?(0,W.jsx)(`span`,{title:`Waiting for an answer`,className:`text-question flex`,children:(0,W.jsx)(V,{icon:Ua,className:`size-4 shrink-0`})}):e.activity?.running===!0?(0,W.jsx)(`span`,{title:`Working`,className:`text-info flex`,children:(0,W.jsx)(V,{icon:to,className:`size-4 shrink-0 animate-spin`})}):e.backgroundRunning?e.activity?.backgroundAgent===!0?(0,W.jsx)(`span`,{title:`Agent running in background`,className:`text-info flex`,children:(0,W.jsx)(V,{icon:Pn,className:`size-4 shrink-0 animate-spin`})}):(0,W.jsx)(`span`,{title:`Task running in background`,className:`text-muted-foreground flex`,children:(0,W.jsx)(V,{icon:Pn,className:`size-4 shrink-0 animate-spin`})}):e.done?(0,W.jsx)(`span`,{title:`Done`,className:`text-success flex`,children:(0,W.jsx)(V,{icon:Qa,className:`size-4 shrink-0`})}):null}function XE(e){let t=R(t=>t.generatingTitles.includes(_(e.session.machine,e.session.id)));return(0,W.jsx)(`span`,{className:z(t&&`text-shimmer`),children:e.session.title})}var ZE=`group/sidebar-row relative w-full cursor-pointer overflow-hidden rounded-md text-left outline-none select-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset`;function QE(e){let t=e.session,n=Ns(t.machine,t.projectId),r=R(e=>I(e,t.machine).icon),[i,a]=(0,U.useState)(null),[o,s]=(0,U.useState)(!1),c=(0,U.useRef)(null),l=e.activity?.waiting===!0,u=Object.values(e.activity?.tasks??{}).includes(`running`),d=!l&&(e.activity?.running===!0||u),f=e.activity?.running===!0||u,p=!l&&!d&&e.unseen,m=!e.selected&&!l&&!p;function h(){qe(t.machine,t.id,e.scope)}function g(){f?s(!0):h()}let _=(0,W.jsx)(xn,{open:o,onOpenChange:s,children:(0,W.jsxs)(Fn,{children:[(0,W.jsxs)(mn,{children:[(0,W.jsx)(Zn,{children:`Stop running work?`}),(0,W.jsx)(On,{children:`The agent or background tasks are running. Do you really want to stop them?`})]}),(0,W.jsxs)(En,{children:[(0,W.jsx)(Vn,{children:`Cancel`}),(0,W.jsx)(wn,{variant:`destructive`,onClick:h,children:`Stop and Make Inactive`})]})]})}),v=e.saved&&(0,W.jsxs)(Qt,{children:[(0,W.jsx)(un,{asChild:!0,children:(0,W.jsx)(`button`,{className:`text-muted-foreground hover:text-foreground inline-flex h-5 cursor-pointer items-center rounded-md px-1.5`,title:`Thread actions`,onClick:e=>e.stopPropagation(),children:(0,W.jsx)(V,{icon:co,className:`size-3.5`})})}),(0,W.jsx)(tn,{align:`end`,className:`w-44`,onClick:e=>e.stopPropagation(),onCloseAutoFocus:e=>{c.current!==null&&(e.preventDefault(),c.current.focus(),c.current.select())},children:(0,W.jsx)(JE,{session:t,mobile:!1,onDeactivate:g,onRename:()=>a(t.title)})})]}),y=i===null?(0,W.jsx)(`span`,{className:z(`min-w-0 flex-1 truncate text-sm`,m?`text-secondary-label font-normal`:`font-medium`,!m&&(e.unseen||l)&&`text-foreground`,!m&&!e.unseen&&!l&&`text-foreground/90`),children:(0,W.jsx)(XE,{session:t})}):(0,W.jsx)(`form`,{className:`min-w-0 flex-1`,onSubmit:e=>{e.preventDefault();let n=i.trim();a(null),n!==``&&n!==t.title&&rt(t.machine,t.id,{title:n})},children:(0,W.jsx)(`input`,{ref:c,value:i,onChange:e=>a(e.target.value),onClick:e=>e.stopPropagation(),onBlur:()=>a(null),onKeyDown:e=>{e.stopPropagation(),e.key===`Escape`&&a(null)},className:`text-foreground ring-ring/50 focus:ring-ring w-full rounded-sm bg-transparent text-sm font-medium ring-1 outline-none ring-inset`})}),b=z(e.selected&&`bg-sidebar-row-active text-sidebar-foreground`,m&&`text-sidebar-muted-foreground/75 hover:bg-sidebar-row-hover hover:text-sidebar-foreground`,!e.selected&&!m&&`text-sidebar-foreground hover:bg-sidebar-row-hover bg-transparent`);return e.slim?(0,W.jsxs)(`li`,{className:`list-none`,children:[(0,W.jsxs)(`div`,{role:`button`,tabIndex:0,className:z(ZE,b,`flex h-9 items-center gap-2.5 px-2.5`),onClick:e.onSelect,onKeyDown:t=>{t.key===`Enter`&&e.onSelect()},children:[(0,W.jsx)(`span`,{className:`flex shrink-0 items-center opacity-40 grayscale transition-opacity group-hover/sidebar-row:opacity-100 group-hover/sidebar-row:grayscale-0`,children:(0,W.jsx)(zs,{machine:t.machine,projectId:t.projectId})}),y,(0,W.jsxs)(`span`,{className:`relative ml-auto flex h-6 min-w-8 shrink-0 items-center justify-end`,children:[(0,W.jsx)(`span`,{className:`text-secondary-label group-any-hover/sidebar-row:opacity-0 inline-flex justify-end text-xs tabular-nums transition-opacity`,children:on(t.updatedAt)}),(0,W.jsx)(`span`,{className:`group-any-hover/sidebar-row:opacity-100 absolute inset-y-0 right-0 -mr-1 flex items-center opacity-0 transition-opacity has-[[data-state=open]]:opacity-100`,children:v})]})]}),_]}):(0,W.jsxs)(`li`,{className:`list-none py-0.5`,children:[(0,W.jsxs)(`div`,{role:`button`,tabIndex:0,className:z(ZE,b,d&&!e.selected&&`opacity-70 transition-opacity focus-within:opacity-100 hover:opacity-100`),onClick:e.onSelect,onKeyDown:t=>{t.key===`Enter`&&e.onSelect()},children:[(0,W.jsxs)(`div`,{className:`px-(--sidebar-row-content-inset) py-(--sidebar-content-inset)`,children:[(0,W.jsxs)(`div`,{className:`flex h-6 min-w-0 items-center gap-2`,children:[(0,W.jsx)(zs,{machine:t.machine,projectId:t.projectId,className:`size-5`}),y,t.status===`pinned`&&(0,W.jsx)(V,{icon:Ro,className:`text-muted-foreground/65 size-3 shrink-0`}),(0,W.jsx)(YE,{activity:e.activity,backgroundRunning:u,done:p})]}),(0,W.jsxs)(`div`,{className:`text-secondary-label mt-1 flex h-5 min-w-0 items-center gap-1.5 text-xs`,children:[(0,W.jsx)(Vu,{icon:r,className:`size-3 shrink-0`}),(0,W.jsxs)(`span`,{className:z(`min-w-0 flex-1 truncate`,m?`font-normal`:`font-medium`),children:[n,t.branch!==null&&(0,W.jsx)(`span`,{className:`text-muted-foreground/40 font-normal`,children:` | ${t.branch}`})]}),t.status===`snoozed`&&(0,W.jsx)(V,{icon:Ma,className:`size-3 shrink-0`}),(0,W.jsx)(`span`,{className:`shrink-0 tabular-nums`,children:on(t.updatedAt)})]})]}),e.saved&&(0,W.jsxs)(`div`,{className:z(`group-any-hover/sidebar-row:pointer-events-auto group-any-hover/sidebar-row:opacity-100 pointer-events-none absolute inset-y-0 right-0 flex w-20 flex-col items-end bg-linear-to-l from-50% to-transparent py-(--sidebar-content-inset) pr-1.5 opacity-0 transition-opacity has-[[data-state=open]]:pointer-events-auto has-[[data-state=open]]:opacity-100`,e.selected?`from-sidebar-row-active`:`from-sidebar-row-hover`),children:[(0,W.jsx)(`div`,{className:`flex h-6 items-center`,children:(0,W.jsx)(`button`,{className:`text-muted-foreground hover:text-foreground inline-flex h-5 cursor-pointer items-center rounded-md px-1.5`,title:`Make inactive`,"aria-label":`Make inactive`,onClick:e=>{e.stopPropagation(),g()},children:(0,W.jsx)(V,{icon:zo,className:`size-3.5 scale-160`})})}),(0,W.jsx)(`div`,{className:`mt-1 flex h-5 items-center`,children:v})]})]}),_]})}function $E(e){let t=Ns(e.machine,e.projectId),n=R(t=>I(t,e.machine).icon);return(0,W.jsx)(`li`,{className:`list-none py-0.5`,children:(0,W.jsx)(`div`,{role:`button`,tabIndex:0,className:z(ZE,`bg-sidebar-row-active text-sidebar-foreground`),onClick:e.onSelect,children:(0,W.jsxs)(`div`,{className:`px-(--sidebar-row-content-inset) py-(--sidebar-content-inset)`,children:[(0,W.jsxs)(`div`,{className:`flex h-6 min-w-0 items-center gap-2`,children:[(0,W.jsx)(zs,{machine:e.machine,projectId:e.projectId,className:`size-5`}),(0,W.jsx)(`span`,{className:`text-foreground min-w-0 flex-1 truncate text-sm font-medium`,children:`New thread`}),(0,W.jsx)(V,{icon:Xo,className:`text-warning-foreground size-4 shrink-0`})]}),(0,W.jsxs)(`div`,{className:`text-secondary-label mt-1 flex h-5 min-w-0 items-center gap-1.5 text-xs`,children:[(0,W.jsx)(Vu,{icon:n,className:`size-3 shrink-0`}),(0,W.jsxs)(`span`,{className:`min-w-0 flex-1 truncate font-medium`,children:[t,(0,W.jsx)(`span`,{className:`text-muted-foreground/40 font-normal`,children:` | Draft`})]}),(0,W.jsx)(`span`,{className:`shrink-0 tabular-nums`,children:`now`})]})]})})})}var eD=`/assets/ghostty-vt-CQAu1Gs5.wasm`,tD=Uint8Array,nD=Uint16Array,rD=Int32Array,iD=new tD([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),aD=new tD([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),oD=new tD([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),sD=function(e,t){for(var n=new nD(31),r=0;r<31;++r)n[r]=t+=1<<e[r-1];for(var i=new rD(n[30]),r=1;r<30;++r)for(var a=n[r];a<n[r+1];++a)i[a]=a-n[r]<<5|r;return{b:n,r:i}},cD=sD(iD,2),lD=cD.b,uD=cD.r;lD[28]=258,uD[258]=28;var dD=sD(aD,0),fD=dD.b;dD.r;for(var pD=new nD(32768),mD=0;mD<32768;++mD){var hD=(mD&43690)>>1|(mD&21845)<<1;hD=(hD&52428)>>2|(hD&13107)<<2,hD=(hD&61680)>>4|(hD&3855)<<4,pD[mD]=((hD&65280)>>8|(hD&255)<<8)>>1}for(var gD=(function(e,t,n){for(var r=e.length,i=0,a=new nD(t);i<r;++i)e[i]&&++a[e[i]-1];var o=new nD(t);for(i=1;i<t;++i)o[i]=o[i-1]+a[i-1]<<1;var s;if(n){s=new nD(1<<t);var c=15-t;for(i=0;i<r;++i)if(e[i])for(var l=i<<4|e[i],u=t-e[i],d=o[e[i]-1]++<<u,f=d|(1<<u)-1;d<=f;++d)s[pD[d]>>c]=l}else for(s=new nD(r),i=0;i<r;++i)e[i]&&(s[i]=pD[o[e[i]-1]++]>>15-e[i]);return s}),_D=new tD(288),mD=0;mD<144;++mD)_D[mD]=8;for(var mD=144;mD<256;++mD)_D[mD]=9;for(var mD=256;mD<280;++mD)_D[mD]=7;for(var mD=280;mD<288;++mD)_D[mD]=8;for(var vD=new tD(32),mD=0;mD<32;++mD)vD[mD]=5;var yD=gD(_D,9,1),bD=gD(vD,5,1),xD=function(e){for(var t=e[0],n=1;n<e.length;++n)e[n]>t&&(t=e[n]);return t},SD=function(e,t,n){var r=t/8|0;return(e[r]|e[r+1]<<8)>>(t&7)&n},CD=function(e,t){var n=t/8|0;return(e[n]|e[n+1]<<8|e[n+2]<<16)>>(t&7)},wD=function(e){return(e+7)/8|0},TD=function(e,t,n){return(t==null||t<0)&&(t=0),(n==null||n>e.length)&&(n=e.length),new tD(e.subarray(t,n))},ED=[`unexpected EOF`,`invalid block type`,`invalid length/literal`,`invalid distance`,`stream finished`,`no stream handler`,,`no callback`,`invalid UTF-8 data`,`extra field too long`,`date not in range 1980-2099`,`filename too long`,`stream finishing`,`invalid zip data`],DD=function(e,t,n){var r=Error(t||ED[e]);if(r.code=e,Error.captureStackTrace&&Error.captureStackTrace(r,DD),!n)throw r;return r},OD=function(e,t,n,r){var i=e.length,a=r?r.length:0;if(!i||t.f&&!t.l)return n||new tD(0);var o=!n,s=o||t.i!=2,c=t.i;o&&(n=new tD(i*3));var l=function(e){var t=n.length;if(e>t){var r=new tD(Math.max(t*2,e));r.set(n),n=r}},u=t.f||0,d=t.p||0,f=t.b||0,p=t.l,m=t.d,h=t.m,g=t.n,_=i*8;do{if(!p){u=SD(e,d,1);var v=SD(e,d+1,3);if(d+=3,!v){var y=wD(d)+4,b=e[y-4]|e[y-3]<<8,x=y+b;if(x>i){c&&DD(0);break}s&&l(f+b),n.set(e.subarray(y,x),f),t.b=f+=b,t.p=d=x*8,t.f=u;continue}if(v==1)p=yD,m=bD,h=9,g=5;else if(v==2){var S=SD(e,d,31)+257,C=SD(e,d+10,15)+4,w=S+SD(e,d+5,31)+1;d+=14;for(var T=new tD(w),E=new tD(19),D=0;D<C;++D)E[oD[D]]=SD(e,d+D*3,7);d+=C*3;for(var O=xD(E),k=(1<<O)-1,A=gD(E,O,1),D=0;D<w;){var j=A[SD(e,d,k)];d+=j&15;var y=j>>4;if(y<16)T[D++]=y;else{var M=0,ee=0;for(y==16?(ee=3+SD(e,d,3),d+=2,M=T[D-1]):y==17?(ee=3+SD(e,d,7),d+=3):y==18&&(ee=11+SD(e,d,127),d+=7);ee--;)T[D++]=M}}var te=T.subarray(0,S),ne=T.subarray(S);h=xD(te),g=xD(ne),p=gD(te,h,1),m=gD(ne,g,1)}else DD(1);if(d>_){c&&DD(0);break}}s&&l(f+131072);for(var re=(1<<h)-1,ie=(1<<g)-1,ae=d;;ae=d){var M=p[CD(e,d)&re],oe=M>>4;if(d+=M&15,d>_){c&&DD(0);break}if(M||DD(2),oe<256)n[f++]=oe;else if(oe==256){ae=d,p=null;break}else{var se=oe-254;if(oe>264){var D=oe-257,ce=iD[D];se=SD(e,d,(1<<ce)-1)+lD[D],d+=ce}var le=m[CD(e,d)&ie],ue=le>>4;le||DD(3),d+=le&15;var ne=fD[ue];if(ue>3){var ce=aD[ue];ne+=CD(e,d)&(1<<ce)-1,d+=ce}if(d>_){c&&DD(0);break}s&&l(f+131072);var de=f+se;if(f<ne){var fe=a-ne,pe=Math.min(ne,de);for(fe+f<0&&DD(3);f<pe;++f)n[f]=r[fe+f]}for(;f<de;++f)n[f]=n[f-ne]}}t.l=p,t.p=ae,t.b=f,t.f=u,p&&(u=1,t.m=h,t.d=m,t.n=g)}while(!u);return f!=n.length&&o?TD(n,0,f):n.subarray(0,f)},kD=new tD(0),AD=function(e,t){return((e[0]&15)!=8||e[0]>>4>7||(e[0]<<8|e[1])%31)&&DD(6,`invalid zlib data`),(e[1]>>5&1)==+!t&&DD(6,`invalid zlib data: `+(e[1]&32?`need`:`unexpected`)+` dictionary`),(e[1]>>3&4)+2},jD=function(){function e(e,t){typeof e==`function`&&(t=e,e={}),this.ondata=t;var n=e&&e.dictionary&&e.dictionary.subarray(-32768);this.s={i:0,b:n?n.length:0},this.o=new tD(32768),this.p=new tD(0),n&&this.o.set(n)}return e.prototype.e=function(e){if(this.ondata||DD(5),this.d&&DD(4),!this.p.length)this.p=e;else if(e.length){var t=new tD(this.p.length+e.length);t.set(this.p),t.set(e,this.p.length),this.p=t}},e.prototype.c=function(e){this.s.i=+(this.d=e||!1);var t=this.s.b,n=OD(this.p,this.s,this.o);this.ondata(TD(n,t,this.s.b),this.d),this.o=TD(n,this.s.b-32768),this.s.b=this.o.length,this.p=TD(this.p,this.s.p/8|0),this.s.p&=7},e.prototype.push=function(e,t){this.e(e),this.c(t)},e}(),MD=function(){function e(e,t){jD.call(this,e,t),this.v=e&&e.dictionary?2:1}return e.prototype.push=function(e,t){if(jD.prototype.e.call(this,e),this.v){if(this.p.length<6&&!t)return;this.p=this.p.subarray(AD(this.p,this.v-1)),this.v=0}t&&(this.p.length<4&&DD(6,`invalid zlib data`),this.p=this.p.subarray(0,-4)),jD.prototype.c.call(this,t)},e}();function ND(e,t){return OD(e.subarray(AD(e,t&&t.dictionary),-4),{i:2},t&&t.out,t&&t.dictionary)}var PD=typeof TextDecoder<`u`&&new TextDecoder;try{PD.decode(kD,{stream:!0})}catch{}function FD(e,t=`utf8`){return new TextDecoder(t).decode(e)}var ID=new TextEncoder;function LD(e){return ID.encode(e)}var RD=8192,zD=(()=>{let e=new Uint8Array(4),t=new Uint32Array(e.buffer);return!((t[0]=1)&e[0])})(),BD={int8:globalThis.Int8Array,uint8:globalThis.Uint8Array,int16:globalThis.Int16Array,uint16:globalThis.Uint16Array,int32:globalThis.Int32Array,uint32:globalThis.Uint32Array,uint64:globalThis.BigUint64Array,int64:globalThis.BigInt64Array,float32:globalThis.Float32Array,float64:globalThis.Float64Array},VD=class e{buffer;byteLength;byteOffset;length;offset;lastWrittenByte;littleEndian;_data;_mark;_marks;constructor(t=RD,n={}){let r=!1;typeof t==`number`?t=new ArrayBuffer(t):(r=!0,this.lastWrittenByte=t.byteLength);let i=n.offset?n.offset>>>0:0,a=t.byteLength-i,o=i;(ArrayBuffer.isView(t)||t instanceof e)&&(t.byteLength!==t.buffer.byteLength&&(o=t.byteOffset+i),t=t.buffer),this.lastWrittenByte=r?a:0,this.buffer=t,this.length=a,this.byteLength=a,this.byteOffset=o,this.offset=0,this.littleEndian=!0,this._data=new DataView(this.buffer,o,a),this._mark=0,this._marks=[]}available(e=1){return this.offset+e<=this.length}isLittleEndian(){return this.littleEndian}setLittleEndian(){return this.littleEndian=!0,this}isBigEndian(){return!this.littleEndian}setBigEndian(){return this.littleEndian=!1,this}skip(e=1){return this.offset+=e,this}back(e=1){return this.offset-=e,this}seek(e){return this.offset=e,this}mark(){return this._mark=this.offset,this}reset(){return this.offset=this._mark,this}pushMark(){return this._marks.push(this.offset),this}popMark(){let e=this._marks.pop();if(e===void 0)throw Error(`Mark stack empty`);return this.seek(e),this}rewind(){return this.offset=0,this}ensureAvailable(e=1){if(!this.available(e)){let t=(this.offset+e)*2,n=new Uint8Array(t);n.set(new Uint8Array(this.buffer)),this.buffer=n.buffer,this.length=t,this.byteLength=t,this._data=new DataView(this.buffer)}return this}readBoolean(){return this.readUint8()!==0}readInt8(){return this._data.getInt8(this.offset++)}readUint8(){return this._data.getUint8(this.offset++)}readByte(){return this.readUint8()}readBytes(e=1){return this.readArray(e,`uint8`)}readArray(e,t){let n=BD[t].BYTES_PER_ELEMENT*e,r=this.byteOffset+this.offset,i=this.buffer.slice(r,r+n);if(this.littleEndian===zD&&t!==`uint8`&&t!==`int8`){let e=new Uint8Array(this.buffer.slice(r,r+n));e.reverse();let i=new BD[t](e.buffer);return this.offset+=n,i.reverse(),i}let a=new BD[t](i);return this.offset+=n,a}readInt16(){let e=this._data.getInt16(this.offset,this.littleEndian);return this.offset+=2,e}readUint16(){let e=this._data.getUint16(this.offset,this.littleEndian);return this.offset+=2,e}readInt32(){let e=this._data.getInt32(this.offset,this.littleEndian);return this.offset+=4,e}readUint32(){let e=this._data.getUint32(this.offset,this.littleEndian);return this.offset+=4,e}readFloat32(){let e=this._data.getFloat32(this.offset,this.littleEndian);return this.offset+=4,e}readFloat64(){let e=this._data.getFloat64(this.offset,this.littleEndian);return this.offset+=8,e}readBigInt64(){let e=this._data.getBigInt64(this.offset,this.littleEndian);return this.offset+=8,e}readBigUint64(){let e=this._data.getBigUint64(this.offset,this.littleEndian);return this.offset+=8,e}readChar(){return String.fromCharCode(this.readInt8())}readChars(e=1){let t=``;for(let n=0;n<e;n++)t+=this.readChar();return t}readUtf8(e=1){return FD(this.readBytes(e))}decodeText(e=1,t=`utf8`){return FD(this.readBytes(e),t)}writeBoolean(e){return this.writeUint8(e?255:0),this}writeInt8(e){return this.ensureAvailable(1),this._data.setInt8(this.offset++,e),this._updateLastWrittenByte(),this}writeUint8(e){return this.ensureAvailable(1),this._data.setUint8(this.offset++,e),this._updateLastWrittenByte(),this}writeByte(e){return this.writeUint8(e)}writeBytes(e){this.ensureAvailable(e.length);for(let t=0;t<e.length;t++)this._data.setUint8(this.offset++,e[t]);return this._updateLastWrittenByte(),this}writeInt16(e){return this.ensureAvailable(2),this._data.setInt16(this.offset,e,this.littleEndian),this.offset+=2,this._updateLastWrittenByte(),this}writeUint16(e){return this.ensureAvailable(2),this._data.setUint16(this.offset,e,this.littleEndian),this.offset+=2,this._updateLastWrittenByte(),this}writeInt32(e){return this.ensureAvailable(4),this._data.setInt32(this.offset,e,this.littleEndian),this.offset+=4,this._updateLastWrittenByte(),this}writeUint32(e){return this.ensureAvailable(4),this._data.setUint32(this.offset,e,this.littleEndian),this.offset+=4,this._updateLastWrittenByte(),this}writeFloat32(e){return this.ensureAvailable(4),this._data.setFloat32(this.offset,e,this.littleEndian),this.offset+=4,this._updateLastWrittenByte(),this}writeFloat64(e){return this.ensureAvailable(8),this._data.setFloat64(this.offset,e,this.littleEndian),this.offset+=8,this._updateLastWrittenByte(),this}writeBigInt64(e){return this.ensureAvailable(8),this._data.setBigInt64(this.offset,e,this.littleEndian),this.offset+=8,this._updateLastWrittenByte(),this}writeBigUint64(e){return this.ensureAvailable(8),this._data.setBigUint64(this.offset,e,this.littleEndian),this.offset+=8,this._updateLastWrittenByte(),this}writeChar(e){return this.writeUint8(e.charCodeAt(0))}writeChars(e){for(let t=0;t<e.length;t++)this.writeUint8(e.charCodeAt(t));return this}writeUtf8(e){return this.writeBytes(LD(e))}toArray(){return new Uint8Array(this.buffer,this.byteOffset,this.lastWrittenByte)}getWrittenByteLength(){return this.lastWrittenByte-this.byteOffset}_updateLastWrittenByte(){this.offset>this.lastWrittenByte&&(this.lastWrittenByte=this.offset)}},HD=[];for(let e=0;e<256;e++){let t=e;for(let e=0;e<8;e++)t&1?t=3988292384^t>>>1:t>>>=1;HD[e]=t}var UD=4294967295;function WD(e,t,n){let r=e;for(let e=0;e<n;e++)r=HD[(r^t[e])&255]^r>>>8;return r}function GD(e,t){return(WD(UD,e,t)^UD)>>>0}function KD(e,t,n){let r=e.readUint32(),i=GD(new Uint8Array(e.buffer,e.byteOffset+e.offset-t-4,t),t);if(i!==r)throw Error(`CRC mismatch for chunk ${n}. Expected ${r}, found ${i}`)}function qD(e,t,n){for(let r=0;r<n;r++)t[r]=e[r]}function JD(e,t,n,r){let i=0;for(;i<r;i++)t[i]=e[i];for(;i<n;i++)t[i]=e[i]+t[i-r]&255}function YD(e,t,n,r){let i=0;if(n.length===0)for(;i<r;i++)t[i]=e[i];else for(;i<r;i++)t[i]=e[i]+n[i]&255}function XD(e,t,n,r,i){let a=0;if(n.length===0){for(;a<i;a++)t[a]=e[a];for(;a<r;a++)t[a]=e[a]+(t[a-i]>>1)&255}else{for(;a<i;a++)t[a]=e[a]+(n[a]>>1)&255;for(;a<r;a++)t[a]=e[a]+(t[a-i]+n[a]>>1)&255}}function ZD(e,t,n,r,i){let a=0;if(n.length===0){for(;a<i;a++)t[a]=e[a];for(;a<r;a++)t[a]=e[a]+t[a-i]&255}else{for(;a<i;a++)t[a]=e[a]+n[a]&255;for(;a<r;a++)t[a]=e[a]+QD(t[a-i],n[a],n[a-i])&255}}function QD(e,t,n){let r=e+t-n,i=Math.abs(r-e),a=Math.abs(r-t),o=Math.abs(r-n);return i<=a&&i<=o?e:a<=o?t:n}function $D(e,t,n,r,i,a){switch(e){case 0:qD(t,n,i);break;case 1:JD(t,n,i,a);break;case 2:YD(t,n,r,i);break;case 3:XD(t,n,r,i,a);break;case 4:ZD(t,n,r,i,a);break;default:throw Error(`Unsupported filter: ${e}`)}}var eO=new Uint16Array([255]),tO=new Uint8Array(eO.buffer)[0]===255;function nO(e){let{data:t,width:n,height:r,channels:i,depth:a}=e,o=[{x:0,y:0,xStep:8,yStep:8},{x:4,y:0,xStep:8,yStep:8},{x:0,y:4,xStep:4,yStep:8},{x:2,y:0,xStep:4,yStep:4},{x:0,y:2,xStep:2,yStep:4},{x:1,y:0,xStep:2,yStep:2},{x:0,y:1,xStep:1,yStep:2}],s=Math.ceil(a/8)*i,c=new Uint8Array(r*n*s),l=0;for(let e=0;e<7;e++){let i=o[e],a=Math.ceil((n-i.x)/i.xStep),u=Math.ceil((r-i.y)/i.yStep);if(a<=0||u<=0)continue;let d=a*s,f=new Uint8Array(d);for(let e=0;e<u;e++){let o=t[l++],u=t.subarray(l,l+d);l+=d;let p=new Uint8Array(d);$D(o,u,p,f,d,s),f.set(p);for(let t=0;t<a;t++){let a=i.x+t*i.xStep,o=i.y+e*i.yStep;if(!(a>=n||o>=r))for(let e=0;e<s;e++)c[(o*n+a)*s+e]=p[t*s+e]}}}if(a===16){let e=new Uint16Array(c.buffer);if(tO)for(let t=0;t<e.length;t++)e[t]=rO(e[t]);return e}return c}function rO(e){return(e&255)<<8|e>>8&255}var iO=new Uint16Array([255]),aO=new Uint8Array(iO.buffer)[0]===255,oO=new Uint8Array;function sO(e){let{data:t,width:n,height:r,channels:i,depth:a}=e,o=Math.ceil(a/8)*i,s=Math.ceil(a/8*i*n),c=new Uint8Array(r*s),l=oO,u=0,d,f;for(let e=0;e<r;e++){switch(d=t.subarray(u+1,u+1+s),f=c.subarray(e*s,(e+1)*s),t[u]){case 0:qD(d,f,s);break;case 1:JD(d,f,s,o);break;case 2:YD(d,f,l,s);break;case 3:XD(d,f,l,s,o);break;case 4:ZD(d,f,l,s,o);break;default:throw Error(`Unsupported filter: ${t[u]}`)}l=f,u+=s+1}if(a===16){let e=new Uint16Array(c.buffer);if(aO)for(let t=0;t<e.length;t++)e[t]=cO(e[t]);return e}return c}function cO(e){return(e&255)<<8|e>>8&255}var lO=Uint8Array.of(137,80,78,71,13,10,26,10);function uO(e){if(!dO(e.readBytes(lO.length)))throw Error(`wrong PNG signature`)}function dO(e){if(e.length<lO.length)return!1;for(let t=0;t<lO.length;t++)if(e[t]!==lO[t])return!1;return!0}var fO=`tEXt`,pO=0,mO=new TextDecoder(`latin1`);function hO(e){if(_O(e),e.length===0||e.length>79)throw Error(`keyword length must be between 1 and 79`)}var gO=/^[\u0000-\u00FF]*$/;function _O(e){if(!gO.test(e))throw Error(`invalid latin1 text`)}function vO(e,t,n){let r=yO(t);e[r]=bO(t,n-r.length-1)}function yO(e){for(e.mark();e.readByte()!==pO;);let t=e.offset;e.reset();let n=mO.decode(e.readBytes(t-e.offset-1));return e.skip(1),hO(n),n}function bO(e,t){return mO.decode(e.readBytes(t))}var xO={UNKNOWN:-1,GREYSCALE:0,TRUECOLOUR:2,INDEXED_COLOUR:3,GREYSCALE_ALPHA:4,TRUECOLOUR_ALPHA:6},SO={UNKNOWN:-1,DEFLATE:0},CO={UNKNOWN:-1,ADAPTIVE:0},wO={UNKNOWN:-1,NO_INTERLACE:0,ADAM7:1},TO={NONE:0,BACKGROUND:1,PREVIOUS:2},EO={SOURCE:0,OVER:1},DO=class extends VD{_checkCrc;_inflator;_png;_apng;_end;_hasPalette;_palette;_hasTransparency;_transparency;_compressionMethod;_filterMethod;_interlaceMethod;_colorType;_isAnimated;_numberOfFrames;_numberOfPlays;_frames;_writingDataChunks;_chunks;_inflatorResult;constructor(e,t={}){super(e);let{checkCrc:n=!1}=t;this._checkCrc=n,this._inflator=new MD((e,t)=>{if(this._chunks.push(e),t){let e=this._chunks.reduce((e,t)=>e+t.length,0);this._inflatorResult=new Uint8Array(e);let t=0;for(let e of this._chunks)this._inflatorResult.set(e,t),t+=e.length;this._chunks=[]}}),this._chunks=[],this._png={width:-1,height:-1,channels:-1,data:new Uint8Array,depth:1,text:{}},this._apng={width:-1,height:-1,channels:-1,depth:1,numberOfFrames:1,numberOfPlays:0,text:{},frames:[]},this._end=!1,this._hasPalette=!1,this._palette=[],this._hasTransparency=!1,this._transparency=new Uint16Array,this._compressionMethod=SO.UNKNOWN,this._filterMethod=CO.UNKNOWN,this._interlaceMethod=wO.UNKNOWN,this._colorType=xO.UNKNOWN,this._isAnimated=!1,this._numberOfFrames=1,this._numberOfPlays=0,this._frames=[],this._writingDataChunks=!1,this._inflatorResult=new Uint8Array,this.setBigEndian()}decode(){for(uO(this);!this._end;){let e=this.readUint32(),t=this.readChars(4);this.decodeChunk(e,t)}return this._inflator.push(new Uint8Array,!0),this.decodeImage(),this._png}decodeApng(){for(uO(this);!this._end;){let e=this.readUint32(),t=this.readChars(4);this.decodeApngChunk(e,t)}return this.decodeApngImage(),this._apng}decodeChunk(e,t){let n=this.offset;switch(t){case`IHDR`:this.decodeIHDR();break;case`PLTE`:this.decodePLTE(e);break;case`IDAT`:this.decodeIDAT(e);break;case`IEND`:this._end=!0;break;case`tRNS`:this.decodetRNS(e);break;case`iCCP`:this.decodeiCCP(e);break;case fO:vO(this._png.text,this,e);break;case`pHYs`:this.decodepHYs();break;default:this.skip(e)}if(this.offset-n!==e)throw Error(`Length mismatch while decoding chunk ${t}`);this._checkCrc?KD(this,e+4,t):this.skip(4)}decodeApngChunk(e,t){let n=this.offset;switch(t!==`fdAT`&&t!==`IDAT`&&this._writingDataChunks&&this.pushDataToFrame(),t){case`acTL`:this.decodeACTL();break;case`fcTL`:this.decodeFCTL();break;case`fdAT`:this.decodeFDAT(e);break;default:this.decodeChunk(e,t),this.offset=n+e}if(this.offset-n!==e)throw Error(`Length mismatch while decoding chunk ${t}`);this._checkCrc?KD(this,e+4,t):this.skip(4)}decodeIHDR(){let e=this._png;e.width=this.readUint32(),e.height=this.readUint32(),e.depth=OO(this.readUint8());let t=this.readUint8();this._colorType=t;let n;switch(t){case xO.GREYSCALE:n=1;break;case xO.TRUECOLOUR:n=3;break;case xO.INDEXED_COLOUR:n=1;break;case xO.GREYSCALE_ALPHA:n=2;break;case xO.TRUECOLOUR_ALPHA:n=4;break;case xO.UNKNOWN:default:throw Error(`Unknown color type: ${t}`)}if(this._png.channels=n,this._compressionMethod=this.readUint8(),this._compressionMethod!==SO.DEFLATE)throw Error(`Unsupported compression method: ${this._compressionMethod}`);this._filterMethod=this.readUint8(),this._interlaceMethod=this.readUint8()}decodeACTL(){this._numberOfFrames=this.readUint32(),this._numberOfPlays=this.readUint32(),this._isAnimated=!0}decodeFCTL(){let e={sequenceNumber:this.readUint32(),width:this.readUint32(),height:this.readUint32(),xOffset:this.readUint32(),yOffset:this.readUint32(),delayNumber:this.readUint16(),delayDenominator:this.readUint16(),disposeOp:this.readUint8(),blendOp:this.readUint8(),data:new Uint8Array};this._frames.push(e)}decodePLTE(e){if(e%3!=0)throw RangeError(`PLTE field length must be a multiple of 3. Got ${e}`);let t=e/3;this._hasPalette=!0;let n=[];this._palette=n;for(let e=0;e<t;e++)n.push([this.readUint8(),this.readUint8(),this.readUint8()])}decodeIDAT(e){this._writingDataChunks=!0;let t=e,n=this.offset+this.byteOffset;try{this._inflator.push(new Uint8Array(this.buffer,n,t),!1)}catch(e){throw Error(`Error while decompressing the data:`,{cause:e})}this.skip(e)}decodeFDAT(e){this._writingDataChunks=!0;let t=e,n=this.offset+this.byteOffset;n+=4,t-=4;try{this._inflator.push(new Uint8Array(this.buffer,n,t),!1)}catch(e){throw Error(`Error while decompressing the data:`,{cause:e})}this.skip(e)}decodetRNS(e){switch(this._colorType){case xO.GREYSCALE:case xO.TRUECOLOUR:if(e%2!=0)throw RangeError(`tRNS chunk length must be a multiple of 2. Got ${e}`);if(e/2>this._png.width*this._png.height)throw Error(`tRNS chunk contains more alpha values than there are pixels (${e/2} vs ${this._png.width*this._png.height})`);this._hasTransparency=!0,this._transparency=new Uint16Array(e/2);for(let t=0;t<e/2;t++)this._transparency[t]=this.readUint16();break;case xO.INDEXED_COLOUR:{if(e>this._palette.length)throw Error(`tRNS chunk contains more alpha values than there are palette colors (${e} vs ${this._palette.length})`);let t=0;for(;t<e;t++){let e=this.readByte();this._palette[t].push(e)}for(;t<this._palette.length;t++)this._palette[t].push(255);break}case xO.UNKNOWN:case xO.GREYSCALE_ALPHA:case xO.TRUECOLOUR_ALPHA:default:throw Error(`tRNS chunk is not supported for color type ${this._colorType}`)}}decodeiCCP(e){let t=yO(this),n=this.readUint8();if(n!==SO.DEFLATE)throw Error(`Unsupported iCCP compression method: ${n}`);let r=this.readBytes(e-t.length-2);this._png.iccEmbeddedProfile={name:t,profile:ND(r)}}decodepHYs(){let e=this.readUint32(),t=this.readUint32(),n=this.readByte();this._png.resolution={x:e,y:t,unit:n}}decodeApngImage(){this._apng.width=this._png.width,this._apng.height=this._png.height,this._apng.channels=this._png.channels,this._apng.depth=this._png.depth,this._apng.numberOfFrames=this._numberOfFrames,this._apng.numberOfPlays=this._numberOfPlays,this._apng.text=this._png.text,this._apng.resolution=this._png.resolution;for(let e=0;e<this._numberOfFrames;e++){let t={sequenceNumber:this._frames[e].sequenceNumber,delayNumber:this._frames[e].delayNumber,delayDenominator:this._frames[e].delayDenominator,data:this._apng.depth===8?new Uint8Array(this._apng.width*this._apng.height*this._apng.channels):new Uint16Array(this._apng.width*this._apng.height*this._apng.channels)},n=this._frames.at(e);if(n){if(n.data=sO({data:n.data,width:n.width,height:n.height,channels:this._apng.channels,depth:this._apng.depth}),this._hasPalette&&(this._apng.palette=this._palette),this._hasTransparency&&(this._apng.transparency=this._transparency),e===0||n.xOffset===0&&n.yOffset===0&&n.width===this._png.width&&n.height===this._png.height)t.data=n.data;else{let r=this._apng.frames.at(e-1);this.disposeFrame(n,r,t),this.addFrameDataToCanvas(t,n)}this._apng.frames.push(t)}}return this._apng}disposeFrame(e,t,n){switch(e.disposeOp){case TO.NONE:break;case TO.BACKGROUND:for(let t=0;t<this._png.height;t++)for(let r=0;r<this._png.width;r++){let i=(t*e.width+r)*this._png.channels;for(let e=0;e<this._png.channels;e++)n.data[i+e]=0}break;case TO.PREVIOUS:n.data.set(t.data);break;default:throw Error(`Unknown disposeOp`)}}addFrameDataToCanvas(e,t){let n=1<<this._png.depth,r=(e,n)=>({index:((e+t.yOffset)*this._png.width+t.xOffset+n)*this._png.channels,frameIndex:(e*t.width+n)*this._png.channels});switch(t.blendOp){case EO.SOURCE:for(let n=0;n<t.height;n++)for(let i=0;i<t.width;i++){let{index:a,frameIndex:o}=r(n,i);for(let n=0;n<this._png.channels;n++)e.data[a+n]=t.data[o+n]}break;case EO.OVER:for(let i=0;i<t.height;i++)for(let a=0;a<t.width;a++){let{index:o,frameIndex:s}=r(i,a);for(let r=0;r<this._png.channels;r++){let i=t.data[s+this._png.channels-1]/n,a=r%(this._png.channels-1)==0?1:t.data[s+r],c=Math.floor(i*a+(1-i)*e.data[o+r]);e.data[o+r]+=c}}break;default:throw Error(`Unknown blendOp`)}}decodeImage(){let e=this._inflatorResult;if(this._filterMethod!==CO.ADAPTIVE)throw Error(`Filter method ${this._filterMethod} not supported`);if(this._interlaceMethod===wO.NO_INTERLACE)this._png.data=sO({data:e,width:this._png.width,height:this._png.height,channels:this._png.channels,depth:this._png.depth});else if(this._interlaceMethod===wO.ADAM7)this._png.data=nO({data:e,width:this._png.width,height:this._png.height,channels:this._png.channels,depth:this._png.depth});else throw Error(`Interlace method ${this._interlaceMethod} not supported`);this._hasPalette&&(this._png.palette=this._palette),this._hasTransparency&&(this._png.transparency=this._transparency)}pushDataToFrame(){this._inflator.push(new Uint8Array,!0);let e=this._inflatorResult,t=this._frames.at(-1);t?t.data=e:this._frames.push({sequenceNumber:0,width:this._png.width,height:this._png.height,xOffset:0,yOffset:0,delayNumber:0,delayDenominator:0,disposeOp:TO.NONE,blendOp:EO.SOURCE,data:e}),this._inflator=new MD((e,t)=>{if(this._chunks.push(e),t){let e=this._chunks.reduce((e,t)=>e+t.length,0);this._inflatorResult=new Uint8Array(e);let t=0;for(let e of this._chunks)this._inflatorResult.set(e,t),t+=e.length;this._chunks=[]}}),this._chunks=[],this._writingDataChunks=!1}};function OO(e){if(e!==1&&e!==2&&e!==4&&e!==8&&e!==16)throw Error(`invalid bit depth: ${e}`);return e}function kO(e){let t=e.palette,n=e.depth;if(!t)throw Error(`Color palette is undefined.`);AO(e);let r=e.width*e.height,i=r*t[0].length,a=new Uint8Array(i),o=0,s=0,c=new Uint8Array(r),l=255;switch(n){case 1:l=128;break;case 2:l=192;break;case 4:l=240;break;case 8:l=255;break;default:throw Error(`Incorrect depth value`)}for(let t of e.data){let r=l,i=8;for(;r&&(i-=n,c[o++]=(t&r)>>i,r>>=n,o%e.width!==0););}if(e.palette)for(let t of c){let n=e.palette.at(t);if(!n)throw Error(`Incorrect index of palette color`);a.set(n,s),s+=n.length}return a}function AO(e){let t=e.depth<8?Math.ceil(e.width*e.depth/8)*e.height*e.channels:e.width*e.height*e.channels;if(e.data.length!==t)throw RangeError(`wrong data size. Found ${e.data.length}, expected ${t}`)}function jO(e,t){return new DO(e,t).decode()}var MO=t((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.DEFAULT_FOREGROUND=e.DEFAULT_BACKGROUND=e.PALETTE_ANSI_256=e.PALETTE_VT340_GREY=e.PALETTE_VT340_COLOR=e.normalizeHLS=e.normalizeRGB=e.nearestColorIndex=e.fromRGBA8888=e.toRGBA8888=e.alpha=e.blue=e.green=e.red=e.BIG_ENDIAN=void 0,e.BIG_ENDIAN=new Uint8Array(new Uint32Array([4278190080]).buffer)[0]===255,e.BIG_ENDIAN&&console.warn(`BE platform detected. This version of node-sixel works only on LE properly.`);function t(e){return e&255}e.red=t;function n(e){return e>>>8&255}e.green=n;function r(e){return e>>>16&255}e.blue=r;function i(e){return e>>>24&255}e.alpha=i;function a(e,t,n,r=255){return((r&255)<<24|(n&255)<<16|(t&255)<<8|e&255)>>>0}e.toRGBA8888=a;function o(e){return[e&255,e>>8&255,e>>16&255,e>>>24]}e.fromRGBA8888=o;function s(e,i){let a=t(e),o=n(e),s=r(e),c=2**53-1,l=-1;for(let e=0;e<i.length;++e){let t=a-i[e][0],n=o-i[e][1],r=s-i[e][2],u=t*t+n*n+r*r;if(!u)return e;u<c&&(c=u,l=e)}return l}e.nearestColorIndex=s;function c(e,t,n){return Math.max(e,Math.min(n,t))}function l(e,t,n){return n<0&&(n+=1),n>1&&--n,n*6<1?t+(e-t)*6*n:n*2<1?e:n*3<2?t+(e-t)*(4-n*6):t}function u(e,t,n){if(!n){let e=Math.round(t*255);return a(e,e,e)}let r=t<.5?t*(1+n):t+n-t*n,i=2*t-r;return a(c(0,255,Math.round(l(r,i,e+1/3)*255)),c(0,255,Math.round(l(r,i,e)*255)),c(0,255,Math.round(l(r,i,e-1/3)*255)))}function d(e,t,n){return(4278190080|Math.round(n/100*255)<<16|Math.round(t/100*255)<<8|Math.round(e/100*255))>>>0}e.normalizeRGB=d;function f(e,t,n){return u((e+240)/360,t/100,n/100)}e.normalizeHLS=f,e.PALETTE_VT340_COLOR=new Uint32Array([d(0,0,0),d(20,20,80),d(80,13,13),d(20,80,20),d(80,20,80),d(20,80,80),d(80,80,20),d(53,53,53),d(26,26,26),d(33,33,60),d(60,26,26),d(33,60,33),d(60,33,60),d(33,60,60),d(60,60,33),d(80,80,80)]),e.PALETTE_VT340_GREY=new Uint32Array([d(0,0,0),d(13,13,13),d(26,26,26),d(40,40,40),d(6,6,6),d(20,20,20),d(33,33,33),d(46,46,46),d(0,0,0),d(13,13,13),d(26,26,26),d(40,40,40),d(6,6,6),d(20,20,20),d(33,33,33),d(46,46,46)]),e.PALETTE_ANSI_256=(()=>{let e=[a(0,0,0),a(205,0,0),a(0,205,0),a(205,205,0),a(0,0,238),a(205,0,205),a(0,250,205),a(229,229,229),a(127,127,127),a(255,0,0),a(0,255,0),a(255,255,0),a(92,92,255),a(255,0,255),a(0,255,255),a(255,255,255)],t=[0,95,135,175,215,255];for(let n=0;n<6;++n)for(let r=0;r<6;++r)for(let i=0;i<6;++i)e.push(a(t[n],t[r],t[i]));for(let t=8;t<=238;t+=10)e.push(a(t,t,t));return new Uint32Array(e)})(),e.DEFAULT_BACKGROUND=a(0,0,0,255),e.DEFAULT_FOREGROUND=a(255,255,255,255)})),NO=t((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.LIMITS=void 0,e.LIMITS={CHUNK_SIZE:16384,PALETTE_SIZE:4096,MAX_WIDTH:16384,BYTES:`AGFzbQEAAAABJAdgAAF/YAJ/fwBgA39/fwF/YAF/AX9gAABgBH9/f38AYAF/AAIlAgNlbnYLaGFuZGxlX2JhbmQAAwNlbnYLbW9kZV9wYXJzZWQAAwMTEgQAAAAAAQQBAQUBAAACAgAGAwQFAXABBwcFBAEBBwcGCAF/AUGAihoLB9wBDgZtZW1vcnkCABFnZXRfc3RhdGVfYWRkcmVzcwADEWdldF9jaHVua19hZGRyZXNzAAQOZ2V0X3AwX2FkZHJlc3MABRNnZXRfcGFsZXR0ZV9hZGRyZXNzAAYEaW5pdAALBmRlY29kZQAMDWN1cnJlbnRfd2lkdGgADQ5jdXJyZW50X2hlaWdodAAOGV9faW5kaXJlY3RfZnVuY3Rpb25fdGFibGUBAAtfaW5pdGlhbGl6ZQACCXN0YWNrU2F2ZQARDHN0YWNrUmVzdG9yZQASCnN0YWNrQWxsb2MAEwkMAQBBAQsGCgcJDxACDAEBCq5UEgMAAQsFAEGgCAsGAEGQiQELBgBBsIkCCwUAQZAJC+okAQh/QeQIKAIAIQVB4AgoAgAhA0HoCCgCACEIIAFBkIkBaiIJQf8BOgAAIAAgAUgEQCAAQZCJAWohBgNAIAMhBCAGQQFqIQECQCAGLQAAQf8AcSIDQTBrQQlLBEAgASEGDAELQewIKAIAQQJ0QewIaiICKAIAIQADQCACIAMgAEEKbGpBMGsiADYCACABLQAAIQMgAUEBaiIGIQEgA0H/AHEiA0Ewa0EKSQ0ACwsCQAJAAkACQAJAAkACQAJ/AkACQCADQT9rIgBBP00EQCAERQ0BIARBIUYEQAJAQfAIKAIAIgFBASABGyIHIAhqIgFB1AgoAgAiA0gNACADQf//AEoNAANAIANBAnQiAkGgiQJqIgRBoAgpAwA3AwAgAkGoiQJqQaAIKQMANwMAIAJBsIkCakGgCCkDADcDACACQbiJAmpBoAgpAwA3AwAgAkHAiQJqQaAIKQMANwMAIAJByIkCakGgCCkDADcDACACQdCJAmpBoAgpAwA3AwAgAkHYiQJqQaAIKQMANwMAIAJB4IkCakGgCCkDADcDACACQeiJAmpBoAgpAwA3AwAgAkHwiQJqQaAIKQMANwMAIAJB+IkCakGgCCkDADcDACACQYCKAmpBoAgpAwA3AwAgAkGIigJqQaAIKQMANwMAIAJBkIoCakGgCCkDADcDACACQZiKAmpBoAgpAwA3AwAgAkGgigJqQaAIKQMANwMAIAJBqIoCakGgCCkDADcDACACQbCKAmpBoAgpAwA3AwAgAkG4igJqQaAIKQMANwMAIAJBwIoCakGgCCkDADcDACACQciKAmpBoAgpAwA3AwAgAkHQigJqQaAIKQMANwMAIAJB2IoCakGgCCkDADcDACACQeCKAmpBoAgpAwA3AwAgAkHoigJqQaAIKQMANwMAIAJB8IoCakGgCCkDADcDACACQfiKAmpBoAgpAwA3AwAgAkGAiwJqQaAIKQMANwMAIAJBiIsCakGgCCkDADcDACACQZCLAmpBoAgpAwA3AwAgAkGYiwJqQaAIKQMANwMAIAJBoIsCakGgCCkDADcDACACQaiLAmpBoAgpAwA3AwAgAkGwiwJqQaAIKQMANwMAIAJBuIsCakGgCCkDADcDACACQcCLAmpBoAgpAwA3AwAgAkHIiwJqQaAIKQMANwMAIAJB0IsCakGgCCkDADcDACACQdiLAmpBoAgpAwA3AwAgAkHgiwJqQaAIKQMANwMAIAJB6IsCakGgCCkDADcDACACQfCLAmpBoAgpAwA3AwAgAkH4iwJqQaAIKQMANwMAIAJBgIwCakGgCCkDADcDACACQYiMAmpBoAgpAwA3AwAgAkGQjAJqQaAIKQMANwMAIAJBmIwCakGgCCkDADcDACACQaCMAmpBoAgpAwA3AwAgAkGojAJqQaAIKQMANwMAIAJBsIwCakGgCCkDADcDACACQbiMAmpBoAgpAwA3AwAgAkHAjAJqQaAIKQMANwMAIAJByIwCakGgCCkDADcDACACQdCMAmpBoAgpAwA3AwAgAkHYjAJqQaAIKQMANwMAIAJB4IwCakGgCCkDADcDACACQeiMAmpBoAgpAwA3AwAgAkHwjAJqQaAIKQMANwMAIAJB+IwCakGgCCkDADcDACACQYCNAmpBoAgpAwA3AwAgAkGIjQJqQaAIKQMANwMAIAJBkI0CakGgCCkDADcDACACQZiNAmpBoAgpAwA3AwAgAkGwiQZqIARBgAT8CgAAQdQIKAIAQQJ0QcCJCmogBEGABPwKAABB1AgoAgBBAnRB0IkOaiAEQYAE/AoAAEHUCCgCAEECdEHgiRJqIARBgAT8CgAAQdQIKAIAQQJ0QfCJFmogBEGABPwKAABB1AhB1AgoAgAiAkGAAWoiAzYCACABIANIDQEgAkGA/wBIDQALCwJAIABFDQAgCEH//wBLDQBBgIABIAhrIAcgAUH//wBLGyECAkAgAEEBcUUNACACRQ0AIAhBAnRBoIkCaiEDIAIhBCACQQdxIgcEQANAIAMgBTYCACADQQRqIQMgBEEBayEEIAdBAWsiBw0ACwsgAkEBa0EHSQ0AA0AgAyAFNgIcIAMgBTYCGCADIAU2AhQgAyAFNgIQIAMgBTYCDCADIAU2AgggAyAFNgIEIAMgBTYCACADQSBqIQMgBEEIayIEDQALCwJAIABBAnFFDQAgAkUNACAIQQJ0QbCJBmohAyACIQQgAkEHcSIHBEADQCADIAU2AgAgA0EEaiEDIARBAWshBCAHQQFrIgcNAAsLIAJBAWtBB0kNAANAIAMgBTYCHCADIAU2AhggAyAFNgIUIAMgBTYCECADIAU2AgwgAyAFNgIIIAMgBTYCBCADIAU2AgAgA0EgaiEDIARBCGsiBA0ACwsCQCAAQQRxRQ0AIAJFDQAgCEECdEHAiQpqIQMgAiEEIAJBB3EiBwRAA0AgAyAFNgIAIANBBGohAyAEQQFrIQQgB0EBayIHDQALCyACQQFrQQdJDQADQCADIAU2AhwgAyAFNgIYIAMgBTYCFCADIAU2AhAgAyAFNgIMIAMgBTYCCCADIAU2AgQgAyAFNgIAIANBIGohAyAEQQhrIgQNAAsLAkAgAEEIcUUNACACRQ0AIAhBAnRB0IkOaiEDIAIhBCACQQdxIgcEQANAIAMgBTYCACADQQRqIQMgBEEBayEEIAdBAWsiBw0ACwsgAkEBa0EHSQ0AA0AgAyAFNgIcIAMgBTYCGCADIAU2AhQgAyAFNgIQIAMgBTYCDCADIAU2AgggAyAFNgIEIAMgBTYCACADQSBqIQMgBEEIayIEDQALCwJAIABBEHFFDQAgAkUNACAIQQJ0QeCJEmohAyACIQQgAkEHcSIHBEADQCADIAU2AgAgA0EEaiEDIARBAWshBCAHQQFrIgcNAAsLIAJBAWtBB0kNAANAIAMgBTYCHCADIAU2AhggAyAFNgIUIAMgBTYCECADIAU2AgwgAyAFNgIIIAMgBTYCBCADIAU2AgAgA0EgaiEDIARBCGsiBA0ACwsgAEEgcUUNACACRQ0AIAJBAWshByAIQQJ0QfCJFmohAyACQQdxIgQEQANAIAMgBTYCACADQQRqIQMgAkEBayECIARBAWsiBA0ACwsgB0EHSQ0AA0AgAyAFNgIcIAMgBTYCGCADIAU2AhQgAyAFNgIQIAMgBTYCDCADIAU2AgggAyAFNgIEIAMgBTYCACADQSBqIQMgAkEIayICDQALC0HcCEHcCCgCACAAcjYCACAGQQFqIgIgBi0AAEH/AHEiA0E/ayIAQT9LDQQaDAMLAkBB7AgoAgAiBEEBRgRAQfAIKAIAIgNBzAgoAgAiAUkNASADIAFwIQMMAQtB+AgoAgAhAkH0CCgCACEBAkACQCAEQQVHDQAgAUEBRw0AIAJB6QJODQQMAQsgAkHkAEoNA0H8CCgCAEHkAEoNA0GACSgCAEHkAEoNAwsCQCABRQ0AIAFBAkoNACACQfwIKAIAQYAJKAIAIAFBAnRBiAhqKAIAEQIAIQFB8AgoAgAiA0HMCCgCACICTwR/IAMgAnAFIAMLQQJ0QZAJaiABNgIAC0HwCCgCACIDQcwIKAIAIgFJDQAgAyABcCEDCyADQQJ0QZAJaigCACEFDAELIANB/QBxQSFHBEAgCCEBIAYhAgwECyAEQSNHDQQCQEHsCCgCACICQQFGBEBB8AgoAgAiAUHMCCgCACIASQ0BIAEgAHAhAQwBC0H4CCgCACEBQfQIKAIAIQACQAJAIAJBBUcNACAAQQFHDQAgAUHpAkgNAQwHCyABQeQASg0GQfwIKAIAQeQASg0GQYAJKAIAQeQASg0GCwJAIABFDQAgAEECSg0AIAFB/AgoAgBBgAkoAgAgAEECdEGICGooAgARAgAhAEHwCCgCACIBQcwIKAIAIgJPBH8gASACcAUgAQtBAnRBkAlqIAA2AgALQfAIKAIAIgFBzAgoAgAiAEkNACABIABwIQELIAFBAnRBkAlqKAIAIQUMBAsgCCEBIAYhAgtB1AgoAgAhBgNAAkAgASAGSA0AIAZB//8ASg0AIAZBAnQiBEGgiQJqIgZBoAgpAwA3AwAgBEGoiQJqQaAIKQMANwMAIARBsIkCakGgCCkDADcDACAEQbiJAmpBoAgpAwA3AwAgBEHAiQJqQaAIKQMANwMAIARByIkCakGgCCkDADcDACAEQdCJAmpBoAgpAwA3AwAgBEHYiQJqQaAIKQMANwMAIARB4IkCakGgCCkDADcDACAEQeiJAmpBoAgpAwA3AwAgBEHwiQJqQaAIKQMANwMAIARB+IkCakGgCCkDADcDACAEQYCKAmpBoAgpAwA3AwAgBEGIigJqQaAIKQMANwMAIARBkIoCakGgCCkDADcDACAEQZiKAmpBoAgpAwA3AwAgBEGgigJqQaAIKQMANwMAIARBqIoCakGgCCkDADcDACAEQbCKAmpBoAgpAwA3AwAgBEG4igJqQaAIKQMANwMAIARBwIoCakGgCCkDADcDACAEQciKAmpBoAgpAwA3AwAgBEHQigJqQaAIKQMANwMAIARB2IoCakGgCCkDADcDACAEQeCKAmpBoAgpAwA3AwAgBEHoigJqQaAIKQMANwMAIARB8IoCakGgCCkDADcDACAEQfiKAmpBoAgpAwA3AwAgBEGAiwJqQaAIKQMANwMAIARBiIsCakGgCCkDADcDACAEQZCLAmpBoAgpAwA3AwAgBEGYiwJqQaAIKQMANwMAIARBoIsCakGgCCkDADcDACAEQaiLAmpBoAgpAwA3AwAgBEGwiwJqQaAIKQMANwMAIARBuIsCakGgCCkDADcDACAEQcCLAmpBoAgpAwA3AwAgBEHIiwJqQaAIKQMANwMAIARB0IsCakGgCCkDADcDACAEQdiLAmpBoAgpAwA3AwAgBEHgiwJqQaAIKQMANwMAIARB6IsCakGgCCkDADcDACAEQfCLAmpBoAgpAwA3AwAgBEH4iwJqQaAIKQMANwMAIARBgIwCakGgCCkDADcDACAEQYiMAmpBoAgpAwA3AwAgBEGQjAJqQaAIKQMANwMAIARBmIwCakGgCCkDADcDACAEQaCMAmpBoAgpAwA3AwAgBEGojAJqQaAIKQMANwMAIARBsIwCakGgCCkDADcDACAEQbiMAmpBoAgpAwA3AwAgBEHAjAJqQaAIKQMANwMAIARByIwCakGgCCkDADcDACAEQdCMAmpBoAgpAwA3AwAgBEHYjAJqQaAIKQMANwMAIARB4IwCakGgCCkDADcDACAEQeiMAmpBoAgpAwA3AwAgBEHwjAJqQaAIKQMANwMAIARB+IwCakGgCCkDADcDACAEQYCNAmpBoAgpAwA3AwAgBEGIjQJqQaAIKQMANwMAIARBkI0CakGgCCkDADcDACAEQZiNAmpBoAgpAwA3AwAgBEGwiQZqIAZBgAT8CgAAQdQIKAIAQQJ0QcCJCmogBkGABPwKAABB1AgoAgBBAnRB0IkOaiAGQYAE/AoAAEHUCCgCAEECdEHgiRJqIAZBgAT8CgAAQdQIKAIAQQJ0QfCJFmogBkGABPwKAABB1AhB1AgoAgBBgAFqIgY2AgALIAFB//8ATQRAIABBAXEgAWxBAnRBoIkCaiAFNgIAIABBAXZBAXEgAWxBAnRBsIkGaiAFNgIAIABBAnZBAXEgAWxBAnRBwIkKaiAFNgIAIABBA3ZBAXEgAWxBAnRB0IkOaiAFNgIAIABBBHZBAXEgAWxBAnRB4IkSaiAFNgIAIABBBXYgAWxBAnRB8IkWaiAFNgIAQdQIKAIAIQYLIAFBAWohAUHcCEHcCCgCACAAcjYCACACLQAAIQAgAkEBaiIEIQIgAEH/AHEiA0E/ayIAQcAASQ0ACyAECyECQQAhBCACIQYgASEIIANB/QBxQSFGDQELIANBJGsOCgEDAwMDAwMDAwIDC0HsCEIBNwIADAQLQdgIIAFB2AgoAgAiACAAIAFIGyIAQYCAASAAQYCAAUgbNgIADAILQegIIAFB2AgoAgAiACAAIAFIGyIAQYCAASAAQYCAAUgbIgA2AgBB2AggADYCACAAQQRrEAAEQEHoCEEENgIAQdgIQQQ2AgBB0AhBATYCAA8LEAgMAQsCQCADQTtHDQBB7AgoAgAiAEEHSg0AQewIIABBAWo2AgAgAEECdEHwCGpBADYCAAsgAiEGIAQhAyABIQgMAQtBBCEIIAIhBiAEIQMLIAYgCUkNAAsLQeQIIAU2AgBB4AggAzYCAEHoCCAINgIAC9ELAgF+CH9B2AhCBDcDAEGojQJBoAgpAwAiADcDAEGgjQIgADcDAEGYjQIgADcDAEGQjQIgADcDAEGIjQIgADcDAEGAjQIgADcDAEH4jAIgADcDAEHwjAIgADcDAEHojAIgADcDAEHgjAIgADcDAEHYjAIgADcDAEHQjAIgADcDAEHIjAIgADcDAEHAjAIgADcDAEG4jAIgADcDAEGwjAIgADcDAEGojAIgADcDAEGgjAIgADcDAEGYjAIgADcDAEGQjAIgADcDAEGIjAIgADcDAEGAjAIgADcDAEH4iwIgADcDAEHwiwIgADcDAEHoiwIgADcDAEHgiwIgADcDAEHYiwIgADcDAEHQiwIgADcDAEHIiwIgADcDAEHAiwIgADcDAEG4iwIgADcDAEGwiwIgADcDAEGoiwIgADcDAEGgiwIgADcDAEGYiwIgADcDAEGQiwIgADcDAEGIiwIgADcDAEGAiwIgADcDAEH4igIgADcDAEHwigIgADcDAEHoigIgADcDAEHgigIgADcDAEHYigIgADcDAEHQigIgADcDAEHIigIgADcDAEHAigIgADcDAEG4igIgADcDAEGwigIgADcDAEGoigIgADcDAEGgigIgADcDAEGYigIgADcDAEGQigIgADcDAEGIigIgADcDAEGAigIgADcDAEH4iQIgADcDAEHwiQIgADcDAEHoiQIgADcDAEHgiQIgADcDAEHYiQIgADcDAEHQiQIgADcDAEHIiQIgADcDAEHAiQIgADcDAEG4iQIgADcDAEGwiQIgADcDAEGoCCgCACIEQf8AakGAAW0hCAJAIARBgQFIDQBBASEBIAhBAiAIQQJKG0EBayICQQFxIQMgBEGBAk4EQCACQX5xIQIDQCABQQl0IgdBEHJBoIkCakGwiQJBgAT8CgAAIAdBsI0CakGwiQJBgAT8CgAAIAFBAmohASACQQJrIgINAAsLIANFDQAgAUEJdEEQckGgiQJqQbCJAkGABPwKAAALAkAgBEEBSA0AIAhBASAIQQFKGyIDQQFxIQUCQCADQQFrIgdFBEBBACEBDAELIANB/v///wdxIQJBACEBA0AgAUEJdCIGQRByQbCJBmpBsIkCQYAE/AoAACAGQZAEckGwiQZqQbCJAkGABPwKAAAgAUECaiEBIAJBAmsiAg0ACwsgBQRAIAFBCXRBEHJBsIkGakGwiQJBgAT8CgAACyAEQQFIDQAgA0EBcSEFIAcEfyADQf7///8HcSECQQAhAQNAIAFBCXQiBkEQckHAiQpqQbCJAkGABPwKAAAgBkGQBHJBwIkKakGwiQJBgAT8CgAAIAFBAmohASACQQJrIgINAAsgAUEHdEEEcgVBBAshASAFBEAgAUECdEHAiQpqQbCJAkGABPwKAAALIARBAUgNACADQQFxIQUgBwR/IANB/v///wdxIQJBACEBA0AgAUEJdCIGQRByQdCJDmpBsIkCQYAE/AoAACAGQZAEckHQiQ5qQbCJAkGABPwKAAAgAUECaiEBIAJBAmsiAg0ACyABQQd0QQRyBUEECyEBIAUEQCABQQJ0QdCJDmpBsIkCQYAE/AoAAAsgBEEBSA0AIANBAXEhBSAHBH8gA0H+////B3EhAkEAIQEDQCABQQl0IgZBEHJB4IkSakGwiQJBgAT8CgAAIAZBkARyQeCJEmpBsIkCQYAE/AoAACABQQJqIQEgAkECayICDQALIAFBB3RBBHIFQQQLIQEgBQRAIAFBAnRB4IkSakGwiQJBgAT8CgAACyAEQQFIDQAgA0EBcSEEIAcEfyADQf7///8HcSECQQAhAQNAIAFBCXQiA0EQckHwiRZqQbCJAkGABPwKAAAgA0GQBHJB8IkWakGwiQJBgAT8CgAAIAFBAmohASACQQJrIgINAAsgAUEHdEEEcgVBBAshASAERQ0AIAFBAnRB8IkWakGwiQJBgAT8CgAAC0HUCCAIQQd0QQRyNgIAC58TAgh/AX5B5AgoAgAhA0HgCCgCACECQegIKAIAIQcgAUGQiQFqIglB/wE6AAAgACABSARAIABBkIkBaiEIA0AgAiEEIAhBAWohAQJAIAgtAABB/wBxIgJBMGtBCUsEQCABIQgMAQtB7AgoAgBBAnRB7AhqIgUoAgAhAANAIAUgAiAAQQpsakEwayIANgIAIAEtAAAhAiABQQFqIgghASACQf8AcSICQTBrQQpJDQALCwJAAkACQAJAAkACQAJ/AkAgAkE/ayIAQT9NBEAgBEUNASAEQSFGBEBB8AgoAgAiAUEBIAEbIgQgB2ohAQJAIABFDQAgB0H//wBLDQBBgIABIAdrIAQgAUH//wBLGyEFAkAgAEEBcUUNACAHQQJ0QaCJAmohAiAFIgRBB3EiBgRAA0AgAiADNgIAIAJBBGohAiAEQQFrIQQgBkEBayIGDQALCyAFQQFrQQdJDQADQCACIAM2AhwgAiADNgIYIAIgAzYCFCACIAM2AhAgAiADNgIMIAIgAzYCCCACIAM2AgQgAiADNgIAIAJBIGohAiAEQQhrIgQNAAsLAkAgAEECcUUNACAHQQJ0QbCJBmohAiAFIgRBB3EiBgRAA0AgAiADNgIAIAJBBGohAiAEQQFrIQQgBkEBayIGDQALCyAFQQFrQQdJDQADQCACIAM2AhwgAiADNgIYIAIgAzYCFCACIAM2AhAgAiADNgIMIAIgAzYCCCACIAM2AgQgAiADNgIAIAJBIGohAiAEQQhrIgQNAAsLAkAgAEEEcUUNACAHQQJ0QcCJCmohAiAFIgRBB3EiBgRAA0AgAiADNgIAIAJBBGohAiAEQQFrIQQgBkEBayIGDQALCyAFQQFrQQdJDQADQCACIAM2AhwgAiADNgIYIAIgAzYCFCACIAM2AhAgAiADNgIMIAIgAzYCCCACIAM2AgQgAiADNgIAIAJBIGohAiAEQQhrIgQNAAsLAkAgAEEIcUUNACAHQQJ0QdCJDmohAiAFIgRBB3EiBgRAA0AgAiADNgIAIAJBBGohAiAEQQFrIQQgBkEBayIGDQALCyAFQQFrQQdJDQADQCACIAM2AhwgAiADNgIYIAIgAzYCFCACIAM2AhAgAiADNgIMIAIgAzYCCCACIAM2AgQgAiADNgIAIAJBIGohAiAEQQhrIgQNAAsLAkAgAEEQcUUNACAHQQJ0QeCJEmohAiAFIgRBB3EiBgRAA0AgAiADNgIAIAJBBGohAiAEQQFrIQQgBkEBayIGDQALCyAFQQFrQQdJDQADQCACIAM2AhwgAiADNgIYIAIgAzYCFCACIAM2AhAgAiADNgIMIAIgAzYCCCACIAM2AgQgAiADNgIAIAJBIGohAiAEQQhrIgQNAAsLIABBIHFFDQAgBUEBayEEIAdBAnRB8IkWaiEAIAVBB3EiAgRAA0AgACADNgIAIABBBGohACAFQQFrIQUgAkEBayICDQALCyAEQQdJDQADQCAAIAM2AhwgACADNgIYIAAgAzYCFCAAIAM2AhAgACADNgIMIAAgAzYCCCAAIAM2AgQgACADNgIAIABBIGohACAFQQhrIgUNAAsLIAhBAWoiBSAILQAAQf8AcSICQT9rIgBBP00NAxoMBAsCQEHsCCgCACIFQQFGBEBB8AgoAgAiAUHMCCgCACIESQ0BIAEgBHAhAQwBC0H4CCgCACEEQfQIKAIAIQECQAJAIAVBBUcNACABQQFHDQAgBEHpAk4NBAwBCyAEQeQASg0DQfwIKAIAQeQASg0DQYAJKAIAQeQASg0DCwJAIAFFDQAgAUECSg0AIARB/AgoAgBBgAkoAgAgAUECdEGICGooAgARAgAhBEHwCCgCACIBQcwIKAIAIgVPBH8gASAFcAUgAQtBAnRBkAlqIAQ2AgALQfAIKAIAIgFBzAgoAgAiBEkNACABIARwIQELIAFBAnRBkAlqKAIAIQMMAQsgAkH9AHFBIUcEQCAHIQEgAiEADAQLIARBI0cNBAJAQewIKAIAIgRBAUYEQEHwCCgCACIBQcwIKAIAIgBJDQEgASAAcCEBDAELQfgIKAIAIQFB9AgoAgAhAAJAAkAgBEEFRw0AIABBAUcNACABQekCSA0BDAcLIAFB5ABKDQZB/AgoAgBB5ABKDQZBgAkoAgBB5ABKDQYLAkAgAEUNACAAQQJKDQAgAUH8CCgCAEGACSgCACAAQQJ0QYgIaigCABECACEAQfAIKAIAIgFBzAgoAgAiBE8EfyABIARwBSABC0ECdEGQCWogADYCAAtB8AgoAgAiAUHMCCgCACIASQ0AIAEgAHAhAQsgAUECdEGQCWooAgAhAwwECyAHIQEgCAshBQNAIAFB//8ATQRAIABBAXEgAWxBAnRBoIkCaiADNgIAIABBAXZBAXEgAWxBAnRBsIkGaiADNgIAIABBAnZBAXEgAWxBAnRBwIkKaiADNgIAIABBA3ZBAXEgAWxBAnRB0IkOaiADNgIAIABBBHZBAXEgAWxBAnRB4IkSaiADNgIAIABBBXYgAWxBAnRB8IkWaiADNgIACyABQQFqIQEgBS0AACEAIAVBAWoiBCEFIABB/wBxIgJBP2siAEHAAEkNAAsgBCEFC0EAIQQgBSEIIAEhByACIQAgAkH9AHFBIUYNAQtBBCEHIAQhAiAAQSRrDgoDAgICAgICAgIBAgtB7AhCATcCAAwCC0GoCCgCAEEEaxAABEBB0AhBATYCAA8LAkBBqAgoAgAiBkEFSA0AQaAIKQMAIQogBkEDa0EBdiIBQQdxIQJBACEAIAFBAWtBB08EQCABQfj///8HcSEFA0AgAEEDdCIBQbCJAmogCjcDACABQQhyQbCJAmogCjcDACABQRByQbCJAmogCjcDACABQRhyQbCJAmogCjcDACABQSByQbCJAmogCjcDACABQShyQbCJAmogCjcDACABQTByQbCJAmogCjcDACABQThyQbCJAmogCjcDACAAQQhqIQAgBUEIayIFDQALCyACRQ0AA0AgAEEDdEGwiQJqIAo3AwAgAEEBaiEAIAJBAWsiAg0ACwtBwIkGQbCJAiAGQQJ0IgD8CgAAQdCJCkGwiQIgAPwKAABB4IkOQbCJAiAA/AoAAEHwiRJBsIkCIAD8CgAAQYCKFkGwiQIgAPwKAAAgBCECDAELAkAgAEE7Rw0AQewIKAIAIgBBB0oNAEHsCCAAQQFqNgIAIABBAnRB8AhqQQA2AgALIAEhBwsgCCAJSQ0ACwtB5AggAzYCAEHgCCACNgIAQegIIAc2AgAL4gcCBX8BfgJAQdAIAn8CQAJAIAAgAU4NACABQZCJAWohBiAAQZCJAWohBQNAIAUtAAAiA0H/AHEhAgJAAkACQAJAAkACQAJAQeAIKAIAIgRBIkcEQCAEDQcgAkEiRgRAQewIQgE3AgBB4AhBIjYCAAwICyACQT9rQcAASQ0GIANBIWsiAkEMTQ0BDAULAkAgAkEwayIEQQlNBEBB7AgoAgBBAnRB7AhqIgIgBCACKAIAQQpsajYCAAwBC0HsCCgCACEEIAJBO0YEQCAEQQdKDQFB7AggBEEBajYCACAEQQJ0QfAIakEANgIADAELIARBBEYEQEHECEECNgIAQbAIQfAIKQMANwMAQbgIQfgIKAIAIgI2AgBBvAhB/AgoAgAiBDYCAEHICEECQQFBwAgoAgAiAxs2AgBBrAggBEEAIAMbNgIAQagIIAJBgIABIAJBgIABSBtBBGpBACADGzYCAEHgCEEANgIADAoLIAJBP2tBwABJDQQLIANBIWsiAkEMTQ0BDAILQQEgAnRBjSBxRQ0DDAQLQQEgAnRBjSBxDQELIANBoQFrIgJBDEsNA0EBIAJ0QY0gcUUNAwtBxAhCgYCAgBA3AgBBsAhB8AgoAgBBAEHsCCgCACICQQBKGzYCAEG0CEH0CCgCAEEAIAJBAUobNgIAQbgIQfgIKAIAQQAgAkECShs2AgBB4AhBADYCAEG8CEEANgIADAQLIANBoQFrIgJBDEsNAUEBIAJ0QY0gcUUNAQtBxAhCgYCAgBA3AgBBsAhCADcDAEG4CEIANwMADAMLIAVBAWoiBSAGSQ0ACwsCQEHICCgCAA4DAwEAAQsCQEGoCCgCACIFQQVIDQBBoAgpAwAhByAFQQNrQQF2IgNBB3EhBEEAIQIgA0EBa0EHTwRAIANB+P///wdxIQYDQCACQQN0IgNBsIkCaiAHNwMAIANBCHJBsIkCaiAHNwMAIANBEHJBsIkCaiAHNwMAIANBGHJBsIkCaiAHNwMAIANBIHJBsIkCaiAHNwMAIANBKHJBsIkCaiAHNwMAIANBMHJBsIkCaiAHNwMAIANBOHJBsIkCaiAHNwMAIAJBCGohAiAGQQhrIgYNAAsLIARFDQADQCACQQN0QbCJAmogBzcDACACQQFqIQIgBEEBayIEDQALC0HAiQZBsIkCIAVBAnQiA/wKAABB0IkKQbCJAiAD/AoAAEHgiQ5BsIkCIAP8CgAAQfCJEkGwiQIgA/wKAABBgIoWQbCJAiAD/AoAAEECDAELEAhByAgoAgALEAEiAjYCACACDQAgACABQcgIKAIAQQJ0QYAIaigCABEBAAsLdABB6AhBBDYCAEHkCCAANgIAQewIQgE3AgBBxAhCADcCAEHACCADNgIAQdwIQgA3AgBBqAhCADcDAEGwCEIANwMAQbgIQgA3AwBBzAggAkGAICACQYAgSRs2AgBBoAggAa1CgYCAgBB+NwMAQdAIQQA2AgALIwBB0AgoAgBFBEAgACABQcgIKAIAQQJ0QYAIaigCABEBAAsLWgECfwJAAkACQEHICCgCAEEBaw4CAAECC0HYCEHoCCgCACIAQdgIKAIAIgEgACABShsiAEGAgAEgAEGAgAFIGyIANgIAIABBBGsPC0GoCCgCAEEEayEACyAAC0IBAX8Cf0EGQdwIKAIAIgBBIHENABpBBSAAQRBxDQAaQQQgAEEIcQ0AGkEDIABBBHENABpBAiAAQQFxIABBAnEbCwu9BQEFfQJ/IAJFBEAgAUH/AWxBMmpB5ABtIgBBCHQgAHIgAEEQdHIMAQsgArJDAADIQpUhBiAAQfABarJDAAC0Q5UhBQJ9IAGyQwAAyEKVIgNDAAAAP10EQCADIAZDAACAP5KUDAELIAYgA0MAAIA/IAaTlJILIQcgAyADkiEGAkAgBUOrqqo+kiIEQwAAAABdBEAgBEMAAIA/kiEEDAELIARDAACAP15FDQAgBEMAAIC/kiEECyAGIAeTIQMgBUMAAAAAXSEAAn8CfSADIAcgA5NDAADAQJQgBJSSIARDq6oqPl0NABogByAEQwAAAD9dDQAaIAMgBEOrqio/XUUNABogAyAHIAOTIARDAADAwJRDAACAQJKUkgtDAAB/Q5RDAAAAP5IiBkMAAIBPXSAGQwAAAABgcQRAIAapDAELQQALIQECQCAABEAgBUMAAIA/kiEEDAELIAUiBEMAAIA/XkUNACAFQwAAgL+SIQQLIAVDq6qqvpIiBUMAAAAAXSECAn8CfSADIAcgA5NDAADAQJQgBJSSIARDq6oqPl0NABogByAEQwAAAD9dDQAaIAMgBEOrqio/XUUNABogAyAHIAOTIARDAADAwJRDAACAQJKUkgtDAAB/Q5RDAAAAP5IiBkMAAIBPXSAGQwAAAABgcQRAIAapDAELQQALIQACQCACBEAgBUMAAIA/kiEFDAELIAVDAACAP15FDQAgBUMAAIC/kiEFCwJAIAVDq6oqPl0EQCADIAcgA5NDAADAQJQgBZSSIQcMAQsgBUMAAAA/XQ0AIAVDq6oqP11FBEAgAyEHDAELIAMgByADkyAFQwAAwMCUQwAAgECSlJIhBwsgAEEIdAJ/IAdDAAB/Q5RDAAAAP5IiBkMAAIBPXSAGQwAAAABgcQRAIAapDAELQQALQRB0ciABcgtBgICAeHILNwAgAEH/AWxBMmpB5ABtIAFB/wFsQTJqQeQAbUEIdHIgAkH/AWxBMmpB5ABtQRB0ckGAgIB4cgsEACMACwYAIAAkAAsQACMAIABrQXBxIgAkACAACwsYAQBBgAgLEQEAAAACAAAAAwAAAAQAAAAF`}})),PO=t((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.decodeAsync=e.decode=e.Decoder=e.DecoderAsync=void 0;var t=MO(),n=NO();function r(e){if(typeof Buffer<`u`)return Buffer.from(e,`base64`);let t=atob(e),n=new Uint8Array(t.length);for(let e=0;e<n.length;++e)n[e]=t.charCodeAt(e);return n}var i=r(n.LIMITS.BYTES),a,o=new Uint32Array,s=class{constructor(){this.bandHandler=e=>1,this.modeHandler=e=>1}handle_band(e){return this.bandHandler(e)}mode_parsed(e){return this.modeHandler(e)}},c={memoryLimit:134217728,sixelColor:t.DEFAULT_FOREGROUND,fillColor:t.DEFAULT_BACKGROUND,palette:t.PALETTE_VT340_COLOR,paletteLimit:n.LIMITS.PALETTE_SIZE,truncate:!0};function l(e){let t=new s,n={env:{handle_band:t.handle_band.bind(t),mode_parsed:t.mode_parsed.bind(t)}};return WebAssembly.instantiate(a||i,n).then(n=>(a||=n.module,new u(e,n.instance||n,t)))}e.DecoderAsync=l;var u=class{constructor(e,r,s){if(this._PIXEL_OFFSET=n.LIMITS.MAX_WIDTH+4,this._canvas=o,this._bandWidths=[],this._maxWidth=0,this._minWidth=n.LIMITS.MAX_WIDTH,this._lastOffset=0,this._currentHeight=0,this._opts=Object.assign({},c,e),this._opts.paletteLimit>n.LIMITS.PALETTE_SIZE)throw Error(`DecoderOptions.paletteLimit must not exceed ${n.LIMITS.PALETTE_SIZE}`);if(r)s.bandHandler=this._handle_band.bind(this),s.modeHandler=this._initCanvas.bind(this);else{let e=a||=new WebAssembly.Module(i);r=new WebAssembly.Instance(e,{env:{handle_band:this._handle_band.bind(this),mode_parsed:this._initCanvas.bind(this)}})}this._instance=r,this._wasm=this._instance.exports,this._chunk=new Uint8Array(this._wasm.memory.buffer,this._wasm.get_chunk_address(),n.LIMITS.CHUNK_SIZE),this._states=new Uint32Array(this._wasm.memory.buffer,this._wasm.get_state_address(),12),this._palette=new Uint32Array(this._wasm.memory.buffer,this._wasm.get_palette_address(),n.LIMITS.PALETTE_SIZE),this._palette.set(this._opts.palette),this._pSrc=new Uint32Array(this._wasm.memory.buffer,this._wasm.get_p0_address()),this._wasm.init(t.DEFAULT_FOREGROUND,0,this._opts.paletteLimit,0)}get _fillColor(){return this._states[0]}get _truncate(){return this._states[8]}get _rasterWidth(){return this._states[6]}get _rasterHeight(){return this._states[7]}get _width(){return this._states[2]?this._states[2]-4:0}get _height(){return this._states[3]}get _level(){return this._states[9]}get _mode(){return this._states[10]}get _paletteLimit(){return this._states[11]}_initCanvas(e){if(e===2){let e=this.width*this.height;if(e>this._canvas.length){if(this._opts.memoryLimit&&e*4>this._opts.memoryLimit)throw this.release(),Error(`image exceeds memory limit`);this._canvas=new Uint32Array(e)}this._maxWidth=this._width}else if(e===1){if(this._level===2){let e=Math.min(this._rasterWidth,n.LIMITS.MAX_WIDTH)*this._rasterHeight;if(e>this._canvas.length){if(this._opts.memoryLimit&&e*4>this._opts.memoryLimit)throw this.release(),Error(`image exceeds memory limit`);this._canvas=new Uint32Array(e)}}else this._canvas.length<65536&&(this._canvas=new Uint32Array(65536))}return 0}_realloc(e,t){let n=e+t;if(n>this._canvas.length){if(this._opts.memoryLimit&&n*4>this._opts.memoryLimit)throw this.release(),Error(`image exceeds memory limit`);let e=new Uint32Array(Math.ceil(n/65536)*65536);e.set(this._canvas),this._canvas=e}}_handle_band(e){let t=this._PIXEL_OFFSET,n=this._lastOffset;if(this._mode===2){let r=this.height-this._currentHeight,i=0;for(;i<6&&r>0;)this._canvas.set(this._pSrc.subarray(t*i,t*i+e),n+e*i),i++,r--;this._lastOffset+=e*i,this._currentHeight+=i}else if(this._mode===1){this._realloc(n,e*6),this._maxWidth=Math.max(this._maxWidth,e),this._minWidth=Math.min(this._minWidth,e);for(let r=0;r<6;++r)this._canvas.set(this._pSrc.subarray(t*r,t*r+e),n+e*r);this._bandWidths.push(e),this._lastOffset+=e*6,this._currentHeight+=6}return 0}get width(){return this._mode===1?Math.max(this._maxWidth,this._wasm.current_width()):this._width}get height(){return this._mode===1?this._wasm.current_width()?this._bandWidths.length*6+this._wasm.current_height():this._bandWidths.length*6:this._height}get palette(){return this._palette.subarray(0,this._paletteLimit)}get memoryUsage(){return this._canvas.byteLength+this._wasm.memory.buffer.byteLength+8*this._bandWidths.length}get properties(){return{width:this.width,height:this.height,mode:this._mode,level:this._level,truncate:!!this._truncate,paletteLimit:this._paletteLimit,fillColor:this._fillColor,memUsage:this.memoryUsage,rasterAttributes:{numerator:this._states[4],denominator:this._states[5],width:this._rasterWidth,height:this._rasterHeight}}}init(e=this._opts.fillColor,t=this._opts.palette,r=this._opts.paletteLimit,i=this._opts.truncate){this._wasm.init(this._opts.sixelColor,e,r,+!!i),t&&this._palette.set(t.subarray(0,n.LIMITS.PALETTE_SIZE)),this._bandWidths.length=0,this._maxWidth=0,this._minWidth=n.LIMITS.MAX_WIDTH,this._lastOffset=0,this._currentHeight=0}decode(e,t=0,r=e.length){let i=t;for(;i<r;){let t=Math.min(r-i,n.LIMITS.CHUNK_SIZE);this._chunk.set(e.subarray(i,i+=t)),this._wasm.decode(0,t)}}decodeString(e,t=0,r=e.length){let i=t;for(;i<r;){let t=Math.min(r-i,n.LIMITS.CHUNK_SIZE);for(let n=0,r=i;n<t;++n,++r)this._chunk[n]=e.charCodeAt(r);i+=t,this._wasm.decode(0,t)}}get data32(){if(this._mode===0||!this.width||!this.height)return o;let e=this._wasm.current_width();if(this._mode===2){let t=this.height-this._currentHeight;if(t>0){let n=this._PIXEL_OFFSET,r=this._lastOffset,i=0;for(;i<6&&t>0;)this._canvas.set(this._pSrc.subarray(n*i,n*i+e),r+e*i),i++,t--;t&&this._canvas.fill(this._fillColor,r+e*i)}return this._canvas.subarray(0,this.width*this.height)}if(this._mode===1){if(this._minWidth===this._maxWidth){let t=!1;if(e){if(e!==this._minWidth)t=!0;else{let t=this._PIXEL_OFFSET,n=this._lastOffset;this._realloc(n,e*6);for(let r=0;r<6;++r)this._canvas.set(this._pSrc.subarray(t*r,t*r+e),n+e*r)}}if(!t)return this._canvas.subarray(0,this.width*this.height)}let t=new Uint32Array(this.width*this.height);t.fill(this._fillColor);let n=0,r=0;for(let e=0;e<this._bandWidths.length;++e){let i=this._bandWidths[e];for(let e=0;e<6;++e)t.set(this._canvas.subarray(r,r+=i),n),n+=this.width}if(e){let r=this._PIXEL_OFFSET,i=this._wasm.current_height();for(let a=0;a<i;++a)t.set(this._pSrc.subarray(r*a,r*a+e),n+this.width*a)}return t}return o}get data8(){return new Uint8ClampedArray(this.data32.buffer,0,this.width*this.height*4)}release(){this._canvas=o,this._bandWidths.length=0,this._maxWidth=0,this._minWidth=n.LIMITS.MAX_WIDTH,this._wasm.init(t.DEFAULT_FOREGROUND,0,this._opts.paletteLimit,0)}};e.Decoder=u;function d(e,t){let n=new u(t);return n.init(),typeof e==`string`?n.decodeString(e):n.decode(e),{width:n.width,height:n.height,data32:n.data32,data8:n.data8}}e.decode=d;async function f(e,t){let n=await l(t);return n.init(),typeof e==`string`?n.decodeString(e):n.decode(e),{width:n.width,height:n.height,data32:n.data32,data8:n.data8}}e.decodeAsync=f})),FO=MO(),IO=PO(),LO=FO.PALETTE_ANSI_256.slice();LO.set(FO.PALETTE_VT340_COLOR);var RO=200,zO=new TextEncoder,BO=`offsite-image:`;async function VO(e){let t=await(0,IO.decodeAsync)(e,{fillColor:0,palette:LO});return!t.width||!t.height?null:createImageBitmap(new ImageData(new Uint8ClampedArray(t.data8),t.width,t.height))}function HO(e,t,n){return e===void 0||e===`auto`?0:e.endsWith(`%`)?parseInt(e.slice(0,-1))*t/100:e.endsWith(`px`)?parseInt(e.slice(0,-2)):parseInt(e)*n}async function UO(e,t){let n=e.indexOf(`:`);if(n===-1)return null;let r=new Map(e.slice(0,n).split(`;`).map(e=>{let t=e.indexOf(`=`);return[e.slice(0,t),e.slice(t+1)]}));if(r.get(`inline`)!==`1`)return null;let i=Uint8Array.from(atob(e.slice(n+1)),e=>e.charCodeAt(0)),a=await createImageBitmap(new Blob([i])),o=HO(r.get(`width`),t.width,t.cellWidth),s=HO(r.get(`height`),t.height,t.cellHeight),c=[a.width,a.height];if(!o&&!s){let e=Math.min(t.width/a.width,(t.height-t.cellHeight)/a.height);e<1&&(c=[a.width*e,a.height*e])}else c=o?r.get(`preserveAspectRatio`)!==`0`||!s?[o,a.height*o/a.width]:[o,s]:[a.width*s/a.height,s];let[l,u]=c.map(e=>Math.max(1,Math.floor(e*t.pixelRatio))),d=await createImageBitmap(a,{resizeWidth:l,resizeHeight:u});return a.close(),d}function WO(e){let t=jO(e),{width:n,height:r,depth:i,channels:a}=t,o=n*r,s=new Uint8Array(o*4);if(t.palette){let e=kO(t),i=t.palette[0].length;for(let t=0;t<o;t+=1)s.set(e.subarray(t*i,t*i+3),t*4),s[t*4+3]=i===4?e[t*i+3]:255;return{width:n,height:r,data:s}}let c=2**i-1,l=Math.ceil(n*i/8);function u(e){if(i>=8)return t.data[e];let r=e%n*i;return t.data[Math.floor(e/n)*l+(r>>3)]>>8-i-(r&7)&c}function d(e){return i===16?e>>8:i===8?e:Math.round(e*255/c)}let f=t.transparency;for(let e=0;e<o;e+=1){let t=e*4;if(a===1||a===2){let n=u(e*a);s.fill(d(n),t,t+3),s[t+3]=a===2?d(u(e*2+1)):f?.[0]===n?0:255}else if(a===3||a===4){let n=u(e*a),r=u(e*a+1),i=u(e*a+2);s[t]=d(n),s[t+1]=d(r),s[t+2]=d(i),s[t+3]=a===4?d(u(e*4+3)):f?.[0]===n&&f[1]===r&&f[2]===i?0:255}else throw Error(`unsupported PNG with ${a} channels`)}return{width:n,height:r,data:s}}var GO=class{core;images=[];nextImage=0;constructor(e){this.core=e}place(e,t,n){let r=`${BO}${this.nextImage++}`;this.core.write(zO.encode(`\x1b]8;;${r}\x1b\\ \x1b]8;;\x1b\\\b`));let i={ref:this.core.trackCursor(),marker:r,bitmap:e,width:e.width/t,height:e.height/t,alternate:this.core.isAlternateScreen()};if(this.images.push(i),this.images.length>RO){let e=this.images.shift();e&&this.remove(e)}let a=Math.ceil(i.height/n);a>1&&this.core.write(zO.encode(`\x1BD`.repeat(a-1)))}visible(e,t,n){if(this.images.length===0)return[];let r=this.core.isAlternateScreen(),i=[],a=[];for(let o of this.images){if(o.alternate!==r){a.push(o);continue}let s=this.core.trackedPoint(o.ref);if(s===null||this.core.trackedHyperlink(o.ref)!==o.marker){this.remove(o);continue}a.push(o);let c=s.y-e;c+Math.ceil(o.height/n)<=0||c>=t||i.push({bitmap:o.bitmap,width:o.width,height:o.height,x:s.x,y:c})}return this.images=a,i}clear(){for(let e of this.images)this.remove(e);this.images=[]}remove(e){this.core.untrack(e.ref),e.bitmap.close()}},KO=new Uint8Array([0,97,115,109,1,0,0,0,1,35,5,96,4,127,127,127,127,0,96,3,127,127,127,1,127,96,2,127,127,0,96,3,127,127,127,0,96,5,127,127,127,127,127,1,127,2,49,6,3,101,110,118,1,119,0,0,3,101,110,118,1,100,0,1,3,101,110,118,1,115,0,1,3,101,110,118,1,98,0,2,3,101,110,118,1,118,0,3,3,101,110,118,1,112,0,4,7,25,6,1,119,0,0,1,100,0,1,1,115,0,2,1,98,0,3,1,118,0,4,1,112,0,5]),qO={userdata:0,writePty:1,bell:2,xtversion:4,size:6,deviceAttributes:8},JO=1,YO=-3,XO={width:0,height:4,data:8,length:12},ZO=new TextDecoder,QO=new TextEncoder,$O=class e{memory;layouts;exports;memoryView;hosts=new Map;nextHostId=1;callbacks={writePty:0,deviceAttributes:0,size:0,bell:0,xtversion:0};version={pointer:0,size:0};constructor(e){this.exports=e.exports;let t=e.exports.memory;if(!(t instanceof WebAssembly.Memory))throw Error(`libghostty-vt did not export its memory`);this.memory=t,this.memoryView=new DataView(t.buffer);let n=this.call(`ghostty_type_json`),r=new Uint8Array(t.buffer),i=n;for(;i<r.length&&r[i]!==0;)i+=1;this.layouts=JSON.parse(ZO.decode(r.subarray(n,i)))}static async load(){let t=await fetch(eD);if(!t.ok)throw Error(`could not load libghostty-vt (${t.status})`);let n=null,r=await WebAssembly.instantiate(await t.arrayBuffer(),{env:{log:(e,t)=>{n&&console.debug(`[libghostty-vt]`,ZO.decode(new Uint8Array(n.buffer,e,t)))}}}),i=new e(r.instance);return n=i.memory,i.installCallbacks(),i}call(e,...t){let n=this.exports[e];if(typeof n!=`function`)throw Error(`libghostty-vt export is missing: ${e}`);return n(...t)}layout(e){let t=this.layouts[e];if(!t)throw Error(`libghostty-vt layout is missing: ${e}`);return t}field(e,t){let n=this.layout(e).fields[t];if(!n)throw Error(`libghostty-vt field is missing: ${e}.${t}`);return n}alloc(e){let t=this.call(`ghostty_wasm_alloc_u8_array`,e);if(t===0)throw Error(`libghostty-vt could not allocate ${e} bytes`);return new Uint8Array(this.memory.buffer,t,e).fill(0),t}free(e,t){e!==0&&this.call(`ghostty_wasm_free_u8_array`,e,t)}allocOpaque(){let e=this.call(`ghostty_wasm_alloc_opaque`);if(e===0)throw Error(`libghostty-vt could not allocate a pointer`);return new DataView(this.memory.buffer).setUint32(e,0,!0),e}freeOpaque(e){e!==0&&this.call(`ghostty_wasm_free_opaque`,e)}readPointer(e){return this.dataView().getUint32(e,!0)}check(e,t){if(t!==0)throw Error(`${e} failed with result ${t}`)}flag(e,t,n){let r=this.alloc(1),i=this.call(e,t,n,r),a=this.bytes(r,1)[0];return this.free(r,1),i===0&&a!==0}encodeOutput(e){let t=this.call(`ghostty_wasm_alloc_usize`),n=``,r=e(0,0,t),i=this.view(t,4).getUint32(0,!0);if(r===YO&&i>0){let r=this.alloc(i),a=e(r,i,t),o=this.view(t,4).getUint32(0,!0);a===0&&(n=ZO.decode(this.bytes(r,o))),this.free(r,i)}return this.call(`ghostty_wasm_free_usize`,t),n}attachHost(e,t){let n=this.nextHostId++;this.hosts.set(n,t),this.call(`ghostty_terminal_set`,e,qO.userdata,n);for(let t of[[qO.writePty,this.callbacks.writePty],[qO.deviceAttributes,this.callbacks.deviceAttributes],[qO.size,this.callbacks.size],[qO.bell,this.callbacks.bell],[qO.xtversion,this.callbacks.xtversion]])this.call(`ghostty_terminal_set`,e,t[0],t[1]);return n}detachHost(e,t){this.call(`ghostty_terminal_set`,e,qO.xtversion,0),this.call(`ghostty_terminal_set`,e,qO.bell,0),this.call(`ghostty_terminal_set`,e,qO.size,0),this.call(`ghostty_terminal_set`,e,qO.deviceAttributes,0),this.call(`ghostty_terminal_set`,e,qO.writePty,0),this.call(`ghostty_terminal_set`,e,qO.userdata,0),this.hosts.delete(t)}view(e,t){return new DataView(this.memory.buffer,e,t)}bytes(e,t){return new Uint8Array(this.memory.buffer,e,t)}dataView(){return this.memoryView.buffer!==this.memory.buffer&&(this.memoryView=new DataView(this.memory.buffer)),this.memoryView}setField(e,t,n,r){let i=this.field(t,n),a=this.dataView(),o=e+i.offset;if(i.type===`bool`||i.type===`u8`)a.setUint8(o,r);else if(i.type===`u16`)a.setUint16(o,r,!0);else if(i.type===`i32`)a.setInt32(o,r,!0);else if(i.type===`u32`||i.type===`enum`)a.setUint32(o,r,!0);else if(i.type===`u64`)a.setBigUint64(o,BigInt(r),!0);else throw Error(`unsupported libghostty-vt field type ${i.type}`)}readField(e,t,n){let r=this.field(t,n),i=this.dataView(),a=e+r.offset;if(r.type===`bool`||r.type===`u8`)return i.getUint8(a);if(r.type===`u16`)return i.getUint16(a,!0);if(r.type===`i32`)return i.getInt32(a,!0);if(r.type===`u32`||r.type===`enum`)return i.getUint32(a,!0);if(r.type===`u64`)return Number(i.getBigUint64(a,!0));throw Error(`unsupported libghostty-vt field type ${r.type}`)}installCallbacks(){let e=new WebAssembly.Instance(new WebAssembly.Module(KO),{env:{w:(e,t,n,r)=>{let i=this.hosts.get(t);i&&r!==0&&i.write(ZO.decode(new Uint8Array(this.memory.buffer,n,r)))},d:(e,t,n)=>this.hosts.has(t)?(this.writeDeviceAttributes(n),1):0,s:(e,t,n)=>{let r=this.hosts.get(t);if(!r)return 0;let i=r.size(),a=`GhosttySizeReportSize`;return this.setField(n,a,`rows`,i.rows),this.setField(n,a,`columns`,i.columns),this.setField(n,a,`cell_width`,i.cellWidth),this.setField(n,a,`cell_height`,i.cellHeight),1},b:(e,t)=>{this.hosts.get(t)?.bell()},v:(e,t,n)=>{let r=this.hosts.get(n);r&&this.writeVersion(e,r.version())},p:(e,t,n,r,i)=>this.decodePng(t,n,r,i)}}),t=this.exports.__indirect_function_table;if(!(t instanceof WebAssembly.Table))throw Error(`libghostty-vt did not expose its callback table`);let n=[`w`,`d`,`s`,`b`,`v`,`p`].map(n=>{let r=e.exports[n];if(typeof r!=`function`)throw Error(`libghostty-vt callback is missing: ${n}`);let i=t.length;return t.grow(1),t.set(i,r),i});if(this.callbacks={writePty:n[0],deviceAttributes:n[1],size:n[2],bell:n[3],xtversion:n[4]},this.call(`ghostty_sys_set`,JO,n[5])!==0)throw Error(`libghostty-vt did not accept the PNG decoder`)}decodePng(e,t,n,r){let i;try{i=WO(new Uint8Array(this.memory.buffer,t,n))}catch(e){return console.warn(`could not decode a kitty PNG image`,e),0}let a=this.call(`ghostty_alloc`,e,i.data.length);if(a===0)return 0;this.bytes(a,i.data.length).set(i.data);let o=this.dataView();return o.setUint32(r+XO.width,i.width,!0),o.setUint32(r+XO.height,i.height,!0),o.setUint32(r+XO.data,a,!0),o.setUint32(r+XO.length,i.data.length,!0),1}writeVersion(e,t){let n=QO.encode(t);this.free(this.version.pointer,this.version.size);let r=this.alloc(n.length);this.bytes(r,n.length).set(n),this.version={pointer:r,size:n.length},this.dataView().setUint32(e+this.field(`GhosttyString`,`ptr`).offset,r,!0),this.setField(e,`GhosttyString`,`len`,n.length)}writeDeviceAttributes(e){let t=e+this.field(`GhosttyDeviceAttributes`,`primary`).offset,n=e+this.field(`GhosttyDeviceAttributes`,`secondary`).offset,r=e+this.field(`GhosttyDeviceAttributes`,`tertiary`).offset,i=`GhosttyDeviceAttributesPrimary`,a=`GhosttyDeviceAttributesSecondary`,o=t+this.field(i,`features`).offset,s=this.dataView(),c=[4,22];c.forEach((e,t)=>s.setUint16(o+t*2,e,!0)),this.setField(t,i,`conformance_level`,62),this.setField(t,i,`num_features`,c.length),this.setField(n,a,`device_type`,0),this.setField(n,a,`firmware_version`,276),this.setField(n,a,`rom_cartridge`,0),this.setField(r,`GhosttyDeviceAttributesTertiary`,`unit_id`,0)}},ek=null;async function tk(){ek=await $O.load()}function nk(){if(!ek)throw Error(`libghostty-vt is not loaded`);return ek}var rk=new Map(`Unidentified.Backquote.Backslash.BracketLeft.BracketRight.Comma.Digit0.Digit1.Digit2.Digit3.Digit4.Digit5.Digit6.Digit7.Digit8.Digit9.Equal.IntlBackslash.IntlRo.IntlYen.KeyA.KeyB.KeyC.KeyD.KeyE.KeyF.KeyG.KeyH.KeyI.KeyJ.KeyK.KeyL.KeyM.KeyN.KeyO.KeyP.KeyQ.KeyR.KeyS.KeyT.KeyU.KeyV.KeyW.KeyX.KeyY.KeyZ.Minus.Period.Quote.Semicolon.Slash.AltLeft.AltRight.Backspace.CapsLock.ContextMenu.ControlLeft.ControlRight.Enter.MetaLeft.MetaRight.ShiftLeft.ShiftRight.Space.Tab.Convert.KanaMode.NonConvert.Delete.End.Help.Home.Insert.PageDown.PageUp.ArrowDown.ArrowLeft.ArrowRight.ArrowUp.NumLock.Numpad0.Numpad1.Numpad2.Numpad3.Numpad4.Numpad5.Numpad6.Numpad7.Numpad8.Numpad9.NumpadAdd.NumpadBackspace.NumpadClear.NumpadClearEntry.NumpadComma.NumpadDecimal.NumpadDivide.NumpadEnter.NumpadEqual.NumpadMemoryAdd.NumpadMemoryClear.NumpadMemoryRecall.NumpadMemoryStore.NumpadMemorySubtract.NumpadMultiply.NumpadParenLeft.NumpadParenRight.NumpadSubtract.NumpadSeparator.NumpadArrowUp.NumpadArrowDown.NumpadArrowRight.NumpadArrowLeft.NumpadBegin.NumpadHome.NumpadEnd.NumpadInsert.NumpadDelete.NumpadPageUp.NumpadPageDown.Escape.F1.F2.F3.F4.F5.F6.F7.F8.F9.F10.F11.F12.F13.F14.F15.F16.F17.F18.F19.F20.F21.F22.F23.F24.F25.Fn.FnLock.PrintScreen.ScrollLock.Pause.BrowserBack.BrowserFavorites.BrowserForward.BrowserHome.BrowserRefresh.BrowserSearch.BrowserStop.Eject.LaunchApp1.LaunchApp2.LaunchMail.MediaPlayPause.MediaSelect.MediaStop.MediaTrackNext.MediaTrackPrevious.Power.Sleep.AudioVolumeDown.AudioVolumeMute.AudioVolumeUp.WakeUp.Copy.Cut.Paste`.split(`.`).map((e,t)=>[e,t]));function ik(e){return rk.get(e)??0}var ak=new Map([[`!`,`1`],[`@`,`2`],[`#`,`3`],[`$`,`4`],[`%`,`5`],[`^`,`6`],[`&`,`7`],[`*`,`8`],[`(`,`9`],[`)`,`0`],[`~`,"`"],[`_`,`-`],[`+`,`=`],[`{`,`[`],[`}`,`]`],[`|`,`\\`],[`:`,`;`],[`"`,`'`],[`<`,`,`],[`>`,`.`],[`?`,`/`]]),ok;function sk(){return ok||(ok=globalThis.navigator?.keyboard?.getLayoutMap().catch(()=>void 0)??Promise.resolve(void 0),ok)}function ck(){return ok=void 0,sk()}function lk(e){return!e.shiftKey||e.ctrlKey||e.altKey||e.metaKey?0:+([...e.key].length===1)}function uk(e,t){if([...e.key].length!==1)return 0;let n=t?.get(e.code);if(n&&[...n].length===1)return n.codePointAt(0)??0;if(/^[A-Z]$/u.test(e.key))return e.key.charCodeAt(0)+32;if(e.shiftKey){let t=ak.get(e.key);if(t)return t.codePointAt(0)??0;let n=e.key.toLowerCase();return n!==e.key&&[...n].length===1?n.codePointAt(0)??0:0}return e.key.codePointAt(0)??0}var dk=new Map([[`Backquote`,"`"],[`Minus`,`-`],[`Equal`,`=`],[`BracketLeft`,`[`],[`BracketRight`,`]`],[`Backslash`,`\\`],[`Semicolon`,`;`],[`Quote`,`'`],[`Comma`,`,`],[`Period`,`.`],[`Slash`,`/`],[`Space`,` `]]),fk=[...`0123456789`].map(e=>[`Digit${e}`,e]),pk=new Map([...ak].map(e=>[e[1],e[0]]));function mk(e){return/^Key[A-Z]$/u.test(e)?e[3].toLowerCase():/^Digit[0-9]$/u.test(e)?e[5]:dk.get(e)}function hk(e){return[...dk,...fk].every(t=>t[0]===`Space`||e.get(t[0])===t[1])}function gk(e,t){let n=t?.get(e.code),r=n&&[...n].length===1?n:mk(e.code);if(r===void 0)return[...e.key].length===1?null:e.key;if(!e.shiftKey)return r;let i=r.toUpperCase();return i!==r&&[...i].length===1?i:t===void 0||!hk(t)?null:pk.get(r)??r}var _k=new TextEncoder,vk=new Map([[`[`,`\x1B`],[`m`,`\r`],[`i`,` `],[`@`,`\0`]]),yk=class{runtime=nk();terminal;keyEncoderSlot;keyEncoder;keyEventSlot;keyEvent;mouseEncoderSlot;mouseEncoder;mouseEventSlot;mouseEvent;scratch;keyboardLayoutMap;constructor(e){let t=this.runtime;this.terminal=e,this.loadKeyboardLayout(sk()),this.keyEncoderSlot=t.allocOpaque(),t.check(`ghostty_key_encoder_new`,t.call(`ghostty_key_encoder_new`,0,this.keyEncoderSlot)),this.keyEncoder=t.readPointer(this.keyEncoderSlot),this.keyEventSlot=t.allocOpaque(),t.check(`ghostty_key_event_new`,t.call(`ghostty_key_event_new`,0,this.keyEventSlot)),this.keyEvent=t.readPointer(this.keyEventSlot),this.mouseEncoderSlot=t.allocOpaque(),t.check(`ghostty_mouse_encoder_new`,t.call(`ghostty_mouse_encoder_new`,0,this.mouseEncoderSlot)),this.mouseEncoder=t.readPointer(this.mouseEncoderSlot),this.mouseEventSlot=t.allocOpaque(),t.check(`ghostty_mouse_event_new`,t.call(`ghostty_mouse_event_new`,0,this.mouseEventSlot)),this.mouseEvent=t.readPointer(this.mouseEventSlot),this.scratch=t.alloc(1)}encodeKey(e,t=`press`,n=!1){let r=this.runtime,i=e.key.toLowerCase(),a=vk.get(i);if(a!==void 0&&t===`press`&&e.ctrlKey&&!e.altKey&&!e.metaKey&&!(e.shiftKey&&/^[a-z]$/u.test(i))&&!r.flag(`ghostty_terminal_get`,this.terminal,8))return a;let o=n?this.metaText(e):null,s=o??e.key;if(o!==null&&t===`press`&&!e.ctrlKey&&[...s].length===1&&(s.codePointAt(0)??0)>127&&r.flag(`ghostty_terminal_mode_get`,this.terminal,1036)&&this.isLegacyKeyboard())return`\x1b${s}`;r.call(`ghostty_key_encoder_setopt_from_terminal`,this.keyEncoder,this.terminal),r.call(`ghostty_key_event_set_action`,this.keyEvent,t===`release`?0:e.repeat?2:1),r.call(`ghostty_key_event_set_key`,this.keyEvent,ik(e.code));let c=+!!e.shiftKey|(e.ctrlKey?2:0)|(e.altKey?4:0)|(e.metaKey?8:0)|(e.getModifierState(`CapsLock`)?16:0)|(e.getModifierState(`NumLock`)?32:0);r.call(`ghostty_key_event_set_mods`,this.keyEvent,c),r.call(`ghostty_key_event_set_consumed_mods`,this.keyEvent,lk(e)),r.call(`ghostty_key_event_set_composing`,this.keyEvent,+!!e.isComposing),r.call(`ghostty_key_event_set_unshifted_codepoint`,this.keyEvent,uk({code:e.code,key:s,shiftKey:e.shiftKey},this.keyboardLayoutMap));let l=_k.encode(s.length===1?s:``),u=l.length===0?0:r.alloc(l.length);u!==0&&r.bytes(u,l.length).set(l),r.call(`ghostty_key_event_set_utf8`,this.keyEvent,u,l.length);let d=r.encodeOutput((e,t,n)=>r.call(`ghostty_key_encoder_encode`,this.keyEncoder,this.keyEvent,e,t,n));return u!==0&&r.free(u,l.length),d}metaText(e){return gk(e,this.keyboardLayoutMap)}refreshKeyboardLayout(){this.loadKeyboardLayout(ck())}encodePaste(e){let t=this.runtime,n=_k.encode(e);if(n.length===0)return``;let r=t.alloc(n.length);t.bytes(r,n.length).set(n);let i=+!!t.flag(`ghostty_terminal_mode_get`,this.terminal,2004),a=t.encodeOutput((e,a,o)=>t.call(`ghostty_paste_encode`,r,n.length,i,e,a,o));return t.free(r,n.length),a}encodeMouse(e){let t=this.runtime;t.call(`ghostty_mouse_encoder_setopt_from_terminal`,this.mouseEncoder,this.terminal);let n=t.layout(`GhosttyMouseEncoderSize`),r=t.alloc(n.size);for(let i of[[`size`,n.size],[`screen_width`,e.screenWidth],[`screen_height`,e.screenHeight],[`cell_width`,e.cellWidth],[`cell_height`,e.cellHeight],[`padding_top`,0],[`padding_bottom`,0],[`padding_right`,0],[`padding_left`,0]])t.setField(r,`GhosttyMouseEncoderSize`,i[0],Math.max(0,Math.round(i[1])));t.call(`ghostty_mouse_encoder_setopt`,this.mouseEncoder,2,r),t.free(r,n.size),t.bytes(this.scratch,1)[0]=+!!e.anyButtonPressed,t.call(`ghostty_mouse_encoder_setopt`,this.mouseEncoder,3,this.scratch),t.bytes(this.scratch,1)[0]=1,t.call(`ghostty_mouse_encoder_setopt`,this.mouseEncoder,4,this.scratch),t.call(`ghostty_mouse_event_set_action`,this.mouseEvent,{press:0,release:1,motion:2}[e.action]),e.button===null?t.call(`ghostty_mouse_event_clear_button`,this.mouseEvent):t.call(`ghostty_mouse_event_set_button`,this.mouseEvent,e.button),t.call(`ghostty_mouse_event_set_mods`,this.mouseEvent,e.mods);let i=t.layout(`GhosttyMousePosition`),a=t.alloc(i.size),o=t.view(a,i.size);return o.setFloat32(t.field(`GhosttyMousePosition`,`x`).offset,e.x,!0),o.setFloat32(t.field(`GhosttyMousePosition`,`y`).offset,e.y,!0),t.call(`ghostty_mouse_event_set_position`,this.mouseEvent,a),t.free(a,i.size),t.encodeOutput((e,n,r)=>t.call(`ghostty_mouse_encoder_encode`,this.mouseEncoder,this.mouseEvent,e,n,r))}dispose(){let e=this.runtime;e.call(`ghostty_mouse_event_free`,this.mouseEvent),e.call(`ghostty_mouse_encoder_free`,this.mouseEncoder),e.call(`ghostty_key_event_free`,this.keyEvent),e.call(`ghostty_key_encoder_free`,this.keyEncoder),e.free(this.scratch,1),e.freeOpaque(this.mouseEventSlot),e.freeOpaque(this.mouseEncoderSlot),e.freeOpaque(this.keyEventSlot),e.freeOpaque(this.keyEncoderSlot)}async loadKeyboardLayout(e){this.keyboardLayoutMap=await e}isLegacyKeyboard(){return this.encodeKey(new KeyboardEvent(`keydown`,{key:`Tab`,code:`Tab`,shiftKey:!0}))===`\x1B[Z`}},bk=26,xk=30,Sk=1,Ck={imageId:1,placementId:2,isVirtual:3,xOffset:4,yOffset:5,columns:10,rows:11,z:12},wk={width:3,height:4,format:5,data:7,length:8},Tk={size:48,pixelWidth:4,pixelHeight:8,column:20,row:24,visible:28,sourceX:32,sourceY:36,sourceWidth:40,sourceHeight:44},Ek=new Map([[0,3],[1,4],[3,2],[4,1]]),Dk=new Map([773,781,782,784,786,829,830,831,838,842,843,844,848,849,850,855,859,867,868,869,870,871,872,873,874,875,876,877,878,879,1155,1156,1157,1158,1159,1426,1427,1428,1429,1431,1432,1433,1436,1437,1438,1439,1440,1441,1448,1449,1451,1452,1455,1476,1552,1553,1554,1555,1556,1557,1558,1559,1623,1624,1625,1626,1627,1629,1630,1750,1751,1752,1753,1754,1755,1756,1759,1760,1761,1762,1764,1767,1768,1771,1772,1840,1842,1843,1845,1846,1850,1853,1855,1856,1857,1859,1861,1863,1865,1866,2027,2028,2029,2030,2031,2032,2033,2035,2070,2071,2072,2073,2075,2076,2077,2078,2079,2080,2081,2082,2083,2085,2086,2087,2089,2090,2091,2092,2093,2385,2387,2388,3970,3971,3974,3975,4957,4958,4959,6109,6458,6679,6773,6774,6775,6776,6777,6778,6779,6780,7019,7021,7022,7023,7024,7025,7026,7027,7376,7377,7378,7386,7387,7392,7616,7617,7619,7620,7621,7622,7623,7624,7625,7627,7628,7633,7634,7635,7636,7637,7638,7639,7640,7641,7642,7643,7644,7645,7646,7647,7648,7649,7650,7651,7652,7653,7654,7678,8400,8401,8404,8405,8406,8407,8411,8412,8417,8423,8425,8432,11503,11504,11505,11744,11745,11746,11747,11748,11749,11750,11751,11752,11753,11754,11755,11756,11757,11758,11759,11760,11761,11762,11763,11764,11765,11766,11767,11768,11769,11770,11771,11772,11773,11774,11775,42607,42620,42621,42736,42737,43232,43233,43234,43235,43236,43237,43238,43239,43240,43241,43242,43243,43244,43245,43246,43247,43248,43249,43696,43698,43699,43703,43704,43710,43711,43713,65056,65057,65058,65059,65060,65061,65062,68111,68152,119173,119174,119175,119176,119177,119210,119211,119212,119213,119362,119363,119364].map((e,t)=>[e,t]));function Ok(e,t,n){let r=Array.from(e).slice(1,4).map(e=>Dk.get(e.codePointAt(0)??0)??null),i=r[2]??null;return{imageId:t,placementId:n,row:r[0]??null,column:r[1]??null,imageIdHigh:i!==null&&i<256?i:null}}function kk(e){let t=[];for(let n=0;n<e.length;n+=1){let r=e[n].cells,i=null;for(let e=0;e<r.length;e+=1){let a=r[e].placeholder;i!==null&&a!==null&&a.imageId===i.imageId&&a.placementId===i.placementId&&(a.row===null||a.row===i.row)&&(a.column===null||a.column===i.column+i.width)&&(a.imageIdHigh===null||a.imageIdHigh===i.imageIdHigh)?i.width+=1:(i!==null&&t.push(Ak(i)),i=a===null?null:{x:e,y:n,imageId:a.imageId,imageIdHigh:a.imageIdHigh,placementId:a.placementId,row:a.row??0,column:a.column??0,width:1})}i!==null&&t.push(Ak(i))}return t}function Ak(e){return{x:e.x,y:e.y,imageId:e.imageId+(e.imageIdHigh??0)*2**24,placementId:e.placementId,row:e.row,column:e.column,width:e.width}}function jk(e,t,n,r){let i=t.columns===0?Math.ceil(n.width/r.width):t.columns,a=t.rows===0?Math.ceil(n.height/r.height):t.rows,o=i*r.width,s=a*r.height,c=n.width*s>n.height*o,l=c?o/Math.max(n.width,1):s/Math.max(n.height,1),u=c?0:(o-n.width*l)/2/l,d=c?(s-n.height*l)/2/l:0,f=n.width+u*2,p=n.height+d*2,m={x:f*e.column/i,y:p*e.row/a,width:f*e.width/i,height:p/a},h=0,g=0,_=e.width*r.width,v=r.height;if(m.y<d){let e=d-m.y;m.height-=e,g=e,v-=e*l,m.y=0,m.height>n.height&&(m.height=n.height,v=n.height*l)}else m.y+m.height>p-d?(m.y-=d,m.height=p-d-m.y-d,v=m.height*l):m.y-=d;if(m.x<u){let e=u-m.x;m.width-=e,h=e,_-=e*l,m.x=0,m.width>n.width&&(m.width=n.width,_=n.width*l)}else m.x+m.width>f-u?(m.x-=u,m.width=f-u-m.x-u,_=m.width*l):m.x-=u;if(m.width<=0||m.height<=0)return null;let y={xOffset:Math.round(h*l),yOffset:Math.round(g*l),width:Math.round(_),height:Math.round(v),source:{x:Math.round(m.x),y:Math.round(m.y),width:Math.round(m.width),height:Math.round(m.height)}};return y.width===0||y.height===0?null:y}function Mk(e){let t=nk(),n=t.alloc(16),r=t.call(`ghostty_terminal_get`,e,bk,n);return t.free(n,16),r===0}var Nk=class{runtime=nk();terminal;iteratorSlot;info;scratch;tail=[0,0];commands=0;cachedCommands=0;bitmaps=new Map;constructor(e){let t=this.runtime;this.terminal=e,this.iteratorSlot=t.allocOpaque(),t.check(`ghostty_kitty_graphics_placement_iterator_new`,t.call(`ghostty_kitty_graphics_placement_iterator_new`,0,this.iteratorSlot)),this.info=t.alloc(Tk.size),this.scratch=t.alloc(16)}note(e){let t=[...this.tail,...e.subarray(0,2)],n=t.some((e,n)=>e===27&&t[n+1]===95&&t[n+2]===71),r=e.indexOf(27);for(;!n&&r!==-1;)n=e[r+1]===95&&e[r+2]===71,r=e.indexOf(27,r+1);n&&(this.commands+=1),this.tail=[...this.tail,...e.subarray(-2)].slice(-2)}images(e,t){this.commands!==this.cachedCommands&&(this.cachedCommands=this.commands,this.bitmaps.clear());let n=new Map,r=this.placements(e,t).map(e=>{let t=n.get(e.key)??this.bitmaps.get(e.key)??Ik(e.image);return n.set(e.key,t),{placement:e,bitmap:t}});return this.bitmaps=n,r}dispose(){let e=this.runtime;e.call(`ghostty_kitty_graphics_placement_iterator_free`,e.readPointer(this.iteratorSlot)),e.free(this.info,Tk.size),e.free(this.scratch,16),e.freeOpaque(this.iteratorSlot),this.bitmaps.clear()}placements(e,t){let n=this.runtime;n.check(`ghostty_terminal_get`,n.call(`ghostty_terminal_get`,this.terminal,xk,this.scratch));let r=n.readPointer(this.scratch);n.check(`ghostty_kitty_graphics_get`,n.call(`ghostty_kitty_graphics_get`,r,Sk,this.iteratorSlot));let i=n.readPointer(this.iteratorSlot),a=[],o=[];for(;n.call(`ghostty_kitty_graphics_placement_next`,i);){let e=this.placementU32(i,Ck.imageId);if(this.placementData(i,Ck.isVirtual).getUint8(0)){o.push({imageId:e,placementId:this.placementU32(i,Ck.placementId),columns:this.placementU32(i,Ck.columns),rows:this.placementU32(i,Ck.rows)});continue}let t=n.call(`ghostty_kitty_graphics_image`,r,e);if(t===0)throw Error(`kitty placement points to missing image ${e}`);n.bytes(this.info,Tk.size).fill(0);let s=n.view(this.info,Tk.size);s.setUint32(0,Tk.size,!0),n.check(`ghostty_kitty_graphics_placement_render_info`,n.call(`ghostty_kitty_graphics_placement_render_info`,i,t,this.terminal,this.info)),s.getUint8(Tk.visible)!==0&&a.push({...this.image(t,e),z:this.placementData(i,Ck.z).getInt32(0,!0),column:s.getInt32(Tk.column,!0),row:s.getInt32(Tk.row,!0),xOffset:this.placementU32(i,Ck.xOffset),yOffset:this.placementU32(i,Ck.yOffset),width:s.getUint32(Tk.pixelWidth,!0),height:s.getUint32(Tk.pixelHeight,!0),source:{x:s.getUint32(Tk.sourceX,!0),y:s.getUint32(Tk.sourceY,!0),width:s.getUint32(Tk.sourceWidth,!0),height:s.getUint32(Tk.sourceHeight,!0)}})}if(o.length===0)return a;for(let i of kk(e)){let e=o.find(e=>e.imageId===i.imageId&&(i.placementId===0||e.placementId===i.placementId));if(e===void 0)continue;let s=n.call(`ghostty_kitty_graphics_image`,r,i.imageId);if(s===0)continue;let c=this.image(s,i.imageId),l=jk(i,e,c.image,t);l!==null&&a.push({...c,...l,z:-1,column:i.x,row:i.y})}return a}image(e,t){let n=this.imageData(e,wk.data),r=this.imageData(e,wk.length);return{key:`${t}:${n}:${r}`,image:{width:this.imageData(e,wk.width),height:this.imageData(e,wk.height),format:this.imageData(e,wk.format),pixels:this.runtime.bytes(n,r)}}}placementData(e,t){return this.runtime.bytes(this.scratch,4).fill(0),this.runtime.check(`ghostty_kitty_graphics_placement_get`,this.runtime.call(`ghostty_kitty_graphics_placement_get`,e,t,this.scratch)),this.runtime.view(this.scratch,4)}placementU32(e,t){return this.placementData(e,t).getUint32(0,!0)}imageData(e,t){return this.runtime.bytes(this.scratch,4).fill(0),this.runtime.check(`ghostty_kitty_graphics_image_get`,this.runtime.call(`ghostty_kitty_graphics_image_get`,e,t,this.scratch)),this.runtime.view(this.scratch,4).getUint32(0,!0)}};function Pk(e,t,n,r,i){let a=r.width/i.width,o=r.height/i.height;for(let i of t){let t=i.placement;Fk(t.z)===n&&e.drawImage(i.bitmap,t.source.x,t.source.y,t.source.width,t.source.height,t.column*r.width+t.xOffset*a,t.row*r.height+t.yOffset*o,t.width*a,t.height*o)}}function Fk(e){return e<-1073741824?`belowBackground`:e<0?`belowText`:`aboveText`}function Ik(e){let t=Ek.get(e.format);if(t===void 0)throw Error(`unsupported kitty image format ${e.format}`);let n=e.width*e.height,r=e.pixels,i=new Uint8ClampedArray(n*4);if(t===4)i.set(r.subarray(0,n*4));else for(let e=0;e<n;e+=1){let n=e*t,a=e*4;t===3?i.set(r.subarray(n,n+3),a):i.fill(r[n],a,a+3),i[a+3]=t===2?r[n+1]:255}let a=new OffscreenCanvas(e.width,e.height),o=a.getContext(`2d`);if(!o)throw Error(`could not create a canvas for a kitty image`);return o.putImageData(new ImageData(i,e.width,e.height),0,0),a}var Lk=8,Rk=16,zk=0,Bk=1,Vk=2,Hk=8,Uk={cols:1,rows:2,dirty:3,rowIterator:4,background:5,foreground:6,cursor:7,cursorHasValue:8,cursorStyle:10,cursorVisible:11,cursorBlinking:12,cursorInViewport:14,cursorX:15,cursorY:16},Wk={dirty:1,raw:2,cells:3},Gk={raw:1,style:2,graphemesLength:3,graphemes:4,background:5,foreground:6,selected:7},Kk={keys:0,values:20,graphemesLength:40,selected:44,background:48,foreground:52,written:56,size:60},qk={narrow:0,wide:1,spacerTail:2},Jk={r:229,g:231,b:235},Yk={r:0,g:0,b:0};function Xk(e,t){return Math.floor((e*155+t*100)/255)}function Zk(e,t){return{r:Xk(e.r,t.r),g:Xk(e.g,t.g),b:Xk(e.b,t.b)}}function Qk(e,t){let n=``;for(let r=0;r<t;r+=4096){let i=Math.min(4096,t-r),a=Array(i);for(let t=0;t<i;t+=1)a[t]=e.getUint32((r+t)*4,!0);n+=String.fromCodePoint(...a)}return n}function $k(e,t){return{text:``,wide:0,foreground:e,background:t,bold:!1,italic:!1,invisible:!1,strikethrough:!1,overline:!1,underline:0,underlineColor:null,selected:!1,placeholder:null}}function eA(e,t){let n=e.dataView();return{r:n.getUint8(t),g:n.getUint8(t+1),b:n.getUint8(t+2)}}function tA(e,t){let n=e.alloc(768);e.call(`ghostty_terminal_get`,t,21,n);let r=e.bytes(n,768),i=Array.from({length:256},(e,t)=>({r:r[t*3],g:r[t*3+1],b:r[t*3+2]}));return e.free(n,768),i}function nA(e,t){let n=[],r=[];return e.cells.forEach((e,i)=>{if(e.wide!==2)for(let a of(e.text||` `).split(``))n.push(a),r.push({x:i,y:t})}),{text:n.join(``),points:r}}var rA=class{runtime=nk();stateSlot;state;rowIteratorSlot;rowCellsSlot;scratch;style;cellQuery;graphemes=0;graphemeCapacity=0;rows=[];palette=[];constructor(){let e=this.runtime;this.stateSlot=e.allocOpaque(),e.check(`ghostty_render_state_new`,e.call(`ghostty_render_state_new`,0,this.stateSlot)),this.state=e.readPointer(this.stateSlot),this.rowIteratorSlot=e.allocOpaque(),e.check(`ghostty_render_state_row_iterator_new`,e.call(`ghostty_render_state_row_iterator_new`,0,this.rowIteratorSlot)),this.rowCellsSlot=e.allocOpaque(),e.check(`ghostty_render_state_row_cells_new`,e.call(`ghostty_render_state_row_cells_new`,0,this.rowCellsSlot)),this.scratch=e.alloc(16),this.style=e.alloc(e.layout(`GhosttyStyle`).size),this.cellQuery=e.alloc(Kk.size);let t=e.dataView();[[Gk.style,this.style],[Gk.graphemesLength,this.cellQuery+Kk.graphemesLength],[Gk.selected,this.cellQuery+Kk.selected],[Gk.background,this.cellQuery+Kk.background],[Gk.foreground,this.cellQuery+Kk.foreground]].forEach((e,n)=>{t.setUint32(this.cellQuery+Kk.keys+n*4,e[0],!0),t.setUint32(this.cellQuery+Kk.values+n*4,e[1],!0)})}snapshot(e,t){let n=this.runtime;n.check(`ghostty_render_state_update`,n.call(`ghostty_render_state_update`,this.state,e));let r=this.getRender(Uk.cols,2),i=this.getRender(Uk.rows,2),a=this.getRender(Uk.dirty,4),o=this.getColor(Uk.foreground,Jk),s=this.getColor(Uk.background,Yk),c=this.getRender(Uk.cursorHasValue,1)===0?o:this.getColor(Uk.cursor,o),l=this.getRender(Uk.cursorInViewport,1)!==0,u=this.getRender(Uk.cursorVisible,1)!==0&&l;(this.rows.length!==i||this.rows.some(e=>e.cells.length!==r))&&(this.rows=Array.from({length:i},()=>({cells:Array.from({length:r},()=>$k(o,s)),isWrapContinuation:!1,wrapsToNext:!1})));let d=new Set;if(a!==0){this.palette=tA(n,e),n.check(`ghostty_render_state_get`,n.call(`ghostty_render_state_get`,this.state,Uk.rowIterator,this.rowIteratorSlot));let c=n.readPointer(this.rowIteratorSlot),l=0;for(;l<i&&n.call(`ghostty_render_state_row_iterator_next`,c)!==0;)(a===2||this.getRowFlag(c,Wk.dirty))&&(this.rows[l]=this.readRow(c,r,o,s,t),d.add(l),n.bytes(this.scratch,1)[0]=0,n.call(`ghostty_render_state_row_set`,c,0,this.scratch)),l+=1;n.view(this.scratch,4).setUint32(0,0,!0),n.call(`ghostty_render_state_set`,this.state,0,this.scratch)}return{cols:r,rows:i,foreground:o,background:s,cursor:c,cursorX:l?this.getRender(Uk.cursorX,2):-1,cursorY:l?this.getRender(Uk.cursorY,2):-1,cursorVisible:u,cursorBlinking:this.getRender(Uk.cursorBlinking,1)!==0,cursorStyle:this.getRender(Uk.cursorStyle,4),dirtyRows:d,rowData:this.rows}}invalidate(){this.rows=[]}dispose(){let e=this.runtime,t=e.readPointer(this.rowCellsSlot);t&&e.call(`ghostty_render_state_row_cells_free`,t);let n=e.readPointer(this.rowIteratorSlot);n&&e.call(`ghostty_render_state_row_iterator_free`,n),e.call(`ghostty_render_state_free`,this.state),e.free(this.style,e.layout(`GhosttyStyle`).size),e.free(this.cellQuery,Kk.size),e.free(this.scratch,16),e.free(this.graphemes,this.graphemeCapacity),e.freeOpaque(this.rowCellsSlot),e.freeOpaque(this.rowIteratorSlot),e.freeOpaque(this.stateSlot)}readRow(e,t,n,r,i){let a=this.runtime;a.check(`ghostty_render_state_row_get`,a.call(`ghostty_render_state_row_get`,e,Wk.raw,this.scratch));let o=a.view(this.scratch,8).getBigUint64(0,!0);a.bytes(this.scratch+8,1)[0]=0,a.call(`ghostty_row_get`,o,2,this.scratch+8);let s=a.bytes(this.scratch+8,1)[0]!==0;a.bytes(this.scratch+8,1)[0]=0,a.call(`ghostty_row_get`,o,1,this.scratch+8);let c=a.bytes(this.scratch+8,1)[0]!==0;a.check(`ghostty_render_state_row_get`,a.call(`ghostty_render_state_row_get`,e,Wk.cells,this.rowCellsSlot));let l=a.readPointer(this.rowCellsSlot),u=a.layout(`GhosttyStyle`),d=u.size,f=u.fields,p=[];for(;p.length<t&&a.call(`ghostty_render_state_row_cells_next`,l)!==0;){a.bytes(this.style,d).fill(0),a.setField(this.style,`GhosttyStyle`,`size`,d);let e=a.call(`ghostty_render_state_row_cells_get_multi`,l,5,this.cellQuery+Kk.keys,this.cellQuery+Kk.values,this.cellQuery+Kk.written),t=a.dataView(),o=t.getUint32(this.cellQuery+Kk.written,!0);o<3&&a.check(`ghostty_render_state_row_cells_get_multi`,e);let s=t.getUint32(this.cellQuery+Kk.graphemesLength,!0),c=t.getUint8(this.cellQuery+Kk.selected)!==0,u=o>=4?eA(a,this.cellQuery+Kk.background):r,m=o===5?eA(a,this.cellQuery+Kk.foreground):o===3?this.getCellColor(l,n):n,h=``;if(s>0){let e=s*4;if(e>this.graphemeCapacity){let t=Math.max(e,this.graphemeCapacity*2),n=a.alloc(t);a.free(this.graphemes,this.graphemeCapacity),this.graphemes=n,this.graphemeCapacity=t}a.call(`ghostty_render_state_row_cells_get`,l,Gk.graphemes,this.graphemes)===0&&(h=Qk(a.view(this.graphemes,e),s))}let g=0;if(h.length===0&&p.at(-1)?.text.length){a.call(`ghostty_render_state_row_cells_get`,l,Gk.raw,this.scratch);let e=a.view(this.scratch,8).getBigUint64(0,!0);a.view(this.scratch+8,4).setUint32(0,0,!0),a.call(`ghostty_cell_get`,e,3,this.scratch+8),g=a.view(this.scratch+8,4).getUint32(0,!0)}let _=a.dataView(),v=e=>_.getUint8(this.style+f[e].offset)!==0,y=v(`bold`);if(i&&y&&_.getUint32(this.style+Lk,!0)===Bk){let e=_.getUint8(this.style+Rk);e<8&&(m=this.palette[e+8]??m)}if(v(`inverse`)){let e=m;m=u,u=e}v(`faint`)&&(m=Zk(m,u));let b=this.style+f.underline_color.offset,x=_.getUint32(b,!0),S=b+Hk,C=null;h.codePointAt(0)===1109742&&(C=Ok(h,this.colorId(this.style+Lk),this.colorId(b)),h=``),p.push({text:h,wide:g,foreground:m,background:u,bold:y,italic:v(`italic`),invisible:v(`invisible`),strikethrough:v(`strikethrough`),overline:v(`overline`),underline:_.getInt32(this.style+f.underline.offset,!0),underlineColor:x===Bk?this.palette[_.getUint8(S)]:x===Vk?eA(a,S):null,selected:c,placeholder:C})}for(;p.length<t;)p.push($k(n,r));return{cells:p,isWrapContinuation:s,wrapsToNext:c}}getRender(e,t){this.runtime.bytes(this.scratch,4).fill(0),this.runtime.check(`ghostty_render_state_get`,this.runtime.call(`ghostty_render_state_get`,this.state,e,this.scratch));let n=this.runtime.view(this.scratch,4);return t===1?n.getUint8(0):t===2?n.getUint16(0,!0):n.getUint32(0,!0)}getColor(e,t){return this.runtime.bytes(this.scratch,3).fill(0),this.runtime.call(`ghostty_render_state_get`,this.state,e,this.scratch)===0?eA(this.runtime,this.scratch):t}getRowFlag(e,t){return this.runtime.bytes(this.scratch,1)[0]=0,this.runtime.call(`ghostty_render_state_row_get`,e,t,this.scratch)===0&&this.runtime.bytes(this.scratch,1)[0]!==0}getCellColor(e,t){return this.runtime.bytes(this.scratch,3).fill(0),this.runtime.call(`ghostty_render_state_row_cells_get`,e,Gk.foreground,this.scratch)===0?eA(this.runtime,this.scratch):t}colorId(e){let t=this.runtime.dataView(),n=t.getUint32(e,!0);if(n===zk)return 0;if(n===Bk)return t.getUint8(e+Hk);if(n===Vk){let t=eA(this.runtime,e+Hk);return t.r<<16|t.g<<8|t.b}throw Error(`unknown style color tag ${n}`)}},iA=16,aA=589824,oA=381888,sA=5e7,cA=new TextDecoder;function lA(e){let t=[...e],n=[0,95,135,175,215,255];for(let e=16;e<232;e+=1){let r=e-16;t.push({r:n[Math.floor(r/36)],g:n[Math.floor(r/6)%6],b:n[r%6]})}for(let e=0;e<24;e+=1){let n=8+e*10;t.push({r:n,g:n,b:n})}return t}var uA=class{encoder;kitty;runtime=nk();terminalSlot;terminal;renderState;formatterSlot;formatter;scratch;point;scrollbar;host;hostId=0;sizeReport;disposed=!1;boldIsBright=!1;version=``;constructor(e,t,n,r,i){let a=this.runtime,o=a.layout(`GhosttyTerminalOptions`).size,s=a.alloc(o);a.setField(s,`GhosttyTerminalOptions`,`cols`,e),a.setField(s,`GhosttyTerminalOptions`,`rows`,t);let c=Math.floor(oA/(8*(e+1)));a.setField(s,`GhosttyTerminalOptions`,`max_scrollback`,n===0?0:Math.min((Math.ceil(n/c)+1)*aA,sA)),this.terminalSlot=a.allocOpaque();let l=a.call(`ghostty_terminal_new`,0,this.terminalSlot,s);if(a.free(s,o),a.check(`ghostty_terminal_new`,l),this.terminal=a.readPointer(this.terminalSlot),!Mk(this.terminal))throw a.call(`ghostty_terminal_free`,this.terminal),a.freeOpaque(this.terminalSlot),Error(`libghostty-vt was built without kitty graphics, build it with scripts/build-ghostty-wasm.mts`);this.sizeReport={rows:t,columns:e,cellWidth:1,cellHeight:1},this.host={write:r,size:()=>this.sizeReport,bell:i,version:()=>this.version},this.hostId=a.attachHost(this.terminal,this.host),this.renderState=new rA,this.encoder=new yk(this.terminal),this.kitty=new Nk(this.terminal);let u=`GhosttyFormatterTerminalOptions`,d=a.layout(u),f=a.alloc(d.size),p=a.field(u,`extra`),m=a.field(`GhosttyFormatterTerminalExtra`,`screen`);a.setField(f,u,`size`,d.size),a.setField(f,u,`trim`,1),a.setField(f+p.offset,`GhosttyFormatterTerminalExtra`,`size`,p.size),a.setField(f+p.offset+m.offset,`GhosttyFormatterScreenExtra`,`size`,m.size),this.formatterSlot=a.allocOpaque();let h=a.call(`ghostty_formatter_terminal_new`,0,this.formatterSlot,this.terminal,f);a.free(f,d.size),a.check(`ghostty_formatter_terminal_new`,h),this.formatter=a.readPointer(this.formatterSlot),this.scratch=a.alloc(16),this.point=a.alloc(a.layout(`GhosttyPoint`).size),this.scrollbar=a.alloc(a.layout(`GhosttyTerminalScrollbar`).size)}write(e){if(e.length===0)return;this.kitty.note(e);let t=this.runtime.alloc(e.length);this.runtime.bytes(t,e.length).set(e),this.runtime.call(`ghostty_terminal_vt_write`,this.terminal,t,e.length),this.runtime.free(t,e.length)}setReplies(e){e&&this.hostId===0?this.hostId=this.runtime.attachHost(this.terminal,this.host):!e&&this.hostId!==0&&(this.runtime.detachHost(this.terminal,this.hostId),this.hostId=0)}reset(){this.runtime.call(`ghostty_terminal_reset`,this.terminal),this.renderState.invalidate()}resize(e,t,n,r,i){this.sizeReport={rows:t,columns:e,cellWidth:Math.max(1,Math.round(n*i)),cellHeight:Math.max(1,Math.round(r*i))},this.runtime.check(`ghostty_terminal_resize`,this.runtime.call(`ghostty_terminal_resize`,this.terminal,Math.max(1,Math.min(65535,e)),Math.max(1,Math.min(65535,t)),this.sizeReport.cellWidth,this.sizeReport.cellHeight))}setColors(e){let t=this.runtime.alloc(3);for(let n of[[11,e.foreground],[12,e.background],[13,e.cursor]]){let e=n[1];this.runtime.bytes(t,3).set([e.r,e.g,e.b]),this.runtime.call(`ghostty_terminal_set`,this.terminal,n[0],t)}this.runtime.free(t,3);let n=lA(e.palette),r=this.runtime.alloc(n.length*3);this.runtime.bytes(r,n.length*3).set(n.flatMap(e=>[e.r,e.g,e.b])),this.runtime.call(`ghostty_terminal_set`,this.terminal,14,r),this.runtime.free(r,n.length*3),this.renderState.invalidate()}setCursor(e,t){let n={bar:0,block:1,underline:2}[e];this.runtime.view(this.scratch,4).setUint32(0,n,!0),this.runtime.call(`ghostty_terminal_set`,this.terminal,22,this.scratch),this.runtime.bytes(this.scratch,1)[0]=+!!t,this.runtime.call(`ghostty_terminal_set`,this.terminal,23,this.scratch)}title(){if(this.runtime.bytes(this.scratch,8).fill(0),this.runtime.call(`ghostty_terminal_get`,this.terminal,12,this.scratch)!==0)return``;let e=this.runtime.view(this.scratch,8),t=e.getUint32(0,!0),n=e.getUint32(4,!0);return n===0?``:cA.decode(this.runtime.bytes(t,n))}screenText(){let e=this.runtime.alloc(8),t=this.runtime.call(`ghostty_formatter_format_alloc`,this.formatter,0,e,e+4),n=this.runtime.view(e,8),r=n.getUint32(0,!0),i=n.getUint32(4,!0);if(this.runtime.free(e,8),t!==0)return``;let a=cA.decode(this.runtime.bytes(r,i));return this.runtime.call(`ghostty_free`,0,r,i),a}scroll(e){let t=this.runtime.layout(`GhosttyTerminalScrollViewport`),n=this.runtime.alloc(t.size);this.runtime.setField(n,`GhosttyTerminalScrollViewport`,`tag`,2);let r=this.runtime.field(`GhosttyTerminalScrollViewport`,`value`);this.runtime.view(n+r.offset,r.size).setInt32(0,e,!0),this.runtime.call(`ghostty_terminal_scroll_viewport`,this.terminal,n),this.runtime.free(n,t.size)}scrollToBottom(){let e=this.runtime.layout(`GhosttyTerminalScrollViewport`),t=this.runtime.alloc(e.size);this.runtime.setField(t,`GhosttyTerminalScrollViewport`,`tag`,1),this.runtime.call(`ghostty_terminal_scroll_viewport`,this.terminal,t),this.runtime.free(t,e.size)}scrollbarState(){let e=this.runtime.layout(`GhosttyTerminalScrollbar`);return this.runtime.bytes(this.scrollbar,e.size).fill(0),this.runtime.call(`ghostty_terminal_get`,this.terminal,9,this.scrollbar)===0?{total:this.runtime.readField(this.scrollbar,`GhosttyTerminalScrollbar`,`total`),offset:this.runtime.readField(this.scrollbar,`GhosttyTerminalScrollbar`,`offset`),len:this.runtime.readField(this.scrollbar,`GhosttyTerminalScrollbar`,`len`)}:null}isMouseTracking(){return this.flag(`ghostty_terminal_get`,11)}isMouseAnyEventTracking(){return this.flag(`ghostty_terminal_mode_get`,1003)}isFocusReporting(){return this.flag(`ghostty_terminal_mode_get`,1004)}isSynchronizedOutput(){return this.flag(`ghostty_terminal_mode_get`,2026)}endSynchronizedOutput(){this.runtime.check(`ghostty_terminal_mode_set`,this.runtime.call(`ghostty_terminal_mode_set`,this.terminal,2026,0))}currentColors(){return{foreground:this.terminalColor(18),background:this.terminalColor(19),cursor:this.terminalColor(20),palette:tA(this.runtime,this.terminal)}}isApplicationCursorKeys(){return this.flag(`ghostty_terminal_mode_get`,1)}isKittyKeyboard(){return this.flag(`ghostty_terminal_get`,8)}isAlternateScreen(){return this.runtime.dataView().setUint32(this.scratch,0,!0),this.runtime.call(`ghostty_terminal_get`,this.terminal,6,this.scratch)===0&&this.runtime.dataView().getUint32(this.scratch,!0)===1}setSelection(e,t){let n=this.runtime.layout(`GhosttyGridRef`).size,r=this.gridRef(e.x,e.y,2);try{let e=this.gridRef(t.x,t.y,2),i=this.runtime.layout(`GhosttySelection`),a=this.runtime.alloc(i.size);this.runtime.setField(a,`GhosttySelection`,`size`,i.size);let o=this.runtime.field(`GhosttySelection`,`start`),s=this.runtime.field(`GhosttySelection`,`end`);this.runtime.bytes(a+o.offset,o.size).set(this.runtime.bytes(r,o.size)),this.runtime.bytes(a+s.offset,s.size).set(this.runtime.bytes(e,s.size)),this.runtime.call(`ghostty_terminal_set`,this.terminal,21,a),this.runtime.free(e,n),this.runtime.free(a,i.size)}finally{this.runtime.free(r,n)}}selectWord(e){return this.selectAt(`GhosttyTerminalSelectWordOptions`,`ghostty_terminal_select_word`,e)}selectLine(e){return this.selectAt(`GhosttyTerminalSelectLineOptions`,`ghostty_terminal_select_line`,e)}clearSelection(){this.runtime.call(`ghostty_terminal_set`,this.terminal,21,0)}selectionText(){let e=this.runtime.alloc(iA),t=this.runtime.view(e,iA);t.setUint32(0,iA,!0),t.setUint8(8,1),t.setUint8(9,1);let n=this.runtime.encodeOutput((t,n,r)=>this.runtime.call(`ghostty_terminal_selection_format_buf`,this.terminal,e,t,n,r));return this.runtime.free(e,iA),n}hyperlinkAt(e,t){let n=this.gridRef(e,t,1),r=this.hyperlinkOf(n);return this.runtime.free(n,this.runtime.layout(`GhosttyGridRef`).size),r}toScreen(e){let t=this.gridRef(e.x,e.y,1),n=this.pointFromGridRef(t,2);return this.runtime.free(t,this.runtime.layout(`GhosttyGridRef`).size),n}trackCursor(){let e=this.runtime.allocOpaque(),t=this.runtime.call(`ghostty_terminal_grid_ref_track`,this.terminal,this.cursorPoint(),e),n=this.runtime.readPointer(e);return this.runtime.freeOpaque(e),this.runtime.check(`ghostty_terminal_grid_ref_track`,t),n}retrack(e){let t=this.runtime.call(`ghostty_tracked_grid_ref_set`,e,this.terminal,this.cursorPoint());this.runtime.check(`ghostty_tracked_grid_ref_set`,t)}trackedPoint(e){return this.runtime.call(`ghostty_tracked_grid_ref_point`,e,2,this.scratch)===0?{x:this.runtime.readField(this.scratch,`GhosttyPointCoordinate`,`x`),y:this.runtime.readField(this.scratch,`GhosttyPointCoordinate`,`y`)}:null}trackedHyperlink(e){let t=this.runtime.layout(`GhosttyGridRef`).size,n=this.runtime.alloc(t);this.runtime.setField(n,`GhosttyGridRef`,`size`,t);let r=this.runtime.call(`ghostty_tracked_grid_ref_snapshot`,e,n)===0?this.hyperlinkOf(n):null;return this.runtime.free(n,t),r}untrack(e){this.runtime.call(`ghostty_tracked_grid_ref_free`,e)}snapshot(){return this.renderState.snapshot(this.terminal,this.boldIsBright)}invalidate(){this.renderState.invalidate()}cellSize(){return{width:this.sizeReport.cellWidth,height:this.sizeReport.cellHeight}}dispose(){if(this.disposed)return;this.disposed=!0;let e=this.runtime;e.call(`ghostty_formatter_free`,this.formatter),this.encoder.dispose(),this.kitty.dispose(),this.renderState.dispose(),this.hostId!==0&&e.detachHost(this.terminal,this.hostId),e.call(`ghostty_terminal_free`,this.terminal),e.free(this.scrollbar,e.layout(`GhosttyTerminalScrollbar`).size),e.free(this.scratch,16),e.free(this.point,e.layout(`GhosttyPoint`).size),e.freeOpaque(this.formatterSlot),e.freeOpaque(this.terminalSlot)}hyperlinkOf(e){let t=this.runtime.encodeOutput((t,n,r)=>this.runtime.call(`ghostty_grid_ref_hyperlink_uri`,e,t,n,r));return t===``?null:t}cursorPosition(){this.runtime.dataView().setUint32(this.scratch,0,!0),this.runtime.call(`ghostty_terminal_get`,this.terminal,3,this.scratch),this.runtime.call(`ghostty_terminal_get`,this.terminal,4,this.scratch+2);let e=this.runtime.dataView();return{x:e.getUint16(this.scratch,!0),y:e.getUint16(this.scratch+2,!0)}}cursorPoint(){let e=this.cursorPosition();return this.fillPoint(this.point,e.x,e.y,0),this.point}fillPoint(e,t,n,r){this.runtime.setField(e,`GhosttyPoint`,`tag`,r);let i=this.runtime.field(`GhosttyPoint`,`value`),a=this.runtime.dataView();a.setUint16(e+i.offset,Math.max(0,t),!0),a.setUint32(e+i.offset+4,Math.max(0,n),!0)}gridRef(e,t,n){let r=this.runtime.alloc(this.runtime.layout(`GhosttyPoint`).size);this.fillPoint(r,e,t,n);let i=this.runtime.layout(`GhosttyGridRef`).size,a=this.runtime.alloc(i);this.runtime.setField(a,`GhosttyGridRef`,`size`,i);let o=this.runtime.call(`ghostty_terminal_grid_ref`,this.terminal,r,a);return this.runtime.free(r,this.runtime.layout(`GhosttyPoint`).size),o!==0&&(this.runtime.free(a,i),this.runtime.check(`ghostty_terminal_grid_ref`,o)),a}selectAt(e,t,n){let r=this.gridRef(n.x,n.y,2),i=this.runtime.layout(e),a=this.runtime.layout(`GhosttySelection`),o=this.runtime.alloc(i.size),s=this.runtime.alloc(a.size);this.runtime.setField(o,e,`size`,i.size);let c=this.runtime.field(e,`ref`);this.runtime.bytes(o+c.offset,c.size).set(this.runtime.bytes(r,c.size)),this.runtime.setField(s,`GhosttySelection`,`size`,a.size);let l=null;if(this.runtime.call(t,this.terminal,o,s)===0){let e=this.pointFromGridRef(s+this.runtime.field(`GhosttySelection`,`start`).offset,2),t=this.pointFromGridRef(s+this.runtime.field(`GhosttySelection`,`end`).offset,2);e&&t&&(l={start:e,end:t})}return this.runtime.free(s,a.size),this.runtime.free(r,this.runtime.layout(`GhosttyGridRef`).size),this.runtime.free(o,i.size),l}pointFromGridRef(e,t){let n=this.runtime.layout(`GhosttyPointCoordinate`),r=this.runtime.alloc(n.size),i=this.runtime.call(`ghostty_terminal_point_from_grid_ref`,this.terminal,e,t,r)===0?{x:this.runtime.readField(r,`GhosttyPointCoordinate`,`x`),y:this.runtime.readField(r,`GhosttyPointCoordinate`,`y`)}:null;return this.runtime.free(r,n.size),i}flag(e,t){return this.runtime.flag(e,this.terminal,t)}terminalColor(e){return this.runtime.bytes(this.scratch,3).fill(0),this.runtime.check(`ghostty_terminal_get`,this.runtime.call(`ghostty_terminal_get`,this.terminal,e,this.scratch)),eA(this.runtime,this.scratch)}};function dA(e,t){let n=[],r=e.toLowerCase(),i=t.toLowerCase(),a=r.indexOf(i);for(;a!==-1;)n.push(a),a=r.indexOf(i,a+i.length);return n}var fA=class{core;redraw;listeners=new Set;query=``;matches=[];activeMatch=-1;stale=!1;timer=null;constructor(e,t){this.core=e,this.redraw=t}find(e,t,n,r){let i=this.matches[this.activeMatch]??null;if(this.query=e,this.refresh(),this.matches.length===0)this.activeMatch=-1;else if(n||i===null){let e=i?.row??r,t=this.matches.findIndex(t=>t.row>=e);this.activeMatch=t===-1?this.matches.length-1:t}else{let e=this.matches.findIndex(e=>e.row===i.row&&e.index===i.index),n=e===-1?0:e,r=t?-1:1;this.activeMatch=(n+r+this.matches.length)%this.matches.length}return this.emit(),this.matches[this.activeMatch]??null}onResults(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}clear(){this.query=``,this.matches=[],this.activeMatch=-1}outputChanged(){this.query!==``&&(this.stale=!0,this.timer===null&&(this.timer=window.setTimeout(()=>{if(this.timer=null,!this.stale||this.query===``)return;let e=this.matches[this.activeMatch];this.refresh();let t=e?this.matches.findIndex(t=>t.row===e.row&&t.index===e.index):-1;this.activeMatch=t===-1?this.matches.length-1:t,this.emit(),this.redraw()},200)))}highlights(e,t){if(this.query===``)return[];let n=this.matches[this.activeMatch],r=[];return e.rowData.forEach((e,i)=>{let a=nA(e,i);dA(a.text,this.query).forEach((e,o)=>{let s=a.points[e],c=a.points[e+this.query.length-1];s&&c&&r.push({row:i,start:s.x,end:c.x+1,active:n?.row===t+i&&n.index===o})})}),r}dispose(){this.timer!==null&&window.clearTimeout(this.timer),this.timer=null}refresh(){this.stale=!1,this.matches=[],this.query!==``&&this.core.screenText().split(`
|
|
13
13
|
`).forEach((e,t)=>{dA(e,this.query).forEach((e,n)=>this.matches.push({row:t,index:n}))})}emit(){let e={resultIndex:this.activeMatch,resultCount:this.matches.length};for(let t of this.listeners)t(e)}},pA=new TextDecoder;function mA(e){function t(e){return e.toString(16).padStart(2,`0`).repeat(2)}return`rgb:${t(e.r)}/${t(e.g)}/${t(e.b)}`}function hA(e){return Math.min(Math.max(e,0),100)}function gA(e){return pA.decode(Uint8Array.from(atob(e),e=>e.charCodeAt(0)))}function _A(e){return e===``?`s0`:[...e].filter(e=>`cpqs01234567`.includes(e)).join(``)}function vA(e){try{return gA(e)}catch(e){return console.warn(`invalid clipboard sequence`,e),null}}function yA(e,t,n){let r=Array.from(new TextEncoder().encode(e),e=>String.fromCharCode(e)).join(``);return`\x1b]52;${t};${btoa(r)}${n}`}function bA(e,t,n){let r=e===`10;?`?t.foreground:e===`11;?`?t.background:t.cursor;return`\x1b]${e.slice(0,2)};${mA(r)}${n}`}function xA(e,t,n){let r=e.split(`;`),i=[];for(let e=1;e+1<r.length;e+=2){if(r[e+1]!==`?`||!/^\d+$/.test(r[e]))continue;let a=t[Number(r[e])];a!==void 0&&i.push(`\x1b]4;${r[e]};${mA(a)}${n}`)}return i}function SA(e,t){let n=e.split(`;`);if(n.length>4)return null;let r=n[2]===void 0||n[2]===``?0:Number(n[2]),i=n[3]===void 0||n[3]===``?-1:Number(n[3]);return!Number.isInteger(r)||!Number.isInteger(i)?null:r===0?{state:r,value:0}:r===1?i<0?null:{state:r,value:hA(i)}:r===2||r===4?i<0?{state:r,value:t.value}:{state:r,value:hA(i||t.value)}:r===3?{state:r,value:t.value}:null}function CA(e,t){if(e.startsWith(`9;`)&&!/^9;\d+(;|$)/.test(e))return{title:``,body:pA.decode(t.subarray(2))};if(e.startsWith(`777;notify;`)){let e=pA.decode(t).split(`;`);return{title:e[2]??``,body:e.slice(3).join(`;`)}}return null}var wA=class{pending={id:``,title:``,body:``};add(e){let t=e.indexOf(`;`,3);if(t===-1)return null;let n=new Map;for(let r of e.slice(3,t).split(`:`)){let e=r.indexOf(`=`);e!==-1&&n.set(r.slice(0,e),r.slice(e+1))}let r=n.get(`p`)??`title`;if(r===`?`||r===`close`||r===`alive`)return null;let i=e.slice(t+1);if(n.get(`e`)===`1`)try{i=gA(i)}catch(e){return console.warn(`invalid notification sequence`,e),null}let a=n.get(`i`)??``;if(a!==this.pending.id&&(this.pending={id:a,title:``,body:``}),r===`title`&&(this.pending.title+=i),r===`body`&&(this.pending.body+=i),n.get(`d`)===`0`)return null;let o=this.pending;return this.pending={id:``,title:``,body:``},o.title===``&&o.body===``?null:{title:o.title,body:o.body}}},TA=27,EA=7,DA=24,OA=26,kA=33554432,AA=class{state=`ground`;params=``;collecting=!1;chunks=[];size=0;reset(){this.state=`ground`,this.drop()}scan(e,t){let n=0;for(let r=0;r<e.length;r+=1){let i=e[r];if(i===DA||i===OA)this.state=`ground`,this.drop();else if(this.state===`ground`)i===TA&&(this.state=`escape`);else if(this.state===`escape`){if(this.params=``,i===93){this.state=`osc`,this.begin(),n=r+1;continue}if(i===80){this.state=`dcsHeader`;continue}this.state=i===TA?`escape`:`ground`}else if(this.state===`osc`){if(i===EA){if(this.state=`ground`,this.append(e,n,r),t({type:`osc`,data:this.take(),terminator:`\x07`},r+1))return r+1;continue}i===TA&&(this.state=`oscEscape`,this.append(e,n,r))}else if(this.state===`oscEscape`){if(i===92){if(this.state=`ground`,t({type:`osc`,data:this.take(),terminator:`\x1B\\`},r+1))return r+1;continue}this.drop(),this.state=`escape`,--r}else if(this.state===`dcsHeader`){if(i===TA){this.state=`dcsEscape`;continue}if(i>=32&&i<=63){this.params.length<16&&(this.params+=String.fromCharCode(i));continue}this.state=`dcs`,i===113&&/^[0-9;]*$/.test(this.params)&&(this.begin(),n=r+1)}else if(this.state===`dcs`)i===TA&&(this.state=`dcsEscape`,this.append(e,n,r));else if(i===92){if(this.state=`ground`,this.collecting&&t({type:`sixel`,data:this.take()},r+1))return r+1}else this.drop(),this.state=`escape`,--r}return(this.state===`osc`||this.state===`dcs`)&&this.append(e,n,e.length),e.length}begin(){this.collecting=!0,this.chunks=[],this.size=0}append(e,t,n){!this.collecting||n<=t||(this.size+n-t>kA?this.drop():(this.chunks.push(e.slice(t,n)),this.size+=n-t))}take(){let e=new Uint8Array(this.size),t=0;for(let n of this.chunks)e.set(n,t),t+=n.length;return this.drop(),e}drop(){this.collecting=!1,this.chunks=[],this.size=0}},jA=`0101.0202.1010.2020.........0110.0210.0120.0220.0011.0012.0021.0022.1100.1200.2100.2200.1001.1002.2001.2002.1110.1210.2110.1120.2120.2210.1220.2220.1011.1012.2011.1021.2021.2012.1022.2022.0111.0112.0211.0212.0121.0122.0221.0222.1101.1102.1201.1202.2101.2102.2201.2202.1111.1112.1211.1212.2111.1121.2121.2112.2211.1122.1221.2212.1222.2122.2221.2222`.split(`.`),MA=[`0001`,`1000`,`0100`,`0010`,`0002`,`2000`,`0200`,`0020`,`0201`,`1020`,`0102`,`2010`],NA=`0303.3030.0310.0130.0330.0013.0031.0033.1300.3100.3300.1003.3001.3003.1310.3130.3330.1013.3031.3033.0313.0131.0333.1303.3101.3303.1313.3131.3333`.split(`.`),PA=[0,0,4,4],FA=[4,0,4,4],IA=[0,4,4,4],LA=[4,4,4,4],RA=[[[0,0,8,4]],[[0,7,8,1]],[[0,6,8,2]],[[0,5,8,3]],[[0,4,8,4]],[[0,3,8,5]],[[0,2,8,6]],[[0,1,8,7]],[[0,0,8,8]],[[0,0,7,8]],[[0,0,6,8]],[[0,0,5,8]],[[0,0,4,8]],[[0,0,3,8]],[[0,0,2,8]],[[0,0,1,8]],[[4,0,4,8]],[],[],[],[[0,0,8,1]],[[7,0,1,8]],[IA],[LA],[PA],[PA,IA,LA],[PA,LA],[PA,FA,IA],[PA,FA,LA],[FA],[FA,IA],[FA,IA,LA]],zA={9617:.25,9618:.5,9619:.75},BA={9581:[1,1],9582:[-1,1],9583:[-1,-1],9584:[1,-1]};function VA(e){return e>=9472&&e<=9547?jA[e-9472]:e>=9552&&e<=9580?NA[e-9552]:e>=9588&&e<=9599?MA[e-9588]:``}function HA(e){if(e.length!==1)return!1;let t=e.charCodeAt(0);return VA(t)!==``||BA[t]!==void 0||t>=9600&&t<=9631}function UA(e){return Math.max(1,Math.round(e.height/20))}function WA(e,t,n){let[r,i,a,o]=t,s=UA(n),c=s*2,l=Math.floor(Math.max(0,n.height-s)/2),u=l+s,d=Math.floor(Math.max(0,n.height-c)/2),f=d+c,p=Math.max(0,l-s),m=u+s,h=Math.floor(Math.max(0,n.width-s)/2),g=h+s,_=Math.floor(Math.max(0,n.width-c)/2),v=_+c,y=Math.max(0,h-s),b=g+s;function x(t,r,i,a){e.fillRect(n.left+t,n.top+r,i-t,a-r)}let S=o===`2`||i===`2`?f:o!==i||a===r?o===`3`||i===`3`?m:u:o===`0`&&i===`0`?u:l,C=o===`2`||i===`2`?d:o!==i||r===a?o===`3`||i===`3`?p:l:o===`0`&&i===`0`?l:u,w=r===`2`||a===`2`?v:r!==a||o===i?r===`3`||a===`3`?b:g:r===`0`&&a===`0`?g:h,T=r===`2`||a===`2`?_:r!==a||i===o?r===`3`||a===`3`?y:h:r===`0`&&a===`0`?h:g;r===`1`&&x(h,0,g,S),r===`2`&&x(_,0,v,S),r===`3`&&(x(y,0,h,o===`3`?l:S),x(g,0,b,i===`3`?l:S)),i===`1`&&x(T,l,n.width,u),i===`2`&&x(T,d,n.width,f),i===`3`&&(x(r===`3`?g:T,p,n.width,l),x(a===`3`?g:T,u,n.width,m)),a===`1`&&x(h,C,g,n.height),a===`2`&&x(_,C,v,n.height),a===`3`&&(x(y,o===`3`?u:C,h,n.height),x(g,i===`3`?u:C,b,n.height)),o===`1`&&x(0,l,w,u),o===`2`&&x(0,d,w,f),o===`3`&&(x(0,p,r===`3`?h:w,l),x(0,u,a===`3`?h:w,m))}function GA(e,[t,n],r){let i=UA(r),a=r.left+Math.floor(Math.max(0,r.width-i)/2)+i/2,o=r.top+Math.floor(Math.max(0,r.height-i)/2)+i/2,s=t===1?r.left+r.width:r.left,c=n===1?r.top+r.height:r.top,l=Math.min(r.width,r.height)/2;e.save(),e.strokeStyle=e.fillStyle,e.lineWidth=i,e.beginPath(),e.moveTo(a,c),e.arcTo(a,o,s,o,l),e.lineTo(s,o),e.stroke(),e.restore()}function KA(e,t,n,r){e.save(),e.setTransform(1,0,0,1,0,0),qA(e,t.charCodeAt(0),{left:Math.round(n.left*r),top:Math.round(n.top*r),width:Math.round((n.left+n.width)*r)-Math.round(n.left*r),height:Math.round((n.top+n.height)*r)-Math.round(n.top*r)}),e.restore()}function qA(e,t,n){let r=VA(t);if(r!==``){WA(e,r,n);return}let i=BA[t];if(i!==void 0){GA(e,i,n);return}let a=zA[t];if(a!==void 0)e.globalAlpha=a,e.fillRect(n.left,n.top,n.width,n.height);else for(let[r,i,a,o]of RA[t-9600]){let t=n.left+Math.round(n.width*r/8),s=n.top+Math.round(n.height*i/8);e.fillRect(t,s,n.left+Math.round(n.width*(r+a)/8)-t,n.top+Math.round(n.height*(i+o)/8)-s)}}function JA(e){return`rgb(${e.r}, ${e.g}, ${e.b})`}function YA(e,t){return e.r===t.r&&e.g===t.g&&e.b===t.b}function XA(e,t){return Math.round(e*t)/t}function ZA(e,t,n,r){let i=XA(e*n.width,r);return{left:i,width:XA(t*n.width,r)-i}}function QA(e,t,n,r,i){let a=i-2,o=n+r;if(t===1)e.fillRect(n,a,r,1);else if(t===2)e.fillRect(n,a,r,1),e.fillRect(n,a-2,r,1);else if(t===3){function t(e){return a-1+Math.sin(e/3*Math.PI)*1.5}e.save(),e.strokeStyle=e.fillStyle,e.lineWidth=1,e.beginPath(),e.moveTo(n,t(n));for(let r=Math.floor(n)+1;r<o;r+=1)e.lineTo(r,t(r));e.lineTo(o,t(o)),e.stroke(),e.restore()}else if(t===4)for(let t=Math.ceil(n/2)*2;t<o;t+=2)e.fillRect(t,a,1,1);else if(t===5)for(let t=Math.floor(n/5)*5;t<o;t+=5){let r=Math.max(t,n),i=Math.min(t+3,o);i>r&&e.fillRect(r,a,i-r,1)}else throw Error(`unknown underline style ${t}`)}function $A(e,t){return e.selected===t.selected&&YA(e.foreground,t.foreground)&&e.bold===t.bold&&e.italic===t.italic&&e.invisible===t.invisible}function ej(e,t){return`${e.italic?`italic`:`normal`} ${e.bold?700:400} ${t.fontSize}px ${t.fontFamily}`}function tj(e,t,n,r,i){e.font=`normal 400 ${t}px ${n}`;let a=e.measureText(`M`).width,o=e.measureText(`Mg`),s=o.fontBoundingBoxAscent||t,c=s+o.fontBoundingBoxDescent,l=Math.max(1,Math.round(c*r*i))/i;return{width:Math.max(1,Math.round(a*i))/i,height:l,baseline:XA((l-c)/2+s,i),faceWidth:a}}function nj(e){return/^[!-/:-@[-`{-~]$/.test(e)}function rj(e,t,n){return!(e===null||t<e.start.y||t>e.end.y||t===e.start.y&&n<e.start.x||t===e.end.y&&n>e.end.x)}function ij(e){let{context:t,snapshot:n,metrics:r,appearance:i,cursorOn:a,previousCursorY:o,pixelRatio:s}=e,c=e.forceFull?Array.from({length:n.rows},(e,t)=>t):[...n.dirtyRows];o!==null&&!c.includes(o)&&c.push(o),n.cursorVisible&&n.cursorY>=0&&!c.includes(n.cursorY)&&c.push(n.cursorY),e.forceFull&&(t.save(),t.resetTransform(),t.fillStyle=JA(n.background),t.fillRect(0,0,t.canvas.width,t.canvas.height),t.restore());function l(e){let t=e*r.height,n=XA(t,s);return{top:t,cellTop:n,cellHeight:XA(t+r.height,s)-n}}t.textBaseline=`alphabetic`;for(let e of c){if(!n.rowData[e])continue;let{cellTop:r,cellHeight:i}=l(e);t.fillStyle=JA(n.background),t.fillRect(0,r,t.canvas.width,i)}e.drawLayer(`belowBackground`);for(let a of c){let o=n.rowData[a];if(!o)continue;let{cellTop:c,cellHeight:u}=l(a),d=0;for(;d<o.cells.length;){let e=o.cells[d],a=d+1;for(;a<o.cells.length&&o.cells[a].selected===e.selected&&YA(o.cells[a].background,e.background);)a+=1;let{left:l,width:f}=ZA(d,a,r,s);e.selected?(t.fillStyle=i.selectionBackground,t.fillRect(l,c,f,u)):YA(e.background,n.background)||(t.fillStyle=JA(e.background),t.fillRect(l,c,f,u)),d=a}for(let n of e.highlights){if(n.row!==a)continue;let{left:e,width:o}=ZA(n.start,n.end,r,s);t.fillStyle=i.matchBackground,t.fillRect(e,c,o,u),n.active&&(t.strokeStyle=i.activeMatchBorder,t.strokeRect(e+.5,c+.5,o-1,u-1))}}e.drawLayer(`belowText`);for(let a of c){let o=n.rowData[a];if(!o)continue;let{top:c,cellTop:u,cellHeight:d}=l(a);t.save(),t.beginPath(),t.rect(0,u,t.canvas.width,d),t.clip();for(let e=0;e<o.cells.length;e+=1){let n=o.cells[e];if(n.invisible||n.text.trim().length===0)continue;t.fillStyle=n.selected?i.selectionForeground:JA(n.foreground);let a=e*r.width;if(HA(n.text)){KA(t,n.text,{left:a,top:c,width:r.width,height:r.height},s);continue}t.font=ej(n,i);let l=a+(r.width-r.faceWidth)/2,u=e,d=e+1;if(i.ligatures&&nj(n.text)){for(;u>e-3&&u>0&&nj(o.cells[u-1].text)&&$A(o.cells[u-1],n);)--u;for(;d<e+4&&d<o.cells.length&&nj(o.cells[d].text)&&$A(o.cells[d],n);)d+=1}d-u===1?t.fillText(n.text,l,c+r.baseline):(t.save(),t.beginPath(),t.rect(a,c,r.width,r.height),t.clip(),t.fillText(o.cells.slice(u,d).map(e=>e.text).join(``),l-(e-u)*r.faceWidth,c+r.baseline),t.restore())}t.restore();for(let n=0;n<o.cells.length;n+=1){let i=o.cells[n],l=rj(e.hoveredLink,a,n);if(i.underline===0&&!i.strikethrough&&!i.overline&&!l)continue;let{left:f,width:p}=ZA(n,n+1,r,s),m=u+d;t.fillStyle=JA(i.foreground),i.strikethrough&&t.fillRect(f,c+Math.floor(r.height*.55),p,1),i.overline&&t.fillRect(f,u+1,p,1),i.underline===0?l&&QA(t,1,f,p,m):(i.underlineColor!==null&&(t.fillStyle=JA(i.underlineColor)),QA(t,i.underline,f,p,m))}}if(!a||!n.cursorVisible||n.cursorX<0||n.cursorY<0)return;let u=n.cursorY*r.height,d=XA(u,s),f=XA(u+r.height,s)-d,p=n.rowData[n.cursorY]?.cells,m=p?.[n.cursorX],h=p?.[n.cursorX+1]?.wide===qk.spacerTail?2:1,{left:g,width:_}=ZA(n.cursorX,n.cursorX+h,r,s);t.fillStyle=JA(n.cursor),t.strokeStyle=JA(n.cursor),!e.focused||n.cursorStyle===3?t.strokeRect(g+.5,d+.5,_-1,f-1):n.cursorStyle===0?t.fillRect(g,d,1,f):n.cursorStyle===2?t.fillRect(g,d+f-2,_,2):(t.fillRect(g,d,_,f),m?.text&&(t.fillStyle=i.cursorText,HA(m.text)?KA(t,m.text,{left:n.cursorX*r.width,top:u,width:r.width,height:r.height},s):(t.font=ej(m,i),t.fillText(m.text,n.cursorX*r.width+(r.width-r.faceWidth)/2,u+r.baseline))))}var aj=navigator.userAgent.includes(`Mac`),oj=500,sj=/https?:\/\/[^\s"'`<>]+/g;function cj(e){return e===0?1:e===1?3:e===2?2:null}function lj(e,t){let n=Math.max(0,e.total-e.len);if(t<=0||e.len<=0||n===0)return null;let r=Math.min(t,Math.max(20,t*e.len/e.total)),i=t-r;return{thumbHeight:r,thumbTop:i*(Math.min(e.offset,n)/n),travel:i,maxOffset:n}}var uj=class{hoveredLink=null;context;linkPointer=null;mousePointer=null;mouseButton=null;lastMotion=``;selectionPointer=null;selectionMode=`cell`;selectionAnchor=null;selectionBase=null;selectionMoved=!1;selectionScroll=null;selectionScrollDelta=0;selectionClient=null;clickMove=null;clicks={count:0,time:0,x:0,y:0};touch=null;wheelRemainder=0;scrollbarDrag=null;constructor(e){this.context=e;let t=e.canvas,n=e.scrollbar;t.addEventListener(`pointerdown`,this.onPointerDown),t.addEventListener(`pointermove`,this.onPointerMove),t.addEventListener(`pointerup`,this.onPointerUp),t.addEventListener(`pointercancel`,this.onPointerUp),t.addEventListener(`pointerleave`,this.onPointerLeave),t.addEventListener(`wheel`,this.onWheel,{passive:!1}),t.addEventListener(`mousedown`,this.onMouseDown),n.addEventListener(`pointerdown`,this.onScrollbarDown),n.addEventListener(`pointermove`,this.onScrollbarMove),n.addEventListener(`pointerup`,this.onScrollbarUp),n.addEventListener(`pointercancel`,this.onScrollbarUp)}updateScrollbar(e){let t=this.context.core.scrollbarState(),n=t===null?null:lj(t,e);this.context.scrollbar.hidden=n===null,n!==null&&(this.context.thumb.style.height=`${n.thumbHeight}px`,this.context.thumb.style.transform=`translateY(${n.thumbTop}px)`)}dispose(){this.setSelectionScroll(0)}scrollRows(e,t){let n=this.context.core,r=this.wheelRemainder+e/this.context.view().metrics.height,i=Math.trunc(r);if(this.wheelRemainder=r-i,i!==0){if(this.reportsMouse(t))for(let e=0;e<Math.abs(i);e+=1)this.sendMouse(`press`,i<0?4:5,t);else if(n.isAlternateScreen()){let e=(n.isApplicationCursorKeys()?`\x1BO`:`\x1B[`)+(i<0?`A`:`B`);this.context.onData(e.repeat(Math.abs(i)))}else this.context.scrollViewport(i)}}cellAt(e,t){let n=this.context.view(),r=this.context.canvas.getBoundingClientRect();return{x:Math.max(0,Math.min(n.cols-1,Math.floor((e-r.left)/n.metrics.width))),y:Math.max(0,Math.min(n.rows-1,Math.floor((t-r.top)/n.metrics.height)))}}reportsMouse(e){return this.context.core.isMouseTracking()&&!e.shiftKey&&!e.ctrlKey&&!e.metaKey}sendMouse(e,t,n){let r=this.context.view(),i=this.context.canvas.getBoundingClientRect(),a=window.devicePixelRatio||1,o=this.context.core.encoder.encodeMouse({action:e,button:t,mods:+!!n.shiftKey|(n.ctrlKey?2:0)|(n.altKey?4:0)|(n.metaKey?8:0),x:Math.max(0,n.clientX-i.left)*a,y:Math.max(0,n.clientY-i.top)*a,screenWidth:r.cols*r.metrics.width*a,screenHeight:r.rows*r.metrics.height*a,cellWidth:r.metrics.width*a,cellHeight:r.metrics.height*a,anyButtonPressed:n.buttons!==0});if(o.length!==0){if(e===`motion`){if(o===this.lastMotion)return;this.lastMotion=o}else this.lastMotion=``;this.context.onData(o)}}linkAt(e,t){let n=this.context.view(),r=this.context.core,i=n.snapshot;if(!i)return null;let a=this.context.canvas.getBoundingClientRect(),o=e-a.left,s=t-a.top;if(o<0||s<0||o>=n.cols*n.metrics.width||s>=n.rows*n.metrics.height)return null;let c={x:Math.floor(o/n.metrics.width),y:Math.floor(s/n.metrics.height)},l=r.hyperlinkAt(c.x,c.y);if(l!==null){if(l.startsWith(`offsite-image:`))return null;let e=c.x,t=c.x;for(;e>0&&r.hyperlinkAt(e-1,c.y)===l;)--e;for(;t<n.cols-1&&r.hyperlinkAt(t+1,c.y)===l;)t+=1;return{uri:l,range:{start:{x:e,y:c.y},end:{x:t,y:c.y}}}}let u=c.y;for(;u>0&&i.rowData[u]?.isWrapContinuation;)--u;let d=c.y;for(;d<i.rows-1&&i.rowData[d]?.wrapsToNext;)d+=1;let f=``,p=[];for(let e=u;e<=d;e+=1){let t=i.rowData[e];if(!t)break;let n=nA(t,e);f+=n.text,p.push(...n.points)}for(let e of f.matchAll(sj)){let t=e[0].replace(/[.,;:!?)\]}'"]+$/,``),n=p[e.index],r=p[e.index+t.length-1];if(!n||!r)continue;let i={start:n,end:r};if(rj(i,c.y,c.x))return{uri:t,range:i}}return null}setHoveredLink(e){let t=this.hoveredLink;this.context.canvas.style.cursor=e?`pointer`:``,(t?.uri!==e?.uri||t?.range.start.x!==e?.range.start.x||t?.range.start.y!==e?.range.start.y)&&(this.hoveredLink=e,this.context.redraw())}beginSelection(e,t){let n=this.context.core,r=this.cellAt(e.clientX,e.clientY),i=n.toScreen(r);if(!i)return;this.selectionMoved=!1,this.selectionMode=t>=3?`line`:t===2?`word`:`cell`;let a=this.selectionMode===`line`?n.selectLine(i):this.selectionMode===`word`?n.selectWord(i):null;this.selectionAnchor=a?a.start:i,this.selectionBase=a,a?n.setSelection(a.start,a.end):(this.selectionMode=`cell`,n.setSelection(i,i)),this.context.redraw()}extendSelection(e,t){let n=this.context.core,r=this.selectionAnchor;if(!r)return;let i=this.cellAt(e,t),a=n.toScreen(i);if(!a)return;this.selectionMoved=!0;let o=this.selectionBase;if(o===null)n.setSelection(r,a);else{let e=this.selectionMode===`line`?n.selectLine(a):n.selectWord(a),t=a.y<o.start.y||a.y===o.start.y&&a.x<o.start.x;n.setSelection(t?o.end:o.start,e?t?e.start:e.end:a)}this.context.redraw()}setSelectionScroll(e){this.selectionScrollDelta=e,e===0?(this.selectionScroll!==null&&window.clearInterval(this.selectionScroll),this.selectionScroll=null):this.selectionScroll===null&&(this.selectionScroll=window.setInterval(()=>{this.context.scrollViewport(this.selectionScrollDelta);let e=this.selectionClient;e&&this.extendSelection(e.x,e.y)},80))}dragScrollbar(e){let t=this.context.core.scrollbarState(),n=this.scrollbarDrag;if(t===null||n===null)return;let r=this.context.scrollbar.getBoundingClientRect(),i=lj(t,r.height);if(i===null||i.travel===0)return;let a=Math.max(0,Math.min(e-r.top-n.offset,i.travel)),o=Math.round(a/i.travel*i.maxOffset);this.context.scrollViewport(o-t.offset)}onPointerDown=e=>{let t=this.context.canvas;if(this.context.focus(),e.pointerType===`touch`){this.touch={id:e.pointerId,y:e.clientY,moved:!1},t.setPointerCapture(e.pointerId);return}if(this.reportsMouse(e)){let n=cj(e.button);if(n===null)return;e.preventDefault(),this.mousePointer=e.pointerId,this.mouseButton=n,this.sendMouse(`press`,n,e),t.setPointerCapture(e.pointerId);return}if(e.button!==0)return;if(this.linkAt(e.clientX,e.clientY)&&(aj?e.metaKey:e.ctrlKey)){e.preventDefault(),this.linkPointer=e.pointerId;return}let n=e.timeStamp-this.clicks.time<=oj&&Math.hypot(e.clientX-this.clicks.x,e.clientY-this.clicks.y)<=4;this.clicks={count:n?this.clicks.count>=3?1:this.clicks.count+1:1,time:e.timeStamp,x:e.clientX,y:e.clientY},this.clickMove=!e.altKey&&!e.shiftKey&&!e.ctrlKey&&!e.metaKey&&this.context.view().clickToMoveCursor&&this.clicks.count===1?this.cellAt(e.clientX,e.clientY):null,this.selectionPointer=e.pointerId,this.beginSelection(e,this.clicks.count),t.setPointerCapture(e.pointerId)};onPointerMove=e=>{let t=this.touch;if(t?.id===e.pointerId){let n=t.y-e.clientY;if(Math.abs(n)<1)return;t.y=e.clientY,t.moved=!0,this.scrollRows(n,e)}else if(this.mousePointer===e.pointerId||this.context.core.isMouseAnyEventTracking()&&this.reportsMouse(e)){let t=e.buttons,n=t&1?1:t&4?3:t&2?2:null;this.sendMouse(`motion`,n,e)}else if(this.selectionPointer===e.pointerId){let t=this.cellAt(e.clientX,e.clientY);this.clickMove!==null&&(t.x!==this.clickMove.x||t.y!==this.clickMove.y)&&(this.clickMove=null),this.selectionClient={x:e.clientX,y:e.clientY};let n=this.context.canvas.getBoundingClientRect();this.setSelectionScroll(e.clientY<n.top?-1:+(e.clientY>n.bottom)),this.extendSelection(e.clientX,e.clientY)}else this.setHoveredLink(this.linkAt(e.clientX,e.clientY))};onPointerUp=e=>{let t=this.context.canvas;if(t.hasPointerCapture(e.pointerId)&&t.releasePointerCapture(e.pointerId),this.touch?.id===e.pointerId)this.touch=null;else if(this.linkPointer===e.pointerId){this.linkPointer=null;let t=this.linkAt(e.clientX,e.clientY);t&&e.type===`pointerup`&&this.context.onLink(t.uri,e)}else if(this.mousePointer===e.pointerId)this.sendMouse(`release`,this.mouseButton,e),this.mousePointer=null,this.mouseButton=null;else if(this.selectionPointer===e.pointerId){this.selectionPointer=null,this.setSelectionScroll(0),!this.selectionMoved&&this.selectionMode===`cell`&&(this.context.core.clearSelection(),this.selectionAnchor=null,this.context.redraw());let t=this.clickMove;this.clickMove=null,t!==null&&e.type===`pointerup`&&this.context.moveCursorTo(t)}};onPointerLeave=()=>{this.lastMotion=``,this.setHoveredLink(null)};onWheel=e=>{if(e.deltaY===0)return;e.preventDefault();let t=this.context.view(),n=e.deltaMode===1?e.deltaY*t.metrics.height:e.deltaMode===2?e.deltaY*t.rows*t.metrics.height:e.deltaY;this.scrollRows(n,e)};onMouseDown=e=>{e.button===0&&e.preventDefault(),this.context.focus()};onScrollbarDown=e=>{let t=this.context.core.scrollbarState();if(e.button!==0||t===null)return;let n=this.context.scrollbar,r=n.getBoundingClientRect(),i=lj(t,r.height);i!==null&&(e.preventDefault(),e.stopPropagation(),this.scrollbarDrag={id:e.pointerId,offset:e.target===this.context.thumb?e.clientY-r.top-i.thumbTop:i.thumbHeight/2},n.setPointerCapture(e.pointerId),this.dragScrollbar(e.clientY))};onScrollbarMove=e=>{this.scrollbarDrag?.id===e.pointerId&&(e.preventDefault(),this.dragScrollbar(e.clientY))};onScrollbarUp=e=>{if(this.scrollbarDrag?.id!==e.pointerId)return;this.scrollbarDrag=null;let t=this.context.scrollbar;t.hasPointerCapture(e.pointerId)&&t.releasePointerCapture(e.pointerId)}},dj=[`\r`,`
|
|
14
|
-
`,``,``,``,``,`\x1B[99;5u`,`\x1B[100;5u`,`\x1B[111;5u`,`\x1B[122;5u`];function fj(e,t){return e.y<t.y||e.y===t.y&&e.x<t.x}var pj=class{shell=`unknown`;generation=0;core;native=!1;input=!1;clickEvents=!1;inputRef=null;constructor(e){this.core=e}mark(e,t){let n=e.startsWith(`133;`),r=n?4:5;if(e.length>r+1&&e[r+1]!==`;`)return;let i=e.charAt(r);if(!this.core.isAlternateScreen()){if(i===`A`){let r=e.split(`;`);if(r.includes(`k=s`)||r.includes(`k=c`))return;let i=n&&r.includes(`click_events=1`),a=this.shell===`prompt`,o=a&&!this.input&&this.native!==n;if(this.shell=`prompt`,this.native=n,t&&this.trackInput(),o){this.clickEvents=this.clickEvents||i;return}if(this.input=!1,this.clickEvents=i,a)return;this.generation+=1}else if(i===`B`)this.shell=`prompt`,this.input=!0,t&&this.trackInput();else if(i===`C`)this.shell=`command`;else if(i===`D`){if(this.shell===`prompt`&&!this.input)return;this.shell=`unknown`}}}beforeInput(e){this.shell===`prompt`&&dj.some(t=>e.includes(t))&&(this.shell=`unknown`)}reset(){this.release(),this.shell=`unknown`,this.input=!1,this.clickEvents=!1}release(){this.inputRef!==null&&this.core.untrack(this.inputRef),this.inputRef=null}moveCursorInput(e,t,n){if(this.shell!==`prompt`||this.inputRef===null||t===null||t.cursorX<0||t.cursorY<0||this.core.isAlternateScreen()||this.core.isMouseTracking())return null;let r=this.core.trackedPoint(this.inputRef);if(r===null)return null;let i={x:r.x,y:r.y-n};if(fj(e,i))return null;if(this.clickEvents){let t=this.core.scrollbarState();if(t===null)return null;let r=e.y+n-(t.total-t.len);return r<0?null:`\x1b[<0;${e.x+1};${r+1}M`}if(!this.input)return null;let a={x:e.x,y:e.y};a.x>0&&t.rowData[a.y]?.cells[a.x]?.wide===qk.spacerTail&&--a.x;let o={x:t.cursorX,y:t.cursorY};if(fj(a,i)||fj(o,i))return null;let s=fj(a,o),c=s?a:o,l=s?o:a,u=0;for(let e=c.y;e<=l.y;e+=1){let n=t.rowData[e];if(n===void 0)return null;let r=e===l.y?l.x:n.cells.length;for(let t=e===c.y?c.x:0;t<r;t+=1)n.cells[t].text!==``&&(u+=1);if(e<l.y&&!n.wrapsToNext){if(s)return null;break}}let d=s?`ArrowLeft`:`ArrowRight`,f=this.core.encoder.encodeKey(new KeyboardEvent(`keydown`,{key:d,code:d}));return u>0?f.repeat(u):``}trackInput(){this.inputRef===null?this.inputRef=this.core.trackCursor():this.core.retrack(this.inputRef)}},mj=navigator.userAgent.includes(`Mac`),hj=navigator.userAgent.includes(`Windows`),gj=600,_j=1e3,vj=1e4,yj=new TextDecoder(`latin1`),bj=new TextDecoder;function xj(e){let t=/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(e);if(!t)throw Error(`unsupported color ${e}`);return{r:parseInt(t[1],16),g:parseInt(t[2],16),b:parseInt(t[3],16)}}function Sj(e){return[...e.split(`,`).map(e=>e.trim()).filter(e=>e.length>0).map(e=>/^(['"]).*\1$/.test(e)||/^[a-zA-Z][a-zA-Z0-9-]*$/.test(e)?e:`"${e.replaceAll(`"`,``)}"`),`monospace`].join(`, `)}async function Cj(e){try{(await e)?.close()}catch(e){console.warn(`could not decode image`,e)}}var wj=class{element;cols=80;rows=24;canvas;input;context;core;scanner=new AA;handlers;observer;prompt;search;images;pointer;notifications=new wA;options;appearance;metrics;snapshot=null;sized=!1;fitted=!1;frame=0;forceFull=!0;renderFailed=!1;cursorOn=!0;cursorTimer=null;syncTimer=null;renderedCursorY=null;focused=!1;composing=!1;suppressedKeys=new Set;heldOptionKeys=new Set;backlog=[];blocked=!1;epoch=0;title=``;progress={state:0,value:0};disposed=!1;constructor(e,t){this.options=e,this.handlers=t,this.element=document.createElement(`div`),this.element.className=`relative h-full overflow-hidden`,this.canvas=document.createElement(`canvas`),this.canvas.className=`absolute top-0 left-0 cursor-text touch-none`,this.input=document.createElement(`textarea`),this.input.setAttribute(`aria-label`,`Terminal input`),this.input.autocapitalize=`off`,this.input.autocomplete=`off`,this.input.spellcheck=!1,this.input.style.cssText=`position:absolute;left:0;top:0;width:1px;height:1px;opacity:0;padding:0;border:0;resize:none;pointer-events:none;`;let n=document.createElement(`div`);n.className=`absolute top-0 right-0 bottom-0 w-2 cursor-default touch-none`,n.hidden=!0;let r=document.createElement(`div`);r.className=`bg-foreground/15 hover:bg-foreground/30 absolute inset-x-0.5 top-0 rounded-full`,n.append(r),this.element.append(this.canvas,this.input,n);let i=this.canvas.getContext(`2d`,{alpha:!1});if(!i)throw Error(`canvas 2d is unavailable`);this.context=i,this.appearance=this.appearanceFor(e),this.metrics=this.measure(),this.core=new uA(Math.max(1,Math.floor(window.innerWidth/this.metrics.width)),this.rows,e.scrollback,t.onReply,t.onBell),this.prompt=new pj(this.core),this.search=new fA(this.core,()=>this.redraw()),this.images=new GO(this.core),this.pointer=new uj({canvas:this.canvas,scrollbar:n,thumb:r,core:this.core,view:()=>({cols:this.cols,rows:this.rows,metrics:this.metrics,snapshot:this.snapshot,clickToMoveCursor:this.options.clickToMoveCursor}),focus:()=>this.focus(),redraw:()=>this.redraw(),scrollViewport:e=>this.scrollViewport(e),moveCursorTo:e=>this.moveCursorTo(e),onData:t.onData,onLink:t.onLink}),this.applyTerminalOptions(),this.resizeCore(),this.installEvents(),this.observer=new ResizeObserver(()=>this.fit()),this.observer.observe(this.element)}setOptions(e){this.options=e,this.appearance=this.appearanceFor(e),this.metrics=this.measure(),e.clickToMoveCursor||this.prompt.release(),this.applyTerminalOptions(),this.resizeCore(),this.forceFull=!0,this.fit(),this.requestRender()}write(e,t){this.disposed||(this.backlog.push({data:e,replay:t}),this.blocked||this.drain())}reset(){this.epoch+=1,this.backlog=[],this.blocked=!1,this.scanner.reset(),this.prompt.reset(),this.core.reset(),this.applyTerminalOptions(),this.images.clear(),this.core.clearSelection(),this.redraw()}focus(){this.input.focus({preventScroll:!0})}isKittyKeyboard(){return this.core.isKittyKeyboard()}paste(e){let t=this.core.encoder.encodePaste(e);t.length>0&&this.sendInput(t)}presize(e,t){this.fitted||e===this.cols&&t===this.rows||(this.cols=e,this.rows=t,this.resizeCore())}fit(){if(this.disposed)return;let e=this.element.clientWidth,t=this.element.clientHeight;if(e===0||t===0){this.sized=!1;return}this.sized=!0,this.fitted=!0;let n=window.devicePixelRatio||1,r=Math.round(e*n),i=Math.round(t*n);(this.canvas.width!==r||this.canvas.height!==i)&&(this.canvas.width=r,this.canvas.height=i,this.canvas.style.width=`${e}px`,this.canvas.style.height=`${t}px`,this.context.setTransform(n,0,0,n,0,0),this.metrics=this.measure(),this.resizeCore(),this.forceFull=!0);let a=Math.max(1,Math.floor(e/this.metrics.width)),o=Math.max(1,Math.floor(t/this.metrics.height));(a!==this.cols||o!==this.rows)&&(this.cols=a,this.rows=o,this.resizeCore(),this.forceFull=!0,this.handlers.onResize(a,o)),this.renderFrame()}find(e,t,n){let r=this.viewportTop(),i=this.search.find(e,t,n,r);i!==null&&(i.row<r||i.row>=r+this.rows)&&this.scrollViewport(i.row-r-Math.floor(this.rows/2)),this.redraw()}onFindResults(e){return this.search.onResults(e)}clearFind(){this.search.clear(),this.redraw()}replyClipboard(e,t){t.epoch!==this.epoch||t.generation!==this.prompt.generation||t.atPrompt&&this.prompt.shell!==`prompt`||this.handlers.onReply(yA(e,t.selection,t.terminator))}beforeInput(e){this.prompt.beforeInput(e)}dispose(){this.disposed||(this.disposed=!0,this.observer.disconnect(),this.cancelRender(),this.pointer.dispose(),this.search.dispose(),window.removeEventListener(`focus`,this.onWindowFocus),document.removeEventListener(`visibilitychange`,this.onVisibilityChange),this.images.clear(),this.prompt.release(),this.core.dispose(),this.element.remove())}redraw(){this.forceFull=!0,this.requestRender()}resizeCore(){this.core.resize(this.cols,this.rows,this.metrics.width,this.metrics.height,window.devicePixelRatio||1)}appearanceFor(e){let t=e.colors;return{fontSize:e.fontSize,fontFamily:Sj(e.fontFamily),ligatures:e.ligatures,cursorText:t.cursorText,selectionBackground:t.selectionBackground,selectionForeground:t.selectionForeground,matchBackground:t.palette[8],activeMatchBorder:t.palette[3]}}measure(){return tj(this.context,this.options.fontSize,this.appearance.fontFamily,this.options.lineHeight,window.devicePixelRatio||1)}applyTerminalOptions(){let e=this.options.colors;this.core.setColors({foreground:xj(e.foreground),background:xj(e.background),cursor:xj(e.cursor),palette:e.palette.map(xj)}),this.core.setCursor(this.options.cursorStyle,this.options.cursorBlink),this.core.boldIsBright=this.options.boldIsBright,this.core.version=this.options.version,this.core.invalidate()}drain(){for(;!this.blocked&&this.backlog.length>0;){let e=this.backlog.shift();e&&this.process(e)}let e=this.core.title();e!==this.title&&(this.title=e,this.handlers.onTitle(e)),this.search.outputChanged(),this.cursorOn=!0,this.requestRender()}process(e){let t=e.data,n=e.replay;this.core.setReplies(!n);let r=0,i=this.scanner.scan(t,(e,i)=>(this.core.write(t.subarray(r,i)),r=i,this.handleOutput(e,n)));this.core.write(t.subarray(r,i)),i<t.length&&this.backlog.unshift({data:t.subarray(i),replay:n})}handleOutput(e,t){if(e.type===`sixel`)return this.decodeImage(VO(e.data));let n=yj.decode(e.data);if(n.startsWith(`1337;File=`))return this.decodeImage(UO(n.slice(10),{cellWidth:this.metrics.width,cellHeight:this.metrics.height,width:this.cols*this.metrics.width,height:this.rows*this.metrics.height,pixelRatio:window.devicePixelRatio||1}));if(n.startsWith(`133;`)||n.startsWith(`6973;`))return this.prompt.mark(n,this.options.clickToMoveCursor),!1;if(n.startsWith(`52;`)){let r=n.split(`;`),i=r[2];if(t||i===void 0)return!1;if(i===`?`)return this.handlers.onClipboardRead({selection:_A(r[1]),terminator:e.terminator,generation:this.prompt.generation,epoch:this.epoch,atPrompt:this.prompt.shell===`prompt`}),!1;let a=vA(i);return a!==null&&this.handlers.onClipboard(a),!1}if(n===`10;?`||n===`11;?`||n===`12;?`)return t||this.handlers.onReply(bA(n,this.core.currentColors(),e.terminator)),!1;if(n.startsWith(`4;`)){if(!t)for(let t of xA(n,this.core.currentColors().palette,e.terminator))this.handlers.onReply(t);return!1}if(n===`9;4`||n.startsWith(`9;4;`)){let e=SA(n,this.progress);return e!==null&&(this.progress=e,this.handlers.onProgress(e)),!1}if(t)return!1;let r=n.startsWith(`99;`)?this.notifications.add(bj.decode(e.data)):CA(n,e.data);return r!==null&&this.handlers.onNotify(r.title,r.body),!1}decodeImage(e){return this.blocked=!0,this.placeImage(e,this.epoch,window.devicePixelRatio||1),!0}async placeImage(e,t,n){let r=0,i=new Promise(e=>{r=window.setTimeout(()=>e(`timeout`),vj)});try{let r=await Promise.race([e,i]);r===`timeout`?(console.warn(`image decoding took too long, skipping the image`),Cj(e)):r!==null&&(t===this.epoch&&!this.disposed?this.images.place(r,n,this.metrics.height):r.close())}catch(e){console.warn(`could not decode image`,e)}window.clearTimeout(r),t!==this.epoch||this.disposed||(this.blocked=!1,this.drain())}moveCursorTo(e){if(!this.options.clickToMoveCursor)return;let t=this.prompt.moveCursorInput(e,this.snapshot,this.viewportTop());t!==null&&(t!==``&&this.sendInput(t),this.core.clearSelection(),this.redraw())}sendInput(e){this.prompt.beforeInput(e),this.core.scrollbarState()?.offset!==this.maxOffset()&&(this.core.scrollToBottom(),this.redraw()),this.handlers.onData(e)}maxOffset(){let e=this.core.scrollbarState();return e?Math.max(0,e.total-e.len):0}viewportTop(){return this.core.toScreen({x:0,y:0})?.y??0}scrollViewport(e){let t=this.core.scrollbarState(),n=Math.trunc(e);if(t!==null){let e=Math.max(0,t.total-t.len);n=Math.max(0,Math.min(t.offset+n,e))-t.offset}n!==0&&(this.core.scroll(n),this.redraw())}requestRender(){!this.disposed&&this.sized&&this.frame===0&&(this.frame=window.requestAnimationFrame(()=>{this.frame=0,this.renderFrame()}))}cancelRender(){this.frame!==0&&window.cancelAnimationFrame(this.frame),this.frame=0,this.cursorTimer!==null&&window.clearTimeout(this.cursorTimer),this.cursorTimer=null,this.syncTimer!==null&&window.clearTimeout(this.syncTimer),this.syncTimer=null}renderFrame(){if(!this.disposed&&this.sized&&this.element.isConnected){this.frame!==0&&window.cancelAnimationFrame(this.frame),this.frame=0;try{this.draw(),this.renderFailed=!1}catch(e){this.renderFailed||console.error(`could not draw the terminal`,e),this.renderFailed=!0}}}draw(){if(this.core.isSynchronizedOutput()){this.syncTimer===null&&(this.syncTimer=window.setTimeout(()=>{this.syncTimer=null,this.core.endSynchronizedOutput(),this.requestRender()},_j));return}this.syncTimer!==null&&window.clearTimeout(this.syncTimer),this.syncTimer=null;let e=this.core.snapshot();this.snapshot=e;let t=this.focused&&e.cursorBlinking&&e.cursorVisible;t||(this.cursorOn=!0);let n=this.viewportTop(),r=this.images.visible(n,this.rows,this.metrics.height),i=this.core.cellSize(),a=this.core.kitty.images(e.rowData,i);ij({context:this.context,snapshot:e,metrics:this.metrics,appearance:this.appearance,forceFull:this.forceFull||r.length>0||a.length>0,cursorOn:this.cursorOn,previousCursorY:this.renderedCursorY,focused:this.focused,hoveredLink:this.pointer.hoveredLink?.range??null,highlights:this.search.highlights(e,n),pixelRatio:window.devicePixelRatio||1,drawLayer:e=>Pk(this.context,a,e,this.metrics,i)}),Pk(this.context,a,`aboveText`,this.metrics,i);for(let e of r)this.context.drawImage(e.bitmap,e.x*this.metrics.width,e.y*this.metrics.height,e.width,e.height);this.forceFull=r.length>0||a.length>0,this.renderedCursorY=this.cursorOn&&e.cursorVisible&&e.cursorY>=0?e.cursorY:null,e.cursorX>=0&&e.cursorY>=0&&(this.input.style.left=`${e.cursorX*this.metrics.width}px`,this.input.style.top=`${e.cursorY*this.metrics.height}px`),this.pointer.updateScrollbar(this.element.clientHeight),this.cursorTimer!==null&&window.clearTimeout(this.cursorTimer),this.cursorTimer=null,t&&(this.cursorTimer=window.setTimeout(()=>{this.cursorTimer=null,this.cursorOn=!this.cursorOn,this.requestRender()},gj))}copySelection(){let e=this.core.selectionText();e.length!==0&&(window.isSecureContext?navigator.clipboard.writeText(e):console.warn(`copy from the terminal needs https or localhost`))}optionIsMeta(e){if(!mj||!e.altKey||e.metaKey)return!1;let t=this.options.optionAsMeta;if(t===`off`)return!1;if(t===`both`)return!0;if(t===`left`)return this.heldOptionKeys.has(`AltLeft`);if(t===`right`)return this.heldOptionKeys.has(`AltRight`);throw Error(`unknown option as meta mode ${t}`)}onKeyDown=e=>{if((e.code===`AltLeft`||e.code===`AltRight`)&&this.heldOptionKeys.add(e.code),!this.handlers.beforeKey(e)){this.suppressedKeys.add(e.code);return}let t=this.optionIsMeta(e),n=t&&this.core.encoder.metaText(e)!==null;if(e.isComposing||this.composing||!n&&(e.key===`Process`||e.keyCode===229)||mj&&this.options.optionAsMeta!==`off`&&!t&&e.altKey&&!e.ctrlKey&&!e.metaKey&&([...e.key].length===1||e.key===`Dead`)||!n&&e.getModifierState(`AltGraph`)&&[...e.key].length===1){this.suppressedKeys.add(e.code);return}let r=e.key.toLowerCase(),i=hj&&this.options.windowsCopyPaste&&e.ctrlKey&&!e.shiftKey&&!e.altKey&&!e.metaKey;if(i&&r===`c`&&this.core.selectionText().length>0){this.copySelection(),this.core.clearSelection(),this.redraw(),e.preventDefault(),this.suppressedKeys.add(e.code);return}if(mj?e.metaKey&&r===`c`:e.ctrlKey&&e.shiftKey&&r===`c`||e.ctrlKey&&!e.shiftKey&&r===`insert`){this.copySelection(),e.preventDefault(),this.suppressedKeys.add(e.code);return}if((mj?e.metaKey&&r===`v`:e.ctrlKey&&e.shiftKey&&r===`v`||e.shiftKey&&!e.ctrlKey&&r===`insert`||i&&r===`v`)||mj&&e.metaKey&&r===`q`){this.suppressedKeys.add(e.code);return}let a=this.core.encoder.encodeKey(e,`press`,n);a.length!==0&&(this.suppressedKeys.delete(e.code),e.preventDefault(),e.stopPropagation(),this.core.selectionText().length>0&&!e.shiftKey&&(this.core.clearSelection(),this.forceFull=!0),this.sendInput(a))};onKeyUp=e=>{if(this.heldOptionKeys.delete(e.code),this.suppressedKeys.delete(e.code)||e.isComposing||this.composing)return;let t=this.core.encoder.encodeKey(e,`release`,this.optionIsMeta(e));t.length!==0&&(e.preventDefault(),this.handlers.onData(t))};onInput=e=>{let t=e;if(this.composing||t.isComposing)return;let n=this.input.value||t.data||``;this.input.value=``,n.length>0&&this.sendInput(n)};onCompositionStart=()=>{this.composing=!0};onCompositionEnd=e=>{this.composing=!1;let t=this.input.value||e.data;this.input.value=``,t.length>0&&this.sendInput(t)};onPaste=e=>{e.preventDefault();let t=e.clipboardData?.getData(`text/plain`)??``;t.length>0&&this.paste(t)};onCopy=e=>{let t=this.core.selectionText();t.length!==0&&e.clipboardData&&(e.preventDefault(),e.clipboardData.setData(`text/plain`,t))};onWindowFocus=()=>{mj&&this.options.optionAsMeta!==`off`&&this.core.encoder.refreshKeyboardLayout()};onContextRestored=()=>{let e=window.devicePixelRatio||1;this.context.setTransform(e,0,0,e,0,0),this.redraw()};onVisibilityChange=()=>{document.visibilityState===`visible`&&this.redraw()};onFocus=()=>{this.focused=!0,this.cursorOn=!0,this.requestRender(),!this.disposed&&this.core.isFocusReporting()&&this.handlers.onReply(`\x1B[I`)};onBlur=()=>{this.focused=!1,this.heldOptionKeys.clear(),this.cursorOn=!0,this.requestRender(),!this.disposed&&this.core.isFocusReporting()&&this.handlers.onReply(`\x1B[O`)};installEvents(){this.input.addEventListener(`keydown`,this.onKeyDown),this.input.addEventListener(`keyup`,this.onKeyUp),this.input.addEventListener(`input`,this.onInput),this.input.addEventListener(`compositionstart`,this.onCompositionStart),this.input.addEventListener(`compositionend`,this.onCompositionEnd),this.input.addEventListener(`paste`,this.onPaste),this.input.addEventListener(`copy`,this.onCopy),this.input.addEventListener(`focus`,this.onFocus),this.input.addEventListener(`blur`,this.onBlur),this.canvas.addEventListener(`contextrestored`,this.onContextRestored),window.addEventListener(`focus`,this.onWindowFocus),document.addEventListener(`visibilitychange`,this.onVisibilityChange)}},Tj=new Map,Ej=new Map,Dj=null,Oj=0;function kj(e){return aM().open&&cM()?.tabId===e&&!document.hidden&&document.hasFocus()}function Aj(e){if(kj(e))return!1;let t=aM();return t.alerts.includes(e)||oM({alerts:[...t.alerts,e]}),!0}function jj(e){if(!Aj(e)||Ej.has(e))return;let t=Tj.get(e);t!==void 0&&performance.now()-t<5e3||Ej.set(e,window.setTimeout(()=>{Ej.delete(e),kj(e)||(Tj.set(e,performance.now()),Nj(e,``,`Bell`))},500))}function Mj(e,t,n){Aj(e)&&(window.clearTimeout(Ej.get(e)),Ej.delete(e),Tj.set(e,performance.now()),Nj(e,t,n))}function Nj(e,t,n){let r=dM(e);r&&na(t||fM(r),n,{machine:rM(),project:r.projectId??`global`,tabId:e}).catch(e=>console.error(`could not show a notification`,e))}function Pj(){let e=performance.now();if(e-Oj<150)return;Oj=e,Dj??=new AudioContext,Dj.state===`suspended`&&Dj.resume();let t=Dj.createOscillator(),n=Dj.createGain(),r=Dj.currentTime;t.frequency.value=880,n.gain.setValueAtTime(.1,r),n.gain.exponentialRampToValueAtTime(.001,r+.15),t.connect(n).connect(Dj.destination),t.start(r),t.stop(r+.15)}function Fj(e){return{alerts:aM().alerts.filter(t=>e(t)&&!kj(t))}}function Ij(e){window.clearTimeout(Ej.get(e)),Ej.delete(e),Tj.delete(e)}function Lj(e){return e.key===`Enter`&&e.shiftKey&&!e.ctrlKey&&!e.altKey&&!e.metaKey}function Rj(e){let t=new wj(nM(),{onData:t=>{aM().status===`active`&&vM(e,zj(t))},onReply:t=>{t===`\x1B[I`||t===`\x1B[O`?vM(e,t):yM(e,t)},onResize:(t,n)=>gM({type:`resize`,id:e,cols:t,rows:n}),onTitle:t=>oM({titles:{...aM().titles,[e]:t}}),onProgress:t=>oM({progress:{...aM().progress,[e]:t}}),onBell:()=>{let n=sM().behavior;n.bellSound&&Pj(),n.bellFlash&&t.element.isConnected&&!document.hidden&&t.element.animate([{opacity:.4},{opacity:1}],{duration:200,easing:`ease-out`}),jj(e)},onNotify:(t,n)=>Mj(e,t,n),onClipboard:yT,onClipboardRead:n=>{kj(e)&&bT(e=>t.replyClipboard(e,n))},onLink:e=>{e.startsWith(`file:`)?Ce(e):window.open(e,`_blank`,`noopener`)},beforeKey:n=>{if(n.type!==`keydown`)return!0;let r=sM(),i=I(L(),rM()).system;if(i===null)throw Error(`the terminal machine is not connected`);let a=i.platform;if(aM().status===`active`&&r.behavior.modernizeShiftEnter&&Lj(n)&&!t.isKittyKeyboard())return n.preventDefault(),t.beforeInput(`\x1B\r`),vM(e,`\x1B\r`),!1;if(aM().status===`active`&&r.behavior.pasteBrowserImages&&window.isSecureContext&&ST(n,a)&&!(St&&r.behavior.windowsCopyPaste&&n.ctrlKey)){n.preventDefault();let r=xT[a].data;return t.beforeInput(r),CT(rM(),t).then(t=>{t||vM(e,r)}).catch(t=>{TT(t),vM(e,r)}),!1}return!DM(n)||(n.preventDefault(),oM({finding:e}),document.querySelector(`[data-find]`)?.select(),!1)}});return t.element.addEventListener(`paste`,e=>{if(!e.clipboardData||e.clipboardData.getData(`text/plain`)!==``)return;let n=[...e.clipboardData.files].filter(e=>e.type.startsWith(`image/`));n.length!==0&&(e.preventDefault(),e.stopPropagation(),wT(rM(),t,n).catch(TT))},!0),t}function zj(e){if(!aM().ctrl||(oM({ctrl:!1}),e.length!==1))return e;let t=e.toUpperCase().charCodeAt(0);return t>=64&&t<=95?String.fromCharCode(t-64):e}function Bj(e,t){dt(e,t)}function Vj(e){let t=e.terminals.map(uM),n=localStorage.getItem(`lastTerminalView`);Bj(e.id,t.find(e=>e===n)??t.at(0)??`global`)}async function Hj(e,t){try{await N(e,`terminal`,{type:`createTab`,projectId:t})}catch(e){console.error(`terminal request failed`,e);return}Bj(e,t??`global`)}function Uj(){let e=aM(),t=ce();if(t===null||e.instance===null||t!==rM()||lM(e.layout,f()).length>0)return;let n=e.layout.tabs.at(0);if(n!==void 0){Bj(t,uM(n));return}let r=L().machines.find(e=>e.id!==t&&e.status===`online`&&e.terminals.length>0);r===void 0?yt(`chat`,()=>void ke.navigate({to:`/`,search:{},replace:!0})):Vj(r)}function Wj(){return{titles:{},progress:{},alerts:[],finding:null}}var Gj=new TextEncoder,Kj=new Map,qj=new Set,Jj=new Set,Yj={status:`connecting`,failure:null,loaded:!1,open:!1,instance:null,layout:{tabs:[],active:{}},ctrl:!1,...Wj()},Xj=null,Zj=null,Qj=!1;async function $j(){mM(),ke.history.subscribe(mM);try{await Promise.all([tk(),mf(sM())]),oM({loaded:!0})}catch(e){console.error(`could not start the terminal`,e),oM({failure:Ot(e)});return}et({close:e=>{e===Zj&&oM({status:`connecting`})},terminal:(e,t)=>{e===Zj&&TM(t)},frame:(e,t)=>{e===Zj&&wM(t)}}),eM(),ke.history.subscribe(eM),ke.history.subscribe(Uj),document.addEventListener(`visibilitychange`,()=>oM({})),window.addEventListener(`focus`,()=>{oM({}),Xj!==null&&OM(Xj,kM(Xj))}),window.addEventListener(`blur`,()=>oM({})),`serviceWorker`in navigator&&navigator.serviceWorker.addEventListener(`message`,e=>{e.data.type===`select`&&hM(e.data.machine,e.data.project,e.data.tabId)});let e=L().prefs,t=tM();j(()=>{eM();let n=L().prefs,r=tM(),i=n.theme!==e.theme||n.terminal!==e.terminal||r!==t;e=n,t=r,i&&jM()}),MM()}function eM(){let e=ce()??L().selection?.machine??null;if(e!==Zj&&(Zj!==null&&Qj&&gM({type:`detach`}),EM([]),qj.clear(),Zj=e,Qj=!1,oM({status:`connecting`,instance:null,layout:{tabs:[],active:{}},...Wj()})),Zj===null)return;let t=I(L(),Zj).status===`online`;t&&!Qj&&(Qj=!0,gM({type:`attach`})),t||(Qj=!1)}function tM(){return Zj===null?null:I(L(),Zj).config?.terminal.behavior.terminalIdentity??null}function nM(){if(Zj===null)throw Error(`the terminal has no machine`);let e=I(L(),Zj);if(e.config===null||e.system===null)throw Error(`${e.name} is not connected`);return hf(sM(),e.config.terminal.behavior.terminalIdentity)}function rM(){if(Zj===null)throw Error(`the terminal has no machine`);return Zj}function iM(e){return Jj.add(e),()=>{Jj.delete(e)}}function aM(){return Yj}function oM(e){Yj={...Yj,...e},Yj={...Yj,...Fj(e=>Kj.has(e))};for(let e of Jj)e()}function sM(){return L().prefs.terminal}function cM(){let e=ce()===null?L().selection?.projectId:f();return e===void 0?null:{view:e,tabs:lM(Yj.layout,e),tabId:Yj.layout.active[e]??null}}function lM(e,t){return e.tabs.filter(e=>uM(e)===t)}function uM(e){return e.projectId??`global`}function dM(e){return Yj.layout.tabs.find(t=>t.id===e)}function fM(e){return(e.customName??Yj.titles[e.id])||`Terminal`}function pM(e){e?oe({bottom:`terminal`}):yt(`overlay`,()=>oe({bottom:void 0}))}function mM(){let e=pt().bottom===`terminal`||ce()!==null;e!==Yj.open&&oM({open:e})}function hM(e,t,n){if(t===`global`)Bj(e,_e);else{let n=L().selection;(n?.machine!==e||n.projectId!==t)&&He({machine:e,projectId:t,sessionId:null}),pM(!0)}_M(e,{type:`select`,view:t,tabId:n})}function gM(e){Zj!==null&&_M(Zj,e)}function _M(e,t){w(e)&&N(e,`terminal`,t).catch(e=>console.error(`terminal request failed`,e))}function vM(e,t){Zj!==null&&he(Zj,0,e,typeof t==`string`?Gj.encode(t):t)}function yM(e,t){Zj!==null&&he(Zj,1,e,Gj.encode(t))}function bM(e,t,n,r){kM(e).find(t,n,r)}function xM(e,t){return kM(e).onFindResults(t)}function SM(e){let t=kM(e);t.clearFind(),oM({finding:null}),t.focus()}function CM(){oM({ctrl:!Yj.ctrl})}function wM(e){let t=Kj.get(e.id);if(!t)return;let n=e.kind===3,r=n&&qj.delete(e.id);r&&t.reset(),t.write(e.data,n),r&&qj.size===0&&oM({status:`active`})}function TM(e){let t=e.type===`active`&&e.instance!==Yj.instance;if(t&&EM([]),EM(e.layout.tabs),e.type===`active`){qj.clear(),Kj.forEach((e,t)=>{qj.add(t),e.element.isConnected&&OM(t,e)}),oM({...t&&{instance:e.instance,...Wj()},status:qj.size===0?`active`:`connecting`,layout:e.layout}),Uj();return}for(let e of qj)Kj.has(e)||qj.delete(e);let n=L().selection?.projectId,r=n!==void 0&&lM(Yj.layout,n).length>0&&lM(e.layout,n).length===0;oM({status:qj.size===0?`active`:`connecting`,layout:e.layout}),r&&Yj.open&&pM(!1),Uj()}function EM(e){let t=new Set(e.map(e=>e.id));Kj.forEach((e,n)=>{t.has(n)||(e.dispose(),Kj.delete(n),Ij(n))});for(let e of t)Kj.has(e)||Kj.set(e,Rj(e))}function DM(e){return e.key.toLowerCase()===`f`?wt?e.metaKey&&!e.ctrlKey&&!e.altKey:e.ctrlKey&&e.shiftKey&&!e.altKey&&!e.metaKey:!1}function OM(e,t){gM({type:`resize`,id:e,cols:t.cols,rows:t.rows})}function kM(e){let t=Kj.get(e);if(!t)throw Error(`terminal ${e} does not exist`);return t}function AM(e,t){let n=kM(e);t.append(n.element),n.fit();for(let e of Kj.values())e.presize(n.cols,n.rows);return Xj=e,OM(e,n),n.focus(),()=>{n.element.remove(),Xj===e&&(Xj=null)}}async function jM(){if(await mf(sM()),Kj.size>0){let e=nM();for(let t of Kj.values())t.setOptions(e)}oM({})}function MM(){let e=pt(),t=ce(),n=t??e.machine,r=t===null?e.project:_e,i=e.terminal;if(n===void 0||r===void 0||i===void 0)return;oe({terminal:void 0});let a=iM(()=>{Yj.status===`active`&&Zj===n&&(a(),hM(n,r,Number(i)))})}var NM=null,PM=null,FM=new Set,IM=new Set;function LM(e){return IM.add(e),()=>{IM.delete(e)}}function RM(){return NM}function zM(){NM!==null&&HM({open:!1,closing:NM.closing})}function BM(){return PM}function VM(){PM!==null&&UM({open:!1,closing:PM.closing})}function HM(e){NM=e;for(let e of IM)e()}function UM(e){PM=e;for(let e of IM)e()}function WM(){return document.querySelector(`[role="dialog"][data-state="open"], [role="alertdialog"][data-state="open"]`)!==null}async function GM(e,t){try{let n=await Promise.race([N(e,`terminal.busy`,{id:t}),new Promise((e,t)=>window.setTimeout(()=>t(Error(`timed out`)),5e3))]);return`error`in n?(console.error(`could not check whether tab ${t} is running a program`,n.error),{checked:!1}):{checked:!0,program:n.program}}catch(e){return console.error(`could not check whether a program is running`,e),{checked:!1}}}async function KM(e){if(!sM().behavior.confirmCloseBusyTab){gM({type:`closeTab`,id:e});return}if(!dM(e)||FM.has(e))return;FM.add(e);let t=await GM(rM(),e);if(FM.delete(e),t.checked&&t.program===null){gM({type:`closeTab`,id:e});return}let n=dM(e);n&&!WM()&&HM({open:!0,closing:{id:e,name:fM(n),program:t.checked?t.program:null}})}function qM(e){for(let t of e)_M(t.machine,{type:`closeTab`,id:t.id})}async function JM(e){if(!sM().behavior.confirmCloseBusyTab){qM(e);return}let t=await Promise.all(e.map(e=>GM(e.machine,e.id)));if(t.every(e=>e.checked&&e.program===null)){qM(e);return}if(WM())return;let n=t.flatMap(e=>e.checked&&e.program!==null?[e.program]:[]);UM({open:!0,closing:{tabs:e,programs:[...new Set(n)]}})}var YM=wt?`meta+t`:`ctrl+shift+t`,XM=wt?`meta+w`:`ctrl+shift+w`,ZM=`ctrl+tab`,QM=`ctrl+shift+tab`;function $M(){let e=cM()?.tabId??null;aM().open&&e!==null&&kM(e).focus()}function eN(){return Ms([YM,XM,ZM,QM],(e,t)=>{e.preventDefault(),e.stopPropagation();let n=cM();if(n===null)return;if(t.hotkey===YM){gM({type:`createTab`,projectId:n.view===`global`?null:n.view});return}if(n.tabId===null)return;if(t.hotkey===XM){KM(n.tabId);return}let r;if(t.hotkey===ZM)r=1;else if(t.hotkey===QM)r=-1;else throw Error(`unknown terminal shortcut ${t.hotkey}`);let i=n.tabs,a=i[(i.findIndex(e=>e.id===n.tabId)+r+i.length)%i.length];a&&gM({type:`select`,view:n.view,tabId:a.id})},{enabled:()=>sM().behavior.captureShortcuts,enableOnFormTags:!0,eventListenerOptions:{capture:!0}})}function tN(e){let[t,n]=(0,U.useState)(e.name);return(0,W.jsx)(Or,{open:!0,onOpenChange:t=>{t||e.onDone()},children:(0,W.jsx)(xr,{onCloseAutoFocus:iN,children:(0,W.jsxs)(`form`,{className:`grid gap-4`,onSubmit:n=>{n.preventDefault(),gM({type:`renameTab`,id:e.id,name:t.trim()}),e.onDone()},children:[(0,W.jsx)(Sr,{children:(0,W.jsx)(Tr,{children:`Rename tab`})}),(0,W.jsx)(Hd,{"aria-label":`Name`,placeholder:`Use terminal title`,value:t,onChange:e=>n(e.target.value)}),(0,W.jsxs)(kr,{children:[(0,W.jsx)(H,{type:`button`,variant:`outline`,onClick:e.onDone,children:`Cancel`}),(0,W.jsx)(H,{type:`submit`,children:`Rename`})]})]})})})}function nN(){let e=(0,U.useSyncExternalStore)(LM,RM),t=(0,U.useRef)(null);if(e===null)return null;let n=e.closing;return(0,W.jsx)(xn,{open:e.open,onOpenChange:e=>{e||zM()},children:(0,W.jsxs)(Fn,{onOpenAutoFocus:e=>{e.preventDefault(),t.current?.focus()},onCloseAutoFocus:iN,children:[(0,W.jsxs)(mn,{children:[(0,W.jsxs)(Zn,{children:[`Close “`,n.name,`”?`]}),(0,W.jsx)(On,{children:n.program===null?`OffSite couldn’t check whether a program is still running.`:`${n.program} is still running.`})]}),(0,W.jsxs)(En,{children:[(0,W.jsx)(Vn,{children:`Cancel`}),(0,W.jsx)(wn,{ref:t,variant:`destructive`,onClick:()=>gM({type:`closeTab`,id:n.id}),children:`Close`})]})]})})}function rN(){let e=(0,U.useSyncExternalStore)(LM,BM);if(e===null)return null;let t=e.closing;return(0,W.jsx)(xn,{open:e.open,onOpenChange:e=>{e||VM()},children:(0,W.jsxs)(Fn,{onCloseAutoFocus:iN,children:[(0,W.jsxs)(mn,{children:[(0,W.jsxs)(Zn,{children:[`Close `,t.tabs.length,` `,t.tabs.length===1?`terminal`:`terminals`,`?`]}),(0,W.jsx)(On,{children:t.programs.length===0?`OffSite couldn’t check whether programs are still running.`:`Still running: ${t.programs.join(`, `)}.`})]}),(0,W.jsxs)(En,{children:[(0,W.jsx)(Vn,{children:`Cancel`}),(0,W.jsx)(wn,{variant:`destructive`,onClick:()=>qM(t.tabs),children:`Close all`})]})]})})}function iN(e){e.preventDefault();let t=document.querySelector(`[role="dialog"], [role="alertdialog"]`);t===null?$M():t.focus()}function aN(e){let t=R(e=>e.machines).filter(e=>e.status===`online`),n=t.some(e=>e.terminals.length>0);return t.length===0?null:(0,W.jsxs)(Qt,{children:[(0,W.jsx)(un,{asChild:!0,children:(0,W.jsx)(`button`,{className:z(`text-muted-foreground hover:text-foreground absolute top-1 right-1 grid size-6 cursor-pointer place-items-center rounded-md opacity-0 transition-opacity group-hover/terminal:opacity-100 group-has-[[data-state=open]]/terminal:opacity-100 focus-visible:opacity-100`,n?`pointer-coarse:opacity-100`:`pointer-coarse:pointer-events-none`),"aria-label":`New terminal`,title:`New terminal`,children:(0,W.jsx)(V,{icon:ka,className:`size-4`})})}),(0,W.jsx)(tn,{side:e.mobile?`bottom`:`right`,align:`end`,className:`max-h-80 w-auto min-w-40 overflow-y-auto`,onCloseAutoFocus:e=>e.preventDefault(),children:(0,W.jsx)(oN,{})})]})}function oN(e){let t=R(e=>e.machines),n=R(e=>e.projects),r=e.contextMenu?Un:Gt;return t.filter(e=>e.status===`online`).flatMap(e=>[(0,W.jsxs)(r,{onSelect:()=>void Hj(e.id,null),children:[(0,W.jsx)(Vu,{icon:e.icon}),(0,W.jsx)(`span`,{className:`max-w-60 truncate`,children:e.name})]},e.id),...n.filter(t=>t.machine===e.id).map(t=>(0,W.jsxs)(r,{className:`pl-7`,onSelect:()=>void Hj(e.id,t.id),children:[(0,W.jsx)(zs,{machine:e.id,projectId:t.id,className:`size-4`}),(0,W.jsx)(`span`,{className:`max-w-60 truncate`,children:t.name})]},`${e.id}:${t.id}`))])}function sN(e){let t=(0,U.useRef)(null),[n,r]=(0,U.useState)(``),[i,a]=(0,U.useState)({resultIndex:-1,resultCount:0});(0,U.useEffect)(()=>xM(e.id,a),[e.id]),(0,U.useEffect)(()=>t.current?.focus(),[]);function o(t,n,i){r(t),bM(e.id,t,n,i)}return(0,W.jsxs)(`div`,{className:`bg-card absolute top-2 right-4 z-10 flex items-center gap-1 rounded-lg border p-1 shadow-lg`,children:[(0,W.jsx)(Hd,{ref:t,"data-find":!0,className:`h-7 w-52`,placeholder:`Find`,value:n,onChange:e=>o(e.target.value,!1,!0),onKeyDown:t=>{t.key===`Escape`?(t.preventDefault(),SM(e.id)):t.key===`Enter`?(t.preventDefault(),o(n,t.shiftKey,!1)):DM(t.nativeEvent)&&(t.preventDefault(),t.currentTarget.select())}}),(0,W.jsx)(`span`,{className:`text-muted-foreground w-16 text-center text-xs tabular-nums`,children:n===``?``:i.resultCount===0?`No results`:`${i.resultIndex+1} of ${i.resultCount}`}),(0,W.jsx)(H,{variant:`ghost`,size:`icon-sm`,"aria-label":`Previous match`,onClick:()=>o(n,!0,!1),children:(0,W.jsx)(V,{icon:Ha})}),(0,W.jsx)(H,{variant:`ghost`,size:`icon-sm`,"aria-label":`Next match`,onClick:()=>o(n,!1,!1),children:(0,W.jsx)(V,{icon:In})}),(0,W.jsx)(H,{variant:`ghost`,size:`icon-sm`,"aria-label":`Close find`,onClick:()=>SM(e.id),children:(0,W.jsx)(V,{icon:Ja})})]})}var cN=[{label:`Esc`,sequence:`\x1B`},{label:`Tab`,sequence:` `},{label:`↑`,sequence:`\x1B[A`},{label:`↓`,sequence:`\x1B[B`},{label:`←`,sequence:`\x1B[D`},{label:`→`,sequence:`\x1B[C`}];function lN(e){let t=(0,U.useSyncExternalStore)(iM,aM),n=t.status===`active`,r=lM(t.layout,e.view),i=t.layout.active[e.view]??null,a=eN();(0,U.useEffect)(()=>{n&&!e.page&&gM({type:`select`,view:e.view,tabId:null})},[e.view,n,e.page]);function o(){gM({type:`createTab`,projectId:e.view===`global`?null:e.view})}return t.loaded?(0,W.jsxs)(`div`,{ref:a,className:`flex h-full flex-col text-sm`,children:[(0,W.jsxs)(`header`,{className:z(`flex h-9 flex-none select-none`,e.tabSize===`lg`&&`h-(--workspace-topbar-height)`,r.length===1?`bg-background`:`bg-sidebar`),children:[e.leading&&(0,W.jsx)(`div`,{className:`flex flex-none items-center border-b px-1.5`,children:e.leading}),(0,W.jsx)(`div`,{className:`flex min-w-0 flex-1 [scrollbar-width:none] overflow-x-auto`,children:r.map(n=>(0,W.jsx)(dN,{tab:n,children:(0,W.jsxs)(`div`,{className:z(`group/tab text-muted-foreground hover:text-foreground relative flex min-w-28 flex-1 items-center justify-center border-r border-b px-7 text-xs transition-colors last:border-r-0`,e.tabSize===`lg`&&`text-[13px]`,n.id===i&&`bg-background text-foreground border-b-transparent`),onMouseDown:e=>e.preventDefault(),onClick:()=>gM({type:`select`,view:e.view,tabId:n.id}),children:[(0,W.jsx)(`span`,{className:`truncate`,children:fM(n)}),(0,W.jsx)(fN,{id:n.id,className:`ml-1.5 size-1.5 flex-none rounded-full`}),(0,W.jsx)(pN,{progress:t.progress[n.id]}),(0,W.jsx)(`button`,{className:z(`text-muted-foreground hover:bg-accent hover:text-foreground absolute left-1.5 grid size-4.5 place-items-center rounded opacity-0 transition-opacity group-hover/tab:opacity-100`,n.id===i&&`pointer-coarse:opacity-100`),"aria-label":`Close tab`,onClick:e=>{e.stopPropagation(),KM(n.id)},children:(0,W.jsx)(V,{icon:Ja,className:`size-3`})})]})},n.id))}),(0,W.jsx)(`button`,{className:z(`text-muted-foreground hover:text-foreground grid w-8 flex-none place-items-center transition-colors`,r.length>1&&`border-b border-l`),"aria-label":`New tab`,title:`New tab`,onClick:o,children:(0,W.jsx)(V,{icon:ka,className:`size-4`})})]}),(0,W.jsxs)(`div`,{className:`relative min-h-0 flex-1`,children:[i!==null&&(0,W.jsx)(uN,{id:i},`${t.instance}-${i}`),i!==null&&t.finding===i&&(0,W.jsx)(sN,{id:i},i),n&&i===null&&!e.page&&(0,W.jsx)(`button`,{className:`text-muted-foreground hover:text-foreground grid size-full cursor-pointer place-items-center text-xs transition-colors`,onClick:o,children:`New terminal`}),!n&&(0,W.jsx)(`div`,{className:`bg-background/80 animate-in fade-in absolute inset-0 z-20 grid place-items-center p-6 text-center backdrop-blur-md duration-200`,children:(0,W.jsxs)(`div`,{className:`flex flex-col items-center gap-3`,children:[(0,W.jsx)(`span`,{className:`border-foreground/15 border-t-foreground/70 size-6 animate-spin rounded-full border-[3px]`}),(0,W.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:`Connecting. Your terminals keep running while you wait.`})]})})]}),i!==null&&(0,W.jsxs)(`div`,{className:`bg-card hidden flex-none gap-1.5 overflow-x-auto border-t p-1.5 pointer-coarse:flex`,children:[cN.map(e=>(0,W.jsx)(H,{variant:`secondary`,className:`min-w-11`,onPointerDown:e=>e.preventDefault(),onClick:()=>vM(i,e.sequence),children:e.label},e.label)),(0,W.jsx)(H,{variant:t.ctrl?`default`:`secondary`,className:`min-w-11`,onPointerDown:e=>e.preventDefault(),onClick:CM,children:`Ctrl`})]}),(0,W.jsx)(nN,{})]}):(0,W.jsx)(`div`,{className:`text-muted-foreground grid h-full place-items-center p-4 text-xs whitespace-pre-wrap`,children:t.failure===null?`Starting the terminal…`:`The terminal could not start: ${t.failure}`})}function uN(e){let t=(0,U.useRef)(null);return(0,U.useEffect)(()=>{if(!t.current)throw Error(`terminal container missing`);return AM(e.id,t.current)},[e.id]),(0,W.jsx)(`div`,{className:`bg-background absolute inset-0 pt-(--pad-top) pr-(--pad-right) pb-(--pad-bottom) pl-(--pad-left)`,ref:t})}function dN(e){let[t,n]=(0,U.useState)(!1),r=R(e=>e.projects).filter(e=>e.machine===rM()),i=e.tab;return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(qn,{children:[(0,W.jsx)(Yn,{asChild:!0,children:e.children}),(0,W.jsxs)(Ln,{children:[(0,W.jsxs)(Un,{onSelect:()=>n(!0),children:[(0,W.jsx)(V,{icon:Lo}),`Rename`]}),(0,W.jsxs)(Gn,{children:[(0,W.jsxs)(Nn,{children:[(0,W.jsx)(V,{icon:_n}),`Move to`]}),(0,W.jsx)(bn,{className:`max-h-80 overflow-y-auto`,children:(0,W.jsxs)(An,{value:i.projectId??``,onValueChange:e=>gM({type:`assignTab`,id:i.id,projectId:e===``?null:e}),children:[(0,W.jsx)(gn,{value:``,children:`No project`}),r.length>0&&(0,W.jsx)(zn,{}),r.map(e=>(0,W.jsx)(gn,{value:e.id,children:(0,W.jsx)(`span`,{className:`max-w-60 truncate`,children:e.name})},e.id))]})})]}),(0,W.jsxs)(Un,{variant:`destructive`,onSelect:()=>void KM(i.id),children:[(0,W.jsx)(V,{icon:oo}),`Close tab`]})]})]}),t&&(0,W.jsx)(tN,{id:i.id,name:i.customName??``,onDone:()=>n(!1)})]})}function fN(e){return aM().alerts.includes(e.id)?(0,W.jsx)(`span`,{className:z(`bg-primary`,e.className)}):null}function pN(e){let t=e.progress;return!t||t.state===0?null:t.state===3?(0,W.jsx)(`span`,{className:`bg-primary absolute inset-x-0 bottom-0 h-0.5 animate-pulse`}):(0,W.jsx)(`span`,{className:z(`absolute bottom-0 left-0 h-0.5 transition-[width]`,t.state===1&&`bg-primary`,t.state===2&&`bg-destructive`,t.state===4&&`bg-yellow-500`),style:{width:`${t.state!==1&&t.value===0?100:t.value}%`}})}function mN(e){(0,U.useSyncExternalStore)(iM,aM);let t=R(e=>e.machines).filter(e=>e.status===`online`),n=Be(),r=gN(),i=r.find(t=>t.machine.id===e.machine&&t.view===n);(0,U.useEffect)(()=>{localStorage.setItem(`lastTerminal`,e.machine),localStorage.setItem(`lastTerminalView`,n)},[e.machine,n]);let a=(0,W.jsxs)(Qt,{children:[(0,W.jsx)(un,{asChild:!0,disabled:t.length===0,children:(0,W.jsx)(`button`,{className:`text-muted-foreground enabled:hover:text-foreground grid w-11 flex-none place-items-center self-stretch transition-colors`,"aria-label":`New terminal`,title:`New terminal`,children:(0,W.jsx)(V,{icon:ka,className:`size-4`})})}),(0,W.jsx)(tn,{align:`end`,className:`w-auto min-w-56`,children:(0,W.jsx)(oN,{})})]});return e.mobile?(0,W.jsxs)(`main`,{className:`bg-background flex min-w-0 flex-1 flex-col overflow-hidden pt-[env(safe-area-inset-top)] pb-[env(safe-area-inset-bottom)]`,children:[(0,W.jsxs)(`header`,{className:`grid h-(--workspace-topbar-height) flex-none grid-cols-[auto_1fr_auto] items-center border-b select-none`,children:[e.leading,(0,W.jsxs)(Qt,{children:[(0,W.jsx)(un,{asChild:!0,children:(0,W.jsxs)(`button`,{className:`text-muted-foreground hover:text-foreground flex min-w-0 items-center justify-center gap-1.5 self-stretch px-1 text-[13px]`,children:[i!==void 0&&(0,W.jsx)(yN,{group:i}),(0,W.jsx)(`span`,{className:`truncate`,children:i?.name})]})}),(0,W.jsx)(tn,{align:`center`,className:`w-auto`,children:r.filter(_N).map(t=>(0,W.jsxs)(Gt,{className:z(t.view!==`global`&&`pl-7`),onSelect:()=>t.count===0?void Hj(t.machine.id,null):Bj(t.machine.id,t.view),children:[(0,W.jsx)(yN,{group:t}),(0,W.jsx)(`span`,{className:`max-w-60 truncate`,children:t.name}),(0,W.jsx)(bN,{count:t.count,alert:vN(t,e.machine)})]},`${t.machine.id}:${t.view}`))})]}),a]}),(0,W.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,W.jsx)(lN,{view:n,page:!0})})]}):(0,W.jsx)(`main`,{className:`bg-background flex min-w-0 flex-1 flex-col overflow-hidden`,children:(0,W.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,W.jsx)(lN,{view:n,page:!0,tabSize:`lg`,leading:e.leading})})})}function hN(){(0,U.useSyncExternalStore)(iM,aM);let e=M(),t=Be(),n=gN().filter(_N);return n.length===0?null:(0,W.jsx)(`div`,{className:`flex max-h-52 flex-col gap-px overflow-y-auto`,children:n.map(n=>(0,W.jsxs)(qn,{children:[(0,W.jsx)(Yn,{asChild:!0,children:(0,W.jsxs)(`div`,{className:z(`group/row text-sidebar-muted-foreground/80 hover:bg-sidebar-row-hover hover:text-sidebar-foreground data-[state=open]:bg-sidebar-row-hover relative shrink-0 rounded-[var(--control-radius)]`,n.machine.id===e&&n.view===t&&`bg-sidebar-row-hover text-sidebar-foreground`),children:[(0,W.jsxs)(`button`,{className:z(`flex h-7 w-full cursor-pointer items-center gap-2 rounded-[var(--control-radius)] pr-2.5 pl-7 text-left text-[13px]`,n.view!==`global`&&`pl-11`),onClick:()=>n.count===0?void Hj(n.machine.id,null):Bj(n.machine.id,n.view),children:[(0,W.jsx)(yN,{group:n}),(0,W.jsx)(`span`,{className:`truncate`,children:n.name}),(0,W.jsx)(bN,{count:n.count,alert:vN(n,e),className:`group-hover/row:invisible`})]}),(0,W.jsx)(`button`,{className:`text-muted-foreground hover:text-foreground absolute top-0.5 right-1 grid size-6 cursor-pointer place-items-center rounded-md opacity-0 transition-opacity group-hover/row:opacity-100 focus-visible:opacity-100 pointer-coarse:hidden`,"aria-label":`New terminal`,title:`New terminal`,onClick:()=>void Hj(n.machine.id,n.view===`global`?null:n.view),children:(0,W.jsx)(V,{icon:ka,className:`size-4`})})]})}),(0,W.jsxs)(Ln,{onCloseAutoFocus:e=>e.preventDefault(),children:[(0,W.jsxs)(Un,{onSelect:()=>void Hj(n.machine.id,n.view===`global`?null:n.view),children:[(0,W.jsx)(V,{icon:ka}),`New terminal`]}),n.view===`global`&&(0,W.jsxs)(Un,{variant:`destructive`,onSelect:()=>void JM(n.machine.terminals.map(e=>({machine:n.machine.id,id:e.id}))),children:[(0,W.jsx)(V,{icon:oo}),`Close All`]}),(0,W.jsxs)(Un,{variant:`destructive`,disabled:n.count===0,onSelect:()=>void JM(n.machine.terminals.filter(e=>uM(e)===n.view).map(e=>({machine:n.machine.id,id:e.id}))),children:[(0,W.jsx)(V,{icon:oo}),n.view===`global`?`Close All Except Projects`:`Close All`]})]})]},`${n.machine.id}:${n.view}`))})}function gN(){let e=R(e=>e.machines),t=R(e=>e.projects);return e.flatMap(e=>{let n=e.status===`online`?e.terminals:[],r=[...new Set(n.flatMap(e=>e.projectId===null?[]:[e.projectId]))];return[{machine:e,view:_e,name:e.name,count:n.filter(e=>e.projectId===null).length},...r.map(r=>({machine:e,view:r,name:t.find(t=>t.machine===e.id&&t.id===r)?.name??`Removed project`,count:n.filter(e=>e.projectId===r).length}))]})}function _N(e){return e.machine.status===`online`&&e.machine.terminals.length>0}function vN(e,t){let n=aM();return e.machine.id===t&&n.layout.tabs.some(t=>(t.projectId??`global`)===e.view&&n.alerts.includes(t.id))}function yN(e){return e.group.view===`global`?(0,W.jsx)(Vu,{icon:e.group.machine.icon,className:`size-4 shrink-0`}):(0,W.jsx)(zs,{machine:e.group.machine.id,projectId:e.group.view,className:`size-4 shrink-0`})}function bN(e){return e.count===0?null:(0,W.jsx)(`span`,{className:z(`ml-auto grid h-4 min-w-4 shrink-0 place-items-center rounded-full px-1 text-[10px] leading-none font-medium tabular-nums`,e.alert?`bg-primary text-primary-foreground`:`text-foreground/75 bg-[color-mix(in_srgb,var(--foreground)_8%,var(--background))]`,e.className),children:e.count})}function xN(e){let t=R(e=>e.machines),[n,r]=ur(`terminalGroupsExpanded`,!0),i=t.reduce((e,t)=>e+t.terminals.length,0),a=t.some(e=>e.status===`online`&&e.terminals.length>0),o=t.some(e=>e.status===`online`),s=a&&!e.mobile;if(t.length===0)return null;let c=(0,W.jsxs)(`button`,{className:z(e.buttonClassName,`group-hover/terminal:text-sidebar-foreground group-hover/terminal:[&>svg]:text-sidebar-foreground group-has-[[data-state=open]]/terminal:text-sidebar-foreground group-has-[[data-state=open]]/terminal:[&>svg]:text-sidebar-foreground h-8 w-full justify-start gap-2 px-2.5 text-sm`,s&&`group-hover/terminal:[&>svg]:opacity-0 pointer-coarse:[&>svg]:opacity-0`),title:`Terminal`,onClick:s?()=>r(!n):void 0,children:[(0,W.jsx)(V,{icon:Qo}),`Terminal`,i>0&&(0,W.jsx)(`span`,{className:z(`text-foreground/75 ml-auto grid h-4 min-w-4 place-items-center rounded-full bg-[color-mix(in_srgb,var(--foreground)_8%,var(--background))] px-1 text-[10px] leading-none font-medium tabular-nums`,o&&`group-hover/terminal:invisible group-has-[[data-state=open]]/terminal:invisible`,a&&`pointer-coarse:invisible`),children:i})]});return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(qn,{children:[(0,W.jsx)(Yn,{asChild:!0,disabled:!o,children:(0,W.jsxs)(`div`,{className:`group/terminal hover:bg-sidebar-row-hover has-[[data-state=open]]:bg-sidebar-row-hover data-[state=open]:bg-sidebar-row-hover relative rounded-[var(--control-radius)]`,children:[s?c:(0,W.jsxs)(Qt,{children:[(0,W.jsx)(un,{asChild:!0,disabled:!o,children:c}),(0,W.jsx)(tn,{side:`bottom`,align:`start`,className:`max-h-80 w-(--radix-dropdown-menu-trigger-width) overflow-y-auto`,onCloseAutoFocus:e=>e.preventDefault(),children:(0,W.jsx)(oN,{})})]}),s&&(0,W.jsx)(`button`,{className:`text-muted-foreground hover:text-foreground absolute top-1 left-1.5 grid size-6 cursor-pointer place-items-center rounded-md opacity-0 group-hover/terminal:opacity-100 focus-visible:opacity-100 pointer-coarse:opacity-100`,"aria-label":n?`Collapse terminals`:`Expand terminals`,"aria-expanded":n,onClick:()=>r(!n),children:(0,W.jsx)(V,{icon:Fr,"aria-hidden":!0,className:z(`size-4 transition-transform duration-200`,n&&`rotate-90`)})}),(0,W.jsx)(aN,{mobile:e.mobile})]})}),(0,W.jsxs)(Ln,{onCloseAutoFocus:e=>e.preventDefault(),children:[(0,W.jsxs)(Gn,{children:[(0,W.jsxs)(Nn,{children:[(0,W.jsx)(V,{icon:ka}),`New terminal`]}),(0,W.jsx)(bn,{className:`max-h-80 overflow-y-auto`,children:(0,W.jsx)(oN,{contextMenu:!0})})]}),(0,W.jsxs)(Un,{variant:`destructive`,disabled:!a,onSelect:()=>void JM(t.filter(e=>e.status===`online`).flatMap(e=>e.terminals.map(t=>({machine:e.id,id:t.id})))),children:[(0,W.jsx)(V,{icon:oo}),`Close All`]})]})]}),(0,W.jsx)(`div`,{className:z(`grid transition-[grid-template-rows] duration-200`,n||e.mobile?`grid-rows-[1fr]`:`grid-rows-[0fr]`),inert:!n&&!e.mobile,children:(0,W.jsx)(`div`,{className:`min-h-0 overflow-hidden`,children:(0,W.jsx)(hN,{})})}),(0,W.jsx)(rN,{})]})}function SN(e){let[t,n]=(0,U.useState)(!1);return(0,W.jsxs)($n,{open:t,onOpenChange:n,children:[(0,W.jsx)(Wt,{asChild:!0,children:(0,W.jsx)(`button`,{className:z(e.buttonClassName,`size-7`),title:`Menu`,"aria-label":`Menu`,children:(0,W.jsx)(V,{icon:Oo})})}),(0,W.jsxs)(sn,{role:`group`,"aria-label":`Menu`,className:`flex w-56 flex-col gap-px p-1`,children:[(0,W.jsx)(xN,{buttonClassName:e.buttonClassName,mobile:!0}),(0,W.jsxs)(`button`,{className:z(e.buttonClassName,`h-8 w-full justify-start gap-2 px-2.5 text-sm`),onClick:()=>{n(!1),d(!0)},children:[(0,W.jsx)(V,{icon:Go}),`Settings`]})]})]})}var CN=`relative w-full cursor-pointer overflow-hidden rounded-md text-left outline-none select-none touch-pan-y [-webkit-touch-callout:none] focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset`;function wN(e){let t=e.session,n=Ns(t.machine,t.projectId),r=R(e=>I(e,t.machine).icon),[i,a]=(0,U.useState)(null),[o,s]=(0,U.useState)(!1),[c,l]=(0,U.useState)(0),u=(0,U.useRef)(null),d=(0,U.useRef)(null),f=(0,U.useRef)(!1),p=e.activity?.waiting===!0,m=Object.values(e.activity?.tasks??{}).includes(`running`),h=!p&&(e.activity?.running===!0||m),g=e.activity?.running===!0||m,_=!p&&!h&&e.unseen,v=!e.selected&&!p&&!_;function y(){qe(t.machine,t.id,e.scope)}function b(){g?s(!0):y()}function x(e){let n=d.current;d.current=null,l(0),n!==null&&n.swiping&&(f.current=!0,e.clientX-n.x>e.currentTarget.offsetWidth*.4&&(t.status===`inactive`?rt(t.machine,t.id,{status:`active`}):b()))}let S={onClick:()=>{f.current?f.current=!1:e.onSelect()},onPointerDown:t=>{e.saved&&t.pointerType===`touch`&&(f.current=!1,d.current={x:t.clientX,y:t.clientY,swiping:!1})},onPointerMove:e=>{let t=d.current;if(t===null)return;let n=e.clientX-t.x,r=e.clientY-t.y;!t.swiping&&Math.abs(n)<10&&Math.abs(r)<10||(!t.swiping&&n<=Math.abs(r)?d.current=null:(t.swiping=!0,l(Math.max(0,n))))},onPointerUp:x,onPointerCancel:()=>{d.current=null,l(0)}},C=c>0&&(0,W.jsx)(`div`,{className:z(`absolute inset-x-0 flex items-center rounded-md px-4 text-white`,e.slim?`inset-y-0`:`inset-y-0.5`,t.status===`inactive`?`bg-success`:`bg-destructive`),children:(0,W.jsx)(V,{icon:t.status===`inactive`?Bo:zo,className:`size-6`})}),w=(0,W.jsx)(xn,{open:o,onOpenChange:s,children:(0,W.jsxs)(Fn,{children:[(0,W.jsxs)(mn,{children:[(0,W.jsx)(Zn,{children:`Stop running work?`}),(0,W.jsx)(On,{children:`The agent or background tasks are running. Do you really want to stop them?`})]}),(0,W.jsxs)(En,{children:[(0,W.jsx)(Vn,{children:`Cancel`}),(0,W.jsx)(wn,{variant:`destructive`,onClick:y,children:`Stop and Make Inactive`})]})]})}),T=(0,W.jsx)(Ln,{className:`w-44`,onCloseAutoFocus:e=>{u.current!==null&&(e.preventDefault(),u.current.focus(),u.current.select())},children:(0,W.jsx)(JE,{session:t,mobile:!0,onDeactivate:b,onRename:()=>a(t.title)})}),E=i===null?(0,W.jsx)(`span`,{className:z(`min-w-0 flex-1 truncate text-sm`,v?`text-secondary-label font-normal`:`font-medium`,!v&&(e.unseen||p)&&`text-foreground`,!v&&!e.unseen&&!p&&`text-foreground/90`),children:(0,W.jsx)(XE,{session:t})}):(0,W.jsx)(`form`,{className:`min-w-0 flex-1`,onSubmit:e=>{e.preventDefault();let n=i.trim();a(null),n!==``&&n!==t.title&&rt(t.machine,t.id,{title:n})},children:(0,W.jsx)(`input`,{ref:u,value:i,onChange:e=>a(e.target.value),onClick:e=>e.stopPropagation(),onBlur:()=>a(null),onKeyDown:e=>{e.stopPropagation(),e.key===`Escape`&&a(null)},className:`text-foreground ring-ring/50 focus:ring-ring w-full rounded-sm bg-transparent text-sm font-medium ring-1 outline-none ring-inset`})}),D=z(e.selected&&`bg-sidebar-row-active text-sidebar-foreground`,v&&`text-sidebar-muted-foreground/75`,!e.selected&&!v&&`text-sidebar-foreground bg-transparent`);return e.slim?(0,W.jsxs)(`li`,{className:`relative list-none`,children:[C,(0,W.jsxs)(qn,{children:[(0,W.jsx)(Yn,{asChild:!0,disabled:!e.saved,children:(0,W.jsxs)(`div`,{role:`button`,tabIndex:0,className:z(CN,D,`flex h-9 items-center gap-2.5 px-2.5`,c>0&&`bg-sidebar`),style:c>0?{transform:`translateX(${c}px)`}:void 0,...S,onKeyDown:t=>{t.key===`Enter`&&e.onSelect()},children:[(0,W.jsx)(`span`,{className:`flex shrink-0 items-center opacity-40 grayscale`,children:(0,W.jsx)(zs,{machine:t.machine,projectId:t.projectId})}),E,(0,W.jsx)(`span`,{className:`text-secondary-label ml-auto shrink-0 text-xs tabular-nums`,children:on(t.updatedAt)})]})}),T]}),w]}):(0,W.jsxs)(`li`,{className:`relative list-none py-0.5`,children:[C,(0,W.jsxs)(qn,{children:[(0,W.jsx)(Yn,{asChild:!0,disabled:!e.saved,children:(0,W.jsx)(`div`,{role:`button`,tabIndex:0,className:z(CN,D,h&&!e.selected&&`opacity-70`,c>0&&`bg-sidebar`),style:c>0?{transform:`translateX(${c}px)`}:void 0,...S,onKeyDown:t=>{t.key===`Enter`&&e.onSelect()},children:(0,W.jsxs)(`div`,{className:`px-(--sidebar-row-content-inset) py-(--sidebar-content-inset)`,children:[(0,W.jsxs)(`div`,{className:`flex h-6 min-w-0 items-center gap-2`,children:[(0,W.jsx)(zs,{machine:t.machine,projectId:t.projectId,className:`size-5`}),E,t.status===`pinned`&&(0,W.jsx)(V,{icon:Ro,className:`text-muted-foreground/65 size-3 shrink-0`}),(0,W.jsx)(YE,{activity:e.activity,backgroundRunning:m,done:_})]}),(0,W.jsxs)(`div`,{className:`text-secondary-label mt-1 flex h-5 min-w-0 items-center gap-1.5 text-xs`,children:[(0,W.jsx)(Vu,{icon:r,className:`size-3 shrink-0`}),(0,W.jsxs)(`span`,{className:z(`min-w-0 flex-1 truncate`,v?`font-normal`:`font-medium`),children:[n,t.branch!==null&&(0,W.jsx)(`span`,{className:`text-muted-foreground/40 font-normal`,children:` | ${t.branch}`})]}),t.status===`snoozed`&&(0,W.jsx)(V,{icon:Ma,className:`size-3 shrink-0`}),(0,W.jsx)(`span`,{className:`shrink-0 tabular-nums`,children:on(t.updatedAt)})]})]})})}),T]}),w]})}function TN(e){let t=Ns(e.machine,e.projectId),n=R(t=>I(t,e.machine).icon);return(0,W.jsx)(`li`,{className:`list-none py-0.5`,children:(0,W.jsx)(`div`,{role:`button`,tabIndex:0,className:z(CN,`bg-sidebar-row-active text-sidebar-foreground`),onClick:e.onSelect,children:(0,W.jsxs)(`div`,{className:`px-(--sidebar-row-content-inset) py-(--sidebar-content-inset)`,children:[(0,W.jsxs)(`div`,{className:`flex h-6 min-w-0 items-center gap-2`,children:[(0,W.jsx)(zs,{machine:e.machine,projectId:e.projectId,className:`size-5`}),(0,W.jsx)(`span`,{className:`text-foreground min-w-0 flex-1 truncate text-sm font-medium`,children:`New thread`}),(0,W.jsx)(V,{icon:Xo,className:`text-warning-foreground size-4 shrink-0`})]}),(0,W.jsxs)(`div`,{className:`text-secondary-label mt-1 flex h-5 min-w-0 items-center gap-1.5 text-xs`,children:[(0,W.jsx)(Vu,{icon:n,className:`size-3 shrink-0`}),(0,W.jsxs)(`span`,{className:`min-w-0 flex-1 truncate font-medium`,children:[t,(0,W.jsx)(`span`,{className:`text-muted-foreground/40 font-normal`,children:` | Draft`})]}),(0,W.jsx)(`span`,{className:`shrink-0 tabular-nums`,children:`now`})]})]})})})}function EN({className:e,...t}){return(0,W.jsx)(Gs,{"data-slot":`label`,className:z(`flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50`,e),...t})}var DN={216:`O`,223:`s`,248:`o`,273:`d`,295:`h`,305:`i`,320:`l`,322:`l`,359:`t`,383:`s`,384:`b`,385:`B`,387:`b`,390:`O`,392:`c`,393:`D`,394:`D`,396:`d`,398:`E`,400:`E`,402:`f`,403:`G`,407:`I`,409:`k`,410:`l`,412:`M`,413:`N`,414:`n`,415:`O`,421:`p`,427:`t`,429:`t`,430:`T`,434:`V`,436:`y`,438:`z`,477:`e`,485:`g`,544:`N`,545:`d`,549:`z`,564:`l`,565:`n`,566:`t`,567:`j`,570:`A`,571:`C`,572:`c`,573:`L`,574:`T`,575:`s`,576:`z`,579:`B`,580:`U`,581:`V`,582:`E`,583:`e`,584:`J`,585:`j`,586:`Q`,587:`q`,588:`R`,589:`r`,590:`Y`,591:`y`,592:`a`,593:`a`,595:`b`,596:`o`,597:`c`,598:`d`,599:`d`,600:`e`,603:`e`,604:`e`,605:`e`,606:`e`,607:`j`,608:`g`,609:`g`,610:`G`,613:`h`,614:`h`,616:`i`,618:`I`,619:`l`,620:`l`,621:`l`,623:`m`,624:`m`,625:`m`,626:`n`,627:`n`,628:`N`,629:`o`,633:`r`,634:`r`,635:`r`,636:`r`,637:`r`,638:`r`,639:`r`,640:`R`,641:`R`,642:`s`,647:`t`,648:`t`,649:`u`,651:`v`,652:`v`,653:`w`,654:`y`,655:`Y`,656:`z`,657:`z`,663:`c`,665:`B`,666:`e`,667:`G`,668:`H`,669:`j`,670:`k`,671:`L`,672:`q`,686:`h`,867:`a`,868:`e`,869:`i`,870:`o`,871:`u`,872:`c`,873:`d`,874:`h`,875:`m`,876:`r`,877:`t`,878:`v`,879:`x`,7424:`A`,7427:`B`,7428:`C`,7429:`D`,7431:`E`,7432:`e`,7433:`i`,7434:`J`,7435:`K`,7436:`L`,7437:`M`,7438:`N`,7439:`O`,7440:`O`,7441:`o`,7442:`o`,7443:`o`,7446:`o`,7447:`o`,7448:`P`,7449:`R`,7450:`R`,7451:`T`,7452:`U`,7453:`u`,7454:`u`,7455:`m`,7456:`V`,7457:`W`,7458:`Z`,7522:`i`,7523:`r`,7524:`u`,7525:`v`,7834:`a`,7835:`s`,8305:`i`,8341:`h`,8342:`k`,8343:`l`,8344:`m`,8345:`n`,8346:`p`,8347:`s`,8348:`t`,8580:`c`};for(let e=`̀`.codePointAt(0);e<=`ͯ`.codePointAt(0);++e){let t=String.fromCodePoint(e);for(let e of`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz`){let n=(e+t).normalize().codePointAt(0);n>126&&(DN[n]=e)}}var ON={a:[7844,7863],e:[7870,7879],o:[7888,7907],u:[7912,7921]};for(let e of Object.keys(ON)){let t=e.toUpperCase();for(let n=ON[e][0];n<=ON[e][1];++n)DN[n]=n%2==0?t:e}function kN(e){if(e<192||e>8580)return e;let t=DN[e];return t===void 0?e:t.codePointAt(0)}function AN(e){return e}function jN(e){return e}function MN(e,t){return e>t?e:t}var NN=e=>e.split(``).map(e=>e.codePointAt(0)),PN=new Set(` \f
|
|
14
|
+
`,``,``,``,``,`\x1B[99;5u`,`\x1B[100;5u`,`\x1B[111;5u`,`\x1B[122;5u`];function fj(e,t){return e.y<t.y||e.y===t.y&&e.x<t.x}var pj=class{shell=`unknown`;generation=0;core;native=!1;input=!1;clickEvents=!1;inputRef=null;constructor(e){this.core=e}mark(e,t){let n=e.startsWith(`133;`),r=n?4:5;if(e.length>r+1&&e[r+1]!==`;`)return;let i=e.charAt(r);if(!this.core.isAlternateScreen()){if(i===`A`){let r=e.split(`;`);if(r.includes(`k=s`)||r.includes(`k=c`))return;let i=n&&r.includes(`click_events=1`),a=this.shell===`prompt`,o=a&&!this.input&&this.native!==n;if(this.shell=`prompt`,this.native=n,t&&this.trackInput(),o){this.clickEvents=this.clickEvents||i;return}if(this.input=!1,this.clickEvents=i,a)return;this.generation+=1}else if(i===`B`)this.shell=`prompt`,this.input=!0,t&&this.trackInput();else if(i===`C`)this.shell=`command`;else if(i===`D`){if(this.shell===`prompt`&&!this.input)return;this.shell=`unknown`}}}beforeInput(e){this.shell===`prompt`&&dj.some(t=>e.includes(t))&&(this.shell=`unknown`)}reset(){this.release(),this.shell=`unknown`,this.input=!1,this.clickEvents=!1}release(){this.inputRef!==null&&this.core.untrack(this.inputRef),this.inputRef=null}moveCursorInput(e,t,n){if(this.shell!==`prompt`||this.inputRef===null||t===null||t.cursorX<0||t.cursorY<0||this.core.isAlternateScreen()||this.core.isMouseTracking())return null;let r=this.core.trackedPoint(this.inputRef);if(r===null)return null;let i={x:r.x,y:r.y-n};if(fj(e,i))return null;if(this.clickEvents){let t=this.core.scrollbarState();if(t===null)return null;let r=e.y+n-(t.total-t.len);return r<0?null:`\x1b[<0;${e.x+1};${r+1}M`}if(!this.input)return null;let a={x:e.x,y:e.y};a.x>0&&t.rowData[a.y]?.cells[a.x]?.wide===qk.spacerTail&&--a.x;let o={x:t.cursorX,y:t.cursorY};if(fj(a,i)||fj(o,i))return null;let s=fj(a,o),c=s?a:o,l=s?o:a,u=0;for(let e=c.y;e<=l.y;e+=1){let n=t.rowData[e];if(n===void 0)return null;let r=e===l.y?l.x:n.cells.length;for(let t=e===c.y?c.x:0;t<r;t+=1)n.cells[t].text!==``&&(u+=1);if(e<l.y&&!n.wrapsToNext){if(s)return null;break}}let d=s?`ArrowLeft`:`ArrowRight`,f=this.core.encoder.encodeKey(new KeyboardEvent(`keydown`,{key:d,code:d}));return u>0?f.repeat(u):``}trackInput(){this.inputRef===null?this.inputRef=this.core.trackCursor():this.core.retrack(this.inputRef)}},mj=navigator.userAgent.includes(`Mac`),hj=navigator.userAgent.includes(`Windows`),gj=600,_j=1e3,vj=1e4,yj=new TextDecoder(`latin1`),bj=new TextDecoder;function xj(e){let t=/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(e);if(!t)throw Error(`unsupported color ${e}`);return{r:parseInt(t[1],16),g:parseInt(t[2],16),b:parseInt(t[3],16)}}function Sj(e){return[...e.split(`,`).map(e=>e.trim()).filter(e=>e.length>0).map(e=>/^(['"]).*\1$/.test(e)||/^[a-zA-Z][a-zA-Z0-9-]*$/.test(e)?e:`"${e.replaceAll(`"`,``)}"`),`monospace`].join(`, `)}async function Cj(e){try{(await e)?.close()}catch(e){console.warn(`could not decode image`,e)}}var wj=class{element;cols=80;rows=24;canvas;input;context;core;scanner=new AA;handlers;observer;prompt;search;images;pointer;notifications=new wA;options;appearance;metrics;snapshot=null;sized=!1;fitted=!1;frame=0;forceFull=!0;renderFailed=!1;cursorOn=!0;cursorTimer=null;syncTimer=null;renderedCursorY=null;focused=!1;composing=!1;suppressedKeys=new Set;heldOptionKeys=new Set;backlog=[];blocked=!1;epoch=0;title=``;progress={state:0,value:0};disposed=!1;constructor(e,t){this.options=e,this.handlers=t,this.element=document.createElement(`div`),this.element.className=`relative h-full overflow-hidden`,this.canvas=document.createElement(`canvas`),this.canvas.className=`absolute top-0 left-0 cursor-text touch-none`,this.input=document.createElement(`textarea`),this.input.setAttribute(`aria-label`,`Terminal input`),this.input.autocapitalize=`off`,this.input.autocomplete=`off`,this.input.spellcheck=!1,this.input.style.cssText=`position:absolute;left:0;top:0;width:1px;height:1px;opacity:0;padding:0;border:0;resize:none;pointer-events:none;`;let n=document.createElement(`div`);n.className=`absolute top-0 right-0 bottom-0 w-2 cursor-default touch-none`,n.hidden=!0;let r=document.createElement(`div`);r.className=`bg-foreground/15 hover:bg-foreground/30 absolute inset-x-0.5 top-0 rounded-full`,n.append(r),this.element.append(this.canvas,this.input,n);let i=this.canvas.getContext(`2d`,{alpha:!1});if(!i)throw Error(`canvas 2d is unavailable`);this.context=i,this.appearance=this.appearanceFor(e),this.metrics=this.measure(),this.core=new uA(Math.max(1,Math.floor(window.innerWidth/this.metrics.width)),this.rows,e.scrollback,t.onReply,t.onBell),this.prompt=new pj(this.core),this.search=new fA(this.core,()=>this.redraw()),this.images=new GO(this.core),this.pointer=new uj({canvas:this.canvas,scrollbar:n,thumb:r,core:this.core,view:()=>({cols:this.cols,rows:this.rows,metrics:this.metrics,snapshot:this.snapshot,clickToMoveCursor:this.options.clickToMoveCursor}),focus:()=>this.focus(),redraw:()=>this.redraw(),scrollViewport:e=>this.scrollViewport(e),moveCursorTo:e=>this.moveCursorTo(e),onData:t.onData,onLink:t.onLink}),this.applyTerminalOptions(),this.resizeCore(),this.installEvents(),this.observer=new ResizeObserver(()=>this.fit()),this.observer.observe(this.element)}setOptions(e){this.options=e,this.appearance=this.appearanceFor(e),this.metrics=this.measure(),e.clickToMoveCursor||this.prompt.release(),this.applyTerminalOptions(),this.resizeCore(),this.forceFull=!0,this.fit(),this.requestRender()}write(e,t){this.disposed||(this.backlog.push({data:e,replay:t}),this.blocked||this.drain())}reset(){this.epoch+=1,this.backlog=[],this.blocked=!1,this.scanner.reset(),this.prompt.reset(),this.core.reset(),this.applyTerminalOptions(),this.images.clear(),this.core.clearSelection(),this.redraw()}focus(){this.input.focus({preventScroll:!0})}isKittyKeyboard(){return this.core.isKittyKeyboard()}paste(e){let t=this.core.encoder.encodePaste(e);t.length>0&&this.sendInput(t)}presize(e,t){this.fitted||e===this.cols&&t===this.rows||(this.cols=e,this.rows=t,this.resizeCore())}fit(){if(this.disposed)return;let e=this.element.clientWidth,t=this.element.clientHeight;if(e===0||t===0){this.sized=!1;return}this.sized=!0,this.fitted=!0;let n=window.devicePixelRatio||1,r=Math.round(e*n),i=Math.round(t*n);(this.canvas.width!==r||this.canvas.height!==i)&&(this.canvas.width=r,this.canvas.height=i,this.canvas.style.width=`${e}px`,this.canvas.style.height=`${t}px`,this.context.setTransform(n,0,0,n,0,0),this.metrics=this.measure(),this.resizeCore(),this.forceFull=!0);let a=Math.max(1,Math.floor(e/this.metrics.width)),o=Math.max(1,Math.floor(t/this.metrics.height));(a!==this.cols||o!==this.rows)&&(this.cols=a,this.rows=o,this.resizeCore(),this.forceFull=!0,this.handlers.onResize(a,o)),this.renderFrame()}find(e,t,n){let r=this.viewportTop(),i=this.search.find(e,t,n,r);i!==null&&(i.row<r||i.row>=r+this.rows)&&this.scrollViewport(i.row-r-Math.floor(this.rows/2)),this.redraw()}onFindResults(e){return this.search.onResults(e)}clearFind(){this.search.clear(),this.redraw()}replyClipboard(e,t){t.epoch!==this.epoch||t.generation!==this.prompt.generation||t.atPrompt&&this.prompt.shell!==`prompt`||this.handlers.onReply(yA(e,t.selection,t.terminator))}beforeInput(e){this.prompt.beforeInput(e)}dispose(){this.disposed||(this.disposed=!0,this.observer.disconnect(),this.cancelRender(),this.pointer.dispose(),this.search.dispose(),window.removeEventListener(`focus`,this.onWindowFocus),document.removeEventListener(`visibilitychange`,this.onVisibilityChange),this.images.clear(),this.prompt.release(),this.core.dispose(),this.element.remove())}redraw(){this.forceFull=!0,this.requestRender()}resizeCore(){this.core.resize(this.cols,this.rows,this.metrics.width,this.metrics.height,window.devicePixelRatio||1)}appearanceFor(e){let t=e.colors;return{fontSize:e.fontSize,fontFamily:Sj(e.fontFamily),ligatures:e.ligatures,cursorText:t.cursorText,selectionBackground:t.selectionBackground,selectionForeground:t.selectionForeground,matchBackground:t.palette[8],activeMatchBorder:t.palette[3]}}measure(){return tj(this.context,this.options.fontSize,this.appearance.fontFamily,this.options.lineHeight,window.devicePixelRatio||1)}applyTerminalOptions(){let e=this.options.colors;this.core.setColors({foreground:xj(e.foreground),background:xj(e.background),cursor:xj(e.cursor),palette:e.palette.map(xj)}),this.core.setCursor(this.options.cursorStyle,this.options.cursorBlink),this.core.boldIsBright=this.options.boldIsBright,this.core.version=this.options.version,this.core.invalidate()}drain(){for(;!this.blocked&&this.backlog.length>0;){let e=this.backlog.shift();e&&this.process(e)}let e=this.core.title();e!==this.title&&(this.title=e,this.handlers.onTitle(e)),this.search.outputChanged(),this.cursorOn=!0,this.requestRender()}process(e){let t=e.data,n=e.replay;this.core.setReplies(!n);let r=0,i=this.scanner.scan(t,(e,i)=>(this.core.write(t.subarray(r,i)),r=i,this.handleOutput(e,n)));this.core.write(t.subarray(r,i)),i<t.length&&this.backlog.unshift({data:t.subarray(i),replay:n})}handleOutput(e,t){if(e.type===`sixel`)return this.decodeImage(VO(e.data));let n=yj.decode(e.data);if(n.startsWith(`1337;File=`))return this.decodeImage(UO(n.slice(10),{cellWidth:this.metrics.width,cellHeight:this.metrics.height,width:this.cols*this.metrics.width,height:this.rows*this.metrics.height,pixelRatio:window.devicePixelRatio||1}));if(n.startsWith(`133;`)||n.startsWith(`6973;`))return this.prompt.mark(n,this.options.clickToMoveCursor),!1;if(n.startsWith(`52;`)){let r=n.split(`;`),i=r[2];if(t||i===void 0)return!1;if(i===`?`)return this.handlers.onClipboardRead({selection:_A(r[1]),terminator:e.terminator,generation:this.prompt.generation,epoch:this.epoch,atPrompt:this.prompt.shell===`prompt`}),!1;let a=vA(i);return a!==null&&this.handlers.onClipboard(a),!1}if(n===`10;?`||n===`11;?`||n===`12;?`)return t||this.handlers.onReply(bA(n,this.core.currentColors(),e.terminator)),!1;if(n.startsWith(`4;`)){if(!t)for(let t of xA(n,this.core.currentColors().palette,e.terminator))this.handlers.onReply(t);return!1}if(n===`9;4`||n.startsWith(`9;4;`)){let e=SA(n,this.progress);return e!==null&&(this.progress=e,this.handlers.onProgress(e)),!1}if(t)return!1;let r=n.startsWith(`99;`)?this.notifications.add(bj.decode(e.data)):CA(n,e.data);return r!==null&&this.handlers.onNotify(r.title,r.body),!1}decodeImage(e){return this.blocked=!0,this.placeImage(e,this.epoch,window.devicePixelRatio||1),!0}async placeImage(e,t,n){let r=0,i=new Promise(e=>{r=window.setTimeout(()=>e(`timeout`),vj)});try{let r=await Promise.race([e,i]);r===`timeout`?(console.warn(`image decoding took too long, skipping the image`),Cj(e)):r!==null&&(t===this.epoch&&!this.disposed?this.images.place(r,n,this.metrics.height):r.close())}catch(e){console.warn(`could not decode image`,e)}window.clearTimeout(r),t!==this.epoch||this.disposed||(this.blocked=!1,this.drain())}moveCursorTo(e){if(!this.options.clickToMoveCursor)return;let t=this.prompt.moveCursorInput(e,this.snapshot,this.viewportTop());t!==null&&(t!==``&&this.sendInput(t),this.core.clearSelection(),this.redraw())}sendInput(e){this.prompt.beforeInput(e),this.core.scrollbarState()?.offset!==this.maxOffset()&&(this.core.scrollToBottom(),this.redraw()),this.handlers.onData(e)}maxOffset(){let e=this.core.scrollbarState();return e?Math.max(0,e.total-e.len):0}viewportTop(){return this.core.toScreen({x:0,y:0})?.y??0}scrollViewport(e){let t=this.core.scrollbarState(),n=Math.trunc(e);if(t!==null){let e=Math.max(0,t.total-t.len);n=Math.max(0,Math.min(t.offset+n,e))-t.offset}n!==0&&(this.core.scroll(n),this.redraw())}requestRender(){!this.disposed&&this.sized&&this.frame===0&&(this.frame=window.requestAnimationFrame(()=>{this.frame=0,this.renderFrame()}))}cancelRender(){this.frame!==0&&window.cancelAnimationFrame(this.frame),this.frame=0,this.cursorTimer!==null&&window.clearTimeout(this.cursorTimer),this.cursorTimer=null,this.syncTimer!==null&&window.clearTimeout(this.syncTimer),this.syncTimer=null}renderFrame(){if(!this.disposed&&this.sized&&this.element.isConnected){this.frame!==0&&window.cancelAnimationFrame(this.frame),this.frame=0;try{this.draw(),this.renderFailed=!1}catch(e){this.renderFailed||console.error(`could not draw the terminal`,e),this.renderFailed=!0}}}draw(){if(this.core.isSynchronizedOutput()){this.syncTimer===null&&(this.syncTimer=window.setTimeout(()=>{this.syncTimer=null,this.core.endSynchronizedOutput(),this.requestRender()},_j));return}this.syncTimer!==null&&window.clearTimeout(this.syncTimer),this.syncTimer=null;let e=this.core.snapshot();this.snapshot=e;let t=this.focused&&e.cursorBlinking&&e.cursorVisible;t||(this.cursorOn=!0);let n=this.viewportTop(),r=this.images.visible(n,this.rows,this.metrics.height),i=this.core.cellSize(),a=this.core.kitty.images(e.rowData,i);ij({context:this.context,snapshot:e,metrics:this.metrics,appearance:this.appearance,forceFull:this.forceFull||r.length>0||a.length>0,cursorOn:this.cursorOn,previousCursorY:this.renderedCursorY,focused:this.focused,hoveredLink:this.pointer.hoveredLink?.range??null,highlights:this.search.highlights(e,n),pixelRatio:window.devicePixelRatio||1,drawLayer:e=>Pk(this.context,a,e,this.metrics,i)}),Pk(this.context,a,`aboveText`,this.metrics,i);for(let e of r)this.context.drawImage(e.bitmap,e.x*this.metrics.width,e.y*this.metrics.height,e.width,e.height);this.forceFull=r.length>0||a.length>0,this.renderedCursorY=this.cursorOn&&e.cursorVisible&&e.cursorY>=0?e.cursorY:null,e.cursorX>=0&&e.cursorY>=0&&(this.input.style.left=`${e.cursorX*this.metrics.width}px`,this.input.style.top=`${e.cursorY*this.metrics.height}px`),this.pointer.updateScrollbar(this.element.clientHeight),this.cursorTimer!==null&&window.clearTimeout(this.cursorTimer),this.cursorTimer=null,t&&(this.cursorTimer=window.setTimeout(()=>{this.cursorTimer=null,this.cursorOn=!this.cursorOn,this.requestRender()},gj))}copySelection(){let e=this.core.selectionText();e.length!==0&&(window.isSecureContext?navigator.clipboard.writeText(e):console.warn(`copy from the terminal needs https or localhost`))}optionIsMeta(e){if(!mj||!e.altKey||e.metaKey)return!1;let t=this.options.optionAsMeta;if(t===`off`)return!1;if(t===`both`)return!0;if(t===`left`)return this.heldOptionKeys.has(`AltLeft`);if(t===`right`)return this.heldOptionKeys.has(`AltRight`);throw Error(`unknown option as meta mode ${t}`)}onKeyDown=e=>{if((e.code===`AltLeft`||e.code===`AltRight`)&&this.heldOptionKeys.add(e.code),!this.handlers.beforeKey(e)){this.suppressedKeys.add(e.code);return}let t=this.optionIsMeta(e),n=t&&this.core.encoder.metaText(e)!==null;if(e.isComposing||this.composing||!n&&(e.key===`Process`||e.keyCode===229)||mj&&this.options.optionAsMeta!==`off`&&!t&&e.altKey&&!e.ctrlKey&&!e.metaKey&&([...e.key].length===1||e.key===`Dead`)||!n&&e.getModifierState(`AltGraph`)&&[...e.key].length===1){this.suppressedKeys.add(e.code);return}let r=e.key.toLowerCase(),i=hj&&this.options.windowsCopyPaste&&e.ctrlKey&&!e.shiftKey&&!e.altKey&&!e.metaKey;if(i&&r===`c`&&this.core.selectionText().length>0){this.copySelection(),this.core.clearSelection(),this.redraw(),e.preventDefault(),this.suppressedKeys.add(e.code);return}if(mj?e.metaKey&&r===`c`:e.ctrlKey&&e.shiftKey&&r===`c`||e.ctrlKey&&!e.shiftKey&&r===`insert`){this.copySelection(),e.preventDefault(),this.suppressedKeys.add(e.code);return}if((mj?e.metaKey&&r===`v`:e.ctrlKey&&e.shiftKey&&r===`v`||e.shiftKey&&!e.ctrlKey&&r===`insert`||i&&r===`v`)||mj&&e.metaKey&&r===`q`){this.suppressedKeys.add(e.code);return}let a=this.core.encoder.encodeKey(e,`press`,n);a.length!==0&&(this.suppressedKeys.delete(e.code),e.preventDefault(),e.stopPropagation(),this.core.selectionText().length>0&&!e.shiftKey&&(this.core.clearSelection(),this.forceFull=!0),this.sendInput(a))};onKeyUp=e=>{if(this.heldOptionKeys.delete(e.code),this.suppressedKeys.delete(e.code)||e.isComposing||this.composing)return;let t=this.core.encoder.encodeKey(e,`release`,this.optionIsMeta(e));t.length!==0&&(e.preventDefault(),this.handlers.onData(t))};onInput=e=>{let t=e;if(this.composing||t.isComposing)return;let n=this.input.value||t.data||``;this.input.value=``,n.length>0&&this.sendInput(n)};onCompositionStart=()=>{this.composing=!0};onCompositionEnd=e=>{this.composing=!1;let t=this.input.value||e.data;this.input.value=``,t.length>0&&this.sendInput(t)};onPaste=e=>{e.preventDefault();let t=e.clipboardData?.getData(`text/plain`)??``;t.length>0&&this.paste(t)};onCopy=e=>{let t=this.core.selectionText();t.length!==0&&e.clipboardData&&(e.preventDefault(),e.clipboardData.setData(`text/plain`,t))};onWindowFocus=()=>{mj&&this.options.optionAsMeta!==`off`&&this.core.encoder.refreshKeyboardLayout()};onContextRestored=()=>{let e=window.devicePixelRatio||1;this.context.setTransform(e,0,0,e,0,0),this.redraw()};onVisibilityChange=()=>{document.visibilityState===`visible`&&this.redraw()};onFocus=()=>{this.focused=!0,this.cursorOn=!0,this.requestRender(),!this.disposed&&this.core.isFocusReporting()&&this.handlers.onReply(`\x1B[I`)};onBlur=()=>{this.focused=!1,this.heldOptionKeys.clear(),this.cursorOn=!0,this.requestRender(),!this.disposed&&this.core.isFocusReporting()&&this.handlers.onReply(`\x1B[O`)};installEvents(){this.input.addEventListener(`keydown`,this.onKeyDown),this.input.addEventListener(`keyup`,this.onKeyUp),this.input.addEventListener(`input`,this.onInput),this.input.addEventListener(`compositionstart`,this.onCompositionStart),this.input.addEventListener(`compositionend`,this.onCompositionEnd),this.input.addEventListener(`paste`,this.onPaste),this.input.addEventListener(`copy`,this.onCopy),this.input.addEventListener(`focus`,this.onFocus),this.input.addEventListener(`blur`,this.onBlur),this.canvas.addEventListener(`contextrestored`,this.onContextRestored),window.addEventListener(`focus`,this.onWindowFocus),document.addEventListener(`visibilitychange`,this.onVisibilityChange)}},Tj=new Map,Ej=new Map,Dj=null,Oj=0;function kj(e){return aM().open&&cM()?.tabId===e&&!document.hidden&&document.hasFocus()}function Aj(e){if(kj(e))return!1;let t=aM();return t.alerts.includes(e)||oM({alerts:[...t.alerts,e]}),!0}function jj(e){if(!Aj(e)||Ej.has(e))return;let t=Tj.get(e);t!==void 0&&performance.now()-t<5e3||Ej.set(e,window.setTimeout(()=>{Ej.delete(e),kj(e)||(Tj.set(e,performance.now()),Nj(e,``,`Bell`))},500))}function Mj(e,t,n){Aj(e)&&(window.clearTimeout(Ej.get(e)),Ej.delete(e),Tj.set(e,performance.now()),Nj(e,t,n))}function Nj(e,t,n){let r=dM(e);r&&na(t||fM(r),n,{machine:rM(),project:r.projectId??`global`,tabId:e}).catch(e=>console.error(`could not show a notification`,e))}function Pj(){let e=performance.now();if(e-Oj<150)return;Oj=e,Dj??=new AudioContext,Dj.state===`suspended`&&Dj.resume();let t=Dj.createOscillator(),n=Dj.createGain(),r=Dj.currentTime;t.frequency.value=880,n.gain.setValueAtTime(.1,r),n.gain.exponentialRampToValueAtTime(.001,r+.15),t.connect(n).connect(Dj.destination),t.start(r),t.stop(r+.15)}function Fj(e){return{alerts:aM().alerts.filter(t=>e(t)&&!kj(t))}}function Ij(e){window.clearTimeout(Ej.get(e)),Ej.delete(e),Tj.delete(e)}function Lj(e){return e.key===`Enter`&&e.shiftKey&&!e.ctrlKey&&!e.altKey&&!e.metaKey}function Rj(e){let t=new wj(nM(),{onData:t=>{aM().status===`active`&&vM(e,zj(t))},onReply:t=>{t===`\x1B[I`||t===`\x1B[O`?vM(e,t):yM(e,t)},onResize:(t,n)=>gM({type:`resize`,id:e,cols:t,rows:n}),onTitle:t=>oM({titles:{...aM().titles,[e]:t}}),onProgress:t=>oM({progress:{...aM().progress,[e]:t}}),onBell:()=>{let n=sM().behavior;n.bellSound&&Pj(),n.bellFlash&&t.element.isConnected&&!document.hidden&&t.element.animate([{opacity:.4},{opacity:1}],{duration:200,easing:`ease-out`}),jj(e)},onNotify:(t,n)=>Mj(e,t,n),onClipboard:yT,onClipboardRead:n=>{kj(e)&&bT(e=>t.replyClipboard(e,n))},onLink:e=>{e.startsWith(`file:`)?Ce(e):window.open(e,`_blank`,`noopener`)},beforeKey:n=>{if(n.type!==`keydown`)return!0;let r=sM(),i=I(L(),rM()).system;if(i===null)throw Error(`the terminal machine is not connected`);let a=i.platform;if(aM().status===`active`&&r.behavior.modernizeShiftEnter&&Lj(n)&&!t.isKittyKeyboard())return n.preventDefault(),t.beforeInput(`\x1B\r`),vM(e,`\x1B\r`),!1;if(aM().status===`active`&&r.behavior.pasteBrowserImages&&window.isSecureContext&&ST(n,a)&&!(St&&r.behavior.windowsCopyPaste&&n.ctrlKey)){n.preventDefault();let r=xT[a].data;return t.beforeInput(r),CT(rM(),t).then(t=>{t||vM(e,r)}).catch(t=>{TT(t),vM(e,r)}),!1}return!DM(n)||(n.preventDefault(),oM({finding:e}),document.querySelector(`[data-find]`)?.select(),!1)}});return t.element.addEventListener(`paste`,e=>{if(!e.clipboardData||e.clipboardData.getData(`text/plain`)!==``)return;let n=[...e.clipboardData.files].filter(e=>e.type.startsWith(`image/`));n.length!==0&&(e.preventDefault(),e.stopPropagation(),wT(rM(),t,n).catch(TT))},!0),t}function zj(e){if(!aM().ctrl||(oM({ctrl:!1}),e.length!==1))return e;let t=e.toUpperCase().charCodeAt(0);return t>=64&&t<=95?String.fromCharCode(t-64):e}function Bj(e,t){dt(e,t)}function Vj(e){let t=e.terminals.map(uM),n=localStorage.getItem(`lastTerminalView`);Bj(e.id,t.find(e=>e===n)??t.at(0)??`global`)}async function Hj(e,t){try{await N(e,`terminal`,{type:`createTab`,projectId:t})}catch(e){console.error(`terminal request failed`,e);return}Bj(e,t??`global`)}function Uj(){let e=aM(),t=ce();if(t===null||e.instance===null||t!==rM()||lM(e.layout,f()).length>0)return;let n=e.layout.tabs.at(0);if(n!==void 0){Bj(t,uM(n));return}let r=L().machines.find(e=>e.id!==t&&e.status===`online`&&e.terminals.length>0);r===void 0?yt(`chat`,()=>void ke.navigate({to:`/`,search:{},replace:!0})):Vj(r)}function Wj(){return{titles:{},progress:{},alerts:[],finding:null}}var Gj=new TextEncoder,Kj=new Map,qj=new Set,Jj=new Set,Yj={status:`connecting`,failure:null,loaded:!1,open:!1,instance:null,layout:{tabs:[],active:{}},ctrl:!1,...Wj()},Xj=null,Zj=null,Qj=!1;async function $j(){mM(),ke.history.subscribe(mM);try{await Promise.all([tk(),mf(sM())]),oM({loaded:!0})}catch(e){console.error(`could not start the terminal`,e),oM({failure:Ot(e)});return}et({close:e=>{e===Zj&&oM({status:`connecting`})},terminal:(e,t)=>{e===Zj&&TM(t)},frame:(e,t)=>{e===Zj&&wM(t)}}),eM(),ke.history.subscribe(eM),ke.history.subscribe(Uj),document.addEventListener(`visibilitychange`,()=>oM({})),window.addEventListener(`focus`,()=>{oM({}),Xj!==null&&OM(Xj,kM(Xj))}),window.addEventListener(`blur`,()=>oM({})),`serviceWorker`in navigator&&navigator.serviceWorker.addEventListener(`message`,e=>{e.data.type===`select`&&hM(e.data.machine,e.data.project,e.data.tabId)});let e=L().prefs,t=tM();j(()=>{eM();let n=L().prefs,r=tM(),i=n.theme!==e.theme||n.terminal!==e.terminal||r!==t;e=n,t=r,i&&jM()}),MM()}function eM(){let e=ce()??L().selection?.machine??null;if(e!==Zj&&(Zj!==null&&Qj&&gM({type:`detach`}),EM([]),qj.clear(),Zj=e,Qj=!1,oM({status:`connecting`,instance:null,layout:{tabs:[],active:{}},...Wj()})),Zj===null)return;let t=I(L(),Zj).status===`online`;t&&!Qj&&(Qj=!0,gM({type:`attach`})),t||(Qj=!1)}function tM(){return Zj===null?null:I(L(),Zj).config?.terminal.behavior.terminalIdentity??null}function nM(){if(Zj===null)throw Error(`the terminal has no machine`);let e=I(L(),Zj);if(e.config===null||e.system===null)throw Error(`${e.name} is not connected`);return hf(sM(),e.config.terminal.behavior.terminalIdentity)}function rM(){if(Zj===null)throw Error(`the terminal has no machine`);return Zj}function iM(e){return Jj.add(e),()=>{Jj.delete(e)}}function aM(){return Yj}function oM(e){Yj={...Yj,...e},Yj={...Yj,...Fj(e=>Kj.has(e))};for(let e of Jj)e()}function sM(){return L().prefs.terminal}function cM(){let e=ce()===null?L().selection?.projectId:f();return e===void 0?null:{view:e,tabs:lM(Yj.layout,e),tabId:Yj.layout.active[e]??null}}function lM(e,t){return e.tabs.filter(e=>uM(e)===t)}function uM(e){return e.projectId??`global`}function dM(e){return Yj.layout.tabs.find(t=>t.id===e)}function fM(e){return(e.customName??Yj.titles[e.id])||`Terminal`}function pM(e){e?oe({bottom:`terminal`}):yt(`overlay`,()=>oe({bottom:void 0}))}function mM(){let e=pt().bottom===`terminal`||ce()!==null;e!==Yj.open&&oM({open:e})}function hM(e,t,n){if(t===`global`)Bj(e,_e);else{let n=L().selection;(n?.machine!==e||n.projectId!==t)&&He({machine:e,projectId:t,sessionId:null}),pM(!0)}_M(e,{type:`select`,view:t,tabId:n})}function gM(e){Zj!==null&&_M(Zj,e)}function _M(e,t){w(e)&&N(e,`terminal`,t).catch(e=>console.error(`terminal request failed`,e))}function vM(e,t){Zj!==null&&he(Zj,0,e,typeof t==`string`?Gj.encode(t):t)}function yM(e,t){Zj!==null&&he(Zj,1,e,Gj.encode(t))}function bM(e,t,n,r){kM(e).find(t,n,r)}function xM(e,t){return kM(e).onFindResults(t)}function SM(e){let t=kM(e);t.clearFind(),oM({finding:null}),t.focus()}function CM(){oM({ctrl:!Yj.ctrl})}function wM(e){let t=Kj.get(e.id);if(!t)return;let n=e.kind===3,r=n&&qj.delete(e.id);r&&t.reset(),t.write(e.data,n),r&&qj.size===0&&oM({status:`active`})}function TM(e){let t=e.type===`active`&&e.instance!==Yj.instance;if(t&&EM([]),EM(e.layout.tabs),e.type===`active`){qj.clear(),Kj.forEach((e,t)=>{qj.add(t),e.element.isConnected&&OM(t,e)}),oM({...t&&{instance:e.instance,...Wj()},status:qj.size===0?`active`:`connecting`,layout:e.layout}),Uj();return}for(let e of qj)Kj.has(e)||qj.delete(e);let n=L().selection?.projectId,r=n!==void 0&&lM(Yj.layout,n).length>0&&lM(e.layout,n).length===0;oM({status:qj.size===0?`active`:`connecting`,layout:e.layout}),r&&Yj.open&&pM(!1),Uj()}function EM(e){let t=new Set(e.map(e=>e.id));Kj.forEach((e,n)=>{t.has(n)||(e.dispose(),Kj.delete(n),Ij(n))});for(let e of t)Kj.has(e)||Kj.set(e,Rj(e))}function DM(e){return e.key.toLowerCase()===`f`?wt?e.metaKey&&!e.ctrlKey&&!e.altKey:e.ctrlKey&&e.shiftKey&&!e.altKey&&!e.metaKey:!1}function OM(e,t){gM({type:`resize`,id:e,cols:t.cols,rows:t.rows})}function kM(e){let t=Kj.get(e);if(!t)throw Error(`terminal ${e} does not exist`);return t}function AM(e,t){let n=kM(e);t.append(n.element),n.fit();for(let e of Kj.values())e.presize(n.cols,n.rows);return Xj=e,OM(e,n),n.focus(),()=>{n.element.remove(),Xj===e&&(Xj=null)}}async function jM(){if(await mf(sM()),Kj.size>0){let e=nM();for(let t of Kj.values())t.setOptions(e)}oM({})}function MM(){let e=pt(),t=ce(),n=t??e.machine,r=t===null?e.project:_e,i=e.terminal;if(n===void 0||r===void 0||i===void 0)return;oe({terminal:void 0});let a=iM(()=>{Yj.status===`active`&&Zj===n&&(a(),hM(n,r,Number(i)))})}var NM=null,PM=null,FM=new Set,IM=new Set;function LM(e){return IM.add(e),()=>{IM.delete(e)}}function RM(){return NM}function zM(){NM!==null&&HM({open:!1,closing:NM.closing})}function BM(){return PM}function VM(){PM!==null&&UM({open:!1,closing:PM.closing})}function HM(e){NM=e;for(let e of IM)e()}function UM(e){PM=e;for(let e of IM)e()}function WM(){return document.querySelector(`[role="dialog"][data-state="open"], [role="alertdialog"][data-state="open"]`)!==null}async function GM(e,t){try{let n=await Promise.race([N(e,`terminal.busy`,{id:t}),new Promise((e,t)=>window.setTimeout(()=>t(Error(`timed out`)),5e3))]);return`error`in n?(console.error(`could not check whether tab ${t} is running a program`,n.error),{checked:!1}):{checked:!0,program:n.program}}catch(e){return console.error(`could not check whether a program is running`,e),{checked:!1}}}async function KM(e){if(!sM().behavior.confirmCloseBusyTab){gM({type:`closeTab`,id:e});return}if(!dM(e)||FM.has(e))return;FM.add(e);let t=await GM(rM(),e);if(FM.delete(e),t.checked&&t.program===null){gM({type:`closeTab`,id:e});return}let n=dM(e);n&&!WM()&&HM({open:!0,closing:{id:e,name:fM(n),program:t.checked?t.program:null}})}function qM(e){for(let t of e)_M(t.machine,{type:`closeTab`,id:t.id})}async function JM(e){if(!sM().behavior.confirmCloseBusyTab){qM(e);return}let t=await Promise.all(e.map(e=>GM(e.machine,e.id)));if(t.every(e=>e.checked&&e.program===null)){qM(e);return}if(WM())return;let n=t.flatMap(e=>e.checked&&e.program!==null?[e.program]:[]);UM({open:!0,closing:{tabs:e,programs:[...new Set(n)]}})}var YM=wt?`meta+t`:`ctrl+shift+t`,XM=wt?`meta+w`:`ctrl+shift+w`,ZM=`ctrl+tab`,QM=`ctrl+shift+tab`;function $M(){let e=cM()?.tabId??null;aM().open&&e!==null&&kM(e).focus()}function eN(){return Ms([YM,XM,ZM,QM],(e,t)=>{e.preventDefault(),e.stopPropagation();let n=cM();if(n===null)return;if(t.hotkey===YM){gM({type:`createTab`,projectId:n.view===`global`?null:n.view});return}if(n.tabId===null)return;if(t.hotkey===XM){KM(n.tabId);return}let r;if(t.hotkey===ZM)r=1;else if(t.hotkey===QM)r=-1;else throw Error(`unknown terminal shortcut ${t.hotkey}`);let i=n.tabs,a=i[(i.findIndex(e=>e.id===n.tabId)+r+i.length)%i.length];a&&gM({type:`select`,view:n.view,tabId:a.id})},{enabled:()=>sM().behavior.captureShortcuts,enableOnFormTags:!0,eventListenerOptions:{capture:!0}})}function tN(e){let[t,n]=(0,U.useState)(e.name);return(0,W.jsx)(Or,{open:!0,onOpenChange:t=>{t||e.onDone()},children:(0,W.jsx)(xr,{onCloseAutoFocus:iN,children:(0,W.jsxs)(`form`,{className:`grid gap-4`,onSubmit:n=>{n.preventDefault(),gM({type:`renameTab`,id:e.id,name:t.trim()}),e.onDone()},children:[(0,W.jsx)(Sr,{children:(0,W.jsx)(Tr,{children:`Rename tab`})}),(0,W.jsx)(Hd,{"aria-label":`Name`,placeholder:`Use terminal title`,value:t,onChange:e=>n(e.target.value)}),(0,W.jsxs)(kr,{children:[(0,W.jsx)(H,{type:`button`,variant:`outline`,onClick:e.onDone,children:`Cancel`}),(0,W.jsx)(H,{type:`submit`,children:`Rename`})]})]})})})}function nN(){let e=(0,U.useSyncExternalStore)(LM,RM),t=(0,U.useRef)(null);if(e===null)return null;let n=e.closing;return(0,W.jsx)(xn,{open:e.open,onOpenChange:e=>{e||zM()},children:(0,W.jsxs)(Fn,{onOpenAutoFocus:e=>{e.preventDefault(),t.current?.focus()},onCloseAutoFocus:iN,children:[(0,W.jsxs)(mn,{children:[(0,W.jsxs)(Zn,{children:[`Close “`,n.name,`”?`]}),(0,W.jsx)(On,{children:n.program===null?`OffSite couldn’t check whether a program is still running.`:`${n.program} is still running.`})]}),(0,W.jsxs)(En,{children:[(0,W.jsx)(Vn,{children:`Cancel`}),(0,W.jsx)(wn,{ref:t,variant:`destructive`,onClick:()=>gM({type:`closeTab`,id:n.id}),children:`Close`})]})]})})}function rN(){let e=(0,U.useSyncExternalStore)(LM,BM);if(e===null)return null;let t=e.closing;return(0,W.jsx)(xn,{open:e.open,onOpenChange:e=>{e||VM()},children:(0,W.jsxs)(Fn,{onCloseAutoFocus:iN,children:[(0,W.jsxs)(mn,{children:[(0,W.jsxs)(Zn,{children:[`Close `,t.tabs.length,` `,t.tabs.length===1?`terminal`:`terminals`,`?`]}),(0,W.jsx)(On,{children:t.programs.length===0?`OffSite couldn’t check whether programs are still running.`:`Still running: ${t.programs.join(`, `)}.`})]}),(0,W.jsxs)(En,{children:[(0,W.jsx)(Vn,{children:`Cancel`}),(0,W.jsx)(wn,{variant:`destructive`,onClick:()=>qM(t.tabs),children:`Close all`})]})]})})}function iN(e){e.preventDefault();let t=document.querySelector(`[role="dialog"], [role="alertdialog"]`);t===null?$M():t.focus()}function aN(e){let t=R(e=>e.machines).filter(e=>e.status===`online`),n=t.some(e=>e.terminals.length>0);return t.length===0?null:(0,W.jsxs)(Qt,{children:[(0,W.jsx)(un,{asChild:!0,children:(0,W.jsx)(`button`,{className:z(`text-muted-foreground hover:text-foreground absolute top-1 right-1 grid size-6 cursor-pointer place-items-center rounded-md opacity-0 transition-opacity group-hover/terminal:opacity-100 group-has-[[data-state=open]]/terminal:opacity-100 focus-visible:opacity-100`,e.mobile&&`text-popover-foreground`,n?`pointer-coarse:opacity-100`:`pointer-coarse:pointer-events-none`),"aria-label":`New terminal`,title:`New terminal`,children:(0,W.jsx)(V,{icon:ka,className:`size-4`})})}),(0,W.jsx)(tn,{side:e.mobile?`bottom`:`right`,align:`end`,className:`max-h-80 w-auto min-w-40 overflow-y-auto`,onCloseAutoFocus:e=>e.preventDefault(),children:(0,W.jsx)(oN,{})})]})}function oN(e){let t=R(e=>e.machines),n=R(e=>e.projects),r=e.contextMenu?Un:Gt;return t.filter(e=>e.status===`online`).flatMap(e=>[(0,W.jsxs)(r,{onSelect:()=>void Hj(e.id,null),children:[(0,W.jsx)(Vu,{icon:e.icon}),(0,W.jsx)(`span`,{className:`max-w-60 truncate`,children:e.name})]},e.id),...n.filter(t=>t.machine===e.id).map(t=>(0,W.jsxs)(r,{className:`pl-7`,onSelect:()=>void Hj(e.id,t.id),children:[(0,W.jsx)(zs,{machine:e.id,projectId:t.id,className:`size-4`}),(0,W.jsx)(`span`,{className:`max-w-60 truncate`,children:t.name})]},`${e.id}:${t.id}`))])}function sN(e){let t=(0,U.useRef)(null),[n,r]=(0,U.useState)(``),[i,a]=(0,U.useState)({resultIndex:-1,resultCount:0});(0,U.useEffect)(()=>xM(e.id,a),[e.id]),(0,U.useEffect)(()=>t.current?.focus(),[]);function o(t,n,i){r(t),bM(e.id,t,n,i)}return(0,W.jsxs)(`div`,{className:`bg-card absolute top-2 right-4 z-10 flex items-center gap-1 rounded-lg border p-1 shadow-lg`,children:[(0,W.jsx)(Hd,{ref:t,"data-find":!0,className:`h-7 w-52`,placeholder:`Find`,value:n,onChange:e=>o(e.target.value,!1,!0),onKeyDown:t=>{t.key===`Escape`?(t.preventDefault(),SM(e.id)):t.key===`Enter`?(t.preventDefault(),o(n,t.shiftKey,!1)):DM(t.nativeEvent)&&(t.preventDefault(),t.currentTarget.select())}}),(0,W.jsx)(`span`,{className:`text-muted-foreground w-16 text-center text-xs tabular-nums`,children:n===``?``:i.resultCount===0?`No results`:`${i.resultIndex+1} of ${i.resultCount}`}),(0,W.jsx)(H,{variant:`ghost`,size:`icon-sm`,"aria-label":`Previous match`,onClick:()=>o(n,!0,!1),children:(0,W.jsx)(V,{icon:Ha})}),(0,W.jsx)(H,{variant:`ghost`,size:`icon-sm`,"aria-label":`Next match`,onClick:()=>o(n,!1,!1),children:(0,W.jsx)(V,{icon:In})}),(0,W.jsx)(H,{variant:`ghost`,size:`icon-sm`,"aria-label":`Close find`,onClick:()=>SM(e.id),children:(0,W.jsx)(V,{icon:Ja})})]})}var cN=[{label:`Esc`,sequence:`\x1B`},{label:`Tab`,sequence:` `},{label:`↑`,sequence:`\x1B[A`},{label:`↓`,sequence:`\x1B[B`},{label:`←`,sequence:`\x1B[D`},{label:`→`,sequence:`\x1B[C`}];function lN(e){let t=(0,U.useSyncExternalStore)(iM,aM),n=t.status===`active`,r=lM(t.layout,e.view),i=t.layout.active[e.view]??null,a=eN();(0,U.useEffect)(()=>{n&&!e.page&&gM({type:`select`,view:e.view,tabId:null})},[e.view,n,e.page]);function o(){gM({type:`createTab`,projectId:e.view===`global`?null:e.view})}return t.loaded?(0,W.jsxs)(`div`,{ref:a,className:`flex h-full flex-col text-sm`,children:[(0,W.jsxs)(`header`,{className:z(`flex h-9 flex-none select-none`,e.tabSize===`lg`&&`h-(--workspace-topbar-height)`,r.length===1?`bg-background`:`bg-sidebar`),children:[e.leading&&(0,W.jsx)(`div`,{className:`flex flex-none items-center border-b px-1.5`,children:e.leading}),(0,W.jsx)(`div`,{className:`flex min-w-0 flex-1 [scrollbar-width:none] overflow-x-auto`,children:r.map(n=>(0,W.jsx)(dN,{tab:n,children:(0,W.jsxs)(`div`,{className:z(`group/tab text-muted-foreground hover:text-foreground relative flex min-w-28 flex-1 items-center justify-center border-r border-b px-7 text-xs transition-colors last:border-r-0`,e.tabSize===`lg`&&`text-[13px]`,n.id===i&&`bg-background text-foreground border-b-transparent`),onMouseDown:e=>e.preventDefault(),onClick:()=>gM({type:`select`,view:e.view,tabId:n.id}),children:[(0,W.jsx)(`span`,{className:`truncate`,children:fM(n)}),(0,W.jsx)(fN,{id:n.id,className:`ml-1.5 size-1.5 flex-none rounded-full`}),(0,W.jsx)(pN,{progress:t.progress[n.id]}),(0,W.jsx)(`button`,{className:z(`text-muted-foreground hover:bg-accent hover:text-foreground absolute left-1.5 grid size-4.5 place-items-center rounded opacity-0 transition-opacity group-hover/tab:opacity-100`,n.id===i&&`pointer-coarse:opacity-100`),"aria-label":`Close tab`,onClick:e=>{e.stopPropagation(),KM(n.id)},children:(0,W.jsx)(V,{icon:Ja,className:`size-3`})})]})},n.id))}),(0,W.jsx)(`button`,{className:z(`text-muted-foreground hover:text-foreground grid w-8 flex-none place-items-center transition-colors`,r.length>1&&`border-b border-l`),"aria-label":`New tab`,title:`New tab`,onClick:o,children:(0,W.jsx)(V,{icon:ka,className:`size-4`})})]}),(0,W.jsxs)(`div`,{className:`relative min-h-0 flex-1`,children:[i!==null&&(0,W.jsx)(uN,{id:i},`${t.instance}-${i}`),i!==null&&t.finding===i&&(0,W.jsx)(sN,{id:i},i),n&&i===null&&!e.page&&(0,W.jsx)(`button`,{className:`text-muted-foreground hover:text-foreground grid size-full cursor-pointer place-items-center text-xs transition-colors`,onClick:o,children:`New terminal`}),!n&&(0,W.jsx)(`div`,{className:`bg-background/80 animate-in fade-in absolute inset-0 z-20 grid place-items-center p-6 text-center backdrop-blur-md duration-200`,children:(0,W.jsxs)(`div`,{className:`flex flex-col items-center gap-3`,children:[(0,W.jsx)(`span`,{className:`border-foreground/15 border-t-foreground/70 size-6 animate-spin rounded-full border-[3px]`}),(0,W.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:`Connecting. Your terminals keep running while you wait.`})]})})]}),i!==null&&(0,W.jsxs)(`div`,{className:`bg-card hidden flex-none gap-1.5 overflow-x-auto border-t p-1.5 pointer-coarse:flex`,children:[cN.map(e=>(0,W.jsx)(H,{variant:`secondary`,className:`min-w-11`,onPointerDown:e=>e.preventDefault(),onClick:()=>vM(i,e.sequence),children:e.label},e.label)),(0,W.jsx)(H,{variant:t.ctrl?`default`:`secondary`,className:`min-w-11`,onPointerDown:e=>e.preventDefault(),onClick:CM,children:`Ctrl`})]}),(0,W.jsx)(nN,{})]}):(0,W.jsx)(`div`,{className:`text-muted-foreground grid h-full place-items-center p-4 text-xs whitespace-pre-wrap`,children:t.failure===null?`Starting the terminal…`:`The terminal could not start: ${t.failure}`})}function uN(e){let t=(0,U.useRef)(null);return(0,U.useEffect)(()=>{if(!t.current)throw Error(`terminal container missing`);return AM(e.id,t.current)},[e.id]),(0,W.jsx)(`div`,{className:`bg-background absolute inset-0 pt-(--pad-top) pr-(--pad-right) pb-(--pad-bottom) pl-(--pad-left)`,ref:t})}function dN(e){let[t,n]=(0,U.useState)(!1),r=R(e=>e.projects).filter(e=>e.machine===rM()),i=e.tab;return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(qn,{children:[(0,W.jsx)(Yn,{asChild:!0,children:e.children}),(0,W.jsxs)(Ln,{children:[(0,W.jsxs)(Un,{onSelect:()=>n(!0),children:[(0,W.jsx)(V,{icon:Lo}),`Rename`]}),(0,W.jsxs)(Gn,{children:[(0,W.jsxs)(Nn,{children:[(0,W.jsx)(V,{icon:_n}),`Move to`]}),(0,W.jsx)(bn,{className:`max-h-80 overflow-y-auto`,children:(0,W.jsxs)(An,{value:i.projectId??``,onValueChange:e=>gM({type:`assignTab`,id:i.id,projectId:e===``?null:e}),children:[(0,W.jsx)(gn,{value:``,children:`No project`}),r.length>0&&(0,W.jsx)(zn,{}),r.map(e=>(0,W.jsx)(gn,{value:e.id,children:(0,W.jsx)(`span`,{className:`max-w-60 truncate`,children:e.name})},e.id))]})})]}),(0,W.jsxs)(Un,{variant:`destructive`,onSelect:()=>void KM(i.id),children:[(0,W.jsx)(V,{icon:oo}),`Close tab`]})]})]}),t&&(0,W.jsx)(tN,{id:i.id,name:i.customName??``,onDone:()=>n(!1)})]})}function fN(e){return aM().alerts.includes(e.id)?(0,W.jsx)(`span`,{className:z(`bg-primary`,e.className)}):null}function pN(e){let t=e.progress;return!t||t.state===0?null:t.state===3?(0,W.jsx)(`span`,{className:`bg-primary absolute inset-x-0 bottom-0 h-0.5 animate-pulse`}):(0,W.jsx)(`span`,{className:z(`absolute bottom-0 left-0 h-0.5 transition-[width]`,t.state===1&&`bg-primary`,t.state===2&&`bg-destructive`,t.state===4&&`bg-yellow-500`),style:{width:`${t.state!==1&&t.value===0?100:t.value}%`}})}function mN(e){(0,U.useSyncExternalStore)(iM,aM);let t=R(e=>e.machines).filter(e=>e.status===`online`),n=Be(),r=gN(),i=r.find(t=>t.machine.id===e.machine&&t.view===n);(0,U.useEffect)(()=>{localStorage.setItem(`lastTerminal`,e.machine),localStorage.setItem(`lastTerminalView`,n)},[e.machine,n]);let a=(0,W.jsxs)(Qt,{children:[(0,W.jsx)(un,{asChild:!0,disabled:t.length===0,children:(0,W.jsx)(`button`,{className:`text-muted-foreground enabled:hover:text-foreground grid w-11 flex-none place-items-center self-stretch transition-colors`,"aria-label":`New terminal`,title:`New terminal`,children:(0,W.jsx)(V,{icon:ka,className:`size-4`})})}),(0,W.jsx)(tn,{align:`end`,className:`w-auto min-w-56`,children:(0,W.jsx)(oN,{})})]});return e.mobile?(0,W.jsxs)(`main`,{className:`bg-background flex min-w-0 flex-1 flex-col overflow-hidden pt-[env(safe-area-inset-top)] pb-[env(safe-area-inset-bottom)]`,children:[(0,W.jsxs)(`header`,{className:`grid h-(--workspace-topbar-height) flex-none grid-cols-[auto_1fr_auto] items-center border-b select-none`,children:[e.leading,(0,W.jsxs)(Qt,{children:[(0,W.jsx)(un,{asChild:!0,children:(0,W.jsxs)(`button`,{className:`text-muted-foreground hover:text-foreground flex min-w-0 items-center justify-center gap-1.5 self-stretch px-1 text-[13px]`,children:[i!==void 0&&(0,W.jsx)(yN,{group:i}),(0,W.jsx)(`span`,{className:`truncate`,children:i?.name})]})}),(0,W.jsx)(tn,{align:`center`,className:`w-auto`,children:r.filter(_N).map(t=>(0,W.jsxs)(Gt,{className:z(t.view!==`global`&&`pl-7`),onSelect:()=>t.count===0?void Hj(t.machine.id,null):Bj(t.machine.id,t.view),children:[(0,W.jsx)(yN,{group:t}),(0,W.jsx)(`span`,{className:`max-w-60 truncate`,children:t.name}),(0,W.jsx)(bN,{count:t.count,alert:vN(t,e.machine)})]},`${t.machine.id}:${t.view}`))})]}),a]}),(0,W.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,W.jsx)(lN,{view:n,page:!0})})]}):(0,W.jsx)(`main`,{className:`bg-background flex min-w-0 flex-1 flex-col overflow-hidden`,children:(0,W.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,W.jsx)(lN,{view:n,page:!0,tabSize:`lg`,leading:e.leading})})})}function hN(e){(0,U.useSyncExternalStore)(iM,aM);let t=M(),n=Be(),r=gN().filter(_N);return r.length===0?null:(0,W.jsx)(`div`,{className:`flex max-h-52 flex-col gap-px overflow-y-auto`,children:r.map(r=>(0,W.jsxs)(qn,{children:[(0,W.jsx)(Yn,{asChild:!0,children:(0,W.jsxs)(`div`,{className:z(`group/row text-sidebar-muted-foreground/80 hover:bg-sidebar-row-hover hover:text-sidebar-foreground data-[state=open]:bg-sidebar-row-hover relative shrink-0 rounded-[var(--control-radius)]`,e.mobile&&`text-popover-foreground`,r.machine.id===t&&r.view===n&&`bg-sidebar-row-hover text-sidebar-foreground`),children:[(0,W.jsxs)(`button`,{className:z(`flex h-7 w-full cursor-pointer items-center gap-2 rounded-[var(--control-radius)] pr-2.5 pl-7 text-left text-[13px]`,r.view!==`global`&&`pl-11`),onClick:()=>r.count===0?void Hj(r.machine.id,null):Bj(r.machine.id,r.view),children:[(0,W.jsx)(yN,{group:r}),(0,W.jsx)(`span`,{className:`truncate`,children:r.name}),(0,W.jsx)(bN,{count:r.count,alert:vN(r,t),className:`group-hover/row:invisible`})]}),(0,W.jsx)(`button`,{className:`text-muted-foreground hover:text-foreground absolute top-0.5 right-1 grid size-6 cursor-pointer place-items-center rounded-md opacity-0 transition-opacity group-hover/row:opacity-100 focus-visible:opacity-100 pointer-coarse:hidden`,"aria-label":`New terminal`,title:`New terminal`,onClick:()=>void Hj(r.machine.id,r.view===`global`?null:r.view),children:(0,W.jsx)(V,{icon:ka,className:`size-4`})})]})}),(0,W.jsxs)(Ln,{onCloseAutoFocus:e=>e.preventDefault(),children:[(0,W.jsxs)(Un,{onSelect:()=>void Hj(r.machine.id,r.view===`global`?null:r.view),children:[(0,W.jsx)(V,{icon:ka}),`New terminal`]}),r.view===`global`&&(0,W.jsxs)(Un,{variant:`destructive`,onSelect:()=>void JM(r.machine.terminals.map(e=>({machine:r.machine.id,id:e.id}))),children:[(0,W.jsx)(V,{icon:oo}),`Close All`]}),(0,W.jsxs)(Un,{variant:`destructive`,disabled:r.count===0,onSelect:()=>void JM(r.machine.terminals.filter(e=>uM(e)===r.view).map(e=>({machine:r.machine.id,id:e.id}))),children:[(0,W.jsx)(V,{icon:oo}),r.view===`global`?`Close All Except Projects`:`Close All`]})]})]},`${r.machine.id}:${r.view}`))})}function gN(){let e=R(e=>e.machines),t=R(e=>e.projects);return e.flatMap(e=>{let n=e.status===`online`?e.terminals:[],r=[...new Set(n.flatMap(e=>e.projectId===null?[]:[e.projectId]))];return[{machine:e,view:_e,name:e.name,count:n.filter(e=>e.projectId===null).length},...r.map(r=>({machine:e,view:r,name:t.find(t=>t.machine===e.id&&t.id===r)?.name??`Removed project`,count:n.filter(e=>e.projectId===r).length}))]})}function _N(e){return e.machine.status===`online`&&e.machine.terminals.length>0}function vN(e,t){let n=aM();return e.machine.id===t&&n.layout.tabs.some(t=>(t.projectId??`global`)===e.view&&n.alerts.includes(t.id))}function yN(e){return e.group.view===`global`?(0,W.jsx)(Vu,{icon:e.group.machine.icon,className:`size-4 shrink-0`}):(0,W.jsx)(zs,{machine:e.group.machine.id,projectId:e.group.view,className:`size-4 shrink-0`})}function bN(e){return e.count===0?null:(0,W.jsx)(`span`,{className:z(`ml-auto grid h-4 min-w-4 shrink-0 place-items-center rounded-full px-1 text-[10px] leading-none font-medium tabular-nums`,e.alert?`bg-primary text-primary-foreground`:`text-foreground/75 bg-[color-mix(in_srgb,var(--foreground)_8%,var(--background))]`,e.className),children:e.count})}function xN(e){let t=R(e=>e.machines),[n,r]=ur(`terminalGroupsExpanded`,!0),i=t.reduce((e,t)=>e+t.terminals.length,0),a=t.some(e=>e.status===`online`&&e.terminals.length>0),o=t.some(e=>e.status===`online`),s=a&&!e.mobile;if(t.length===0)return null;let c=(0,W.jsxs)(`button`,{className:z(e.buttonClassName,`group-hover/terminal:text-sidebar-foreground group-hover/terminal:[&>svg]:text-sidebar-foreground group-has-[[data-state=open]]/terminal:text-sidebar-foreground group-has-[[data-state=open]]/terminal:[&>svg]:text-sidebar-foreground h-8 w-full justify-start gap-2 px-2.5 text-sm`,s&&`group-hover/terminal:[&>svg]:opacity-0 pointer-coarse:[&>svg]:opacity-0`),title:`Terminal`,onClick:s?()=>r(!n):void 0,children:[(0,W.jsx)(V,{icon:Qo}),`Terminal`,i>0&&(0,W.jsx)(`span`,{className:z(`text-foreground/75 ml-auto grid h-4 min-w-4 place-items-center rounded-full bg-[color-mix(in_srgb,var(--foreground)_8%,var(--background))] px-1 text-[10px] leading-none font-medium tabular-nums`,o&&`group-hover/terminal:invisible group-has-[[data-state=open]]/terminal:invisible`,a&&`pointer-coarse:invisible`),children:i})]});return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(qn,{children:[(0,W.jsx)(Yn,{asChild:!0,disabled:!o,children:(0,W.jsxs)(`div`,{className:`group/terminal hover:bg-sidebar-row-hover has-[[data-state=open]]:bg-sidebar-row-hover data-[state=open]:bg-sidebar-row-hover relative rounded-[var(--control-radius)]`,children:[s?c:(0,W.jsxs)(Qt,{children:[(0,W.jsx)(un,{asChild:!0,disabled:!o,children:c}),(0,W.jsx)(tn,{side:`bottom`,align:`start`,className:`max-h-80 w-(--radix-dropdown-menu-trigger-width) overflow-y-auto`,onCloseAutoFocus:e=>e.preventDefault(),children:(0,W.jsx)(oN,{})})]}),s&&(0,W.jsx)(`button`,{className:`text-muted-foreground hover:text-foreground absolute top-1 left-1.5 grid size-6 cursor-pointer place-items-center rounded-md opacity-0 group-hover/terminal:opacity-100 focus-visible:opacity-100 pointer-coarse:opacity-100`,"aria-label":n?`Collapse terminals`:`Expand terminals`,"aria-expanded":n,onClick:()=>r(!n),children:(0,W.jsx)(V,{icon:Fr,"aria-hidden":!0,className:z(`size-4 transition-transform duration-200`,n&&`rotate-90`)})}),(0,W.jsx)(aN,{mobile:e.mobile})]})}),(0,W.jsxs)(Ln,{onCloseAutoFocus:e=>e.preventDefault(),children:[(0,W.jsxs)(Gn,{children:[(0,W.jsxs)(Nn,{children:[(0,W.jsx)(V,{icon:ka}),`New terminal`]}),(0,W.jsx)(bn,{className:`max-h-80 overflow-y-auto`,children:(0,W.jsx)(oN,{contextMenu:!0})})]}),(0,W.jsxs)(Un,{variant:`destructive`,disabled:!a,onSelect:()=>void JM(t.filter(e=>e.status===`online`).flatMap(e=>e.terminals.map(t=>({machine:e.id,id:t.id})))),children:[(0,W.jsx)(V,{icon:oo}),`Close All`]})]})]}),(0,W.jsx)(`div`,{className:z(`grid transition-[grid-template-rows] duration-200`,n||e.mobile?`grid-rows-[1fr]`:`grid-rows-[0fr]`),inert:!n&&!e.mobile,children:(0,W.jsx)(`div`,{className:`min-h-0 overflow-hidden`,children:(0,W.jsx)(hN,{mobile:e.mobile})})}),(0,W.jsx)(rN,{})]})}function SN(e){let[t,n]=(0,U.useState)(!1);return(0,W.jsxs)($n,{open:t,onOpenChange:n,children:[(0,W.jsx)(Wt,{asChild:!0,children:(0,W.jsx)(`button`,{className:z(e.buttonClassName,`size-7`),title:`Menu`,"aria-label":`Menu`,children:(0,W.jsx)(V,{icon:Oo})})}),(0,W.jsxs)(sn,{role:`group`,"aria-label":`Menu`,className:`flex w-56 flex-col gap-px p-1`,children:[(0,W.jsx)(xN,{buttonClassName:z(e.buttonClassName,`text-popover-foreground [&>svg]:text-popover-foreground`),mobile:!0}),(0,W.jsxs)(`button`,{className:z(e.buttonClassName,`text-popover-foreground [&>svg]:text-popover-foreground h-8 w-full justify-start gap-2 px-2.5 text-sm`),onClick:()=>{n(!1),d(!0)},children:[(0,W.jsx)(V,{icon:Go}),`Settings`]})]})]})}var CN=`relative w-full cursor-pointer overflow-hidden rounded-md text-left outline-none select-none touch-pan-y [-webkit-touch-callout:none] focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset`;function wN(e){let t=e.session,n=Ns(t.machine,t.projectId),r=R(e=>I(e,t.machine).icon),[i,a]=(0,U.useState)(null),[o,s]=(0,U.useState)(!1),[c,l]=(0,U.useState)(0),u=(0,U.useRef)(null),d=(0,U.useRef)(null),f=(0,U.useRef)(!1),p=e.activity?.waiting===!0,m=Object.values(e.activity?.tasks??{}).includes(`running`),h=!p&&(e.activity?.running===!0||m),g=e.activity?.running===!0||m,_=!p&&!h&&e.unseen,v=!e.selected&&!p&&!_;function y(){qe(t.machine,t.id,e.scope)}function b(){g?s(!0):y()}function x(e){let n=d.current;d.current=null,l(0),n!==null&&n.swiping&&(f.current=!0,e.clientX-n.x>e.currentTarget.offsetWidth*.4&&(t.status===`inactive`?rt(t.machine,t.id,{status:`active`}):b()))}let S={onClick:()=>{f.current?f.current=!1:e.onSelect()},onPointerDown:t=>{e.saved&&t.pointerType===`touch`&&(f.current=!1,d.current={x:t.clientX,y:t.clientY,swiping:!1})},onPointerMove:e=>{let t=d.current;if(t===null)return;let n=e.clientX-t.x,r=e.clientY-t.y;!t.swiping&&Math.abs(n)<10&&Math.abs(r)<10||(!t.swiping&&n<=Math.abs(r)?d.current=null:(t.swiping=!0,l(Math.max(0,n))))},onPointerUp:x,onPointerCancel:()=>{d.current=null,l(0)}},C=c>0&&(0,W.jsx)(`div`,{className:z(`absolute inset-x-0 flex items-center rounded-md px-4 text-white`,e.slim?`inset-y-0`:`inset-y-0.5`,t.status===`inactive`?`bg-success`:`bg-destructive`),children:(0,W.jsx)(V,{icon:t.status===`inactive`?Bo:zo,className:`size-6`})}),w=(0,W.jsx)(xn,{open:o,onOpenChange:s,children:(0,W.jsxs)(Fn,{children:[(0,W.jsxs)(mn,{children:[(0,W.jsx)(Zn,{children:`Stop running work?`}),(0,W.jsx)(On,{children:`The agent or background tasks are running. Do you really want to stop them?`})]}),(0,W.jsxs)(En,{children:[(0,W.jsx)(Vn,{children:`Cancel`}),(0,W.jsx)(wn,{variant:`destructive`,onClick:y,children:`Stop and Make Inactive`})]})]})}),T=(0,W.jsx)(Ln,{className:`w-44`,onCloseAutoFocus:e=>{u.current!==null&&(e.preventDefault(),u.current.focus(),u.current.select())},children:(0,W.jsx)(JE,{session:t,mobile:!0,onDeactivate:b,onRename:()=>a(t.title)})}),E=i===null?(0,W.jsx)(`span`,{className:z(`min-w-0 flex-1 truncate text-sm`,v?`text-secondary-label font-normal`:`font-medium`,!v&&(e.unseen||p)&&`text-foreground`,!v&&!e.unseen&&!p&&`text-foreground/90`),children:(0,W.jsx)(XE,{session:t})}):(0,W.jsx)(`form`,{className:`min-w-0 flex-1`,onSubmit:e=>{e.preventDefault();let n=i.trim();a(null),n!==``&&n!==t.title&&rt(t.machine,t.id,{title:n})},children:(0,W.jsx)(`input`,{ref:u,value:i,onChange:e=>a(e.target.value),onClick:e=>e.stopPropagation(),onBlur:()=>a(null),onKeyDown:e=>{e.stopPropagation(),e.key===`Escape`&&a(null)},className:`text-foreground ring-ring/50 focus:ring-ring w-full rounded-sm bg-transparent text-sm font-medium ring-1 outline-none ring-inset`})}),D=z(e.selected&&`bg-sidebar-row-active text-sidebar-foreground`,v&&`text-sidebar-muted-foreground/75`,!e.selected&&!v&&`text-sidebar-foreground bg-transparent`);return e.slim?(0,W.jsxs)(`li`,{className:`relative list-none`,children:[C,(0,W.jsxs)(qn,{children:[(0,W.jsx)(Yn,{asChild:!0,disabled:!e.saved,children:(0,W.jsxs)(`div`,{role:`button`,tabIndex:0,className:z(CN,D,`flex h-9 items-center gap-2.5 px-2.5`,c>0&&`bg-sidebar`),style:c>0?{transform:`translateX(${c}px)`}:void 0,...S,onKeyDown:t=>{t.key===`Enter`&&e.onSelect()},children:[(0,W.jsx)(`span`,{className:`flex shrink-0 items-center opacity-40 grayscale`,children:(0,W.jsx)(zs,{machine:t.machine,projectId:t.projectId})}),E,(0,W.jsx)(`span`,{className:`text-secondary-label ml-auto shrink-0 text-xs tabular-nums`,children:on(t.updatedAt)})]})}),T]}),w]}):(0,W.jsxs)(`li`,{className:`relative list-none py-0.5`,children:[C,(0,W.jsxs)(qn,{children:[(0,W.jsx)(Yn,{asChild:!0,disabled:!e.saved,children:(0,W.jsx)(`div`,{role:`button`,tabIndex:0,className:z(CN,D,h&&!e.selected&&`opacity-70`,c>0&&`bg-sidebar`),style:c>0?{transform:`translateX(${c}px)`}:void 0,...S,onKeyDown:t=>{t.key===`Enter`&&e.onSelect()},children:(0,W.jsxs)(`div`,{className:`px-(--sidebar-row-content-inset) py-(--sidebar-content-inset)`,children:[(0,W.jsxs)(`div`,{className:`flex h-6 min-w-0 items-center gap-2`,children:[(0,W.jsx)(zs,{machine:t.machine,projectId:t.projectId,className:`size-5`}),E,t.status===`pinned`&&(0,W.jsx)(V,{icon:Ro,className:`text-muted-foreground/65 size-3 shrink-0`}),(0,W.jsx)(YE,{activity:e.activity,backgroundRunning:m,done:_})]}),(0,W.jsxs)(`div`,{className:`text-secondary-label mt-1 flex h-5 min-w-0 items-center gap-1.5 text-xs`,children:[(0,W.jsx)(Vu,{icon:r,className:`size-3 shrink-0`}),(0,W.jsxs)(`span`,{className:z(`min-w-0 flex-1 truncate`,v?`font-normal`:`font-medium`),children:[n,t.branch!==null&&(0,W.jsx)(`span`,{className:`text-muted-foreground/40 font-normal`,children:` | ${t.branch}`})]}),t.status===`snoozed`&&(0,W.jsx)(V,{icon:Ma,className:`size-3 shrink-0`}),(0,W.jsx)(`span`,{className:`shrink-0 tabular-nums`,children:on(t.updatedAt)})]})]})})}),T]}),w]})}function TN(e){let t=Ns(e.machine,e.projectId),n=R(t=>I(t,e.machine).icon);return(0,W.jsx)(`li`,{className:`list-none py-0.5`,children:(0,W.jsx)(`div`,{role:`button`,tabIndex:0,className:z(CN,`bg-sidebar-row-active text-sidebar-foreground`),onClick:e.onSelect,children:(0,W.jsxs)(`div`,{className:`px-(--sidebar-row-content-inset) py-(--sidebar-content-inset)`,children:[(0,W.jsxs)(`div`,{className:`flex h-6 min-w-0 items-center gap-2`,children:[(0,W.jsx)(zs,{machine:e.machine,projectId:e.projectId,className:`size-5`}),(0,W.jsx)(`span`,{className:`text-foreground min-w-0 flex-1 truncate text-sm font-medium`,children:`New thread`}),(0,W.jsx)(V,{icon:Xo,className:`text-warning-foreground size-4 shrink-0`})]}),(0,W.jsxs)(`div`,{className:`text-secondary-label mt-1 flex h-5 min-w-0 items-center gap-1.5 text-xs`,children:[(0,W.jsx)(Vu,{icon:n,className:`size-3 shrink-0`}),(0,W.jsxs)(`span`,{className:`min-w-0 flex-1 truncate font-medium`,children:[t,(0,W.jsx)(`span`,{className:`text-muted-foreground/40 font-normal`,children:` | Draft`})]}),(0,W.jsx)(`span`,{className:`shrink-0 tabular-nums`,children:`now`})]})]})})})}function EN({className:e,...t}){return(0,W.jsx)(Gs,{"data-slot":`label`,className:z(`flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50`,e),...t})}var DN={216:`O`,223:`s`,248:`o`,273:`d`,295:`h`,305:`i`,320:`l`,322:`l`,359:`t`,383:`s`,384:`b`,385:`B`,387:`b`,390:`O`,392:`c`,393:`D`,394:`D`,396:`d`,398:`E`,400:`E`,402:`f`,403:`G`,407:`I`,409:`k`,410:`l`,412:`M`,413:`N`,414:`n`,415:`O`,421:`p`,427:`t`,429:`t`,430:`T`,434:`V`,436:`y`,438:`z`,477:`e`,485:`g`,544:`N`,545:`d`,549:`z`,564:`l`,565:`n`,566:`t`,567:`j`,570:`A`,571:`C`,572:`c`,573:`L`,574:`T`,575:`s`,576:`z`,579:`B`,580:`U`,581:`V`,582:`E`,583:`e`,584:`J`,585:`j`,586:`Q`,587:`q`,588:`R`,589:`r`,590:`Y`,591:`y`,592:`a`,593:`a`,595:`b`,596:`o`,597:`c`,598:`d`,599:`d`,600:`e`,603:`e`,604:`e`,605:`e`,606:`e`,607:`j`,608:`g`,609:`g`,610:`G`,613:`h`,614:`h`,616:`i`,618:`I`,619:`l`,620:`l`,621:`l`,623:`m`,624:`m`,625:`m`,626:`n`,627:`n`,628:`N`,629:`o`,633:`r`,634:`r`,635:`r`,636:`r`,637:`r`,638:`r`,639:`r`,640:`R`,641:`R`,642:`s`,647:`t`,648:`t`,649:`u`,651:`v`,652:`v`,653:`w`,654:`y`,655:`Y`,656:`z`,657:`z`,663:`c`,665:`B`,666:`e`,667:`G`,668:`H`,669:`j`,670:`k`,671:`L`,672:`q`,686:`h`,867:`a`,868:`e`,869:`i`,870:`o`,871:`u`,872:`c`,873:`d`,874:`h`,875:`m`,876:`r`,877:`t`,878:`v`,879:`x`,7424:`A`,7427:`B`,7428:`C`,7429:`D`,7431:`E`,7432:`e`,7433:`i`,7434:`J`,7435:`K`,7436:`L`,7437:`M`,7438:`N`,7439:`O`,7440:`O`,7441:`o`,7442:`o`,7443:`o`,7446:`o`,7447:`o`,7448:`P`,7449:`R`,7450:`R`,7451:`T`,7452:`U`,7453:`u`,7454:`u`,7455:`m`,7456:`V`,7457:`W`,7458:`Z`,7522:`i`,7523:`r`,7524:`u`,7525:`v`,7834:`a`,7835:`s`,8305:`i`,8341:`h`,8342:`k`,8343:`l`,8344:`m`,8345:`n`,8346:`p`,8347:`s`,8348:`t`,8580:`c`};for(let e=`̀`.codePointAt(0);e<=`ͯ`.codePointAt(0);++e){let t=String.fromCodePoint(e);for(let e of`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz`){let n=(e+t).normalize().codePointAt(0);n>126&&(DN[n]=e)}}var ON={a:[7844,7863],e:[7870,7879],o:[7888,7907],u:[7912,7921]};for(let e of Object.keys(ON)){let t=e.toUpperCase();for(let n=ON[e][0];n<=ON[e][1];++n)DN[n]=n%2==0?t:e}function kN(e){if(e<192||e>8580)return e;let t=DN[e];return t===void 0?e:t.codePointAt(0)}function AN(e){return e}function jN(e){return e}function MN(e,t){return e>t?e:t}var NN=e=>e.split(``).map(e=>e.codePointAt(0)),PN=new Set(` \f
|
|
15
15
|
\r \v\xA0 \u2028\u2029 `.split(``).map(e=>e.codePointAt(0)));for(let e=` `.codePointAt(0);e<=` `.codePointAt(0);e++)PN.add(e);var FN=``.codePointAt(0),IN=`A`.codePointAt(0),LN=`Z`.codePointAt(0),RN=`a`.codePointAt(0),zN=`z`.codePointAt(0),BN=`0`.codePointAt(0),VN=`9`.codePointAt(0);function HN(e,t,n){return n?e:t-e-1}var UN=16,WN=-3,GN=-1,KN=UN/2,qN=UN/2,JN=7,YN=4,XN=2;function ZN(e){return e?new Set:null}function QN(e,t,n){if(t!==null&&t.i16.length>e+n){let r=t.i16.subarray(e,e+n);return[e+n,r]}return[e,new Int16Array(n)]}function $N(e,t,n){if(t!==null&&t.i32.length>e+n){let r=t.i32.subarray(e,e+n);return[e+n,r]}return[e,new Int32Array(n)]}function eP(e){return e>=RN&&e<=zN?1:e>=IN&&e<=LN?2:e>=BN&&e<=VN?4:0}function tP(e){let t=String.fromCodePoint(e);return t===t.toUpperCase()?t===t.toLowerCase()?t.match(/\p{Number}/gu)===null?t.match(/\p{Letter}/gu)===null?0:3:4:2:1}function nP(e){return e<=FN?eP(e):tP(e)}function rP(e,t){return e===0&&t!==0?KN:e===1&&t===2||e!==4&&t===4?JN:t===0?qN:0}function iP(e,t){return t===0?KN:rP(nP(e[t-1]),nP(e[t]))}function aP(e,t,n,r){let i=e.slice(r),a=i.indexOf(n);if(a===0)return r;if(!t&&n>=RN&&n<=zN){a>0&&(i=i.slice(0,a));let e=i.indexOf(n-32);e>=0&&(a=e)}return a<0?-1:r+a}function oP(e){for(let t of e)if(t>=128)return!1;return!0}function sP(e,t,n){if(!oP(e))return 0;if(!oP(t))return-1;let r=0,i=0;for(let a=0;a<t.length;a++){if(i=aP(e,n,t[a],i),i<0)return-1;a===0&&i>0&&(r=i-1),i++}return r}var cP=(e,t,n,r,i,a,o)=>{let s=i.length;if(s===0)return[{start:0,end:0,score:0},ZN(a)];let c=r.length;if(o!==null&&c*s>o.i16.length)return uP(e,t,n,r,i,a);let l=sP(r,i,e);if(l<0)return[{start:-1,end:-1,score:0},null];let u=0,d=0,f=null,p=null,m=null,h=null;[u,f]=QN(u,o,c),[u,p]=QN(u,o,c),[u,m]=QN(u,o,c),[d,h]=$N(d,o,s);let[,g]=$N(d,o,c);for(let e=0;e<g.length;e++)g[e]=r[e];let _=AN(0),v=0,y=0,b=0,x=i[0],S=i[0],C=AN(0),w=0,T=!1,E=g.subarray(l),D=f.subarray(l).subarray(0,E.length),O=p.subarray(l).subarray(0,E.length),k=m.subarray(l).subarray(0,E.length);for(let[r,a]of E.entries()){let o=null;a<=FN?(o=eP(a),!e&&o===2&&(a+=32)):(o=tP(a),!e&&o===2&&(a=String.fromCodePoint(a).toLowerCase().codePointAt(0)),t&&(a=kN(a))),E[r]=a;let c=rP(w,o);if(k[r]=c,w=o,a===S&&(y<s&&(h[y]=jN(l+r),y++,S=i[Math.min(y,s-1)]),b=l+r),a===x){let e=UN+c*XN;if(D[r]=e,O[r]=1,s===1&&(n&&e>_||!n&&e>=_)&&(_=e,v=l+r,n&&c===KN))break;T=!1}else D[r]=MN(T?C+GN:C+WN,0),O[r]=0,T=!0;C=D[r]}if(y!==s)return[{start:-1,end:-1,score:0},null];if(s===1){let e={start:v,end:v+1,score:_};if(!a)return[e,null];let t=new Set;return t.add(v),[e,t]}let A=h[0],j=b-A+1,M=null;[u,M]=QN(u,o,j*s);{let e=f.subarray(A,b+1);for(let[t,n]of e.entries())M[t]=n}let[,ee]=QN(u,o,j*s);{let e=p.subarray(A,b+1);for(let[t,n]of e.entries())ee[t]=n}let te=h.subarray(1),ne=i.slice(1).slice(0,te.length);for(let[e,t]of te.entries()){let r=!1,i=ne[e],a=e+1,o=a*j,c=g.subarray(t,b+1),l=m.subarray(t).subarray(0,c.length),u=ee.subarray(o+t-A).subarray(0,c.length),d=ee.subarray(o+t-A-1-j).subarray(0,c.length),f=M.subarray(o+t-A).subarray(0,c.length),p=M.subarray(o+t-A-1-j).subarray(0,c.length),h=M.subarray(o+t-A-1).subarray(0,c.length);h[0]=0;for(let[e,o]of c.entries()){let c=e+t,g=0,y=0,b=0;if(y=r?h[e]+GN:h[e]+WN,i===o){g=p[e]+UN;let t=l[e];b=d[e]+1,t===KN?b=1:b>1&&(t=MN(t,MN(YN,m[c-b+1]))),g+t<y?(g+=l[e],b=0):g+=t}u[e]=b,r=g<y;let x=MN(MN(g,y),0);a===s-1&&(n&&x>_||!n&&x>=_)&&(_=x,v=c),f[e]=x}}let re=ZN(a),ie=A;if(a&&re!==null){let e=s-1;ie=v;let t=!0;for(;;){let n=e*j,r=ie-A,i=M[n+r],a=0,o=0;if(e>0&&ie>=h[e]&&(a=M[n-j+r-1]),ie>h[e]&&(o=M[n+r-1]),i>a&&(i>o||i===o&&t)){if(re.add(ie),e===0)break;e--}t=ee[n+r]>1||n+j+r+1<ee.length&&ee[n+j+r+1]>0,ie--}}return[{start:ie,end:v+1,score:_},re]};function lP(e,t,n,r,i,a,o){let s=0,c=0,l=!1,u=0,d=AN(0),f=ZN(o),p=0;i>0&&(p=nP(n[i-1]));for(let m=i;m<a;m++){let i=n[m],a=nP(i);if(e||(i>=IN&&i<=LN?i+=32:i>FN&&(i=String.fromCodePoint(i).toLowerCase().codePointAt(0))),t&&(i=kN(i)),i===r[s]){o&&f!==null&&f.add(m),c+=UN;let e=rP(p,a);u===0?d=e:(e===KN&&(d=e),e=MN(MN(e,d),YN)),c+=s===0?e*XN:e,l=!1,u++,s++}else c+=l?GN:WN,l=!0,u=0,d=0;p=a}return[c,f]}var uP=(e,t,n,r,i,a,o)=>{if(i.length===0)return[{start:0,end:0,score:0},null];if(sP(r,i,e)<0)return[{start:-1,end:-1,score:0},null];let s=0,c=-1,l=-1,u=r.length,d=i.length;for(let a=0;a<u;a++){let o=r[HN(a,u,n)];e||(o>=IN&&o<=LN?o+=32:o>FN&&(o=String.fromCodePoint(o).toLowerCase().codePointAt(0))),t&&(o=kN(o));let f=i[HN(s,d,n)];if(o===f&&(c<0&&(c=a),s++,s===d)){l=a+1;break}}if(c>=0&&l>=0){s--;for(let t=l-1;t>=c;t--){let a=r[HN(t,u,n)];e||(a>=IN&&a<=LN?a+=32:a>FN&&(a=String.fromCodePoint(a).toLowerCase().codePointAt(0)));let o=i[HN(s,d,n)];if(a===o&&(s--,s<0)){c=t;break}}if(!n){let e=c;c=u-l,l=u-e}let[o,f]=lP(e,t,r,i,c,l,a);return[{start:c,end:l,score:o},f]}return[{start:-1,end:-1,score:0},null]},dP=(e,t,n,r,i,a,o)=>{if(i.length===0)return[{start:0,end:0,score:0},null];let s=r.length,c=i.length;if(s<c||sP(r,i,e)<0)return[{start:-1,end:-1,score:0},null];let l=0,u=-1,d=AN(0),f=AN(-1);for(let a=0;a<s;a++){let o=HN(a,s,n),p=r[o];e||(p>=IN&&p<=LN?p+=32:p>FN&&(p=String.fromCodePoint(p).toLowerCase().codePointAt(0))),t&&(p=kN(p));let m=HN(l,c,n);if(i[m]===p){if(m===0&&(d=iP(r,o)),l++,l===c){if(d>f&&(u=a,f=d),d===KN)break;a-=l-1,l=0,d=0}}else a-=l,l=0,d=0}if(u>=0){let a=0,o=0;n?(a=u-c+1,o=u+1):(a=s-(u+1),o=s-(u-c+1));let[l]=lP(e,t,r,i,a,o,!1);return[{start:a,end:o,score:l},null]}return[{start:-1,end:-1,score:0},null]},fP=102400,pP=2048;function mP(e,t){return{i16:new Int16Array(e),i32:new Int32Array(t)}}var hP=mP(fP,pP),gP=(e,t,n)=>{let r=!1;switch(t){case`smart-case`:e.toLowerCase()!==e&&(r=!0);break;case`case-sensitive`:r=!0;break;case`case-insensitive`:e=e.toLowerCase(),r=!1}let i=NN(e);return n&&(i=i.map(kN)),{queryRunes:i,caseSensitive:r}};function _P(e,t){let n=Object.keys(e).map(e=>parseInt(e,10)).sort((e,t)=>t-e),r=[];for(let i of n)if(r=r.concat(e[i]),r.length>=t)break;return r}function vP(e,t,n){return r=>{let i=this.runesList[r];if(t.length>i.length)return;let[a,o]=this.algoFn(n,this.opts.normalize,this.opts.forward,i,t,!0,hP);if(a.start===-1)return;if(this.opts.fuzzy===!1){o=new Set;for(let e=a.start;e<a.end;++e)o.add(e)}let s=this.opts.sort?a.score:0;e[s]===void 0&&(e[s]=[]),e[s].push({item:this.items[r],...a,positions:o??new Set})}}function yP(e){let{queryRunes:t,caseSensitive:n}=gP(e,this.opts.casing,this.opts.normalize),r={},i=vP.bind(this)(r,t,n);for(let e=0,t=this.runesList.length;e<t;++e)i(e);return _P(r,this.opts.limit)}var bP={limit:1/0,selector:e=>e,casing:`smart-case`,normalize:!0,fuzzy:`v2`,tiebreakers:[],sort:!0,forward:!0},xP=class{constructor(e,...t){switch(this.opts={...bP,...t[0]},this.items=e,this.runesList=e.map(e=>NN(this.opts.selector(e).normalize())),this.algoFn=dP,this.opts.fuzzy){case`v2`:this.algoFn=cP;break;case`v1`:this.algoFn=uP}}},SP={...bP,match:yP},CP=class extends xP{constructor(e,...t){super(e,...t),this.opts={...SP,...t[0]}}find(e){return e.length===0||this.items.length===0?this.items.slice(0,this.opts.limit).map(wP):(e=e.normalize(),TP(this.opts.match.bind(this)(e),this.opts))}};({...bP});var wP=e=>({item:e,start:-1,end:-1,score:0,positions:new Set});function TP(e,t){if(t.sort){let{selector:n}=t;e.sort((e,r)=>{if(e.score===r.score)for(let i of t.tiebreakers){let t=i(e,r,n);if(t!==0)return t}return 0})}return Number.isFinite(t.limit)&&e.splice(t.limit),e}function EP(e,t,n){return n(e.item).length-n(t.item).length}var DP=class{constructor(e,...t){this.finder=new CP(e,...t),this.find=this.finder.find.bind(this.finder)}};function OP(e){let[t,n]=(0,U.useState)(null),[r,i]=(0,U.useState)(``),[a,o]=(0,U.useState)(``),[s,c]=(0,U.useState)(null),l=a===``?``:`${a}/`,u=(t??[]).filter(e=>e.startsWith(l)).map(e=>e.slice(l.length)),d=[...new Set(u.filter(e=>e.includes(`/`)).map(e=>e.split(`/`)[0]))].sort((e,t)=>e.localeCompare(t)),f=r===``?u.filter(e=>!e.includes(`/`)).sort((e,t)=>e.localeCompare(t)).map(e=>`${l}${e}`):new DP(t??[],{limit:50,casing:`case-insensitive`,tiebreakers:[(e,t)=>kP(t)-kP(e),EP]}).find(r).map(e=>e.item);return(0,U.useEffect)(()=>{let t=!1;return(async()=>{try{let r=await N(e.machine,`projects.logoFiles`,{id:e.projectId});t||n(r)}catch(e){t||c(Ot(e))}})(),()=>{t=!0}},[e.machine,e.projectId]),(0,W.jsx)(Or,{open:!0,onOpenChange:()=>e.onClose(),children:(0,W.jsxs)(xr,{className:`gap-0 overflow-hidden p-0 sm:max-w-lg`,showCloseButton:!1,"aria-describedby":void 0,children:[(0,W.jsx)(Tr,{className:`sr-only`,children:`Pick icon`}),(0,W.jsxs)(`div`,{className:`flex items-center gap-1 border-b p-1`,children:[(0,W.jsxs)(`label`,{className:`flex h-7 min-w-0 flex-1 items-center gap-2.5 px-2`,children:[(0,W.jsx)(V,{icon:Cn,className:`text-muted-foreground size-4 flex-none`}),(0,W.jsx)(`input`,{className:`placeholder:text-muted-foreground min-w-0 flex-1 bg-transparent text-sm outline-none`,placeholder:`Search images in this project`,value:r,onChange:e=>i(e.target.value)})]}),(0,W.jsx)(wr,{asChild:!0,children:(0,W.jsx)(H,{variant:`ghost`,size:`icon-sm`,"aria-label":`Close`,children:(0,W.jsx)(V,{icon:Ja})})})]}),r===``&&(0,W.jsxs)(`div`,{className:`flex items-center gap-1 border-b p-1`,children:[(0,W.jsx)(H,{variant:`ghost`,size:`icon-sm`,"aria-label":`Parent folder`,disabled:a===``,onClick:()=>o(a.split(`/`).slice(0,-1).join(`/`)),children:(0,W.jsx)(V,{icon:Sn})}),(0,W.jsxs)(`span`,{className:`truncate px-1.5 font-mono text-xs`,children:[`/`,a]})]}),(0,W.jsxs)(`div`,{className:`h-72 overflow-y-auto p-1`,children:[r===``&&d.map(e=>(0,W.jsxs)(`button`,{className:`hover:bg-muted flex h-9 w-full cursor-pointer items-center gap-2.5 rounded-md px-2.5 text-left text-sm transition-colors`,onClick:()=>o(`${l}${e}`),children:[(0,W.jsx)(V,{icon:_n,className:`text-muted-foreground size-4 flex-none`}),(0,W.jsx)(`span`,{className:`truncate font-mono text-xs`,children:e})]},e)),f.map(t=>(0,W.jsxs)(`button`,{className:`hover:bg-muted flex h-9 w-full cursor-pointer items-center gap-2.5 rounded-md px-2.5 text-left text-sm transition-colors`,onClick:async()=>{try{let n=await N(e.machine,`files.read`,{projectId:e.projectId,path:t});n.kind===`image`?e.onPick(`data:${n.mediaType};base64,${n.data}`):n.kind===`large`?c(`${t} is too large`):c(`${t} is not an image`)}catch(e){c(Ot(e))}},children:[(0,W.jsx)(V,{icon:Wn,className:`text-muted-foreground size-4 flex-none`}),(0,W.jsx)(`span`,{className:`truncate font-mono text-xs`,children:r===``?t.slice(l.length):t})]},t)),t?.length===0&&(0,W.jsx)(`p`,{className:`text-muted-foreground grid h-full place-items-center text-sm`,children:`No images in this project`}),t!==null&&t.length>0&&r!==``&&f.length===0&&(0,W.jsx)(`p`,{className:`text-muted-foreground grid h-full place-items-center text-sm`,children:`No matching images`})]}),s!==null&&(0,W.jsx)(`p`,{className:`text-destructive border-t px-3 py-2 text-sm break-all`,children:s})]})})}function kP(e){let t=e.item.lastIndexOf(`/`)+1;return[...e.positions].filter(e=>e>=t).length}function AP(e){let t=R(e=>e.machines),[n,r]=(0,U.useState)(null),[i,a]=(0,U.useState)(null),[o,s]=(0,U.useState)(()=>jP(t.find(t=>t.id===e.machine))),[c,l]=(0,U.useState)(``),[u,d]=(0,U.useState)(!1),f=o.trim()===``?void 0:n?.listing,p=f?.directories.filter(e=>e.name.toLowerCase().includes(c.toLowerCase()));function m(e){s(e),l(``)}return(0,U.useEffect)(()=>{if(o.trim()===``)return;let t=!1,n=setTimeout(async()=>{try{let n=await N(e.machine,`directories.list`,{path:o});if(t)return;r({path:o,listing:n}),a(null)}catch(e){if(t)return;r(null),a(Ot(e))}},150);return()=>{t=!0,clearTimeout(n)}},[e.machine,o]),(0,W.jsx)(Or,{open:!0,onOpenChange:()=>e.onClose(),children:(0,W.jsxs)(xr,{className:`gap-0 overflow-hidden p-0 sm:max-w-lg`,showCloseButton:!1,"aria-describedby":void 0,children:[(0,W.jsx)(Tr,{className:`sr-only`,children:`Add project`}),(0,W.jsxs)(`div`,{className:`flex items-center gap-1 border-b p-1`,children:[(0,W.jsx)(H,{variant:`ghost`,size:`icon-sm`,"aria-label":`Home folder`,onClick:()=>m(`~`),children:(0,W.jsx)(V,{icon:bo})}),(0,W.jsx)(`div`,{className:`bg-border mx-0.5 h-4 w-px`}),(0,W.jsx)(H,{variant:`ghost`,size:`icon-sm`,"aria-label":`Parent folder`,disabled:f?.parent===void 0||f.parent===null,onClick:()=>{f?.parent!==void 0&&f.parent!==null&&m(f.parent)},children:(0,W.jsx)(V,{icon:Sn})}),(0,W.jsx)(`input`,{"aria-label":`Folder path`,className:`hover:bg-muted focus:bg-muted h-7 min-w-0 flex-1 rounded-md bg-transparent px-1.5 font-mono text-xs outline-none`,spellCheck:!1,value:o,onChange:e=>m(e.target.value)}),(0,W.jsx)(wr,{asChild:!0,children:(0,W.jsx)(H,{variant:`ghost`,size:`icon-sm`,"aria-label":`Close`,children:(0,W.jsx)(V,{icon:Ja})})})]}),(0,W.jsxs)(`label`,{className:`flex h-9 items-center gap-2.5 border-b px-3`,children:[(0,W.jsx)(V,{icon:Cn,className:`text-muted-foreground size-4 flex-none`}),(0,W.jsx)(`input`,{className:`placeholder:text-muted-foreground min-w-0 flex-1 bg-transparent text-sm outline-none`,placeholder:`Search this folder`,value:c,onChange:e=>l(e.target.value)})]}),(0,W.jsxs)(`div`,{className:`h-72 overflow-y-auto p-1`,children:[p?.map(e=>(0,W.jsxs)(`button`,{className:`hover:bg-muted flex h-9 w-full cursor-pointer items-center gap-2.5 rounded-md px-2.5 text-left text-sm transition-colors`,onClick:()=>m(e.path),children:[(0,W.jsx)(V,{icon:_n,className:`text-muted-foreground size-4 flex-none`}),(0,W.jsx)(`span`,{className:`truncate`,children:e.name})]},e.path)),p?.length===0&&(0,W.jsx)(`p`,{className:`text-muted-foreground grid h-full place-items-center text-sm`,children:c===``?`No folders here`:`No matching folders`})]}),i!==null&&o.trim()!==``&&(0,W.jsx)(`p`,{className:`text-destructive border-t px-3 py-2 text-sm break-all`,children:i}),(0,W.jsx)(kr,{className:`border-t p-3`,children:(0,W.jsx)(H,{disabled:n?.path!==o||u,onClick:async()=>{if(n!==null&&n.path===o){d(!0);try{e.onAdd({...await Ps(e.machine,n.listing.path),machine:e.machine})}catch(e){a(Ot(e)),d(!1)}}},children:`Add project`})})]})})}function jP(e){return e===void 0||e.config===null||e.system===null?`~`:e.config.workingDir[e.system.platform]??`~`}function MP(e){let t=e.project.path,[n,r]=(0,U.useState)(e.project.name),[i,a]=(0,U.useState)(e.project.logo),[o,s]=(0,U.useState)(null),[c,l]=(0,U.useState)(!1),[u,d]=(0,U.useState)(!1),[f,p]=(0,U.useState)(!1),m=(0,U.useRef)(null);return(0,W.jsx)(Or,{open:!0,onOpenChange:()=>e.onClose(),children:(0,W.jsxs)(xr,{className:`gap-0 overflow-hidden p-0 sm:max-w-md`,children:[(0,W.jsxs)(`form`,{className:`grid`,onSubmit:async t=>{t.preventDefault(),l(!0);try{await Fs(e.project.machine,e.project.id,{name:n,logo:i===e.project.logo?void 0:i}),e.onClose()}catch(e){s(Ot(e)),l(!1)}},children:[(0,W.jsxs)(Sr,{className:`gap-1 px-6 pt-4 pr-12`,children:[(0,W.jsx)(Tr,{className:`text-base`,children:`Edit project`}),(0,W.jsx)(Er,{className:`truncate font-mono text-xs`,title:t,children:t})]}),(0,W.jsxs)(`div`,{className:`grid gap-6 p-6`,children:[(0,W.jsxs)(`div`,{className:`grid gap-2.5`,children:[(0,W.jsx)(EN,{children:`Icon`}),(0,W.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,W.jsxs)(`div`,{className:`relative flex-none`,children:[(0,W.jsx)(Bs,{name:n.trim()===``?yn(t):n,logo:i,className:`ring-foreground/10 size-16 rounded-2xl ring-1 [&>img]:rounded-2xl [&>svg]:rounded-2xl`}),i!==null&&(0,W.jsx)(`button`,{type:`button`,className:`bg-popover text-muted-foreground hover:text-foreground absolute -top-1.5 -right-1.5 grid size-5 cursor-pointer place-items-center rounded-full border shadow-xs`,title:`Remove icon`,onClick:()=>a(null),children:(0,W.jsx)(V,{icon:Ja,className:`size-3`})})]}),(0,W.jsxs)(`div`,{className:`grid gap-2`,children:[(0,W.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,W.jsxs)(H,{type:`button`,variant:`outline`,size:`sm`,title:`Upload an image from this device`,onClick:()=>m.current?.click(),children:[(0,W.jsx)(V,{icon:es}),`Upload`]}),(0,W.jsxs)(H,{type:`button`,variant:`outline`,size:`sm`,title:`Choose an image from the project on the server`,onClick:()=>p(!0),children:[(0,W.jsx)(V,{icon:_n}),`Choose from project`]})]}),(0,W.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:`PNG, JPG, WebP, SVG or ICO. SVG and ICO up to 384 KB`})]})]}),(0,W.jsx)(`input`,{ref:m,type:`file`,accept:`image/png,image/jpeg,image/webp,image/svg+xml,image/x-icon`,hidden:!0,onChange:async e=>{let t=e.target.files?.[0];e.target.value=``,t!==void 0&&a(`data:${t.type};base64,${await Uu(t)}`)}})]}),(0,W.jsxs)(`div`,{className:`grid gap-2`,children:[(0,W.jsx)(EN,{htmlFor:`project-name`,children:`Name`}),(0,W.jsx)(Hd,{id:`project-name`,placeholder:yn(t),value:n,onChange:e=>r(e.target.value)})]}),o!==null&&(0,W.jsx)(`p`,{className:`text-destructive text-sm break-all`,children:o})]}),(0,W.jsxs)(kr,{className:`bg-muted/40 border-t px-6 py-4`,children:[(0,W.jsxs)(H,{type:`button`,variant:u?`destructive`:`ghost`,className:z(`sm:mr-auto`,!u&&`text-destructive hover:bg-destructive/10 hover:text-destructive`),title:`Its threads stay in their provider`,onClick:async()=>{if(!u)d(!0);else try{await Is(e.project.machine,e.project.id),e.onRemoved()}catch(e){s(Ot(e))}},children:[(0,W.jsx)(V,{icon:oo,className:`text-current`}),u?`Click again to remove`:`Remove project`]}),(0,W.jsx)(H,{type:`button`,variant:`outline`,onClick:e.onClose,children:`Cancel`}),(0,W.jsx)(H,{type:`submit`,disabled:n.trim()===``||c,children:`Save`})]})]}),f&&(0,W.jsx)(OP,{machine:e.project.machine,projectId:e.project.id,onClose:()=>p(!1),onPick:e=>{a(e),p(!1)}})]})})}var NP=`group/sidebar-row relative w-full cursor-pointer overflow-hidden rounded-md text-left outline-none select-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset`;function PP(e){let t=e.session,[n,r]=(0,U.useState)(null),[i,a]=(0,U.useState)(!1),o=(0,U.useRef)(null),s=e.activity?.waiting===!0,c=Object.values(e.activity?.tasks??{}).includes(`running`),l=!s&&(e.activity?.running===!0||c),u=e.activity?.running===!0||c,d=!s&&!l&&e.unseen,f=!e.selected&&!s&&!d;function p(){qe(t.machine,t.id,null)}function m(){u?a(!0):p()}let h=(0,W.jsx)(xn,{open:i,onOpenChange:a,children:(0,W.jsxs)(Fn,{children:[(0,W.jsxs)(mn,{children:[(0,W.jsx)(Zn,{children:`Stop running work?`}),(0,W.jsx)(On,{children:`The agent or background tasks are running. Do you really want to stop them?`})]}),(0,W.jsxs)(En,{children:[(0,W.jsx)(Vn,{children:`Cancel`}),(0,W.jsx)(wn,{variant:`destructive`,onClick:p,children:`Stop and Make Inactive`})]})]})}),g=e.saved&&(0,W.jsxs)(Qt,{children:[(0,W.jsx)(un,{asChild:!0,children:(0,W.jsx)(`button`,{className:`text-muted-foreground hover:text-foreground inline-flex h-5 cursor-pointer items-center rounded-md px-1.5`,title:`Thread actions`,onClick:e=>e.stopPropagation(),children:(0,W.jsx)(V,{icon:co,className:`size-3.5`})})}),(0,W.jsx)(tn,{align:`end`,className:`w-44`,onClick:e=>e.stopPropagation(),onCloseAutoFocus:e=>{o.current!==null&&(e.preventDefault(),o.current.focus(),o.current.select())},children:(0,W.jsx)(JE,{session:t,mobile:!1,onDeactivate:m,onRename:()=>r(t.title)})})]}),_=n===null?(0,W.jsx)(`span`,{className:z(`min-w-0 flex-1 truncate text-sm`,f?`text-secondary-label font-normal`:`font-medium`,!f&&(e.unseen||s)&&`text-foreground`,!f&&!e.unseen&&!s&&`text-foreground/90`),children:(0,W.jsx)(XE,{session:t})}):(0,W.jsx)(`form`,{className:`min-w-0 flex-1`,onSubmit:e=>{e.preventDefault();let i=n.trim();r(null),i!==``&&i!==t.title&&rt(t.machine,t.id,{title:i})},children:(0,W.jsx)(`input`,{ref:o,value:n,onChange:e=>r(e.target.value),onClick:e=>e.stopPropagation(),onBlur:()=>r(null),onKeyDown:e=>{e.stopPropagation(),e.key===`Escape`&&r(null)},className:`text-foreground ring-ring/50 focus:ring-ring w-full rounded-sm bg-transparent text-sm font-medium ring-1 outline-none ring-inset`})}),v=z(e.selected&&`bg-sidebar-row-active text-sidebar-foreground`,f&&`text-sidebar-muted-foreground/75 hover:bg-sidebar-row-hover hover:text-sidebar-foreground`,!e.selected&&!f&&`text-sidebar-foreground hover:bg-sidebar-row-hover bg-transparent`);return(0,W.jsxs)(`li`,{className:`list-none`,children:[(0,W.jsxs)(`div`,{role:`button`,tabIndex:0,className:z(NP,v,`flex h-9 items-center gap-2 px-2.5`,l&&!e.selected&&`opacity-70 transition-opacity focus-within:opacity-100 hover:opacity-100`),onClick:e.onSelect,onKeyDown:t=>{t.key===`Enter`&&e.onSelect()},children:[_,t.status===`pinned`&&(0,W.jsx)(V,{icon:Ro,className:`text-muted-foreground/65 size-3 shrink-0`}),t.status===`snoozed`&&(0,W.jsx)(V,{icon:Ma,className:`text-secondary-label size-3 shrink-0`}),(0,W.jsx)(YE,{activity:e.activity,backgroundRunning:c,done:d}),(0,W.jsx)(`span`,{className:`text-secondary-label shrink-0 text-xs tabular-nums`,children:on(t.updatedAt)}),e.saved&&(0,W.jsxs)(`div`,{className:z(`group-any-hover/sidebar-row:pointer-events-auto group-any-hover/sidebar-row:opacity-100 pointer-events-none absolute inset-y-0 right-0 flex items-center bg-linear-to-l from-60% to-transparent pr-1.5 pl-6 opacity-0 transition-opacity has-[[data-state=open]]:pointer-events-auto has-[[data-state=open]]:opacity-100`,e.selected?`from-sidebar-row-active`:`from-sidebar-row-hover`),children:[g,(0,W.jsx)(`button`,{className:`text-muted-foreground hover:text-foreground inline-flex h-5 cursor-pointer items-center rounded-md px-1.5`,title:`Make inactive`,"aria-label":`Make inactive`,onClick:e=>{e.stopPropagation(),m()},children:(0,W.jsx)(V,{icon:zo,className:`size-3.5 scale-160`})})]})]}),h]})}function FP(e){return(0,W.jsx)(`li`,{className:`list-none`,children:(0,W.jsxs)(`div`,{role:`button`,tabIndex:0,className:z(NP,`bg-sidebar-row-active text-sidebar-foreground flex h-9 items-center gap-2 px-2.5`),onClick:e.onSelect,children:[(0,W.jsx)(`span`,{className:`text-foreground min-w-0 flex-1 truncate text-sm font-medium`,children:`New thread`}),(0,W.jsx)(V,{icon:Xo,className:`text-warning-foreground size-4 shrink-0`})]})})}var IP=`relative w-full cursor-pointer overflow-hidden rounded-md text-left outline-none select-none touch-pan-y [-webkit-touch-callout:none] focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset`;function LP(e){let t=e.session,[n,r]=(0,U.useState)(null),[i,a]=(0,U.useState)(!1),[o,s]=(0,U.useState)(0),c=(0,U.useRef)(null),l=(0,U.useRef)(null),u=(0,U.useRef)(!1),d=e.activity?.waiting===!0,f=Object.values(e.activity?.tasks??{}).includes(`running`),p=!d&&(e.activity?.running===!0||f),m=e.activity?.running===!0||f,h=!d&&!p&&e.unseen,g=!e.selected&&!d&&!h;function _(){qe(t.machine,t.id,null)}function v(){m?a(!0):_()}function y(e){let n=l.current;l.current=null,s(0),n!==null&&n.swiping&&(u.current=!0,e.clientX-n.x>e.currentTarget.offsetWidth*.4&&(t.status===`inactive`?rt(t.machine,t.id,{status:`active`}):v()))}let b={onClick:()=>{u.current?u.current=!1:e.onSelect()},onPointerDown:t=>{e.saved&&t.pointerType===`touch`&&(u.current=!1,l.current={x:t.clientX,y:t.clientY,swiping:!1})},onPointerMove:e=>{let t=l.current;if(t===null)return;let n=e.clientX-t.x,r=e.clientY-t.y;!t.swiping&&Math.abs(n)<10&&Math.abs(r)<10||(!t.swiping&&n<=Math.abs(r)?l.current=null:(t.swiping=!0,s(Math.max(0,n))))},onPointerUp:y,onPointerCancel:()=>{l.current=null,s(0)}},x=o>0&&(0,W.jsx)(`div`,{className:z(`absolute inset-0 flex items-center rounded-md px-4 text-white`,t.status===`inactive`?`bg-success`:`bg-destructive`),children:(0,W.jsx)(V,{icon:t.status===`inactive`?Bo:zo,className:`size-6`})}),S=(0,W.jsx)(xn,{open:i,onOpenChange:a,children:(0,W.jsxs)(Fn,{children:[(0,W.jsxs)(mn,{children:[(0,W.jsx)(Zn,{children:`Stop running work?`}),(0,W.jsx)(On,{children:`The agent or background tasks are running. Do you really want to stop them?`})]}),(0,W.jsxs)(En,{children:[(0,W.jsx)(Vn,{children:`Cancel`}),(0,W.jsx)(wn,{variant:`destructive`,onClick:_,children:`Stop and Make Inactive`})]})]})}),C=(0,W.jsx)(Ln,{className:`w-44`,onCloseAutoFocus:e=>{c.current!==null&&(e.preventDefault(),c.current.focus(),c.current.select())},children:(0,W.jsx)(JE,{session:t,mobile:!0,onDeactivate:v,onRename:()=>r(t.title)})}),w=n===null?(0,W.jsx)(`span`,{className:z(`min-w-0 flex-1 truncate text-sm`,g?`text-secondary-label font-normal`:`font-medium`,!g&&(e.unseen||d)&&`text-foreground`,!g&&!e.unseen&&!d&&`text-foreground/90`),children:(0,W.jsx)(XE,{session:t})}):(0,W.jsx)(`form`,{className:`min-w-0 flex-1`,onSubmit:e=>{e.preventDefault();let i=n.trim();r(null),i!==``&&i!==t.title&&rt(t.machine,t.id,{title:i})},children:(0,W.jsx)(`input`,{ref:c,value:n,onChange:e=>r(e.target.value),onClick:e=>e.stopPropagation(),onBlur:()=>r(null),onKeyDown:e=>{e.stopPropagation(),e.key===`Escape`&&r(null)},className:`text-foreground ring-ring/50 focus:ring-ring w-full rounded-sm bg-transparent text-sm font-medium ring-1 outline-none ring-inset`})}),T=z(e.selected&&`bg-sidebar-row-active text-sidebar-foreground`,g&&`text-sidebar-muted-foreground/75`,!e.selected&&!g&&`text-sidebar-foreground bg-transparent`);return(0,W.jsxs)(`li`,{className:`relative list-none`,children:[x,(0,W.jsxs)(qn,{children:[(0,W.jsx)(Yn,{asChild:!0,disabled:!e.saved,children:(0,W.jsxs)(`div`,{role:`button`,tabIndex:0,className:z(IP,T,`flex h-9 items-center gap-2 px-2.5`,p&&!e.selected&&`opacity-70`,o>0&&`bg-sidebar`),style:o>0?{transform:`translateX(${o}px)`}:void 0,...b,onKeyDown:t=>{t.key===`Enter`&&e.onSelect()},children:[w,t.status===`pinned`&&(0,W.jsx)(V,{icon:Ro,className:`text-muted-foreground/65 size-3 shrink-0`}),t.status===`snoozed`&&(0,W.jsx)(V,{icon:Ma,className:`text-secondary-label size-3 shrink-0`}),(0,W.jsx)(YE,{activity:e.activity,backgroundRunning:f,done:h}),(0,W.jsx)(`span`,{className:`text-secondary-label shrink-0 text-xs tabular-nums`,children:on(t.updatedAt)})]})}),C]}),S]})}function RP(e){return(0,W.jsx)(`li`,{className:`list-none`,children:(0,W.jsxs)(`div`,{role:`button`,tabIndex:0,className:z(IP,`bg-sidebar-row-active text-sidebar-foreground flex h-9 items-center gap-2 px-2.5`),onClick:e.onSelect,children:[(0,W.jsx)(`span`,{className:`text-foreground min-w-0 flex-1 truncate text-sm font-medium`,children:`New thread`}),(0,W.jsx)(V,{icon:Xo,className:`text-warning-foreground size-4 shrink-0`})]})})}function zP(e){let t=Ns(e.machine,e.projectId),n=R(t=>I(t,e.machine).icon),r=R(e=>e.selection),i=R(e=>e.machines),a=R(e=>e.unseen),o=r!==null&&r.sessionId===null&&r.machine===e.machine&&r.projectId===e.projectId,s=e.mobile?RP:FP,c=e.mobile?LP:PP;function l(){He({machine:e.machine,projectId:e.projectId,sessionId:null})}return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(`li`,{className:`text-sidebar-muted-foreground/60 mx-0.5 mt-2 flex h-7 items-center gap-2 pl-2 text-xs font-medium first:mt-0`,children:[(0,W.jsx)(Vu,{icon:n,className:`size-3.5 shrink-0`}),(0,W.jsx)(`span`,{className:`bg-sidebar-border/60 h-px min-w-2 flex-1`}),(0,W.jsx)(zs,{machine:e.machine,projectId:e.projectId,className:`size-3.5 shrink-0`}),(0,W.jsx)(`span`,{className:`min-w-0 truncate`,children:t}),(0,W.jsx)(`span`,{className:`bg-sidebar-border/60 h-px min-w-2 flex-1`}),(0,W.jsx)(`button`,{className:`text-sidebar-muted-foreground/80 hover:bg-sidebar-row-hover hover:text-sidebar-foreground flex size-6 shrink-0 cursor-pointer items-center justify-center rounded-[var(--control-radius)]`,title:`New thread`,"aria-label":`New thread`,onClick:l,children:(0,W.jsx)(V,{icon:ka,className:`size-4 text-(--sidebar-icon-color)`})})]}),o&&(0,W.jsx)(s,{onSelect:l}),e.sessions.map(t=>(0,W.jsx)(c,{session:t,selected:r?.machine===t.machine&&r.sessionId===t.id,activity:Ee(i,t.machine,t.id),unseen:a.includes(_(t.machine,t.id)),saved:t!==e.started,onSelect:()=>He({machine:t.machine,projectId:t.projectId,sessionId:t.id})},_(t.machine,t.id)))]})}function BP(e){let t=R(e=>e.machines),n=R(e=>e.projects),r=R(e=>e.sessions),i=R(e=>e.unseen),[a,o]=(0,U.useState)(!1),[s,c]=(0,U.useState)(null),l=(0,U.useRef)(!1),u=t.map(e=>({machine:e,projects:n.filter(t=>t.machine===e.id&&!t.hidden).sort((t,n)=>s!==null&&s.machine===e.id?s.ids.indexOf(t.id)-s.ids.indexOf(n.id):0),hidden:n.filter(t=>t.machine===e.id&&t.hidden)})).filter(e=>t.length>1||e.projects.length>0||e.hidden.length>0),d=r.filter(e=>{let n=Ee(t,e.machine,e.id);return n?.running===!0||n?.waiting===!0||Object.values(n?.tasks??{}).includes(`running`)||i.includes(_(e.machine,e.id))});function f(e,t){return n.find(n=>n.machine===e&&n.id===t)}function p(t){return t.length>0&&(0,W.jsxs)(ln,{children:[(0,W.jsx)(cn,{className:`text-muted-foreground grid size-5 min-h-0 shrink-0 place-items-center rounded-sm p-0 [&>svg:last-child]:hidden`,title:`Archived projects`,"aria-label":`Archived projects`,children:(0,W.jsx)(V,{icon:za,className:`size-3.5`})}),(0,W.jsx)(Zt,{children:(0,W.jsx)(qt,{className:`max-h-(--radix-dropdown-menu-content-available-height) w-56 overflow-y-auto`,children:t.map(t=>(0,W.jsxs)(Gt,{title:t.path,onSelect:()=>{Fs(t.machine,t.id,{hidden:!1}).catch(mt),e.onScope({machine:t.machine,projectId:t.id})},children:[(0,W.jsx)(zs,{machine:t.machine,projectId:t.id,className:`size-5 shrink-0 [&>img]:rounded-[4px] [&>svg]:rounded-[4px]`}),(0,W.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:t.name})]},t.id))})})]})}function m(e){return e.status===`online`?e.name:e.status===`unpaired`?`${e.name} · needs pairing`:`${e.name} · offline`}return(0,W.jsxs)(Qt,{open:a,onOpenChange:o,children:[(0,W.jsx)(un,{asChild:!0,children:(0,W.jsxs)(`button`,{className:`hover:bg-sidebar-row-hover data-[state=open]:bg-sidebar-row-hover -ml-1.5 flex h-7 min-w-0 cursor-pointer items-center gap-1.5 rounded-[var(--control-radius)] px-1.5 text-sm font-medium`,title:e.scope===null?`Inbox`:f(e.scope.machine,e.scope.projectId)?.path,children:[e.scope!==null&&(0,W.jsx)(zs,{machine:e.scope.machine,projectId:e.scope.projectId,className:`size-4 shrink-0 [&>img]:rounded-[4px] [&>svg]:rounded-[4px]`}),(0,W.jsx)(`span`,{className:`truncate`,children:e.scope===null?`Inbox`:f(e.scope.machine,e.scope.projectId)?.name}),(0,W.jsx)(V,{icon:cr,className:`text-sidebar-muted-foreground size-3.5 shrink-0`})]})}),(0,W.jsxs)(tn,{className:`w-64`,children:[(0,W.jsxs)(rn,{value:e.scope===null?``:_(e.scope.machine,e.scope.projectId),children:[(0,W.jsxs)(ir,{value:``,className:`pr-9 pl-8 *:data-[slot=dropdown-menu-radio-item-indicator]:right-auto *:data-[slot=dropdown-menu-radio-item-indicator]:left-2`,onSelect:()=>e.onScope(null),children:[(0,W.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:`Inbox`}),d.length>0&&(0,W.jsx)(`span`,{className:`text-foreground grid h-4 min-w-4 place-items-center rounded-full bg-[color-mix(in_srgb,var(--foreground)_22%,var(--background))] px-1 text-[10px] leading-none font-medium tabular-nums`,children:d.length})]}),u.length>0&&(0,W.jsx)(Ht,{}),u.map(({machine:n,projects:r,hidden:i},a)=>(0,W.jsxs)(U.Fragment,{children:[a>0&&(0,W.jsx)(Ht,{}),t.length>1&&(0,W.jsxs)(`div`,{className:`flex items-center`,children:[(0,W.jsxs)(Jt,{className:`flex min-w-0 flex-1 items-center gap-2 pl-[0.52rem]!`,children:[(0,W.jsx)(Vu,{icon:n.icon,className:`size-3.5 shrink-0`}),(0,W.jsx)(`span`,{className:`truncate`,children:m(n)})]}),(0,W.jsxs)(`div`,{className:`flex shrink-0 items-center gap-0.5 pr-1`,children:[p(i),(0,W.jsx)(Gt,{className:`text-muted-foreground grid size-5 min-h-0 shrink-0 place-items-center rounded-sm p-0`,title:`Add project to ${n.name}`,"aria-label":`Add project to ${n.name}`,disabled:n.status!==`online`,onSelect:()=>e.onAddProject(n.id),children:(0,W.jsx)(V,{icon:ka,className:`size-3.5`})})]})]}),(0,W.jsx)(Yw,{as:`div`,axis:`y`,values:r.map(e=>e.id),onReorder:e=>c({machine:n.id,ids:e}),children:r.map(t=>{let n=d.filter(e=>e.machine===t.machine&&e.projectId===t.id).length;return(0,W.jsx)(Jw,{as:`div`,value:t.id,className:`relative`,onDragStart:()=>{l.current=!0},onDragEnd:async()=>{if(s!==null){try{await Ls(s.machine,[...s.ids,...i.map(e=>e.id)])}catch(e){mt(e)}c(null)}},children:(0,W.jsxs)(ir,{value:_(t.machine,t.id),title:t.path,className:`group/project pr-1 pl-8 *:data-[slot=dropdown-menu-radio-item-indicator]:right-auto *:data-[slot=dropdown-menu-radio-item-indicator]:left-2`,onPointerDown:()=>{l.current=!1},onSelect:n=>{l.current?n.preventDefault():e.onScope({machine:t.machine,projectId:t.id})},onContextMenu:n=>{n.preventDefault(),o(!1),e.onEdit(t)},children:[(0,W.jsx)(zs,{machine:t.machine,projectId:t.id,className:`size-5 shrink-0 [&>img]:rounded-[4px] [&>svg]:rounded-[4px]`}),(0,W.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:t.name}),n>0&&(0,W.jsx)(`span`,{className:`text-foreground grid h-4 min-w-4 place-items-center rounded-full bg-[color-mix(in_srgb,var(--foreground)_22%,var(--background))] px-1 text-[10px] leading-none font-medium tabular-nums`,children:n}),(0,W.jsxs)(`div`,{className:`-my-0.5 flex shrink-0 items-center gap-0.5 opacity-0 transition-opacity group-data-highlighted/project:opacity-100 pointer-coarse:opacity-100`,children:[(0,W.jsx)(`button`,{className:`text-muted-foreground hover:text-foreground hover:bg-foreground/10 grid size-5 cursor-pointer place-items-center rounded-sm [&_svg]:size-3.5`,title:`Archive project`,"aria-label":`Archive ${t.name}`,onClick:e=>{e.stopPropagation(),Fs(t.machine,t.id,{hidden:!0}).catch(mt)},children:(0,W.jsx)(V,{icon:lo})}),(0,W.jsx)(`button`,{className:`text-muted-foreground hover:text-foreground hover:bg-foreground/10 grid size-5 cursor-pointer place-items-center rounded-sm [&_svg]:size-3.5`,title:`Configure project`,"aria-label":`Configure ${t.name}`,onClick:n=>{n.stopPropagation(),o(!1),e.onEdit(t)},children:(0,W.jsx)(V,{icon:Go})})]})]})},_(t.machine,t.id))})})]},n.id))]}),t.length===1&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(Ht,{}),(0,W.jsxs)(`div`,{className:`flex items-center`,children:[(0,W.jsxs)(Gt,{className:`flex-1 pl-8`,onSelect:()=>e.onAddProject(t[0].id),children:[(0,W.jsx)(V,{icon:ka}),`Add project…`]}),(0,W.jsx)(`div`,{className:`flex shrink-0 items-center pr-1`,children:p(n.filter(e=>e.hidden))})]})]})]})]})}function VP(e){let t=R(e=>e.errors),n=R(e=>e.machines),r=R(e=>e.sessions),i=R(e=>e.unseen),a=n.filter(e=>e.status===`offline`||e.status===`unpaired`),o=r.filter(e=>Object.values(Ee(n,e.machine,e.id)?.tasks??{}).includes(`failed`)),s=r.filter(e=>Ee(n,e.machine,e.id)?.waiting===!0),c=r.filter(e=>{let t=Ee(n,e.machine,e.id);return i.includes(_(e.machine,e.id))&&t?.waiting!==!0&&t?.running!==!0&&!Object.values(t?.tasks??{}).includes(`running`)}),l=t.length+a.length+o.length,u=!e.hideDone&&c.length>0;if(l===0&&s.length===0&&!u)return null;let d=c.map(e=>(0,W.jsx)(WP,{session:e,icon:eo,className:`text-success`,detail:`Done`},_(e.machine,e.id))),f=s.map(e=>(0,W.jsx)(WP,{session:e,icon:Yo,className:`text-question`,detail:`Waiting for approval`},_(e.machine,e.id))),p=e.collapsed===!0&&u&&s.length>0&&l>0;return(0,W.jsxs)(`div`,{className:z(`flex shrink-0 items-center gap-1`,e.className),children:[p&&(0,W.jsxs)(HP,{className:`bg-question/15 text-question`,icon:Yo,count:s.length+c.length,label:`${s.length} waiting for approval, ${c.length} done`,children:[f,d]}),!p&&u&&(0,W.jsx)(HP,{className:`bg-success/15 text-success`,icon:eo,count:c.length,label:`${c.length} done`,children:d}),!p&&s.length>0&&(0,W.jsx)(HP,{className:`bg-question/15 text-question`,icon:Yo,count:s.length,label:`${s.length} waiting for approval`,children:f}),l>0&&(0,W.jsxs)(HP,{className:z(t.length>0&&`bg-error/15 text-error`,t.length===0&&`bg-warning/15 text-warning-foreground`),icon:t.length>0?Dn:Na,count:l,label:l===1?`1 problem`:`${l} problems`,onClose:Ue,children:[t.map((e,t)=>(0,W.jsx)(UP,{icon:Dn,className:`text-error`,children:(0,W.jsx)(`span`,{className:`text-error-foreground whitespace-pre-wrap`,children:e})},t)),a.map(e=>(0,W.jsxs)(UP,{icon:Na,className:`text-warning-foreground`,children:[e.status===`offline`&&`${e.name} is offline`,e.status===`unpaired`&&`${e.name} needs pairing`]},e.id)),o.map(e=>(0,W.jsx)(WP,{session:e,icon:Na,className:`text-warning-foreground`,detail:`Background task failed`},_(e.machine,e.id)))]})]})}function HP(e){return(0,W.jsxs)($n,{onOpenChange:t=>!t&&e.onClose?.(),children:[(0,W.jsx)(Wt,{asChild:!0,children:(0,W.jsxs)(`button`,{className:z(`flex h-5 shrink-0 cursor-pointer items-center gap-0.75 rounded-[6px] px-1.25 text-[11px] font-medium tabular-nums`,e.className),title:e.label,"aria-label":e.label,children:[(0,W.jsx)(V,{icon:e.icon,className:`size-3 shrink-0`}),e.count]})}),(0,W.jsx)(sn,{align:`end`,collisionPadding:12,className:`flex max-h-80 w-[min(20rem,calc(100vw-2rem))] flex-col gap-px overflow-y-auto p-1 text-sm`,children:e.children})]})}function UP(e){return(0,W.jsxs)(`div`,{className:`flex items-start gap-2 px-2 py-1.5`,children:[(0,W.jsx)(V,{icon:e.icon,className:z(`mt-0.5 size-4 shrink-0`,e.className)}),(0,W.jsx)(`div`,{className:`min-w-0 flex-1`,children:e.children})]})}function WP(e){return(0,W.jsx)(Kt,{asChild:!0,children:(0,W.jsx)(`button`,{className:`hover:bg-accent cursor-pointer rounded-md text-left`,onClick:()=>He({machine:e.session.machine,projectId:e.session.projectId,sessionId:e.session.id}),children:(0,W.jsxs)(UP,{icon:e.icon,className:e.className,children:[(0,W.jsx)(`div`,{className:`text-foreground truncate`,children:e.session.title}),(0,W.jsx)(`div`,{className:`text-muted-foreground text-xs`,children:e.detail})]})})})}var GP=`text-sidebar-muted-foreground/80 hover:bg-sidebar-row-hover hover:text-sidebar-foreground flex shrink-0 cursor-pointer items-center justify-center rounded-[var(--control-radius)] [&>svg]:size-4 [&>svg]:shrink-0 [&>svg]:text-(--sidebar-icon-color) hover:[&>svg]:text-sidebar-foreground`;function KP(e){let t=R(e=>e.selection),n=R(e=>e.machines),r=R(e=>e.sessions),i=R(e=>e.projects),a=R(e=>e.settings.provider),o=R(e=>e.unseen),s=R(e=>e.loaded),c=R(e=>e.inactive),l=R(e=>e.inactiveVersion),f=R(e=>e.prefs.groupActiveByProject),[p,m]=ur(`sidebarScope`,null),[h,g]=(0,U.useState)(null),[v,y]=(0,U.useState)(null),[b,x]=(0,U.useState)(!1),[S,C]=(0,U.useState)(!1),[w,T]=(0,U.useState)(!1),[E,D]=ur(`sidebarWidth`,240),O=r.filter(e=>p===null||e.machine===p.machine&&e.projectId===p.projectId).sort((e,t)=>t.updatedAt-e.updatedAt),k=O.filter(e=>{let t=Ee(n,e.machine,e.id);return e.status===`snoozed`&&t?.waiting!==!0&&(t?.running===!0||Object.values(t?.tasks??{}).includes(`running`))}),A=[...O.filter(e=>e.status===`pinned`),...O.filter(e=>e.status===`active`||e.status===`snoozed`&&!k.includes(e))],j=O.filter(e=>e.status===`minimized`),M=p?.machine??null,ee=p?.projectId??null,te=t!==null&&t.sessionId!==null&&s&&!r.some(e=>e.machine===t.machine&&e.id===t.sessionId)?{machine:t.machine,id:t.sessionId,provider:a,title:`New thread`,projectId:t.projectId,branch:null,updatedAt:Date.now(),status:`active`}:null,ne=t!==null&&t.sessionId===null?t:null,re=te===null?A:[te,...A],ie=f&&p===null,ae=[...new Map([...ne===null?[]:[ne],...re].map(e=>[_(e.machine,e.projectId),e]))],oe=e.mobile?TN:$E;(0,U.useEffect)(()=>{if(!w)return;let e=!0,t=M===null?L().machines.filter(e=>e.status===`online`).map(e=>e.id):[M];return Promise.all(t.map(async e=>(await N(e,`sessions.inactive`,{projectId:ee})).map(t=>({...t,machine:e})))).then(t=>{e&&ze({inactive:t.flat()})}).catch(mt),()=>{e=!1}},[w,M,ee,l]);function ce(e,t,n){He({machine:e,projectId:t,sessionId:n})}function le(){let e=p??t??ue();e===null?n.length>0?g(n[0].id):u(`Machines`):ce(e.machine,e.projectId,null)}function ue(){let e=localStorage.getItem(`lastProject`),t=e===null?null:JSON.parse(e),n=(t===null?void 0:i.find(e=>e.machine===t.machine&&e.id===t.projectId))??i.at(0);return n===void 0?null:{machine:n.machine,projectId:n.id}}Ms([`mod+n`,`mod+t`],le,{enableOnFormTags:!0,preventDefault:!0});function de(e){let t=e.clientX-E;Et(e,e=>{let n=Math.min(480,Math.max(200,e.clientX-t));D(n)})}function fe(r,i){let a=e.mobile?wN:QE;return(0,W.jsx)(a,{session:r,slim:i,selected:t?.machine===r.machine&&t.sessionId===r.id,activity:Ee(n,r.machine,r.id),unseen:o.includes(_(r.machine,r.id)),saved:r!==te,scope:p,onSelect:()=>ce(r.machine,r.projectId,r.id)},_(r.machine,r.id))}function pe(e,t,n,r,i){return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`li`,{className:z(`mx-0.5 h-9 pt-2`,i&&`mt-auto`),children:(0,W.jsxs)(`button`,{"aria-expanded":n,className:`text-sidebar-muted-foreground/60 flex h-9 w-full cursor-pointer items-center gap-2 rounded-md px-2 text-left text-xs font-medium`,onClick:r,children:[(0,W.jsx)(`span`,{className:`shrink-0`,children:e}),(0,W.jsx)(`span`,{className:`bg-sidebar-border/60 h-px min-w-2 flex-1`}),(0,W.jsx)(V,{icon:cr,className:z(`size-3 shrink-0 transition-transform`,!n&&`rotate-180`)})]})}),n&&t.map(e=>fe(e,e.status===`inactive`))]})}return(0,W.jsxs)(`aside`,{className:z(`bg-sidebar text-sidebar-foreground border-sidebar-border flex flex-none border-r select-none`,e.className),children:[(0,W.jsxs)(`div`,{className:z(`relative flex min-w-0 flex-col`,e.mobile&&`flex-1`),style:e.mobile?void 0:{width:E},children:[(0,W.jsxs)(`div`,{className:`flex h-(--workspace-topbar-height) shrink-0 items-center gap-2 px-3`,children:[e.mobile?(0,W.jsx)(SN,{buttonClassName:GP}):(0,W.jsx)(`button`,{className:z(GP,`size-7`),title:`Hide sidebar (${Dt}+B)`,"aria-label":`Hide sidebar`,onClick:e.onHide,children:(0,W.jsx)(V,{icon:Fo})}),(0,W.jsx)(BP,{scope:p,onScope:m,onEdit:y,onAddProject:g}),e.mobile&&(0,W.jsx)(VP,{hideDone:!0}),(0,W.jsx)(`button`,{className:z(GP,`ml-auto size-7`),title:`Search (${Dt}+K)`,"aria-label":`Search`,onClick:()=>se(!0),children:(0,W.jsx)(V,{icon:Cn})}),(0,W.jsx)(`button`,{className:z(GP,`size-7`),title:`New thread (${Dt}+N)`,onClick:le,children:(0,W.jsx)(V,{icon:Xo})})]}),(0,W.jsx)(`nav`,{className:`flex min-h-0 flex-1 [scrollbar-width:none] flex-col overflow-y-auto px-(--sidebar-content-inset) pb-(--sidebar-content-inset)`,children:(0,W.jsxs)(`ul`,{className:`flex flex-1 flex-col gap-px`,children:[ie?ae.map(([t,n])=>(0,W.jsx)(zP,{machine:n.machine,projectId:n.projectId,sessions:re.filter(e=>_(e.machine,e.projectId)===t),started:te,mobile:e.mobile},t)):(0,W.jsxs)(W.Fragment,{children:[ne!==null&&(0,W.jsx)(oe,{machine:ne.machine,projectId:ne.projectId,onSelect:()=>ce(ne.machine,ne.projectId,null)}),re.map(e=>fe(e,!1))]}),A.length===0&&te===null&&t?.sessionId!==null&&(0,W.jsx)(`li`,{className:`text-sidebar-muted-foreground/60 px-2.5 py-6 text-center text-xs`,children:`No threads yet`}),k.length>0&&pe(b?`Snoozed`:`Snoozed (${k.length})`,k,b,()=>x(!b),!0),j.length>0&&pe(S?`Minimized`:`Minimized (${j.length})`,j,S,()=>C(!S),k.length===0),pe(`Inactive`,c,w,()=>T(!w),k.length===0&&j.length===0)]})}),!e.mobile&&(0,W.jsxs)(`div`,{className:`border-sidebar-border @container flex shrink-0 flex-col gap-px border-t p-(--sidebar-content-inset)`,children:[(0,W.jsx)(xN,{buttonClassName:GP,mobile:!1}),(0,W.jsxs)(`div`,{className:`relative`,children:[(0,W.jsxs)(`button`,{className:z(GP,`h-8 w-full justify-start gap-2 px-2.5 text-sm`),title:`Settings`,onClick:()=>d(!0),children:[(0,W.jsx)(V,{icon:Go}),(0,W.jsx)(`span`,{className:`truncate`,children:`Settings`})]}),(0,W.jsxs)(`div`,{className:`absolute top-1.5 right-1.5`,children:[(0,W.jsx)(VP,{className:`@max-[13rem]:hidden`,hideDone:!1}),(0,W.jsx)(VP,{className:`hidden @max-[13rem]:flex`,hideDone:!1,collapsed:!0})]})]})]}),!e.mobile&&(0,W.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,className:`group absolute inset-y-0 -right-1 z-20 w-2 cursor-col-resize select-none`,onPointerDown:de,children:(0,W.jsx)(`span`,{className:`group-hover:bg-border group-active:bg-primary/60 pointer-events-none absolute inset-y-0 left-1/2 w-px -translate-x-1/2 transition-colors`})})]}),h!==null&&(0,W.jsx)(AP,{machine:h,onClose:()=>g(null),onAdd:e=>{g(null),ce(e.machine,e.id,null)}}),v!==null&&(0,W.jsx)(MP,{project:v,onClose:()=>y(null),onRemoved:()=>{p?.machine===v.machine&&p.projectId===v.id&&m(null),y(null)}})]})}var qP={running:`Running`,completed:`Done`,failed:`Failed`,stopped:`Stopped`};function JP(e,t){return{agents:e.flatMap(e=>e.kind===`subagent`?[{item:e,agentId:e.agentId,status:XP(e.status,e.agentId,t)}]:[]),tasks:e.flatMap(e=>e.kind===`command`&&e.background!==null?[{item:e,taskId:e.background.taskId,path:e.background.outputPath,events:e.background.events,status:XP(e.status,e.background.taskId,t)}]:[])}}function YP(e){return e.description===``?e.command:e.description}function XP(e,t,n){let r=t===null?void 0:n?.tasks[t];return r===void 0?e===`running`?t===null&&n?.running===!0?`Running`:`Stopped`:qP[e]:qP[r]}function ZP(e){return(0,W.jsx)(`span`,{className:z(e.active&&`text-shimmer`),children:e.text})}function QP(e){return(0,W.jsxs)(`span`,{className:z(`flex min-w-0 items-baseline overflow-hidden text-[13px] leading-4 tracking-[-0.04px]`,e.grouped?`gap-1.5`:`gap-2`),children:[(0,W.jsx)(`span`,{className:z(`text-foreground shrink-0`,e.grouped?`font-normal`:`font-medium`),children:(0,W.jsx)(ZP,{text:e.title,active:e.pending})}),e.subtitle!==void 0&&e.subtitle!==``&&(0,W.jsx)(`span`,{className:z(`min-w-0 truncate tabular-nums`,e.grouped?`text-muted-foreground/70`:`text-muted-foreground`),children:e.subtitle}),e.args?.map(t=>(0,W.jsx)(`span`,{className:z(`min-w-0 truncate tabular-nums`,e.grouped?`text-muted-foreground/70`:`text-muted-foreground`),children:t},t))]})}function $P(e){return(0,W.jsx)(`span`,{"aria-hidden":!0,className:z(`text-muted-foreground/70 flex size-6 shrink-0 items-center justify-center transition-opacity`,e.open?`opacity-100`:`opacity-0 group-hover/tool:opacity-100`,e.className),children:(0,W.jsx)(V,{icon:In,strokeWidth:2.5,className:z(`size-3.5 transition-transform`,!e.open&&`-rotate-90`)})})}function eF(e){let t=e.onToggle,n=(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`span`,{className:`flex max-w-[calc(100%-24px)] min-w-0 items-center`,children:(0,W.jsx)(QP,{title:e.title,subtitle:e.subtitle,args:e.args,pending:e.pending,grouped:e.grouped})}),t!==null&&(0,W.jsx)($P,{open:e.open})]});return(0,W.jsxs)(`div`,{className:`flex w-full min-w-0 flex-col`,children:[t===null?(0,W.jsx)(`div`,{className:z(`flex w-full items-center select-none`,e.grouped?`min-h-7`:`min-h-9`),children:n}):(0,W.jsx)(`button`,{type:`button`,"aria-expanded":e.open,onClick:t,className:z(`group/tool focus-visible:ring-ring/70 flex w-full cursor-pointer items-center rounded-md text-left select-none focus-visible:ring-2 focus-visible:outline-none`,e.grouped?`h-7`:`h-9`),children:n}),e.open&&e.children!==void 0&&(0,W.jsx)(`div`,{className:z(`min-w-0 pt-1`,e.rail!==!1&&`ps-3`),children:e.children})]})}var tF=new Map([[`build`,`text-blue-400`],[`explore`,`text-yellow-400`],[`plan`,`text-pink-400`],[`review`,`text-green-400`],[`writer`,`text-purple-400`]]),nF=new Map([[`Running`,`Launched agent`],[`Done`,`Agent finished`],[`Failed`,`Agent failed`],[`Stopped`,`Agent stopped`]]),rF=new Map([[`Running`,`Started in background`],[`Done`,`Background task finished`],[`Failed`,`Background task failed`],[`Stopped`,`Background task stopped`]]),iF=[`text-sky-400`,`text-amber-400`,`text-fuchsia-400`,`text-emerald-400`,`text-violet-400`,`text-cyan-400`,`text-orange-400`,`text-teal-400`,`text-rose-400`,`text-indigo-400`,`text-lime-400`,`text-red-400`];function aF(e){let t=e.agent,n=t.toLowerCase(),r=0;for(let e of n)r=r*31+e.charCodeAt(0)>>>0;return{name:t[0].toUpperCase()+t.slice(1),description:e.description,tone:tF.get(n)??iF[r%iF.length]}}function oF(e){return(0,W.jsxs)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,"aria-hidden":!0,className:z(`size-4 shrink-0`,e.className),children:[(0,W.jsx)(`path`,{d:`M4 4.5C4 4.22386 4.22386 4 4.5 4H11.5C11.7761 4 12 4.22386 12 4.5V11.5C12 11.7761 11.7761 12 11.5 12H4.5C4.22386 12 4 11.7761 4 11.5V4.5Z`,fill:`currentColor`}),(0,W.jsx)(`path`,{d:`M14.5 1C14.7761 1 15 1.22386 15 1.5V14.5C15 14.7761 14.7761 15 14.5 15H1.5C1.22386 15 1 14.7761 1 14.5V1.5C1 1.22386 1.22386 1 1.5 1H14.5ZM2 14H14V2H2V14Z`,fill:`currentColor`})]})}function sF(e){return(0,W.jsx)(`svg`,{viewBox:`0 0 16 16`,"aria-hidden":!0,className:z(`size-4 shrink-0`,e.className),children:Array.from({length:25},(e,t)=>(0,W.jsx)(`rect`,{x:1+t%5*3,y:1+Math.floor(t/5)*3,width:2,height:2,fill:`currentColor`,className:`agent-dot`,style:{animationDelay:`${(t%5+Math.floor(t/5))*90}ms`}},t))})}function cF(e){let t=e.item;if(t.kind===`agent_message`){let n=t.target;return(0,W.jsx)(lF,{label:`Messaged agent`,detail:t.summary,pending:e.sending,onOpen:n===null?null:()=>e.onOpen(n)})}if(t.kind===`command`){let n=e.tasks.find(e=>e.item.id===t.id);if(n===void 0)throw Error(`Task ${t.id} is missing from the thread`);return(0,W.jsx)(lF,{label:rF.get(n.status)??`Background task ${n.status.toLowerCase()}`,detail:YP(n.item),pending:n.status===`Running`,onOpen:()=>e.onOpen(t.id)})}let n=e.agents.find(e=>e.item.id===t.id);if(n===void 0)throw Error(`Agent ${t.id} is missing from the thread`);return(0,W.jsx)(lF,{label:nF.get(n.status)??`Agent ${n.status.toLowerCase()}`,detail:t.description,pending:n.status===`Running`,onOpen:()=>e.onOpen(t.id)})}function lF(e){let t=(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`span`,{className:`text-muted-foreground shrink-0`,children:(0,W.jsx)(ZP,{text:e.detail===``?e.label:`${e.label}:`,active:e.pending})}),e.detail!==``&&(0,W.jsx)(`span`,{className:`text-foreground min-w-0 truncate`,children:e.detail})]});return e.onOpen===null?(0,W.jsx)(`div`,{className:`flex min-h-7 min-w-0 items-center gap-1 text-[13px] leading-4 tracking-[-0.04px] select-none`,children:t}):(0,W.jsxs)(`button`,{type:`button`,title:`Open in Tasks panel`,onClick:e.onOpen,className:`group/agent focus-visible:ring-ring/70 flex min-h-7 w-fit max-w-full cursor-pointer items-center gap-1 rounded-md text-left text-[13px] leading-4 tracking-[-0.04px] select-none focus-visible:ring-2 focus-visible:outline-none`,children:[t,(0,W.jsx)(`span`,{className:`text-muted-foreground/70 flex shrink-0 opacity-0 transition-opacity group-hover/agent:opacity-100 group-focus-visible/agent:opacity-100 pointer-coarse:opacity-100`,children:(0,W.jsx)(V,{icon:Tn,className:`size-3.5`})})]})}function uF(e){let[t,n]=(0,U.useState)(!1),r=en(),i=e.plan,a=dF(i),o=i.length>900||i.split(`
|
|
16
16
|
`).length>20,s=o&&!t,c=`${i.trimEnd()}\n`;return(0,W.jsxs)(`div`,{className:`border-border/80 bg-card/70 rounded-3xl border p-4 sm:p-5`,children:[(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,W.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,W.jsx)(`span`,{className:`bg-secondary text-secondary-foreground relative inline-flex h-5.5 min-w-5.5 shrink-0 items-center justify-center gap-1 rounded-sm border border-transparent px-[calc(--spacing(1)-1px)] text-sm font-medium whitespace-nowrap sm:h-4.5 sm:min-w-4.5 sm:text-xs`,children:`Plan`}),(0,W.jsx)(`h3`,{className:`text-foreground truncate text-sm font-medium`,children:a??`Proposed plan`})]}),(0,W.jsxs)(Qt,{children:[(0,W.jsx)(un,{asChild:!0,children:(0,W.jsx)(H,{"aria-label":`Plan actions`,size:`icon-xs`,variant:`outline`,children:(0,W.jsx)(V,{icon:Rn,className:`size-4`})})}),(0,W.jsxs)(tn,{align:`end`,children:[(0,W.jsx)(Gt,{onSelect:e=>{e.preventDefault(),r.copy(c)},children:r.copied?`Copied!`:`Copy to clipboard`}),(0,W.jsx)(Gt,{onSelect:()=>{let e=URL.createObjectURL(new Blob([c],{type:`text/markdown;charset=utf-8`})),t=document.createElement(`a`);t.href=e,t.download=`${mF(a??`plan`)}.md`,t.click(),setTimeout(()=>URL.revokeObjectURL(e),0)},children:`Download as markdown`})]})]})]}),(0,W.jsxs)(`div`,{className:`mt-4`,children:[(0,W.jsxs)(`div`,{className:z(`relative`,s&&`max-h-104 overflow-hidden`),children:[(0,W.jsx)(B,{text:s?pF(i):fF(i)}),s&&(0,W.jsx)(`div`,{className:`from-card/95 via-card/80 pointer-events-none absolute inset-x-0 bottom-0 h-24 bg-linear-to-t to-transparent`})]}),o&&(0,W.jsx)(`div`,{className:`mt-4 flex justify-center`,children:(0,W.jsx)(H,{size:`sm`,variant:`outline`,onClick:()=>n(!t),children:t?`Collapse plan`:`Expand plan`})})]})]})}function dF(e){let t=/^\s{0,3}#{1,6}\s+(.+)$/m.exec(e)?.[1]?.trim();return t===void 0||t===``?null:t}function fF(e){let t=e.trimEnd().split(/\r?\n/),n=/^\s{0,3}#{1,6}\s+/.test(t[0]??``)?t.slice(1):t;for(;n[0]?.trim()===``;)n.shift();if(/^\s{0,3}#{1,6}\s+(.+)$/.exec(n[0]??``)?.[1]?.trim().toLowerCase()===`summary`)for(n.shift();n[0]?.trim()===``;)n.shift();return n.join(`
|
|
17
17
|
`)}function pF(e){let t=fF(e).trimEnd().split(/\r?\n/).map(e=>e.trimEnd()),n=[],r=0,i=!1;for(let e of t){let t=e.trim()!==``;if(t&&r>=10){i=!0;break}n.push(e),t&&(r+=1)}for(;n.length>0&&n.at(-1)?.trim()===``;)n.pop();return n.length===0?dF(e)??`Plan preview unavailable.`:(i&&n.push(``,`...`),n.join(`
|