@fungi.computer/inkcap 0.8.4 → 0.8.6

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.
@@ -0,0 +1 @@
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{$t as t,At as n,Br as r,Bt as i,Ct as a,Dt as o,Ft as s,Gt as c,Hn as l,Ht as u,It as d,J as f,Kt as p,Ln as m,Lt as h,Mn as g,Mt as _,Nt as v,Ot as y,Pn as b,Pt as x,Q as S,Rt as C,T as w,Tt as T,Ut as E,Vn as D,Vr as O,Vt as k,Wt as A,Zt as j,an as M,at as ee,ct as te,dt as ne,en as re,et as ie,ft as ae,ht as oe,in as se,it as ce,jt as le,kt as ue,lt as de,mt as fe,ot as pe,pt as N,q as me,qt as he,st as ge,ut as _e,zn as ve,zt as P}from"./tree-path-D47zLaQq.js";var ye=se(`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`}]]),be=se(`Minus`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}]]),xe=se(`Plus`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`M12 5v14`,key:`s699le`}]]),F=e(O(),1);function Se(e,t){return t!=null&&!ae(t)?0:typeof e==`function`?e():e}function Ce(e,t,n){let r=Se(e,n);return typeof r==`number`?r:r?.[t]}function we(e){return typeof e==`function`?e():e}function Te(e,t){return t||e===`click`||e===`mousedown`}function Ee(e){return e?.includes(`mouse`)&&e!==`mousedown`}var I=r(),L=Math.min,R=Math.max,z=Math.round,De=Math.floor,B=e=>({x:e,y:e}),Oe={left:`right`,right:`left`,bottom:`top`,top:`bottom`};function ke(e,t,n){return R(e,L(t,n))}function V(e,t){return typeof e==`function`?e(t):e}function H(e){return e.split(`-`)[0]}function U(e){return e.split(`-`)[1]}function Ae(e){return e===`x`?`y`:`x`}function W(e){return e===`y`?`height`:`width`}function G(e){let t=e[0];return t===`t`||t===`b`?`y`:`x`}function je(e){return Ae(G(e))}function Me(e,t,n){n===void 0&&(n=!1);let r=U(e),i=je(e),a=W(i),o=i===`x`?r===(n?`end`:`start`)?`right`:`left`:r===`start`?`bottom`:`top`;return t.reference[a]>t.floating[a]&&(o=Ve(o)),[o,Ve(o)]}function Ne(e){let t=Ve(e);return[Pe(e),t,Pe(t)]}function Pe(e){return e.includes(`start`)?e.replace(`start`,`end`):e.replace(`end`,`start`)}var Fe=[`left`,`right`],Ie=[`right`,`left`],Le=[`top`,`bottom`],Re=[`bottom`,`top`];function ze(e,t,n){switch(e){case`top`:case`bottom`:return n?t?Ie:Fe:t?Fe:Ie;case`left`:case`right`:return t?Le:Re;default:return[]}}function Be(e,t,n,r){let i=U(e),a=ze(H(e),n===`start`,r);return i&&(a=a.map(e=>e+`-`+i),t&&(a=a.concat(a.map(Pe)))),a}function Ve(e){let t=H(e);return Oe[t]+e.slice(t.length)}function He(e){return{top:e.top??0,right:e.right??0,bottom:e.bottom??0,left:e.left??0}}function Ue(e){return typeof e==`number`?{top:e,right:e,bottom:e,left:e}:He(e)}function We(e){let{x:t,y:n,width:r,height:i}=e;return{width:r,height:i,top:n,left:t,right:t+r,bottom:n+i,x:t,y:n}}var Ge=class e{pointerType=void 0;interactedInside=!1;handler=void 0;blockMouseMove=!0;performedPointerEventsMutation=!1;pointerEventsScopeElement=null;pointerEventsReferenceElement=null;pointerEventsFloatingElement=null;restTimeoutPending=!1;openChangeTimeout=new N;restTimeout=new N;handleCloseOptions=void 0;static create(){return new e}dispose=()=>{this.openChangeTimeout.clear(),this.restTimeout.clear()};disposeEffect=()=>this.dispose},Ke=new WeakMap;function qe(e){if(!e.performedPointerEventsMutation)return;let t=e.pointerEventsScopeElement;t&&Ke.get(t)===e&&(e.pointerEventsScopeElement?.style.removeProperty(`pointer-events`),e.pointerEventsReferenceElement?.style.removeProperty(`pointer-events`),e.pointerEventsFloatingElement?.style.removeProperty(`pointer-events`),Ke.delete(t)),e.performedPointerEventsMutation=!1,e.pointerEventsScopeElement=null,e.pointerEventsReferenceElement=null,e.pointerEventsFloatingElement=null}function Je(e,t){let{scopeElement:n,referenceElement:r,floatingElement:i}=t,a=Ke.get(n);a&&a!==e&&qe(a),qe(e),e.performedPointerEventsMutation=!0,e.pointerEventsScopeElement=n,e.pointerEventsReferenceElement=r,e.pointerEventsFloatingElement=i,Ke.set(n,e),n.style.pointerEvents=`none`,r.style.pointerEvents=`auto`,i.style.pointerEvents=`auto`}function Ye(e){let t=e.context.dataRef.current,n=re(()=>t.hoverInteractionState??Ge.create()).current;return t.hoverInteractionState||=n,oe(t.hoverInteractionState.disposeEffect),t.hoverInteractionState}function Xe(e,t={}){let{enabled:n=!0,closeDelay:r=0,nodeId:s}=t,c=e.useState(`open`),l=e.useState(`floatingElement`),u=e.useState(`domReferenceElement`),{dataRef:d}=e.context,p=f(),m=me(),h=Ye(e),g=fe(),_=ue(()=>Te(d.current.openEvent?.type,h.interactedInside)),v=ue(()=>Ee(d.current.openEvent?.type)),b=ue(()=>{qe(h)});y(()=>{c||(h.pointerType=void 0,h.restTimeoutPending=!1,h.interactedInside=!1,b())},[c,h,b]),F.useEffect(()=>b,[b]),y(()=>{if(n&&c&&h.handleCloseOptions?.blockPointerEvents&&v()&&i(u)&&l){let e=u,t=l,n=o(l),r=p?.nodesRef.current.find(e=>e.id===m)?.context?.elements.floating;r&&(r.style.pointerEvents=``);let i=h.pointerEventsScopeElement===t?null:h.pointerEventsScopeElement,a=r===t?null:r,s=h.handleCloseOptions?.getScope?.()??i??a??de(e,`[data-rootownerid]`)??n.body;return Je(h,{scopeElement:s,referenceElement:e,floatingElement:t}),()=>{b()}}},[n,c,u,l,h,v,p,m,b]),F.useEffect(()=>{if(!n)return;function t(){return!!(p&&m&&ie(p.nodesRef.current,m).length>0)}function o(t){let n=Ce(r,`close`,h.pointerType),i=()=>{e.setOpen(!1,T(a,t)),p?.events.emit(`floating.closed`,t)};n?h.openChangeTimeout.start(n,i):(h.openChangeTimeout.clear(),i())}function c(e){let t=ne(e);if(!ge(t)){h.interactedInside=!1;return}h.interactedInside=de(t,`[aria-haspopup]`)!=null}function u(){h.openChangeTimeout.clear(),g.clear(),p?.events.off(`floating.closed`,y),b()}function f(n){if(t()&&p){p.events.on(`floating.closed`,y);return}if(te(n.relatedTarget,e.context.triggerElements))return;let r=d.current.floatingContext?.nodeId??s,a=n.relatedTarget;if(!(p&&r&&i(a)&&ie(p.nodesRef.current,r,!1).some(e=>_e(e.context?.elements.floating,a)))){if(h.handler){h.handler(n);return}b(),v()&&!_()&&o(n)}}function y(n){!p||!m||t()||g.start(0,()=>{p.events.off(`floating.closed`,y),e.setOpen(!1,T(a,n)),p.events.emit(`floating.closed`,n)})}let x=l;return ee(x&&pe(x,`mouseenter`,u),x&&pe(x,`mouseleave`,f),x&&pe(x,`pointerdown`,c,!0),()=>{p?.events.off(`floating.closed`,y)})},[n,l,e,d,r,s,v,_,b,h,p,m,g])}function Ze(e,t,n){let{reference:r,floating:i}=e,a=G(t),o=je(t),s=W(o),c=H(t),l=a===`y`,u=r.x+r.width/2-i.width/2,d=r.y+r.height/2-i.height/2,f=r[s]/2-i[s]/2,p;switch(c){case`top`:p={x:u,y:r.y-i.height};break;case`bottom`:p={x:u,y:r.y+r.height};break;case`right`:p={x:r.x+r.width,y:d};break;case`left`:p={x:r.x-i.width,y:d};break;default:p={x:r.x,y:r.y}}let m=U(t);return m&&(p[o]+=f*(m===`end`?1:-1)*(n&&l?-1:1)),p}async function Qe(e,t){t===void 0&&(t={});let{x:n,y:r,platform:i,rects:a,elements:o,strategy:s}=e,{boundary:c=`clippingAncestors`,rootBoundary:l=`viewport`,elementContext:u=`floating`,altBoundary:d=!1,padding:f=0}=V(t,e),p=Ue(f),m=o[d?u===`floating`?`reference`:`floating`:u],h=We(await i.getClippingRect({element:await(i.isElement==null?void 0:i.isElement(m))??!0?m:m.contextElement||await(i.getDocumentElement==null?void 0:i.getDocumentElement(o.floating)),boundary:c,rootBoundary:l,strategy:s})),g=u===`floating`?{x:n,y:r,width:a.floating.width,height:a.floating.height}:a.reference,_=await(i.getOffsetParent==null?void 0:i.getOffsetParent(o.floating)),v=await(i.isElement==null?void 0:i.isElement(_))&&await(i.getScale==null?void 0:i.getScale(_))||{x:1,y:1},y=We(i.convertOffsetParentRelativeRectToViewportRelativeRect?await i.convertOffsetParentRelativeRectToViewportRelativeRect({elements:o,rect:g,offsetParent:_,strategy:s}):g);return{top:(h.top-y.top+p.top)/v.y,bottom:(y.bottom-h.bottom+p.bottom)/v.y,left:(h.left-y.left+p.left)/v.x,right:(y.right-h.right+p.right)/v.x}}var $e=50,et=async(e,t,n)=>{let{placement:r=`bottom`,strategy:i=`absolute`,middleware:a=[],platform:o}=n,s=o.detectOverflow?o:{...o,detectOverflow:Qe},c=await(o.isRTL==null?void 0:o.isRTL(t)),l=await o.getElementRects({reference:e,floating:t,strategy:i}),{x:u,y:d}=Ze(l,r,c),f=r,p=0,m={};for(let n=0;n<a.length;n++){let h=a[n];if(!h)continue;let{name:g,fn:_}=h,{x:v,y,data:b,reset:x}=await _({x:u,y:d,initialPlacement:r,placement:f,strategy:i,middlewareData:m,rects:l,platform:s,elements:{reference:e,floating:t}});u=v??u,d=y??d,m[g]={...m[g],...b},x&&p<$e&&(p++,typeof x==`object`&&(x.placement&&(f=x.placement),x.rects&&(l=x.rects===!0?await o.getElementRects({reference:e,floating:t,strategy:i}):x.rects),{x:u,y:d}=Ze(l,f,c)),n=-1)}return{x:u,y:d,placement:f,strategy:i,middlewareData:m}},tt=function(e){return e===void 0&&(e={}),{name:`flip`,options:e,async fn(t){var n;let{placement:r,middlewareData:i,rects:a,initialPlacement:o,platform:s,elements:c}=t,{mainAxis:l=!0,crossAxis:u=!0,fallbackPlacements:d,fallbackStrategy:f=`bestFit`,fallbackAxisSideDirection:p=`none`,flipAlignment:m=!0,...h}=V(e,t);if((n=i.arrow)!=null&&n.alignmentOffset)return{};let g=H(r),_=G(o),v=H(o)===o,y=await(s.isRTL==null?void 0:s.isRTL(c.floating)),b=d||(v||!m?[Ve(o)]:Ne(o)),x=p!==`none`;!d&&x&&b.push(...Be(o,m,p,y));let S=[o,...b],C=await s.detectOverflow(t,h),w=[],T=i.flip?.overflows||[];if(l&&w.push(C[g]),u){let e=Me(r,a,y);w.push(C[e[0]],C[e[1]])}if(T=[...T,{placement:r,overflows:w}],!w.every(e=>e<=0)){let e=(i.flip?.index||0)+1,t=S[e];if(t&&(u!==`alignment`||_===G(t)||T.every(e=>G(e.placement)!==_||e.overflows[0]>0)))return{data:{index:e,overflows:T},reset:{placement:t}};let n=T.filter(e=>e.overflows[0]<=0).sort((e,t)=>e.overflows[1]-t.overflows[1])[0]?.placement;if(!n)switch(f){case`bestFit`:{let e=T.filter(e=>{if(x){let t=G(e.placement);return t===_||t===`y`}return!0}).map(e=>[e.placement,e.overflows.filter(e=>e>0).reduce((e,t)=>e+t,0)]).sort((e,t)=>e[1]-t[1])[0]?.[0];e&&(n=e);break}case`initialPlacement`:n=o}if(r!==n)return{reset:{placement:n}}}return{}}}},nt=new Set([`left`,`top`]);async function rt(e,t){let{placement:n,platform:r,elements:i}=e,a=await(r.isRTL==null?void 0:r.isRTL(i.floating)),o=H(n),s=U(n),c=G(n)===`y`,l=nt.has(o)?-1:1,u=a&&c?-1:1,d=V(t,e),{mainAxis:f,crossAxis:p,alignmentAxis:m}=typeof d==`number`?{mainAxis:d,crossAxis:0,alignmentAxis:null}:{mainAxis:d.mainAxis||0,crossAxis:d.crossAxis||0,alignmentAxis:d.alignmentAxis};return s&&typeof m==`number`&&(p=s===`end`?m*-1:m),c?{x:p*u,y:f*l}:{x:f*l,y:p*u}}var it=function(e){return e===void 0&&(e=0),{name:`offset`,options:e,async fn(t){var n;let{x:r,y:i,placement:a,middlewareData:o}=t,s=await rt(t,e);return a===o.offset?.placement&&(n=o.arrow)!=null&&n.alignmentOffset?{}:{x:r+s.x,y:i+s.y,data:{...s,placement:a}}}}},at=function(e){return e===void 0&&(e={}),{name:`shift`,options:e,async fn(t){let{x:n,y:r,placement:i,platform:a}=t,{mainAxis:o=!0,crossAxis:s=!1,limiter:c={fn:e=>{let{x:t,y:n}=e;return{x:t,y:n}}},...l}=V(e,t),u={x:n,y:r},d=await a.detectOverflow(t,l),f=G(i),p=Ae(f),m=u[p],h=u[f],g=(e,t)=>ke(t+d[e===`y`?`top`:`left`],t,t-d[e===`y`?`bottom`:`right`]);o&&(m=g(p,m)),s&&(h=g(f,h));let _=c.fn({...t,[p]:m,[f]:h});return{..._,data:{x:_.x-n,y:_.y-r,enabled:{[p]:o,[f]:s}}}}}},ot=function(e){return e===void 0&&(e={}),{options:e,fn(t){let{x:n,y:r,placement:i,rects:a,middlewareData:o}=t,{offset:s=0,mainAxis:c=!0,crossAxis:l=!0}=V(e,t),u={x:n,y:r},d=G(i),f=Ae(d),p=u[f],m=u[d],h=V(s,t),g=typeof h==`number`?{mainAxis:h,crossAxis:0}:{mainAxis:h.mainAxis??0,crossAxis:h.crossAxis??0};if(c){let e=f===`y`?`height`:`width`,t=a.reference[f]-a.floating[e]+g.mainAxis,n=a.reference[f]+a.reference[e]-g.mainAxis;p<t?p=t:p>n&&(p=n)}if(l){let e=f===`y`?`width`:`height`,t=nt.has(H(i)),n=a.reference[d]-a.floating[e]+(t&&o.offset?.[d]||0)+(t?0:g.crossAxis),r=a.reference[d]+a.reference[e]+(t?0:o.offset?.[d]||0)-(t?g.crossAxis:0);m<n?m=n:m>r&&(m=r)}return{[f]:p,[d]:m}}}},st=function(e){return e===void 0&&(e={}),{name:`size`,options:e,async fn(t){let{placement:n,rects:r,platform:i,elements:a}=t,{apply:o=()=>{},...s}=V(e,t),c=await i.detectOverflow(t,s),l=H(n),u=U(n),d=G(n)===`y`,{width:f,height:p}=r.floating,m,h;l===`top`||l===`bottom`?(m=l,h=u===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?`start`:`end`)?`left`:`right`):(h=l,m=u===`end`?`top`:`bottom`);let g=p-c.top-c.bottom,_=f-c.left-c.right,v=L(p-c[m],g),y=L(f-c[h],_),b=t.middlewareData.shift,x=!b,S=v,C=y;b!=null&&b.enabled.x&&(C=_),b!=null&&b.enabled.y&&(S=g),x&&!u&&(d?C=f-2*R(c.left,c.right):S=p-2*R(c.top,c.bottom)),await o({...t,availableWidth:C,availableHeight:S});let w=await i.getDimensions(a.floating);return f!==w.width||p!==w.height?{reset:{rects:!0}}:{}}}};function ct(e){let t=n(e),r=parseFloat(t.width)||0,i=parseFloat(t.height)||0,a=k(e),o=a?e.offsetWidth:r,s=a?e.offsetHeight:i,c=z(r)!==o||z(i)!==s;return c&&(r=o,i=s),{width:r,height:i,$:c}}function lt(e){return i(e)?e:e.contextElement}function ut(e){let t=lt(e);if(!k(t))return B(1);let n=t.getBoundingClientRect(),{width:r,height:i,$:a}=ct(t),o=(a?z(n.width):n.width)/r,s=(a?z(n.height):n.height)/i;return(!o||!Number.isFinite(o))&&(o=1),(!s||!Number.isFinite(s))&&(s=1),{x:o,y:s}}var dt=B(0);function ft(e){let t=C(e);return!p()||!t.visualViewport?dt:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function pt(e,t,n){return t===void 0&&(t=!1),!!n&&t&&n===C(e)}function mt(e,t,r,a){t===void 0&&(t=!1),r===void 0&&(r=!1);let o=e.getBoundingClientRect(),s=lt(e),c=B(1);t&&(a?i(a)&&(c=ut(a)):c=ut(e));let l=pt(s,r,a)?ft(s):B(0),u=(o.left+l.x)/c.x,d=(o.top+l.y)/c.y,f=o.width/c.x,p=o.height/c.y;if(s&&a){let e=C(s),t=i(a)?C(a):a,r=e,o=v(r);for(;o&&t!==r;){let e=ut(o),t=o.getBoundingClientRect(),i=n(o),a=t.left+(o.clientLeft+parseFloat(i.paddingLeft))*e.x,s=t.top+(o.clientTop+parseFloat(i.paddingTop))*e.y;u*=e.x,d*=e.y,f*=e.x,p*=e.y,u+=a,d+=s,r=C(o),o=v(r)}}return We({width:f,height:p,x:u,y:d})}function ht(e,t){let n=s(e).scrollLeft;return t?t.left+n:mt(_(e)).left+n}function gt(e,t){let n=e.getBoundingClientRect();return{x:n.left+t.scrollLeft-ht(e,n),y:n.top+t.scrollTop}}function _t(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e,a=i===`fixed`,o=_(r),l=t?c(t.floating):!1;if(r===o||l&&a)return n;let u={scrollLeft:0,scrollTop:0},d=B(1),f=B(0),p=k(r);if((p||!a)&&((x(r)!==`body`||E(o))&&(u=s(r)),p)){let e=mt(r);d=ut(r),f.x=e.x+r.clientLeft,f.y=e.y+r.clientTop}let m=o&&!p&&!a?gt(o,u):B(0);return{width:n.width*d.x,height:n.height*d.y,x:n.x*d.x-u.scrollLeft*d.x+f.x+m.x,y:n.y*d.y-u.scrollTop*d.y+f.y+m.y}}function vt(e){return e.getClientRects?Array.from(e.getClientRects()):[]}function yt(e){let t=s(e),r=e.ownerDocument.body,i=R(e.scrollWidth,e.clientWidth,r.scrollWidth,r.clientWidth),a=R(e.scrollHeight,e.clientHeight,r.scrollHeight,r.clientHeight),o=-t.scrollLeft+ht(e),c=-t.scrollTop;return n(r).direction===`rtl`&&(o+=R(e.clientWidth,r.clientWidth)-i),{width:i,height:a,x:o,y:c}}var bt=25;function xt(e,t,n){n===void 0&&(n=`viewport`);let r=n===`layoutViewport`,i=C(e),a=_(e),o=i.visualViewport,s=a.clientWidth,c=a.clientHeight,l=0,u=0;if(o){let e=!p()||t===`fixed`;r?e||(l=-o.offsetLeft,u=-o.offsetTop):(s=o.width,c=o.height,e&&(l=o.offsetLeft,u=o.offsetTop))}if(ht(a)<=0){let e=a.ownerDocument,t=e.body,n=getComputedStyle(t),r=e.compatMode===`CSS1Compat`&&parseFloat(n.marginLeft)+parseFloat(n.marginRight)||0,i=Math.abs(a.clientWidth-t.clientWidth-r),o=getComputedStyle(a).scrollbarGutter===`stable both-edges`?i/2:i;o<=bt&&(s-=o)}return{width:s,height:c,x:l,y:u}}function St(e,t){let n=mt(e,!0,t===`fixed`),r=n.top+e.clientTop,i=n.left+e.clientLeft,a=ut(e);return{width:e.clientWidth*a.x,height:e.clientHeight*a.y,x:i*a.x,y:r*a.y}}function Ct(e,t,n){let r;if(t===`viewport`||t===`layoutViewport`)r=xt(e,n,t);else if(t===`document`)r=yt(_(e));else if(i(t))r=St(t,n);else{let n=ft(e);r={x:t.x-n.x,y:t.y-n.y,width:t.width,height:t.height}}return We(r)}function wt(e,t){let r=t.get(e);if(r)return r;let a=d(e,[],!1).filter(e=>i(e)&&x(e)!==`body`),o=null,s=n(e).position===`fixed`,c=s?h(e):e;for(;i(c)&&!u(c);){let e=n(c),t=P(c),r=o?o.position:s?`fixed`:``;!t&&(r===`fixed`||r===`absolute`&&e.position===`static`)?a=a.filter(e=>e!==c):o=e,c=h(c)}return t.set(e,a),a}function Tt(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e,a=[...n===`clippingAncestors`?c(t)?[]:wt(t,this._c):[].concat(n),r],o=Ct(t,a[0],i),s=o.top,l=o.right,u=o.bottom,d=o.left;for(let e=1;e<a.length;e++){let n=Ct(t,a[e],i);s=R(n.top,s),l=L(n.right,l),u=L(n.bottom,u),d=R(n.left,d)}return{width:l-d,height:u-s,x:d,y:s}}function Et(e){let{width:t,height:n}=ct(e);return{width:t,height:n}}function Dt(e,t,n){let r=k(t),i=_(t),a=n===`fixed`,o=mt(e,!0,a,t),c={scrollLeft:0,scrollTop:0},l=B(0);if((r||!a)&&((x(t)!==`body`||E(i))&&(c=s(t)),r)){let e=mt(t,!0,a,t);l.x=e.x+t.clientLeft,l.y=e.y+t.clientTop}!r&&i&&(l.x=ht(i));let u=i&&!r&&!a?gt(i,c):B(0);return{x:o.left+c.scrollLeft-l.x-u.x,y:o.top+c.scrollTop-l.y-u.y,width:o.width,height:o.height}}function Ot(e){return n(e).position===`static`}function kt(e,t){if(!k(e)||n(e).position===`fixed`)return null;if(t)return t(e);let r=e.offsetParent;return _(e)===r&&(r=r.ownerDocument.body),r}function At(e,t){let n=C(e);if(c(e))return n;if(!k(e)){let t=h(e);for(;t&&!u(t);){if(i(t)&&!Ot(t))return t;t=h(t)}return n}let r=kt(e,t);for(;r&&A(r)&&Ot(r);)r=kt(r,t);return r&&u(r)&&Ot(r)&&!P(r)?n:r||le(e)||n}var jt=async function(e){let t=this.getOffsetParent||At,n=this.getDimensions,r=await n(e.floating);return{reference:Dt(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function Mt(e){return n(e).direction===`rtl`}var Nt={convertOffsetParentRelativeRectToViewportRelativeRect:_t,getDocumentElement:_,getClippingRect:Tt,getOffsetParent:At,getElementRects:jt,getClientRects:vt,getDimensions:Et,getScale:ut,isElement:i,isRTL:Mt};function Pt(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function Ft(e,t,n){let r=null,i,a=_(e);function o(){var e;clearTimeout(i),(e=r)==null||e.disconnect(),r=null}function s(n,c){n===void 0&&(n=!1),c===void 0&&(c=1),o();let l=e.getBoundingClientRect(),{left:u,top:d,width:f,height:p}=l;if(n||t(),!f||!p)return;let m=De(d),h=De(a.clientWidth-(u+f)),g=De(a.clientHeight-(d+p)),_=De(u),v={rootMargin:-m+`px `+-h+`px `+-g+`px `+-_+`px`,threshold:R(0,L(1,c))||1},y=!0;function b(t){let n=t[0].intersectionRatio;if(!Pt(l,e.getBoundingClientRect()))return s();if(n!==c){if(!y)return s();n?s(!1,n):i=setTimeout(()=>{s(!1,1e-7)},1e3)}y=!1}try{r=new IntersectionObserver(b,{...v,root:a.ownerDocument})}catch{r=new IntersectionObserver(b,v)}r.observe(e)}let c=C(e),l=()=>s(n);return c.addEventListener(`resize`,l),s(!0),()=>{c.removeEventListener(`resize`,l),o()}}function It(e,t,n,r){r===void 0&&(r={});let{ancestorScroll:i=!0,ancestorResize:a=!0,elementResize:o=typeof ResizeObserver==`function`,layoutShift:s=typeof IntersectionObserver==`function`,animationFrame:c=!1}=r,l=lt(e),u=i||a?[...l?d(l):[],...t?d(t):[]]:[];u.forEach(e=>{i&&e.addEventListener(`scroll`,n),a&&e.addEventListener(`resize`,n)});let f=l&&s?Ft(l,n,a):null,p=-1,m=null;o&&(m=new ResizeObserver(e=>{let[r]=e;r&&r.target===l&&m&&t&&(m.unobserve(t),cancelAnimationFrame(p),p=requestAnimationFrame(()=>{var e;(e=m)==null||e.observe(t)})),n()}),l&&!c&&m.observe(l),t&&m.observe(t));let h,g=c?mt(e):null;c&&_();function _(){let t=mt(e);g&&!Pt(g,t)&&n(),g=t,h=requestAnimationFrame(_)}return n(),()=>{var e;u.forEach(e=>{i&&e.removeEventListener(`scroll`,n),a&&e.removeEventListener(`resize`,n)}),f?.(),(e=m)==null||e.disconnect(),m=null,c&&cancelAnimationFrame(h)}}var Lt=it,Rt=at,zt=tt,Bt=st,Vt=ot,Ht=(e,t,n)=>{let r=new Map,i=n??{},a={...Nt,...i.platform,_c:r};return et(e,t,{...i,platform:a})},Ut=e(l(),1),Wt=typeof document<`u`?F.useLayoutEffect:function(){};function Gt(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(typeof e==`function`&&e.toString()===t.toString())return!0;let n,r,i;if(e&&t&&typeof e==`object`){if(Array.isArray(e)){if(n=e.length,n!==t.length)return!1;for(r=n;r--!==0;)if(!Gt(e[r],t[r]))return!1;return!0}if(i=Object.keys(e),n=i.length,n!==Object.keys(t).length)return!1;for(r=n;r--!==0;)if(!{}.hasOwnProperty.call(t,i[r]))return!1;for(r=n;r--!==0;){let n=i[r];if(!(n===`_owner`&&e.$$typeof)&&!Gt(e[n],t[n]))return!1}return!0}return e!==e&&t!==t}function Kt(e){return typeof window>`u`?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function qt(e,t){let n=Kt(e);return Math.round(t*n)/n}function Jt(e){let t=F.useRef(e);return Wt(()=>{t.current=e}),t}function Yt(e){e===void 0&&(e={});let{placement:t=`bottom`,strategy:n=`absolute`,middleware:r=[],platform:i,elements:{reference:a,floating:o}={},transform:s=!0,whileElementsMounted:c,open:l}=e,[u,d]=F.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[f,p]=F.useState(r);Gt(f,r)||p(r);let[m,h]=F.useState(null),[g,_]=F.useState(null),v=F.useCallback(e=>{e!==S.current&&(S.current=e,h(e))},[]),y=F.useCallback(e=>{e!==C.current&&(C.current=e,_(e))},[]),b=a||m,x=o||g,S=F.useRef(null),C=F.useRef(null),w=F.useRef(u),T=c!=null,E=Jt(c),D=Jt(i),O=Jt(l),k=F.useCallback(()=>{if(!S.current||!C.current)return;let e={placement:t,strategy:n,middleware:f};D.current&&(e.platform=D.current),Ht(S.current,C.current,e).then(e=>{let t={...e,isPositioned:O.current!==!1};A.current&&!Gt(w.current,t)&&(w.current=t,Ut.flushSync(()=>{d(t)}))})},[f,t,n,D,O]);Wt(()=>{l===!1&&w.current.isPositioned&&(w.current.isPositioned=!1,d(e=>({...e,isPositioned:!1})))},[l]);let A=F.useRef(!1);Wt(()=>(A.current=!0,()=>{A.current=!1}),[]),Wt(()=>{if(b&&(S.current=b),x&&(C.current=x),b&&x){if(E.current)return E.current(b,x,k);k()}},[b,x,k,E,T]);let j=F.useMemo(()=>({reference:S,floating:C,setReference:v,setFloating:y}),[v,y]),M=F.useMemo(()=>({reference:b,floating:x}),[b,x]),ee=F.useMemo(()=>{let e={position:n,left:0,top:0};if(!M.floating)return e;let t=qt(M.floating,u.x),r=qt(M.floating,u.y);return s?{...e,transform:`translate(`+t+`px, `+r+`px)`,...Kt(M.floating)>=1.5&&{willChange:`transform`}}:{position:n,left:t,top:r}},[n,s,M.floating,u.x,u.y]);return F.useMemo(()=>({...u,update:k,refs:j,elements:M,floatingStyles:ee}),[u,k,j,M,ee])}var Xt=(e,t)=>{let n=Lt(e);return{name:n.name,fn:n.fn,options:[e,t]}},Zt=(e,t)=>{let n=Rt(e);return{name:n.name,fn:n.fn,options:[e,t]}},Qt=(e,t)=>({fn:Vt(e).fn,options:[e,t]}),$t=(e,t)=>{let n=zt(e);return{name:n.name,fn:n.fn,options:[e,t]}},en=(e,t)=>{let n=Bt(e);return{name:n.name,fn:n.fn,options:[e,t]}},tn=(0,F.forwardRef)(function({className:e,invalid:t,...n},r){return(0,I.jsx)(`input`,{...n,"aria-invalid":t?!0:n[`aria-invalid`]===!1?void 0:n[`aria-invalid`],className:D(`input caps-input w-full`,e),ref:r})});(0,F.forwardRef)(function({leading:e,className:t,...n},r){return(0,I.jsxs)(`span`,{className:`caps-search-input`,"data-leading":e?`true`:void 0,children:[e?(0,I.jsx)(`span`,{className:`caps-search-leading`,"aria-hidden":`true`,children:e}):null,(0,I.jsx)(tn,{...n,type:`search`,className:t,ref:r})]})});function nn(e){let{nodeId:t,externalTree:n,rootContext:r}=e,a=r.useState(`referenceElement`),o=r.useState(`floatingElement`),s=r.useState(`domReferenceElement`),c=r.useState(`open`),l=r.useState(`floatingId`),[u,d]=F.useState(null),p=F.useRef(null),m=f(n),h=F.useMemo(()=>({reference:a,floating:o,domReference:s}),[a,o,s]),g=Yt({...e,elements:{...h,...u&&{reference:u}}}),_=F.useCallback(e=>{let t=i(e)?{getBoundingClientRect:()=>e.getBoundingClientRect(),getClientRects:()=>e.getClientRects(),contextElement:e}:e;d(t),g.refs.setReference(t)},[g.refs]),v=F.useMemo(()=>({...g.refs,setPositionReference:_,domReference:p}),[g.refs,_]),b=F.useMemo(()=>({...g.elements,domReference:s}),[g.elements,s]),x=F.useMemo(()=>({...g,dataRef:r.context.dataRef,open:c,onOpenChange:r.setOpen,events:r.context.events,floatingId:l,refs:v,elements:b,nodeId:t,rootStore:r}),[g,v,b,t,r,c,l]);return y(()=>{s&&(p.current=s)},[s]),y(()=>{r.context.dataRef.current.floatingContext=x;let e=m?.nodesRef.current.find(e=>e.id===t);e&&(e.context=x)}),F.useMemo(()=>({...g,context:x,refs:v,elements:b,rootStore:r}),[g,v,b,x,r])}var rn=F.createContext(void 0);function an(){return F.useContext(rn)?.direction??`ltr`}var on=e=>({name:`arrow`,options:e,async fn(t){let{x:n,y:r,placement:i,rects:a,platform:o,elements:s,middlewareData:c}=t,{element:l,padding:u=0}=V(e,t)||{};if(l==null)return{};let d=Ue(u),f={x:n,y:r},p=je(i),m=W(p),h=await o.getDimensions(l),g=p===`y`,_=g?`top`:`left`,v=g?`bottom`:`right`,y=g?`clientHeight`:`clientWidth`,b=a.reference[m]+a.reference[p]-f[p]-a.floating[m],x=f[p]-a.reference[p],S=s.floating[y]||a.floating[m],C=b/2-x/2,w=S/2-h[m]/2-1,T=Math.min(d[_],w),E=Math.min(d[v],w),D=T,O=S-h[m]-E,k=S/2-h[m]/2+C,A=ke(D,k,O),j=!c.arrow&&U(i)!=null&&k!==A&&a.reference[m]/2-(k<D?T:E)-h[m]/2<0,M=j?k<D?k-D:k-O:0;return{[p]:f[p]+M,data:{[p]:A,centerOffset:k-A-M,...j&&{alignmentOffset:M}},reset:j}}}),sn=(e,t)=>{let{name:n,fn:r}=on(e);return{name:n,fn:r,options:[e,t]}},cn={name:`hide`,async fn(e){let{width:t,height:n,x:r,y:i}=e.rects.reference,a=t===0&&n===0&&r===0&&i===0,o=await e.platform.detectOverflow(e,{elementContext:`reference`});return{data:{referenceHidden:o.top-n>=0||o.right-t>=0||o.bottom-n>=0||o.left-t>=0||a}}}},ln={sideX:`left`,sideY:`top`},un=`--available-width`,dn=`--available-height`,fn=`--anchor-width`,pn=`--anchor-height`,mn=`--transform-origin`,hn=un,gn=dn;function _n(e,t,n){let r=e===`inline-start`||e===`inline-end`;return{top:`top`,right:r?n?`inline-start`:`inline-end`:`right`,bottom:`bottom`,left:r?n?`inline-end`:`inline-start`:`left`}[t]}function vn(e,t,n){let{rects:r,placement:i}=e;return{side:_n(t,H(i),n),align:U(i)||`center`,anchor:{width:r.reference.width,height:r.reference.height},positioner:{width:r.floating.width,height:r.floating.height}}}function yn(e){return bn(e,nn)}function bn(e,t){let{anchor:n,positionMethod:r=`absolute`,side:i=`bottom`,sideOffset:a=0,align:s=`center`,alignOffset:c=0,collisionBoundary:l,collisionPadding:u=5,sticky:d=!1,arrowPadding:f=5,disableAnchorTracking:p=!1,inline:m,keepMounted:h=!1,floatingRootContext:g,mounted:_,collisionAvoidance:v,shift:b,nodeId:x,adaptiveOrigin:S,lazyFlip:w=!1,externalTree:T}=e,E=v.side||`flip`,D=v.align||`flip`,O=v.fallbackAxisSide||`end`,k=b?.crossAxis??!1,A=b?.rootBoundary,j=typeof n==`function`?n:void 0,M=ue(j),ee=j?M:n,te=ce(n),ne=ce(_),re=an()===`rtl`,[ie,ae]=F.useState(null);!_&&ie!==null&&ae(null);let oe=w===`placement`,se=ie?H(ie):null,le=ie&&oe?U(ie)||`center`:null,de=se||{top:`top`,right:`right`,bottom:`bottom`,left:`left`,"inline-end":re?`left`:`right`,"inline-start":re?`right`:`left`}[i],fe=le||s,pe=fe===`center`?de:`${de}-${fe}`,N=u;typeof N==`number`?N={top:N,right:N,bottom:N,left:N}:N&&={top:N.top||0,right:N.right||0,bottom:N.bottom||0,left:N.left||0};let me=+(i===`bottom`),he=+(i===`top`),ge=+(i===`right`),_e=+(i===`left`),ve={boundary:l===`clipping-ancestors`?`clippingAncestors`:l,padding:N},P=F.useRef(null),ye=ce(a),be=ce(c),xe=typeof a==`function`?0:a,Se=typeof c==`function`?0:c,Ce=[];m&&Ce.push(m),Ce.push(Xt(e=>{let t=vn(e,i,re),n=typeof ye.current==`function`?ye.current(t):ye.current,r=typeof be.current==`function`?be.current(t):be.current;return{mainAxis:n,crossAxis:r,alignmentAxis:r}},[xe,Se,re,i]));let we=D===`none`&&E!==`shift`,Te=!we&&(d||k||E===`shift`),Ee=E===`none`?null:$t({...ve,padding:{top:N.top+1+me,right:N.right+1+_e,bottom:N.bottom+1+he,left:N.left+1+ge},mainAxis:!k&&E===`flip`,crossAxis:D===`flip`&&`alignment`,fallbackAxisSideDirection:O}),I=we?null:Zt({...ve,rootBoundary:A,mainAxis:D!==`none`,crossAxis:Te,limiter:d||k?void 0:Qt(e=>{if(!P.current)return{};let{width:t,height:n}=P.current.getBoundingClientRect(),r=G(H(e.placement)),i=r===`y`?t:n,a=r===`y`?N.left+N.right:N.top+N.bottom;return{offset:i/2+a/2}})},[ve,d,k,A,N,D]);E===`shift`||D===`shift`||fe===`center`?Ce.push(I,Ee):Ce.push(Ee,I),Ce.push(en({...ve,apply({elements:{floating:e},availableWidth:t,availableHeight:n,rects:r}){if(!ne.current)return;let i=e.style;i.setProperty(hn,`${t}px`),i.setProperty(gn,`${n}px`);let a=C(e).devicePixelRatio||1,{x:o,y:s,width:c,height:l}=r.reference,u=(Math.round((o+c)*a)-Math.round(o*a))/a,d=(Math.round((s+l)*a)-Math.round(s*a))/a;i.setProperty(fn,`${u}px`),i.setProperty(pn,`${d}px`)}}),sn(e=>({element:P.current||o(e.elements.floating).createElement(`div`),padding:P.current?f:0}),[f]),{name:`transformOrigin`,fn(e){let{elements:{floating:t},middlewareData:n,placement:r,platform:o,rects:s,y:c}=e,l=H(r),u=U(r),d=G(l)===`y`,f=P.current,p=typeof a==`function`?a(vn(e,i,re)):a,m;m=!f&&u&&Math.abs(d?n.shift?.x||0:n.shift?.y||0)<=1?u===`start`===(d&&o.isRTL?.(t)===!0)?`100%`:`0%`:`${(d?n.arrow?.x||0:n.arrow?.y||0)+(d?f?.clientWidth||0:f?.clientHeight||0)/2}px`;let h=l===`top`||l===`left`?`calc(100% + ${p}px)`:`${-p}px`;return Te&&d&&Math.abs(n.shift?.y||0)>p&&(h=`${s.reference.y+s.reference.height/2-c}px`),t.style.setProperty(mn,d?`${m} ${h}`:`${h} ${m}`),{}}},cn,S),y(()=>{!_&&g&&g.update({referenceElement:null,floatingElement:null,domReferenceElement:null,positionReference:null})},[_,g]);let L=F.useMemo(()=>({ancestorScroll:!p,elementResize:!p&&typeof ResizeObserver<`u`,layoutShift:!p&&typeof IntersectionObserver<`u`}),[p]),{refs:R,elements:z,x:De,y:B,middlewareData:Oe,update:ke,placement:V,context:Ae,isPositioned:W,floatingStyles:je}=t({rootContext:g,open:h?_:void 0,placement:pe,middleware:Ce,strategy:r,whileElementsMounted:h?void 0:(...e)=>It(...e,L),nodeId:x,externalTree:T}),{sideX:Me,sideY:Ne}=Oe.adaptiveOrigin||ln,Pe=W?r:`fixed`,Fe=F.useMemo(()=>{let e;return e=W?S?{position:Pe,[Me]:De,[Ne]:B}:{...je,position:Pe}:{position:Pe,top:0,left:0},e[hn]=`100vw`,e[gn]=`100vh`,W||(e.opacity=0),e},[S,Pe,Me,De,Ne,B,je,W]),Ie=F.useRef(null);y(()=>{if(!_)return;let e=te.current,t=typeof e==`function`?e():e,n=(xn(t)?t.current:t)||null;n!==Ie.current&&(R.setPositionReference(n),Ie.current=n)},[_,R,ee,te]),F.useEffect(()=>{if(!_)return;let e=te.current;typeof e!=`function`&&xn(e)&&e.current!==Ie.current&&(R.setPositionReference(e.current),Ie.current=e.current)},[_,R,ee,te]),F.useEffect(()=>{if(h&&_&&z.reference&&z.floating)return It(z.reference,z.floating,ke,L)},[h,_,z,ke,L]);let Le=H(V),Re=_n(i,Le,re),ze=U(V)||`center`,Be=!!Oe.hide?.referenceHidden;y(()=>{w&&_&&W&&(Le!==de||oe&&ze!==fe)&&ae(V)},[w,oe,_,W,V,Le,ze,de,fe]);let Ve=F.useMemo(()=>({position:`absolute`,top:Oe.arrow?.y,left:Oe.arrow?.x}),[Oe.arrow]),He=Oe.arrow?.centerOffset!==0;return F.useMemo(()=>({positionerStyles:Fe,arrowStyles:Ve,arrowRef:P,arrowUncentered:He,side:Re,align:ze,physicalSide:Le,anchorHidden:Be,refs:R,context:Ae,isPositioned:W,update:ke}),[Fe,Ve,P,He,Re,ze,Le,Be,R,Ae,W,ke])}function xn(e){return e!=null&&`current`in e}function Sn(e){return e===`starting`?S:t}function Cn(e,t,{styles:n,transitionStatus:r,props:i,refs:a,hidden:o,inert:s=!1}){let c={...n};return s&&(c.pointerEvents=`none`),j(`div`,e,{state:t,ref:a,props:[{role:`presentation`,hidden:o,style:c},Sn(r),i],stateAttributesMapping:he})}var wn=(0,F.forwardRef)(function({children:e,className:t,optional:n,required:r,...i},a){return(0,I.jsxs)(`label`,{...i,className:D(`label caps-label cursor-pointer justify-start gap-sm text-sm font-semibold text-base-content`,t),ref:a,children:[e,r?(0,I.jsx)(`span`,{"aria-hidden":`true`,className:`text-error`,children:`*`}):null,n&&!r?(0,I.jsx)(`span`,{className:`caps-label-optional`,children:`Optional`}):null]})}),Tn=(0,F.forwardRef)(function({children:e,className:t,...n},r){return(0,I.jsx)(`div`,{...n,className:D(`caps-input-group join flex w-full items-stretch [&>*]:join-item [&>*:first-child]:rounded-e-none [&>*:last-child]:rounded-s-none [&>*:not(:first-child):not(:last-child)]:rounded-none [&>.btn]:shrink-0 [&>.input]:min-w-0 [&>.input]:flex-1 [&>.select]:min-w-0 [&>.select]:flex-1`,t),ref:r,children:F.Children.map(e,e=>(0,F.isValidElement)(e)?(0,F.cloneElement)(e,{className:D(`join-item caps-input-group-control`,e.props.className)}):e)})}),En=(0,F.forwardRef)(function({className:e,...t},n){return(0,I.jsx)(`div`,{...t,className:D(`join-item flex items-center border border-base-300 bg-base-200 px-md text-sm text-base-content`,e),ref:n})});function Dn(e){let t=e.parentElement;if(!t||e.previousElementSibling===null)return 0;let n=getComputedStyle(t);if(!(n.display.includes(`grid`)||n.display.includes(`flex`)&&n.flexDirection.startsWith(`column`)))return 0;let r=Number.parseFloat(n.rowGap);return Number.isFinite(r)?r:0}(0,F.forwardRef)(function({show:e,appear:t=!1,children:n,className:r,...i},a){let o=(0,F.useRef)(null);(0,F.useImperativeHandle)(a,()=>o.current);let s=ve(),[c,l]=(0,F.useState)(e),u=(0,F.useRef)(!0);return e&&!c&&l(!0),(0,F.useLayoutEffect)(()=>{let n=o.current,r=u.current;if(u.current=!1,!n||r&&!t)return;if(!g(n)){e||l(!1);return}let i=m(n),a=`translateY(${String(i.distance)}px)`,c=b(i,i.ease),d=n.getBoundingClientRect().height,f=Dn(n),p=(e,t)=>{n.style.overflow=`clip`;let r=e=>({height:`${String(e)}px`,marginBlockStart:`${String(e===0?-f:0)}px`}),a=n.animate([r(e),r(t)],{duration:i.normal,easing:c}),o=()=>{n.style.removeProperty(`overflow`)};return a.addEventListener(`finish`,o),a.addEventListener(`cancel`,o),a};if(e){let e=[n.animate([{opacity:0,transform:a},{opacity:1,transform:`none`}],{duration:i.normal,easing:c})];return!s&&d>0&&e.push(p(0,d)),()=>{for(let t of e)t.cancel()}}let h=n.animate([{opacity:1,transform:`none`},{opacity:0,transform:a}],{duration:i.fast,easing:b(i,i.easeExit),fill:`forwards`}),_=!s&&d>0?p(d,0):h;return _!==h&&_.effect?.updateTiming({fill:`forwards`}),_.addEventListener(`finish`,()=>{l(!1)}),()=>{h.cancel(),_.cancel()}},[e,t,s]),c?(0,I.jsx)(`div`,{...i,ref:o,className:D(`caps-presence`,r),"data-present":e,"aria-hidden":!e||void 0,children:n}):null});var On=(0,F.forwardRef)(function({open:e,children:t,className:n,...r},i){return(0,I.jsx)(`div`,{...r,ref:i,className:D(`caps-collapse`,n),"data-open":e,"aria-hidden":!e||void 0,children:(0,I.jsx)(`div`,{className:`caps-collapse-clip`,children:t})})});(0,F.forwardRef)(function({swapKey:e,anchor:t=`start`,children:n,className:r,...i},a){let o=(0,F.useRef)(null);(0,F.useImperativeHandle)(a,()=>o.current);let s=ve(),[c,l]=(0,F.useState)({key:e,content:n}),[u,d]=(0,F.useState)([]);c.key===e?c.content!==n&&l({key:e,content:n}):(d([...u.filter(t=>t.key!==e&&t.key!==c.key),c]),l({key:e,content:n}));let f=(0,F.useRef)(null);return(0,F.useLayoutEffect)(()=>{let e=o.current;if(!e||!(`ResizeObserver`in globalThis))return;f.current=e.getBoundingClientRect();let t=new ResizeObserver(()=>{e.getAnimations().length===0&&(f.current=e.getBoundingClientRect())});return t.observe(e),()=>{t.disconnect()}},[]),(0,F.useLayoutEffect)(()=>{let e=o.current;if(!e)return;let t=[...e.querySelectorAll(`:scope > [data-swap-leaving]`)],n=e.querySelector(`:scope > [data-swap-current]`);if(n===null||t.length===0)return;if(!g(e)){d([]);return}let r=f.current,i=e.getBoundingClientRect(),a=m(e),c=[n.animate([{opacity:0,filter:`blur(${String(a.blur)}px)`,transform:`translateY(${String(a.distance/2)}px)`},{opacity:1,filter:`blur(0px)`,transform:`none`}],{duration:a.normal,easing:b(a,a.ease)})];for(let e of t){let t=e.animate([{opacity:1,filter:`blur(0px)`,transform:`none`},{opacity:0,filter:`blur(${String(a.blur)}px)`,transform:`translateY(${String(-a.distance/2)}px)`}],{duration:a.fast,easing:b(a,a.easeExit),fill:`forwards`}),n=e.dataset.swapLeaving;t.onfinish=()=>{d(e=>e.filter(e=>e.key!==n))},c.push(t)}let l=r!==null&&(Math.abs(r.height-i.height)>.5||Math.abs(r.width-i.width)>.5);return!s&&l&&c.push(e.animate([{width:`${String(r.width)}px`,height:`${String(r.height)}px`},{width:`${String(i.width)}px`,height:`${String(i.height)}px`}],{duration:a.normal,easing:b(a,a.ease)})),()=>{for(let e of c)e.cancel()}},[e,s]),(0,I.jsx)(`div`,{...i,ref:o,className:D(`caps-swap`,r),"data-anchor":t,children:[...u.map(e=>(0,I.jsx)(`div`,{className:`caps-swap-layer`,"data-swap-leaving":e.key,"aria-hidden":`true`,children:e.content},e.key)),(0,I.jsx)(`div`,{className:`caps-swap-layer`,"data-swap-current":``,children:n},e)]})});function kn({children:e,...t}){let[n,r]=(0,F.useState)(e);return e&&e!==n&&r(e),(0,I.jsx)(On,{...t,className:D(`caps-field-error-reveal`,t.className),open:!!e,children:(0,I.jsx)(`div`,{className:`caps-field-error`,role:`alert`,"aria-hidden":!e,children:n})})}function An({children:e,divider:t=!0,error:n,layout:r=`end`,status:i,...a}){return(0,I.jsxs)(`footer`,{...a,className:D(`caps-form-footer`,a.className),"data-divider":t,"data-layout":r,children:[(0,I.jsx)(kn,{children:n}),(0,I.jsxs)(`div`,{className:`caps-form-footer-row`,children:[i?(0,I.jsx)(`div`,{className:`caps-form-footer-status`,role:`status`,children:i}):null,(0,I.jsx)(`div`,{className:`caps-form-footer-actions`,children:e})]})]})}var jn=(0,F.forwardRef)(function({busy:e=!1,children:t,className:n,layout:r,...i},a){return(0,I.jsx)(`form`,{...i,"aria-busy":e||void 0,className:D(`caps-form`,n),"data-layout":r,ref:a,children:(0,I.jsx)(`fieldset`,{className:`caps-form-body`,disabled:e,children:t})})}),Mn={2:`h2`,3:`h3`,4:`h4`},Nn=(0,F.forwardRef)(function({children:e,className:t,description:n,layout:r,level:i=3,title:a,...o},s){let c=(0,F.useId)(),l=Mn[i];return(0,I.jsxs)(`section`,{...o,"aria-labelledby":`${c}-title`,className:D(`caps-form-section`,t),"data-layout":r,ref:s,children:[(0,I.jsxs)(`header`,{className:`caps-form-section-copy`,children:[(0,I.jsx)(l,{className:`caps-form-section-title`,id:`${c}-title`,children:a}),n?(0,I.jsx)(`p`,{className:`caps-form-section-description`,children:n}):null]}),(0,I.jsx)(`div`,{className:`caps-form-section-fields`,children:e})]})}),Pn=(0,F.forwardRef)(function({children:e,className:t,description:n,error:r,icon:i,layout:a,legend:o,legendTitle:s,...c},l){let u=(0,F.useId)(),d=[n?`${u}-description`:c[`aria-describedby`],r?`${u}-error`:null].filter(Boolean).join(` `)||void 0;return(0,I.jsxs)(`fieldset`,{...c,"aria-describedby":d,"aria-invalid":r?!0:c[`aria-invalid`],className:D(`caps-fieldset`,t),"data-layout":a,ref:l,children:[(0,I.jsxs)(`legend`,{className:`caps-fieldset-legend`,title:s,children:[i?(0,I.jsx)(`span`,{className:`caps-field-icon`,"aria-hidden":`true`,children:i}):null,o]}),n?(0,I.jsx)(`p`,{className:`caps-fieldset-description`,id:`${u}-description`,children:n}):null,(0,I.jsx)(`div`,{className:`caps-fieldset-fields`,children:e}),r===void 0?null:(0,I.jsx)(kn,{id:`${u}-error`,children:r})]})});function Fn(e){let t=[];return F.Children.forEach(e.props.children,e=>{(0,F.isValidElement)(e)&&e.type!==En&&t.push(e)}),t[0]??null}var In=(0,F.forwardRef)(function({children:e,className:t,description:n,error:r,icon:i,label:a,labelTitle:o,optional:s,orientation:c=`vertical`,readout:l=!1,required:u,...d},f){let p=(0,F.useId)(),m=(0,F.isValidElement)(e)?e:null,h=m?.type===Tn,g=h?Fn(m):m,_=g?.props.id??p,v=`${_}-description`,y=`${_}-error`,b=[g?.props[`aria-describedby`],n?v:null,r?y:null].filter(Boolean).join(` `)||void 0,x=u===!0||g?.props.required,S=r?!0:g?.props[`aria-invalid`],C=u===!0||g?.props[`aria-required`],w={id:_};x!==void 0&&(w.required=x),b!==void 0&&(w[`aria-describedby`]=b),S!==void 0&&(w[`aria-invalid`]=S),C!==void 0&&(w[`aria-required`]=C);let T=m&&g&&!l?h?(0,F.cloneElement)(m,void 0,F.Children.map(m.props.children,e=>e===g?(0,F.cloneElement)(g,w):e)):(0,F.cloneElement)(m,w):e,E=a?(0,I.jsx)(wn,{htmlFor:l?void 0:_,title:o,className:c===`inline`?`font-normal`:void 0,...u===void 0?{}:{required:u},...s===void 0?{}:{optional:s},children:a}):null,O=a||n?(0,I.jsxs)(`div`,{className:`caps-field-copy`,children:[E,n?(0,I.jsx)(`p`,{className:`caps-field-description`,id:v,children:n}):null]}):null,k=i?(0,I.jsxs)(`div`,{className:`caps-field-lead`,children:[(0,I.jsx)(`span`,{className:`caps-field-icon`,"aria-hidden":`true`,children:i}),O]}):O;return(0,I.jsxs)(`div`,{...d,className:D(`caps-field`,t),"data-orientation":c,ref:f,children:[c===`horizontal`?(0,I.jsxs)(`div`,{className:`caps-field-row`,children:[k,T]}):c===`inline`?(0,I.jsxs)(`div`,{className:`caps-field-row`,children:[T,k]}):(0,I.jsxs)(I.Fragment,{children:[k,T]}),(0,I.jsx)(kn,{id:y,children:r})]})});function Ln(e){let t=String(e),n=t.indexOf(`.`);return n===-1?0:t.length-n-1}var Rn=`M 9.86 38.14 A 20 20 0 1 1 38.14 38.14`,zn=6,Bn=new Map([[`ArrowUp`,1],[`ArrowDown`,-1],[`PageUp`,10],[`PageDown`,-10]]),Vn=(0,F.forwardRef)(function({className:e,decrementLabel:t=`Decrease`,defaultValue:n=null,disabled:r,incrementLabel:i=`Increase`,invalid:a,max:o,min:s,onBlur:c,onKeyDown:l,onValueChange:u,step:d=1,unit:f,value:p,wrap:m=!1,...h},g){let[_,v]=(0,F.useState)(n),[y,b]=(0,F.useState)(null),x=p===void 0?_:p,S=Ln(d),C=e=>{let t=Number(e.toFixed(S));return s!==void 0&&t<s?s:o!==void 0&&t>o?o:t},w=e=>{let t=e===null?null:C(e);v(t),b(null),t!==x&&u?.(t)},T=()=>{if(y===null)return;let e=Number(y);w(y.trim()===``||!Number.isFinite(e)?null:e)},E=e=>{let t=(x??s??0)+e*d;if(m&&s!==void 0&&o!==void 0){if(t>o){w(s);return}if(t<s){w(o);return}}w(t)},O=s!==void 0&&x!==null&&x<=s,k=o!==void 0&&x!==null&&x>=o,A=r===!0,j=(0,F.useRef)(null),ee=s!==void 0&&o!==void 0&&o>s?((x??s)-s)/(o-s):null,te=e=>{A||(e.currentTarget.setPointerCapture(e.pointerId),j.current={y:e.clientY,value:x??s??0})},ne=e=>{if(!j.current)return;let t=Math.trunc((j.current.y-e.clientY)/zn),n=C(j.current.value+t*d);n!==x&&w(n)},re=()=>{j.current=null};return(0,I.jsxs)(`span`,{className:D(`caps-number-field`,e),"data-at-max":k||void 0,"data-at-min":O||void 0,"data-disabled":A||void 0,"data-wrap":m||void 0,children:[ee===null?null:(0,I.jsxs)(`svg`,{className:`caps-number-field-dial`,viewBox:`0 0 48 48`,"aria-hidden":`true`,focusable:`false`,onPointerDown:te,onPointerMove:ne,onPointerUp:re,onPointerCancel:re,children:[(0,I.jsx)(`path`,{className:`caps-number-field-dial-track`,d:Rn,pathLength:100}),(0,I.jsx)(`path`,{className:`caps-number-field-dial-level`,d:Rn,pathLength:100,strokeDasharray:`${String(Math.max(.5,ee*100))} 100`})]}),(0,I.jsx)(M,{type:`button`,variant:`outline`,size:`icon`,className:`caps-number-field-decrement`,"aria-label":t,"aria-controls":h.id,tabIndex:-1,disabled:A||O&&!m,onClick:()=>{E(-1)},children:(0,I.jsx)(be,{"aria-hidden":`true`})}),(0,I.jsxs)(`span`,{className:`caps-number-field-readout`,children:[(0,I.jsx)(`input`,{...h,"aria-invalid":a?!0:h[`aria-invalid`]===!1?void 0:h[`aria-invalid`],className:`input caps-input caps-number-field-input`,disabled:r,inputMode:h.inputMode??(S>0?`decimal`:`numeric`),max:o,min:s,onBlur:e=>{T(),c?.(e)},onChange:e=>{b(e.target.value)},onKeyDown:e=>{if(l?.(e),e.defaultPrevented)return;let t=Bn.get(e.key);t===void 0?e.key===`Home`&&s!==void 0?(e.preventDefault(),w(s)):e.key===`End`&&o!==void 0?(e.preventDefault(),w(o)):e.key===`Enter`&&T():(e.preventDefault(),E(t))},ref:g,step:d,type:`number`,value:y??(x===null?``:String(x))}),f?(0,I.jsx)(`span`,{className:`caps-number-field-unit`,"aria-hidden":`true`,children:f}):null]}),(0,I.jsx)(M,{type:`button`,variant:`outline`,size:`icon`,className:`caps-number-field-increment`,"aria-label":i,"aria-controls":h.id,tabIndex:-1,disabled:A||k&&!m,onClick:()=>{E(1)},children:(0,I.jsx)(xe,{"aria-hidden":`true`})})]})});function Hn({update:e,notify:t,unwatched:n}){return{link:r,unlink:i,propagate:a,checkDirty:o,shallowPropagate:s};function r(e,t,n){let r=t.depsTail;if(r!==void 0&&r.dep===e)return;let i=r===void 0?t.deps:r.nextDep;if(i!==void 0&&i.dep===e){i.version=n,t.depsTail=i;return}let a=e.subsTail;if(a!==void 0&&a.version===n&&a.sub===t)return;let o=t.depsTail=e.subsTail={version:n,dep:e,sub:t,prevDep:r,nextDep:i,prevSub:a,nextSub:void 0};i!==void 0&&(i.prevDep=o),r===void 0?t.deps=o:r.nextDep=o,a===void 0?e.subs=o:a.nextSub=o}function i(e,t=e.sub){let r=e.dep,i=e.prevDep,a=e.nextDep,o=e.nextSub,s=e.prevSub;return a===void 0?t.depsTail=i:a.prevDep=i,i===void 0?t.deps=a:i.nextDep=a,o===void 0?r.subsTail=s:o.prevSub=s,s===void 0?(r.subs=o)===void 0&&n(r):s.nextSub=o,a}function a(e){let n=e.nextSub,r;top:do{let i=e.sub,a=i.flags;if(a&60?a&12?a&4?!(a&48)&&c(e,i)?(i.flags=a|40,a&=1):a=0:i.flags=a&-9|32:a=0:i.flags=a|32,a&2&&t(i),a&1){let t=i.subs;if(t!==void 0){let i=(e=t).nextSub;i!==void 0&&(r={value:n,prev:r},n=i);continue}}if((e=n)!==void 0){n=e.nextSub;continue}for(;r!==void 0;)if(e=r.value,r=r.prev,e!==void 0){n=e.nextSub;continue top}break}while(!0)}function o(t,n){let r,i=0,a=!1;top:do{let o=t.dep,c=o.flags;if(n.flags&16)a=!0;else if((c&17)==17){if(e(o)){let e=o.subs;e.nextSub!==void 0&&s(e),a=!0}}else if((c&33)==33){(t.nextSub!==void 0||t.prevSub!==void 0)&&(r={value:t,prev:r}),t=o.deps,n=o,++i;continue}if(!a){let e=t.nextDep;if(e!==void 0){t=e;continue}}for(;i--;){let i=n.subs,o=i.nextSub!==void 0;if(o?(t=r.value,r=r.prev):t=i,a){if(e(n)){o&&s(i),n=t.sub;continue}a=!1}else n.flags&=-33;n=t.sub;let c=t.nextDep;if(c!==void 0){t=c;continue top}}return a}while(!0)}function s(e){do{let n=e.sub,r=n.flags;(r&48)==32&&(n.flags=r|16,(r&6)==2&&t(n))}while((e=e.nextSub)!==void 0)}function c(e,t){let n=t.depsTail;for(;n!==void 0;){if(n===e)return!0;n=n.prevDep}return!1}}function Un(e,t,n){let r=typeof e==`object`,i=r?e:void 0;return{next:(r?e.next:e)?.bind(i),error:(r?e.error:t)?.bind(i),complete:(r?e.complete:n)?.bind(i)}}var Wn=[],Gn=0,{link:Kn,unlink:qn,propagate:Jn,checkDirty:Yn,shallowPropagate:Xn}=Hn({update(e){return e._update()},notify(e){Wn[Qn++]=e,e.flags&=-3},unwatched(e){e.depsTail!==void 0&&(e.depsTail=void 0,e.flags=17,er(e))}}),Zn=0,Qn=0,K,$n=0;function q(e){try{++$n,e()}finally{--$n||tr()}}function er(e){let t=e.depsTail,n=t===void 0?e.deps:t.nextDep;for(;n!==void 0;)n=qn(n,e)}function tr(){if(!($n>0)){for(;Zn<Qn;){let e=Wn[Zn];Wn[Zn++]=void 0,e.notify()}Zn=0,Qn=0}}function nr(e,t){let n=typeof e==`function`,r=e,i={_snapshot:n?void 0:e,subs:void 0,subsTail:void 0,deps:void 0,depsTail:void 0,flags:+!n,get(){return K!==void 0&&Kn(i,K,Gn),i._snapshot},subscribe(e){let t=Un(e),n={current:!1},r=rr(()=>{i.get(),n.current?t.next?.(i._snapshot):n.current=!0});return{unsubscribe:()=>{r.stop()}}},_update(e){let a=K,o=t?.compare??Object.is;if(n)K=i,++Gn,i.depsTail=void 0;else if(e===void 0)return!1;n&&(i.flags=5);try{let t=i._snapshot,a=typeof e==`function`?e(t):e===void 0&&n?r(t):e;return t===void 0||!o(t,a)?(i._snapshot=a,!0):!1}finally{K=a,n&&(i.flags&=-5),er(i)}}};return n?(i.flags=17,i.get=function(){let e=i.flags;if(e&16||e&32&&Yn(i.deps,i)){if(i._update()){let e=i.subs;e!==void 0&&Xn(e)}}else e&32&&(i.flags=e&-33);return K!==void 0&&Kn(i,K,Gn),i._snapshot}):i.set=function(e){if(i._update(e)){let e=i.subs;e!==void 0&&(Jn(e),Xn(e),tr())}},i}function rr(e){let t=()=>{let t=K;K=n,++Gn,n.depsTail=void 0,n.flags=6;try{return e()}finally{K=t,n.flags&=-5,er(n)}},n={deps:void 0,depsTail:void 0,subs:void 0,subsTail:void 0,flags:6,notify(){let e=this.flags;e&16||e&32&&Yn(this.deps,this)?t():this.flags=2},stop(){this.flags=0,this.depsTail=void 0,er(this)}};return t(),n}var ir=class{constructor(e,t){this.atom=nr(e),this.get=this.get.bind(this),this.setState=this.setState.bind(this),this.subscribe=this.subscribe.bind(this),t&&(this.actions=t(this))}setState(e){this.atom.set(e)}get state(){return this.atom.get()}get(){return this.state}subscribe(e){return this.atom.subscribe(Un(e))}},ar=class{constructor(e){this.atom=nr(e)}get state(){return this.atom.get()}get(){return this.state}subscribe(e){return this.atom.subscribe(Un(e))}};function or(e,t){return typeof e==`function`?new ar(e):t?new ir(e,t):new ir(e)}var sr=class{constructor(e,t){this.fn=e,this.options=t,this.lastExecutionTime=0,this.isPending=!1,this.maybeExecute=(...e)=>{let t=Date.now()-this.lastExecutionTime;if(this.options.leading&&t>=this.options.wait)this.execute(...e);else if(this.lastArgs=e,!this.timeoutId&&this.options.trailing){let e=this.options.wait-t;this.isPending=!0,this.timeoutId=setTimeout(()=>{this.lastArgs!==void 0&&this.execute(...this.lastArgs)},e)}},this.execute=(...e)=>{this.fn(...e),this.options.onExecute?.(e,this),this.lastExecutionTime=Date.now(),this.clearTimeout(),this.lastArgs=void 0,this.isPending=!1},this.flush=()=>{this.isPending&&this.lastArgs&&this.execute(...this.lastArgs)},this.cancel=()=>{this.clearTimeout(),this.lastArgs=void 0,this.isPending=!1},this.clearTimeout=()=>{this.timeoutId&&=(clearTimeout(this.timeoutId),void 0)},this.options.leading===void 0&&this.options.trailing===void 0&&(this.options.leading=!0,this.options.trailing=!0)}};function cr(e,t){return new sr(e,t).maybeExecute}var lr=class{#e=!0;#t;#n;#r;#i;#a;#o;#s;#c=0;#l=5;#u=!1;#d=!1;#f=null;#p=()=>{this.debugLog(`Connected to event bus`),this.#a=!0,this.#u=!1,this.debugLog(`Emitting queued events`,this.#i),this.#i.forEach(e=>this.emitEventToBus(e)),this.#i=[],this.stopConnectLoop(),this.#n().removeEventListener(`tanstack-connect-success`,this.#p)};#m=()=>{if(this.#c<this.#l){this.#c++,this.dispatchCustomEvent(`tanstack-connect`,{});return}this.#n().removeEventListener(`tanstack-connect`,this.#m),this.#d=!0,this.debugLog(`Max retries reached, giving up on connection`),this.stopConnectLoop()};#h=()=>{this.#u||(this.#u=!0,this.#n().addEventListener(`tanstack-connect-success`,this.#p),this.#m())};constructor({pluginId:e,debug:t=!1,enabled:n=!0,reconnectEveryMs:r=300}){this.#t=e,this.#e=n,this.#n=this.getGlobalTarget,this.#r=t,this.debugLog(` Initializing event subscription for plugin`,this.#t),this.#i=[],this.#a=!1,this.#d=!1,this.#o=null,this.#s=r}startConnectLoop(){this.#o!==null||this.#a||(this.debugLog(`Starting connect loop (every ${this.#s}ms)`),this.#o=setInterval(this.#m,this.#s))}stopConnectLoop(){this.#u=!1,this.#o!==null&&(clearInterval(this.#o),this.#o=null,this.#i=[],this.debugLog(`Stopped connect loop`))}debugLog(...e){this.#r&&console.log(`🌴 [tanstack-devtools:${this.#t}-plugin]`,...e)}getGlobalTarget(){if(typeof globalThis<`u`&&globalThis.__TANSTACK_EVENT_TARGET__)return this.debugLog(`Using global event target`),globalThis.__TANSTACK_EVENT_TARGET__;if(typeof window<`u`&&window.addEventListener!==void 0)return this.debugLog(`Using window as event target`),window;let e=typeof EventTarget<`u`?new EventTarget:void 0;return e===void 0||e.addEventListener===void 0?(this.debugLog(`No event mechanism available, running in non-web environment`),{addEventListener:()=>{},removeEventListener:()=>{},dispatchEvent:()=>!1}):(this.debugLog(`Using new EventTarget as fallback`),e)}getPluginId(){return this.#t}dispatchCustomEventShim(e,t){try{let n=new Event(e,{detail:t});this.#n().dispatchEvent(n)}catch{this.debugLog(`Failed to dispatch shim event`)}}dispatchCustomEvent(e,t){try{this.#n().dispatchEvent(new CustomEvent(e,{detail:t}))}catch{this.dispatchCustomEventShim(e,t)}}emitEventToBus(e){this.debugLog(`Emitting event to client bus`,e),this.dispatchCustomEvent(`tanstack-dispatch-event`,e)}createEventPayload(e,t){return{type:`${this.#t}:${e}`,payload:t,pluginId:this.#t}}emit(e,t){if(!this.#e){this.debugLog(`Event bus client is disabled, not emitting event`,e,t);return}if(this.#f&&(this.debugLog(`Emitting event to internal event target`,e,t),this.#f.dispatchEvent(new CustomEvent(`${this.#t}:${e}`,{detail:this.createEventPayload(e,t)}))),this.#d){this.debugLog(`Previously failed to connect, not emitting to bus`);return}if(!this.#a){this.debugLog(`Bus not available, will be pushed as soon as connected`),this.#i.push(this.createEventPayload(e,t)),typeof CustomEvent<`u`&&!this.#u&&(this.#h(),this.startConnectLoop());return}return this.emitEventToBus(this.createEventPayload(e,t))}on(e,t,n){let r=n?.withEventTarget??!1,i=`${this.#t}:${e}`;if(r&&(this.#f||=new EventTarget,this.#f.addEventListener(i,e=>{t(e.detail)})),!this.#e)return this.debugLog(`Event bus client is disabled, not registering event`,i),()=>{};let a=e=>{this.debugLog(`Received event from bus`,e.detail),t(e.detail)};return this.#n().addEventListener(i,a),this.debugLog(`Registered event to bus`,i),()=>{r&&this.#f?.removeEventListener(i,a),this.#n().removeEventListener(i,a)}}onAll(e){if(!this.#e)return this.debugLog(`Event bus client is disabled, not registering event`),()=>{};let t=t=>{let n=t.detail;e(n)};return this.#n().addEventListener(`tanstack-devtools-global`,t),()=>this.#n().removeEventListener(`tanstack-devtools-global`,t)}onAllPluginEvents(e){if(!this.#e)return this.debugLog(`Event bus client is disabled, not registering event`),()=>{};let t=t=>{let n=t.detail;this.#t&&n.pluginId!==this.#t||e(n)};return this.#n().addEventListener(`tanstack-devtools-global`,t),()=>this.#n().removeEventListener(`tanstack-devtools-global`,t)}},J=new class extends lr{constructor(){super({pluginId:`form-devtools`,reconnectEveryMs:1e3})}};function ur(e,t){return typeof e==`function`?e(t):e}function dr(e,t){return yr(t).reduce((e,t)=>{if(e===null)return null;if(e!==void 0)return e[t]},e)}function fr(e,t,n){let r=yr(t);function i(e){if(!r.length)return ur(n,e);let t=r.shift();if(typeof t==`string`||typeof t==`number`&&!Array.isArray(e))return typeof e==`object`?(e===null&&(e={}),{...e,[t]:i(e[t])}):{[t]:i()};if(Array.isArray(e)&&typeof t==`number`){let n=e.slice(0,t);return[...n.length?n:Array(t),i(e[t]),...e.slice(t+1)]}return[...Array(t),i()]}return i(e)}function pr(e,t){let n=yr(t);function r(e){if(!e)return;if(n.length===1){let t=n[0];if(Array.isArray(e)&&typeof t==`number`)return e.filter((e,n)=>n!==t);let{[t]:r,...i}=e;return i}let t=n.shift();if((typeof t==`string`||typeof t==`number`&&!Array.isArray(e))&&typeof e==`object`)return{...e,[t]:r(e[t])};if(typeof t==`number`&&Array.isArray(e)){if(t>=e.length)return e;let n=e.slice(0,t);return[...n.length?n:Array(t),r(e[t]),...e.slice(t+1)]}throw Error(`It seems we have created an infinite loop in deleteBy. `)}return r(e)}var mr=46,hr=91,gr=93,_r=48,vr=57;function yr(e){if(Array.isArray(e))return[...e];if(typeof e!=`string`)throw Error(`Path must be a string.`);let t=e.length,n=[],r=+(t>0&&e.charCodeAt(0)===hr),i=!0,a=-1;for(let o=r;o<=t;o++){let s=o<t?e.charCodeAt(o):-1;if(o===t||s===mr||s===hr||s===gr){let t=o-r;if(t>0){let a=i&&(t===1||e.charCodeAt(r)!==_r),s=e.slice(r,o);if(a){let e=parseInt(s,10);t<=15||String(e)===s?n.push(e):n.push(s)}else n.push(s)}else a!==gr&&(a!==-1||s!==gr)&&(a!==s||s!==mr&&s!==hr)&&n.push(``);r=o+1,i=!0}else(s<_r||s>vr)&&(i=!1);a=s}return n.length||n.push(``),n}function br(e){return!(Array.isArray(e)&&e.length===0)}function xr(e,t){return t.validationLogic({form:t.form,group:t.group,validators:t.validators,event:{type:e,fieldName:t.fieldName,async:!1},runValidation:e=>e.validators.filter(Boolean).map(e=>({cause:e.cause,validate:e.fn}))})}function Sr(e,t){let{asyncDebounceMs:n}=t,{onBlurAsyncDebounceMs:r,onChangeAsyncDebounceMs:i,onDynamicAsyncDebounceMs:a}=t.validators||{},o=n??0;return t.validationLogic({form:t.form,group:t.group,validators:t.validators,event:{type:e,fieldName:t.fieldName,async:!0},runValidation:t=>t.validators.filter(Boolean).map(t=>{let n=t?.cause||e,s=o;switch(n){case`change`:s=i??o;break;case`blur`:s=r??o;break;case`dynamic`:s=a??o;break;case`submit`:s=0}return e===`submit`&&(s=0),{cause:n,validate:t.fn,debounceMs:s}})})}var Cr=e=>!!e&&typeof e==`object`&&`fields`in e;function Y(e,t){if(Object.is(e,t))return!0;if(typeof e!=`object`||!e||typeof t!=`object`||!t)return!1;if(e instanceof Date&&t instanceof Date)return e.getTime()===t.getTime();if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(let[n,r]of e)if(!t.has(n)||!Object.is(r,t.get(n)))return!1;return!0}if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(let n of e)if(!t.has(n))return!1;return!0}let n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length||n.length===0&&!Array.isArray(e)&&!Array.isArray(t)&&(Object.getPrototypeOf(e)!==Object.prototype||Object.getPrototypeOf(t)!==Object.prototype))return!1;for(let i of n)if(!r.includes(i)||!Y(e[i],t[i]))return!1;return!0}var wr=({newFormValidatorError:e,isPreviousErrorFromFormValidator:t,previousErrorValue:n})=>e?{newErrorValue:e,newSource:`form`}:t?{newErrorValue:void 0,newSource:void 0}:n?{newErrorValue:n,newSource:`field`}:{newErrorValue:void 0,newSource:void 0},Tr=({formLevelError:e,fieldLevelError:t})=>t?{newErrorValue:t,newSource:`field`}:e?{newErrorValue:e,newSource:`form`}:{newErrorValue:void 0,newSource:void 0};function X(e,t){return e==null?t:{...e,...t}}for(var Er=256,Dr=[],Or;Er--;)Dr[Er]=(Er+256).toString(16).substring(1);function kr(){let e=0,t,n=``;if(!Or||Er+16>256){for(Or=Array(256),e=256;e--;)Or[e]=256*Math.random()|0;e=0,Er=0}for(;e<16;e++)t=Or[Er+e],n+=e===6?Dr[t&15|64]:e===8?Dr[t&63|128]:Dr[t],e&1&&e>1&&e<11&&(n+=`-`);return Er++,n}var Ar=cr(e=>J.emit(`form-state`,{id:e.formId,state:e.store.state}),{wait:300});function jr(e){if(typeof e!=`object`||!e)return e;if(e instanceof Date)return new Date(e.getTime());if(Array.isArray(e)){let t=[];for(let n=0;n<e.length;n++)t[n]=jr(e[n]);return t}if(e instanceof Map){let t=new Map;return e.forEach((e,n)=>{t.set(n,jr(e))}),t}if(e instanceof Set){let t=new Set;return e.forEach(e=>{t.add(jr(e))}),t}let t={};for(let n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=jr(e[n]));return t}function Mr(e,t){return t===e||t.startsWith(`${e}.`)||t.startsWith(`${e}[`)}var Z=e=>{if(!e.validators)return e.runValidation({validators:[],form:e.form});let t=e.event.async,n=t?void 0:{fn:e.validators.onMount,cause:`mount`},r={fn:t?e.validators.onChangeAsync:e.validators.onChange,cause:`change`},i={fn:t?e.validators.onBlurAsync:e.validators.onBlur,cause:`blur`},a={fn:t?e.validators.onSubmitAsync:e.validators.onSubmit,cause:`submit`},o=t?void 0:{fn:()=>void 0,cause:`server`};switch(e.event.type){case`mount`:return e.runValidation({validators:[n],form:e.form});case`submit`:return e.runValidation({validators:[r,i,a,o],form:e.form});case`server`:return e.runValidation({validators:[],form:e.form});case`blur`:return e.runValidation({validators:[i,o],form:e.form});case`change`:return e.runValidation({validators:[r,o],form:e.form});default:throw Error(`Unknown validation event type: ${e.event.type}`)}};function Nr(e,t){let n=new Map;for(let r of e){let e=r.path??[],i=t,a=``;for(let t=0;t<e.length;t++){let n=e[t];if(n===void 0)continue;let r=typeof n==`object`?n.key:n,o=Number(r);a+=Array.isArray(i)&&!Number.isNaN(o)?`[${o}]`:(t>0?`.`:``)+String(r),i=typeof i==`object`&&i?i[r]:void 0}n.set(a,(n.get(a)??[]).concat(r))}return Object.fromEntries(n)}var Pr=(e,t)=>{let n=Nr(e,t);return{form:n,fields:n}},Fr={validate({value:e,validationSource:t},n){let r=n[`~standard`].validate(e);if(r instanceof Promise)throw Error(`async function passed to sync validator`);if(r.issues)return t===`field`?r.issues:Pr(r.issues,e)},async validateAsync({value:e,validationSource:t},n){let r=await n[`~standard`].validate(e);if(r.issues)return t===`field`?r.issues:Pr(r.issues,e)}},Ir=e=>!!e&&`~standard`in e,Q={isValidating:!1,isTouched:!1,isBlurred:!1,isDirty:!1,isPristine:!0,isValid:!0,isDefaultValue:!0,errors:[],errorMap:{},errorSourceMap:{},_arrayVersion:0,_pendingValidationsCount:0};function Lr(e){function t(t){let n=e.getFieldMeta(t)??Q;e.setFieldMeta(t,{...n,_arrayVersion:(n._arrayVersion||0)+1})}function n(n,r,i){t(n);let a=s(n,r,`move`,i),c=Math.min(r,i),u=Math.max(r,i);for(let e=c;e<=u;e++)a.push(o(n,e));let d=Object.keys(e.fieldInfo).reduce((t,i)=>(i.startsWith(o(n,r))&&t.set(i,e.getFieldMeta(i)),t),new Map);l(a,r<i?`up`:`down`),Object.keys(e.fieldInfo).filter(e=>e.startsWith(o(n,i))).forEach(t=>{let a=t.replace(o(n,i),o(n,r)),s=d.get(a);s&&e.setFieldMeta(t,s)})}function r(e,n){t(e),l(s(e,n,`remove`),`up`)}function i(n,r,i){t(n),s(n,r,`swap`,i).forEach(t=>{if(!t.toString().startsWith(o(n,r)))return;let a=t.toString().replace(o(n,r),o(n,i)),[s,c]=[e.getFieldMeta(t),e.getFieldMeta(a)];s&&e.setFieldMeta(a,s),c&&e.setFieldMeta(t,c)})}function a(n,r){t(n);let i=s(n,r,`insert`);l(i,`down`),i.forEach(t=>{t.toString().startsWith(o(n,r))&&e.setFieldMeta(t,u())})}function o(e,t){return`${e}[${t}]`}function s(t,n,r,i){let a=[o(t,n)];switch(r){case`swap`:a.push(o(t,i));break;case`move`:{let[e,r]=[Math.min(n,i),Math.max(n,i)];for(let n=e;n<=r;n++)a.push(o(t,n));break}default:{let r=e.getFieldValue(t),i=Array.isArray(r)?r.length:0;for(let e=n+1;e<i;e++)a.push(o(t,e));break}}return Object.keys(e.fieldInfo).filter(e=>a.some(t=>e.startsWith(t)))}function c(e,t){return e.replace(/\[(\d+)\]/,(e,n)=>{let r=parseInt(n,10);return`[${t===`up`?r+1:Math.max(0,r-1)}]`})}function l(t,n){(n===`up`?t:[...t].reverse()).forEach(t=>{let r=c(t.toString(),n),i=e.getFieldMeta(r);i?e.setFieldMeta(t,i):e.setFieldMeta(t,u())})}let u=()=>Q;return{bumpArrayVersion:t,handleArrayMove:n,handleArrayRemove:r,handleArraySwap:i,handleArrayInsert:a}}function Rr(e){return{values:e.values??{},errorMap:e.errorMap??{},fieldMetaBase:e.fieldMetaBase??{},formGroupStateBase:e.formGroupStateBase??{},isSubmitted:e.isSubmitted??!1,isSubmitting:e.isSubmitting??!1,isValidating:e.isValidating??!1,submissionAttempts:e.submissionAttempts??0,isSubmitSuccessful:e.isSubmitSuccessful??!1,validationMetaMap:e.validationMetaMap??{onChange:void 0,onBlur:void 0,onSubmit:void 0,onMount:void 0,onServer:void 0,onDynamic:void 0}}}var zr=class{constructor(e){this.options={},this.fieldInfo={},this.formGroupApis=new Set,this.mount=()=>{let e=this.store.subscribe(()=>{Ar(this)}),t=J.on(`request-form-state`,e=>{e.payload.id===this._formId&&J.emit(`form-api`,{id:this._formId,state:this.store.state,options:this.options})}),n=J.on(`request-form-reset`,e=>{e.payload.id===this._formId&&this.reset()}),r=J.on(`request-form-force-submit`,e=>{e.payload.id===this._formId&&(this._devtoolsSubmissionOverride=!0,this.handleSubmit(),this._devtoolsSubmissionOverride=!1)}),i=()=>{r(),n(),t(),e.unsubscribe(),J.emit(`form-unmounted`,{id:this._formId})};this.options.listeners?.onMount?.({formApi:this});let{onMount:a}=this.options.validators||{};return J.emit(`form-api`,{id:this._formId,state:this.store.state,options:this.options}),a&&this.validateSync(`mount`),i},this.update=e=>{if(!e)return;let t=this.options;this.options=e;let n=e.defaultValues&&!Y(e.defaultValues,t.defaultValues)&&!this.state.isTouched,r=!Y(e.defaultState,t.defaultState)&&!this.state.isTouched;if(!(!n&&!r)){if(q(()=>{this.baseStore.setState(()=>Rr(Object.assign({},this.state,r?e.defaultState:{},n?{values:e.defaultValues}:{})))}),n){let e=Lr(this);for(let t of Object.keys(this.fieldInfo))Array.isArray(this.getFieldValue(t))&&e.bumpArrayVersion(t)}J.emit(`form-api`,{id:this._formId,state:this.store.state,options:this.options})}},this.reset=(e,t)=>{let{fieldMeta:n}=this.state,r=this.resetFieldMeta(n);e&&!t?.keepDefaultValues&&(this.options={...this.options,defaultValues:e}),this.baseStore.setState(()=>{let t=e??this.options.defaultValues??this.options.defaultState?.values;return e||Object.values(this.fieldInfo).forEach(e=>{e.instance&&e.instance.options.defaultValue!==void 0&&(t=fr(t,e.instance.name,e.instance.options.defaultValue))}),Rr({...this.options.defaultState,values:t,fieldMetaBase:r})})},this.validateAllFields=async e=>{let t=[];return q(()=>{Object.values(this.fieldInfo).forEach(n=>{if(!n.instance)return;let r=n.instance;t.push(Promise.resolve().then(()=>r.validate(e,{skipFormValidation:!0,skipGroupValidation:!0}))),n.instance.store.state.meta.isTouched||n.instance.setMeta(e=>({...e,isTouched:!0}))})}),(await Promise.all(t)).flat()},this.validateArrayFieldsStartingFrom=async(e,t,n)=>{let r=this.getFieldValue(e),i=Array.isArray(r)?Math.max(r.length-1,0):null,a=[`${e}[${t}]`];for(let n=t+1;n<=(i??0);n++)a.push(`${e}[${n}]`);let o=Object.keys(this.fieldInfo).filter(e=>a.some(t=>e.startsWith(t))),s=[];return q(()=>{o.forEach(e=>{s.push(Promise.resolve().then(()=>this.validateField(e,n)))})}),(await Promise.all(s)).flat()},this.validateField=(e,t)=>{let n=this.fieldInfo[e]?.instance;if(!n){let{hasErrored:n}=this.validateSync(t);return n&&!this.options.asyncAlways?this.getFieldMeta(e)?.errors??[]:this.validateAsync(t).then(()=>this.getFieldMeta(e)?.errors??[])}return n.store.state.meta.isTouched||n.setMeta(e=>({...e,isTouched:!0})),n.validate(t)},this.validateSync=(e,t)=>{let n=xr(e,{...this.options,form:this,group:t?.group,validationLogic:this.options.validationLogic||Z}),r=!1,i={};return q(()=>{for(let e of n){if(!e.validate)continue;let{formError:n,fieldErrors:a}=Br(this.runValidator({validate:e.validate,value:{value:this.state.values,formApi:this,validationSource:`form`},type:`validate`})),o=Vr(e.cause),s=new Set([...Object.keys(this.state.fieldMeta),...Object.keys(a||{})]);t?.filterFieldNames&&(s=new Set([...s].filter(t.filterFieldNames)));for(let e of s){if(this.baseStore.state.fieldMetaBase[e]===void 0&&!a?.[e])continue;let{errorMap:t,errorSourceMap:n}=this.getFieldMeta(e)??Q,r=a?.[e],{newErrorValue:s,newSource:c}=wr({newFormValidatorError:r,isPreviousErrorFromFormValidator:n?.[o]===`form`,previousErrorValue:t?.[o]});c===`form`&&(i[e]={...i[e],[o]:r}),t?.[o]!==s&&this.setFieldMeta(e,(e=Q)=>({...e,errorMap:{...e.errorMap,[o]:s},errorSourceMap:{...e.errorSourceMap,[o]:c}}))}t?.dontUpdateFormErrorMap||this.state.errorMap?.[o]!==n&&this.baseStore.setState(e=>({...e,errorMap:{...e.errorMap,[o]:n}})),(n||a)&&(r=!0)}if(t?.dontUpdateFormErrorMap)return;let a=Vr(`submit`);this.state.errorMap?.[a]&&e!==`submit`&&!r&&this.baseStore.setState(e=>({...e,errorMap:{...e.errorMap,[a]:void 0}}));let o=Vr(`server`);this.state.errorMap?.[o]&&e!==`server`&&!r&&this.baseStore.setState(e=>({...e,errorMap:{...e.errorMap,[o]:void 0}}))}),{hasErrored:r,fieldsErrorMap:i}},this.validateAsync=async(e,t)=>{let n=Sr(e,{...this.options,form:this,group:t?.group,validationLogic:this.options.validationLogic||Z});this.state.isFormValidating||this.baseStore.setState(e=>({...e,isFormValidating:!0}));let r=[],i;for(let e of n){if(!e.validate)continue;let n=Vr(e.cause);this.state.validationMetaMap[n]?.lastAbortController.abort();let a=new AbortController;this.state.validationMetaMap[n]={lastAbortController:a},r.push(new Promise(async n=>{let r;try{r=await new Promise((t,n)=>{setTimeout(async()=>{if(a.signal.aborted)return t(void 0);try{t(await this.runValidator({validate:e.validate,value:{value:this.state.values,formApi:this,validationSource:`form`,signal:a.signal},type:`validateAsync`}))}catch(e){n(e)}},e.debounceMs)})}catch(e){r=e}let{formError:o,fieldErrors:s}=Br(r);s&&(i=i?{...i,...s}:s);let c=Vr(e.cause),l=new Set([...Object.keys(this.state.fieldMeta),...Object.keys(i||{})]),u=Array.from(l);t?.filterFieldNames&&(u=u.filter(t.filterFieldNames));for(let e of u){if(this.baseStore.state.fieldMetaBase[e]===void 0&&!i?.[e])continue;let{errorMap:t,errorSourceMap:n}=this.getFieldMeta(e)??Q,r=i?.[e],{newErrorValue:a,newSource:o}=wr({newFormValidatorError:r,isPreviousErrorFromFormValidator:n?.[c]===`form`,previousErrorValue:t?.[c]});t?.[c]!==a&&this.setFieldMeta(e,(e=Q)=>({...e,errorMap:{...e.errorMap,[c]:a},errorSourceMap:{...e.errorSourceMap,[c]:o}}))}t?.dontUpdateFormErrorMap||this.baseStore.setState(e=>({...e,errorMap:{...e.errorMap,[c]:o}})),n(i?{fieldErrors:i,errorMapKey:c}:void 0)}))}let a=[],o={};if(r.length){a=await Promise.all(r);for(let e of a)if(e?.fieldErrors){let{errorMapKey:t}=e;for(let[n,r]of Object.entries(e.fieldErrors))o[n]={...o[n]||{},[t]:r}}}return this.baseStore.setState(e=>({...e,isFormValidating:!1})),o},this.validate=(e,t)=>{let{hasErrored:n,fieldsErrorMap:r}=this.validateSync(e,t);return n&&!this.options.asyncAlways?r:this.validateAsync(e,t)},this._handleSubmit=async e=>{this.baseStore.setState(e=>({...e,isSubmitted:!1,submissionAttempts:e.submissionAttempts+1,isSubmitSuccessful:!1})),q(()=>{Object.values(this.fieldInfo).forEach(e=>{e.instance&&(e.instance.store.state.meta.isTouched||e.instance.setMeta(e=>({...e,isTouched:!0})))})});let t=e??this.options.onSubmitMeta;if(!this.state.canSubmit&&!this._devtoolsSubmissionOverride&&this.baseStore.state.submissionAttempts<=1){this.options.onSubmitInvalid?.({value:this.state.values,formApi:this,meta:t});return}this.baseStore.setState(e=>({...e,isSubmitting:!0}));let n=()=>{this.baseStore.setState(e=>({...e,isSubmitting:!1}))};if(await this.validateAllFields(`submit`),!this.state.isFieldsValid){n(),this.options.onSubmitInvalid?.({value:this.state.values,formApi:this,meta:t}),J.emit(`form-submission`,{id:this._formId,submissionAttempt:this.state.submissionAttempts,successful:!1,stage:`validateAllFields`,errors:Object.values(this.state.fieldMeta).map(e=>e.errors).flat()});return}if(await this.validate(`submit`),!this.state.isValid){n(),this.options.onSubmitInvalid?.({value:this.state.values,formApi:this,meta:t}),J.emit(`form-submission`,{id:this._formId,submissionAttempt:this.state.submissionAttempts,successful:!1,stage:`validate`,errors:this.state.errors});return}q(()=>{Object.values(this.fieldInfo).forEach(e=>{e.instance?.triggerOnSubmitListener()})}),this.options.listeners?.onSubmit?.({formApi:this,meta:t});try{await this.options.onSubmit?.({value:this.state.values,formApi:this,meta:t}),q(()=>{this.baseStore.setState(e=>({...e,isSubmitted:!0,isSubmitSuccessful:!0})),J.emit(`form-submission`,{id:this._formId,submissionAttempt:this.state.submissionAttempts,successful:!0}),n()})}catch(e){throw this.baseStore.setState(e=>({...e,isSubmitSuccessful:!1})),J.emit(`form-submission`,{id:this._formId,submissionAttempt:this.state.submissionAttempts,successful:!1,stage:`inflight`,onError:e}),n(),e}},this.getFieldValue=e=>dr(this.state.values,e),this.getFieldMeta=e=>this.state.fieldMeta[e],this.getFormGroupMeta=e=>this.formGroupMetaDerived.state[e],this.getFieldInfo=e=>this.fieldInfo[e]||={instance:null,validationMetaMap:{onChange:void 0,onBlur:void 0,onSubmit:void 0,onMount:void 0,onServer:void 0,onDynamic:void 0}},this.setFieldMeta=(e,t)=>{this.baseStore.setState(n=>({...n,fieldMetaBase:{...n.fieldMetaBase,[e]:ur(t,n.fieldMetaBase[e])}}))},this.resetFieldMeta=e=>Object.keys(e).reduce((e,t)=>{let n=t;return e[n]=Q,e},{}),this.setFieldValue=(e,t,n)=>{let r=n?.dontUpdateMeta??!1,i=n?.dontRunListeners??!1,a=n?.dontValidate??!1;q(()=>{r||this.setFieldMeta(e,e=>({...e,isTouched:!0,isDirty:!0,errorMap:{...e?.errorMap,onMount:void 0}})),this.baseStore.setState(n=>({...n,values:fr(n.values,e,t)}))}),i||this.getFieldInfo(e).instance?.triggerOnChangeListener(),a||this.validateField(e,`change`)},this.deleteField=e=>{let t=[...Object.keys(this.fieldInfo).filter(t=>{let n=e.toString();return t!==n&&t.startsWith(n)}),e];this.baseStore.setState(e=>{let n={...e};return t.forEach(e=>{n.values=pr(n.values,e),delete this.fieldInfo[e],delete n.fieldMetaBase[e]}),n})},this.pushFieldValue=(e,t,n)=>{this.setFieldValue(e,e=>[...Array.isArray(e)?e:[],t],n),Lr(this).bumpArrayVersion(e)},this.insertFieldValue=async(e,t,n,r)=>{this.setFieldValue(e,e=>[...e.slice(0,t),n,...e.slice(t)],X(r,{dontValidate:!0}));let i=r?.dontValidate??!1;i||await this.validateField(e,`change`),Lr(this).handleArrayInsert(e,t),i||await this.validateArrayFieldsStartingFrom(e,t,`change`)},this.replaceFieldValue=async(e,t,n,r)=>{this.setFieldValue(e,e=>e.map((e,r)=>r===t?n:e),X(r,{dontValidate:!0})),Lr(this).bumpArrayVersion(e),(r?.dontValidate??!1)||(await this.validateField(e,`change`),await this.validateArrayFieldsStartingFrom(e,t,`change`))},this.removeFieldValue=async(e,t,n)=>{let r=this.getFieldValue(e),i=Array.isArray(r)?Math.max(r.length-1,0):null;if(this.setFieldValue(e,e=>e.filter((e,n)=>n!==t),X(n,{dontValidate:!0})),Lr(this).handleArrayRemove(e,t),i!==null){let t=`${e}[${i}]`;this.deleteField(t)}(n?.dontValidate??!1)||(await this.validateField(e,`change`),await this.validateArrayFieldsStartingFrom(e,t,`change`))},this.swapFieldValues=(e,t,n,r)=>{this.setFieldValue(e,e=>{let r=e[t],i=e[n];return fr(fr(e,`${t}`,i),`${n}`,r)},X(r,{dontValidate:!0})),Lr(this).handleArraySwap(e,t,n),(r?.dontValidate??!1)||(this.validateField(e,`change`),this.validateField(`${e}[${t}]`,`change`),this.validateField(`${e}[${n}]`,`change`))},this.moveFieldValues=(e,t,n,r)=>{this.setFieldValue(e,e=>{let r=[...e];return r.splice(n,0,r.splice(t,1)[0]),r},X(r,{dontValidate:!0})),Lr(this).handleArrayMove(e,t,n),(r?.dontValidate??!1)||(this.validateField(e,`change`),this.validateField(`${e}[${t}]`,`change`),this.validateField(`${e}[${n}]`,`change`))},this.clearFieldValues=(e,t)=>{let n=this.getFieldValue(e),r=Array.isArray(n)?Math.max(n.length-1,0):null;if(this.setFieldValue(e,[],X(t,{dontValidate:!0})),Lr(this).bumpArrayVersion(e),r!==null)for(let t=0;t<=r;t++){let n=`${e}[${t}]`;this.deleteField(n)}(t?.dontValidate??!1)||this.validateField(e,`change`)},this.resetField=e=>{this.baseStore.setState(t=>{let n=this.getFieldInfo(e).instance?.options.defaultValue,r=dr(this.options.defaultValues,e),i=n??r;return{...t,fieldMetaBase:{...t.fieldMetaBase,[e]:Q},values:i===void 0?t.values:fr(t.values,e,i)}})},this.setErrorMap=e=>{q(()=>{Object.entries(e).forEach(([e,t])=>{let n=e;if(Cr(t)){let{formError:e,fieldErrors:r}=Br(t);for(let e of Object.keys(this.fieldInfo))this.getFieldMeta(e)&&this.setFieldMeta(e,t=>({...t,errorMap:{...t.errorMap,[n]:r?.[e]},errorSourceMap:{...t.errorSourceMap,[n]:`form`}}));this.baseStore.setState(t=>({...t,errorMap:{...t.errorMap,[n]:e}}))}else this.baseStore.setState(e=>({...e,errorMap:{...e.errorMap,[n]:t}}))})})},this.getAllErrors=()=>({form:{errors:this.state.errors,errorMap:this.state.errorMap},fields:Object.entries(this.state.fieldMeta).reduce((e,[t,n])=>(Object.keys(n).length&&n.errors.length&&(e[t]={errors:n.errors,errorMap:n.errorMap}),e),{})}),this.parseValuesWithSchema=e=>Fr.validate({value:this.state.values,validationSource:`form`},e),this.parseValuesWithSchemaAsync=e=>Fr.validateAsync({value:this.state.values,validationSource:`form`},e),this.timeoutIds={validations:{},listeners:{},formListeners:{}},this._formId=e?.formId??kr(),this._devtoolsSubmissionOverride=!1;let t=Rr({...e?.defaultState,values:e?.defaultValues??e?.defaultState?.values});if(e?.transform){t=e.transform({state:t}).state;for(let e of Object.keys(t.errorMap)){let n=t.errorMap[e];if(!(n===void 0||!Cr(n)))for(let r of Object.keys(n.fields)){let i=n.fields[r];if(i===void 0)continue;let a=t.fieldMetaBase[r];t.fieldMetaBase[r]={isTouched:!1,isValidating:!1,isBlurred:!1,isDirty:!1,_arrayVersion:0,_pendingValidationsCount:0,...a??{},errorSourceMap:{...a?.errorSourceMap??{},onChange:`form`},errorMap:{...a?.errorMap??{},[e]:i}}}}}this.baseStore=or(t);let n;this.fieldMetaDerived=or(e=>{let t=this.baseStore.get(),r=0,i={};for(let a of Object.keys(t.fieldMetaBase)){let o=t.fieldMetaBase[a],s=n?.fieldMetaBase[a],c=e?.[a],l=dr(t.values,a),u=c?.errors;if(!s||o.errorMap!==s.errorMap){u=Object.values(o.errorMap??{}).filter(e=>e!==void 0);let e=this.getFieldInfo(a)?.instance;(!e||!e.options.disableErrorFlat)&&(u=u.flat(1))}let d=!br(u),f=!o.isDirty,p=Y(l,this.getFieldInfo(a)?.instance?.options.defaultValue??dr(this.options.defaultValues,a));if(c&&c.isPristine===f&&c.isValid===d&&c.isDefaultValue===p&&c.errors===u&&o===s){i[a]=c,r++;continue}i[a]={...o,errors:u??[],isPristine:f,isValid:d,isDefaultValue:p}}return Object.keys(t.fieldMetaBase).length?e&&r===Object.keys(t.fieldMetaBase).length?e:(n=this.baseStore.get(),i):i}),this.formGroupMetaDerived=or(e=>{let t=this.baseStore.get(),n=this.fieldMetaDerived.get(),r={};for(let i of this.formGroupApis){let a=i.name,o=t.formGroupStateBase[a]??{isSubmitted:!1,isSubmitting:!1,isValidating:!1,submissionAttempts:0,isSubmitSuccessful:!1},s=n[a],c=!1,l=!0,u=!1,d=!1,f=!0,p=!1;for(let e in n){if(e===a||!Mr(a,e))continue;let t=n[e];t&&(t.isValidating&&(c=!0),t.isValid||(l=!1),t.isTouched&&(u=!0),t.isBlurred&&(d=!0),t.isDefaultValue||(f=!1),t.isDirty&&(p=!0))}let m=!p,h=!!c||o.isValidating,g=s?.errorMap??{},_=s?.errorSourceMap??{},v=!!(g.onMount||Object.entries(n).some(([e,t])=>t&&e!==a&&Mr(a,e)&&t.errorMap.onMount)),y=e?.[a],b=y?.errors??[];(!y||y.__srcErrorMap!==g)&&(b=Object.values(g).reduce((e,t)=>{if(t===void 0)return e;if(t&&typeof t==`object`&&`fields`in t){let n=t.group;return n!==void 0&&e.push(n),e}return e.push(t),e},[]));let x=b.length===0,S=l&&x,C=i.options.canSubmitWhenInvalid??!1,w=o.submissionAttempts===0&&!u&&!v||!h&&!o.isSubmitting&&S||C;if(y&&y.errorMap===g&&y.errorSourceMap===_&&y.errors===b&&y.isFieldsValidating===c&&y.isFieldsValid===l&&y.isGroupValid===x&&y.isValid===S&&y.canSubmit===w&&y.isTouched===u&&y.isBlurred===d&&y.isPristine===m&&y.isDefaultValue===f&&y.isDirty===p&&y.isValidating===h&&y.isSubmitting===o.isSubmitting&&y.isSubmitted===o.isSubmitted&&y.submissionAttempts===o.submissionAttempts&&y.isSubmitSuccessful===o.isSubmitSuccessful){r[a]=y;continue}let T={...o,errorMap:g,errorSourceMap:_,_arrayVersion:s?._arrayVersion??0,isTouched:u,isBlurred:d,isDirty:p,isPristine:m,isDefaultValue:f,isValid:S,errors:b,isValidating:h,isFieldsValidating:c,isFieldsValid:l,isGroupValid:x,canSubmit:w};Object.defineProperty(T,"__srcErrorMap",{value:g,enumerable:!1,configurable:!0}),r[a]=T}return r});let r;this.store=or(e=>{let t=this.baseStore.get(),n=this.fieldMetaDerived.get(),i=Object.values(n).filter(Boolean),a=i.some(e=>e.isValidating),o=i.every(e=>e.isValid),s=i.some(e=>e.isTouched),c=i.some(e=>e.isBlurred),l=i.every(e=>e.isDefaultValue),u=s&&t.errorMap?.onMount,d=i.some(e=>e.isDirty),f=!d,p=!!(t.errorMap?.onMount||i.some(e=>e?.errorMap?.onMount)),m=!!a,h=e?.errors??[];(!r||t.errorMap!==r.errorMap)&&(h=Object.values(t.errorMap).reduce((e,t)=>t===void 0?e:t&&Cr(t)?(e.push(t.form),e):(e.push(t),e),[]));let g=h.length===0,_=o&&g,v=this.options.canSubmitWhenInvalid??!1,y=t.submissionAttempts===0&&!s&&!p||!m&&!t.isSubmitting&&_||v,b=t.errorMap;if(u&&(h=h.filter(e=>e!==t.errorMap.onMount),b=Object.assign(b,{onMount:void 0})),e&&r&&e.errorMap===b&&e.fieldMeta===this.fieldMetaDerived.state&&e.errors===h&&e.isFieldsValidating===a&&e.isFieldsValid===o&&e.isFormValid===g&&e.isValid===_&&e.canSubmit===y&&e.isTouched===s&&e.isBlurred===c&&e.isPristine===f&&e.isDefaultValue===l&&e.isDirty===d&&Y(r,t))return e;let x={...t,errorMap:b,fieldMeta:this.fieldMetaDerived.state,errors:h,isFieldsValidating:a,isFieldsValid:o,isFormValid:g,isValid:_,canSubmit:y,isTouched:s,isBlurred:c,isPristine:f,isDefaultValue:l,isDirty:d};return r=this.baseStore.get(),x}),this.handleSubmit=this.handleSubmit.bind(this),this.update(e||{})}get state(){return this.store.state}get formId(){return this._formId}runValidator(e){return Ir(e.validate)?Fr[e.type](e.value,e.validate):e.validate(e.value)}handleSubmit(e){return this._handleSubmit(e)}};function Br(e){return e?Cr(e)?{formError:Br(e.form).formError,fieldErrors:e.fields}:{formError:e}:{formError:void 0}}function Vr(e){switch(e){case`submit`:return`onSubmit`;case`blur`:return`onBlur`;case`mount`:return`onMount`;case`server`:return`onServer`;case`dynamic`:return`onDynamic`;default:return`onChange`}}var Hr=class e{constructor(t){this.options={},this.mount=()=>{this.options.defaultValue!==void 0&&!this.getMeta().isTouched&&this.form.setFieldValue(this.name,this.options.defaultValue,{dontUpdateMeta:!0});let e=this.getInfo();e.instance=this,this.update(this.options);let{onMount:t}=this.options.validators||{};if(t){let e=this.runValidator({validate:t,value:{value:this.state.value,fieldApi:this,validationSource:`field`},type:`validate`});e&&this.setMeta(t=>({...t,errorMap:{...t?.errorMap,onMount:e},errorSourceMap:{...t?.errorSourceMap,onMount:`field`}}))}return this.options.listeners?.onMount?.({value:this.state.value,fieldApi:this}),()=>{for(let[e,t]of Object.entries(this.timeoutIds.validations))t&&(clearTimeout(t),this.timeoutIds.validations[e]=null);for(let[e,t]of Object.entries(this.timeoutIds.listeners))t&&(clearTimeout(t),this.timeoutIds.listeners[e]=null);for(let[e,t]of Object.entries(this.timeoutIds.formListeners))t&&(clearTimeout(t),this.timeoutIds.formListeners[e]=null);let e=this.form.fieldInfo[this.name];if(e&&e.instance===this){for(let[t,n]of Object.entries(e.validationMetaMap))n?.lastAbortController.abort(),e.validationMetaMap[t]=void 0;this.form.baseStore.setState(e=>({...e,fieldMetaBase:{...e.fieldMetaBase,[this.name]:{...Q,isTouched:e.fieldMetaBase[this.name]?.isTouched??Q.isTouched,isBlurred:e.fieldMetaBase[this.name]?.isBlurred??Q.isBlurred,isDirty:e.fieldMetaBase[this.name]?.isDirty??Q.isDirty}}})),e.instance=null,this.options.listeners?.onUnmount?.({value:this.state.value,fieldApi:this}),this.form.options.listeners?.onFieldUnmount?.({formApi:this.form,fieldApi:this})}}},this.update=e=>{this.options=e,this.name=e.name,!this.state.meta.isTouched&&this.options.defaultValue!==void 0&&(Y(this.form.getFieldValue(this.name),e.defaultValue)||this.form.setFieldValue(this.name,e.defaultValue,{dontUpdateMeta:!0,dontValidate:!0,dontRunListeners:!0})),this.form.getFieldMeta(this.name)||this.form.setFieldMeta(this.name,this.state.meta)},this.getValue=()=>this.form.getFieldValue(this.name),this.setValue=(e,t)=>{this.form.setFieldValue(this.name,e,X(t,{dontRunListeners:!0,dontValidate:!0})),t?.dontRunListeners||this.triggerOnChangeListener(),t?.dontValidate||this.validate(`change`)},this.getMeta=()=>this.store.state.meta,this.setMeta=e=>this.form.setFieldMeta(this.name,e),this.getInfo=()=>this.form.getFieldInfo(this.name),this.pushValue=(e,t)=>{this.form.pushFieldValue(this.name,e,X(t,{dontRunListeners:!0})),t?.dontRunListeners||this.triggerOnChangeListener()},this.insertValue=(e,t,n)=>{this.form.insertFieldValue(this.name,e,t,X(n,{dontRunListeners:!0})),n?.dontRunListeners||this.triggerOnChangeListener()},this.replaceValue=(e,t,n)=>{this.form.replaceFieldValue(this.name,e,t,X(n,{dontRunListeners:!0})),n?.dontRunListeners||this.triggerOnChangeListener()},this.removeValue=(e,t)=>{this.form.removeFieldValue(this.name,e,X(t,{dontRunListeners:!0})),t?.dontRunListeners||this.triggerOnChangeListener()},this.swapValues=(e,t,n)=>{this.form.swapFieldValues(this.name,e,t,X(n,{dontRunListeners:!0})),n?.dontRunListeners||this.triggerOnChangeListener()},this.moveValue=(e,t,n)=>{this.form.moveFieldValues(this.name,e,t,X(n,{dontRunListeners:!0})),n?.dontRunListeners||this.triggerOnChangeListener()},this.clearValues=e=>{this.form.clearFieldValues(this.name,X(e,{dontRunListeners:!0})),e?.dontRunListeners||this.triggerOnChangeListener()},this.getLinkedFields=t=>{let n=Object.values(this.form.fieldInfo),r=[];for(let i of n){if(!i.instance||!(i.instance instanceof e))continue;let{onChangeListenTo:n,onBlurListenTo:a}=i.instance.options.validators||{};t===`change`&&n?.includes(this.name)&&r.push(i.instance),t===`blur`&&a?.includes(this.name)&&r.push(i.instance)}return r},this.validateSync=(e,t)=>{let n=xr(e,{...this.options,form:this.form,fieldName:this.name,validationLogic:this.form.options.validationLogic||Z}),r=this.getLinkedFields(e).reduce((t,n)=>{let r=xr(e,{...n.options,form:n.form,fieldName:n.name,validationLogic:n.form.options.validationLogic||Z});return r.forEach(e=>{e.field=n}),t.concat(r)},[]),i=!1;q(()=>{let e=(e,n)=>{let r=Wr(n.cause),a=n.validate?Ur(e.runValidator({validate:n.validate,value:{value:e.store.state.value,validationSource:`field`,fieldApi:e},type:`validate`})):void 0,o=t[r],{newErrorValue:s,newSource:c}=Tr({formLevelError:o,fieldLevelError:a});e.state.meta.errorMap?.[r]!==s&&e.setMeta(e=>({...e,errorMap:{...e.errorMap,[r]:s},errorSourceMap:{...e.errorSourceMap,[r]:c}})),s&&(i=!0)};for(let t of n)e(this,t);for(let t of r)t.validate&&e(t.field,t)});let a=Wr(`submit`);return this.state.meta.errorMap?.[a]&&e!==`submit`&&!i&&this.setMeta(e=>({...e,errorMap:{...e.errorMap,[a]:void 0},errorSourceMap:{...e.errorSourceMap,[a]:void 0}})),{hasErrored:i}},this.validateAsync=async(e,t)=>{let n=Sr(e,{...this.options,form:this.form,fieldName:this.name,validationLogic:this.form.options.validationLogic||Z}),r=await t,i=this.getLinkedFields(e).reduce((t,n)=>{let r=Sr(e,{...n.options,form:n.form,fieldName:n.name,validationLogic:n.form.options.validationLogic||Z});return r.forEach(e=>{e.field=n}),t.concat(r)},[]),a=[],o=[],s=n.some(e=>e.validate),c=Array.from(new Set(i.filter(e=>e.validate).map(e=>e.field)));q(()=>{s&&this.startValidation();for(let e of c)e.startValidation()});let l=(e,t,n)=>{let i=Wr(t.cause),a=e.getInfo();a.validationMetaMap[i]?.lastAbortController.abort();let o=new AbortController;a.validationMetaMap[i]={lastAbortController:o},n.push(new Promise(async n=>{let a;try{a=await new Promise((n,r)=>{e.timeoutIds.validations[t.cause]&&(clearTimeout(e.timeoutIds.validations[t.cause]),e.endValidation()),e.timeoutIds.validations[t.cause]=setTimeout(async()=>{if(o.signal.aborted)return n(void 0);try{n(await this.runValidator({validate:t.validate,value:{value:e.store.state.value,fieldApi:e,signal:o.signal,validationSource:`field`},type:`validateAsync`}))}catch(e){r(e)}},t.debounceMs)})}catch(e){a=e}if(o.signal.aborted)return n(void 0);let s=Ur(a),c=r[e.name]?.[i],{newErrorValue:l,newSource:u}=Tr({formLevelError:c,fieldLevelError:s});if(e.getInfo().instance!==e)return n(void 0);e.setMeta(e=>({...e,errorMap:{...e?.errorMap,[i]:l},errorSourceMap:{...e.errorSourceMap,[i]:u}})),n(l)}))};for(let e of n)e.validate&&l(this,e,a);for(let e of i)e.validate&&l(e.field,e,o);let u=[];return(a.length||o.length)&&(u=await Promise.all(a),await Promise.all(o)),q(()=>{s&&this.endValidation();for(let e of c)e.endValidation()}),u.filter(Boolean)},this.validate=(e,t)=>{if(!this.state.meta.isTouched)return[];let n=t?.skipGroupValidation?[]:Array.from(this.form.formGroupApis).filter(e=>this.name.startsWith(e.name)),r=(t?.skipFormValidation?{fieldsErrorMap:{}}:this.form.validateSync(e)).fieldsErrorMap[this.name]??{};if(!t?.skipFormValidation)for(let t of n){if(t.state.meta.submissionAttempts===0)continue;let{fieldsErrorMap:n}=this.form.validateSync(e,{group:t,dontUpdateFormErrorMap:!0,filterFieldNames:e=>Mr(t.name,e)});r={...r,...n[this.name]??{}}}let{hasErrored:i}=this.validateSync(e,r),a=new WeakMap;for(let t of n){let{hasErrored:n}=t.validateSync(e,{},{skipRelatedFieldValidation:!0});a.set(t,n)}if(i&&!this.options.asyncAlways){this.getInfo().validationMetaMap[Wr(e)]?.lastAbortController.abort();let t=[];for(let r of n)r.getInfo().validationMetaMap[Wr(e)]?.lastAbortController.abort(),t.push(r.state.meta.errors);return[...this.state.meta.errors,...t.flat()]}let o=t?.skipFormValidation?Promise.resolve({}):this.form.validateAsync(e),s=this.validateAsync(e,o),c=[];for(let t of n)a.get(t)&&!t.options.asyncAlways||c.push(t.validateAsync(e,o,{skipRelatedFieldValidation:!0}));return c.length===0?s:Promise.all([s,...c]).then(e=>e.flat())},this.handleChange=e=>{this.setValue(e)},this.handleBlur=()=>{this.state.meta.isTouched||this.setMeta(e=>({...e,isTouched:!0})),this.state.meta.isBlurred||this.setMeta(e=>({...e,isBlurred:!0})),this.validate(`blur`),this.triggerOnBlurListener()},this.setErrorMap=e=>{this.setMeta(t=>({...t,errorMap:{...t.errorMap,...e}}))},this.parseValueWithSchema=e=>Fr.validate({value:this.state.value,validationSource:`field`},e),this.parseValueWithSchemaAsync=e=>Fr.validateAsync({value:this.state.value,validationSource:`field`},e),this.triggerOnBlurListener=()=>{let e=this.form.options.listeners?.onBlurDebounceMs;e&&e>0?(this.timeoutIds.formListeners.blur&&clearTimeout(this.timeoutIds.formListeners.blur),this.timeoutIds.formListeners.blur=setTimeout(()=>{this.form.options.listeners?.onBlur?.({formApi:this.form,fieldApi:this})},e)):this.form.options.listeners?.onBlur?.({formApi:this.form,fieldApi:this});let t=this.options.listeners?.onBlurDebounceMs;t&&t>0?(this.timeoutIds.listeners.blur&&clearTimeout(this.timeoutIds.listeners.blur),this.timeoutIds.listeners.blur=setTimeout(()=>{this.options.listeners?.onBlur?.({value:this.state.value,fieldApi:this})},t)):this.options.listeners?.onBlur?.({value:this.state.value,fieldApi:this})},this.triggerOnChangeListener=()=>{let e=this.form.options.listeners?.onChangeDebounceMs;e&&e>0?(this.timeoutIds.formListeners.change&&clearTimeout(this.timeoutIds.formListeners.change),this.timeoutIds.formListeners.change=setTimeout(()=>{this.form.options.listeners?.onChange?.({formApi:this.form,fieldApi:this})},e)):this.form.options.listeners?.onChange?.({formApi:this.form,fieldApi:this});let t=this.options.listeners?.onChangeDebounceMs;t&&t>0?(this.timeoutIds.listeners.change&&clearTimeout(this.timeoutIds.listeners.change),this.timeoutIds.listeners.change=setTimeout(()=>{this.options.listeners?.onChange?.({value:this.state.value,fieldApi:this})},t)):this.options.listeners?.onChange?.({value:this.state.value,fieldApi:this});for(let e of this.form.formGroupApis)Mr(e.name,this.name)&&e.triggerOnChangeListener()},this.triggerOnSubmitListener=()=>{this.options.listeners?.onSubmit?.({value:this.state.value,fieldApi:this})},this.form=t.form,this.name=t.name,this.options=t,this.timeoutIds={validations:{},listeners:{},formListeners:{}},this.store=or(e=>{this.form.store.get();let n=this.form.getFieldMeta(this.name)??{...Q,...t.defaultMeta},r=this.form.getFieldValue(this.name);return!n.isTouched&&r===void 0&&this.options.defaultValue!==void 0&&!Y(r,this.options.defaultValue)&&(r=this.options.defaultValue),e&&e.value===r&&e.meta===n?e:{value:r,meta:n}})}get state(){return this.store.state}runValidator(e){return Ir(e.validate)?Fr[e.type](e.value,e.validate):e.validate(e.value)}startValidation(){this.setMeta(e=>{let t=e._pendingValidationsCount+1;return{...e,_pendingValidationsCount:t,isValidating:t>0&&!e.isValidating||e.isValidating}})}endValidation(){this.setMeta(e=>{let t=Math.max(0,e._pendingValidationsCount-1);return{...e,_pendingValidationsCount:t,isValidating:t===0&&e.isValidating?!1:e.isValidating}})}};function Ur(e){if(e)return e}function Wr(e){switch(e){case`submit`:return`onSubmit`;case`blur`:return`onBlur`;case`mount`:return`onMount`;case`server`:return`onServer`;case`dynamic`:return`onDynamic`;default:return`onChange`}}function Gr(e){return{isSubmitted:e.isSubmitted??!1,isSubmitting:e.isSubmitting??!1,isValidating:e.isValidating??!1,submissionAttempts:e.submissionAttempts??0,isSubmitSuccessful:e.isSubmitSuccessful??!1}}function Kr(e){return{...Q,...e,errors:[],isPristine:!0,isValid:!0,isDefaultValue:!0,isFieldsValidating:!1,isFieldsValid:!0,isGroupValid:!0,canSubmit:!0,isSubmitting:!1,isSubmitted:!1,isValidating:!1,submissionAttempts:0,isSubmitSuccessful:!1}}var qr=class e{constructor(t){this.options={},this.setFormGroupState=e=>{this.form.baseStore.setState(t=>{let n=t.formGroupStateBase[this.name]??Gr({});return{...t,formGroupStateBase:{...t.formGroupStateBase,[this.name]:e(n)}}})},this._lastDistributedFieldNames={},this.update=e=>{this.options=e,this.name=e.name,!this.state.meta.isTouched&&this.options.defaultValue!==void 0&&(Y(this.form.getFieldValue(this.name),e.defaultValue)||this.form.setFieldValue(this.name,e.defaultValue,{dontUpdateMeta:!0,dontValidate:!0,dontRunListeners:!0})),this.form.getFieldMeta(this.name)||this.form.setFieldMeta(this.name,{...Q,...this.options.defaultMeta})},this.mount=()=>{this.update(this.options),this.form.formGroupApis.add(this),this.fieldInfo.instance=this,this.form.baseStore.setState(e=>({...e,formGroupStateBase:{...e.formGroupStateBase,[this.name]:e.formGroupStateBase[this.name]??Gr({...this.options.defaultState})}}));let{onMount:e}=this.options.validators||{};if(e){let t=this.runValidator({validate:e,value:{value:this.state.value,groupApi:this,validationSource:`form`},type:`validate`}),n=t,r;Yr(t)&&(n=t.group,r=t.fields);let i=Jr(n);i&&this.setMeta(e=>({...e,errorMap:{...e.errorMap,onMount:i},errorSourceMap:{...e.errorSourceMap,onMount:`field`}})),this.distributeFieldErrors(`onMount`,r)}return this.options.listeners?.onMount?.({value:this.state.value,groupApi:this}),()=>{for(let[e,t]of Object.entries(this.timeoutIds.validations))t&&(clearTimeout(t),this.timeoutIds.validations[e]=null);for(let[e,t]of Object.entries(this.timeoutIds.listeners))t&&(clearTimeout(t),this.timeoutIds.listeners[e]=null);for(let[e,t]of Object.entries(this.timeoutIds.formListeners))t&&(clearTimeout(t),this.timeoutIds.formListeners[e]=null);if(this.fieldInfo.instance===this){for(let[e,t]of Object.entries(this.fieldInfo.validationMetaMap))t?.lastAbortController.abort(),this.fieldInfo.validationMetaMap[e]=void 0;this.form.formGroupApis.delete(this),this.form.baseStore.setState(e=>({...e,formGroupStateBase:{...e.formGroupStateBase,[this.name]:Gr({})}})),this.fieldInfo.instance=null,this.options.listeners?.onUnmount?.({value:this.state.value,groupApi:this})}}},this.setValue=(e,t)=>{this.form.setFieldValue(this.name,e,X(t,{dontRunListeners:!0,dontValidate:!0})),t?.dontRunListeners||this.triggerOnChangeListener(),t?.dontValidate||this.validate(`change`)},this.getMeta=()=>this.store.state.meta,this.setMeta=e=>this.form.setFieldMeta(this.name,e),this.getInfo=()=>this.fieldInfo,this.getRelatedFields=()=>{let e=Object.values(this.form.fieldInfo),t=[];for(let n of e)n.instance&&n.instance instanceof Hr&&n.instance.name.startsWith(this.name)&&t.push(n.instance);return t},this.getRelatedFieldMetasDerived=()=>{let e=Object.entries(this.form.fieldMetaDerived.state),t=[];for(let[n,r]of e)n!==this.name&&Mr(this.name,n)&&t.push({...r,name:n});return t},this.buildChildFieldName=e=>e===``?this.name:e.startsWith(`[`)?`${this.name}${e}`:`${this.name}.${e}`,this.distributeFieldErrors=(e,t)=>{let n=this._lastDistributedFieldNames[e]??new Set,r=new Set;if(t)for(let[e,n]of Object.entries(t))n!=null&&n!==!1&&r.add(this.buildChildFieldName(e));let i=new Set([...n,...r]),a=!1;for(let n of i){let r=n.startsWith(this.name+`[`)?n.slice(this.name.length):n.slice(this.name.length+1),i=t?.[r],o=this.form.getFieldMeta(n);if(!o&&!i)continue;let s=o?.errorMap[e],{newErrorValue:c,newSource:l}=wr({newFormValidatorError:i,isPreviousErrorFromFormValidator:o?.errorSourceMap[e]===`form`,previousErrorValue:s});c&&(a=!0),(s!==c||o?.errorSourceMap[e]!==l)&&this.form.setFieldMeta(n,(t=Q)=>({...t,errorMap:{...t.errorMap,[e]:c},errorSourceMap:{...t.errorSourceMap,[e]:l}}))}return this._lastDistributedFieldNames[e]=r,a},this.validateSync=(t,n,r={})=>{let i=xr(t,{...this.options,form:this.form,group:this,validationLogic:this.options.validationLogic||this.form.options.validationLogic||Z}),a=(r.skipRelatedFieldValidation?[]:this.getRelatedFields()).reduce((e,n)=>{let r=xr(t,{...n.options,form:n.form,validationLogic:n.form.options.validationLogic||Z});return r.forEach(e=>{e.field=n}),e.concat(r)},[]),o=!1;q(()=>{let t=(t,r)=>{let i=Zr(r.cause),a=t===this,s;r.validate&&(s=t.runValidator({validate:r.validate,value:{value:t.store.state.value,validationSource:a?`form`:`field`,...t instanceof e?{groupApi:t}:{fieldApi:t}},type:`validate`}));let c=s,l;a&&Yr(s)&&(c=s.group,l=s.fields);let u=Jr(c),d=n[i],{newErrorValue:f,newSource:p}=Tr({formLevelError:d,fieldLevelError:u});t.state.meta.errorMap?.[i]!==f&&t.setMeta(e=>({...e,errorMap:{...e.errorMap,[i]:f},errorSourceMap:{...e.errorSourceMap,[i]:p}})),f&&(o=!0),a&&this.distributeFieldErrors(i,l)&&(o=!0)};for(let e of i)t(this,e);for(let e of a)e.validate&&t(e.field,e)});let s=Zr(`submit`);return this.state.meta.errorMap?.[s]&&t!==`submit`&&!o&&this.setMeta(e=>({...e,errorMap:{...e.errorMap,[s]:void 0},errorSourceMap:{...e.errorSourceMap,[s]:void 0}})),{hasErrored:o}},this.validateAsync=async(t,n,r={})=>{let i=Sr(t,{...this.options,form:this.form,group:this,validationLogic:this.options.validationLogic||this.form.options.validationLogic||Z}),a=await n,o=r.skipRelatedFieldValidation?[]:this.getRelatedFields(),s=o.reduce((e,n)=>{let r=Sr(t,{...n.options,form:n.form,validationLogic:n.form.options.validationLogic||Z});return r.forEach(e=>{e.field=n}),e.concat(r)},[]),c=[],l=[],u=i.some(e=>e.validate)||s.some(e=>e.validate);if(u){this.state.meta.isValidating||this.setMeta(e=>({...e,isValidating:!0}));for(let e of o)e.setMeta(e=>({...e,isValidating:!0}))}let d=(t,n,r)=>{let i=Zr(n.cause),o=t.getInfo();o.validationMetaMap[i]?.lastAbortController.abort();let s=new AbortController;o.validationMetaMap[i]={lastAbortController:s};let c=t===this;r.push(new Promise(async r=>{let o;try{o=await new Promise((r,i)=>{t.timeoutIds.validations[n.cause]&&clearTimeout(t.timeoutIds.validations[n.cause]),t.timeoutIds.validations[n.cause]=setTimeout(async()=>{if(s.signal.aborted)return r(void 0);try{r(await this.runValidator({validate:n.validate,value:{value:t.store.state.value,signal:s.signal,validationSource:c?`form`:`field`,...t instanceof e?{groupApi:t}:{fieldApi:t}},type:`validateAsync`}))}catch(e){i(e)}},n.debounceMs)})}catch(e){o=e}if(s.signal.aborted)return r(void 0);let l=o,u;c&&Yr(o)&&(l=o.group,u=o.fields);let d=Jr(l),f=a[t.name]?.[i],{newErrorValue:p,newSource:m}=Tr({formLevelError:f,fieldLevelError:d});if(t.getInfo().instance!==t)return r(void 0);t.setMeta(e=>({...e,errorMap:{...e?.errorMap,[i]:p},errorSourceMap:{...e.errorSourceMap,[i]:m}})),c&&this.distributeFieldErrors(i,u),r(p)}))};for(let e of i)e.validate&&d(this,e,c);for(let e of s)e.validate&&d(e.field,e,l);let f=[];if((c.length||l.length)&&(f=await Promise.all(c),await Promise.all(l)),u){this.setMeta(e=>({...e,isValidating:!1}));for(let e of o)e.setMeta(e=>({...e,isValidating:!1}))}return f.filter(Boolean)},this.validateAllFields=async e=>{let t=[];return q(()=>{Object.values(this.getRelatedFields()).forEach(n=>{t.push(Promise.resolve().then(()=>n.validate(e,{skipFormValidation:!0,skipGroupValidation:!0}))),n.store.state.meta.isTouched||n.setMeta(e=>({...e,isTouched:!0}))})}),(await Promise.all(t)).flat()},this.validateArrayFieldsStartingFrom=(e,t,n)=>this.form.validateArrayFieldsStartingFrom(e,t,n),this.validateField=(e,t)=>this.form.validateField(e,t),this.getFieldValue=e=>this.form.getFieldValue(e),this.getFieldMeta=e=>this.form.getFieldMeta(e),this.setFieldMeta=(e,t)=>this.form.setFieldMeta(e,t),this.setFieldValue=(e,t)=>this.form.setFieldValue(e,t),this.deleteField=e=>this.form.deleteField(e),this.pushFieldValue=(e,t)=>this.form.pushFieldValue(e,t),this.insertFieldValue=(e,t,n)=>this.form.insertFieldValue(e,t,n),this.replaceFieldValue=(e,t,n)=>this.form.replaceFieldValue(e,t,n),this.swapFieldValues=(e,t,n)=>this.form.swapFieldValues(e,t,n),this.moveFieldValues=(e,t,n)=>this.form.moveFieldValues(e,t,n),this.clearFieldValues=e=>this.form.clearFieldValues(e),this.resetField=e=>this.form.resetField(e),this.removeFieldValue=(e,t)=>this.form.removeFieldValue(e,t),this.areRelatedFieldsValid=()=>Object.values(this.getRelatedFields()).every(e=>e.state.meta.isValid),this.validate=(e,t)=>{let{fieldsErrorMap:n}=t?.skipFormValidation?{fieldsErrorMap:{}}:this.form.validateSync(e,{dontUpdateFormErrorMap:!0,filterFieldNames:e=>Mr(this.name,e)}),{hasErrored:r}=this.validateSync(e,n[this.name]??{},{skipRelatedFieldValidation:t?.skipRelatedFieldValidation});if(r&&!this.options.asyncAlways)return this.getInfo().validationMetaMap[Zr(e)]?.lastAbortController.abort(),this.state.meta.errors;let i=t?.skipFormValidation?Promise.resolve({}):this.form.validateAsync(e,{dontUpdateFormErrorMap:!0,filterFieldNames:e=>Mr(this.name,e)});return this.validateAsync(e,i,{skipRelatedFieldValidation:t?.skipRelatedFieldValidation})},this.triggerOnChangeListener=()=>{let e=this.form.options.listeners?.onChangeGroupDebounceMs;e&&e>0?(this.timeoutIds.formListeners.change&&clearTimeout(this.timeoutIds.formListeners.change),this.timeoutIds.formListeners.change=setTimeout(()=>{this.form.options.listeners?.onChangeGroup?.({formApi:this.form,groupApi:this})},e)):this.form.options.listeners?.onChangeGroup?.({formApi:this.form,groupApi:this});let t=this.options.listeners?.onChangeDebounceMs;t&&t>0?(this.timeoutIds.listeners.change&&clearTimeout(this.timeoutIds.listeners.change),this.timeoutIds.listeners.change=setTimeout(()=>{this.options.listeners?.onChange?.({value:this.state.value,groupApi:this})},t)):this.options.listeners?.onChange?.({value:this.state.value,groupApi:this})},this.triggerOnSubmitListener=()=>{this.options.listeners?.onSubmit?.({value:this.state.value,groupApi:this})},this._handleSubmit=async e=>{this.setFormGroupState(e=>({...e,isSubmitted:!1,submissionAttempts:e.submissionAttempts+1,isSubmitSuccessful:!1})),q(()=>{Object.values(this.getRelatedFields()).forEach(e=>{e.state.meta.isTouched||e.setMeta(e=>({...e,isTouched:!0}))})});let t=e??this.options.onSubmitMeta;this.setFormGroupState(e=>({...e,isSubmitting:!0}));let n=()=>{this.setFormGroupState(e=>({...e,isSubmitting:!1}))};if(await this.validateAllFields(`submit`),!this.areRelatedFieldsValid()){n(),this.options.onGroupSubmitInvalid?.({value:this.state.value,groupApi:this,meta:t});return}if(await this.validate(`submit`,{skipRelatedFieldValidation:!0}),!this.areRelatedFieldsValid()||!this.state.meta.isValid){n(),this.options.onGroupSubmitInvalid?.({value:this.state.value,groupApi:this,meta:t});return}q(()=>{Object.values(this.getRelatedFields()).forEach(e=>{e.options.listeners?.onGroupSubmit?.({value:e.state.value,fieldApi:e})})}),this.options.listeners?.onSubmit?.({groupApi:this,value:this.state.value});try{await this.options.onGroupSubmit?.({value:this.state.value,groupApi:this,meta:t}),q(()=>{this.setFormGroupState(e=>({...e,isSubmitted:!0,isSubmitSuccessful:!0})),n()})}catch(e){throw this.setFormGroupState(e=>({...e,isSubmitSuccessful:!1})),n(),e}},this.form=t.form,this.name=t.name,this.options=t,this.timeoutIds={validations:{},listeners:{},formListeners:{}},this.fieldInfo={instance:null,validationMetaMap:{onChange:void 0,onBlur:void 0,onSubmit:void 0,onMount:void 0,onServer:void 0,onDynamic:void 0}},this.store=or(e=>{this.form.formGroupMetaDerived.get(),this.form.baseStore.get();let n=this.form.getFormGroupMeta(this.name)??Kr(t.defaultMeta),r=this.form.getFieldValue(this.name);return!n.isTouched&&r===void 0&&this.options.defaultValue!==void 0&&!Y(r,this.options.defaultValue)&&(r=this.options.defaultValue),e&&e.value===r&&e.meta===n?e:{value:r,meta:n}}),this.handleSubmit=this.handleSubmit.bind(this)}get state(){return this.store.state}runValidator(e){if(Ir(e.validate)){let t=Fr[e.type](e.value,e.validate);return e.type===`validate`?Xr(t):t.then(Xr)}return e.validate(e.value)}handleSubmit(e){return this._handleSubmit(e)}};function Jr(e){if(e)return e}function Yr(e){return!!e&&typeof e==`object`&&`fields`in e}function Xr(e){if(!e||typeof e!=`object`||!(`form`in e)&&!(`fields`in e))return e;let{form:t,fields:n,...r}=e;return{...r,group:t,fields:n}}function Zr(e){switch(e){case`submit`:return`onSubmit`;case`blur`:return`onBlur`;case`mount`:return`onMount`;case`server`:return`onServer`;case`dynamic`:return`onDynamic`;default:return`onChange`}}function Qr(e,t){if(!t)return;let n=Object.assign({},e,{state:jr(e.state)});t(n),n.fieldInfo!==e.fieldInfo&&(e.fieldInfo=n.fieldInfo),n.options!==e.options&&(e.options=n.options);let r=Object.keys({values:null,validationMetaMap:null,fieldMetaBase:null,formGroupStateBase:null,isSubmitting:null,isSubmitted:null,isValidating:null,submissionAttempts:null,isSubmitSuccessful:null,_force_re_eval:null}).reduce((t,r)=>(e.state[r]!==n.state[r]&&(t[r]=n.state[r]),t),{});return q(()=>{Object.keys(r).length&&e.baseStore.setState(e=>({...e,...r})),n.state.errorMap!==e.state.errorMap&&e.setErrorMap(n.state.errorMap)}),n}var $r=w();function ei(e,t){return e===t}function $(e,t=e=>e,n){let r=n?.compare??ei,i=(0,F.useCallback)(t=>{let{unsubscribe:n}=e.subscribe(t);return n},[e]),a=(0,F.useCallback)(()=>e.get(),[e]);return(0,$r.useSyncExternalStoreWithSelector)(i,a,a,t,r)}var ti=typeof window<`u`?F.useLayoutEffect:F.useEffect;function ni(e){let[t,n]=(0,F.useState)(()=>({form:e.form,name:e.name})),[r,i]=(0,F.useState)(()=>new Hr({...e})),a=r;(t.form!==e.form||t.name!==e.name)&&(a=new Hr({...e}),i(a),n({form:e.form,name:e.name}));let o=$(a.store,e.mode===`array`?e=>e.meta._arrayVersion||0:e=>e.value),s=$(a.store,e=>e.meta.isTouched),c=$(a.store,e=>e.meta.isBlurred),l=$(a.store,e=>e.meta.isDirty),u=$(a.store,e=>e.meta.errorMap),d=$(a.store,e=>e.meta.errorSourceMap),f=$(a.store,e=>e.meta.isValidating),p=(0,F.useMemo)(()=>({...a,get state(){return{value:e.mode===`array`?a.state.value:o,get meta(){return{...a.state.meta,isTouched:s,isBlurred:c,isDirty:l,errorMap:u,errorSourceMap:d,isValidating:f}}}}}),[a,e.mode,o,s,c,l,u,d,f]);return ti(a.mount,[a]),ti(()=>{a.update(e)}),p}var ri=(({children:e,...t})=>{let n=ni(t),r=(0,F.useMemo)(()=>ur(e,n),[e,n]);return(0,I.jsx)(I.Fragment,{children:r})});function ii(){return(0,F.useState)(()=>kr())[0]}var ai=F,oi=`18.3.1`.split(`.`)[0]===`17`?ii:ai.useId;function si(e){let[t,n]=(0,F.useState)(()=>({form:e.form,name:e.name})),[r,i]=(0,F.useState)(()=>new qr({...e}));(t.form!==e.form||t.name!==e.name)&&(i(new qr({...e})),n({form:e.form,name:e.name}));let a=$(r.store,e=>e.value),o=$(r.store,e=>e.meta.isTouched),s=$(r.store,e=>e.meta.isBlurred),c=$(r.store,e=>e.meta.isDirty),l=$(r.store,e=>e.meta.errorMap),u=$(r.store,e=>e.meta.errorSourceMap),d=$(r.store,e=>e.meta.isValidating),f=$(r.store,e=>e.meta.isSubmitting),p=$(r.store,e=>e.meta.isSubmitted),m=$(r.store,e=>e.meta.submissionAttempts),h=$(r.store,e=>e.meta.isSubmitSuccessful),g=$(r.store,e=>e.meta.canSubmit),_=$(r.store,e=>e.meta.isValid),v=$(r.store,e=>e.meta.isFieldsValid),y=$(r.store,e=>e.meta.isFieldsValidating),b=$(r.store,e=>e.meta.isGroupValid),x=(0,F.useMemo)(()=>({...r,handleSubmit:((...e)=>r._handleSubmit(...e)),get state(){return{...r.state,value:a,get meta(){return{...r.state.meta,isTouched:o,isBlurred:s,isDirty:c,errorMap:l,errorSourceMap:u,isValidating:d,isSubmitting:f,isSubmitted:p,submissionAttempts:m,isSubmitSuccessful:h,canSubmit:g,isValid:_,isFieldsValid:v,isFieldsValidating:y,isGroupValid:b}}}}}),[r,a,o,s,c,l,u,d,f,p,m,h,g,_,v,y,b]);return ti(r.mount,[r]),ti(()=>{r.update(e)}),x}var ci=(({children:e,...t})=>{let n=si(t),r=(0,F.useMemo)(()=>ur(e,n),[e,n]);return(0,I.jsx)(I.Fragment,{children:r})});function li({form:e,selector:t=e=>e,children:n}){let r=$(e.store,t);return(0,I.jsx)(I.Fragment,{children:ur(n,r)})}function ui(e){let t=oi(),[n,r]=(0,F.useState)(e?.formId),[i,a]=(0,F.useState)(()=>new zr({...e,formId:e?.formId??t}));if(n!==e?.formId){let n=e?.formId??t;a(new zr({...e,formId:n})),r(n)}let o=(0,F.useMemo)(()=>{let e={...i,handleSubmit:((...e)=>i._handleSubmit(...e)),get formId(){return i._formId},get state(){return i.store.state}};return e.Field=function(e){return(0,I.jsx)(ri,{...e,form:i})},e.FormGroup=function(e){return(0,I.jsx)(ci,{...e,form:i})},e.Subscribe=function(e){return(0,I.jsx)(li,{form:i,selector:e.selector,children:e.children})},e},[i]);ti(i.mount,[]),ti(()=>{i.update(e)});let s=(0,F.useRef)(!1);return ti(()=>{s.current&&e?.transform&&Qr(i,e.transform)},[i,e?.transform]),ti(()=>{s.current=!0}),o}export{Te as C,we as S,Xe as _,In as a,Ye as b,An as c,Tn as d,En as f,tn as g,yn as h,Y as i,Nn as l,Sn as m,ni as n,Pn as o,Cn as p,$ as r,jn as s,ui as t,Vn as u,Je as v,ye as w,Ce as x,qe as y};
package/dist/index.html CHANGED
@@ -4,11 +4,11 @@
4
4
  <meta charset="UTF-8" />
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1" />
6
6
  <title>Inkcap</title>
7
- <script type="module" crossorigin src="./assets/index-B-zUw4Dm.js"></script>
7
+ <script type="module" crossorigin src="./assets/index-CCQdYVlj.js"></script>
8
8
  <link rel="modulepreload" crossorigin href="./assets/rolldown-runtime-hePW80VL.js">
9
- <link rel="modulepreload" crossorigin href="./assets/tree-path-JjH_INEe.js">
10
- <link rel="modulepreload" crossorigin href="./assets/folder-open-DArW1Xa9.js">
11
- <link rel="stylesheet" crossorigin href="./assets/index-B93IuBn_.css">
9
+ <link rel="modulepreload" crossorigin href="./assets/tree-path-D47zLaQq.js">
10
+ <link rel="modulepreload" crossorigin href="./assets/folder-open-vITejO7G.js">
11
+ <link rel="stylesheet" crossorigin href="./assets/index-BVzEVOIH.css">
12
12
  </head>
13
13
  <body>
14
14
  <div id="inkcap-root"></div>
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@fungi.computer/inkcap",
3
3
  "description": "Inkcap: edit the files on your Computer, an App for Oyster",
4
- "version": "0.8.4",
4
+ "version": "0.8.6",
5
5
  "author": "Levi <levi@technomancy.dev>",
6
6
  "type": "module",
7
7
  "exports": {
@@ -12,7 +12,7 @@
12
12
  "react": "18.3.1",
13
13
  "react-dom": "18.3.1",
14
14
  "@tanstack/react-form": "1.33.2",
15
- "@fungi.computer/caps": "0.10.2",
15
+ "@fungi.computer/caps": "0.10.4",
16
16
  "@fungi.computer/agar": "0.9.1",
17
17
  "lucide-react": "0.460.0",
18
18
  "@fungi.computer/stipe": "0.1.1",
@@ -27,7 +27,7 @@
27
27
  "@fungi.computer/computer-contract": "0.1.0"
28
28
  },
29
29
  "devDependencies": {
30
- "@fungi.computer/oyster": "0.19.24",
30
+ "@fungi.computer/oyster": "0.19.27",
31
31
  "@ladle/react": "5.1.1",
32
32
  "@fungi.computer/capnweb": "0.12.0-fungi.0",
33
33
  "@vitejs/plugin-react": "6.1.1",
@@ -1 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{$ as t,$n as n,$r as r,A as i,Ai as a,An as o,Ar as s,B as c,Bi as l,Bn as u,Br as d,Bt as f,C as p,Cn as m,Ct as h,D as g,Di as _,Dn as v,Dr as y,Dt as b,E as x,Ei as S,En as C,Et as w,F as T,Fi as E,Fn as D,Fr as O,G as k,Gi as A,Gn as j,H as M,Hi as N,Hn as ee,Hr as P,I as F,Ii as te,In as ne,Ir as re,J as ie,Jn as ae,Jr as oe,Jt as se,K as ce,L as le,Li as ue,Ln as de,Lr as fe,M as pe,Mi as me,Mn as he,Mr as ge,N as _e,Ni as ve,Nn as ye,Nr as be,O as xe,Oi as Se,On as Ce,Or as we,Ot as Te,P as Ee,Pi as De,Pn as Oe,Pr as ke,Qn as Ae,Qr as I,R as je,Rr as Me,S as Ne,Sn as Pe,Ti as Fe,Tn as L,Tt as R,U as Ie,Ui as Le,Ur as Re,V as ze,Vi as Be,Vn as z,Vr as Ve,Vt as He,W as Ue,Wi as We,Wr as Ge,Xn as Ke,Xt as qe,Y as Je,Yn as Ye,Yr as Xe,Yt as Ze,Z as Qe,Zn as $e,Zr as et,Zt as tt,_ as nt,_n as rt,ai as it,an as at,ar as ot,at as st,b as ct,bi as lt,bn as ut,bt as dt,ci as B,cn as ft,ct as pt,dn as V,dt as mt,ei as ht,er as gt,et as _t,f as vt,fi as yt,fn as H,ft as bt,g as xt,gn as U,gt as St,h as Ct,hn as wt,i as Tt,ir as Et,it as Dt,j as Ot,ji as kt,jn as At,jr as jt,ki as Mt,kn as Nt,kr as Pt,kt as W,l as Ft,ln as It,m as Lt,mn as Rt,ni as zt,nn as Bt,nr as Vt,nt as Ht,o as Ut,on as Wt,ot as Gt,p as Kt,pn as qt,pt as Jt,qn as Yt,r as Xt,ri as Zt,rn as G,rr as Qt,rt as $t,s as en,sn as tn,t as nn,tn as rn,tr as an,tt as on,u as sn,un as cn,ut as K,v as ln,vn as un,w as dn,wi as fn,wn as pn,x as mn,xn as hn,xt as gn,y as _n,yn as vn,z as yn,zn as bn}from"./tree-path-JjH_INEe.js";import{At as xn,St as Sn,_t as Cn,a as wn,bt as Tn,c as En,d as Dn,ht as On,i as kn,kt as An,l as jn,n as Mn,r as Nn,t as Pn,wt as Fn,y as In}from"./folder-open-DArW1Xa9.js";import{a as Ln,c as Rn,d as zn,i as Bn,l as Vn,n as Hn,o as Un,r as Wn,s as Gn,t as Kn,u as qn}from"./useFileTree-BtMBhuEG.js";import{C as Jn,S as Yn,_ as Xn,a as Zn,b as Qn,c as $n,d as er,f as tr,g as nr,h as rr,i as ir,l as ar,m as or,n as sr,o as cr,p as lr,r as ur,s as dr,t as fr,u as pr,v as mr,w as hr,x as gr,y as _r}from"./useForm-Bv4zS8bL.js";import{t as vr}from"./refresh-cw-Cj8Ajrfj.js";function yr(e,t){let n=new Set(t);return e.filter(e=>!n.has(e))}var br=class extends Cn{#e;#t;#n;#r;#i;#a;#o;#s;#c;#l=[];constructor(e,t,n){super(),this.#e=e,this.#r=n,this.#n=[],this.#i=[],this.#t=[],this.setQueries(t)}onSubscribe(){this.listeners.size===1&&this.#i.forEach(e=>{e.subscribe(t=>{this.#m(e,t)})})}onUnsubscribe(){this.listeners.size||this.destroy()}destroy(){this.listeners=new Set,this.#i.forEach(e=>{e.destroy()})}setQueries(e,t){this.#n=e,this.#r=t,On.batch(()=>{let e=this.#i,t=this.#p(this.#n);t.forEach(e=>e.observer.setOptions(e.defaultedQueryOptions));let n=t.map(e=>e.observer),r=n.map(e=>e.getCurrentResult()),i=e.length!==n.length,a=n.some((t,n)=>t!==e[n]),o=i||a,s=o?!0:r.some((e,t)=>{let n=this.#t[t];return!n||!Fn(e,n)});!o&&!s||(o&&(this.#l=t,this.#i=n),this.#t=r,this.hasListeners()&&(o&&(yr(e,n).forEach(e=>{e.destroy()}),yr(n,e).forEach(e=>{e.subscribe(t=>{this.#m(e,t)})})),this.#h()))})}getCurrentResult(){return this.#t}getQueries(){return this.#i.map(e=>e.getCurrentQuery())}getObservers(){return this.#i}getOptimisticResult(e,t){let n=this.#p(e),r=n.map(e=>e.observer.getOptimisticResult(e.defaultedQueryOptions)),i=n.map(e=>e.defaultedQueryOptions.queryHash);return[r,e=>this.#d(e??r,t,i),()=>this.#u(r,n)]}#u(e,t){let n=new Set;return t.map((r,i)=>{let a=e[i];return r.defaultedQueryOptions.notifyOnChangeProps?a:r.observer.trackResult(a,e=>{n.has(e)||(n.add(e),t.forEach(t=>{t.observer.trackProp(e)}))})})}#d(e,t,n){if(t){let r=this.#c,i=n!==void 0&&r!==void 0&&(r.length!==n.length||n.some((e,t)=>e!==r[t]));return(this.#t!==this.#s||i||t!==this.#o)&&(this.#o=t,this.#s=this.#t,n!==void 0&&(this.#c=n),this.#a=Sn(this.#a,t(e))),this.#a}return e}#f(){return!this.#r?.combine||this.#i.some((e,t)=>e.options.suspense&&this.#t[t]?.data===void 0)}#p(e){let t=new Map;this.#i.forEach(e=>{let n=e.options.queryHash;if(!n)return;let r=t.get(n);r?r.push(e):t.set(n,[e])});let n=[];return e.forEach(e=>{let r=this.#e.defaultQueryOptions(e),i=t.get(r.queryHash)?.shift()??new zn(this.#e,r);n.push({defaultedQueryOptions:r,observer:i})}),n}#m(e,t){let n=this.#i.indexOf(e);n!==-1&&(this.#t=this.#t.slice(),this.#t[n]=t,this.#h())}#h(){if(this.hasListeners()){let e=this.#f(),t=this.#a,n=e?t:this.#d(this.#u(this.#t,this.#l),this.#r?.combine);(e||t!==n)&&On.batch(()=>{this.listeners.forEach(e=>{e(this.#t)})})}}},q=e(Ve(),1);function xr({queries:e,...t},n){let r=An(n),i=qn(),a=Vn(),o=t.subscribed!==!1,s=q.useMemo(()=>e.map(e=>{let t=r.defaultQueryOptions(e);return t._optimisticResults=i?`isRestoring`:o?`optimistic`:void 0,t}),[e,r,i,o]);s.forEach(e=>{Wn(e);let t=r.getQueryCache().get(e.queryHash);Un(e,a,t)}),Rn(a);let[c]=q.useState(()=>new br(r,s,t)),[l,u,d]=c.getOptimisticResult(s,t.combine),f=!i&&o;q.useSyncExternalStore(q.useCallback(e=>f?c.subscribe(On.batchCalls(e)):Tn,[c,f]),()=>c.getCurrentResult(),()=>c.getCurrentResult()),q.useEffect(()=>{c.setQueries(s,t)},[s,t,c]);let p=l.some((e,t)=>Ln(s[t],e))?l.flatMap((e,t)=>{let n=s[t];if(n&&Ln(n,e)){let e=new zn(r,n);return Bn(n,e,a)}return[]}):[];if(p.length>0)throw Promise.all(p);let m=l.find((e,t)=>{let n=s[t];return n&&Gn({result:e,errorResetBoundary:a,throwOnError:n.throwOnError,query:r.getQueryCache().get(n.queryHash),suspense:n.suspense})});if(m)throw m.error;return u(d())}var Sr=Me(`ZodMiniType`,(e,t)=>{if(!e._zod)throw Error(`Uninitialized schema in ZodMiniType.`);s.init(e,t),e.def=t,e.type=t.type,e.parse=(t,n)=>jt(e,t,n,{callee:e.parse}),e.safeParse=(t,n)=>be(e,t,n),e.parseAsync=async(t,n)=>ge(e,t,n,{callee:e.parseAsync}),e.safeParseAsync=async(t,n)=>ke(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)=>O(e,t,n),e.brand=()=>e,e.register=((t,n)=>(t.add(e,n),e)),e.apply=t=>t(e)}),Cr=Me(`ZodMiniObject`,(e,t)=>{Pt.init(e,t),Sr.init(e,t),re(e,`shape`,()=>t.shape)});function wr(e,t){return new Cr({type:`object`,shape:e??{},...fe(t)})}var Tr=Me(`ZodMiniLiteral`,(e,t)=>{we.init(e,t),Sr.init(e,t)});function Er(e,t){return new Tr({type:`literal`,values:Array.isArray(e)?e:[e],...fe(t)})}var Dr=u(`Check`,[[`path`,{d:`M20 6 9 17l-5-5`,key:`1gmf2c`}]]),Or=u(`ChevronDown`,[[`path`,{d:`m6 9 6 6 6-6`,key:`qrunsl`}]]),kr=u(`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`}]]),Ar=u(`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`}]]),jr=u(`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`}]]),Mr=u(`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=C*10,Nr=class{constructor(e={}){let t=!ut(e.bounce)||!ut(e.duration);this.timeStep=.02,this.restThreshold=5e-4,this.restDuration=200,this.maxDuration=6e4,this.maxRestSteps=this.restDuration/this.timeStep/C,this.maxIterations=this.maxDuration/this.timeStep/C,this.bn=U(H(e.bounce,.5),-1,1),this.pd=U(H(e.duration,628),10*L.timeScale,J*L.timeScale),this.m=U(H(e.mass,1),1,J),this.s=U(H(e.stiffness,100),v,J),this.d=U(H(e.damping,10),v,J),this.v=U(H(e.velocity,0),-J,J),this.w0=0,this.zeta=0,this.wd=0,this.b=0,this.completed=!1,this.solverDuration=0,this.settlingDuration=0,this.parent=null,this.onComplete=e.onComplete||Ce,t&&this.calculateSDFromBD(),this.compute(),this.ease=e=>{let t=e*this.settlingDuration,n=this.completed,r=this.pd;return t>=r&&!n&&(this.completed=!0,this.onComplete(this.parent)),t<r&&n&&(this.completed=!1),e===0||e===1?e:this.solve(e*this.solverDuration)}}solve(e){let{zeta:t,w0:n,wd:r,b:i}=this,a=e;return a=t<1?un(-a*t*n)*(1*rt(r*a)+i*m(r*a)):t===1?(1+i*a)*un(-a*n):((1+i)*un((-t*n+r)*a)+(1-i)*un((-t*n-r)*a))/2,1-a}calculateSDFromBD(){let e=L.timeScale===1?this.pd/C:this.pd;this.m=1,this.v=0,this.s=hn(2*qt/e,2),this.d=this.bn>=0?(1-this.bn)*4*qt/e:4*qt/(e*(1+this.bn)),this.s=Pe(U(this.s,v,J),3),this.d=Pe(U(this.d,v,300),3)}calculateBDFromSD(){let e=2*qt/pn(this.s);this.pd=e*(L.timeScale===1?C:1),this.bn=this.d/(2*pn(this.s))<=1?1-this.d*e/(4*qt):4*qt/(this.d*e)-1,this.bn=Pe(U(this.bn,-1,1),3),this.pd=Pe(U(this.pd,10*L.timeScale,J*L.timeScale),3)}compute(){let{maxRestSteps:e,maxIterations:t,restThreshold:n,timeStep:r,m:i,d:a,s:o,v:s}=this,c=this.w0=U(pn(o/i),v,C),l=this.zeta=a/(2*pn(o*i));l<1?(this.wd=c*pn(1-l*l),this.b=(l*c+-s)/this.wd):l===1?(this.wd=0,this.b=-s+c):(this.wd=c*pn(l*l-1),this.b=(l*c+-s)/this.wd);let u=0,d=0,f=0;for(;d<=e&&f<=t;)Rt(1-this.solve(u))<n?d++:d=0,this.solverDuration=u,u+=r,f++;this.settlingDuration=Pe(this.solverDuration*C,0)*L.timeScale}get bounce(){return this.bn}set bounce(e){this.bn=U(H(e,1),-1,1),this.calculateSDFromBD(),this.compute()}get duration(){return this.pd}set duration(e){this.pd=U(H(e,1),10*L.timeScale,J*L.timeScale),this.calculateSDFromBD(),this.compute()}get stiffness(){return this.s}set stiffness(e){this.s=U(H(e,100),v,J),this.calculateBDFromSD(),this.compute()}get damping(){return this.d}set damping(e){this.d=U(H(e,10),v,J),this.calculateBDFromSD(),this.compute()}get mass(){return this.m}set mass(e){this.m=U(H(e,1),1,J),this.compute()}get velocity(){return this.v}set velocity(e){this.v=U(H(e,0),-J,J),this.compute()}},Pr=e=>new Nr(e),Fr=(e=10,t)=>{let n=t?wt:vn;return t=>n(U(t,0,1)*e)*(1/e)},Ir=e(ee(),1),Lr={current:null};function Rr(e,t={}){let{enabled:n=!0,delay:r=0,handleClose:i=null,mouseOnly:a=!1,restMs:o=0,move:s=!0,triggerElementRef:c=Lr,externalTree:l,isActiveTrigger:u=!0,getHandleCloseContext:d,isClosing:p,shouldOpen:m,guardStaleOpen:g=!1}=t,{dataRef:_,events:v}=e.context,y=ie(l),x=Qn(e),S=q.useRef(!1),C=Dt(i),w=Dt(r),T=Dt(o),E=Dt(n),D=Dt(m),O=Dt(p),k=W(()=>Jn(_.current.openEvent?.type,x.interactedInside)),A=W(()=>D.current?.()!==!1),j=W((t,n,r)=>{let i=e.context.triggerElements;if(i.hasElement(n))return!t||!K(t,n);if(!f(r))return!1;let a=r;return i.hasMatchingElement(e=>K(e,a))&&(!t||!K(t,a))}),M=W(()=>{x.handler&&=(b(e.select(`domReferenceElement`)).removeEventListener(`mousemove`,x.handler),void 0)}),N=W(()=>{_r(x)});return u&&(x.handleCloseOptions=i?.__options),q.useEffect(()=>M,[M]),q.useEffect(()=>{if(!n)return;function e(e){e.open?S.current=!1:(S.current=e.reason===h,M(),x.openChangeTimeout.clear(),x.restTimeout.clear(),x.blockMouseMove=!0,x.restTimeoutPending=!1)}return v.on(`openchange`,e),()=>{v.off(`openchange`,e)}},[n,v,x,M]),q.useEffect(()=>{if(!n)return;function t(t,n=!0){let r=gr(w.current,`close`,x.pointerType);r?x.openChangeTimeout.start(r,()=>{e.setOpen(!1,R(h,t)),y?.events.emit(`floating.closed`,t)}):n&&(x.openChangeTimeout.clear(),e.setOpen(!1,R(h,t)),y?.events.emit(`floating.closed`,t))}let r=c.current??(u?e.select(`domReferenceElement`):null);if(!f(r))return;function i(t){if(x.openChangeTimeout.clear(),x.blockMouseMove=!1,a&&!bt(x.pointerType))return;let n=Yn(T.current),r=gr(w.current,`open`,x.pointerType),i=mt(t),o=t.currentTarget??null,s=e.select(`domReferenceElement`),c=o;if(f(i)&&!e.context.triggerElements.hasElement(i)){for(let t of e.context.triggerElements.elements())if(K(t,i)){c=t;break}}f(o)&&f(s)&&!e.context.triggerElements.hasElement(o)&&K(o,s)&&(c=s);let l=c!=null&&j(s,c,i),u=e.select(`open`),d=O.current?.()??e.select(`transitionStatus`)===`ending`,p=!u&&d&&S.current,m=!l&&f(c)&&f(s)&&K(s,c)&&p,g=n>0&&!r,_=l&&(u||p)||m,v=!u||l;if(_){A()&&e.setOpen(!0,R(h,t,c));return}g||(r?x.openChangeTimeout.start(r,()=>{v&&A()&&e.setOpen(!0,R(h,t,c))}):v&&A()&&e.setOpen(!0,R(h,t,c)))}function o(n){if(k()){N();return}M();let r=e.select(`domReferenceElement`),i=b(r);x.restTimeout.clear(),x.restTimeoutPending=!1;let a=_.current.floatingContext??d?.();if(!pt(n.relatedTarget,e.context.triggerElements)){if(C.current&&a){e.select(`open`)||x.openChangeTimeout.clear();let r=c.current;x.handler=C.current({...a,tree:y,x:n.clientX,y:n.clientY,onClose(){N(),M(),E.current&&!k()&&r===e.select(`domReferenceElement`)&&t(n,!0)}}),i.addEventListener(`mousemove`,x.handler),x.handler(n);return}(x.pointerType!==`touch`||!K(e.select(`floatingElement`),n.relatedTarget))&&t(n)}}function l(e){K(r,e.relatedTarget)||(x.openChangeTimeout.clear(),x.restTimeout.clear(),x.restTimeoutPending=!1)}let p=g?Gt(r,`mouseout`,l):void 0;return s?st(Gt(r,`mousemove`,i,{once:!0}),Gt(r,`mouseenter`,i),Gt(r,`mouseleave`,o),p):st(Gt(r,`mouseenter`,i),Gt(r,`mouseleave`,o),p)},[M,N,_,w,e,n,C,x,u,j,k,a,s,T,c,y,E,d,O,A,g]),q.useMemo(()=>{if(!n)return;function t(e){x.pointerType=e.pointerType}return{onPointerDown:t,onPointerEnter:t,onMouseMove(t){let{nativeEvent:n}=t,r=t.currentTarget,i=e.select(`domReferenceElement`),o=e.select(`open`),s=j(i,r,t.target);if(a&&!bt(x.pointerType))return;if(o&&s&&x.handleCloseOptions?.blockPointerEvents){let t=e.select(`floatingElement`);if(t){let e=x.handleCloseOptions?.getScope?.()??r.ownerDocument.body;mr(x,{scopeElement:e,referenceElement:r,floatingElement:t})}}let c=Yn(T.current);if(o&&!s||c===0||!s&&x.restTimeoutPending&&t.movementX**2+t.movementY**2<2)return;x.restTimeout.clear();function l(){if(x.restTimeoutPending=!1,k())return;let t=e.select(`open`);!x.blockMouseMove&&(!t||s)&&A()&&e.setOpen(!0,R(h,n,r))}x.pointerType===`touch`?Ir.flushSync(()=>{l()}):s&&o?l():(x.restTimeoutPending=!0,x.restTimeout.start(c,l))}}},[n,x,k,j,a,e,T,A])}var zr=.1,Br=zr*zr,Y=.5;function Vr(e,t,n,r,i,a){return r>=t!=a>=t&&e<=(i-n)*(t-r)/(a-r)+n}function Hr(e,t,n,r,i,a,o,s,c,l){let u=!1;return Vr(e,t,n,r,i,a)&&(u=!u),Vr(e,t,i,a,o,s)&&(u=!u),Vr(e,t,o,s,c,l)&&(u=!u),Vr(e,t,c,l,n,r)&&(u=!u),u}function Ur(e,t,n){return e>=n.x&&e<=n.x+n.width&&t>=n.y&&t<=n.y+n.height}function Wr(e,t,n,r,i,a){return e>=Math.min(n,i)&&e<=Math.max(n,i)&&t>=Math.min(r,a)&&t<=Math.max(r,a)}function Gr(e={}){let{blockPointerEvents:t=!1}=e,n=new Jt,r=({x:e,y:t,placement:r,elements:i,onClose:a,nodeId:o,tree:s})=>{let c=r?.split(`-`)[0],l=!1,u=null,d=null,p=typeof performance<`u`?performance.now():0;function m(e,t){let n=performance.now(),r=n-p;if(u===null||d===null||r===0)return u=e,d=t,p=n,!1;let i=e-u,a=t-d,o=i*i+a*a,s=r*r*Br;return u=e,d=t,p=n,o<s}function h(){n.clear(),a()}return function(r){n.clear();let a=i.domReference,u=i.floating;if(!a||!u||c==null||e==null||t==null)return;let{clientX:d,clientY:p}=r,g=mt(r),_=r.type===`mouseleave`,v=K(u,g),y=K(a,g);if(v&&(l=!0,!_))return;if(y&&(l=!1,!_)){l=!0;return}if(_&&f(r.relatedTarget)&&K(u,r.relatedTarget))return;function b(){return!!(s&&_t(s.nodesRef.current,o).length>0)}function x(){b()||h()}if(b())return;let S=a.getBoundingClientRect(),C=u.getBoundingClientRect(),w=e>C.right-C.width/2,T=t>C.bottom-C.height/2,E=C.width>S.width,D=C.height>S.height,O=(E?S:C).left,k=(E?S:C).right,A=(D?S:C).top,j=(D?S:C).bottom;if(c===`top`&&t>=S.bottom-1||c===`bottom`&&t<=S.top+1||c===`left`&&e>=S.right-1||c===`right`&&e<=S.left+1){x();return}let M=!1;switch(c){case`top`:M=Wr(d,p,O,S.top+1,k,C.bottom-1);break;case`bottom`:M=Wr(d,p,O,C.top+1,k,S.bottom-1);break;case`left`:M=Wr(d,p,C.right-1,j,S.left+1,A);break;case`right`:M=Wr(d,p,S.right-1,j,C.left+1,A)}if(M)return;if(l&&!Ur(d,p,S)){x();return}if(!_&&m(d,p)){x();return}let N=!1;switch(c){case`top`:{let n=E?Y/2:Y*4,r=E||w?e+n:e-n,i=E?e-n:w?e+n:e-n,a=t+Y+1,o=w||E?C.bottom-Y:C.top,s=w?E?C.bottom-Y:C.top:C.bottom-Y;N=Hr(d,p,r,a,i,a,C.left,o,C.right,s);break}case`bottom`:{let n=E?Y/2:Y*4,r=E||w?e+n:e-n,i=E?e-n:w?e+n:e-n,a=t-Y,o=w||E?C.top+Y:C.bottom,s=w?E?C.top+Y:C.bottom:C.top+Y;N=Hr(d,p,r,a,i,a,C.left,o,C.right,s);break}case`left`:{let n=D?Y/2:Y*4,r=D||T?t+n:t-n,i=D?t-n:T?t+n:t-n,a=e+Y+1,o=T||D?C.right-Y:C.left,s=T?D?C.right-Y:C.left:C.right-Y;N=Hr(d,p,o,C.top,s,C.bottom,a,r,a,i);break}case`right`:{let n=D?Y/2:Y*4,r=D||T?t+n:t-n,i=D?t-n:T?t+n:t-n,a=e-Y,o=T||D?C.left+Y:C.right,s=T?D?C.left+Y:C.right:C.left+Y;N=Hr(d,p,a,r,a,i,o,C.top,s,C.bottom);break}}N?l||n.start(40,x):x()}};return r.__options={...e,blockPointerEvents:t},r}function Kr(e,t,n){return`${e.endsWith(`/`)?e:`${e}/`}${t}${n===`directory`?`/`:``}`}function qr(e,t,n){let r=t.entries.filter(e=>e.type!==`symlink`).map(e=>Kr(t.path,e.name,e.type)),i=r.filter(e=>!n.has(e));if(i.length>0){let t=i.map(e=>({type:`add`,path:e}));e.batch(t)}n.add(t.path);for(let e of r)n.add(e);return i}function Jr(e,t){let n=t===`/`?`/`:t.replace(/\/+$/,``);if(n!==`/`&&e!==n&&!e.startsWith(`${n}/`))return[];let r=n===`/`?e.split(`/`).filter(Boolean):e.slice(n.length).split(`/`).filter(Boolean),i=[n],a=n;for(let e of r.slice(0,-1))a=`${a===`/`?``:a}/${e}`,i.push(a);return i}function Yr({app:e,rootPath:t,rootLabel:n=`Computer`,activePath:r,onOpenFile:i,onSelectPath:a}){let o=An(),s=In(e),c=(0,q.useCallback)(t=>e.capabilities.subscribe(t),[e]),l=(0,q.useCallback)(()=>e.capabilities.version,[e]),u=(0,q.useSyncExternalStore)(c,l,l),d=(0,q.useMemo)(()=>({app:e,rootPath:t,computerId:s,version:u}),[e,t,s,u]),[f,p]=(0,q.useState)(null),m=f?.scope===d?f:null,h=r?Jr(r,t):[],g=m?.activePath===r?m.path:h.at(-1)??t,_=new Map;for(let e of[t,...h])_.set(`${e}:0`,{path:e,offset:0});for(let e of m?.pages??[])_.set(`${e.path}:${String(e.offset)}`,e);let v=[..._.values()],y=(t,n)=>Dn.of(e,`tree`,u,t,n),b=xr({queries:v.map(({path:t,offset:n})=>jn(e,Nn,y(t,n),async(e,r)=>{let i=await e.list({path:t,offset:n,limit:256});return r.throwIfAborted(),i})),combine:e=>({listings:e.flatMap((e,t)=>e.data?[{request:v[t],listing:e.data}]:[]),busy:e.some(e=>e.isFetching),failure:e.find(e=>e.error)?.error??null})}),x=(0,q.useRef)({activePath:r,onOpenFile:i,onSelectPath:a,rootLabel:n});x.current={activePath:r,onOpenFile:i,onSelectPath:a,rootLabel:n};let S=(e,t)=>{let n=e.replace(/\/+$/,``)||`/`,i=y(n,t);o.getQueryState(i)?.status===`error`&&o.invalidateQueries({queryKey:i,exact:!0}),p(e=>({scope:d,activePath:r,path:n,pages:[...e?.scope===d?e.pages.filter(e=>e.path!==n||e.offset!==t):[],{path:n,offset:t}]}))},C=(0,q.useRef)(S);C.current=S;let{model:w}=Kn({paths:[],itemHeight:32,initialExpansion:1,composition:{contextMenu:{enabled:!0}},renderRowDecoration:({row:e})=>e.path===`/`?{text:x.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&&(x.current.onSelectPath?.(t),t.endsWith(`/`)?C.current(t,0):t!==x.current.activePath&&x.current.onOpenFile(t))}}),T=(0,q.useRef)(new Set),E=(0,q.useRef)(new Map),D=(0,q.useRef)(null);(0,q.useLayoutEffect)(()=>{T.current.clear(),E.current.clear(),w.resetPaths([]),D.current=null},[w,d]),(0,q.useLayoutEffect)(()=>{D.current=null;for(let e of w.getSelectedPaths())!e.endsWith(`/`)&&e!==r&&w.getItem(e)?.deselect()},[r,w]),(0,q.useLayoutEffect)(()=>{b.listings.length===0&&(T.current.clear(),E.current.clear(),w.resetPaths([]),D.current=null);for(let{request:e,listing:t}of b.listings){let n=`${e.path}:${String(e.offset)}`,r=t.entries.filter(e=>e.type!==`symlink`).map(e=>Kr(t.path,e.name,e.type)),i=E.current.get(n)??[];E.current.set(n,r);let a=new Set([...E.current.values()].flat());for(let e of i)if(!a.has(e)){w.getItem(e)&&w.remove(e,{recursive:!0});for(let t of T.current)(t===e||e.endsWith(`/`)&&t.startsWith(e))&&T.current.delete(t)}qr(w,t,T.current)}if(!r||D.current===r)return;let e=Jr(r,t);if(!e.every(e=>T.current.has(e)))return;for(let t of e){let e=w.getItem(t);e&&`expand`in e&&e.expand()}let n=w.getItem(r);n&&(D.current=r,n.select(),w.scrollToPath(r,{focus:!1}))},[r,w,t,d,b.listings]),(0,q.useEffect)(()=>{b.failure&&console.error(`Inkcap directory listing failed`,xn(b.failure))},[b.failure]);let O=b.listings.filter(({request:e})=>e.path===g).sort((e,t)=>e.request.offset-t.request.offset).at(-1)?.listing,k={path:O?.path??g,next:O?.nextOffset??null},A=b.listings.some(({request:e,listing:n})=>e.path===t&&e.offset===0&&n.entries.length===0&&n.nextOffset===null);return{model:w,page:k,error:b.failure?`Could not list this directory. Existing files remain available.`:``,busy:b.busy,rootEmpty:A,reloadRoot:()=>{o.invalidateQueries({queryKey:Dn.of(e,`tree`,u)})},loadNext:()=>{k.next!==null&&S(k.path,k.next)}}}var Xr=B(I),Zr=B(r({message:I}));function Qr(e){for(let t of e.errors){let e=Be(A(Le(Zr(t),e=>e.message),()=>Xr(t)));if(e!==void 0&&e.length>0)return e}}var X=Object.freeze({ease:`linear`,duration:0});function $r(e,t){let n=ye(e,t.duration);return n<=0?X:e.steps>0?{ease:Fr(e.steps),duration:n}:{ease:Pr({bounce:At(e,t.bounce),duration:n}),duration:n}}function Z(e,t){let n=Oe(e,t.duration);return{ease:e.steps>0?Fr(e.steps):t.ease,duration:n}}var Q=d(),ei={dot:{y:-4,height:8,cy:0},pill:{y:-16,height:32,cy:0},bang:{y:-16,height:20,cy:12}};function ti({className:e,glyph:t,motion:n}){let r=`caps-status-${(0,q.useId)().replaceAll(`:`,``)}`,i=(0,q.useRef)(null),a=(0,q.useRef)(null),o=(0,q.useRef)(null),s=(0,q.useRef)(null),c=(0,q.useRef)(null),l=(0,q.useRef)(null),u=(0,q.useRef)(ei[t]).current,d=(0,q.useRef)(t===`dot`?1:4).current,f=(0,q.useRef)(+(t===`bang`)).current,p=(0,q.useRef)(t),m=ne(s),{reduced:h}=m;return(0,q.useLayoutEffect)(()=>{if(!i.current||!a.current||!c.current||!l.current)return;let e=ei[t],n=h||p.current===t;p.current=t;let r=D(i.current),o=n?{duration:0}:$r(r,{bounce:.3,duration:360}),s=V(i.current,{y:e.y,height:e.height,...o}),u=V(a.current,{cy:e.cy,...n?{duration:0}:{delay:Oe(r,35),...$r(r,{bounce:.3,duration:420})}}),d=V(c.current,{gradientTransform:`matrix(1 0 0 ${t===`dot`?`1`:`4`} 0 0)`,...o}),f=V(l.current,{opacity:+(t===`bang`),...n?X:Z(r,{ease:`inOutSine`,duration:220})});return()=>{s.cancel(),u.cancel(),d.cancel(),f.cancel()}},[t,h]),(0,q.useLayoutEffect)(()=>{if(!o.current||!s.current||h||n===`none`)return;let e=n===`pulse`?V(o.current,{opacity:[1,.45],...Z(m,{ease:`inOutSine`,duration:750}),alternate:!0,loop:!0}):V(o.current,{keyframes:{"0%":{translateY:0,scaleX:1,scaleY:1},"18%":{translateY:.25,scaleX:1.1,scaleY:.91},"42%":{translateY:-1.3,scaleX:.94,scaleY:1.06},"62%":{translateY:-1.65,scaleX:1,scaleY:1},"82%":{translateY:.15,scaleX:1.06,scaleY:.95},"100%":{translateY:0,scaleX:1,scaleY:1}},...Z(m,{ease:`inOutSine`,duration:1e3}),loop:!0}),t=at(s.current,t=>{t?e.resume():e.pause()});return()=>{t(),e.revert()}},[n,h,m]),(0,Q.jsxs)(`svg`,{ref:s,"aria-hidden":`true`,className:`caps-status-bead ${e??``}`,width:`8`,height:`8`,viewBox:`-4 -4 8 8`,focusable:`false`,children:[(0,Q.jsxs)(`defs`,{children:[(0,Q.jsx)(Wt,{id:r,values:cn}),(0,Q.jsx)(It,{ref:c,id:`${r}-surface`,transform:`matrix(1 0 0 ${String(d)} 0 0)`}),(0,Q.jsxs)(`radialGradient`,{id:`${r}-drop-light`,gradientUnits:`userSpaceOnUse`,cx:`-1.2`,cy:`10.4`,r:`5.6`,children:[(0,Q.jsx)(`stop`,{offset:`0`,stopColor:`var(--color-white)`,style:{stopOpacity:`calc(var(--depth) * 0.5)`}}),(0,Q.jsx)(`stop`,{offset:`1`,stopColor:`var(--color-white)`,stopOpacity:`0`})]}),(0,Q.jsx)(ft,{id:`${r}-shadow`}),(0,Q.jsx)(`mask`,{id:`${r}-silhouette`,maskUnits:`userSpaceOnUse`,x:`-12`,y:`-24`,width:`24`,height:`48`,style:{maskType:`alpha`},children:(0,Q.jsxs)(`g`,{fill:`var(--color-white)`,filter:`url(#${r})`,children:[(0,Q.jsx)(`rect`,{ref:i,x:`-4`,y:u.y,width:`8`,height:u.height,rx:`4`}),(0,Q.jsx)(`circle`,{ref:a,cx:`0`,cy:u.cy,r:`4`})]})})]}),(0,Q.jsx)(`g`,{ref:o,filter:`url(#${r}-shadow)`,children:(0,Q.jsxs)(`g`,{mask:`url(#${r}-silhouette)`,children:[(0,Q.jsx)(`rect`,{x:`-12`,y:`-24`,width:`24`,height:`48`,fill:`url(#${r}-surface)`}),(0,Q.jsx)(`rect`,{ref:l,x:`-12`,y:`-24`,width:`24`,height:`48`,fill:`url(#${r}-drop-light)`,opacity:f})]})})]})}var ni=.28;function ri(e,t){switch(e){case`ring`:return{dashes:1,track:0,arc:0,sweep:0,disc:0,tick:0,cross:0};case`arc`:return{dashes:0,track:1,arc:1,sweep:t===void 0?ni:Math.min(1,Math.max(0,t)),disc:0,tick:0,cross:0};case`check`:return{dashes:0,track:0,arc:1,sweep:1,disc:1,tick:1,cross:0};case`cross`:return{dashes:0,track:0,arc:1,sweep:1,disc:1,tick:0,cross:1}}}var ii=7.25;function ai({className:e,glyph:t,progress:n}){let r=`caps-status-mark-${(0,q.useId)().replaceAll(`:`,``)}`,i=(0,q.useRef)(null),a=(0,q.useRef)(null),o=(0,q.useRef)(null),s=(0,q.useRef)(null),c=(0,q.useRef)(null),l=(0,q.useRef)(null),u=(0,q.useRef)(null),d=(0,q.useRef)(null),f=(0,q.useRef)(ri(t,n)).current,p=(0,q.useRef)(t),m=de();(0,q.useLayoutEffect)(()=>{let e=i.current,r=a.current,c=o.current,f=s.current,h=l.current,g=u.current,_=d.current;if(!e||!r||!c||!f||!h||!g||!_)return;let v=ri(t,n),y=p.current;p.current=t;let b=D(e),x=m||y===t&&t!==`arc`,S=x?m?{ease:b.ease,duration:b.fast}:X:Z(b,{ease:`outQuad`,duration:160}),C=(t===`check`||t===`cross`)&&!x,w=Z(b,{ease:`inOutSine`,duration:220}),T=[V(r,{opacity:v.dashes,...S}),V(c,{opacity:v.track*.28,...S}),V(f,{opacity:v.arc,"stroke-dasharray":`${String(v.sweep)} 1`,...x?m?X:S:w}),V(h,{r:v.disc*ii,...C?{delay:w.duration*.7,...$r(b,{bounce:.35,duration:360})}:m?X:Z(b,{ease:`inCubic`,duration:140})}),V(g,{"stroke-dashoffset":1-v.tick,...C&&v.tick>0?{delay:w.duration*.7+b.fast,...Z(b,{ease:`outCubic`,duration:240})}:X}),V(_,{"stroke-dashoffset":1-v.cross,...C&&v.cross>0?{delay:w.duration*.7+b.fast,...Z(b,{ease:`outCubic`,duration:240})}:X})];return t===`cross`&&C&&b.shake>0&&T.push(V(e,{translateX:[0,-b.shake,b.shake,-b.shake/2,0],delay:w.duration+b.fast,...Z(b,{ease:`linear`,duration:300})})),()=>{for(let e of T)e.cancel()}},[t,n,m]);let h=t===`arc`&&n===void 0&&!m;return(0,q.useLayoutEffect)(()=>{if(!h||!c.current||!i.current)return;let e=D(i.current),t=V(c.current,{rotate:[0,360],...Z(e,{ease:`linear`,duration:900}),loop:!0}),n=at(i.current,e=>{e?t.resume():t.pause()});return()=>{n(),t.revert()}},[h]),(0,Q.jsxs)(`svg`,{ref:i,"aria-hidden":`true`,className:`caps-status-mark ${e??``}`,viewBox:`0 0 16 16`,focusable:`false`,children:[(0,Q.jsxs)(`defs`,{children:[(0,Q.jsx)(It,{id:`${r}-surface`,transform:`matrix(1.6 0 0 1.6 8 8)`}),(0,Q.jsxs)(`mask`,{id:`${r}-knock`,maskUnits:`userSpaceOnUse`,x:`0`,y:`0`,width:`16`,height:`16`,children:[(0,Q.jsx)(`rect`,{width:`16`,height:`16`,fill:`var(--color-white)`}),(0,Q.jsx)(`path`,{ref:u,d:`M4.9 8.3 7.1 10.5 11.2 5.9`,fill:`none`,stroke:`var(--color-black)`,strokeWidth:`1.9`,strokeLinecap:`round`,strokeLinejoin:`round`,pathLength:1,strokeDasharray:`1 1`,strokeDashoffset:1-f.tick}),(0,Q.jsx)(`path`,{ref:d,d:`M5.4 5.4 10.6 10.6 M10.6 5.4 5.4 10.6`,fill:`none`,stroke:`var(--color-black)`,strokeWidth:`1.9`,strokeLinecap:`round`,pathLength:1,strokeDasharray:`1 1`,strokeDashoffset:1-f.cross})]})]}),(0,Q.jsx)(`circle`,{ref:a,cx:`8`,cy:`8`,r:`6.25`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.5`,strokeDasharray:`1.7 2.2`,opacity:f.dashes}),(0,Q.jsx)(`circle`,{ref:o,cx:`8`,cy:`8`,r:`6.25`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.5`,opacity:f.track*.28}),(0,Q.jsx)(`g`,{ref:c,className:`caps-status-mark-spin`,children:(0,Q.jsx)(`circle`,{ref:s,cx:`8`,cy:`8`,r:`6.25`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`,pathLength:1,strokeDasharray:`${String(f.sweep)} 1`,transform:`rotate(-90 8 8)`,opacity:f.arc})}),(0,Q.jsx)(`circle`,{ref:l,cx:`8`,cy:`8`,r:f.disc*ii,fill:`url(#${r}-surface)`,mask:`url(#${r}-knock)`})]})}var oi=new Set([`ring`,`arc`,`check`,`cross`]);function si(e){return oi.has(e)}var ci={neutral:`text-base-content`,primary:`text-primary`,secondary:`text-secondary`,accent:`text-accent`,success:`text-success`,info:`text-info`,warning:`text-warning`,error:`text-error`},li=(0,q.forwardRef)(function({className:e,label:t,glyph:n=`dot`,motion:r=`none`,tone:i=`neutral`,size:a=`default`,appearance:o=`plain`,progress:s,...c},l){return(0,Q.jsxs)(`span`,{...c,className:z(`caps-status`,a===`compact`&&`caps-status-compact`,o===`chip`&&`caps-status-chip`,e),"data-tone":o===`chip`?i:void 0,"data-glyph":n,"data-motion":r,ref:l,children:[si(n)?(0,Q.jsx)(ai,{className:ci[i],glyph:n,progress:s}):(0,Q.jsx)(ti,{className:ci[i],glyph:n,motion:r}),t===void 0?null:(0,Q.jsx)(`span`,{children:t})]})}),ui={neutral:`progress-neutral`,primary:`progress-primary`,secondary:`progress-secondary`,accent:`progress-accent`,success:`progress-success`,info:`progress-info`,warning:`progress-warning`,error:`progress-error`},di=(0,q.forwardRef)(function({className:e,tone:t=`primary`,...n},r){return(0,Q.jsx)(`progress`,{...n,"data-complete":n.value!==void 0&&Number(n.value)>=Number(n.max??1)?`true`:void 0,className:z(`progress caps-gooey-motion caps-gooey-progress w-full`,ui[t],e),ref:r})});(0,q.forwardRef)(function({label:e,value:t,max:n,tone:r=`info`,className:i,...a},o){return(0,Q.jsxs)(`div`,{...a,ref:o,className:z(`caps-game-meter`,i),children:[(0,Q.jsxs)(`div`,{className:`caps-game-meter-readout`,children:[(0,Q.jsx)(`span`,{children:e}),(0,Q.jsxs)(`span`,{className:`caps-game-meter-value`,children:[t,` / `,n]})]}),(0,Q.jsx)(di,{"aria-label":e,value:t,max:n,tone:r})]})});function fi({className:e,items:t,onCancel:n,onRemove:r,onRetry:i,rowClassName:a}){return t.length?(0,Q.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,Q.jsx)(hi,{item:e,onCancel:n,onRemove:r,onRetry:i,...a===void 0?{}:{rowClassName:a}},e.id))}):null}function pi({action:e,id:t,onAction:n,retry:r=!1}){return e?(0,Q.jsx)(Bt,{"aria-label":e.accessibleLabel,title:e.label,variant:`ghost`,size:`xs`,className:`motion-reduce:transition-none`,icon:r?(0,Q.jsx)(Mr,{}):(0,Q.jsx)(bn,{}),onClick:()=>void n(t),type:`button`}):null}function mi({item:e}){return(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`span`,{className:`block min-w-0 truncate`,title:e.name,children:e.name}),(0,Q.jsx)(`div`,{className:`caps-upload-details`,children:(0,Q.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 hi({item:e,onCancel:t,onRemove:n,onRetry:r,rowClassName:i}){return(0,Q.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,Q.jsx)(`img`,{alt:``,className:`caps-upload-preview mask mask-squircle size-8 shrink-0 object-cover`,src:e.preview.url}):(0,Q.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,Q.jsx)(Ar,{className:`size-4`})}),(0,Q.jsx)(mi,{item:e}),(0,Q.jsx)(gi,{actions:e.actions,id:e.id,onCancel:t,onRemove:n,onRetry:r}),(0,Q.jsx)(di,{"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 gi({actions:e,id:t,onCancel:n,onRemove:r,onRetry:i}){return(0,Q.jsxs)(`div`,{className:`caps-upload-actions flex min-w-0 flex-wrap justify-end gap-xs`,children:[(0,Q.jsx)(pi,{action:e.retry,id:t,onAction:i,retry:!0}),(0,Q.jsx)(pi,{action:e.cancel,id:t,onAction:n}),(0,Q.jsx)(pi,{action:e.remove,id:t,onAction:r})]})}var _i={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`},vi={blurStdDeviation:.22,alphaSlope:18,alphaIntercept:-8};function yi({state:e}){let t=`caps-checkbox-${(0,q.useId)().replaceAll(`:`,``)}`,n=(0,q.useRef)(null),r=(0,q.useRef)(e).current,i=(0,q.useRef)(e),a=de();return(0,q.useLayoutEffect)(()=>{if(!n.current)return;let t=e!==`unchecked`,r=i.current!==`unchecked`,o=a||i.current===e;i.current=e;let s=D(n.current),c=Z(s,{ease:`inCubic`,duration:160}),l=V(n.current,{d:{to:_i[e],...o?X:Z(s,{ease:`outCubic`,duration:200})},"stroke-dashoffset":{to:+!t,...o?X:t?Z(s,{ease:`inOutSine`,duration:260}):c},"stroke-width":o?{to:t?2.4:0,duration:0}:t&&!r?[{to:2.2,...Z(s,{ease:`outCubic`,duration:65})},{to:2.4,delay:Oe(s,120),...$r(s,{bounce:.35,duration:220})}]:{to:t?2.4:0,...c}});return()=>{l.cancel()}},[e,a]),(0,Q.jsxs)(`svg`,{className:`caps-checkbox-visual`,width:`24`,height:`24`,viewBox:`0 0 12 12`,"aria-hidden":`true`,focusable:`false`,children:[(0,Q.jsxs)(`defs`,{children:[(0,Q.jsx)(It,{id:`${t}-surface`,transform:`matrix(1 0 0 1 6 6)`}),(0,Q.jsx)(ft,{id:`${t}-shadow`}),(0,Q.jsx)(tn,{id:`${t}-inset`}),(0,Q.jsx)(Wt,{id:`${t}-goo`,values:vi}),(0,Q.jsxs)(`filter`,{id:`${t}-relief`,x:`-25%`,y:`-25%`,width:`150%`,height:`150%`,colorInterpolationFilters:`sRGB`,children:[(0,Q.jsx)(`feGaussianBlur`,{in:`SourceAlpha`,stdDeviation:`0.28`,result:`relief`}),(0,Q.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,Q.jsx)(`feDistantLight`,{azimuth:`225`,elevation:`55`})}),(0,Q.jsx)(`feComposite`,{in:`light`,in2:`SourceAlpha`,operator:`in`,result:`clipped-light`}),(0,Q.jsx)(`feBlend`,{in:`SourceGraphic`,in2:`clipped-light`,mode:`screen`})]}),(0,Q.jsx)(`mask`,{id:`${t}-contour`,maskUnits:`userSpaceOnUse`,x:`0`,y:`0`,width:`12`,height:`12`,style:{maskType:`alpha`},children:(0,Q.jsx)(`path`,{ref:n,d:_i[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,Q.jsx)(`clipPath`,{id:`${t}-well`,children:(0,Q.jsx)(`rect`,{x:`1`,y:`1`,width:`10`,height:`10`,rx:`2.5`})})]}),(0,Q.jsx)(`rect`,{className:`caps-checkbox-track`,x:`0.5`,y:`0.5`,width:`11`,height:`11`,rx:`3`,filter:`url(#${t}-inset)`}),(0,Q.jsx)(`g`,{clipPath:`url(#${t}-well)`,children:(0,Q.jsx)(`g`,{filter:`url(#${t}-shadow)`,children:(0,Q.jsx)(`g`,{filter:`url(#${t}-relief)`,children:(0,Q.jsx)(`g`,{mask:`url(#${t}-contour)`,children:(0,Q.jsx)(`rect`,{x:`0`,y:`0`,width:`12`,height:`12`,fill:`url(#${t}-surface)`})})})})})]})}var bi=(0,q.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,q.useRef)(null),[d,f]=(0,q.useState)(o),p=a??d,m=i?`mixed`:p?`checked`:`unchecked`;return(0,q.useImperativeHandle)(l,()=>{if(!u.current)throw Error(`Checkbox input is not mounted`);return u.current},[]),(0,q.useLayoutEffect)(()=>{u.current&&(u.current.indeterminate=i)},[i]),(0,q.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,Q.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,Q.jsx)(`input`,{...c,checked:p,"aria-checked":i?`mixed`:p,"aria-invalid":r?!0:c[`aria-invalid`]===!1?void 0:c[`aria-invalid`],className:z(`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,Q.jsx)(yi,{state:m}):n]})}),xi=wr({keyCode:Er(229)});function Si(e){return e.nativeEvent.isComposing||be(xi,e.nativeEvent).success}var Ci=q.createContext(void 0);function wi(e){let t=q.useContext(Ci);if(t===void 0&&!e)throw Error(rn(47));return t}var Ti={...mn,disabled:e=>e.disabled,instantType:e=>e.instantType===`trigger-change`&&!mn.open(e)?void 0:e.instantType,openMethod:e=>e.openMethod,openChangeReason:e=>e.openChangeReason,isPressOpenedByTrigger:(e,t)=>e.openChangeReason===`trigger-press`&&mn.isOpenedByTrigger(e,t),isTouchPressOpen:(e,t)=>t&&e.openMethod===`touch`&&e.openChangeReason===`trigger-press`,hasTriggerFocusGuards:(e,t)=>mn.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},Ei=class extends Ne{constructor(e,t,n){let r=new x;super(Di(e,r,t,n),Oi(r),Ti)}setOpen=(e,t)=>{let n=t.reason===h,r=t.reason===`trigger-press`&&t.event.detail===0,a=!e&&(t.reason===`escape-key`||t.reason==null),o=i(t),s=this.select(`activeTriggerId`);if(!e&&t.reason===`close-press`&&t.trigger==null&&s!=null&&(t.trigger=this.context.triggerElements.getById(s)??this.select(`activeTriggerElement`)??void 0),this.context.onOpenChange?.(e,t),t.isCanceled)return;this.state.floatingRootContext.dispatchOpenChange(e,t);let c=()=>{let n=pe(this.state,e,t.trigger,o());n.openChangeReason=t.reason,this.update(n)};n?(this.context.stickIfOpen=!0,this.context.stickIfOpenTimeout.start(500,()=>{this.context.stickIfOpen=!1}),Ir.flushSync(c)):c();let l;r?l=`click`:a?l=`dismiss`:t.reason===`focus-out`&&(l=`focus`),this.set(`instantType`,l)}};function Di(e,t,n,r=!1){let i={...ct(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 Oi(e){return{popupRef:q.createRef(),onOpenChange:void 0,onOpenChangeComplete:void 0,triggerFocusTargetRef:q.createRef(),beforeTriggerFocusGuardRef:q.createRef(),beforeContentFocusGuardRef:q.createRef(),stickIfOpenTimeout:new Jt,stickIfOpen:!0,triggerElements:e}}var ki=p(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=ji(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),le(u,d),_e(u);let{forceUnmount:m}=Ee(d,u,()=>{u.context.stickIfOpen=!0,u.set(`openChangeReason`,null)});u.useSyncedValues({modal:o}),q.useEffect(()=>{d||u.context.stickIfOpenTimeout.clear()},[u,d]),q.useImperativeHandle(e.actionsRef,()=>({unmount:m,close:()=>u.setOpen(!1,R(gn))}),[m,u]);let h=d||f||s!=null;return(0,Q.jsxs)(Ci.Provider,{value:u,children:[s&&(0,Q.jsx)(xe,{handle:s,store:u}),h&&(0,Q.jsx)(Mi,{store:u,modal:o}),typeof t==`function`?t({payload:p}):t]})});function Ai(e){return wi(!0)?(0,Q.jsx)(ki,{props:e}):(0,Q.jsx)(k,{children:(0,Q.jsx)(ki,{props:e})})}function ji(e,t){let n=F((e,n)=>new Ei(t,e,n));return q.useEffect(()=>n.context.stickIfOpenTimeout.disposeEffect(),[n]),n}function Mi({store:e,modal:t}){let n=e.useState(`floatingRootContext`),r=ze(n,{outsidePressEvent:{mouse:t===`trap-focus`?`sloppy`:`intentional`,touch:`sloppy`}}),i=r.reference,a=r.floating;return T(e,{activeTriggerProps:i,inactiveTriggerProps:i,popupProps:a}),null}function Ni(e,t){function n(n,r,i){let a=n.currentTarget;Ir.flushSync(()=>{e.setOpen(!1,R(dt,n.nativeEvent,a))}),on(a.isConnected?a:t.current,r,i)?.focus()}function r(t){n(t,-1,e.select(`positionerElement`))}function i(t){let r=e.select(`positionerElement`);r&&Ht(t,r)?e.context.beforeContentFocusGuardRef.current?.focus():n(t,1,r)}return{handlePreFocusGuardFocus:r,handleFocusTargetFocus:i}}var Pi=dn(function(e,t){let{render:n,className:r,style:i,disabled:a=!1,nativeButton:o=!0,handle:s,payload:c,openOnHover:l=!1,delay:u=300,closeDelay:d=0,id:f,...p}=e,m=wi(!0),h=_n(s)??m;if(!h)throw Error(rn(74));let g=St(f),_=h.useState(`isTriggerActive`,g),v=h.useState(`floatingRootContext`),y=h.useState(`isOpenedByTrigger`,g),b=h.useState(`triggerPopupId`,g),x=q.useRef(null),{registerTrigger:S,isMountedByThisTrigger:C}=je(g,x,h,{payload:c,disabled:a,openOnHover:l,closeDelay:d}),T=h.useState(`isPressOpenedByTrigger`,g),E=h.useState(`isTouchPressOpen`,l),D=h.useState(`hasTriggerFocusGuards`,g),O=Rr(v,{enabled:!a&&l&&!E,mouseOnly:!0,move:!1,handleClose:Gr(),restMs:u,delay:{close:d},triggerElementRef:x,isActiveTrigger:_,isClosing:()=>h.select(`transitionStatus`)===`ending`}),k=W(()=>h.context.stickIfOpen),A=M(v,{stickIfOpen:k}),j=Lt(()=>h.select(`open`),e=>{h.set(`openMethod`,e)}),N=h.useState(`triggerProps`,C),{getButtonProps:ee,buttonRef:P}=w({disabled:a,native:o}),F={open(e){return T?Ze.open(e):qe.open(e)}},{handlePreFocusGuardFocus:te,handleFocusTargetFocus:ne}=Ni(h,x),re=tt(`button`,e,{state:{disabled:a,open:y},ref:[P,t,S,x],props:[A.reference,O,N,j,{[Qe]:``,id:g,"aria-haspopup":`dialog`,"aria-expanded":y,"aria-controls":b},p,ee],stateAttributesMapping:F}),ie=(0,Q.jsx)(q.Fragment,{children:re},g);return D?(0,Q.jsxs)(q.Fragment,{children:[(0,Q.jsx)($t,{ref:h.context.beforeTriggerFocusGuardRef,onFocus:te}),ie,(0,Q.jsx)($t,{ref:h.context.triggerFocusTargetRef,onFocus:ne})]}):ie}),Fi=q.createContext(void 0);function Ii(){let e=q.useContext(Fi);if(e===void 0)throw Error(rn(45));return e}var Li=q.forwardRef(function(e,t){let{keepMounted:n=!1,...r}=e;return wi().useState(`mounted`)||n?(0,Q.jsx)(Fi.Provider,{value:n,children:(0,Q.jsx)(Je,{ref:t,...r})}):null}),Ri=q.createContext(void 0);function zi(){let e=q.useContext(Ri);if(!e)throw Error(rn(46));return e}function Bi(e){let{store:t,domReference:n,positionerElement:r,open:i}=e,a=q.useRef(null),o=q.useRef(null),s=c(r);Te(()=>{i||(o.current?.abort(),o.current=null,t.state.instantType===`trigger-change`&&t.set(`instantType`,void 0))},[i,t]),Te(()=>{let e=n,r=a.current;if(e&&(a.current=e),!r||!e||e===r||!t.select(`open`))return;t.set(`instantType`,void 0);let i=new AbortController;return o.current=i,s(()=>{t.select(`open`)&&t.set(`instantType`,`trigger-change`)},i.signal),()=>{i.abort()}},[n,s,t])}var Vi=20;function Hi(e,t,n,r){let[i,a]=q.useState(!1);Te(()=>{if(!e||!t||n==null){a(!1);return}let r=b(n).documentElement.clientWidth,i=n.offsetWidth;a(r>0&&i>0&&i>=r-Vi)},[e,t,n]),Ct(e&&(!t||i),r)}var Ui=q.forwardRef(function(e,n){let{render:r,className:i,style:a,anchor:o,positionMethod:s,side:c,align:l,sideOffset:u,alignOffset:d,collisionBoundary:f=`clipping-ancestors`,collisionPadding:p,arrowPadding:m,sticky:h,disableAnchorTracking:g=!1,collisionAvoidance:_=t,...v}=e,y=wi(),b=Ii(),x=ce(),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=rr({anchor:o,floatingRootContext:S,positionMethod:s,mounted:C,side:c,sideOffset:u,align:l,alignOffset:d,arrowPadding:m,collisionBoundary:f,collisionPadding:p,sticky:h,disableAnchorTracking:g,keepMounted:b,nodeId:x,collisionAvoidance:_,adaptiveOrigin:M});Bi({store:y,domReference:S.useState(`domReferenceElement`),positionerElement:k,open:w});let ee=D===!0&&T!==`trigger-hover`;Hi(w&&ee,O===`touch`,k,E);let P=y.useStateSetter(`positionerElement`),F={open:w,side:N.side,align:N.align,anchorHidden:N.anchorHidden,instant:A},te=lr(e,F,{styles:N.positionerStyles,transitionStatus:j,props:v,refs:[n,P],hidden:!C,inert:!w});return(0,Q.jsxs)(Ri.Provider,{value:N,children:[C&&ee&&(0,Q.jsx)(xt,{inert:nt(!w),cutout:E}),(0,Q.jsx)(Ue,{id:x,children:te})]})}),Wi=q.createContext(void 0);function Gi(e){let t=q.useContext(Wi);if(t===void 0&&!e)throw Error(rn(69));return t}var Ki=q.createContext(void 0);function qi(){let[e,t]=q.useState(0),n=W(()=>(t(e=>e+1),()=>{t(e=>Math.max(0,e-1))}));return{context:q.useMemo(()=>({register:n}),[n]),hasClosePart:e>0}}var Ji=q.forwardRef(function(e,t){let{render:n,className:r,style:i,initialFocus:a,finalFocus:o,...s}=e,c=wi(),l=zi(),u=Gi(!0)!=null,{context:d,hasClosePart:f}=qi(),p=c.useState(`open`),m=c.useState(`openMethod`),h=c.useState(`instantType`),_=c.useState(`transitionStatus`),v=c.useState(`popupProps`),y=c.useState(`titleElementId`),b=c.useState(`descriptionElementId`),x=c.useState(`modal`),S=c.useState(`mounted`),C=c.useState(`openChangeReason`),w=c.useState(`activeTriggerElement`),T=c.useState(`floatingRootContext`),E=T.useState(`floatingId`),D=c.useState(`disabled`),O=c.useState(`openOnHover`),k=c.useState(`closeDelay`);yn({open:p,ref:c.context.popupRef,onComplete(){p&&c.context.onOpenChangeComplete?.(!0)}}),Xn(T,{enabled:O&&!D,closeDelay:k});let A=a===void 0?Ot(c.context.popupRef):a,j=x!==!1&&f;c.useSyncedValue(`focusManagerModal`,j);let M=c.useStateSetter(`popupElement`),N={open:p,side:l.side,align:l.align,instant:h,transitionStatus:_},ee=tt(`div`,e,{state:N,ref:[t,c.context.popupRef,M],props:[v,{id:E,role:`dialog`,...g,"aria-labelledby":y,"aria-describedby":b,onKeyDown(e){u&&ln.has(e.key)&&e.stopPropagation()}},or(_),s],stateAttributesMapping:se});return(0,Q.jsx)(Ie,{context:T,openInteractionType:m,modal:j,disabled:!S||C===`trigger-hover`,initialFocus:A,returnFocus:o,restoreFocus:`popup`,getInsideElements:()=>[c.context.beforeTriggerFocusGuardRef.current],previousFocusableElement:He(w)?w:void 0,nextFocusableElement:c.context.triggerFocusTargetRef,beforeContentFocusGuardRef:c.context.beforeContentFocusGuardRef,children:(0,Q.jsx)(Ki.Provider,{value:d,children:ee})})}),Yi=`data-glide-stand-in`;function Xi(e,t){let n=e.getBoundingClientRect(),r=t.getBoundingClientRect();return{x:r.left-n.left+e.scrollLeft-e.clientLeft,y:r.top-n.top+e.scrollTop-e.clientTop,width:r.width,height:r.height}}function Zi(e){return{transform:`translate(${String(e.x)}px, ${String(e.y)}px)`,width:`${String(e.width)}px`,height:`${String(e.height)}px`}}function Qi(e){let t=(0,q.useRef)(null);return(0,q.useCallback)(n=>{t.current?.(),t.current=n?$i(n,e):null},[e])}function $i(e,t){if(!o(e))return()=>void 0;let n=e.ownerDocument,r=e.querySelector(t),i=r?Xi(e,r):null,a=null,s=null,c=new Set,l=()=>{for(let e of c)e.removeAttribute(Yi);c.clear(),a&&(a.hidden=!0),s=null},u=()=>{if(a)return a;let t=n.createElement(`span`);return t.className=`caps-glide`,t.setAttribute(`aria-hidden`,`true`),e.prepend(t),e.classList.add(`caps-glide-host`),getComputedStyle(e).position===`static`&&e.classList.add(`caps-glide-anchor`),a=t,t},d=(t,n)=>{let r=D(e),o=Xi(e,t),d=s&&a?Xi(e,a):i;if(i=o,s?.cancel(),l(),r.reduced||d===null||Math.abs(d.y-o.y)<1&&Math.abs(d.x-o.x)<1)return;t.setAttribute(Yi,`measure`);let f=getComputedStyle(t),p=f.backgroundColor,m=f.borderRadius;for(let e of[t,n])e&&(e.setAttribute(Yi,``),c.add(e));let h=u();h.hidden=!1,h.style.backgroundColor=p,h.style.borderRadius=m;let g=h.animate([Zi(d),Zi(o)],{duration:r.normal,easing:he(r,r.ease),fill:`forwards`});s=g,g.addEventListener(`finish`,()=>{s===g&&l()})},f=()=>{let n=e.querySelector(t);if(n===r)return;let i=r;r=n,n&&d(n,i)},p=new MutationObserver(f);return p.observe(e,{subtree:!0,attributes:!0,attributeFilter:[`data-highlighted`,`data-active`,`data-navigation`,`aria-selected`]}),e.addEventListener(`pointerover`,f),e.addEventListener(`pointerout`,f),()=>{p.disconnect(),e.removeEventListener(`pointerover`,f),e.removeEventListener(`pointerout`,f),s?.cancel(),l(),a?.remove()}}function ea({getKey:e,isDisabled:t=()=>!1,items:n}){let r=(0,q.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]),[i,a]=(0,q.useState)(null);(0,q.useEffect)(()=>{i!==null&&!r.some(t=>e(t)===i)&&a(null)},[i,r,e]);let o=r.find(t=>e(t)===i),s=o?r.findIndex(t=>e(t)===i):-1;return{activeIndex:s,activeItem:o,activeKey:i,enabledItems:r,move:(t,n)=>{if(r.length===0)return;let i=n?n===`start`?0:r.length-1:s<0?t>0?0:r.length-1:(s+t+r.length)%r.length,o=r[i];o&&a(e(o))},setActiveKey:a}}var ta=(0,q.forwardRef)(function({children:e,className:t,type:n=`button`,...r},i){return(0,Q.jsxs)(`button`,{...r,ref:i,type:n,className:z(`select caps-select caps-combobox-trigger w-full`,t),children:[(0,Q.jsx)(`span`,{children:e}),(0,Q.jsx)(Or,{className:`caps-select-chevron`,"aria-hidden":`true`})]})});function na({defaultOpen:e,defaultValue:t,getKey:n,getSearchText:r,groupBy:i,id:a,isDisabled:o,items:s,onOpenChange:c,onCommit:l,multiple:u,controlledOpen:d,controlledKeys:f,trigger:p}){let m=`${a}-listbox`,[h,g]=(0,q.useState)(``),[_,v]=(0,q.useState)(!1),[y,b]=(0,q.useState)(t),[x,S]=(0,q.useState)(e),C=f??(y===null?[]:[y]),w=p?d??x:!0,T=(0,q.useMemo)(()=>{let e=h.trim().toLowerCase();return e?s.filter(t=>r(t).toLowerCase().includes(e)):s},[r,s,h]),E=ea({getKey:n,isDisabled:o,items:T});(0,q.useEffect)(()=>{if(E.activeKey!==null)return;let e=E.enabledItems.find(e=>C.includes(n(e)))??E.enabledItems[0];e&&E.setActiveKey(n(e))},[E.activeKey,E.enabledItems,E.setActiveKey,n,C]);let D=e=>{v(!1),e||g(``),d===void 0&&S(e),c?.(e)},O=e=>`${m}-option-${encodeURIComponent(e)}`,k=e=>{let t=n(e);f===void 0&&b(t),l(e),p&&!u&&D(!1)},A=e=>{v(!0),g(e.target.value),E.setActiveKey(null)},j=e=>{if(Si(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?(v(!0),e.preventDefault(),E.move(t[0],t[1])):e.key===`Enter`&&E.activeItem&&(e.preventDefault(),k(E.activeItem))},M=(0,q.useMemo)(()=>{if(!i)return[{label:``,items:T}];let e=new Map;for(let t of T){let n=i(t),r=e.get(n);r?r.push(t):e.set(n,[t])}return[...e].map(([e,t])=>({label:e,items:t}))},[T,i]);return{keyboardNavigation:_,onPointerMove:()=>{v(!1)},activeKey:E.activeKey,activeItem:E.activeItem,groups:M,inputValue:h,listboxId:m,onInputChange:A,onInputKeyDown:j,optionId:O,open:w,commit:k,selectedKeys:C,setOpen:D}}function ra(e){let{"aria-describedby":t,"aria-invalid":n,"aria-label":r,"aria-labelledby":i,"aria-required":a,activeTone:o=`neutral`,container:s,contentClassName:c,defaultOpen:l=!1,defaultValue:u=null,emptyMessage:d=`No matches`,getKey:f,getLabel:p,getSearchText:m=p,groupBy:h,id:g,inputProps:_,inputRef:v,isDisabled:y=()=>!1,items:b,onOpenChange:x,onValueChange:S,multiple:C,open:w,placeholder:T=`Search…`,renderItem:E,rootRef:D,trigger:O,triggerRef:k,value:A,...j}=e,M=e=>{let t=f(e);if(C){let e=A.includes(t)?A.filter(e=>e!==t):[...A,t];S?.(e,b.filter(t=>e.includes(f(t))))}else S?.(t,e)},N;C?N=A:A!==void 0&&(N=A===null?[]:[A]);let ee=(0,q.useId)(),P=O?.props??_,F=g??P?.id??ee,te={id:F,"aria-describedby":[t,P?.[`aria-describedby`]].filter(Boolean).join(` `)||void 0,"aria-invalid":n??P?.[`aria-invalid`],"aria-label":P?.[`aria-label`]??r,"aria-labelledby":P?.[`aria-labelledby`]??i,"aria-required":a??P?.[`aria-required`]},{keyboardNavigation:ne,onPointerMove:re,activeItem:ie,activeKey:ae,commit:oe,groups:se,inputValue:ce,listboxId:le,onInputChange:ue,onInputKeyDown:de,open:fe,optionId:pe,selectedKeys:me,setOpen:he}=na({defaultOpen:l,defaultValue:u,getKey:f,getSearchText:m,groupBy:h,id:F,isDisabled:y,items:b,onOpenChange:x,onCommit:M,multiple:C??!1,controlledOpen:w,controlledKeys:N,trigger:O});vt(()=>{O&&he(!1)});let ge=Kt(`popover`),_e=s===void 0?ge:s,ve=Qi(`.caps-combobox-option[data-active="true"]:not(:disabled), [data-navigation="pointer"] .caps-combobox-option:hover:not(:disabled)`),ye=(0,Q.jsx)(nr,{..._,...O?{}:te,"aria-activedescendant":ie?pe(f(ie)):void 0,"aria-autocomplete":`list`,"aria-controls":le,"aria-expanded":!0,className:z(`input-sm`,_?.className),id:O?_?.id??`${F}-input`:F,onChange:e=>{_?.onChange?.(e),ue(e)},onKeyDown:e=>{_?.onKeyDown?.(e),e.defaultPrevented||de(e)},placeholder:_?.placeholder??T,ref:v,role:`combobox`,value:ce}),be=(0,Q.jsx)(`div`,{id:le,ref:ve,className:`caps-combobox-list`,"data-navigation":ne?`keyboard`:`pointer`,onPointerMove:re,role:`listbox`,"aria-multiselectable":C??void 0,children:se.every(e=>e.items.length===0)?(0,Q.jsx)(`div`,{className:`px-md py-md text-sm text-base-content`,children:d}):se.map(e=>(0,Q.jsxs)(`div`,{"aria-label":e.label||void 0,role:e.label?`group`:void 0,children:[e.label?(0,Q.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=f(e),n=y(e),r=ae===t,i={active:r,disabled:n,selected:me.includes(t)};return(0,Q.jsxs)(`button`,{"aria-disabled":n||void 0,"aria-selected":i.selected,className:`caps-combobox-option`,"data-active":r&&ne,disabled:n,id:pe(t),onClick:()=>{oe(e)},onMouseDown:e=>{e.preventDefault()},role:`option`,tabIndex:-1,type:`button`,children:[(0,Q.jsx)(`span`,{"aria-hidden":`true`,className:`caps-combobox-check`,children:i.selected?(0,Q.jsx)(Dr,{}):null}),E?.(e,r,i)??p(e)]},t)})]},e.label))});return O?(0,Q.jsx)(`div`,{...j,className:z(j.className),ref:D,children:(0,Q.jsxs)(Ai,{modal:!0,onOpenChange:he,open:fe,children:[(0,Q.jsx)(Pi,{...te,"aria-haspopup":`dialog`,className:`btn`,ref:k,render:O}),_e===null?null:(0,Q.jsx)(Li,{container:_e,children:(0,Q.jsx)(Ui,{align:`start`,side:`bottom`,sideOffset:4,children:(0,Q.jsxs)(Ji,{"data-active-tone":o,className:z(`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,Q.jsx)(`div`,{className:`caps-combobox-search`,children:ye}),be]})})})]})}):(0,Q.jsx)(`div`,{...j,className:z(j.className),ref:D,children:(0,Q.jsxs)(`div`,{className:z(`caps-combobox-panel`,c),"data-active-tone":o,children:[(0,Q.jsx)(`div`,{className:`caps-combobox-search`,children:ye}),be]})})}function ia({icon:e,caption:t}){return(0,Q.jsxs)(`span`,{className:`caps-icon-choice-mark`,"aria-hidden":`true`,children:[(0,Q.jsx)(`span`,{className:`caps-icon-choice-art`,children:e}),t?(0,Q.jsx)(`span`,{className:`caps-icon-choice-caption`,children:t}):null,(0,Q.jsx)(`span`,{className:`caps-icon-choice-lamp`})]})}var aa=(0,q.forwardRef)(function({label:e,icon:t,caption:n,appearance:r,className:i,...a},o){return(0,Q.jsx)(`label`,{className:`caps-icon-choice`,"data-appearance":r===`compact`?r:void 0,children:(0,Q.jsx)(bi,{...a,appearance:r??`default`,"aria-label":e,className:z(`caps-icon-choice-input`,i),indicator:(0,Q.jsx)(ia,{icon:t,caption:n}),ref:o})})}),oa=(0,q.forwardRef)(function({label:e,icon:t,hint:n,className:r,...i},a){let o=(0,q.useId)(),s=[i[`aria-describedby`],n?o:null].filter(Boolean).join(` `)||void 0;return(0,Q.jsx)(`label`,{className:`caps-check-key`,children:(0,Q.jsx)(bi,{...i,"aria-label":e,"aria-describedby":s,className:z(`caps-check-key-input`,r),indicator:(0,Q.jsxs)(`span`,{className:`caps-check-key-face`,"aria-hidden":`true`,children:[t?(0,Q.jsx)(`span`,{className:`caps-check-key-icon`,children:t}):null,(0,Q.jsxs)(`span`,{className:`caps-check-key-copy`,children:[(0,Q.jsx)(`span`,{className:`caps-check-key-label`,children:e}),n?(0,Q.jsx)(`span`,{className:`caps-check-key-hint`,id:o,children:n}):null]}),(0,Q.jsx)(`span`,{className:`caps-check-key-lamp`})]}),ref:a})})});function sa({className:e,...t}){return(0,Q.jsx)(`div`,{...t,className:z(`caps-check-keys`,e)})}function ca({checked:e}){let t=`caps-radio-${(0,q.useId)().replaceAll(`:`,``)}`,n=(0,q.useRef)(null),r=(0,q.useRef)(e).current,i=(0,q.useRef)(e),a=(0,q.useRef)(null),o=ne(a),{reduced:s}=o;return(0,q.useLayoutEffect)(()=>{if(!n.current)return;let t=s||i.current===e;i.current=e;let r=e?4:0,a=Z(o,{ease:`outCubic`,duration:75}),c=e?$r(o,{bounce:.65,duration:300}):Z(o,{ease:`inCubic`,duration:100}),l=V(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,Q.jsxs)(`svg`,{ref:a,className:`caps-radio-visual`,width:`24`,height:`24`,viewBox:`0 0 12 12`,"aria-hidden":`true`,focusable:`false`,children:[(0,Q.jsxs)(`defs`,{children:[(0,Q.jsx)(It,{id:`${t}-surface`,transform:`matrix(1 0 0 1 6 6)`}),(0,Q.jsx)(ft,{id:`${t}-shadow`}),(0,Q.jsx)(tn,{id:`${t}-inset`}),(0,Q.jsx)(`clipPath`,{id:`${t}-well`,children:(0,Q.jsx)(`circle`,{cx:`6`,cy:`6`,r:`5`})})]}),(0,Q.jsx)(`circle`,{className:`caps-radio-track`,cx:`6`,cy:`6`,r:`5.5`,filter:`url(#${t}-inset)`}),(0,Q.jsx)(`g`,{clipPath:`url(#${t}-well)`,children:(0,Q.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 la=(0,q.createContext)(null),ua=(0,q.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,q.useId)(),d=(0,q.useRef)(null);(0,q.useImperativeHandle)(l,()=>{if(!d.current)throw Error(`RadioGroup is not mounted`);return d.current},[]);let f=i??`radio-group-${u}`,[p,m]=(0,q.useState)(n),h=s??p;return(0,q.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,Q.jsx)(la.Provider,{value:{disabled:r,name:f,onValueChange:e=>{s===void 0&&m(e),a?.(e)},value:h},children:(0,Q.jsx)(`fieldset`,{...c,className:z(`flex gap-md`,o===`horizontal`?`flex-row flex-wrap`:`flex-col`,t),disabled:r,role:c.role??`radiogroup`,ref:d,children:e})})}),da=(0,q.forwardRef)(function({className:e,indicator:t,onChange:n,onClick:r,value:i,...a},o){let s=(0,q.useContext)(la);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,Q.jsxs)(`span`,{className:`caps-radio`,"data-checked":c,"data-custom-indicator":t!==void 0||void 0,children:[(0,Q.jsx)(`input`,{...a,"aria-checked":c,checked:c,className:z(`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,Q.jsx)(ca,{checked:c}):t]})}),fa=(0,q.forwardRef)(function({description:e,id:t,meta:n,title:r,...i},a){let o=(0,q.useContext)(la),s=(0,q.useId)(),c=t??s,l=o?.value===i.value,u=o?.disabled===!0||i.disabled===!0;return(0,Q.jsxs)(`label`,{className:`caps-choice-card`,"data-checked":l,"data-disabled":u||void 0,htmlFor:c,children:[(0,Q.jsx)(da,{...i,"aria-describedby":e?`${c}-description`:void 0,"aria-labelledby":`${c}-title`,id:c,ref:a}),(0,Q.jsxs)(`span`,{className:`caps-choice-card-copy`,children:[(0,Q.jsx)(`span`,{className:`caps-choice-card-title`,id:`${c}-title`,children:r}),e?(0,Q.jsx)(`span`,{className:`caps-choice-card-description`,id:`${c}-description`,children:e}):null]}),n?(0,Q.jsx)(`span`,{className:`caps-choice-card-meta`,children:n}):null]})}),pa=(0,q.forwardRef)(function({label:e,icon:t,caption:n,art:r=`dim`,className:i,...a},o){return(0,Q.jsx)(`label`,{className:`caps-icon-choice`,"data-art":r===`color`?r:void 0,children:(0,Q.jsx)(da,{...a,"aria-label":e,className:z(`caps-icon-choice-input`,i),indicator:(0,Q.jsx)(ia,{icon:t,caption:n}),ref:o})})});(0,q.forwardRef)(function({label:e,color:t,className:n,...r},i){return(0,Q.jsx)(`label`,{className:`caps-icon-choice`,"data-art":`color`,"data-swatch":``,title:e,children:(0,Q.jsx)(da,{...r,"aria-label":e,className:z(`caps-icon-choice-input`,n),indicator:(0,Q.jsx)(ia,{icon:(0,Q.jsx)(`span`,{className:`caps-swatch-dot`,style:{backgroundColor:t}})}),ref:i})})});var ma=(0,q.forwardRef)(function({className:e,invalid:t,...n},r){return(0,Q.jsxs)(`span`,{className:`caps-select-shell`,children:[(0,Q.jsx)(`select`,{...n,"aria-invalid":t?!0:n[`aria-invalid`]===!1?void 0:n[`aria-invalid`],className:z(`select select-bordered caps-select w-full`,t&&`select-error`,e),ref:r}),!n.multiple&&(!n.size||n.size<=1)?(0,Q.jsx)(Or,{className:`caps-select-chevron`,"aria-hidden":`true`}):null]})});function ha({checked:e}){let t=`caps-switch-${(0,q.useId)().replaceAll(`:`,``)}`,n=(0,q.useRef)(null),r=(0,q.useRef)(null),i=(0,q.useRef)(e).current,a=(0,q.useRef)(e),o=de();return(0,q.useLayoutEffect)(()=>{if(!n.current||!r.current)return;let t=o||a.current===e;a.current=e;let i=e?16:8,s=D(n.current),c=$r(s,{bounce:.25,duration:440}),l=Z(s,{ease:`inOutSine`,duration:100}),u=V(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=V(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,Q.jsxs)(`svg`,{className:`caps-switch-visual`,width:`40`,height:`24`,viewBox:`0 0 20 12`,"aria-hidden":`true`,focusable:`false`,children:[(0,Q.jsxs)(`defs`,{children:[(0,Q.jsx)(It,{ref:r,id:`${t}-surface`,transform:i?`matrix(2 0 0 1 10 6)`:`matrix(1 0 0 1 6 6)`}),(0,Q.jsx)(ft,{id:`${t}-shadow`}),(0,Q.jsx)(tn,{id:`${t}-inset`}),(0,Q.jsx)(`clipPath`,{id:`${t}-track`,children:(0,Q.jsx)(`rect`,{x:`1`,y:`1`,width:`18`,height:`10`,rx:`5`})})]}),(0,Q.jsx)(`rect`,{className:`caps-switch-track`,filter:`url(#${t}-inset)`,x:`0.5`,y:`0.5`,width:`19`,height:`11`,rx:`5.5`}),(0,Q.jsx)(`g`,{clipPath:`url(#${t}-track)`,children:(0,Q.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 ga=(0,q.forwardRef)(function({className:e,checked:t,defaultChecked:n=!1,onChange:r,onCheckedChange:i,...a},o){let s=(0,q.useRef)(null),[c,l]=(0,q.useState)(n),u=t??c;return(0,q.useImperativeHandle)(o,()=>{if(!s.current)throw Error(`Switch input is not mounted`);return s.current},[]),(0,q.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,Q.jsxs)(`span`,{className:`caps-switch`,"data-checked":u,children:[(0,Q.jsx)(`input`,{...a,checked:u,className:z(`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,Q.jsx)(ha,{checked:u})]})}),_a=(0,q.forwardRef)(function({className:e,invalid:t,...n},r){return(0,Q.jsx)(`textarea`,{...n,"aria-invalid":t?!0:n[`aria-invalid`]===!1?void 0:n[`aria-invalid`],className:z(`textarea textarea-bordered w-full`,t&&`textarea-error`,e),ref:r})}),va=B(I),ya=B(Re),ba=B(Xe(Ge)),xa=B(P(I)),Sa=P(yt(File)),Ca=B(Sa),wa=Zt([I,Ge,Re,oe,zt,P(I),Sa]),Ta=B(wa),$=e=>l(va(e.state.value),()=>``),Ea=e=>l(ya(e.state.value),()=>!1),Da=e=>l(ba(e.state.value),()=>null),Oa=e=>l(xa(e.state.value),()=>[]),ka=e=>l(Ca(e.state.value),()=>[]),Aa=e=>l(Ta(e.state.value),()=>null);function ja({field:e,spec:t,locked:n,...r}){let[i,a]=(0,q.useState)(!1);return(0,Q.jsxs)(er,{children:[(0,Q.jsx)(nr,{...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,Q.jsx)(G,{type:`button`,variant:`outline`,size:`icon`,"aria-label":i?`Hide`:`Show`,"aria-pressed":i,disabled:n,onClick:()=>{a(e=>!e)},children:i?(0,Q.jsx)(kr,{"aria-hidden":`true`}):(0,Q.jsx)(hr,{"aria-hidden":`true`})})]})}var Ma={text:`text`,email:`email`,url:`url`,tel:`tel`};function Na({spec:e,field:t,locked:n,...r}){let i=ka(t),a=n||e.readOnly===!0,o=(0,q.useRef)(null);return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-sm`,children:[(0,Q.jsx)(Nt,{asChild:!0,children:(0,Q.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,Q.jsx)(G,{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,Q.jsx)(fi,{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 Pa({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,Q.jsx)(nr,{...a,type:Ma[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,Q.jsx)(_a,{...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,Q.jsx)(ja,{...r,field:t,spec:e,locked:n});case`money`:return(0,Q.jsxs)(er,{children:[(0,Q.jsx)(tr,{className:`caps-field-currency`,children:e.currency??`USD`}),(0,Q.jsx)(nr,{...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,Q.jsx)(nr,{...a,type:`date`,readOnly:e.readOnly,value:$(t),onChange:e=>{i(e.currentTarget.value)}});case`number`:return(0,Q.jsx)(pr,{...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:Da(t),onValueChange:e=>{t.handleChange(e)}});case`select`:return(0,Q.jsxs)(ma,{...a,value:$(t),onChange:e=>{i(e.currentTarget.value)},children:[e.placeholder===void 0?null:(0,Q.jsx)(`option`,{value:``,disabled:!0,children:e.placeholder}),e.options.map(e=>(0,Q.jsx)(`option`,{value:e.value,disabled:e.disabled,children:e.label},e.value))]});case`combobox`:return(0,Q.jsx)(ra,{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,Q.jsx)(ta,{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,Q.jsx)(Na,{...r,spec:e,field:t,locked:n});case`checkbox`:return(0,Q.jsx)(bi,{...a,disabled:n||e.readOnly===!0,checked:Ea(t),onChange:e=>{t.handleChange(e.currentTarget.checked)}});case`switch`:return(0,Q.jsx)(ga,{...a,disabled:n||e.readOnly===!0,checked:Ea(t),onCheckedChange:e=>{t.handleChange(e)}});case`radio`:case`icon-radio`:case`checkboxes`:case`icon-checkboxes`:return null}}var Fa=new Set([`radio`,`icon-radio`,`checkboxes`,`icon-checkboxes`]);function Ia({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=Oa(t),s=(e,r)=>{t.handleChange(r?[...n,e]:n.filter(t=>t!==e))};return(0,Q.jsx)(cr,{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,Q.jsx)(`div`,{className:`caps-field-icon-choices`,children:e.options.map(r=>(0,Q.jsx)(aa,{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,Q.jsx)(sa,{children:e.options.map(r=>(0,Q.jsx)(oa,{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,Q.jsx)(cr,{legend:o,icon:e.icon,layout:i,...i===`columns`?{legendTitle:o}:{},description:e.help,disabled:a,error:r??null,children:(0,Q.jsx)(ua,{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,Q.jsx)(pa,{value:t.value,label:t.label,...t.caption===void 0?{}:{caption:t.caption},icon:t.icon,disabled:t.disabled},t.value):s?(0,Q.jsx)(fa,{value:t.value,title:t.label,description:t.description,meta:t.meta,disabled:t.disabled},t.value):(0,Q.jsx)(Zn,{label:t.label,orientation:`inline`,children:(0,Q.jsx)(da,{value:t.value,disabled:t.disabled})},t.value))})})}function La({spec:e,field:t,locked:n,error:r,render:i,...a}){return i({name:e.name,label:e.label,help:e.help,value:Aa(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 Ra({form:e,spec:t,locked:n,layout:r}){let i=sr({form:e,name:t.name}),a=ur(e.store,e=>e.submissionAttempts>0),o=i.state.meta.isBlurred||a?Qr(i.state.meta):void 0;if(t.render===void 0&&Fa.has(t.kind))return(0,Q.jsx)(Ia,{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,Q.jsx)(Zn,{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,Q.jsx)(Pa,{spec:t,field:i,locked:n}):(0,Q.jsx)(La,{spec:t,field:i,locked:n,error:o,render:t.render})})}var za=B(et(I,wa));function Ba({form:e,spec:t,locked:n,layout:r}){let i=t.when;return ur(e.store,e=>i===void 0||i(l(za(e.values),()=>({}))))?(0,Q.jsx)(Ra,{form:e,spec:t,locked:n,layout:r}):null}function Va({form:e,section:t,locked:n,layout:r}){let i=t.fields.map(t=>(0,Q.jsx)(Ba,{form:e,spec:t,locked:n,layout:r},t.name));return t.title===void 0?i:(0,Q.jsx)(ar,{title:t.title,description:t.description,layout:r,children:i})}function Ha({model:e,names:t,disabled:n=!1,layout:r}){let i=e.form;return t===void 0?e.description.sections.map(e=>(0,Q.jsx)(Va,{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,Q.jsx)(Ba,{form:i,spec:a,locked:n,layout:r},t)})}var Ua=class{annotation;constructor(e){this.annotation=e}},Wa=class{sections;constructor(e){this.sections=e}},Ga=`caps/form`,Ka=0;function qa(e){Ka+=1;let t={[`${Ga}:${String(Ka)}`]:new Ua(e)};return e.label!==void 0&&(t.title=e.label),e.help!==void 0&&(t.description=e.help),t}I.annotate(qa({kind:`secret`})).pipe(it(`Secret`));var Ja=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 Ya(e){return Object.values(e??{}).reduce((e,t)=>t instanceof Ua?{...e,...t.annotation}:e,{})}function Xa(e){return e.reduce((e,t)=>({...e,...Ya(t)}),{})}function Za(e){let t=e?.[Ga];return t instanceof Wa?t.sections:{}}var Qa=B(I);function $a(e){if(_(e))return We(Qa(e.literal),{onNone:()=>null,onSome:e=>[e]});if(!ve(e))return null;let t=[];for(let n of e.types){if(me(n))continue;let e=$a(n);if(e===null)return null;t.push(...e)}return t}function eo(e){if(kt(e))return{type:`string`,literals:[]};if(Mt(e))return{type:`number`,nullable:!1};if(S(e))return{type:`boolean`};let t=$a(e);if(t!==null)return{type:`string`,literals:t};if(Fe(e)){let[t]=e.rest;if(t===void 0)return null;if(kt(t))return{type:`strings`,literals:[]};let n=$a(t);return n===null?null:{type:`strings`,literals:n}}if(ve(e)){let t=e.types.filter(e=>!me(e)&&!Se(e)),n=e.types.some(e=>Se(e)),[r]=t;if(t.length!==1||r===void 0)return null;let i=eo(r);return i?.type===`number`?{type:`number`,nullable:n}:n?null:i}return null}function to(e){let t=e.ast;if(!a(t))throw Error(`A schema form needs a Schema.Struct.`);return{fields:t.propertySignatures.map(e=>{let t=String(e.name),n=ue(e.type),r=Xa([e.type.annotations,...(e.type.checks??[]).map(e=>e.annotations)]),i=r.kind===`file`?{type:`files`}:eo(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:te(e.type),description:E(e.type)}}),sections:Za(De(t))}}function no(e){let t=e,n=!1,r=!1;for(;;)if(t instanceof an)n=!0,t=t.unwrap();else if(t instanceof Ae)r=!0,t=t.unwrap();else if(t instanceof Ye)t=t.unwrap();else if(t instanceof Vt)t=t.in;else return{node:t,optional:n,nullable:r}}function ro(e){if(e instanceof ot){let t=e.options.map(e=>ro(e));return t.some(e=>e===null)?null:t.flatMap(e=>e??[])}let t=e instanceof Ke?e.options:e instanceof $e?[...e.values]:null;if(t===null)return null;let n=t.map(e=>Qa(e));return n.every(N)?n.map(e=>e.value):null}function io(e){let{node:t,nullable:r}=no(e);if(t instanceof Qt)return{type:`string`,literals:[]};if(t instanceof n)return{type:`number`,nullable:r};if(t instanceof ae)return{type:`boolean`};let i=ro(t);if(i!==null)return{type:`string`,literals:i};if(t instanceof Yt){let e=no(t.element).node;if(e instanceof Qt)return{type:`strings`,literals:[]};let n=ro(e);return n===null?null:{type:`strings`,literals:n}}return null}function ao(e){let t=[e];for(;;){let e=t[t.length-1];if(e===void 0)break;let n=e instanceof an||e instanceof Ae||e instanceof Ye?e.unwrap():e instanceof Vt?e.in:e;if(n===e)break;t.push(n)}return t.reverse().map(e=>y.get(e))}function oo(e){return ao(e).reduce((e,t)=>({...e,...t}),{})}function so(e){return Object.entries(e.shape)}function co(e){let t=no(e).node;if(!(t instanceof gt))throw Error(`A schema form needs a z.object.`);return{fields:so(t).map(([e,t])=>{let n=Xa(ao(t)),r=n.kind===`file`?{type:`files`}:io(t);if(r===null)throw Error(`Schema field "${e}" has no form control. Annotate it with field({ render }) or a kind.`);let i=oo(t);return{name:e,valueType:r,optional:no(t).optional,annotation:n,title:i.title,description:i.description}}),sections:Za(oo(e))}}function lo(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??Ja(e),description:r.description,meta:r.meta,icon:r.icon,caption:r.caption,disabled:r.disabled===!0}})}function uo(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 fo(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 po(e){let t=e instanceof Et?co(e):to(e),n=t.fields.map((e,t)=>{let{kind:n,...r}=e.annotation,i=lo(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??Ja(e.name),help:a,kind:n??uo(e.valueType,i),options:i,optionalInSchema:e.optional,index:t}}),r={};t.fields.forEach((e,t)=>{let i=n[t];i&&(r[e.name]=fo(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 mo(e){let t=e instanceof Et?e:fn(e);return{"~standard":{...t[`~standard`],validate:e=>{let n=t[`~standard`].validate(e);return n instanceof Promise?n.then(e=>ho(e)):ho(n)}}}}function ho(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 go=`onServer`;function _o(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 vo(e){if(_o(e))return()=>void 0;let t=new MutationObserver(()=>{_o(e)&&t.disconnect()});return t.observe(e,{subtree:!0,childList:!0,attributes:!0,attributeFilter:[`aria-invalid`]}),()=>{t.disconnect()}}function yo(e){return e.state.meta.errorMap.onServer!==void 0}function bo(e){e.setMeta(e=>({...e,errorMap:{...e.errorMap,[go]:void 0}}))}function xo(e,t,n){e.setFieldMeta(t,e=>({...e,isBlurred:!0,errorMap:{...e.errorMap,[go]:n}}))}function So(e){let[t,n]=(0,q.useState)(null),[r,i]=(0,q.useState)(null),[a,o]=(0,q.useState)(e.defaultValues),[s,c]=(0,q.useState)(null);ir(a,e.defaultValues)||(o(e.defaultValues),c(null));let{schema:l}=e,u=(0,q.useMemo)(()=>po(l),[l]),d=(0,q.useMemo)(()=>mo(l),[l]),f=fr({defaultValues:s??a,validators:{onChange:d,onSubmit:d},listeners:{onChange:({fieldApi:e})=>{n(null),i(null),yo(e)&&bo(e)}},onSubmit:async({value:t,formApi:r})=>{n(null),i(null);let a=await mo(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&&xo(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 Co(e){return{dirty:ur(e.form.store,e=>!e.isDefaultValue),submitting:ur(e.form.store,e=>e.isSubmitting),canSubmit:ur(e.form.store,e=>e.canSubmit)}}function wo({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}=Co(e),f=(0,q.useRef)(null),p=(0,q.useRef)(()=>void 0);return(0,q.useEffect)(()=>()=>{p.current()},[]),(0,Q.jsxs)(dr,{...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=vo(t))})},children:[c??(0,Q.jsx)(Ha,{model:e,disabled:l,layout:o}),s===void 0?(0,Q.jsx)(Do,{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 To({schema:e,defaultValues:t,onSubmit:n,onSaved:r,failure:i,...a}){let o=So({schema:e,defaultValues:t,onSubmit:n,onSaved:r,failure:i});return(0,Q.jsx)(wo,{...a,model:o})}function Eo(e){return`model`in e?(0,Q.jsx)(wo,{...e}):(0,Q.jsx)(To,{...e})}function Do({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}=Co(e),d=u?null:e.saved&&!l?(0,Q.jsx)(li,{tone:`success`,size:`compact`,label:e.saved}):l?(0,Q.jsx)(li,{tone:`neutral`,size:`compact`,label:o}):null;return(0,Q.jsxs)($n,{...c,error:e.error,status:d,children:[r?(0,Q.jsx)(G,{type:`button`,variant:`ghost`,disabled:u,onClick:r,children:i}):n&&l?(0,Q.jsx)(G,{type:`button`,variant:`ghost`,disabled:u,onClick:e.discard,children:n}):null,(0,Q.jsx)(G,{...s,type:`submit`,loading:u,disabled:u||!l&&!a,title:!l&&!a?`No changes to save`:void 0,children:t})]})}var Oo=ht.check(lt(/^(?!\.{1,2}$)[^/]+$/u,{message:`Enter a single file or folder name.`})),ko={file:r({name:Oo.annotate(qa({label:`File name`}))}),folder:r({name:Oo.annotate(qa({label:`Folder name`}))})};function Ao(e){return(0,Q.jsx)(jo,{...e},e.creation?`${e.creation.kind}:${e.creation.directory}:${e.creation.name??``}`:`closed`)}function jo({creation:e,rootPath:t,onCreate:n,onClose:r}){let i=So({schema:ko[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}=Co(i);return(0,Q.jsx)(Tt,{open:e!==null,onOpenChange:e=>{!e&&!i.form.state.isSubmitting&&r()},children:(0,Q.jsxs)(Ut,{children:[(0,Q.jsxs)(Ft,{className:`mb-4`,children:[(0,Q.jsxs)(sn,{children:[`New `,e?.kind===`folder`?`folder`:`file`]}),(0,Q.jsxs)(en,{children:[`Create in `,e?.directory??t,` on this Computer.`]})]}),(0,Q.jsx)(Eo,{model:i,onSubmitCapture:()=>{i.form.state.isSubmitting||i.form.setFieldValue(`name`,e=>e)},footer:(0,Q.jsxs)($n,{divider:!1,error:i.error,children:[(0,Q.jsx)(G,{variant:`ghost`,type:`button`,disabled:a,onClick:r,children:`Cancel`}),(0,Q.jsx)(G,{type:`submit`,disabled:a,loading:a,children:a?`Creating…`:`Create`})]})})]})})}var Mo=`That name already exists in this directory.`;function No({app:e,onOpenFile:t,activePath:n,rootPath:r=`/`,rootLabel:i=`Computer`,onSelectPath:a,creationRequest:o=null,onCreationRequestHandled:s,onRootEmpty:c}){let[l,u]=(0,q.useState)(null),d=Yr({app:e,rootPath:r,rootLabel:i,activePath:n,onOpenFile:t,onSelectPath:e=>{u(e),a?.(e)}}),[f,p]=(0,q.useState)(null),m=d.rootEmpty;(0,q.useEffect)(()=>{c?.(m)},[c,m]);let h=e.capabilities.has(kn);function g(e,t){p({kind:e,directory:nn(t)})}(0,q.useEffect)(()=>{if(!o)return;let e={kind:o.kind,directory:nn(l??`${r}/`)};o.name!==void 0&&(e.name=o.name),o.immediate===!0&&o.name!==void 0?_(e,o.name):p(e),s?.()},[o,s,r,l]);async function _(e,n){let r=await v(e,n);r===Mo?t(Xt(n,e.directory)):r!==void 0&&p(e)}async function v(n,r){let i=Xt(r,n.directory);try{let a=0;for(;a!==null;){let t=a,i=await wn(e.capabilities,{path:n.directory,limit:256,offset:t});if(i.entries.some(e=>e.name===r))return Mo;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(kn).mkdir({path:i}),d.model.batch([{type:`add`,path:`${i}/`}])):(await En(e.capabilities,{path:i,content:new Blob([])},{}),d.model.batch([{type:`add`,path:i}]),t(i));return}catch(e){return e instanceof Error?j(e).message:`Couldn't create ${n.kind}. Check Computer write access.`}}return(0,Q.jsxs)(`aside`,{className:`inkcap-tree`,"aria-label":`File tree`,children:[(0,Q.jsxs)(`div`,{className:`inkcap-tree-toolbar`,children:[(0,Q.jsxs)(`span`,{children:[(0,Q.jsx)(Pn,{"aria-hidden":`true`}),` Explorer`]}),(0,Q.jsxs)(`span`,{className:`inkcap-tree-actions`,children:[(0,Q.jsx)(Bt,{icon:(0,Q.jsx)(Mn,{}),"aria-label":`New file`,title:`New file`,variant:`ghost`,size:`xs`,disabled:!h,onClick:()=>{g(`file`,l??`${r}/`)}}),(0,Q.jsx)(Bt,{icon:(0,Q.jsx)(jr,{}),"aria-label":`New folder`,title:`New folder`,variant:`ghost`,size:`xs`,disabled:!h,onClick:()=>{g(`folder`,l??`${r}/`)}}),(0,Q.jsx)(Bt,{icon:(0,Q.jsx)(vr,{}),"aria-label":`Refresh files`,title:`Refresh files`,variant:`ghost`,size:`xs`,disabled:d.busy,onClick:d.reloadRoot})]})]}),d.error&&(0,Q.jsx)(`p`,{role:`alert`,children:d.error}),d.rootEmpty?(0,Q.jsx)(`p`,{className:`inkcap-tree-note`,children:`Empty folder`}):null,(0,Q.jsx)(Hn,{model:d.model,style:{flex:`1`,"--trees-item-height":`32px`,"--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`},renderContextMenu:(e,t)=>(0,Q.jsxs)(`div`,{className:`flex min-w-36 flex-col gap-xs p-xs`,role:`menu`,children:[(0,Q.jsxs)(G,{className:`w-full justify-start`,disabled:!h,role:`menuitem`,title:h?void 0:`Computer write access is not granted.`,size:`sm`,variant:`ghost`,onClick:()=>{t.close({restoreFocus:!1}),g(`file`,e.path)},children:[(0,Q.jsx)(Mn,{"aria-hidden":`true`}),` New file`]}),(0,Q.jsxs)(G,{className:`w-full justify-start`,disabled:!h,role:`menuitem`,title:h?void 0:`Computer write access is not granted.`,size:`sm`,variant:`ghost`,onClick:()=>{t.close({restoreFocus:!1}),g(`folder`,e.path)},children:[(0,Q.jsx)(jr,{"aria-hidden":`true`}),` New folder`]})]})}),(0,Q.jsx)(Ao,{creation:f,rootPath:r,onCreate:v,onClose:()=>{p(null)}}),d.page.next!==null&&(0,Q.jsxs)(G,{disabled:d.busy,onClick:d.loadNext,children:[`More in `,d.page.path]})]})}export{No as InkcapFileTree};
@@ -1 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Bn as t,Br as n,Un as r,Vr as i,i as a,l as o,nn as s,o as c,rn as l,s as u,u as d}from"./tree-path-JjH_INEe.js";import{bt as f,ht as p,kt as m,t as h}from"./folder-open-DArW1Xa9.js";import{a as g,c as _,d as v,i as y,l as b,n as x,o as S,r as C,s as w,t as T,u as E}from"./useFileTree-BtMBhuEG.js";import{t as D}from"./refresh-cw-Cj8Ajrfj.js";import{_ as O,a as k,b as A,c as j,d as M,f as N,g as P,h as F,l as I,m as L,n as ee,p as R,t as z,u as B,v as V,y as H}from"./index-B-zUw4Dm.js";var U=e(i(),1);function W(e,t,n){let r=E(),i=b(),a=m(n),o=a.defaultQueryOptions(e),s=a.getQueryCache().get(o.queryHash),c=e.subscribed!==!1;o._optimisticResults=r?`isRestoring`:c?`optimistic`:void 0,C(o),S(o,i,s),_(i);let[l]=U.useState(()=>new t(a,o)),u=l.getOptimisticResult(o),d=!r&&c;if(U.useSyncExternalStore(U.useCallback(e=>{let t=d?l.subscribe(p.batchCalls(e)):f;return l.updateResult(),t},[l,d]),()=>l.getCurrentResult(),()=>l.getCurrentResult()),U.useEffect(()=>{l.setOptions(o)},[o,l]),g(o,u))throw y(o,l,i);if(w({result:u,errorResetBoundary:i,throwOnError:o.throwOnError,query:s,suspense:o.suspense}))throw u.error;return o.notifyOnChangeProps?u:l.trackResult(u)}function G(e,t){return W(e,v,t)}var K=t(`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`}]]),q=t(`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`}]]),J=256;async function Y(e,t,n,i,a){i.throwIfAborted();let o=await n(e,t);if(!O.safeParse(o).success)return o;a(!0);try{let a=null,o=!1;for(let e=0;e<J&&!o;e++){i.throwIfAborted();let e=I.parse(await n(`rebuildCopies`,{cursor:a}));o=e.done,a=e.cursor}if(!o)throw new r(`Bonsai is still preparing this repository. Try again shortly.`,{code:`TIMEOUT`,retryable:!0});i.throwIfAborted();let s=await n(e,t);if(O.safeParse(s).success)throw Error(`The repository changed while loading. Refresh to retry.`);return s}finally{a(!1)}}function X({repository:e,branch:t,request:n,onSaved:i,onSaveState:a}){let o=new Map;async function s(i,a){a.throwIfAborted();let o=B.parse(await n(`files.read`,{repo:e,ref:t,path:i}));if(a.throwIfAborted(),o.binary)throw Error(`This Bonsai file is not a text document.`);if(o.text===null&&o.blob!==null)throw new r(`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=P.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 r(`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 r(`Your saved file changed. Compare before syncing.`,{code:`CONFLICT`,retryable:!0});a(s,u.result)}i()}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 r(`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 r(`The file changed. Compare before saving.`,{code:`CONFLICT`,retryable:!0});e.pending===void 0&&(p.file=e)}let m=L.parse({repo:e,branch:t,path:l,baseCommit:p.file.commit,baseBlob:p.file.blob,text:u,revision:p.version}),h=F.parse(await n(`files.save`,m));if(h.kind===`refused`)throw new r(`Bonsai refused this save: ${h.reason}`,{code:`CAPABILITY_DENIED`,retryable:h.reason===`background-unavailable`});if(a(l,h),h.kind===`conflict`)throw new r(`Your saved file changed. Compare before saving.`,{code:`CONFLICT`,retryable:!0});o.set(l,{file:p.file,contents:u,version:h.revision}),i(),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),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=M.parse({repo:e,branch:t,path:s,revision:l.version}),d=N.parse(await n(`files.discard`,u));if(c.throwIfAborted(),d.kind===`conflict`)throw new r(`Your saved file changed. Refresh before discarding.`,{code:`CONFLICT`,retryable:!0});o.delete(s),a(s,null),i()},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 Z(e,t,n){let r={repo:t,ref:n},i=V.parse(await e(`files.tree`,{...r,path:``})),a=R.parse(await e(`files.list`,r)),o=j.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 Q=n();function te({files:e,dirtyPaths:t,activePath:n,busy:r,onRefresh:i,onOpenFile:a}){let o=(0,U.useRef)({files:e,onOpenFile:a});o.current={files:e,onOpenFile:a};let{model:c}=T({paths:[],initialExpansion:`open`,itemHeight:32,onSelectionChange(e){let t=e[0];t&&!t.endsWith(`/`)&&o.current.files.some(e=>e.path===t)&&o.current.onOpenFile(t)}}),l=(0,U.useMemo)(()=>{let n=new Set(t);return e.flatMap(e=>n.has(e.path)?[{path:e.path,status:`modified`}]:[])},[e,t]);return(0,U.useEffect)(()=>{c.resetPaths(e.map(e=>e.path))},[c,e]),(0,U.useEffect)(()=>{c.setGitStatus(l)},[c,l]),(0,U.useEffect)(()=>{for(let e of c.getSelectedPaths())e!==n&&c.getItem(e)?.deselect();n&&c.getItem(n)?.select()},[c,n]),(0,Q.jsxs)(`aside`,{className:`inkcap-tree`,"aria-label":`Repository files`,children:[(0,Q.jsxs)(`div`,{className:`inkcap-tree-toolbar`,children:[(0,Q.jsxs)(`span`,{children:[(0,Q.jsx)(h,{"aria-hidden":`true`}),` Explorer`]}),(0,Q.jsx)(s,{icon:(0,Q.jsx)(D,{}),"aria-label":`Refresh repository`,variant:`ghost`,size:`xs`,disabled:r,onClick:i})]}),(0,Q.jsx)(`p`,{className:`inkcap-repository-legend`,children:`Changes in latest commit · drafts marked modified`}),(0,Q.jsx)(x,{model:c,style:{flex:`1`,"--trees-item-height":`32px`,"--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`}})]})}var $={all:(e,t)=>[`inkcap-repository`,e,t],branch:(e,t,n)=>[...$.all(e,t),n]};function ne({connection:e,repository:t,initialBranch:n,initialPath:r,openRequestId:i,transport:s,onReady:f}){let p=m(),[h,g]=(0,U.useState)(!1),[_,v]=(0,U.useState)(0),[y,b]=(0,U.useState)(new Map),[x,S]=(0,U.useState)(``),C=(0,U.useRef)(new AbortController);(0,U.useEffect)(()=>{let e=new AbortController;return C.current=e,()=>{e.abort()}},[]);let w=(0,U.useCallback)((t,n)=>s?s(t,n):e.app.capabilities.require(A).call(`app_bonsai`,t,JSON.stringify(n)),[e.app,s]),T=(0,U.useCallback)((e,t)=>Y(e,t,w,C.current.signal,e=>{v(t=>t+(e?1:-1))}),[w]),E=(0,U.useCallback)(()=>{p.invalidateQueries({queryKey:$.all(e.app.identity.surfaceId,t)})},[p,e.app,t]),D=(0,U.useRef)(new Map),O=(0,U.useMemo)(()=>{let r=`${e.app.identity.surfaceId}:${t}:${n}`,i=D.current.get(r);if(i?.app===e.app)return i;let a=X({repository:t,branch:n,request:T,onSaved:E,onSaveState:(e,r)=>{C.current.signal.aborted||b(i=>{let a=new Map(i),o=`${t}:${n}:${e}`;return r===null?a.delete(o):a.set(o,r),a})}}),o={app:e.app,source:a};return D.current.set(r,o),o},[t,n,T,E,e.app]),j=z({connection:O}),M=G({queryKey:$.branch(e.app.identity.surfaceId,t,n),queryFn:()=>Z(T,t,n),refetchInterval:15e3});(0,U.useEffect)(()=>e.app.window.onBeforeClose(j.requestWindowClose),[e.app,j.requestWindowClose]),(0,U.useEffect)(()=>{f?.({requestWindowClose:j.requestWindowClose})},[f,j.requestWindowClose]);let N=(0,U.useRef)(),P=(0,U.useRef)(new Map),F=(0,U.useRef)(new Set);(0,U.useEffect)(()=>{if(!M.data)return;let e=`${O.app.identity.surfaceId}:${O.source.id}:${i}`;N.current!==e&&(N.current=e,j.onOpenFile(r));let t=P.current.get(O.source.id),n=t!==void 0&&t!==M.data.head;P.current.set(O.source.id,M.data.head);let a=new Set(j.tabs.map(e=>e.tabKey));for(let e of F.current)a.has(e)||F.current.delete(e);for(let e of j.tabs)if(!(e.target.closed||e.connection!==O||!n&&!F.current.has(e.tabKey))){if(e.target.saving){F.current.add(e.tabKey);continue}F.current.delete(e.tabKey),e.target.dirty||j.onReopen(e,{background:!0})}},[M.data,O,r,i,j]);let I=j.tabs.find(e=>e.tabKey===j.active),L=I?.connection?.source?y.get(`${I.connection.source.id}:${I.path}`):void 0,R=L?.kind===`saved`?`Saved · syncing`:L?.kind===`synced`?`Synced · ${L.commit.slice(0,7)}`:L?.kind===`conflict`?`Sync conflict · Compare`:L?.kind===`failed`?`Sync failed · Retry`:void 0;async function B(){if(!I?.connection?.source)return;let e=D.current.get(`${I.connection.app.identity.surfaceId}:${I.connection.source.id}`);if(e)try{S(``),await e.source.retry(I.path,C.current.signal)}catch(e){console.error(`Bonsai sync retry failed`,e),S(`Could not retry sync. Your saved text remains in Bonsai.`)}}async function V(){if(!I?.connection?.source)return;let e=()=>!I.target.dirty&&!I.target.saving&&!I.target.closed;if(!e())return;let t=D.current.get(`${I.connection.app.identity.surfaceId}:${I.connection.source.id}`);if(t)try{S(``);let n=await t.source.read(I.path,C.current.signal);if(n.kind!==`text`)throw Error(`This saved text is unavailable.`);if(!e())return;await t.source.replace(I.path,n.contents,n.contents,C.current.signal)}catch(e){console.error(`Bonsai explicit re-save failed`,e),S(`Could not save again. Your saved text and open edits remain available.`)}}return(0,Q.jsxs)(`div`,{className:`inkcap-repository`,children:[(0,Q.jsxs)(`div`,{className:`inkcap-repository-toolbar`,children:[(0,Q.jsxs)(`span`,{className:`inkcap-repository-name`,children:[(0,Q.jsx)(K,{"aria-hidden":`true`}),` `,t,` · `,n]}),(0,Q.jsxs)(l,{size:`sm`,variant:`outline`,onClick:()=>{g(!0)},children:[(0,Q.jsx)(q,{"aria-hidden":`true`,className:`size-[var(--stipe-icon-size-sm)]`}),` `,`History`]})]}),_>0&&(0,Q.jsx)(k,{message:`Loading this repository…`}),M.data?.truncated&&(0,Q.jsx)(H,{tone:`info`,title:`Only the indexed files are shown`}),x&&(0,Q.jsx)(H,{tone:`error`,title:`Sync unavailable`,description:x}),L?.kind===`failed`&&(0,Q.jsx)(H,{tone:`warning`,title:L.reason===`permanent_material`?`Sync needs a new save`:`Sync failed`,description:L.reason===`permanent_material`?`Your text is saved. Save again using the current repository state to retry sync.`:`Your file is saved in Bonsai. Retry when access is available.`,action:(0,Q.jsx)(l,{size:`sm`,disabled:L.reason===`permanent_material`&&I!==void 0&&(I.target.dirty||I.target.saving),onClick:()=>void(L.reason===`permanent_material`?V():B()),children:L.reason===`permanent_material`?`Save again`:`Retry`})}),(0,Q.jsx)(ee,{model:{...j,repositoryStatus:R,repositoryStates:y,canList:!0,sourceLabel:O.source.label,onReadCurrent:async(e,t)=>{if(e.connection?.source?.kind!==`repository`)return j.onReadCurrent(e);let n=D.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,C.current.signal),n.source.readCommitted(e.path,C.current.signal)},error:M.error?`Could not refresh this repository. Your open edits remain available.`:j.error,fileTree:e=>(0,Q.jsx)(te,{files:M.data?.files??[],dirtyPaths:j.tabs.filter(e=>e.connection===O&&e.dirty).map(e=>e.path),activePath:I?.connection===O?I.path:null,busy:M.isFetching,onRefresh:E,onOpenFile:e})}}),(0,Q.jsx)(a,{open:h,onOpenChange:g,children:(0,Q.jsxs)(c,{children:[(0,Q.jsxs)(o,{children:[(0,Q.jsx)(d,{children:`Commit history`}),(0,Q.jsxs)(u,{children:[t,` · `,n]})]}),(0,Q.jsx)(`ol`,{className:`inkcap-repository-history`,children:M.data?.history.map(e=>(0,Q.jsxs)(`li`,{children:[(0,Q.jsx)(`code`,{children:e.hash.slice(0,7)}),` `,e.message,(0,Q.jsx)(`span`,{className:`text-dim`,children:e.author.name})]},e.hash))})]})})]})}export{ne as InkcapRepositoryApp};