offsite 0.0.79 → 0.0.80
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.
|
@@ -13,12 +13,12 @@ Error generating stack: `+e.message+`
|
|
|
13
13
|
`),s=i.length===1?i[0]:`${i.length} branches`;async function c(t){r(!0);try{await z(e.machine,`git.sync`,{projectId:e.projectId,repo:t})}catch(e){N(e)}finally{r(!1),e.onRefresh()}}return(0,W.jsxs)(W.Fragment,{children:[e.repos.length===1&&(0,W.jsx)(on,{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:Hn,className:`size-3.5 shrink-0`}),(0,W.jsx)(`span`,{className:`truncate`,children:s})]}),e.repos.length>1&&a.length>0&&(0,W.jsxs)(fn,{children:[(0,W.jsx)(dr,{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?xr:a.length===1?a[0].next.icon:Cr,className:B(`size-3.5 shrink-0`,n&&`animate-spin`)}),(0,W.jsx)(`span`,{className:`truncate`,children:s})]})}),(0,W.jsx)(vn,{align:`end`,className:`w-64`,children:a.map(e=>(0,W.jsxs)(wn,{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)(Sr,{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:q}),(0,W.jsx)(`span`,{className:`hidden sm:inline`,children:`Commit`})]}),(0,W.jsxs)(fn,{open:t.menuOpen,onOpenChange:t.setMenuOpen,children:[(0,W.jsx)(dr,{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?xr:jr,className:B(`size-4`,t.committing&&`animate-spin`)})})}),(0,W.jsx)(vn,{align:`end`,className:`w-56`,children:(0,W.jsx)(up,{git:t,collapsed:!1})})]})]}),(0,W.jsx)(dp,{git:t})]})}function pp({className:e,size:t=`default`,...n}){return(0,W.jsx)(au,{"data-slot":`switch`,"data-size":t,className:B(`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)(su,{"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 mp=`3.6.8`,hp=`1.3.1`,gp=[{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`}],_p=[{value:`macos`,label:`macOS`},{value:`linux`,label:`Linux`},{value:`windows`,label:`Windows`}];async function vp(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 yp(e,t){let n=m();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:bp(t),clickToMoveCursor:e.behavior.clickToMoveCursor,optionAsMeta:e.behavior.optionAsMeta,windowsCopyPaste:e.behavior.windowsCopyPaste}}function bp(e){if(e===`offsite`)return`offsite 0.0.0`;if(e===`ghostty`)return`ghostty ${hp}`;if(e===`iterm2`)return`iTerm2 ${mp}`;throw Error(`unknown terminal identity ${e}`)}function xp(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 Q(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 Sp(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)(Kf,{className:B(`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 Cp(e){return(0,W.jsx)(Sp,{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 wp(e){let t=e.prefs.editor,[n,r]=(0,U.useState)(!gp.some(e=>e.family===t.font.family));function i(t){D({...e.prefs,editor:t})}function a(e,n){i({...t,[e]:{...t[e],...n}})}return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(xp,{title:`Font`,children:[(0,W.jsx)(Q,{label:`Family`,children:(0,W.jsxs)(qf,{value:n?`custom`:t.font.family,onValueChange:e=>{r(e===`custom`),e!==`custom`&&a(`font`,{family:e})},children:[(0,W.jsx)(Yf,{className:`w-56`,children:(0,W.jsx)(Jf,{})}),(0,W.jsxs)(Xf,{children:[gp.map(e=>(0,W.jsx)(Zf,{value:e.family,children:e.label},e.family)),(0,W.jsx)(Zf,{value:`custom`,children:`Custom`})]})]})}),n&&(0,W.jsx)(Q,{label:`Custom family`,children:(0,W.jsx)(Sp,{placeholder:`Installed font name`,value:t.font.family,onCommit:e=>a(`font`,{family:e})})}),(0,W.jsx)(Q,{label:`Size`,children:(0,W.jsx)(Cp,{value:t.font.size,step:.5,onCommit:e=>a(`font`,{size:e})})}),(0,W.jsx)(Q,{label:`Line height`,children:(0,W.jsx)(Cp,{value:t.font.lineHeight,step:.05,onCommit:e=>a(`font`,{lineHeight:e})})}),(0,W.jsx)(Q,{label:`Ligatures`,children:(0,W.jsx)(pp,{checked:t.font.ligatures,onCheckedChange:e=>a(`font`,{ligatures:e})})}),(0,W.jsx)(Q,{label:`Font features`,children:(0,W.jsx)(Sp,{placeholder:`'ss01', 'zero'`,value:t.font.features,onCommit:e=>a(`font`,{features:e})})})]}),(0,W.jsxs)(xp,{title:`Cursor`,children:[(0,W.jsx)(Q,{label:`Style`,children:(0,W.jsxs)(qf,{value:t.cursor.style,onValueChange:e=>a(`cursor`,{style:e}),children:[(0,W.jsx)(Yf,{className:`w-56`,children:(0,W.jsx)(Jf,{})}),(0,W.jsxs)(Xf,{children:[(0,W.jsx)(Zf,{value:`block`,children:`Block`}),(0,W.jsx)(Zf,{value:`bar`,children:`Bar`}),(0,W.jsx)(Zf,{value:`underline`,children:`Underline`})]})]})}),(0,W.jsx)(Q,{label:`Blink`,children:(0,W.jsx)(pp,{checked:t.cursor.blink,onCheckedChange:e=>a(`cursor`,{blink:e})})})]}),(0,W.jsxs)(xp,{title:`Text`,children:[(0,W.jsx)(Q,{label:`Tab size`,children:(0,W.jsx)(Cp,{value:t.tabSize,onCommit:e=>i({...t,tabSize:e})})}),(0,W.jsx)(Q,{label:`Word wrap`,children:(0,W.jsx)(pp,{checked:t.wordWrap,onCheckedChange:e=>i({...t,wordWrap:e})})})]})]})}var Tp=[{id:`original`,name:`Original`,scale:1,tile:null},{id:`small`,name:`Small`,scale:.7,tile:null},{id:`dark`,name:`Dark`,scale:.7,tile:{color:`#0a0a0a`,shape:`rounded`}},{id:`light`,name:`Light`,scale:.7,tile:{color:`#ffffff`,shape:`rounded`}},{id:`dark-circle`,name:`Dark circle`,scale:.62,tile:{color:`#0a0a0a`,shape:`circle`}},{id:`light-circle`,name:`Light circle`,scale:.62,tile:{color:`#ffffff`,shape:`circle`}},{id:`dark-square`,name:`Dark square`,scale:.7,tile:{color:`#0a0a0a`,shape:`square`}},{id:`light-square`,name:`Light square`,scale:.7,tile:{color:`#ffffff`,shape:`square`}}];function Ep(e){let t=e.prefs;return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(xp,{title:`Appearance`,children:(0,W.jsx)(Q,{label:`Theme`,children:(0,W.jsxs)(qf,{value:t.theme,onValueChange:e=>D({...t,theme:e}),children:[(0,W.jsx)(Yf,{className:`w-56`,children:(0,W.jsx)(Jf,{})}),(0,W.jsx)(Xf,{children:Pt.map(e=>(0,W.jsx)(Zf,{value:e.id,children:e.name},e.id))})]})})}),(0,W.jsx)(xp,{title:`Sidebar`,children:(0,W.jsx)(Q,{label:`Group active sessions by project in Inbox`,children:(0,W.jsx)(pp,{checked:t.groupActiveByProject,onCheckedChange:e=>D({...t,groupActiveByProject:e})})})}),(0,W.jsx)(kp,{}),(0,W.jsx)(Dp,{}),(0,W.jsx)(H,{variant:`outline`,onClick:e.onRestore,children:`Restore browser defaults`})]})}function Dp(){let[e,t]=(0,U.useState)(!1),[n,r]=(0,U.useState)(null);async function i(){t(!0),r(null);try{let e=`serviceWorker`in navigator?await navigator.serviceWorker.getRegistration():void 0;if(e===void 0){let e=await fetch(`/?update=${Date.now()}`,{cache:`no-store`});if(!e.ok)throw Error(`the server answered ${e.status}`)}else{await e.update();let t=e.installing??e.waiting;t!==null&&await Op(t)}location.reload()}catch(e){console.error(`could not update`,e),r(Ht(e)),t(!1)}}return(0,W.jsx)(xp,{title:`App`,children:(0,W.jsx)(Q,{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-destructive text-xs`,children:[`Could not update: `,n]}),(0,W.jsxs)(H,{size:`sm`,variant:`outline`,disabled:e,onClick:()=>void i(),children:[e&&(0,W.jsx)(V,{icon:hr,className:`animate-spin`}),e?`Updating…`:`Update`]})]})})})}async function Op(e){await new Promise((t,n)=>{function r(){e.state===`activated`&&t(),e.state===`redundant`&&n(Error(`the new version failed to install`))}e.addEventListener(`statechange`,r),r()})}function kp(){let e=k(e=>e.machines.find(e=>e.addresses.some(e=>(de??[location.origin]).includes(e))));if(e===void 0||e.appIcon===null)return null;let t=e.appIcon;return(0,W.jsx)(xp,{title:`App icon`,children:(0,W.jsx)(`div`,{className:`grid grid-cols-4 gap-2 p-3 @max-lg:grid-cols-2`,children:Tp.map(n=>(0,W.jsxs)(`button`,{type:`button`,"aria-pressed":t===n.id,className:B(`hover:bg-accent flex flex-col items-center gap-2 rounded-lg border p-3 text-xs`,t===n.id&&`border-primary bg-accent`),onClick:()=>z(e.id,`appIcon.save`,n.id).catch(N),children:[(0,W.jsx)(`span`,{className:B(`flex size-12 items-center justify-center`,n.tile?.shape===`rounded`&&`rounded-[22%]`,n.tile?.shape===`circle`&&`rounded-full`,n.tile!==null&&`ring-border ring-1`),style:{background:n.tile?.color},children:(0,W.jsx)(`img`,{src:`/icon.svg`,alt:``,style:{width:`${n.scale*100}%`}})}),n.name]},n.id))})})}function Ap(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(!jp(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(!jp(a,r))return!1;break}if(a===`b`||a===`c`||r&&`dfnprvx`.includes(a)||!r&&a===`i`)return!1}}return!0}function jp(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 Mp(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`?Ap(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 Np=[10,15,30,45,60,120,180,300,600,900,1800,3600];function Pp(e){let t=e.config;function n(n){bt(e.machine,{...t,...n})}return(0,W.jsxs)(xp,{title:`Agents`,children:[(0,W.jsx)(Q,{label:`Send while working`,children:(0,W.jsxs)(qf,{value:t.delivery,onValueChange:n=>{if(n!==`queue`&&n!==`steer`)throw Error(`Unknown delivery ${n}`);bt(e.machine,{...t,delivery:n})},children:[(0,W.jsx)(Yf,{className:`w-56`,children:(0,W.jsx)(Jf,{})}),(0,W.jsxs)(Xf,{children:[(0,W.jsx)(Zf,{value:`queue`,children:`Queue messages`}),(0,W.jsx)(Zf,{value:`steer`,children:`Steer the agent`})]})]})}),(0,W.jsx)(Q,{label:`Auto-skip questions`,children:(0,W.jsx)(Fp,{value:t.autoSkipQuestionTimeout,onChange:e=>n({autoSkipQuestionTimeout:e})})}),(0,W.jsx)(Q,{label:`Auto-resolve permissions`,children:(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[t.autoPermissionTimeout!==null&&(0,W.jsxs)(qf,{value:t.autoPermissionMode,onValueChange:e=>{if(e!==`allow`&&e!==`deny`)throw Error(`Unknown decision ${e}`);n({autoPermissionMode:e})},children:[(0,W.jsx)(Yf,{className:`w-24`,children:(0,W.jsx)(Jf,{})}),(0,W.jsxs)(Xf,{children:[(0,W.jsx)(Zf,{value:`allow`,children:`Allow`}),(0,W.jsx)(Zf,{value:`deny`,children:`Deny`})]})]}),(0,W.jsx)(Fp,{value:t.autoPermissionTimeout,onChange:e=>n({autoPermissionTimeout:e})})]})})]})}function Fp(e){let t=e.value===null||Np.includes(e.value)?Np:[...Np,e.value].sort((e,t)=>e-t);return(0,W.jsxs)(qf,{value:e.value===null?`off`:String(e.value),onValueChange:t=>e.onChange(t===`off`?null:Number(t)),children:[(0,W.jsx)(Yf,{className:`w-40`,children:(0,W.jsx)(Jf,{})}),(0,W.jsxs)(Xf,{children:[(0,W.jsx)(Zf,{value:`off`,children:`Off`}),t.map(e=>(0,W.jsx)(Zf,{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 Ip(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),z(e.machine,`capabilities`,{provider:t.provider,accountId:t.accountId,projectId:null}).then(e=>{n&&r(e.models)},e=>{n&&a(Ht(e))}),()=>{n=!1}},[e.machine,t.provider,t.accountId]);function o(t){bt(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)(xp,{title:e.title,children:[(0,W.jsx)(Q,{label:`Account`,children:(0,W.jsxs)(qf,{value:t.provider===null?`off`:t.provider===`opencode`?`opencode`:t.accountId??`off`,onValueChange:s,children:[(0,W.jsx)(Yf,{className:`w-56`,children:(0,W.jsx)(Jf,{})}),(0,W.jsxs)(Xf,{children:[(0,W.jsx)(Zf,{value:`off`,children:`Off`}),[...e.claudeAccounts,...e.codexAccounts].map(e=>(0,W.jsxs)(Zf,{value:e.id,disabled:!e.valid,children:[(0,W.jsx)(Vs,{provider:e.provider,className:`size-4`}),`${rn[e.provider]} · ${e.name}`]},e.id)),e.openCode.available&&(0,W.jsxs)(Zf,{value:`opencode`,children:[(0,W.jsx)(Vs,{provider:`opencode`,className:`size-4`}),rn.opencode]})]})]})}),t.provider!==null&&(0,W.jsx)(Q,{label:`Model`,children:(0,W.jsxs)(qf,{value:t.model??void 0,disabled:n===null,onValueChange:e=>o({...t,model:e}),children:[(0,W.jsx)(Yf,{className:`w-56`,children:(0,W.jsx)(Jf,{placeholder:i===null?n===null?`Loading…`:`Choose a model`:`Unavailable`})}),(0,W.jsx)(Xf,{children:(n??[]).map(e=>(0,W.jsx)(Zf,{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 Lp={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`},Rp={zsh:`zsh`,bash:`bash`,fish:`fish`,pwsh:`powershell`,powershell:`powershell`,cmd:`cmd`},zp={macos:[`zsh`,`bash`,`fish`,`pwsh`],linux:[`bash`,`zsh`,`fish`,`pwsh`],windows:[`pwsh`,`powershell`,`cmd`]};function Bp(e){let t=e.trim().split(/[\\/]/).pop()?.toLowerCase().replace(/\.exe$/,``);return t===void 0?void 0:Rp[t]}function Vp(e){return e.replace(/[\\/][^\\/]*$/,``)}function Hp(e){return(0,W.jsx)(`svg`,{viewBox:`0 0 24 24`,className:`size-4 flex-none`,fill:`currentColor`,children:(0,W.jsx)(`path`,{d:Lp[e.logo]})})}function Up(e){let[t,n]=(0,U.useState)(e.value??``),[r,i]=(0,U.useState)(null),[a,o]=(0,U.useState)(null),s=Bp(t),c=e.platform===e.device,l=c?r:zp[e.platform].map(e=>({name:e,path:null}));(0,U.useEffect)(()=>{c&&z(e.machine,`terminal.shells`,void 0).then(i,e=>o(Ht(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)(Hp,{logo:s})}),(0,W.jsx)(Kf,{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)(fn,{children:[(0,W.jsx)(dr,{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:sn})})}),(0,W.jsxs)(vn,{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)(wn,{onSelect:()=>u(e.path??e.name),children:[(0,W.jsx)(Hp,{logo:Rp[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:Vp(e.path)})})]},e.path??e.name)),(0,W.jsx)(On,{}),(0,W.jsx)(wn,{onSelect:()=>u(``),children:`System default`})]})]})]})}function Wp(e){let t=e.config.workingDir[e.platform]??``,n=e.config.newThreads;return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(xp,{title:`Projects`,children:(0,W.jsx)(Q,{label:`Working directory`,children:(0,W.jsx)(Sp,{className:`w-72 font-mono`,value:t,placeholder:`Home folder`,onCommit:t=>bt(e.machine,{...e.config,workingDir:{...e.config.workingDir,[e.platform]:t.trim()===``?null:t.trim()}})},`${e.machine}-${t}`)})}),(0,W.jsx)(xp,{title:`New threads`,children:(0,W.jsx)(Q,{label:`Account`,children:(0,W.jsxs)(qf,{value:n.provider===`opencode`?`opencode`:n.accountId??void 0,onValueChange:t=>{if(t===`opencode`){bt(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`);bt(e.machine,{...e.config,newThreads:{...n,provider:r.provider,accountId:r.id}})},children:[(0,W.jsx)(Yf,{className:`w-56`,children:(0,W.jsx)(Jf,{placeholder:`First available`})}),(0,W.jsxs)(Xf,{children:[[...e.claudeAccounts,...e.codexAccounts].map(e=>(0,W.jsxs)(Zf,{value:e.id,disabled:!e.valid,children:[(0,W.jsx)(Vs,{provider:e.provider,className:`size-4`}),`${rn[e.provider]} · ${e.name}`]},e.id)),e.openCode.available&&(0,W.jsxs)(Zf,{value:`opencode`,children:[(0,W.jsx)(Vs,{provider:`opencode`,className:`size-4`}),rn.opencode]})]})]})})}),(0,W.jsx)(Gp,{machine:e.machine,config:e.config,platform:e.platform,defaultShell:e.defaultShell},e.machine),(0,W.jsx)(Pp,{machine:e.machine,config:e.config}),(0,W.jsx)(Ip,{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)(Ip,{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 Gp(e){let t=e.config.terminal,[n,r]=(0,U.useState)(e.platform),i=Mp(t.shell[e.platform],e.platform,e.defaultShell);function a(t){bt(e.machine,{...e.config,terminal:t})}return(0,W.jsxs)(xp,{title:`Shell`,note:`Applies to new terminals`,children:[(0,W.jsx)(Q,{label:`Platform`,children:(0,W.jsxs)(qf,{value:n,onValueChange:e=>r(e),children:[(0,W.jsx)(Yf,{className:`w-56`,children:(0,W.jsx)(Jf,{})}),(0,W.jsx)(Xf,{children:_p.map(t=>(0,W.jsxs)(Zf,{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)(Q,{label:`Command`,children:(0,W.jsx)(Up,{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)(Q,{label:(0,W.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[`Shell integration`,(0,W.jsx)(Wr,{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:Wo,"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)(pp,{checked:i===null&&t.behavior.shellIntegration,disabled:i!==null,onCheckedChange:e=>a({...t,behavior:{...t.behavior,shellIntegration:e}})})]})}),(0,W.jsx)(Kp,{identity:t.behavior.terminalIdentity,onChange:e=>a({...t,behavior:{...t.behavior,terminalIdentity:e}})})]})}function Kp(e){return(0,W.jsx)(Q,{label:`Report the terminal as`,children:(0,W.jsxs)(qf,{value:e.identity,onValueChange:e.onChange,children:[(0,W.jsx)(Yf,{className:`w-56`,children:(0,W.jsx)(Jf,{})}),(0,W.jsxs)(Xf,{children:[(0,W.jsx)(Zf,{value:`offsite`,children:`OffSite`}),(0,W.jsx)(Zf,{value:`ghostty`,children:`Ghostty`}),(0,W.jsx)(Zf,{value:`iterm2`,children:`iTerm2`})]})]})})}var qp=(0,U.createContext)({});function Jp(e){let t=(0,U.useRef)(null);return t.current===null&&(t.current=e()),t.current}var Yp=typeof window<`u`?U.useLayoutEffect:U.useEffect,Xp=(0,U.createContext)(null);function Zp(e,t){e.indexOf(t)===-1&&e.push(t)}function Qp(e,t){let n=e.indexOf(t);n>-1&&e.splice(n,1)}function $p([...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 em=(e,t,n)=>n>t?t:n<e?e:n,tm={},nm=e=>/^-?(?:\d+(?:\.\d+)?|\.\d+)$/u.test(e),rm=e=>typeof e==`object`&&!!e,im=e=>/^0[^.\s]+$/u.test(e);function am(e){let t;return()=>(t===void 0&&(t=e()),t)}var om=e=>e,sm=(...e)=>e.reduce((e,t)=>n=>t(e(n))),cm=(e,t,n)=>{let r=t-e;return r?(n-e)/r:1},lm=class{constructor(){this.subscriptions=[]}add(e){return Zp(this.subscriptions,e),()=>this.remove(e)}remove(e){Qp(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}},um=e=>e*1e3,dm=e=>e/1e3,fm=(e,t)=>t?1e3/t*e:0,pm=(e,t,n)=>e*(3*(1-e)*((1-e)*t+e*n)+e*e);function mm(e,t,n,r){return e===t&&n===r?om:i=>{let a=0,o=1,s=i;for(let t=0;;t++){s>=a&&s<=o||(s=(a+o)/2);let r=pm(s,e,n)-i;if(r*r<1e-28||t===40)break;r>0?o=s:a=s,s-=r*1e-7/(pm(s+1e-7,e,n)-i-r)}return pm(s,t,r)}}var hm=e=>t=>t<=.5?e(2*t)/2:(2-e(2*(1-t)))/2,gm=e=>t=>1-e(1-t),_m=mm(.33,1.53,.69,.99),vm=gm(_m),ym=hm(vm),bm=e=>e>=1?1:(e*=2)<1?.5*vm(e):.5*(2-2**(-10*(e-1))),xm=e=>1-Math.sin(Math.acos(e)),Sm=gm(xm),Cm=hm(xm),wm=mm(.42,0,1,1),Tm=mm(0,0,.58,1),Em=mm(.42,0,.58,1),Dm=e=>Array.isArray(e)&&typeof e[0]!=`number`,Om=e=>Array.isArray(e)&&typeof e[0]==`number`,km={linear:om,easeIn:wm,easeInOut:Em,easeOut:Tm,circIn:xm,circInOut:Cm,circOut:Sm,backIn:vm,backInOut:ym,backOut:_m,anticipate:bm},Am=e=>typeof e==`string`,jm=e=>{if(Om(e)){let[t,n,r,i]=e;return mm(t,n,r,i)}return Am(e)?km[e]:e},Mm={delta:0,timestamp:0,isProcessing:!1},Nm;function Pm(){Nm=void 0}var Fm={now:()=>(Nm===void 0&&Fm.set(Mm.isProcessing||tm.useManualTiming?Mm.timestamp:performance.now()),Nm),set:e=>{Nm=e,queueMicrotask(Pm)}},Im=e=>Math.round(e*1e5)/1e5,Lm=e=>t=>typeof t==`string`&&t.startsWith(e),Rm=Lm(`--`),zm=Lm(`var(--`),Bm=e=>zm(e)?Vm.test(e.split(`/*`)[0].trim()):!1,Vm=/var\(--(?:[\w-]+\s*|[\w-]+\s*,(?:\s*[^)(\s]|\s*\((?:[^)(]|\([^)(]*\))*\))+\s*)\)$/iu;function Hm(e){return typeof e==`string`&&e.split(`/*`)[0].includes(`var(--`)}var Um={test:e=>typeof e==`number`,parse:parseFloat,transform:e=>e},Wm={...Um,transform:e=>em(0,1,e)},Gm={...Um,default:1},Km=/-?(?:\d+(?:\.\d+)?|\.\d+)/gu;function qm(e){return e==null}var Jm=/^(?:#[\da-f]{3,8}|(?:rgb|hsl)a?\((?:-?[\d.]+%?[,\s]+){2}-?[\d.]+%?\s*(?:[,/]\s*)?(?:\b\d+(?:\.\d+)?|\.\d+)?%?\))$/iu,Ym=(e,t)=>n=>!!(typeof n==`string`&&Jm.test(n)&&n.startsWith(e)||t&&!qm(n)&&Object.prototype.hasOwnProperty.call(n,t)),Xm=(e,t,n)=>r=>{if(typeof r!=`string`)return r;let[i,a,o,s]=r.match(Km);return{[e]:parseFloat(i),[t]:parseFloat(a),[n]:parseFloat(o),alpha:s===void 0?1:parseFloat(s)}},Zm=e=>em(0,255,e),Qm={...Um,transform:e=>Math.round(Zm(e))},$m={test:Ym(`rgb`,`red`),parse:Xm(`red`,`green`,`blue`),transform:({red:e,green:t,blue:n,alpha:r=1})=>`rgba(`+Qm.transform(e)+`, `+Qm.transform(t)+`, `+Qm.transform(n)+`, `+Im(Wm.transform(r))+`)`},eh=(e,t,n)=>{let r=e.substring(1+t*n,1+(t+1)*n);return n>1?r:r+r};function th(e){let t=e.length>5?2:1,n=eh(e,3,t);return{red:parseInt(eh(e,0,t),16),green:parseInt(eh(e,1,t),16),blue:parseInt(eh(e,2,t),16),alpha:n?parseInt(n,16)/255:1}}var nh={test:Ym(`#`),parse:th,transform:$m.transform},rh=e=>({test:t=>typeof t==`string`&&t.endsWith(e)&&t.split(` `).length===1,parse:parseFloat,transform:t=>`${t}${e}`}),ih=rh(`deg`),ah=rh(`%`),$=rh(`px`),oh=rh(`vh`),sh=rh(`vw`),ch={...ah,parse:e=>ah.parse(e)/100,transform:e=>ah.transform(e*100)},lh={test:Ym(`hsl`,`hue`),parse:Xm(`hue`,`saturation`,`lightness`),transform:({hue:e,saturation:t,lightness:n,alpha:r=1})=>`hsla(`+Math.round(e)+`, `+ah.transform(Im(t))+`, `+ah.transform(Im(n))+`, `+Im(Wm.transform(r))+`)`},uh={test:e=>$m.test(e)||nh.test(e)||lh.test(e),parse:e=>$m.test(e)?$m.parse(e):lh.test(e)?lh.parse(e):nh.parse(e),transform:e=>typeof e==`string`?e:e.hasOwnProperty(`red`)?$m.transform(e):lh.transform(e),getAnimatableNone:e=>{let t=uh.parse(e);return t.alpha=0,uh.transform(t)}},dh=/(?:#[\da-f]{3,8}|(?:rgb|hsl)a?\((?:-?[\d.]+%?[,\s]+){2}-?[\d.]+%?\s*(?:[,/]\s*)?(?:\b\d+(?:\.\d+)?|\.\d+)?%?\))/giu,fh=new RegExp(Km.source),ph=new RegExp(dh.source,`i`);function mh(e){return isNaN(e)&&typeof e==`string`&&(fh.test(e)||ph.test(e))}var hh=`number`,gh=`color`,_h=`var`,vh=`var(`,yh="${}",bh=/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 xh(e){let t=e.toString();return fh.test(t)||ph.test(t)}function Sh(e){let t=e.toString(),n=[],r={color:[],number:[],var:[]},i=[],a=0;return{values:n,split:t.replace(bh,e=>(uh.test(e)?(r.color.push(a),i.push(gh),n.push(uh.parse(e))):e.startsWith(vh)?(r.var.push(a),i.push(_h),n.push(e)):(r.number.push(a),i.push(hh),n.push(parseFloat(e))),++a,yh)).split(yh),indexes:r,types:i}}function Ch(e){return Sh(e).values}function wh({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===hh?Im(r[a]):e===gh?uh.transform(r[a]):r[a]}return i}}function Th(e){return wh(Sh(e))}var Eh=e=>typeof e==`number`?0:uh.test(e)?uh.getAnimatableNone(e):e,Dh=(e,t)=>typeof e==`number`?t?.trim().endsWith(`/`)?e:0:Eh(e);function Oh(e){let t=Sh(e);return wh(t)(t.values.map((e,n)=>Dh(e,t.split[n])))}var kh={test:mh,parse:Ch,createTransformer:Th,getAnimatableNone:Oh};function Ah(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 jh({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=Ah(s,r,e+1/3),a=Ah(s,r,e),o=Ah(s,r,e-1/3)}return{red:Math.round(i*255),green:Math.round(a*255),blue:Math.round(o*255),alpha:r}}function Mh(e,t){return n=>n>0?t:e}var Nh=(e,t,n)=>e+(t-e)*n,Ph=(e,t,n)=>{let r=e*e,i=n*(t*t-r)+r;return i<0?0:Math.sqrt(i)},Fh=[nh,$m,lh],Ih=e=>Fh.find(t=>t.test(e));function Lh(e){let t=Ih(e);if(!t)return!1;let n=t.parse(e);return t===lh&&(n=jh(n)),n}var Rh=(e,t)=>{let n=Lh(e),r=Lh(t);if(!n||!r)return Mh(e,t);let i={...n};return e=>(i.red=Ph(n.red,r.red,e),i.green=Ph(n.green,r.green,e),i.blue=Ph(n.blue,r.blue,e),i.alpha=Nh(n.alpha,r.alpha,e),$m.transform(i))},zh=new Set([`none`,`hidden`]);function Bh(e,t){return zh.has(e)?n=>n<=0?e:t:n=>n>=1?t:e}function Vh(e,t){return n=>Nh(e,t,n)}function Hh(e){return typeof e==`number`?Vh:typeof e==`string`?Bm(e)?Mh:uh.test(e)?Rh:Kh:Array.isArray(e)?Uh:typeof e==`object`?uh.test(e)?Rh:Wh:Mh}function Uh(e,t){let n=[...e],r=n.length,i=e.map((e,n)=>Hh(e)(e,t[n]));return e=>{for(let t=0;t<r;t++)n[t]=i[t](e);return n}}function Wh(e,t){let n={...e,...t},r={};for(let i in n)e[i]!==void 0&&t[i]!==void 0&&(r[i]=Hh(e[i])(e[i],t[i]));return e=>{for(let t in r)n[t]=r[t](e);return n}}function Gh(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 Kh=(e,t)=>{let n=Sh(e),r=Sh(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?zh.has(e)&&!r.values.length||zh.has(t)&&!n.values.length?Bh(e,t):sm(Uh(Gh(n,r),r.values),wh(r)):Mh(e,t)},qh=/^(-?(?:\d+(?:\.\d*)?|\.\d+))([a-z%]*)$/iu;function Jh(e,t){let n=qh.exec(e);if(!n)return;let r=qh.exec(t);if(!r||n[2]!==r[2])return;let i=n[2],a=parseFloat(n[1]),o=parseFloat(r[1]);return e=>Im(Nh(a,o,e))+i}function Yh(e,t,n){if(typeof e==`number`&&typeof t==`number`&&typeof n==`number`)return Nh(e,t,n);if(typeof e==`string`&&typeof t==`string`){let n=Jh(e,t);if(n)return n}return Hh(e)(e,t)}var Xh=[`setup`,`read`,`resolveKeyframes`,`preUpdate`,`update`,`preRender`,`render`,`postRender`];function Zh(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 Qh=40;function $h(e,t,n={delta:0,timestamp:0,isProcessing:!1}){let r=!1,i=!0,a=()=>r=!0,o=Xh.reduce((e,t)=>(e[t]=Zh(a),e),{}),{setup:s,read:c,resolveKeyframes:l,preUpdate:u,update:d,preRender:f,render:p,postRender:m}=o,h=()=>{let a=tm.useManualTiming,o=a?n.timestamp:performance.now();r=!1,a||(n.delta=i?1e3/60:Math.max(Math.min(o-n.timestamp,Qh),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:Xh.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<Xh.length;t++)o[Xh[t]].cancel(e)},state:n,steps:o}}var{schedule:eg,cancel:tg,steps:ng}=$h(typeof requestAnimationFrame<`u`?requestAnimationFrame:om,!0,Mm),rg=e=>{let t=({timestamp:t})=>e(t);return{start:(e=!0)=>eg.update(t,e),stop:()=>tg(t),now:()=>Mm.isProcessing?Mm.timestamp:Fm.now()}},ig=(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)})`},ag=2e4;function og(e,t=50,n=ag,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 sg(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(og(o),ag);return{type:`keyframes`,ease:e=>o.next(s*e).value/t,duration:dm(s)}}var cg=100,lg=10,ug=1,dg=800,fg=.3,pg=.3,mg=.01,hg=2,gg=.005,_g=.5,vg=.01,yg=10,bg=.05,xg=e=>e<0?1/Math.max(1+e,bg):Math.max(1-e,bg);function Sg(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 Tg(e=>i*Math.exp(-r*e)-r*Math.exp(-i*e)-a,e=>Math.exp(-i*e)-Math.exp(-r*e),t)/t}function Cg(e,t){return e*Math.sqrt(1-t*t)}var wg=12;function Tg(e,t,n){let r=n;for(let n=1;n<wg;n++)r-=e(r)/t(r);return r}var Eg=.001;function Dg({duration:e=dg,bounce:t=fg}){let n,r,i=xg(t);e=em(vg,yg,dm(e)),i<1?(n=t=>{let n=t*i,r=n*e,a=Cg(t,i),o=Math.exp(-r);return Eg-n/a*o},r=t=>{let r=t*i*e,a=i*i*t*t*e,o=Math.exp(-r),s=Cg(t*t,i);return(-n(t)+Eg>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=Tg(n,r,a),s=o*Sg(i,o*e),c=s*s;return{stiffness:c,damping:i*2*Math.sqrt(c),duration:um(e)}}var Og=(e,t)=>(t?e>=0:e>0)&&e<1/0;function kg(e,t){if(Og(e,t))return e}function Ag(e){let t=kg(e.stiffness),n=kg(e.damping,!0),r=kg(e.mass),i={...e,stiffness:t??cg,damping:n??lg,mass:r??ug,isResolvedFromDuration:!1,isTimeDefined:(t??n??r)===void 0&&(e.duration!==void 0||e.bounce!==void 0)};if(i.isTimeDefined){if(e.visualDuration){let t=xg(e.bounce||0),n=2*Math.PI/(e.visualDuration*1.2)*Sg(t,2*Math.PI/1.2);i.stiffness=n*n,i.damping=2*t*Math.sqrt(i.stiffness)}else Object.assign(i,Dg(i)),i.isResolvedFromDuration=!0;Og(i.stiffness)&&Og(i.damping,!0)||(i.stiffness=cg,i.damping=lg)}return i}function jg(e=pg,t=fg){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}=Ag({...n}),f=e=>d?0:-dm(e),p=s/(2*Math.sqrt(o*c)),m=dm(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?mg:hg),g.restDelta=n.restDelta||(e?gg:_g)};_();let v,y,b;if(p<1){let e=Cg(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=>um(y(e)),next:e=>{let t=v(e);if(u)a.done=e>=l;else{let n=um(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(og(S),ag),t=ig(t=>S.next(e*t).value,e,30);return e+`ms `+t},toTransition:()=>{}};return S}var Mg=Object.assign(jg,{applyToOptions:e=>{let t=sg(e,100,jg);return e.ease=t.ease,e.duration=um(t.duration),e.type=`keyframes`,e}});function Ng({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=Mg({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 Pg(e,t,n){let r=[],i=tm.mix||Yh,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=sm(Array.isArray(t)?t[o]||om:t,a)),r.push(a)}return r}function Fg(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=Pg(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=cm(e[r],e[r+1],n);return s[r](i)};return n?t=>l(em(e[0],e[a-1],t)):l}function Ig(e,t){let n=e[e.length-1];for(let r=1;r<=t;r++){let i=cm(0,t,r);e.push(Nh(n,1,i))}}function Lg(e){let t=[0];return Ig(t,e.length-1),t}function Rg(e,t){return e.map(e=>e*t)}function zg(e,t){return e.map(()=>t||Em).splice(0,e.length-1)}function Bg({duration:e=300,keyframes:t,times:n,ease:r=`easeInOut`,mixer:i}){let a=typeof t[0]==`number`?void 0:i,o=Dm(r)?r.map(jm):jm(r)||Em,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:(tm.mix||Yh)(n,r);return{calculatedDuration:e,next:t=>(s.value=i?i(o(e>0?em(0,1,t/e):1)):r,s.done=t>=e,s)}}let c=Fg(Rg(n&&n.length===t.length?n:Lg(t),e),t,{ease:Array.isArray(o)?o:zg(t,o),mixer:a});return{calculatedDuration:e,next:t=>(s.value=c(t),s.done=t>=e,s)}}var Vg=5;function Hg(e,t,n){let r=Math.max(t-Vg,0);return fm(n-e(r),t-r)}function Ug(e,t,n=0){return t<=0?n:e.velocity?e.velocity(t):Hg(t=>e.next(t).value,t,e.next(t).value)}var Wg=e=>e!==null;function Gg(e,{repeat:t,repeatType:n=`loop`},r,i=1){let a=e.filter(Wg),o=i<0||t&&n!==`loop`&&t%2==1?0:a.length-1;return!o||r===void 0?a[o]:r}var Kg={decay:Ng,inertia:Ng,tween:Bg,keyframes:Bg,spring:Mg};function qg(e){typeof e.type==`string`&&(e.type=Kg[e.type])}var Jg=40,Yg=(e,t)=>t-e>Jg&&!tm.useManualTiming?t:e;function Xg(e,t){return{kind:e,animation:t,timestamp:Fm.now(),frameTimestamp:Mm.timestamp,frameIsProcessing:Mm.isProcessing}}function Zg(e,t,n){let r=globalThis.__MOTION_INSPECT__;if(r)try{r({...Xg(`animation-start`,e),options:n?{...t,...n}:t})}catch{}}function Qg(e,t){let n=globalThis.__MOTION_INSPECT__;if(n)try{n({...Xg(`layout-animation-start`,e),node:t})}catch{}}var $g=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)}},e_=e=>e/100,t_=e=>Math.round(e*1e4)/1e4,n_=class extends $g{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!==Fm.now()&&this.tick(Fm.now()),this.isStopped=!0,this.state!==`idle`&&(this.teardown(),this.options.onStop?.())},this.options=e,this.initAnimation(),this.play(),e.autoplay===!1&&this.pause(),Zg(this,this.options)}initAnimation(){let{options:e}=this;qg(e);let{type:t=Bg,repeat:n=0,repeatDelay:r=0,repeatType:i,velocity:a=0}=e,{keyframes:o}=e,s=t||Bg;this.mixKeyframes=void 0,s!==Bg&&typeof o[0]!=`number`&&(this.mixKeyframes=sm(e_,e.mixer?.(o[0],o[1])||Yh(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=og(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=Yg(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!==Ng&&(f.value=Gg(o,this.options,l,this.speed)),c&&c(f.value),m&&this.finish(),f}at(e){return this.holdTime??t_((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!==Ng?Gg(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=em(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 dm(this.calculatedDuration)}get iterationDuration(){return this.duration+dm(this.options.delay??0)}get time(){return dm(this.currentTime)}set time(e){e=um(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 Ug(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(Fm.now()),this.playbackSpeed=e,t&&this.driver&&(this.time=dm(this.currentTime))}play(){if(this.isStopped)return;let{driver:e=rg,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(Fm.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)}},r_=new Set([`brightness`,`contrast`,`saturate`,`opacity`]);function i_(e){let[t,n]=e.slice(0,-1).split(`(`);if(t===`drop-shadow`)return e;let[r]=n.match(Km)||[];if(!r)return e;let i=n.replace(r,``),a=+!!r_.has(t);return r!==n&&(a*=100),t+`(`+a+i+`)`}var a_=/\b([a-z-]*)\(.*?\)/gu,o_={...kh,getAnimatableNone:e=>{let t=e.match(a_);return t?t.map(i_).join(` `):e}},s_={...kh,getAnimatableNone:e=>{let t=kh.parse(e);return kh.createTransformer(e)(t.map(e=>typeof e==`number`?0:typeof e==`object`?{...e,alpha:1}:e))}},c_={...Um,transform:Math.round},l_={rotate:ih,pathRotation:ih,rotateX:ih,rotateY:ih,rotateZ:ih,scale:Gm,scaleX:Gm,scaleY:Gm,scaleZ:Gm,skew:ih,skewX:ih,skewY:ih,distance:$,translateX:$,translateY:$,translateZ:$,x:$,y:$,z:$,perspective:$,transformPerspective:$,opacity:Wm,originX:ch,originY:ch,originZ:$},u_={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:$,...l_,zIndex:c_,fillOpacity:Wm,strokeOpacity:Wm,numOctaves:c_},d_={...u_,color:uh,backgroundColor:uh,outlineColor:uh,fill:uh,stroke:uh,borderColor:uh,borderTopColor:uh,borderRightColor:uh,borderBottomColor:uh,borderLeftColor:uh,filter:o_,WebkitFilter:o_,mask:s_,WebkitMask:s_},f_=e=>d_[e],p_=new Set([o_,s_]);function m_(e,t){let n=f_(e);return p_.has(n)||(n=kh),n.getAnimatableNone?n.getAnimatableNone(t):void 0}function h_(e){for(let t=1;t<e.length;t++)e[t]??(e[t]=e[t-1])}var g_=e=>e*180/Math.PI,__=e=>y_(g_(Math.atan2(e[1],e[0]))),v_={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:__,rotateZ:__,skewX:e=>g_(Math.atan(e[1])),skewY:e=>g_(Math.atan(e[2])),skew:e=>(Math.abs(e[1])+Math.abs(e[2]))/2},y_=e=>(e%=360,e<0&&(e+=360),e),b_=__,x_=e=>Math.hypot(e[0],e[1]),S_=e=>Math.hypot(e[4],e[5]),C_={x:12,y:13,z:14,translateX:12,translateY:13,translateZ:14,scaleX:x_,scaleY:S_,scaleZ:e=>Math.hypot(e[8],e[9],e[10]),scale:e=>(x_(e)+S_(e))/2,rotateX:e=>y_(g_(Math.atan2(e[6],e[5]))),rotateY:e=>y_(g_(Math.atan2(-e[2],e[0]))),rotateZ:b_,rotate:b_,skewX:e=>g_(Math.atan(e[4])),skewY:e=>g_(Math.atan(e[1])),skew:e=>(Math.abs(e[1])+Math.abs(e[4]))/2};function w_(e){return+!!e.includes(`scale`)}function T_(e,t){if(!e||e===`none`)return w_(t);let n=e.match(/^matrix(3d)?\(([-\d.e\s,]+)\)$/u);if(!n)return w_(t);let r=(n[1]?C_:v_)[t],i=n[2].split(`,`).map(e=>parseFloat(e));return typeof r==`function`?r(i):i[r]}var E_=(e,t)=>{let{transform:n=`none`}=getComputedStyle(e);return T_(n,t)},D_=[`transformPerspective`,`x`,`y`,`z`,`translateX`,`translateY`,`translateZ`,`scale`,`scaleX`,`scaleY`,`scaleZ`,`rotate`,`rotateX`,`rotateY`,`rotateZ`,`skew`,`skewX`,`skewY`],O_=new Set([...D_,`pathRotation`]),k_=e=>e===Um||e===$,A_=new Set([`x`,`y`,`z`]),j_=D_.filter(e=>!A_.has(e));function M_(e){let t=[];return j_.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 N_=new Set([`bottom`,`right`]);function P_(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 F_=({transform:e})=>T_(e,`x`),I_=({transform:e})=>T_(e,`y`),L_={width:({width:e,paddingLeft:t=`0`,paddingRight:n=`0`,boxSizing:r},i)=>P_(e,i,`x`,t,n,r),height:({height:e,paddingTop:t=`0`,paddingBottom:n=`0`,boxSizing:r},i)=>P_(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:F_,y:I_,translateX:F_,translateY:I_},R_=new Set,z_=!1,B_=!1,V_=!1;function H_(){if(B_){let e=[],t=new Set,n=new Set;R_.forEach(r=>{r.needsMeasurement&&(e.push(r),t.add(r.element),N_.has(r.name)&&n.add(r.element))});let r=new Map;n.forEach(e=>{let t=M_(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)})}B_=!1,z_=!1,R_.forEach(e=>e.complete(V_)),R_.clear()}function U_(){R_.forEach(e=>{e.readKeyframes(),e.needsMeasurement&&(B_=!0)})}function W_(){V_=!0,U_(),H_(),V_=!1}function G_(e,t,n){if(typeof e==`string`){if(nm(e)||im(e))return parseFloat(e);if(!kh.test(e)&&kh.test(n))return m_(t,n)}return e??void 0}var K_=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?(R_.add(this),z_||(z_=!0,eg.read(U_),eg.resolveKeyframes(H_))):(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=G_(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])}h_(e)}setFinalKeyframe(){}measureInitialState(){}renderEndStyles(){}measureEndState(){}complete(e=!1){this.state=`complete`,this.onComplete(this.unresolvedKeyframes,this.finalKeyframe,e),R_.delete(this)}cancel(){this.state===`scheduled`&&(R_.delete(this),this.state=`pending`)}resume(){this.state===`pending`&&this.scheduleResolve()}},q_=e=>e.startsWith(`--`);function J_(e,t,n){q_(t)?e.style.setProperty(t,n):e.style[t]=n}var Y_={};function X_(e,t){let n=am(e);return()=>Y_[t]??n()}var Z_=X_(()=>window.ScrollTimeline!==void 0,`scrollTimeline`),Q_=X_(()=>{try{document.createElement(`div`).animate({opacity:0},{easing:`linear(0, 1)`})}catch{return!1}return!0},`linearEasing`),$_=([e,t,n,r])=>`cubic-bezier(${e}, ${t}, ${n}, ${r})`,ev={linear:`linear`,ease:`ease`,easeIn:`ease-in`,easeOut:`ease-out`,easeInOut:`ease-in-out`,circIn:$_([0,.65,.55,1]),circOut:$_([.55,0,1,.45]),backIn:$_([.31,.01,.66,-.59]),backOut:$_([.33,1.53,.69,.99])};function tv(e,t){if(e)return typeof e==`function`?Q_()?ig(e,t):`ease-out`:Om(e)?$_(e):Array.isArray(e)?e.map(e=>tv(e,t)||ev.easeOut):ev[e]}function nv(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=tv(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 rv(e){return typeof e==`function`&&`applyToOptions`in e}function iv({type:e,...t}){return rv(e)&&Q_()?e.applyToOptions(t):(t.duration??=300,t.ease??=`easeOut`,t)}var av=class extends $g{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=iv(e);this.animation=nv(t,n,r,c,i),c.autoplay===!1&&this.animation.pause(),this.animation.onfinish=()=>{if(this.finishedTime=this.time,!i){let e=Gg(r,this.options,o,this.speed);this.updateMotionValue?.(e),J_(t,n,e),this.animation.cancel()}s?.(),this.notifyFinished()},Zg(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 dm(Number(e))}get iterationDuration(){let{delay:e=0}=this.options||{};return this.duration+dm(e)}get time(){return dm(Number(this.animation.currentTime)||0)}set time(e){let t=this.finishedTime!==null;this.manualStartTime=null,this.finishedTime=null,this.animation.currentTime=um(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&&Z_()?(this.animation.timeline=e,t?.(this.animation),om):n(this)}},ov={anticipate:bm,backInOut:ym,circInOut:Cm};function sv(e){return e in ov}function cv(e){typeof e.ease==`string`&&sv(e.ease)&&(e.ease=ov[e.ease])}var lv=class extends av{constructor(e){cv(e),qg(e),super(e),e.startTime!==void 0&&e.autoplay!==!1&&(this.startTime=e.startTime),this.options=e}elapsed(){return this.state===`running`?(Fm.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 n_({...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?em(0,10,a):0,s=this.sample(a);n&&r&&J_(n,r,s),t.setWithVelocity(this.sample(a-o*Math.sign(i)),s,o/Math.abs(i||1))}},uv=(e,t)=>t!==`zIndex`&&!!(typeof e==`number`||Array.isArray(e)||typeof e==`string`&&(kh.test(e)||e===`0`)&&!e.startsWith(`url(`));function dv(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 fv(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=uv(i,t),s=uv(a,t);return!o||!s?!1:dv(e)||(n===`spring`||rv(n))&&r}function pv(e){e.duration=0,e.type=`keyframes`}var mv=new Set([`opacity`,`clipPath`,`filter`,`transform`]),hv=/^(?:oklch|oklab|lab|lch|color|color-mix|light-dark)\(/;function gv(e){for(let t=0;t<e.length;t++)if(typeof e[t]==`string`&&hv.test(e[t]))return!0;return!1}var _v=({mixer:e,keyframes:t})=>e&&typeof t[0]!=`number`&&t.some((n,r)=>r&&e(t[r-1],n)),vv=new Set([`color`,`backgroundColor`,`outlineColor`,`fill`,`stroke`,`borderColor`,`borderTopColor`,`borderRightColor`,`borderBottomColor`,`borderLeftColor`]),yv=()=>!tm.useManualTiming&&Object.hasOwnProperty.call(Element.prototype,`animate`);function bv(e){let{motionValue:t,name:n,repeatDelay:r,repeatType:i,damping:a,type:o,keyframes:s}=e;if(!n||!(mv.has(n)||vv.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 yv()&&(mv.has(n)||vv.has(n)&&gv(s))&&(n!==`transform`||!u)&&!l&&!r&&i!==`mirror`&&a!==0&&o!==`inertia`&&!_v(e)}var xv=(e,t)=>t&&typeof e==`number`?t.transform(e):e,Sv={x:`translateX`,y:`translateY`,z:`translateZ`,transformPerspective:`perspective`},Cv=D_.length,wv={},Tv=(e,t,n=xv(t,l_[e]))=>(wv[e]||(wv[e]=(Sv[e]||e)+`(`))+n+`)`,Ev=(e,t)=>(typeof t==`number`?t:parseFloat(t))===+!!e.startsWith(`scale`);function Dv(e,t,n){let r=``;for(let i=0;i<Cv;i++){let a=D_[i],o=e[a];if(o===void 0)continue;let s=n&&(t[a]=xv(o,u_[a]));Ev(a,o)||(r+=Tv(a,o,s||void 0)+` `)}let i=e.pathRotation;return i&&(r+=Tv(`rotate`,i)),r=r.trim(),n?n(t,r):r||`none`}var Ov=new WeakMap,kv=200,Av=.001,jv=.1,Mv=.001,Nv=100,Pv=e=>/^(linear|ease(In|Out|InOut))$/.test(e),Fv=(e,t)=>Math.abs(e-t)<=Av,Iv=(e,t)=>e-t,Lv=(e,t,n)=>Lg(Array(n+1)).map(n=>Nh(e,t,n)),Rv=e=>e.motionValue.owner,zv=e=>Ov.get(e),Bv=({state:e})=>e===`idle`||e===`finished`,Vv=(e,t)=>e.latestValues?e.latestValues[t]:e.getValue(t)?.get(),Hv=({name:e,motionValue:t})=>e&&D_.includes(e)&&t?.owner?.current instanceof HTMLElement&&yv()&&Q_();function Uv(e){let t=Rv(e),{onUpdate:n,transformTemplate:r}=t.getProps();return!e.isHandoff&&!n&&!e.hasOnUpdate&&!r&&e.type!==`inertia`&&(Vv(t,`transform`)||`none`)===`none`&&!Vv(t,`pathRotation`)&&!t.projection?.isProjecting()&&!_v(e)}var Wv=class extends n_{constructor(e){let t=Rv(e).current,{driver:n=rg}=e,r,i=Uv(e);e.driver=e=>{let i=n(e);return{js:i,now:i.now,start:(e=!0)=>{let n=zv(t);!n||n.isJS?i.start(e):n.schedule(!1,!e)},stop:()=>{i.stop();let e=zv(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 zv(Rv(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(Fm.now()):void 0}tween(){let{keyframes:e,type:t,ease:n,times:r,repeat:i,delay:a=0}=this.options,o=Om(n)?$_(n):Pv(n)&&ev[n];if(o&&!i&&!r&&e.length===2&&t===Bg&&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||Bg)===Bg?u||Lg(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=Fm.now();this.options.motionValue.setWithVelocity(this.sampleAt(e-10,!0),this.sampleAt(e,!0),10)}play(){this.isStopped||((this.group||Gv(Rv(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(Fm.now())}get time(){return this.isAccelerated()?dm(em(0,this.totalDuration,this.at(Fm.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 Gv(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?D_:a){let a=r.get(s),c=t===void 0?Vv(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&&Ev(r,i)||(n+=Tv(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=Fm.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(kv,Math.max(2,Math.ceil((n-t)/10)));if(r.length*4>i)return;let a=Lv(t,n,i).concat(r).sort(Iv),o=e=>cm(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)*Av>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)=>!Fv(e,o&&s[t])))return}if(!s||s.every((e,t)=>Fv(e,o(a[t]))))return`linear`;let l=[],u=(e,t=c(e))=>l.push(t_(t)+` `+t_(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`)?Mv:jv))),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=Lv(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(Iv))e>c&&o(c,e,0),c=e;return i.sort(Iv)},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=>cm(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=D_.filter(t=>{if(r.has(t))return!0;let n=i[t]=Vv(e,t);return n!==void 0&&!Ev(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,zv(t)===A&&Ov.delete(t),A.isJS||v(),!0),k=()=>{let t=Fm.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]=Vv(e,n.name),o.has(n)||(c=!0))}),A.isFinishing=!1),l=!1,u||(n.forEach(e=>Bv(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<Nv)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,Mm.isProcessing?eg.render(k,!1,!0):queueMicrotask(k)))},release(e){Bv(e)&&n.delete(e),O()||A.schedule(!0)},check(){if(!A.isJS){for(let t in i)if(Vv(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 Ov.set(t,A),A}var Kv=class extends $g{constructor(e){super(),this.stop=()=>{this._animation&&(this._animation.stop(),this.stopTimeline?.()),this.keyframeResolver?.cancel()},this.createdAt=Fm.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||K_;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=Fm.now();let u=fv(e,i,a,o);u||((tm.instantAnimations||!s)&&l?.(Gg(e,n,t)),e[0]=e[e.length-1],pv(n),n.repeat=0);let{onComplete:d}=n;n.finalKeyframe=t,n.keyframes=e,n.onComplete=()=>{d?.(),this.notifyFinished()};let f=u&&!c&&bv(n),p=!f&&Hv(n);r&&(f||p||this.resolvedAt!==this.createdAt)&&(n.startTime??=Yg(this.createdAt,this.resolvedAt));let m;if(f){n.element=n.motionValue?.owner?.current;try{m=new lv(n)}catch{m=new n_(n)}}else m=p?new Wv(n):new n_(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(),W_()),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 qv(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 Jv=30,Yv=e=>!isNaN(parseFloat(e)),Xv={current:void 0},Zv=class{constructor(e,t={}){this.canTrackVelocity=null,this.events={},this.updateAndNotify=e=>{let t=Fm.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=Fm.now(),this.canTrackVelocity===null&&e!==void 0&&(this.canTrackVelocity=Yv(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 lm)).add(t)}onChangeSubscribe(e){let{events:t}=this;return!t.change&&!this.changeSubscriber?this.changeSubscriber=e:(t.change||(t.change=new lm,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(){eg.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=Fm.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(){Xv.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=Fm.now();if(!this.canTrackVelocity||this.prevFrameValue===void 0||e-this.updatedAt>Jv)return 0;let t=Math.min(this.updatedAt-this.prevUpdatedAt,Jv);return fm(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 Qv(e,t){return new Zv(e,t)}function $v(e,t){if(e?.inherit&&t){let{inherit:n,...r}=e;return{...t,...r}}return e}function ey(e,t){let n=e?.[t]??e?.default??e;return n===e?n:$v(n,e)}var ty={type:`spring`,stiffness:500,damping:25,restSpeed:10},ny=e=>({type:`spring`,stiffness:550,damping:e===0?2*Math.sqrt(550):30,restSpeed:10}),ry={type:`keyframes`,duration:.8},iy={type:`keyframes`,ease:[.25,.1,.35,1],duration:.3},ay=(e,{keyframes:t})=>t.length>2?ry:O_.has(e)?e.startsWith(`scale`)?ny(t[1]):ty:iy,oy=new Set([`when`,`delay`,`delayChildren`,`staggerChildren`,`staggerDirection`,`repeat`,`repeatType`,`repeatDelay`,`from`,`elapsed`,`out`,`mixer`]);function sy(e){for(let t in e)if(!oy.has(t))return!0;return!1}var cy=(e,t,n,r={},i,a)=>o=>{let s=ey(r,e)||{},c=s.delay||r.delay||0,{elapsed:l=0}=r;l-=um(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};sy(s)||Object.assign(u,ay(e,u)),u.duration&&=um(u.duration),u.repeatDelay&&=um(u.repeatDelay),u.from!==void 0&&(u.keyframes[0]=u.from);let d=!1;if((u.type===!1||u.duration===0&&!u.repeatDelay)&&(pv(u),u.delay===0&&(d=!0)),(tm.instantAnimations||tm.skipAnimations||i?.shouldSkipAnimations||s.skipAnimations)&&(d=!0,pv(u),u.delay=0),u.allowFlatten=!s.type&&!s.ease,d&&!a&&t.get()!==void 0){let e=Gg(u.keyframes,s);if(e!==void 0){eg.update(()=>{u.onUpdate(e),u.onComplete()});return}}return s.isSync?new n_(u):new Kv(u)},ly=/^var\(--(?:([\w-]+)|([\w-]+), ?([a-zA-Z\d ()%#.,-]+))\)/u;function uy(e){let t=ly.exec(e);if(!t)return[,];let[,n,r,i]=t;return[`--${n??r}`,i]}function dy(e,t,n=1){let[r,i]=uy(e);if(!r)return;let a=window.getComputedStyle(t).getPropertyValue(r);if(a){let e=a.trim();return nm(e)?parseFloat(e):e}return Bm(i)?dy(i,t,n+1):i}function fy(e){let t=[{},{}];return e?.values.forEach((e,n)=>{t[0][n]=e.get(),t[1][n]=e.getVelocity()}),t}function py(e,t,n,r){let i=t=>typeof t==`function`?t(n===void 0?e.custom:n,...fy(r)):t;return t=i(t),typeof t==`string`&&(t=e.variants&&e.variants[t]),i(t)}function my(e,t,n){return py(e.getProps(),t,n,e)}var hy=(e,t)=>t===`exit`?e.presenceContext?.custom:void 0,gy=new Set([`width`,`height`,`top`,`left`,`right`,`bottom`,...D_]),_y=e=>Array.isArray(e);function vy(e,t,n){e.hasValue(t)?e.getValue(t).set(n):e.addValue(t,Qv(n))}function yy(e){return _y(e)?e[e.length-1]||0:e}function by(e,t){let{transitionEnd:n={},transition:r={},...i}=my(e,t)||{};i={...i,...n};for(let t in i)vy(e,t,yy(i[t]))}var xy=e=>!!(e&&e.getVelocity);function Sy(e){return!!(xy(e)&&e.add)}function Cy(e,t){let n=e.getValue(`willChange`);if(Sy(n))return n.add(t);if(!n&&tm.WillChange){let n=new tm.WillChange(`auto`);e.addValue(`willChange`,n),n.add(t)}}var wy=`data-framer-appear-id`;function Ty(e){return e.props[wy]}var Ey=typeof window<`u`;function Dy({protectedKeys:e,needsAnimating:t},n){let r=n in e&&!t[n];return t[n]=!1,r}function Oy(e,t,{delay:n=0,transitionOverride:r,type:i}={}){let{transition:a,transitionEnd:o,...s}=t,c=e.getDefaultTransition();a=a?$v(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&&Dy(f,t))continue;let o={delay:n,...ey(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){eg.update(()=>r.set(i));continue}let p=!1;if(Ey&&window.MotionHandoffAnimation){let n=Ty(e);if(n){let e=window.MotionHandoffAnimation(n,t,eg);e!==null&&(o.startTime=e,p=!0)}}Cy(e,t);let m=l??e.shouldReduceMotion;r.start(cy(t,r,i,m&&gy.has(t)?{type:!1}:o,e,p));let h=r.animation;h&&d.push(h)}if(o){let t=()=>eg.update(()=>{o&&by(e,o)});d.length?Promise.all(d).then(t):t()}return d}function ky(e,t,n={}){let r=my(e,t,hy(e,n.type)),i=n.transitionOverride||(r?.transition??(e.getDefaultTransition()||{})),a=()=>Promise.all(r?Oy(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(ky(e,t,{...n,delay:r+(typeof o==`function`?0:o)+qv(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 Ay(e,t,n={}){return e.notify(`AnimationStart`,t),(Array.isArray(t)?Promise.all(t.map(t=>ky(e,t,n))):typeof t==`string`?ky(e,t,n):Promise.all(Oy(e,my(e,t,n.custom),n))).then(()=>{e.notify(`AnimationComplete`,t)})}var jy={test:e=>e===`auto`,parse:e=>e},My=e=>t=>t.test(e),Ny=[Um,$,ah,ih,sh,oh,jy],Py=e=>Ny.find(My(e));function Fy(e){return typeof e==`number`?e===0:e===null||e===`none`||e===`0`||im(e)}var Iy=new Set([`auto`,`none`,`0`]);function Ly(e,t,n){let r=0,i;for(;r<e.length&&!i;){let t=e[r];typeof t==`string`&&!Iy.has(t)&&xh(t)&&(i=e[r]),r++}if(i&&n)for(let r of t)e[r]!==i&&(e[r]=m_(n,i))}var Ry=class extends K_{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(Hm(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(),Bm(r))){let i=dy(r,t.current);i!==void 0&&(e[n]=i),n===e.length-1&&(this.finalKeyframe=r)}}if(this.resolveNoneKeyframes(),!gy.has(n)||e.length!==2)return;let[r,i]=e;if(typeof r==`number`&&typeof i==`number`)return;let a=Py(r),o=Py(i);if(Hm(r)!==Hm(i)&&L_[n])this.needsMeasurement=!0;else if(a!==o){if(k_(a)&&k_(o))for(let t=0;t<e.length;t++){let n=e[t];typeof n==`string`&&(e[t]=parseFloat(n))}else L_[n]&&(this.needsMeasurement=!0)}}resolveNoneKeyframes(){let{unresolvedKeyframes:e,name:t}=this,n=[];for(let t=0;t<e.length;t++)(e[t]===null||Fy(e[t]))&&n.push(t);n.length&&Ly(e,n,t)}measure(){let{element:e,name:t}=this;return L_[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()}},zy=[`borderTopLeftRadius`,`borderTopRightRadius`,`borderBottomRightRadius`,`borderBottomLeftRadius`];function By(e){return rm(e)&&`offsetHeight`in e&&!(`ownerSVGElement`in e)}function Vy(e){return rm(e)&&`ownerSVGElement`in e}var Hy={};function Uy(e){return Hy.current?.add(e),e}var Wy=e=>Hy.current?Hy.current.bind(e):e;function Gy(e,t,n){if(e==null)return[];if(e instanceof EventTarget)return[e];if(typeof e==`string`){let r=t?t.current:Hy.current?.root||document,i=n?.[e]??r.querySelectorAll(e);return i?Array.from(i):[]}return Array.from(e).filter(e=>e!=null)}function Ky(e){return e.replace(/([A-Z])/g,e=>`-${e.toLowerCase()}`)}function qy(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(O_.has(e))o=!0;else if(Rm(e))i[e]=n;else{let t=xv(n,u_[e]);e.startsWith(`origin`)?(s=!0,a[e]=t):r[e]=t}}if(t.transform||(o||n?r.transform=Dv(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 Jy={offset:`stroke-dashoffset`,array:`stroke-dasharray`},Yy={offset:`strokeDashoffset`,array:`strokeDasharray`};function Xy(e,t,n=1,r=0,i=!0){e.pathLength=1;let a=i?Jy:Yy;e[a.offset]=`${-r}`,e[a.array]=`${t} ${n}`}var Zy=[`transform`,`opacity`,`clipPath`,`filter`,`offsetDistance`,`offsetPath`,`offsetRotate`,`offsetAnchor`];function Qy(e,{attrX:t,attrY:n,attrScale:r,pathLength:i,pathSpacing:a=1,pathOffset:o=0,...s},c,l,u){if(qy(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 Zy)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&&Xy(d,i,a,o,!1)}function $y({top:e,left:t,right:n,bottom:r}){return{x:{min:t,max:n},y:{min:e,max:r}}}function eb({x:e,y:t}){return{top:t.min,right:e.max,bottom:t.max,left:e.min}}function tb(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 nb(e){return e===void 0||e===1}function rb({scale:e,scaleX:t,scaleY:n}){return!nb(e)||!nb(t)||!nb(n)}var ib=[`rotate`,`rotateX`,`rotateY`,`rotateZ`,`skewX`,`skewY`];function ab(e){return rb(e)||sb(e)||ob(e)}function ob(e){return e.z||e.rotate||e.rotateX||e.rotateY||e.rotateZ||e.skewX||e.skewY}function sb(e){return cb(e.x)||cb(e.y)}function cb(e){return e&&e!==`0%`}function lb(e,t,n){return n+t*(e-n)}function ub(e,t,n,r,i){return i!==void 0&&(e=lb(e,i,r)),lb(e,n,r)+t}function db(e,t=0,n=1,r,i){e.min=ub(e.min,t,n,r,i),e.max=ub(e.max,t,n,r,i)}function fb(e,{x:t,y:n}){db(e.x,t.translate,t.scale,t.originPoint),db(e.y,n.translate,n.scale,n.originPoint)}var pb=.999999999999,mb=1.0000000000001;function hb(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&&(gb(e.x,-a.scroll.offset.x),gb(e.y,-a.scroll.offset.y)),o&&(t.x*=o.x.scale,t.y*=o.y.scale,fb(e,o)),r&&(r.path?.[s]||r)!==a&&ab(a.latestValues)&&yb(e,a.latestValues,a.layout?.layoutBox));t.x<mb&&t.x>pb&&(t.x=1),t.y<mb&&t.y>pb&&(t.y=1)}function gb(e,t){e.min+=t,e.max+=t}function _b(e,t,n,r,i=.5){db(e,t,n,Nh(e.min,e.max,i),r)}function vb(e,t){return typeof e==`string`?parseFloat(e)/100*(t.max-t.min):e}function yb(e,t,n){let r=n??e;_b(e.x,vb(t.x,r.x),t.scaleX,t.scale,t.originX),_b(e.y,vb(t.y,r.y),t.scaleY,t.scale,t.originY)}function bb(e,t){return $y(tb(e.getBoundingClientRect(),t))}function xb(e,t,n){let r=bb(e,n),{scroll:i}=t;return i&&(gb(r.x,i.offset.x),gb(r.y,i.offset.y)),r}var Sb=()=>({x:document.documentElement.scrollLeft||document.body?.scrollLeft||0,y:document.documentElement.scrollTop||document.body?.scrollTop||0}),{schedule:Cb,cancel:wb}=$h(queueMicrotask,!1);function Tb(e,t,n){let r=xy(e)?e:Qv(e);return r.start(cy(``,r,t,n)),r.animation}var Eb={},Db={value:null,addProjectionMetrics:null,countProjection:void 0};function Ob(e,t){let n=Fm.now();e=Wy(e);let r=({timestamp:i})=>{let a=i-n;a>=t&&(tg(r),e(a-t))};return eg.setup(r,!0),Uy(()=>tg(r))}function kb(e){return e&&typeof e==`object`&&Object.prototype.hasOwnProperty.call(e,`current`)}function Ab(e){return Vy(e)&&e.tagName===`svg`}function jb(e){return xy(e)?e.get():e}var Mb=e=>typeof e==`number`?e:parseFloat(e),Nb=zy.length,Pb=e=>typeof e==`number`||$.test(e);function Fb(e,t,n,r,i,a){i?(e.opacity=Nh(0,n.opacity??1,Lb(r)),e.opacityExit=Nh(t.opacity??1,0,Rb(r))):a&&(e.opacity=Nh(t.opacity??1,n.opacity??1,r));for(let i=0;i<Nb;i++){let a=zy[i],o=Ib(t,a),s=Ib(n,a);(o!==void 0||s!==void 0)&&(o||=0,s||=0,o===0||s===0||Pb(o)===Pb(s)?(e[a]=Math.max(Nh(Mb(o),Mb(s),r),0),(ah.test(s)||ah.test(o))&&(e[a]+=`%`)):e[a]=s)}for(let i=0;i<ib.length;i++){let a=ib[i];(t[a]||n[a])&&(e[a]=Nh(t[a]||0,n[a]||0,r))}}function Ib(e,t){return e[t]===void 0?e.borderRadius:e[t]}var Lb=zb(0,.5,Sm),Rb=zb(.5,.95,om);function zb(e,t,n){return r=>r<e?0:r>t?1:n(cm(e,t,r))}function Bb(e,t){e.min=t.min,e.max=t.max}function Vb(e,t){Bb(e.x,t.x),Bb(e.y,t.y)}function Hb(e,t){e.translate=t.translate,e.scale=t.scale,e.originPoint=t.originPoint,e.origin=t.origin}var Ub=.9999,Wb=1.0001,Gb=-.01,Kb=.01;function qb(e){return e.max-e.min}function Jb(e,t,n){return Math.abs(e-t)<=n}function Yb(e,t,n,r=.5){e.origin=r,e.originPoint=Nh(t.min,t.max,e.origin),e.scale=qb(n)/qb(t),e.translate=Nh(n.min,n.max,e.origin)-e.originPoint,(e.scale>=Ub&&e.scale<=Wb||isNaN(e.scale))&&(e.scale=1),(e.translate>=Gb&&e.translate<=Kb||isNaN(e.translate))&&(e.translate=0)}function Xb(e,t,n,r){Yb(e.x,t.x,n.x,r?.originX),Yb(e.y,t.y,n.y,r?.originY)}function Zb(e,t,n,r=0){e.min=(r?Nh(n.min,n.max,r):n.min)+t.min,e.max=e.min+qb(t)}function Qb(e,t,n,r){Zb(e.x,t.x,n.x,r?.x),Zb(e.y,t.y,n.y,r?.y)}function $b(e,t,n,r=0){let i=r?Nh(n.min,n.max,r):n.min;e.min=t.min-i,e.max=e.min+qb(t)}function ex(e,t,n,r){$b(e.x,t.x,n.x,r?.x),$b(e.y,t.y,n.y,r?.y)}function tx(e,t,n,r,i){return e-=t,e=lb(e,1/n,r),i!==void 0&&(e=lb(e,1/i,r)),e}function nx(e,t=0,n=1,r=.5,i,a=e,o=e){if(ah.test(t)&&(t=parseFloat(t),t=Nh(o.min,o.max,t/100)-o.min),typeof t!=`number`)return;let s=Nh(a.min,a.max,r);e===a&&(s-=t),e.min=tx(e.min,t,n,s,i),e.max=tx(e.max,t,n,s,i)}function rx(e,t,[n,r,i],a,o){nx(e,t[n],t[r],t[i],t.scale,a,o)}var ix=[`x`,`scaleX`,`originX`],ax=[`y`,`scaleY`,`originY`];function ox(e,t,n,r){rx(e.x,t,ix,n?.x,r?.x),rx(e.y,t,ax,n?.y,r?.y)}var sx=e=>typeof navigator<`u`&&navigator.userAgent&&navigator.userAgent.toLowerCase().includes(e),cx=sx(`applewebkit/`)&&!sx(`chrome/`)?Math.round:om;function lx(e){e.min=cx(e.min),e.max=cx(e.max)}function ux(e){lx(e.x),lx(e.y)}var dx=()=>({translate:0,scale:1,origin:0,originPoint:0}),fx=()=>({x:dx(),y:dx()}),px=()=>({min:0,max:0}),mx=()=>({x:px(),y:px()});function hx(e){return e.translate===0&&e.scale===1}function gx(e){return hx(e.x)&&hx(e.y)}function _x(e,t){return e.min===t.min&&e.max===t.max}function vx(e,t){return _x(e.x,t.x)&&_x(e.y,t.y)}function yx(e,t){return Math.round(e.min)===Math.round(t.min)&&Math.round(e.max)===Math.round(t.max)}function bx(e,t){return yx(e.x,t.x)&&yx(e.y,t.y)}function xx(e){return qb(e.x)/qb(e.y)}function Sx(e,t){return e.translate===t.translate&&e.scale===t.scale&&e.originPoint===t.originPoint}var Cx=class{constructor(){this.members=[]}add(e){Zp(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||(Qp(this.members,n),n.unmount())}e.scheduleRender()}remove(e){if(Qp(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 wx(e,t){return t.max===t.min?0:e/(t.max-t.min)*100}var Tx={correct:(e,t)=>{if(!t.target)return e;if(typeof e==`string`){if($.test(e))e=parseFloat(e);else return e}return`${wx(e,t.target.x)}% ${wx(e,t.target.y)}%`}},Ex={borderRadius:Object.assign({},Tx,{applyTo:zy.slice()}),borderTopLeftRadius:Tx,borderTopRightRadius:Tx,borderBottomLeftRadius:Tx,borderBottomRightRadius:Tx,boxShadow:{correct:(e,{treeScale:t,projectionDelta:n})=>{let r=e,i=kh.parse(e);if(i.length>5)return r;let a=kh.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=Nh(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 Dx(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<ib.length;e++){let t=ib[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 Ox(e){return[e(`x`),e(`y`)]}var kx=(e,t)=>e.depth-t.depth,Ax=class{constructor(){this.children=[],this.isDirty=!1}add(e){Zp(this.children,e),this.isDirty=!0}remove(e){Qp(this.children,e),this.isDirty=!0}forEach(e){this.isDirty&&this.children.sort(kx),this.isDirty=!1,this.children.forEach(e)}},jx={hasAnimatedSinceResize:!0,hasEverUpdated:!1},Mx=[`z`,`skew`,`skewZ`],Nx=1e3,Px=0;function Fx(e,t,n,r){let{latestValues:i}=t;i[e]&&(n[e]=i[e],t.setStaticValue(e,0),r&&(r[e]=0))}var Ix=e=>e.instance&&Ov.get(e.instance)?.demote()&&e.resetSkewAndRotation();function Lx(e){if(e.hasCheckedOptimisedAppear=!0,e.root===e)return;let{visualElement:t}=e.options;if(!t)return;let n=Ty(t);if(window.MotionHasOptimisedAnimation(n,`transform`)){let{layout:t,layoutId:r}=e.options;window.MotionCancelOptimisedAnimation(n,`transform`,eg,!(t||r))}let{parent:r}=e;r&&!r.hasCheckedOptimisedAppear&&Lx(r)}function Rx(e){if(e)return e.options.allowProjection===!1?Rx(e.parent):e.projection}function zx({attachResizeListener:e,defaultParent:t,measureScroll:n,checkIsScrollRoot:r,resetTransform:i}){return Object.assign(Eb,{...Ex,...Eb}),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:Rx(e.parent));d.setOptions({layoutId:r,layout:i,alwaysMeasureLayout:!!a||o&&kb(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=Px++,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(Hx),this.nodes.forEach($x),this.nodes.forEach(eS),this.nodes.forEach(Ux),Db.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 Ax)}addEventListener(e,t){return this.eventHandlers.has(e)||this.eventHandlers.set(e,new lm),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=Vy(t)&&!Ab(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;eg.read(()=>{r=window.innerWidth}),e(t,()=>{let e=window.innerWidth;e!==r&&(r=e,this.root.updateBlockedByResize=!0,n?.(),n=Ob(i,250),jx.hasAnimatedSinceResize&&(jx.hasAnimatedSinceResize=!1,this.nodes.forEach(Qx)))})}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()||oS,{onLayoutAnimationStart:o,onLayoutAnimationComplete:s}=n.getProps(),c=!this.targetLayout||!bx(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={...ey(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||Qx(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,tg(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(tS),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&&Lx(this),!this.root.isUpdating&&this.root.startUpdate(),this.isLayoutDirty)return;Ix(this),this.isLayoutDirty=!0;for(let e=0;e<this.path.length;e++){let t=this.path[e];t.shouldResetTransform=!0,Ix(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(Kx),this.nodes.forEach(Gx);return}if(this.animationId<=this.animationCommitId){this.nodes.forEach(qx);return}this.animationCommitId=this.animationId,this.isUpdating?(this.isUpdating=!1,this.nodes.forEach(Yx),this.nodes.forEach(Xx),this.nodes.forEach(Zx),this.nodes.forEach(Bx),this.nodes.forEach(Vx)):this.nodes.forEach(qx),this.clearAllSnapshots();let e=Fm.now();Mm.delta=em(0,1e3/60,e-Mm.timestamp),Mm.timestamp=e,Mm.isProcessing=!0,ng.update.process(Mm),ng.preRender.process(Mm),ng.render.process(Mm),Mm.isProcessing=!1}didUpdate(){this.updateScheduled||(this.updateScheduled=!0,Cb.read(this.scheduleUpdate))}clearAllSnapshots(){this.nodes.forEach(Wx),this.sharedNodes.forEach((e,t)=>e.members.length?e.removeLeadSnapshot():this.sharedNodes.delete(t))}scheduleUpdateProjection(){this.projectionUpdateScheduled||(this.projectionUpdateScheduled=!0,eg.preRender(this.updateProjection,!1,!0))}scheduleCheckAfterUnmount(){eg.postRender(()=>{this.isLayoutDirty?this.root.didUpdate():this.root.checkUpdateFailed()})}updateSnapshot(){!this.snapshot&&this.instance&&(this.snapshot=this.measure(),this.snapshot&&!qb(this.snapshot.measuredBox.x)&&!qb(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||=mx(),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&&Ix(this);let t=this.projectionDelta&&!gx(this.projectionDelta),n=this.getTransformTemplate(),r=n?n(this.latestValues,``):void 0,a=r!==this.prevTransformTemplateValue;e&&this.instance&&(t||ab(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)),ux(n),{animationId:this.root.animationId,measuredBox:t,layoutBox:n,latestValues:{},source:this.id}}measurePageBox(){let{visualElement:e}=this.options;if(!e)return mx();let t=e.measureViewportBox();if(!(this.scroll?.wasRoot||this.path.some(lS))){let{scroll:e}=this.root;e&&(gb(t.x,e.offset.x),gb(t.y,e.offset.y))}return t}removeElementScroll(e){let t=mx();if(Vb(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&&Vb(t,e),gb(t.x,i.offset.x),gb(t.y,i.offset.y))}return t}applyTransform(e,t=!1,n,r,i=0){let a=n||mx();Vb(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&&(gb(a.x,-n.scroll.offset.x),gb(a.y,-n.scroll.offset.y)),ab(n.latestValues)&&yb(a,n.latestValues,n.layout?.layoutBox)}return!r&&ab(this.latestValues)&&yb(a,this.latestValues,this.layout?.layoutBox),a}removeTransform(e){let t=mx();Vb(t,e);for(let e=0;e<this.path.length;e++){let n=this.path[e];if(!ab(n.latestValues))continue;let r;n.instance&&(rb(n.latestValues)&&n.updateSnapshot(),r=mx(),Vb(r,n.measurePageBox())),ox(t,n.latestValues,n.snapshot?.layoutBox,r)}return ab(this.latestValues)&&ox(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!==Mm.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=Mm.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=mx(),this.targetWithTransforms=mx()),this.relativeTarget&&this.relativeTargetOrigin&&this.relativeParent&&this.relativeParent.target?(this.forceRelativeParentToResolveTarget(),Qb(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):Vb(this.target,this.layout.layoutBox),fb(this.target,this.targetDelta)):Vb(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),Db.countProjection?.(1))}getClosestProjectingParent(){if(!(!this.parent||rb(this.parent.latestValues)||sb(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=mx(),this.relativeTargetOrigin=mx(),ex(this.relativeTargetOrigin,t,n,this.options.layoutAnchor||void 0),Vb(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===Mm.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;Vb(this.layoutCorrected,this.layout.layoutBox);let a=this.treeScale.x,o=this.treeScale.y;hb(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=mx());let{target:s}=e;s?(!this.projectionDelta||!this.prevProjectionDelta?this.createProjectionDeltas():(Hb(this.prevProjectionDelta.x,this.projectionDelta.x),Hb(this.prevProjectionDelta.y,this.projectionDelta.y)),Xb(this.projectionDelta,this.layoutCorrected,s,this.latestValues),this.treeScale.x===a&&this.treeScale.y===o&&Sx(this.projectionDelta.x,this.prevProjectionDelta.x)&&Sx(this.projectionDelta.y,this.prevProjectionDelta.y)||(this.hasProjected=!0,this.scheduleRender(),this.notifyListeners(`projectionUpdate`,s)),Db.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=fx(),this.projectionDelta=fx(),this.projectionDeltaWithTransform=fx()}setAnimationOrigin(e,t=!1,n){let r=this.snapshot,i=r?r.latestValues:{},a={...this.latestValues},o=fx();this.relativeParent&&this.relativeParent.options.layoutRoot||(this.relativeTarget=this.relativeTargetOrigin=void 0),this.attemptToResolveRelativeTarget=!t;let s=mx(),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(aS));this.animationProgress=0;let f,p=n?.interpolateProjection(e);this.mixTargetDelta=t=>{let n=t/1e3,r=p?.(n);nS(o.x,e.x,n),nS(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&&(ex(s,this.layout.layoutBox,this.relativeParent.layout.layoutBox,this.options.layoutAnchor||void 0),iS(this.relativeTarget,this.relativeTargetOrigin,s,n),f&&vx(this.relativeTarget,f)&&(this.isProjectionDirty=!1),f||=mx(),Vb(f,this.relativeTarget)),c&&(this.animationValues=a,Fb(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&&=(tg(this.pendingAnimation),void 0),this.pendingAnimation=eg.update(()=>{jx.hasAnimatedSinceResize=!0,this.motionValue||=Qv(0),this.motionValue.jump(0,!1),this.currentAnimation=Tb(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()}}),Qg(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?.(Nx),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&&cS(this.options.animationType,this.layout.layoutBox,n.layoutBox)){let{layoutBox:e}=this.layout,t=i;i=this.target||mx(),sS(i.x,t.x,e.x),sS(i.y,t.y,e.y)}Vb(t,i),yb(t,r),Xb(this.projectionDeltaWithTransform,this.layoutCorrected,t,r)}}registerSharedNode(e,t){this.sharedNodes.has(e)||this.sharedNodes.set(e,new Cx),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(!ob(t))return;let n={};for(let t=0;t<Mx.length;t++)Fx(Mx[t],e,n,this.animationValues);for(let t=0;t<ib.length;t++)Fx(ib[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=jb(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=jb(t?.pointerEvents)||``),this.hasProjected&&!ab(this.latestValues)&&(e.transform=r?r({},``):`none`,this.hasProjected=!1);return}e.visibility=``;let i=n.animationValues||n.latestValues;this.applyTransformsToTarget();let a=Dx(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 Eb){if(i[t]===void 0)continue;let{correct:r,applyTo:o,isCSSVariable:s}=Eb[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?jb(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(Gx),this.root.sharedNodes.clear()}}}function Bx(e){e.updateLayout(),Jx(e)}function Vx(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`)Ox(e=>{let t=qb(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`;Bb(r[e],a[e])}else cS(i,t.layoutBox,n)&&Ox(t=>{let n=qb(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=fx();Xb(c,n,t.layoutBox);let l=fx();Xb(l,a?e.applyTransform(r,!0):n,s);let u=!gx(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=mx();ex(c,a?e.resumeFrom.applyTransform(t.layoutBox,!0,void 0,!0,f.depth+1):t.layoutBox,r.layoutBox,s);let l=mx();ex(l,n,i.layoutBox,s),a&&o(c,l),bx(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 Hx(e){Db.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 Ux(e){e.isProjectionDirty=e.isSharedProjectionDirty=e.isTransformDirty=!1}function Wx(e){e.clearSnapshot()}function Gx(e){e.clearMeasurements()}function Kx(e){e.isLayoutDirty=!0,e.updateLayout()}function qx(e){e.isLayoutDirty=!1}function Jx(e){let{snapshot:t,dragAncestor:n}=e,r=n?.isAnimationBlocked&&n.layout;if(!t||!r||e.resumeFrom||e.isAnimationBlocked)return;let i=n.dragSnapshot;Ox(e=>gb(t.layoutBox[e],r.layoutBox[e].min-i.layoutBox[e].min))}function Yx(e){e.isAnimationBlocked&&e.layout&&!e.isLayoutDirty&&(e.snapshot=e.dragSnapshot||e.layout,e.isLayoutDirty=!0)}function Xx(e){e.relativeTarget&&e.relativeParent?.isLayoutDirty&&(e.currentAnimation?e.isLayoutDirty=!0:(e.targetDelta=void 0,e.removeRelativeTarget()))}function Zx(e){let{visualElement:t}=e.options;t?.getProps().onBeforeLayoutMeasure&&t.notify(`BeforeLayoutMeasure`),e.resetTransform()}function Qx(e){e.finishAnimation(),e.targetDelta=e.relativeTarget=e.target=void 0,e.isProjectionDirty=!0}function $x(e){e.resolveTargetDelta()}function eS(e){e.calcProjection()}function tS(e){e.resetSkewAndRotation()}function nS(e,t,n){e.translate=Nh(t.translate,0,n),e.scale=Nh(t.scale,1,n),e.origin=t.origin,e.originPoint=t.originPoint}function rS(e,t,n,r){e.min=Nh(t.min,n.min,r),e.max=Nh(t.max,n.max,r)}function iS(e,t,n,r){rS(e.x,t.x,n.x,r),rS(e.y,t.y,n.y,r)}function aS(e){return e.animationValues?.opacityExit!==void 0}var oS={duration:.45,ease:[.4,0,.1,1]};function sS(e,t,n){e.max=qb(n)+(e.min=t.min)}function cS(e,t,n){return e===`position`||e===`preserve-aspect`&&!Jb(xx(t),xx(n),.2)}function lS(e){return e!==e.root&&e.scroll?.wasRoot}function uS(e,t,n,r={passive:!0}){return e.addEventListener(t,n,r),()=>e.removeEventListener(t,n,r)}var dS=zx({attachResizeListener:(e,t)=>uS(e,`resize`,t),measureScroll:Sb,checkIsScrollRoot:()=>!0}),fS={current:void 0},pS=zx({measureScroll:e=>({x:e.scrollLeft,y:e.scrollTop}),defaultParent:()=>{if(!fS.current){let e=new dS({});e.mount(window),e.setOptions({layoutScroll:!0}),fS.current=e}return fS.current},resetTransform:(e,t)=>{e.style.transform=t===void 0?`none`:t},checkIsScrollRoot:e=>window.getComputedStyle(e).position===`fixed`}),mS=new WeakMap;function hS(e){return typeof e==`object`&&!!e&&typeof e.start==`function`}function gS(e){return typeof e==`string`||Array.isArray(e)}var _S=[`animate`,`whileInView`,`whileFocus`,`whileHover`,`whileTap`,`whileDrag`,`exit`],vS=[`initial`].concat(_S);function yS(e){if(hS(e.animate))return!0;for(let t=0;t<vS.length;t++)if(gS(e[vS[t]]))return!0;return!1}function bS(e){return!!(yS(e)||e.variants)}function xS(e,t,n){for(let r in t){let i=t[r],a=n[r];if(xy(i))e.addValue(r,i);else if(xy(a))e.addValue(r,Qv(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,Qv(t===void 0?i:t,{owner:e}))}}}for(let r in n)t[r]===void 0&&e.removeValue(r);return t}var SS={current:null},CS={current:!1},wS=typeof window<`u`;function TS(){if(CS.current=!0,wS){if(window.matchMedia){let e=window.matchMedia(`(prefers-reduced-motion)`),t=()=>SS.current=e.matches;e.addEventListener(`change`,t),t()}else SS.current=!1}}var ES=[`AnimationStart`,`AnimationComplete`,`Update`,`BeforeLayoutMeasure`,`LayoutMeasure`,`LayoutAnimationStart`,`LayoutAnimationComplete`],DS={};function OS(e){DS=e}function kS(){return DS}var AS=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=K_,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=Fm.now();this.renderScheduledAt<e&&(this.renderScheduledAt=e,eg.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=yS(t),this.isVariantNode=bS(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&&xy(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,mS.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:(CS.current||TS(),this.shouldReduceMotion=SS.current),this.shouldSkipAnimations=this.skipAnimationsConfig??!1,this.parent?.addChild(this),this.update(this.props,this.presenceContext),this.hasBeenMounted=!0}unmount(){this.projection?.unmount(),tg(this.notifyUpdate),tg(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&&mv.has(e)&&this.current instanceof HTMLElement){let{factory:n,keyframes:r,times:i,ease:a,duration:o}=t.accelerate,s=new av({element:this.current,name:e,keyframes:r,times:i,ease:a,duration:um(o)}),c=n(s);this.valueSubscriptions.set(e,()=>{c(),s.cancel()});return}let n=O_.has(e);n&&this.onBindTransform&&this.onBindTransform();let r=t.on(`change`,t=>{this.latestValues[e]=t,this.props.onUpdate&&eg.preRender(this.notifyUpdate),n&&(this.projection&&(this.projection.isTransformDirty=!0),Ov.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 DS){let t=DS[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):mx()}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)&&Ov.get(this.current)?.demote(),this.prevProps=this.props,this.props=e,this.prevPresenceContext=this.presenceContext,this.presenceContext=t;for(let t=0;t<ES.length;t++){let n=ES[t];this.propEventSubscriptions[n]?.(),delete this.propEventSubscriptions[n];let r=e[`on`+n];r&&(this.propEventSubscriptions[n]=this.on(n,r))}this.prevMotionValues=xS(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=Qv(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`&&(nm(n)||im(n))?n=parseFloat(n):typeof n!=`number`&&!kh.test(n)&&kh.test(t)&&(n=m_(e,t)),this.setBaseTarget(e,xy(n)?n.get():n)),xy(n)?n.get():n}setBaseTarget(e,t){this.baseTarget[e]=t}on(e,t){return(this.events[e]||(this.events[e]=new lm)).add(t)}notify(e,...t){this.events[e]?.notify(...t)}scheduleRenderMicrotask(){Cb.render(this.render)}},jS=class extends AS{constructor(){super(...arguments),this.KeyframeResolver=Ry}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;xy(e)&&(this.childSubscription=e.on(`change`,e=>{this.current&&(this.current.textContent=`${e}`)}))}};function MS(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 NS(e,{layout:t,layoutId:n}){return O_.has(e)||e.startsWith(`origin`)||(t||n!==void 0)&&(!!Eb[e]||e===`opacity`)}function PS(e,t,n){let r=e.style,i=t?.style,a={};if(!r)return a;for(let t in r)(xy(r[t])||i&&xy(i[t])||NS(t,e)||n?.getValue(t)?.liveStyle!==void 0)&&(a[t]=r[t]);return a}function FS(e){return window.getComputedStyle(e)}var IS=class extends jS{constructor(){super(...arguments),this.type=`html`,this.renderInstance=MS}mount(e){super.mount(e)}readValueFromInstance(e,t){if(O_.has(t))return this.projection?.isProjecting?w_(t):E_(e,t);{let n=FS(e),r=(Rm(t)?n.getPropertyValue(t):n[t])||0;return typeof r==`string`?r.trim():r}}measureInstanceViewportBox(e,{transformPagePoint:t}){return bb(e,t)}build(e,t,n){qy(e,t,n.transformTemplate)}scrapeMotionValuesFromProps(e,t,n){return PS(e,t,n)}},LS=e=>e.pointerType===`mouse`?typeof e.button!=`number`||e.button<=0:e.isPrimary!==!1;function RS(e){return{point:{x:e.pageX,y:e.pageY}}}var zS=e=>t=>LS(t)&&e(t,RS(t));function BS(e,t,n,r){return uS(e,t,zS(n),r)}var VS=new WeakMap,HS,US=(e,t,n)=>(r,i)=>i&&i[0]?i[0][e+`Size`]:Vy(r)&&`getBBox`in r?r.getBBox()[t]:r[n],WS=US(`inline`,`width`,`offsetWidth`),GS=US(`block`,`height`,`offsetHeight`);function KS({target:e,borderBoxSize:t}){VS.get(e)?.forEach(n=>{n(e,{get width(){return WS(e,t)},get height(){return GS(e,t)}})})}function qS(e){e.forEach(KS)}function JS(){typeof ResizeObserver<`u`&&(HS=new ResizeObserver(qS))}function YS(e,t){HS||JS();let n=Gy(e);return n.forEach(e=>{let n=VS.get(e);n||(n=new Set,VS.set(e,n)),n.add(t),HS?.observe(e)}),()=>{n.forEach(e=>{let n=VS.get(e);n?.delete(t),n?.size||HS?.unobserve(e)})}}var XS=new Set,ZS;function QS(){ZS=()=>{let e={get width(){return window.innerWidth},get height(){return window.innerHeight}};XS.forEach(t=>t(e))},window.addEventListener(`resize`,ZS)}function $S(e){return XS.add(e),ZS||QS(),()=>{XS.delete(e),!XS.size&&typeof ZS==`function`&&(window.removeEventListener(`resize`,ZS),ZS=void 0)}}function eC(e,t){return Uy(typeof e==`function`?$S(e):YS(e,t))}var tC=(e,t)=>Math.abs(e-t);function nC(e,t){let n=tC(e.x,t.x),r=tC(e.y,t.y);return Math.sqrt(n**2+r**2)}var rC=new Set([`auto`,`scroll`]),iC=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=oC(this.lastRawMoveEventInfo,this.transformPagePoint));let e=cC(this.lastMoveEventInfo,this.history),t=this.startEvent!==null,n=nC(e.offset,{x:0,y:0})>=this.distanceThreshold;if(!t&&!n)return;let{point:r}=e;this.history.push({...r,timestamp:Fm.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=oC(t,this.transformPagePoint),this.hasPendingMove=!0,eg.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=cC(e.type===`pointercancel`?this.lastMoveEventInfo:oC(t,this.transformPagePoint),this.history);this.startEvent&&n?.(e,a),r?.(e,a)},!LS(e))return;this.dragSnapToOrigin=i,this.handlers=t,this.transformPagePoint=n,this.distanceThreshold=a,this.contextWindow=r||window;let s=oC(RS(e),this.transformPagePoint),{point:c}=s;this.history=[{...c,timestamp:Fm.now()}];let{onSessionStart:l}=t;l&&l(e,cC(s,this.history));let u={passive:!0,capture:!0};this.removeListeners=sm(BS(this.contextWindow,`pointermove`,this.handlePointerMove,u),BS(this.contextWindow,`pointerup`,this.handlePointerUp,u),BS(this.contextWindow,`pointercancel`,this.handlePointerUp,u)),o&&this.startScrollTracking(o)}startScrollTracking(e){let t=e.parentElement;for(;t;){let e=getComputedStyle(t);(rC.has(e.overflowX)||rC.has(e.overflowY))&&this.scrollPositions.set(t,aC(t)),t=t.parentElement}this.scrollPositions.set(window,aC(window)),this.removeScrollListeners=sm(uS(window,`scroll`,this.onElementScroll,{capture:!0}),uS(window,`scroll`,this.onWindowScroll,{}))}handleScroll(e){let t=this.scrollPositions.get(e);if(!t)return;let n=e===window,r=aC(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),eg.update(this.updatePoint,!0))}updateHandlers(e){this.handlers=e}end(){this.removeListeners?.(),this.removeScrollListeners?.(),this.scrollPositions.clear(),tg(this.updatePoint)}},aC=e=>e===window?{x:window.scrollX,y:window.scrollY}:{x:e.scrollLeft,y:e.scrollTop};function oC(e,t){return t?{point:t(e.point)}:e}function sC(e,t){return{x:e.x-t.x,y:e.y-t.y}}function cC({point:e},t){return{point:e,delta:sC(e,uC(t)),offset:sC(e,lC(t)),velocity:dC(t,.1)}}function lC(e){return e[0]}function uC(e){return e[e.length-1]}function dC(e,t){if(e.length<2)return{x:0,y:0};let n=e.length-1,r=null,i=uC(e);for(;n>=0&&(r=e[n],!(i.timestamp-r.timestamp>um(t)));)n--;if(!r)return{x:0,y:0};r===e[0]&&e.length>2&&i.timestamp-r.timestamp>um(t)*2&&(r=e[1]);let a=dm(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 fC=new Set([`BUTTON`,`INPUT`,`SELECT`,`TEXTAREA`,`A`]);function pC(e){return fC.has(e.tagName)||e.isContentEditable===!0}var mC=new Set([`INPUT`,`SELECT`,`TEXTAREA`]);function hC(e){return mC.has(e.tagName)||e.isContentEditable===!0}var gC={x:!1,y:!1};function _C(){return gC.x||gC.y}function vC(e){return e===`x`||e===`y`?gC[e]?null:(gC[e]=!0,()=>{gC[e]=!1}):gC.x||gC.y?null:(gC.x=gC.y=!0,()=>{gC.x=gC.y=!1})}function yC(e,{min:t,max:n},r){return t!==void 0&&e<t?e=r?Nh(t,e,r.min):Math.max(e,t):n!==void 0&&e>n&&(e=r?Nh(n,e,r.max):Math.min(e,n)),e}function bC(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 xC(e,{top:t,left:n,bottom:r,right:i}){return{x:bC(e.x,n,i),y:bC(e.y,t,r)}}function SC(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 CC(e,t){return{x:SC(e.x,t.x),y:SC(e.y,t.y)}}function wC(e,t){let n=.5,r=qb(e),i=qb(t);return i>r?n=cm(t.min,t.max-r,e.min):r>i&&(n=cm(e.min,e.max-i,t.min)),em(0,1,n)}function TC(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 EC=.35;function DC(e=EC){return e===!1?e=0:e===!0&&(e=EC),{x:OC(e,`left`,`right`),y:OC(e,`top`,`bottom`)}}function OC(e,t,n){return{min:kC(e,t),max:kC(e,n)}}function kC(e,t){return typeof e==`number`?e:e[t]||0}function AC(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 jC=new WeakMap,MC=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=mx(),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=vC(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),Ox(e=>{let t=this.getAxisMotionValue(e).get()||0;if(Bm(t)&&(t=dy(t,this.visualElement.current)||0),$.test(t))t=parseFloat(t);else if(ah.test(t)){let n=a?.layout?.layoutBox[e];n&&(t=qb(n)*(parseFloat(t)/100))}this.originPoint[e]=t}),i&&eg.update(()=>i(e,t),!1,!0),Cy(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=RC(o),this.currentDirection===null)return;i&&i(this.currentDirection)}this.updateAxis(`x`,o),this.updateAxis(`y`,o),this.visualElement.render(),a&&eg.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 iC(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&&eg.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||!LC(e,n,this.currentDirection))return;let r=this.getAxisMotionValue(e),i=this.originPoint[e]+t[e],a=this.constraints&&this.constraints[e];a&&(i=yC(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;NC(e)?this.constraints&&this.scroll===AC(n)||(this.constraints=this.resolveRefConstraints()):this.constraints=e&&r?xC(r.layoutBox,e):!1,this.elastic=DC(t),i!==this.constraints&&!NC(e)&&r&&this.constraints&&!this.hasMutatedConstraints&&Ox(e=>{this.constraints!==!1&&this.getAxisMotionValue(e)&&(this.constraints[e]=TC(r.layoutBox[e],this.constraints[e]))})}resolveRefConstraints(){let{dragConstraints:e,onMeasureDragConstraints:t}=this.getProps();if(!NC(e))return!1;let n=PC(e),{projection:r}=this.visualElement;if(!r||!r.layout)return!1;this.scroll=AC(r);let i=xb(n,r.root,this.visualElement.getTransformPagePoint()),a=CC(r.layout.layoutBox,r.removeElementScroll(i));if(t){let e=t(eb(a));this.hasMutatedConstraints=!!e,e&&(a=$y(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=Ox(s=>{if(!LC(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 Cy(this.visualElement,e),n.start(cy(e,n,0,t,this.visualElement,!1))}stopAnimation(){Ox(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();Ox(e=>{if(!LC(e,n,this.currentDirection))return;let t=this.getAxisMotionValue(e),{min:r,max:o}=a[e];t.set((t.get()||0)+i[e]-Nh(r,o,.5))})}scalePositionWithinConstraints(){if(!this.visualElement.current)return;let{drag:e,dragConstraints:t}=this.getProps(),{projection:n}=this.visualElement;if(!NC(t)||!n||!this.constraints)return;this.stopAnimation();let r=this.constraints,i={x:0,y:0};Ox(e=>{let t=this.getAxisMotionValue(e).get();i[e]=wC({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(),Ox(t=>{let n=this.getAxisMotionValue(t);if(!LC(t,e,null)||!n.get())return;let{min:r,max:a}=this.constraints[t];n.set(Nh(r,a,i[t]))}),this.visualElement.render()}addListeners(){if(!this.visualElement.current)return;jC.set(this.visualElement,this);let e=this.visualElement.current,t=BS(e,`pointerdown`,t=>{let{drag:n,dragListener:r=!0}=this.getProps(),i=t.target,a=i!==e&&hC(i);n&&r&&!a&&this.start(t)}),n,r=()=>{let{dragConstraints:t}=this.getProps(),r=NC(t)&&PC(t);r&&(this.constraints=this.resolveRefConstraints(),n||=IC(e,r,()=>this.scalePositionWithinConstraints()))},{projection:i}=this.visualElement,a=i.addEventListener(`measure`,r);i.layout||(i.root?.updateScroll(),i.updateLayout()),eg.read(r);let o=uS(window,`resize`,()=>this.scalePositionWithinConstraints()),s=i.addEventListener(`didUpdate`,(({delta:e,hasLayoutChanged:t})=>{this.isDragging&&t&&(Ox(t=>{if(!LC(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=EC,dragMomentum:n=!0}=e;return{...e,dragElastic:t,dragMomentum:n}}};function NC(e){return!!e&&typeof e==`object`&&(`current`in e||`nodeType`in e)}var PC=e=>`current`in e?e.current:e;function FC(e){let t=!0;return()=>{t?t=!1:e()}}function IC(e,t,n){let r=eC(e,FC(n)),i=eC(t,FC(n));return()=>{r(),i()}}function LC(e,t,n){return(t===!0||t===e)&&(n===null||n===e)}function RC(e,t=10){let n=null;return Math.abs(e.y)>t?n=`y`:Math.abs(e.x)>t&&(n=`x`),n}function zC(e,t){let n=Gy(e),r=new AbortController;return[n,{passive:!0,...t,signal:r.signal},Uy(()=>r.abort())]}function BC(e){return!(e.pointerType===`touch`||_C())}function VC(e,t,n={}){t=Wy(t);let[r,i,a]=zC(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(!BC(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 HC=(e,t)=>t?e===t||HC(e,t.parentElement):!1,UC=new WeakSet;function WC(e){return t=>{t.key===`Enter`&&e(t)}}function GC(e,t){e.dispatchEvent(new PointerEvent(`pointer`+t,{isPrimary:!0,bubbles:!0}))}var KC=(e,t)=>{let n=!1,r=WC(()=>{UC.has(e)||(n=!0,GC(e,`down`))}),i=WC(()=>{n&&(n=!1,GC(e,`up`))});e.addEventListener(`keydown`,r,t),e.addEventListener(`keyup`,i,t),e.addEventListener(`blur`,()=>{e.removeEventListener(`keydown`,r),e.removeEventListener(`keyup`,i),n&&GC(e,`cancel`)},{...t,once:!0})};function qC(e){return LS(e)&&!_C()}var JC=new WeakSet;function YC(e,t,n={}){t=Wy(t);let[r,i,a]=zC(e,n),o=e=>{let r=e.currentTarget;if(!qC(e)||JC.has(e))return;UC.add(r),n.stopPropagation&&JC.add(e);let a=t(r,e),o={...i,capture:!0},s=(e,t)=>{window.removeEventListener(`pointerup`,c,o),window.removeEventListener(`pointercancel`,l,o),UC.has(r)&&UC.delete(r),qC(e)&&typeof a==`function`&&a(e,{success:t})},c=e=>{s(e,r===window||r===document||n.useGlobalTarget||HC(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),By(e)&&(e.addEventListener(`focus`,()=>KC(e,i),i),!pC(e)&&!e.hasAttribute(`tabindex`)&&(e.tabIndex=0))}),a}function XC(...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=Fg(i,a,o);return t?s(r):s}var ZC=class{constructor(e){this.isMounted=!1,this.node=e}update(){}},QC=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`]),$C=e=>typeof e==`string`&&e.toLowerCase()===`svg`;function ew(e,t,n,r){MS(e,t,void 0,r);for(let n in t.attrs)e.setAttribute(QC.has(n)?n:Ky(n),t.attrs[n])}function tw(e,t,n){let r=PS(e,t,n);for(let n in e)if(n!==`children`&&(xy(e[n])||xy(t[n]))){let t=D_.indexOf(n)===-1?n:`attr`+n.charAt(0).toUpperCase()+n.substring(1);r[t]=e[n]}return r}var nw=class extends jS{constructor(){super(...arguments),this.type=`svg`,this.isSVGTag=!1,this.measureInstanceViewportBox=mx}getBaseTargetFromProps(e,t){return O_.has(t)?super.getBaseTargetFromProps(e,t)??w_(t):e[t]}getDefaultValue(e){return O_.has(e)?this.latestValues[e]??w_(e):void 0}readValueFromInstance(e,t){if(O_.has(t)){let e=f_(t);return e&&e.default||0}if(Zy.includes(t)){let n=getComputedStyle(e)[t];if(typeof n==`string`&&n)return n.trim()}return t=QC.has(t)?t:Ky(t),e.getAttribute(t)}scrapeMotionValuesFromProps(e,t,n){return tw(e,t,n)}build(e,t,n){Qy(e,t,this.isSVGTag,n.transformTemplate,n.style)}renderInstance(e,t,n,r){ew(e,t,n,r)}mount(e){this.isSVGTag=$C(e.tagName),super.mount(e)}};function rw(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 iw=[..._S].reverse(),aw=e=>e?.out===!0?e:e?.out;function ow(e){let t=t=>Promise.all(t.map(({animation:t,options:n})=>Ay(e,t,n))),n=cw(),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`&&my(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&&aw(f(l??(g&&g.props.initial))?.transition);if(iw.forEach((t,r)=>{let i=n[t],l=o[t],f=g&&g.props[t],v=l===void 0?gS(f)||f===!1?f:void 0:l,y=gS(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||hS(v)||typeof v==`boolean`)return;if(b===!1&&(h=r),t===`exit`&&i.isActive&&b!==!0){m={...m,...i.prevResolvedValues};return}let S=sw(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}=my(e,n,hy(e,t))||{};E={...E,...a,...i},D=aw(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)?!rw(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=my(s,n)?.transition?.delayChildren;r.delay=qv(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&&!xy(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=cw(),i=!0}}}function sw(e,t){return typeof t==`string`?t!==e:Array.isArray(t)?!rw(t,e):!1}function cw(){let e={};for(let t of _S)e[t]={isActive:t===`animate`,protectedKeys:{},needsAnimating:{},prevResolvedValues:{},out:{}};return e}var lw=(0,U.createContext)({transformPagePoint:e=>e,isStatic:!1,reducedMotion:`never`});function uw(e=!0){let t=(0,U.useContext)(Xp);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 dw=(0,U.createContext)({strict:!1}),fw={animation:[`variants`,..._S],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`]},pw=!1;function mw(){if(pw)return;let e={};for(let t in fw)e[t]={isEnabled:e=>fw[t].some(t=>!!e[t])};OS(e),pw=!0}function hw(){return mw(),kS()}function gw(e){let t=hw();for(let n in e)t[n]={...t[n],...e[n]};OS(t)}var _w=(0,U.createContext)({});function vw(e,t){if(yS(e)){let{initial:t,animate:n}=e;return{initial:t===!1||gS(t)?t:void 0,animate:gS(n)?n:void 0}}return e.inherit===!1?{}:t}function yw(e){let{initial:t,animate:n}=vw(e,(0,U.useContext)(_w));return(0,U.useMemo)(()=>({initial:t,animate:n}),[bw(t),bw(n)])}function bw(e){return Array.isArray(e)?e.join(` `):e}var xw=()=>({style:{},transform:{},transformOrigin:{},vars:{}});function Sw(e,t,n){for(let r in t)!xy(t[r])&&!NS(r,n)&&(e[r]=t[r])}function Cw({transformTemplate:e},t){return(0,U.useMemo)(()=>{let n=xw();return qy(n,t,e),Object.assign({},n.vars,n.style)},[t])}function ww(e,t){let n=e.style||{},r={};return Sw(r,n,e),Object.assign(r,Cw(e,t)),r}function Tw(e,t){let n={},r=ww(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 Ew=()=>({...xw(),attrs:{}});function Dw(e,t,n,r){let i=(0,U.useMemo)(()=>{let n=Ew();return Qy(n,t,$C(r),e.transformTemplate,e.style),{...n.attrs,style:{...n.style}}},[t]);if(e.style){let t={};return Sw(t,e.style,e),{...i,style:{...t,...i.style}}}return i}var Ow=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 kw(e){return e.startsWith(`while`)||e.startsWith(`drag`)&&e!==`draggable`||e.startsWith(`layout`)||e.startsWith(`onTap`)||e.startsWith(`onPan`)||e.startsWith(`onLayout`)||Ow.has(e)}function Aw(e,t){return e.startsWith(`on`)?!kw(e):t?.(e)??!kw(e)}function jw(e,t,n,r){let i={};for(let a in e)a===`values`&&typeof e.values==`object`||xy(e[a])||(Aw(a,r)||n===!0&&kw(a)||!t&&!kw(a)||e.draggable&&a.startsWith(`onDrag`))&&(i[a]=e[a]);return i}var Mw=[`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 Nw(e){return typeof e!=`string`||e.includes(`-`)?!1:!!(Mw.indexOf(e)>-1||/[A-Z]/u.test(e))}function Pw(e,t,n,{latestValues:r},i,a=!1,o,s){let c=(o??Nw(e)?Dw:Tw)(t,r,i,e),l=jw(t,typeof e==`string`,a,s),u=e===U.Fragment?{}:{...l,...c,ref:n},{children:d}=t,f=(0,U.useMemo)(()=>xy(d)?d.get():d,[d]);return(0,U.createElement)(e,{...u,children:f})}function Fw({scrapeMotionValuesFromProps:e,createRenderState:t},n,r,i){return{latestValues:Iw(n,r,i,e),renderState:t()}}function Iw(e,t,n,r){let i={},a=r(e,{});for(let e in a)i[e]=jb(a[e]);let{initial:o,animate:s}=e,c=yS(e),l=bS(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`&&!hS(d)){let t=Array.isArray(d)?d:[d];for(let n=0;n<t.length;n++){let r=py(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 Lw=e=>(t,n)=>{let r=(0,U.useContext)(_w),i=(0,U.useContext)(Xp),a=()=>Fw(e,t,r,i);return n?a():Jp(a)},Rw=Lw({scrapeMotionValuesFromProps:PS,createRenderState:xw}),zw=Lw({scrapeMotionValuesFromProps:tw,createRenderState:Ew}),Bw=Symbol.for(`motionComponentSymbol`);function Vw(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 Hw=(0,U.createContext)({});function Uw(e,t,n,r,i,a){let{visualElement:o}=(0,U.useContext)(_w),s=(0,U.useContext)(dw),c=(0,U.useContext)(Xp),l=(0,U.useContext)(lw),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)(Hw);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[wy],_=(0,U.useRef)(!!g&&typeof window<`u`&&!window.MotionHandoffIsComplete?.(g)&&window.MotionHasOptimisedAnimation?.(g));return Yp(()=>{p.current&&m&&(m.animationState?.animateChanges(),m.enteringChildren=void 0)},[]),Yp(()=>{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 Ww(e,{forwardMotionProps:t=!1,type:n}={},r,i){r&&gw(r);let a=n?n===`svg`:Nw(e),o=a?zw:Rw;function s(n,s){let c,l=Gw(n);Jp(()=>!!fS.current?.sharedNodes.get(l)?.lead&&n.initial)&&(n={...n,initial:!1});let u={...(0,U.useContext)(lw),...n,layoutId:l},{isStatic:d,isValidProp:f}=u,p=yw(n),m=o(n,d);if(!d&&typeof window<`u`){Kw(u,r);let t=qw(u);p.visualElement=Uw(e,m,u,i,t.ProjectionNode,a),(t.isEnabled||p.visualElement?.projection?.options.layoutId)&&(c=t.MeasureLayout)}return(0,W.jsxs)(_w.Provider,{value:p,children:[c&&p.visualElement?(0,W.jsx)(c,{visualElement:p.visualElement,...u}):null,Pw(e,n,Vw(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[Bw]=e,c}function Gw({layoutId:e}){let t=(0,U.useContext)(qp).id;return t&&e!==void 0?t+`-`+e:e}function Kw(e,t){(0,U.useContext)(dw).strict}function qw(e){let{drag:t,layout:n}=hw();if(!t&&!n)return{};let r={...t,...n};return{MeasureLayout:r.MeasureLayout,isEnabled:t?.isEnabled(e)||n?.isEnabled(e),ProjectionNode:r.ProjectionNode}}function Jw(e,t){if(typeof Proxy>`u`)return Ww;let n=new Map,r=(n,r)=>Ww(n,r,e,t);return new Proxy((e,t)=>r(e,t),{get:(i,a)=>a===`create`?r:(n.has(a)||n.set(a,Ww(a,void 0,e,t)),n.get(a))})}var Yw=(e,t)=>t.isSVG??Nw(e)?new nw(t):new IS(t,{allowProjection:e!==U.Fragment}),Xw=class extends ZC{constructor(e){super(e),e.animationState||=ow(e)}updateAnimationControlsSubscription(){let{animate:e}=this.node.getProps();hS(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?.()}},Zw=0,Qw={animation:{Feature:Xw},exit:{Feature:class extends ZC{constructor(){super(...arguments),this.id=Zw++}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}=my(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(){}}}},$w=class extends ZC{constructor(e){super(e),this.removeGroupControls=om,this.removeListeners=om,this.controls=new MC(e)}mount(){let{dragControls:e}=this.node.getProps();e&&(this.removeGroupControls=e.subscribe(this.controls)),this.removeListeners=this.controls.addListeners()||om}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()}},eT=e=>(t,n)=>{e&&eg.update(()=>e(t,n),!1,!0)},tT=class extends ZC{constructor(){super(...arguments),this.removePointerDownListener=om}onPointerDown(e){this.session=new iC(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:eT(e),onStart:eT(t),onMove:eT(n),onEnd:(e,t)=>{delete this.session,r&&eg.postRender(()=>r(e,t))}}}mount(){this.removePointerDownListener=BS(this.node.current,`pointerdown`,e=>this.onPointerDown(e))}update(){this.session?.updateHandlers(this.createPanHandlers())}unmount(){this.removePointerDownListener(),this.session?.end()}},nT=!1,rT=({layout:e,layoutDependency:t,layoutAnchor:n})=>({layout:e,layoutDependency:t,layoutAnchor:n,animationType:typeof e==`string`?e:`both`}),iT=(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)}},aT=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),nT&&i.root.didUpdate(),i.options.layoutId!==r&&iT(i,r)?.(),i.addEventListener(`animationComplete`,()=>this.safeToRemove()),i.setOptions({...i.options,...rT(this.props),onExitComplete:()=>this.safeToRemove()})),jx.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(),iT(o,n)),o.setOptions({...o.options,...rT(this.props)}),nT=!0,i||e.layoutDependency!==t||t===void 0||e.isPresent!==a?o.willUpdate():this.safeToRemove(),e.isPresent!==a&&(a?o.promote():o.relegate()||eg.postRender(()=>{o.getStack()?.members.length||this.safeToRemove()}))),null}componentDidUpdate(){let{projection:e}=this.props.visualElement;e&&(this.takeOver?.(),e.root.didUpdate(),Cb.postRender(()=>{!e.currentAnimation&&e.isLead()&&this.safeToRemove()}))}componentWillUnmount(){let{visualElement:e,layoutGroup:t,switchLayoutGroup:n}=this.props,{projection:r}=e;nT=!0,r&&(r.scheduleCheckAfterUnmount(),t.group?.remove(r),n?.deregister?.(r))}safeToRemove(){this.props.safeToRemove?.()}render(){return null}};function oT(e){let[t,n]=uw(),r=(0,U.useContext)(qp);return(0,W.jsx)(aT,{...e,layoutGroup:r,switchLayoutGroup:(0,U.useContext)(Hw),isPresent:t,safeToRemove:n})}var sT={pan:{Feature:tT},drag:{Feature:$w,ProjectionNode:pS,MeasureLayout:oT}};function cT(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&&eg.postRender(()=>o(t,RS(t)))}var lT=class extends ZC{mount(){let{current:e}=this.node;e&&(this.unmount=VC(e,(e,t)=>(cT(this.node,t,`Hover`,`Start`),e=>cT(this.node,e,`Hover`,`End`))))}unmount(){}},uT=class extends ZC{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=sm(uS(this.node.current,`focus`,()=>this.onFocus()),uS(this.node.current,`blur`,()=>this.onBlur()))}unmount(){}};function dT(e,t,n){e.current instanceof HTMLButtonElement&&e.current.disabled||cT(e,t,`Tap`,n)}var fT=class extends ZC{mount(){let{current:e}=this.node;if(!e)return;let{globalTapTarget:t,propagate:n}=this.node.props;this.unmount=YC(e,(e,t)=>(dT(this.node,t,`Start`),(e,{success:t})=>dT(this.node,e,t?``:`Cancel`)),{useGlobalTarget:t,stopPropagation:n?.tap===!1})}unmount(){}},pT=new WeakMap,mT=new WeakMap,hT=e=>{let t=pT.get(e.target);t&&t(e)},gT=e=>{e.forEach(hT)};function _T({root:e,...t}){let n=e||document;mT.has(n)||mT.set(n,{});let r=mT.get(n),i=JSON.stringify(t);return r[i]||(r[i]=new IntersectionObserver(gT,{root:e,...t})),r[i]}function vT(e,t,n){let r=_T(t);return pT.set(e,n),r.observe(e),()=>{pT.delete(e),r.unobserve(e)}}var yT={some:0,all:1},bT=class extends ZC{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:yT[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=vT(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(xT(e,t))&&this.startObserver()}unmount(){this.stopObserver?.(),this.hasEnteredView=!1,this.isInView=!1}};function xT({viewport:e={}},{viewport:t={}}={}){return n=>e[n]!==t[n]}var ST=Jw(Object.assign({},Qw,{inView:{Feature:bT},tap:{Feature:fT},focus:{Feature:uT},hover:{Feature:lT}},sT,{layout:{ProjectionNode:pS,MeasureLayout:oT}}),Yw);function CT(e){let t=Jp(()=>Qv(e)),{isStatic:n}=(0,U.useContext)(lw);if(n){let[,n]=(0,U.useState)(e);(0,U.useEffect)(()=>t.on(`change`,n),[])}return t}function wT(e,t){let n=CT(t()),r=()=>n.set(t());return r(),Yp(()=>{let t=()=>eg.preRender(r,!1,!0),n=e.map(e=>e.on(`change`,t));return r(),()=>{n.forEach(e=>e()),tg(r)}}),n}function TT(e){Xv.current=[],e();let t=wT(Xv.current,e);return Xv.current=void 0,t}function ET(e,t,n,r){if(typeof e==`function`)return TT(e);if(n!==void 0&&!Array.isArray(n)&&typeof t!=`function`)return OT(e,t,n,r);let i=typeof t==`function`?t:XC(t,n,r),a=Array.isArray(e)?DT(e,i):DT([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 DT(e,t){let n=Jp(()=>[]);return wT(e,()=>{n.length=0;let r=e.length;for(let t=0;t<r;t++)n[t]=e[t].get();return t(n)})}function OT(e,t,n,r){let i=Jp(()=>Object.keys(n)),a=Jp(()=>({}));for(let o of i)a[o]=ET(e,t,n[o],r);return a}var kT=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()})}},AT=()=>new kT;function jT(){return Jp(AT)}var MT=(0,U.createContext)(null);function NT(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:Nh(t.x.min,t.x.max,.5)+n.x,y:Nh(t.y.min,t.y.max,.5)+n.y},i=PT(e),s=i.find(t=>t.items.includes(e[o])),c=i.reduce((e,t)=>FT(r.y,t)<FT(r.y,e)?t:e);if(c!==s)return IT(e,o,r.x,c,a);let l=LT(r,t),u=-1,d=l;return e.forEach((e,t)=>{if(t===o)return;let n=LT(r,e.layout);n<d&&(u=t,d=n)}),u===-1?e:$p(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=Nh(u.min,u.max,.5);return s===1&&l.max+n[i]>d||s===-1&&l.min+n[i]<d?$p(e,o,o+s):e}function PT(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 FT(e,t){return e<t.min?t.min-e:e>t.max?e-t.max:0}function IT(e,t,n,r,i){let a=e.filter((e,n)=>n!==t),o=r.items.find(e=>{let t=Nh(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 LT(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 RT=(e,t)=>e.max<=t.min||t.max<=e.min;function zT(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||=RT(e[r].x,e[i].x),n||=RT(e[r].y,e[i].y),t&&n)return`xy`;return t?`x`:`y`}function BT({children:e,as:t=`ul`,axis:n,onReorder:r,values:i,onPointerDownCapture:a,onClickCapture:o,...s},c,l){let u=Jp(()=>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($p(s,e,n),t)}e.preventDefault()},registerItem:(e,t)=>{if(d.current.set(e,t),!n){let e=zT(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=NT(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)(MT.Provider,{value:S,children:e})})}var VT=e=>(0,U.forwardRef)((t,n)=>BT(t,n,e)),HT=50,UT=1.5,WT=new Set([`auto`,`scroll`]),GT=new WeakMap,KT=new WeakMap,qT=null;function JT(){if(qT){let e=XT(qT,`y`);e&&(KT.delete(e),GT.delete(e));let t=XT(qT,`x`);t&&t!==e&&(KT.delete(t),GT.delete(t)),qT=null}}function YT(e,t){let n=getComputedStyle(e),r=t===`x`?n.overflowX:n.overflowY,i=e===document.body||e===document.documentElement;return WT.has(r)||i}function XT(e,t){let n=e?.parentElement;for(;n;){if(YT(n,t))return n;n=n.parentElement}return null}function ZT(e){let t=Math.min(1,1-e/HT);return UT*t*t*Mm.delta}function QT(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<HT?{amount:-ZT(o),edge:`start`}:s<HT?{amount:ZT(s),edge:`end`}:{amount:0,edge:null}}function $T(e,t,n,r){if(!e)return;qT=e;let i=XT(e,n);if(!i)return;let{amount:a,edge:o}=QT(t-(n===`x`?window.scrollX:window.scrollY),i,n);if(o===null){KT.delete(i),GT.delete(i);return}let s=KT.get(i),c=i===document.body||i===document.documentElement;if(s!==o){if(!(o===`start`&&r<0||o===`end`&&r>0))return;KT.set(i,o);let e=n===`x`?i.scrollWidth-(c?window.innerWidth:i.clientWidth):i.scrollHeight-(c?window.innerHeight:i.clientHeight);GT.set(i,e)}if(a>0){let e=GT.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 eE(e,t=0){return xy(e)?e:CT(t)}function tE({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)(MT),f=Jp(()=>d.proxy[r]),[p,m]=(0,U.useState)(),h={x:eE(t.x),y:eE(t.y)},g=ET([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),mS.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`:_;$T(b.current,a[s],s,r[s]),i&&i(e,t)},onDragEnd:(e,t)=>{x.current=!1,JT(),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 nE=(0,U.forwardRef)(tE),rE=VT(ST);function iE(e){let[t,n]=(0,U.useState)(!1),[r,i]=(0,U.useState)(``),[a,s]=(0,U.useState)(``),[c,l]=(0,U.useState)(``),[u,d]=(0,U.useState)(null);return(0,W.jsxs)(`form`,{className:`grid`,onSubmit:async n=>{n.preventDefault(),d(null);try{if(t)await o([x(a).address],c.trim()===``?null:c.trim());else{let e=x(r);await o([e.address],e.code)}e.onAdded?.()}catch(e){d(Ht(e))}},children:[(0,W.jsxs)(`div`,{className:B(`grid gap-2`,e.fieldsClassName),children:[t?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(Kf,{"aria-label":`Server URL`,placeholder:`Server URL, e.g. http://127.0.0.1:47841`,spellCheck:!1,autoComplete:`off`,value:a,onChange:e=>s(e.target.value)}),(0,W.jsx)(Kf,{"aria-label":`Pairing code`,placeholder:`Pairing code, empty if auth is off`,spellCheck:!1,autoComplete:`off`,value:c,onChange:e=>l(e.target.value)})]}):(0,W.jsx)(Kf,{"aria-label":`Pairing link`,placeholder:`Pairing link`,spellCheck:!1,autoComplete:`off`,value:r,onChange:e=>i(e.target.value)}),u!==null&&(0,W.jsx)(`p`,{className:`text-destructive text-sm break-all`,children:u}),(0,W.jsx)(`button`,{type:`button`,className:`text-muted-foreground hover:text-foreground w-fit cursor-pointer text-xs`,onClick:()=>{n(!t),d(null)},children:t?`Paste a pairing link instead`:`Enter the server URL and code separately`})]}),e.actions(t?a.trim()!==``:r.trim()!==``)]})}function aE(e){return(0,W.jsx)(ei,{open:!0,onOpenChange:()=>e.onClose(),children:(0,W.jsxs)(qr,{className:`gap-0 overflow-hidden p-0 sm:max-w-md`,children:[(0,W.jsxs)(Jr,{className:`gap-1 px-6 pt-4 pr-12`,children:[(0,W.jsx)(Zr,{className:`text-base`,children:`Add machine`}),(0,W.jsx)(Qr,{children:`Paste the pairing link that OffSite printed when it started.`})]}),(0,W.jsx)(iE,{fieldsClassName:`p-6`,onAdded:e.onClose,actions:t=>(0,W.jsxs)(ti,{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 oE(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:[(Ad.includes(n)?Ad:[n,...Ad]).map(e=>(0,W.jsx)(H,{title:e,size:`icon-sm`,"aria-pressed":e===n,variant:e===n?`default`:`ghost`,onClick:()=>v(t.id,{icon:e}),children:(0,W.jsx)(jd,{icon:e})},e)),(0,W.jsxs)(un,{open:r,onOpenChange:i,modal:!0,children:[(0,W.jsx)(bn,{asChild:!0,children:(0,W.jsx)(H,{title:`More icons`,size:`icon-sm`,variant:`ghost`,children:(0,W.jsx)(V,{icon:nr})})}),(0,W.jsx)(cn,{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(kd).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(kd).filter(t=>kd[t].group===e&&!Ad.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:()=>{v(t.id,{icon:e}),i(!1)},children:(0,W.jsx)(jd,{icon:e,className:`block aspect-square! h-auto! w-[66%]! min-w-0! shrink-0!`})},e))})]},e))})]})]})]})}var sE={connecting:`Connecting…`,online:`Online`,offline:`Offline`,unpaired:`Needs pairing`};function cE(){let e=k(e=>e.machines),t=k(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)(xp,{title:`Machines`,note:`This browser connects to each one directly. The list stays in this browser`,children:(0,W.jsx)(rE,{as:`div`,axis:`y`,className:`divide-y`,values:o.map(e=>e.id),onReorder:a,children:o.map(e=>(0,W.jsxs)(uE,{value:e.id,disabled:!1,className:`min-h-13 gap-4`,onDragEnd:()=>{i!==null&&ne(i),a(null)},children:[(0,W.jsx)(jd,{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:[rn[e.provider],` threads: `,e.error]},e.provider))]}),(0,W.jsxs)(`span`,{className:`text-muted-foreground shrink-0 text-xs`,children:[sE[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:()=>I(e.id),children:(0,W.jsx)(V,{icon:ds})}),(0,W.jsx)(H,{size:`icon-sm`,variant:`ghost-muted`,title:`Open machine`,onClick:()=>We({settingsEditedMachine:e.id}),children:(0,W.jsx)(V,{icon:Tr})})]})]},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)(aE,{onClose:()=>r(!1)})]}):(0,W.jsx)(lE,{machine:t})}function lE(e){let t=e.machine,[n,r]=(0,U.useState)(!1),[i,a]=(0,U.useState)(``),[o,s]=(0,U.useState)(null),[c,l]=(0,U.useState)(null),u=c??t.addresses,d=t.addresses.some(e=>de!==null&&de.includes(e)),f=(0,U.useRef)(null);(0,U.useEffect)(()=>{n&&f.current?.focus()},[n]);function p(e){s(null);try{return v(t.id,{addresses:[...new Set(e.map(e=>x(e).address))]}),!0}catch(e){return s(Ht(e)),!1}}async function m(e){s(null);let n=e.trim();if(n===``)return!0;try{let e=n.includes(`#`)?x(n).code:n;if(e===null)throw Error(`That link has no pairing code`);return await g(t.id,e),!0}catch(e){return s(Ht(e)),!1}}return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(xp,{title:`Machine`,children:[(0,W.jsx)(Q,{label:`Name`,children:(0,W.jsx)(Sp,{value:t.label??``,placeholder:t.hostname,onCommit:e=>v(t.id,{label:e.trim()===``?null:e.trim()})},t.label)}),(0,W.jsx)(oE,{machine:t})]}),!d&&(0,W.jsx)(xp,{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 ${xn(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 m(i)&&a(``)},children:[(0,W.jsx)(Kf,{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:qo}),`Pair`]})]})]})}),(0,W.jsxs)(xp,{title:`Addresses`,note:`OffSite tries them in order whenever it reconnects`,children:[(0,W.jsx)(rE,{as:`div`,axis:`y`,className:`divide-y`,values:u,onReorder:l,children:u.map((e,t)=>(0,W.jsxs)(uE,{value:e,disabled:d,onDragEnd:()=>{c!==null&&p(c),l(null)},children:[(0,W.jsx)(Sp,{className:`flex-1 font-mono`,value:e,disabled:d,onCommit:e=>p(u.map((n,r)=>r===t?e:n))}),(0,W.jsx)(H,{size:`icon-sm`,variant:`ghost`,title:`Remove address`,disabled:d||u.length===1,onClick:()=>p(u.filter((e,n)=>n!==t)),children:(0,W.jsx)(V,{icon:Mo})})]},e))}),n&&(0,W.jsx)(`div`,{className:`px-4 py-2.5`,children:(0,W.jsx)(Kf,{ref:f,className:`font-mono`,placeholder:`http://192.168.1.10:47841`,spellCheck:!1,autoComplete:`off`,onBlur:e=>{let n=e.target.value.trim();(n===``||p([...t.addresses,n]))&&r(!1)},onKeyDown:e=>{e.key===`Enter`&&e.currentTarget.blur()}})}),!n&&!d&&(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:to,className:`size-4`}),`Add address`]})]}),o!==null&&(0,W.jsx)(`p`,{className:`text-destructive px-1 text-xs break-all`,children:o}),!d&&(0,W.jsxs)(lr,{children:[(0,W.jsx)(wr,{asChild:!0,children:(0,W.jsx)(H,{variant:`outline`,className:`text-destructive`,children:`Remove machine`})}),(0,W.jsxs)(Kn,{children:[(0,W.jsxs)(Er,{children:[(0,W.jsxs)(Ln,{children:[`Remove `,t.name,`?`]}),(0,W.jsx)(Pn,{children:`This browser forgets the machine. The machine and its threads stay untouched.`})]}),(0,W.jsxs)(br,{children:[(0,W.jsx)(Jn,{children:`Cancel`}),(0,W.jsx)(rr,{variant:`destructive`,onClick:()=>{We({settingsEditedMachine:null}),ge(t.id)},children:`Remove machine`})]})]})]})]})}function uE(e){let t=jT();return(0,W.jsxs)(nE,{as:`div`,value:e.value,dragListener:!1,dragControls:t,onDragEnd:e.onDragEnd,className:B(`bg-background relative flex items-center gap-3 px-4 py-2.5`,e.className),children:[(0,W.jsx)(`span`,{className:B(`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:No,className:`size-4`})}),e.children]})}var dE=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 fE(e){let t=e.prefs.terminal,n=t.behavior;function r(r){D({...e.prefs,terminal:{...t,behavior:{...n,...r}}})}return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(xp,{title:`Notifications`,children:[(0,W.jsx)(Q,{label:`Desktop notifications on this device`,children:(0,W.jsx)(pE,{})}),(0,W.jsx)(Q,{label:`Push terminal alerts when no OffSite page is open`,children:(0,W.jsx)(mE,{})})]}),(0,W.jsxs)(xp,{title:`Terminal bell`,children:[(0,W.jsx)(Q,{label:`Flash the screen on bell`,children:(0,W.jsx)(pp,{checked:n.bellFlash,onCheckedChange:e=>r({bellFlash:e})})}),(0,W.jsx)(Q,{label:`Play a sound on bell`,children:(0,W.jsx)(pp,{checked:n.bellSound,onCheckedChange:e=>r({bellSound:e})})})]})]})}function pE(){let[e,t]=(0,U.useState)(ya),[n,r]=(0,U.useState)(ba);(0,U.useEffect)(()=>{let e=ya();if(e===`insecure`||e===`unsupported`)return;let n=new AbortController;return Sa(n.signal,()=>t(ya())).catch(e=>console.error(`could not watch the notification permission`,e)),()=>n.abort()},[]);async function i(e){await xa(e),r(e),t(ya())}return(0,W.jsxs)(`div`,{className:`flex items-center gap-3`,children:[dE.has(e)&&(0,W.jsx)(`span`,{className:`text-muted-foreground text-xs`,children:dE.get(e)}),(0,W.jsx)(pp,{checked:e===`granted`&&n,disabled:e!==`granted`&&e!=="default",onCheckedChange:e=>void i(e)})]})}function mE(){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 Ma();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 Na()):(await Pa(),r(!1))}catch(e){console.error(`could not change push notifications`,e),s(Ht(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]}),dE.has(e)&&(0,W.jsx)(`span`,{className:`text-muted-foreground text-xs`,children:dE.get(e)}),(0,W.jsx)(pp,{checked:e===`supported`&&n,disabled:e!==`supported`||i,onCheckedChange:e=>void c(e)})]})}function hE({className:e,...t}){return(0,W.jsx)(Gs,{"data-slot":`label`,className:B(`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 gE={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&&(gE[n]=e)}}var _E={a:[7844,7863],e:[7870,7879],o:[7888,7907],u:[7912,7921]};for(let e of Object.keys(_E)){let t=e.toUpperCase();for(let n=_E[e][0];n<=_E[e][1];++n)gE[n]=n%2==0?t:e}function vE(e){if(e<192||e>8580)return e;let t=gE[e];return t===void 0?e:t.codePointAt(0)}function yE(e){return e}function bE(e){return e}function xE(e,t){return e>t?e:t}var SE=e=>e.split(``).map(e=>e.codePointAt(0)),CE=new Set(` \f
|
|
14
14
|
\r \v\xA0 \u2028\u2029 `.split(``).map(e=>e.codePointAt(0)));for(let e=` `.codePointAt(0);e<=` `.codePointAt(0);e++)CE.add(e);var wE=``.codePointAt(0),TE=`A`.codePointAt(0),EE=`Z`.codePointAt(0),DE=`a`.codePointAt(0),OE=`z`.codePointAt(0),kE=`0`.codePointAt(0),AE=`9`.codePointAt(0);function jE(e,t,n){return n?e:t-e-1}var ME=16,NE=-3,PE=-1,FE=ME/2,IE=ME/2,LE=7,RE=4,zE=2;function BE(e){return e?new Set:null}function VE(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 HE(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 UE(e){return e>=DE&&e<=OE?1:e>=TE&&e<=EE?2:e>=kE&&e<=AE?4:0}function WE(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 GE(e){return e<=wE?UE(e):WE(e)}function KE(e,t){return e===0&&t!==0?FE:e===1&&t===2||e!==4&&t===4?LE:t===0?IE:0}function qE(e,t){return t===0?FE:KE(GE(e[t-1]),GE(e[t]))}function JE(e,t,n,r){let i=e.slice(r),a=i.indexOf(n);if(a===0)return r;if(!t&&n>=DE&&n<=OE){a>0&&(i=i.slice(0,a));let e=i.indexOf(n-32);e>=0&&(a=e)}return a<0?-1:r+a}function YE(e){for(let t of e)if(t>=128)return!1;return!0}function XE(e,t,n){if(!YE(e))return 0;if(!YE(t))return-1;let r=0,i=0;for(let a=0;a<t.length;a++){if(i=JE(e,n,t[a],i),i<0)return-1;a===0&&i>0&&(r=i-1),i++}return r}var ZE=(e,t,n,r,i,a,o)=>{let s=i.length;if(s===0)return[{start:0,end:0,score:0},BE(a)];let c=r.length;if(o!==null&&c*s>o.i16.length)return $E(e,t,n,r,i,a);let l=XE(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]=VE(u,o,c),[u,p]=VE(u,o,c),[u,m]=VE(u,o,c),[d,h]=HE(d,o,s);let[,g]=HE(d,o,c);for(let e=0;e<g.length;e++)g[e]=r[e];let _=yE(0),v=0,y=0,b=0,x=i[0],S=i[0],C=yE(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<=wE?(o=UE(a),!e&&o===2&&(a+=32)):(o=WE(a),!e&&o===2&&(a=String.fromCodePoint(a).toLowerCase().codePointAt(0)),t&&(a=vE(a))),E[r]=a;let c=KE(w,o);if(k[r]=c,w=o,a===S&&(y<s&&(h[y]=bE(l+r),y++,S=i[Math.min(y,s-1)]),b=l+r),a===x){let e=ME+c*zE;if(D[r]=e,O[r]=1,s===1&&(n&&e>_||!n&&e>=_)&&(_=e,v=l+r,n&&c===FE))break;T=!1}else D[r]=xE(T?C+PE:C+NE,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]=VE(u,o,j*s);{let e=f.subarray(A,b+1);for(let[t,n]of e.entries())M[t]=n}let[,ee]=VE(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]+PE:h[e]+NE,i===o){g=p[e]+ME;let t=l[e];b=d[e]+1,t===FE?b=1:b>1&&(t=xE(t,xE(RE,m[c-b+1]))),g+t<y?(g+=l[e],b=0):g+=t}u[e]=b,r=g<y;let x=xE(xE(g,y),0);a===s-1&&(n&&x>_||!n&&x>=_)&&(_=x,v=c),f[e]=x}}let re=BE(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 QE(e,t,n,r,i,a,o){let s=0,c=0,l=!1,u=0,d=yE(0),f=BE(o),p=0;i>0&&(p=GE(n[i-1]));for(let m=i;m<a;m++){let i=n[m],a=GE(i);if(e||(i>=TE&&i<=EE?i+=32:i>wE&&(i=String.fromCodePoint(i).toLowerCase().codePointAt(0))),t&&(i=vE(i)),i===r[s]){o&&f!==null&&f.add(m),c+=ME;let e=KE(p,a);u===0?d=e:(e===FE&&(d=e),e=xE(xE(e,d),RE)),c+=s===0?e*zE:e,l=!1,u++,s++}else c+=l?PE:NE,l=!0,u=0,d=0;p=a}return[c,f]}var $E=(e,t,n,r,i,a,o)=>{if(i.length===0)return[{start:0,end:0,score:0},null];if(XE(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[jE(a,u,n)];e||(o>=TE&&o<=EE?o+=32:o>wE&&(o=String.fromCodePoint(o).toLowerCase().codePointAt(0))),t&&(o=vE(o));let f=i[jE(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[jE(t,u,n)];e||(a>=TE&&a<=EE?a+=32:a>wE&&(a=String.fromCodePoint(a).toLowerCase().codePointAt(0)));let o=i[jE(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]=QE(e,t,r,i,c,l,a);return[{start:c,end:l,score:o},f]}return[{start:-1,end:-1,score:0},null]},eD=(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||XE(r,i,e)<0)return[{start:-1,end:-1,score:0},null];let l=0,u=-1,d=yE(0),f=yE(-1);for(let a=0;a<s;a++){let o=jE(a,s,n),p=r[o];e||(p>=TE&&p<=EE?p+=32:p>wE&&(p=String.fromCodePoint(p).toLowerCase().codePointAt(0))),t&&(p=vE(p));let m=jE(l,c,n);if(i[m]===p){if(m===0&&(d=qE(r,o)),l++,l===c){if(d>f&&(u=a,f=d),d===FE)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]=QE(e,t,r,i,a,o,!1);return[{start:a,end:o,score:l},null]}return[{start:-1,end:-1,score:0},null]},tD=102400,nD=2048;function rD(e,t){return{i16:new Int16Array(e),i32:new Int32Array(t)}}var iD=rD(tD,nD),aD=(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=SE(e);return n&&(i=i.map(vE)),{queryRunes:i,caseSensitive:r}};function oD(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 sD(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,iD);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 cD(e){let{queryRunes:t,caseSensitive:n}=aD(e,this.opts.casing,this.opts.normalize),r={},i=sD.bind(this)(r,t,n);for(let e=0,t=this.runesList.length;e<t;++e)i(e);return oD(r,this.opts.limit)}var lD={limit:1/0,selector:e=>e,casing:`smart-case`,normalize:!0,fuzzy:`v2`,tiebreakers:[],sort:!0,forward:!0},uD=class{constructor(e,...t){switch(this.opts={...lD,...t[0]},this.items=e,this.runesList=e.map(e=>SE(this.opts.selector(e).normalize())),this.algoFn=eD,this.opts.fuzzy){case`v2`:this.algoFn=ZE;break;case`v1`:this.algoFn=$E}}},dD={...lD,match:cD},fD=class extends uD{constructor(e,...t){super(e,...t),this.opts={...dD,...t[0]}}find(e){return e.length===0||this.items.length===0?this.items.slice(0,this.opts.limit).map(pD):(e=e.normalize(),mD(this.opts.match.bind(this)(e),this.opts))}};({...lD});var pD=e=>({item:e,start:-1,end:-1,score:0,positions:new Set});function mD(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 hD(e,t,n){return n(e.item).length-n(t.item).length}var gD=class{constructor(e,...t){this.finder=new fD(e,...t),this.find=this.finder.find.bind(this.finder)}};function _D(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 gD(t??[],{limit:50,casing:`case-insensitive`,tiebreakers:[(e,t)=>vD(t)-vD(e),hD]}).find(r).map(e=>e.item);return(0,U.useEffect)(()=>{let t=!1;return(async()=>{try{let r=await z(e.machine,`projects.logoFiles`,{id:e.projectId});t||n(r)}catch(e){t||c(Ht(e))}})(),()=>{t=!0}},[e.machine,e.projectId]),(0,W.jsx)(ei,{open:!0,onOpenChange:()=>e.onClose(),children:(0,W.jsxs)(qr,{className:`gap-0 overflow-hidden p-0 sm:max-w-lg`,showCloseButton:!1,"aria-describedby":void 0,children:[(0,W.jsx)(Zr,{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:cr,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)(Xr,{asChild:!0,children:(0,W.jsx)(H,{variant:`ghost`,size:`icon-sm`,"aria-label":`Close`,children:(0,W.jsx)(V,{icon:bo})})})]}),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:Rn})}),(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:ur,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 z(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(Ht(e))}},children:[(0,W.jsx)(V,{icon:yr,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 vD(e){let t=e.item.lastIndexOf(`/`)+1;return[...e.positions].filter(e=>e>=t).length}function yD(e){let t=k(e=>e.machines),[n,r]=(0,U.useState)(null),[i,a]=(0,U.useState)(null),[o,s]=(0,U.useState)(()=>bD(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 z(e.machine,`directories.list`,{path:o});if(t)return;r({path:o,listing:n}),a(null)}catch(e){if(t)return;r(null),a(Ht(e))}},150);return()=>{t=!0,clearTimeout(n)}},[e.machine,o]),(0,W.jsx)(ei,{open:!0,onOpenChange:()=>e.onClose(),children:(0,W.jsxs)(qr,{className:`gap-0 overflow-hidden p-0 sm:max-w-lg`,showCloseButton:!1,"aria-describedby":void 0,children:[(0,W.jsx)(Zr,{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:Uo})}),(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:Rn})}),(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)(Xr,{asChild:!0,children:(0,W.jsx)(H,{variant:`ghost`,size:`icon-sm`,"aria-label":`Close`,children:(0,W.jsx)(V,{icon:bo})})})]}),(0,W.jsxs)(`label`,{className:`flex h-9 items-center gap-2.5 border-b px-3`,children:[(0,W.jsx)(V,{icon:cr,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:ur,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)(ti,{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(Ht(e)),d(!1)}}},children:`Add project`})})]})})}function bD(e){return e===void 0||e.config===null||e.system===null?`~`:e.config.workingDir[e.system.platform]??`~`}function xD(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)(ei,{open:!0,onOpenChange:()=>e.onClose(),children:(0,W.jsxs)(qr,{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(Ht(e)),l(!1)}},children:[(0,W.jsxs)(Jr,{className:`gap-1 px-6 pt-4 pr-12`,children:[(0,W.jsx)(Zr,{className:`text-base`,children:`Edit project`}),(0,W.jsx)(Qr,{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)(hE,{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()===``?er(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:bo,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:ks}),`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:ur}),`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 Nd(t)}`)}})]}),(0,W.jsxs)(`div`,{className:`grid gap-2`,children:[(0,W.jsx)(hE,{htmlFor:`project-name`,children:`Name`}),(0,W.jsx)(Kf,{id:`project-name`,placeholder:er(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)(ti,{className:`bg-muted/40 border-t px-6 py-4`,children:[(0,W.jsxs)(H,{type:`button`,variant:u?`destructive`:`ghost`,className:B(`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(Ht(e))}},children:[(0,W.jsx)(V,{icon:Mo,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)(_D,{machine:e.project.machine,projectId:e.project.id,onClose:()=>p(!1),onPick:e=>{a(e),p(!1)}})]})})}function SD(e){let t=k(e=>e.projects),[n,r]=(0,U.useState)(null),[i,a]=(0,U.useState)(null),[o,s]=Nr(`sidebarScope`,null),c=t.filter(t=>t.machine===e.machine&&!t.scratch).sort((e,t)=>n===null?0:n.indexOf(e.id)-n.indexOf(t.id));return(0,W.jsxs)(W.Fragment,{children:[c.length===0&&(0,W.jsx)(`p`,{className:`text-muted-foreground py-8 text-center text-sm`,children:`No projects yet`}),(0,W.jsx)(rE,{as:`div`,axis:`y`,values:c.map(e=>e.id),onReorder:r,children:c.map(t=>(0,W.jsxs)(uE,{value:t.id,disabled:!1,className:`min-h-13 px-1 outline-none`,onDragEnd:async()=>{if(n!==null){try{await Ls(e.machine,n)}catch(e){N(e)}r(null)}},children:[(0,W.jsx)(zs,{machine:t.machine,projectId:t.id,className:`size-5 shrink-0 [&>img]:rounded-[4px] [&>svg]:rounded-[4px]`}),(0,W.jsxs)(`span`,{className:`min-w-0 flex-1`,title:t.path,children:[(0,W.jsx)(`span`,{className:B(`block truncate text-sm`,t.hidden&&`text-muted-foreground`),children:t.name}),(0,W.jsx)(`span`,{className:`text-muted-foreground block truncate font-mono text-xs`,children:CD(t.path,e.homeDir)})]}),(0,W.jsx)(H,{size:`icon-sm`,variant:`ghost-muted`,title:`Configure project`,"aria-label":`Configure ${t.name}`,onClick:()=>a(t),children:(0,W.jsx)(V,{icon:ms})}),(0,W.jsx)(pp,{size:`sm`,checked:!t.hidden,onCheckedChange:e=>Fs(t.machine,t.id,{hidden:!e}).catch(N),"aria-label":`Show ${t.name}`})]},t.id))}),i!==null&&(0,W.jsx)(xD,{project:i,onClose:()=>a(null),onRemoved:()=>{o?.machine===i.machine&&o.projectId===i.id&&s(null),a(null)}})]})}function CD(e,t){return e===t?`~`:e.startsWith(`${t}/`)||e.startsWith(`${t}\\`)?`~${e.slice(t.length)}`:e}function wD(e){let t=e.account,[n,r]=(0,U.useState)(null);async function i(n){r(null);try{await z(e.machine,`accounts.update`,{id:t.id,name:t.name,color:t.color,configDir:t.configDir,enabled:t.enabled,...n})}catch(e){r(Ht(e))}}async function a(){r(null);try{await z(e.machine,`accounts.remove`,{id:t.id}),We({settingsAccount:null})}catch(e){r(Ht(e))}}return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(xp,{title:`Account`,children:[(0,W.jsx)(Q,{label:`Name`,children:(0,W.jsx)(Sp,{value:t.name,valid:e=>e.trim()!==``,onCommit:e=>void i({name:e})},t.name)}),(0,W.jsx)(Q,{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)(Sp,{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)(Q,{label:`Config directory`,children:(0,W.jsx)(Sp,{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)(lr,{children:[(0,W.jsx)(wr,{asChild:!0,children:(0,W.jsx)(H,{variant:`outline`,className:`text-destructive`,children:`Remove account`})}),(0,W.jsxs)(Kn,{children:[(0,W.jsxs)(Er,{children:[(0,W.jsxs)(Ln,{children:[`Remove `,t.name,`?`]}),(0,W.jsx)(Pn,{children:`OffSite stops using this account. Its config directory and sessions stay untouched.`})]}),(0,W.jsxs)(br,{children:[(0,W.jsx)(Jn,{children:`Cancel`}),(0,W.jsx)(rr,{variant:`destructive`,onClick:()=>void a(),children:`Remove account`})]})]})]})]})}function TD(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 z(e.machine,`accounts.add`,{provider:e.provider,name:t,configDir:r}),We({settingsAccount:null})}catch(e){c(Ht(e)),o(!1)}}return(0,W.jsxs)(`form`,{className:`space-y-5`,onSubmit:e=>{e.preventDefault(),l()},children:[(0,W.jsxs)(xp,{title:`Account`,children:[(0,W.jsx)(Q,{label:`Name`,children:(0,W.jsx)(Kf,{className:`w-56`,value:t,onChange:e=>n(e.target.value),placeholder:`Work`})}),(0,W.jsx)(Q,{label:`Config directory`,children:(0,W.jsx)(Kf,{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:()=>We({settingsAccount:null}),children:`Cancel`}),(0,W.jsx)(H,{type:`submit`,disabled:a||t.trim()===``,children:`Add account`})]})]})}function ED(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)(TD,{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)(wD,{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)(Q,{label:`Base directory`,children:(0,W.jsx)(Sp,{className:`w-72 font-mono`,value:a,valid:e=>e.trim()!==``,onCommit:n=>bt(e.machine,{...t,claudeBaseDir:{...t.claudeBaseDir,[e.platform]:n}})},a)})}),(0,W.jsxs)(`div`,{className:B(`space-y-5 transition-opacity`,!n&&`opacity-50`),children:[e.provider!==`opencode`&&(0,W.jsx)(xp,{title:`Accounts`,children:(0,W.jsx)(OD,{machine:e.machine,accounts:r})}),n&&e.provider===`opencode`&&e.openCode.available&&(0,W.jsx)(DD,{machine:e.machine,config:t,provider:e.provider,accountId:null}),n&&e.provider!==`opencode`&&i!==void 0&&(0,W.jsx)(DD,{machine:e.machine,config:t,provider:e.provider,accountId:i.id})]})]})}function DD(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),z(e.machine,`capabilities`,{provider:e.provider,accountId:e.accountId,projectId:null}).then(e=>{t&&n(e)},e=>{t&&i(Ht(e))}),()=>{t=!1}},[e.machine,e.provider,e.accountId]);function c(t,n){bt(e.machine,{...e.config,models:{...e.config.models,[e.provider]:{...a,[t]:n}}})}return(0,W.jsxs)(xp,{title:`Models`,children:[o!==null&&(0,W.jsx)(Q,{label:`Default model`,children:(0,W.jsxs)(qf,{value:s??void 0,onValueChange:t=>void bt(e.machine,{...e.config,newThreads:{...e.config.newThreads,models:{...e.config.newThreads.models,[e.provider]:t}}}),children:[(0,W.jsx)(Yf,{className:`w-56`,children:(0,W.jsx)(Jf,{placeholder:`Choose a model`})}),(0,W.jsx)(Xf,{children:o.filter(e=>!(a[e.value]?.hidden??e.deprecated)||e.value===s).map(e=>(0,W.jsx)(Zf,{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:B(`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)(qf,{value:n.effort??t.effort??void 0,onValueChange:e=>c(t.value,{...n,effort:e}),children:[(0,W.jsx)(Yf,{size:`sm`,className:`w-28`,children:(0,W.jsx)(Jf,{placeholder:`Effort`})}),(0,W.jsx)(Xf,{children:t.efforts.map(e=>(0,W.jsx)(Zf,{value:e,children:e.charAt(0).toUpperCase()+e.slice(1)},e))})]}),(0,W.jsx)(pp,{size:`sm`,checked:!n.hidden,onCheckedChange:e=>c(t.value,{...n,hidden:!e}),"aria-label":`Show ${t.name}`})]},t.value)})]})}function OD(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(Ht(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:B(`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:B(`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)(kD,{limit:e},e.window))})]}),(0,W.jsx)(pp,{size:`sm`,checked:n.enabled,disabled:t,onCheckedChange:t=>void a(()=>z(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:()=>We({settingsAccount:n.id}),children:(0,W.jsx)(V,{icon:Tr})})]},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:()=>We({settingsAccount:`new`}),children:[(0,W.jsx)(V,{icon:to,className:`size-4`}),`Add account`]}),r!==null&&(0,W.jsx)(`p`,{className:`text-destructive px-4 py-3 text-xs`,children:r})]})}function kD(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)(Wr,{label:t.resetsAt===null?`Reset time unknown`:`Resets ${xn(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:jf(t)}),(0,W.jsx)(`div`,{className:`bg-foreground/10 h-1 w-16 overflow-hidden rounded-full`,children:(0,W.jsx)(`div`,{className:B(`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:B(`tabular-nums`,t.rejected&&`text-destructive`,!t.rejected&&`text-muted-foreground`),children:[n,`%`]})]})})}var AD=Rt?`⌘`:`Ctrl+Shift`,jD=[[`Enter`,`Send, or queue or steer while the agent works`],[`${Vt}+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`],[`${Vt}+S`,`Stash the prompt, or bring back the last stash`],[`${Vt}+Shift+V`,`Paste long text inline instead of as a file`],[`${Vt}+. or ${Vt}+Shift+M`,`Choose the model`],[`${Vt}+/ or ${Vt}+Shift+E`,`Choose the effort`],[`${Vt}+P`,`Choose the project, or the sidebar scope`],[`${Vt}+;`,`Choose the project of a new thread`],[`${Vt}+F`,`Find in the thread`],[`${Vt}+K or ${Vt}+Shift+P`,`Search sessions and actions`],[`${Vt}+,`,`Open settings`],[`${Vt}+1…9`,`Open a session from the sidebar`],[`${Vt}+N or ${Vt}+T`,`New thread`],[Rt?"⌘+` or Ctrl+`":"Ctrl+`",`Toggle the terminal`],[`${Vt}+B or ${Vt}+Shift+J`,`Toggle the sidebar`],[`${Vt}+J or ${Vt}+Shift+B`,`Toggle the right panel`],[`${Vt}+E`,`Toggle the editor`],[`${AD}+T`,`New terminal tab, in the terminal`],[`${AD}+W`,`Close the terminal tab`],[`${AD}+F`,`Find in the terminal`],[`Ctrl+Tab`,`Next terminal tab`],[`Ctrl+Shift+Tab`,`Previous terminal tab`]];function MD(){return(0,W.jsx)(xp,{title:`Keyboard shortcuts`,children:jD.map(([e,t])=>(0,W.jsx)(Q,{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 ND=1048576;function PD(e){window.isSecureContext?navigator.clipboard.writeText(e).catch(e=>{console.warn(`could not copy to the clipboard`,e),ea(`Could not copy to the clipboard`)}):console.warn(`copy from the terminal needs https or localhost`)}async function FD(e){if(!window.isSecureContext){console.warn(`programs can read the clipboard only over https or localhost`),ea(`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),ea(`Could not read the clipboard`);return}new TextEncoder().encode(t).length>ND?(console.warn(`the clipboard is over 1 MiB, not replying`),ea(`The clipboard is too large to share (over 1 MiB)`)):e(t)}var ID={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 LD(e,t){let n=ID[t];return e.key.toLowerCase()===`v`&&e.ctrlKey===n.ctrl&&e.altKey===n.alt&&!e.shiftKey&&!e.metaKey}async function RD(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?(ea(`No image in the clipboard`),!1):(await zD(e,t,n),!0)}async function zD(e,t,n){let r=[];for(let t of n){let n=await z(e,`terminal.paste`,{type:t.type,data:await Nd(t)});r.push(/\s/.test(n)?`"${n}"`:n)}t.paste(r.join(` `))}function BD(e){console.error(`could not paste image`,e),ea(`Could not paste the image`)}function VD(e){let t=e.prefs.terminal,[n,r]=(0,U.useState)(!gp.some(e=>e.family===t.font.family));function i(t){D({...e.prefs,terminal:t})}function a(e,n){i({...t,[e]:{...t[e],...n}})}return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(xp,{title:`Font`,children:[(0,W.jsx)(Q,{label:`Family`,children:(0,W.jsxs)(qf,{value:n?`custom`:t.font.family,onValueChange:e=>{r(e===`custom`),e!==`custom`&&a(`font`,{family:e})},children:[(0,W.jsx)(Yf,{className:`w-56`,children:(0,W.jsx)(Jf,{})}),(0,W.jsxs)(Xf,{children:[gp.map(e=>(0,W.jsx)(Zf,{value:e.family,children:e.label},e.family)),(0,W.jsx)(Zf,{value:`custom`,children:`Custom`})]})]})}),n&&(0,W.jsx)(Q,{label:`Custom family`,children:(0,W.jsx)(Sp,{placeholder:`Installed font name`,value:t.font.family,onCommit:e=>a(`font`,{family:e})})}),(0,W.jsx)(Q,{label:`Size`,children:(0,W.jsx)(Cp,{value:t.font.size,step:.5,onCommit:e=>a(`font`,{size:e})})}),(0,W.jsx)(Q,{label:`Line height`,children:(0,W.jsx)(Cp,{value:t.font.lineHeight,step:.05,onCommit:e=>a(`font`,{lineHeight:e})})}),(0,W.jsx)(Q,{label:`Ligatures`,children:(0,W.jsx)(pp,{checked:t.font.ligatures,onCheckedChange:e=>a(`font`,{ligatures:e})})}),(0,W.jsx)(Q,{label:`Bold text in bright colors`,children:(0,W.jsx)(pp,{checked:t.boldIsBright,onCheckedChange:e=>i({...t,boldIsBright:e})})})]}),(0,W.jsxs)(xp,{title:`Cursor`,children:[(0,W.jsx)(Q,{label:`Style`,children:(0,W.jsxs)(qf,{value:t.cursor.style,onValueChange:e=>a(`cursor`,{style:e}),children:[(0,W.jsx)(Yf,{className:`w-56`,children:(0,W.jsx)(Jf,{})}),(0,W.jsxs)(Xf,{children:[(0,W.jsx)(Zf,{value:`block`,children:`Block`}),(0,W.jsx)(Zf,{value:`bar`,children:`Bar`}),(0,W.jsx)(Zf,{value:`underline`,children:`Underline`})]})]})}),(0,W.jsx)(Q,{label:`Blink`,children:(0,W.jsx)(pp,{checked:t.cursor.blink,onCheckedChange:e=>a(`cursor`,{blink:e})})})]}),(0,W.jsx)(HD,{behavior:t.behavior,onChange:e=>a(`behavior`,e)}),(0,W.jsx)(UD,{behavior:t.behavior,onChange:e=>a(`behavior`,e)}),(0,W.jsx)(WD,{behavior:t.behavior,onChange:e=>a(`behavior`,e)}),(0,W.jsxs)(xp,{title:`Layout`,children:[[`top`,`right`,`bottom`,`left`].map(e=>(0,W.jsx)(Q,{label:`Padding ${e}`,children:(0,W.jsx)(Cp,{value:t.padding[e],onCommit:t=>a(`padding`,{[e]:t})})},e)),(0,W.jsx)(Q,{label:`Scrollback lines`,children:(0,W.jsx)(Cp,{value:t.scrollback,step:1e3,onCommit:e=>i({...t,scrollback:e})})})]})]})}function HD(e){return(0,W.jsxs)(xp,{title:`Behavior`,children:[(0,W.jsx)(Q,{label:`Modernize Shift+Enter`,children:(0,W.jsx)(pp,{checked:e.behavior.modernizeShiftEnter,onCheckedChange:t=>e.onChange({modernizeShiftEnter:t})})}),(0,W.jsx)(Q,{label:`${ID.linux.label} (${ID.windows.label} on Windows machines) pastes images from the browser clipboard`,children:(0,W.jsx)(pp,{checked:e.behavior.pasteBrowserImages,onCheckedChange:t=>e.onChange({pasteBrowserImages:t})})}),(0,W.jsx)(Q,{label:`Capture browser shortcuts`,children:(0,W.jsx)(pp,{checked:e.behavior.captureShortcuts,onCheckedChange:t=>e.onChange({captureShortcuts:t})})}),(0,W.jsx)(Q,{label:`Click moves the cursor in the command line`,children:(0,W.jsx)(pp,{checked:e.behavior.clickToMoveCursor,onCheckedChange:t=>e.onChange({clickToMoveCursor:t})})}),(0,W.jsx)(Q,{label:`Ask before closing a tab that is running a program`,children:(0,W.jsx)(pp,{checked:e.behavior.confirmCloseBusyTab,onCheckedChange:t=>e.onChange({confirmCloseBusyTab:t})})})]})}function UD(e){return Rt?(0,W.jsx)(xp,{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)(Q,{label:`Use Option as Meta`,children:(0,W.jsxs)(qf,{value:e.behavior.optionAsMeta,onValueChange:t=>e.onChange({optionAsMeta:t}),children:[(0,W.jsx)(Yf,{className:`w-56`,children:(0,W.jsx)(Jf,{})}),(0,W.jsxs)(Xf,{children:[(0,W.jsx)(Zf,{value:`off`,children:`Off`}),(0,W.jsx)(Zf,{value:`left`,children:`Left Option`}),(0,W.jsx)(Zf,{value:`right`,children:`Right Option`}),(0,W.jsx)(Zf,{value:`both`,children:`Both Options`})]})]})})}):null}function WD(e){return It?(0,W.jsx)(xp,{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)(Q,{label:`Ctrl+C copies the selection and Ctrl+V pastes`,children:(0,W.jsx)(pp,{checked:e.behavior.windowsCopyPaste,onCheckedChange:t=>e.onChange({windowsCopyPaste:t})})})}):null}var GD=[`General`,`Editor`,`Terminal`,`Notifications`,`Shortcuts`,`Machines`],KD=[`Machine`,`Projects`,`Claude`,`Codex`,`OpenCode`];function qD(){let e=k(e=>e.machines),t=k(e=>e.settingsMachine===null?null:L(e,e.settingsMachine)),n=k(e=>e.settingsPage),r=QD(n),i=k(e=>r===null?null:e.settingsAccount),a=k(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 JD(){let e=k(e=>e.settingsOpen),t=qD(),n=t.page,r=t.machine;or(`mod+comma`,()=>j(!e),{enableOnFormTags:!0,preventDefault:!0});function i(e){return(0,W.jsx)(`button`,{className:B(`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:()=>Ke(e),children:(0,W.jsx)(YD,{page:e})},e)}return(0,W.jsx)(ei,{open:e,onOpenChange:j,children:(0,W.jsxs)(qr,{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)(Zr,{className:`hidden px-2 pt-1 pb-3 text-base font-semibold sm:block`,children:`Settings`}),GD.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)(qf,{value:r.id,onValueChange:e=>We({settingsMachine:e,settingsAccount:null}),children:[(0,W.jsx)(Yf,{className:`mb-1 w-40 sm:w-full`,children:(0,W.jsx)(Jf,{})}),(0,W.jsx)(Xf,{children:t.machines.map(e=>(0,W.jsxs)(Zf,{value:e.id,children:[(0,W.jsx)(jd,{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)(jd,{icon:r.icon}),(0,W.jsx)(`span`,{className:`truncate`,children:r.name})]}),KD.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:()=>We({settingsAccount:null,settingsEditedMachine:null}),children:n}),(0,W.jsx)(V,{icon:Tr,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)(XD,{view:t,className:`ml-3`}),(0,W.jsx)(Xr,{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:bo})})})]}),(0,W.jsx)(ZD,{view:t})]})]})})}function YD(e){let t=QD(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:B(t===`claude`&&`size-4`,t===`codex`&&`size-[19px] shrink-0`,t===`opencode`&&`h-3.5`)})}),e.page===`Machine`?`General`:e.page]})}function XD(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)(pp,{className:e.className,checked:n.enabledProviders[r],onCheckedChange:e=>void bt(t.id,{...n,enabledProviders:{...n.enabledProviders,[r]:e}}),"aria-label":`Enable ${e.view.page}`})}function ZD(e){let t=k(e=>e.prefs),n=e.view.page,r=e.view.machine,i=e.view.config,a=e.view.system,o=KD.includes(n),[s,c]=(0,U.useState)(null),[l,u]=(0,U.useState)(0);return(0,W.jsxs)(W.Fragment,{children:[o&&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)(Ep,{prefs:t,onRestore:()=>c(`browser`)}),n===`Machine`&&r!==null&&i!==null&&a!==null&&(0,W.jsx)(Wp,{machine:r.id,config:i,platform:a.platform,defaultShell:a.defaultShell,claudeAccounts:r.claudeAccounts,codexAccounts:r.codexAccounts,openCode:r.openCode,onRestore:()=>c(`machine`)}),n===`Projects`&&r!==null&&a!==null&&(0,W.jsx)(SD,{machine:r.id,homeDir:a.homeDir}),o&&r===null&&(0,W.jsx)(`p`,{className:`text-muted-foreground text-sm`,children:`Add a machine to see its settings.`}),o&&r!==null&&(i===null||a===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)(wp,{prefs:t}),n===`Terminal`&&(0,W.jsx)(VD,{prefs:t}),n===`Notifications`&&(0,W.jsx)(fE,{prefs:t}),e.view.provider!==null&&r!==null&&i!==null&&a!==null&&(0,W.jsx)(ED,{machine:r.id,config:i,platform:a.platform,defaultClaudeBaseDir:a.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)(cE,{}),n===`Shortcuts`&&(0,W.jsx)(MD,{})]},l),(0,W.jsx)(lr,{open:s!==null,onOpenChange:e=>{e||c(null)},children:(0,W.jsxs)(Kn,{children:[(0,W.jsxs)(Er,{children:[(0,W.jsx)(Ln,{children:s===`browser`?`Restore browser defaults?`:`Restore machine defaults?`}),(0,W.jsx)(Pn,{children:s===`browser`?`All settings of this browser go back to their defaults.`:`All settings of ${r?.name} go back to their defaults.`})]}),(0,W.jsxs)(br,{children:[(0,W.jsx)(Jn,{children:`Cancel`}),(0,W.jsx)(rr,{variant:`destructive`,onClick:()=>{if(u(l+1),s===`browser`)D(T);else{if(r===null||i===null||a===null)throw Error(`Restoring machine defaults needs a connected machine`);bt(r.id,{...a.defaults,claudeAccounts:i.claudeAccounts,codexAccounts:i.codexAccounts})}},children:`Restore defaults`})]})]})})]})}function QD(e){return e===`Claude`?`claude`:e===`Codex`?`codex`:e===`OpenCode`?`opencode`:null}function $D(){let e=k(e=>e.settingsOpen),t=k(e=>e.settingsListing),n=qD(),r=n.machine;te(e,i);function i(){t?j(!1):n.subpage?We({settingsAccount:null,settingsEditedMachine:null}):We({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:()=>Ke(e),children:[(0,W.jsx)(YD,{page:e}),(0,W.jsx)(V,{icon:Tr,className:`text-muted-foreground ml-auto size-4`})]},e)}return(0,W.jsx)($r,{open:e,onOpenChange:j,children:(0,W.jsx)(ri,{children:(0,W.jsxs)(Yr,{"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:po,className:`text-foreground size-5`,strokeWidth:2})}),(0,W.jsxs)(ai,{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)(XD,{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)(xp,{title:`This browser`,children:GD.map(a)}),(0,W.jsxs)(xp,{title:`Machine`,children:[r!==null&&(0,W.jsxs)(Q,{label:`Machine`,children:[n.machines.length>1&&(0,W.jsxs)(qf,{value:r.id,onValueChange:e=>We({settingsMachine:e,settingsAccount:null}),children:[(0,W.jsx)(Yf,{className:`w-40`,children:(0,W.jsx)(Jf,{})}),(0,W.jsx)(Xf,{children:n.machines.map(e=>(0,W.jsxs)(Zf,{value:e.id,children:[(0,W.jsx)(jd,{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)(jd,{icon:r.icon}),r.name]})]}),KD.map(a)]})]}),!t&&(0,W.jsx)(ZD,{view:n})]})]})})})}function eO(){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)(iE,{actions:e=>(0,W.jsx)(H,{type:`submit`,className:`mt-4`,disabled:!e,children:`Connect`})})]})})}var tO=[`messages`,`steps`,`details`,`full`],nO={messages:`Messages`,steps:`Steps`,details:`Details`,full:`Everything`},rO=[{label:`Messages, plans and answers`,how:{messages:`Full text`,steps:`Full text`,details:`Full text`,full:`Full text`}},{label:`Commands`,how:{messages:null,steps:`One line each`,details:`Full command`,full:`Command and output`}},{label:`File edits`,how:{messages:null,steps:`File path`,details:`Path and diff`,full:`Diff and output`}},{label:`Tools, skills and web searches`,how:{messages:null,steps:`Name only`,details:`Inputs and search results`,full:`Inputs and outputs`}},{label:`Subagents and notices`,how:{messages:null,steps:`One line each`,details:`With compaction summaries`,full:`With compaction summaries`}},{label:`Thinking`,how:{messages:null,steps:null,details:`Full text`,full:`Full text`}},{label:`Todo lists`,how:{messages:null,steps:null,details:`Every step`,full:`Every step`}}];function iO(e){let t=e.session,n=nn(),[r,i]=(0,U.useState)(`steps`),[a,o]=(0,U.useState)(null);(0,U.useEffect)(()=>{z(t.machine,`sessions.export`,{sessionId:t.id,projectId:t.projectId}).then(o).catch(e=>{N(e),f(null)})},[t.machine,t.id,t.projectId]);function s(e){let n=t.title.toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``);yn(new Blob([e],{type:`text/markdown;charset=utf-8`}),`${n===``?`chat`:n}.md`),f(null)}return(0,W.jsx)(ei,{open:!0,onOpenChange:()=>f(null),children:(0,W.jsxs)(qr,{className:`gap-0 overflow-hidden p-0 sm:max-w-md`,"aria-describedby":void 0,children:[(0,W.jsx)(Jr,{className:`gap-1 px-6 pt-4 pr-12`,children:(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(Zr,{className:`text-base`,children:`Export to Markdown`}),a!==null&&a.context!==null&&(0,W.jsx)(`span`,{className:`text-muted-foreground rounded-full border px-2 py-0.5 text-xs tabular-nums`,children:ln(a.context.tokens)})]})}),(0,W.jsxs)(`div`,{className:`flex flex-col gap-3 px-6 pt-5 pb-6`,children:[(0,W.jsxs)(vl,{className:`relative flex h-5 w-full touch-none items-center select-none`,min:0,max:tO.length-1,step:1,value:[tO.indexOf(r)],onValueChange:e=>i(tO[e[0]]),children:[(0,W.jsx)(Tl,{className:`bg-muted relative h-1.5 grow overflow-hidden rounded-full`,children:(0,W.jsx)(Dl,{className:`bg-primary absolute h-full`})}),(0,W.jsx)(Pl,{"aria-label":`Detail`,className:`border-primary bg-background ring-ring/50 block size-4 rounded-full border-2 shadow-sm transition-shadow hover:ring-4 focus-visible:ring-4 focus-visible:outline-hidden`})]}),(0,W.jsx)(`div`,{className:`relative h-8 text-xs`,children:tO.map((e,t)=>(0,W.jsxs)(`button`,{type:`button`,className:B(`text-muted-foreground hover:text-foreground absolute top-0 flex cursor-pointer flex-col`,t===0&&`left-0 items-start`,t>0&&t<tO.length-1&&`-translate-x-1/2 items-center`,t===tO.length-1&&`right-0 items-end`,e===r&&`text-foreground font-medium`),style:t>0&&t<tO.length-1?{left:`calc(8px + (100% - 16px) * ${t/(tO.length-1)})`}:void 0,onClick:()=>i(e),children:[(0,W.jsx)(`span`,{children:nO[e]}),(0,W.jsx)(`span`,{className:`text-muted-foreground/70 font-normal tabular-nums`,children:a===null?`…`:`~${ln(aO(a.markdown[e]))}`})]},e))}),(0,W.jsx)(`ul`,{className:`mt-1 flex flex-col gap-1.5`,children:rO.map(e=>(0,W.jsxs)(`li`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(V,{icon:e.how[r]===null?zr:pr,className:B(`size-4 shrink-0`,e.how[r]===null&&`text-muted-foreground/50`,e.how[r]!==null&&`text-primary`),strokeWidth:2}),(0,W.jsx)(`span`,{className:B(`min-w-0 flex-1 truncate`,e.how[r]===null&&`text-muted-foreground/60`,e.how[r]!==null&&`text-foreground`),children:e.label}),(0,W.jsx)(`span`,{className:`text-muted-foreground shrink-0 text-xs`,children:e.how[r]??`Not included`})]},e.label))})]}),(0,W.jsxs)(ti,{className:`bg-muted/40 border-t px-6 py-4 sm:justify-between`,children:[(0,W.jsx)(H,{type:`button`,variant:`ghost`,onClick:()=>f(null),children:`Cancel`}),(0,W.jsxs)(`div`,{className:`flex gap-2`,children:[(0,W.jsxs)(H,{type:`button`,variant:`outline`,disabled:a===null||n.copied,onClick:()=>{a!==null&&n.copy(a.markdown[r])},children:[(0,W.jsx)(V,{icon:n.copied?Dr:Yn}),n.copied?`Copied`:`Copy`]}),(0,W.jsxs)(H,{type:`button`,disabled:a===null,onClick:()=>{a!==null&&s(a.markdown[r])},children:[(0,W.jsx)(V,{icon:ir}),`Export`]})]})]})]})})}function aO(e){return Math.round(e.length/4)}var oO=.5,sO=.8,cO=.6,lO=.45,uO=.3,dO=.25,fO=.25,pO=4,mO=new Set([`a`,`an`,`and`,`for`,`in`,`of`,`on`,`the`,`to`,`with`]),hO=/[\p{L}\p{N}]/u,gO=/\p{Ll}/u,_O=/\p{Lu}/u,vO=/\p{N}/u,yO=/\p{L}/u;function bO(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 xO(e){let t=/^"([^"]+)"$/.exec(e.trim())?.[1].trim();return t===void 0||t===``?null:t}function SO(e){let t=xO(e);return t===null?bO(e).replace(/^["'`]+|["'`]+$/g,``).split(/\s+/).filter(Boolean):[bO(t)]}function CO(e){return SO(e).some(e=>e.length>=3)}function wO(e,t){let n=e[t],r=e[t-1]??``,i=e[t+1]??``;return hO.test(n)&&(r===``||!hO.test(r)||gO.test(r)&&_O.test(n)||_O.test(r)&&_O.test(n)&&gO.test(i)||vO.test(r)!==vO.test(n))}function TO(e,t){return t>=e.length||!hO.test(e[t])||wO(e,t)}function EO(e,t){let n=t+1;for(;n<e.length&&hO.test(e[n])&&!wO(e,n);)n+=1;return n}function DO(e){return Array.from({length:e.length},(e,t)=>t).filter(t=>wO(e,t))}function OO(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 kO(e,t,n){for(let r of DO(e)){if(t[r]!==n[0])continue;let i=[],a=r,o=n;for(;o!==``&&a<t.length;){let n=EO(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&&!wO(e,a);)a+=1;else break}if(o===``&&i.length>1)return{score:cO,start:r,end:i[i.length-1].end,pieces:i}}return null}function AO(e,t,n){if(n.length<3||!yO.test(n))return null;let r=n.length<=pO;for(let i of DO(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&&hO.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)&&OO(n,t.slice(i,i+o),r&&o===n.length)){let e={start:i,end:i+o};return{score:lO,...e,pieces:[e]}}}return null}function jO(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(wO(r,n)){let e=TO(r,i.end)?1:sO;if((a===null||e>a.score)&&(a={score:e,...i,pieces:[i]}),e===1)return a}else e.midWord&&t.length>=pO&&a===null&&(a={score:uO,...i,pieces:[i]})}if(a!==null&&a.score>uO)return a;let o=n.primary?kO(r,i,t):null;return o===null?n.typos?AO(r,i,t)??a:a:o}function MO(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 NO(e,t){let n=[];for(let r=e.indexOf(t);r!==-1;r=e.indexOf(t,r+1)){let i=r+t.length,a=hO.test(t[0])&&hO.test(e[r-1]??``),o=hO.test(t[t.length-1])&&hO.test(e[i]??``);!a&&!o&&n.push({start:r,end:i})}return MO(n)}function PO(e,t){let n=NO(e.folded,t);return n.length===0?null:{score:1,...n[0],pieces:n}}function FO(e,t,n){let r=SO(e);if(r.length===0)return null;let i=xO(e)!==null,a=t.filter(e=>e.value!==``).map(e=>({...e,source:e.value,folded:bO(e.value)})),o=r.some(e=>!mO.has(e)),s=[],c=0,l=0,u=!0;for(let e of r){let t=0,r=!1;for(let[o,c]of a.entries()){let a=i?PO(c,e):jO(c,e,{primary:o===0,typos:n});a!==null&&(o===0&&s.push(...a.pieces),a.score>=sO&&c.weight>fO&&(r=!0),t=Math.max(t,a.score*c.weight))}if(t===0){if(o&&mO.has(e))continue;return null}u&&=r,c+=t,l+=1}let d=a.at(0)?.folded??``,f=r.join(` `),p=d===f?oO:r.length>1&&d.includes(f)?dO:0;return{quality:c/l+p,strong:u,ranges:MO(s)}}function IO(e,t){let n=bO(t);return xO(e)===null?MO(SO(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})):NO(n,SO(e)[0])}var LO=.6,RO=.25,zO=.6,BO=8,VO=3,HO=18144e5,UO=32,WO=12096e5,GO=2.5;function KO(e){return 2**(-Math.max(0,e)/WO)}function qO(e,t){let n=KO(t-e.updatedAt),r=e.opens===null?0:e.opens.score*KO(t-e.opens.openedAt);return Math.min(GO,1+n+.5*Math.log2(1+r))}function JO(e){return SO(e).join(` `).slice(0,UO).trim()}function YO(e,t,n){let r=JO(t),i=(e.opens?.picks??[]).filter(e=>n-e.at<=HO&&(e.query===r||r.length>=VO&&e.query.startsWith(r)));return Math.max(0,...i.map(e=>e.at))}function XO(e,t,n){let r=FO(t,[{value:e.title,weight:1,midWord:!0},{value:e.branch??``,weight:zO,midWord:!1},{value:e.projectName??``,weight:RO,midWord:!1},{value:e.machineName??``,weight:RO,midWord:!1}],n);if(r!==null)return r;let i=t.trim().toLowerCase();return i.length>=BO&&e.id.toLowerCase().includes(i)?{quality:LO,strong:!0,ranges:[]}:null}function ZO(e){return e>=1.5?3:e>=.7?2:+(e>=.4)}function QO(e,t,n,r){function i(i){return e.flatMap(e=>{let a=t(e),o=XO(a,n,i);return o===null?[]:[{item:e,match:o,picked:YO(a,n,r),score:o.quality*qO(a,r)}]})}let a=i(!1);return[...a.some(e=>e.match.strong)?a:i(!0)].sort((e,t)=>ZO(t.match.quality)-ZO(e.match.quality)||t.picked-e.picked||t.score-e.score).map(e=>({item:e.item,ranges:e.match.ranges}))}function $O(e){return Math.max(e.updatedAt,e.opens?.openedAt??0)}function ek(e,t,n){return FO(e,[{value:t,weight:1,midWord:!0},{value:n,weight:zO,midWord:!1}],!1)}function tk(e,t,n,r){return e.flatMap(e=>{let n=t(e);return n===void 0?[]:[{match:e,subject:n}]}).sort((e,t)=>nk(e.match,t.match)||YO(t.subject,n,r)-YO(e.subject,n,r)||qO(t.subject,r)-qO(e.subject,r)).map(e=>e.match)}function nk(e,t){return t.quality-e.quality||Number(t.author===`user`)-Number(e.author===`user`)}function rk(e,t,n){let r=k(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 R().machines.filter(e=>e.status===`online`))z(t.id,`sessions.searchable`,void 0).then(n=>{e&&a(e=>ik(e,{machine:t.id,sessions:n.sessions.map(e=>({...e,machine:t.id})),failed:ak(n.failed)}))}).catch(()=>{e&&a(e=>ik(e,{machine:t.id,sessions:[],failed:[t.name]}))});return()=>{e=!1}},[c]),(0,U.useEffect)(()=>{if(t.startsWith(`>`)||!CO(t))return;let e=!0;for(let n of R().machines.filter(e=>e.status===`online`))z(n.id,`sessions.searchMessages`,{query:t}).then(r=>{e&&s(e=>ik(e,{machine:n.id,query:t,matches:r.matches.map(e=>({...e,machine:n.id})),failed:ak(r.failed)}))}).catch(()=>{e&&s(e=>ik(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(`>`)&&CO(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 ik(e,t){return[...e.filter(e=>e.machine!==t.machine),t]}function ak(e){return e.map(e=>rn[e])}var ok=20,sk=12,ck=10;function lk(){let e=k(e=>e.paletteOpen);return(0,W.jsx)(ei,{open:e,onOpenChange:u,children:(0,W.jsxs)(qr,{showCloseButton:!1,className:`top-[20%] translate-y-0 gap-0 overflow-hidden p-0 sm:max-w-xl`,children:[(0,W.jsx)(Zr,{className:`sr-only`,children:`Search threads`}),(0,W.jsx)(uk,{})]})})}function uk(){let e=k(e=>e.selection),t=k(e=>e.machines),n=k(e=>e.projects),[r,i]=(0,U.useState)(``),[a]=Fr(r,300),[o,s]=(0,U.useState)(`all`),[c,l]=(0,U.useState)(null),[d]=(0,U.useState)(()=>Date.now()),f=(0,U.useRef)(null),p=(0,U.useRef)(null),m=r.startsWith(`>`),h=m?r.slice(1):r,g=rk(r,a,o),_=g.threadResults,v=g.reachable,y=t.find(e=>e.id===o),b=(0,U.useMemo)(()=>_.filter(e=>v.split(` `).includes(e.machine)).flatMap(e=>e.sessions).map(e=>({thread:e,subject:mk(e,t,n)})),[_,v,t,n]),x=new Map(b.map(e=>[P(e.thread.machine,e.thread.id),e.subject])),S=(0,U.useMemo)(()=>h.trim()===``?[]:QO(b,e=>e.subject,h,d).slice(0,ok).map(e=>({item:e.item.thread,ranges:e.ranges})),[b,h,d]),C=(0,U.useMemo)(()=>[...b].sort((e,t)=>$O(t.subject)-$O(e.subject)).slice(0,sk).map(e=>({item:e.thread,ranges:[]})),[b]),w=h.trim()===``?C:S,T=[...e===null?[]:[{key:`new`,label:`New thread`,place:{machine:e.machine,projectId:e.projectId},detail:gk(e.machine,e.projectId,n),run:()=>Tt(e.machine,e.projectId)}],{key:`accounts`,label:`Manage accounts`,detail:``,place:null,run:()=>Ke(jt[R().settings.provider])},{key:`settings`,label:`Settings`,detail:`Theme, notifications, keyboard shortcuts`,place:null,run:()=>j(!0)}].flatMap(e=>{let t={...e,section:`Actions`,labelRanges:[],detailRanges:[],branch:``,updatedAt:null};if(h.trim()===``)return[t];let n=ek(h,e.label,e.detail);return n===null?[]:[{...t,labelRanges:n.ranges}]}),E=new Set(S.map(e=>P(e.item.machine,e.item.id))),D=m?[]:w.map(e=>{let t=e.item,r=h.trim()!==``&&t.branch!==null?` | ${t.branch}`:``;return{key:P(t.machine,t.id),section:h.trim()===``?`Recent`:`Threads`,label:t.title,labelRanges:e.ranges,detail:hk(t,n),detailRanges:[],branch:r,updatedAt:t.updatedAt,place:{machine:t.machine,projectId:t.projectId},run:()=>Ie({machine:t.machine,projectId:t.projectId,sessionId:t.id},h.trim()===``?null:h)}}),O=m?[]:tk(g.messages.filter(e=>!E.has(P(e.machine,e.sessionId))),e=>x.get(P(e.machine,e.sessionId)),h,d).slice(0,ck).flatMap(e=>{let t=b.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:${P(e.machine,e.sessionId)}`,section:`In messages`,label:t.title,labelRanges:[],detail:n,detailRanges:IO(h,n),branch:``,updatedAt:t.updatedAt,place:{machine:t.machine,projectId:t.projectId},run:()=>Ie({machine:t.machine,projectId:t.projectId,sessionId:t.id},h)}]}),A=[...T,...D,...O],M=Math.min(Math.max(0,A.findIndex(e=>e.key===c)),A.length-1);(0,U.useLayoutEffect)(()=>{f.current?.querySelector(`[data-active="true"]`)?.scrollIntoView({block:`nearest`})},[M]);function ee(e){u(!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:cr,className:`text-muted-foreground size-4 shrink-0`}),(0,W.jsx)(`input`,{ref:p,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;A.length>0&&l(A[(M+t+A.length)%A.length].key)}e.key===`Enter`&&M>=0&&(e.preventDefault(),ee(A[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)(fn,{children:[(0,W.jsx)(dr,{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:[y!==void 0&&(0,W.jsx)(jd,{icon:y.icon,className:`size-3 shrink-0`}),(0,W.jsx)(`span`,{className:`truncate`,children:y?.name??`All machines`}),(0,W.jsx)(V,{icon:jr,className:`size-3 shrink-0`})]})}),(0,W.jsx)(vn,{align:`end`,className:`w-56`,onCloseAutoFocus:e=>{e.preventDefault(),p.current?.focus()},children:(0,W.jsxs)(kn,{value:o,onValueChange:e=>{s(e),l(null)},children:[(0,W.jsx)(mn,{value:`all`,children:`All machines`}),t.map(e=>(0,W.jsxs)(mn,{value:e.id,disabled:e.status!==`online`,children:[(0,W.jsx)(jd,{icon:e.icon,className:`size-3.5 shrink-0`}),(0,W.jsx)(`span`,{className:`min-w-0 truncate`,children:pk(e)})]},e.id))]})})]})]}),(0,W.jsxs)(`div`,{ref:f,className:`max-h-96 overflow-y-auto p-1`,children:[A.length===0&&!g.searching&&(0,W.jsx)(`p`,{className:`text-muted-foreground px-3 py-6 text-center text-xs`,children:`Nothing matches.`}),A.map((e,n)=>(0,W.jsxs)(`div`,{children:[e.section!==A[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:B(`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)(fk,{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)(dk,{id:e.place.machine,machines:t}),(0,W.jsxs)(`span`,{className:`min-w-0 truncate`,children:[(0,W.jsx)(fk,{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:Qn(e.updatedAt)})]})]})]},e.key)),g.searching&&(0,W.jsx)(`p`,{className:`text-muted-foreground px-2.5 py-2 text-xs`,children:`Searching messages…`})]}),g.failures.length>0&&(0,W.jsxs)(`p`,{className:`text-muted-foreground border-t px-4 py-2 text-xs`,children:[`Couldn't search `,g.failures.join(`, `)]})]})}function dk(e){let t=e.machines.find(t=>t.id===e.id);return(0,W.jsx)(jd,{icon:t?.icon??null,className:`size-3 shrink-0`})}function fk(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 pk(e){return e.status===`online`?e.name:e.status===`unpaired`?`${e.name} · needs pairing`:`${e.name} · offline`}function mk(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 hk(e,t){return`${e.status===`minimized`?`Minimized · `:``}${gk(e.machine,e.projectId,t)}`}function gk(e,t,n){return t===`no-project`?`Chat`:n.find(n=>n.machine===e&&n.id===t)?.name??``}function _k(e){let t=e.session,[n,r]=(0,U.useState)(!1),i=k(e=>e.generatingTitles.includes(P(t.machine,t.id))),a=k(e=>Ct(e,t.machine,t.projectId)?.scratch===!0),o=e.context?Fn:wn,s=e.context?zn:On;return(0,W.jsxs)(W.Fragment,{children:[t.status!==`active`&&(0,W.jsxs)(o,{onSelect:()=>void Se(t.machine,t.id,{status:`active`}),children:[(0,W.jsx)(V,{icon:t.status===`pinned`?os:cs}),t.status===`pinned`?`Unpin`:`Activate`]}),t.status!==`inactive`&&(0,W.jsxs)(o,{onSelect:e.onDeactivate,children:[(0,W.jsx)(V,{icon:Ds}),`Done`]}),t.status!==`snoozed`&&(0,W.jsxs)(o,{onSelect:()=>void Se(t.machine,t.id,{status:`snoozed`}),children:[(0,W.jsx)(V,{icon:Ms}),`Snooze`]}),t.status!==`minimized`&&(0,W.jsxs)(o,{onSelect:()=>void Se(t.machine,t.id,{status:`minimized`}),children:[(0,W.jsx)(V,{icon:ts}),`Minimize`]}),t.status!==`pinned`&&(0,W.jsxs)(o,{onSelect:()=>void Se(t.machine,t.id,{status:`pinned`}),children:[(0,W.jsx)(V,{icon:ss}),`Pin`]}),(0,W.jsx)(s,{}),(0,W.jsxs)(o,{disabled:i,onSelect:()=>void $e(t),children:[(0,W.jsx)(V,{icon:no}),`Refresh title`]}),(0,W.jsxs)(o,{onSelect:e.onRename,children:[(0,W.jsx)(V,{icon:as}),`Rename`]}),(0,W.jsxs)(o,{onSelect:()=>f(t),children:[(0,W.jsx)(V,{icon:ir}),`Export`]}),a&&(0,W.jsxs)(o,{onSelect:()=>Fs(t.machine,t.projectId,{scratch:!1,name:t.title}).catch(N),children:[(0,W.jsx)(V,{icon:Gn}),`Turn into project`]}),(0,W.jsxs)(o,{variant:`destructive`,title:`Also removes it from ${rn[t.provider]}`,onSelect:e=>{n?Ve(t.machine,t.id,t.projectId):(e.preventDefault(),r(!0))},children:[(0,W.jsx)(V,{icon:Mo}),n?e.mobile?`Tap again to delete`:`Click again to delete`:`Delete`]})]})}function vk(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:vs,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:hs,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:go,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:Do,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:xr,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:xr,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:wo,className:`size-4 shrink-0`})}):null}function yk(e){let t=k(t=>t.generatingTitles.includes(P(e.session.machine,e.session.id)));return(0,W.jsx)(`span`,{className:B((t||e.awaitingTitle)&&`text-shimmer`),children:e.session.title})}var bk=`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 xk(e){let t=e.session,n=Ns(t.machine,t.projectId),r=k(e=>L(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(){Ue(t.machine,t.id,e.scope)}function g(){f?s(!0):h()}let _=(0,W.jsx)(lr,{open:o,onOpenChange:s,children:(0,W.jsxs)(Kn,{children:[(0,W.jsxs)(Er,{children:[(0,W.jsx)(Ln,{children:`Stop running work?`}),(0,W.jsx)(Pn,{children:`The agent or background tasks are running. Do you really want to stop them?`})]}),(0,W.jsxs)(br,{children:[(0,W.jsx)(Jn,{children:`Cancel`}),(0,W.jsx)(rr,{variant:`destructive`,onClick:h,children:`Stop and Mark Done`})]})]})}),v=e.saved&&(0,W.jsxs)(fn,{children:[(0,W.jsx)(dr,{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:Po,className:`size-3.5`})})}),(0,W.jsx)(vn,{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)(_k,{session:t,context:!1,mobile:!1,onDeactivate:g,onRename:()=>a(t.title)})})]}),y=(0,W.jsx)(Xn,{className:`w-44`,onCloseAutoFocus:e=>{c.current!==null&&(e.preventDefault(),c.current.focus(),c.current.select())},children:(0,W.jsx)(_k,{session:t,context:!0,mobile:!1,onDeactivate:g,onRename:()=>a(t.title)})}),b=i===null?(0,W.jsx)(`span`,{className:B(`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)(yk,{session:t,awaitingTitle:!e.saved})}):(0,W.jsx)(`form`,{className:`min-w-0 flex-1`,onSubmit:e=>{e.preventDefault();let n=i.trim();a(null),n!==``&&n!==t.title&&Se(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`})}),x=B(e.selected&&`bg-sidebar-row-active text-sidebar-foreground`,m&&`text-sidebar-muted-foreground/75 hover:bg-sidebar-row-hover hover:text-sidebar-foreground has-[[data-state=open]]:bg-sidebar-row-hover has-[[data-state=open]]:text-sidebar-foreground`,!e.selected&&!m&&`text-sidebar-foreground hover:bg-sidebar-row-hover has-[[data-state=open]]:bg-sidebar-row-hover bg-transparent`);return e.slim?(0,W.jsxs)(`li`,{className:`list-none`,children:[(0,W.jsxs)(ar,{children:[(0,W.jsx)(Wn,{asChild:!0,disabled:!e.saved,children:(0,W.jsxs)(`div`,{role:`button`,tabIndex:0,className:B(bk,x,`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 group-has-[[data-state=open]]/sidebar-row:opacity-100 group-has-[[data-state=open]]/sidebar-row:grayscale-0`,children:(0,W.jsx)(zs,{machine:t.machine,projectId:t.projectId})}),(0,W.jsx)(`span`,{className:`group-any-hover/sidebar-row:mask-r-from-[calc(100%-2rem)] group-any-hover/sidebar-row:mask-r-to-[calc(100%-0.5rem)] flex min-w-0 flex-1 group-has-[[data-state=open]]/sidebar-row:mask-r-from-[calc(100%-2rem)] group-has-[[data-state=open]]/sidebar-row:mask-r-to-[calc(100%-0.5rem)]`,children:b}),(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 group-has-[[data-state=open]]/sidebar-row:opacity-0`,children:Qn(t.updatedAt)}),(0,W.jsxs)(`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,e.saved&&(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:`Activate`,"aria-label":`Activate`,onClick:e=>{e.stopPropagation(),Se(t.machine,t.id,{status:`active`})},children:(0,W.jsx)(V,{icon:cs,className:`size-3.5`})})]})]})]})}),y]}),_]}):(0,W.jsxs)(`li`,{className:`list-none py-0.5`,children:[(0,W.jsxs)(ar,{children:[(0,W.jsx)(Wn,{asChild:!0,disabled:!e.saved,children:(0,W.jsxs)(`div`,{role:`button`,tabIndex:0,className:B(bk,x,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:`group-any-hover/sidebar-row:mask-r-from-[calc(100%-4.5rem)] group-any-hover/sidebar-row:mask-r-to-[calc(100%-2.5rem)] px-(--sidebar-row-content-inset) py-(--sidebar-content-inset) group-has-[[data-state=open]]/sidebar-row:mask-r-from-[calc(100%-4.5rem)] group-has-[[data-state=open]]/sidebar-row:mask-r-to-[calc(100%-2.5rem)]`,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`}),b,(0,W.jsx)(vk,{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)(jd,{icon:r,className:`size-3 shrink-0`}),(0,W.jsxs)(`span`,{className:B(`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===`pinned`&&(0,W.jsx)(V,{icon:ss,className:`size-3 shrink-0`}),t.status===`snoozed`&&(0,W.jsx)(V,{icon:Ms,className:`size-3 shrink-0`}),(0,W.jsx)(`span`,{className:`shrink-0 tabular-nums`,children:Qn(t.updatedAt)})]})]}),e.saved&&(0,W.jsxs)(`div`,{className:`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 flex-col items-end py-(--sidebar-content-inset) pr-1.5 opacity-0 transition-opacity has-[[data-state=open]]:pointer-events-auto has-[[data-state=open]]:opacity-100`,children:[(0,W.jsx)(`div`,{className:`flex h-6 items-center`,children:(0,W.jsx)(`button`,{className:`text-muted-foreground hover:text-foreground me-0.75 inline-flex size-5 cursor-pointer items-center justify-center transition-colors`,title:`Done`,"aria-label":`Done`,onClick:e=>{e.stopPropagation(),g()},children:(0,W.jsx)(V,{icon:Ds,strokeWidth:1.25,className:`size-5 scale-110`})})}),(0,W.jsx)(`div`,{className:`mt-1 flex h-5 items-center`,children:v})]})]})}),y]}),_]})}function Sk(e){let t=Ns(e.machine,e.projectId),n=k(t=>L(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:B(bk,`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:bs,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)(jd,{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 Ck=`/assets/ghostty-vt-CQAu1Gs5.wasm`,wk=Uint8Array,Tk=Uint16Array,Ek=Int32Array,Dk=new wk([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]),Ok=new wk([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]),kk=new wk([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),Ak=function(e,t){for(var n=new Tk(31),r=0;r<31;++r)n[r]=t+=1<<e[r-1];for(var i=new Ek(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}},jk=Ak(Dk,2),Mk=jk.b,Nk=jk.r;Mk[28]=258,Nk[258]=28;var Pk=Ak(Ok,0),Fk=Pk.b;Pk.r;for(var Ik=new Tk(32768),Lk=0;Lk<32768;++Lk){var Rk=(Lk&43690)>>1|(Lk&21845)<<1;Rk=(Rk&52428)>>2|(Rk&13107)<<2,Rk=(Rk&61680)>>4|(Rk&3855)<<4,Ik[Lk]=((Rk&65280)>>8|(Rk&255)<<8)>>1}for(var zk=(function(e,t,n){for(var r=e.length,i=0,a=new Tk(t);i<r;++i)e[i]&&++a[e[i]-1];var o=new Tk(t);for(i=1;i<t;++i)o[i]=o[i-1]+a[i-1]<<1;var s;if(n){s=new Tk(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[Ik[d]>>c]=l}else for(s=new Tk(r),i=0;i<r;++i)e[i]&&(s[i]=Ik[o[e[i]-1]++]>>15-e[i]);return s}),Bk=new wk(288),Lk=0;Lk<144;++Lk)Bk[Lk]=8;for(var Lk=144;Lk<256;++Lk)Bk[Lk]=9;for(var Lk=256;Lk<280;++Lk)Bk[Lk]=7;for(var Lk=280;Lk<288;++Lk)Bk[Lk]=8;for(var Vk=new wk(32),Lk=0;Lk<32;++Lk)Vk[Lk]=5;var Hk=zk(Bk,9,1),Uk=zk(Vk,5,1),Wk=function(e){for(var t=e[0],n=1;n<e.length;++n)e[n]>t&&(t=e[n]);return t},Gk=function(e,t,n){var r=t/8|0;return(e[r]|e[r+1]<<8)>>(t&7)&n},Kk=function(e,t){var n=t/8|0;return(e[n]|e[n+1]<<8|e[n+2]<<16)>>(t&7)},qk=function(e){return(e+7)/8|0},Jk=function(e,t,n){return(t==null||t<0)&&(t=0),(n==null||n>e.length)&&(n=e.length),new wk(e.subarray(t,n))},Yk=[`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`],Xk=function(e,t,n){var r=Error(t||Yk[e]);if(r.code=e,Error.captureStackTrace&&Error.captureStackTrace(r,Xk),!n)throw r;return r},Zk=function(e,t,n,r){var i=e.length,a=r?r.length:0;if(!i||t.f&&!t.l)return n||new wk(0);var o=!n,s=o||t.i!=2,c=t.i;o&&(n=new wk(i*3));var l=function(e){var t=n.length;if(e>t){var r=new wk(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=Gk(e,d,1);var v=Gk(e,d+1,3);if(d+=3,!v){var y=qk(d)+4,b=e[y-4]|e[y-3]<<8,x=y+b;if(x>i){c&&Xk(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=Hk,m=Uk,h=9,g=5;else if(v==2){var S=Gk(e,d,31)+257,C=Gk(e,d+10,15)+4,w=S+Gk(e,d+5,31)+1;d+=14;for(var T=new wk(w),E=new wk(19),D=0;D<C;++D)E[kk[D]]=Gk(e,d+D*3,7);d+=C*3;for(var O=Wk(E),k=(1<<O)-1,A=zk(E,O,1),D=0;D<w;){var j=A[Gk(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+Gk(e,d,3),d+=2,M=T[D-1]):y==17?(ee=3+Gk(e,d,7),d+=3):y==18&&(ee=11+Gk(e,d,127),d+=7);ee--;)T[D++]=M}}var te=T.subarray(0,S),ne=T.subarray(S);h=Wk(te),g=Wk(ne),p=zk(te,h,1),m=zk(ne,g,1)}else Xk(1);if(d>_){c&&Xk(0);break}}s&&l(f+131072);for(var re=(1<<h)-1,ie=(1<<g)-1,ae=d;;ae=d){var M=p[Kk(e,d)&re],oe=M>>4;if(d+=M&15,d>_){c&&Xk(0);break}if(M||Xk(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,N=Dk[D];se=Gk(e,d,(1<<N)-1)+Mk[D],d+=N}var ce=m[Kk(e,d)&ie],le=ce>>4;ce||Xk(3),d+=ce&15;var ne=Fk[le];if(le>3){var N=Ok[le];ne+=Kk(e,d)&(1<<N)-1,d+=N}if(d>_){c&&Xk(0);break}s&&l(f+131072);var ue=f+se;if(f<ne){var de=a-ne,fe=Math.min(ne,ue);for(de+f<0&&Xk(3);f<fe;++f)n[f]=r[de+f]}for(;f<ue;++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?Jk(n,0,f):n.subarray(0,f)},Qk=new wk(0),$k=function(e,t){return((e[0]&15)!=8||e[0]>>4>7||(e[0]<<8|e[1])%31)&&Xk(6,`invalid zlib data`),(e[1]>>5&1)==+!t&&Xk(6,`invalid zlib data: `+(e[1]&32?`need`:`unexpected`)+` dictionary`),(e[1]>>3&4)+2},eA=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 wk(32768),this.p=new wk(0),n&&this.o.set(n)}return e.prototype.e=function(e){if(this.ondata||Xk(5),this.d&&Xk(4),!this.p.length)this.p=e;else if(e.length){var t=new wk(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=Zk(this.p,this.s,this.o);this.ondata(Jk(n,t,this.s.b),this.d),this.o=Jk(n,this.s.b-32768),this.s.b=this.o.length,this.p=Jk(this.p,this.s.p/8|0),this.s.p&=7},e.prototype.push=function(e,t){this.e(e),this.c(t)},e}(),tA=function(){function e(e,t){eA.call(this,e,t),this.v=e&&e.dictionary?2:1}return e.prototype.push=function(e,t){if(eA.prototype.e.call(this,e),this.v){if(this.p.length<6&&!t)return;this.p=this.p.subarray($k(this.p,this.v-1)),this.v=0}t&&(this.p.length<4&&Xk(6,`invalid zlib data`),this.p=this.p.subarray(0,-4)),eA.prototype.c.call(this,t)},e}();function nA(e,t){return Zk(e.subarray($k(e,t&&t.dictionary),-4),{i:2},t&&t.out,t&&t.dictionary)}var rA=typeof TextDecoder<`u`&&new TextDecoder;try{rA.decode(Qk,{stream:!0})}catch{}function iA(e,t=`utf8`){return new TextDecoder(t).decode(e)}var aA=new TextEncoder;function oA(e){return aA.encode(e)}var sA=8192,cA=(()=>{let e=new Uint8Array(4),t=new Uint32Array(e.buffer);return!((t[0]=1)&e[0])})(),lA={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},uA=class e{buffer;byteLength;byteOffset;length;offset;lastWrittenByte;littleEndian;_data;_mark;_marks;constructor(t=sA,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=lA[t].BYTES_PER_ELEMENT*e,r=this.byteOffset+this.offset,i=this.buffer.slice(r,r+n);if(this.littleEndian===cA&&t!==`uint8`&&t!==`int8`){let e=new Uint8Array(this.buffer.slice(r,r+n));e.reverse();let i=new lA[t](e.buffer);return this.offset+=n,i.reverse(),i}let a=new lA[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 iA(this.readBytes(e))}decodeText(e=1,t=`utf8`){return iA(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(oA(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)}},dA=[];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;dA[e]=t}var fA=4294967295;function pA(e,t,n){let r=e;for(let e=0;e<n;e++)r=dA[(r^t[e])&255]^r>>>8;return r}function mA(e,t){return(pA(fA,e,t)^fA)>>>0}function hA(e,t,n){let r=e.readUint32(),i=mA(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 gA(e,t,n){for(let r=0;r<n;r++)t[r]=e[r]}function _A(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 vA(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 yA(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 bA(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]+xA(t[a-i],n[a],n[a-i])&255}}function xA(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 SA(e,t,n,r,i,a){switch(e){case 0:gA(t,n,i);break;case 1:_A(t,n,i,a);break;case 2:vA(t,n,r,i);break;case 3:yA(t,n,r,i,a);break;case 4:bA(t,n,r,i,a);break;default:throw Error(`Unsupported filter: ${e}`)}}var CA=new Uint16Array([255]),wA=new Uint8Array(CA.buffer)[0]===255;function TA(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);SA(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(wA)for(let t=0;t<e.length;t++)e[t]=EA(e[t]);return e}return c}function EA(e){return(e&255)<<8|e>>8&255}var DA=new Uint16Array([255]),OA=new Uint8Array(DA.buffer)[0]===255,kA=new Uint8Array;function AA(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=kA,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:gA(d,f,s);break;case 1:_A(d,f,s,o);break;case 2:vA(d,f,l,s);break;case 3:yA(d,f,l,s,o);break;case 4:bA(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(OA)for(let t=0;t<e.length;t++)e[t]=jA(e[t]);return e}return c}function jA(e){return(e&255)<<8|e>>8&255}var MA=Uint8Array.of(137,80,78,71,13,10,26,10);function NA(e){if(!PA(e.readBytes(MA.length)))throw Error(`wrong PNG signature`)}function PA(e){if(e.length<MA.length)return!1;for(let t=0;t<MA.length;t++)if(e[t]!==MA[t])return!1;return!0}var FA=`tEXt`,IA=0,LA=new TextDecoder(`latin1`);function RA(e){if(BA(e),e.length===0||e.length>79)throw Error(`keyword length must be between 1 and 79`)}var zA=/^[\u0000-\u00FF]*$/;function BA(e){if(!zA.test(e))throw Error(`invalid latin1 text`)}function VA(e,t,n){let r=HA(t);e[r]=UA(t,n-r.length-1)}function HA(e){for(e.mark();e.readByte()!==IA;);let t=e.offset;e.reset();let n=LA.decode(e.readBytes(t-e.offset-1));return e.skip(1),RA(n),n}function UA(e,t){return LA.decode(e.readBytes(t))}var WA={UNKNOWN:-1,GREYSCALE:0,TRUECOLOUR:2,INDEXED_COLOUR:3,GREYSCALE_ALPHA:4,TRUECOLOUR_ALPHA:6},GA={UNKNOWN:-1,DEFLATE:0},KA={UNKNOWN:-1,ADAPTIVE:0},qA={UNKNOWN:-1,NO_INTERLACE:0,ADAM7:1},JA={NONE:0,BACKGROUND:1,PREVIOUS:2},YA={SOURCE:0,OVER:1},XA=class extends uA{_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 tA((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=GA.UNKNOWN,this._filterMethod=KA.UNKNOWN,this._interlaceMethod=qA.UNKNOWN,this._colorType=WA.UNKNOWN,this._isAnimated=!1,this._numberOfFrames=1,this._numberOfPlays=0,this._frames=[],this._writingDataChunks=!1,this._inflatorResult=new Uint8Array,this.setBigEndian()}decode(){for(NA(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(NA(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 FA:VA(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?hA(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?hA(this,e+4,t):this.skip(4)}decodeIHDR(){let e=this._png;e.width=this.readUint32(),e.height=this.readUint32(),e.depth=ZA(this.readUint8());let t=this.readUint8();this._colorType=t;let n;switch(t){case WA.GREYSCALE:n=1;break;case WA.TRUECOLOUR:n=3;break;case WA.INDEXED_COLOUR:n=1;break;case WA.GREYSCALE_ALPHA:n=2;break;case WA.TRUECOLOUR_ALPHA:n=4;break;case WA.UNKNOWN:default:throw Error(`Unknown color type: ${t}`)}if(this._png.channels=n,this._compressionMethod=this.readUint8(),this._compressionMethod!==GA.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 WA.GREYSCALE:case WA.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 WA.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 WA.UNKNOWN:case WA.GREYSCALE_ALPHA:case WA.TRUECOLOUR_ALPHA:default:throw Error(`tRNS chunk is not supported for color type ${this._colorType}`)}}decodeiCCP(e){let t=HA(this),n=this.readUint8();if(n!==GA.DEFLATE)throw Error(`Unsupported iCCP compression method: ${n}`);let r=this.readBytes(e-t.length-2);this._png.iccEmbeddedProfile={name:t,profile:nA(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=AA({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 JA.NONE:break;case JA.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 JA.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 YA.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 YA.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!==KA.ADAPTIVE)throw Error(`Filter method ${this._filterMethod} not supported`);if(this._interlaceMethod===qA.NO_INTERLACE)this._png.data=AA({data:e,width:this._png.width,height:this._png.height,channels:this._png.channels,depth:this._png.depth});else if(this._interlaceMethod===qA.ADAM7)this._png.data=TA({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:JA.NONE,blendOp:YA.SOURCE,data:e}),this._inflator=new tA((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 ZA(e){if(e!==1&&e!==2&&e!==4&&e!==8&&e!==16)throw Error(`invalid bit depth: ${e}`);return e}function QA(e){let t=e.palette,n=e.depth;if(!t)throw Error(`Color palette is undefined.`);$A(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 $A(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 ej(e,t){return new XA(e,t).decode()}var tj=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)})),nj=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`}})),rj=t((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.decodeAsync=e.decode=e.Decoder=e.DecoderAsync=void 0;var t=tj(),n=nj();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})),ij=tj(),aj=rj(),oj=ij.PALETTE_ANSI_256.slice();oj.set(ij.PALETTE_VT340_COLOR);var sj=200,cj=new TextEncoder,lj=`offsite-image:`;async function uj(e){let t=await(0,aj.decodeAsync)(e,{fillColor:0,palette:oj});return!t.width||!t.height?null:createImageBitmap(new ImageData(new Uint8ClampedArray(t.data8),t.width,t.height))}function dj(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 fj(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=dj(r.get(`width`),t.width,t.cellWidth),s=dj(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 pj(e){let t=ej(e),{width:n,height:r,depth:i,channels:a}=t,o=n*r,s=new Uint8Array(o*4);if(t.palette){let e=QA(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 mj=class{core;images=[];nextImage=0;constructor(e){this.core=e}place(e,t,n){let r=`${lj}${this.nextImage++}`;this.core.write(cj.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>sj){let e=this.images.shift();e&&this.remove(e)}let a=Math.ceil(i.height/n);a>1&&this.core.write(cj.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()}},hj=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]),gj={userdata:0,writePty:1,bell:2,xtversion:4,size:6,deviceAttributes:8},_j=1,vj=-3,yj={width:0,height:4,data:8,length:12},bj=new TextDecoder,xj=new TextEncoder,Sj=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(bj.decode(r.subarray(n,i)))}static async load(){let t=await fetch(Ck);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]`,bj.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===vj&&i>0){let r=this.alloc(i),a=e(r,i,t),o=this.view(t,4).getUint32(0,!0);a===0&&(n=bj.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,gj.userdata,n);for(let t of[[gj.writePty,this.callbacks.writePty],[gj.deviceAttributes,this.callbacks.deviceAttributes],[gj.size,this.callbacks.size],[gj.bell,this.callbacks.bell],[gj.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,gj.xtversion,0),this.call(`ghostty_terminal_set`,e,gj.bell,0),this.call(`ghostty_terminal_set`,e,gj.size,0),this.call(`ghostty_terminal_set`,e,gj.deviceAttributes,0),this.call(`ghostty_terminal_set`,e,gj.writePty,0),this.call(`ghostty_terminal_set`,e,gj.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(hj),{env:{w:(e,t,n,r)=>{let i=this.hosts.get(t);i&&r!==0&&i.write(bj.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`,_j,n[5])!==0)throw Error(`libghostty-vt did not accept the PNG decoder`)}decodePng(e,t,n,r){let i;try{i=pj(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+yj.width,i.width,!0),o.setUint32(r+yj.height,i.height,!0),o.setUint32(r+yj.data,a,!0),o.setUint32(r+yj.length,i.data.length,!0),1}writeVersion(e,t){let n=xj.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)}},Cj=null;async function wj(){Cj=await Sj.load()}function Tj(){if(!Cj)throw Error(`libghostty-vt is not loaded`);return Cj}var Ej=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 Dj(e){return Ej.get(e)??0}var Oj=new Map([[`!`,`1`],[`@`,`2`],[`#`,`3`],[`$`,`4`],[`%`,`5`],[`^`,`6`],[`&`,`7`],[`*`,`8`],[`(`,`9`],[`)`,`0`],[`~`,"`"],[`_`,`-`],[`+`,`=`],[`{`,`[`],[`}`,`]`],[`|`,`\\`],[`:`,`;`],[`"`,`'`],[`<`,`,`],[`>`,`.`],[`?`,`/`]]),kj;function Aj(){return kj||(kj=globalThis.navigator?.keyboard?.getLayoutMap().catch(()=>void 0)??Promise.resolve(void 0),kj)}function jj(){return kj=void 0,Aj()}function Mj(e){return!e.shiftKey||e.ctrlKey||e.altKey||e.metaKey?0:+([...e.key].length===1)}function Nj(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=Oj.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 Pj=new Map([[`Backquote`,"`"],[`Minus`,`-`],[`Equal`,`=`],[`BracketLeft`,`[`],[`BracketRight`,`]`],[`Backslash`,`\\`],[`Semicolon`,`;`],[`Quote`,`'`],[`Comma`,`,`],[`Period`,`.`],[`Slash`,`/`],[`Space`,` `]]),Fj=[...`0123456789`].map(e=>[`Digit${e}`,e]),Ij=new Map([...Oj].map(e=>[e[1],e[0]]));function Lj(e){return/^Key[A-Z]$/u.test(e)?e[3].toLowerCase():/^Digit[0-9]$/u.test(e)?e[5]:Pj.get(e)}function Rj(e){return[...Pj,...Fj].every(t=>t[0]===`Space`||e.get(t[0])===t[1])}function zj(e,t){let n=t?.get(e.code),r=n&&[...n].length===1?n:Lj(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||!Rj(t)?null:Ij.get(r)??r}var Bj=new TextEncoder,Vj=new Map([[`[`,`\x1B`],[`m`,`\r`],[`i`,` `],[`@`,`\0`]]),Hj=class{runtime=Tj();terminal;keyEncoderSlot;keyEncoder;keyEventSlot;keyEvent;mouseEncoderSlot;mouseEncoder;mouseEventSlot;mouseEvent;scratch;keyboardLayoutMap;constructor(e){let t=this.runtime;this.terminal=e,this.loadKeyboardLayout(Aj()),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=Vj.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,Dj(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,Mj(e)),r.call(`ghostty_key_event_set_composing`,this.keyEvent,+!!e.isComposing),r.call(`ghostty_key_event_set_unshifted_codepoint`,this.keyEvent,Nj({code:e.code,key:s,shiftKey:e.shiftKey},this.keyboardLayoutMap));let l=Bj.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 zj(e,this.keyboardLayoutMap)}refreshKeyboardLayout(){this.loadKeyboardLayout(jj())}encodePaste(e){let t=this.runtime,n=Bj.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`}},Uj=26,Wj=30,Gj=1,Kj={imageId:1,placementId:2,isVirtual:3,xOffset:4,yOffset:5,columns:10,rows:11,z:12},qj={width:3,height:4,format:5,data:7,length:8},Jj={size:48,pixelWidth:4,pixelHeight:8,column:20,row:24,visible:28,sourceX:32,sourceY:36,sourceWidth:40,sourceHeight:44},Yj=new Map([[0,3],[1,4],[3,2],[4,1]]),Xj=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 Zj(e,t,n){let r=Array.from(e).slice(1,4).map(e=>Xj.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 Qj(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($j(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($j(i))}return t}function $j(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 eM(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 tM(e){let t=Tj(),n=t.alloc(16),r=t.call(`ghostty_terminal_get`,e,Uj,n);return t.free(n,16),r===0}var nM=class{runtime=Tj();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(Jj.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)??aM(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,Jj.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,Wj,this.scratch));let r=n.readPointer(this.scratch);n.check(`ghostty_kitty_graphics_get`,n.call(`ghostty_kitty_graphics_get`,r,Gj,this.iteratorSlot));let i=n.readPointer(this.iteratorSlot),a=[],o=[];for(;n.call(`ghostty_kitty_graphics_placement_next`,i);){let e=this.placementU32(i,Kj.imageId);if(this.placementData(i,Kj.isVirtual).getUint8(0)){o.push({imageId:e,placementId:this.placementU32(i,Kj.placementId),columns:this.placementU32(i,Kj.columns),rows:this.placementU32(i,Kj.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,Jj.size).fill(0);let s=n.view(this.info,Jj.size);s.setUint32(0,Jj.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(Jj.visible)!==0&&a.push({...this.image(t,e),z:this.placementData(i,Kj.z).getInt32(0,!0),column:s.getInt32(Jj.column,!0),row:s.getInt32(Jj.row,!0),xOffset:this.placementU32(i,Kj.xOffset),yOffset:this.placementU32(i,Kj.yOffset),width:s.getUint32(Jj.pixelWidth,!0),height:s.getUint32(Jj.pixelHeight,!0),source:{x:s.getUint32(Jj.sourceX,!0),y:s.getUint32(Jj.sourceY,!0),width:s.getUint32(Jj.sourceWidth,!0),height:s.getUint32(Jj.sourceHeight,!0)}})}if(o.length===0)return a;for(let i of Qj(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=eM(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,qj.data),r=this.imageData(e,qj.length);return{key:`${t}:${n}:${r}`,image:{width:this.imageData(e,qj.width),height:this.imageData(e,qj.height),format:this.imageData(e,qj.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 rM(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;iM(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 iM(e){return e<-1073741824?`belowBackground`:e<0?`belowText`:`aboveText`}function aM(e){let t=Yj.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 oM=8,sM=16,cM=0,lM=1,uM=2,dM=8,fM={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},pM={dirty:1,raw:2,cells:3},mM={raw:1,style:2,graphemesLength:3,graphemes:4,background:5,foreground:6,selected:7},hM={keys:0,values:20,graphemesLength:40,selected:44,background:48,foreground:52,written:56,size:60},gM={narrow:0,wide:1,spacerTail:2},_M={r:229,g:231,b:235},vM={r:0,g:0,b:0};function yM(e,t){return Math.floor((e*155+t*100)/255)}function bM(e,t){return{r:yM(e.r,t.r),g:yM(e.g,t.g),b:yM(e.b,t.b)}}function xM(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 SM(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 CM(e,t){let n=e.dataView();return{r:n.getUint8(t),g:n.getUint8(t+1),b:n.getUint8(t+2)}}function wM(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 TM(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 EM=class{runtime=Tj();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(hM.size);let t=e.dataView();[[mM.style,this.style],[mM.graphemesLength,this.cellQuery+hM.graphemesLength],[mM.selected,this.cellQuery+hM.selected],[mM.background,this.cellQuery+hM.background],[mM.foreground,this.cellQuery+hM.foreground]].forEach((e,n)=>{t.setUint32(this.cellQuery+hM.keys+n*4,e[0],!0),t.setUint32(this.cellQuery+hM.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(fM.cols,2),i=this.getRender(fM.rows,2),a=this.getRender(fM.dirty,4),o=this.getColor(fM.foreground,_M),s=this.getColor(fM.background,vM),c=this.getRender(fM.cursorHasValue,1)===0?o:this.getColor(fM.cursor,o),l=this.getRender(fM.cursorInViewport,1)!==0,u=this.getRender(fM.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},()=>SM(o,s)),isWrapContinuation:!1,wrapsToNext:!1})));let d=new Set;if(a!==0){this.palette=wM(n,e),n.check(`ghostty_render_state_get`,n.call(`ghostty_render_state_get`,this.state,fM.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,pM.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(fM.cursorX,2):-1,cursorY:l?this.getRender(fM.cursorY,2):-1,cursorVisible:u,cursorBlinking:this.getRender(fM.cursorBlinking,1)!==0,cursorStyle:this.getRender(fM.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,hM.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,pM.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,pM.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+hM.keys,this.cellQuery+hM.values,this.cellQuery+hM.written),t=a.dataView(),o=t.getUint32(this.cellQuery+hM.written,!0);o<3&&a.check(`ghostty_render_state_row_cells_get_multi`,e);let s=t.getUint32(this.cellQuery+hM.graphemesLength,!0),c=t.getUint8(this.cellQuery+hM.selected)!==0,u=o>=4?CM(a,this.cellQuery+hM.background):r,m=o===5?CM(a,this.cellQuery+hM.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,mM.graphemes,this.graphemes)===0&&(h=xM(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,mM.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+oM,!0)===lM){let e=_.getUint8(this.style+sM);e<8&&(m=this.palette[e+8]??m)}if(v(`inverse`)){let e=m;m=u,u=e}v(`faint`)&&(m=bM(m,u));let b=this.style+f.underline_color.offset,x=_.getUint32(b,!0),S=b+dM,C=null;h.codePointAt(0)===1109742&&(C=Zj(h,this.colorId(this.style+oM),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===lM?this.palette[_.getUint8(S)]:x===uM?CM(a,S):null,selected:c,placeholder:C})}for(;p.length<t;)p.push(SM(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?CM(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,mM.foreground,this.scratch)===0?CM(this.runtime,this.scratch):t}colorId(e){let t=this.runtime.dataView(),n=t.getUint32(e,!0);if(n===cM)return 0;if(n===lM)return t.getUint8(e+dM);if(n===uM){let t=CM(this.runtime,e+dM);return t.r<<16|t.g<<8|t.b}throw Error(`unknown style color tag ${n}`)}},DM=16,OM=589824,kM=381888,AM=5e7,jM=new TextDecoder;function MM(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 NM=class{encoder;kitty;runtime=Tj();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(kM/(8*(e+1)));a.setField(s,`GhosttyTerminalOptions`,`max_scrollback`,n===0?0:Math.min((Math.ceil(n/c)+1)*OM,AM)),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),!tM(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 EM,this.encoder=new Hj(this.terminal),this.kitty=new nM(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=MM(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?``:jM.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=jM.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:wM(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(DM),t=this.runtime.view(e,DM);t.setUint32(0,DM,!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,DM),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)),CM(this.runtime,this.scratch)}};function PM(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 FM=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=TM(e,i);PM(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(`
|
|
15
15
|
`).forEach((e,t)=>{PM(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)}},IM=new TextDecoder;function LM(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 RM(e){return Math.min(Math.max(e,0),100)}function zM(e){return IM.decode(Uint8Array.from(atob(e),e=>e.charCodeAt(0)))}function BM(e){return e===``?`s0`:[...e].filter(e=>`cpqs01234567`.includes(e)).join(``)}function VM(e){try{return zM(e)}catch(e){return console.warn(`invalid clipboard sequence`,e),null}}function HM(e,t,n){let r=Array.from(new TextEncoder().encode(e),e=>String.fromCharCode(e)).join(``);return`\x1b]52;${t};${btoa(r)}${n}`}function UM(e,t,n){let r=e===`10;?`?t.foreground:e===`11;?`?t.background:t.cursor;return`\x1b]${e.slice(0,2)};${LM(r)}${n}`}function WM(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]};${LM(a)}${n}`)}return i}function GM(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:RM(i)}:r===2||r===4?i<0?{state:r,value:t.value}:{state:r,value:RM(i||t.value)}:r===3?{state:r,value:t.value}:null}function KM(e,t){if(e.startsWith(`9;`)&&!/^9;\d+(;|$)/.test(e))return{title:``,body:IM.decode(t.subarray(2))};if(e.startsWith(`777;notify;`)){let e=IM.decode(t).split(`;`);return{title:e[2]??``,body:e.slice(3).join(`;`)}}return null}var qM=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=zM(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}}},JM=27,YM=7,XM=24,ZM=26,QM=33554432,$M=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===XM||i===ZM)this.state=`ground`,this.drop();else if(this.state===`ground`)i===JM&&(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===JM?`escape`:`ground`}else if(this.state===`osc`){if(i===YM){if(this.state=`ground`,this.append(e,n,r),t({type:`osc`,data:this.take(),terminator:`\x07`},r+1))return r+1;continue}i===JM&&(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===JM){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===JM&&(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>QM?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}},eN=`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(`.`),tN=[`0001`,`1000`,`0100`,`0010`,`0002`,`2000`,`0200`,`0020`,`0201`,`1020`,`0102`,`2010`],nN=`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(`.`),rN=[0,0,4,4],iN=[4,0,4,4],aN=[0,4,4,4],oN=[4,4,4,4],sN=[[[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]],[aN],[oN],[rN],[rN,aN,oN],[rN,oN],[rN,iN,aN],[rN,iN,oN],[iN],[iN,aN],[iN,aN,oN]],cN={9617:.25,9618:.5,9619:.75},lN={9581:[1,1],9582:[-1,1],9583:[-1,-1],9584:[1,-1]};function uN(e){return e>=9472&&e<=9547?eN[e-9472]:e>=9552&&e<=9580?nN[e-9552]:e>=9588&&e<=9599?tN[e-9588]:``}function dN(e){if(e.length!==1)return!1;let t=e.charCodeAt(0);return uN(t)!==``||lN[t]!==void 0||t>=9600&&t<=9631}function fN(e){return Math.max(1,Math.round(e.height/20))}function pN(e,t,n){let[r,i,a,o]=t,s=fN(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 mN(e,[t,n],r){let i=fN(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 hN(e,t,n,r){e.save(),e.setTransform(1,0,0,1,0,0),gN(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 gN(e,t,n){let r=uN(t);if(r!==``){pN(e,r,n);return}let i=lN[t];if(i!==void 0){mN(e,i,n);return}let a=cN[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 sN[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 _N(e){return`rgb(${e.r}, ${e.g}, ${e.b})`}function vN(e,t){return e.r===t.r&&e.g===t.g&&e.b===t.b}function yN(e,t){return Math.round(e*t)/t}function bN(e,t,n,r){let i=yN(e*n.width,r);return{left:i,width:yN(t*n.width,r)-i}}function xN(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 SN(e,t){return e.selected===t.selected&&vN(e.foreground,t.foreground)&&e.bold===t.bold&&e.italic===t.italic&&e.invisible===t.invisible}function CN(e,t){return`${e.italic?`italic`:`normal`} ${e.bold?700:400} ${t.fontSize}px ${t.fontFamily}`}function wN(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:yN((l-c)/2+s,i),faceWidth:a}}function TN(e){return/^[!-/:-@[-`{-~]$/.test(e)}function EN(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 DN(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=_N(n.background),t.fillRect(0,0,t.canvas.width,t.canvas.height),t.restore());function l(e){let t=e*r.height,n=yN(t,s);return{top:t,cellTop:n,cellHeight:yN(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=_N(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&&vN(o.cells[a].background,e.background);)a+=1;let{left:l,width:f}=bN(d,a,r,s);e.selected?(t.fillStyle=i.selectionBackground,t.fillRect(l,c,f,u)):vN(e.background,n.background)||(t.fillStyle=_N(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}=bN(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:_N(n.foreground);let a=e*r.width;if(dN(n.text)){hN(t,n.text,{left:a,top:c,width:r.width,height:r.height},s);continue}t.font=CN(n,i);let l=a+(r.width-r.faceWidth)/2,u=e,d=e+1;if(i.ligatures&&TN(n.text)){for(;u>e-3&&u>0&&TN(o.cells[u-1].text)&&SN(o.cells[u-1],n);)--u;for(;d<e+4&&d<o.cells.length&&TN(o.cells[d].text)&&SN(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=EN(e.hoveredLink,a,n);if(i.underline===0&&!i.strikethrough&&!i.overline&&!l)continue;let{left:f,width:p}=bN(n,n+1,r,s),m=u+d;t.fillStyle=_N(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&&xN(t,1,f,p,m):(i.underlineColor!==null&&(t.fillStyle=_N(i.underlineColor)),xN(t,i.underline,f,p,m))}}if(!a||!n.cursorVisible||n.cursorX<0||n.cursorY<0)return;let u=n.cursorY*r.height,d=yN(u,s),f=yN(u+r.height,s)-d,p=n.rowData[n.cursorY]?.cells,m=p?.[n.cursorX],h=p?.[n.cursorX+1]?.wide===gM.spacerTail?2:1,{left:g,width:_}=bN(n.cursorX,n.cursorX+h,r,s);t.fillStyle=_N(n.cursor),t.strokeStyle=_N(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,dN(m.text)?hN(t,m.text,{left:n.cursorX*r.width,top:u,width:r.width,height:r.height},s):(t.font=CN(m,i),t.fillText(m.text,n.cursorX*r.width+(r.width-r.faceWidth)/2,u+r.baseline))))}var ON=navigator.userAgent.includes(`Mac`),kN=500,AN=/https?:\/\/[^\s"'`<>]+/g;function jN(e){return e===0?1:e===1?3:e===2?2:null}function MN(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 NN=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:MN(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=TM(t,e);f+=n.text,p.push(...n.points)}for(let e of f.matchAll(AN)){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(EN(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=MN(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=jN(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)&&(ON?e.metaKey:e.ctrlKey)){e.preventDefault(),this.linkPointer=e.pointerId;return}let n=e.timeStamp-this.clicks.time<=kN&&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=MN(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)}},PN=[`\r`,`
|
|
16
|
-
`,``,``,``,``,`\x1B[99;5u`,`\x1B[100;5u`,`\x1B[111;5u`,`\x1B[122;5u`];function FN(e,t){return e.y<t.y||e.y===t.y&&e.x<t.x}var IN=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`&&PN.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(FN(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===gM.spacerTail&&--a.x;let o={x:t.cursorX,y:t.cursorY};if(FN(a,i)||FN(o,i))return null;let s=FN(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)}},LN=navigator.userAgent.includes(`Mac`),RN=navigator.userAgent.includes(`Windows`),zN=600,BN=1e3,VN=1e4,HN=new TextDecoder(`latin1`),UN=new TextDecoder;function WN(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 GN(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 KN(e){try{(await e)?.close()}catch(e){console.warn(`could not decode image`,e)}}var qN=class{element;cols=80;rows=24;canvas;input;context;core;scanner=new $M;handlers;observer;prompt;search;images;pointer;notifications=new qM;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 NM(Math.max(1,Math.floor(window.innerWidth/this.metrics.width)),this.rows,e.scrollback,t.onReply,t.onBell),this.prompt=new IN(this.core),this.search=new FM(this.core,()=>this.redraw()),this.images=new mj(this.core),this.pointer=new NN({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(HM(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:GN(e.fontFamily),ligatures:e.ligatures,cursorText:t.cursorText,selectionBackground:t.selectionBackground,selectionForeground:t.selectionForeground,matchBackground:t.palette[8],activeMatchBorder:t.palette[3]}}measure(){return wN(this.context,this.options.fontSize,this.appearance.fontFamily,this.options.lineHeight,window.devicePixelRatio||1)}applyTerminalOptions(){let e=this.options.colors;this.core.setColors({foreground:WN(e.foreground),background:WN(e.background),cursor:WN(e.cursor),palette:e.palette.map(WN)}),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(uj(e.data));let n=HN.decode(e.data);if(n.startsWith(`1337;File=`))return this.decodeImage(fj(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:BM(r[1]),terminator:e.terminator,generation:this.prompt.generation,epoch:this.epoch,atPrompt:this.prompt.shell===`prompt`}),!1;let a=VM(i);return a!==null&&this.handlers.onClipboard(a),!1}if(n===`10;?`||n===`11;?`||n===`12;?`)return t||this.handlers.onReply(UM(n,this.core.currentColors(),e.terminator)),!1;if(n.startsWith(`4;`)){if(!t)for(let t of WM(n,this.core.currentColors().palette,e.terminator))this.handlers.onReply(t);return!1}if(n===`9;4`||n.startsWith(`9;4;`)){let e=GM(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(UN.decode(e.data)):KM(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`),VN)});try{let r=await Promise.race([e,i]);r===`timeout`?(console.warn(`image decoding took too long, skipping the image`),KN(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()},BN));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);DN({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=>rM(this.context,a,e,this.metrics,i)}),rM(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()},zN))}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(!LN||!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)||LN&&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=RN&&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(LN?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((LN?e.metaKey&&r===`v`:e.ctrlKey&&e.shiftKey&&r===`v`||e.shiftKey&&!e.ctrlKey&&r===`insert`||i&&r===`v`)||LN&&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=()=>{LN&&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)}},JN=new Map,YN=new Map,XN=null,ZN=0;function QN(e){return wP().open&&DP()?.tabId===e&&!document.hidden&&document.hasFocus()}function $N(e){if(QN(e))return!1;let t=wP();return t.alerts.includes(e)||TP({alerts:[...t.alerts,e]}),!0}function eP(e){if(!$N(e)||YN.has(e))return;let t=JN.get(e);t!==void 0&&performance.now()-t<5e3||YN.set(e,window.setTimeout(()=>{YN.delete(e),QN(e)||(JN.set(e,performance.now()),nP(e,``,`Bell`))},500))}function tP(e,t,n){$N(e)&&(window.clearTimeout(YN.get(e)),YN.delete(e),JN.set(e,performance.now()),nP(e,t,n))}function nP(e,t,n){let r=AP(e);r&&Da(t||jP(r),n,{machine:SP(),project:r.projectId??`global`,tabId:e}).catch(e=>console.error(`could not show a notification`,e))}function rP(){let e=performance.now();if(e-ZN<150)return;ZN=e,XN??=new AudioContext,XN.state===`suspended`&&XN.resume();let t=XN.createOscillator(),n=XN.createGain(),r=XN.currentTime;t.frequency.value=880,n.gain.setValueAtTime(.1,r),n.gain.exponentialRampToValueAtTime(.001,r+.15),t.connect(n).connect(XN.destination),t.start(r),t.stop(r+.15)}function iP(e){return{alerts:wP().alerts.filter(t=>e(t)&&!QN(t))}}function aP(e){window.clearTimeout(YN.get(e)),YN.delete(e),JN.delete(e)}function oP(e){return e.key===`Enter`&&e.shiftKey&&!e.ctrlKey&&!e.altKey&&!e.metaKey}function sP(e){let t=new qN(xP(),{onData:t=>{wP().status===`active`&&LP(e,cP(t))},onReply:t=>{t===`\x1B[I`||t===`\x1B[O`?LP(e,t):RP(e,t)},onResize:(t,n)=>FP({type:`resize`,id:e,cols:t,rows:n}),onTitle:t=>TP({titles:{...wP().titles,[e]:t}}),onProgress:t=>TP({progress:{...wP().progress,[e]:t}}),onBell:()=>{let n=EP().behavior;n.bellSound&&rP(),n.bellFlash&&t.element.isConnected&&!document.hidden&&t.element.animate([{opacity:.4},{opacity:1}],{duration:200,easing:`ease-out`}),eP(e)},onNotify:(t,n)=>tP(e,t,n),onClipboard:PD,onClipboardRead:n=>{QN(e)&&FD(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=EP(),i=L(R(),SP()).system;if(i===null)throw Error(`the terminal machine is not connected`);let a=i.platform;if(wP().status===`active`&&r.behavior.modernizeShiftEnter&&oP(n)&&!t.isKittyKeyboard())return n.preventDefault(),t.beforeInput(`\x1B\r`),LP(e,`\x1B\r`),!1;if(wP().status===`active`&&r.behavior.pasteBrowserImages&&window.isSecureContext&&LD(n,a)&&!(It&&r.behavior.windowsCopyPaste&&n.ctrlKey)){n.preventDefault();let r=ID[a].data;return t.beforeInput(r),RD(SP(),t).then(t=>{t||LP(e,r)}).catch(t=>{BD(t),LP(e,r)}),!1}return!KP(n)||(n.preventDefault(),TP({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(),zD(SP(),t,n).catch(BD))},!0),t}function cP(e){if(!wP().ctrl||(TP({ctrl:!1}),e.length!==1))return e;let t=e.toUpperCase().charCodeAt(0);return t>=64&&t<=95?String.fromCharCode(t-64):e}function lP(){return{titles:{},progress:{},alerts:[],finding:null}}var uP=new TextEncoder,dP=new Map,fP=new Set,pP=new Set,mP={status:`connecting`,failure:null,loaded:!1,open:!1,instance:null,layout:{tabs:[],active:{}},ctrl:!1,...lP()},hP=null,gP=null,_P=!1;async function vP(){d(),NP(),nt.history.subscribe(({action:e})=>{(e.type===`PUSH`||e.type===`REPLACE`)&&d(),NP()});try{await Promise.all([wj(),vp(EP())]),TP({loaded:!0})}catch(e){console.error(`could not start the terminal`,e),TP({failure:Ht(e)});return}ht({close:e=>{e===gP&&TP({status:`connecting`})},terminal:(e,t)=>{e===gP&&WP(t)},frame:(e,t)=>{e===gP&&UP(t)}}),yP(),nt.history.subscribe(yP),nt.history.subscribe(tF),document.addEventListener(`visibilitychange`,()=>TP({})),window.addEventListener(`focus`,()=>{TP({}),hP!==null&&qP(hP,JP(hP))}),window.addEventListener(`blur`,()=>TP({})),`serviceWorker`in navigator&&navigator.serviceWorker.addEventListener(`message`,e=>{e.data.type===`select`&&PP(e.data.machine,e.data.project,e.data.tabId)});let e=R().prefs,t=bP();i(()=>{yP();let n=R().prefs,r=bP(),i=n.theme!==e.theme||n.terminal!==e.terminal||r!==t;e=n,t=r,i&&XP()}),ZP()}function yP(){let e=O()??R().selection?.machine??null;if(e!==gP&&(gP!==null&&_P&&FP({type:`detach`}),GP([]),fP.clear(),gP=e,_P=!1,TP({status:`connecting`,instance:null,layout:{tabs:[],active:{}},...lP()})),gP===null)return;let t=L(R(),gP).status===`online`;t&&!_P&&(_P=!0,FP({type:`attach`})),t||(_P=!1)}function bP(){return gP===null?null:L(R(),gP).config?.terminal.behavior.terminalIdentity??null}function xP(){if(gP===null)throw Error(`the terminal has no machine`);let e=L(R(),gP);if(e.config===null||e.system===null)throw Error(`${e.name} is not connected`);return yp(EP(),e.config.terminal.behavior.terminalIdentity)}function SP(){if(gP===null)throw Error(`the terminal has no machine`);return gP}function CP(e){return pP.add(e),()=>{pP.delete(e)}}function wP(){return mP}function TP(e){mP={...mP,...e},mP={...mP,...iP(e=>dP.has(e))};for(let e of pP)e()}function EP(){return R().prefs.terminal}function DP(){let e=O()===null?R().selection?.projectId:A();return e===void 0?null:{view:e,tabs:OP(mP.layout,e),tabId:mP.layout.active[e]??null}}function OP(e,t){return e.tabs.filter(e=>kP(e)===t)}function kP(e){return e.projectId??`global`}function AP(e){return mP.layout.tabs.find(t=>t.id===e)}function jP(e){return(e.customName??mP.titles[e.id])||`Terminal`}function MP(e){e?M({bottom:`terminal`}):l(`overlay`,()=>M({bottom:void 0}))}function NP(){let e=se().bottom===`terminal`||O()!==null;e!==mP.open&&TP({open:e})}function PP(e,t,n){if(t===`global`)QP(e,Ae);else{let n=R().selection;(n?.machine!==e||n.projectId!==t)&&Ie({machine:e,projectId:t,sessionId:null}),MP(!0)}IP(e,{type:`select`,view:t,tabId:n})}function FP(e){gP!==null&&IP(gP,e)}function IP(e,t){it(e)&&z(e,`terminal`,t).catch(e=>console.error(`terminal request failed`,e))}function LP(e,t){gP!==null&&Ye(gP,0,e,typeof t==`string`?uP.encode(t):t)}function RP(e,t){gP!==null&&Ye(gP,1,e,uP.encode(t))}function zP(e,t,n,r){JP(e).find(t,n,r)}function BP(e,t){return JP(e).onFindResults(t)}function VP(e){let t=JP(e);t.clearFind(),TP({finding:null}),t.focus()}function HP(){TP({ctrl:!mP.ctrl})}function UP(e){let t=dP.get(e.id);if(!t)return;let n=e.kind===3,r=n&&fP.delete(e.id);r&&t.reset(),t.write(e.data,n),r&&fP.size===0&&TP({status:`active`})}function WP(e){let t=e.type===`active`&&e.instance!==mP.instance;if(t&&GP([]),GP(e.layout.tabs),e.type===`active`){fP.clear(),dP.forEach((e,t)=>{fP.add(t),e.element.isConnected&&qP(t,e)}),TP({...t&&{instance:e.instance,...lP()},status:fP.size===0?`active`:`connecting`,layout:e.layout}),tF();return}for(let e of fP)dP.has(e)||fP.delete(e);let n=R().selection?.projectId,r=n!==void 0&&OP(mP.layout,n).length>0&&OP(e.layout,n).length===0;TP({status:fP.size===0?`active`:`connecting`,layout:e.layout}),r&&mP.open&&MP(!1),tF()}function GP(e){let t=new Set(e.map(e=>e.id));dP.forEach((e,n)=>{t.has(n)||(e.dispose(),dP.delete(n),aP(n))});for(let e of t)dP.has(e)||dP.set(e,sP(e))}function KP(e){return e.key.toLowerCase()===`f`?Rt?e.metaKey&&!e.ctrlKey&&!e.altKey:e.ctrlKey&&e.shiftKey&&!e.altKey&&!e.metaKey:!1}function qP(e,t){FP({type:`resize`,id:e,cols:t.cols,rows:t.rows})}function JP(e){let t=dP.get(e);if(!t)throw Error(`terminal ${e} does not exist`);return t}function YP(e,t){let n=JP(e);t.append(n.element),n.fit();for(let e of dP.values())e.presize(n.cols,n.rows);return hP=e,qP(e,n),n.focus(),()=>{n.element.remove(),hP===e&&(hP=null)}}async function XP(){if(await vp(EP()),dP.size>0){let e=xP();for(let t of dP.values())t.setOptions(e)}TP({})}function ZP(){let e=se(),t=O(),n=t??e.machine,r=t===null?e.project:Ae,i=e.terminal;if(n===void 0||r===void 0||i===void 0)return;M({terminal:void 0});let a=CP(()=>{mP.status===`active`&&gP===n&&(a(),PP(n,r,Number(i)))})}function QP(e,t){ct(e,t)}function $P(e){let t=e.terminals.map(kP),n=localStorage.getItem(`lastTerminalView`);QP(e.id,t.find(e=>e===n)??t.at(0)??`global`)}async function eF(e,t){try{await z(e,`terminal`,{type:`createTab`,projectId:t})}catch(e){console.error(`terminal request failed`,e);return}QP(e,t??`global`)}function tF(){let e=wP(),t=O();if(t===null||e.instance===null||t!==SP()||OP(e.layout,A()).length>0)return;let n=e.layout.tabs.at(0);if(n!==void 0){QP(t,kP(n));return}let r=R().machines.find(e=>e.id!==t&&e.status===`online`&&e.terminals.length>0);r===void 0?l(`chat`,()=>void nt.navigate({to:`/`,search:{},replace:!0})):$P(r)}function nF(e){let t=k(e=>e.machines).filter(e=>e.status===`online`),n=t.some(e=>e.terminals.length>0);return t.length===0?null:(0,W.jsxs)(fn,{children:[(0,W.jsx)(dr,{asChild:!0,children:(0,W.jsx)(`button`,{className:B(`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:to,className:`size-4`})})}),(0,W.jsx)(vn,{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)(rF,{})})]})}function rF(e){let t=k(e=>e.machines),n=k(e=>e.projects),r=e.contextMenu?Fn:wn;return t.filter(e=>e.status===`online`).flatMap(e=>[(0,W.jsxs)(r,{onSelect:()=>void eF(e.id,null),children:[(0,W.jsx)(jd,{icon:e.icon}),(0,W.jsx)(`span`,{className:`max-w-60 truncate`,children:e.name})]},e.id),...n.filter(t=>t.machine===e.id&&!t.hidden&&!t.scratch).map(t=>(0,W.jsxs)(r,{className:`pl-7`,onSelect:()=>void eF(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 iF(e){let t=k(e=>e.machines).filter(e=>e.status===`online`),n=t.filter(e=>e.terminals.length>0),r=localStorage.getItem(`lastTerminal`),i=(0,W.jsx)(`button`,{className:B(e.buttonClassName,`size-7 [&>svg]:size-4.5`),title:`Terminal`,"aria-label":`Terminal`,disabled:t.length===0,onClick:n.length>0?()=>$P(n.find(e=>e.id===r)??n[0]):void 0,children:(0,W.jsx)(V,{icon:Ss})});return(0,W.jsxs)(`div`,{className:`mr-1.5 flex items-center gap-0.75`,children:[(0,W.jsx)(`button`,{className:B(e.buttonClassName,`size-7 [&>svg]:size-4.5`),title:`Settings`,"aria-label":`Settings`,onClick:()=>j(!0),children:(0,W.jsx)(V,{icon:ms})}),n.length>0?i:(0,W.jsxs)(fn,{children:[(0,W.jsx)(dr,{asChild:!0,children:i}),(0,W.jsx)(vn,{align:`start`,className:`max-h-80 w-auto min-w-40 overflow-y-auto`,onCloseAutoFocus:e=>e.preventDefault(),children:(0,W.jsx)(rF,{})})]})]})}var aF=`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`,oF={active:{status:`snoozed`,icon:Ms},snoozed:{status:`active`,icon:ws},minimized:{status:`active`,icon:fo},inactive:{status:`minimized`,icon:ts},pinned:{status:`active`,icon:os}};function sF(e){let t=e.session,n=Ns(t.machine,t.projectId),r=k(e=>L(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(){Ue(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`?Se(t.machine,t.id,{status:`active`}):b()),e.clientX-n.x<-e.currentTarget.offsetWidth*.4&&Se(t.machine,t.id,{status:oF[t.status].status}))}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&&Math.abs(n)<=Math.abs(r)?d.current=null:(t.swiping=!0,l(n)))},onPointerUp:x,onPointerCancel:()=>{d.current=null,l(0)}},C=c!==0&&(0,W.jsx)(`div`,{className:B(`absolute inset-x-0 flex items-center rounded-md px-4 text-white`,e.slim?`inset-y-0`:`inset-y-0.5`,c>0&&t.status!==`inactive`&&`bg-success`,c>0&&t.status===`inactive`&&`bg-[#56b6c2]`,c<0&&t.status===`active`&&`bg-[#c678dd]`,c<0&&t.status===`snoozed`&&`bg-[#d19a66]`,c<0&&t.status===`minimized`&&`bg-info`,c<0&&t.status===`inactive`&&`bg-[#5c6370]`,c<0&&t.status===`pinned`&&`bg-[#e06c75]`,c<0&&`justify-end`),children:(0,W.jsx)(V,{icon:c<0?oF[t.status].icon:t.status===`inactive`?cs:Ds,className:`size-6`})}),w=(0,W.jsx)(lr,{open:o,onOpenChange:s,children:(0,W.jsxs)(Kn,{children:[(0,W.jsxs)(Er,{children:[(0,W.jsx)(Ln,{children:`Stop running work?`}),(0,W.jsx)(Pn,{children:`The agent or background tasks are running. Do you really want to stop them?`})]}),(0,W.jsxs)(br,{children:[(0,W.jsx)(Jn,{children:`Cancel`}),(0,W.jsx)(rr,{variant:`destructive`,onClick:y,children:`Stop and Mark Done`})]})]})}),T=(0,W.jsx)(Xn,{className:`w-44`,onCloseAutoFocus:e=>{u.current!==null&&(e.preventDefault(),u.current.focus(),u.current.select())},children:(0,W.jsx)(_k,{session:t,context:!0,mobile:!0,onDeactivate:b,onRename:()=>a(t.title)})}),E=i===null?(0,W.jsx)(`span`,{className:B(`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)(yk,{session:t,awaitingTitle:!e.saved})}):(0,W.jsx)(`form`,{className:`min-w-0 flex-1`,onSubmit:e=>{e.preventDefault();let n=i.trim();a(null),n!==``&&n!==t.title&&Se(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=B(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)(ar,{children:[(0,W.jsx)(Wn,{asChild:!0,disabled:!e.saved,children:(0,W.jsxs)(`div`,{role:`button`,tabIndex:0,className:B(aF,D,`flex h-9 items-center gap-2.5 px-2.5`,c!==0&&`bg-sidebar`),style:c===0?void 0:{transform:`translateX(${c}px)`},...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:Qn(t.updatedAt)})]})}),T]}),w]}):(0,W.jsxs)(`li`,{className:`relative list-none py-0.5`,children:[C,(0,W.jsxs)(ar,{children:[(0,W.jsx)(Wn,{asChild:!0,disabled:!e.saved,children:(0,W.jsx)(`div`,{role:`button`,tabIndex:0,className:B(aF,D,h&&!e.selected&&c===0&&`opacity-70`,c!==0&&`bg-sidebar`),style:c===0?void 0:{transform:`translateX(${c}px)`},...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,(0,W.jsx)(vk,{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)(jd,{icon:r,className:`size-3 shrink-0`}),(0,W.jsxs)(`span`,{className:B(`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===`pinned`&&(0,W.jsx)(V,{icon:ss,className:`size-3 shrink-0`}),t.status===`snoozed`&&(0,W.jsx)(V,{icon:Ms,className:`size-3 shrink-0`}),(0,W.jsx)(`span`,{className:`shrink-0 tabular-nums`,children:Qn(t.updatedAt)})]})]})})}),T]}),w]})}function cF(e){let t=Ns(e.machine,e.projectId),n=k(t=>L(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:B(aF,`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:bs,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)(jd,{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 lF=`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 uF(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(){Ue(t.machine,t.id,null)}function m(){u?a(!0):p()}let h=(0,W.jsx)(lr,{open:i,onOpenChange:a,children:(0,W.jsxs)(Kn,{children:[(0,W.jsxs)(Er,{children:[(0,W.jsx)(Ln,{children:`Stop running work?`}),(0,W.jsx)(Pn,{children:`The agent or background tasks are running. Do you really want to stop them?`})]}),(0,W.jsxs)(br,{children:[(0,W.jsx)(Jn,{children:`Cancel`}),(0,W.jsx)(rr,{variant:`destructive`,onClick:p,children:`Stop and Mark Done`})]})]})}),g=e.saved&&(0,W.jsxs)(fn,{children:[(0,W.jsx)(dr,{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:Po,className:`size-3.5`})})}),(0,W.jsx)(vn,{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)(_k,{session:t,context:!1,mobile:!1,onDeactivate:m,onRename:()=>r(t.title)})})]}),_=(0,W.jsx)(Xn,{className:`w-44`,onCloseAutoFocus:e=>{o.current!==null&&(e.preventDefault(),o.current.focus(),o.current.select())},children:(0,W.jsx)(_k,{session:t,context:!0,mobile:!1,onDeactivate:m,onRename:()=>r(t.title)})}),v=n===null?(0,W.jsx)(`span`,{className:B(`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)(yk,{session:t,awaitingTitle:!e.saved})}):(0,W.jsx)(`form`,{className:`min-w-0 flex-1`,onSubmit:e=>{e.preventDefault();let i=n.trim();r(null),i!==``&&i!==t.title&&Se(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`})}),y=B(e.selected&&`bg-sidebar-row-active text-sidebar-foreground`,f&&`text-sidebar-muted-foreground/75 hover:bg-sidebar-row-hover hover:text-sidebar-foreground has-[[data-state=open]]:bg-sidebar-row-hover has-[[data-state=open]]:text-sidebar-foreground`,!e.selected&&!f&&`text-sidebar-foreground hover:bg-sidebar-row-hover has-[[data-state=open]]:bg-sidebar-row-hover bg-transparent`);return(0,W.jsxs)(`li`,{className:`list-none`,children:[(0,W.jsxs)(ar,{children:[(0,W.jsx)(Wn,{asChild:!0,disabled:!e.saved,children:(0,W.jsxs)(`div`,{role:`button`,tabIndex:0,className:B(lF,y,`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:[(0,W.jsxs)(`span`,{className:`group-any-hover/sidebar-row:mask-r-from-[calc(100%-5rem)] group-any-hover/sidebar-row:mask-r-to-[calc(100%-3rem)] flex min-w-0 flex-1 items-center gap-2 group-has-[[data-state=open]]/sidebar-row:mask-r-from-[calc(100%-5rem)] group-has-[[data-state=open]]/sidebar-row:mask-r-to-[calc(100%-3rem)]`,children:[v,t.status===`pinned`&&(0,W.jsx)(V,{icon:ss,className:`text-muted-foreground/65 size-3 shrink-0`}),t.status===`snoozed`&&(0,W.jsx)(V,{icon:Ms,className:`text-secondary-label size-3 shrink-0`}),(0,W.jsx)(vk,{activity:e.activity,backgroundRunning:c,done:d}),(0,W.jsx)(`span`,{className:`text-secondary-label shrink-0 text-xs tabular-nums`,children:Qn(t.updatedAt)})]}),e.saved&&(0,W.jsxs)(`div`,{className:`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 pr-1.5 opacity-0 transition-opacity has-[[data-state=open]]:pointer-events-auto has-[[data-state=open]]:opacity-100`,children:[g,(0,W.jsx)(`button`,{className:`text-muted-foreground hover:text-foreground ms-0.5 me-0.5 inline-flex size-5 cursor-pointer items-center justify-center transition-colors`,title:`Done`,"aria-label":`Done`,onClick:e=>{e.stopPropagation(),m()},children:(0,W.jsx)(V,{icon:Ds,strokeWidth:1.35,className:`size-5 scale-110`})})]})]})}),_]}),h]})}function dF(e){return(0,W.jsx)(`li`,{className:`list-none`,children:(0,W.jsxs)(`div`,{role:`button`,tabIndex:0,className:B(lF,`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:bs,className:`text-warning-foreground size-4 shrink-0`})]})})}var fF=`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 pF(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 _(){Ue(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`?Se(t.machine,t.id,{status:`active`}):v()),e.clientX-n.x<-e.currentTarget.offsetWidth*.4&&Se(t.machine,t.id,{status:oF[t.status].status}))}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&&Math.abs(n)<=Math.abs(r)?l.current=null:(t.swiping=!0,s(n)))},onPointerUp:y,onPointerCancel:()=>{l.current=null,s(0)}},x=o!==0&&(0,W.jsx)(`div`,{className:B(`absolute inset-0 flex items-center rounded-md px-4 text-white`,o>0&&t.status!==`inactive`&&`bg-success`,o>0&&t.status===`inactive`&&`bg-[#56b6c2]`,o<0&&t.status===`active`&&`bg-[#c678dd]`,o<0&&t.status===`snoozed`&&`bg-[#d19a66]`,o<0&&t.status===`minimized`&&`bg-info`,o<0&&t.status===`inactive`&&`bg-[#5c6370]`,o<0&&t.status===`pinned`&&`bg-[#e06c75]`,o<0&&`justify-end`),children:(0,W.jsx)(V,{icon:o<0?oF[t.status].icon:t.status===`inactive`?cs:Ds,className:`size-6`})}),S=(0,W.jsx)(lr,{open:i,onOpenChange:a,children:(0,W.jsxs)(Kn,{children:[(0,W.jsxs)(Er,{children:[(0,W.jsx)(Ln,{children:`Stop running work?`}),(0,W.jsx)(Pn,{children:`The agent or background tasks are running. Do you really want to stop them?`})]}),(0,W.jsxs)(br,{children:[(0,W.jsx)(Jn,{children:`Cancel`}),(0,W.jsx)(rr,{variant:`destructive`,onClick:_,children:`Stop and Mark Done`})]})]})}),C=(0,W.jsx)(Xn,{className:`w-44`,onCloseAutoFocus:e=>{c.current!==null&&(e.preventDefault(),c.current.focus(),c.current.select())},children:(0,W.jsx)(_k,{session:t,context:!0,mobile:!0,onDeactivate:v,onRename:()=>r(t.title)})}),w=n===null?(0,W.jsx)(`span`,{className:B(`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)(yk,{session:t,awaitingTitle:!e.saved})}):(0,W.jsx)(`form`,{className:`min-w-0 flex-1`,onSubmit:e=>{e.preventDefault();let i=n.trim();r(null),i!==``&&i!==t.title&&Se(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=B(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)(ar,{children:[(0,W.jsx)(Wn,{asChild:!0,disabled:!e.saved,children:(0,W.jsxs)(`div`,{role:`button`,tabIndex:0,className:B(fF,T,`flex h-9 items-center gap-2 px-2.5`,p&&!e.selected&&o===0&&`opacity-70`,o!==0&&`bg-sidebar`),style:o===0?void 0:{transform:`translateX(${o}px)`},...b,onKeyDown:t=>{t.key===`Enter`&&e.onSelect()},children:[w,t.status===`pinned`&&(0,W.jsx)(V,{icon:ss,className:`text-muted-foreground/65 size-3 shrink-0`}),t.status===`snoozed`&&(0,W.jsx)(V,{icon:Ms,className:`text-secondary-label size-3 shrink-0`}),(0,W.jsx)(vk,{activity:e.activity,backgroundRunning:f,done:h}),(0,W.jsx)(`span`,{className:`text-secondary-label shrink-0 text-xs tabular-nums`,children:Qn(t.updatedAt)})]})}),C]}),S]})}function mF(e){return(0,W.jsx)(`li`,{className:`list-none`,children:(0,W.jsxs)(`div`,{role:`button`,tabIndex:0,className:B(fF,`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:bs,className:`text-warning-foreground size-4 shrink-0`})]})})}function hF(e){let t=Ns(e.machine,e.projectId),n=k(t=>L(t,e.machine).icon),r=k(e=>e.selection),i=k(e=>e.machines),a=k(e=>e.unseen),o=r!==null&&r.sessionId===null&&r.machine===e.machine&&r.projectId===e.projectId,s=e.mobile?mF:dF,c=e.mobile?pF:uF;function l(){Ie({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)(jd,{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:to,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:ke(i,t.machine,t.id),unseen:a.includes(P(t.machine,t.id)),saved:t!==e.started,onSelect:()=>Ie({machine:t.machine,projectId:t.projectId,sessionId:t.id})},P(t.machine,t.id)))]})}function gF(e){let t=k(e=>e.machines),n=k(e=>e.projects),r=k(e=>e.sessions),i=k(e=>e.unseen),[a,o]=(0,U.useState)(!1);or(`mod+p`,()=>o(!a),{enableOnFormTags:!0,preventDefault:!0});let s=t.map(e=>({machine:e,projects:n.filter(t=>t.machine===e.id&&!t.hidden&&!t.scratch)})).filter(e=>t.length>1||e.projects.length>0||e.machine.system?.scratchAvailable===!0),c=r.filter(e=>{let n=ke(t,e.machine,e.id);return n?.running===!0||n?.waiting===!0||Object.values(n?.tasks??{}).includes(`running`)||i.includes(P(e.machine,e.id))});function l(e,t){return n.find(n=>n.machine===e&&n.id===t)}function u(e){return c.filter(t=>t.machine===e&&l(e,t.projectId)?.scratch===!0).length}function d(e){return(0,W.jsx)(wn,{className:`text-muted-foreground grid size-5 min-h-0 shrink-0 place-items-center rounded-sm p-0`,title:`Manage projects on ${e.name}`,"aria-label":`Manage projects on ${e.name}`,disabled:e.status!==`online`,onSelect:()=>{Ke(`Projects`),We({settingsMachine:e.id})},children:(0,W.jsx)(V,{icon:ys,className:`size-3.5`})})}function f(e){return e.status===`online`?e.name:e.status===`unpaired`?`${e.name} · needs pairing`:`${e.name} · offline`}return(0,W.jsxs)(fn,{open:a,onOpenChange:o,children:[(0,W.jsx)(dr,{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`:l(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`:e.scope.projectId===`no-project`?`Chat`:l(e.scope.machine,e.scope.projectId)?.name}),(0,W.jsx)(V,{icon:jr,className:`text-sidebar-muted-foreground size-3.5 shrink-0`})]})}),(0,W.jsxs)(vn,{className:`w-64`,children:[(0,W.jsxs)(kn,{value:e.scope===null?``:P(e.scope.machine,e.scope.projectId),children:[(0,W.jsxs)(mn,{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`}),c.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:c.length})]}),s.length>0&&(0,W.jsx)(On,{}),s.map(({machine:n,projects:r},i)=>(0,W.jsxs)(U.Fragment,{children:[i>0&&(0,W.jsx)(On,{}),t.length>1&&(0,W.jsxs)(`div`,{className:`flex items-center`,children:[(0,W.jsxs)(Or,{className:`flex min-w-0 flex-1 items-center gap-2 pl-[0.52rem]!`,children:[(0,W.jsx)(jd,{icon:n.icon,className:`size-3.5 shrink-0`}),(0,W.jsx)(`span`,{className:`truncate`,children:f(n)})]}),n.system?.scratchAvailable===!0&&(0,W.jsxs)(mn,{value:P(n.id,`no-project`),className:`text-muted-foreground data-[state=checked]:bg-foreground/10 data-[state=checked]:text-foreground mr-0.5 h-5 min-h-0 shrink-0 gap-1 px-1.5 py-0 text-xs *:data-[slot=dropdown-menu-radio-item-indicator]:hidden`,title:`Threads on ${n.name} without a project`,onSelect:()=>e.onScope({machine:n.id,projectId:`no-project`}),children:[(0,W.jsx)(zs,{machine:n.id,projectId:`no-project`,className:`size-3.5 shrink-0`}),`Chat`,u(n.id)>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:u(n.id)})]}),(0,W.jsxs)(`div`,{className:`flex shrink-0 items-center gap-0.5 pr-1`,children:[d(n),(0,W.jsx)(wn,{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:to,className:`size-3.5`})})]})]}),t.length===1&&n.system?.scratchAvailable===!0&&(0,W.jsxs)(mn,{value:P(n.id,`no-project`),className:`pr-1 pl-8 *:data-[slot=dropdown-menu-radio-item-indicator]:right-auto *:data-[slot=dropdown-menu-radio-item-indicator]:left-2`,onSelect:()=>e.onScope({machine:n.id,projectId:`no-project`}),children:[(0,W.jsx)(zs,{machine:n.id,projectId:`no-project`,className:`size-5 shrink-0`}),(0,W.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:`Chat`}),u(n.id)>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:u(n.id)})]}),r.map(t=>{let n=c.filter(e=>e.machine===t.machine&&e.projectId===t.id).length;return(0,W.jsxs)(mn,{value:P(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`,onSelect:()=>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.jsx)(`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:`Configure project`,"aria-label":`Configure ${t.name}`,onClick:n=>{n.stopPropagation(),o(!1),e.onEdit(t)},children:(0,W.jsx)(V,{icon:ms})})})]},P(t.machine,t.id))})]},n.id))]}),t.length===1&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(On,{}),(0,W.jsxs)(`div`,{className:`flex items-center`,children:[(0,W.jsxs)(wn,{className:`flex-1 pl-8`,onSelect:()=>e.onAddProject(t[0].id),children:[(0,W.jsx)(V,{icon:to}),`Add project…`]}),(0,W.jsx)(`div`,{className:`flex shrink-0 items-center pr-1`,children:d(t[0])})]})]})]})]})}function _F(e){let t=k(e=>e.errors),n=k(e=>e.machines),r=k(e=>e.sessions),i=k(e=>e.unseen),a=n.filter(e=>e.status===`offline`||e.status===`unpaired`),o=r.filter(e=>Object.values(ke(n,e.machine,e.id)?.tasks??{}).includes(`failed`)),s=r.filter(e=>ke(n,e.machine,e.id)?.waiting===!0),c=r.filter(e=>{let t=ke(n,e.machine,e.id);return i.includes(P(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)(bF,{session:e,icon:Eo,className:`text-success`,detail:`Done`},P(e.machine,e.id))),f=s.map(e=>(0,W.jsx)(bF,{session:e,icon:vs,className:`text-question`,detail:`Waiting for approval`},P(e.machine,e.id))),p=e.collapsed===!0&&u&&s.length>0&&l>0;return(0,W.jsxs)(`div`,{className:B(`flex shrink-0 items-center gap-1`,e.className),children:[p&&(0,W.jsxs)(vF,{className:`bg-question/15 text-question`,icon:vs,count:s.length+c.length,label:`${s.length} waiting for approval, ${c.length} done`,children:[f,d]}),!p&&u&&(0,W.jsx)(vF,{className:`bg-success/15 text-success`,icon:Eo,count:c.length,label:`${c.length} done`,children:d}),!p&&s.length>0&&(0,W.jsx)(vF,{className:`bg-question/15 text-question`,icon:vs,count:s.length,label:`${s.length} waiting for approval`,children:f}),l>0&&(0,W.jsxs)(vF,{className:B(t.length>0&&`bg-error/15 text-error`,t.length===0&&`bg-warning/15 text-warning-foreground`),icon:t.length>0?Dn:ro,count:l,label:l===1?`1 problem`:`${l} problems`,onClose:Ze,children:[t.map((e,t)=>(0,W.jsx)(yF,{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)(yF,{icon:ro,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)(bF,{session:e,icon:ro,className:`text-warning-foreground`,detail:`Background task failed`},P(e.machine,e.id)))]})]})}function vF(e){return(0,W.jsxs)(un,{onOpenChange:t=>!t&&e.onClose?.(),children:[(0,W.jsx)(bn,{asChild:!0,children:(0,W.jsxs)(`button`,{className:B(`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)(cn,{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 yF(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:B(`mt-0.5 size-4 shrink-0`,e.className)}),(0,W.jsx)(`div`,{className:`min-w-0 flex-1`,children:e.children})]})}function bF(e){return(0,W.jsx)(Mn,{asChild:!0,children:(0,W.jsx)(`button`,{className:`hover:bg-accent cursor-pointer rounded-md text-left`,onClick:()=>Ie({machine:e.session.machine,projectId:e.session.projectId,sessionId:e.session.id}),children:(0,W.jsxs)(yF,{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 xF=null,SF=null,CF=new Set,wF=new Set;function TF(e){return wF.add(e),()=>{wF.delete(e)}}function EF(){return xF}function DF(){xF!==null&&AF({open:!1,closing:xF.closing})}function OF(){return SF}function kF(){SF!==null&&jF({open:!1,closing:SF.closing})}function AF(e){xF=e;for(let e of wF)e()}function jF(e){SF=e;for(let e of wF)e()}function MF(){return document.querySelector(`[role="dialog"][data-state="open"], [role="alertdialog"][data-state="open"]`)!==null}async function NF(e,t){try{let n=await Promise.race([z(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 PF(e){if(!EP().behavior.confirmCloseBusyTab){FP({type:`closeTab`,id:e});return}if(!AP(e)||CF.has(e))return;CF.add(e);let t=await NF(SP(),e);if(CF.delete(e),t.checked&&t.program===null){FP({type:`closeTab`,id:e});return}let n=AP(e);n&&!MF()&&AF({open:!0,closing:{id:e,name:jP(n),program:t.checked?t.program:null}})}function FF(e){for(let t of e)IP(t.machine,{type:`closeTab`,id:t.id})}async function IF(e){if(!EP().behavior.confirmCloseBusyTab){FF(e);return}let t=await Promise.all(e.map(e=>NF(e.machine,e.id)));if(t.every(e=>e.checked&&e.program===null)){FF(e);return}if(MF())return;let n=t.flatMap(e=>e.checked&&e.program!==null?[e.program]:[]);jF({open:!0,closing:{tabs:e,programs:[...new Set(n)]}})}var LF=Rt?`meta+t`:`ctrl+shift+t`,RF=Rt?`meta+w`:`ctrl+shift+w`,zF=`ctrl+tab`,BF=`ctrl+shift+tab`;function VF(){let e=DP()?.tabId??null;wP().open&&e!==null&&JP(e).focus()}function HF(){return or([LF,RF,zF,BF],(e,t)=>{e.preventDefault(),e.stopPropagation();let n=DP();if(n===null)return;if(t.hotkey===LF){FP({type:`createTab`,projectId:n.view===`global`?null:n.view});return}if(n.tabId===null)return;if(t.hotkey===RF){PF(n.tabId);return}let r;if(t.hotkey===zF)r=1;else if(t.hotkey===BF)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&&FP({type:`select`,view:n.view,tabId:a.id})},{enabled:()=>EP().behavior.captureShortcuts,enableOnFormTags:!0,eventListenerOptions:{capture:!0}})}function UF(e){let[t,n]=(0,U.useState)(e.name);return(0,W.jsx)(ei,{open:!0,onOpenChange:t=>{t||e.onDone()},children:(0,W.jsx)(qr,{onCloseAutoFocus:KF,children:(0,W.jsxs)(`form`,{className:`grid gap-4`,onSubmit:n=>{n.preventDefault(),FP({type:`renameTab`,id:e.id,name:t.trim()}),e.onDone()},children:[(0,W.jsx)(Jr,{children:(0,W.jsx)(Zr,{children:`Rename tab`})}),(0,W.jsx)(Kf,{"aria-label":`Name`,placeholder:`Use terminal title`,value:t,onChange:e=>n(e.target.value)}),(0,W.jsxs)(ti,{children:[(0,W.jsx)(H,{type:`button`,variant:`outline`,onClick:e.onDone,children:`Cancel`}),(0,W.jsx)(H,{type:`submit`,children:`Rename`})]})]})})})}function WF(){let e=(0,U.useSyncExternalStore)(TF,EF),t=(0,U.useRef)(null);if(e===null)return null;let n=e.closing;return(0,W.jsx)(lr,{open:e.open,onOpenChange:e=>{e||DF()},children:(0,W.jsxs)(Kn,{onOpenAutoFocus:e=>{e.preventDefault(),t.current?.focus()},onCloseAutoFocus:KF,children:[(0,W.jsxs)(Er,{children:[(0,W.jsxs)(Ln,{children:[`Close “`,n.name,`”?`]}),(0,W.jsx)(Pn,{children:n.program===null?`OffSite couldn’t check whether a program is still running.`:`${n.program} is still running.`})]}),(0,W.jsxs)(br,{children:[(0,W.jsx)(Jn,{children:`Cancel`}),(0,W.jsx)(rr,{ref:t,variant:`destructive`,onClick:()=>FP({type:`closeTab`,id:n.id}),children:`Close`})]})]})})}function GF(){let e=(0,U.useSyncExternalStore)(TF,OF);if(e===null)return null;let t=e.closing;return(0,W.jsx)(lr,{open:e.open,onOpenChange:e=>{e||kF()},children:(0,W.jsxs)(Kn,{onCloseAutoFocus:KF,children:[(0,W.jsxs)(Er,{children:[(0,W.jsxs)(Ln,{children:[`Close `,t.tabs.length,` `,t.tabs.length===1?`terminal`:`terminals`,`?`]}),(0,W.jsx)(Pn,{children:t.programs.length===0?`OffSite couldn’t check whether programs are still running.`:`Still running: ${t.programs.join(`, `)}.`})]}),(0,W.jsxs)(br,{children:[(0,W.jsx)(Jn,{children:`Cancel`}),(0,W.jsx)(rr,{variant:`destructive`,onClick:()=>FF(t.tabs),children:`Close all`})]})]})})}function KF(e){e.preventDefault();let t=document.querySelector(`[role="dialog"], [role="alertdialog"]`);t===null?VF():t.focus()}function qF(e){let t=(0,U.useRef)(null),[n,r]=(0,U.useState)(``),[i,a]=(0,U.useState)({resultIndex:-1,resultCount:0});(0,U.useEffect)(()=>BP(e.id,a),[e.id]),(0,U.useEffect)(()=>t.current?.focus(),[]);function o(t,n,i){r(t),zP(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)(Kf,{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(),VP(e.id)):t.key===`Enter`?(t.preventDefault(),o(n,t.shiftKey,!1)):KP(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:ho})}),(0,W.jsx)(H,{variant:`ghost`,size:`icon-sm`,"aria-label":`Next match`,onClick:()=>o(n,!1,!1),children:(0,W.jsx)(V,{icon:sn})}),(0,W.jsx)(H,{variant:`ghost`,size:`icon-sm`,"aria-label":`Close find`,onClick:()=>VP(e.id),children:(0,W.jsx)(V,{icon:bo})})]})}var JF=[{label:`Esc`,sequence:`\x1B`},{label:`Tab`,sequence:` `},{label:`↑`,sequence:`\x1B[A`},{label:`↓`,sequence:`\x1B[B`},{label:`←`,sequence:`\x1B[D`},{label:`→`,sequence:`\x1B[C`}];function YF(e){let t=(0,U.useSyncExternalStore)(CP,wP),n=t.status===`active`,r=OP(t.layout,e.view),i=t.layout.active[e.view]??null,a=HF();(0,U.useEffect)(()=>{n&&!e.page&&FP({type:`select`,view:e.view,tabId:null})},[e.view,n,e.page]);function o(){FP({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:B(`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)(ZF,{tab:n,children:(0,W.jsxs)(`div`,{className:B(`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:()=>FP({type:`select`,view:e.view,tabId:n.id}),children:[(0,W.jsx)(`span`,{className:`truncate`,children:jP(n)}),(0,W.jsx)(QF,{id:n.id,className:`ml-1.5 size-1.5 flex-none rounded-full`}),(0,W.jsx)($F,{progress:t.progress[n.id]}),(0,W.jsx)(`button`,{className:B(`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(),PF(n.id)},children:(0,W.jsx)(V,{icon:bo,className:`size-3`})})]})},n.id))}),(0,W.jsx)(`button`,{className:B(`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:to,className:`size-4`})})]}),(0,W.jsxs)(`div`,{className:`relative min-h-0 flex-1`,children:[i!==null&&(0,W.jsx)(XF,{id:i},`${t.instance}-${i}`),i!==null&&t.finding===i&&(0,W.jsx)(qF,{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:[JF.map(e=>(0,W.jsx)(H,{variant:`secondary`,className:`min-w-11`,onPointerDown:e=>e.preventDefault(),onClick:()=>LP(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:HP,children:`Ctrl`})]}),(0,W.jsx)(WF,{})]}):(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 XF(e){let t=(0,U.useRef)(null);return(0,U.useEffect)(()=>{if(!t.current)throw Error(`terminal container missing`);return YP(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 ZF(e){let[t,n]=(0,U.useState)(!1),r=k(e=>e.projects).filter(e=>e.machine===SP()&&!e.scratch),i=e.tab;return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(ar,{children:[(0,W.jsx)(Wn,{asChild:!0,children:e.children}),(0,W.jsxs)(Xn,{children:[(0,W.jsxs)(Fn,{onSelect:()=>n(!0),children:[(0,W.jsx)(V,{icon:as}),`Rename`]}),(0,W.jsxs)(tr,{children:[(0,W.jsxs)(Vn,{children:[(0,W.jsx)(V,{icon:ur}),`Move to`]}),(0,W.jsx)(vr,{className:`max-h-80 overflow-y-auto`,children:(0,W.jsxs)(sr,{value:i.projectId??``,onValueChange:e=>FP({type:`assignTab`,id:i.id,projectId:e===``?null:e}),children:[(0,W.jsx)(mr,{value:``,children:`No project`}),r.length>0&&(0,W.jsx)(zn,{}),r.map(e=>(0,W.jsx)(mr,{value:e.id,children:(0,W.jsx)(`span`,{className:`max-w-60 truncate`,children:e.name})},e.id))]})})]}),(0,W.jsxs)(Fn,{variant:`destructive`,onSelect:()=>void PF(i.id),children:[(0,W.jsx)(V,{icon:Mo}),`Close tab`]})]})]}),t&&(0,W.jsx)(UF,{id:i.id,name:i.customName??``,onDone:()=>n(!1)})]})}function QF(e){return wP().alerts.includes(e.id)?(0,W.jsx)(`span`,{className:B(`bg-primary`,e.className)}):null}function $F(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:B(`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 eI(e){(0,U.useSyncExternalStore)(CP,wP);let t=k(e=>e.machines).filter(e=>e.status===`online`),n=b(),r=nI(),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)(fn,{children:[(0,W.jsx)(dr,{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:to,className:`size-4`})})}),(0,W.jsx)(vn,{align:`end`,className:`w-auto min-w-56`,children:(0,W.jsx)(rF,{})})]});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)(fn,{children:[(0,W.jsx)(dr,{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)(aI,{group:i}),(0,W.jsx)(`span`,{className:`truncate`,children:i?.name})]})}),(0,W.jsx)(vn,{align:`center`,className:`w-auto`,children:r.filter(rI).map(t=>(0,W.jsxs)(wn,{className:B(t.view!==`global`&&`pl-7`),onSelect:()=>t.count===0?void eF(t.machine.id,null):QP(t.machine.id,t.view),children:[(0,W.jsx)(aI,{group:t}),(0,W.jsx)(`span`,{className:`max-w-60 truncate`,children:t.name}),(0,W.jsx)(oI,{count:t.count,alert:iI(t,e.machine)})]},`${t.machine.id}:${t.view}`))})]}),a]}),(0,W.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,W.jsx)(YF,{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)(YF,{view:n,page:!0,tabSize:`lg`,leading:e.leading})})})}function tI(e){(0,U.useSyncExternalStore)(CP,wP);let t=h(),n=b(),r=nI().filter(rI);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)(ar,{children:[(0,W.jsx)(Wn,{asChild:!0,children:(0,W.jsxs)(`div`,{className:B(`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:B(`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 eF(r.machine.id,null):QP(r.machine.id,r.view),children:[(0,W.jsx)(aI,{group:r}),(0,W.jsx)(`span`,{className:`truncate`,children:r.name}),(0,W.jsx)(oI,{count:r.count,alert:iI(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 eF(r.machine.id,r.view===`global`?null:r.view),children:(0,W.jsx)(V,{icon:to,className:`size-4`})})]})}),(0,W.jsxs)(Xn,{onCloseAutoFocus:e=>e.preventDefault(),children:[(0,W.jsxs)(Fn,{onSelect:()=>void eF(r.machine.id,r.view===`global`?null:r.view),children:[(0,W.jsx)(V,{icon:to}),`New terminal`]}),r.view===`global`&&(0,W.jsxs)(Fn,{variant:`destructive`,onSelect:()=>void IF(r.machine.terminals.map(e=>({machine:r.machine.id,id:e.id}))),children:[(0,W.jsx)(V,{icon:Mo}),`Close All`]}),(0,W.jsxs)(Fn,{variant:`destructive`,disabled:r.count===0,onSelect:()=>void IF(r.machine.terminals.filter(e=>kP(e)===r.view).map(e=>({machine:r.machine.id,id:e.id}))),children:[(0,W.jsx)(V,{icon:Mo}),r.view===`global`?`Close All Except Projects`:`Close All`]})]})]},`${r.machine.id}:${r.view}`))})}function nI(){let e=k(e=>e.machines),t=k(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:Ae,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 rI(e){return e.machine.status===`online`&&e.machine.terminals.length>0}function iI(e,t){let n=wP();return e.machine.id===t&&n.layout.tabs.some(t=>(t.projectId??`global`)===e.view&&n.alerts.includes(t.id))}function aI(e){return e.group.view===`global`?(0,W.jsx)(jd,{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 oI(e){return e.count===0?null:(0,W.jsx)(`span`,{className:B(`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 sI(e){let t=k(e=>e.machines),[n,r]=Nr(`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:B(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:Ss}),`Terminal`,i>0&&(0,W.jsx)(`span`,{className:B(`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)(ar,{children:[(0,W.jsx)(Wn,{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)(fn,{children:[(0,W.jsx)(dr,{asChild:!0,disabled:!o,children:c}),(0,W.jsx)(vn,{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)(rF,{})})]}),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:si,"aria-hidden":!0,className:B(`size-4 transition-transform duration-200`,n&&`rotate-90`)})}),(0,W.jsx)(nF,{mobile:e.mobile})]})}),(0,W.jsxs)(Xn,{onCloseAutoFocus:e=>e.preventDefault(),children:[(0,W.jsxs)(tr,{children:[(0,W.jsxs)(Vn,{children:[(0,W.jsx)(V,{icon:to}),`New terminal`]}),(0,W.jsx)(vr,{className:`max-h-80 overflow-y-auto`,children:(0,W.jsx)(rF,{contextMenu:!0})})]}),(0,W.jsxs)(Fn,{variant:`destructive`,disabled:!a,onSelect:()=>void IF(t.filter(e=>e.status===`online`).flatMap(e=>e.terminals.map(t=>({machine:e.id,id:t.id})))),children:[(0,W.jsx)(V,{icon:Mo}),`Close All`]})]})]}),(0,W.jsx)(`div`,{className:B(`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)(tI,{mobile:e.mobile})})}),(0,W.jsx)(GF,{})]})}function cI(e,t,n){let r=k(e=>e.inactiveVersion);(0,U.useEffect)(()=>{if(!e)return;let r=!0,i=0;async function a(){let e=++i,a=t===null?R().machines.filter(e=>e.status===`online`).map(e=>e.id):[t],o=await Promise.all(a.map(async e=>(await z(e,`sessions.inactive`,{projectId:n})).map(t=>({...t,machine:e}))));r&&e===i&&We({inactive:o.flat().sort((e,t)=>t.updatedAt-e.updatedAt)})}function o(){document.visibilityState===`visible`&&a().catch(N)}return a().catch(N),window.addEventListener(`focus`,o),document.addEventListener(`visibilitychange`,o),()=>{r=!1,window.removeEventListener(`focus`,o),document.removeEventListener(`visibilitychange`,o)}},[e,t,n,r])}var lI=`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 uI(e){let t=k(e=>e.selection),n=k(e=>e.machines),r=k(e=>e.sessions),i=k(e=>e.projects),a=k(e=>e.settings.provider),o=k(e=>e.unseen),s=k(e=>e.loaded),c=k(e=>e.inactive),l=k(e=>e.prefs.groupActiveByProject),[d,f]=Nr(`sidebarScope`,null),[p,m]=(0,U.useState)(null),[h,g]=(0,U.useState)(null),[_,v]=(0,U.useState)(!1),[y,b]=(0,U.useState)(!1),[x,S]=(0,U.useState)(!1),[C,w]=Nr(`sidebarWidth`,240),T=r.filter(e=>d===null||e.machine===d.machine&&se(e.machine,e.projectId)===d.projectId).sort((e,t)=>t.updatedAt-e.updatedAt),D=T.filter(e=>{let t=ke(n,e.machine,e.id);return e.status===`snoozed`&&t?.waiting!==!0&&(t?.running===!0||Object.values(t?.tasks??{}).includes(`running`))}),O=[...T.filter(e=>e.status===`pinned`),...T.filter(e=>e.status===`active`||e.status===`snoozed`&&!D.includes(e))],A=T.filter(e=>e.status===`minimized`),M=d?.machine??null,ee=d?.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?O:[te,...O],ie=l&&d===null,ae=[...new Map([...ne===null?[]:[ne],...re].map(e=>{let t=se(e.machine,e.projectId);return[P(e.machine,t),{machine:e.machine,projectId:t}]}))],oe=e.mobile?cF:Sk;function se(e,t){return i.some(n=>n.machine===e&&n.id===t&&n.scratch)?E:t}cI(x,M,ee);function N(e,t,n){Ie({machine:e,projectId:t,sessionId:n})}function ce(){let e=d??t??Oe();e===null?n.length>0?m(n[0].id):Ke(`Machines`):Tt(e.machine,e.projectId)}or([`mod+n`,`mod+t`],ce,{enableOnFormTags:!0,preventDefault:!0}),or([`mod+1`,`mod+2`,`mod+3`,`mod+4`,`mod+5`,`mod+6`,`mod+7`,`mod+8`,`mod+9`],e=>{let t=ie?ae.flatMap(e=>re.filter(t=>P(t.machine,se(t.machine,t.projectId))===e[0])):re,n=/^(?:Digit|Numpad)([1-9])$/.exec(e.code);if(n===null)throw Error(`unexpected session shortcut key ${e.code}`);let r=t[Number(n[1])-1];r!==void 0&&N(r.machine,r.projectId,r.id)},{enableOnFormTags:!0,preventDefault:!0,enabled:!e.mobile});function le(e){let t=e.clientX-C;Bt(e,e=>{let n=Math.min(480,Math.max(200,e.clientX-t));w(n)})}function ue(r,i){let a=e.mobile?sF:xk;return(0,W.jsx)(a,{session:r,slim:i,selected:t?.machine===r.machine&&t.sessionId===r.id,activity:ke(n,r.machine,r.id),unseen:o.includes(P(r.machine,r.id)),saved:r!==te,scope:d,onSelect:()=>N(r.machine,r.projectId,r.id)},P(r.machine,r.id))}function de(e){return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`li`,{className:B(`mx-0.5 h-9 pt-2`,e.first&&`mt-auto`),children:(0,W.jsxs)(`button`,{"aria-expanded":e.open,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:e.onToggle,children:[(0,W.jsx)(V,{icon:e.icon,className:`size-3 shrink-0`}),(0,W.jsx)(`span`,{className:`-ms-1 shrink-0`,children:e.label}),(0,W.jsx)(`span`,{className:`bg-sidebar-border/60 h-px min-w-2 flex-1`}),(0,W.jsx)(V,{icon:jr,className:B(`size-3 shrink-0 transition-transform`,!e.open&&`rotate-180`)})]})}),e.open&&e.items.map(e=>ue(e,e.status===`inactive`))]})}return(0,W.jsxs)(`aside`,{className:B(`bg-sidebar text-sidebar-foreground border-sidebar-border flex flex-none border-r select-none`,e.className),children:[(0,W.jsxs)(`div`,{className:B(`relative flex min-w-0 flex-col`,e.mobile&&`flex-1`),style:e.mobile?void 0:{width:C},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)(iF,{buttonClassName:lI}):(0,W.jsx)(`button`,{className:B(lI,`size-7 [&>svg]:size-4.5`),title:`Hide sidebar (${Vt}+B)`,"aria-label":`Hide sidebar`,onClick:e.onHide,children:(0,W.jsx)(V,{icon:rs})}),(0,W.jsx)(gF,{scope:d,onScope:f,onEdit:g,onAddProject:m}),e.mobile&&(0,W.jsx)(_F,{hideDone:!0}),(0,W.jsxs)(`div`,{className:`ml-auto flex items-center gap-0.75`,children:[(0,W.jsx)(`button`,{className:B(lI,`size-7 [&>svg]:size-4.5`),title:`Search (${Vt}+K)`,"aria-label":`Search`,onClick:()=>u(!0),children:(0,W.jsx)(V,{icon:cr})}),(0,W.jsx)(`button`,{className:B(lI,`size-7 [&>svg]:size-4.5`),title:`New thread (${Vt}+N)`,onClick:ce,children:(0,W.jsx)(V,{icon:bs})})]})]}),(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)(hF,{machine:n.machine,projectId:n.projectId,sessions:re.filter(e=>P(e.machine,se(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:()=>N(ne.machine,ne.projectId,null)}),re.map(e=>ue(e,!1))]}),O.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`}),D.length>0&&de({icon:Ms,label:_?`Snoozed`:`Snoozed (${D.length})`,items:D,open:_,onToggle:()=>v(!_),first:!0}),A.length>0&&de({icon:ts,label:y?`Minimized`:`Minimized (${A.length})`,items:A,open:y,onToggle:()=>b(!y),first:D.length===0}),de({icon:Es,label:`Done`,items:c,open:x,onToggle:()=>S(!x),first:D.length===0&&A.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)(sI,{buttonClassName:lI,mobile:!1}),(0,W.jsxs)(`div`,{className:`relative`,children:[(0,W.jsxs)(`button`,{className:B(lI,`h-8 w-full justify-start gap-2 px-2.5 text-sm`),title:`Settings`,onClick:()=>j(!0),children:[(0,W.jsx)(V,{icon:ms}),(0,W.jsx)(`span`,{className:`truncate`,children:`Settings`})]}),(0,W.jsxs)(`div`,{className:`absolute top-1.5 right-1.5`,children:[(0,W.jsx)(_F,{className:`@max-[13rem]:hidden`,hideDone:!1}),(0,W.jsx)(_F,{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:le,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`})})]}),p!==null&&(0,W.jsx)(yD,{machine:p,onClose:()=>m(null),onAdd:e=>{m(null),N(e.machine,e.id,null)}}),h!==null&&(0,W.jsx)(xD,{project:h,onClose:()=>g(null),onRemoved:()=>{d?.machine===h.machine&&d.projectId===h.id&&f(null),g(null)}})]})}var dI={running:`Running`,completed:`Done`,failed:`Failed`,stopped:`Stopped`};function fI(e,t){return{agents:e.flatMap(e=>e.kind===`subagent`?[{item:e,agentId:e.agentId,status:mI(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:mI(e.status,e.background.taskId,t)}]:[])}}function pI(e){return e.description===``?e.command:e.description}function mI(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`:dI[e]:dI[r]}function hI(e){return(0,W.jsx)(`span`,{className:B(e.active&&`text-shimmer`),children:e.text})}function gI(e){return(0,W.jsxs)(`span`,{className:B(`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:B(`text-foreground shrink-0`,e.grouped?`font-normal`:`font-medium`),children:(0,W.jsx)(hI,{text:e.title,active:e.pending})}),e.subtitle!==void 0&&e.subtitle!==``&&(0,W.jsx)(`span`,{className:B(`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:B(`min-w-0 truncate tabular-nums`,e.grouped?`text-muted-foreground/70`:`text-muted-foreground`),children:t},t))]})}function _I(e){return(0,W.jsx)(`span`,{"aria-hidden":!0,className:B(`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:sn,strokeWidth:2.5,className:B(`size-3.5 transition-transform`,!e.open&&`-rotate-90`)})})}function vI(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)(gI,{title:e.title,subtitle:e.subtitle,args:e.args,pending:e.pending,grouped:e.grouped})}),t!==null&&(0,W.jsx)(_I,{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:B(`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:B(`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:B(`min-w-0 pt-1`,e.rail!==!1&&`ps-3`),children:e.children})]})}var yI=new Map([[`build`,`text-blue-400`],[`explore`,`text-yellow-400`],[`plan`,`text-pink-400`],[`review`,`text-green-400`],[`writer`,`text-purple-400`]]),bI=new Map([[`Running`,`Launched agent`],[`Done`,`Agent finished`],[`Failed`,`Agent failed`],[`Stopped`,`Agent stopped`]]),xI=new Map([[`Running`,`Started in background`],[`Done`,`Background task finished`],[`Failed`,`Background task failed`],[`Stopped`,`Background task stopped`]]),SI=[`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 CI(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:yI.get(n)??SI[r%SI.length]}}function wI(e){return(0,W.jsxs)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,"aria-hidden":!0,className:B(`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 TI(e){return(0,W.jsx)(`svg`,{viewBox:`0 0 16 16`,"aria-hidden":!0,className:B(`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 EI(e){let t=e.item;if(t.kind===`agent_message`){let n=t.target;return(0,W.jsx)(DI,{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)(DI,{label:xI.get(n.status)??`Background task ${n.status.toLowerCase()}`,detail:pI(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)(DI,{label:bI.get(n.status)??`Agent ${n.status.toLowerCase()}`,detail:t.description,pending:n.status===`Running`,onOpen:()=>e.onOpen(t.id)})}function DI(e){let t=(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`span`,{className:`text-muted-foreground shrink-0`,children:(0,W.jsx)(hI,{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:Tr,className:`size-3.5`})})]})}function OI(e){let t=(0,U.useRef)(null),[n,r]=(0,U.useState)(``),[i,a]=(0,U.useState)(0),[o,s]=(0,U.useState)([]),c=o.length===0?-1:Math.min(i,o.length-1);(0,U.useEffect)(()=>t.current?.focus(),[]),(0,U.useEffect)(()=>{let t=e.content.current;if(t===null)throw Error(`transcript is not mounted`);if(n===``)return;let r=0,i=new MutationObserver(()=>{cancelAnimationFrame(r),r=requestAnimationFrame(()=>s(kI(t,n)))});return i.observe(t,{childList:!0,subtree:!0,characterData:!0}),()=>{i.disconnect(),cancelAnimationFrame(r)}},[n,e.content]),(0,U.useEffect)(()=>{if(o.length!==0)return CSS.highlights.set(`transcript-find`,new Highlight(...o)),c!==-1&&CSS.highlights.set(`transcript-find-current`,new Highlight(o[c])),()=>{CSS.highlights.delete(`transcript-find`),CSS.highlights.delete(`transcript-find-current`)}},[o,c]);function l(t,n){let i=e.content.current,o=e.scroller.current;if(i===null||o===null)throw Error(`transcript is not mounted`);let c=t===``?[]:kI(i,t),l=c.length===0?0:(n+c.length)%c.length;if(r(t),a(l),s(c),c.length===0)return;let u=c[l].getBoundingClientRect(),d=o.getBoundingClientRect();(u.top<d.top+48||u.bottom>d.bottom-48)&&o.scrollBy({top:u.top-d.top-d.height/3})}return(0,W.jsxs)(`div`,{"data-transcript":!0,className:`bg-card absolute top-2 right-6 z-30 flex items-center gap-1 rounded-lg border p-1 shadow-lg`,children:[(0,W.jsx)(Kf,{ref:t,"data-thread-find":!0,className:`h-7 w-52`,placeholder:`Find in thread`,"aria-label":`Find in thread`,value:n,onChange:e=>l(e.target.value,0),onKeyDown:t=>{t.key===`Escape`?(t.preventDefault(),e.onClose()):t.key===`Enter`&&(t.preventDefault(),l(n,c+(t.shiftKey?-1:1)))}}),(0,W.jsx)(`span`,{className:`text-muted-foreground w-16 text-center text-xs tabular-nums`,children:n===``?``:o.length===0?`No results`:`${c+1} of ${o.length}`}),(0,W.jsx)(H,{variant:`ghost`,size:`icon-sm`,"aria-label":`Previous match`,onClick:()=>l(n,c-1),children:(0,W.jsx)(V,{icon:ho})}),(0,W.jsx)(H,{variant:`ghost`,size:`icon-sm`,"aria-label":`Next match`,onClick:()=>l(n,c+1),children:(0,W.jsx)(V,{icon:sn})}),(0,W.jsx)(H,{variant:`ghost`,size:`icon-sm`,"aria-label":`Close find`,onClick:e.onClose,children:(0,W.jsx)(V,{icon:bo})})]})}function kI(e,t){let n=[],r=[],i=``,a=document.createTreeWalker(e,NodeFilter.SHOW_TEXT);for(let e=a.nextNode();e!==null;e=a.nextNode())e instanceof Text&&(n.push(e),r.push(i.length),i+=e.data);let o=new RegExp(t.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),`gi`),s=[],c=0;for(let e of i.matchAll(o)){let t=e.index+e[0].length;for(;c+1<r.length&&r[c+1]<=e.index;)c++;let i=c;for(;i+1<r.length&&r[i+1]<t;)i++;let a=document.createRange();a.setStart(n[c],e.index-r[c]),a.setEnd(n[i],t-r[i]),a.getClientRects().length>0&&s.push(a)}return s}function AI(e){let[t,n]=(0,U.useState)(!1),r=nn(),i=e.plan,a=jI(i),o=i.length>900||i.split(`
|
|
16
|
+
`,``,``,``,``,`\x1B[99;5u`,`\x1B[100;5u`,`\x1B[111;5u`,`\x1B[122;5u`];function FN(e,t){return e.y<t.y||e.y===t.y&&e.x<t.x}var IN=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`&&PN.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(FN(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===gM.spacerTail&&--a.x;let o={x:t.cursorX,y:t.cursorY};if(FN(a,i)||FN(o,i))return null;let s=FN(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)}},LN=navigator.userAgent.includes(`Mac`),RN=navigator.userAgent.includes(`Windows`),zN=600,BN=1e3,VN=1e4,HN=new TextDecoder(`latin1`),UN=new TextDecoder;function WN(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 GN(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 KN(e){try{(await e)?.close()}catch(e){console.warn(`could not decode image`,e)}}var qN=class{element;cols=80;rows=24;canvas;input;context;core;scanner=new $M;handlers;observer;prompt;search;images;pointer;notifications=new qM;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 NM(Math.max(1,Math.floor(window.innerWidth/this.metrics.width)),this.rows,e.scrollback,t.onReply,t.onBell),this.prompt=new IN(this.core),this.search=new FM(this.core,()=>this.redraw()),this.images=new mj(this.core),this.pointer=new NN({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(HM(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:GN(e.fontFamily),ligatures:e.ligatures,cursorText:t.cursorText,selectionBackground:t.selectionBackground,selectionForeground:t.selectionForeground,matchBackground:t.palette[8],activeMatchBorder:t.palette[3]}}measure(){return wN(this.context,this.options.fontSize,this.appearance.fontFamily,this.options.lineHeight,window.devicePixelRatio||1)}applyTerminalOptions(){let e=this.options.colors;this.core.setColors({foreground:WN(e.foreground),background:WN(e.background),cursor:WN(e.cursor),palette:e.palette.map(WN)}),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(uj(e.data));let n=HN.decode(e.data);if(n.startsWith(`1337;File=`))return this.decodeImage(fj(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:BM(r[1]),terminator:e.terminator,generation:this.prompt.generation,epoch:this.epoch,atPrompt:this.prompt.shell===`prompt`}),!1;let a=VM(i);return a!==null&&this.handlers.onClipboard(a),!1}if(n===`10;?`||n===`11;?`||n===`12;?`)return t||this.handlers.onReply(UM(n,this.core.currentColors(),e.terminator)),!1;if(n.startsWith(`4;`)){if(!t)for(let t of WM(n,this.core.currentColors().palette,e.terminator))this.handlers.onReply(t);return!1}if(n===`9;4`||n.startsWith(`9;4;`)){let e=GM(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(UN.decode(e.data)):KM(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`),VN)});try{let r=await Promise.race([e,i]);r===`timeout`?(console.warn(`image decoding took too long, skipping the image`),KN(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()},BN));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);DN({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=>rM(this.context,a,e,this.metrics,i)}),rM(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()},zN))}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(!LN||!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)||LN&&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=RN&&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(LN?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((LN?e.metaKey&&r===`v`:e.ctrlKey&&e.shiftKey&&r===`v`||e.shiftKey&&!e.ctrlKey&&r===`insert`||i&&r===`v`)||LN&&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=()=>{LN&&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)}},JN=new Map,YN=new Map,XN=null,ZN=0;function QN(e){return wP().open&&DP()?.tabId===e&&!document.hidden&&document.hasFocus()}function $N(e){if(QN(e))return!1;let t=wP();return t.alerts.includes(e)||TP({alerts:[...t.alerts,e]}),!0}function eP(e){if(!$N(e)||YN.has(e))return;let t=JN.get(e);t!==void 0&&performance.now()-t<5e3||YN.set(e,window.setTimeout(()=>{YN.delete(e),QN(e)||(JN.set(e,performance.now()),nP(e,``,`Bell`))},500))}function tP(e,t,n){$N(e)&&(window.clearTimeout(YN.get(e)),YN.delete(e),JN.set(e,performance.now()),nP(e,t,n))}function nP(e,t,n){let r=AP(e);r&&Da(t||jP(r),n,{machine:SP(),project:r.projectId??`global`,tabId:e}).catch(e=>console.error(`could not show a notification`,e))}function rP(){let e=performance.now();if(e-ZN<150)return;ZN=e,XN??=new AudioContext,XN.state===`suspended`&&XN.resume();let t=XN.createOscillator(),n=XN.createGain(),r=XN.currentTime;t.frequency.value=880,n.gain.setValueAtTime(.1,r),n.gain.exponentialRampToValueAtTime(.001,r+.15),t.connect(n).connect(XN.destination),t.start(r),t.stop(r+.15)}function iP(e){return{alerts:wP().alerts.filter(t=>e(t)&&!QN(t))}}function aP(e){window.clearTimeout(YN.get(e)),YN.delete(e),JN.delete(e)}function oP(e){return e.key===`Enter`&&e.shiftKey&&!e.ctrlKey&&!e.altKey&&!e.metaKey}function sP(e){let t=new qN(xP(),{onData:t=>{wP().status===`active`&&LP(e,cP(t))},onReply:t=>{t===`\x1B[I`||t===`\x1B[O`?LP(e,t):RP(e,t)},onResize:(t,n)=>FP({type:`resize`,id:e,cols:t,rows:n}),onTitle:t=>TP({titles:{...wP().titles,[e]:t}}),onProgress:t=>TP({progress:{...wP().progress,[e]:t}}),onBell:()=>{let n=EP().behavior;n.bellSound&&rP(),n.bellFlash&&t.element.isConnected&&!document.hidden&&t.element.animate([{opacity:.4},{opacity:1}],{duration:200,easing:`ease-out`}),eP(e)},onNotify:(t,n)=>tP(e,t,n),onClipboard:PD,onClipboardRead:n=>{QN(e)&&FD(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=EP(),i=L(R(),SP()).system;if(i===null)throw Error(`the terminal machine is not connected`);let a=i.platform;if(wP().status===`active`&&r.behavior.modernizeShiftEnter&&oP(n)&&!t.isKittyKeyboard())return n.preventDefault(),t.beforeInput(`\x1B\r`),LP(e,`\x1B\r`),!1;if(wP().status===`active`&&r.behavior.pasteBrowserImages&&window.isSecureContext&&LD(n,a)&&!(It&&r.behavior.windowsCopyPaste&&n.ctrlKey)){n.preventDefault();let r=ID[a].data;return t.beforeInput(r),RD(SP(),t).then(t=>{t||LP(e,r)}).catch(t=>{BD(t),LP(e,r)}),!1}return!KP(n)||(n.preventDefault(),TP({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(),zD(SP(),t,n).catch(BD))},!0),t}function cP(e){if(!wP().ctrl||(TP({ctrl:!1}),e.length!==1))return e;let t=e.toUpperCase().charCodeAt(0);return t>=64&&t<=95?String.fromCharCode(t-64):e}function lP(){return{titles:{},progress:{},alerts:[],finding:null}}var uP=new TextEncoder,dP=new Map,fP=new Set,pP=new Set,mP={status:`connecting`,failure:null,loaded:!1,open:!1,instance:null,layout:{tabs:[],active:{}},ctrl:!1,...lP()},hP=null,gP=null,_P=!1;async function vP(){d(),NP(),nt.history.subscribe(({action:e})=>{(e.type===`PUSH`||e.type===`REPLACE`)&&d(),NP()});try{await Promise.all([wj(),vp(EP())]),TP({loaded:!0})}catch(e){console.error(`could not start the terminal`,e),TP({failure:Ht(e)});return}ht({close:e=>{e===gP&&TP({status:`connecting`})},terminal:(e,t)=>{e===gP&&WP(t)},frame:(e,t)=>{e===gP&&UP(t)}}),yP(),nt.history.subscribe(yP),nt.history.subscribe(tF),document.addEventListener(`visibilitychange`,()=>TP({})),window.addEventListener(`focus`,()=>{TP({}),hP!==null&&qP(hP,JP(hP))}),window.addEventListener(`blur`,()=>TP({})),`serviceWorker`in navigator&&navigator.serviceWorker.addEventListener(`message`,e=>{e.data.type===`select`&&PP(e.data.machine,e.data.project,e.data.tabId)});let e=R().prefs,t=bP();i(()=>{yP();let n=R().prefs,r=bP(),i=n.theme!==e.theme||n.terminal!==e.terminal||r!==t;e=n,t=r,i&&XP()}),ZP()}function yP(){let e=O()??R().selection?.machine??null;if(e!==gP&&(gP!==null&&_P&&FP({type:`detach`}),GP([]),fP.clear(),gP=e,_P=!1,TP({status:`connecting`,instance:null,layout:{tabs:[],active:{}},...lP()})),gP===null)return;let t=L(R(),gP).status===`online`;t&&!_P&&(_P=!0,FP({type:`attach`})),t||(_P=!1)}function bP(){return gP===null?null:L(R(),gP).config?.terminal.behavior.terminalIdentity??null}function xP(){if(gP===null)throw Error(`the terminal has no machine`);let e=L(R(),gP);if(e.config===null||e.system===null)throw Error(`${e.name} is not connected`);return yp(EP(),e.config.terminal.behavior.terminalIdentity)}function SP(){if(gP===null)throw Error(`the terminal has no machine`);return gP}function CP(e){return pP.add(e),()=>{pP.delete(e)}}function wP(){return mP}function TP(e){mP={...mP,...e},mP={...mP,...iP(e=>dP.has(e))};for(let e of pP)e()}function EP(){return R().prefs.terminal}function DP(){let e=O()===null?R().selection?.projectId:A();return e===void 0?null:{view:e,tabs:OP(mP.layout,e),tabId:mP.layout.active[e]??null}}function OP(e,t){return e.tabs.filter(e=>kP(e)===t)}function kP(e){return e.projectId??`global`}function AP(e){return mP.layout.tabs.find(t=>t.id===e)}function jP(e){return(e.customName??mP.titles[e.id])||`Terminal`}function MP(e){e?M({bottom:`terminal`}):l(`overlay`,()=>M({bottom:void 0}))}function NP(){let e=se().bottom===`terminal`||O()!==null;e!==mP.open&&TP({open:e})}function PP(e,t,n){if(t===`global`)QP(e,Ae);else{let n=R().selection;(n?.machine!==e||n.projectId!==t)&&Ie({machine:e,projectId:t,sessionId:null}),MP(!0)}IP(e,{type:`select`,view:t,tabId:n})}function FP(e){gP!==null&&IP(gP,e)}function IP(e,t){it(e)&&z(e,`terminal`,t).catch(e=>console.error(`terminal request failed`,e))}function LP(e,t){gP!==null&&Ye(gP,0,e,typeof t==`string`?uP.encode(t):t)}function RP(e,t){gP!==null&&Ye(gP,1,e,uP.encode(t))}function zP(e,t,n,r){JP(e).find(t,n,r)}function BP(e,t){return JP(e).onFindResults(t)}function VP(e){let t=JP(e);t.clearFind(),TP({finding:null}),t.focus()}function HP(){TP({ctrl:!mP.ctrl})}function UP(e){let t=dP.get(e.id);if(!t)return;let n=e.kind===3,r=n&&fP.delete(e.id);r&&t.reset(),t.write(e.data,n),r&&fP.size===0&&TP({status:`active`})}function WP(e){let t=e.type===`active`&&e.instance!==mP.instance;if(t&&GP([]),GP(e.layout.tabs),e.type===`active`){fP.clear(),dP.forEach((e,t)=>{fP.add(t),e.element.isConnected&&qP(t,e)}),TP({...t&&{instance:e.instance,...lP()},status:fP.size===0?`active`:`connecting`,layout:e.layout}),tF();return}for(let e of fP)dP.has(e)||fP.delete(e);let n=R().selection?.projectId,r=n!==void 0&&OP(mP.layout,n).length>0&&OP(e.layout,n).length===0;TP({status:fP.size===0?`active`:`connecting`,layout:e.layout}),r&&mP.open&&MP(!1),tF()}function GP(e){let t=new Set(e.map(e=>e.id));dP.forEach((e,n)=>{t.has(n)||(e.dispose(),dP.delete(n),aP(n))});for(let e of t)dP.has(e)||dP.set(e,sP(e))}function KP(e){return e.key.toLowerCase()===`f`?Rt?e.metaKey&&!e.ctrlKey&&!e.altKey:e.ctrlKey&&e.shiftKey&&!e.altKey&&!e.metaKey:!1}function qP(e,t){FP({type:`resize`,id:e,cols:t.cols,rows:t.rows})}function JP(e){let t=dP.get(e);if(!t)throw Error(`terminal ${e} does not exist`);return t}function YP(e,t){let n=JP(e);t.append(n.element),n.fit();for(let e of dP.values())e.presize(n.cols,n.rows);return hP=e,qP(e,n),n.focus(),()=>{n.element.remove(),hP===e&&(hP=null)}}async function XP(){if(await vp(EP()),dP.size>0){let e=xP();for(let t of dP.values())t.setOptions(e)}TP({})}function ZP(){let e=se(),t=O(),n=t??e.machine,r=t===null?e.project:Ae,i=e.terminal;if(n===void 0||r===void 0||i===void 0)return;M({terminal:void 0});let a=CP(()=>{mP.status===`active`&&gP===n&&(a(),PP(n,r,Number(i)))})}function QP(e,t){ct(e,t)}function $P(e){let t=e.terminals.map(kP),n=localStorage.getItem(`lastTerminalView`);QP(e.id,t.find(e=>e===n)??t.at(0)??`global`)}async function eF(e,t){try{await z(e,`terminal`,{type:`createTab`,projectId:t})}catch(e){console.error(`terminal request failed`,e);return}QP(e,t??`global`)}function tF(){let e=wP(),t=O();if(t===null||e.instance===null||t!==SP()||OP(e.layout,A()).length>0)return;let n=e.layout.tabs.at(0);if(n!==void 0){QP(t,kP(n));return}let r=R().machines.find(e=>e.id!==t&&e.status===`online`&&e.terminals.length>0);r===void 0?l(`chat`,()=>void nt.navigate({to:`/`,search:{},replace:!0})):$P(r)}function nF(e){let t=k(e=>e.machines).filter(e=>e.status===`online`),n=t.some(e=>e.terminals.length>0);return t.length===0?null:(0,W.jsxs)(fn,{children:[(0,W.jsx)(dr,{asChild:!0,children:(0,W.jsx)(`button`,{className:B(`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:to,className:`size-4`})})}),(0,W.jsx)(vn,{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)(rF,{})})]})}function rF(e){let t=k(e=>e.machines),n=k(e=>e.projects),r=e.contextMenu?Fn:wn;return t.filter(e=>e.status===`online`).flatMap(e=>[(0,W.jsxs)(r,{onSelect:()=>void eF(e.id,null),children:[(0,W.jsx)(jd,{icon:e.icon}),(0,W.jsx)(`span`,{className:`max-w-60 truncate`,children:e.name})]},e.id),...n.filter(t=>t.machine===e.id&&!t.hidden&&!t.scratch).map(t=>(0,W.jsxs)(r,{className:`pl-7`,onSelect:()=>void eF(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 iF(e){let t=k(e=>e.machines).filter(e=>e.status===`online`),n=t.filter(e=>e.terminals.length>0),r=n.reduce((e,t)=>e+t.terminals.length,0),i=localStorage.getItem(`lastTerminal`),a=(0,W.jsxs)(`button`,{className:B(e.buttonClassName,`relative size-7 [&>svg]:size-4.5`),title:`Terminal`,"aria-label":`Terminal`,disabled:t.length===0,onClick:n.length>0?()=>$P(n.find(e=>e.id===i)??n[0]):void 0,children:[(0,W.jsx)(V,{icon:Ss}),r>0&&(0,W.jsx)(`span`,{className:`text-foreground/75 border-sidebar pointer-events-none absolute -top-0.5 -right-0.5 grid h-3.5 min-w-3.5 place-items-center rounded-full border bg-[color-mix(in_srgb,var(--foreground)_8%,var(--background))] px-0.5 text-[9px] leading-none font-medium tabular-nums`,children:r})]});return(0,W.jsxs)(`div`,{className:`mr-1.5 flex items-center gap-0.75`,children:[(0,W.jsx)(`button`,{className:B(e.buttonClassName,`size-7 [&>svg]:size-4.5`),title:`Settings`,"aria-label":`Settings`,onClick:()=>j(!0),children:(0,W.jsx)(V,{icon:ms})}),n.length>0?a:(0,W.jsxs)(fn,{children:[(0,W.jsx)(dr,{asChild:!0,children:a}),(0,W.jsx)(vn,{align:`start`,className:`max-h-80 w-auto min-w-40 overflow-y-auto`,onCloseAutoFocus:e=>e.preventDefault(),children:(0,W.jsx)(rF,{})})]})]})}var aF=`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`,oF={active:{status:`snoozed`,icon:Ms},snoozed:{status:`active`,icon:ws},minimized:{status:`active`,icon:fo},inactive:{status:`minimized`,icon:ts},pinned:{status:`active`,icon:os}};function sF(e){let t=e.session,n=Ns(t.machine,t.projectId),r=k(e=>L(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(){Ue(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`?Se(t.machine,t.id,{status:`active`}):b()),e.clientX-n.x<-e.currentTarget.offsetWidth*.4&&Se(t.machine,t.id,{status:oF[t.status].status}))}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&&Math.abs(n)<=Math.abs(r)?d.current=null:(t.swiping=!0,l(n)))},onPointerUp:x,onPointerCancel:()=>{d.current=null,l(0)}},C=c!==0&&(0,W.jsx)(`div`,{className:B(`absolute inset-x-0 flex items-center rounded-md px-4 text-white`,e.slim?`inset-y-0`:`inset-y-0.5`,c>0&&t.status!==`inactive`&&`bg-success`,c>0&&t.status===`inactive`&&`bg-[#56b6c2]`,c<0&&t.status===`active`&&`bg-[#c678dd]`,c<0&&t.status===`snoozed`&&`bg-[#d19a66]`,c<0&&t.status===`minimized`&&`bg-info`,c<0&&t.status===`inactive`&&`bg-[#5c6370]`,c<0&&t.status===`pinned`&&`bg-[#e06c75]`,c<0&&`justify-end`),children:(0,W.jsx)(V,{icon:c<0?oF[t.status].icon:t.status===`inactive`?cs:Ds,className:`size-6`})}),w=(0,W.jsx)(lr,{open:o,onOpenChange:s,children:(0,W.jsxs)(Kn,{children:[(0,W.jsxs)(Er,{children:[(0,W.jsx)(Ln,{children:`Stop running work?`}),(0,W.jsx)(Pn,{children:`The agent or background tasks are running. Do you really want to stop them?`})]}),(0,W.jsxs)(br,{children:[(0,W.jsx)(Jn,{children:`Cancel`}),(0,W.jsx)(rr,{variant:`destructive`,onClick:y,children:`Stop and Mark Done`})]})]})}),T=(0,W.jsx)(Xn,{className:`w-44`,onCloseAutoFocus:e=>{u.current!==null&&(e.preventDefault(),u.current.focus(),u.current.select())},children:(0,W.jsx)(_k,{session:t,context:!0,mobile:!0,onDeactivate:b,onRename:()=>a(t.title)})}),E=i===null?(0,W.jsx)(`span`,{className:B(`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)(yk,{session:t,awaitingTitle:!e.saved})}):(0,W.jsx)(`form`,{className:`min-w-0 flex-1`,onSubmit:e=>{e.preventDefault();let n=i.trim();a(null),n!==``&&n!==t.title&&Se(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=B(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)(ar,{children:[(0,W.jsx)(Wn,{asChild:!0,disabled:!e.saved,children:(0,W.jsxs)(`div`,{role:`button`,tabIndex:0,className:B(aF,D,`flex h-9 items-center gap-2.5 px-2.5`,c!==0&&`bg-sidebar`),style:c===0?void 0:{transform:`translateX(${c}px)`},...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:Qn(t.updatedAt)})]})}),T]}),w]}):(0,W.jsxs)(`li`,{className:`relative list-none py-0.5`,children:[C,(0,W.jsxs)(ar,{children:[(0,W.jsx)(Wn,{asChild:!0,disabled:!e.saved,children:(0,W.jsx)(`div`,{role:`button`,tabIndex:0,className:B(aF,D,h&&!e.selected&&c===0&&`opacity-70`,c!==0&&`bg-sidebar`),style:c===0?void 0:{transform:`translateX(${c}px)`},...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,(0,W.jsx)(vk,{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)(jd,{icon:r,className:`size-3 shrink-0`}),(0,W.jsxs)(`span`,{className:B(`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===`pinned`&&(0,W.jsx)(V,{icon:ss,className:`size-3 shrink-0`}),t.status===`snoozed`&&(0,W.jsx)(V,{icon:Ms,className:`size-3 shrink-0`}),(0,W.jsx)(`span`,{className:`shrink-0 tabular-nums`,children:Qn(t.updatedAt)})]})]})})}),T]}),w]})}function cF(e){let t=Ns(e.machine,e.projectId),n=k(t=>L(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:B(aF,`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:bs,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)(jd,{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 lF=`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 uF(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(){Ue(t.machine,t.id,null)}function m(){u?a(!0):p()}let h=(0,W.jsx)(lr,{open:i,onOpenChange:a,children:(0,W.jsxs)(Kn,{children:[(0,W.jsxs)(Er,{children:[(0,W.jsx)(Ln,{children:`Stop running work?`}),(0,W.jsx)(Pn,{children:`The agent or background tasks are running. Do you really want to stop them?`})]}),(0,W.jsxs)(br,{children:[(0,W.jsx)(Jn,{children:`Cancel`}),(0,W.jsx)(rr,{variant:`destructive`,onClick:p,children:`Stop and Mark Done`})]})]})}),g=e.saved&&(0,W.jsxs)(fn,{children:[(0,W.jsx)(dr,{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:Po,className:`size-3.5`})})}),(0,W.jsx)(vn,{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)(_k,{session:t,context:!1,mobile:!1,onDeactivate:m,onRename:()=>r(t.title)})})]}),_=(0,W.jsx)(Xn,{className:`w-44`,onCloseAutoFocus:e=>{o.current!==null&&(e.preventDefault(),o.current.focus(),o.current.select())},children:(0,W.jsx)(_k,{session:t,context:!0,mobile:!1,onDeactivate:m,onRename:()=>r(t.title)})}),v=n===null?(0,W.jsx)(`span`,{className:B(`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)(yk,{session:t,awaitingTitle:!e.saved})}):(0,W.jsx)(`form`,{className:`min-w-0 flex-1`,onSubmit:e=>{e.preventDefault();let i=n.trim();r(null),i!==``&&i!==t.title&&Se(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`})}),y=B(e.selected&&`bg-sidebar-row-active text-sidebar-foreground`,f&&`text-sidebar-muted-foreground/75 hover:bg-sidebar-row-hover hover:text-sidebar-foreground has-[[data-state=open]]:bg-sidebar-row-hover has-[[data-state=open]]:text-sidebar-foreground`,!e.selected&&!f&&`text-sidebar-foreground hover:bg-sidebar-row-hover has-[[data-state=open]]:bg-sidebar-row-hover bg-transparent`);return(0,W.jsxs)(`li`,{className:`list-none`,children:[(0,W.jsxs)(ar,{children:[(0,W.jsx)(Wn,{asChild:!0,disabled:!e.saved,children:(0,W.jsxs)(`div`,{role:`button`,tabIndex:0,className:B(lF,y,`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:[(0,W.jsxs)(`span`,{className:`group-any-hover/sidebar-row:mask-r-from-[calc(100%-5rem)] group-any-hover/sidebar-row:mask-r-to-[calc(100%-3rem)] flex min-w-0 flex-1 items-center gap-2 group-has-[[data-state=open]]/sidebar-row:mask-r-from-[calc(100%-5rem)] group-has-[[data-state=open]]/sidebar-row:mask-r-to-[calc(100%-3rem)]`,children:[v,t.status===`pinned`&&(0,W.jsx)(V,{icon:ss,className:`text-muted-foreground/65 size-3 shrink-0`}),t.status===`snoozed`&&(0,W.jsx)(V,{icon:Ms,className:`text-secondary-label size-3 shrink-0`}),(0,W.jsx)(vk,{activity:e.activity,backgroundRunning:c,done:d}),(0,W.jsx)(`span`,{className:`text-secondary-label shrink-0 text-xs tabular-nums`,children:Qn(t.updatedAt)})]}),e.saved&&(0,W.jsxs)(`div`,{className:`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 pr-1.5 opacity-0 transition-opacity has-[[data-state=open]]:pointer-events-auto has-[[data-state=open]]:opacity-100`,children:[g,(0,W.jsx)(`button`,{className:`text-muted-foreground hover:text-foreground ms-0.5 me-0.5 inline-flex size-5 cursor-pointer items-center justify-center transition-colors`,title:`Done`,"aria-label":`Done`,onClick:e=>{e.stopPropagation(),m()},children:(0,W.jsx)(V,{icon:Ds,strokeWidth:1.35,className:`size-5 scale-110`})})]})]})}),_]}),h]})}function dF(e){return(0,W.jsx)(`li`,{className:`list-none`,children:(0,W.jsxs)(`div`,{role:`button`,tabIndex:0,className:B(lF,`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:bs,className:`text-warning-foreground size-4 shrink-0`})]})})}var fF=`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 pF(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 _(){Ue(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`?Se(t.machine,t.id,{status:`active`}):v()),e.clientX-n.x<-e.currentTarget.offsetWidth*.4&&Se(t.machine,t.id,{status:oF[t.status].status}))}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&&Math.abs(n)<=Math.abs(r)?l.current=null:(t.swiping=!0,s(n)))},onPointerUp:y,onPointerCancel:()=>{l.current=null,s(0)}},x=o!==0&&(0,W.jsx)(`div`,{className:B(`absolute inset-0 flex items-center rounded-md px-4 text-white`,o>0&&t.status!==`inactive`&&`bg-success`,o>0&&t.status===`inactive`&&`bg-[#56b6c2]`,o<0&&t.status===`active`&&`bg-[#c678dd]`,o<0&&t.status===`snoozed`&&`bg-[#d19a66]`,o<0&&t.status===`minimized`&&`bg-info`,o<0&&t.status===`inactive`&&`bg-[#5c6370]`,o<0&&t.status===`pinned`&&`bg-[#e06c75]`,o<0&&`justify-end`),children:(0,W.jsx)(V,{icon:o<0?oF[t.status].icon:t.status===`inactive`?cs:Ds,className:`size-6`})}),S=(0,W.jsx)(lr,{open:i,onOpenChange:a,children:(0,W.jsxs)(Kn,{children:[(0,W.jsxs)(Er,{children:[(0,W.jsx)(Ln,{children:`Stop running work?`}),(0,W.jsx)(Pn,{children:`The agent or background tasks are running. Do you really want to stop them?`})]}),(0,W.jsxs)(br,{children:[(0,W.jsx)(Jn,{children:`Cancel`}),(0,W.jsx)(rr,{variant:`destructive`,onClick:_,children:`Stop and Mark Done`})]})]})}),C=(0,W.jsx)(Xn,{className:`w-44`,onCloseAutoFocus:e=>{c.current!==null&&(e.preventDefault(),c.current.focus(),c.current.select())},children:(0,W.jsx)(_k,{session:t,context:!0,mobile:!0,onDeactivate:v,onRename:()=>r(t.title)})}),w=n===null?(0,W.jsx)(`span`,{className:B(`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)(yk,{session:t,awaitingTitle:!e.saved})}):(0,W.jsx)(`form`,{className:`min-w-0 flex-1`,onSubmit:e=>{e.preventDefault();let i=n.trim();r(null),i!==``&&i!==t.title&&Se(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=B(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)(ar,{children:[(0,W.jsx)(Wn,{asChild:!0,disabled:!e.saved,children:(0,W.jsxs)(`div`,{role:`button`,tabIndex:0,className:B(fF,T,`flex h-9 items-center gap-2 px-2.5`,p&&!e.selected&&o===0&&`opacity-70`,o!==0&&`bg-sidebar`),style:o===0?void 0:{transform:`translateX(${o}px)`},...b,onKeyDown:t=>{t.key===`Enter`&&e.onSelect()},children:[w,t.status===`pinned`&&(0,W.jsx)(V,{icon:ss,className:`text-muted-foreground/65 size-3 shrink-0`}),t.status===`snoozed`&&(0,W.jsx)(V,{icon:Ms,className:`text-secondary-label size-3 shrink-0`}),(0,W.jsx)(vk,{activity:e.activity,backgroundRunning:f,done:h}),(0,W.jsx)(`span`,{className:`text-secondary-label shrink-0 text-xs tabular-nums`,children:Qn(t.updatedAt)})]})}),C]}),S]})}function mF(e){return(0,W.jsx)(`li`,{className:`list-none`,children:(0,W.jsxs)(`div`,{role:`button`,tabIndex:0,className:B(fF,`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:bs,className:`text-warning-foreground size-4 shrink-0`})]})})}function hF(e){let t=Ns(e.machine,e.projectId),n=k(t=>L(t,e.machine).icon),r=k(e=>e.selection),i=k(e=>e.machines),a=k(e=>e.unseen),o=r!==null&&r.sessionId===null&&r.machine===e.machine&&r.projectId===e.projectId,s=e.mobile?mF:dF,c=e.mobile?pF:uF;function l(){Ie({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)(jd,{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:to,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:ke(i,t.machine,t.id),unseen:a.includes(P(t.machine,t.id)),saved:t!==e.started,onSelect:()=>Ie({machine:t.machine,projectId:t.projectId,sessionId:t.id})},P(t.machine,t.id)))]})}function gF(e){let t=k(e=>e.machines),n=k(e=>e.projects),r=k(e=>e.sessions),i=k(e=>e.unseen),[a,o]=(0,U.useState)(!1);or(`mod+p`,()=>o(!a),{enableOnFormTags:!0,preventDefault:!0});let s=t.map(e=>({machine:e,projects:n.filter(t=>t.machine===e.id&&!t.hidden&&!t.scratch)})).filter(e=>t.length>1||e.projects.length>0||e.machine.system?.scratchAvailable===!0),c=r.filter(e=>{let n=ke(t,e.machine,e.id);return n?.running===!0||n?.waiting===!0||Object.values(n?.tasks??{}).includes(`running`)||i.includes(P(e.machine,e.id))});function l(e,t){return n.find(n=>n.machine===e&&n.id===t)}function u(e){return c.filter(t=>t.machine===e&&l(e,t.projectId)?.scratch===!0).length}function d(e){return(0,W.jsx)(wn,{className:`text-muted-foreground grid size-5 min-h-0 shrink-0 place-items-center rounded-sm p-0`,title:`Manage projects on ${e.name}`,"aria-label":`Manage projects on ${e.name}`,disabled:e.status!==`online`,onSelect:()=>{Ke(`Projects`),We({settingsMachine:e.id})},children:(0,W.jsx)(V,{icon:ys,className:`size-3.5`})})}function f(e){return e.status===`online`?e.name:e.status===`unpaired`?`${e.name} · needs pairing`:`${e.name} · offline`}return(0,W.jsxs)(fn,{open:a,onOpenChange:o,children:[(0,W.jsx)(dr,{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`:l(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`:e.scope.projectId===`no-project`?`Chat`:l(e.scope.machine,e.scope.projectId)?.name}),(0,W.jsx)(V,{icon:jr,className:`text-sidebar-muted-foreground size-3.5 shrink-0`})]})}),(0,W.jsxs)(vn,{className:`w-64`,children:[(0,W.jsxs)(kn,{value:e.scope===null?``:P(e.scope.machine,e.scope.projectId),children:[(0,W.jsxs)(mn,{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`}),c.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:c.length})]}),s.length>0&&(0,W.jsx)(On,{}),s.map(({machine:n,projects:r},i)=>(0,W.jsxs)(U.Fragment,{children:[i>0&&(0,W.jsx)(On,{}),t.length>1&&(0,W.jsxs)(`div`,{className:`flex items-center`,children:[(0,W.jsxs)(Or,{className:`flex min-w-0 flex-1 items-center gap-2 pl-[0.52rem]!`,children:[(0,W.jsx)(jd,{icon:n.icon,className:`size-3.5 shrink-0`}),(0,W.jsx)(`span`,{className:`truncate`,children:f(n)})]}),n.system?.scratchAvailable===!0&&(0,W.jsxs)(mn,{value:P(n.id,`no-project`),className:`text-muted-foreground data-[state=checked]:bg-foreground/10 data-[state=checked]:text-foreground mr-0.5 h-5 min-h-0 shrink-0 gap-1 px-1.5 py-0 text-xs *:data-[slot=dropdown-menu-radio-item-indicator]:hidden`,title:`Threads on ${n.name} without a project`,onSelect:()=>e.onScope({machine:n.id,projectId:`no-project`}),children:[(0,W.jsx)(zs,{machine:n.id,projectId:`no-project`,className:`size-3.5 shrink-0`}),`Chat`,u(n.id)>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:u(n.id)})]}),(0,W.jsxs)(`div`,{className:`flex shrink-0 items-center gap-0.5 pr-1`,children:[d(n),(0,W.jsx)(wn,{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:to,className:`size-3.5`})})]})]}),t.length===1&&n.system?.scratchAvailable===!0&&(0,W.jsxs)(mn,{value:P(n.id,`no-project`),className:`pr-1 pl-8 *:data-[slot=dropdown-menu-radio-item-indicator]:right-auto *:data-[slot=dropdown-menu-radio-item-indicator]:left-2`,onSelect:()=>e.onScope({machine:n.id,projectId:`no-project`}),children:[(0,W.jsx)(zs,{machine:n.id,projectId:`no-project`,className:`size-5 shrink-0`}),(0,W.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:`Chat`}),u(n.id)>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:u(n.id)})]}),r.map(t=>{let n=c.filter(e=>e.machine===t.machine&&e.projectId===t.id).length;return(0,W.jsxs)(mn,{value:P(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`,onSelect:()=>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.jsx)(`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:`Configure project`,"aria-label":`Configure ${t.name}`,onClick:n=>{n.stopPropagation(),o(!1),e.onEdit(t)},children:(0,W.jsx)(V,{icon:ms})})})]},P(t.machine,t.id))})]},n.id))]}),t.length===1&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(On,{}),(0,W.jsxs)(`div`,{className:`flex items-center`,children:[(0,W.jsxs)(wn,{className:`flex-1 pl-8`,onSelect:()=>e.onAddProject(t[0].id),children:[(0,W.jsx)(V,{icon:to}),`Add project…`]}),(0,W.jsx)(`div`,{className:`flex shrink-0 items-center pr-1`,children:d(t[0])})]})]})]})]})}function _F(e){let t=k(e=>e.errors),n=k(e=>e.machines),r=k(e=>e.sessions),i=k(e=>e.unseen),a=n.filter(e=>e.status===`offline`||e.status===`unpaired`),o=r.filter(e=>Object.values(ke(n,e.machine,e.id)?.tasks??{}).includes(`failed`)),s=r.filter(e=>ke(n,e.machine,e.id)?.waiting===!0),c=r.filter(e=>{let t=ke(n,e.machine,e.id);return i.includes(P(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)(bF,{session:e,icon:Eo,className:`text-success`,detail:`Done`},P(e.machine,e.id))),f=s.map(e=>(0,W.jsx)(bF,{session:e,icon:vs,className:`text-question`,detail:`Waiting for approval`},P(e.machine,e.id))),p=e.collapsed===!0&&u&&s.length>0&&l>0;return(0,W.jsxs)(`div`,{className:B(`flex shrink-0 items-center gap-1`,e.className),children:[p&&(0,W.jsxs)(vF,{className:`bg-question/15 text-question`,icon:vs,count:s.length+c.length,label:`${s.length} waiting for approval, ${c.length} done`,children:[f,d]}),!p&&u&&(0,W.jsx)(vF,{className:`bg-success/15 text-success`,icon:Eo,count:c.length,label:`${c.length} done`,children:d}),!p&&s.length>0&&(0,W.jsx)(vF,{className:`bg-question/15 text-question`,icon:vs,count:s.length,label:`${s.length} waiting for approval`,children:f}),l>0&&(0,W.jsxs)(vF,{className:B(t.length>0&&`bg-error/15 text-error`,t.length===0&&`bg-warning/15 text-warning-foreground`),icon:t.length>0?Dn:ro,count:l,label:l===1?`1 problem`:`${l} problems`,onClose:Ze,children:[t.map((e,t)=>(0,W.jsx)(yF,{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)(yF,{icon:ro,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)(bF,{session:e,icon:ro,className:`text-warning-foreground`,detail:`Background task failed`},P(e.machine,e.id)))]})]})}function vF(e){return(0,W.jsxs)(un,{onOpenChange:t=>!t&&e.onClose?.(),children:[(0,W.jsx)(bn,{asChild:!0,children:(0,W.jsxs)(`button`,{className:B(`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)(cn,{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 yF(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:B(`mt-0.5 size-4 shrink-0`,e.className)}),(0,W.jsx)(`div`,{className:`min-w-0 flex-1`,children:e.children})]})}function bF(e){return(0,W.jsx)(Mn,{asChild:!0,children:(0,W.jsx)(`button`,{className:`hover:bg-accent cursor-pointer rounded-md text-left`,onClick:()=>Ie({machine:e.session.machine,projectId:e.session.projectId,sessionId:e.session.id}),children:(0,W.jsxs)(yF,{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 xF=null,SF=null,CF=new Set,wF=new Set;function TF(e){return wF.add(e),()=>{wF.delete(e)}}function EF(){return xF}function DF(){xF!==null&&AF({open:!1,closing:xF.closing})}function OF(){return SF}function kF(){SF!==null&&jF({open:!1,closing:SF.closing})}function AF(e){xF=e;for(let e of wF)e()}function jF(e){SF=e;for(let e of wF)e()}function MF(){return document.querySelector(`[role="dialog"][data-state="open"], [role="alertdialog"][data-state="open"]`)!==null}async function NF(e,t){try{let n=await Promise.race([z(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 PF(e){if(!EP().behavior.confirmCloseBusyTab){FP({type:`closeTab`,id:e});return}if(!AP(e)||CF.has(e))return;CF.add(e);let t=await NF(SP(),e);if(CF.delete(e),t.checked&&t.program===null){FP({type:`closeTab`,id:e});return}let n=AP(e);n&&!MF()&&AF({open:!0,closing:{id:e,name:jP(n),program:t.checked?t.program:null}})}function FF(e){for(let t of e)IP(t.machine,{type:`closeTab`,id:t.id})}async function IF(e){if(!EP().behavior.confirmCloseBusyTab){FF(e);return}let t=await Promise.all(e.map(e=>NF(e.machine,e.id)));if(t.every(e=>e.checked&&e.program===null)){FF(e);return}if(MF())return;let n=t.flatMap(e=>e.checked&&e.program!==null?[e.program]:[]);jF({open:!0,closing:{tabs:e,programs:[...new Set(n)]}})}var LF=Rt?`meta+t`:`ctrl+shift+t`,RF=Rt?`meta+w`:`ctrl+shift+w`,zF=`ctrl+tab`,BF=`ctrl+shift+tab`;function VF(){let e=DP()?.tabId??null;wP().open&&e!==null&&JP(e).focus()}function HF(){return or([LF,RF,zF,BF],(e,t)=>{e.preventDefault(),e.stopPropagation();let n=DP();if(n===null)return;if(t.hotkey===LF){FP({type:`createTab`,projectId:n.view===`global`?null:n.view});return}if(n.tabId===null)return;if(t.hotkey===RF){PF(n.tabId);return}let r;if(t.hotkey===zF)r=1;else if(t.hotkey===BF)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&&FP({type:`select`,view:n.view,tabId:a.id})},{enabled:()=>EP().behavior.captureShortcuts,enableOnFormTags:!0,eventListenerOptions:{capture:!0}})}function UF(e){let[t,n]=(0,U.useState)(e.name);return(0,W.jsx)(ei,{open:!0,onOpenChange:t=>{t||e.onDone()},children:(0,W.jsx)(qr,{onCloseAutoFocus:KF,children:(0,W.jsxs)(`form`,{className:`grid gap-4`,onSubmit:n=>{n.preventDefault(),FP({type:`renameTab`,id:e.id,name:t.trim()}),e.onDone()},children:[(0,W.jsx)(Jr,{children:(0,W.jsx)(Zr,{children:`Rename tab`})}),(0,W.jsx)(Kf,{"aria-label":`Name`,placeholder:`Use terminal title`,value:t,onChange:e=>n(e.target.value)}),(0,W.jsxs)(ti,{children:[(0,W.jsx)(H,{type:`button`,variant:`outline`,onClick:e.onDone,children:`Cancel`}),(0,W.jsx)(H,{type:`submit`,children:`Rename`})]})]})})})}function WF(){let e=(0,U.useSyncExternalStore)(TF,EF),t=(0,U.useRef)(null);if(e===null)return null;let n=e.closing;return(0,W.jsx)(lr,{open:e.open,onOpenChange:e=>{e||DF()},children:(0,W.jsxs)(Kn,{onOpenAutoFocus:e=>{e.preventDefault(),t.current?.focus()},onCloseAutoFocus:KF,children:[(0,W.jsxs)(Er,{children:[(0,W.jsxs)(Ln,{children:[`Close “`,n.name,`”?`]}),(0,W.jsx)(Pn,{children:n.program===null?`OffSite couldn’t check whether a program is still running.`:`${n.program} is still running.`})]}),(0,W.jsxs)(br,{children:[(0,W.jsx)(Jn,{children:`Cancel`}),(0,W.jsx)(rr,{ref:t,variant:`destructive`,onClick:()=>FP({type:`closeTab`,id:n.id}),children:`Close`})]})]})})}function GF(){let e=(0,U.useSyncExternalStore)(TF,OF);if(e===null)return null;let t=e.closing;return(0,W.jsx)(lr,{open:e.open,onOpenChange:e=>{e||kF()},children:(0,W.jsxs)(Kn,{onCloseAutoFocus:KF,children:[(0,W.jsxs)(Er,{children:[(0,W.jsxs)(Ln,{children:[`Close `,t.tabs.length,` `,t.tabs.length===1?`terminal`:`terminals`,`?`]}),(0,W.jsx)(Pn,{children:t.programs.length===0?`OffSite couldn’t check whether programs are still running.`:`Still running: ${t.programs.join(`, `)}.`})]}),(0,W.jsxs)(br,{children:[(0,W.jsx)(Jn,{children:`Cancel`}),(0,W.jsx)(rr,{variant:`destructive`,onClick:()=>FF(t.tabs),children:`Close all`})]})]})})}function KF(e){e.preventDefault();let t=document.querySelector(`[role="dialog"], [role="alertdialog"]`);t===null?VF():t.focus()}function qF(e){let t=(0,U.useRef)(null),[n,r]=(0,U.useState)(``),[i,a]=(0,U.useState)({resultIndex:-1,resultCount:0});(0,U.useEffect)(()=>BP(e.id,a),[e.id]),(0,U.useEffect)(()=>t.current?.focus(),[]);function o(t,n,i){r(t),zP(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)(Kf,{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(),VP(e.id)):t.key===`Enter`?(t.preventDefault(),o(n,t.shiftKey,!1)):KP(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:ho})}),(0,W.jsx)(H,{variant:`ghost`,size:`icon-sm`,"aria-label":`Next match`,onClick:()=>o(n,!1,!1),children:(0,W.jsx)(V,{icon:sn})}),(0,W.jsx)(H,{variant:`ghost`,size:`icon-sm`,"aria-label":`Close find`,onClick:()=>VP(e.id),children:(0,W.jsx)(V,{icon:bo})})]})}var JF=[{label:`Esc`,sequence:`\x1B`},{label:`Tab`,sequence:` `},{label:`↑`,sequence:`\x1B[A`},{label:`↓`,sequence:`\x1B[B`},{label:`←`,sequence:`\x1B[D`},{label:`→`,sequence:`\x1B[C`}];function YF(e){let t=(0,U.useSyncExternalStore)(CP,wP),n=t.status===`active`,r=OP(t.layout,e.view),i=t.layout.active[e.view]??null,a=HF();(0,U.useEffect)(()=>{n&&!e.page&&FP({type:`select`,view:e.view,tabId:null})},[e.view,n,e.page]);function o(){FP({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:B(`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)(ZF,{tab:n,children:(0,W.jsxs)(`div`,{className:B(`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:()=>FP({type:`select`,view:e.view,tabId:n.id}),children:[(0,W.jsx)(`span`,{className:`truncate`,children:jP(n)}),(0,W.jsx)(QF,{id:n.id,className:`ml-1.5 size-1.5 flex-none rounded-full`}),(0,W.jsx)($F,{progress:t.progress[n.id]}),(0,W.jsx)(`button`,{className:B(`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(),PF(n.id)},children:(0,W.jsx)(V,{icon:bo,className:`size-3`})})]})},n.id))}),(0,W.jsx)(`button`,{className:B(`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:to,className:`size-4`})})]}),(0,W.jsxs)(`div`,{className:`relative min-h-0 flex-1`,children:[i!==null&&(0,W.jsx)(XF,{id:i},`${t.instance}-${i}`),i!==null&&t.finding===i&&(0,W.jsx)(qF,{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:[JF.map(e=>(0,W.jsx)(H,{variant:`secondary`,className:`min-w-11`,onPointerDown:e=>e.preventDefault(),onClick:()=>LP(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:HP,children:`Ctrl`})]}),(0,W.jsx)(WF,{})]}):(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 XF(e){let t=(0,U.useRef)(null);return(0,U.useEffect)(()=>{if(!t.current)throw Error(`terminal container missing`);return YP(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 ZF(e){let[t,n]=(0,U.useState)(!1),r=k(e=>e.projects).filter(e=>e.machine===SP()&&!e.scratch),i=e.tab;return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(ar,{children:[(0,W.jsx)(Wn,{asChild:!0,children:e.children}),(0,W.jsxs)(Xn,{children:[(0,W.jsxs)(Fn,{onSelect:()=>n(!0),children:[(0,W.jsx)(V,{icon:as}),`Rename`]}),(0,W.jsxs)(tr,{children:[(0,W.jsxs)(Vn,{children:[(0,W.jsx)(V,{icon:ur}),`Move to`]}),(0,W.jsx)(vr,{className:`max-h-80 overflow-y-auto`,children:(0,W.jsxs)(sr,{value:i.projectId??``,onValueChange:e=>FP({type:`assignTab`,id:i.id,projectId:e===``?null:e}),children:[(0,W.jsx)(mr,{value:``,children:`No project`}),r.length>0&&(0,W.jsx)(zn,{}),r.map(e=>(0,W.jsx)(mr,{value:e.id,children:(0,W.jsx)(`span`,{className:`max-w-60 truncate`,children:e.name})},e.id))]})})]}),(0,W.jsxs)(Fn,{variant:`destructive`,onSelect:()=>void PF(i.id),children:[(0,W.jsx)(V,{icon:Mo}),`Close tab`]})]})]}),t&&(0,W.jsx)(UF,{id:i.id,name:i.customName??``,onDone:()=>n(!1)})]})}function QF(e){return wP().alerts.includes(e.id)?(0,W.jsx)(`span`,{className:B(`bg-primary`,e.className)}):null}function $F(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:B(`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 eI(e){(0,U.useSyncExternalStore)(CP,wP);let t=k(e=>e.machines).filter(e=>e.status===`online`),n=b(),r=nI(),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)(fn,{children:[(0,W.jsx)(dr,{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:to,className:`size-4`})})}),(0,W.jsx)(vn,{align:`end`,className:`w-auto min-w-56`,children:(0,W.jsx)(rF,{})})]});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)(fn,{children:[(0,W.jsx)(dr,{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)(aI,{group:i}),(0,W.jsx)(`span`,{className:`truncate`,children:i?.name})]})}),(0,W.jsx)(vn,{align:`center`,className:`w-auto`,children:r.filter(rI).map(t=>(0,W.jsxs)(wn,{className:B(t.view!==`global`&&`pl-7`),onSelect:()=>t.count===0?void eF(t.machine.id,null):QP(t.machine.id,t.view),children:[(0,W.jsx)(aI,{group:t}),(0,W.jsx)(`span`,{className:`max-w-60 truncate`,children:t.name}),(0,W.jsx)(oI,{count:t.count,alert:iI(t,e.machine)})]},`${t.machine.id}:${t.view}`))})]}),a]}),(0,W.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,W.jsx)(YF,{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)(YF,{view:n,page:!0,tabSize:`lg`,leading:e.leading})})})}function tI(e){(0,U.useSyncExternalStore)(CP,wP);let t=h(),n=b(),r=nI().filter(rI);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)(ar,{children:[(0,W.jsx)(Wn,{asChild:!0,children:(0,W.jsxs)(`div`,{className:B(`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:B(`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 eF(r.machine.id,null):QP(r.machine.id,r.view),children:[(0,W.jsx)(aI,{group:r}),(0,W.jsx)(`span`,{className:`truncate`,children:r.name}),(0,W.jsx)(oI,{count:r.count,alert:iI(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 eF(r.machine.id,r.view===`global`?null:r.view),children:(0,W.jsx)(V,{icon:to,className:`size-4`})})]})}),(0,W.jsxs)(Xn,{onCloseAutoFocus:e=>e.preventDefault(),children:[(0,W.jsxs)(Fn,{onSelect:()=>void eF(r.machine.id,r.view===`global`?null:r.view),children:[(0,W.jsx)(V,{icon:to}),`New terminal`]}),r.view===`global`&&(0,W.jsxs)(Fn,{variant:`destructive`,onSelect:()=>void IF(r.machine.terminals.map(e=>({machine:r.machine.id,id:e.id}))),children:[(0,W.jsx)(V,{icon:Mo}),`Close All`]}),(0,W.jsxs)(Fn,{variant:`destructive`,disabled:r.count===0,onSelect:()=>void IF(r.machine.terminals.filter(e=>kP(e)===r.view).map(e=>({machine:r.machine.id,id:e.id}))),children:[(0,W.jsx)(V,{icon:Mo}),r.view===`global`?`Close All Except Projects`:`Close All`]})]})]},`${r.machine.id}:${r.view}`))})}function nI(){let e=k(e=>e.machines),t=k(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:Ae,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 rI(e){return e.machine.status===`online`&&e.machine.terminals.length>0}function iI(e,t){let n=wP();return e.machine.id===t&&n.layout.tabs.some(t=>(t.projectId??`global`)===e.view&&n.alerts.includes(t.id))}function aI(e){return e.group.view===`global`?(0,W.jsx)(jd,{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 oI(e){return e.count===0?null:(0,W.jsx)(`span`,{className:B(`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 sI(e){let t=k(e=>e.machines),[n,r]=Nr(`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:B(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:Ss}),`Terminal`,i>0&&(0,W.jsx)(`span`,{className:B(`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)(ar,{children:[(0,W.jsx)(Wn,{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)(fn,{children:[(0,W.jsx)(dr,{asChild:!0,disabled:!o,children:c}),(0,W.jsx)(vn,{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)(rF,{})})]}),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:si,"aria-hidden":!0,className:B(`size-4 transition-transform duration-200`,n&&`rotate-90`)})}),(0,W.jsx)(nF,{mobile:e.mobile})]})}),(0,W.jsxs)(Xn,{onCloseAutoFocus:e=>e.preventDefault(),children:[(0,W.jsxs)(tr,{children:[(0,W.jsxs)(Vn,{children:[(0,W.jsx)(V,{icon:to}),`New terminal`]}),(0,W.jsx)(vr,{className:`max-h-80 overflow-y-auto`,children:(0,W.jsx)(rF,{contextMenu:!0})})]}),(0,W.jsxs)(Fn,{variant:`destructive`,disabled:!a,onSelect:()=>void IF(t.filter(e=>e.status===`online`).flatMap(e=>e.terminals.map(t=>({machine:e.id,id:t.id})))),children:[(0,W.jsx)(V,{icon:Mo}),`Close All`]})]})]}),(0,W.jsx)(`div`,{className:B(`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)(tI,{mobile:e.mobile})})}),(0,W.jsx)(GF,{})]})}function cI(e,t,n){let r=k(e=>e.inactiveVersion);(0,U.useEffect)(()=>{if(!e)return;let r=!0,i=0;async function a(){let e=++i,a=t===null?R().machines.filter(e=>e.status===`online`).map(e=>e.id):[t],o=await Promise.all(a.map(async e=>(await z(e,`sessions.inactive`,{projectId:n})).map(t=>({...t,machine:e}))));r&&e===i&&We({inactive:o.flat().sort((e,t)=>t.updatedAt-e.updatedAt)})}function o(){document.visibilityState===`visible`&&a().catch(N)}return a().catch(N),window.addEventListener(`focus`,o),document.addEventListener(`visibilitychange`,o),()=>{r=!1,window.removeEventListener(`focus`,o),document.removeEventListener(`visibilitychange`,o)}},[e,t,n,r])}var lI=`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 uI(e){let t=k(e=>e.selection),n=k(e=>e.machines),r=k(e=>e.sessions),i=k(e=>e.projects),a=k(e=>e.settings.provider),o=k(e=>e.unseen),s=k(e=>e.loaded),c=k(e=>e.inactive),l=k(e=>e.prefs.groupActiveByProject),[d,f]=Nr(`sidebarScope`,null),[p,m]=(0,U.useState)(null),[h,g]=(0,U.useState)(null),[_,v]=(0,U.useState)(!1),[y,b]=(0,U.useState)(!1),[x,S]=(0,U.useState)(!1),[C,w]=Nr(`sidebarWidth`,240),T=r.filter(e=>d===null||e.machine===d.machine&&se(e.machine,e.projectId)===d.projectId).sort((e,t)=>t.updatedAt-e.updatedAt),D=T.filter(e=>{let t=ke(n,e.machine,e.id);return e.status===`snoozed`&&t?.waiting!==!0&&(t?.running===!0||Object.values(t?.tasks??{}).includes(`running`))}),O=[...T.filter(e=>e.status===`pinned`),...T.filter(e=>e.status===`active`||e.status===`snoozed`&&!D.includes(e))],A=T.filter(e=>e.status===`minimized`),M=d?.machine??null,ee=d?.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?O:[te,...O],ie=l&&d===null,ae=[...new Map([...ne===null?[]:[ne],...re].map(e=>{let t=se(e.machine,e.projectId);return[P(e.machine,t),{machine:e.machine,projectId:t}]}))],oe=e.mobile?cF:Sk;function se(e,t){return i.some(n=>n.machine===e&&n.id===t&&n.scratch)?E:t}cI(x,M,ee);function N(e,t,n){Ie({machine:e,projectId:t,sessionId:n})}function ce(){let e=d??t??Oe();e===null?n.length>0?m(n[0].id):Ke(`Machines`):Tt(e.machine,e.projectId)}or([`mod+n`,`mod+t`],ce,{enableOnFormTags:!0,preventDefault:!0}),or([`mod+1`,`mod+2`,`mod+3`,`mod+4`,`mod+5`,`mod+6`,`mod+7`,`mod+8`,`mod+9`],e=>{let t=ie?ae.flatMap(e=>re.filter(t=>P(t.machine,se(t.machine,t.projectId))===e[0])):re,n=/^(?:Digit|Numpad)([1-9])$/.exec(e.code);if(n===null)throw Error(`unexpected session shortcut key ${e.code}`);let r=t[Number(n[1])-1];r!==void 0&&N(r.machine,r.projectId,r.id)},{enableOnFormTags:!0,preventDefault:!0,enabled:!e.mobile});function le(e){let t=e.clientX-C;Bt(e,e=>{let n=Math.min(480,Math.max(200,e.clientX-t));w(n)})}function ue(r,i){let a=e.mobile?sF:xk;return(0,W.jsx)(a,{session:r,slim:i,selected:t?.machine===r.machine&&t.sessionId===r.id,activity:ke(n,r.machine,r.id),unseen:o.includes(P(r.machine,r.id)),saved:r!==te,scope:d,onSelect:()=>N(r.machine,r.projectId,r.id)},P(r.machine,r.id))}function de(e){return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`li`,{className:B(`mx-0.5 h-9 pt-2`,e.first&&`mt-auto`),children:(0,W.jsxs)(`button`,{"aria-expanded":e.open,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:e.onToggle,children:[(0,W.jsx)(V,{icon:e.icon,className:`size-3 shrink-0`}),(0,W.jsx)(`span`,{className:`-ms-1 shrink-0`,children:e.label}),(0,W.jsx)(`span`,{className:`bg-sidebar-border/60 h-px min-w-2 flex-1`}),(0,W.jsx)(V,{icon:jr,className:B(`size-3 shrink-0 transition-transform`,!e.open&&`rotate-180`)})]})}),e.open&&e.items.map(e=>ue(e,e.status===`inactive`))]})}return(0,W.jsxs)(`aside`,{className:B(`bg-sidebar text-sidebar-foreground border-sidebar-border flex flex-none border-r select-none`,e.className),children:[(0,W.jsxs)(`div`,{className:B(`relative flex min-w-0 flex-col`,e.mobile&&`flex-1`),style:e.mobile?void 0:{width:C},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)(iF,{buttonClassName:lI}):(0,W.jsx)(`button`,{className:B(lI,`size-7 [&>svg]:size-4.5`),title:`Hide sidebar (${Vt}+B)`,"aria-label":`Hide sidebar`,onClick:e.onHide,children:(0,W.jsx)(V,{icon:rs})}),(0,W.jsx)(gF,{scope:d,onScope:f,onEdit:g,onAddProject:m}),e.mobile&&(0,W.jsx)(_F,{hideDone:!0}),(0,W.jsxs)(`div`,{className:`ml-auto flex items-center gap-0.75`,children:[(0,W.jsx)(`button`,{className:B(lI,`size-7 [&>svg]:size-4.5`),title:`Search (${Vt}+K)`,"aria-label":`Search`,onClick:()=>u(!0),children:(0,W.jsx)(V,{icon:cr})}),(0,W.jsx)(`button`,{className:B(lI,`size-7 [&>svg]:size-4.5`),title:`New thread (${Vt}+N)`,onClick:ce,children:(0,W.jsx)(V,{icon:bs})})]})]}),(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)(hF,{machine:n.machine,projectId:n.projectId,sessions:re.filter(e=>P(e.machine,se(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:()=>N(ne.machine,ne.projectId,null)}),re.map(e=>ue(e,!1))]}),O.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`}),D.length>0&&de({icon:Ms,label:_?`Snoozed`:`Snoozed (${D.length})`,items:D,open:_,onToggle:()=>v(!_),first:!0}),A.length>0&&de({icon:ts,label:y?`Minimized`:`Minimized (${A.length})`,items:A,open:y,onToggle:()=>b(!y),first:D.length===0}),de({icon:Es,label:`Done`,items:c,open:x,onToggle:()=>S(!x),first:D.length===0&&A.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)(sI,{buttonClassName:lI,mobile:!1}),(0,W.jsxs)(`div`,{className:`relative`,children:[(0,W.jsxs)(`button`,{className:B(lI,`h-8 w-full justify-start gap-2 px-2.5 text-sm`),title:`Settings`,onClick:()=>j(!0),children:[(0,W.jsx)(V,{icon:ms}),(0,W.jsx)(`span`,{className:`truncate`,children:`Settings`})]}),(0,W.jsxs)(`div`,{className:`absolute top-1.5 right-1.5`,children:[(0,W.jsx)(_F,{className:`@max-[13rem]:hidden`,hideDone:!1}),(0,W.jsx)(_F,{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:le,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`})})]}),p!==null&&(0,W.jsx)(yD,{machine:p,onClose:()=>m(null),onAdd:e=>{m(null),N(e.machine,e.id,null)}}),h!==null&&(0,W.jsx)(xD,{project:h,onClose:()=>g(null),onRemoved:()=>{d?.machine===h.machine&&d.projectId===h.id&&f(null),g(null)}})]})}var dI={running:`Running`,completed:`Done`,failed:`Failed`,stopped:`Stopped`};function fI(e,t){return{agents:e.flatMap(e=>e.kind===`subagent`?[{item:e,agentId:e.agentId,status:mI(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:mI(e.status,e.background.taskId,t)}]:[])}}function pI(e){return e.description===``?e.command:e.description}function mI(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`:dI[e]:dI[r]}function hI(e){return(0,W.jsx)(`span`,{className:B(e.active&&`text-shimmer`),children:e.text})}function gI(e){return(0,W.jsxs)(`span`,{className:B(`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:B(`text-foreground shrink-0`,e.grouped?`font-normal`:`font-medium`),children:(0,W.jsx)(hI,{text:e.title,active:e.pending})}),e.subtitle!==void 0&&e.subtitle!==``&&(0,W.jsx)(`span`,{className:B(`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:B(`min-w-0 truncate tabular-nums`,e.grouped?`text-muted-foreground/70`:`text-muted-foreground`),children:t},t))]})}function _I(e){return(0,W.jsx)(`span`,{"aria-hidden":!0,className:B(`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:sn,strokeWidth:2.5,className:B(`size-3.5 transition-transform`,!e.open&&`-rotate-90`)})})}function vI(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)(gI,{title:e.title,subtitle:e.subtitle,args:e.args,pending:e.pending,grouped:e.grouped})}),t!==null&&(0,W.jsx)(_I,{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:B(`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:B(`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:B(`min-w-0 pt-1`,e.rail!==!1&&`ps-3`),children:e.children})]})}var yI=new Map([[`build`,`text-blue-400`],[`explore`,`text-yellow-400`],[`plan`,`text-pink-400`],[`review`,`text-green-400`],[`writer`,`text-purple-400`]]),bI=new Map([[`Running`,`Launched agent`],[`Done`,`Agent finished`],[`Failed`,`Agent failed`],[`Stopped`,`Agent stopped`]]),xI=new Map([[`Running`,`Started in background`],[`Done`,`Background task finished`],[`Failed`,`Background task failed`],[`Stopped`,`Background task stopped`]]),SI=[`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 CI(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:yI.get(n)??SI[r%SI.length]}}function wI(e){return(0,W.jsxs)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,"aria-hidden":!0,className:B(`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 TI(e){return(0,W.jsx)(`svg`,{viewBox:`0 0 16 16`,"aria-hidden":!0,className:B(`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 EI(e){let t=e.item;if(t.kind===`agent_message`){let n=t.target;return(0,W.jsx)(DI,{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)(DI,{label:xI.get(n.status)??`Background task ${n.status.toLowerCase()}`,detail:pI(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)(DI,{label:bI.get(n.status)??`Agent ${n.status.toLowerCase()}`,detail:t.description,pending:n.status===`Running`,onOpen:()=>e.onOpen(t.id)})}function DI(e){let t=(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`span`,{className:`text-muted-foreground shrink-0`,children:(0,W.jsx)(hI,{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:Tr,className:`size-3.5`})})]})}function OI(e){let t=(0,U.useRef)(null),[n,r]=(0,U.useState)(``),[i,a]=(0,U.useState)(0),[o,s]=(0,U.useState)([]),c=o.length===0?-1:Math.min(i,o.length-1);(0,U.useEffect)(()=>t.current?.focus(),[]),(0,U.useEffect)(()=>{let t=e.content.current;if(t===null)throw Error(`transcript is not mounted`);if(n===``)return;let r=0,i=new MutationObserver(()=>{cancelAnimationFrame(r),r=requestAnimationFrame(()=>s(kI(t,n)))});return i.observe(t,{childList:!0,subtree:!0,characterData:!0}),()=>{i.disconnect(),cancelAnimationFrame(r)}},[n,e.content]),(0,U.useEffect)(()=>{if(o.length!==0)return CSS.highlights.set(`transcript-find`,new Highlight(...o)),c!==-1&&CSS.highlights.set(`transcript-find-current`,new Highlight(o[c])),()=>{CSS.highlights.delete(`transcript-find`),CSS.highlights.delete(`transcript-find-current`)}},[o,c]);function l(t,n){let i=e.content.current,o=e.scroller.current;if(i===null||o===null)throw Error(`transcript is not mounted`);let c=t===``?[]:kI(i,t),l=c.length===0?0:(n+c.length)%c.length;if(r(t),a(l),s(c),c.length===0)return;let u=c[l].getBoundingClientRect(),d=o.getBoundingClientRect();(u.top<d.top+48||u.bottom>d.bottom-48)&&o.scrollBy({top:u.top-d.top-d.height/3})}return(0,W.jsxs)(`div`,{"data-transcript":!0,className:`bg-card absolute top-2 right-6 z-30 flex items-center gap-1 rounded-lg border p-1 shadow-lg`,children:[(0,W.jsx)(Kf,{ref:t,"data-thread-find":!0,className:`h-7 w-52`,placeholder:`Find in thread`,"aria-label":`Find in thread`,value:n,onChange:e=>l(e.target.value,0),onKeyDown:t=>{t.key===`Escape`?(t.preventDefault(),e.onClose()):t.key===`Enter`&&(t.preventDefault(),l(n,c+(t.shiftKey?-1:1)))}}),(0,W.jsx)(`span`,{className:`text-muted-foreground w-16 text-center text-xs tabular-nums`,children:n===``?``:o.length===0?`No results`:`${c+1} of ${o.length}`}),(0,W.jsx)(H,{variant:`ghost`,size:`icon-sm`,"aria-label":`Previous match`,onClick:()=>l(n,c-1),children:(0,W.jsx)(V,{icon:ho})}),(0,W.jsx)(H,{variant:`ghost`,size:`icon-sm`,"aria-label":`Next match`,onClick:()=>l(n,c+1),children:(0,W.jsx)(V,{icon:sn})}),(0,W.jsx)(H,{variant:`ghost`,size:`icon-sm`,"aria-label":`Close find`,onClick:e.onClose,children:(0,W.jsx)(V,{icon:bo})})]})}function kI(e,t){let n=[],r=[],i=``,a=document.createTreeWalker(e,NodeFilter.SHOW_TEXT);for(let e=a.nextNode();e!==null;e=a.nextNode())e instanceof Text&&(n.push(e),r.push(i.length),i+=e.data);let o=new RegExp(t.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),`gi`),s=[],c=0;for(let e of i.matchAll(o)){let t=e.index+e[0].length;for(;c+1<r.length&&r[c+1]<=e.index;)c++;let i=c;for(;i+1<r.length&&r[i+1]<t;)i++;let a=document.createRange();a.setStart(n[c],e.index-r[c]),a.setEnd(n[i],t-r[i]),a.getClientRects().length>0&&s.push(a)}return s}function AI(e){let[t,n]=(0,U.useState)(!1),r=nn(),i=e.plan,a=jI(i),o=i.length>900||i.split(`
|
|
17
17
|
`).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)(fn,{children:[(0,W.jsx)(dr,{asChild:!0,children:(0,W.jsx)(H,{"aria-label":`Plan actions`,size:`icon-xs`,variant:`outline`,children:(0,W.jsx)(V,{icon:nr,className:`size-4`})})}),(0,W.jsxs)(vn,{align:`end`,children:[(0,W.jsx)(wn,{onSelect:e=>{e.preventDefault(),r.copy(c)},children:r.copied?`Copied!`:`Copy to clipboard`}),(0,W.jsx)(wn,{onSelect:()=>{let e=URL.createObjectURL(new Blob([c],{type:`text/markdown;charset=utf-8`})),t=document.createElement(`a`);t.href=e,t.download=`${PI(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:B(`relative`,s&&`max-h-104 overflow-hidden`),children:[(0,W.jsx)($n,{text:s?NI(i):MI(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 jI(e){let t=/^\s{0,3}#{1,6}\s+(.+)$/m.exec(e)?.[1]?.trim();return t===void 0||t===``?null:t}function MI(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(`
|
|
18
18
|
`)}function NI(e){let t=MI(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?jI(e)??`Plan preview unavailable.`:(i&&n.push(``,`...`),n.join(`
|
|
19
19
|
`))}function PI(e){let t=e.toLowerCase().replace(/[`'".,!?()[\]{}]+/g,``).replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``);return t===``?`plan`:t}function FI(e){let t=e.item.answers;return(0,W.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-3 text-sm leading-6 select-text`,children:[e.item.questions.map(e=>(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`p`,{className:`text-foreground font-medium`,children:e.question}),(0,W.jsx)(`ul`,{className:`text-secondary-label list-disc pl-5`,children:e.options.map(e=>(0,W.jsxs)(`li`,{children:[e.label,e.description!==``&&` — ${e.description}`]},e.label))}),t?.[e.question]!==void 0&&(0,W.jsxs)(`p`,{className:`text-foreground whitespace-pre-wrap`,children:[`Answer: `,t[e.question]]})]},e.question)),e.item.status===`failed`&&(0,W.jsx)(`p`,{className:`text-muted-foreground`,children:`Skipped`})]})}function II(e){let[t,n]=(0,U.useState)(null);return(0,U.useEffect)(()=>{function t(){let t=e.scroller.current,r=window.getSelection();if(t===null||r===null||r.isCollapsed||r.rangeCount===0){n(null);return}let i=r.getRangeAt(0),a=r.toString().trim();if(a===``||!LI(i.startContainer,t)||!LI(i.endContainer,t)){n(null);return}let o=i.getBoundingClientRect(),s=t.getBoundingClientRect();n({text:a,top:o.bottom-s.top+t.scrollTop+6,left:Math.min(Math.max(o.left+o.width/2-s.left,48),s.width-48)})}return document.addEventListener(`selectionchange`,t),()=>document.removeEventListener(`selectionchange`,t)},[e.scroller]),t===null?null:(0,W.jsxs)(H,{type:`button`,size:`xs`,variant:`outline`,className:`bg-popover dark:bg-popover hover:bg-accent dark:hover:bg-accent absolute z-20 -translate-x-1/2 shadow-md`,style:{top:t.top,left:t.left},onPointerDown:e=>e.preventDefault(),onClick:()=>{RI(t.text),window.getSelection()?.removeAllRanges(),n(null)},children:[(0,W.jsx)(V,{icon:us}),`Quote`]})}function LI(e,t){let n=e instanceof Element?e:e.parentElement;return n!==null&&t.contains(n)&&n.closest(`[data-quotable]`)!==null}function RI(e){let t=R().selection;if(t===null)throw Error(`no thread is open to quote into`);let n=e.split(`
|
|
20
20
|
`).map(e=>e.trim()===``?`>`:`> ${e}`).join(`
|
|
21
|
-
`);F(ze(t),e=>({...e,text:e.text.trim()===``?`${n}\n\n`:`${e.text.trimEnd()}\n\n${n}\n\n`})),requestAnimationFrame(()=>{let e=document.querySelector(`[data-composer]`);if(e===null)throw Error(`the composer is not mounted`);e.focus(),e.setSelectionRange(e.value.length,e.value.length)})}function zI(e){return e.kind===`group`||e.kind===`agent`}function BI(e,t){let n=[],r=e.prompt?.id??`start`;e.prompt!==null&&n.push({kind:`user`,key:e.prompt.id,item:e.prompt,first:e.first});for(let r of e.items){let e=VI(r,t!==null),i=n.at(-1);e?.kind===`group`&&i?.kind===`group`?i.entries.push(...e.entries):e!==null&&n.push(e)}let i=n.at(-1);return t!==null&&t.partial===``&&i?.kind===`group`&&(n[n.length-1]={...i,live:!0}),t!==null&&t.partial!==``&&n.push({kind:`assistant`,key:`${r}:partial`,message:``,text:t.partial,time:null,streaming:!0,meta:!1}),t!==null&&t.partial===``&&n.push({kind:`working`,key:`${r}:working`}),t===null&&i?.kind===`assistant`&&(n[n.length-1]={...i,meta:!0}),n}function VI(e,t){switch(e.kind){case`assistant`:return{kind:`assistant`,key:e.id,message:e.message,text:e.text,time:e.time,streaming:!1,meta:!1};case`reasoning`:case`file_change`:case`web_search`:case`skill`:case`tool`:return{kind:`group`,key:`group:${e.id}`,entries:[e],live:!1};case`command`:return e.background===null?{kind:`group`,key:`group:${e.id}`,entries:[e],live:!1}:{kind:`agent`,key:e.id,item:e,live:t};case`subagent`:case`agent_message`:return{kind:`agent`,key:e.id,item:e,live:t};case`plan`:return{kind:`plan`,key:e.id,plan:e.plan};case`question`:return{kind:`question`,key:e.id,item:e};case`notice`:return{kind:`notice`,key:e.id,text:e.text};case`compaction`:return{kind:`compaction`,key:e.id,summary:e.summary,time:e.time};case`error`:return{kind:`error`,key:e.id,text:e.text,time:e.time};case`user`:case`todo_list`:return null}}function HI(e,t,n){let r=[],i=!1;for(let t of e)t.parent===null&&(t.kind===`user`?(r.push({prompt:t,first:!i,items:[]}),i=!0):(t.kind!==`notice`&&t.kind!==`error`&&(i=!0),r.length===0&&r.push({prompt:null,first:!0,items:[]}),r[r.length-1].items.push(t)));let a=r.flatMap((e,i)=>BI(e,t&&i===r.length-1?{partial:n}:null));return t&&r.length===0&&a.push({kind:`working`,key:`working`}),a}var UI={all:{label:`Restore code and chat`,description:`This will undo file changes made since this message and remove this message and everything after it from the chat.`,icon:mo,code:!0,conversation:!0},chat:{label:`Restore chat`,description:`This will remove this message and everything after it from the chat. Files will not change.`,icon:as,code:!1,conversation:!0},code:{label:`Restore code`,description:`This will undo file changes made since this message. The chat will not change.`,icon:In,code:!0,conversation:!1}};function WI(e){if(e===`claude`)return[`all`,`chat`,`code`];if(e===`opencode`)return[`all`,`chat`];if(e===`codex`)return[`chat`];throw Error(`unknown provider ${e}`)}function GI(e){let[t,n]=(0,U.useState)(!1),[r,i]=(0,U.useState)(null),[a,o]=(0,U.useState)(null),[s,c]=(0,U.useState)(!1),[l,u]=(0,U.useState)(null),d=e.target,f=d.messageId,p=k(e=>e.selection),m=k(e=>e.settings.provider),h=WI(m),g=k(e=>e.prefs.rewind),_=h.includes(g)?g:`chat`,v=p?.machine??null,y=p?.sessionId??null,b=p?.projectId??``,x=k(e=>v===null?``:Ct(e,v,b)?.path??``),S=t||l!==null;(0,U.useEffect)(()=>{if(i(null),o(null),!S||v===null||y===null)return;let e=!0;return z(v,`sessions.rewind`,{sessionId:y,projectId:b,messageId:f,settings:R().settings,code:!0,conversation:!1,dryRun:!0}).then(t=>{e&&i(t)},t=>{e&&o(Ht(t))}),()=>{e=!1}},[S,f,v,y,b]);async function C(e){if(v===null||y===null)return;let{code:t,conversation:r}=UI[e];c(!0);try{let i=r?await Promise.all(d.images.map((e,t)=>e.data===null?z(v,`sessions.image`,{sessionId:y,itemId:d.messageId,index:t}):{mediaType:e.mediaType,data:e.data})):[],a=r&&d.first&&m===`claude`,o=r&&!a;(t||o)&&await z(v,`sessions.rewind`,{sessionId:y,projectId:b,messageId:d.messageId,settings:R().settings,code:t,conversation:o,dryRun:!1}),a&&(Tt(v,b),We({replacing:{machine:v,projectId:b,sessionId:y}})),r&&oe({text:d.text,images:i}),D({...R().prefs,rewind:e}),n(!1)}catch(e){ea(Ht(e)),N(e)}finally{c(!1)}}let w=r!==null&&a===null;return(0,W.jsxs)(W.Fragment,{children:[h.length>1&&(0,W.jsxs)(fn,{open:t,onOpenChange:e=>{s||n(e)},children:[(0,W.jsx)(Wr,{label:`Restore options`,children:(0,W.jsx)(dr,{asChild:!0,children:(0,W.jsx)(H,{type:`button`,size:`icon-micro`,variant:`ghost-muted`,"aria-label":`Restore options`,disabled:e.disabled,children:(0,W.jsx)(V,{icon:nr,className:`size-4`})})})}),(0,W.jsxs)(vn,{align:`end`,className:`w-72`,children:[(0,W.jsxs)(`div`,{className:`text-muted-foreground px-2 py-1.5 text-xs`,children:[a!==null&&`Code can't be restored: ${a}`,a===null&&r===null&&`Checking file changes…`,r!==null&&r.files.length===0&&`No file changes since this message.`,r!==null&&r.files.length>0&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(`div`,{children:[`Restores `,r.files.length,` `,r.files.length===1?`file`:`files`,` (`,(0,W.jsxs)(`span`,{className:`text-diff-addition`,children:[`+`,r.insertions]}),` `,(0,W.jsxs)(`span`,{className:`text-diff-deletion`,children:[`−`,r.deletions]}),`)`]}),(0,W.jsx)(`ul`,{className:`mt-1 max-h-24 overflow-y-auto font-mono`,children:r.files.map(e=>(0,W.jsx)(`li`,{className:`truncate`,children:nf(e,x)},e))})]})]}),(0,W.jsx)(On,{}),h.map(e=>(0,W.jsxs)(wn,{disabled:s||UI[e].code&&!w,onSelect:()=>u(e),children:[(0,W.jsx)(V,{icon:UI[e].icon}),UI[e].label]},e))]})]}),(0,W.jsx)(Wr,{label:UI[_].label,children:(0,W.jsx)(H,{type:`button`,size:`icon-micro`,variant:`ghost-muted`,"aria-label":UI[_].label,disabled:e.disabled||s,onClick:()=>u(_),children:(0,W.jsx)(V,{icon:UI[_].icon,className:`size-4`})})}),(0,W.jsx)(lr,{open:l!==null,onOpenChange:e=>{e||u(null)},children:l!==null&&(0,W.jsxs)(Kn,{children:[(0,W.jsxs)(Er,{children:[(0,W.jsxs)(Ln,{children:[UI[l].label,`?`]}),(0,W.jsxs)(Pn,{children:[UI[l].description,` Do you really want to continue?`,UI[l].code&&a!==null&&(0,W.jsx)(`span`,{className:`text-destructive mt-2 block`,children:`Code can't be restored: ${a}`})]})]}),(0,W.jsxs)(br,{children:[(0,W.jsx)(Jn,{children:`Cancel`}),(0,W.jsx)(rr,{variant:`destructive`,disabled:UI[l].code&&!w,onClick:()=>void C(l),children:UI[l].label})]})]})})]})}var KI=20,qI=`linear-gradient(to bottom, black calc(100% - 1.75rem), transparent)`,JI=new Map;function YI(e){let[t,n]=(0,U.useState)(!1),r=e.item,i=r.format===`text`||r.format===`command`?r.text:``,a=i.trim()!==``&&(i.length>600||i.split(`
|
|
21
|
+
`);F(ze(t),e=>({...e,text:e.text.trim()===``?`${n}\n\n`:`${e.text.trimEnd()}\n\n${n}\n\n`})),requestAnimationFrame(()=>{let e=document.querySelector(`[data-composer]`);if(e===null)throw Error(`the composer is not mounted`);e.focus(),e.setSelectionRange(e.value.length,e.value.length)})}function zI(e){return e.kind===`group`||e.kind===`agent`}function BI(e,t){let n=[],r=e.prompt?.id??`start`;e.prompt!==null&&n.push({kind:`user`,key:e.prompt.id,item:e.prompt,first:e.first});for(let r of e.items){let e=VI(r,t!==null),i=n.at(-1);e?.kind===`group`&&i?.kind===`group`?i.entries.push(...e.entries):e!==null&&n.push(e)}let i=n.at(-1);return t!==null&&t.partial===``&&i?.kind===`group`&&(n[n.length-1]={...i,live:!0}),t!==null&&t.partial!==``&&n.push({kind:`assistant`,key:`${r}:partial`,message:``,text:t.partial,time:null,streaming:!0,meta:!1}),t!==null&&t.partial===``&&n.push({kind:`working`,key:`${r}:working`}),t===null&&i?.kind===`assistant`&&(n[n.length-1]={...i,meta:!0}),n}function VI(e,t){switch(e.kind){case`assistant`:return{kind:`assistant`,key:e.id,message:e.message,text:e.text,time:e.time,streaming:!1,meta:!1};case`reasoning`:case`file_change`:case`web_search`:case`skill`:case`tool`:return{kind:`group`,key:`group:${e.id}`,entries:[e],live:!1};case`command`:return e.background===null?{kind:`group`,key:`group:${e.id}`,entries:[e],live:!1}:{kind:`agent`,key:e.id,item:e,live:t};case`subagent`:case`agent_message`:return{kind:`agent`,key:e.id,item:e,live:t};case`plan`:return{kind:`plan`,key:e.id,plan:e.plan};case`question`:return{kind:`question`,key:e.id,item:e};case`notice`:return{kind:`notice`,key:e.id,text:e.text};case`compaction`:return{kind:`compaction`,key:e.id,summary:e.summary,time:e.time};case`error`:return{kind:`error`,key:e.id,text:e.text,time:e.time};case`user`:case`todo_list`:return null}}function HI(e,t,n){let r=[],i=!1;for(let t of e)t.parent===null&&(t.kind===`user`?(r.push({prompt:t,first:!i,items:[]}),i=!0):(t.kind!==`notice`&&t.kind!==`error`&&(i=!0),r.length===0&&r.push({prompt:null,first:!0,items:[]}),r[r.length-1].items.push(t)));let a=r.flatMap((e,i)=>BI(e,t&&i===r.length-1?{partial:n}:null));return t&&r.length===0&&a.push({kind:`working`,key:`working`}),a}var UI={all:{label:`Restore code and chat`,description:`This will undo file changes made since this message and remove this message and everything after it from the chat.`,icon:mo,code:!0,conversation:!0},chat:{label:`Restore chat`,description:`This will remove this message and everything after it from the chat. Files will not change.`,icon:as,code:!1,conversation:!0},code:{label:`Restore code`,description:`This will undo file changes made since this message. The chat will not change.`,icon:In,code:!0,conversation:!1}};function WI(e){if(e===`claude`)return[`all`,`chat`,`code`];if(e===`opencode`)return[`all`,`chat`];if(e===`codex`)return[`chat`];throw Error(`unknown provider ${e}`)}function GI(e){let[t,n]=(0,U.useState)(!1),[r,i]=(0,U.useState)(null),[a,o]=(0,U.useState)(null),[s,c]=(0,U.useState)(!1),[l,u]=(0,U.useState)(null),d=e.target,f=d.messageId,p=k(e=>e.selection),m=k(e=>e.settings.provider),h=WI(m),g=k(e=>e.prefs.rewind),_=h.includes(g)?g:`chat`,v=p?.machine??null,y=p?.sessionId??null,b=p?.projectId??``,x=k(e=>v===null?``:Ct(e,v,b)?.path??``),S=t||l!==null;(0,U.useEffect)(()=>{if(i(null),o(null),!S||v===null||y===null)return;let e=!0;return z(v,`sessions.rewind`,{sessionId:y,projectId:b,messageId:f,settings:R().settings,code:!0,conversation:!1,dryRun:!0}).then(t=>{e&&i(t)},t=>{e&&o(Ht(t))}),()=>{e=!1}},[S,f,v,y,b]);async function C(e){if(v===null||y===null)return;let{code:t,conversation:r}=UI[e];c(!0);try{let i=r?await Promise.all(d.images.map((e,t)=>e.data===null?z(v,`sessions.image`,{sessionId:y,itemId:d.messageId,index:t}):{mediaType:e.mediaType,data:e.data})):[],a=r&&d.first&&m===`claude`,o=r&&!a;(t||o)&&await z(v,`sessions.rewind`,{sessionId:y,projectId:b,messageId:d.messageId,settings:R().settings,code:t,conversation:o,dryRun:!1}),a&&(Tt(v,b,!0),We({replacing:{machine:v,projectId:b,sessionId:y}})),r&&oe({text:d.text,images:i}),D({...R().prefs,rewind:e}),n(!1)}catch(e){ea(Ht(e)),N(e)}finally{c(!1)}}let w=r!==null&&a===null;return(0,W.jsxs)(W.Fragment,{children:[h.length>1&&(0,W.jsxs)(fn,{open:t,onOpenChange:e=>{s||n(e)},children:[(0,W.jsx)(Wr,{label:`Restore options`,children:(0,W.jsx)(dr,{asChild:!0,children:(0,W.jsx)(H,{type:`button`,size:`icon-micro`,variant:`ghost-muted`,"aria-label":`Restore options`,disabled:e.disabled,children:(0,W.jsx)(V,{icon:nr,className:`size-4`})})})}),(0,W.jsxs)(vn,{align:`end`,className:`w-72`,children:[(0,W.jsxs)(`div`,{className:`text-muted-foreground px-2 py-1.5 text-xs`,children:[a!==null&&`Code can't be restored: ${a}`,a===null&&r===null&&`Checking file changes…`,r!==null&&r.files.length===0&&`No file changes since this message.`,r!==null&&r.files.length>0&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(`div`,{children:[`Restores `,r.files.length,` `,r.files.length===1?`file`:`files`,` (`,(0,W.jsxs)(`span`,{className:`text-diff-addition`,children:[`+`,r.insertions]}),` `,(0,W.jsxs)(`span`,{className:`text-diff-deletion`,children:[`−`,r.deletions]}),`)`]}),(0,W.jsx)(`ul`,{className:`mt-1 max-h-24 overflow-y-auto font-mono`,children:r.files.map(e=>(0,W.jsx)(`li`,{className:`truncate`,children:nf(e,x)},e))})]})]}),(0,W.jsx)(On,{}),h.map(e=>(0,W.jsxs)(wn,{disabled:s||UI[e].code&&!w,onSelect:()=>u(e),children:[(0,W.jsx)(V,{icon:UI[e].icon}),UI[e].label]},e))]})]}),(0,W.jsx)(Wr,{label:UI[_].label,children:(0,W.jsx)(H,{type:`button`,size:`icon-micro`,variant:`ghost-muted`,"aria-label":UI[_].label,disabled:e.disabled||s,onClick:()=>u(_),children:(0,W.jsx)(V,{icon:UI[_].icon,className:`size-4`})})}),(0,W.jsx)(lr,{open:l!==null,onOpenChange:e=>{e||u(null)},children:l!==null&&(0,W.jsxs)(Kn,{children:[(0,W.jsxs)(Er,{children:[(0,W.jsxs)(Ln,{children:[UI[l].label,`?`]}),(0,W.jsxs)(Pn,{children:[UI[l].description,` Do you really want to continue?`,UI[l].code&&a!==null&&(0,W.jsx)(`span`,{className:`text-destructive mt-2 block`,children:`Code can't be restored: ${a}`})]})]}),(0,W.jsxs)(br,{children:[(0,W.jsx)(Jn,{children:`Cancel`}),(0,W.jsx)(rr,{variant:`destructive`,disabled:UI[l].code&&!w,onClick:()=>void C(l),children:UI[l].label})]})]})})]})}var KI=20,qI=`linear-gradient(to bottom, black calc(100% - 1.75rem), transparent)`,JI=new Map;function YI(e){let[t,n]=(0,U.useState)(!1),r=e.item,i=r.format===`text`||r.format===`command`?r.text:``,a=i.trim()!==``&&(i.length>600||i.split(`
|
|
22
22
|
`).length>8),o=a&&!t;return(0,W.jsxs)(`div`,{className:`group flex flex-col items-end gap-1`,children:[(0,W.jsxs)(`div`,{className:`bg-message text-message-foreground relative max-w-[80%] rounded-2xl px-3 py-2`,children:[r.images.length>0&&(0,W.jsx)(`div`,{className:`mb-2 grid max-w-[210px] grid-cols-2 gap-2`,children:r.images.map((e,t)=>(0,W.jsx)(`div`,{className:`border-border/80 bg-background/70 aspect-[4/3] overflow-hidden rounded-lg border`,children:(0,W.jsx)(ZI,{itemId:r.id,index:t,mediaType:e.mediaType,data:e.data})},t))}),r.text!==``&&(0,W.jsxs)(`div`,{children:[(0,W.jsxs)(`div`,{className:B(`relative`,o&&`max-h-44 overflow-hidden`),style:o?{WebkitMaskImage:qI,maskImage:qI}:void 0,children:[r.format===`command`&&(0,W.jsx)(`span`,{className:`font-mono text-sm`,children:r.text}),r.format===`output`&&(0,W.jsx)(`pre`,{className:`text-muted-foreground font-mono text-xs whitespace-pre-wrap`,children:r.text}),r.format===`text`&&(0,W.jsx)($n,{text:r.text,className:`text-foreground`,lineBreaks:!0,rawHtml:!1})]}),a&&(0,W.jsx)(`div`,{className:`mt-1.5 flex items-center justify-end gap-2`,children:(0,W.jsx)(H,{type:`button`,size:`xs`,variant:`ghost-muted`,"aria-expanded":t,className:`-ml-1`,onClick:()=>n(!t),children:t?`Show less`:`Show full message`})})]})]}),(0,W.jsx)(`div`,{className:`flex w-full max-w-[80%] items-center justify-end pe-1 text-xs tabular-nums opacity-0 transition-opacity duration-200 group-hover:opacity-100 focus-within:opacity-100 has-aria-expanded:opacity-100 pointer-coarse:opacity-100`,children:(0,W.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[r.time!==null&&(0,W.jsx)(Wr,{label:xn(r.time),children:(0,W.jsx)(`p`,{className:`text-muted-foreground text-xs tabular-nums`,children:dn(r.time)})}),i!==``&&(0,W.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[e.rewind&&(0,W.jsx)(GI,{target:{messageId:r.id,text:i,images:r.images,first:e.first},disabled:e.running}),(0,W.jsx)(XI,{text:i})]})]})})]})}function XI(e){let t=nn();return(0,W.jsx)(Wr,{label:`Copy message`,children:(0,W.jsx)(H,{type:`button`,size:`icon-micro`,variant:`ghost-muted`,"aria-label":`Copy message`,disabled:t.copied,onClick:()=>void t.copy(e.text),children:(0,W.jsx)(V,{icon:t.copied?Dr:Yn,className:B(`size-4`,t.copied&&`text-primary`)})})})}function ZI(e){let t=k(e=>e.selection),n=t?.machine??null,r=t?.sessionId??null,[i,a]=(0,U.useState)(null);(0,U.useEffect)(()=>{if(e.data!==null||n===null||r===null)return;let t=!0,i=JSON.stringify([n,r,e.itemId,e.index]),o=JI.get(i);if(o===void 0){if(o=z(n,`sessions.image`,{sessionId:r,itemId:e.itemId,index:e.index}),JI.set(i,o),JI.size>KI){let[e]=JI.keys();JI.delete(e)}o.catch(()=>JI.delete(i))}return o.then(e=>{t&&a(e.data)}).catch(N),()=>{t=!1}},[e.data,e.itemId,e.index,n,r]);let o=e.data??i;return o===null?null:(0,W.jsx)(Sn,{src:`data:${e.mediaType};base64,${o}`,alt:``,name:`Image`,className:`block size-full`,imageClassName:`block size-full object-cover`})}function QI(e){switch(e.kind){case`command`:return`Shell`;case`file_change`:return`Edit`;case`web_search`:return e.url===null?`Web Search`:`Webfetch`;case`skill`:return`Skill`;case`tool`:return e.name}}function $I(e){let t=e.item,n=e.live&&t.status===`running`;if(t.status===`failed`)return(0,W.jsx)(aL,{title:QI(t),subtitle:oL(t,e.cwd),error:t.output});switch(t.kind){case`command`:return(0,W.jsx)(eL,{command:t.command,output:t.output,pending:n});case`file_change`:return(0,W.jsx)(rL,{items:[t],cwd:e.cwd,live:e.live});case`web_search`:{let e=t.url;return e===null?(0,W.jsx)(tL,{query:t.query??``,links:t.results,pending:n}):(0,W.jsx)(vI,{title:`Webfetch`,subtitle:(0,W.jsx)(`a`,{href:e,target:`_blank`,rel:`noopener noreferrer`,className:`text-primary hover:underline hover:underline-offset-2`,children:e}),pending:n,grouped:!0,open:!1,onToggle:null})}case`skill`:return(0,W.jsxs)(`div`,{className:`flex min-h-7 items-center gap-1 text-[13px] leading-4 tracking-[-0.04px]`,children:[(0,W.jsx)(`span`,{className:`text-muted-foreground`,children:`Loaded`}),(0,W.jsx)(`span`,{className:`text-foreground`,children:(0,W.jsx)(hI,{text:t.skill,active:n})}),(0,W.jsx)(`span`,{className:`text-muted-foreground`,children:`skill`})]});case`tool`:{let r=t.input;switch(Xd(t.name)){case`read`:return(0,W.jsx)(vI,{title:`Read`,subtitle:cL(Zd(r)),args:sL(r,[`offset`,`limit`]),pending:n,grouped:!0,open:!1,onToggle:null});case`search`:return(0,W.jsx)(vI,{title:t.name,subtitle:oL(t,e.cwd),args:[...sL(r,[`pattern`]),...tf(r.glob)===``?[]:[`include=${tf(r.glob)}`]],pending:n,grouped:!0,open:!1,onToggle:null});case`other`:return(0,W.jsx)(vI,{title:`Called ${t.name}`,subtitle:oL(t,e.cwd),args:sL(r,Object.keys(r).filter(e=>![`description`,`query`,`url`,`path`,`pattern`].includes(e))).slice(0,3),pending:n,grouped:!0,open:!1,onToggle:null})}}}}function eL(e){let[t,n]=(0,U.useState)(!1);return(0,W.jsx)(vI,{title:`Shell`,subtitle:t?void 0:e.command,pending:e.pending,grouped:!0,open:t,onToggle:()=>n(!t),rail:!1,children:(0,W.jsxs)(`div`,{dir:`ltr`,className:`group/output border-border relative w-full overflow-hidden rounded-md border`,children:[(0,W.jsx)(`div`,{className:`absolute top-1 right-1 opacity-0 transition-opacity group-hover/output:opacity-100 focus-within:opacity-100`,children:(0,W.jsx)(XI,{text:e.command})}),(0,W.jsx)(`div`,{className:`max-h-60 [scrollbar-width:none] overflow-x-hidden overflow-y-auto`,children:(0,W.jsx)(`pre`,{className:`m-0 font-mono text-[13px] leading-5 tracking-[-0.04px] [overflow-wrap:anywhere] whitespace-pre-wrap select-text`,children:(0,W.jsxs)(`code`,{children:[(0,W.jsx)(`span`,{className:`text-foreground block p-3`,children:e.command}),e.output!==``&&(0,W.jsx)(`span`,{className:`border-border bg-muted text-muted-foreground block border-t p-3`,children:e.output})]})})})]})})}function tL(e){let[t,n]=(0,U.useState)(!1),r=e.links;return(0,W.jsx)(vI,{title:`Web Search`,subtitle:e.query,pending:e.pending,grouped:!0,open:t,onToggle:r.length===0?null:()=>n(!t),children:(0,W.jsxs)(`div`,{className:`flex flex-col gap-1 text-[13px] leading-5`,children:[r.slice(0,10).map(e=>(0,W.jsx)(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,className:`text-primary truncate hover:underline hover:underline-offset-2`,children:e.title===``?e.url:e.title},e.url)),r.length>10&&(0,W.jsxs)(`span`,{className:`text-muted-foreground`,children:[`+`,r.length-10,` more`]})]})})}function nL(e){let[t,n]=(0,U.useState)(!1);return(0,W.jsx)(vI,{title:e.streaming?`Thinking`:`Thought`,subtitle:e.streaming?lL(e.text):void 0,pending:e.streaming,grouped:!0,open:t,onToggle:()=>n(!t),children:(0,W.jsx)($n,{text:e.text,className:`text-muted-foreground text-[13px]`,lineBreaks:!0})})}function rL(e){let t=new Map;for(let n of e.items){let r=nf(n.path,e.cwd);t.set(r,[...t.get(r)??[],n])}return(0,W.jsx)(`div`,{className:`border-border overflow-hidden rounded-md border`,children:[...t].map(([t,n])=>(0,W.jsx)(iL,{file:t,items:n,pending:e.live&&n.some(e=>e.status===`running`)},t))})}function iL(e){let[t,n]=(0,U.useState)(!1),r=Math.max(e.file.lastIndexOf(`/`),e.file.lastIndexOf(`\\`)),i=0,a=0;for(let t of e.items){let e=Qd(t);i+=e.added,a+=e.removed}return(0,W.jsxs)(`div`,{className:`border-border border-b last:border-b-0`,children:[(0,W.jsxs)(`button`,{type:`button`,"aria-expanded":t,onClick:()=>n(!t),className:`group/tool flex h-9 w-full cursor-pointer items-center gap-2 ps-3 pe-1 text-left text-[13px] leading-4 tracking-[-0.04px] select-none`,children:[(0,W.jsx)(ni,{path:e.file,className:`size-4 shrink-0`}),(0,W.jsxs)(`span`,{className:`flex min-w-0 flex-1 items-baseline`,children:[r>=0&&(0,W.jsx)(`span`,{className:`text-muted-foreground truncate`,children:e.file.slice(0,r+1)}),(0,W.jsx)(`span`,{className:`text-foreground shrink-0`,children:(0,W.jsx)(hI,{text:e.file.slice(r+1),active:e.pending})})]}),(0,W.jsxs)(`span`,{role:`group`,"aria-label":`${i} additions, ${a} deletions`,className:`inline-flex items-center gap-1 align-middle font-mono text-xs tabular-nums`,children:[(0,W.jsxs)(`span`,{"aria-hidden":!0,className:`text-diff-addition`,children:[`+`,ln(i)]}),(0,W.jsxs)(`span`,{"aria-hidden":!0,className:`text-diff-deletion`,children:[`-`,ln(a)]})]}),(0,W.jsx)(_I,{open:t})]}),t&&(0,W.jsx)(`div`,{className:`border-border flex flex-col gap-2 border-t p-2`,children:e.items.map(e=>(0,W.jsx)(Jd,{item:e},e.id))})]})}function aL(e){let[t,n]=(0,U.useState)(!1),r=e.error.replace(/<\/?tool_use_error>/g,``).trim(),i=r.split(`: `)[0].trim();return(0,W.jsxs)(`div`,{className:`group/error flex w-full min-w-0 flex-col`,children:[(0,W.jsxs)(`button`,{type:`button`,"aria-expanded":t,onClick:()=>n(!t),className:`flex h-6 w-full cursor-pointer items-center text-left text-[13px] leading-4 tracking-[-0.04px] select-none`,children:[(0,W.jsxs)(`span`,{className:`flex max-w-[calc(100%-20px)] min-w-0 items-center gap-1.5`,children:[(0,W.jsx)(V,{icon:io,className:`text-destructive size-4 shrink-0`}),(0,W.jsx)(`span`,{className:`text-foreground shrink-0 font-medium`,children:e.title}),e.subtitle!==``&&!t&&(0,W.jsx)(`span`,{className:`text-muted-foreground min-w-0 truncate`,children:e.subtitle}),!t&&(0,W.jsx)(`span`,{className:`text-destructive min-w-0 truncate`,children:i===``?`Failed`:i[0].toUpperCase()+i.slice(1)})]}),(0,W.jsx)(_I,{open:!0,className:`ms-1.5 size-3.5`})]}),t&&(0,W.jsxs)(`div`,{className:`relative ps-6 pe-10 select-text`,children:[(0,W.jsx)(`div`,{className:`absolute top-0 right-0 opacity-0 transition-opacity group-hover/error:opacity-100 focus-within:opacity-100`,children:(0,W.jsx)(XI,{text:r})}),(0,W.jsx)(`p`,{className:`text-destructive text-[13px] leading-5 tracking-[-0.04px] [overflow-wrap:anywhere] whitespace-pre-wrap`,children:r})]})]})}function oL(e,t){switch(e.kind){case`command`:return e.command;case`file_change`:return e.path;case`web_search`:return e.url??e.query??``;case`skill`:return e.skill;case`tool`:{let n=e.input;if(Xd(e.name)===`search`){let e=tf(n.path);return e===``||e===t?``:nf(e,t)}return[`description`,`query`,`url`,`file_path`,`path`,`pattern`].map(e=>tf(n[e])).find(e=>e!==``)??``}}}function sL(e,t){return t.flatMap(t=>{let n=e[t];return typeof n==`string`||typeof n==`number`||typeof n==`boolean`?[`${t}=${n}`]:[]})}function cL(e){return e.split(`/`).at(-1)??e}function lL(e){let t=[...e.matchAll(/^\s*(?:#{1,6}[ \t]+(.+?)|\*\*([^*\n]+)\*\*)\s*$/gm)].at(-1);return t===void 0?void 0:(t[1]??t[2]).trim()}var uL=new Intl.ListFormat(`en`,{style:`long`,type:`conjunction`});function dL(e){let t=e.entries.flatMap(e=>e.kind===`reasoning`?[]:[e]),n=e.entries.length-t.length,r=uL.format([...new Set(t.map(QI))]),i=r===``?n===1?`Thought`:`Thoughts`:r,a=t.length>0?t.length:n;return(0,W.jsxs)(`div`,{className:`flex w-full min-w-0 flex-col`,children:[(0,W.jsxs)(`button`,{type:`button`,"aria-expanded":e.open,"aria-label":`Used ${a} ${i}`,onClick:e.onToggle,className:B(`group/tool focus-visible:ring-ring/70 flex h-7 w-full cursor-pointer items-center rounded-md text-left text-xs select-none focus-visible:ring-2 focus-visible:outline-none`,e.open&&`bg-background sticky top-0 z-20 box-content pb-2`),children:[(0,W.jsxs)(`span`,{className:`flex max-w-[calc(100%-24px)] min-w-0 items-center gap-1`,children:[(0,W.jsx)(`span`,{className:`text-muted-foreground shrink-0`,children:`Used`}),(0,W.jsx)(`span`,{className:`text-muted-foreground shrink-0 tabular-nums`,children:a}),(0,W.jsx)(`span`,{className:`text-muted-foreground min-w-0 truncate`,children:i})]}),(0,W.jsx)(_I,{open:e.open})]}),e.open&&(0,W.jsx)(`div`,{className:`flex flex-col gap-2`,children:pL(e.entries).map(t=>(0,W.jsx)(`div`,{className:`flex min-h-7 min-w-0 flex-col justify-center`,children:(0,W.jsx)(fL,{item:t,cwd:e.cwd,live:e.live})},t.key))})]})}function fL(e){let t=e.item;switch(t.kind){case`thinking`:return(0,W.jsx)(nL,{text:t.text,streaming:e.live&&t.last});case`tool`:return(0,W.jsx)($I,{item:t.item,cwd:e.cwd,live:e.live});case`reads`:return(0,W.jsx)(vI,{title:`Read`,subtitle:(0,W.jsx)(`span`,{title:t.items.map(e=>Zd(e.input)).join(`
|
|
23
23
|
`),children:t.items.map((t,n)=>(0,W.jsxs)(`span`,{children:[n>0&&` `,(0,W.jsx)(hI,{text:Zd(t.input).split(`/`).at(-1)??``,active:e.live&&t.status===`running`})]},t.id))}),pending:e.live&&t.items.some(e=>e.status===`running`),grouped:!0,open:!1,onToggle:null});case`files`:return(0,W.jsx)(rL,{items:t.items,cwd:e.cwd,live:e.live})}}function pL(e){let t=[];return e.forEach((n,r)=>{if(n.kind===`reasoning`){t.push({kind:`thinking`,key:n.id,text:n.text,last:r===e.length-1});return}let i=t.at(-1);n.status!==`failed`&&n.kind===`file_change`?i?.kind===`files`?i.items.push(n):t.push({kind:`files`,key:n.id,items:[n]}):n.status!==`failed`&&n.kind===`tool`&&Xd(n.name)===`read`?i?.kind===`reads`?i.items.push(n):t.push({kind:`reads`,key:n.id,items:[n]}):t.push({kind:`tool`,key:n.id,item:n})}),t}function mL(e){let[t,n]=(0,U.useState)([]),[r,i]=(0,U.useState)(null),[a,o]=(0,U.useState)(!0),s=(0,U.useRef)(null),c=e.rows.flatMap((t,n)=>t.kind===`user`?[{key:t.key,prompt:gL(t.item),reply:_L(e.rows,n)}]:[]),l=Math.max(c.findIndex(e=>e.key===t[0]),0),u=r===null?null:c[r];if((0,U.useEffect)(()=>{let t=e.scroller.current;if(t===null)throw Error(`transcript is not mounted`);function r(){if(t===null)throw Error(`transcript is not mounted`);let e=t.getBoundingClientRect(),r=[...t.querySelectorAll(`[data-kind="user"]`)],i=r.flatMap((t,n)=>{let i=t.getBoundingClientRect().top,a=r[n+1]?.getBoundingClientRect().top??1/0;return i<e.bottom&&a>e.top&&t.dataset.row?[t.dataset.row]:[]});n(e=>ft(e,i)?e:i)}let i=new ResizeObserver(()=>{if(t===null)throw Error(`transcript is not mounted`);r();let e=t.querySelector(`[data-row]`)?.parentElement;e!=null&&o(t.getBoundingClientRect().right-e.getBoundingClientRect().right>=40)});return r(),i.observe(t),t.addEventListener(`scroll`,r,{passive:!0}),()=>{i.disconnect(),t.removeEventListener(`scroll`,r)}},[e.scroller,c.length]),c.length<2)return null;function d(e){let t=s.current?.getBoundingClientRect();if(t===void 0)throw Error(`message rail is not mounted`);let n=Math.min(Math.max((e-t.top)/t.height,0),1);return Math.round(n*(c.length-1))}function f(e){return`${e/(c.length-1)*100}%`}return(0,W.jsxs)(`div`,{ref:s,className:B(`absolute top-1/2 right-[calc(var(--app-scrollbar-width)+0.25rem)] z-20 w-8 -translate-y-1/2 select-none pointer-coarse:hidden`,!a&&`hidden`),style:{height:`min(${(c.length-1)*10}px, 60%)`},children:[(0,W.jsx)(`button`,{type:`button`,"aria-label":`Jump to your message: ${u?.prompt??c[l].prompt}`,className:`focus-visible:ring-ring absolute inset-x-0 -inset-y-3 cursor-pointer rounded-md outline-none focus-visible:ring-2`,onPointerMove:e=>i(d(e.clientY)),onPointerLeave:()=>i(null),onFocus:()=>i(e=>e??l),onBlur:()=>i(null),onWheel:t=>{if(e.scroller.current===null)throw Error(`transcript is not mounted`);e.scroller.current.scrollBy({top:t.deltaY})},onClick:t=>{let n=t.detail===0?r:d(t.clientY);if(n===null)throw Error(`no message is selected`);e.onJump(c[n].key)},onKeyDown:e=>{let t=r??l,n=e.key===`ArrowUp`?t-1:e.key===`ArrowDown`?t+1:e.key===`Home`?0:e.key===`End`?c.length-1:null;n!==null&&(e.preventDefault(),i(Math.min(Math.max(n,0),c.length-1)))}}),c.map((e,n)=>{let i=r===null?null:Math.abs(n-r),a=t.includes(e.key);return(0,W.jsx)(`span`,{"aria-hidden":`true`,className:B(`pointer-events-none absolute right-1 h-0.5 w-5 origin-right -translate-y-1/2 rounded-full transition-all duration-150 ease-out`,i===0?`bg-foreground/85`:a?`bg-foreground/55`:`bg-foreground/20`,i===0?`scale-x-100`:i===1?`scale-x-75`:i===2?`scale-x-[0.55]`:a?`scale-x-50`:`scale-x-[0.35]`),style:{top:f(n)}},e.key)}),u!==null&&r!==null&&(0,W.jsxs)(`div`,{className:`bg-popover text-popover-foreground animate-in fade-in-0 zoom-in-98 pointer-events-none absolute right-9 w-80 rounded-xl border p-3 shadow-lg/10 transition-[top,translate] duration-100 ease-out`,style:{top:f(r),translate:r===0?`0 -0.75rem`:r===c.length-1?`0 calc(-100% + 0.75rem)`:`0 -50%`},children:[(0,W.jsx)(`p`,{className:`line-clamp-2 text-sm leading-5 font-medium wrap-anywhere`,children:u.prompt}),u.reply!==``&&(0,W.jsx)(`p`,{className:`text-muted-foreground mt-1 line-clamp-3 text-xs leading-[1.125rem] wrap-anywhere`,children:u.reply})]})]})}function hL(e,t){let n=e?.querySelector(`[data-row="${CSS.escape(t)}"]`);if(e===null||!(n instanceof HTMLElement))throw Error(`that message is not on screen`);e.scrollTop+=n.getBoundingClientRect().top-e.getBoundingClientRect().top-24}function gL(e){let t=e.text.replace(/\s+/g,` `).trim();return t===``?e.images.length>0?`Image`:`Message`:t.slice(0,300)}function _L(e,t){let n=``;for(let r of e.slice(t+1)){if(r.kind===`user`)break;r.kind===`assistant`&&(n=r.text)}return n.slice(0,600).replace(/[#*`>|]+/g,``).replace(/\s+/g,` `).trim()}var vL=30;function yL(e){let t=k(e=>e.selection),n=k(e=>e.loaded),r=k(e=>e.items),i=k(e=>e.earlier),a=k(e=>e.before),o=k(e=>e.partial),s=k(e=>e.requests),c=k(Ce),l=(0,U.useRef)(null),u=(0,U.useRef)(null),d=(0,U.useRef)(!0),f=(0,U.useRef)(null),[p,m]=(0,U.useState)(!1),[h,g]=(0,U.useState)([]),[_,v]=(0,U.useState)(null),[y,b]=(0,U.useState)(!1),x=(0,U.useRef)(null),S=k(e=>t===null?``:Ct(e,t.machine,t.projectId)?.path??``),C=k(Ot),w=k(e=>e.sentAt);(0,U.useLayoutEffect)(()=>{let e=l.current;e!==null&&w!==0&&(d.current=!0,e.scrollTop=e.scrollHeight)},[w]),(0,U.useEffect)(()=>{let e=l.current;if(e===null||u.current===null)throw Error(`transcript is not mounted`);let t=new ResizeObserver(()=>{d.current&&(e.scrollTop=e.scrollHeight)});return t.observe(e),t.observe(u.current),()=>t.disconnect()},[]),(0,U.useLayoutEffect)(()=>{let e=l.current;e!==null&&d.current&&(e.scrollTop=e.scrollHeight)},[r,o,s,C]);let T=(0,U.useMemo)(()=>fI([...i,...r],c),[i,r,c]),E=HI(i,!1,``),D=[...E,...HI(r,C,o)],O=D.findIndex(e=>e.key===_?.key),A=y?0:Math.max(0,O===-1?D.length-vL:O-(_?.above??0));(0,U.useLayoutEffect)(()=>{let e=l.current;e!==null&&f.current!==null&&(e.scrollTop=e.scrollHeight-f.current),f.current=null},[i,A]),(0,U.useLayoutEffect)(()=>{x.current!==null&&(hL(l.current,x.current),x.current=null)},[A]),or(`mod+f`,e=>{let t=e.target;e.defaultPrevented||t instanceof Element&&t!==document.body&&t.closest(`[data-composer], [data-transcript]`)===null||(e.preventDefault(),b(!0),requestAnimationFrame(()=>document.querySelector(`[data-thread-find]`)?.select()))},{enableOnFormTags:!0}),(0,U.useLayoutEffect)(()=>{let e=l.current;e!==null&&D.length!==0&&(O===-1?v({key:D[A].key,above:0}):j(e))});function j(e){A===0||e.scrollTop>=e.clientHeight||(f.current=e.scrollHeight-e.scrollTop,v({key:D[A].key,above:vL}))}function M(e){let t=D.findIndex(t=>t.key===e);if(t===-1)throw Error(`that message is not loaded`);t>=A?hL(l.current,e):(x.current=e,v({key:e,above:1}))}let ee=(0,U.useCallback)(e=>{g(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},[]);return(0,W.jsxs)(W.Fragment,{children:[y&&(0,W.jsx)(OI,{content:u,scroller:l,onClose:()=>{b(!1),D.length>0&&v({key:D[0].key,above:0}),document.querySelector(`[data-composer]`)?.focus()}}),(0,W.jsx)(mL,{rows:D,scroller:l,onJump:M}),(0,W.jsxs)(`div`,{ref:l,"data-transcript":!0,className:`topbar-scroll-fade relative min-h-0 flex-1 overflow-y-auto overscroll-y-contain pb-8`,onScroll:e=>{let t=e.currentTarget;d.current=t.scrollHeight-t.scrollTop-t.clientHeight<40,j(t)},children:[(0,W.jsx)(`div`,{ref:u,children:(0,W.jsxs)(Pd,{width:`chat`,className:`pt-3`,children:[!n&&(0,W.jsx)(`p`,{className:`text-muted-foreground py-6 text-center text-xs`,children:`Loading…`}),a!==null&&A===0&&(0,W.jsx)(`div`,{className:`flex justify-center pb-4`,children:(0,W.jsx)(H,{type:`button`,size:`xs`,variant:`ghost-muted`,disabled:p,onClick:async()=>{let e=l.current;e!==null&&(f.current=e.scrollHeight-e.scrollTop),v({key:D[0].key,above:vL}),m(!0),await St(),m(!1)},children:p?`Loading…`:`Load earlier conversation`})}),D.slice(A).map((t,n)=>{let r=A+n,i=D[r-1],a=r<E.length;return(0,W.jsx)(`div`,{"data-row":t.key,"data-kind":t.kind,className:B(i===void 0?void 0:t.kind===`user`?`pt-6`:t.kind===`working`?void 0:zI(t)&&zI(i)?`pt-2`:zI(t)||zI(i)?`pt-3`:`pt-4`,t.kind===`assistant`&&`group/assistant`),children:(0,W.jsx)(SL,{row:t,agents:T.agents,tasks:T.tasks,running:C,compacting:c?.compacting===!0,fork:!a,expanded:h.includes(t.key),onToggle:ee,onOpenTask:e.onOpenTask,rewind:!a,cwd:S})},t.key)})]})}),(0,W.jsx)(II,{scroller:l})]})]})}var bL=(0,U.memo)(yL);function xL(e){let t=e.row;switch(t.kind){case`user`:return(0,W.jsx)(YI,{item:t.item,first:t.first,running:e.running,rewind:e.rewind});case`working`:return(0,W.jsx)(`div`,{className:`text-muted-foreground h-9 pt-3 text-[13px] leading-5 font-medium tracking-[-0.04px]`,children:(0,W.jsx)(hI,{text:e.compacting?`Compacting conversation`:`Working`,active:!0})});case`group`:return(0,W.jsx)(dL,{entries:t.entries,cwd:e.cwd,live:t.live,open:e.expanded,onToggle:()=>e.onToggle(t.key)});case`agent`:return(0,W.jsx)(EI,{item:t.item,agents:e.agents,tasks:e.tasks,sending:t.live&&t.item.status===`running`,onOpen:e.onOpenTask});case`assistant`:return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`div`,{"data-quotable":!0,children:(0,W.jsx)($n,{text:t.text===``&&!t.streaming?`(empty response)`:t.text,streaming:t.streaming})}),t.meta&&(0,W.jsxs)(`div`,{className:`mt-1.5 flex items-center gap-2 text-xs tabular-nums opacity-0 transition-opacity duration-200 group-hover/assistant:opacity-100 focus-within:opacity-100 pointer-coarse:opacity-100`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[(0,W.jsx)(XI,{text:t.text}),e.fork&&(0,W.jsx)(CL,{uuid:t.message})]}),t.time!==null&&(0,W.jsx)(Wr,{label:xn(t.time),children:(0,W.jsx)(`p`,{className:`text-muted-foreground text-xs tabular-nums`,children:dn(t.time)})})]})]});case`error`:return(0,W.jsxs)(`div`,{className:`text-destructive flex gap-1.5 text-[13px] leading-5 tracking-[-0.04px]`,children:[(0,W.jsx)(V,{icon:io,className:`mt-0.5 size-4 shrink-0`}),(0,W.jsx)(`p`,{className:`min-w-0 [overflow-wrap:anywhere] whitespace-pre-wrap select-text`,children:t.text})]});case`notice`:return(0,W.jsxs)(`div`,{className:`text-muted-foreground mx-auto flex w-full max-w-(--chat-content-max-width) items-center gap-3 py-1 text-xs`,children:[(0,W.jsx)(`span`,{className:`bg-border/70 h-px flex-1`}),(0,W.jsx)(`span`,{children:t.text}),(0,W.jsx)(`span`,{className:`bg-border/70 h-px flex-1`})]});case`compaction`:return(0,W.jsxs)(`div`,{className:`mx-auto w-full max-w-(--chat-content-max-width)`,children:[(0,W.jsxs)(`div`,{className:`text-muted-foreground flex items-center gap-3 py-1 text-xs`,children:[(0,W.jsx)(`span`,{className:`bg-border/70 h-px flex-1`}),t.summary===null?(0,W.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,W.jsx)(V,{icon:es,className:`size-3`}),`Conversation compacted`]}):(0,W.jsxs)(`button`,{type:`button`,"aria-expanded":e.expanded,className:`hover:text-foreground flex items-center gap-1.5 transition-colors`,onClick:()=>e.onToggle(t.key),children:[(0,W.jsx)(V,{icon:es,className:`size-3`}),`Compacted summary`,(0,W.jsx)(V,{icon:sn,strokeWidth:2.5,className:B(`size-3 transition-transform`,!e.expanded&&`-rotate-90`)})]}),(0,W.jsx)(`span`,{className:`bg-border/70 h-px flex-1`})]}),e.expanded&&t.summary!==null&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`div`,{className:`bg-muted/40 text-muted-foreground mt-2 rounded-lg border px-4 py-3 text-sm`,children:(0,W.jsx)($n,{text:t.summary,streaming:!1})}),(0,W.jsxs)(`div`,{className:`mt-1.5 flex items-center justify-end gap-2 text-xs tabular-nums`,children:[t.time!==null&&(0,W.jsx)(Wr,{label:xn(t.time),children:(0,W.jsx)(`p`,{className:`text-muted-foreground text-xs tabular-nums`,children:dn(t.time)})}),(0,W.jsx)(XI,{text:t.summary})]})]})]});case`plan`:return(0,W.jsx)(`div`,{className:`min-w-0`,"data-quotable":!0,children:(0,W.jsx)(AI,{plan:t.plan})});case`question`:return(0,W.jsx)(FI,{item:t.item})}}var SL=(0,U.memo)(xL,(e,t)=>t.row.kind===`agent`?ft(e,t):ft(Li(e,[`agents`,`tasks`]),Li(t,[`agents`,`tasks`])));function CL(e){let[t,n]=(0,U.useState)(!1);return(0,W.jsx)(Wr,{label:`Fork from this response`,children:(0,W.jsx)(H,{type:`button`,size:`icon-micro`,variant:`ghost-muted`,disabled:t,"aria-label":`Fork from this response`,onClick:()=>{n(!0),at(e.uuid).finally(()=>n(!1))},children:(0,W.jsx)(V,{icon:Ro,className:B(`size-4`,t&&`animate-pulse`)})})})}var wL=Ft(`event`,[fe({offsite:s(`browser`),event:s(`location`),url:y(),replaced:ae()}),fe({offsite:s(`browser`),event:s(`open`),url:y()}),fe({offsite:s(`browser`),event:s(`loading`)})]);function TL(e){let t=Fe({from:`__root__`,select:e=>e.browse??null}),[n,r]=(0,U.useState)(null),[i,a]=(0,U.useState)(0),[o,s]=(0,U.useState)(0),[c,l]=(0,U.useState)(!1),[u,d]=(0,U.useState)(null),f=(0,U.useRef)(null),p=(0,U.useRef)(null),m=(0,U.useRef)({entries:[],index:-1}),h=k(t=>L(t,e.machine).status===`online`);(0,U.useEffect)(()=>{if(t===null||!h)return;let n=`${e.machine} ${i} ${t}`;if(p.current===n)return;let a=!0;return EL(e.machine,t).then(e=>{a&&(p.current=n,m.current={entries:[],index:-1},r({target:t,src:e,error:null}),s(e=>e+1),d(null),l(!0))},e=>{a&&(r({target:t,src:null,error:Ht(e)}),d(null),l(!1))}),()=>{a=!1}},[e.machine,t,i,h]),(0,U.useEffect)(()=>{function a(a){if(a.source===null||a.source!==f.current?.contentWindow)return;let o=wL.safeParse(a.data);if(!o.success)return;if(o.data.event===`loading`){d(null),l(!0);return}if(t===null||n===null)throw Error(`a page reported its location outside the browser`);let s=o.data.url;o.data.event===`open`?z(e.machine,`browser.open`,{url:s,fromPage:!0}).then(t=>{p.current=`${e.machine} ${i} ${s}`,r({target:s,src:`${De(e.machine)}${t}`,error:null}),l(!0),M({browse:s})},N):(d(DL(m.current,s,o.data.replaced)),s!==t&&(p.current=`${e.machine} ${i} ${s}`,r({...n,target:s}),M({browse:s})))}return window.addEventListener(`message`,a),()=>window.removeEventListener(`message`,a)},[e.machine,i,t,n]);let g=t!==null&&/^https?:\/\//i.test(t),_=t===null?null:n?.src??null,v=!g&&n?.target===t?n.src:null,y=n?.target===t?n.error:null,b=t!==null&&h&&(n?.target!==t||c);function x(e){if(u===null)throw Error(`no page is open to send a browser command to`);f.current?.contentWindow?.postMessage({offsite:`browser`,command:e},`*`)}return(0,W.jsxs)(`div`,{className:`bg-background flex h-full min-h-0 min-w-0 flex-col`,children:[(0,W.jsxs)(`div`,{className:`border-border/60 bg-background flex h-(--workspace-topbar-height) shrink-0 items-center gap-2 border-b pr-3 pl-3`,children:[(0,W.jsx)(H,{size:`icon-sm`,variant:`ghost`,title:`Close`,"aria-label":`Close`,onClick:e.onClose,children:(0,W.jsx)(V,{icon:_t,className:`size-4`})}),(0,W.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[(0,W.jsx)(H,{size:`icon-sm`,variant:`ghost`,title:`Back`,"aria-label":`Back`,disabled:u?.back!==!0,onClick:()=>x(`back`),children:(0,W.jsx)(V,{icon:po,className:`size-4`})}),(0,W.jsx)(H,{size:`icon-sm`,variant:`ghost`,title:`Forward`,"aria-label":`Forward`,disabled:u?.forward!==!0,onClick:()=>x(`forward`),children:(0,W.jsx)(V,{icon:Tr,className:`size-4`})}),(0,W.jsx)(H,{size:`icon-sm`,variant:`ghost`,title:`Reload`,"aria-label":`Reload`,onClick:()=>{u===null?a(i+1):x(`reload`)},children:(0,W.jsx)(V,{icon:oi,className:B(`size-4`,b&&`animate-spin`)})})]}),(0,W.jsx)(`form`,{className:`min-w-0 flex-1`,onSubmit:e=>{e.preventDefault();let t=new FormData(e.currentTarget).get(`address`);if(typeof t!=`string`)throw Error(`the address field is missing`);let n=t.trim();n!==``&&ce(OL(n))},children:(0,W.jsx)(Kf,{name:`address`,className:`h-7 font-mono text-xs`,placeholder:`URL or file path`,"aria-label":`URL or file path`,defaultValue:t??``})},t),v!==null&&(0,W.jsx)(H,{size:`icon-sm`,variant:`ghost`,asChild:!0,children:(0,W.jsx)(`a`,{href:v,target:`_blank`,rel:`noopener noreferrer`,title:`Open in a new tab`,"aria-label":`Open in a new tab`,children:(0,W.jsx)(V,{icon:Jo,className:`size-4`})})})]}),y!==null&&(0,W.jsx)(`p`,{className:`text-muted-foreground p-4 text-center text-xs`,children:y}),t===null&&(0,W.jsx)(`p`,{className:`text-muted-foreground p-4 text-center text-xs`,children:`Type a URL or a file path above. URLs load from this machine.`}),_!==null&&(0,W.jsx)(`iframe`,{ref:f,src:_,sandbox:g?`allow-scripts allow-forms allow-popups allow-modals allow-downloads allow-presentation allow-pointer-lock`:void 0,title:t??``,className:`min-h-0 w-full flex-1 bg-white scheme-light`,onLoad:()=>l(!1)},o)]})}async function EL(e,t){if(/^https?:\/\//i.test(t)){let n=await z(e,`browser.open`,{url:t,fromPage:!1});return`${De(e)}${n}`}let n=await z(e,`files.browse`,void 0);return`${De(e)}/api/browse/${n}${kL(t)}`}function DL(e,t,n){return n&&e.index>=0?e.entries[e.index]=t:e.entries[e.index-1]===t?--e.index:e.entries[e.index+1]===t?e.index+=1:e.entries[e.index]!==t&&(e.entries=[...e.entries.slice(0,e.index+1),t],e.index+=1),{back:e.index>0,forward:e.index<e.entries.length-1}}function OL(e){return/^(https?:\/\/|file:)/i.test(e)||/^[/.]/.test(e)||/^[a-z]:[\\/]/i.test(e)?e:/^(localhost|\d+(\.\d+){3}|[\w.-]+:\d+)([:/?#]\S*)?$/i.test(e)?`http://${e}`:/^[\w-]+(\.[\w-]+)+([/?#]\S*)?$/.test(e)?`https://${e}`:`https://www.google.com/search?q=${encodeURIComponent(e)}`}function kL(e){let t=e.replaceAll(`\\`,`/`).split(`/`).map(encodeURIComponent).join(`/`);return t.startsWith(`/`)?t:`/${t}`}function AL(e){let t=e.stopping;return(0,W.jsx)(lr,{open:t!==null,onOpenChange:t=>{t||e.onClose()},children:t!==null&&(0,W.jsxs)(Kn,{children:[(0,W.jsxs)(Er,{children:[(0,W.jsxs)(Ln,{children:[`Stop `,t.title,`?`]}),(0,W.jsx)(Pn,{children:`It is still running. Do you really want to stop it?`})]}),(0,W.jsxs)(br,{children:[(0,W.jsx)(Jn,{children:`Cancel`}),(0,W.jsx)(rr,{variant:`destructive`,onClick:()=>{if(e.sessionId===null)throw Error(`Cannot stop a task without a session`);Te(e.machine,e.sessionId,t.taskId)},children:`Stop`})]})]})})}function jL(e){return(0,W.jsx)(`button`,{type:`button`,title:e.label,"aria-label":e.label,className:`text-muted-foreground hover:text-destructive focus-visible:ring-ring/70 mr-1.5 grid size-7 shrink-0 cursor-pointer place-items-center rounded-md focus-visible:ring-2 focus-visible:outline-none`,onClick:e.onClick,children:(0,W.jsx)(V,{icon:Cs,className:`size-4`})})}function ML(e){return(0,W.jsx)(H,{size:`xs`,variant:`outline`,className:`shrink-0`,onClick:()=>Te(e.machine,e.sessionId,e.taskId),children:`Stop`})}function NL(e){let t=k(e=>e.items),n=k(e=>e.earlier),r=k(t=>ke(t.machines,e.machine,e.sessionId)),[i,a]=(0,U.useState)(null),o=[...n,...t],s=fI(o,r),c=s.agents.find(t=>t.item.id===e.selected),l=s.tasks.find(t=>t.item.id===e.selected),u=c===void 0?null:CI(c.item);return(0,W.jsxs)(`div`,{className:`bg-background flex h-full min-h-0 min-w-0 flex-col`,children:[(0,W.jsxs)(`div`,{className:`border-border/60 bg-background flex h-(--workspace-topbar-height) shrink-0 items-center gap-1 border-b pr-3 pl-3`,children:[(0,W.jsx)(H,{size:`icon-sm`,variant:`ghost`,title:`Close`,"aria-label":`Close`,onClick:e.onClose,children:(0,W.jsx)(V,{icon:_t,className:`size-4`})}),c===void 0&&l===void 0&&(0,W.jsx)(`span`,{className:`text-foreground min-w-0 truncate text-xs font-medium`,children:`Tasks`}),(c!==void 0||l!==void 0)&&(0,W.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2 text-xs`,children:[(0,W.jsx)(H,{size:`icon-sm`,variant:`ghost`,title:`Back to tasks`,"aria-label":`Back to tasks`,onClick:()=>e.onSelect(null),children:(0,W.jsx)(V,{icon:po,className:`size-4`})}),c!==void 0&&u!==null&&(0,W.jsxs)(W.Fragment,{children:[c.status===`Running`?(0,W.jsx)(TI,{className:u.tone}):(0,W.jsx)(wI,{className:u.tone}),(0,W.jsx)(`span`,{className:`text-foreground shrink-0 font-medium`,children:u.name}),u.description!==``&&(0,W.jsx)(`span`,{className:`text-muted-foreground min-w-0 truncate`,children:u.description}),c.status===`Running`&&c.agentId!==null&&e.sessionId!==null&&(0,W.jsx)(ML,{machine:e.machine,sessionId:e.sessionId,taskId:c.agentId})]}),l!==void 0&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(V,{icon:Ao,className:`text-muted-foreground size-4 shrink-0`}),(0,W.jsx)(`span`,{className:`text-foreground min-w-0 truncate font-medium`,children:pI(l.item)}),(0,W.jsx)(`span`,{className:B(`text-muted-foreground shrink-0`,l.status===`Failed`&&`text-destructive`,l.status===`Running`&&`text-shimmer`),children:l.status}),l.status===`Running`&&l.taskId!==null&&e.sessionId!==null&&(0,W.jsx)(ML,{machine:e.machine,sessionId:e.sessionId,taskId:l.taskId})]})]})]}),c===void 0&&l===void 0&&(0,W.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-3`,children:[(0,W.jsx)(`h2`,{className:`text-muted-foreground px-1 pb-1.5 text-xs font-medium`,children:`Agents`}),s.agents.length===0&&(0,W.jsx)(`p`,{className:`text-muted-foreground px-1 py-1 text-xs`,children:`No agents in this thread.`}),(0,W.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:[...s.agents.filter(e=>e.status===`Running`),...s.agents.filter(e=>e.status!==`Running`)].map(t=>{let n=CI(t.item),r=t.agentId;return(0,W.jsxs)(`div`,{className:`bg-secondary hover:bg-accent flex items-center rounded-lg`,children:[(0,W.jsxs)(`button`,{type:`button`,"aria-label":`Open ${n.name} agent: ${n.description}`,className:`focus-visible:ring-ring/70 flex min-w-0 flex-1 cursor-pointer items-center gap-2 rounded-lg px-3 py-2 text-left text-[13px] leading-5 tracking-[-0.04px] select-none focus-visible:ring-2 focus-visible:outline-none`,onClick:()=>e.onSelect(t.item.id),children:[t.status===`Running`?(0,W.jsx)(TI,{className:n.tone}):(0,W.jsx)(wI,{className:n.tone}),(0,W.jsx)(`span`,{className:`text-foreground shrink-0 font-medium`,children:n.name}),(0,W.jsx)(`span`,{className:`text-foreground min-w-0 flex-1 truncate`,children:n.description}),(0,W.jsx)(`span`,{className:B(`text-muted-foreground shrink-0 text-xs`,t.status===`Failed`&&`text-destructive`,t.status===`Running`&&`text-shimmer`),children:t.status})]}),t.status===`Running`&&r!==null&&e.sessionId!==null&&(0,W.jsx)(jL,{label:`Stop ${n.name} agent`,onClick:()=>a({taskId:r,title:`${n.name} agent`})})]},t.item.id)})}),(0,W.jsx)(`h2`,{className:`text-muted-foreground px-1 pt-5 pb-1.5 text-xs font-medium`,children:`Tasks`}),s.tasks.length===0&&(0,W.jsx)(`p`,{className:`text-muted-foreground px-1 py-1 text-xs`,children:`No background tasks in this thread.`}),(0,W.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:[...s.tasks.filter(e=>e.status===`Running`),...s.tasks.filter(e=>e.status!==`Running`)].map(t=>{let n=t.taskId;return(0,W.jsxs)(`div`,{className:`bg-secondary hover:bg-accent flex items-center rounded-lg`,children:[(0,W.jsxs)(`button`,{type:`button`,"aria-label":`Open task: ${pI(t.item)}`,className:`focus-visible:ring-ring/70 flex min-w-0 flex-1 cursor-pointer items-center gap-2 rounded-lg px-3 py-2 text-left text-[13px] leading-5 tracking-[-0.04px] select-none focus-visible:ring-2 focus-visible:outline-none`,onClick:()=>e.onSelect(t.item.id),children:[(0,W.jsx)(V,{icon:Ao,className:B(`size-4 shrink-0`,t.status===`Running`?`text-foreground animate-pulse`:`text-muted-foreground`)}),(0,W.jsx)(`span`,{className:`text-foreground min-w-0 flex-1 truncate`,children:pI(t.item)}),(0,W.jsx)(`span`,{className:B(`text-muted-foreground shrink-0 text-xs`,t.status===`Failed`&&`text-destructive`,t.status===`Running`&&`text-shimmer`),children:t.status})]}),t.status===`Running`&&n!==null&&e.sessionId!==null&&(0,W.jsx)(jL,{label:`Stop task: ${pI(t.item)}`,onClick:()=>a({taskId:n,title:pI(t.item)})})]},t.item.id)})})]}),c!==void 0&&(0,W.jsx)(FL,{item:c.item,agentId:c.agentId,running:c.status===`Running`,items:o,found:s,cwd:e.cwd,onSelect:e.onSelect},c.item.id),l!==void 0&&e.sessionId!==null&&(0,W.jsx)(PL,{machine:e.machine,sessionId:e.sessionId,command:l.item.command,path:l.path,events:l.events,running:l.status===`Running`},l.item.id),(0,W.jsx)(AL,{machine:e.machine,sessionId:e.sessionId,stopping:i,onClose:()=>a(null)})]})}function PL(e){let[t,n]=(0,U.useState)(void 0),[r,i]=(0,U.useState)(null),a=(0,U.useRef)(null),o=(0,U.useRef)(!0);(0,U.useEffect)(()=>{let t=e.path;if(t===null)return;let r=!0;async function a(t){try{let a=await z(e.machine,`tasks.output`,{sessionId:e.sessionId,path:t});if(!r)return;n(a),i(null)}catch(e){r&&i(Ht(e))}}a(t);let o=e.running?window.setInterval(()=>void a(t),2e3):null;return()=>{r=!1,o!==null&&window.clearInterval(o)}},[e.machine,e.sessionId,e.path,e.running]),(0,U.useLayoutEffect)(()=>{let e=a.current;e!==null&&o.current&&(e.scrollTop=e.scrollHeight)},[t,e.events]);let s=e.path===null?e.events.join(`
|
|
24
24
|
`):t?.text??``;return(0,W.jsxs)(`div`,{ref:a,className:`min-h-0 flex-1 overflow-y-auto overscroll-y-contain p-3`,onScroll:e=>{let t=e.currentTarget;o.current=t.scrollHeight-t.scrollTop-t.clientHeight<40},children:[e.command!==``&&(0,W.jsxs)(`p`,{className:`text-muted-foreground pb-2 font-mono text-xs [overflow-wrap:anywhere] whitespace-pre-wrap`,children:[`$ `,e.command]}),r!==null&&(0,W.jsx)(`p`,{className:`text-destructive text-xs`,children:r}),r===null&&e.path!==null&&t===void 0&&(0,W.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:`Loading…`}),r===null&&e.path!==null&&t===null&&(0,W.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:`The output file no longer exists.`}),t?.truncated===!0&&(0,W.jsx)(`p`,{className:`text-muted-foreground pb-2 text-xs`,children:`Showing the end of the output.`}),e.path===null&&e.events.length===0&&(0,W.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:`No events yet.`}),t?.text===``&&(0,W.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:e.running?`No output yet.`:`No output.`}),s!==``&&(0,W.jsx)(`pre`,{className:`bg-secondary text-foreground rounded-lg p-3 font-mono text-xs leading-5 [overflow-wrap:anywhere] whitespace-pre-wrap select-text`,children:s})]})}function FL(e){let t=(0,U.useRef)(null),n=(0,U.useRef)(!0),[r,i]=(0,U.useState)([]);(0,U.useLayoutEffect)(()=>{let e=t.current;e!==null&&n.current&&(e.scrollTop=e.scrollHeight)},[e.items,e.running]);function a(e){i(r.includes(e)?r.filter(t=>t!==e):[...r,e])}let o=e.items.filter(t=>t.parent===e.item.id),s=o.length===0;(0,U.useEffect)(()=>{s&&e.agentId!==null&&Xe(e.item.id,e.agentId)},[s,e.item.id,e.agentId]);let c=o.at(0),l=c?.kind===`user`?c:null,u=BI({prompt:null,first:!1,items:l===null?o:o.slice(1)},e.running?{partial:``}:null);return(0,W.jsxs)(`div`,{ref:t,className:`min-h-0 flex-1 overflow-y-auto overscroll-y-contain px-4 pt-1 pb-8`,onScroll:e=>{let t=e.currentTarget;n.current=t.scrollHeight-t.scrollTop-t.clientHeight<40},children:[l!==null&&(0,W.jsx)(vI,{title:`Prompt`,pending:!1,grouped:!0,open:r.includes(`prompt`),onToggle:()=>a(`prompt`),children:(0,W.jsx)($n,{text:l.text,className:`text-muted-foreground text-[13px]`})}),u.map((t,n)=>{let i=u[n-1];return(0,W.jsx)(`div`,{className:B(i===void 0?`pt-2`:t.kind===`working`?void 0:zI(t)&&zI(i)?`pt-2`:`pt-4`,t.kind===`assistant`&&`group/assistant`),children:(0,W.jsx)(SL,{row:t,agents:e.found.agents,tasks:e.found.tasks,running:e.running,compacting:!1,fork:!1,expanded:r.includes(t.key),onToggle:a,onOpenTask:e.onSelect,rewind:!1,cwd:e.cwd})},t.key)})]})}var IL=(0,U.lazy)(async()=>({default:(await ci(async()=>{let{DiffPanel:e}=await import(`./diff-panel-Dp94FfM1.js`);return{DiffPanel:e}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17]))).DiffPanel})),LL=`text-foreground hover:bg-accent data-[pressed=true]:bg-accent relative grid h-7 min-w-7 cursor-pointer place-items-center rounded-lg border border-transparent [&_svg]:size-4 [&_svg]:opacity-80`;function RL(e){let t=BL(e),n=k(e=>e.prefs),r=k(e=>e.editor===null);return gr(()=>Et({machine:e.selection.machine,projectId:e.selection.projectId}),r),(0,W.jsxs)(ar,{children:[(0,W.jsx)(Wn,{asChild:!0,children:(0,W.jsxs)(`div`,{className:`flex items-center gap-1`,children:[t.filter(e=>n.toolbar.includes(e.id)).map(e=>(0,W.jsxs)(`button`,{className:LL,"data-pressed":e.pressed,"aria-label":e.label,title:e.title,onClick:e.onSelect,children:[(0,W.jsx)(V,{icon:e.icon}),e.badge]},e.id)),e.children]})}),(0,W.jsx)(Xn,{className:`w-44`,children:t.map(e=>(0,W.jsxs)(fr,{checked:n.toolbar.includes(e.id),onCheckedChange:t=>D({...n,toolbar:t?[...n.toolbar,e.id]:n.toolbar.filter(t=>t!==e.id)}),children:[(0,W.jsx)(V,{icon:e.icon}),e.label]},e.id))})]})}function zL(e){let t=e.session,n=k(e=>e.prefs.toolbar),r=BL(e).filter(t=>e.mobile||!n.includes(t.id)),i=Pr(`sidebarScope`),a=k(e=>{if(t===void 0)return!1;let n=ke(e.machines,t.machine,t.id);return n?.running===!0||Object.values(n?.tasks??{}).includes(`running`)}),[o,s]=(0,U.useState)(null),[c,l]=(0,U.useState)(!1);function u(){if(t===void 0)throw Error(`session is missing`);Ue(t.machine,t.id,i)}return(0,W.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[(0,W.jsxs)(fn,{open:e.open,onOpenChange:e.onOpenChange,children:[(0,W.jsx)(dr,{asChild:!0,children:(0,W.jsxs)(`button`,{className:B(LL,`data-[state=open]:bg-accent`),"aria-label":`More`,title:`More`,children:[(0,W.jsx)(V,{icon:nr}),r.some(e=>e.attention)&&(0,W.jsx)(`span`,{className:`bg-muted-foreground ring-background absolute top-0.5 right-0.5 size-1.5 rounded-full ring-2`})]})}),(0,W.jsxs)(vn,{className:`w-56 [&>[data-slot=dropdown-menu-separator]:first-child]:hidden`,align:`end`,children:[r.map(e=>(0,W.jsxs)(wn,{onSelect:e.onSelect,children:[(0,W.jsx)(V,{icon:e.icon}),(0,W.jsx)(`span`,{className:`flex-1`,children:e.label}),e.detail]},e.id)),e.children,t!==void 0&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(On,{}),(0,W.jsx)(_k,{session:t,context:!1,mobile:e.mobile,onDeactivate:()=>{a?l(!0):u()},onRename:()=>s(t.title)})]})]})]}),t!==void 0&&o!==null&&(0,W.jsx)(ei,{open:!0,onOpenChange:e=>{e||s(null)},children:(0,W.jsx)(qr,{children:(0,W.jsxs)(`form`,{className:`grid gap-4`,onSubmit:e=>{e.preventDefault();let n=o.trim();s(null),n!==``&&n!==t.title&&Se(t.machine,t.id,{title:n})},children:[(0,W.jsx)(Jr,{children:(0,W.jsx)(Zr,{children:`Rename thread`})}),(0,W.jsx)(Kf,{"aria-label":`Title`,value:o,onChange:e=>s(e.target.value)}),(0,W.jsxs)(ti,{children:[(0,W.jsx)(H,{type:`button`,variant:`outline`,onClick:()=>s(null),children:`Cancel`}),(0,W.jsx)(H,{type:`submit`,children:`Rename`})]})]})})}),(0,W.jsx)(lr,{open:c,onOpenChange:l,children:(0,W.jsxs)(Kn,{children:[(0,W.jsxs)(Er,{children:[(0,W.jsx)(Ln,{children:`Stop running work?`}),(0,W.jsx)(Pn,{children:`The agent or background tasks are running. Do you really want to stop them?`})]}),(0,W.jsxs)(br,{children:[(0,W.jsx)(Jn,{children:`Cancel`}),(0,W.jsx)(rr,{variant:`destructive`,onClick:u,children:`Stop and Mark Done`})]})]})})]})}function BL(e){let t=(0,U.useSyncExternalStore)(CP,()=>wP().alerts.length>0),n=(0,U.useSyncExternalStore)(CP,()=>wP().layout.tabs.filter(t=>t.projectId===e.selection.projectId).length),r=k(e=>{if(e.selection?.sessionId===null)return 0;let t=fI([...e.earlier,...e.items],Ce(e));return[...t.agents,...t.tasks].filter(e=>e.status===`Running`).length});return[{id:`diff`,label:`Diff`,title:`Diff`,icon:Lo,pressed:e.panel===`diff`,attention:e.changed,badge:e.changed&&(0,W.jsx)(`span`,{className:`bg-muted-foreground ring-background absolute top-0.5 right-0.5 size-1.5 rounded-full ring-2`}),detail:e.changed&&(0,W.jsx)(`span`,{className:`bg-muted-foreground size-1.5 rounded-full`}),onSelect:()=>e.onPanel(e.panel===`diff`?null:`diff`)},{id:`terminal`,label:`Terminal`,title:`Terminal (${Vt}+\`)`,icon:Ss,pressed:e.terminal,attention:t,badge:n>0&&(0,W.jsx)(`span`,{className:B(`absolute top-0 right-0 grid h-3 min-w-3 place-items-center rounded-full px-0.5 text-[8px] leading-none font-medium tabular-nums`,t?`bg-primary text-primary-foreground`:`text-foreground bg-[color-mix(in_srgb,var(--foreground)_22%,var(--background))]`),children:n}),detail:n>0&&(0,W.jsx)(`span`,{className:B(`text-xs tabular-nums`,t?`text-primary`:`text-muted-foreground`),children:n}),onSelect:()=>e.onTerminal(!e.terminal)},{id:`tasks`,label:`Tasks`,title:`Tasks`,icon:Ts,pressed:e.panel===`tasks`,attention:r>0,badge:r>0&&(0,W.jsx)(`span`,{className:`text-foreground absolute top-0 right-0 grid h-3 min-w-3 place-items-center rounded-full bg-[color-mix(in_srgb,var(--foreground)_22%,var(--background))] px-0.5 text-[8px] leading-none font-medium tabular-nums`,children:r}),detail:r>0&&(0,W.jsx)(`span`,{className:`text-muted-foreground text-xs tabular-nums`,children:r}),onSelect:()=>e.onPanel(e.panel===`tasks`?null:`tasks`)},{id:`browser`,label:`Browser`,title:`Browser`,icon:vo,pressed:e.panel===`browser`,attention:!1,badge:null,detail:null,onSelect:()=>e.onPanel(e.panel===`browser`?null:`browser`)},{id:`editor`,label:`Editor`,title:`Editor`,icon:js,pressed:!1,attention:!1,badge:null,detail:null,onSelect:()=>Et({machine:e.selection.machine,projectId:e.selection.projectId})}]}function VL(e){return(0,W.jsxs)(W.Fragment,{children:[e.panel===`browser`&&(0,W.jsx)(TL,{machine:e.selection.machine,onClose:()=>e.onPanel(null)}),e.panel===`diff`&&(0,W.jsx)(U.Suspense,{children:(0,W.jsx)(IL,{machine:e.selection.machine,projectId:e.selection.projectId,running:e.running,onClose:()=>e.onPanel(null)},`${e.selection.machine} ${e.selection.projectId}`)}),e.panel===`tasks`&&(0,W.jsx)(NL,{machine:e.selection.machine,cwd:e.cwd,sessionId:e.selection.sessionId,selected:e.selectedTask,onSelect:e.onSelectTask,onClose:()=>e.onPanel(null)})]})}function HL(){let e=k(e=>e.selection),t=k(e=>e.machines.length>0),n=h();return n===null?e===null?t?(0,W.jsx)(`div`,{className:`bg-sidebar relative flex min-w-0 flex-1 pt-[env(safe-area-inset-top)] pb-[env(safe-area-inset-bottom)]`,children:(0,W.jsx)(uI,{className:`min-w-0 flex-1 border-r-0`,mobile:!0})}):(0,W.jsx)(`main`,{className:`bg-background flex flex-1 overflow-y-auto pt-[env(safe-area-inset-top)] pb-[env(safe-area-inset-bottom)]`,children:(0,W.jsx)(eO,{})}):(0,W.jsx)(UL,{selection:e}):(0,W.jsx)(eI,{machine:n,mobile:!0,leading:(0,W.jsx)(H,{variant:`ghost`,size:`icon-xs`,className:`h-full w-11 rounded-none`,"aria-label":`Back`,title:`Back`,onClick:()=>l(`chat`,()=>void nt.navigate({to:`/`,search:{},replace:!0})),children:(0,W.jsx)(V,{icon:po})})})}function UL(e){let t=k(t=>L(t,e.selection.machine)),n=k(t=>t.sessions.find(t=>t.machine===e.selection.machine&&t.id===e.selection.sessionId)),r=k(e=>n!==void 0&&e.generatingTitles.includes(P(n.machine,n.id))),i=k(t=>Ct(t,e.selection.machine,e.selection.projectId)?.path??``),a=Ns(e.selection.machine,e.selection.projectId),o=k(Ot),s=k(t=>e.selection.projectId===`no-project`||Ct(t,e.selection.machine,e.selection.projectId)?.scratch===!0),c=cp(e.selection.machine,t.status===`online`&&!s?e.selection.projectId:null,o),u=lp({machine:e.selection.machine,projectId:e.selection.projectId,repos:c.repos,onRefresh:c.refresh}),d=(0,U.useSyncExternalStore)(CP,()=>wP().open),f=Fe({from:`__root__`,select:e=>e.panel??null}),[m,h]=(0,U.useState)(null),g=c.repos.some(e=>e.changed>0),_=!s&&(f!==null||d),v=(0,U.useCallback)(e=>{_?M(e):p(e,`overlay`)},[_]),y=(0,U.useCallback)(e=>{h(null),e===null?WL():v({panel:e,bottom:void 0})},[v]),b=(0,U.useCallback)(e=>{y(`tasks`),h(e)},[y]);function x(e){e?v({panel:void 0,bottom:`terminal`}):WL()}return(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:`flex h-(--workspace-topbar-height) shrink-0 items-center gap-1.5 px-2`,children:[(0,W.jsx)(H,{variant:`ghost`,size:`icon`,"aria-label":`Back`,onClick:()=>l(`chat`,pt),children:(0,W.jsx)(V,{icon:po,className:`text-foreground size-5`,strokeWidth:2})}),(0,W.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,W.jsx)(`div`,{className:`text-foreground truncate font-medium`,children:(0,W.jsx)(`span`,{className:B((r||e.selection.sessionId!==null&&n===void 0)&&`text-shimmer`),children:n?.title??`New thread`})}),t.status===`online`&&(0,W.jsxs)(`div`,{className:`text-muted-foreground flex items-center gap-1 text-xs`,children:[(0,W.jsx)(jd,{icon:t.icon,className:`size-3.5 shrink-0`}),(0,W.jsxs)(`span`,{className:`truncate`,children:[t.name,` / `,a]})]}),t.status!==`online`&&(0,W.jsxs)(`div`,{className:`text-warning-foreground truncate text-xs`,children:[t.status===`connecting`&&`Connecting to ${t.name}…`,t.status===`offline`&&`${t.name} is offline, reconnecting…`,t.status===`unpaired`&&`${t.name} needs pairing`]})]}),(0,W.jsx)(Mf,{}),!s&&(0,W.jsx)(zL,{selection:e.selection,mobile:!0,session:n,panel:f,terminal:d,changed:g,open:u.menuOpen,onOpenChange:u.setMenuOpen,onPanel:y,onTerminal:x,children:c.repos.length>0&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(On,{}),(0,W.jsx)(up,{git:u,collapsed:!0})]})}),(0,W.jsx)(dp,{git:u})]}),(0,W.jsx)(`div`,{className:`relative flex min-h-0 min-w-0 flex-1 flex-col`,children:(0,W.jsxs)(U.Fragment,{children:[(0,W.jsx)(bL,{onOpenTask:b}),(0,W.jsx)(Df,{})]},`${e.selection.machine} ${e.selection.sessionId??e.selection.projectId}`)}),(0,W.jsx)($r,{open:_,onOpenChange:()=>y(null),children:(0,W.jsx)(ri,{children:(0,W.jsxs)(Yr,{"aria-describedby":void 0,className:`bg-background data-open:animate-in data-open:slide-in-from-right fixed inset-0 z-40 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)(ai,{className:`sr-only`,children:[f===`diff`&&`Diff`,f===`tasks`&&`Tasks`,f===`browser`&&`Browser`,f===null&&`Terminal`]}),(0,W.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[f!==null&&(0,W.jsx)(VL,{panel:f,selection:e.selection,cwd:i,running:o,selectedTask:m,onSelectTask:h,onPanel:y}),f===null&&d&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(`div`,{className:`border-border/60 flex h-(--workspace-topbar-height) shrink-0 items-center gap-1 border-b px-3`,children:[(0,W.jsx)(H,{size:`icon-sm`,variant:`ghost`,title:`Close`,"aria-label":`Close`,onClick:()=>x(!1),children:(0,W.jsx)(V,{icon:_t,className:`size-4`})}),(0,W.jsx)(`span`,{className:`text-foreground min-w-0 truncate text-xs font-medium`,children:`Terminal`})]}),(0,W.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,W.jsx)(YF,{view:e.selection.projectId})})]})]})]})})})]})}function WL(){l(`overlay`,()=>M({panel:void 0,bottom:void 0}))}var GL=(0,U.lazy)(async()=>({default:(await ci(async()=>{let{EditorDialog:e}=await import(`./editor-dialog-DYSeKCLc.js`);return{EditorDialog:e}},__vite__mapDeps([18,1,19,3,6,7,20,8,4,21,22,11,12,23,5,9,10,13,14,15,16,17,24,25,26,27,28]))).EditorDialog})),KL=window.matchMedia(`(min-width: 768px)`),qL=800,JL=[`mod+k`,`mod+shift+p`];function YL(e){return KL.addEventListener(`change`,e),()=>KL.removeEventListener(`change`,e)}function XL(){let e=(0,U.useSyncExternalStore)(YL,()=>KL.matches),t=k(e=>e.editor),n=k(e=>e.exporting);return Ua(),or(JL,()=>u(!R().paletteOpen),{enableOnFormTags:!0,preventDefault:!0}),(0,W.jsxs)(`div`,{className:`flex h-dvh text-sm`,children:[e?(0,W.jsx)(QL,{}):(0,W.jsx)(HL,{}),(0,W.jsx)(lk,{}),e?(0,W.jsx)(JD,{}):(0,W.jsx)($D,{}),t!==null&&(0,W.jsx)(U.Suspense,{children:(0,W.jsx)(GL,{machine:t.machine,projectId:t.projectId,onClose:()=>Et(null)})}),n!==null&&(0,W.jsx)(iO,{session:n}),(0,W.jsx)(Gf,{}),(0,W.jsx)(fu,{position:e?`bottom-right`:`top-center`,swipeDirections:e?[`right`,`bottom`]:[`left`,`right`,`top`]})]})}function ZL(e){M({panel:e??void 0})}function QL(){let e=k(e=>e.selection),t=k(e=>e.sessions),n=h(),r=k(e=>e.selection===null?``:Ct(e,e.selection.machine,e.selection.projectId)?.path??``),i=k(e=>{let t=ot(e);return t===null?null:L(e,t)}),[a,o]=(0,U.useState)(!0),s=(0,U.useRef)(null),[c,l]=(0,U.useState)(!1),u=Fe({from:`__root__`,select:e=>e.panel??null}),d=(0,U.useRef)(`diff`),[f,p]=(0,U.useState)(null),m=(0,U.useCallback)(e=>{p(e),ZL(`tasks`)},[]),[g,_]=Nr(`panelWidth`,540),[v,y]=(0,U.useState)(280),b=(0,U.useSyncExternalStore)(CP,()=>wP().open),x=k(Ot),S=k(e=>e.selection?.projectId===`no-project`||e.selection!==null&&Ct(e,e.selection.machine,e.selection.projectId)?.scratch===!0),C=cp(e?.machine??``,i?.status===`online`&&!S?e?.projectId??null:null,x),w=lp({machine:e?.machine??``,projectId:e?.projectId??``,repos:C.repos,onRefresh:C.refresh}),T=t.find(t=>t.machine===e?.machine&&t.id===e.sessionId),E=k(e=>T!==void 0&&e.generatingTitles.includes(P(T.machine,T.id))),D=Ns(e?.machine??``,e?.projectId??``);return or([`meta+backquote`,`ctrl+backquote`],e=>{e.stopPropagation(),MP(!wP().open)},{enableOnFormTags:!0,preventDefault:!0,eventListenerOptions:{capture:!0}}),or([`mod+j`,`mod+shift+b`],e=>{e.stopPropagation(),ZL(se().panel===void 0?d.current:null)},{enableOnFormTags:!0,preventDefault:!0,eventListenerOptions:{capture:!0}}),(0,U.useEffect)(()=>{u!==null&&(d.current=u)},[u]),or([`mod+b`,`mod+shift+j`],()=>o(e=>!e),{enableOnFormTags:!0,preventDefault:!0}),(0,U.useEffect)(()=>{if(n!==null)return;let e=s.current;if(e===null)throw Error(`header is not mounted`);let t=new ResizeObserver(e=>l(e[0].contentRect.width<qL));return t.observe(e),()=>t.disconnect()},[n]),n===null?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(uI,{className:B(`relative`,!a&&`hidden`),mobile:!1,onHide:()=>o(!1)}),!a&&(0,W.jsx)(`div`,{className:`fixed top-0 left-3 z-50 flex h-(--workspace-topbar-height) items-center`,children:(0,W.jsx)(H,{variant:`ghost`,size:`icon-sm`,"aria-label":`Show sidebar`,title:`Show sidebar (${Vt}+B)`,onClick:()=>o(!0),children:(0,W.jsx)(V,{icon:Bn})})}),(0,W.jsxs)(`main`,{className:`bg-background relative flex min-w-0 flex-1 flex-col overflow-hidden`,children:[(0,W.jsxs)(`header`,{ref:s,className:B(`bg-background flex h-(--workspace-topbar-height) shrink-0 items-center gap-3 pr-3 pl-[3.25rem]`,a&&`pl-5`),children:[e!==null&&i!==null&&(0,W.jsx)(`nav`,{className:`min-w-0 flex-1`,children:(0,W.jsxs)(`ol`,{className:`flex min-w-0 items-center gap-3 text-sm`,children:[(0,W.jsxs)(`li`,{className:`text-icon-muted flex shrink-0 items-center gap-1.5`,children:[(0,W.jsx)(jd,{icon:i.icon,className:`size-3.5 shrink-0`}),(0,W.jsx)(`span`,{className:`max-w-40 truncate`,children:i.name})]}),(0,W.jsx)(`li`,{"aria-hidden":!0,className:`text-icon-muted shrink-0`,children:`/`}),(0,W.jsxs)(`li`,{className:`text-muted-foreground flex min-w-0 shrink items-center gap-1.5 font-medium`,title:`${i.name}:${r}`,children:[(0,W.jsx)(zs,{machine:e.machine,projectId:e.projectId,className:`size-3.5`}),(0,W.jsx)(`span`,{className:`max-w-40 truncate`,children:D})]}),(0,W.jsx)(`li`,{"aria-hidden":!0,className:`text-icon-muted shrink-0`,children:`/`}),(0,W.jsxs)(`li`,{className:B(`text-foreground flex min-w-10 items-center gap-2 font-medium`,a&&`flex-1`),children:[(0,W.jsx)(`span`,{className:B(`truncate`,(E||e.sessionId!==null&&T===void 0)&&`text-shimmer`),children:T?.title??`New thread`}),(0,W.jsx)(Mf,{})]}),!a&&(0,W.jsx)(`li`,{className:`shrink-0`,children:(0,W.jsx)(_F,{hideDone:!0})})]})}),e===null&&!a&&(0,W.jsx)(_F,{hideDone:!0}),e===null&&(0,W.jsx)(`span`,{className:`flex-1`}),i!==null&&i.status!==`online`&&(0,W.jsxs)(`span`,{className:`text-warning-foreground shrink-0 text-xs`,children:[i.status===`connecting`&&`Connecting to ${i.name}…`,i.status===`offline`&&`${i.name} is offline, reconnecting…`,i.status===`unpaired`&&`${i.name} needs pairing`]}),e!==null&&!S&&(0,W.jsxs)(`div`,{className:`ml-auto flex shrink-0 items-center gap-1`,children:[!c&&C.repos.length>0&&(0,W.jsx)(fp,{machine:e.machine,projectId:e.projectId,repos:C.repos,onRefresh:C.refresh}),!c&&C.repos.length>0&&(0,W.jsx)(`span`,{className:`bg-foreground/15 mr-1 ml-2.5 h-4 w-px`}),(0,W.jsx)(RL,{selection:e,panel:u,terminal:b,changed:C.repos.some(e=>e.changed>0),onPanel:e=>{p(null),ZL(e)},onTerminal:MP,children:(0,W.jsx)(zL,{selection:e,mobile:!1,session:T,panel:u,terminal:b,changed:C.repos.some(e=>e.changed>0),open:w.menuOpen,onOpenChange:w.setMenuOpen,onPanel:e=>{p(null),ZL(e)},onTerminal:MP,children:c&&C.repos.length>0&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(On,{}),(0,W.jsx)(up,{git:w,collapsed:!0})]})})})]})]}),(0,W.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[(0,W.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col overflow-x-hidden`,children:[(0,W.jsxs)(`div`,{className:`relative flex min-h-0 min-w-0 flex-1 flex-col`,children:[i===null&&(0,W.jsx)(eO,{}),e===null&&i!==null&&(0,W.jsx)(`div`,{className:`grid flex-1 place-items-center p-6 text-center`,children:(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`h1`,{className:`text-foreground text-3xl font-normal tracking-tight`,children:`Pick a thread, or start one`}),(0,W.jsx)(`p`,{className:`text-muted-foreground mt-2 text-sm`,children:`Open a project from the sidebar to talk to Claude.`})]})}),e!==null&&(0,W.jsxs)(U.Fragment,{children:[(0,W.jsx)(bL,{onOpenTask:m}),(0,W.jsx)(Df,{})]},`${e.machine} ${e.sessionId??e.projectId}`)]}),e!==null&&b&&!S&&(0,W.jsxs)(`aside`,{className:`border-border/80 bg-background relative shrink-0 overflow-hidden border-t`,style:{height:v},children:[(0,W.jsx)(`div`,{role:`separator`,"aria-orientation":`horizontal`,className:`group absolute inset-x-0 top-0 z-30 h-1.5 cursor-row-resize touch-none select-none`,onPointerDown:e=>Bt(e,e=>{let t=Math.max(120,Math.floor(window.innerHeight*.8));y(Math.min(t,Math.max(120,window.innerHeight-e.clientY)))}),children:(0,W.jsx)(`span`,{className:`group-hover:bg-border group-active:bg-primary/60 pointer-events-none absolute inset-x-0 top-0 h-px transition-colors`})}),(0,W.jsx)(YF,{view:e.projectId})]})]}),e!==null&&u!==null&&!S&&(0,W.jsxs)(`div`,{className:`relative flex shrink-0`,style:{width:g},children:[(0,W.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,className:`group absolute inset-y-0 -left-1 z-20 w-2 cursor-col-resize select-none`,onPointerDown:e=>Bt(e,e=>{let t=Math.max(360,Math.floor(window.innerWidth*.7)),n=Math.min(t,Math.max(360,window.innerWidth-e.clientX));_(n)}),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`})}),(0,W.jsx)(`div`,{className:`bg-background flex min-w-0 flex-1 flex-col overflow-hidden rounded-tl-lg border-t border-l`,children:(0,W.jsx)(VL,{panel:u,selection:e,cwd:r,running:x,selectedTask:f,onSelectTask:p,onPanel:ZL})})]})]})]}),(0,W.jsx)(dp,{git:w})]}):(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(uI,{className:B(`relative`,!a&&`hidden`),mobile:!1,onHide:()=>o(!1)}),(0,W.jsx)(eI,{machine:n,mobile:!1,leading:!a&&(0,W.jsx)(H,{variant:`ghost`,size:`icon-xs`,"aria-label":`Show sidebar`,title:`Show sidebar (${Vt}+B)`,onClick:()=>o(!0),children:(0,W.jsx)(V,{icon:Bn})})})]})}var $L=class extends U.Component{state={error:null};static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e,t){console.error(e,t.componentStack)}render(){let e=this.state.error;return e===null?this.props.children:(0,W.jsxs)(`div`,{className:`flex h-dvh flex-col items-center justify-center gap-3 p-4 text-center`,children:[(0,W.jsx)(`p`,{className:`font-medium`,children:`Something went wrong`}),(0,W.jsx)(`p`,{className:`text-muted-foreground max-w-xl text-sm whitespace-pre-wrap`,children:e.message}),(0,W.jsx)(H,{onClick:()=>location.reload(),children:`Reload`})]})}},eR=[`typescript`,`tsx`,`javascript`],tR=`import { readFile } from 'node:fs/promises'
|