@fungi.computer/inkcap 0.18.3 → 0.18.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{$ as t,$a as n,$i as r,A as i,Aa as a,B as o,Ba as s,Bi as c,Bn as l,Bt as u,C as d,Cn as f,D as p,Dn as m,E as h,En as g,F as _,Fa as v,G as y,Ga as b,Gi as x,Gr as S,Gt as C,H as w,Ha as T,Hi as E,Hr as D,Ht as O,I as k,Ia as A,J as j,Ji as M,Jr as N,K as P,Ka as F,Ki as I,Kr as L,L as R,La as ee,Li as te,Ln as ne,Lr as re,M as ie,N as ae,Nn as oe,O as se,P as z,Pa as ce,Q as le,Qa as ue,Qi as de,Qr as fe,Ra as pe,Ri as me,Rt as he,S as ge,Sa as _e,Sn as ve,St as ye,T as be,Tn as xe,U as Se,Ua as Ce,Ui as we,Ur as Te,Ut as B,V as Ee,Va as De,Vi as Oe,Vt as ke,W as Ae,Wa as je,Wi as Me,Wr as Ne,X as Pe,Xa as V,Xi as Fe,Y as Ie,Yr as Le,Za as Re,Zi as ze,Zt as Be,_n as Ve,_r as He,a as Ue,aa as We,ai as Ge,b as Ke,bt as qe,c as Je,ca as H,ci as Ye,cn as Xe,ct as Ze,d as Qe,di as $e,dr as U,ea as et,eo as tt,et as nt,fa as rt,fi as it,g as at,gr as ot,h as st,ha as ct,hr as lt,i as ut,ia as dt,ii as ft,in as pt,j as mt,jn as ht,k as gt,kn as _t,la as vt,li as yt,lr as bt,m as xt,mi as St,mr as Ct,n as wt,ni as Tt,nn as W,nt as Et,oi as Dt,on as Ot,p as kt,pa as At,pi as jt,pn as Mt,q as Nt,qa as Pt,qi as Ft,qt as It,ri as Lt,rt as Rt,s as zt,sa as Bt,si as Vt,st as Ht,tn as Ut,to as Wt,tt as Gt,u as Kt,ua as qt,ui as Jt,ur as G,ut as Yt,v as Xt,va as K,wn as Zt,x as Qt,y as $t,yr as en,yt as tn,z as nn,za as rn,zi as an,zn as on}from"./tree-path-DQAnGoeW.js";import{C as sn,D as cn,Ft as ln,O as un,Rt as dn,_ as fn,a as pn,b as q,c as mn,f as hn,g as gn,h as _n,i as vn,l as yn,m as bn,n as xn,o as Sn,p as Cn,r as wn,s as Tn,t as En,u as Dn,v as On,w as kn,x as An,y as jn}from"./changes-patch-DeYy-1aU.js";import{a as Mn,c as Nn,d as Pn,f as Fn,i as In,l as Ln,n as Rn,o as zn,p as Bn,r as Vn,s as Hn,t as Un,u as Wn}from"./useForm-CkS3eP5p.js";import{n as Gn,r as Kn,t as qn}from"./useFileTree-D7u_RYsd.js";var Jn=M(`ZodMiniType`,(e,t)=>{if(!e._zod)throw Error(`Uninitialized schema in ZodMiniType.`);c.init(e,t),e.def=t,e.type=t.type,e.parse=(t,n)=>Oe(e,t,n,{callee:e.parse}),e.safeParse=(t,n)=>we(e,t,n),e.parseAsync=async(t,n)=>E(e,t,n,{callee:e.parseAsync}),e.safeParseAsync=async(t,n)=>Me(e,t,n),e.check=(...n)=>e.clone({...t,checks:[...t.checks??[],...n.map(e=>typeof e==`function`?{_zod:{check:e,def:{check:`custom`},onattach:[]}}:e)]},{parent:!0}),e.with=e.check,e.clone=(t,n)=>x(e,t,n),e.brand=()=>e,e.register=((t,n)=>(t.add(e,n),e)),e.apply=t=>t(e)}),Yn=M(`ZodMiniObject`,(e,t)=>{an.init(e,t),Jn.init(e,t),I(e,`shape`,()=>t.shape)});function Xn(e,t){return new Yn({type:`object`,shape:e??{},...Ft(t)})}var Zn=M(`ZodMiniLiteral`,(e,t)=>{me.init(e,t),Jn.init(e,t)});function Qn(e,t){return new Zn({type:`literal`,values:Array.isArray(e)?e:[e],...Ft(t)})}var $n=G(`Check`,[[`path`,{d:`M20 6 9 17l-5-5`,key:`1gmf2c`}]]),er=G(`ChevronRight`,[[`path`,{d:`m9 18 6-6-6-6`,key:`mthhwq`}]]),tr=G(`EyeOff`,[[`path`,{d:`M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49`,key:`ct8e1f`}],[`path`,{d:`M14.084 14.158a3 3 0 0 1-4.242-4.242`,key:`151rxh`}],[`path`,{d:`M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143`,key:`13bj9a`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}]]),nr=G(`Eye`,[[`path`,{d:`M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0`,key:`1nclc0`}],[`circle`,{cx:`12`,cy:`12`,r:`3`,key:`1v7zrd`}]]),rr=G(`FileImage`,[[`path`,{d:`M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z`,key:`1rqfz7`}],[`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`,key:`tnqrlb`}],[`circle`,{cx:`10`,cy:`12`,r:`2`,key:`737tya`}],[`path`,{d:`m20 17-1.296-1.296a2.41 2.41 0 0 0-3.408 0L9 22`,key:`wt3hpn`}]]),ir=G(`FolderPlus`,[[`path`,{d:`M12 10v6`,key:`1bos4e`}],[`path`,{d:`M9 13h6`,key:`1uhe8q`}],[`path`,{d:`M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z`,key:`1kt360`}]]),ar=G(`RotateCcw`,[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}]]),J=e(ze(),1);function or(e){let{open:t,defaultOpen:n=!1,onOpenChange:r,disabled:i}=e,[a,o]=Xe({controlled:t,default:n,name:`Collapsible`,state:`open`}),{mounted:s,setMounted:c,transitionStatus:l}=O(a,!0,!0),u=It(),[d,p]=J.useState(),m=d===null?void 0:d??u,h=W(e=>{let t=!a,n=C(f,e.nativeEvent);r(t,n),!n.isCanceled&&o(t)});return J.useMemo(()=>({defaultPanelId:u,disabled:i,handleTrigger:h,mounted:s,open:a,panelId:m,setMounted:c,setOpen:o,setPanelIdState:p,transitionStatus:l}),[u,i,h,s,a,m,c,o,p,l])}var sr=J.createContext(void 0);function cr(){let e=J.useContext(sr);if(e===void 0)throw Error(on(15));return e}var lr=`data-open`,ur=`data-closed`,dr=_t,fr=`data-panel-open`,pr={[lr]:``},mr={[ur]:``},hr={open(e){return e?{[fr]:``}:null}},gr={open(e){return e?pr:mr},...m},Y=Fe(),_r=J.forwardRef(function(e,t){let{render:n,className:r,defaultOpen:i=!1,disabled:a=!1,onOpenChange:o,open:s,style:c,...l}=e,u=W(o),d=or({open:s,defaultOpen:i,onOpenChange:u,disabled:a}),f=J.useMemo(()=>({open:d.open,disabled:d.disabled,transitionStatus:d.transitionStatus}),[d.open,d.disabled,d.transitionStatus]),p=J.useMemo(()=>({...d,onOpenChange:u,state:f}),[d,u,f]),m=ht(`div`,e,{state:f,ref:t,props:l,stateAttributesMapping:gr});return(0,Y.jsx)(sr.Provider,{value:p,children:m})}),vr={...hr,...m},yr=J.forwardRef(function(e,t){let{panelId:n,open:r,handleTrigger:i,state:a,disabled:o}=cr(),{className:s,disabled:c=o,render:l,nativeButton:u=!0,style:d,...f}=e,{getButtonProps:p,buttonRef:m}=Be({disabled:c,native:u});return ht(`button`,e,{state:a,ref:[t,m],props:[{"aria-controls":r?n:void 0,"aria-expanded":r,onClick:i},f,p],stateAttributesMapping:vr})}),X={height:void 0,width:void 0};function br(e){let{externalRef:t,hiddenUntilFound:n,id:r,keepMounted:i,mounted:a,onOpenChange:o,open:s,setMounted:c,setOpen:l,transitionStatus:d}=e,f=J.useRef(null),p=J.useRef(null),[m,h]=J.useState(X),g=J.useRef(X),_=J.useRef(!1),v=J.useRef(s),y=J.useRef(!1),[b,x]=J.useState(!1),S=J.useRef(null),w=ne(t,f),T=qe(s),E=ke(f),D=!s&&!a,O=b?`idle`:d,k=s&&(v.current||y.current),A=!s&&a&&p.current===`css-animation`&&m.height===void 0&&m.width===void 0?g.current:m,j=n&&D&&p.current!==`css-animation`,M=W((e,t=!0)=>{t&&(g.current=e),h(e)}),N=W(()=>{S.current?.(),S.current=null}),P=W(e=>{N(),S.current=()=>{S.current=null,e()}}),F=W(()=>{s&&a&&p.current===`css-animation`&&(y.current=!0)});Ut(()=>{!b||d===`starting`||x(!1)},[b,d]),J.useEffect(()=>()=>{F(),N()},[F,N]),Ut(()=>{s||(v.current=!1,y.current=!1);let e=f.current;if(!e)return;!s&&S.current&&N();let t=xr(e,k);if(p.current=t,s&&d===`idle`&&v.current&&t===`css-animation`){g.current=Z(e);return}if(s&&d===`starting`){let n=_.current;if(_.current=!1,t===`none`){M(Z(e)),x(!0);return}if(t===`css-transition`){let t=wr(e);if(M(Z(e)),!n)return t;let r=Cr(e,`transition-duration`,`0s`);return P(r),x(!0),t}M(Z(e));let r=Cr(e,`animation-name`,`none`);if(!n){r();return}let i=Cr(e,`animation-duration`,`0s`);r(),P(i),x(!0);return}if(!s&&a&&(d===`idle`||d===`starting`)){if(t===`none`){M(X,!1),c(!1);return}M(Z(e));return}if(d!==`ending`)return;if(t===`none`){c(!1);return}let n=Z(e);if(!(n.height>0||n.width>0)){c(!1);return}M(n),t===`css-animation`&&Cr(e,`animation-name`,`none`)()},[a,s,N,M,c,P,k,d]),u({enabled:s&&a&&O===`idle`,open:!0,ref:f,onComplete(){s&&M(X,!1)}}),J.useEffect(()=>{if(s||!a||O!==`ending`)return;if(!f.current){c(!1),M(X,!1);return}let e=new AbortController,t=-1;function n(){T.current||(c(!1),M(X,!1))}return t=B.request(()=>{E(n,e.signal)}),()=>{B.cancel(t),e.abort()}},[T,a,s,O,E,M,c]),Ut(()=>{let e=f.current;!e||!n||!D||e.setAttribute(`hidden`,`until-found`)},[D,n]),J.useEffect(function(){let e=f.current;if(!e)return;let t=he.create(),n=-1,r=(r,i)=>{t.start(0,()=>{T.current||(n=B.request(()=>{T.current||(r&&(_.current=!1),i&&e.setAttribute(dr,``),e.setAttribute(`hidden`,`until-found`))}))})},i=ye(e,`beforematch`,t=>{let n=C(Ve,t);if(o(!0,n),n.isCanceled){r(!1,!1);return}_.current=!0;let i=e.hasAttribute(dr);e.removeAttribute(dr),l(!0),r(!0,i)});return()=>{t.clear(),B.cancel(n),i()}},[T,o,l]);let I=i||n||a||s;return{height:A.height,props:{...j?{[dr]:``}:void 0,hidden:D,id:r},ref:w,shouldPreventOpenAnimation:k,shouldRender:I,transitionStatus:O,width:A.width}}function Z(e){return{height:e.scrollHeight,width:e.scrollWidth}}function xr(e,t){let n=pt(e).getComputedStyle(e),r=(n.animationName.split(`,`).map(e=>e.trim()).some(e=>e!==``&&e!==`none`)||t)&&Sr(n.animationDuration),i=Sr(n.transitionDuration);return r&&i||i?`css-transition`:r?`css-animation`:`none`}function Sr(e){return e.split(`,`).map(e=>e.trim()).some(e=>e!==``&&Number.parseFloat(e)>0)}function Cr(e,t,n){let r=e.style.getPropertyValue(t),i=e.style.getPropertyPriority(t);return e.style.setProperty(t,n),()=>{if(r===``){e.style.removeProperty(t);return}e.style.setProperty(t,r,i)}}function wr(e){let t={"justify-content":e.style.justifyContent,"align-items":e.style.alignItems,"align-content":e.style.alignContent,"justify-items":e.style.justifyItems};Object.keys(t).forEach(t=>{e.style.setProperty(t,`initial`,`important`)});function n(){Object.entries(t).forEach(([t,n])=>{if(n===``){e.style.removeProperty(t);return}e.style.setProperty(t,n)})}let r=B.request(n);return()=>{B.cancel(r),n()}}var Tr=`--collapsible-panel-height`,Er=`--collapsible-panel-width`,Dr=J.forwardRef(function(e,t){let{className:n,hiddenUntilFound:r,keepMounted:i,render:a,id:o,style:s,...c}=e,{defaultPanelId:l,mounted:u,onOpenChange:d,open:f,setMounted:p,setPanelIdState:m,setOpen:h,state:g,transitionStatus:_}=cr(),v=r??!1,y=i??!1,b=o||void 0,x=b??l;Ut(()=>(m(e=>b??(e===null?void 0:e)),()=>{m(e=>e===b?null:e)}),[b,m]);let{height:S,props:C,ref:w,shouldPreventOpenAnimation:T,shouldRender:E,transitionStatus:D,width:O}=br({externalRef:t,hiddenUntilFound:v,id:x,keepMounted:y,mounted:u,onOpenChange:d,open:f,setMounted:p,setOpen:h,transitionStatus:_}),k={...g,transitionStatus:D},A=oe(s,k),j=ht(`div`,{...e,style:void 0},{state:k,ref:w,props:[C,{style:{[Tr]:S===void 0?`auto`:`${S}px`,[Er]:O===void 0?`auto`:`${O}px`}},c,A?{style:A}:void 0,T?{style:{animationName:`none`}}:void 0],stateAttributesMapping:gr});return E?j:null}),Or=N(`caps-disclosure`,{variants:{tone:{neutral:``,error:`caps-disclosure-error`},size:{group:`caps-disclosure-group`,row:`caps-disclosure-row`}},defaultVariants:{tone:`neutral`,size:`group`}});function kr({open:e,onOpenChange:t,summary:n,leading:r,trailing:i,children:a,tone:o,size:s,className:c}){return(0,Y.jsxs)(_r,{className:L(Or({tone:o,size:s}),c),onOpenChange:t,open:e,children:[(0,Y.jsxs)(yr,{className:`caps-disclosure-trigger`,children:[r===void 0?null:(0,Y.jsx)(`span`,{className:`caps-disclosure-leading`,children:r}),(0,Y.jsx)(`span`,{className:`caps-disclosure-summary`,children:n}),i===void 0?null:(0,Y.jsx)(`span`,{className:`caps-disclosure-trailing`,children:i}),(0,Y.jsx)(er,{"aria-hidden":`true`,className:`caps-disclosure-chevron`,size:12})]}),(0,Y.jsx)(Dr,{className:`caps-disclosure-panel`,children:a})]})}function Ar({app:e,rootPath:t,rootLabel:n=`Computer`,activePath:r,onOpenFile:i,onSelectPath:a,rowHeight:o=32}){let{scope:s,snapshot:c,focusedPath:l,requestPage:u,reload:d}=gn({app:e,rootPath:t,activePath:r}),f=(0,J.useRef)({activePath:r,onOpenFile:i,onSelectPath:a,rootLabel:n});f.current={activePath:r,onOpenFile:i,onSelectPath:a,rootLabel:n};let p=(0,J.useRef)(u);p.current=u;let{model:m}=qn({paths:[],itemHeight:o,initialExpansion:2,flattenEmptyDirectories:!1,composition:{contextMenu:{enabled:!0}},renderRowDecoration:({row:e})=>e.path===`/`?{text:f.current.rootLabel}:null,unsafeCSS:`[data-item-section="content"] { display: flex; align-items: center; }[data-item-path="/"] [data-item-section="decoration"] { justify-content: flex-start; color: inherit; }`,onSelectionChange(e){let t=e[0];t&&(f.current.onSelectPath?.(t),t.endsWith(`/`)?p.current(t,0):t!==f.current.activePath&&f.current.onOpenFile(t))}}),h=(0,J.useRef)(Dn()),g=(0,J.useRef)(null);(0,J.useLayoutEffect)(()=>{Cn(m,h.current),g.current=null},[m,s]),(0,J.useLayoutEffect)(()=>{g.current=null;for(let e of m.getSelectedPaths())!e.endsWith(`/`)&&e!==r&&m.getItem(e)?.deselect()},[r,m]),(0,J.useLayoutEffect)(()=>{if(c.listings.length===0&&(g.current=null),_n(m,c.listings,h.current),!r||g.current===r)return;let e=bn(r,t);if(!e.every(e=>h.current.known.has(e)))return;for(let t of e){let e=m.getItem(t);e&&`expand`in e&&e.expand()}let n=m.getItem(r);n&&(g.current=r,n.select(),m.scrollToPath(r,{focus:!1}))},[r,m,t,s,c.listings]),(0,J.useEffect)(()=>{c.failure&&console.error(`Inkcap directory listing failed`,dn(c.failure))},[c.failure]);let _=c.listings.filter(({request:e})=>e.path===l).sort((e,t)=>e.request.offset-t.request.offset).at(-1)?.listing,v={path:_?.path??l,next:_?.nextOffset??null},y=c.listings.some(({request:e,listing:n})=>e.path===t&&e.offset===0&&n.entries.length===0&&n.nextOffset===null),b=d;return{model:m,page:v,error:c.failure?`${fe(c.failure).message} Your open files remain available.`:``,busy:c.busy,rootEmpty:y,reloadRoot:b,noteCreated:e=>{let t=e.split(`/`).filter(Boolean).at(-1)??``;!hn({name:t,type:``})&&!m.getItem(e)&&m.batch([{type:`add`,path:e}]),b()},loadNext:()=>{v.next!==null&&u(v.path,v.next)}}}var jr=K(H),Mr=K(vt({message:H}));function Nr(e){for(let t of e.errors){let e=Re(Wt(n(Mr(t),e=>e.message),()=>jr(t)));if(e!==void 0&&e.length>0)return e}}var Pr={neutral:`progress-neutral`,primary:`progress-primary`,secondary:`progress-secondary`,accent:`progress-accent`,success:`progress-success`,info:`progress-info`,warning:`progress-warning`,error:`progress-error`},Fr=(0,J.forwardRef)(function({className:e,tone:t=`primary`,...n},r){return(0,Y.jsx)(`progress`,{...n,"data-complete":n.value!==void 0&&Number(n.value)>=Number(n.max??1)?`true`:void 0,className:L(`progress caps-gooey-motion caps-gooey-progress w-full`,Pr[t],e),ref:r})});(0,J.forwardRef)(function({label:e,value:t,max:n,tone:r=`info`,className:i,...a},o){return(0,Y.jsxs)(`div`,{...a,ref:o,className:L(`caps-game-meter`,i),children:[(0,Y.jsxs)(`div`,{className:`caps-game-meter-readout`,children:[(0,Y.jsx)(`span`,{children:e}),(0,Y.jsxs)(`span`,{className:`caps-game-meter-value`,children:[t,` / `,n]})]}),(0,Y.jsx)(Fr,{"aria-label":e,value:t,max:n,tone:r})]})});function Ir({className:e,items:t,onCancel:n,onRemove:r,onRetry:i,rowClassName:a}){return t.length?(0,Y.jsx)(`div`,{"aria-live":`polite`,className:`caps-upload-queue flex w-full min-w-0 flex-col gap-sm ${e??``}`,"data-upload-rows":!0,children:t.map(e=>(0,Y.jsx)(zr,{item:e,onCancel:n,onRemove:r,onRetry:i,...a===void 0?{}:{rowClassName:a}},e.id))}):null}function Lr({action:e,id:t,onAction:n,retry:r=!1}){return e?(0,Y.jsx)(l,{"aria-label":e.accessibleLabel,title:e.label,variant:`ghost`,size:`xs`,className:`motion-reduce:transition-none`,icon:r?(0,Y.jsx)(ar,{}):(0,Y.jsx)(bt,{}),onClick:()=>void n(t),type:`button`}):null}function Rr({item:e}){return(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsx)(`span`,{className:`block min-w-0 truncate`,title:e.name,children:e.name}),(0,Y.jsx)(`div`,{className:`caps-upload-details`,children:(0,Y.jsxs)(`span`,{"aria-live":e.alert?`assertive`:void 0,className:`caps-upload-status min-w-0 break-words`,"data-upload-status":!0,role:e.alert?`alert`:void 0,children:[e.alert??e.statusLabel,` `,e.progressLabel]})})]})}function zr({item:e,onCancel:t,onRemove:n,onRetry:r,rowClassName:i}){return(0,Y.jsxs)(`div`,{className:`caps-upload-row grid w-full min-w-0 max-w-full grid-cols-[2rem_minmax(0,1fr)_auto] items-center gap-sm p-sm text-xs ${i??``}`,children:[e.preview.kind===`image`?(0,Y.jsx)(`img`,{alt:``,className:`caps-upload-preview mask mask-squircle size-8 shrink-0 object-cover`,src:e.preview.url}):(0,Y.jsx)(`span`,{"aria-hidden":`true`,className:`caps-upload-preview mask mask-squircle flex size-8 shrink-0 items-center justify-center bg-base-300`,children:(0,Y.jsx)(rr,{className:`size-4`})}),(0,Y.jsx)(Rr,{item:e}),(0,Y.jsx)(Br,{actions:e.actions,id:e.id,onCancel:t,onRemove:n,onRetry:r}),(0,Y.jsx)(Fr,{"aria-label":`${e.name} progress`,className:`caps-upload-progress`,tone:e.alert?`error`:e.progress===100?`success`:`accent`,max:100,value:e.progress??(e.alert?0:void 0)})]})}function Br({actions:e,id:t,onCancel:n,onRemove:r,onRetry:i}){return(0,Y.jsxs)(`div`,{className:`caps-upload-actions flex min-w-0 flex-wrap justify-end gap-xs`,children:[(0,Y.jsx)(Lr,{action:e.retry,id:t,onAction:i,retry:!0}),(0,Y.jsx)(Lr,{action:e.cancel,id:t,onAction:n}),(0,Y.jsx)(Lr,{action:e.remove,id:t,onAction:r})]})}var Vr={unchecked:`M3.25 5.9 L5.1 7.9 L8.8 3.8`,checked:`M3.25 5.9 L5.1 7.9 L8.8 3.8`,mixed:`M3.4 6 L6 6 L8.6 6`},Hr={blurStdDeviation:.22,alphaSlope:18,alphaIntercept:-8};function Ur({state:e}){let t=`caps-checkbox-${(0,J.useId)().replaceAll(`:`,``)}`,n=(0,J.useRef)(null),r=(0,J.useRef)(e).current,i=(0,J.useRef)(e),a=S();return(0,J.useLayoutEffect)(()=>{if(!n.current)return;let t=e!==`unchecked`,r=i.current!==`unchecked`,o=a||i.current===e;i.current=e;let s=Te(n.current),c=q(s,{ease:`inCubic`,duration:160}),l=en(n.current,{d:{to:Vr[e],...o?jn:q(s,{ease:`outCubic`,duration:200})},"stroke-dashoffset":{to:+!t,...o?jn:t?q(s,{ease:`inOutSine`,duration:260}):c},"stroke-width":o?{to:t?2.4:0,duration:0}:t&&!r?[{to:2.2,...q(s,{ease:`outCubic`,duration:65})},{to:2.4,delay:D(s,120),...An(s,{bounce:.35,duration:220})}]:{to:t?2.4:0,...c}});return()=>{l.cancel()}},[e,a]),(0,Y.jsxs)(`svg`,{className:`caps-checkbox-visual`,width:`24`,height:`24`,viewBox:`0 0 12 12`,"aria-hidden":`true`,focusable:`false`,children:[(0,Y.jsxs)(`defs`,{children:[(0,Y.jsx)(He,{id:`${t}-surface`,transform:`matrix(1 0 0 1 6 6)`}),(0,Y.jsx)(ot,{id:`${t}-shadow`}),(0,Y.jsx)(lt,{id:`${t}-inset`}),(0,Y.jsx)(Ct,{id:`${t}-goo`,values:Hr}),(0,Y.jsxs)(`filter`,{id:`${t}-relief`,x:`-25%`,y:`-25%`,width:`150%`,height:`150%`,colorInterpolationFilters:`sRGB`,children:[(0,Y.jsx)(`feGaussianBlur`,{in:`SourceAlpha`,stdDeviation:`0.28`,result:`relief`}),(0,Y.jsx)(`feSpecularLighting`,{in:`relief`,surfaceScale:`1.2`,specularConstant:`0.55`,specularExponent:`18`,lightingColor:`color-mix(in srgb, var(--color-white) calc(var(--depth) * 100%), var(--color-black))`,result:`light`,children:(0,Y.jsx)(`feDistantLight`,{azimuth:`225`,elevation:`55`})}),(0,Y.jsx)(`feComposite`,{in:`light`,in2:`SourceAlpha`,operator:`in`,result:`clipped-light`}),(0,Y.jsx)(`feBlend`,{in:`SourceGraphic`,in2:`clipped-light`,mode:`screen`})]}),(0,Y.jsx)(`mask`,{id:`${t}-contour`,maskUnits:`userSpaceOnUse`,x:`0`,y:`0`,width:`12`,height:`12`,style:{maskType:`alpha`},children:(0,Y.jsx)(`path`,{ref:n,d:Vr[r],fill:`none`,stroke:`var(--color-white)`,strokeWidth:r===`unchecked`?0:2.4,pathLength:`1`,strokeDasharray:`1`,strokeDashoffset:+(r===`unchecked`),strokeLinecap:`round`,strokeLinejoin:`round`,filter:e===`mixed`?void 0:`url(#${t}-goo)`})}),(0,Y.jsx)(`clipPath`,{id:`${t}-well`,children:(0,Y.jsx)(`rect`,{x:`1`,y:`1`,width:`10`,height:`10`,rx:`2.5`})})]}),(0,Y.jsx)(`rect`,{className:`caps-checkbox-track`,x:`0.5`,y:`0.5`,width:`11`,height:`11`,rx:`3`,filter:`url(#${t}-inset)`}),(0,Y.jsx)(`g`,{clipPath:`url(#${t}-well)`,children:(0,Y.jsx)(`g`,{filter:`url(#${t}-shadow)`,children:(0,Y.jsx)(`g`,{filter:`url(#${t}-relief)`,children:(0,Y.jsx)(`g`,{mask:`url(#${t}-contour)`,children:(0,Y.jsx)(`rect`,{x:`0`,y:`0`,width:`12`,height:`12`,fill:`url(#${t}-surface)`})})})})})]})}var Wr=(0,J.forwardRef)(function({className:e,appearance:t,indicator:n,invalid:r,indeterminate:i=!1,checked:a,defaultChecked:o=!1,onChange:s,...c},l){let u=(0,J.useRef)(null),[d,f]=(0,J.useState)(o),p=a??d,m=i?`mixed`:p?`checked`:`unchecked`;return(0,J.useImperativeHandle)(l,()=>{if(!u.current)throw Error(`Checkbox input is not mounted`);return u.current},[]),(0,J.useLayoutEffect)(()=>{u.current&&(u.current.indeterminate=i)},[i]),(0,J.useEffect)(()=>{let e=u.current?.form;if(!e||a!==void 0)return;let t=e=>{queueMicrotask(()=>{!e.defaultPrevented&&u.current&&f(o)})};return e.addEventListener(`reset`,t),()=>{e.removeEventListener(`reset`,t)}},[a,o,c.form]),(0,Y.jsxs)(`span`,{className:`caps-checkbox`,"data-appearance":t===`compact`?t:void 0,"data-state":m,"data-custom-indicator":n!==void 0||void 0,children:[(0,Y.jsx)(`input`,{...c,checked:p,"aria-checked":i?`mixed`:p,"aria-invalid":r?!0:c[`aria-invalid`]===!1?void 0:c[`aria-invalid`],className:L(`caps-checkbox-input`,e),onChange:e=>{a===void 0&&f(e.target.checked),s?.(e),e.currentTarget.indeterminate=i},ref:u,type:`checkbox`}),n===void 0?(0,Y.jsx)(Ur,{state:m}):n]})}),Gr=Xn({keyCode:Qn(229)});function Kr(e){return e.nativeEvent.isComposing||we(Gr,e.nativeEvent).success}var qr=J.createContext(void 0);function Q(e){let t=J.useContext(qr);if(t===void 0&&!e)throw Error(on(47));return t}var Jr=e(Le(),1),Yr={...z,disabled:e=>e.disabled,instantType:e=>e.instantType===`trigger-change`&&!z.open(e)?void 0:e.instantType,openMethod:e=>e.openMethod,openChangeReason:e=>e.openChangeReason,isPressOpenedByTrigger:(e,t)=>e.openChangeReason===`trigger-press`&&z.isOpenedByTrigger(e,t),isTouchPressOpen:(e,t)=>t&&e.openMethod===`touch`&&e.openChangeReason===`trigger-press`,hasTriggerFocusGuards:(e,t)=>z.isOpenedByTrigger(e,t)&&!e.focusManagerModal,modal:e=>e.modal,titleElementId:e=>e.titleElementId,descriptionElementId:e=>e.descriptionElementId,openOnHover:e=>e.openOnHover,closeDelay:e=>e.closeDelay,adaptiveOrigin:e=>e.adaptiveOrigin},Xr=class extends _{constructor(e,t,n){let r=new nn;super(Zr(e,r,t,n),Qr(r),Yr)}setOpen=(e,t)=>{let n=t.reason===ve,r=t.reason===`trigger-press`&&t.event.detail===0,i=!e&&(t.reason===`escape-key`||t.reason==null),a=w(t),o=this.select(`activeTriggerId`);if(!e&&t.reason===`close-press`&&t.trigger==null&&o!=null&&(t.trigger=this.context.triggerElements.getById(o)??this.select(`activeTriggerElement`)??void 0),this.context.onOpenChange?.(e,t),t.isCanceled)return;this.state.floatingRootContext.dispatchOpenChange(e,t);let s=()=>{let n=Ae(this.state,e,t.trigger,a());n.openChangeReason=t.reason,this.update(n)};n?(this.context.stickIfOpen=!0,this.context.stickIfOpenTimeout.start(500,()=>{this.context.stickIfOpen=!1}),Jr.flushSync(s)):s();let c;r?c=`click`:i?c=`dismiss`:t.reason===`focus-out`&&(c=`focus`),this.set(`instantType`,c)}};function Zr(e,t,n,r=!1){let i={...ae(t,n,r),disabled:!1,modal:!1,focusManagerModal:!1,instantType:void 0,openMethod:null,openChangeReason:null,titleElementId:void 0,descriptionElementId:void 0,openOnHover:!1,closeDelay:0,adaptiveOrigin:void 0,...e};return i.open&&e?.mounted===void 0&&(i.mounted=!0),i}function Qr(e){return{popupRef:J.createRef(),onOpenChange:void 0,onOpenChangeComplete:void 0,triggerFocusTargetRef:J.createRef(),beforeTriggerFocusGuardRef:J.createRef(),beforeContentFocusGuardRef:J.createRef(),stickIfOpenTimeout:new he,stickIfOpen:!0,triggerElements:e}}var $r=k(function({props:e}){let{children:t,open:n,defaultOpen:r=!1,onOpenChange:i,onOpenChangeComplete:a,modal:o=!1,handle:s,triggerId:c,defaultTriggerId:l=null}=e,u=ti(s,{modal:o,open:r,openProp:n,activeTriggerId:l,triggerIdProp:c});u.useControlledProp(`openProp`,n),u.useControlledProp(`triggerIdProp`,c);let d=u.useState(`open`),f=u.useState(`mounted`),p=u.useState(`payload`);u.useContextCallback(`onOpenChange`,i),u.useContextCallback(`onOpenChangeComplete`,a),Ie(u,d),y(u);let{forceUnmount:m}=P(d,u,()=>{u.context.stickIfOpen=!0,u.set(`openChangeReason`,null)});u.useSyncedValues({modal:o}),J.useEffect(()=>{d||u.context.stickIfOpenTimeout.clear()},[u,d]),J.useImperativeHandle(e.actionsRef,()=>({unmount:m,close:()=>u.setOpen(!1,C(Mt))}),[m,u]);let h=d||f||s!=null;return(0,Y.jsxs)(qr.Provider,{value:u,children:[s&&(0,Y.jsx)(Ee,{handle:s,store:u}),h&&(0,Y.jsx)(ni,{store:u,modal:o}),typeof t==`function`?t({payload:p}):t]})});function ei(e){return Q(!0)?(0,Y.jsx)($r,{props:e}):(0,Y.jsx)(Et,{children:(0,Y.jsx)($r,{props:e})})}function ti(e,t){let n=j((e,n)=>new Xr(t,e,n));return J.useEffect(()=>n.context.stickIfOpenTimeout.disposeEffect(),[n]),n}function ni({store:e,modal:t}){let n=e.useState(`floatingRootContext`),r=le(n,{outsidePressEvent:{mouse:t===`trap-focus`?`sloppy`:`intentional`,touch:`sloppy`}}),i=r.reference,a=r.floating;return Nt(e,{activeTriggerProps:i,inactiveTriggerProps:i,popupProps:a}),null}var ri=R(function(e,n){let{render:r,className:a,style:o,disabled:s=!1,nativeButton:c=!0,handle:l,payload:u,openOnHover:d=!1,delay:f=300,closeDelay:p=0,id:m,...h}=e,_=Q(!0),v=ie(l)??_;if(!v)throw Error(on(74));let y=It(m),b=v.useState(`isTriggerActive`,y),x=v.useState(`floatingRootContext`),S=v.useState(`isOpenedByTrigger`,y),C=v.useState(`triggerPopupId`,y),w=J.useRef(null),{registerTrigger:T,isMountedByThisTrigger:E}=Pe(y,w,v,{payload:u,disabled:s,openOnHover:d,closeDelay:p}),D=v.useState(`isPressOpenedByTrigger`,y),O=v.useState(`isTouchPressOpen`,d),k=v.useState(`hasTriggerFocusGuards`,y),A=i(x,{enabled:!s&&d&&!O,mouseOnly:!0,move:!1,handleClose:gt(),restMs:f,delay:{close:p},triggerElementRef:w,isActiveTrigger:b,isClosing:()=>v.select(`transitionStatus`)===`ending`}),j=W(()=>v.context.stickIfOpen),M=t(x,{stickIfOpen:j}),N=Xt(()=>v.select(`open`),e=>{v.set(`openMethod`,e)}),P=v.useState(`triggerProps`,E),{getButtonProps:F,buttonRef:I}=Be({disabled:s,native:c}),L={open(e){return D?xe.open(e):g.open(e)}},{handlePreFocusGuardFocus:R,handleFocusTargetFocus:ee}=at(v,w),te=ht(`button`,e,{state:{disabled:s,open:S},ref:[I,n,T,w],props:[M.reference,A,P,N,{[Ze]:``,id:y,"aria-haspopup":`dialog`,"aria-expanded":S,"aria-controls":C},h,F],stateAttributesMapping:L}),ne=(0,Y.jsx)(J.Fragment,{children:te},y);return k?(0,Y.jsxs)(J.Fragment,{children:[(0,Y.jsx)(tn,{ref:v.context.beforeTriggerFocusGuardRef,onFocus:R}),ne,(0,Y.jsx)(tn,{ref:v.context.triggerFocusTargetRef,onFocus:ee})]}):ne}),ii=J.createContext(void 0);function ai(){let e=J.useContext(ii);if(e===void 0)throw Error(on(45));return e}var oi=J.forwardRef(function(e,t){let{keepMounted:n=!1,...r}=e;return Q().useState(`mounted`)||n?(0,Y.jsx)(ii.Provider,{value:n,children:(0,Y.jsx)(Ht,{ref:t,...r})}):null}),si=J.createContext(void 0);function ci(){let e=J.useContext(si);if(!e)throw Error(on(46));return e}var li=J.forwardRef(function(e,t){let{render:n,className:r,style:i,anchor:a,positionMethod:o,side:s,align:c,sideOffset:l,alignOffset:u,collisionBoundary:f=`clipping-ancestors`,collisionPadding:p,arrowPadding:m,sticky:h,disableAnchorTracking:g=!1,collisionAvoidance:_=Yt,...v}=e,y=Q(),b=ai(),x=Rt(),S=y.useState(`floatingRootContext`),C=y.useState(`mounted`),w=y.useState(`open`),T=y.useState(`openChangeReason`),E=y.useState(`activeTriggerElement`),D=y.useState(`modal`),O=y.useState(`openMethod`),k=y.useState(`positionerElement`),A=y.useState(`instantType`),j=y.useState(`transitionStatus`),M=y.useState(`adaptiveOrigin`),N=d({anchor:a,floatingRootContext:S,positionMethod:o,mounted:C,side:s,sideOffset:l,align:c,alignOffset:u,arrowPadding:m,collisionBoundary:f,collisionPadding:p,sticky:h,disableAnchorTracking:g,keepMounted:b,nodeId:x,collisionAvoidance:_,adaptiveOrigin:M}),P=S.useState(`domReferenceElement`);Qt({store:y,domReference:P,positionerElement:k,open:w});let F=D===!0&&T!==`trigger-hover`;$t(w&&F,O===`touch`,k,E);let I=y.useStateSetter(`positionerElement`),L={open:w,side:N.side,align:N.align,anchorHidden:N.anchorHidden,instant:A},R=Ke(e,L,{styles:N.positionerStyles,transitionStatus:j,props:v,refs:[t,I],hidden:!C,inert:!w});return(0,Y.jsxs)(si.Provider,{value:N,children:[C&&F&&(0,Y.jsx)(ge,{inert:be(!w),cutout:E}),(0,Y.jsx)(Gt,{id:x,children:R})]})}),ui=J.createContext(void 0);function di(){let[e,t]=J.useState(0),n=W(()=>(t(e=>e+1),()=>{t(e=>Math.max(0,e-1))}));return{context:J.useMemo(()=>({register:n}),[n]),hasClosePart:e>0}}var fi=J.forwardRef(function(e,t){let{render:n,className:r,style:i,initialFocus:a,finalFocus:s,...c}=e,l=Q(),d=ci(),f=se(!0)!=null,{context:m,hasClosePart:g}=di(),_=l.useState(`open`),v=l.useState(`openMethod`),y=l.useState(`instantType`),b=l.useState(`transitionStatus`),x=l.useState(`popupProps`),S=l.useState(`titleElementId`),C=l.useState(`descriptionElementId`),w=l.useState(`modal`),T=l.useState(`mounted`),E=l.useState(`openChangeReason`),D=l.useState(`activeTriggerElement`),O=l.useState(`floatingRootContext`),k=O.useState(`floatingId`),A=l.useState(`disabled`),j=l.useState(`openOnHover`),M=l.useState(`closeDelay`);u({open:_,ref:l.context.popupRef,onComplete(){_&&l.context.onOpenChangeComplete?.(!0)}}),mt(O,{enabled:j&&!A,closeDelay:M});let N=a===void 0?Se(l.context.popupRef):a,P=w!==!1&&g;l.useSyncedValue(`focusManagerModal`,P);let F=l.useStateSetter(`popupElement`),I={open:_,side:d.side,align:d.align,instant:y,transitionStatus:b},L=ht(`div`,e,{state:I,ref:[t,l.context.popupRef,F],props:[x,{id:k,role:`dialog`,...o,"aria-labelledby":S,"aria-describedby":C,onKeyDown(e){f&&p.has(e.key)&&e.stopPropagation()}},h(b),c],stateAttributesMapping:Zt});return(0,Y.jsx)(nt,{context:O,openInteractionType:v,modal:P,disabled:!T||E===`trigger-hover`,initialFocus:N,returnFocus:s,restoreFocus:`popup`,getInsideElements:()=>[l.context.beforeTriggerFocusGuardRef.current],previousFocusableElement:Ot(D)?D:void 0,nextFocusableElement:l.context.triggerFocusTargetRef,beforeContentFocusGuardRef:l.context.beforeContentFocusGuardRef,children:(0,Y.jsx)(ui.Provider,{value:m,children:L})})});function pi({getKey:e,isDisabled:t=()=>!1,items:n,getFallbackKey:r}){let i=(0,J.useMemo)(()=>{let r=n.map(e);if(r.some(e=>!e))throw Error(`Selectable items require non-empty keys`);if(new Set(r).size!==r.length)throw Error(`Selectable items require unique keys`);return n.filter(e=>!t(e))},[e,t,n]),[a,o]=(0,J.useState)(null),s=r?.(i)??null,c=a!==null&&i.some(t=>e(t)===a)?a:s!==null&&i.some(t=>e(t)===s)?s:null;(0,J.useEffect)(()=>{a!==null&&!i.some(t=>e(t)===a)&&o(null)},[a,i,e]);let l=i.find(t=>e(t)===c),u=l?i.findIndex(t=>e(t)===c):-1;return{activeIndex:u,activeItem:l,activeKey:c,enabledItems:i,move:(t,n)=>{if(i.length===0)return;let r=n?n===`start`?0:i.length-1:u<0?t>0?0:i.length-1:(u+t+i.length)%i.length,a=i[r];a&&o(e(a))},setActiveKey:o}}var mi=(0,J.forwardRef)(function({children:e,className:t,type:n=`button`,...r},i){return(0,Y.jsxs)(`button`,{...r,ref:i,type:n,className:L(`select caps-select caps-combobox-trigger w-full`,t),children:[(0,Y.jsx)(`span`,{children:e}),(0,Y.jsx)(yn,{className:`caps-select-chevron`,"aria-hidden":`true`})]})});function hi({defaultInputValue:e,defaultOpen:t,defaultValue:n,getKey:r,getSearchText:i,groupBy:a,id:o,isDisabled:s,items:c,onOpenChange:l,onCommit:u,multiple:d,controlledOpen:f,controlledKeys:p,trigger:m}){let h=`${o}-listbox`,[g,_]=(0,J.useState)(e),[v,y]=(0,J.useState)(!1),[b,x]=(0,J.useState)(n),[S,C]=(0,J.useState)(t),w=p??(b===null?[]:[b]),T=m?f??S:!0,E=(0,J.useMemo)(()=>{let e=g.trim().toLowerCase();return e?c.filter(t=>i(t).toLowerCase().includes(e)):c},[i,c,g]),D=pi({getKey:r,isDisabled:s,items:E});(0,J.useEffect)(()=>{if(D.activeKey!==null)return;let e=D.enabledItems.find(e=>w.includes(r(e)))??D.enabledItems[0];e&&D.setActiveKey(r(e))},[D.activeKey,D.enabledItems,D.setActiveKey,r,w]);let O=e=>{y(!1),e||_(``),f===void 0&&C(e),l?.(e)},k=e=>`${h}-option-${encodeURIComponent(e)}`,A=e=>{let t=r(e);p===void 0&&x(t),u(e),m&&!d&&O(!1)},j=e=>{y(!0),_(e.target.value),D.setActiveKey(null)},M=e=>{if(Kr(e))return;let t;switch(e.key){case`ArrowDown`:t=[1,void 0];break;case`ArrowUp`:t=[-1,void 0];break;case`End`:t=[1,`end`];break;case`Home`:t=[-1,`start`]}t?(y(!0),e.preventDefault(),D.move(t[0],t[1])):e.key===`Enter`&&D.activeItem&&(e.preventDefault(),A(D.activeItem))},N=(0,J.useMemo)(()=>{if(!a)return[{label:``,items:E}];let e=new Map;for(let t of E){let n=a(t),r=e.get(n);r?r.push(t):e.set(n,[t])}return[...e].map(([e,t])=>({label:e,items:t}))},[E,a]);return{keyboardNavigation:v,onPointerMove:()=>{y(!1)},activeKey:D.activeKey,activeItem:D.activeItem,groups:N,inputValue:g,listboxId:h,onInputChange:j,onInputKeyDown:M,optionId:k,open:T,commit:A,selectedKeys:w,setOpen:O}}function gi(e){let{"aria-describedby":t,"aria-invalid":n,"aria-label":r,"aria-labelledby":i,"aria-required":a,activeTone:o=`neutral`,container:s,contentClassName:c,defaultInputValue:l=``,defaultOpen:u=!1,defaultValue:d=null,emptyMessage:f=`No matches`,getKey:p,getLabel:m,getSearchText:h=m,groupBy:g,id:_,inputProps:v,inputRef:y,isDisabled:b=()=>!1,items:x,onOpenChange:S,onValueChange:C,multiple:w,open:T,placeholder:E=`Search…`,renderItem:D,rootRef:O,trigger:k,triggerRef:A,value:j,...M}=e,N=e=>{let t=p(e);if(w){let e=j.includes(t)?j.filter(e=>e!==t):[...j,t];C?.(e,x.filter(t=>e.includes(p(t))))}else C?.(t,e)},P;w?P=j:j!==void 0&&(P=j===null?[]:[j]);let F=(0,J.useId)(),I=k?.props??v,R=_??I?.id??F,ee={id:R,"aria-describedby":[t,I?.[`aria-describedby`]].filter(Boolean).join(` `)||void 0,"aria-invalid":n??I?.[`aria-invalid`],"aria-label":I?.[`aria-label`]??r,"aria-labelledby":I?.[`aria-labelledby`]??i,"aria-required":a??I?.[`aria-required`]},{keyboardNavigation:te,onPointerMove:ne,activeItem:re,activeKey:ie,commit:ae,groups:oe,inputValue:se,listboxId:z,onInputChange:ce,onInputKeyDown:le,open:ue,optionId:de,selectedKeys:fe,setOpen:pe}=hi({defaultInputValue:l,defaultOpen:u,defaultValue:d,getKey:p,getSearchText:h,groupBy:g,id:R,isDisabled:b,items:x,onOpenChange:S,onCommit:N,multiple:w??!1,controlledOpen:T,controlledKeys:P,trigger:k});kt(()=>{k&&pe(!1)});let me=xt(`popover`),he=s===void 0?me:s,ge=st(`.caps-combobox-option[data-active="true"]:not(:disabled), [data-navigation="pointer"] .caps-combobox-option:hover:not(:disabled)`),_e=(0,Y.jsx)(Bn,{...v,...k?{}:ee,"aria-activedescendant":re?de(p(re)):void 0,"aria-autocomplete":`list`,"aria-controls":z,"aria-expanded":!0,className:L(`input-sm`,v?.className),id:k?v?.id??`${R}-input`:R,onChange:e=>{v?.onChange?.(e),ce(e)},onKeyDown:e=>{v?.onKeyDown?.(e),e.defaultPrevented||le(e)},placeholder:v?.placeholder??E,ref:y,role:`combobox`,value:se}),ve=(0,Y.jsx)(`div`,{id:z,ref:ge,className:`caps-combobox-list`,"data-navigation":te?`keyboard`:`pointer`,onPointerMove:ne,role:`listbox`,"aria-multiselectable":w??void 0,children:oe.every(e=>e.items.length===0)?(0,Y.jsx)(`div`,{className:`px-md py-md text-sm text-base-content`,children:f}):oe.map(e=>(0,Y.jsxs)(`div`,{"aria-label":e.label||void 0,role:e.label?`group`:void 0,children:[e.label?(0,Y.jsx)(`div`,{className:`px-md pb-xs pt-sm text-xs text-base-content uppercase tracking-wider`,children:e.label}):null,e.items.map(e=>{let t=p(e),n=b(e),r=ie===t,i={active:r,disabled:n,selected:fe.includes(t)};return(0,Y.jsxs)(`button`,{"aria-disabled":n||void 0,"aria-selected":i.selected,className:`caps-combobox-option`,"data-active":r&&te,disabled:n,id:de(t),onClick:()=>{ae(e)},onMouseDown:e=>{e.preventDefault()},role:`option`,tabIndex:-1,type:`button`,children:[(0,Y.jsx)(`span`,{"aria-hidden":`true`,className:`caps-combobox-check`,children:i.selected?(0,Y.jsx)($n,{}):null}),D?.(e,r,i)??m(e)]},t)})]},e.label))});return k?(0,Y.jsx)(`div`,{...M,className:L(M.className),ref:O,children:(0,Y.jsxs)(ei,{modal:!0,onOpenChange:pe,open:ue,children:[(0,Y.jsx)(ri,{...ee,"aria-haspopup":`dialog`,className:`btn`,ref:A,render:k}),he===null?null:(0,Y.jsx)(oi,{container:he,children:(0,Y.jsx)(li,{align:`start`,side:`bottom`,sideOffset:4,className:`z-(--stipe-layer-popover)`,children:(0,Y.jsxs)(fi,{"data-active-tone":o,className:L(`min-w-40 rounded-box border border-base-300 bg-base-100 p-xs shadow-lg outline-none caps-combobox-panel caps-combobox-popup`,c),children:[(0,Y.jsx)(`div`,{className:`caps-combobox-search`,children:_e}),ve]})})})]})}):(0,Y.jsx)(`div`,{...M,className:L(M.className),ref:O,children:(0,Y.jsxs)(`div`,{className:L(`caps-combobox-panel`,c),"data-active-tone":o,children:[(0,Y.jsx)(`div`,{className:`caps-combobox-search`,children:_e}),ve]})})}function _i({icon:e,caption:t}){return(0,Y.jsxs)(`span`,{className:`caps-icon-choice-mark`,"aria-hidden":`true`,children:[(0,Y.jsx)(`span`,{className:`caps-icon-choice-art`,children:e}),t?(0,Y.jsx)(`span`,{className:`caps-icon-choice-caption`,children:t}):null,(0,Y.jsx)(`span`,{className:`caps-icon-choice-lamp`})]})}var vi=(0,J.forwardRef)(function({label:e,icon:t,caption:n,appearance:r,className:i,...a},o){return(0,Y.jsx)(`label`,{className:`caps-icon-choice`,"data-appearance":r===`compact`?r:void 0,children:(0,Y.jsx)(Wr,{...a,appearance:r??`default`,"aria-label":e,className:L(`caps-icon-choice-input`,i),indicator:(0,Y.jsx)(_i,{icon:t,caption:n}),ref:o})})}),yi=(0,J.forwardRef)(function({label:e,icon:t,hint:n,className:r,...i},a){let o=(0,J.useId)(),s=[i[`aria-describedby`],n?o:null].filter(Boolean).join(` `)||void 0;return(0,Y.jsx)(`label`,{className:`caps-check-key`,children:(0,Y.jsx)(Wr,{...i,"aria-label":e,"aria-describedby":s,className:L(`caps-check-key-input`,r),indicator:(0,Y.jsxs)(`span`,{className:`caps-check-key-face`,"aria-hidden":`true`,children:[t?(0,Y.jsx)(`span`,{className:`caps-check-key-icon`,children:t}):null,(0,Y.jsxs)(`span`,{className:`caps-check-key-copy`,children:[(0,Y.jsx)(`span`,{className:`caps-check-key-label`,children:e}),n?(0,Y.jsx)(`span`,{className:`caps-check-key-hint`,id:o,children:n}):null]}),(0,Y.jsx)(`span`,{className:`caps-check-key-lamp`})]}),ref:a})})});function bi({className:e,...t}){return(0,Y.jsx)(`div`,{...t,className:L(`caps-check-keys`,e)})}function xi({checked:e}){let t=`caps-radio-${(0,J.useId)().replaceAll(`:`,``)}`,n=(0,J.useRef)(null),r=(0,J.useRef)(e).current,i=(0,J.useRef)(e),a=(0,J.useRef)(null),o=Ne(a),{reduced:s}=o;return(0,J.useLayoutEffect)(()=>{if(!n.current)return;let t=s||i.current===e;i.current=e;let r=e?4:0,a=q(o,{ease:`outCubic`,duration:75}),c=e?An(o,{bounce:.65,duration:300}):q(o,{ease:`inCubic`,duration:100}),l=en(n.current,t?{rx:r,ry:r,cy:6,duration:0}:{rx:[{to:e?3.5:4.15,...a},{to:r,...c}],ry:[{to:e?4.5:3.85,...a},{to:r,...c}],cy:[{to:e?5.85:6.1,...a},{to:6,...c}]});return()=>{l.cancel()}},[e,s,o]),(0,Y.jsxs)(`svg`,{ref:a,className:`caps-radio-visual`,width:`24`,height:`24`,viewBox:`0 0 12 12`,"aria-hidden":`true`,focusable:`false`,children:[(0,Y.jsxs)(`defs`,{children:[(0,Y.jsx)(He,{id:`${t}-surface`,transform:`matrix(1 0 0 1 6 6)`}),(0,Y.jsx)(ot,{id:`${t}-shadow`}),(0,Y.jsx)(lt,{id:`${t}-inset`}),(0,Y.jsx)(`clipPath`,{id:`${t}-well`,children:(0,Y.jsx)(`circle`,{cx:`6`,cy:`6`,r:`5`})})]}),(0,Y.jsx)(`circle`,{className:`caps-radio-track`,cx:`6`,cy:`6`,r:`5.5`,filter:`url(#${t}-inset)`}),(0,Y.jsx)(`g`,{clipPath:`url(#${t}-well)`,children:(0,Y.jsx)(`ellipse`,{ref:n,cx:`6`,cy:`6`,rx:r?4:0,ry:r?4:0,fill:`url(#${t}-surface)`,filter:`url(#${t}-shadow)`})})]})}var Si=(0,J.createContext)(null),Ci=(0,J.forwardRef)(function({children:e,className:t,defaultValue:n,disabled:r=!1,name:i,onValueChange:a,orientation:o=`vertical`,value:s,...c},l){let u=(0,J.useId)(),d=(0,J.useRef)(null);(0,J.useImperativeHandle)(l,()=>{if(!d.current)throw Error(`RadioGroup is not mounted`);return d.current},[]);let f=i??`radio-group-${u}`,[p,m]=(0,J.useState)(n),h=s??p;return(0,J.useEffect)(()=>{let e=d.current?.form;if(!e||s!==void 0)return;let t=e=>{queueMicrotask(()=>{e.defaultPrevented||m(n)})};return e.addEventListener(`reset`,t),()=>{e.removeEventListener(`reset`,t)}},[s,n,c.form]),(0,Y.jsx)(Si.Provider,{value:{disabled:r,name:f,onValueChange:e=>{s===void 0&&m(e),a?.(e)},value:h},children:(0,Y.jsx)(`fieldset`,{...c,className:L(`flex gap-md`,o===`horizontal`?`flex-row flex-wrap`:`flex-col`,t),disabled:r,role:c.role??`radiogroup`,ref:d,children:e})})}),wi=(0,J.forwardRef)(function({className:e,indicator:t,onChange:n,onClick:r,value:i,...a},o){let s=(0,J.useContext)(Si);if(!s)throw Error(`RadioGroupItem must be used inside <RadioGroup>`);let c=s.value===i,l=e=>{n?.(e),e.target.checked&&s.onValueChange?.(i)};return(0,Y.jsxs)(`span`,{className:`caps-radio`,"data-checked":c,"data-custom-indicator":t!==void 0||void 0,children:[(0,Y.jsx)(`input`,{...a,"aria-checked":c,checked:c,className:L(`caps-radio-input`,e),disabled:s.disabled||a.disabled,name:s.name,onChange:l,onClick:r,ref:o,type:`radio`,value:i}),t===void 0?(0,Y.jsx)(xi,{checked:c}):t]})}),Ti=(0,J.forwardRef)(function({description:e,id:t,meta:n,title:r,...i},a){let o=(0,J.useContext)(Si),s=(0,J.useId)(),c=t??s,l=o?.value===i.value,u=o?.disabled===!0||i.disabled===!0;return(0,Y.jsxs)(`label`,{className:`caps-choice-card`,"data-checked":l,"data-disabled":u||void 0,htmlFor:c,children:[(0,Y.jsx)(wi,{...i,"aria-describedby":e?`${c}-description`:void 0,"aria-labelledby":`${c}-title`,id:c,ref:a}),(0,Y.jsxs)(`span`,{className:`caps-choice-card-copy`,children:[(0,Y.jsx)(`span`,{className:`caps-choice-card-title`,id:`${c}-title`,children:r}),e?(0,Y.jsx)(`span`,{className:`caps-choice-card-description`,id:`${c}-description`,children:e}):null]}),n?(0,Y.jsx)(`span`,{className:`caps-choice-card-meta`,children:n}):null]})}),Ei=(0,J.forwardRef)(function({label:e,icon:t,caption:n,art:r=`dim`,className:i,...a},o){return(0,Y.jsx)(`label`,{className:`caps-icon-choice`,"data-art":r===`color`?r:void 0,children:(0,Y.jsx)(wi,{...a,"aria-label":e,className:L(`caps-icon-choice-input`,i),indicator:(0,Y.jsx)(_i,{icon:t,caption:n}),ref:o})})});(0,J.forwardRef)(function({label:e,color:t,className:n,...r},i){return(0,Y.jsx)(`label`,{className:`caps-icon-choice`,"data-art":`color`,"data-swatch":``,title:e,children:(0,Y.jsx)(wi,{...r,"aria-label":e,className:L(`caps-icon-choice-input`,n),indicator:(0,Y.jsx)(_i,{icon:(0,Y.jsx)(`span`,{className:`caps-swatch-dot`,style:{backgroundColor:t}})}),ref:i})})});var Di=(0,J.forwardRef)(function({className:e,invalid:t,...n},r){return(0,Y.jsxs)(`span`,{className:`caps-select-shell`,children:[(0,Y.jsx)(`select`,{...n,"aria-invalid":t?!0:n[`aria-invalid`]===!1?void 0:n[`aria-invalid`],className:L(`select select-bordered caps-select w-full`,t&&`select-error`,e),ref:r}),!n.multiple&&(!n.size||n.size<=1)?(0,Y.jsx)(yn,{className:`caps-select-chevron`,"aria-hidden":`true`}):null]})});function Oi({checked:e}){let t=`caps-switch-${(0,J.useId)().replaceAll(`:`,``)}`,n=(0,J.useRef)(null),r=(0,J.useRef)(null),i=(0,J.useRef)(e).current,a=(0,J.useRef)(e),o=S();return(0,J.useLayoutEffect)(()=>{if(!n.current||!r.current)return;let t=o||a.current===e;a.current=e;let i=e?16:8,s=Te(n.current),c=An(s,{bounce:.25,duration:440}),l=q(s,{ease:`inOutSine`,duration:100}),u=en(n.current,t?{x:2,y:2,width:i,height:8,duration:0}:{x:[{to:e?2.5:1.5,...l},{to:2,...c}],y:[{to:1.5,...l},{to:2,...c}],height:[{to:9,...l},{to:8,...c}],width:[{to:e?7:16.5,...l},{to:i,...c}]}),d=en(r.current,{gradientTransform:e?`matrix(2 0 0 1 10 6)`:`matrix(1 0 0 1 6 6)`,...t?{duration:0}:{delay:l.duration,...c}});return()=>{u.cancel(),d.cancel()}},[e,o]),(0,Y.jsxs)(`svg`,{className:`caps-switch-visual`,width:`40`,height:`24`,viewBox:`0 0 20 12`,"aria-hidden":`true`,focusable:`false`,children:[(0,Y.jsxs)(`defs`,{children:[(0,Y.jsx)(He,{ref:r,id:`${t}-surface`,transform:i?`matrix(2 0 0 1 10 6)`:`matrix(1 0 0 1 6 6)`}),(0,Y.jsx)(ot,{id:`${t}-shadow`}),(0,Y.jsx)(lt,{id:`${t}-inset`}),(0,Y.jsx)(`clipPath`,{id:`${t}-track`,children:(0,Y.jsx)(`rect`,{x:`1`,y:`1`,width:`18`,height:`10`,rx:`5`})})]}),(0,Y.jsx)(`rect`,{className:`caps-switch-track`,filter:`url(#${t}-inset)`,x:`0.5`,y:`0.5`,width:`19`,height:`11`,rx:`5.5`}),(0,Y.jsx)(`g`,{clipPath:`url(#${t}-track)`,children:(0,Y.jsx)(`rect`,{ref:n,x:`2`,y:`2`,width:i?16:8,height:`8`,rx:`4`,fill:`url(#${t}-surface)`,filter:`url(#${t}-shadow)`})})]})}var ki=(0,J.forwardRef)(function({className:e,checked:t,defaultChecked:n=!1,onChange:r,onCheckedChange:i,...a},o){let s=(0,J.useRef)(null),[c,l]=(0,J.useState)(n),u=t??c;return(0,J.useImperativeHandle)(o,()=>{if(!s.current)throw Error(`Switch input is not mounted`);return s.current},[]),(0,J.useEffect)(()=>{let e=s.current?.form;if(!e||t!==void 0)return;let r=e=>{queueMicrotask(()=>{!e.defaultPrevented&&s.current&&l(n)})};return e.addEventListener(`reset`,r),()=>{e.removeEventListener(`reset`,r)}},[t,n,a.form]),(0,Y.jsxs)(`span`,{className:`caps-switch`,"data-checked":u,children:[(0,Y.jsx)(`input`,{...a,checked:u,className:L(`caps-switch-input`,e),onChange:e=>{t===void 0&&l(e.target.checked),r?.(e),i?.(e.target.checked)},ref:s,role:`switch`,type:`checkbox`}),(0,Y.jsx)(Oi,{checked:u})]})}),Ai=(0,J.forwardRef)(function({className:e,invalid:t,...n},r){return(0,Y.jsx)(`textarea`,{...n,"aria-invalid":t?!0:n[`aria-invalid`]===!1?void 0:n[`aria-invalid`],className:L(`textarea textarea-bordered w-full`,t&&`textarea-error`,e),ref:r})}),ji=K(H),Mi=K(r),Ni=K(We(et)),Pi=K(de(H)),Fi=de(_e(File)),Ii=K(Fi),Li=At([H,et,r,dt,rt,de(H),Fi]),Ri=K(Li),$=e=>V(ji(e.state.value),()=>``),zi=e=>V(Mi(e.state.value),()=>!1),Bi=e=>V(Ni(e.state.value),()=>null),Vi=e=>V(Pi(e.state.value),()=>[]),Hi=e=>V(Ii(e.state.value),()=>[]),Ui=e=>V(Ri(e.state.value),()=>null);function Wi({field:e,spec:t,locked:n,...r}){let[i,a]=(0,J.useState)(!1);return(0,Y.jsxs)(Pn,{children:[(0,Y.jsx)(Bn,{...r,name:t.name,disabled:n,type:i?`text`:`password`,autoComplete:`off`,spellCheck:!1,className:`caps-field-secret`,placeholder:t.placeholder,readOnly:t.readOnly,value:$(e),onBlur:e.handleBlur,onChange:t=>{e.handleChange(t.currentTarget.value)}}),(0,Y.jsx)(U,{type:`button`,variant:`outline`,size:`icon`,"aria-label":i?`Hide`:`Show`,"aria-pressed":i,disabled:n,onClick:()=>{a(e=>!e)},children:i?(0,Y.jsx)(tr,{"aria-hidden":`true`}):(0,Y.jsx)(nr,{"aria-hidden":`true`})})]})}var Gi={text:`text`,email:`email`,url:`url`,tel:`tel`};function Ki({spec:e,field:t,locked:n,...r}){let i=Hi(t),a=n||e.readOnly===!0,o=(0,J.useRef)(null);return(0,Y.jsxs)(`div`,{className:`flex flex-col gap-sm`,children:[(0,Y.jsx)(re,{asChild:!0,children:(0,Y.jsx)(`input`,{...r,ref:o,type:`file`,tabIndex:-1,required:r.required===!0&&i.length===0,name:e.name,accept:e.accept,multiple:e.multiple,disabled:a,onBlur:t.handleBlur,onChange:e=>{t.handleChange(Array.from(e.currentTarget.files??[])),e.currentTarget.value=``}})}),(0,Y.jsx)(U,{type:`button`,variant:`outline`,"aria-label":`Choose files for ${e.label}`,"aria-describedby":r[`aria-describedby`],"aria-invalid":r[`aria-invalid`],disabled:a,onBlur:t.handleBlur,onClick:()=>{o.current?.click()},children:`Choose files`}),(0,Y.jsx)(Ir,{items:i.map((e,t)=>({id:String(t),name:e.name,preview:{kind:`file`},progress:0,progressLabel:`${String(e.size)} bytes`,statusLabel:`Selected`,actions:a?{}:{remove:{label:`Remove`,accessibleLabel:`Remove ${e.name}`}}})),onRemove:e=>{t.handleChange(i.filter((t,n)=>String(n)!==e))},onCancel:()=>void 0,onRetry:()=>void 0})]})}function qi({spec:e,field:t,locked:n,...r}){let i=e=>{t.handleChange(e)},a={...r,name:e.name,disabled:n,onBlur:t.handleBlur};switch(e.kind){case`text`:case`email`:case`url`:case`tel`:return(0,Y.jsx)(Bn,{...a,type:Gi[e.kind],inputMode:e.kind===`text`?void 0:e.kind,autoComplete:e.autoComplete,placeholder:e.placeholder,maxLength:e.maxLength,readOnly:e.readOnly,value:$(t),onChange:e=>{i(e.currentTarget.value)}});case`textarea`:return(0,Y.jsx)(Ai,{...a,rows:e.rows??3,placeholder:e.placeholder,maxLength:e.maxLength,readOnly:e.readOnly,value:$(t),onChange:e=>{i(e.currentTarget.value)}});case`secret`:return(0,Y.jsx)(Wi,{...r,field:t,spec:e,locked:n});case`money`:return(0,Y.jsxs)(Pn,{children:[(0,Y.jsx)(Fn,{className:`caps-field-currency`,children:e.currency??`USD`}),(0,Y.jsx)(Bn,{...a,inputMode:`decimal`,autoComplete:`off`,className:`caps-field-amount`,placeholder:e.placeholder??`0.00`,readOnly:e.readOnly,value:$(t),onChange:e=>{i(e.currentTarget.value)}})]});case`date`:return(0,Y.jsx)(Bn,{...a,type:`date`,readOnly:e.readOnly,value:$(t),onChange:e=>{i(e.currentTarget.value)}});case`number`:return(0,Y.jsx)(Wn,{...a,...e.min===void 0?{}:{min:e.min},...e.max===void 0?{}:{max:e.max},...e.step===void 0?{}:{step:e.step},...e.unit===void 0?{}:{unit:e.unit},...e.wrap===void 0?{}:{wrap:e.wrap},disabled:n||e.readOnly===!0,decrementLabel:`Decrease ${e.label}`,incrementLabel:`Increase ${e.label}`,value:Bi(t),onValueChange:e=>{t.handleChange(e)}});case`select`:return(0,Y.jsxs)(Di,{...a,value:$(t),onChange:e=>{i(e.currentTarget.value)},children:[e.placeholder===void 0?null:(0,Y.jsx)(`option`,{value:``,disabled:!0,children:e.placeholder}),e.options.map(e=>(0,Y.jsx)(`option`,{value:e.value,disabled:e.disabled,children:e.label},e.value))]});case`combobox`:return(0,Y.jsx)(gi,{id:r.id??e.name,"aria-describedby":r[`aria-describedby`],"aria-invalid":r[`aria-invalid`],"aria-required":r[`aria-required`],items:e.options,getKey:e=>e.value,getLabel:e=>e.label,isDisabled:t=>t.disabled||n||e.readOnly===!0,value:$(t),...e.placeholder===void 0?{}:{placeholder:e.placeholder},trigger:(0,Y.jsx)(mi,{name:e.name,disabled:n||e.readOnly===!0,onBlur:t.handleBlur,children:e.options.find(e=>e.value===$(t))?.label??e.placeholder??`Choose…`}),inputProps:{"aria-label":`Search ${e.label}`,disabled:n||e.readOnly===!0},onValueChange:e=>{i(e??``),t.handleBlur()}});case`file`:return(0,Y.jsx)(Ki,{...r,spec:e,field:t,locked:n});case`checkbox`:return(0,Y.jsx)(Wr,{...a,disabled:n||e.readOnly===!0,checked:zi(t),onChange:e=>{t.handleChange(e.currentTarget.checked)}});case`switch`:return(0,Y.jsx)(ki,{...a,disabled:n||e.readOnly===!0,checked:zi(t),onCheckedChange:e=>{t.handleChange(e)}});case`radio`:case`icon-radio`:case`checkboxes`:case`icon-checkboxes`:return null}}var Ji=new Set([`radio`,`icon-radio`,`checkboxes`,`icon-checkboxes`]);function Yi({spec:e,field:t,locked:n,error:r,layout:i}){let a=n||e.readOnly===!0,o=e.label;if(e.kind===`checkboxes`||e.kind===`icon-checkboxes`){let n=Vi(t),s=(e,r)=>{t.handleChange(r?[...n,e]:n.filter(t=>t!==e))};return(0,Y.jsx)(zn,{legend:o,icon:e.icon,layout:i,...i===`columns`?{legendTitle:o}:{},description:e.help,disabled:a,error:r??null,children:e.kind===`icon-checkboxes`?(0,Y.jsx)(`div`,{className:`caps-field-icon-choices`,children:e.options.map(r=>(0,Y.jsx)(vi,{name:e.name,value:r.value,label:r.label,...r.caption===void 0?{}:{caption:r.caption},icon:r.icon,disabled:r.disabled,checked:n.includes(r.value),onBlur:t.handleBlur,onChange:e=>{s(r.value,e.currentTarget.checked)}},r.value))}):(0,Y.jsx)(bi,{children:e.options.map(r=>(0,Y.jsx)(yi,{name:e.name,value:r.value,label:r.label,icon:r.icon,hint:r.description,disabled:r.disabled,checked:n.includes(r.value),onBlur:t.handleBlur,onChange:e=>{s(r.value,e.currentTarget.checked)}},r.value))})})}let s=e.options.some(e=>e.description!==void 0||e.meta!==void 0);return(0,Y.jsx)(zn,{legend:o,icon:e.icon,layout:i,...i===`columns`?{legendTitle:o}:{},description:e.help,disabled:a,error:r??null,children:(0,Y.jsx)(Ci,{name:e.name,"aria-label":o,value:$(t),onValueChange:e=>{t.handleChange(e),t.handleBlur()},orientation:e.kind===`icon-radio`||s?`horizontal`:`vertical`,children:e.options.map(t=>e.kind===`icon-radio`?(0,Y.jsx)(Ei,{value:t.value,label:t.label,...t.caption===void 0?{}:{caption:t.caption},icon:t.icon,disabled:t.disabled},t.value):s?(0,Y.jsx)(Ti,{value:t.value,title:t.label,description:t.description,meta:t.meta,disabled:t.disabled},t.value):(0,Y.jsx)(Mn,{label:t.label,orientation:`inline`,children:(0,Y.jsx)(wi,{value:t.value,disabled:t.disabled})},t.value))})})}function Xi({spec:e,field:t,locked:n,error:r,render:i,...a}){return i({name:e.name,label:e.label,help:e.help,value:Ui(t),onChange:e=>{t.handleChange(e)},onBlur:t.handleBlur,error:r,disabled:n,id:a.id??e.name,"aria-describedby":a[`aria-describedby`],"aria-invalid":r!==void 0})}function Zi({form:e,spec:t,locked:n,layout:r}){let i=Rn({form:e,name:t.name}),a=Vn(e.store,e=>e.submissionAttempts>0),o=i.state.meta.isBlurred||a?Nr(i.state.meta):void 0;if(t.render===void 0&&Ji.has(t.kind))return(0,Y.jsx)(Yi,{spec:t,field:i,locked:n,error:o,layout:r});let s=r===`columns`?t.kind===`switch`||t.kind===`checkbox`?`horizontal`:`vertical`:t.kind===`checkbox`?`inline`:(t.layout??(t.kind===`switch`?`row`:`stacked`))===`row`?`horizontal`:`vertical`;return(0,Y.jsx)(Mn,{label:t.label,...r===`columns`?{labelTitle:t.label}:{},description:t.help,icon:t.icon,orientation:s,error:o,...t.required===void 0?{}:{required:t.required},...t.optional===void 0?{}:{optional:t.optional},children:t.render===void 0?(0,Y.jsx)(qi,{spec:t,field:i,locked:n}):(0,Y.jsx)(Xi,{spec:t,field:i,locked:n,error:o,render:t.render})})}var Qi=K(Bt(H,Li));function $i({form:e,spec:t,locked:n,layout:r}){let i=t.when;return Vn(e.store,e=>i===void 0||i(V(Qi(e.values),()=>({}))))?(0,Y.jsx)(Zi,{form:e,spec:t,locked:n,layout:r}):null}function ea({form:e,section:t,locked:n,layout:r}){let i=t.fields.map(t=>(0,Y.jsx)($i,{form:e,spec:t,locked:n,layout:r},t.name));return t.title===void 0?i:(0,Y.jsx)(Ln,{title:t.title,description:t.description,layout:r,children:i})}function ta({model:e,names:t,disabled:n=!1,layout:r}){let i=e.form;return t===void 0?e.description.sections.map(e=>(0,Y.jsx)(ea,{form:i,section:e,locked:n,layout:r},e.id??``)):t.map(t=>{let a=e.description.fields.find(e=>e.name===t);return a===void 0?null:(0,Y.jsx)($i,{form:i,spec:a,locked:n,layout:r},t)})}var na=class{annotation;constructor(e){this.annotation=e}},ra=class{sections;constructor(e){this.sections=e}},ia=`caps/form`,aa=0;function oa(e){aa+=1;let t={[`${ia}:${String(aa)}`]:new na(e)};return e.label!==void 0&&(t.title=e.label),e.help!==void 0&&(t.description=e.help),t}H.annotate(oa({kind:`secret`})).pipe(ct(`Secret`));var sa=e=>{let t=e.replace(/([a-z0-9])([A-Z])/g,`$1 $2`).replace(/[-_]+/g,` `).toLowerCase();return t.charAt(0).toUpperCase()+t.slice(1)};function ca(e){return Object.values(e??{}).reduce((e,t)=>t instanceof na?{...e,...t.annotation}:e,{})}function la(e){return e.reduce((e,t)=>({...e,...ca(t)}),{})}function ua(e){let t=e?.[ia];return t instanceof ra?t.sections:{}}var da=K(H);function fa(e){if(ee(e))return tt(da(e.literal),{onNone:()=>null,onSome:e=>[e]});if(!Ce(e))return null;let t=[];for(let n of e.types){if(T(n))continue;let e=fa(n);if(e===null)return null;t.push(...e)}return t}function pa(e){if(De(e))return{type:`string`,literals:[]};if(rn(e))return{type:`number`,nullable:!1};if(A(e))return{type:`boolean`};let t=fa(e);if(t!==null)return{type:`string`,literals:t};if(v(e)){let[t]=e.rest;if(t===void 0)return null;if(De(t))return{type:`strings`,literals:[]};let n=fa(t);return n===null?null:{type:`strings`,literals:n}}if(Ce(e)){let t=e.types.filter(e=>!T(e)&&!pe(e)),n=e.types.some(e=>pe(e)),[r]=t;if(t.length!==1||r===void 0)return null;let i=pa(r);return i?.type===`number`?{type:`number`,nullable:n}:n?null:i}return null}function ma(e){let t=e.ast;if(!s(t))throw Error(`A schema form needs a Schema.Struct.`);return{fields:t.propertySignatures.map(e=>{let t=String(e.name),n=Pt(e.type),r=la([e.type.annotations,...(e.type.checks??[]).map(e=>e.annotations)]),i=r.kind===`file`?{type:`files`}:pa(n);if(i===null)throw Error(`Schema field "${t}" has no form control. Annotate it with field({ render }) or a kind.`);return{name:t,valueType:i,optional:e.type.context?.isOptional===!0,annotation:r,title:F(e.type),description:b(e.type)}}),sections:ua(je(t))}}function ha(e){let t=e,n=!1,r=!1;for(;;)if(t instanceof Jt)n=!0,t=t.unwrap();else if(t instanceof Vt)r=!0,t=t.unwrap();else if(t instanceof ft)t=t.unwrap();else if(t instanceof $e)t=t.in;else return{node:t,optional:n,nullable:r}}function ga(e){if(e instanceof St){let t=e.options.map(e=>ga(e));return t.some(e=>e===null)?null:t.flatMap(e=>e??[])}let t=e instanceof Ge?e.options:e instanceof Dt?[...e.values]:null;if(t===null)return null;let n=t.map(e=>da(e));return n.every(ue)?n.map(e=>e.value):null}function _a(e){let{node:t,nullable:n}=ha(e);if(t instanceof it)return{type:`string`,literals:[]};if(t instanceof Ye)return{type:`number`,nullable:n};if(t instanceof Lt)return{type:`boolean`};let r=ga(t);if(r!==null)return{type:`string`,literals:r};if(t instanceof Tt){let e=ha(t.element).node;if(e instanceof it)return{type:`strings`,literals:[]};let n=ga(e);return n===null?null:{type:`strings`,literals:n}}return null}function va(e){let t=[e];for(;;){let e=t[t.length-1];if(e===void 0)break;let n=e instanceof Jt||e instanceof Vt||e instanceof ft?e.unwrap():e instanceof $e?e.in:e;if(n===e)break;t.push(n)}return t.reverse().map(e=>te.get(e))}function ya(e){return va(e).reduce((e,t)=>({...e,...t}),{})}function ba(e){return Object.entries(e.shape)}function xa(e){let t=ha(e).node;if(!(t instanceof yt))throw Error(`A schema form needs a z.object.`);return{fields:ba(t).map(([e,t])=>{let n=la(va(t)),r=n.kind===`file`?{type:`files`}:_a(t);if(r===null)throw Error(`Schema field "${e}" has no form control. Annotate it with field({ render }) or a kind.`);let i=ya(t);return{name:e,valueType:r,optional:ha(t).optional,annotation:n,title:i.title,description:i.description}}),sections:ua(ya(e))}}function Sa(e,t){let n=t.options??{};return(e.length>0?e:Object.keys(n)).map(e=>{let t=n[e],r=t===void 0?{}:t instanceof Object?t:{label:t};return{value:e,label:r.label??sa(e),description:r.description,meta:r.meta,icon:r.icon,caption:r.caption,disabled:r.disabled===!0}})}function Ca(e,t){let n=t.some(e=>e.icon!==void 0);switch(e.type){case`boolean`:return`switch`;case`number`:return`number`;case`strings`:return n?`icon-checkboxes`:`checkboxes`;case`files`:return`file`;case`string`:return t.length===0?`text`:t.length>12?`combobox`:n?`icon-radio`:t.some(e=>e.description!==void 0||e.meta!==void 0)||t.length<=3?`radio`:`select`}}function wa(e,t){switch(e.type){case`boolean`:return!1;case`number`:return e.nullable?null:0;case`strings`:case`files`:return[];case`string`:return t[0]?.value??``}}function Ta(e){let t=e instanceof jt?xa(e):ma(e),n=t.fields.map((e,t)=>{let{kind:n,...r}=e.annotation,i=Sa(e.valueType.type===`string`||e.valueType.type===`strings`?e.valueType.literals:[],e.annotation),a=r.help??e.description;return{...r,name:e.name,label:r.label??e.title??sa(e.name),help:a,kind:n??Ca(e.valueType,i),options:i,optionalInSchema:e.optional,index:t}}),r={};t.fields.forEach((e,t)=>{let i=n[t];i&&(r[e.name]=wa(e.valueType,i.options))});let i=e=>e.order??e.index,a=e=>e.section!==void 0&&Object.hasOwn(t.sections,e.section)?e.section:null,o=e=>n.filter(t=>a(t)===e).sort((e,t)=>i(e)-i(t)),s=Object.entries(t.sections).map(([e,t])=>({id:e,title:t.title,description:t.description,fields:o(e)}));return{fields:n,sections:[{id:null,title:void 0,description:void 0,fields:o(null)},...s].filter(e=>e.fields.length>0),defaults:r}}function Ea(e){let t=e instanceof jt?e:ce(e);return{"~standard":{...t[`~standard`],validate:e=>{let n=t[`~standard`].validate(e);return n instanceof Promise?n.then(e=>Da(e)):Da(n)}}}}function Da(e){return e.issues===void 0?e:{issues:e.issues.map(e=>e.path===void 0?e:{...e,path:e.path.slice(0,1)})}}var Oa=`onServer`;function ka(e){let t=e.querySelector(`[aria-invalid="true"]`),n=t?.matches(`input, select, textarea, button, [tabindex]`)?t:t?.querySelector(`input, select, textarea, button`);return n?.focus(),n!=null}function Aa(e){if(ka(e))return()=>void 0;let t=new MutationObserver(()=>{ka(e)&&t.disconnect()});return t.observe(e,{subtree:!0,childList:!0,attributes:!0,attributeFilter:[`aria-invalid`]}),()=>{t.disconnect()}}function ja(e){return e.state.meta.errorMap.onServer!==void 0}function Ma(e){e.setMeta(e=>({...e,errorMap:{...e.errorMap,[Oa]:void 0}}))}function Na(e,t,n){e.setFieldMeta(t,e=>({...e,isBlurred:!0,errorMap:{...e.errorMap,[Oa]:n}}))}function Pa(e){let[t,n]=(0,J.useState)(null),[r,i]=(0,J.useState)(null),[a,o]=(0,J.useState)(e.defaultValues),[s,c]=(0,J.useState)(null);In(a,e.defaultValues)||(o(e.defaultValues),c(null));let{schema:l}=e,u=(0,J.useMemo)(()=>Ta(l),[l]),d=(0,J.useMemo)(()=>Ea(l),[l]),f=Un({defaultValues:s??a,validators:{onChange:d,onSubmit:d},listeners:{onChange:({fieldApi:e})=>{n(null),i(null),ja(e)&&Ma(e)}},onSubmit:async({value:t,formApi:r})=>{n(null),i(null);let a=await Ea(l)[`~standard`].validate(t);if(a.issues){n(a.issues[0]?.message??`Check the form and try again.`);return}let o;try{o=await e.onSubmit(a.value,t)??{kind:`saved`}}catch(t){console.error(`SchemaForm submit failed`,t),n(e.failure??`Couldn't save changes. Try again.`);return}if(o.kind===`refused`){n(o.error??null);let e=r;for(let[t,n]of Object.entries(o.fields??{}))n!==void 0&&n.length>0&&Na(e,t,n);return}let s=o.values??t;c(s),r.reset(s),i(o.message??`Saved`),e.onSaved?.(s)}});return{description:u,form:f,error:t,saved:r,discard:()=>{n(null),i(null),f.reset()},submit:()=>f.handleSubmit()}}function Fa(e){return{dirty:Vn(e.form.store,e=>!e.isDefaultValue),submitting:Vn(e.form.store,e=>e.isSubmitting),canSubmit:Vn(e.form.store,e=>e.canSubmit)}}function Ia({model:e,submitLabel:t=`Save changes`,discardLabel:n,onCancel:r,cancelLabel:i,allowClean:a,layout:o,footer:s,children:c,disabled:l=!1,...u}){let{submitting:d}=Fa(e),f=(0,J.useRef)(null),p=(0,J.useRef)(()=>void 0);return(0,J.useEffect)(()=>()=>{p.current()},[]),(0,Y.jsxs)(Hn,{...u,ref:f,layout:o,busy:d,noValidate:!0,onSubmit:t=>{t.preventDefault(),e.form.state.isSubmitting||e.submit().then(()=>{p.current();let t=f.current;t!==null&&!e.form.state.isValid&&(p.current=Aa(t))})},children:[c??(0,Y.jsx)(ta,{model:e,disabled:l,layout:o}),s===void 0?(0,Y.jsx)(za,{model:e,label:t,discardLabel:r===void 0?n:void 0,onCancel:r,cancelLabel:i,allowClean:a??r!==void 0,divider:r===void 0}):s]})}function La({schema:e,defaultValues:t,onSubmit:n,onSaved:r,failure:i,...a}){let o=Pa({schema:e,defaultValues:t,onSubmit:n,onSaved:r,failure:i});return(0,Y.jsx)(Ia,{...a,model:o})}function Ra(e){return`model`in e?(0,Y.jsx)(Ia,{...e}):(0,Y.jsx)(La,{...e})}function za({model:e,label:t,discardLabel:n,onCancel:r,cancelLabel:i=`Cancel`,allowClean:a=!1,dirtyLabel:o=`Unsaved changes`,buttonProps:s,...c}){let{dirty:l,submitting:u}=Fa(e),d=u?null:e.saved&&!l?(0,Y.jsx)(On,{tone:`success`,size:`compact`,label:e.saved}):l?(0,Y.jsx)(On,{tone:`neutral`,size:`compact`,label:o}):null;return(0,Y.jsxs)(Nn,{...c,error:e.error,status:d,children:[r?(0,Y.jsx)(U,{type:`button`,variant:`ghost`,disabled:u,onClick:r,children:i}):n&&l?(0,Y.jsx)(U,{type:`button`,variant:`ghost`,disabled:u,onClick:e.discard,children:n}):null,(0,Y.jsx)(U,{...s,type:`submit`,loading:u,disabled:u||!l&&!a,title:!l&&!a?`No changes to save`:void 0,children:t})]})}var Ba=qt.check(a(/^(?!\.{1,2}$)[^/]+$/u,{message:`Enter a single file or folder name.`})),Va={file:vt({name:Ba.annotate(oa({label:`File name`}))}),folder:vt({name:Ba.annotate(oa({label:`Folder name`}))})};function Ha(e){return(0,Y.jsx)(Ua,{...e},e.creation?`${e.creation.kind}:${e.creation.directory}:${e.creation.name??``}`:`closed`)}function Ua({creation:e,rootPath:t,onCreate:n,onClose:r}){let i=Pa({schema:Va[e?.kind??`file`],defaultValues:{name:e?.name??``},onSubmit:async t=>{if(!e)return;let i=await n(e,t.name);if(i)return i===`That name already exists in this directory.`?{kind:`refused`,fields:{name:i}}:{kind:`refused`,error:i};r()}}),{submitting:a}=Fa(i);return(0,Y.jsx)(Ue,{open:e!==null,onOpenChange:e=>{!e&&!i.form.state.isSubmitting&&r()},children:(0,Y.jsxs)(zt,{children:[(0,Y.jsxs)(Kt,{className:`mb-4`,children:[(0,Y.jsxs)(Qe,{children:[`New `,e?.kind===`folder`?`folder`:`file`]}),(0,Y.jsxs)(Je,{children:[`Create in `,e?.directory??t,` on this Computer.`]})]}),(0,Y.jsx)(Ra,{model:i,onSubmitCapture:()=>{i.form.state.isSubmitting||i.form.setFieldValue(`name`,e=>e)},footer:(0,Y.jsxs)(Nn,{divider:!1,error:i.error,children:[(0,Y.jsx)(U,{variant:`ghost`,type:`button`,disabled:a,onClick:r,children:`Cancel`}),(0,Y.jsx)(U,{type:`submit`,disabled:a,loading:a,children:a?`Creating…`:`Create`})]})})]})})}function Wa({files:e,patch:t,truncated:n,activeDiff:r,rowHeight:i,onOpenDiff:a}){let o=(0,J.useMemo)(()=>En(t),[t]);return e.length===0?(0,Y.jsx)(pn,{className:`inkcap-changes-empty`,variant:`quiet`,title:`No changes yet`,description:`Files the Agent edits show up here.`}):(0,Y.jsxs)(`div`,{className:`inkcap-changes-list`,children:[n?(0,Y.jsx)(`p`,{className:`inkcap-tree-note`,children:`Showing the first part of a large change. Review the rest in a terminal.`}):null,(0,Y.jsx)(`ul`,{children:e.map(e=>{let t=o.get(e.path);return(0,Y.jsx)(`li`,{children:(0,Y.jsxs)(U,{className:`inkcap-change-file`,style:{minHeight:i},size:`sm`,variant:`ghost`,"aria-current":r===e.path?`true`:void 0,title:`Review changes to ${e.path}`,onClick:()=>{a(e.path)},children:[(0,Y.jsx)(`span`,{className:`inkcap-change-mark`,"data-status":e.status,role:`img`,"aria-label":xn[e.status],children:wn[e.status]}),(0,Y.jsx)(`span`,{className:`inkcap-change-path`,children:e.path}),t?(0,Y.jsxs)(`span`,{className:`inkcap-change-counts`,children:[t.additions>0?(0,Y.jsxs)(`span`,{className:`inkcap-change-added`,children:[`+`,t.additions]}):null,t.deletions>0?(0,Y.jsxs)(`span`,{className:`inkcap-change-removed`,children:[`−`,t.deletions]}):null]}):null]})},`${e.status}:${e.path}`)})})]})}var Ga=`That name already exists in this directory.`;function Ka({app:e,onOpenFile:t,onOpenDiff:n,activeDiff:r=null,activePath:i,rootPath:a=`/`,rootLabel:o=`Computer`,onSelectPath:s,creationRequest:c=null,onCreationRequestHandled:u,rowHeight:d=32}){let[f,p]=(0,J.useState)(null),m=Ar({app:e,rootPath:a,rootLabel:o,rowHeight:d,activePath:i,onOpenFile:t,onSelectPath:e=>{p(e),s?.(e)}}),[h,g]=(0,J.useState)(null),_=e.capabilities.has(sn),[v,y]=(0,J.useState)(!1),b=e.capabilities.has(un),x=ln(vn(b?e:null,a)),S=x.data?.kind===`changes`?x.data:null;function C(){m.reloadRoot(),b&&x.refetch()}(0,J.useEffect)(()=>{x.isError&&e.ui.showToast({message:fe(x.error).message,tone:`error`}).catch(e=>{console.error(`Inkcap changes toast failed`,e)})},[e,x.isError,x.error]);function w(e,t){g({kind:e,directory:wt(t,a)})}(0,J.useEffect)(()=>{if(!c)return;let e={kind:c.kind,directory:wt(f??`${a}/`,a)};c.name!==void 0&&(e.name=c.name),c.immediate===!0&&c.name!==void 0?T(e,c.name):g(e),u?.()},[c,u,a,f]);async function T(e,n){let r=await E(e,n);r===Ga?t(ut(n,e.directory)):r!==void 0&&g(e)}async function E(n,r){let i=ut(r,n.directory);try{let a=0;for(;a!==null;){let t=a,i=await kn(e.capabilities,{path:n.directory,limit:256,offset:t});if(i.entries.some(e=>e.name===r))return Ga;if(i.nextOffset!==null&&i.nextOffset<=t)return`Could not verify that name is available.`;a=i.nextOffset}n.kind===`folder`?(await e.capabilities.require(sn).mkdir({path:i}),m.noteCreated(`${i}/`)):(await cn(e.capabilities,{path:i,content:new Blob([])},{}),m.noteCreated(i),t(i));return}catch(e){return e instanceof Error?fe(e).message:`Couldn't create ${n.kind}. Check Computer write access.`}}let D={flex:`1`,"--trees-item-height":`${String(d)}px`,"--trees-padding-inline-override":`var(--spacing-xs)`,"--trees-item-margin-x-override":`0px`,"--trees-item-padding-x-override":`var(--spacing-xs)`,"--trees-item-row-gap-override":`var(--spacing-xs)`,"--trees-bg-override":`var(--color-base-100)`,"--trees-fg-override":`var(--color-base-content)`,"--trees-bg-muted-override":`var(--color-base-200)`,"--trees-selected-bg-override":`var(--color-base-300)`,"--trees-border-radius-override":`var(--radius-field)`,"--trees-font-family-override":`var(--font-sans)`,"--trees-font-size-override":`12px`};return(0,Y.jsxs)(`aside`,{className:`inkcap-tree`,"aria-label":`File tree`,children:[(0,Y.jsxs)(`div`,{className:`inkcap-tree-toolbar`,children:[(0,Y.jsxs)(`span`,{children:[(0,Y.jsx)(Tn,{"aria-hidden":`true`}),` `,(0,Y.jsx)(`span`,{className:`inkcap-tree-title`,children:`Explorer`})]}),(0,Y.jsxs)(`span`,{className:`inkcap-tree-actions`,children:[(0,Y.jsx)(l,{icon:(0,Y.jsx)(mn,{}),"aria-label":`New file`,title:`New file`,variant:`ghost`,size:`responsive`,disabled:!_,onClick:()=>{w(`file`,f??`${a}/`)}}),(0,Y.jsx)(l,{icon:(0,Y.jsx)(ir,{}),"aria-label":`New folder`,title:`New folder`,variant:`ghost`,size:`responsive`,disabled:!_,onClick:()=>{w(`folder`,f??`${a}/`)}}),(0,Y.jsx)(l,{icon:(0,Y.jsx)(Kn,{}),"aria-label":`Refresh files`,title:`Refresh files`,variant:`ghost`,size:`responsive`,disabled:m.busy||x.isFetching,onClick:C})]})]}),S===null?x.isError?(0,Y.jsx)(U,{className:`inkcap-changes-retry`,size:`sm`,variant:`ghost`,onClick:()=>void x.refetch(),children:`Changes unavailable. Retry`}):null:(0,Y.jsx)(kr,{className:`inkcap-changes`,size:`row`,open:v,onOpenChange:y,summary:`Changes`,trailing:(0,Y.jsx)(Sn,{count:S.files.length}),children:(0,Y.jsx)(Wa,{files:S.files,patch:S.patch,truncated:S.truncated,activeDiff:r,rowHeight:d,onOpenDiff:e=>{n?.(e)}})}),m.error&&(0,Y.jsx)(fn,{message:m.error,onRetry:m.reloadRoot}),m.rootEmpty?(0,Y.jsx)(`p`,{className:`inkcap-tree-note`,children:`Empty folder`}):null,(0,Y.jsxs)(`div`,{className:`inkcap-tree-files`,children:[(0,Y.jsx)(Gn,{model:m.model,style:D,renderContextMenu:(e,t)=>(0,Y.jsxs)(`div`,{className:`flex min-w-36 flex-col gap-xs p-xs`,role:`menu`,children:[(0,Y.jsxs)(U,{className:`w-full justify-start`,disabled:!_,role:`menuitem`,title:_?void 0:`Computer write access is not granted.`,size:`sm`,variant:`ghost`,onClick:()=>{t.close({restoreFocus:!1}),w(`file`,e.path)},children:[(0,Y.jsx)(mn,{"aria-hidden":`true`}),` New file`]}),(0,Y.jsxs)(U,{className:`w-full justify-start`,disabled:!_,role:`menuitem`,title:_?void 0:`Computer write access is not granted.`,size:`sm`,variant:`ghost`,onClick:()=>{t.close({restoreFocus:!1}),w(`folder`,e.path)},children:[(0,Y.jsx)(ir,{"aria-hidden":`true`}),` New folder`]})]})}),m.page.next!==null&&(0,Y.jsxs)(U,{disabled:m.busy,onClick:m.loadNext,children:[`More in `,m.page.path]})]}),(0,Y.jsx)(Ha,{creation:h,rootPath:a,onCreate:E,onClose:()=>{g(null)}})]})}export{Ka as InkcapFileTree};
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{$ as t,$a as n,$i as r,A as i,Aa as a,B as o,Ba as s,Bi as c,Bn as l,Bt as u,C as d,Cn as f,D as p,Dn as m,E as h,En as g,F as _,Fa as v,G as y,Ga as b,Gi as x,Gr as S,Gt as C,H as w,Ha as T,Hi as E,Hr as D,Ht as O,I as k,Ia as A,J as j,Ji as M,Jr as N,K as P,Ka as F,Ki as I,Kr as L,L as R,La as ee,Li as te,Ln as ne,Lr as re,M as ie,N as ae,Nn as oe,O as se,P as z,Pa as ce,Q as le,Qa as ue,Qi as de,Qr as fe,Ra as pe,Ri as me,Rt as he,S as ge,Sa as _e,Sn as ve,St as ye,T as be,Tn as xe,U as Se,Ua as Ce,Ui as we,Ur as Te,Ut as B,V as Ee,Va as De,Vi as Oe,Vt as ke,W as Ae,Wa as je,Wi as Me,Wr as Ne,X as Pe,Xa as V,Xi as Fe,Y as Ie,Yr as Le,Za as Re,Zi as ze,Zt as Be,_n as Ve,_r as He,a as Ue,aa as We,ai as Ge,b as Ke,bt as qe,c as Je,ca as H,ci as Ye,cn as Xe,ct as Ze,d as Qe,di as $e,dr as U,ea as et,eo as tt,et as nt,fa as rt,fi as it,g as at,gr as ot,h as st,ha as ct,hr as lt,i as ut,ia as dt,ii as ft,in as pt,j as mt,jn as ht,k as gt,kn as _t,la as vt,li as yt,lr as bt,m as xt,mi as St,mr as Ct,n as wt,ni as Tt,nn as W,nt as Et,oi as Dt,on as Ot,p as kt,pa as At,pi as jt,pn as Mt,q as Nt,qa as Pt,qi as Ft,qt as It,ri as Lt,rt as Rt,s as zt,sa as Bt,si as Vt,st as Ht,tn as Ut,to as Wt,tt as Gt,u as Kt,ua as qt,ui as Jt,ur as G,ut as Yt,v as Xt,va as K,wn as Zt,x as Qt,y as $t,yr as en,yt as tn,z as nn,za as rn,zi as an,zn as on}from"./tree-path-DQAnGoeW.js";import{C as sn,D as cn,Ft as ln,O as un,Rt as dn,_ as fn,a as pn,b as q,c as mn,f as hn,g as gn,h as _n,i as vn,l as yn,m as bn,n as xn,o as Sn,p as Cn,r as wn,s as Tn,t as En,u as Dn,v as On,w as kn,x as An,y as jn}from"./changes-patch-DhbNb84Y.js";import{a as Mn,c as Nn,d as Pn,f as Fn,i as In,l as Ln,n as Rn,o as zn,p as Bn,r as Vn,s as Hn,t as Un,u as Wn}from"./useForm-CkS3eP5p.js";import{n as Gn,r as Kn,t as qn}from"./useFileTree-D7u_RYsd.js";var Jn=M(`ZodMiniType`,(e,t)=>{if(!e._zod)throw Error(`Uninitialized schema in ZodMiniType.`);c.init(e,t),e.def=t,e.type=t.type,e.parse=(t,n)=>Oe(e,t,n,{callee:e.parse}),e.safeParse=(t,n)=>we(e,t,n),e.parseAsync=async(t,n)=>E(e,t,n,{callee:e.parseAsync}),e.safeParseAsync=async(t,n)=>Me(e,t,n),e.check=(...n)=>e.clone({...t,checks:[...t.checks??[],...n.map(e=>typeof e==`function`?{_zod:{check:e,def:{check:`custom`},onattach:[]}}:e)]},{parent:!0}),e.with=e.check,e.clone=(t,n)=>x(e,t,n),e.brand=()=>e,e.register=((t,n)=>(t.add(e,n),e)),e.apply=t=>t(e)}),Yn=M(`ZodMiniObject`,(e,t)=>{an.init(e,t),Jn.init(e,t),I(e,`shape`,()=>t.shape)});function Xn(e,t){return new Yn({type:`object`,shape:e??{},...Ft(t)})}var Zn=M(`ZodMiniLiteral`,(e,t)=>{me.init(e,t),Jn.init(e,t)});function Qn(e,t){return new Zn({type:`literal`,values:Array.isArray(e)?e:[e],...Ft(t)})}var $n=G(`Check`,[[`path`,{d:`M20 6 9 17l-5-5`,key:`1gmf2c`}]]),er=G(`ChevronRight`,[[`path`,{d:`m9 18 6-6-6-6`,key:`mthhwq`}]]),tr=G(`EyeOff`,[[`path`,{d:`M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49`,key:`ct8e1f`}],[`path`,{d:`M14.084 14.158a3 3 0 0 1-4.242-4.242`,key:`151rxh`}],[`path`,{d:`M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143`,key:`13bj9a`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}]]),nr=G(`Eye`,[[`path`,{d:`M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0`,key:`1nclc0`}],[`circle`,{cx:`12`,cy:`12`,r:`3`,key:`1v7zrd`}]]),rr=G(`FileImage`,[[`path`,{d:`M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z`,key:`1rqfz7`}],[`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`,key:`tnqrlb`}],[`circle`,{cx:`10`,cy:`12`,r:`2`,key:`737tya`}],[`path`,{d:`m20 17-1.296-1.296a2.41 2.41 0 0 0-3.408 0L9 22`,key:`wt3hpn`}]]),ir=G(`FolderPlus`,[[`path`,{d:`M12 10v6`,key:`1bos4e`}],[`path`,{d:`M9 13h6`,key:`1uhe8q`}],[`path`,{d:`M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z`,key:`1kt360`}]]),ar=G(`RotateCcw`,[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}]]),J=e(ze(),1);function or(e){let{open:t,defaultOpen:n=!1,onOpenChange:r,disabled:i}=e,[a,o]=Xe({controlled:t,default:n,name:`Collapsible`,state:`open`}),{mounted:s,setMounted:c,transitionStatus:l}=O(a,!0,!0),u=It(),[d,p]=J.useState(),m=d===null?void 0:d??u,h=W(e=>{let t=!a,n=C(f,e.nativeEvent);r(t,n),!n.isCanceled&&o(t)});return J.useMemo(()=>({defaultPanelId:u,disabled:i,handleTrigger:h,mounted:s,open:a,panelId:m,setMounted:c,setOpen:o,setPanelIdState:p,transitionStatus:l}),[u,i,h,s,a,m,c,o,p,l])}var sr=J.createContext(void 0);function cr(){let e=J.useContext(sr);if(e===void 0)throw Error(on(15));return e}var lr=`data-open`,ur=`data-closed`,dr=_t,fr=`data-panel-open`,pr={[lr]:``},mr={[ur]:``},hr={open(e){return e?{[fr]:``}:null}},gr={open(e){return e?pr:mr},...m},Y=Fe(),_r=J.forwardRef(function(e,t){let{render:n,className:r,defaultOpen:i=!1,disabled:a=!1,onOpenChange:o,open:s,style:c,...l}=e,u=W(o),d=or({open:s,defaultOpen:i,onOpenChange:u,disabled:a}),f=J.useMemo(()=>({open:d.open,disabled:d.disabled,transitionStatus:d.transitionStatus}),[d.open,d.disabled,d.transitionStatus]),p=J.useMemo(()=>({...d,onOpenChange:u,state:f}),[d,u,f]),m=ht(`div`,e,{state:f,ref:t,props:l,stateAttributesMapping:gr});return(0,Y.jsx)(sr.Provider,{value:p,children:m})}),vr={...hr,...m},yr=J.forwardRef(function(e,t){let{panelId:n,open:r,handleTrigger:i,state:a,disabled:o}=cr(),{className:s,disabled:c=o,render:l,nativeButton:u=!0,style:d,...f}=e,{getButtonProps:p,buttonRef:m}=Be({disabled:c,native:u});return ht(`button`,e,{state:a,ref:[t,m],props:[{"aria-controls":r?n:void 0,"aria-expanded":r,onClick:i},f,p],stateAttributesMapping:vr})}),X={height:void 0,width:void 0};function br(e){let{externalRef:t,hiddenUntilFound:n,id:r,keepMounted:i,mounted:a,onOpenChange:o,open:s,setMounted:c,setOpen:l,transitionStatus:d}=e,f=J.useRef(null),p=J.useRef(null),[m,h]=J.useState(X),g=J.useRef(X),_=J.useRef(!1),v=J.useRef(s),y=J.useRef(!1),[b,x]=J.useState(!1),S=J.useRef(null),w=ne(t,f),T=qe(s),E=ke(f),D=!s&&!a,O=b?`idle`:d,k=s&&(v.current||y.current),A=!s&&a&&p.current===`css-animation`&&m.height===void 0&&m.width===void 0?g.current:m,j=n&&D&&p.current!==`css-animation`,M=W((e,t=!0)=>{t&&(g.current=e),h(e)}),N=W(()=>{S.current?.(),S.current=null}),P=W(e=>{N(),S.current=()=>{S.current=null,e()}}),F=W(()=>{s&&a&&p.current===`css-animation`&&(y.current=!0)});Ut(()=>{!b||d===`starting`||x(!1)},[b,d]),J.useEffect(()=>()=>{F(),N()},[F,N]),Ut(()=>{s||(v.current=!1,y.current=!1);let e=f.current;if(!e)return;!s&&S.current&&N();let t=xr(e,k);if(p.current=t,s&&d===`idle`&&v.current&&t===`css-animation`){g.current=Z(e);return}if(s&&d===`starting`){let n=_.current;if(_.current=!1,t===`none`){M(Z(e)),x(!0);return}if(t===`css-transition`){let t=wr(e);if(M(Z(e)),!n)return t;let r=Cr(e,`transition-duration`,`0s`);return P(r),x(!0),t}M(Z(e));let r=Cr(e,`animation-name`,`none`);if(!n){r();return}let i=Cr(e,`animation-duration`,`0s`);r(),P(i),x(!0);return}if(!s&&a&&(d===`idle`||d===`starting`)){if(t===`none`){M(X,!1),c(!1);return}M(Z(e));return}if(d!==`ending`)return;if(t===`none`){c(!1);return}let n=Z(e);if(!(n.height>0||n.width>0)){c(!1);return}M(n),t===`css-animation`&&Cr(e,`animation-name`,`none`)()},[a,s,N,M,c,P,k,d]),u({enabled:s&&a&&O===`idle`,open:!0,ref:f,onComplete(){s&&M(X,!1)}}),J.useEffect(()=>{if(s||!a||O!==`ending`)return;if(!f.current){c(!1),M(X,!1);return}let e=new AbortController,t=-1;function n(){T.current||(c(!1),M(X,!1))}return t=B.request(()=>{E(n,e.signal)}),()=>{B.cancel(t),e.abort()}},[T,a,s,O,E,M,c]),Ut(()=>{let e=f.current;!e||!n||!D||e.setAttribute(`hidden`,`until-found`)},[D,n]),J.useEffect(function(){let e=f.current;if(!e)return;let t=he.create(),n=-1,r=(r,i)=>{t.start(0,()=>{T.current||(n=B.request(()=>{T.current||(r&&(_.current=!1),i&&e.setAttribute(dr,``),e.setAttribute(`hidden`,`until-found`))}))})},i=ye(e,`beforematch`,t=>{let n=C(Ve,t);if(o(!0,n),n.isCanceled){r(!1,!1);return}_.current=!0;let i=e.hasAttribute(dr);e.removeAttribute(dr),l(!0),r(!0,i)});return()=>{t.clear(),B.cancel(n),i()}},[T,o,l]);let I=i||n||a||s;return{height:A.height,props:{...j?{[dr]:``}:void 0,hidden:D,id:r},ref:w,shouldPreventOpenAnimation:k,shouldRender:I,transitionStatus:O,width:A.width}}function Z(e){return{height:e.scrollHeight,width:e.scrollWidth}}function xr(e,t){let n=pt(e).getComputedStyle(e),r=(n.animationName.split(`,`).map(e=>e.trim()).some(e=>e!==``&&e!==`none`)||t)&&Sr(n.animationDuration),i=Sr(n.transitionDuration);return r&&i||i?`css-transition`:r?`css-animation`:`none`}function Sr(e){return e.split(`,`).map(e=>e.trim()).some(e=>e!==``&&Number.parseFloat(e)>0)}function Cr(e,t,n){let r=e.style.getPropertyValue(t),i=e.style.getPropertyPriority(t);return e.style.setProperty(t,n),()=>{if(r===``){e.style.removeProperty(t);return}e.style.setProperty(t,r,i)}}function wr(e){let t={"justify-content":e.style.justifyContent,"align-items":e.style.alignItems,"align-content":e.style.alignContent,"justify-items":e.style.justifyItems};Object.keys(t).forEach(t=>{e.style.setProperty(t,`initial`,`important`)});function n(){Object.entries(t).forEach(([t,n])=>{if(n===``){e.style.removeProperty(t);return}e.style.setProperty(t,n)})}let r=B.request(n);return()=>{B.cancel(r),n()}}var Tr=`--collapsible-panel-height`,Er=`--collapsible-panel-width`,Dr=J.forwardRef(function(e,t){let{className:n,hiddenUntilFound:r,keepMounted:i,render:a,id:o,style:s,...c}=e,{defaultPanelId:l,mounted:u,onOpenChange:d,open:f,setMounted:p,setPanelIdState:m,setOpen:h,state:g,transitionStatus:_}=cr(),v=r??!1,y=i??!1,b=o||void 0,x=b??l;Ut(()=>(m(e=>b??(e===null?void 0:e)),()=>{m(e=>e===b?null:e)}),[b,m]);let{height:S,props:C,ref:w,shouldPreventOpenAnimation:T,shouldRender:E,transitionStatus:D,width:O}=br({externalRef:t,hiddenUntilFound:v,id:x,keepMounted:y,mounted:u,onOpenChange:d,open:f,setMounted:p,setOpen:h,transitionStatus:_}),k={...g,transitionStatus:D},A=oe(s,k),j=ht(`div`,{...e,style:void 0},{state:k,ref:w,props:[C,{style:{[Tr]:S===void 0?`auto`:`${S}px`,[Er]:O===void 0?`auto`:`${O}px`}},c,A?{style:A}:void 0,T?{style:{animationName:`none`}}:void 0],stateAttributesMapping:gr});return E?j:null}),Or=N(`caps-disclosure`,{variants:{tone:{neutral:``,error:`caps-disclosure-error`},size:{group:`caps-disclosure-group`,row:`caps-disclosure-row`}},defaultVariants:{tone:`neutral`,size:`group`}});function kr({open:e,onOpenChange:t,summary:n,leading:r,trailing:i,children:a,tone:o,size:s,className:c}){return(0,Y.jsxs)(_r,{className:L(Or({tone:o,size:s}),c),onOpenChange:t,open:e,children:[(0,Y.jsxs)(yr,{className:`caps-disclosure-trigger`,children:[r===void 0?null:(0,Y.jsx)(`span`,{className:`caps-disclosure-leading`,children:r}),(0,Y.jsx)(`span`,{className:`caps-disclosure-summary`,children:n}),i===void 0?null:(0,Y.jsx)(`span`,{className:`caps-disclosure-trailing`,children:i}),(0,Y.jsx)(er,{"aria-hidden":`true`,className:`caps-disclosure-chevron`,size:12})]}),(0,Y.jsx)(Dr,{className:`caps-disclosure-panel`,children:a})]})}function Ar({app:e,rootPath:t,rootLabel:n=`Computer`,activePath:r,onOpenFile:i,onSelectPath:a,rowHeight:o=32}){let{scope:s,snapshot:c,focusedPath:l,requestPage:u,reload:d}=gn({app:e,rootPath:t,activePath:r}),f=(0,J.useRef)({activePath:r,onOpenFile:i,onSelectPath:a,rootLabel:n});f.current={activePath:r,onOpenFile:i,onSelectPath:a,rootLabel:n};let p=(0,J.useRef)(u);p.current=u;let{model:m}=qn({paths:[],itemHeight:o,initialExpansion:2,flattenEmptyDirectories:!1,composition:{contextMenu:{enabled:!0}},renderRowDecoration:({row:e})=>e.path===`/`?{text:f.current.rootLabel}:null,unsafeCSS:`[data-item-section="content"] { display: flex; align-items: center; }[data-item-path="/"] [data-item-section="decoration"] { justify-content: flex-start; color: inherit; }`,onSelectionChange(e){let t=e[0];t&&(f.current.onSelectPath?.(t),t.endsWith(`/`)?p.current(t,0):t!==f.current.activePath&&f.current.onOpenFile(t))}}),h=(0,J.useRef)(Dn()),g=(0,J.useRef)(null);(0,J.useLayoutEffect)(()=>{Cn(m,h.current),g.current=null},[m,s]),(0,J.useLayoutEffect)(()=>{g.current=null;for(let e of m.getSelectedPaths())!e.endsWith(`/`)&&e!==r&&m.getItem(e)?.deselect()},[r,m]),(0,J.useLayoutEffect)(()=>{if(c.listings.length===0&&(g.current=null),_n(m,c.listings,h.current),!r||g.current===r)return;let e=bn(r,t);if(!e.every(e=>h.current.known.has(e)))return;for(let t of e){let e=m.getItem(t);e&&`expand`in e&&e.expand()}let n=m.getItem(r);n&&(g.current=r,n.select(),m.scrollToPath(r,{focus:!1}))},[r,m,t,s,c.listings]),(0,J.useEffect)(()=>{c.failure&&console.error(`Inkcap directory listing failed`,dn(c.failure))},[c.failure]);let _=c.listings.filter(({request:e})=>e.path===l).sort((e,t)=>e.request.offset-t.request.offset).at(-1)?.listing,v={path:_?.path??l,next:_?.nextOffset??null},y=c.listings.some(({request:e,listing:n})=>e.path===t&&e.offset===0&&n.entries.length===0&&n.nextOffset===null),b=d;return{model:m,page:v,error:c.failure?`${fe(c.failure).message} Your open files remain available.`:``,busy:c.busy,rootEmpty:y,reloadRoot:b,noteCreated:e=>{let t=e.split(`/`).filter(Boolean).at(-1)??``;!hn({name:t,type:``})&&!m.getItem(e)&&m.batch([{type:`add`,path:e}]),b()},loadNext:()=>{v.next!==null&&u(v.path,v.next)}}}var jr=K(H),Mr=K(vt({message:H}));function Nr(e){for(let t of e.errors){let e=Re(Wt(n(Mr(t),e=>e.message),()=>jr(t)));if(e!==void 0&&e.length>0)return e}}var Pr={neutral:`progress-neutral`,primary:`progress-primary`,secondary:`progress-secondary`,accent:`progress-accent`,success:`progress-success`,info:`progress-info`,warning:`progress-warning`,error:`progress-error`},Fr=(0,J.forwardRef)(function({className:e,tone:t=`primary`,...n},r){return(0,Y.jsx)(`progress`,{...n,"data-complete":n.value!==void 0&&Number(n.value)>=Number(n.max??1)?`true`:void 0,className:L(`progress caps-gooey-motion caps-gooey-progress w-full`,Pr[t],e),ref:r})});(0,J.forwardRef)(function({label:e,value:t,max:n,tone:r=`info`,className:i,...a},o){return(0,Y.jsxs)(`div`,{...a,ref:o,className:L(`caps-game-meter`,i),children:[(0,Y.jsxs)(`div`,{className:`caps-game-meter-readout`,children:[(0,Y.jsx)(`span`,{children:e}),(0,Y.jsxs)(`span`,{className:`caps-game-meter-value`,children:[t,` / `,n]})]}),(0,Y.jsx)(Fr,{"aria-label":e,value:t,max:n,tone:r})]})});function Ir({className:e,items:t,onCancel:n,onRemove:r,onRetry:i,rowClassName:a}){return t.length?(0,Y.jsx)(`div`,{"aria-live":`polite`,className:`caps-upload-queue flex w-full min-w-0 flex-col gap-sm ${e??``}`,"data-upload-rows":!0,children:t.map(e=>(0,Y.jsx)(zr,{item:e,onCancel:n,onRemove:r,onRetry:i,...a===void 0?{}:{rowClassName:a}},e.id))}):null}function Lr({action:e,id:t,onAction:n,retry:r=!1}){return e?(0,Y.jsx)(l,{"aria-label":e.accessibleLabel,title:e.label,variant:`ghost`,size:`xs`,className:`motion-reduce:transition-none`,icon:r?(0,Y.jsx)(ar,{}):(0,Y.jsx)(bt,{}),onClick:()=>void n(t),type:`button`}):null}function Rr({item:e}){return(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsx)(`span`,{className:`block min-w-0 truncate`,title:e.name,children:e.name}),(0,Y.jsx)(`div`,{className:`caps-upload-details`,children:(0,Y.jsxs)(`span`,{"aria-live":e.alert?`assertive`:void 0,className:`caps-upload-status min-w-0 break-words`,"data-upload-status":!0,role:e.alert?`alert`:void 0,children:[e.alert??e.statusLabel,` `,e.progressLabel]})})]})}function zr({item:e,onCancel:t,onRemove:n,onRetry:r,rowClassName:i}){return(0,Y.jsxs)(`div`,{className:`caps-upload-row grid w-full min-w-0 max-w-full grid-cols-[2rem_minmax(0,1fr)_auto] items-center gap-sm p-sm text-xs ${i??``}`,children:[e.preview.kind===`image`?(0,Y.jsx)(`img`,{alt:``,className:`caps-upload-preview mask mask-squircle size-8 shrink-0 object-cover`,src:e.preview.url}):(0,Y.jsx)(`span`,{"aria-hidden":`true`,className:`caps-upload-preview mask mask-squircle flex size-8 shrink-0 items-center justify-center bg-base-300`,children:(0,Y.jsx)(rr,{className:`size-4`})}),(0,Y.jsx)(Rr,{item:e}),(0,Y.jsx)(Br,{actions:e.actions,id:e.id,onCancel:t,onRemove:n,onRetry:r}),(0,Y.jsx)(Fr,{"aria-label":`${e.name} progress`,className:`caps-upload-progress`,tone:e.alert?`error`:e.progress===100?`success`:`accent`,max:100,value:e.progress??(e.alert?0:void 0)})]})}function Br({actions:e,id:t,onCancel:n,onRemove:r,onRetry:i}){return(0,Y.jsxs)(`div`,{className:`caps-upload-actions flex min-w-0 flex-wrap justify-end gap-xs`,children:[(0,Y.jsx)(Lr,{action:e.retry,id:t,onAction:i,retry:!0}),(0,Y.jsx)(Lr,{action:e.cancel,id:t,onAction:n}),(0,Y.jsx)(Lr,{action:e.remove,id:t,onAction:r})]})}var Vr={unchecked:`M3.25 5.9 L5.1 7.9 L8.8 3.8`,checked:`M3.25 5.9 L5.1 7.9 L8.8 3.8`,mixed:`M3.4 6 L6 6 L8.6 6`},Hr={blurStdDeviation:.22,alphaSlope:18,alphaIntercept:-8};function Ur({state:e}){let t=`caps-checkbox-${(0,J.useId)().replaceAll(`:`,``)}`,n=(0,J.useRef)(null),r=(0,J.useRef)(e).current,i=(0,J.useRef)(e),a=S();return(0,J.useLayoutEffect)(()=>{if(!n.current)return;let t=e!==`unchecked`,r=i.current!==`unchecked`,o=a||i.current===e;i.current=e;let s=Te(n.current),c=q(s,{ease:`inCubic`,duration:160}),l=en(n.current,{d:{to:Vr[e],...o?jn:q(s,{ease:`outCubic`,duration:200})},"stroke-dashoffset":{to:+!t,...o?jn:t?q(s,{ease:`inOutSine`,duration:260}):c},"stroke-width":o?{to:t?2.4:0,duration:0}:t&&!r?[{to:2.2,...q(s,{ease:`outCubic`,duration:65})},{to:2.4,delay:D(s,120),...An(s,{bounce:.35,duration:220})}]:{to:t?2.4:0,...c}});return()=>{l.cancel()}},[e,a]),(0,Y.jsxs)(`svg`,{className:`caps-checkbox-visual`,width:`24`,height:`24`,viewBox:`0 0 12 12`,"aria-hidden":`true`,focusable:`false`,children:[(0,Y.jsxs)(`defs`,{children:[(0,Y.jsx)(He,{id:`${t}-surface`,transform:`matrix(1 0 0 1 6 6)`}),(0,Y.jsx)(ot,{id:`${t}-shadow`}),(0,Y.jsx)(lt,{id:`${t}-inset`}),(0,Y.jsx)(Ct,{id:`${t}-goo`,values:Hr}),(0,Y.jsxs)(`filter`,{id:`${t}-relief`,x:`-25%`,y:`-25%`,width:`150%`,height:`150%`,colorInterpolationFilters:`sRGB`,children:[(0,Y.jsx)(`feGaussianBlur`,{in:`SourceAlpha`,stdDeviation:`0.28`,result:`relief`}),(0,Y.jsx)(`feSpecularLighting`,{in:`relief`,surfaceScale:`1.2`,specularConstant:`0.55`,specularExponent:`18`,lightingColor:`color-mix(in srgb, var(--color-white) calc(var(--depth) * 100%), var(--color-black))`,result:`light`,children:(0,Y.jsx)(`feDistantLight`,{azimuth:`225`,elevation:`55`})}),(0,Y.jsx)(`feComposite`,{in:`light`,in2:`SourceAlpha`,operator:`in`,result:`clipped-light`}),(0,Y.jsx)(`feBlend`,{in:`SourceGraphic`,in2:`clipped-light`,mode:`screen`})]}),(0,Y.jsx)(`mask`,{id:`${t}-contour`,maskUnits:`userSpaceOnUse`,x:`0`,y:`0`,width:`12`,height:`12`,style:{maskType:`alpha`},children:(0,Y.jsx)(`path`,{ref:n,d:Vr[r],fill:`none`,stroke:`var(--color-white)`,strokeWidth:r===`unchecked`?0:2.4,pathLength:`1`,strokeDasharray:`1`,strokeDashoffset:+(r===`unchecked`),strokeLinecap:`round`,strokeLinejoin:`round`,filter:e===`mixed`?void 0:`url(#${t}-goo)`})}),(0,Y.jsx)(`clipPath`,{id:`${t}-well`,children:(0,Y.jsx)(`rect`,{x:`1`,y:`1`,width:`10`,height:`10`,rx:`2.5`})})]}),(0,Y.jsx)(`rect`,{className:`caps-checkbox-track`,x:`0.5`,y:`0.5`,width:`11`,height:`11`,rx:`3`,filter:`url(#${t}-inset)`}),(0,Y.jsx)(`g`,{clipPath:`url(#${t}-well)`,children:(0,Y.jsx)(`g`,{filter:`url(#${t}-shadow)`,children:(0,Y.jsx)(`g`,{filter:`url(#${t}-relief)`,children:(0,Y.jsx)(`g`,{mask:`url(#${t}-contour)`,children:(0,Y.jsx)(`rect`,{x:`0`,y:`0`,width:`12`,height:`12`,fill:`url(#${t}-surface)`})})})})})]})}var Wr=(0,J.forwardRef)(function({className:e,appearance:t,indicator:n,invalid:r,indeterminate:i=!1,checked:a,defaultChecked:o=!1,onChange:s,...c},l){let u=(0,J.useRef)(null),[d,f]=(0,J.useState)(o),p=a??d,m=i?`mixed`:p?`checked`:`unchecked`;return(0,J.useImperativeHandle)(l,()=>{if(!u.current)throw Error(`Checkbox input is not mounted`);return u.current},[]),(0,J.useLayoutEffect)(()=>{u.current&&(u.current.indeterminate=i)},[i]),(0,J.useEffect)(()=>{let e=u.current?.form;if(!e||a!==void 0)return;let t=e=>{queueMicrotask(()=>{!e.defaultPrevented&&u.current&&f(o)})};return e.addEventListener(`reset`,t),()=>{e.removeEventListener(`reset`,t)}},[a,o,c.form]),(0,Y.jsxs)(`span`,{className:`caps-checkbox`,"data-appearance":t===`compact`?t:void 0,"data-state":m,"data-custom-indicator":n!==void 0||void 0,children:[(0,Y.jsx)(`input`,{...c,checked:p,"aria-checked":i?`mixed`:p,"aria-invalid":r?!0:c[`aria-invalid`]===!1?void 0:c[`aria-invalid`],className:L(`caps-checkbox-input`,e),onChange:e=>{a===void 0&&f(e.target.checked),s?.(e),e.currentTarget.indeterminate=i},ref:u,type:`checkbox`}),n===void 0?(0,Y.jsx)(Ur,{state:m}):n]})}),Gr=Xn({keyCode:Qn(229)});function Kr(e){return e.nativeEvent.isComposing||we(Gr,e.nativeEvent).success}var qr=J.createContext(void 0);function Q(e){let t=J.useContext(qr);if(t===void 0&&!e)throw Error(on(47));return t}var Jr=e(Le(),1),Yr={...z,disabled:e=>e.disabled,instantType:e=>e.instantType===`trigger-change`&&!z.open(e)?void 0:e.instantType,openMethod:e=>e.openMethod,openChangeReason:e=>e.openChangeReason,isPressOpenedByTrigger:(e,t)=>e.openChangeReason===`trigger-press`&&z.isOpenedByTrigger(e,t),isTouchPressOpen:(e,t)=>t&&e.openMethod===`touch`&&e.openChangeReason===`trigger-press`,hasTriggerFocusGuards:(e,t)=>z.isOpenedByTrigger(e,t)&&!e.focusManagerModal,modal:e=>e.modal,titleElementId:e=>e.titleElementId,descriptionElementId:e=>e.descriptionElementId,openOnHover:e=>e.openOnHover,closeDelay:e=>e.closeDelay,adaptiveOrigin:e=>e.adaptiveOrigin},Xr=class extends _{constructor(e,t,n){let r=new nn;super(Zr(e,r,t,n),Qr(r),Yr)}setOpen=(e,t)=>{let n=t.reason===ve,r=t.reason===`trigger-press`&&t.event.detail===0,i=!e&&(t.reason===`escape-key`||t.reason==null),a=w(t),o=this.select(`activeTriggerId`);if(!e&&t.reason===`close-press`&&t.trigger==null&&o!=null&&(t.trigger=this.context.triggerElements.getById(o)??this.select(`activeTriggerElement`)??void 0),this.context.onOpenChange?.(e,t),t.isCanceled)return;this.state.floatingRootContext.dispatchOpenChange(e,t);let s=()=>{let n=Ae(this.state,e,t.trigger,a());n.openChangeReason=t.reason,this.update(n)};n?(this.context.stickIfOpen=!0,this.context.stickIfOpenTimeout.start(500,()=>{this.context.stickIfOpen=!1}),Jr.flushSync(s)):s();let c;r?c=`click`:i?c=`dismiss`:t.reason===`focus-out`&&(c=`focus`),this.set(`instantType`,c)}};function Zr(e,t,n,r=!1){let i={...ae(t,n,r),disabled:!1,modal:!1,focusManagerModal:!1,instantType:void 0,openMethod:null,openChangeReason:null,titleElementId:void 0,descriptionElementId:void 0,openOnHover:!1,closeDelay:0,adaptiveOrigin:void 0,...e};return i.open&&e?.mounted===void 0&&(i.mounted=!0),i}function Qr(e){return{popupRef:J.createRef(),onOpenChange:void 0,onOpenChangeComplete:void 0,triggerFocusTargetRef:J.createRef(),beforeTriggerFocusGuardRef:J.createRef(),beforeContentFocusGuardRef:J.createRef(),stickIfOpenTimeout:new he,stickIfOpen:!0,triggerElements:e}}var $r=k(function({props:e}){let{children:t,open:n,defaultOpen:r=!1,onOpenChange:i,onOpenChangeComplete:a,modal:o=!1,handle:s,triggerId:c,defaultTriggerId:l=null}=e,u=ti(s,{modal:o,open:r,openProp:n,activeTriggerId:l,triggerIdProp:c});u.useControlledProp(`openProp`,n),u.useControlledProp(`triggerIdProp`,c);let d=u.useState(`open`),f=u.useState(`mounted`),p=u.useState(`payload`);u.useContextCallback(`onOpenChange`,i),u.useContextCallback(`onOpenChangeComplete`,a),Ie(u,d),y(u);let{forceUnmount:m}=P(d,u,()=>{u.context.stickIfOpen=!0,u.set(`openChangeReason`,null)});u.useSyncedValues({modal:o}),J.useEffect(()=>{d||u.context.stickIfOpenTimeout.clear()},[u,d]),J.useImperativeHandle(e.actionsRef,()=>({unmount:m,close:()=>u.setOpen(!1,C(Mt))}),[m,u]);let h=d||f||s!=null;return(0,Y.jsxs)(qr.Provider,{value:u,children:[s&&(0,Y.jsx)(Ee,{handle:s,store:u}),h&&(0,Y.jsx)(ni,{store:u,modal:o}),typeof t==`function`?t({payload:p}):t]})});function ei(e){return Q(!0)?(0,Y.jsx)($r,{props:e}):(0,Y.jsx)(Et,{children:(0,Y.jsx)($r,{props:e})})}function ti(e,t){let n=j((e,n)=>new Xr(t,e,n));return J.useEffect(()=>n.context.stickIfOpenTimeout.disposeEffect(),[n]),n}function ni({store:e,modal:t}){let n=e.useState(`floatingRootContext`),r=le(n,{outsidePressEvent:{mouse:t===`trap-focus`?`sloppy`:`intentional`,touch:`sloppy`}}),i=r.reference,a=r.floating;return Nt(e,{activeTriggerProps:i,inactiveTriggerProps:i,popupProps:a}),null}var ri=R(function(e,n){let{render:r,className:a,style:o,disabled:s=!1,nativeButton:c=!0,handle:l,payload:u,openOnHover:d=!1,delay:f=300,closeDelay:p=0,id:m,...h}=e,_=Q(!0),v=ie(l)??_;if(!v)throw Error(on(74));let y=It(m),b=v.useState(`isTriggerActive`,y),x=v.useState(`floatingRootContext`),S=v.useState(`isOpenedByTrigger`,y),C=v.useState(`triggerPopupId`,y),w=J.useRef(null),{registerTrigger:T,isMountedByThisTrigger:E}=Pe(y,w,v,{payload:u,disabled:s,openOnHover:d,closeDelay:p}),D=v.useState(`isPressOpenedByTrigger`,y),O=v.useState(`isTouchPressOpen`,d),k=v.useState(`hasTriggerFocusGuards`,y),A=i(x,{enabled:!s&&d&&!O,mouseOnly:!0,move:!1,handleClose:gt(),restMs:f,delay:{close:p},triggerElementRef:w,isActiveTrigger:b,isClosing:()=>v.select(`transitionStatus`)===`ending`}),j=W(()=>v.context.stickIfOpen),M=t(x,{stickIfOpen:j}),N=Xt(()=>v.select(`open`),e=>{v.set(`openMethod`,e)}),P=v.useState(`triggerProps`,E),{getButtonProps:F,buttonRef:I}=Be({disabled:s,native:c}),L={open(e){return D?xe.open(e):g.open(e)}},{handlePreFocusGuardFocus:R,handleFocusTargetFocus:ee}=at(v,w),te=ht(`button`,e,{state:{disabled:s,open:S},ref:[I,n,T,w],props:[M.reference,A,P,N,{[Ze]:``,id:y,"aria-haspopup":`dialog`,"aria-expanded":S,"aria-controls":C},h,F],stateAttributesMapping:L}),ne=(0,Y.jsx)(J.Fragment,{children:te},y);return k?(0,Y.jsxs)(J.Fragment,{children:[(0,Y.jsx)(tn,{ref:v.context.beforeTriggerFocusGuardRef,onFocus:R}),ne,(0,Y.jsx)(tn,{ref:v.context.triggerFocusTargetRef,onFocus:ee})]}):ne}),ii=J.createContext(void 0);function ai(){let e=J.useContext(ii);if(e===void 0)throw Error(on(45));return e}var oi=J.forwardRef(function(e,t){let{keepMounted:n=!1,...r}=e;return Q().useState(`mounted`)||n?(0,Y.jsx)(ii.Provider,{value:n,children:(0,Y.jsx)(Ht,{ref:t,...r})}):null}),si=J.createContext(void 0);function ci(){let e=J.useContext(si);if(!e)throw Error(on(46));return e}var li=J.forwardRef(function(e,t){let{render:n,className:r,style:i,anchor:a,positionMethod:o,side:s,align:c,sideOffset:l,alignOffset:u,collisionBoundary:f=`clipping-ancestors`,collisionPadding:p,arrowPadding:m,sticky:h,disableAnchorTracking:g=!1,collisionAvoidance:_=Yt,...v}=e,y=Q(),b=ai(),x=Rt(),S=y.useState(`floatingRootContext`),C=y.useState(`mounted`),w=y.useState(`open`),T=y.useState(`openChangeReason`),E=y.useState(`activeTriggerElement`),D=y.useState(`modal`),O=y.useState(`openMethod`),k=y.useState(`positionerElement`),A=y.useState(`instantType`),j=y.useState(`transitionStatus`),M=y.useState(`adaptiveOrigin`),N=d({anchor:a,floatingRootContext:S,positionMethod:o,mounted:C,side:s,sideOffset:l,align:c,alignOffset:u,arrowPadding:m,collisionBoundary:f,collisionPadding:p,sticky:h,disableAnchorTracking:g,keepMounted:b,nodeId:x,collisionAvoidance:_,adaptiveOrigin:M}),P=S.useState(`domReferenceElement`);Qt({store:y,domReference:P,positionerElement:k,open:w});let F=D===!0&&T!==`trigger-hover`;$t(w&&F,O===`touch`,k,E);let I=y.useStateSetter(`positionerElement`),L={open:w,side:N.side,align:N.align,anchorHidden:N.anchorHidden,instant:A},R=Ke(e,L,{styles:N.positionerStyles,transitionStatus:j,props:v,refs:[t,I],hidden:!C,inert:!w});return(0,Y.jsxs)(si.Provider,{value:N,children:[C&&F&&(0,Y.jsx)(ge,{inert:be(!w),cutout:E}),(0,Y.jsx)(Gt,{id:x,children:R})]})}),ui=J.createContext(void 0);function di(){let[e,t]=J.useState(0),n=W(()=>(t(e=>e+1),()=>{t(e=>Math.max(0,e-1))}));return{context:J.useMemo(()=>({register:n}),[n]),hasClosePart:e>0}}var fi=J.forwardRef(function(e,t){let{render:n,className:r,style:i,initialFocus:a,finalFocus:s,...c}=e,l=Q(),d=ci(),f=se(!0)!=null,{context:m,hasClosePart:g}=di(),_=l.useState(`open`),v=l.useState(`openMethod`),y=l.useState(`instantType`),b=l.useState(`transitionStatus`),x=l.useState(`popupProps`),S=l.useState(`titleElementId`),C=l.useState(`descriptionElementId`),w=l.useState(`modal`),T=l.useState(`mounted`),E=l.useState(`openChangeReason`),D=l.useState(`activeTriggerElement`),O=l.useState(`floatingRootContext`),k=O.useState(`floatingId`),A=l.useState(`disabled`),j=l.useState(`openOnHover`),M=l.useState(`closeDelay`);u({open:_,ref:l.context.popupRef,onComplete(){_&&l.context.onOpenChangeComplete?.(!0)}}),mt(O,{enabled:j&&!A,closeDelay:M});let N=a===void 0?Se(l.context.popupRef):a,P=w!==!1&&g;l.useSyncedValue(`focusManagerModal`,P);let F=l.useStateSetter(`popupElement`),I={open:_,side:d.side,align:d.align,instant:y,transitionStatus:b},L=ht(`div`,e,{state:I,ref:[t,l.context.popupRef,F],props:[x,{id:k,role:`dialog`,...o,"aria-labelledby":S,"aria-describedby":C,onKeyDown(e){f&&p.has(e.key)&&e.stopPropagation()}},h(b),c],stateAttributesMapping:Zt});return(0,Y.jsx)(nt,{context:O,openInteractionType:v,modal:P,disabled:!T||E===`trigger-hover`,initialFocus:N,returnFocus:s,restoreFocus:`popup`,getInsideElements:()=>[l.context.beforeTriggerFocusGuardRef.current],previousFocusableElement:Ot(D)?D:void 0,nextFocusableElement:l.context.triggerFocusTargetRef,beforeContentFocusGuardRef:l.context.beforeContentFocusGuardRef,children:(0,Y.jsx)(ui.Provider,{value:m,children:L})})});function pi({getKey:e,isDisabled:t=()=>!1,items:n,getFallbackKey:r}){let i=(0,J.useMemo)(()=>{let r=n.map(e);if(r.some(e=>!e))throw Error(`Selectable items require non-empty keys`);if(new Set(r).size!==r.length)throw Error(`Selectable items require unique keys`);return n.filter(e=>!t(e))},[e,t,n]),[a,o]=(0,J.useState)(null),s=r?.(i)??null,c=a!==null&&i.some(t=>e(t)===a)?a:s!==null&&i.some(t=>e(t)===s)?s:null;(0,J.useEffect)(()=>{a!==null&&!i.some(t=>e(t)===a)&&o(null)},[a,i,e]);let l=i.find(t=>e(t)===c),u=l?i.findIndex(t=>e(t)===c):-1;return{activeIndex:u,activeItem:l,activeKey:c,enabledItems:i,move:(t,n)=>{if(i.length===0)return;let r=n?n===`start`?0:i.length-1:u<0?t>0?0:i.length-1:(u+t+i.length)%i.length,a=i[r];a&&o(e(a))},setActiveKey:o}}var mi=(0,J.forwardRef)(function({children:e,className:t,type:n=`button`,...r},i){return(0,Y.jsxs)(`button`,{...r,ref:i,type:n,className:L(`select caps-select caps-combobox-trigger w-full`,t),children:[(0,Y.jsx)(`span`,{children:e}),(0,Y.jsx)(yn,{className:`caps-select-chevron`,"aria-hidden":`true`})]})});function hi({defaultInputValue:e,defaultOpen:t,defaultValue:n,getKey:r,getSearchText:i,groupBy:a,id:o,isDisabled:s,items:c,onOpenChange:l,onCommit:u,multiple:d,controlledOpen:f,controlledKeys:p,trigger:m}){let h=`${o}-listbox`,[g,_]=(0,J.useState)(e),[v,y]=(0,J.useState)(!1),[b,x]=(0,J.useState)(n),[S,C]=(0,J.useState)(t),w=p??(b===null?[]:[b]),T=m?f??S:!0,E=(0,J.useMemo)(()=>{let e=g.trim().toLowerCase();return e?c.filter(t=>i(t).toLowerCase().includes(e)):c},[i,c,g]),D=pi({getKey:r,isDisabled:s,items:E});(0,J.useEffect)(()=>{if(D.activeKey!==null)return;let e=D.enabledItems.find(e=>w.includes(r(e)))??D.enabledItems[0];e&&D.setActiveKey(r(e))},[D.activeKey,D.enabledItems,D.setActiveKey,r,w]);let O=e=>{y(!1),e||_(``),f===void 0&&C(e),l?.(e)},k=e=>`${h}-option-${encodeURIComponent(e)}`,A=e=>{let t=r(e);p===void 0&&x(t),u(e),m&&!d&&O(!1)},j=e=>{y(!0),_(e.target.value),D.setActiveKey(null)},M=e=>{if(Kr(e))return;let t;switch(e.key){case`ArrowDown`:t=[1,void 0];break;case`ArrowUp`:t=[-1,void 0];break;case`End`:t=[1,`end`];break;case`Home`:t=[-1,`start`]}t?(y(!0),e.preventDefault(),D.move(t[0],t[1])):e.key===`Enter`&&D.activeItem&&(e.preventDefault(),A(D.activeItem))},N=(0,J.useMemo)(()=>{if(!a)return[{label:``,items:E}];let e=new Map;for(let t of E){let n=a(t),r=e.get(n);r?r.push(t):e.set(n,[t])}return[...e].map(([e,t])=>({label:e,items:t}))},[E,a]);return{keyboardNavigation:v,onPointerMove:()=>{y(!1)},activeKey:D.activeKey,activeItem:D.activeItem,groups:N,inputValue:g,listboxId:h,onInputChange:j,onInputKeyDown:M,optionId:k,open:T,commit:A,selectedKeys:w,setOpen:O}}function gi(e){let{"aria-describedby":t,"aria-invalid":n,"aria-label":r,"aria-labelledby":i,"aria-required":a,activeTone:o=`neutral`,container:s,contentClassName:c,defaultInputValue:l=``,defaultOpen:u=!1,defaultValue:d=null,emptyMessage:f=`No matches`,getKey:p,getLabel:m,getSearchText:h=m,groupBy:g,id:_,inputProps:v,inputRef:y,isDisabled:b=()=>!1,items:x,onOpenChange:S,onValueChange:C,multiple:w,open:T,placeholder:E=`Search…`,renderItem:D,rootRef:O,trigger:k,triggerRef:A,value:j,...M}=e,N=e=>{let t=p(e);if(w){let e=j.includes(t)?j.filter(e=>e!==t):[...j,t];C?.(e,x.filter(t=>e.includes(p(t))))}else C?.(t,e)},P;w?P=j:j!==void 0&&(P=j===null?[]:[j]);let F=(0,J.useId)(),I=k?.props??v,R=_??I?.id??F,ee={id:R,"aria-describedby":[t,I?.[`aria-describedby`]].filter(Boolean).join(` `)||void 0,"aria-invalid":n??I?.[`aria-invalid`],"aria-label":I?.[`aria-label`]??r,"aria-labelledby":I?.[`aria-labelledby`]??i,"aria-required":a??I?.[`aria-required`]},{keyboardNavigation:te,onPointerMove:ne,activeItem:re,activeKey:ie,commit:ae,groups:oe,inputValue:se,listboxId:z,onInputChange:ce,onInputKeyDown:le,open:ue,optionId:de,selectedKeys:fe,setOpen:pe}=hi({defaultInputValue:l,defaultOpen:u,defaultValue:d,getKey:p,getSearchText:h,groupBy:g,id:R,isDisabled:b,items:x,onOpenChange:S,onCommit:N,multiple:w??!1,controlledOpen:T,controlledKeys:P,trigger:k});kt(()=>{k&&pe(!1)});let me=xt(`popover`),he=s===void 0?me:s,ge=st(`.caps-combobox-option[data-active="true"]:not(:disabled), [data-navigation="pointer"] .caps-combobox-option:hover:not(:disabled)`),_e=(0,Y.jsx)(Bn,{...v,...k?{}:ee,"aria-activedescendant":re?de(p(re)):void 0,"aria-autocomplete":`list`,"aria-controls":z,"aria-expanded":!0,className:L(`input-sm`,v?.className),id:k?v?.id??`${R}-input`:R,onChange:e=>{v?.onChange?.(e),ce(e)},onKeyDown:e=>{v?.onKeyDown?.(e),e.defaultPrevented||le(e)},placeholder:v?.placeholder??E,ref:y,role:`combobox`,value:se}),ve=(0,Y.jsx)(`div`,{id:z,ref:ge,className:`caps-combobox-list`,"data-navigation":te?`keyboard`:`pointer`,onPointerMove:ne,role:`listbox`,"aria-multiselectable":w??void 0,children:oe.every(e=>e.items.length===0)?(0,Y.jsx)(`div`,{className:`px-md py-md text-sm text-base-content`,children:f}):oe.map(e=>(0,Y.jsxs)(`div`,{"aria-label":e.label||void 0,role:e.label?`group`:void 0,children:[e.label?(0,Y.jsx)(`div`,{className:`px-md pb-xs pt-sm text-xs text-base-content uppercase tracking-wider`,children:e.label}):null,e.items.map(e=>{let t=p(e),n=b(e),r=ie===t,i={active:r,disabled:n,selected:fe.includes(t)};return(0,Y.jsxs)(`button`,{"aria-disabled":n||void 0,"aria-selected":i.selected,className:`caps-combobox-option`,"data-active":r&&te,disabled:n,id:de(t),onClick:()=>{ae(e)},onMouseDown:e=>{e.preventDefault()},role:`option`,tabIndex:-1,type:`button`,children:[(0,Y.jsx)(`span`,{"aria-hidden":`true`,className:`caps-combobox-check`,children:i.selected?(0,Y.jsx)($n,{}):null}),D?.(e,r,i)??m(e)]},t)})]},e.label))});return k?(0,Y.jsx)(`div`,{...M,className:L(M.className),ref:O,children:(0,Y.jsxs)(ei,{modal:!0,onOpenChange:pe,open:ue,children:[(0,Y.jsx)(ri,{...ee,"aria-haspopup":`dialog`,className:`btn`,ref:A,render:k}),he===null?null:(0,Y.jsx)(oi,{container:he,children:(0,Y.jsx)(li,{align:`start`,side:`bottom`,sideOffset:4,className:`z-(--stipe-layer-popover)`,children:(0,Y.jsxs)(fi,{"data-active-tone":o,className:L(`min-w-40 rounded-box border border-base-300 bg-base-100 p-xs shadow-lg outline-none caps-combobox-panel caps-combobox-popup`,c),children:[(0,Y.jsx)(`div`,{className:`caps-combobox-search`,children:_e}),ve]})})})]})}):(0,Y.jsx)(`div`,{...M,className:L(M.className),ref:O,children:(0,Y.jsxs)(`div`,{className:L(`caps-combobox-panel`,c),"data-active-tone":o,children:[(0,Y.jsx)(`div`,{className:`caps-combobox-search`,children:_e}),ve]})})}function _i({icon:e,caption:t}){return(0,Y.jsxs)(`span`,{className:`caps-icon-choice-mark`,"aria-hidden":`true`,children:[(0,Y.jsx)(`span`,{className:`caps-icon-choice-art`,children:e}),t?(0,Y.jsx)(`span`,{className:`caps-icon-choice-caption`,children:t}):null,(0,Y.jsx)(`span`,{className:`caps-icon-choice-lamp`})]})}var vi=(0,J.forwardRef)(function({label:e,icon:t,caption:n,appearance:r,className:i,...a},o){return(0,Y.jsx)(`label`,{className:`caps-icon-choice`,"data-appearance":r===`compact`?r:void 0,children:(0,Y.jsx)(Wr,{...a,appearance:r??`default`,"aria-label":e,className:L(`caps-icon-choice-input`,i),indicator:(0,Y.jsx)(_i,{icon:t,caption:n}),ref:o})})}),yi=(0,J.forwardRef)(function({label:e,icon:t,hint:n,className:r,...i},a){let o=(0,J.useId)(),s=[i[`aria-describedby`],n?o:null].filter(Boolean).join(` `)||void 0;return(0,Y.jsx)(`label`,{className:`caps-check-key`,children:(0,Y.jsx)(Wr,{...i,"aria-label":e,"aria-describedby":s,className:L(`caps-check-key-input`,r),indicator:(0,Y.jsxs)(`span`,{className:`caps-check-key-face`,"aria-hidden":`true`,children:[t?(0,Y.jsx)(`span`,{className:`caps-check-key-icon`,children:t}):null,(0,Y.jsxs)(`span`,{className:`caps-check-key-copy`,children:[(0,Y.jsx)(`span`,{className:`caps-check-key-label`,children:e}),n?(0,Y.jsx)(`span`,{className:`caps-check-key-hint`,id:o,children:n}):null]}),(0,Y.jsx)(`span`,{className:`caps-check-key-lamp`})]}),ref:a})})});function bi({className:e,...t}){return(0,Y.jsx)(`div`,{...t,className:L(`caps-check-keys`,e)})}function xi({checked:e}){let t=`caps-radio-${(0,J.useId)().replaceAll(`:`,``)}`,n=(0,J.useRef)(null),r=(0,J.useRef)(e).current,i=(0,J.useRef)(e),a=(0,J.useRef)(null),o=Ne(a),{reduced:s}=o;return(0,J.useLayoutEffect)(()=>{if(!n.current)return;let t=s||i.current===e;i.current=e;let r=e?4:0,a=q(o,{ease:`outCubic`,duration:75}),c=e?An(o,{bounce:.65,duration:300}):q(o,{ease:`inCubic`,duration:100}),l=en(n.current,t?{rx:r,ry:r,cy:6,duration:0}:{rx:[{to:e?3.5:4.15,...a},{to:r,...c}],ry:[{to:e?4.5:3.85,...a},{to:r,...c}],cy:[{to:e?5.85:6.1,...a},{to:6,...c}]});return()=>{l.cancel()}},[e,s,o]),(0,Y.jsxs)(`svg`,{ref:a,className:`caps-radio-visual`,width:`24`,height:`24`,viewBox:`0 0 12 12`,"aria-hidden":`true`,focusable:`false`,children:[(0,Y.jsxs)(`defs`,{children:[(0,Y.jsx)(He,{id:`${t}-surface`,transform:`matrix(1 0 0 1 6 6)`}),(0,Y.jsx)(ot,{id:`${t}-shadow`}),(0,Y.jsx)(lt,{id:`${t}-inset`}),(0,Y.jsx)(`clipPath`,{id:`${t}-well`,children:(0,Y.jsx)(`circle`,{cx:`6`,cy:`6`,r:`5`})})]}),(0,Y.jsx)(`circle`,{className:`caps-radio-track`,cx:`6`,cy:`6`,r:`5.5`,filter:`url(#${t}-inset)`}),(0,Y.jsx)(`g`,{clipPath:`url(#${t}-well)`,children:(0,Y.jsx)(`ellipse`,{ref:n,cx:`6`,cy:`6`,rx:r?4:0,ry:r?4:0,fill:`url(#${t}-surface)`,filter:`url(#${t}-shadow)`})})]})}var Si=(0,J.createContext)(null),Ci=(0,J.forwardRef)(function({children:e,className:t,defaultValue:n,disabled:r=!1,name:i,onValueChange:a,orientation:o=`vertical`,value:s,...c},l){let u=(0,J.useId)(),d=(0,J.useRef)(null);(0,J.useImperativeHandle)(l,()=>{if(!d.current)throw Error(`RadioGroup is not mounted`);return d.current},[]);let f=i??`radio-group-${u}`,[p,m]=(0,J.useState)(n),h=s??p;return(0,J.useEffect)(()=>{let e=d.current?.form;if(!e||s!==void 0)return;let t=e=>{queueMicrotask(()=>{e.defaultPrevented||m(n)})};return e.addEventListener(`reset`,t),()=>{e.removeEventListener(`reset`,t)}},[s,n,c.form]),(0,Y.jsx)(Si.Provider,{value:{disabled:r,name:f,onValueChange:e=>{s===void 0&&m(e),a?.(e)},value:h},children:(0,Y.jsx)(`fieldset`,{...c,className:L(`flex gap-md`,o===`horizontal`?`flex-row flex-wrap`:`flex-col`,t),disabled:r,role:c.role??`radiogroup`,ref:d,children:e})})}),wi=(0,J.forwardRef)(function({className:e,indicator:t,onChange:n,onClick:r,value:i,...a},o){let s=(0,J.useContext)(Si);if(!s)throw Error(`RadioGroupItem must be used inside <RadioGroup>`);let c=s.value===i,l=e=>{n?.(e),e.target.checked&&s.onValueChange?.(i)};return(0,Y.jsxs)(`span`,{className:`caps-radio`,"data-checked":c,"data-custom-indicator":t!==void 0||void 0,children:[(0,Y.jsx)(`input`,{...a,"aria-checked":c,checked:c,className:L(`caps-radio-input`,e),disabled:s.disabled||a.disabled,name:s.name,onChange:l,onClick:r,ref:o,type:`radio`,value:i}),t===void 0?(0,Y.jsx)(xi,{checked:c}):t]})}),Ti=(0,J.forwardRef)(function({description:e,id:t,meta:n,title:r,...i},a){let o=(0,J.useContext)(Si),s=(0,J.useId)(),c=t??s,l=o?.value===i.value,u=o?.disabled===!0||i.disabled===!0;return(0,Y.jsxs)(`label`,{className:`caps-choice-card`,"data-checked":l,"data-disabled":u||void 0,htmlFor:c,children:[(0,Y.jsx)(wi,{...i,"aria-describedby":e?`${c}-description`:void 0,"aria-labelledby":`${c}-title`,id:c,ref:a}),(0,Y.jsxs)(`span`,{className:`caps-choice-card-copy`,children:[(0,Y.jsx)(`span`,{className:`caps-choice-card-title`,id:`${c}-title`,children:r}),e?(0,Y.jsx)(`span`,{className:`caps-choice-card-description`,id:`${c}-description`,children:e}):null]}),n?(0,Y.jsx)(`span`,{className:`caps-choice-card-meta`,children:n}):null]})}),Ei=(0,J.forwardRef)(function({label:e,icon:t,caption:n,art:r=`dim`,className:i,...a},o){return(0,Y.jsx)(`label`,{className:`caps-icon-choice`,"data-art":r===`color`?r:void 0,children:(0,Y.jsx)(wi,{...a,"aria-label":e,className:L(`caps-icon-choice-input`,i),indicator:(0,Y.jsx)(_i,{icon:t,caption:n}),ref:o})})});(0,J.forwardRef)(function({label:e,color:t,className:n,...r},i){return(0,Y.jsx)(`label`,{className:`caps-icon-choice`,"data-art":`color`,"data-swatch":``,title:e,children:(0,Y.jsx)(wi,{...r,"aria-label":e,className:L(`caps-icon-choice-input`,n),indicator:(0,Y.jsx)(_i,{icon:(0,Y.jsx)(`span`,{className:`caps-swatch-dot`,style:{backgroundColor:t}})}),ref:i})})});var Di=(0,J.forwardRef)(function({className:e,invalid:t,...n},r){return(0,Y.jsxs)(`span`,{className:`caps-select-shell`,children:[(0,Y.jsx)(`select`,{...n,"aria-invalid":t?!0:n[`aria-invalid`]===!1?void 0:n[`aria-invalid`],className:L(`select select-bordered caps-select w-full`,t&&`select-error`,e),ref:r}),!n.multiple&&(!n.size||n.size<=1)?(0,Y.jsx)(yn,{className:`caps-select-chevron`,"aria-hidden":`true`}):null]})});function Oi({checked:e}){let t=`caps-switch-${(0,J.useId)().replaceAll(`:`,``)}`,n=(0,J.useRef)(null),r=(0,J.useRef)(null),i=(0,J.useRef)(e).current,a=(0,J.useRef)(e),o=S();return(0,J.useLayoutEffect)(()=>{if(!n.current||!r.current)return;let t=o||a.current===e;a.current=e;let i=e?16:8,s=Te(n.current),c=An(s,{bounce:.25,duration:440}),l=q(s,{ease:`inOutSine`,duration:100}),u=en(n.current,t?{x:2,y:2,width:i,height:8,duration:0}:{x:[{to:e?2.5:1.5,...l},{to:2,...c}],y:[{to:1.5,...l},{to:2,...c}],height:[{to:9,...l},{to:8,...c}],width:[{to:e?7:16.5,...l},{to:i,...c}]}),d=en(r.current,{gradientTransform:e?`matrix(2 0 0 1 10 6)`:`matrix(1 0 0 1 6 6)`,...t?{duration:0}:{delay:l.duration,...c}});return()=>{u.cancel(),d.cancel()}},[e,o]),(0,Y.jsxs)(`svg`,{className:`caps-switch-visual`,width:`40`,height:`24`,viewBox:`0 0 20 12`,"aria-hidden":`true`,focusable:`false`,children:[(0,Y.jsxs)(`defs`,{children:[(0,Y.jsx)(He,{ref:r,id:`${t}-surface`,transform:i?`matrix(2 0 0 1 10 6)`:`matrix(1 0 0 1 6 6)`}),(0,Y.jsx)(ot,{id:`${t}-shadow`}),(0,Y.jsx)(lt,{id:`${t}-inset`}),(0,Y.jsx)(`clipPath`,{id:`${t}-track`,children:(0,Y.jsx)(`rect`,{x:`1`,y:`1`,width:`18`,height:`10`,rx:`5`})})]}),(0,Y.jsx)(`rect`,{className:`caps-switch-track`,filter:`url(#${t}-inset)`,x:`0.5`,y:`0.5`,width:`19`,height:`11`,rx:`5.5`}),(0,Y.jsx)(`g`,{clipPath:`url(#${t}-track)`,children:(0,Y.jsx)(`rect`,{ref:n,x:`2`,y:`2`,width:i?16:8,height:`8`,rx:`4`,fill:`url(#${t}-surface)`,filter:`url(#${t}-shadow)`})})]})}var ki=(0,J.forwardRef)(function({className:e,checked:t,defaultChecked:n=!1,onChange:r,onCheckedChange:i,...a},o){let s=(0,J.useRef)(null),[c,l]=(0,J.useState)(n),u=t??c;return(0,J.useImperativeHandle)(o,()=>{if(!s.current)throw Error(`Switch input is not mounted`);return s.current},[]),(0,J.useEffect)(()=>{let e=s.current?.form;if(!e||t!==void 0)return;let r=e=>{queueMicrotask(()=>{!e.defaultPrevented&&s.current&&l(n)})};return e.addEventListener(`reset`,r),()=>{e.removeEventListener(`reset`,r)}},[t,n,a.form]),(0,Y.jsxs)(`span`,{className:`caps-switch`,"data-checked":u,children:[(0,Y.jsx)(`input`,{...a,checked:u,className:L(`caps-switch-input`,e),onChange:e=>{t===void 0&&l(e.target.checked),r?.(e),i?.(e.target.checked)},ref:s,role:`switch`,type:`checkbox`}),(0,Y.jsx)(Oi,{checked:u})]})}),Ai=(0,J.forwardRef)(function({className:e,invalid:t,...n},r){return(0,Y.jsx)(`textarea`,{...n,"aria-invalid":t?!0:n[`aria-invalid`]===!1?void 0:n[`aria-invalid`],className:L(`textarea textarea-bordered w-full`,t&&`textarea-error`,e),ref:r})}),ji=K(H),Mi=K(r),Ni=K(We(et)),Pi=K(de(H)),Fi=de(_e(File)),Ii=K(Fi),Li=At([H,et,r,dt,rt,de(H),Fi]),Ri=K(Li),$=e=>V(ji(e.state.value),()=>``),zi=e=>V(Mi(e.state.value),()=>!1),Bi=e=>V(Ni(e.state.value),()=>null),Vi=e=>V(Pi(e.state.value),()=>[]),Hi=e=>V(Ii(e.state.value),()=>[]),Ui=e=>V(Ri(e.state.value),()=>null);function Wi({field:e,spec:t,locked:n,...r}){let[i,a]=(0,J.useState)(!1);return(0,Y.jsxs)(Pn,{children:[(0,Y.jsx)(Bn,{...r,name:t.name,disabled:n,type:i?`text`:`password`,autoComplete:`off`,spellCheck:!1,className:`caps-field-secret`,placeholder:t.placeholder,readOnly:t.readOnly,value:$(e),onBlur:e.handleBlur,onChange:t=>{e.handleChange(t.currentTarget.value)}}),(0,Y.jsx)(U,{type:`button`,variant:`outline`,size:`icon`,"aria-label":i?`Hide`:`Show`,"aria-pressed":i,disabled:n,onClick:()=>{a(e=>!e)},children:i?(0,Y.jsx)(tr,{"aria-hidden":`true`}):(0,Y.jsx)(nr,{"aria-hidden":`true`})})]})}var Gi={text:`text`,email:`email`,url:`url`,tel:`tel`};function Ki({spec:e,field:t,locked:n,...r}){let i=Hi(t),a=n||e.readOnly===!0,o=(0,J.useRef)(null);return(0,Y.jsxs)(`div`,{className:`flex flex-col gap-sm`,children:[(0,Y.jsx)(re,{asChild:!0,children:(0,Y.jsx)(`input`,{...r,ref:o,type:`file`,tabIndex:-1,required:r.required===!0&&i.length===0,name:e.name,accept:e.accept,multiple:e.multiple,disabled:a,onBlur:t.handleBlur,onChange:e=>{t.handleChange(Array.from(e.currentTarget.files??[])),e.currentTarget.value=``}})}),(0,Y.jsx)(U,{type:`button`,variant:`outline`,"aria-label":`Choose files for ${e.label}`,"aria-describedby":r[`aria-describedby`],"aria-invalid":r[`aria-invalid`],disabled:a,onBlur:t.handleBlur,onClick:()=>{o.current?.click()},children:`Choose files`}),(0,Y.jsx)(Ir,{items:i.map((e,t)=>({id:String(t),name:e.name,preview:{kind:`file`},progress:0,progressLabel:`${String(e.size)} bytes`,statusLabel:`Selected`,actions:a?{}:{remove:{label:`Remove`,accessibleLabel:`Remove ${e.name}`}}})),onRemove:e=>{t.handleChange(i.filter((t,n)=>String(n)!==e))},onCancel:()=>void 0,onRetry:()=>void 0})]})}function qi({spec:e,field:t,locked:n,...r}){let i=e=>{t.handleChange(e)},a={...r,name:e.name,disabled:n,onBlur:t.handleBlur};switch(e.kind){case`text`:case`email`:case`url`:case`tel`:return(0,Y.jsx)(Bn,{...a,type:Gi[e.kind],inputMode:e.kind===`text`?void 0:e.kind,autoComplete:e.autoComplete,placeholder:e.placeholder,maxLength:e.maxLength,readOnly:e.readOnly,value:$(t),onChange:e=>{i(e.currentTarget.value)}});case`textarea`:return(0,Y.jsx)(Ai,{...a,rows:e.rows??3,placeholder:e.placeholder,maxLength:e.maxLength,readOnly:e.readOnly,value:$(t),onChange:e=>{i(e.currentTarget.value)}});case`secret`:return(0,Y.jsx)(Wi,{...r,field:t,spec:e,locked:n});case`money`:return(0,Y.jsxs)(Pn,{children:[(0,Y.jsx)(Fn,{className:`caps-field-currency`,children:e.currency??`USD`}),(0,Y.jsx)(Bn,{...a,inputMode:`decimal`,autoComplete:`off`,className:`caps-field-amount`,placeholder:e.placeholder??`0.00`,readOnly:e.readOnly,value:$(t),onChange:e=>{i(e.currentTarget.value)}})]});case`date`:return(0,Y.jsx)(Bn,{...a,type:`date`,readOnly:e.readOnly,value:$(t),onChange:e=>{i(e.currentTarget.value)}});case`number`:return(0,Y.jsx)(Wn,{...a,...e.min===void 0?{}:{min:e.min},...e.max===void 0?{}:{max:e.max},...e.step===void 0?{}:{step:e.step},...e.unit===void 0?{}:{unit:e.unit},...e.wrap===void 0?{}:{wrap:e.wrap},disabled:n||e.readOnly===!0,decrementLabel:`Decrease ${e.label}`,incrementLabel:`Increase ${e.label}`,value:Bi(t),onValueChange:e=>{t.handleChange(e)}});case`select`:return(0,Y.jsxs)(Di,{...a,value:$(t),onChange:e=>{i(e.currentTarget.value)},children:[e.placeholder===void 0?null:(0,Y.jsx)(`option`,{value:``,disabled:!0,children:e.placeholder}),e.options.map(e=>(0,Y.jsx)(`option`,{value:e.value,disabled:e.disabled,children:e.label},e.value))]});case`combobox`:return(0,Y.jsx)(gi,{id:r.id??e.name,"aria-describedby":r[`aria-describedby`],"aria-invalid":r[`aria-invalid`],"aria-required":r[`aria-required`],items:e.options,getKey:e=>e.value,getLabel:e=>e.label,isDisabled:t=>t.disabled||n||e.readOnly===!0,value:$(t),...e.placeholder===void 0?{}:{placeholder:e.placeholder},trigger:(0,Y.jsx)(mi,{name:e.name,disabled:n||e.readOnly===!0,onBlur:t.handleBlur,children:e.options.find(e=>e.value===$(t))?.label??e.placeholder??`Choose…`}),inputProps:{"aria-label":`Search ${e.label}`,disabled:n||e.readOnly===!0},onValueChange:e=>{i(e??``),t.handleBlur()}});case`file`:return(0,Y.jsx)(Ki,{...r,spec:e,field:t,locked:n});case`checkbox`:return(0,Y.jsx)(Wr,{...a,disabled:n||e.readOnly===!0,checked:zi(t),onChange:e=>{t.handleChange(e.currentTarget.checked)}});case`switch`:return(0,Y.jsx)(ki,{...a,disabled:n||e.readOnly===!0,checked:zi(t),onCheckedChange:e=>{t.handleChange(e)}});case`radio`:case`icon-radio`:case`checkboxes`:case`icon-checkboxes`:return null}}var Ji=new Set([`radio`,`icon-radio`,`checkboxes`,`icon-checkboxes`]);function Yi({spec:e,field:t,locked:n,error:r,layout:i}){let a=n||e.readOnly===!0,o=e.label;if(e.kind===`checkboxes`||e.kind===`icon-checkboxes`){let n=Vi(t),s=(e,r)=>{t.handleChange(r?[...n,e]:n.filter(t=>t!==e))};return(0,Y.jsx)(zn,{legend:o,icon:e.icon,layout:i,...i===`columns`?{legendTitle:o}:{},description:e.help,disabled:a,error:r??null,children:e.kind===`icon-checkboxes`?(0,Y.jsx)(`div`,{className:`caps-field-icon-choices`,children:e.options.map(r=>(0,Y.jsx)(vi,{name:e.name,value:r.value,label:r.label,...r.caption===void 0?{}:{caption:r.caption},icon:r.icon,disabled:r.disabled,checked:n.includes(r.value),onBlur:t.handleBlur,onChange:e=>{s(r.value,e.currentTarget.checked)}},r.value))}):(0,Y.jsx)(bi,{children:e.options.map(r=>(0,Y.jsx)(yi,{name:e.name,value:r.value,label:r.label,icon:r.icon,hint:r.description,disabled:r.disabled,checked:n.includes(r.value),onBlur:t.handleBlur,onChange:e=>{s(r.value,e.currentTarget.checked)}},r.value))})})}let s=e.options.some(e=>e.description!==void 0||e.meta!==void 0);return(0,Y.jsx)(zn,{legend:o,icon:e.icon,layout:i,...i===`columns`?{legendTitle:o}:{},description:e.help,disabled:a,error:r??null,children:(0,Y.jsx)(Ci,{name:e.name,"aria-label":o,value:$(t),onValueChange:e=>{t.handleChange(e),t.handleBlur()},orientation:e.kind===`icon-radio`||s?`horizontal`:`vertical`,children:e.options.map(t=>e.kind===`icon-radio`?(0,Y.jsx)(Ei,{value:t.value,label:t.label,...t.caption===void 0?{}:{caption:t.caption},icon:t.icon,disabled:t.disabled},t.value):s?(0,Y.jsx)(Ti,{value:t.value,title:t.label,description:t.description,meta:t.meta,disabled:t.disabled},t.value):(0,Y.jsx)(Mn,{label:t.label,orientation:`inline`,children:(0,Y.jsx)(wi,{value:t.value,disabled:t.disabled})},t.value))})})}function Xi({spec:e,field:t,locked:n,error:r,render:i,...a}){return i({name:e.name,label:e.label,help:e.help,value:Ui(t),onChange:e=>{t.handleChange(e)},onBlur:t.handleBlur,error:r,disabled:n,id:a.id??e.name,"aria-describedby":a[`aria-describedby`],"aria-invalid":r!==void 0})}function Zi({form:e,spec:t,locked:n,layout:r}){let i=Rn({form:e,name:t.name}),a=Vn(e.store,e=>e.submissionAttempts>0),o=i.state.meta.isBlurred||a?Nr(i.state.meta):void 0;if(t.render===void 0&&Ji.has(t.kind))return(0,Y.jsx)(Yi,{spec:t,field:i,locked:n,error:o,layout:r});let s=r===`columns`?t.kind===`switch`||t.kind===`checkbox`?`horizontal`:`vertical`:t.kind===`checkbox`?`inline`:(t.layout??(t.kind===`switch`?`row`:`stacked`))===`row`?`horizontal`:`vertical`;return(0,Y.jsx)(Mn,{label:t.label,...r===`columns`?{labelTitle:t.label}:{},description:t.help,icon:t.icon,orientation:s,error:o,...t.required===void 0?{}:{required:t.required},...t.optional===void 0?{}:{optional:t.optional},children:t.render===void 0?(0,Y.jsx)(qi,{spec:t,field:i,locked:n}):(0,Y.jsx)(Xi,{spec:t,field:i,locked:n,error:o,render:t.render})})}var Qi=K(Bt(H,Li));function $i({form:e,spec:t,locked:n,layout:r}){let i=t.when;return Vn(e.store,e=>i===void 0||i(V(Qi(e.values),()=>({}))))?(0,Y.jsx)(Zi,{form:e,spec:t,locked:n,layout:r}):null}function ea({form:e,section:t,locked:n,layout:r}){let i=t.fields.map(t=>(0,Y.jsx)($i,{form:e,spec:t,locked:n,layout:r},t.name));return t.title===void 0?i:(0,Y.jsx)(Ln,{title:t.title,description:t.description,layout:r,children:i})}function ta({model:e,names:t,disabled:n=!1,layout:r}){let i=e.form;return t===void 0?e.description.sections.map(e=>(0,Y.jsx)(ea,{form:i,section:e,locked:n,layout:r},e.id??``)):t.map(t=>{let a=e.description.fields.find(e=>e.name===t);return a===void 0?null:(0,Y.jsx)($i,{form:i,spec:a,locked:n,layout:r},t)})}var na=class{annotation;constructor(e){this.annotation=e}},ra=class{sections;constructor(e){this.sections=e}},ia=`caps/form`,aa=0;function oa(e){aa+=1;let t={[`${ia}:${String(aa)}`]:new na(e)};return e.label!==void 0&&(t.title=e.label),e.help!==void 0&&(t.description=e.help),t}H.annotate(oa({kind:`secret`})).pipe(ct(`Secret`));var sa=e=>{let t=e.replace(/([a-z0-9])([A-Z])/g,`$1 $2`).replace(/[-_]+/g,` `).toLowerCase();return t.charAt(0).toUpperCase()+t.slice(1)};function ca(e){return Object.values(e??{}).reduce((e,t)=>t instanceof na?{...e,...t.annotation}:e,{})}function la(e){return e.reduce((e,t)=>({...e,...ca(t)}),{})}function ua(e){let t=e?.[ia];return t instanceof ra?t.sections:{}}var da=K(H);function fa(e){if(ee(e))return tt(da(e.literal),{onNone:()=>null,onSome:e=>[e]});if(!Ce(e))return null;let t=[];for(let n of e.types){if(T(n))continue;let e=fa(n);if(e===null)return null;t.push(...e)}return t}function pa(e){if(De(e))return{type:`string`,literals:[]};if(rn(e))return{type:`number`,nullable:!1};if(A(e))return{type:`boolean`};let t=fa(e);if(t!==null)return{type:`string`,literals:t};if(v(e)){let[t]=e.rest;if(t===void 0)return null;if(De(t))return{type:`strings`,literals:[]};let n=fa(t);return n===null?null:{type:`strings`,literals:n}}if(Ce(e)){let t=e.types.filter(e=>!T(e)&&!pe(e)),n=e.types.some(e=>pe(e)),[r]=t;if(t.length!==1||r===void 0)return null;let i=pa(r);return i?.type===`number`?{type:`number`,nullable:n}:n?null:i}return null}function ma(e){let t=e.ast;if(!s(t))throw Error(`A schema form needs a Schema.Struct.`);return{fields:t.propertySignatures.map(e=>{let t=String(e.name),n=Pt(e.type),r=la([e.type.annotations,...(e.type.checks??[]).map(e=>e.annotations)]),i=r.kind===`file`?{type:`files`}:pa(n);if(i===null)throw Error(`Schema field "${t}" has no form control. Annotate it with field({ render }) or a kind.`);return{name:t,valueType:i,optional:e.type.context?.isOptional===!0,annotation:r,title:F(e.type),description:b(e.type)}}),sections:ua(je(t))}}function ha(e){let t=e,n=!1,r=!1;for(;;)if(t instanceof Jt)n=!0,t=t.unwrap();else if(t instanceof Vt)r=!0,t=t.unwrap();else if(t instanceof ft)t=t.unwrap();else if(t instanceof $e)t=t.in;else return{node:t,optional:n,nullable:r}}function ga(e){if(e instanceof St){let t=e.options.map(e=>ga(e));return t.some(e=>e===null)?null:t.flatMap(e=>e??[])}let t=e instanceof Ge?e.options:e instanceof Dt?[...e.values]:null;if(t===null)return null;let n=t.map(e=>da(e));return n.every(ue)?n.map(e=>e.value):null}function _a(e){let{node:t,nullable:n}=ha(e);if(t instanceof it)return{type:`string`,literals:[]};if(t instanceof Ye)return{type:`number`,nullable:n};if(t instanceof Lt)return{type:`boolean`};let r=ga(t);if(r!==null)return{type:`string`,literals:r};if(t instanceof Tt){let e=ha(t.element).node;if(e instanceof it)return{type:`strings`,literals:[]};let n=ga(e);return n===null?null:{type:`strings`,literals:n}}return null}function va(e){let t=[e];for(;;){let e=t[t.length-1];if(e===void 0)break;let n=e instanceof Jt||e instanceof Vt||e instanceof ft?e.unwrap():e instanceof $e?e.in:e;if(n===e)break;t.push(n)}return t.reverse().map(e=>te.get(e))}function ya(e){return va(e).reduce((e,t)=>({...e,...t}),{})}function ba(e){return Object.entries(e.shape)}function xa(e){let t=ha(e).node;if(!(t instanceof yt))throw Error(`A schema form needs a z.object.`);return{fields:ba(t).map(([e,t])=>{let n=la(va(t)),r=n.kind===`file`?{type:`files`}:_a(t);if(r===null)throw Error(`Schema field "${e}" has no form control. Annotate it with field({ render }) or a kind.`);let i=ya(t);return{name:e,valueType:r,optional:ha(t).optional,annotation:n,title:i.title,description:i.description}}),sections:ua(ya(e))}}function Sa(e,t){let n=t.options??{};return(e.length>0?e:Object.keys(n)).map(e=>{let t=n[e],r=t===void 0?{}:t instanceof Object?t:{label:t};return{value:e,label:r.label??sa(e),description:r.description,meta:r.meta,icon:r.icon,caption:r.caption,disabled:r.disabled===!0}})}function Ca(e,t){let n=t.some(e=>e.icon!==void 0);switch(e.type){case`boolean`:return`switch`;case`number`:return`number`;case`strings`:return n?`icon-checkboxes`:`checkboxes`;case`files`:return`file`;case`string`:return t.length===0?`text`:t.length>12?`combobox`:n?`icon-radio`:t.some(e=>e.description!==void 0||e.meta!==void 0)||t.length<=3?`radio`:`select`}}function wa(e,t){switch(e.type){case`boolean`:return!1;case`number`:return e.nullable?null:0;case`strings`:case`files`:return[];case`string`:return t[0]?.value??``}}function Ta(e){let t=e instanceof jt?xa(e):ma(e),n=t.fields.map((e,t)=>{let{kind:n,...r}=e.annotation,i=Sa(e.valueType.type===`string`||e.valueType.type===`strings`?e.valueType.literals:[],e.annotation),a=r.help??e.description;return{...r,name:e.name,label:r.label??e.title??sa(e.name),help:a,kind:n??Ca(e.valueType,i),options:i,optionalInSchema:e.optional,index:t}}),r={};t.fields.forEach((e,t)=>{let i=n[t];i&&(r[e.name]=wa(e.valueType,i.options))});let i=e=>e.order??e.index,a=e=>e.section!==void 0&&Object.hasOwn(t.sections,e.section)?e.section:null,o=e=>n.filter(t=>a(t)===e).sort((e,t)=>i(e)-i(t)),s=Object.entries(t.sections).map(([e,t])=>({id:e,title:t.title,description:t.description,fields:o(e)}));return{fields:n,sections:[{id:null,title:void 0,description:void 0,fields:o(null)},...s].filter(e=>e.fields.length>0),defaults:r}}function Ea(e){let t=e instanceof jt?e:ce(e);return{"~standard":{...t[`~standard`],validate:e=>{let n=t[`~standard`].validate(e);return n instanceof Promise?n.then(e=>Da(e)):Da(n)}}}}function Da(e){return e.issues===void 0?e:{issues:e.issues.map(e=>e.path===void 0?e:{...e,path:e.path.slice(0,1)})}}var Oa=`onServer`;function ka(e){let t=e.querySelector(`[aria-invalid="true"]`),n=t?.matches(`input, select, textarea, button, [tabindex]`)?t:t?.querySelector(`input, select, textarea, button`);return n?.focus(),n!=null}function Aa(e){if(ka(e))return()=>void 0;let t=new MutationObserver(()=>{ka(e)&&t.disconnect()});return t.observe(e,{subtree:!0,childList:!0,attributes:!0,attributeFilter:[`aria-invalid`]}),()=>{t.disconnect()}}function ja(e){return e.state.meta.errorMap.onServer!==void 0}function Ma(e){e.setMeta(e=>({...e,errorMap:{...e.errorMap,[Oa]:void 0}}))}function Na(e,t,n){e.setFieldMeta(t,e=>({...e,isBlurred:!0,errorMap:{...e.errorMap,[Oa]:n}}))}function Pa(e){let[t,n]=(0,J.useState)(null),[r,i]=(0,J.useState)(null),[a,o]=(0,J.useState)(e.defaultValues),[s,c]=(0,J.useState)(null);In(a,e.defaultValues)||(o(e.defaultValues),c(null));let{schema:l}=e,u=(0,J.useMemo)(()=>Ta(l),[l]),d=(0,J.useMemo)(()=>Ea(l),[l]),f=Un({defaultValues:s??a,validators:{onChange:d,onSubmit:d},listeners:{onChange:({fieldApi:e})=>{n(null),i(null),ja(e)&&Ma(e)}},onSubmit:async({value:t,formApi:r})=>{n(null),i(null);let a=await Ea(l)[`~standard`].validate(t);if(a.issues){n(a.issues[0]?.message??`Check the form and try again.`);return}let o;try{o=await e.onSubmit(a.value,t)??{kind:`saved`}}catch(t){console.error(`SchemaForm submit failed`,t),n(e.failure??`Couldn't save changes. Try again.`);return}if(o.kind===`refused`){n(o.error??null);let e=r;for(let[t,n]of Object.entries(o.fields??{}))n!==void 0&&n.length>0&&Na(e,t,n);return}let s=o.values??t;c(s),r.reset(s),i(o.message??`Saved`),e.onSaved?.(s)}});return{description:u,form:f,error:t,saved:r,discard:()=>{n(null),i(null),f.reset()},submit:()=>f.handleSubmit()}}function Fa(e){return{dirty:Vn(e.form.store,e=>!e.isDefaultValue),submitting:Vn(e.form.store,e=>e.isSubmitting),canSubmit:Vn(e.form.store,e=>e.canSubmit)}}function Ia({model:e,submitLabel:t=`Save changes`,discardLabel:n,onCancel:r,cancelLabel:i,allowClean:a,layout:o,footer:s,children:c,disabled:l=!1,...u}){let{submitting:d}=Fa(e),f=(0,J.useRef)(null),p=(0,J.useRef)(()=>void 0);return(0,J.useEffect)(()=>()=>{p.current()},[]),(0,Y.jsxs)(Hn,{...u,ref:f,layout:o,busy:d,noValidate:!0,onSubmit:t=>{t.preventDefault(),e.form.state.isSubmitting||e.submit().then(()=>{p.current();let t=f.current;t!==null&&!e.form.state.isValid&&(p.current=Aa(t))})},children:[c??(0,Y.jsx)(ta,{model:e,disabled:l,layout:o}),s===void 0?(0,Y.jsx)(za,{model:e,label:t,discardLabel:r===void 0?n:void 0,onCancel:r,cancelLabel:i,allowClean:a??r!==void 0,divider:r===void 0}):s]})}function La({schema:e,defaultValues:t,onSubmit:n,onSaved:r,failure:i,...a}){let o=Pa({schema:e,defaultValues:t,onSubmit:n,onSaved:r,failure:i});return(0,Y.jsx)(Ia,{...a,model:o})}function Ra(e){return`model`in e?(0,Y.jsx)(Ia,{...e}):(0,Y.jsx)(La,{...e})}function za({model:e,label:t,discardLabel:n,onCancel:r,cancelLabel:i=`Cancel`,allowClean:a=!1,dirtyLabel:o=`Unsaved changes`,buttonProps:s,...c}){let{dirty:l,submitting:u}=Fa(e),d=u?null:e.saved&&!l?(0,Y.jsx)(On,{tone:`success`,size:`compact`,label:e.saved}):l?(0,Y.jsx)(On,{tone:`neutral`,size:`compact`,label:o}):null;return(0,Y.jsxs)(Nn,{...c,error:e.error,status:d,children:[r?(0,Y.jsx)(U,{type:`button`,variant:`ghost`,disabled:u,onClick:r,children:i}):n&&l?(0,Y.jsx)(U,{type:`button`,variant:`ghost`,disabled:u,onClick:e.discard,children:n}):null,(0,Y.jsx)(U,{...s,type:`submit`,loading:u,disabled:u||!l&&!a,title:!l&&!a?`No changes to save`:void 0,children:t})]})}var Ba=qt.check(a(/^(?!\.{1,2}$)[^/]+$/u,{message:`Enter a single file or folder name.`})),Va={file:vt({name:Ba.annotate(oa({label:`File name`}))}),folder:vt({name:Ba.annotate(oa({label:`Folder name`}))})};function Ha(e){return(0,Y.jsx)(Ua,{...e},e.creation?`${e.creation.kind}:${e.creation.directory}:${e.creation.name??``}`:`closed`)}function Ua({creation:e,rootPath:t,onCreate:n,onClose:r}){let i=Pa({schema:Va[e?.kind??`file`],defaultValues:{name:e?.name??``},onSubmit:async t=>{if(!e)return;let i=await n(e,t.name);if(i)return i===`That name already exists in this directory.`?{kind:`refused`,fields:{name:i}}:{kind:`refused`,error:i};r()}}),{submitting:a}=Fa(i);return(0,Y.jsx)(Ue,{open:e!==null,onOpenChange:e=>{!e&&!i.form.state.isSubmitting&&r()},children:(0,Y.jsxs)(zt,{children:[(0,Y.jsxs)(Kt,{className:`mb-4`,children:[(0,Y.jsxs)(Qe,{children:[`New `,e?.kind===`folder`?`folder`:`file`]}),(0,Y.jsxs)(Je,{children:[`Create in `,e?.directory??t,` on this Computer.`]})]}),(0,Y.jsx)(Ra,{model:i,onSubmitCapture:()=>{i.form.state.isSubmitting||i.form.setFieldValue(`name`,e=>e)},footer:(0,Y.jsxs)(Nn,{divider:!1,error:i.error,children:[(0,Y.jsx)(U,{variant:`ghost`,type:`button`,disabled:a,onClick:r,children:`Cancel`}),(0,Y.jsx)(U,{type:`submit`,disabled:a,loading:a,children:a?`Creating…`:`Create`})]})})]})})}function Wa({files:e,patch:t,truncated:n,activeDiff:r,rowHeight:i,onOpenDiff:a}){let o=(0,J.useMemo)(()=>En(t),[t]);return e.length===0?(0,Y.jsx)(pn,{className:`inkcap-changes-empty`,variant:`quiet`,title:`No changes yet`,description:`Files the Agent edits show up here.`}):(0,Y.jsxs)(`div`,{className:`inkcap-changes-list`,children:[n?(0,Y.jsx)(`p`,{className:`inkcap-tree-note`,children:`Showing the first part of a large change. Review the rest in a terminal.`}):null,(0,Y.jsx)(`ul`,{children:e.map(e=>{let t=o.get(e.path);return(0,Y.jsx)(`li`,{children:(0,Y.jsxs)(U,{className:`inkcap-change-file`,style:{minHeight:i},size:`sm`,variant:`ghost`,"aria-current":r===e.path?`true`:void 0,title:`Review changes to ${e.path}`,onClick:()=>{a(e.path)},children:[(0,Y.jsx)(`span`,{className:`inkcap-change-mark`,"data-status":e.status,role:`img`,"aria-label":xn[e.status],children:wn[e.status]}),(0,Y.jsx)(`span`,{className:`inkcap-change-path`,children:e.path}),t?(0,Y.jsxs)(`span`,{className:`inkcap-change-counts`,children:[t.additions>0?(0,Y.jsxs)(`span`,{className:`inkcap-change-added`,children:[`+`,t.additions]}):null,t.deletions>0?(0,Y.jsxs)(`span`,{className:`inkcap-change-removed`,children:[`−`,t.deletions]}):null]}):null]})},`${e.status}:${e.path}`)})})]})}var Ga=`That name already exists in this directory.`;function Ka({app:e,onOpenFile:t,onOpenDiff:n,activeDiff:r=null,activePath:i,rootPath:a=`/`,rootLabel:o=`Computer`,onSelectPath:s,creationRequest:c=null,onCreationRequestHandled:u,rowHeight:d=32}){let[f,p]=(0,J.useState)(null),m=Ar({app:e,rootPath:a,rootLabel:o,rowHeight:d,activePath:i,onOpenFile:t,onSelectPath:e=>{p(e),s?.(e)}}),[h,g]=(0,J.useState)(null),_=e.capabilities.has(sn),[v,y]=(0,J.useState)(!1),b=e.capabilities.has(un),x=ln(vn(b?e:null,a)),S=x.data?.kind===`changes`?x.data:null;function C(){m.reloadRoot(),b&&x.refetch()}(0,J.useEffect)(()=>{x.isError&&e.ui.showToast({message:fe(x.error).message,tone:`error`}).catch(e=>{console.error(`Inkcap changes toast failed`,e)})},[e,x.isError,x.error]);function w(e,t){g({kind:e,directory:wt(t,a)})}(0,J.useEffect)(()=>{if(!c)return;let e={kind:c.kind,directory:wt(f??`${a}/`,a)};c.name!==void 0&&(e.name=c.name),c.immediate===!0&&c.name!==void 0?T(e,c.name):g(e),u?.()},[c,u,a,f]);async function T(e,n){let r=await E(e,n);r===Ga?t(ut(n,e.directory)):r!==void 0&&g(e)}async function E(n,r){let i=ut(r,n.directory);try{let a=0;for(;a!==null;){let t=a,i=await kn(e.capabilities,{path:n.directory,limit:256,offset:t});if(i.entries.some(e=>e.name===r))return Ga;if(i.nextOffset!==null&&i.nextOffset<=t)return`Could not verify that name is available.`;a=i.nextOffset}n.kind===`folder`?(await e.capabilities.require(sn).mkdir({path:i}),m.noteCreated(`${i}/`)):(await cn(e.capabilities,{path:i,content:new Blob([])},{}),m.noteCreated(i),t(i));return}catch(e){return e instanceof Error?fe(e).message:`Couldn't create ${n.kind}. Check Computer write access.`}}let D={flex:`1`,"--trees-item-height":`${String(d)}px`,"--trees-padding-inline-override":`var(--spacing-xs)`,"--trees-item-margin-x-override":`0px`,"--trees-item-padding-x-override":`var(--spacing-xs)`,"--trees-item-row-gap-override":`var(--spacing-xs)`,"--trees-bg-override":`var(--color-base-100)`,"--trees-fg-override":`var(--color-base-content)`,"--trees-bg-muted-override":`var(--color-base-200)`,"--trees-selected-bg-override":`var(--color-base-300)`,"--trees-border-radius-override":`var(--radius-field)`,"--trees-font-family-override":`var(--font-sans)`,"--trees-font-size-override":`12px`};return(0,Y.jsxs)(`aside`,{className:`inkcap-tree`,"aria-label":`File tree`,children:[(0,Y.jsxs)(`div`,{className:`inkcap-tree-toolbar`,children:[(0,Y.jsxs)(`span`,{children:[(0,Y.jsx)(Tn,{"aria-hidden":`true`}),` `,(0,Y.jsx)(`span`,{className:`inkcap-tree-title`,children:`Explorer`})]}),(0,Y.jsxs)(`span`,{className:`inkcap-tree-actions`,children:[(0,Y.jsx)(l,{icon:(0,Y.jsx)(mn,{}),"aria-label":`New file`,title:`New file`,variant:`ghost`,size:`responsive`,disabled:!_,onClick:()=>{w(`file`,f??`${a}/`)}}),(0,Y.jsx)(l,{icon:(0,Y.jsx)(ir,{}),"aria-label":`New folder`,title:`New folder`,variant:`ghost`,size:`responsive`,disabled:!_,onClick:()=>{w(`folder`,f??`${a}/`)}}),(0,Y.jsx)(l,{icon:(0,Y.jsx)(Kn,{}),"aria-label":`Refresh files`,title:`Refresh files`,variant:`ghost`,size:`responsive`,disabled:m.busy||x.isFetching,onClick:C})]})]}),S===null?x.isError?(0,Y.jsx)(U,{className:`inkcap-changes-retry`,size:`sm`,variant:`ghost`,onClick:()=>void x.refetch(),children:`Changes unavailable. Retry`}):null:(0,Y.jsx)(kr,{className:`inkcap-changes`,size:`row`,open:v,onOpenChange:y,summary:`Changes`,trailing:(0,Y.jsx)(Sn,{count:S.files.length}),children:(0,Y.jsx)(Wa,{files:S.files,patch:S.patch,truncated:S.truncated,activeDiff:r,rowHeight:d,onOpenDiff:e=>{n?.(e)}})}),m.error&&(0,Y.jsx)(fn,{message:m.error,onRetry:m.reloadRoot}),m.rootEmpty?(0,Y.jsx)(`p`,{className:`inkcap-tree-note`,children:`Empty folder`}):null,(0,Y.jsxs)(`div`,{className:`inkcap-tree-files`,children:[(0,Y.jsx)(Gn,{model:m.model,style:D,renderContextMenu:(e,t)=>(0,Y.jsxs)(`div`,{className:`flex min-w-36 flex-col gap-xs p-xs`,role:`menu`,children:[(0,Y.jsxs)(U,{className:`w-full justify-start`,disabled:!_,role:`menuitem`,title:_?void 0:`Computer write access is not granted.`,size:`sm`,variant:`ghost`,onClick:()=>{t.close({restoreFocus:!1}),w(`file`,e.path)},children:[(0,Y.jsx)(mn,{"aria-hidden":`true`}),` New file`]}),(0,Y.jsxs)(U,{className:`w-full justify-start`,disabled:!_,role:`menuitem`,title:_?void 0:`Computer write access is not granted.`,size:`sm`,variant:`ghost`,onClick:()=>{t.close({restoreFocus:!1}),w(`folder`,e.path)},children:[(0,Y.jsx)(ir,{"aria-hidden":`true`}),` New folder`]})]})}),m.page.next!==null&&(0,Y.jsxs)(U,{disabled:m.busy,onClick:m.loadNext,children:[`More in `,m.page.path]})]}),(0,Y.jsx)(Ha,{creation:h,rootPath:a,onCreate:E,onClose:()=>{g(null)}})]})}export{Ka as InkcapFileTree};
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Bn as t,Qr as n,Xi as r,Xr as i,Zi as a,a as o,c as s,d as c,dr as l,s as u,u as d,ur as f}from"./tree-path-DQAnGoeW.js";import{Ft as p,Lt as m,_ as h,s as g}from"./changes-patch-DeYy-1aU.js";import{Wt as _}from"./dropdown-menu-BlFqxqxM.js";import{n as v,r as y,t as b}from"./useFileTree-D7u_RYsd.js";import{a as x,c as S,d as C,f as w,h as T,i as E,l as D,m as O,n as k,o as A,p as j,r as M,s as N,t as P,u as F}from"./index-DydaQgop.js";var I=f(`GitBranch`,[[`line`,{x1:`6`,x2:`6`,y1:`3`,y2:`15`,key:`17qcm7`}],[`circle`,{cx:`18`,cy:`6`,r:`3`,key:`1h7g24`}],[`circle`,{cx:`6`,cy:`18`,r:`3`,key:`fqmcym`}],[`path`,{d:`M18 9a9 9 0 0 1-9 9`,key:`n2h4wq`}]]),L=f(`History`,[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}],[`path`,{d:`M12 7v5l4 2`,key:`1fdv2h`}]]),R=e(a(),1),z=256;async function B(e,t,n,r,a){r.throwIfAborted();let o=await n(e,t);if(!j.safeParse(o).success)return o;a(!0);try{let a=null,o=!1;for(let e=0;e<z&&!o;e++){r.throwIfAborted();let e=x.parse(await n(`rebuildCopies`,{cursor:a}));o=e.done,a=e.cursor}if(!o)throw new i(`Bonsai is still preparing this repository. Try again shortly.`,{code:`TIMEOUT`,retryable:!0});r.throwIfAborted();let s=await n(e,t);if(j.safeParse(s).success)throw Error(`The repository changed while loading. Refresh to retry.`);return s}finally{a(!1)}}function V({repository:e,branch:t,request:n,onSaved:r,onSaveState:a}){let o=new Map;async function s(r,a){a.throwIfAborted();let o=A.parse(await n(`files.read`,{repo:e,ref:t,path:r}));if(a.throwIfAborted(),o.binary)throw Error(`This Bonsai file is not a text document.`);if(o.text===null&&o.blob!==null)throw new i(`This Bonsai file is too large to edit.`,{code:`FILE_TOO_LARGE`,retryable:!1});return o}async function c(s,c){c.throwIfAborted();let l=w.parse(await n(`files.sync`,{}));c.throwIfAborted();let u=l.settled.find(n=>n.repo===e&&n.branch===t&&n.path===s);if(u){if(u.result.kind===`refused`)throw new i(`Bonsai refused sync: ${u.result.reason}`,{code:`CAPABILITY_DENIED`,retryable:u.result.reason===`background-unavailable`});let e=o.get(s);if(u.result.revision!==e?.version)throw new i(`Your saved file changed. Compare before syncing.`,{code:`CONFLICT`,retryable:!0});a(s,u.result)}r()}async function l(l,u,d,f){f.throwIfAborted();let p=o.get(l);if(d===void 0){let e=await s(l,f);p={file:e,contents:e.pending?.text??e.text??``,version:e.version}}if(!p)throw Error(`Reopen this Bonsai file before saving.`);if(d!==void 0&&p.contents!==d)throw new i(`The file baseline changed. Compare before saving.`,{code:`CONFLICT`,retryable:!0});if(d!==void 0){let e=await s(l,f);if(e.version!==p.version||(e.pending?.text??e.text??``)!==p.contents)throw new i(`The file changed. Compare before saving.`,{code:`CONFLICT`,retryable:!0});e.pending===void 0&&(p.file=e)}let m=F.parse({repo:e,branch:t,path:l,baseCommit:p.file.commit,baseBlob:p.file.blob,text:u,revision:p.version}),h=C.parse(await n(`files.save`,m));if(h.kind===`refused`)throw new i(`Bonsai refused this save: ${h.reason}`,{code:`CAPABILITY_DENIED`,retryable:h.reason===`background-unavailable`});if(a(l,h),h.kind===`conflict`)throw new i(`Your saved file changed. Compare before saving.`,{code:`CONFLICT`,retryable:!0});o.set(l,{file:p.file,contents:u,version:h.revision}),r(),h.kind===`saved`&&c(l,f).catch(e=>{console.error(`Bonsai sync status could not be refreshed`,e),!(o.get(l)?.version!==h.revision||f.aborted)&&a(l,{kind:`failed`,revision:h.revision,reason:`sync_failed`})})}return{kind:`repository`,id:`${e}:${t}`,label:`${e} · ${t}`,async read(e,t,n){let r=n?.revision,i=await s(e,t);if(n?.closed)return{kind:`closed`};if(n&&n.revision!==r)return{kind:`changed`};let c=i.pending?.text??i.text??``;o.set(e,{file:i,contents:c,version:i.version});let l=i.pending;return l?.state===`pending`?a(e,{kind:`saved`,revision:l.revision,state:`pending`}):l?.state===`conflict`?a(e,{kind:`conflict`,revision:l.revision,theirs:l.theirs}):l?.state===`failed`?a(e,{kind:`failed`,revision:l.revision,reason:l.failure??`sync_failed`}):i.version!==null&&a(e,{kind:`synced`,revision:i.version,commit:i.commit}),{kind:`text`,contents:c}},replace:(e,t,n,r)=>l(e,t,n,r),write:(e,t,n)=>l(e,t,void 0,n),async exists(r,i){i.throwIfAborted();let a=D.parse(await n(`files.list`,{repo:e,ref:t}));if(i.throwIfAborted(),a.paths.includes(r))return!0;if(a.truncated)throw Error(`The repository file list is incomplete.`);return!1},retry:c,async discard(s,c){c.throwIfAborted();let l=o.get(s);if(!l)throw Error(`Reopen this saved file before discarding it.`);if(l.version===null)return;let u=N.parse({repo:e,branch:t,path:s,revision:l.version}),d=S.parse(await n(`files.discard`,u));if(c.throwIfAborted(),d.kind===`conflict`)throw new i(`Your saved file changed. Refresh before discarding.`,{code:`CONFLICT`,retryable:!0});o.delete(s),a(s,null),r()},async readCommitted(e,t){let n=await s(e,t),r=n.text??``;return o.has(e)||o.set(e,{file:n,contents:r,version:n.version}),r}}}async function H(e,t,n){let r={repo:t,ref:n},i=O.parse(await e(`files.tree`,{...r,path:``})),a=D.parse(await e(`files.list`,r)),o=E.parse(await e(`commits.list`,{...r,limit:20}));if(i.commit.hash!==a.commit.hash)throw Error(`The repository changed while loading. Refresh to retry.`);return{head:i.commit.hash,branch:n,files:a.paths.map(e=>({path:e})),history:o.commits.map(e=>e.commit),truncated:a.truncated}}var U=r();function W({files:e,rowHeight:n,dirtyPaths:r,activePath:i,busy:a,onRefresh:o,onOpenFile:s}){let c=(0,R.useRef)({files:e,onOpenFile:s});c.current={files:e,onOpenFile:s};let{model:l}=b({paths:[],initialExpansion:`open`,itemHeight:n,onSelectionChange(e){let t=e[0];t&&!t.endsWith(`/`)&&c.current.files.some(e=>e.path===t)&&c.current.onOpenFile(t)}}),u=(0,R.useMemo)(()=>{let t=new Set(r);return e.flatMap(e=>t.has(e.path)?[{path:e.path,status:`modified`}]:[])},[e,r]);(0,R.useEffect)(()=>{l.resetPaths(e.map(e=>e.path))},[l,e]),(0,R.useEffect)(()=>{l.setGitStatus(u)},[l,u]),(0,R.useEffect)(()=>{for(let e of l.getSelectedPaths())e!==i&&l.getItem(e)?.deselect();i&&l.getItem(i)?.select()},[l,i]);let d={flex:`1`,"--trees-item-height":`${String(n)}px`,"--trees-padding-inline-override":`var(--spacing-xs)`,"--trees-item-margin-x-override":`0px`,"--trees-item-padding-x-override":`var(--spacing-xs)`,"--trees-item-row-gap-override":`var(--spacing-xs)`,"--trees-border-radius-override":`var(--radius-field)`,"--trees-bg-override":`var(--color-base-100)`,"--trees-fg-override":`var(--color-base-content)`,"--trees-bg-muted-override":`var(--color-base-200)`,"--trees-selected-bg-override":`var(--color-base-300)`,"--trees-font-family-override":`var(--font-sans)`,"--trees-font-size-override":`12px`};return(0,U.jsxs)(`aside`,{className:`inkcap-tree`,"aria-label":`Repository files`,children:[(0,U.jsxs)(`div`,{className:`inkcap-tree-toolbar`,children:[(0,U.jsxs)(`span`,{children:[(0,U.jsx)(g,{"aria-hidden":`true`}),` Explorer`]}),(0,U.jsx)(t,{icon:(0,U.jsx)(y,{}),"aria-label":`Refresh repository`,variant:`ghost`,size:`responsive`,disabled:a,onClick:o})]}),(0,U.jsx)(`p`,{className:`inkcap-repository-legend`,children:`Changes in latest commit · drafts marked modified`}),(0,U.jsx)(v,{model:l,style:d})]})}var G={all:(e,t)=>[`inkcap-repository`,e,t],branch:(e,t,n)=>[...G.all(e,t),n]},K={branch_missing:`The repository branch no longer exists. Your text is saved; restore the branch before retrying.`,access_changed:`Repository access changed. Your text is saved; restore Bonsai's Git access before retrying.`,sync_failed:`Git could not publish this change. Your text is saved; retry sync.`,permanent_material:`The saved change no longer matches the repository state. Save again to publish your text from the current state.`};function q({connection:e,repository:t,initialBranch:r,initialPath:i,openRequestId:a,transport:f,onReady:g}){let v=m(),[y,b]=(0,R.useState)(!1),[x,S]=(0,R.useState)(0),[C,w]=(0,R.useState)(new Map),[E,D]=(0,R.useState)(``),O=(0,R.useRef)(new AbortController);(0,R.useEffect)(()=>{let e=new AbortController;return O.current=e,()=>{e.abort()}},[]);let A=(0,R.useCallback)((t,n)=>f?f(t,n):e.app.capabilities.require(T).call(`app_bonsai`,t,JSON.stringify(n)),[e.app,f]),j=(0,R.useCallback)((e,t)=>B(e,t,A,O.current.signal,e=>{S(t=>t+(e?1:-1))}),[A]),N=(0,R.useCallback)(()=>{v.invalidateQueries({queryKey:G.all(e.app.identity.surfaceId,t)})},[v,e.app,t]),F=(0,R.useRef)(new Map),z=(0,R.useMemo)(()=>{let n=`${e.app.identity.surfaceId}:${t}:${r}`,i=F.current.get(n);if(i?.app===e.app)return i;let a=V({repository:t,branch:r,request:j,onSaved:N,onSaveState:(e,n)=>{O.current.signal.aborted||w(i=>{let a=new Map(i),o=`${t}:${r}:${e}`;return n===null?a.delete(o):a.set(o,n),a})}}),o={app:e.app,source:a};return F.current.set(n,o),o},[t,r,j,N,e.app]),q=P({connection:z}),J=p({queryKey:G.branch(e.app.identity.surfaceId,t,r),queryFn:()=>H(j,t,r),refetchInterval:15e3});(0,R.useEffect)(()=>e.app.window.onBeforeClose(q.requestWindowClose),[e.app,q.requestWindowClose]),(0,R.useEffect)(()=>{g?.({requestWindowClose:q.requestWindowClose})},[g,q.requestWindowClose]);let Y=(0,R.useRef)(),X=(0,R.useRef)(new Map),Z=(0,R.useRef)(new Set);(0,R.useEffect)(()=>{if(!J.data)return;let e=`${z.app.identity.surfaceId}:${z.source.id}:${a}`;Y.current!==e&&(Y.current=e,q.onOpenFile(i));let t=X.current.get(z.source.id),n=t!==void 0&&t!==J.data.head;X.current.set(z.source.id,J.data.head);let r=new Set(q.tabs.map(e=>e.tabKey));for(let e of Z.current)r.has(e)||Z.current.delete(e);for(let e of q.tabs)if(!(e.target.closed||e.connection!==z||!n&&!Z.current.has(e.tabKey))){if(e.target.saving){Z.current.add(e.tabKey);continue}Z.current.delete(e.tabKey),e.target.dirty||q.onReopen(e,{background:!0})}},[J.data,z,i,a,q]);let Q=q.tabs.find(e=>e.tabKey===q.active),$=Q?.connection?.source?C.get(`${Q.connection.source.id}:${Q.path}`):void 0,ee=$?.kind===`saved`?`Saved · syncing`:$?.kind===`synced`?`Synced · ${$.commit.slice(0,7)}`:$?.kind===`conflict`?`Sync conflict · Compare`:$?.kind===`failed`?`Sync failed · Retry`:void 0;async function te(){if(!Q?.connection?.source)return;let e=F.current.get(`${Q.connection.app.identity.surfaceId}:${Q.connection.source.id}`);if(e)try{D(``),await e.source.retry(Q.path,O.current.signal)}catch(e){console.error(`Bonsai sync retry failed`,e),D(`${n(e).message} Your saved text remains in Bonsai.`)}}async function ne(){if(!Q?.connection?.source)return;let e=()=>!Q.target.dirty&&!Q.target.saving&&!Q.target.closed;if(!e())return;let t=F.current.get(`${Q.connection.app.identity.surfaceId}:${Q.connection.source.id}`);if(t)try{D(``);let n=await t.source.read(Q.path,O.current.signal);if(n.kind!==`text`)throw Error(`This saved text is unavailable.`);if(!e())return;await t.source.replace(Q.path,n.contents,n.contents,O.current.signal)}catch(e){console.error(`Bonsai explicit re-save failed`,e),D(`${n(e).message} Your saved text and open edits remain available.`)}}return(0,U.jsxs)(`div`,{className:`inkcap-repository`,children:[(0,U.jsxs)(`div`,{className:`inkcap-repository-toolbar`,children:[(0,U.jsxs)(`span`,{className:`inkcap-repository-name`,children:[(0,U.jsx)(I,{"aria-hidden":`true`}),` `,t,` · `,r]}),(0,U.jsxs)(l,{size:`sm`,variant:`outline`,onClick:()=>{b(!0)},children:[(0,U.jsx)(L,{"aria-hidden":`true`,className:`size-[var(--stipe-icon-size-sm)]`}),` `,`History`]})]}),x>0&&(0,U.jsx)(M,{message:`Loading this repository…`}),J.data?.truncated&&(0,U.jsx)(_,{tone:`info`,title:`Only the indexed files are shown`}),E&&(0,U.jsx)(h,{message:E,onDismiss:()=>{D(``)}}),$?.kind===`failed`&&!E&&(0,U.jsx)(_,{tone:`warning`,title:$.reason===`permanent_material`?`Sync needs a new save`:`Sync failed`,description:K[$.reason],action:(0,U.jsx)(l,{size:`sm`,disabled:$.reason===`permanent_material`&&Q!==void 0&&(Q.target.dirty||Q.target.saving),onClick:()=>void($.reason===`permanent_material`?ne():te()),children:$.reason===`permanent_material`?`Save again`:`Retry`})}),(0,U.jsx)(k,{model:{...q,repositoryStatus:ee,repositoryStates:C,canList:!0,sourceLabel:z.source.label,onReadCurrent:async(e,t)=>{if(e.connection?.source?.kind!==`repository`)return q.onReadCurrent(e);let n=F.current.get(`${e.connection.app.identity.surfaceId}:${e.connection.source.id}`);if(!n||e.target.closed)throw Error(`This Bonsai file is no longer open.`);return t&&await n.source.discard(e.path,O.current.signal),n.source.readCommitted(e.path,O.current.signal)},error:J.error?`${n(J.error).message} Your open edits remain available.`:void 0,fileTree:(e,t)=>(0,U.jsx)(W,{rowHeight:t?44:32,files:J.data?.files??[],dirtyPaths:q.tabs.filter(e=>e.connection===z&&e.dirty).map(e=>e.path),activePath:Q?.connection===z?Q.path:null,busy:J.isFetching,onRefresh:N,onOpenFile:e},t?`phone`:`desktop`)}}),(0,U.jsx)(o,{open:y,onOpenChange:b,children:(0,U.jsxs)(u,{children:[(0,U.jsxs)(d,{children:[(0,U.jsx)(c,{children:`Commit history`}),(0,U.jsxs)(s,{children:[t,` · `,r]})]}),(0,U.jsx)(`ol`,{className:`inkcap-repository-history`,children:J.data?.history.map(e=>(0,U.jsxs)(`li`,{children:[(0,U.jsx)(`code`,{children:e.hash.slice(0,7)}),` `,e.message,(0,U.jsx)(`span`,{className:`text-dim`,children:e.author.name})]},e.hash))})]})})]})}export{q as InkcapRepositoryApp};
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Bn as t,Qr as n,Xi as r,Xr as i,Zi as a,a as o,c as s,d as c,dr as l,s as u,u as d,ur as f}from"./tree-path-DQAnGoeW.js";import{Ft as p,Lt as m,_ as h,s as g}from"./changes-patch-DhbNb84Y.js";import{Wt as _}from"./dropdown-menu-BlFqxqxM.js";import{n as v,r as y,t as b}from"./useFileTree-D7u_RYsd.js";import{a as x,c as S,d as C,f as w,h as T,i as E,l as D,m as O,n as k,o as A,p as j,r as M,s as N,t as P,u as F}from"./index-DEbu5E0M.js";var I=f(`GitBranch`,[[`line`,{x1:`6`,x2:`6`,y1:`3`,y2:`15`,key:`17qcm7`}],[`circle`,{cx:`18`,cy:`6`,r:`3`,key:`1h7g24`}],[`circle`,{cx:`6`,cy:`18`,r:`3`,key:`fqmcym`}],[`path`,{d:`M18 9a9 9 0 0 1-9 9`,key:`n2h4wq`}]]),L=f(`History`,[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}],[`path`,{d:`M12 7v5l4 2`,key:`1fdv2h`}]]),R=e(a(),1),z=256;async function B(e,t,n,r,a){r.throwIfAborted();let o=await n(e,t);if(!j.safeParse(o).success)return o;a(!0);try{let a=null,o=!1;for(let e=0;e<z&&!o;e++){r.throwIfAborted();let e=x.parse(await n(`rebuildCopies`,{cursor:a}));o=e.done,a=e.cursor}if(!o)throw new i(`Bonsai is still preparing this repository. Try again shortly.`,{code:`TIMEOUT`,retryable:!0});r.throwIfAborted();let s=await n(e,t);if(j.safeParse(s).success)throw Error(`The repository changed while loading. Refresh to retry.`);return s}finally{a(!1)}}function V({repository:e,branch:t,request:n,onSaved:r,onSaveState:a}){let o=new Map;async function s(r,a){a.throwIfAborted();let o=A.parse(await n(`files.read`,{repo:e,ref:t,path:r}));if(a.throwIfAborted(),o.binary)throw Error(`This Bonsai file is not a text document.`);if(o.text===null&&o.blob!==null)throw new i(`This Bonsai file is too large to edit.`,{code:`FILE_TOO_LARGE`,retryable:!1});return o}async function c(s,c){c.throwIfAborted();let l=w.parse(await n(`files.sync`,{}));c.throwIfAborted();let u=l.settled.find(n=>n.repo===e&&n.branch===t&&n.path===s);if(u){if(u.result.kind===`refused`)throw new i(`Bonsai refused sync: ${u.result.reason}`,{code:`CAPABILITY_DENIED`,retryable:u.result.reason===`background-unavailable`});let e=o.get(s);if(u.result.revision!==e?.version)throw new i(`Your saved file changed. Compare before syncing.`,{code:`CONFLICT`,retryable:!0});a(s,u.result)}r()}async function l(l,u,d,f){f.throwIfAborted();let p=o.get(l);if(d===void 0){let e=await s(l,f);p={file:e,contents:e.pending?.text??e.text??``,version:e.version}}if(!p)throw Error(`Reopen this Bonsai file before saving.`);if(d!==void 0&&p.contents!==d)throw new i(`The file baseline changed. Compare before saving.`,{code:`CONFLICT`,retryable:!0});if(d!==void 0){let e=await s(l,f);if(e.version!==p.version||(e.pending?.text??e.text??``)!==p.contents)throw new i(`The file changed. Compare before saving.`,{code:`CONFLICT`,retryable:!0});e.pending===void 0&&(p.file=e)}let m=F.parse({repo:e,branch:t,path:l,baseCommit:p.file.commit,baseBlob:p.file.blob,text:u,revision:p.version}),h=C.parse(await n(`files.save`,m));if(h.kind===`refused`)throw new i(`Bonsai refused this save: ${h.reason}`,{code:`CAPABILITY_DENIED`,retryable:h.reason===`background-unavailable`});if(a(l,h),h.kind===`conflict`)throw new i(`Your saved file changed. Compare before saving.`,{code:`CONFLICT`,retryable:!0});o.set(l,{file:p.file,contents:u,version:h.revision}),r(),h.kind===`saved`&&c(l,f).catch(e=>{console.error(`Bonsai sync status could not be refreshed`,e),!(o.get(l)?.version!==h.revision||f.aborted)&&a(l,{kind:`failed`,revision:h.revision,reason:`sync_failed`})})}return{kind:`repository`,id:`${e}:${t}`,label:`${e} · ${t}`,async read(e,t,n){let r=n?.revision,i=await s(e,t);if(n?.closed)return{kind:`closed`};if(n&&n.revision!==r)return{kind:`changed`};let c=i.pending?.text??i.text??``;o.set(e,{file:i,contents:c,version:i.version});let l=i.pending;return l?.state===`pending`?a(e,{kind:`saved`,revision:l.revision,state:`pending`}):l?.state===`conflict`?a(e,{kind:`conflict`,revision:l.revision,theirs:l.theirs}):l?.state===`failed`?a(e,{kind:`failed`,revision:l.revision,reason:l.failure??`sync_failed`}):i.version!==null&&a(e,{kind:`synced`,revision:i.version,commit:i.commit}),{kind:`text`,contents:c}},replace:(e,t,n,r)=>l(e,t,n,r),write:(e,t,n)=>l(e,t,void 0,n),async exists(r,i){i.throwIfAborted();let a=D.parse(await n(`files.list`,{repo:e,ref:t}));if(i.throwIfAborted(),a.paths.includes(r))return!0;if(a.truncated)throw Error(`The repository file list is incomplete.`);return!1},retry:c,async discard(s,c){c.throwIfAborted();let l=o.get(s);if(!l)throw Error(`Reopen this saved file before discarding it.`);if(l.version===null)return;let u=N.parse({repo:e,branch:t,path:s,revision:l.version}),d=S.parse(await n(`files.discard`,u));if(c.throwIfAborted(),d.kind===`conflict`)throw new i(`Your saved file changed. Refresh before discarding.`,{code:`CONFLICT`,retryable:!0});o.delete(s),a(s,null),r()},async readCommitted(e,t){let n=await s(e,t),r=n.text??``;return o.has(e)||o.set(e,{file:n,contents:r,version:n.version}),r}}}async function H(e,t,n){let r={repo:t,ref:n},i=O.parse(await e(`files.tree`,{...r,path:``})),a=D.parse(await e(`files.list`,r)),o=E.parse(await e(`commits.list`,{...r,limit:20}));if(i.commit.hash!==a.commit.hash)throw Error(`The repository changed while loading. Refresh to retry.`);return{head:i.commit.hash,branch:n,files:a.paths.map(e=>({path:e})),history:o.commits.map(e=>e.commit),truncated:a.truncated}}var U=r();function W({files:e,rowHeight:n,dirtyPaths:r,activePath:i,busy:a,onRefresh:o,onOpenFile:s}){let c=(0,R.useRef)({files:e,onOpenFile:s});c.current={files:e,onOpenFile:s};let{model:l}=b({paths:[],initialExpansion:`open`,itemHeight:n,onSelectionChange(e){let t=e[0];t&&!t.endsWith(`/`)&&c.current.files.some(e=>e.path===t)&&c.current.onOpenFile(t)}}),u=(0,R.useMemo)(()=>{let t=new Set(r);return e.flatMap(e=>t.has(e.path)?[{path:e.path,status:`modified`}]:[])},[e,r]);(0,R.useEffect)(()=>{l.resetPaths(e.map(e=>e.path))},[l,e]),(0,R.useEffect)(()=>{l.setGitStatus(u)},[l,u]),(0,R.useEffect)(()=>{for(let e of l.getSelectedPaths())e!==i&&l.getItem(e)?.deselect();i&&l.getItem(i)?.select()},[l,i]);let d={flex:`1`,"--trees-item-height":`${String(n)}px`,"--trees-padding-inline-override":`var(--spacing-xs)`,"--trees-item-margin-x-override":`0px`,"--trees-item-padding-x-override":`var(--spacing-xs)`,"--trees-item-row-gap-override":`var(--spacing-xs)`,"--trees-border-radius-override":`var(--radius-field)`,"--trees-bg-override":`var(--color-base-100)`,"--trees-fg-override":`var(--color-base-content)`,"--trees-bg-muted-override":`var(--color-base-200)`,"--trees-selected-bg-override":`var(--color-base-300)`,"--trees-font-family-override":`var(--font-sans)`,"--trees-font-size-override":`12px`};return(0,U.jsxs)(`aside`,{className:`inkcap-tree`,"aria-label":`Repository files`,children:[(0,U.jsxs)(`div`,{className:`inkcap-tree-toolbar`,children:[(0,U.jsxs)(`span`,{children:[(0,U.jsx)(g,{"aria-hidden":`true`}),` Explorer`]}),(0,U.jsx)(t,{icon:(0,U.jsx)(y,{}),"aria-label":`Refresh repository`,variant:`ghost`,size:`responsive`,disabled:a,onClick:o})]}),(0,U.jsx)(`p`,{className:`inkcap-repository-legend`,children:`Changes in latest commit · drafts marked modified`}),(0,U.jsx)(v,{model:l,style:d})]})}var G={all:(e,t)=>[`inkcap-repository`,e,t],branch:(e,t,n)=>[...G.all(e,t),n]},K={branch_missing:`The repository branch no longer exists. Your text is saved; restore the branch before retrying.`,access_changed:`Repository access changed. Your text is saved; restore Bonsai's Git access before retrying.`,sync_failed:`Git could not publish this change. Your text is saved; retry sync.`,permanent_material:`The saved change no longer matches the repository state. Save again to publish your text from the current state.`};function q({connection:e,repository:t,initialBranch:r,initialPath:i,openRequestId:a,transport:f,onReady:g}){let v=m(),[y,b]=(0,R.useState)(!1),[x,S]=(0,R.useState)(0),[C,w]=(0,R.useState)(new Map),[E,D]=(0,R.useState)(``),O=(0,R.useRef)(new AbortController);(0,R.useEffect)(()=>{let e=new AbortController;return O.current=e,()=>{e.abort()}},[]);let A=(0,R.useCallback)((t,n)=>f?f(t,n):e.app.capabilities.require(T).call(`app_bonsai`,t,JSON.stringify(n)),[e.app,f]),j=(0,R.useCallback)((e,t)=>B(e,t,A,O.current.signal,e=>{S(t=>t+(e?1:-1))}),[A]),N=(0,R.useCallback)(()=>{v.invalidateQueries({queryKey:G.all(e.app.identity.surfaceId,t)})},[v,e.app,t]),F=(0,R.useRef)(new Map),z=(0,R.useMemo)(()=>{let n=`${e.app.identity.surfaceId}:${t}:${r}`,i=F.current.get(n);if(i?.app===e.app)return i;let a=V({repository:t,branch:r,request:j,onSaved:N,onSaveState:(e,n)=>{O.current.signal.aborted||w(i=>{let a=new Map(i),o=`${t}:${r}:${e}`;return n===null?a.delete(o):a.set(o,n),a})}}),o={app:e.app,source:a};return F.current.set(n,o),o},[t,r,j,N,e.app]),q=P({connection:z}),J=p({queryKey:G.branch(e.app.identity.surfaceId,t,r),queryFn:()=>H(j,t,r),refetchInterval:15e3});(0,R.useEffect)(()=>e.app.window.onBeforeClose(q.requestWindowClose),[e.app,q.requestWindowClose]),(0,R.useEffect)(()=>{g?.({requestWindowClose:q.requestWindowClose})},[g,q.requestWindowClose]);let Y=(0,R.useRef)(),X=(0,R.useRef)(new Map),Z=(0,R.useRef)(new Set);(0,R.useEffect)(()=>{if(!J.data)return;let e=`${z.app.identity.surfaceId}:${z.source.id}:${a}`;Y.current!==e&&(Y.current=e,q.onOpenFile(i));let t=X.current.get(z.source.id),n=t!==void 0&&t!==J.data.head;X.current.set(z.source.id,J.data.head);let r=new Set(q.tabs.map(e=>e.tabKey));for(let e of Z.current)r.has(e)||Z.current.delete(e);for(let e of q.tabs)if(!(e.target.closed||e.connection!==z||!n&&!Z.current.has(e.tabKey))){if(e.target.saving){Z.current.add(e.tabKey);continue}Z.current.delete(e.tabKey),e.target.dirty||q.onReopen(e,{background:!0})}},[J.data,z,i,a,q]);let Q=q.tabs.find(e=>e.tabKey===q.active),$=Q?.connection?.source?C.get(`${Q.connection.source.id}:${Q.path}`):void 0,ee=$?.kind===`saved`?`Saved · syncing`:$?.kind===`synced`?`Synced · ${$.commit.slice(0,7)}`:$?.kind===`conflict`?`Sync conflict · Compare`:$?.kind===`failed`?`Sync failed · Retry`:void 0;async function te(){if(!Q?.connection?.source)return;let e=F.current.get(`${Q.connection.app.identity.surfaceId}:${Q.connection.source.id}`);if(e)try{D(``),await e.source.retry(Q.path,O.current.signal)}catch(e){console.error(`Bonsai sync retry failed`,e),D(`${n(e).message} Your saved text remains in Bonsai.`)}}async function ne(){if(!Q?.connection?.source)return;let e=()=>!Q.target.dirty&&!Q.target.saving&&!Q.target.closed;if(!e())return;let t=F.current.get(`${Q.connection.app.identity.surfaceId}:${Q.connection.source.id}`);if(t)try{D(``);let n=await t.source.read(Q.path,O.current.signal);if(n.kind!==`text`)throw Error(`This saved text is unavailable.`);if(!e())return;await t.source.replace(Q.path,n.contents,n.contents,O.current.signal)}catch(e){console.error(`Bonsai explicit re-save failed`,e),D(`${n(e).message} Your saved text and open edits remain available.`)}}return(0,U.jsxs)(`div`,{className:`inkcap-repository`,children:[(0,U.jsxs)(`div`,{className:`inkcap-repository-toolbar`,children:[(0,U.jsxs)(`span`,{className:`inkcap-repository-name`,children:[(0,U.jsx)(I,{"aria-hidden":`true`}),` `,t,` · `,r]}),(0,U.jsxs)(l,{size:`sm`,variant:`outline`,onClick:()=>{b(!0)},children:[(0,U.jsx)(L,{"aria-hidden":`true`,className:`size-[var(--stipe-icon-size-sm)]`}),` `,`History`]})]}),x>0&&(0,U.jsx)(M,{message:`Loading this repository…`}),J.data?.truncated&&(0,U.jsx)(_,{tone:`info`,title:`Only the indexed files are shown`}),E&&(0,U.jsx)(h,{message:E,onDismiss:()=>{D(``)}}),$?.kind===`failed`&&!E&&(0,U.jsx)(_,{tone:`warning`,title:$.reason===`permanent_material`?`Sync needs a new save`:`Sync failed`,description:K[$.reason],action:(0,U.jsx)(l,{size:`sm`,disabled:$.reason===`permanent_material`&&Q!==void 0&&(Q.target.dirty||Q.target.saving),onClick:()=>void($.reason===`permanent_material`?ne():te()),children:$.reason===`permanent_material`?`Save again`:`Retry`})}),(0,U.jsx)(k,{model:{...q,repositoryStatus:ee,repositoryStates:C,canList:!0,sourceLabel:z.source.label,onReadCurrent:async(e,t)=>{if(e.connection?.source?.kind!==`repository`)return q.onReadCurrent(e);let n=F.current.get(`${e.connection.app.identity.surfaceId}:${e.connection.source.id}`);if(!n||e.target.closed)throw Error(`This Bonsai file is no longer open.`);return t&&await n.source.discard(e.path,O.current.signal),n.source.readCommitted(e.path,O.current.signal)},error:J.error?`${n(J.error).message} Your open edits remain available.`:void 0,fileTree:(e,t)=>(0,U.jsx)(W,{rowHeight:t?44:32,files:J.data?.files??[],dirtyPaths:q.tabs.filter(e=>e.connection===z&&e.dirty).map(e=>e.path),activePath:Q?.connection===z?Q.path:null,busy:J.isFetching,onRefresh:N,onOpenFile:e},t?`phone`:`desktop`)}}),(0,U.jsx)(o,{open:y,onOpenChange:b,children:(0,U.jsxs)(u,{children:[(0,U.jsxs)(d,{children:[(0,U.jsx)(c,{children:`Commit history`}),(0,U.jsxs)(s,{children:[t,` · `,r]})]}),(0,U.jsx)(`ol`,{className:`inkcap-repository-history`,children:J.data?.history.map(e=>(0,U.jsxs)(`li`,{children:[(0,U.jsx)(`code`,{children:e.hash.slice(0,7)}),` `,e.message,(0,U.jsx)(`span`,{className:`text-dim`,children:e.author.name})]},e.hash))})]})})]})}export{q as InkcapRepositoryApp};