@fungi.computer/inkcap 0.18.5 → 0.18.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.
@@ -1,4 +1,4 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Bn as t,Jn as n,Kn as r,Kr as i,Xi as a,Xr as o,Yn as s,Yr as c,Zi as l,Zn as u,a as d,ar as f,c as p,d as m,dr as h,ei as g,er as _,ir as v,l as y,lr as b,o as x,r as S,rr as C,s as w,tr as T,u as E,ur as D}from"./tree-path-DQAnGoeW.js";import{$ as ee,A as O,At as k,B as A,Bt as j,C as te,Ct as M,D as N,Dt as P,E as ne,Et as F,F as I,G as re,H as ie,I as ae,It as oe,J as se,K as L,Kt as ce,L as R,M as le,Mt as ue,N as de,Nt as fe,O as pe,Ot as me,P as he,Pt as ge,Q as _e,R as ve,S as ye,St as be,T as xe,Tt as Se,U as Ce,V as we,Vt as Te,W as Ee,Wt as De,X as Oe,Y as ke,Z as Ae,_ as je,_t as z,a as Me,at as Ne,b as Pe,bt as Fe,c as Ie,ct as Le,d as Re,dt as ze,et as Be,f as Ve,ft as He,g as Ue,gt as We,h as Ge,ht as Ke,i as qe,it as Je,j as Ye,jt as Xe,k as Ze,kt as Qe,l as $e,lt as et,m as tt,mt as nt,n as rt,nt as it,o as at,ot,p as st,pt as ct,q as lt,qt as ut,r as dt,rt as ft,s as pt,st as mt,t as ht,tt as gt,u as _t,ut as vt,v as yt,vt as bt,w as xt,x as St,xt as Ct,y as wt,yt as Tt,z as Et}from"./dropdown-menu-BlFqxqxM.js";import{a as Dt,p as Ot,r as kt,t as At}from"./useForm-CkS3eP5p.js";var jt=D(`Ellipsis`,[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`19`,cy:`12`,r:`1`,key:`1wjl8i`}],[`circle`,{cx:`5`,cy:`12`,r:`1`,key:`1pcz8c`}]]),B=a();function Mt({file:e,renderCustomHeader:t,renderHeaderPrefix:n,renderHeaderFilenameSuffix:i,renderHeaderMetadata:a,renderAnnotation:o,lineAnnotations:s,renderGutterUtility:c,getHoveredLine:l}){let u=t?.(e),d=n?.(e),f=i?.(e),p=a?.(e);return(0,B.jsxs)(B.Fragment,{children:[u==null?(0,B.jsxs)(B.Fragment,{children:[d!=null&&(0,B.jsx)(`div`,{slot:`header-prefix`,children:d}),f!=null&&(0,B.jsx)(`div`,{slot:`header-filename-suffix`,children:f}),p!=null&&(0,B.jsx)(`div`,{slot:`header-metadata`,children:p})]}):(0,B.jsx)(`div`,{slot:r,children:u}),o!=null&&s?.map((e,t)=>(0,B.jsx)(`div`,{slot:Qe(e),children:o(e)},t)),c!=null&&(0,B.jsx)(`div`,{slot:`gutter-utility-slot`,style:k,children:c(l)})]})}function Nt(e){return Se.hasResolvedThemes(e)}function Pt(e,t){return P(e.theme,t.theme)&&e.useTokenTransformer===t.useTokenTransformer&&e.tokenizeMaxLineLength===t.tokenizeMaxLineLength}function Ft(e){return(e.lang??z(e.name))===`text`}var It=10,Lt=13,Rt=4,zt=40;function Bt(e){let t=[0],n=e.indexOf(`\r`),r=e.indexOf(`
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Bn as t,Jn as n,Kn as r,Kr as i,Xi as a,Xr as o,Yn as s,Yr as c,Zi as l,Zn as u,a as d,ar as f,c as p,d as m,dr as h,ei as g,er as _,ir as v,l as y,lr as b,o as x,r as S,rr as C,s as w,tr as T,u as E,ur as D}from"./tree-path-CaOESv-X.js";import{$ as ee,A as O,At as k,B as A,Bt as j,C as te,Ct as M,D as N,Dt as P,E as ne,Et as F,F as I,G as re,H as ie,I as ae,It as oe,J as se,K as L,Kt as ce,L as R,M as le,Mt as ue,N as de,Nt as fe,O as pe,Ot as me,P as he,Pt as ge,Q as _e,R as ve,S as ye,St as be,T as xe,Tt as Se,U as Ce,V as we,Vt as Te,W as Ee,Wt as De,X as Oe,Y as ke,Z as Ae,_ as je,_t as z,a as Me,at as Ne,b as Pe,bt as Fe,c as Ie,ct as Le,d as Re,dt as ze,et as Be,f as Ve,ft as He,g as Ue,gt as We,h as Ge,ht as Ke,i as qe,it as Je,j as Ye,jt as Xe,k as Ze,kt as Qe,l as $e,lt as et,m as tt,mt as nt,n as rt,nt as it,o as at,ot,p as st,pt as ct,q as lt,qt as ut,r as dt,rt as ft,s as pt,st as mt,t as ht,tt as gt,u as _t,ut as vt,v as yt,vt as bt,w as xt,x as St,xt as Ct,y as wt,yt as Tt,z as Et}from"./dropdown-menu-DKDqc_fC.js";import{a as Dt,p as Ot,r as kt,t as At}from"./useForm-B3Yg2hut.js";var jt=D(`Ellipsis`,[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`19`,cy:`12`,r:`1`,key:`1wjl8i`}],[`circle`,{cx:`5`,cy:`12`,r:`1`,key:`1pcz8c`}]]),B=a();function Mt({file:e,renderCustomHeader:t,renderHeaderPrefix:n,renderHeaderFilenameSuffix:i,renderHeaderMetadata:a,renderAnnotation:o,lineAnnotations:s,renderGutterUtility:c,getHoveredLine:l}){let u=t?.(e),d=n?.(e),f=i?.(e),p=a?.(e);return(0,B.jsxs)(B.Fragment,{children:[u==null?(0,B.jsxs)(B.Fragment,{children:[d!=null&&(0,B.jsx)(`div`,{slot:`header-prefix`,children:d}),f!=null&&(0,B.jsx)(`div`,{slot:`header-filename-suffix`,children:f}),p!=null&&(0,B.jsx)(`div`,{slot:`header-metadata`,children:p})]}):(0,B.jsx)(`div`,{slot:r,children:u}),o!=null&&s?.map((e,t)=>(0,B.jsx)(`div`,{slot:Qe(e),children:o(e)},t)),c!=null&&(0,B.jsx)(`div`,{slot:`gutter-utility-slot`,style:k,children:c(l)})]})}function Nt(e){return Se.hasResolvedThemes(e)}function Pt(e,t){return P(e.theme,t.theme)&&e.useTokenTransformer===t.useTokenTransformer&&e.tokenizeMaxLineLength===t.tokenizeMaxLineLength}function Ft(e){return(e.lang??z(e.name))===`text`}var It=10,Lt=13,Rt=4,zt=40;function Bt(e){let t=[0],n=e.indexOf(`\r`),r=e.indexOf(`
2
2
  `),i=0,a=0;for(;n!==-1||r!==-1;){let o;if(n!==-1&&(r===-1||n<r)?r===n+1?(o=r+1,n=e.indexOf(`\r`,o),r=e.indexOf(`
3
3
  `,o)):(o=n+1,n=e.indexOf(`\r`,o)):(o=r+1,r=e.indexOf(`
4
4
  `,o)),t.push(o),++a===Rt){if(o-i<=zt){for(let n=o;n<e.length;n++){let r=e.charCodeAt(n);(r===It||r===Lt)&&(r===Lt&&n+1<e.length&&e.charCodeAt(n+1)===It&&n++,t.push(n+1))}return t}i=o,a=0}}return t}function Vt(e){let t=0;for(let n=0;n<e.length;n++){let r=e.charCodeAt(n);(r===It||r===Lt)&&(r===Lt&&n+1<e.length&&e.charCodeAt(n+1)===It&&n++,t++)}return t}function Ht(e){let t=Bt(e);return Array.from({length:t.length},(n,r)=>{let i=t[r],a=t[r+1]??e.length;return e.slice(i,a)})}var Ut={compositeOverBg:it,contrastRatio:ft,deriveMutedFg:Je,hoverWouldEraseText:Ne,isDarkSurface:ot,isFullyTransparent:mt,pickReadableForeground:Le,relativeLuminance:et,surfacesMatch:vt},Wt={forcePlainText:!1};function Gt(e,t,{theme:n=s,tokenizeMaxLineLength:r,useTokenTransformer:i},{forcePlainText:a,startingLine:o,totalLines:c,lines:l}=Wt){a?(o??=0,c??=1/0):(o=0,c=1/0);let u=o>0||c<1/0,{state:d,transformers:f}=He(i),p=a?`text`:e.lang??z(e.name),m=typeof n==`string`?t.getTheme(n).type:void 0,h=gt({theme:n,highlighter:t});d.lineInfo=e=>({type:`context`,lineIndex:e-1+o,lineNumber:e+o});let g=typeof n==`string`?{lang:p,theme:n,transformers:f,defaultColor:!1,cssVariablePrefix:ze(`token`),tokenizeMaxLineLength:r,tokenizeTimeLimit:0}:{lang:p,themes:n,transformers:f,defaultColor:!1,cssVariablePrefix:ze(`token`),tokenizeMaxLineLength:r,tokenizeTimeLimit:0},_=Be(t.codeToHast(u?Kt(l??Ht(e.contents),o,c):e.contents,g)),v=u?Array(o):_;return u&&v.push(..._),{code:v,themeStyles:h,baseThemeType:m}}function Kt(e,t,n){if(e.length===0)return``;let r=Math.min(t+n,e.length);return e.slice(t,r).join(``)}function qt(e,t){return t.cacheKey==null?e.file===t&&e.sourceContents===t.contents:e.cacheKey===t.cacheKey}var Jt=-1,Yt=class{options;onRenderUpdate;workerManager;__id=`file-renderer:${++Jt}`;highlighter;renderCache;computedLang=`text`;lineAnnotations={};lineCache;pendingStructuralRows;textDocumentCache=new WeakMap;editSessionActive=!1;constructor(e={theme:s},t,n){this.options=e,this.onRenderUpdate=t,this.workerManager=n,n?.isWorkingPool()!==!0&&(this.highlighter=de(e.theme??s)?Tt():void 0)}setOptions(e){this.options=e}mergeOptions(e){this.options={...this.options,...e}}setLineAnnotations(e){this.lineAnnotations={};for(let t of e){let e=this.lineAnnotations[t.lineNumber]??[];this.lineAnnotations[t.lineNumber]=e,e.push(t)}}cleanUp(){this.recycle(),this.workerManager=void 0,this.onRenderUpdate=void 0}beginEditSession(){this.editSessionActive=!0}endEditSession(){this.editSessionActive=!1}editorRenderReady(){return this.renderCache?.options.useTokenTransformer===!0&&this.renderCache.highlighted&&this.renderCache.result!=null}recycle(){this.clearRenderCache(),this.highlighter=void 0,this.workerManager?.cleanUpTasks(this),this.lineCache=void 0,this.endEditSession(),this.textDocumentCache=new WeakMap}syncEditedContentsToFile(){let{renderCache:e,lineCache:t}=this;e?.isDirty!==!0||t==null||!qt(t,e.file)||(e.file.contents=t.lines.join(``))}hasUnkeyedFileContentsChanged(e){let{lineCache:t}=this;return e.cacheKey==null&&t!=null&&t.file===e&&t.sourceContents!==e.contents}invalidateChangedUnkeyedFile(e){this.hasUnkeyedFileContentsChanged(e)&&(this.workerManager?.cleanUpTasks(this),this.clearRenderCache(),this.lineCache=void 0,this.textDocumentCache=new WeakMap)}clearRenderCache(){this.syncEditedContentsToFile(),this.pendingStructuralRows=void 0;let e=this.renderCache;this.renderCache=void 0,e!=null&&e.isDirty===!0&&e.file.cacheKey!=null&&this.workerManager?.evictFileFromCache(e.file.cacheKey)}hydrate(e){let{options:t}=this.getRenderOptions(e),n=Xt(this.getOrCreateLineCache(e).length,this.getTokenizeMaxLength()),r=this.workerManager?.getFileResultCache(e);r!=null&&!Pt(t,r.options)&&(r=void 0),this.renderCache??={file:e,options:t,highlighted:!n&&!Ft(e),result:n?void 0:r?.result,renderRange:void 0},!this.editSessionActive&&this.workerManager?.isWorkingPool()===!0?this.renderCache.result==null&&!n&&this.workerManager.highlightFileAST(this,e):this.highlighter??(this.computedLang=e.lang??z(e.name),this.initializeHighlighter())}getLocalHighlightTheme(){return this.workerManager?.getFileRenderOptions().theme??this.options.theme??s}getEffectiveCodeOptions(){let e=this.workerManager?.isWorkingPool()===!0?this.workerManager.getFileRenderOptions():void 0;return{theme:this.getLocalHighlightTheme(),tokenizeMaxLineLength:e?.tokenizeMaxLineLength??this.options.tokenizeMaxLineLength}}getRenderOptions(e){let t=(()=>{if(this.workerManager?.isWorkingPool()===!0){let e=this.workerManager.getFileRenderOptions();return this.editSessionActive&&e.useTokenTransformer!==!0?{...e,useTokenTransformer:!0}:e}let{tokenizeMaxLineLength:e=1e3}=this.options;return{theme:this.getLocalHighlightTheme(),useTokenTransformer:this.editSessionActive||this.options.useTokenTransformer===!0,tokenizeMaxLineLength:e}})(),{renderCache:n}=this;return n?.result==null||!F(e,n.file)||!Pt(t,n.options)?{options:t,forceHighlight:!0}:{options:t,forceHighlight:!1}}getOrCreateLineCache(e){this.invalidateChangedUnkeyedFile(e);let{lineCache:t}=this;return(t==null||!qt(t,e))&&(t={cacheKey:e.cacheKey,file:e,sourceContents:e.contents,lines:Ht(e.contents)}),this.lineCache=t,t.lines}getLineCount(e){let t=this.getOrCreateLineCache(e);return this.textDocumentCache.get(e)?.lineCount??t.length}updateRenderCache(e,t,n=!1){if(this.pendingStructuralRows=void 0,this.renderCache==null)return;let{file:r,result:i}=this.renderCache;if(i==null)return;let a=n?new Map:void 0;this.pendingStructuralRows=a;let o=this.lineCache!=null&&qt(this.lineCache,r)?this.lineCache:void 0;for(let[t,n]of e){if(a===void 0&&o!=null&&t<o.lines.length){let e=n.map(e=>e[2]).join(``);o.lines[t]=le(o.lines[t]??``,e)}let e={type:`element`,tagName:`div`,properties:{"data-line":t+1,"data-line-type":`context`,"data-line-index":t},children:n.map(([e,t,n])=>e===0&&t===``?n===``?{type:`element`,tagName:`br`,properties:{},children:[]}:{type:`text`,value:n}:{type:`element`,tagName:`span`,properties:{"data-char":e,style:`color:${t};`},children:[{type:`text`,value:n}]})};a===void 0?i.code[t]=e:a.set(t,e)}i.baseThemeType=t,this.renderCache.isDirty=!0}applyDocumentChange(e){let t=this.pendingStructuralRows;if(this.pendingStructuralRows=void 0,this.renderCache==null)return;let{file:n,result:r}=this.renderCache;if(r==null)return;let i=this.lineCache!=null&&qt(this.lineCache,n)?this.lineCache.lines:Ht(n.contents),a=Ht(e.getText());if(i.length!==a.length){let n=Math.min(i.length,a.length),o=0;for(;o<n&&i[o]===a[o];)o++;let s=0;for(;s<n-o&&i[i.length-1-s]===a[a.length-1-s];)s++;let c=r.code;r.code=Array(a.length);for(let e=0;e<o;e++)r.code[e]=c[e];for(let e=0;e<s;e++)r.code[a.length-1-e]=c[i.length-1-e];if(t!==void 0)for(let[e,n]of t)e<a.length&&(r.code[e]=n);for(let t=o;t<a.length-s;t++)r.code[t]??={type:`element`,tagName:`div`,properties:{"data-line":t+1,"data-line-type":`context`,"data-line-index":t},children:[{type:`element`,tagName:`span`,properties:{"data-char":0},children:[{type:`text`,value:e.getLineText(t)}]}]};for(let e=0;e<r.code.length;e++){let t=r.code[e];t?.type===`element`&&(t.properties[`data-line`]=e+1,t.properties[`data-line-index`]=e)}this.renderCache.isDirty=!0}this.lineCache={cacheKey:n.cacheKey,file:n,sourceContents:n.contents,lines:a},this.textDocumentCache.set(n,e)}renderFile(e=this.renderCache?.file,t=n){if(e==null)return;this.invalidateChangedUnkeyedFile(e),this.renderCache?.isDirty===!0&&!F(e,this.renderCache.file)&&(this.clearRenderCache(),this.lineCache=void 0,this.textDocumentCache=new WeakMap);let{options:r,forceHighlight:i}=this.getRenderOptions(e);this.renderCache?.isDirty===!0&&!Pt(r,this.renderCache.options)&&this.clearRenderCache();let a=this.getMatchingWorkerResultCache(e,r);a!=null&&!this.hasHighlightedRenderCache(e,r)&&(this.renderCache={file:e,highlighted:!0,renderRange:void 0,...a},i=!1),this.renderCache??={file:e,highlighted:!1,options:r,result:void 0,renderRange:void 0};let o=this.getOrCreateLineCache(e),s=e.contents.length>0,c=!s||Ft(e)||Xt(o.length,this.getTokenizeMaxLength()),l=!F(e,this.renderCache.file),u=!I(this.renderCache.renderRange,t);if(!this.editSessionActive&&this.workerManager?.isWorkingPool()===!0)(c||this.renderCache.result==null||!this.renderCache.highlighted&&(l||u))&&(this.renderCache.file=e,this.renderCache.options=r,this.renderCache.highlighted=!1,(this.renderCache.result==null||l||u||i)&&(this.renderCache.result=this.workerManager.getPlainFileAST(e,t.startingLine,t.totalLines,o)),this.renderCache.renderRange=t),!c&&s&&(!this.renderCache.highlighted||i)&&this.workerManager.highlightFileAST(this,e);else{this.computedLang=e.lang??z(e.name);let t=this.highlighter!=null&&de(r.theme),n=this.highlighter!=null&&he(this.computedLang),a=!c&&n;if(this.highlighter!=null&&t&&(i||c||!this.renderCache.highlighted&&a||this.renderCache.result==null)){let{result:t,options:r}=this.renderFileWithHighlighter(e,this.highlighter,c||!n);this.renderCache={file:e,options:r,highlighted:a,result:t,renderRange:void 0}}(!t||!c&&!n)&&this.asyncHighlight(e).then(({result:t,options:n})=>{this.renderCache!=null&&(this.renderCache.highlighted=!1),this.applyHighlightResult(e,t,n,!c)})}return this.renderCache.result==null?void 0:this.processFileResult(this.renderCache.file,t,this.renderCache.result)}async asyncRender(e,t=n){let{result:r}=await this.asyncHighlight(e);return this.processFileResult(e,t,r)}async asyncHighlight(e){let t=Xt(this.getOrCreateLineCache(e).length,this.getTokenizeMaxLength());this.computedLang=t?`text`:e.lang??z(e.name);let n=this.highlighter!=null&&Nt(bt(this.getLocalHighlightTheme())),r=t||this.highlighter!=null&&he(this.computedLang);return(this.highlighter==null||!n||!r)&&(this.highlighter=await this.initializeHighlighter()),this.renderFileWithHighlighter(e,this.highlighter,t)}renderFileWithHighlighter(e,t,n=!1){let{options:r}=this.getRenderOptions(e);return{result:Gt(e,t,r,{forcePlainText:n}),options:r}}processFileResult(e,t,{code:n,themeStyles:r,baseThemeType:i}){let a=this.getLineCount(e),{disableFileHeader:o=!1}=this.options,s=[],c=Ke(),l=Math.min(t.startingLine+t.totalLines,a),u=0,d=Ce(t)?we(this.lineAnnotations):void 0;d!=null&&(c.children.push(ct(`context`,`annotation`,1)),s.push(Ye({type:`annotation`,hunkIndex:-1,lineIndex:-1,annotations:d.map(e=>Qe(e))})),u++);for(let r=t.startingLine;r<l;r++){let t=r+1,i=n[r];if(i==null){let n=`FileRenderer.processFileResult: Line doesnt exist`;throw console.error(n,{name:e.name,lineIndex:r,lineNumber:t}),Error(n)}c.children.push(nt(`context`,t,`${r}`)),s.push(i),u++;let a=this.lineAnnotations[t];a!=null&&(c.children.push(ct(`context`,`annotation`,1)),s.push(Ye({type:`annotation`,hunkIndex:0,lineIndex:t,annotations:a.map(e=>Qe(e))})),u++)}return c.properties.style=`grid-row: span ${u}`,{gutterAST:c.children??[],contentAST:s,preAST:this.createPreElement(a),headerAST:o?void 0:this.renderHeader(e),totalLines:a,rowCount:u,themeStyles:r,baseThemeType:i,bufferBefore:t.bufferBefore,bufferAfter:t.bufferAfter,css:``}}renderHeader(e){let{headerRenderMode:t=`default`,stickyHeader:n=!1}=this.options;return Ze({fileOrDiff:e,mode:t,stickyHeader:n})}renderFullHTML(e){return Ct(this.renderFullAST(e))}renderFullAST(e,t=[]){return t.push(We({tagName:`code`,children:this.renderCodeAST(e),properties:{"data-code":``}})),{...e.preAST,children:t}}renderCodeAST(e){let t=Ke();return t.children=e.gutterAST,t.properties.style=`grid-row: span ${e.rowCount}`,[t,O(e.contentAST,e.rowCount)]}renderPartialHTML(e,t=!1){return Ct(t?We({tagName:`code`,children:e,properties:{"data-code":``}}):e)}async initializeHighlighter(){return this.highlighter=await Fe(N(this.computedLang,{theme:this.getLocalHighlightTheme(),preferredHighlighter:this.workerManager?.getPreferredHighlighter()??this.options.preferredHighlighter})),this.highlighter}onHighlightSuccess(e,t,n,r=!0){this.editSessionActive||this.applyHighlightResult(e,t,n,r)}applyHighlightResult(e,t,n,r=!0){if(this.renderCache==null)return;let i=!F(e,this.renderCache.file)||!this.renderCache.highlighted||!Pt(n,this.renderCache.options);this.renderCache={file:e,options:n,highlighted:r,result:t,renderRange:void 0},i&&this.onRenderUpdate?.()}getMatchingWorkerResultCache(e,t){if(this.editSessionActive)return;let n=this.workerManager?.getFileResultCache(e);if(!(n==null||!Pt(t,n.options)))return n}hasHighlightedRenderCache(e,t){let{renderCache:n}=this;return n?.result!=null&&n.highlighted&&F(e,n.file)&&Pt(t,n.options)}onHighlightError(e){console.error(e)}getTokenizeMaxLength(){return this.options.tokenizeMaxLength??1e5}createPreElement(e){let{disableLineNumbers:t=!1,overflow:n=`scroll`}=this.options;return pe({type:`file`,diffIndicators:`none`,disableBackground:!0,disableLineNumbers:t,overflow:n,split:!1,totalLines:e})}};function Xt(e,t){return e>t}function Zt(e,t){return e.lineNumber===t.lineNumber&&e.metadata===t.metadata}function Qt(e){return{theme:e?.theme,disableLineNumbers:e?.disableLineNumbers,overflow:e?.overflow,themeType:e?.themeType,collapsed:e?.collapsed,disableFileHeader:e?.disableFileHeader,disableVirtualizationBuffers:e?.disableVirtualizationBuffers,stickyHeader:e?.stickyHeader,preferredHighlighter:e?.preferredHighlighter,useCSSClasses:e?.useCSSClasses,useTokenTransformer:je(e),tokenizeMaxLineLength:e?.tokenizeMaxLineLength,tokenizeMaxLength:e?.tokenizeMaxLength,unsafeCSS:e?.unsafeCSS,headerRenderMode:e?.renderCustomHeader==null?`default`:`custom`}}var $t=[``],en=-1,tn=class{options;workerManager;isContainerManaged;static LoadedCustomComponent=!0;__id=`file:${++en}`;type=`file`;fileContainer;spriteSVG;pre;code;bufferBefore;bufferAfter;themeCSSStyle;appliedThemeCSS;hasAdoptedThemeCSS=!1;unsafeCSSStyle;appliedUnsafeCSS;gutterUtilityContent;errorWrapper;placeHolder;lastRenderedHeaderHTML;cachedHeaderHTML;appliedPreAttributes;lastRowCount;mounted=!1;headerElement;headerCustom;headerPrefix;headerFilenameSuffix;headerMetadata;fileRenderer;resizeManager;interactionManager;annotationCache=new Map;lineAnnotations=[];managersDirty=!1;file;renderRange;enabled=!0;editor;constructor(e={theme:s},t,n=!1){this.options=e,this.workerManager=t,this.isContainerManaged=n,this.fileRenderer=new Yt(e,this.handleHighlightRender,this.workerManager),this.resizeManager=new ae,this.interactionManager=new R(`file`,ve(e)),this.workerManager?.subscribeToThemeChanges(this)}handleHighlightRender=()=>{this.rerender()};rerender(){!this.enabled||this.file==null||this.render({file:this.file,forceRender:!0,renderRange:this.renderRange})}__getCurrentFile(){return this.file}onThemeChange(){this.fileRenderer.clearRenderCache(),this.rerender()}setOptions(e){e!=null&&(this.options=e,this.cachedHeaderHTML=void 0,this.syncInteractionOptions())}syncInteractionOptions(){this.interactionManager.setOptions(ve(this.options))}mergeOptions(e){this.options={...this.options,...e}}setThemeType(e){(this.options.themeType??`system`)!==e&&(this.mergeOptions({themeType:e}),this.applyCachedThemeState(e))}applyCachedThemeState(e){if(typeof this.options.theme==`string`||this.fileContainer==null||this.appliedThemeCSS==null)return!1;let t=this.appliedThemeCSS.baseThemeType??e;return this.appliedThemeCSS.themeType!==t&&(this.applyThemeState(this.fileContainer,this.appliedThemeCSS.themeStyles,e,this.appliedThemeCSS.baseThemeType),!0)}hasThemeChanged(){return this.appliedThemeCSS!=null&&!P(this.appliedThemeCSS.theme,this.options.theme??s)}getHoveredLine=()=>this.interactionManager.getHoveredLine();setLineAnnotations(e){this.lineAnnotations=e}setSelectedLines(e,t){this.interactionManager.setSelection(e,t)}setEditorActiveLine(e,t){this.interactionManager.setEditorActiveLine(e,{lineNumberOnly:t?.lineNumberOnly,side:t?.side??`additions`})}getCodeScrollLeft(){return this.code?.scrollLeft??0}setCodeScrollLeft(e){this.code!=null&&(this.code.scrollLeft=e)}__getEffectiveCodeOptions(){return{...this.options,...this.fileRenderer.getEffectiveCodeOptions()}}flushManagers(){if(!this.managersDirty||this.pre==null){this.managersDirty=!1;return}let{overflow:e=`scroll`}=this.options;this.interactionManager.setup(this.pre),this.resizeManager.setup(this.pre,{disableAnnotations:e===`wrap`,columnVariables:this.shouldApplyColumnVariables(e)?`apply`:`measure`}),this.managersDirty=!1}shouldApplyColumnVariables(e){return e===`scroll`&&this.lineAnnotations.length>0}cleanUp(e=!1){this.emitPostRender(!0),this.editor?.cleanUp(e),this.editor=void 0,this.resizeManager.cleanUp(),this.interactionManager.cleanUp(),this.managersDirty=!1,this.workerManager?.unsubscribeToThemeChanges(this),this.renderRange=void 0,this.isContainerManaged||this.fileContainer?.remove(),this.fileContainer=void 0,this.mounted=!1,e||(this.lineAnnotations=[]),this.clearAuxiliaryNodes(),this.pre=void 0,this.code=void 0,this.bufferBefore?.remove(),this.bufferBefore=void 0,this.bufferAfter?.remove(),this.bufferAfter=void 0,this.appliedPreAttributes=void 0,this.lastRowCount=void 0,this.headerElement=void 0,this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0,this.headerCustom=void 0,this.lastRenderedHeaderHTML=void 0,e||(this.cachedHeaderHTML=void 0),this.errorWrapper?.remove(),this.errorWrapper=void 0,this.spriteSVG=void 0,this.themeCSSStyle=void 0,this.appliedThemeCSS=void 0,this.hasAdoptedThemeCSS=!1,this.unsafeCSSStyle=void 0,this.appliedUnsafeCSS=void 0,this.placeHolder?.remove(),this.placeHolder=void 0,e?this.fileRenderer.recycle():(this.fileRenderer.cleanUp(),this.workerManager=void 0,this.file=void 0),this.enabled=!1}virtualizedSetup(){this.enabled=!0,this.workerManager?.subscribeToThemeChanges(this)}hydrate(e){let{fileContainer:t,prerenderedHTML:n,preventEmit:r=!1,file:i,lineAnnotations:a}=e;if(!this.enabled)throw Error(`File.hydrate: attempting to call hydrate after cleaned up`);if(this.fileContainer!=null)throw Error(`File.hydrate: hydrate can only be called before the instance has rendered or hydrated`);this.hydrateElements(t,n),nn(this.pre,i,this.options.collapsed)||rn(this.headerElement,i,this.options.disableFileHeader)?this.render({...e,preventEmit:!0}):this.hydrationSetup({file:i,lineAnnotations:a}),r||this.emitPostRender()}hydrateElements(e,t){this.fileContainer!==e&&this.emitPostRender(!0),Re(e,t);for(let t of Array.from(e.shadowRoot?.children??[])){if(t instanceof SVGElement){this.spriteSVG=t;continue}if(t instanceof HTMLElement){if(t instanceof HTMLPreElement){this.pre=t,this.appliedPreAttributes=void 0;continue}if(t instanceof HTMLStyleElement&&t.hasAttribute(`data-theme-css`)){this.themeCSSStyle=t;continue}if(t instanceof HTMLStyleElement&&t.hasAttribute(`data-unsafe-css`)){this.unsafeCSSStyle=t,this.appliedUnsafeCSS=t.textContent;continue}if(`diffsHeader`in t.dataset){this.headerElement=t,this.lastRenderedHeaderHTML=void 0;continue}}}this.pre!=null&&(this.syncCodeNodeFromPre(this.pre),this.pre.removeAttribute(`data-dehydrated`)),this.fileContainer=e,this.hydrateMeasuredScrollbar()}hydrationSetup({file:e,lineAnnotations:t}){this.lineAnnotations=t??this.lineAnnotations,this.file=e,this.fileRenderer.setOptions(Qt(this.options)),this.syncInteractionOptions(),this.pre!=null&&(this.fileRenderer.hydrate(e),this.renderAnnotations(),this.renderGutterUtility(),this.injectUnsafeCSS(),this.managersDirty=!0,this.flushManagers())}getOrCreateLineCache(e=this.file){return e==null?$t:this.fileRenderer.getOrCreateLineCache(e)}updateBuffers(e){this.pre!=null&&this.applyBuffers(this.pre,e)}syncRenderViewToEditor(){let e=this.editor,t=this.fileContainer,n=this.file,r=this.lineAnnotations,i=this.renderRange;e!=null&&t!=null&&n!=null&&this.fileRenderer.initializeHighlighter().then(a=>{!this.enabled||this.editor!==e||this.fileContainer!==t||this.file!==n||e.__syncRenderView(a,t,n,r,i)})}attachEditor(e){this.editor?.cleanUp(),this.editor=e,this.fileRenderer.beginEditSession();let t=this.file==null?void 0:e.__prepareFile?.(this.file);return t!==void 0&&t!==this.file?this.renderPreparedFile({file:t,forceRender:!0,preventEmit:!0,renderRange:this.renderRange}):this.fileRenderer.editorRenderReady()?this.syncRenderViewToEditor():this.rerender(),()=>{this.editor=void 0,this.fileRenderer.endEditSession()}}applyDocumentChange(e,t){this.fileRenderer.applyDocumentChange(e),t!=null&&t!==this.lineAnnotations&&this.file!=null&&(this.setLineAnnotations(t),this.fileRenderer.setLineAnnotations(this.lineAnnotations),this.renderAnnotations())}updateRenderCache(e,t,n){this.fileRenderer.updateRenderCache(e,t,n?.lineCountChangeInFlight)}render(e){if(!this.enabled)throw Error(`File.render: attempting to call render after cleaned up`);let t=this.editor?.__prepareFile?.(e.file)??e.file;return this.renderPreparedFile(t===e.file?e:{...e,file:t})}renderPreparedFile({file:e,fileContainer:t,forceRender:n=!1,preventEmit:r=!1,containerWrapper:i,deferManagers:a=!1,lineAnnotations:o,renderRange:s}){this.editor?.__postponeBgTokenizeToNextFrame();let{collapsed:c=!1,themeType:l=`system`}=this.options,u=c?void 0:s,d=this.renderRange,f=this.hasThemeChanged(),p=o!=null&&(o.length>0||this.lineAnnotations.length>0)&&o!==this.lineAnnotations,m=!F(this.file,e)||this.fileRenderer.hasUnkeyedFileContentsChanged(e);if(!c&&!n&&I(u,this.renderRange)&&!m&&!p&&!f)return this.applyCachedThemeState(l);this.renderRange=u,m&&(this.cachedHeaderHTML=void 0),this.file=e,this.fileRenderer.setOptions(Qt(this.options)),this.syncInteractionOptions(),o!=null&&this.setLineAnnotations(o),this.fileRenderer.setLineAnnotations(this.lineAnnotations);let{disableErrorHandling:h=!1,disableFileHeader:g=!1}=this.options;if(g&&(this.headerElement!=null&&(this.headerElement.remove(),this.headerElement=void 0,this.lastRenderedHeaderHTML=void 0),this.clearHeaderSlots()),t=this.getOrCreateFileContainerNode(t,i),this.applyCachedThemeState(l),c){this.removeRenderedCode(),this.clearAuxiliaryNodes();try{let n=this.fileRenderer.renderFile(e,T);n!=null&&this.applyThemeState(t,n.themeStyles,l,n.baseThemeType),n?.headerAST!=null&&this.applyHeaderToDOM(n.headerAST,t),this.injectUnsafeCSS()}catch(e){if(h)throw e;console.error(e),e instanceof Error&&this.applyErrorToDOM(e,t)}return r||this.emitPostRender(),!0}try{let r=this.getOrCreatePreNode(t);if(!this.canPartiallyRender(n,p,m||f)||!this.applyPartialRender(d,u)){let n=this.fileRenderer.renderFile(e,u);if(n==null)return this.workerManager?.isInitialized()===!1&&this.workerManager.initialize().then(()=>this.rerender()),!1;this.applyThemeState(t,n.themeStyles,l,n.baseThemeType),n.headerAST!=null&&this.applyHeaderToDOM(n.headerAST,t),this.applyFullRender(n,r)}this.applyBuffers(r,u),this.injectUnsafeCSS(),this.renderAnnotations(),this.renderGutterUtility(),this.managersDirty=!0,a||this.flushManagers(),this.editor!=null&&this.syncRenderViewToEditor()}catch(e){if(h)throw e;console.error(e),e instanceof Error&&this.applyErrorToDOM(e,t)}return r||this.emitPostRender(),!0}emitPostRender(e=!1){let{fileContainer:t,options:{onPostRender:n}}=this;if(e){if(!this.mounted||(this.mounted=!1,t==null))return;n?.(t,this,`unmount`);return}if(t==null)return;let r=this.mounted?`update`:`mount`;this.mounted=!0,n?.(t,this,r)}removeRenderedCode(){this.resizeManager.cleanUp(),this.interactionManager.cleanUp(),this.bufferBefore?.remove(),this.bufferBefore=void 0,this.bufferAfter?.remove(),this.bufferAfter=void 0,this.code?.remove(),this.code=void 0,this.pre?.remove(),this.pre=void 0,this.appliedPreAttributes=void 0,this.lastRowCount=void 0}clearAuxiliaryNodes(){for(let{element:e}of this.annotationCache.values())e.remove();this.annotationCache.clear(),this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0}canPartiallyRender(e,t,n){return!(e||t||n)}renderPlaceholder(e){if(this.fileContainer==null)return!1;if(this.emitPostRender(!0),this.cleanChildNodes(),this.placeHolder==null){let e=this.fileContainer.shadowRoot??this.fileContainer.attachShadow({mode:`open`});this.placeHolder=document.createElement(`div`),this.placeHolder.dataset.placeholder=``,e.appendChild(this.placeHolder)}return this.placeHolder.style.setProperty(`height`,`${e}px`),!0}async primeHighlightCache(e=this.file){let{workerManager:t}=this;if(e==null||t==null||!t.isWorkingPool()||e.cacheKey==null||Ft(e))return;let n=this.options.tokenizeMaxLength??1e5;this.fileRenderer.getOrCreateLineCache(e).length>n||await t.primeFileHighlightCache(e).catch(e=>{console.error(e)})}cleanChildNodes(){this.resizeManager.cleanUp(),this.interactionManager.cleanUp(),this.clearAuxiliaryNodes(),this.bufferAfter?.remove(),this.bufferBefore?.remove(),this.code?.remove(),this.errorWrapper?.remove(),this.headerElement?.remove(),this.headerPrefix?.remove(),this.headerFilenameSuffix?.remove(),this.headerMetadata?.remove(),this.headerCustom?.remove(),this.pre?.remove(),this.spriteSVG?.remove(),this.themeCSSStyle?.remove(),this.unsafeCSSStyle?.remove(),this.bufferAfter=void 0,this.bufferBefore=void 0,this.code=void 0,this.errorWrapper=void 0,this.headerElement=void 0,this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0,this.headerCustom=void 0,this.pre=void 0,this.spriteSVG=void 0,this.themeCSSStyle=void 0,this.appliedThemeCSS=void 0,this.hasAdoptedThemeCSS=!1,this.unsafeCSSStyle=void 0,this.appliedUnsafeCSS=void 0,this.lastRenderedHeaderHTML=void 0,this.lastRowCount=void 0,this.mounted=!1}renderAnnotations(){if(this.isContainerManaged||this.fileContainer==null){for(let{element:e}of this.annotationCache.values())e.remove();this.annotationCache.clear();return}let e=new Map(this.annotationCache),{renderAnnotation:t}=this.options;if(t!=null&&this.lineAnnotations.length>0)for(let[n,r]of this.lineAnnotations.entries()){let i=`${n}-${Qe(r)}`,a=this.annotationCache.get(i);if(a==null||!Zt(r,a.annotation)){a?.element.remove();let e=t(r);if(e==null)continue;a={element:xt(Qe(r)),annotation:r},a.element.appendChild(e),this.fileContainer.appendChild(a.element),this.annotationCache.set(i,a)}e.delete(i)}for(let[t,{element:n}]of e.entries())this.annotationCache.delete(t),n.remove()}renderGutterUtility(){let{renderGutterUtility:e}=this.options;if(this.fileContainer==null||e==null){this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0;return}let t=e(this.interactionManager.getHoveredLine);if(t!=null&&this.gutterUtilityContent!=null)return;if(t==null){this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0;return}let n=te();n.appendChild(t),this.fileContainer.appendChild(n),this.gutterUtilityContent=n}injectUnsafeCSS(){let{unsafeCSS:e}=this.options,t=this.fileContainer?.shadowRoot;if(t!=null){if(e==null||e===``){this.unsafeCSSStyle!=null&&(this.unsafeCSSStyle.remove(),this.unsafeCSSStyle=void 0),this.appliedUnsafeCSS=void 0;return}(this.unsafeCSSStyle?.parentNode!==t||this.appliedUnsafeCSS!==e)&&(this.unsafeCSSStyle??=ye(),this.unsafeCSSStyle.parentNode!==t&&t.appendChild(this.unsafeCSSStyle),this.unsafeCSSStyle.textContent=Pe(e),this.appliedUnsafeCSS=e)}}applyThemeState(e,t,n,r){let i=e.shadowRoot??e.attachShadow({mode:`open`}),a=r??n,o=this.options.theme??s,c=typeof o==`string`?o:{...o},l=St(i);if(this.themeCSSStyle?.parentNode===i&&this.appliedThemeCSS?.themeStyles===t&&this.appliedThemeCSS.themeType===a&&this.appliedThemeCSS.scrollbarGutter===l){this.appliedThemeCSS.theme=c;return}if(this.hasAdoptedThemeCSS&&this.themeCSSStyle?.parentNode===i){this.hasAdoptedThemeCSS=!1,this.appliedThemeCSS={theme:c,themeStyles:t,themeType:a,baseThemeType:r,scrollbarGutter:l};return}this.themeCSSStyle=tt({shadowRoot:i,currentNode:this.themeCSSStyle,themeCSS:wt(t,a,l)}),this.appliedThemeCSS=this.themeCSSStyle==null?void 0:{theme:c,themeStyles:t,themeType:a,baseThemeType:r,scrollbarGutter:l}}hydrateMeasuredScrollbar(){let e=this.fileContainer?.shadowRoot;e!=null&&this.themeCSSStyle!=null&&(this.themeCSSStyle.textContent=yt(this.themeCSSStyle.textContent??``,St(e)))}shouldGuardRebuildScroll(){return this.editor!=null&&st()}applyFullRender(e,t){this.cleanupErrorWrapper(),this.applyPreNodeAttributes(t,e);let n=this.code=Ue({code:this.code}),r=this.fileRenderer.renderCodeAST(e);this.editor?.__captureFocusForDOMReplacement();let i=()=>{if(n.childElementCount>=2)for(let e=0;e<2;e++){let t=n.children[e],i=r[e];t.innerHTML=Ct(i.children),t.style.cssText=i.properties.style}else n.innerHTML=Ct(r);t.contains(n)||t.replaceChildren(n)};this.shouldGuardRebuildScroll()?Ge(t,i):i(),this.lastRowCount=e.rowCount}applyPartialRender(e,t){if(e==null||t==null)return!1;let{file:n,code:r}=this,i=r==null?void 0:this.getColumns(r);if(n==null||r==null||i==null)return!1;let a=e.startingLine,o=t.startingLine,s=e.totalLines===1/0?1/0:a+e.totalLines,c=t.totalLines===1/0?1/0:o+t.totalLines,l=Math.max(a,o),u=Math.min(s,c);if(u<=l)return!1;if(!this.trimDOMToOverlap(i.gutter,l,u)||!this.trimDOMToOverlap(i.content,l,u))throw Error(`File.applyPartialRender: failed to trim to overlap`);let{length:d}=i.content.children,f=(e,t)=>{if(!(t<=0))return this.fileRenderer.renderFile(n,{startingLine:e,totalLines:t,bufferBefore:0,bufferAfter:0})},p=o<l?f(o,l-o):void 0;if(p===void 0&&o<l)return!1;let m=c===1/0?1/0:Math.max(0,c-u),h=c>u?f(u,m):void 0;return h===void 0&&c>u?!1:(this.cleanupErrorWrapper(),p!=null&&(i.gutter.insertAdjacentHTML(`afterbegin`,this.fileRenderer.renderPartialHTML(p.gutterAST)),i.content.insertAdjacentHTML(`afterbegin`,this.fileRenderer.renderPartialHTML(p.contentAST)),d+=p.rowCount),h!=null&&(i.gutter.insertAdjacentHTML(`beforeend`,this.fileRenderer.renderPartialHTML(h.gutterAST)),i.content.insertAdjacentHTML(`beforeend`,this.fileRenderer.renderPartialHTML(h.contentAST)),d+=h.rowCount),this.lastRowCount!==d&&(i.gutter.style.setProperty(`grid-row`,`span ${d}`),i.content.style.setProperty(`grid-row`,`span ${d}`),this.lastRowCount=d),!0)}getColumns(e){let t=e.children[0],n=e.children[1];if(!(!(t instanceof HTMLElement)||!(n instanceof HTMLElement)||t.dataset.gutter==null||n.dataset.content==null))return{gutter:t,content:n}}trimDOMToOverlap(e,t,n){let r=this.getDOMBoundaryIndices(e,[t,n]),i=r.get(t)??e.children.length,a=r.get(n)??e.children.length;if(i>a)return!1;for(let t=e.children.length-1;t>=a;--t)e.children[t]?.remove();for(let t=i-1;t>=0;--t)e.children[t]?.remove();return!0}getDOMBoundaryIndices(e,t){let n=[...new Set(t)].sort((e,t)=>e-t),r=new Map;if(n.length===0)return r;let i=0,a=n[i],{children:o}=e;a===0&&(r.set(0,0),i+=1,a=n[i]);for(let e=0;e<o.length;e+=1){let t=o[e];if(!(t instanceof HTMLElement))continue;let s=this.getLineIndexFromDOMNode(t);if(s!=null){for(;a!=null&&s>=a;)r.set(a,e),i+=1,a=n[i];if(i>=n.length)break}}for(let e of n)r.has(e)||r.set(e,o.length);return r}getLineIndexFromDOMNode(e){let t=e.dataset.lineIndex;if(t==null)return;let n=Number(t);return Number.isNaN(n)?void 0:n}applyBuffers(e,t){if(t==null||this.shouldDisableVirtualizationBuffers()){this.bufferBefore!=null&&(this.bufferBefore.remove(),this.bufferBefore=void 0),this.bufferAfter!=null&&(this.bufferAfter.remove(),this.bufferAfter=void 0);return}t.bufferBefore>0?(this.bufferBefore??(this.bufferBefore=document.createElement(`div`),this.bufferBefore.dataset.virtualizerBuffer=`before`,e.before(this.bufferBefore)),this.bufferBefore.style.setProperty(`height`,`${t.bufferBefore}px`),this.bufferBefore.style.setProperty(`contain`,`strict`)):this.bufferBefore!=null&&(this.bufferBefore.remove(),this.bufferBefore=void 0),t.bufferAfter>0?(this.bufferAfter??(this.bufferAfter=document.createElement(`div`),this.bufferAfter.dataset.virtualizerBuffer=`after`,e.after(this.bufferAfter)),this.bufferAfter.style.setProperty(`height`,`${t.bufferAfter}px`),this.bufferAfter.style.setProperty(`contain`,`strict`)):this.bufferAfter!=null&&(this.bufferAfter.remove(),this.bufferAfter=void 0)}shouldDisableVirtualizationBuffers(){return this.options.disableVirtualizationBuffers??!1}applyHeaderToDOM(e,t){let{file:n}=this;if(n==null)return;this.cleanupErrorWrapper(),this.placeHolder?.remove(),this.placeHolder=void 0;let i=this.cachedHeaderHTML??Ct(e);if(this.cachedHeaderHTML=i,i!==this.lastRenderedHeaderHTML){let e=document.createElement(`div`);e.innerHTML=i;let n=e.firstElementChild;if(!(n instanceof HTMLElement))return;this.headerElement==null?t.shadowRoot?.prepend(n):t.shadowRoot?.replaceChild(n,this.headerElement),this.headerElement=n,this.lastRenderedHeaderHTML=i}if(this.isContainerManaged)return;let{renderHeaderPrefix:a,renderHeaderFilenameSuffix:o,renderCustomHeader:s,renderHeaderMetadata:c}=this.options;if(s!=null){let e=s(n)??void 0;this.headerCustom=this.upsertHeaderSlotElement(t,this.headerCustom,r,e),this.headerPrefix?.remove(),this.headerFilenameSuffix?.remove(),this.headerMetadata?.remove(),this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0}else{let e=a?.(n)??void 0,r=o?.(n)??void 0,i=c?.(n)??void 0;this.headerPrefix=this.upsertHeaderSlotElement(t,this.headerPrefix,f,e),this.headerFilenameSuffix=this.upsertHeaderSlotElement(t,this.headerFilenameSuffix,C,r),this.headerMetadata=this.upsertHeaderSlotElement(t,this.headerMetadata,v,i),this.headerCustom?.remove(),this.headerCustom=void 0}}clearHeaderSlots(){this.headerPrefix?.remove(),this.headerFilenameSuffix?.remove(),this.headerMetadata?.remove(),this.headerCustom?.remove(),this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0,this.headerCustom=void 0}upsertHeaderSlotElement(e,t,n,r){if(r==null){t?.remove();return}let i=t??this.createHeaderSlotElement(n);return t??e.appendChild(i),this.replaceHeaderSlotContent(i,r),i}replaceHeaderSlotContent(e,t){e.replaceChildren(),t instanceof Element?e.appendChild(t):e.innerText=`${t}`}createHeaderSlotElement(e){let t=document.createElement(`div`);return t.slot=e,t}getOrCreateFileContainerNode(e,t){let{fileContainer:n}=this,r=e??n??document.createElement(`diffs-container`),i=n!==r;return n!=null&&i&&this.editor?.__captureFocusForDOMReplacement(),i&&this.emitPostRender(!0),this.fileContainer=r,n!=null&&i&&(this.lastRenderedHeaderHTML=void 0,this.headerElement=void 0),t!=null&&this.fileContainer.parentNode!==t&&t.appendChild(this.fileContainer),i&&this.adoptReusableShellElements(this.fileContainer),this.ensureSpriteSVG(this.fileContainer),this.fileContainer}adoptReusableShellElements(e){let{shadowRoot:t}=e;if(t!=null)for(let e of t.children)e instanceof SVGElement?this.spriteSVG??=e:Ee(e)&&e.hasAttribute(`data-theme-css`)?(this.themeCSSStyle??=e,this.hasAdoptedThemeCSS=!0):Ee(e)&&e.hasAttribute(`data-unsafe-css`)&&(this.unsafeCSSStyle??=e,this.appliedUnsafeCSS??=this.options.unsafeCSS??void 0)}ensureSpriteSVG(e){let t=e.shadowRoot??e.attachShadow({mode:`open`});if(this.spriteSVG==null){let e=document.createElement(`div`);e.innerHTML=ne;let t=e.firstChild;t instanceof SVGElement&&(this.spriteSVG=t)}this.spriteSVG!=null&&this.spriteSVG.parentNode!==t&&t.appendChild(this.spriteSVG)}getOrCreatePreNode(e){let t=e.shadowRoot??e.attachShadow({mode:`open`});return this.pre==null?(this.pre=document.createElement(`pre`),this.appliedPreAttributes=void 0,this.code=void 0,t.appendChild(this.pre)):this.pre.parentNode!==t&&(this.editor?.__captureFocusForDOMReplacement(),e.shadowRoot?.appendChild(this.pre),this.appliedPreAttributes=void 0),this.placeHolder?.remove(),this.placeHolder=void 0,this.pre}syncCodeNodeFromPre(e){this.code=void 0;for(let t of Array.from(e.children))if(t instanceof HTMLElement&&t.hasAttribute(`data-code`)){this.code=t;return}}applyPreNodeAttributes(e,{totalLines:t}){let{overflow:n=`scroll`,disableLineNumbers:r=!1}=this.options,i={type:`file`,split:!1,overflow:n,disableLineNumbers:r,diffIndicators:`none`,disableBackground:!0,totalLines:t};xe(i,this.appliedPreAttributes)||(_t(e,i),this.appliedPreAttributes=i)}applyErrorToDOM(e,t){this.cleanupErrorWrapper(),this.pre?.remove(),this.pre=void 0,this.appliedPreAttributes=void 0;let n=t.shadowRoot??t.attachShadow({mode:`open`});this.errorWrapper??=document.createElement(`div`),this.errorWrapper.dataset.errorWrapper=``,this.errorWrapper.textContent=``,n.appendChild(this.errorWrapper);let r=document.createElement(`div`);r.dataset.errorMessage=``,r.innerText=e.message,this.errorWrapper.appendChild(r);let i=document.createElement(`pre`);i.dataset.errorStack=``,i.innerText=e.stack??`No Error Stack`,this.errorWrapper.appendChild(i)}cleanupErrorWrapper(){this.errorWrapper?.remove(),this.errorWrapper=void 0}};function nn(e,t,n=!1){return!n&&e==null&&t!=null}function rn(e,t,n=!1){return e==null&&t!=null&&!n}var an=5e3,on=-1;function sn(e,t){return(e.overflow??`scroll`)!==(t.overflow??`scroll`)||(e.collapsed??!1)!==(t.collapsed??!1)||(e.disableLineNumbers??!1)!==(t.disableLineNumbers??!1)||(e.disableFileHeader??!1)!==(t.disableFileHeader??!1)||e.unsafeCSS!==t.unsafeCSS}var cn=class extends tn{virtualizer;metrics;__id=`virtualized-file:${++on}`;top;height=0;cache={heights:new Map,checkpoints:[],fileAnnotationHeight:0};isVisible=!1;isSetup=!1;layoutDirty=!0;forceRenderOverride;currentCollapsed;constructor(e,t,n=u,r,i=!1){super(e,r,i),this.virtualizer=t,this.metrics=n}setMetrics(e,t=!1){let n=Ae(e);!t&&ke(this.metrics,n)||(this.metrics=n,this.resetLayoutCache())}setLineAnnotations(e){this.syncLineAnnotations(e)&&this.resetLayoutCache()}syncLineAnnotations(e){return e==null||e===this.lineAnnotations||e.length===0&&this.lineAnnotations.length===0?!1:(super.setLineAnnotations(e),!0)}hasLineAnnotations(){return this.lineAnnotations.some(e=>e.lineNumber>0)}getLineHeight(e,t=!1){let n=this.cache.heights.get(e);if(n!=null)return n;let r=t?2:1;return this.metrics.lineHeight*r}setOptions(e){if(this.isAdvancedMode())throw Error(`VirtualizedFile.setOptions cannot be used inside CodeView. Update CodeView options instead.`);if(e==null)return;let{options:t}=this,n=!se(t,e),r=sn(t,e);super.setOptions(e),r&&this.resetLayoutCache(!0),n&&(this.forceRenderOverride=!0),n&&this.virtualizer.instanceChanged(this,r)}setThemeType(e){if(this.isAdvancedMode())throw Error(`VirtualizedFile.setThemeType cannot be used inside CodeView. Update CodeView options instead.`);super.setThemeType(e)}resetLayoutCache(e=!1,t=!0){this.layoutDirty=!0,this.cache.fileAnnotationHeight=0,this.cache.heights.size>0&&this.cache.heights.clear(),this.cache.checkpoints.length>0&&(this.cache.checkpoints.length=0),this.renderRange!=null&&t&&(this.renderRange=void 0),e&&this.isSimpleMode()&&this.computeApproximateSize()}reconcileHeights(){let e=!1;if(this.fileContainer==null||this.file==null)return this.height!==0&&(e=!0),this.height=0,e;let{overflow:t=`scroll`}=this.options;if(this.top=this.getVirtualizedTop(),t===`scroll`&&this.lineAnnotations.length===0&&!this.isResizeDebuggingEnabled()||this.code==null)return e;let n=this.code.children[1];if(!(n instanceof HTMLElement))return e;let r=ie(this.lineAnnotations);if(this.renderRange!=null&&r&&Ce(this.renderRange)){let t=ln(n)??0;t!==this.cache.fileAnnotationHeight&&(this.cache.fileAnnotationHeight=t,e=!0)}else!r&&this.cache.fileAnnotationHeight!==0&&(this.cache.fileAnnotationHeight=0,e=!0);for(let t of n.children){if(!(t instanceof HTMLElement))continue;let n=t.dataset.lineIndex;if(n==null)continue;let r=Number(n),i=t.getBoundingClientRect().height,a=!1;t.nextElementSibling instanceof HTMLElement&&(`lineAnnotation`in t.nextElementSibling.dataset||`noNewline`in t.nextElementSibling.dataset)&&(`noNewline`in t.nextElementSibling.dataset&&(a=!0),i+=t.nextElementSibling.getBoundingClientRect().height);let o=this.getLineHeight(r,a);i!==o&&(e=!0,i===this.metrics.lineHeight*(a?2:1)?this.cache.heights.delete(r):this.cache.heights.set(r,i))}return(e||this.isResizeDebuggingEnabled())&&this.computeApproximateSize(!0),e}onRender=e=>this.fileContainer==null||this.file==null?!1:(e&&(this.top=this.getVirtualizedTop()),this.render({file:this.file}));prepareCodeViewItem(e,t,n,r){let i=this.syncLineAnnotations(r),a=!F(this.file,e)||this.fileRenderer.hasUnkeyedFileContentsChanged(e),o=n?.resetFileLayoutCache===!0||a||i;n?.metrics!=null&&(this.metrics=n.metrics,o=!0);let{collapsed:s=!1}=this.options;return this.currentCollapsed!==s&&(this.currentCollapsed=s,o=!0),o&&this.resetLayoutCache(),this.file!==e&&(this.layoutDirty=!0),this.file=e,this.top=t,this.computeApproximateSize(),this.height}getLinePosition(e){if(this.file==null||e<1)return;let{disableFileHeader:t=!1,collapsed:n=!1}=this.options,r=this.fileRenderer.getLineCount(this.file)-1,i=_e(this.metrics,t);if(n||r<0)return{top:i,height:0};let a=Math.min(Math.max(e-1,0),r),{overflow:o=`scroll`}=this.options,{lineHeight:s}=this.metrics;if(i+=this.cache.fileAnnotationHeight,o===`scroll`&&!this.hasLineAnnotations())return{top:i+a*s,height:s};let c=this.getLayoutCheckpointBeforeLineIndex(a);i=c?.top??i;for(let e=c?.lineIndex??0;e<a;e++)i+=this.getLineHeight(e,!1);return{top:i,height:this.getLineHeight(a,!1)}}getEditorViewport(){return this.virtualizer.type===`simple`?this.virtualizer.getRoot():this.virtualizer.getContainerElement()}getNumericScrollAnchor(e){if(this.file==null||this.renderRange==null)return;let{disableFileHeader:t=!1,collapsed:n=!1,overflow:r=`scroll`}=this.options;if(n||this.renderRange.totalLines<=0)return;let i=this.fileRenderer.getLineCount(this.file)-1;if(i<0)return;let a=_e(this.metrics,t),o=Math.min(this.renderRange.startingLine,i),s=Math.min(o+this.renderRange.totalLines-1,i);if(s<o)return;let{fileAnnotationHeight:c}=this.cache;if(r===`scroll`&&!this.hasLineAnnotations()){let{lineHeight:t}=this.metrics,n=a+(o===0?c:this.renderRange.bufferBefore),r=o+Math.max(Math.ceil((e-n)/t),0);return r>s?void 0:{lineNumber:r+1,top:a+c+r*t}}let l=a+(o===0?c:this.renderRange.bufferBefore);for(let t=o;t<=s;t++){if(l>=e)return{lineNumber:t+1,top:l};l+=this.getLineHeight(t)}}getVirtualizedHeight(){return this.height}getAdvancedStickySpecs(e){if(this.top==null||this.file==null)return;if(this.options.collapsed===!0)return{topOffset:this.top,height:this.height};let t=e==null?this.renderRange:this.computeRenderRangeFromWindow(this.file,this.top,e);if(t==null)return;let{bufferBefore:n,bufferAfter:r,totalLines:i}=t,a=0;if(i===0){let t=e??this.virtualizer.getWindowSpecs();this.top<t.top&&(a=r)}return{topOffset:this.top+n+a,height:this.height-(n+r)}}cleanUp(e=!1){this.fileContainer!=null&&this.isSimpleMode()&&this.getSimpleVirtualizer()?.disconnect(this.fileContainer),e||this.resetLayoutCache(),this.isSetup=!1,super.cleanUp(e)}computeApproximateSize(e=!1,t=this.file){let n=this.isResizeDebuggingEnabled();if(!e&&!this.layoutDirty&&!n)return;let r=this.height===0;if(this.height=0,this.cache.checkpoints=[],t==null){this.layoutDirty=!1;return}let{disableFileHeader:i=!1,collapsed:a=!1,overflow:o=`scroll`}=this.options,{lineHeight:s}=this.metrics,c=this.fileRenderer.getLineCount(t),l=_e(this.metrics,i),u=ee(this.metrics);if(this.height+=l,a){this.layoutDirty=!1;return}if(this.height+=this.cache.fileAnnotationHeight,o===`scroll`&&!this.hasLineAnnotations())this.height+=c*s;else for(let e=0;e<c;e++)this.addLayoutCheckpoint(e,this.height),this.height+=this.getLineHeight(e,!1);if(c>0&&(this.height+=u),this.fileContainer!=null&&n&&!r){let e=this.fileContainer.getBoundingClientRect();e.height===this.height?console.log(`VirtualizedFile.computeApproximateSize: computed height IS CORRECT`):console.log(`VirtualizedFile.computeApproximateSize: computed height doesnt match`,{name:t.name,elementHeight:e.height,computedHeight:this.height})}this.layoutDirty=!1}setVisibility(e){this.isAdvancedMode()||this.fileContainer==null||(this.renderRange=void 0,e&&!this.isVisible?(this.top=this.getVirtualizedTop(),this.isVisible=!0):!e&&this.isVisible&&(this.isVisible=!1,this.rerender()))}rerender(){!this.enabled||this.file==null||(this.forceRenderOverride=!0,this.virtualizer.instanceChanged(this,!1))}applyDocumentChange(e,t,n=!1){let{renderRange:r}=this;if(this.getAdvancedVirtualizer()?.capturePendingLayoutAnchor(),super.applyDocumentChange(e,t),this.getSimpleVirtualizer()?.markDOMDirty(),this.resetLayoutCache(this.isSimpleMode(),!1),!this.isSimpleMode())this.computeApproximateSize(!0);else if(n&&r!==void 0&&this.file!==void 0){let e=this.virtualizer.getWindowSpecs(),t=this.computeRenderRangeFromWindow(this.file,this.top??0,e);t.bufferAfter!==r.bufferAfter&&this.updateBuffers(t)}this.forceRenderOverride=!0,this.virtualizer.instanceChanged(this,!0)}renderPreparedFile({fileContainer:e,file:t,forceRender:n=!1,lineAnnotations:r,...i}){let a=this.file==null||!F(this.file,t)||this.fileRenderer.hasUnkeyedFileContentsChanged(t),{forceRenderOverride:o,isSetup:s}=this;this.forceRenderOverride=void 0;let c=this.syncLineAnnotations(r);if(c&&this.resetLayoutCache(),e=this.getOrCreateFileContainerNode(e),t==null)return console.error(`VirtualizedFile.render: attempting to virtually render when we dont have file`),!1;if(s)this.top??=this.getVirtualizedTop(),a&&this.isSimpleMode()&&(this.getSimpleVirtualizer()?.markDOMDirty(),this.resetLayoutCache(!1),this.computeApproximateSize(!1,t));else{this.computeApproximateSize(!1,t);let n=this.getSimpleVirtualizer();if(this.top??=this.getVirtualizedTop(),this.isAdvancedMode())this.isVisible=!0;else{if(n==null)throw Error(`VirtualizedFile.render: simple virtualizer is not available`);n.connect(e,this),this.isVisible=n.isInstanceVisible(this.top??0,this.height)}this.isSetup=!0}if(!this.isVisible&&this.isSimpleMode()&&(!a||!s))return this.file=t,a&&(this.cachedHeaderHTML=void 0),this.renderPlaceholder(this.height);let l=this.virtualizer.getWindowSpecs(),u=this.top??0,d=this.computeRenderRangeFromWindow(t,u,l),f=super.renderPreparedFile({file:t,fileContainer:e,renderRange:d,lineAnnotations:r,forceRender:(o??n)||c||a,...i});return this.isSimpleMode()&&f&&this.getSimpleVirtualizer()?.requestHeightReconcile(this),f}syncVirtualizedTop(){this.top=this.getVirtualizedTop()}shouldDisableVirtualizationBuffers(){return this.isAdvancedMode()||super.shouldDisableVirtualizationBuffers()}shouldGuardRebuildScroll(){return!1}isSimpleMode(){return this.virtualizer.type===`simple`}isAdvancedMode(){return this.virtualizer.type===`advanced`}addLayoutCheckpoint(e,t){e%an===0&&this.cache.checkpoints.push({lineIndex:e,top:t})}getLayoutCheckpointBeforeLineIndex(e){if(e<=0||this.cache.checkpoints.length===0)return;let t=0,n=this.cache.checkpoints.length-1,r;for(;t<=n;){let i=t+n>>1,a=this.cache.checkpoints[i];if(a==null)throw Error(`VirtualizedFile: invalid checkpoint index`);a.lineIndex<=e?(r=a,t=i+1):n=i-1}return r}getLayoutCheckpointBeforeTop(e,t){let n=0,r=this.cache.checkpoints.length-1,i=-1;for(;n<=r;){let t=n+r>>1,a=this.cache.checkpoints[t];if(a==null)throw Error(`VirtualizedFile: invalid checkpoint index`);a.top<=e?(i=t,n=t+1):r=t-1}if(t==null)return i>=0?this.cache.checkpoints[i]:void 0;for(let e=i;e>=0;e--){let n=this.cache.checkpoints[e];if(n==null)throw Error(`VirtualizedFile: invalid checkpoint index`);if(n.lineIndex%t===0)return n}}getVirtualizedTop(){return this.virtualizer.type===`advanced`?this.virtualizer.getLocalTopForInstance(this):this.fileContainer==null?0:this.virtualizer.getOffsetInScrollContainer(this.fileContainer)}getSimpleVirtualizer(){return this.virtualizer.type===`simple`?this.virtualizer:void 0}getAdvancedVirtualizer(){return this.virtualizer.type===`advanced`?this.virtualizer:void 0}isResizeDebuggingEnabled(){return this.getSimpleVirtualizer()?.config.resizeDebugging??!1}computeRenderRangeFromWindow(e,t,{top:n,bottom:r}){let{disableFileHeader:i=!1,overflow:a=`scroll`}=this.options,{hunkLineCount:o,lineHeight:s}=this.metrics,c=this.fileRenderer.getLineCount(e),l=this.height,u=_e(this.metrics,i),d=c>0?ee(this.metrics):0,{fileAnnotationHeight:f}=this.cache,p=u+f,m=Math.max(0,l-u-f-d),h=ie(this.lineAnnotations),g=t+u,_=f>0&&h&&g<r&&g+f>n;if(t<n-l||t>r)return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:l-u-d};if(c<=o)return{startingLine:0,totalLines:o,bufferBefore:0,bufferAfter:0};let v=Math.ceil(Math.max(r-n,0)/s),y=Math.ceil(v/o)*o+o,b=y/o,x=(n+r)/2;if(a===`scroll`&&!this.hasLineAnnotations()){let e=t+p,i=e+m;if(!_&&!(e<r&&i>n))return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:l-u-d};let a=Math.floor(_&&x<t+p?0:(x-(t+p))/s),h=Math.floor(a/o)-Math.floor(b/2),g=Math.ceil(c/o),v=Math.max(0,Math.min(h,g))*o,S=h<0?y+h*o:y,C=v===0?0:f+v*s,w=Math.min(S,c-v);return{startingLine:v,totalLines:S,bufferBefore:C,bufferAfter:Math.max(0,(c-v-w)*s)}}let S=b,C=[],w=this.getLayoutCheckpointBeforeTop(Math.max(0,n-t-y*s*2),o),T=t+(w?.top??p),E=w?.lineIndex??0,D,O,k,A=w?.lineIndex??0;for(let e=A;e<c;e++){let i=E%o===0,a=Math.floor(E/o);if(i&&(C[a]=T-(t+p),k!=null)){if(k<=0)break;k--}let s=this.getLineHeight(e,!1);T>n-s&&T<r&&(D??=a),T+s>x&&(O??=a),k==null&&T>=r&&i&&(k=S),E++,T+=s}if(D==null){if(_)D=0,O=0;else return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:l-u-d}}O??=D;let j=Math.round(O-b/2),te=Math.max(0,Math.ceil(c/o)-b),M=Math.max(0,Math.min(j,te)),N=M*o,P=j<0?y+j*o:y,ne=C[M]??0,F=N===0?0:f+ne,I=M+P/o,re=I<C.length?m-C[I]:m-(T-t-p);return{startingLine:N,totalLines:P,bufferBefore:F,bufferAfter:Math.max(0,re)}}};function ln(e){let t;for(let n of e.children)n instanceof HTMLElement&&n.dataset.lineAnnotation===A&&(t=Math.max(t??0,n.getBoundingClientRect().height));return t}var V=e(l(),1),un=typeof window>`u`?V.useEffect:V.useLayoutEffect;function dn({file:e,options:t,editorOptions:n,lineAnnotations:r,selectedLines:i,prerenderedHTML:a,metrics:o,hasGutterRenderUtility:s,hasCustomHeader:c,disableWorkerPool:l,edit:u}){let d=Ie(),f=i!==void 0,p=(0,V.useContext)(Oe),m=fe(),h=(0,V.useRef)(null),g=ge(n=>{if(n!=null){if(h.current!=null)throw Error(`File: An instance should not already exist when a node is created`);d==null?h.current=new tn(fn({controlledSelection:f,hasCustomHeader:c,hasGutterRenderUtility:s,options:t}),l?void 0:p,!0):h.current=new cn(fn({controlledSelection:f,hasCustomHeader:c,hasGutterRenderUtility:s,options:t}),d,o,l?void 0:p,!0),h.current.hydrate({file:e,fileContainer:n,lineAnnotations:r,prerenderedHTML:a})}else{if(h.current==null)throw Error(`File: A File instance should exist when unmounting`);h.current.cleanUp(),h.current=null}});return un(()=>{if(h.current==null)return;let n=fn({controlledSelection:f,hasCustomHeader:c,hasGutterRenderUtility:s,options:t}),a=n!==void 0&&!se(h.current.options,n);h.current.setOptions(n),h.current.render({file:e,lineAnnotations:r,forceRender:a}),i!==void 0&&h.current.setSelectedLines(i)}),un(()=>{if(u&&h.current!=null){if(m===void 0)throw Error(`File: EditContext is not attached`);let e=m(n??{});if(e==null)throw Error(`File: EditProvider.createEditor must return an editor instance`);try{return e.edit(h.current)}catch(t){throw e.cleanUp(),t}}},[u]),{ref:g,getHoveredLine:(0,V.useCallback)(()=>h.current?.getHoveredLine(),[])}}function fn({options:e,controlledSelection:t,hasCustomHeader:n,hasGutterRenderUtility:r}){return t||r||n?{...e,controlledSelection:t,renderCustomHeader:n?Xe:e?.renderCustomHeader,renderGutterUtility:r?Xe:e?.renderGutterUtility}:e}function pn({file:e,lineAnnotations:t,selectedLines:n,options:r,editorOptions:i,metrics:a,className:o,style:s,renderAnnotation:c,renderCustomHeader:l,renderHeaderPrefix:u,renderHeaderFilenameSuffix:d,renderHeaderMetadata:f,prerenderedHTML:p,renderGutterUtility:m,disableWorkerPool:h=!1,edit:g=!1}){let{ref:v,getHoveredLine:y}=dn({file:e,options:r,editorOptions:i,metrics:a,lineAnnotations:t,selectedLines:n,prerenderedHTML:p,hasGutterRenderUtility:m!=null,hasCustomHeader:l!=null,disableWorkerPool:h,edit:g});return(0,B.jsx)(_,{ref:v,className:o,style:s,children:$e(Mt({file:e,renderAnnotation:c,renderCustomHeader:l,renderHeaderPrefix:u,renderHeaderFilenameSuffix:d,renderHeaderMetadata:f,renderGutterUtility:m,lineAnnotations:t,getHoveredLine:y}),p)})}function mn({oldFile:e,newFile:t,options:n,editorOptions:r,metrics:i,lineAnnotations:a,selectedLines:o,className:s,style:c,prerenderedHTML:l,renderAnnotation:u,renderCustomHeader:d,renderHeaderPrefix:f,renderHeaderFilenameSuffix:p,renderHeaderMetadata:m,renderGutterUtility:h,disableWorkerPool:g=!1,edit:v=!1}){let y=(0,V.useMemo)(()=>re(e,t,n?.parseDiffOptions),[e,t,n?.parseDiffOptions]),{ref:b,getHoveredLine:x}=pt({fileDiff:y,options:n,editorOptions:r,metrics:i,lineAnnotations:a,selectedLines:o,prerenderedHTML:l,hasGutterRenderUtility:h!=null,hasCustomHeader:d!=null,disableWorkerPool:g,edit:v});return(0,B.jsx)(_,{ref:b,className:s,style:c,children:$e(me({fileDiff:y,renderCustomHeader:d,renderHeaderPrefix:f,renderHeaderFilenameSuffix:p,renderHeaderMetadata:m,renderAnnotation:u,lineAnnotations:a,renderGutterUtility:h,getHoveredLine:x}),l)})}function hn(e){if(e.local){if(e.closed)return{status:`unavailable`,reason:`This draft is closed.`}}else if(e.closed||!e.savable)return{status:`unavailable`,reason:`No focused savable document.`};return e.saving?{status:`unavailable`,reason:`A save is already running.`}:!e.local&&!e.dirty?{status:`unavailable`,reason:`No unsaved changes.`}:{status:`available`}}var gn=100,_n=1,vn=2,yn=3,bn=class{#e=[];#t=[];#n;#r=!1;constructor(e){this.#n=Math.max(1,e?.maxEntries??gn)}get canUndo(){return this.#e.length>0}get canRedo(){return this.#t.length>0}clear(){this.#e.length=0,this.#t.length=0,this.#r=!1}clearRedo(){this.#t.length=0}push(e){this.#e.push(e),this.clearRedo(),this.#r=!0,this.#e.length>this.#n&&this.#e.shift()}setLastUndoSelectionsAfter(e){let t=this.#e[this.#e.length-1];t!==void 0&&(t.selectionsAfter=e.map(e=>({...e})))}setLastUndoLineAnnotations(e,t){let n=this.#e[this.#e.length-1];n!==void 0&&(n.lineAnnotationsBefore=e.slice(),n.lineAnnotationsAfter=t.slice())}peekUndo(){return this.#e[this.#e.length-1]}peekUndoForCoalescing(){return this.#r?this.peekUndo():void 0}replaceLastUndo(e){if(this.#e.length===0){this.push(e);return}this.#e[this.#e.length-1]=e,this.clearRedo(),this.#r=!0}popUndoToRedo(){let e=this.#e.pop();if(e!==void 0)return this.#t.push(e),this.#r=!1,e}popRedoToUndo(){let e=this.#t.pop();if(e!==void 0)return this.#e.push(e),this.#r=!1,e}};function xn(e,t,n,r,i,a,o,s){let c=[...t].sort((e,t)=>e.start-t.start),l=[],u;if(i?.length===c.length){let t=[];for(let n of i){if(n.start.line!==n.end.line||n.start.character!==n.end.character)break;t.push(e.offsetAt(n.start))}if(t.length===c.length){t.sort((e,t)=>e-t);let e=!0,n=!0;for(let r=0;r<c.length;r++){let i=c[r];if(i.text.length>0||i.start===i.end){e=!1,n=!1;break}e&&=t[r]===i.end,n&&=t[r]===i.start}u=e?vn:n?yn:void 0}}for(let t=0,n=0;t<c.length;t++){let r=c[t],i=e.getTextSlice(r.start,r.end),a=r.start+n;l.push({start:a,end:a+r.text.length,text:i}),n+=r.text.length-(r.end-r.start)}return{forwardEdits:c.map(e=>({...e})),inverseEdits:l,versionBefore:n,versionAfter:r,selectionsBefore:i?.map(e=>({...e})),selectionsAfter:a?.map(e=>({...e})),lineAnnotationsBefore:o?.slice(),lineAnnotationsAfter:s?.slice(),coalescingMode:u}}function Sn(e,t){if(e===void 0||e.undoBoundary===!0||t.undoBoundary===!0||e.forwardEdits.length===0||e.forwardEdits.length!==e.inverseEdits.length||e.forwardEdits.length!==t.forwardEdits.length||t.forwardEdits.length!==t.inverseEdits.length)return!1;let n;for(let r=0;r<e.forwardEdits.length;r++){let i=e.forwardEdits[r],a=e.inverseEdits[r],o=t.forwardEdits[r],s=t.inverseEdits[r],c=Tn(o.start,e.forwardEdits),l=i.start<=i.end&&i.text.length>0&&!i.text.includes(`
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{$ as t,$a as n,$i as r,A as i,Aa as a,B as o,Ba as s,Bi as c,Bn as l,Bt as u,C as d,Cn as f,D as p,Dn as m,E as h,En as g,F as _,Fa as v,G as y,Ga as b,Gi as x,Gr as S,Gt as C,H as w,Ha as T,Hi as E,Hr as D,Ht as O,I as k,Ia as A,J as j,Ji as M,Jr as N,K as P,Ka as F,Ki as I,Kr as L,L as R,La as ee,Li as te,Ln as ne,Lr as re,M as ie,N as ae,Nn as oe,O as se,P as z,Pa as ce,Q as le,Qa as ue,Qi as de,Qr as fe,Ra as pe,Ri as me,Rt as he,S as ge,Sa as _e,Sn as ve,St as ye,T as be,Tn as xe,U as Se,Ua as Ce,Ui as we,Ur as Te,Ut as B,V as Ee,Va as De,Vi as Oe,Vt as ke,W as Ae,Wa as je,Wi as Me,Wr as Ne,X as Pe,Xa as V,Xi as Fe,Y as Ie,Yr as Le,Za as Re,Zi as ze,Zt as Be,_n as Ve,_r as He,a as Ue,aa as We,ai as Ge,b as Ke,bt as qe,c as Je,ca as H,ci as Ye,cn as Xe,ct as Ze,d as Qe,di as $e,dr as U,ea as et,eo as tt,et as nt,fa as rt,fi as it,g as at,gr as ot,h as st,ha as ct,hr as lt,i as ut,ia as dt,ii as ft,in as pt,j as mt,jn as ht,k as gt,kn as _t,la as vt,li as yt,lr as bt,m as xt,mi as St,mr as Ct,n as wt,ni as Tt,nn as W,nt as Et,oi as Dt,on as Ot,p as kt,pa as At,pi as jt,pn as Mt,q as Nt,qa as Pt,qi as Ft,qt as It,ri as Lt,rt as Rt,s as zt,sa as Bt,si as Vt,st as Ht,tn as Ut,to as Wt,tt as Gt,u as Kt,ua as qt,ui as Jt,ur as G,ut as Yt,v as Xt,va as K,wn as Zt,x as Qt,y as $t,yr as en,yt as tn,z as nn,za as rn,zi as an,zn as on}from"./tree-path-DQAnGoeW.js";import{C as sn,D as cn,Ft as ln,O as un,Rt as dn,_ as fn,a as pn,b as q,c as mn,f as hn,g as gn,h as _n,i as vn,l as yn,m as bn,n as xn,o as Sn,p as Cn,r as wn,s as Tn,t as En,u as Dn,v as On,w as kn,x as An,y as jn}from"./changes-patch-DhbNb84Y.js";import{a as Mn,c as Nn,d as Pn,f as Fn,i as In,l as Ln,n as Rn,o as zn,p as Bn,r as Vn,s as Hn,t as Un,u as Wn}from"./useForm-CkS3eP5p.js";import{n as Gn,r as Kn,t as qn}from"./useFileTree-D7u_RYsd.js";var Jn=M(`ZodMiniType`,(e,t)=>{if(!e._zod)throw Error(`Uninitialized schema in ZodMiniType.`);c.init(e,t),e.def=t,e.type=t.type,e.parse=(t,n)=>Oe(e,t,n,{callee:e.parse}),e.safeParse=(t,n)=>we(e,t,n),e.parseAsync=async(t,n)=>E(e,t,n,{callee:e.parseAsync}),e.safeParseAsync=async(t,n)=>Me(e,t,n),e.check=(...n)=>e.clone({...t,checks:[...t.checks??[],...n.map(e=>typeof e==`function`?{_zod:{check:e,def:{check:`custom`},onattach:[]}}:e)]},{parent:!0}),e.with=e.check,e.clone=(t,n)=>x(e,t,n),e.brand=()=>e,e.register=((t,n)=>(t.add(e,n),e)),e.apply=t=>t(e)}),Yn=M(`ZodMiniObject`,(e,t)=>{an.init(e,t),Jn.init(e,t),I(e,`shape`,()=>t.shape)});function Xn(e,t){return new Yn({type:`object`,shape:e??{},...Ft(t)})}var Zn=M(`ZodMiniLiteral`,(e,t)=>{me.init(e,t),Jn.init(e,t)});function Qn(e,t){return new Zn({type:`literal`,values:Array.isArray(e)?e:[e],...Ft(t)})}var $n=G(`Check`,[[`path`,{d:`M20 6 9 17l-5-5`,key:`1gmf2c`}]]),er=G(`ChevronRight`,[[`path`,{d:`m9 18 6-6-6-6`,key:`mthhwq`}]]),tr=G(`EyeOff`,[[`path`,{d:`M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49`,key:`ct8e1f`}],[`path`,{d:`M14.084 14.158a3 3 0 0 1-4.242-4.242`,key:`151rxh`}],[`path`,{d:`M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143`,key:`13bj9a`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}]]),nr=G(`Eye`,[[`path`,{d:`M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0`,key:`1nclc0`}],[`circle`,{cx:`12`,cy:`12`,r:`3`,key:`1v7zrd`}]]),rr=G(`FileImage`,[[`path`,{d:`M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z`,key:`1rqfz7`}],[`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`,key:`tnqrlb`}],[`circle`,{cx:`10`,cy:`12`,r:`2`,key:`737tya`}],[`path`,{d:`m20 17-1.296-1.296a2.41 2.41 0 0 0-3.408 0L9 22`,key:`wt3hpn`}]]),ir=G(`FolderPlus`,[[`path`,{d:`M12 10v6`,key:`1bos4e`}],[`path`,{d:`M9 13h6`,key:`1uhe8q`}],[`path`,{d:`M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z`,key:`1kt360`}]]),ar=G(`RotateCcw`,[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}]]),J=e(ze(),1);function or(e){let{open:t,defaultOpen:n=!1,onOpenChange:r,disabled:i}=e,[a,o]=Xe({controlled:t,default:n,name:`Collapsible`,state:`open`}),{mounted:s,setMounted:c,transitionStatus:l}=O(a,!0,!0),u=It(),[d,p]=J.useState(),m=d===null?void 0:d??u,h=W(e=>{let t=!a,n=C(f,e.nativeEvent);r(t,n),!n.isCanceled&&o(t)});return J.useMemo(()=>({defaultPanelId:u,disabled:i,handleTrigger:h,mounted:s,open:a,panelId:m,setMounted:c,setOpen:o,setPanelIdState:p,transitionStatus:l}),[u,i,h,s,a,m,c,o,p,l])}var sr=J.createContext(void 0);function cr(){let e=J.useContext(sr);if(e===void 0)throw Error(on(15));return e}var lr=`data-open`,ur=`data-closed`,dr=_t,fr=`data-panel-open`,pr={[lr]:``},mr={[ur]:``},hr={open(e){return e?{[fr]:``}:null}},gr={open(e){return e?pr:mr},...m},Y=Fe(),_r=J.forwardRef(function(e,t){let{render:n,className:r,defaultOpen:i=!1,disabled:a=!1,onOpenChange:o,open:s,style:c,...l}=e,u=W(o),d=or({open:s,defaultOpen:i,onOpenChange:u,disabled:a}),f=J.useMemo(()=>({open:d.open,disabled:d.disabled,transitionStatus:d.transitionStatus}),[d.open,d.disabled,d.transitionStatus]),p=J.useMemo(()=>({...d,onOpenChange:u,state:f}),[d,u,f]),m=ht(`div`,e,{state:f,ref:t,props:l,stateAttributesMapping:gr});return(0,Y.jsx)(sr.Provider,{value:p,children:m})}),vr={...hr,...m},yr=J.forwardRef(function(e,t){let{panelId:n,open:r,handleTrigger:i,state:a,disabled:o}=cr(),{className:s,disabled:c=o,render:l,nativeButton:u=!0,style:d,...f}=e,{getButtonProps:p,buttonRef:m}=Be({disabled:c,native:u});return ht(`button`,e,{state:a,ref:[t,m],props:[{"aria-controls":r?n:void 0,"aria-expanded":r,onClick:i},f,p],stateAttributesMapping:vr})}),X={height:void 0,width:void 0};function br(e){let{externalRef:t,hiddenUntilFound:n,id:r,keepMounted:i,mounted:a,onOpenChange:o,open:s,setMounted:c,setOpen:l,transitionStatus:d}=e,f=J.useRef(null),p=J.useRef(null),[m,h]=J.useState(X),g=J.useRef(X),_=J.useRef(!1),v=J.useRef(s),y=J.useRef(!1),[b,x]=J.useState(!1),S=J.useRef(null),w=ne(t,f),T=qe(s),E=ke(f),D=!s&&!a,O=b?`idle`:d,k=s&&(v.current||y.current),A=!s&&a&&p.current===`css-animation`&&m.height===void 0&&m.width===void 0?g.current:m,j=n&&D&&p.current!==`css-animation`,M=W((e,t=!0)=>{t&&(g.current=e),h(e)}),N=W(()=>{S.current?.(),S.current=null}),P=W(e=>{N(),S.current=()=>{S.current=null,e()}}),F=W(()=>{s&&a&&p.current===`css-animation`&&(y.current=!0)});Ut(()=>{!b||d===`starting`||x(!1)},[b,d]),J.useEffect(()=>()=>{F(),N()},[F,N]),Ut(()=>{s||(v.current=!1,y.current=!1);let e=f.current;if(!e)return;!s&&S.current&&N();let t=xr(e,k);if(p.current=t,s&&d===`idle`&&v.current&&t===`css-animation`){g.current=Z(e);return}if(s&&d===`starting`){let n=_.current;if(_.current=!1,t===`none`){M(Z(e)),x(!0);return}if(t===`css-transition`){let t=wr(e);if(M(Z(e)),!n)return t;let r=Cr(e,`transition-duration`,`0s`);return P(r),x(!0),t}M(Z(e));let r=Cr(e,`animation-name`,`none`);if(!n){r();return}let i=Cr(e,`animation-duration`,`0s`);r(),P(i),x(!0);return}if(!s&&a&&(d===`idle`||d===`starting`)){if(t===`none`){M(X,!1),c(!1);return}M(Z(e));return}if(d!==`ending`)return;if(t===`none`){c(!1);return}let n=Z(e);if(!(n.height>0||n.width>0)){c(!1);return}M(n),t===`css-animation`&&Cr(e,`animation-name`,`none`)()},[a,s,N,M,c,P,k,d]),u({enabled:s&&a&&O===`idle`,open:!0,ref:f,onComplete(){s&&M(X,!1)}}),J.useEffect(()=>{if(s||!a||O!==`ending`)return;if(!f.current){c(!1),M(X,!1);return}let e=new AbortController,t=-1;function n(){T.current||(c(!1),M(X,!1))}return t=B.request(()=>{E(n,e.signal)}),()=>{B.cancel(t),e.abort()}},[T,a,s,O,E,M,c]),Ut(()=>{let e=f.current;!e||!n||!D||e.setAttribute(`hidden`,`until-found`)},[D,n]),J.useEffect(function(){let e=f.current;if(!e)return;let t=he.create(),n=-1,r=(r,i)=>{t.start(0,()=>{T.current||(n=B.request(()=>{T.current||(r&&(_.current=!1),i&&e.setAttribute(dr,``),e.setAttribute(`hidden`,`until-found`))}))})},i=ye(e,`beforematch`,t=>{let n=C(Ve,t);if(o(!0,n),n.isCanceled){r(!1,!1);return}_.current=!0;let i=e.hasAttribute(dr);e.removeAttribute(dr),l(!0),r(!0,i)});return()=>{t.clear(),B.cancel(n),i()}},[T,o,l]);let I=i||n||a||s;return{height:A.height,props:{...j?{[dr]:``}:void 0,hidden:D,id:r},ref:w,shouldPreventOpenAnimation:k,shouldRender:I,transitionStatus:O,width:A.width}}function Z(e){return{height:e.scrollHeight,width:e.scrollWidth}}function xr(e,t){let n=pt(e).getComputedStyle(e),r=(n.animationName.split(`,`).map(e=>e.trim()).some(e=>e!==``&&e!==`none`)||t)&&Sr(n.animationDuration),i=Sr(n.transitionDuration);return r&&i||i?`css-transition`:r?`css-animation`:`none`}function Sr(e){return e.split(`,`).map(e=>e.trim()).some(e=>e!==``&&Number.parseFloat(e)>0)}function Cr(e,t,n){let r=e.style.getPropertyValue(t),i=e.style.getPropertyPriority(t);return e.style.setProperty(t,n),()=>{if(r===``){e.style.removeProperty(t);return}e.style.setProperty(t,r,i)}}function wr(e){let t={"justify-content":e.style.justifyContent,"align-items":e.style.alignItems,"align-content":e.style.alignContent,"justify-items":e.style.justifyItems};Object.keys(t).forEach(t=>{e.style.setProperty(t,`initial`,`important`)});function n(){Object.entries(t).forEach(([t,n])=>{if(n===``){e.style.removeProperty(t);return}e.style.setProperty(t,n)})}let r=B.request(n);return()=>{B.cancel(r),n()}}var Tr=`--collapsible-panel-height`,Er=`--collapsible-panel-width`,Dr=J.forwardRef(function(e,t){let{className:n,hiddenUntilFound:r,keepMounted:i,render:a,id:o,style:s,...c}=e,{defaultPanelId:l,mounted:u,onOpenChange:d,open:f,setMounted:p,setPanelIdState:m,setOpen:h,state:g,transitionStatus:_}=cr(),v=r??!1,y=i??!1,b=o||void 0,x=b??l;Ut(()=>(m(e=>b??(e===null?void 0:e)),()=>{m(e=>e===b?null:e)}),[b,m]);let{height:S,props:C,ref:w,shouldPreventOpenAnimation:T,shouldRender:E,transitionStatus:D,width:O}=br({externalRef:t,hiddenUntilFound:v,id:x,keepMounted:y,mounted:u,onOpenChange:d,open:f,setMounted:p,setOpen:h,transitionStatus:_}),k={...g,transitionStatus:D},A=oe(s,k),j=ht(`div`,{...e,style:void 0},{state:k,ref:w,props:[C,{style:{[Tr]:S===void 0?`auto`:`${S}px`,[Er]:O===void 0?`auto`:`${O}px`}},c,A?{style:A}:void 0,T?{style:{animationName:`none`}}:void 0],stateAttributesMapping:gr});return E?j:null}),Or=N(`caps-disclosure`,{variants:{tone:{neutral:``,error:`caps-disclosure-error`},size:{group:`caps-disclosure-group`,row:`caps-disclosure-row`}},defaultVariants:{tone:`neutral`,size:`group`}});function kr({open:e,onOpenChange:t,summary:n,leading:r,trailing:i,children:a,tone:o,size:s,className:c}){return(0,Y.jsxs)(_r,{className:L(Or({tone:o,size:s}),c),onOpenChange:t,open:e,children:[(0,Y.jsxs)(yr,{className:`caps-disclosure-trigger`,children:[r===void 0?null:(0,Y.jsx)(`span`,{className:`caps-disclosure-leading`,children:r}),(0,Y.jsx)(`span`,{className:`caps-disclosure-summary`,children:n}),i===void 0?null:(0,Y.jsx)(`span`,{className:`caps-disclosure-trailing`,children:i}),(0,Y.jsx)(er,{"aria-hidden":`true`,className:`caps-disclosure-chevron`,size:12})]}),(0,Y.jsx)(Dr,{className:`caps-disclosure-panel`,children:a})]})}function Ar({app:e,rootPath:t,rootLabel:n=`Computer`,activePath:r,onOpenFile:i,onSelectPath:a,rowHeight:o=32}){let{scope:s,snapshot:c,focusedPath:l,requestPage:u,reload:d}=gn({app:e,rootPath:t,activePath:r}),f=(0,J.useRef)({activePath:r,onOpenFile:i,onSelectPath:a,rootLabel:n});f.current={activePath:r,onOpenFile:i,onSelectPath:a,rootLabel:n};let p=(0,J.useRef)(u);p.current=u;let{model:m}=qn({paths:[],itemHeight:o,initialExpansion:2,flattenEmptyDirectories:!1,composition:{contextMenu:{enabled:!0}},renderRowDecoration:({row:e})=>e.path===`/`?{text:f.current.rootLabel}:null,unsafeCSS:`[data-item-section="content"] { display: flex; align-items: center; }[data-item-path="/"] [data-item-section="decoration"] { justify-content: flex-start; color: inherit; }`,onSelectionChange(e){let t=e[0];t&&(f.current.onSelectPath?.(t),t.endsWith(`/`)?p.current(t,0):t!==f.current.activePath&&f.current.onOpenFile(t))}}),h=(0,J.useRef)(Dn()),g=(0,J.useRef)(null);(0,J.useLayoutEffect)(()=>{Cn(m,h.current),g.current=null},[m,s]),(0,J.useLayoutEffect)(()=>{g.current=null;for(let e of m.getSelectedPaths())!e.endsWith(`/`)&&e!==r&&m.getItem(e)?.deselect()},[r,m]),(0,J.useLayoutEffect)(()=>{if(c.listings.length===0&&(g.current=null),_n(m,c.listings,h.current),!r||g.current===r)return;let e=bn(r,t);if(!e.every(e=>h.current.known.has(e)))return;for(let t of e){let e=m.getItem(t);e&&`expand`in e&&e.expand()}let n=m.getItem(r);n&&(g.current=r,n.select(),m.scrollToPath(r,{focus:!1}))},[r,m,t,s,c.listings]),(0,J.useEffect)(()=>{c.failure&&console.error(`Inkcap directory listing failed`,dn(c.failure))},[c.failure]);let _=c.listings.filter(({request:e})=>e.path===l).sort((e,t)=>e.request.offset-t.request.offset).at(-1)?.listing,v={path:_?.path??l,next:_?.nextOffset??null},y=c.listings.some(({request:e,listing:n})=>e.path===t&&e.offset===0&&n.entries.length===0&&n.nextOffset===null),b=d;return{model:m,page:v,error:c.failure?`${fe(c.failure).message} Your open files remain available.`:``,busy:c.busy,rootEmpty:y,reloadRoot:b,noteCreated:e=>{let t=e.split(`/`).filter(Boolean).at(-1)??``;!hn({name:t,type:``})&&!m.getItem(e)&&m.batch([{type:`add`,path:e}]),b()},loadNext:()=>{v.next!==null&&u(v.path,v.next)}}}var jr=K(H),Mr=K(vt({message:H}));function Nr(e){for(let t of e.errors){let e=Re(Wt(n(Mr(t),e=>e.message),()=>jr(t)));if(e!==void 0&&e.length>0)return e}}var Pr={neutral:`progress-neutral`,primary:`progress-primary`,secondary:`progress-secondary`,accent:`progress-accent`,success:`progress-success`,info:`progress-info`,warning:`progress-warning`,error:`progress-error`},Fr=(0,J.forwardRef)(function({className:e,tone:t=`primary`,...n},r){return(0,Y.jsx)(`progress`,{...n,"data-complete":n.value!==void 0&&Number(n.value)>=Number(n.max??1)?`true`:void 0,className:L(`progress caps-gooey-motion caps-gooey-progress w-full`,Pr[t],e),ref:r})});(0,J.forwardRef)(function({label:e,value:t,max:n,tone:r=`info`,className:i,...a},o){return(0,Y.jsxs)(`div`,{...a,ref:o,className:L(`caps-game-meter`,i),children:[(0,Y.jsxs)(`div`,{className:`caps-game-meter-readout`,children:[(0,Y.jsx)(`span`,{children:e}),(0,Y.jsxs)(`span`,{className:`caps-game-meter-value`,children:[t,` / `,n]})]}),(0,Y.jsx)(Fr,{"aria-label":e,value:t,max:n,tone:r})]})});function Ir({className:e,items:t,onCancel:n,onRemove:r,onRetry:i,rowClassName:a}){return t.length?(0,Y.jsx)(`div`,{"aria-live":`polite`,className:`caps-upload-queue flex w-full min-w-0 flex-col gap-sm ${e??``}`,"data-upload-rows":!0,children:t.map(e=>(0,Y.jsx)(zr,{item:e,onCancel:n,onRemove:r,onRetry:i,...a===void 0?{}:{rowClassName:a}},e.id))}):null}function Lr({action:e,id:t,onAction:n,retry:r=!1}){return e?(0,Y.jsx)(l,{"aria-label":e.accessibleLabel,title:e.label,variant:`ghost`,size:`xs`,className:`motion-reduce:transition-none`,icon:r?(0,Y.jsx)(ar,{}):(0,Y.jsx)(bt,{}),onClick:()=>void n(t),type:`button`}):null}function Rr({item:e}){return(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsx)(`span`,{className:`block min-w-0 truncate`,title:e.name,children:e.name}),(0,Y.jsx)(`div`,{className:`caps-upload-details`,children:(0,Y.jsxs)(`span`,{"aria-live":e.alert?`assertive`:void 0,className:`caps-upload-status min-w-0 break-words`,"data-upload-status":!0,role:e.alert?`alert`:void 0,children:[e.alert??e.statusLabel,` `,e.progressLabel]})})]})}function zr({item:e,onCancel:t,onRemove:n,onRetry:r,rowClassName:i}){return(0,Y.jsxs)(`div`,{className:`caps-upload-row grid w-full min-w-0 max-w-full grid-cols-[2rem_minmax(0,1fr)_auto] items-center gap-sm p-sm text-xs ${i??``}`,children:[e.preview.kind===`image`?(0,Y.jsx)(`img`,{alt:``,className:`caps-upload-preview mask mask-squircle size-8 shrink-0 object-cover`,src:e.preview.url}):(0,Y.jsx)(`span`,{"aria-hidden":`true`,className:`caps-upload-preview mask mask-squircle flex size-8 shrink-0 items-center justify-center bg-base-300`,children:(0,Y.jsx)(rr,{className:`size-4`})}),(0,Y.jsx)(Rr,{item:e}),(0,Y.jsx)(Br,{actions:e.actions,id:e.id,onCancel:t,onRemove:n,onRetry:r}),(0,Y.jsx)(Fr,{"aria-label":`${e.name} progress`,className:`caps-upload-progress`,tone:e.alert?`error`:e.progress===100?`success`:`accent`,max:100,value:e.progress??(e.alert?0:void 0)})]})}function Br({actions:e,id:t,onCancel:n,onRemove:r,onRetry:i}){return(0,Y.jsxs)(`div`,{className:`caps-upload-actions flex min-w-0 flex-wrap justify-end gap-xs`,children:[(0,Y.jsx)(Lr,{action:e.retry,id:t,onAction:i,retry:!0}),(0,Y.jsx)(Lr,{action:e.cancel,id:t,onAction:n}),(0,Y.jsx)(Lr,{action:e.remove,id:t,onAction:r})]})}var Vr={unchecked:`M3.25 5.9 L5.1 7.9 L8.8 3.8`,checked:`M3.25 5.9 L5.1 7.9 L8.8 3.8`,mixed:`M3.4 6 L6 6 L8.6 6`},Hr={blurStdDeviation:.22,alphaSlope:18,alphaIntercept:-8};function Ur({state:e}){let t=`caps-checkbox-${(0,J.useId)().replaceAll(`:`,``)}`,n=(0,J.useRef)(null),r=(0,J.useRef)(e).current,i=(0,J.useRef)(e),a=S();return(0,J.useLayoutEffect)(()=>{if(!n.current)return;let t=e!==`unchecked`,r=i.current!==`unchecked`,o=a||i.current===e;i.current=e;let s=Te(n.current),c=q(s,{ease:`inCubic`,duration:160}),l=en(n.current,{d:{to:Vr[e],...o?jn:q(s,{ease:`outCubic`,duration:200})},"stroke-dashoffset":{to:+!t,...o?jn:t?q(s,{ease:`inOutSine`,duration:260}):c},"stroke-width":o?{to:t?2.4:0,duration:0}:t&&!r?[{to:2.2,...q(s,{ease:`outCubic`,duration:65})},{to:2.4,delay:D(s,120),...An(s,{bounce:.35,duration:220})}]:{to:t?2.4:0,...c}});return()=>{l.cancel()}},[e,a]),(0,Y.jsxs)(`svg`,{className:`caps-checkbox-visual`,width:`24`,height:`24`,viewBox:`0 0 12 12`,"aria-hidden":`true`,focusable:`false`,children:[(0,Y.jsxs)(`defs`,{children:[(0,Y.jsx)(He,{id:`${t}-surface`,transform:`matrix(1 0 0 1 6 6)`}),(0,Y.jsx)(ot,{id:`${t}-shadow`}),(0,Y.jsx)(lt,{id:`${t}-inset`}),(0,Y.jsx)(Ct,{id:`${t}-goo`,values:Hr}),(0,Y.jsxs)(`filter`,{id:`${t}-relief`,x:`-25%`,y:`-25%`,width:`150%`,height:`150%`,colorInterpolationFilters:`sRGB`,children:[(0,Y.jsx)(`feGaussianBlur`,{in:`SourceAlpha`,stdDeviation:`0.28`,result:`relief`}),(0,Y.jsx)(`feSpecularLighting`,{in:`relief`,surfaceScale:`1.2`,specularConstant:`0.55`,specularExponent:`18`,lightingColor:`color-mix(in srgb, var(--color-white) calc(var(--depth) * 100%), var(--color-black))`,result:`light`,children:(0,Y.jsx)(`feDistantLight`,{azimuth:`225`,elevation:`55`})}),(0,Y.jsx)(`feComposite`,{in:`light`,in2:`SourceAlpha`,operator:`in`,result:`clipped-light`}),(0,Y.jsx)(`feBlend`,{in:`SourceGraphic`,in2:`clipped-light`,mode:`screen`})]}),(0,Y.jsx)(`mask`,{id:`${t}-contour`,maskUnits:`userSpaceOnUse`,x:`0`,y:`0`,width:`12`,height:`12`,style:{maskType:`alpha`},children:(0,Y.jsx)(`path`,{ref:n,d:Vr[r],fill:`none`,stroke:`var(--color-white)`,strokeWidth:r===`unchecked`?0:2.4,pathLength:`1`,strokeDasharray:`1`,strokeDashoffset:+(r===`unchecked`),strokeLinecap:`round`,strokeLinejoin:`round`,filter:e===`mixed`?void 0:`url(#${t}-goo)`})}),(0,Y.jsx)(`clipPath`,{id:`${t}-well`,children:(0,Y.jsx)(`rect`,{x:`1`,y:`1`,width:`10`,height:`10`,rx:`2.5`})})]}),(0,Y.jsx)(`rect`,{className:`caps-checkbox-track`,x:`0.5`,y:`0.5`,width:`11`,height:`11`,rx:`3`,filter:`url(#${t}-inset)`}),(0,Y.jsx)(`g`,{clipPath:`url(#${t}-well)`,children:(0,Y.jsx)(`g`,{filter:`url(#${t}-shadow)`,children:(0,Y.jsx)(`g`,{filter:`url(#${t}-relief)`,children:(0,Y.jsx)(`g`,{mask:`url(#${t}-contour)`,children:(0,Y.jsx)(`rect`,{x:`0`,y:`0`,width:`12`,height:`12`,fill:`url(#${t}-surface)`})})})})})]})}var Wr=(0,J.forwardRef)(function({className:e,appearance:t,indicator:n,invalid:r,indeterminate:i=!1,checked:a,defaultChecked:o=!1,onChange:s,...c},l){let u=(0,J.useRef)(null),[d,f]=(0,J.useState)(o),p=a??d,m=i?`mixed`:p?`checked`:`unchecked`;return(0,J.useImperativeHandle)(l,()=>{if(!u.current)throw Error(`Checkbox input is not mounted`);return u.current},[]),(0,J.useLayoutEffect)(()=>{u.current&&(u.current.indeterminate=i)},[i]),(0,J.useEffect)(()=>{let e=u.current?.form;if(!e||a!==void 0)return;let t=e=>{queueMicrotask(()=>{!e.defaultPrevented&&u.current&&f(o)})};return e.addEventListener(`reset`,t),()=>{e.removeEventListener(`reset`,t)}},[a,o,c.form]),(0,Y.jsxs)(`span`,{className:`caps-checkbox`,"data-appearance":t===`compact`?t:void 0,"data-state":m,"data-custom-indicator":n!==void 0||void 0,children:[(0,Y.jsx)(`input`,{...c,checked:p,"aria-checked":i?`mixed`:p,"aria-invalid":r?!0:c[`aria-invalid`]===!1?void 0:c[`aria-invalid`],className:L(`caps-checkbox-input`,e),onChange:e=>{a===void 0&&f(e.target.checked),s?.(e),e.currentTarget.indeterminate=i},ref:u,type:`checkbox`}),n===void 0?(0,Y.jsx)(Ur,{state:m}):n]})}),Gr=Xn({keyCode:Qn(229)});function Kr(e){return e.nativeEvent.isComposing||we(Gr,e.nativeEvent).success}var qr=J.createContext(void 0);function Q(e){let t=J.useContext(qr);if(t===void 0&&!e)throw Error(on(47));return t}var Jr=e(Le(),1),Yr={...z,disabled:e=>e.disabled,instantType:e=>e.instantType===`trigger-change`&&!z.open(e)?void 0:e.instantType,openMethod:e=>e.openMethod,openChangeReason:e=>e.openChangeReason,isPressOpenedByTrigger:(e,t)=>e.openChangeReason===`trigger-press`&&z.isOpenedByTrigger(e,t),isTouchPressOpen:(e,t)=>t&&e.openMethod===`touch`&&e.openChangeReason===`trigger-press`,hasTriggerFocusGuards:(e,t)=>z.isOpenedByTrigger(e,t)&&!e.focusManagerModal,modal:e=>e.modal,titleElementId:e=>e.titleElementId,descriptionElementId:e=>e.descriptionElementId,openOnHover:e=>e.openOnHover,closeDelay:e=>e.closeDelay,adaptiveOrigin:e=>e.adaptiveOrigin},Xr=class extends _{constructor(e,t,n){let r=new nn;super(Zr(e,r,t,n),Qr(r),Yr)}setOpen=(e,t)=>{let n=t.reason===ve,r=t.reason===`trigger-press`&&t.event.detail===0,i=!e&&(t.reason===`escape-key`||t.reason==null),a=w(t),o=this.select(`activeTriggerId`);if(!e&&t.reason===`close-press`&&t.trigger==null&&o!=null&&(t.trigger=this.context.triggerElements.getById(o)??this.select(`activeTriggerElement`)??void 0),this.context.onOpenChange?.(e,t),t.isCanceled)return;this.state.floatingRootContext.dispatchOpenChange(e,t);let s=()=>{let n=Ae(this.state,e,t.trigger,a());n.openChangeReason=t.reason,this.update(n)};n?(this.context.stickIfOpen=!0,this.context.stickIfOpenTimeout.start(500,()=>{this.context.stickIfOpen=!1}),Jr.flushSync(s)):s();let c;r?c=`click`:i?c=`dismiss`:t.reason===`focus-out`&&(c=`focus`),this.set(`instantType`,c)}};function Zr(e,t,n,r=!1){let i={...ae(t,n,r),disabled:!1,modal:!1,focusManagerModal:!1,instantType:void 0,openMethod:null,openChangeReason:null,titleElementId:void 0,descriptionElementId:void 0,openOnHover:!1,closeDelay:0,adaptiveOrigin:void 0,...e};return i.open&&e?.mounted===void 0&&(i.mounted=!0),i}function Qr(e){return{popupRef:J.createRef(),onOpenChange:void 0,onOpenChangeComplete:void 0,triggerFocusTargetRef:J.createRef(),beforeTriggerFocusGuardRef:J.createRef(),beforeContentFocusGuardRef:J.createRef(),stickIfOpenTimeout:new he,stickIfOpen:!0,triggerElements:e}}var $r=k(function({props:e}){let{children:t,open:n,defaultOpen:r=!1,onOpenChange:i,onOpenChangeComplete:a,modal:o=!1,handle:s,triggerId:c,defaultTriggerId:l=null}=e,u=ti(s,{modal:o,open:r,openProp:n,activeTriggerId:l,triggerIdProp:c});u.useControlledProp(`openProp`,n),u.useControlledProp(`triggerIdProp`,c);let d=u.useState(`open`),f=u.useState(`mounted`),p=u.useState(`payload`);u.useContextCallback(`onOpenChange`,i),u.useContextCallback(`onOpenChangeComplete`,a),Ie(u,d),y(u);let{forceUnmount:m}=P(d,u,()=>{u.context.stickIfOpen=!0,u.set(`openChangeReason`,null)});u.useSyncedValues({modal:o}),J.useEffect(()=>{d||u.context.stickIfOpenTimeout.clear()},[u,d]),J.useImperativeHandle(e.actionsRef,()=>({unmount:m,close:()=>u.setOpen(!1,C(Mt))}),[m,u]);let h=d||f||s!=null;return(0,Y.jsxs)(qr.Provider,{value:u,children:[s&&(0,Y.jsx)(Ee,{handle:s,store:u}),h&&(0,Y.jsx)(ni,{store:u,modal:o}),typeof t==`function`?t({payload:p}):t]})});function ei(e){return Q(!0)?(0,Y.jsx)($r,{props:e}):(0,Y.jsx)(Et,{children:(0,Y.jsx)($r,{props:e})})}function ti(e,t){let n=j((e,n)=>new Xr(t,e,n));return J.useEffect(()=>n.context.stickIfOpenTimeout.disposeEffect(),[n]),n}function ni({store:e,modal:t}){let n=e.useState(`floatingRootContext`),r=le(n,{outsidePressEvent:{mouse:t===`trap-focus`?`sloppy`:`intentional`,touch:`sloppy`}}),i=r.reference,a=r.floating;return Nt(e,{activeTriggerProps:i,inactiveTriggerProps:i,popupProps:a}),null}var ri=R(function(e,n){let{render:r,className:a,style:o,disabled:s=!1,nativeButton:c=!0,handle:l,payload:u,openOnHover:d=!1,delay:f=300,closeDelay:p=0,id:m,...h}=e,_=Q(!0),v=ie(l)??_;if(!v)throw Error(on(74));let y=It(m),b=v.useState(`isTriggerActive`,y),x=v.useState(`floatingRootContext`),S=v.useState(`isOpenedByTrigger`,y),C=v.useState(`triggerPopupId`,y),w=J.useRef(null),{registerTrigger:T,isMountedByThisTrigger:E}=Pe(y,w,v,{payload:u,disabled:s,openOnHover:d,closeDelay:p}),D=v.useState(`isPressOpenedByTrigger`,y),O=v.useState(`isTouchPressOpen`,d),k=v.useState(`hasTriggerFocusGuards`,y),A=i(x,{enabled:!s&&d&&!O,mouseOnly:!0,move:!1,handleClose:gt(),restMs:f,delay:{close:p},triggerElementRef:w,isActiveTrigger:b,isClosing:()=>v.select(`transitionStatus`)===`ending`}),j=W(()=>v.context.stickIfOpen),M=t(x,{stickIfOpen:j}),N=Xt(()=>v.select(`open`),e=>{v.set(`openMethod`,e)}),P=v.useState(`triggerProps`,E),{getButtonProps:F,buttonRef:I}=Be({disabled:s,native:c}),L={open(e){return D?xe.open(e):g.open(e)}},{handlePreFocusGuardFocus:R,handleFocusTargetFocus:ee}=at(v,w),te=ht(`button`,e,{state:{disabled:s,open:S},ref:[I,n,T,w],props:[M.reference,A,P,N,{[Ze]:``,id:y,"aria-haspopup":`dialog`,"aria-expanded":S,"aria-controls":C},h,F],stateAttributesMapping:L}),ne=(0,Y.jsx)(J.Fragment,{children:te},y);return k?(0,Y.jsxs)(J.Fragment,{children:[(0,Y.jsx)(tn,{ref:v.context.beforeTriggerFocusGuardRef,onFocus:R}),ne,(0,Y.jsx)(tn,{ref:v.context.triggerFocusTargetRef,onFocus:ee})]}):ne}),ii=J.createContext(void 0);function ai(){let e=J.useContext(ii);if(e===void 0)throw Error(on(45));return e}var oi=J.forwardRef(function(e,t){let{keepMounted:n=!1,...r}=e;return Q().useState(`mounted`)||n?(0,Y.jsx)(ii.Provider,{value:n,children:(0,Y.jsx)(Ht,{ref:t,...r})}):null}),si=J.createContext(void 0);function ci(){let e=J.useContext(si);if(!e)throw Error(on(46));return e}var li=J.forwardRef(function(e,t){let{render:n,className:r,style:i,anchor:a,positionMethod:o,side:s,align:c,sideOffset:l,alignOffset:u,collisionBoundary:f=`clipping-ancestors`,collisionPadding:p,arrowPadding:m,sticky:h,disableAnchorTracking:g=!1,collisionAvoidance:_=Yt,...v}=e,y=Q(),b=ai(),x=Rt(),S=y.useState(`floatingRootContext`),C=y.useState(`mounted`),w=y.useState(`open`),T=y.useState(`openChangeReason`),E=y.useState(`activeTriggerElement`),D=y.useState(`modal`),O=y.useState(`openMethod`),k=y.useState(`positionerElement`),A=y.useState(`instantType`),j=y.useState(`transitionStatus`),M=y.useState(`adaptiveOrigin`),N=d({anchor:a,floatingRootContext:S,positionMethod:o,mounted:C,side:s,sideOffset:l,align:c,alignOffset:u,arrowPadding:m,collisionBoundary:f,collisionPadding:p,sticky:h,disableAnchorTracking:g,keepMounted:b,nodeId:x,collisionAvoidance:_,adaptiveOrigin:M}),P=S.useState(`domReferenceElement`);Qt({store:y,domReference:P,positionerElement:k,open:w});let F=D===!0&&T!==`trigger-hover`;$t(w&&F,O===`touch`,k,E);let I=y.useStateSetter(`positionerElement`),L={open:w,side:N.side,align:N.align,anchorHidden:N.anchorHidden,instant:A},R=Ke(e,L,{styles:N.positionerStyles,transitionStatus:j,props:v,refs:[t,I],hidden:!C,inert:!w});return(0,Y.jsxs)(si.Provider,{value:N,children:[C&&F&&(0,Y.jsx)(ge,{inert:be(!w),cutout:E}),(0,Y.jsx)(Gt,{id:x,children:R})]})}),ui=J.createContext(void 0);function di(){let[e,t]=J.useState(0),n=W(()=>(t(e=>e+1),()=>{t(e=>Math.max(0,e-1))}));return{context:J.useMemo(()=>({register:n}),[n]),hasClosePart:e>0}}var fi=J.forwardRef(function(e,t){let{render:n,className:r,style:i,initialFocus:a,finalFocus:s,...c}=e,l=Q(),d=ci(),f=se(!0)!=null,{context:m,hasClosePart:g}=di(),_=l.useState(`open`),v=l.useState(`openMethod`),y=l.useState(`instantType`),b=l.useState(`transitionStatus`),x=l.useState(`popupProps`),S=l.useState(`titleElementId`),C=l.useState(`descriptionElementId`),w=l.useState(`modal`),T=l.useState(`mounted`),E=l.useState(`openChangeReason`),D=l.useState(`activeTriggerElement`),O=l.useState(`floatingRootContext`),k=O.useState(`floatingId`),A=l.useState(`disabled`),j=l.useState(`openOnHover`),M=l.useState(`closeDelay`);u({open:_,ref:l.context.popupRef,onComplete(){_&&l.context.onOpenChangeComplete?.(!0)}}),mt(O,{enabled:j&&!A,closeDelay:M});let N=a===void 0?Se(l.context.popupRef):a,P=w!==!1&&g;l.useSyncedValue(`focusManagerModal`,P);let F=l.useStateSetter(`popupElement`),I={open:_,side:d.side,align:d.align,instant:y,transitionStatus:b},L=ht(`div`,e,{state:I,ref:[t,l.context.popupRef,F],props:[x,{id:k,role:`dialog`,...o,"aria-labelledby":S,"aria-describedby":C,onKeyDown(e){f&&p.has(e.key)&&e.stopPropagation()}},h(b),c],stateAttributesMapping:Zt});return(0,Y.jsx)(nt,{context:O,openInteractionType:v,modal:P,disabled:!T||E===`trigger-hover`,initialFocus:N,returnFocus:s,restoreFocus:`popup`,getInsideElements:()=>[l.context.beforeTriggerFocusGuardRef.current],previousFocusableElement:Ot(D)?D:void 0,nextFocusableElement:l.context.triggerFocusTargetRef,beforeContentFocusGuardRef:l.context.beforeContentFocusGuardRef,children:(0,Y.jsx)(ui.Provider,{value:m,children:L})})});function pi({getKey:e,isDisabled:t=()=>!1,items:n,getFallbackKey:r}){let i=(0,J.useMemo)(()=>{let r=n.map(e);if(r.some(e=>!e))throw Error(`Selectable items require non-empty keys`);if(new Set(r).size!==r.length)throw Error(`Selectable items require unique keys`);return n.filter(e=>!t(e))},[e,t,n]),[a,o]=(0,J.useState)(null),s=r?.(i)??null,c=a!==null&&i.some(t=>e(t)===a)?a:s!==null&&i.some(t=>e(t)===s)?s:null;(0,J.useEffect)(()=>{a!==null&&!i.some(t=>e(t)===a)&&o(null)},[a,i,e]);let l=i.find(t=>e(t)===c),u=l?i.findIndex(t=>e(t)===c):-1;return{activeIndex:u,activeItem:l,activeKey:c,enabledItems:i,move:(t,n)=>{if(i.length===0)return;let r=n?n===`start`?0:i.length-1:u<0?t>0?0:i.length-1:(u+t+i.length)%i.length,a=i[r];a&&o(e(a))},setActiveKey:o}}var mi=(0,J.forwardRef)(function({children:e,className:t,type:n=`button`,...r},i){return(0,Y.jsxs)(`button`,{...r,ref:i,type:n,className:L(`select caps-select caps-combobox-trigger w-full`,t),children:[(0,Y.jsx)(`span`,{children:e}),(0,Y.jsx)(yn,{className:`caps-select-chevron`,"aria-hidden":`true`})]})});function hi({defaultInputValue:e,defaultOpen:t,defaultValue:n,getKey:r,getSearchText:i,groupBy:a,id:o,isDisabled:s,items:c,onOpenChange:l,onCommit:u,multiple:d,controlledOpen:f,controlledKeys:p,trigger:m}){let h=`${o}-listbox`,[g,_]=(0,J.useState)(e),[v,y]=(0,J.useState)(!1),[b,x]=(0,J.useState)(n),[S,C]=(0,J.useState)(t),w=p??(b===null?[]:[b]),T=m?f??S:!0,E=(0,J.useMemo)(()=>{let e=g.trim().toLowerCase();return e?c.filter(t=>i(t).toLowerCase().includes(e)):c},[i,c,g]),D=pi({getKey:r,isDisabled:s,items:E});(0,J.useEffect)(()=>{if(D.activeKey!==null)return;let e=D.enabledItems.find(e=>w.includes(r(e)))??D.enabledItems[0];e&&D.setActiveKey(r(e))},[D.activeKey,D.enabledItems,D.setActiveKey,r,w]);let O=e=>{y(!1),e||_(``),f===void 0&&C(e),l?.(e)},k=e=>`${h}-option-${encodeURIComponent(e)}`,A=e=>{let t=r(e);p===void 0&&x(t),u(e),m&&!d&&O(!1)},j=e=>{y(!0),_(e.target.value),D.setActiveKey(null)},M=e=>{if(Kr(e))return;let t;switch(e.key){case`ArrowDown`:t=[1,void 0];break;case`ArrowUp`:t=[-1,void 0];break;case`End`:t=[1,`end`];break;case`Home`:t=[-1,`start`]}t?(y(!0),e.preventDefault(),D.move(t[0],t[1])):e.key===`Enter`&&D.activeItem&&(e.preventDefault(),A(D.activeItem))},N=(0,J.useMemo)(()=>{if(!a)return[{label:``,items:E}];let e=new Map;for(let t of E){let n=a(t),r=e.get(n);r?r.push(t):e.set(n,[t])}return[...e].map(([e,t])=>({label:e,items:t}))},[E,a]);return{keyboardNavigation:v,onPointerMove:()=>{y(!1)},activeKey:D.activeKey,activeItem:D.activeItem,groups:N,inputValue:g,listboxId:h,onInputChange:j,onInputKeyDown:M,optionId:k,open:T,commit:A,selectedKeys:w,setOpen:O}}function gi(e){let{"aria-describedby":t,"aria-invalid":n,"aria-label":r,"aria-labelledby":i,"aria-required":a,activeTone:o=`neutral`,container:s,contentClassName:c,defaultInputValue:l=``,defaultOpen:u=!1,defaultValue:d=null,emptyMessage:f=`No matches`,getKey:p,getLabel:m,getSearchText:h=m,groupBy:g,id:_,inputProps:v,inputRef:y,isDisabled:b=()=>!1,items:x,onOpenChange:S,onValueChange:C,multiple:w,open:T,placeholder:E=`Search…`,renderItem:D,rootRef:O,trigger:k,triggerRef:A,value:j,...M}=e,N=e=>{let t=p(e);if(w){let e=j.includes(t)?j.filter(e=>e!==t):[...j,t];C?.(e,x.filter(t=>e.includes(p(t))))}else C?.(t,e)},P;w?P=j:j!==void 0&&(P=j===null?[]:[j]);let F=(0,J.useId)(),I=k?.props??v,R=_??I?.id??F,ee={id:R,"aria-describedby":[t,I?.[`aria-describedby`]].filter(Boolean).join(` `)||void 0,"aria-invalid":n??I?.[`aria-invalid`],"aria-label":I?.[`aria-label`]??r,"aria-labelledby":I?.[`aria-labelledby`]??i,"aria-required":a??I?.[`aria-required`]},{keyboardNavigation:te,onPointerMove:ne,activeItem:re,activeKey:ie,commit:ae,groups:oe,inputValue:se,listboxId:z,onInputChange:ce,onInputKeyDown:le,open:ue,optionId:de,selectedKeys:fe,setOpen:pe}=hi({defaultInputValue:l,defaultOpen:u,defaultValue:d,getKey:p,getSearchText:h,groupBy:g,id:R,isDisabled:b,items:x,onOpenChange:S,onCommit:N,multiple:w??!1,controlledOpen:T,controlledKeys:P,trigger:k});kt(()=>{k&&pe(!1)});let me=xt(`popover`),he=s===void 0?me:s,ge=st(`.caps-combobox-option[data-active="true"]:not(:disabled), [data-navigation="pointer"] .caps-combobox-option:hover:not(:disabled)`),_e=(0,Y.jsx)(Bn,{...v,...k?{}:ee,"aria-activedescendant":re?de(p(re)):void 0,"aria-autocomplete":`list`,"aria-controls":z,"aria-expanded":!0,className:L(`input-sm`,v?.className),id:k?v?.id??`${R}-input`:R,onChange:e=>{v?.onChange?.(e),ce(e)},onKeyDown:e=>{v?.onKeyDown?.(e),e.defaultPrevented||le(e)},placeholder:v?.placeholder??E,ref:y,role:`combobox`,value:se}),ve=(0,Y.jsx)(`div`,{id:z,ref:ge,className:`caps-combobox-list`,"data-navigation":te?`keyboard`:`pointer`,onPointerMove:ne,role:`listbox`,"aria-multiselectable":w??void 0,children:oe.every(e=>e.items.length===0)?(0,Y.jsx)(`div`,{className:`px-md py-md text-sm text-base-content`,children:f}):oe.map(e=>(0,Y.jsxs)(`div`,{"aria-label":e.label||void 0,role:e.label?`group`:void 0,children:[e.label?(0,Y.jsx)(`div`,{className:`px-md pb-xs pt-sm text-xs text-base-content uppercase tracking-wider`,children:e.label}):null,e.items.map(e=>{let t=p(e),n=b(e),r=ie===t,i={active:r,disabled:n,selected:fe.includes(t)};return(0,Y.jsxs)(`button`,{"aria-disabled":n||void 0,"aria-selected":i.selected,className:`caps-combobox-option`,"data-active":r&&te,disabled:n,id:de(t),onClick:()=>{ae(e)},onMouseDown:e=>{e.preventDefault()},role:`option`,tabIndex:-1,type:`button`,children:[(0,Y.jsx)(`span`,{"aria-hidden":`true`,className:`caps-combobox-check`,children:i.selected?(0,Y.jsx)($n,{}):null}),D?.(e,r,i)??m(e)]},t)})]},e.label))});return k?(0,Y.jsx)(`div`,{...M,className:L(M.className),ref:O,children:(0,Y.jsxs)(ei,{modal:!0,onOpenChange:pe,open:ue,children:[(0,Y.jsx)(ri,{...ee,"aria-haspopup":`dialog`,className:`btn`,ref:A,render:k}),he===null?null:(0,Y.jsx)(oi,{container:he,children:(0,Y.jsx)(li,{align:`start`,side:`bottom`,sideOffset:4,className:`z-(--stipe-layer-popover)`,children:(0,Y.jsxs)(fi,{"data-active-tone":o,className:L(`min-w-40 rounded-box border border-base-300 bg-base-100 p-xs shadow-lg outline-none caps-combobox-panel caps-combobox-popup`,c),children:[(0,Y.jsx)(`div`,{className:`caps-combobox-search`,children:_e}),ve]})})})]})}):(0,Y.jsx)(`div`,{...M,className:L(M.className),ref:O,children:(0,Y.jsxs)(`div`,{className:L(`caps-combobox-panel`,c),"data-active-tone":o,children:[(0,Y.jsx)(`div`,{className:`caps-combobox-search`,children:_e}),ve]})})}function _i({icon:e,caption:t}){return(0,Y.jsxs)(`span`,{className:`caps-icon-choice-mark`,"aria-hidden":`true`,children:[(0,Y.jsx)(`span`,{className:`caps-icon-choice-art`,children:e}),t?(0,Y.jsx)(`span`,{className:`caps-icon-choice-caption`,children:t}):null,(0,Y.jsx)(`span`,{className:`caps-icon-choice-lamp`})]})}var vi=(0,J.forwardRef)(function({label:e,icon:t,caption:n,appearance:r,className:i,...a},o){return(0,Y.jsx)(`label`,{className:`caps-icon-choice`,"data-appearance":r===`compact`?r:void 0,children:(0,Y.jsx)(Wr,{...a,appearance:r??`default`,"aria-label":e,className:L(`caps-icon-choice-input`,i),indicator:(0,Y.jsx)(_i,{icon:t,caption:n}),ref:o})})}),yi=(0,J.forwardRef)(function({label:e,icon:t,hint:n,className:r,...i},a){let o=(0,J.useId)(),s=[i[`aria-describedby`],n?o:null].filter(Boolean).join(` `)||void 0;return(0,Y.jsx)(`label`,{className:`caps-check-key`,children:(0,Y.jsx)(Wr,{...i,"aria-label":e,"aria-describedby":s,className:L(`caps-check-key-input`,r),indicator:(0,Y.jsxs)(`span`,{className:`caps-check-key-face`,"aria-hidden":`true`,children:[t?(0,Y.jsx)(`span`,{className:`caps-check-key-icon`,children:t}):null,(0,Y.jsxs)(`span`,{className:`caps-check-key-copy`,children:[(0,Y.jsx)(`span`,{className:`caps-check-key-label`,children:e}),n?(0,Y.jsx)(`span`,{className:`caps-check-key-hint`,id:o,children:n}):null]}),(0,Y.jsx)(`span`,{className:`caps-check-key-lamp`})]}),ref:a})})});function bi({className:e,...t}){return(0,Y.jsx)(`div`,{...t,className:L(`caps-check-keys`,e)})}function xi({checked:e}){let t=`caps-radio-${(0,J.useId)().replaceAll(`:`,``)}`,n=(0,J.useRef)(null),r=(0,J.useRef)(e).current,i=(0,J.useRef)(e),a=(0,J.useRef)(null),o=Ne(a),{reduced:s}=o;return(0,J.useLayoutEffect)(()=>{if(!n.current)return;let t=s||i.current===e;i.current=e;let r=e?4:0,a=q(o,{ease:`outCubic`,duration:75}),c=e?An(o,{bounce:.65,duration:300}):q(o,{ease:`inCubic`,duration:100}),l=en(n.current,t?{rx:r,ry:r,cy:6,duration:0}:{rx:[{to:e?3.5:4.15,...a},{to:r,...c}],ry:[{to:e?4.5:3.85,...a},{to:r,...c}],cy:[{to:e?5.85:6.1,...a},{to:6,...c}]});return()=>{l.cancel()}},[e,s,o]),(0,Y.jsxs)(`svg`,{ref:a,className:`caps-radio-visual`,width:`24`,height:`24`,viewBox:`0 0 12 12`,"aria-hidden":`true`,focusable:`false`,children:[(0,Y.jsxs)(`defs`,{children:[(0,Y.jsx)(He,{id:`${t}-surface`,transform:`matrix(1 0 0 1 6 6)`}),(0,Y.jsx)(ot,{id:`${t}-shadow`}),(0,Y.jsx)(lt,{id:`${t}-inset`}),(0,Y.jsx)(`clipPath`,{id:`${t}-well`,children:(0,Y.jsx)(`circle`,{cx:`6`,cy:`6`,r:`5`})})]}),(0,Y.jsx)(`circle`,{className:`caps-radio-track`,cx:`6`,cy:`6`,r:`5.5`,filter:`url(#${t}-inset)`}),(0,Y.jsx)(`g`,{clipPath:`url(#${t}-well)`,children:(0,Y.jsx)(`ellipse`,{ref:n,cx:`6`,cy:`6`,rx:r?4:0,ry:r?4:0,fill:`url(#${t}-surface)`,filter:`url(#${t}-shadow)`})})]})}var Si=(0,J.createContext)(null),Ci=(0,J.forwardRef)(function({children:e,className:t,defaultValue:n,disabled:r=!1,name:i,onValueChange:a,orientation:o=`vertical`,value:s,...c},l){let u=(0,J.useId)(),d=(0,J.useRef)(null);(0,J.useImperativeHandle)(l,()=>{if(!d.current)throw Error(`RadioGroup is not mounted`);return d.current},[]);let f=i??`radio-group-${u}`,[p,m]=(0,J.useState)(n),h=s??p;return(0,J.useEffect)(()=>{let e=d.current?.form;if(!e||s!==void 0)return;let t=e=>{queueMicrotask(()=>{e.defaultPrevented||m(n)})};return e.addEventListener(`reset`,t),()=>{e.removeEventListener(`reset`,t)}},[s,n,c.form]),(0,Y.jsx)(Si.Provider,{value:{disabled:r,name:f,onValueChange:e=>{s===void 0&&m(e),a?.(e)},value:h},children:(0,Y.jsx)(`fieldset`,{...c,className:L(`flex gap-md`,o===`horizontal`?`flex-row flex-wrap`:`flex-col`,t),disabled:r,role:c.role??`radiogroup`,ref:d,children:e})})}),wi=(0,J.forwardRef)(function({className:e,indicator:t,onChange:n,onClick:r,value:i,...a},o){let s=(0,J.useContext)(Si);if(!s)throw Error(`RadioGroupItem must be used inside <RadioGroup>`);let c=s.value===i,l=e=>{n?.(e),e.target.checked&&s.onValueChange?.(i)};return(0,Y.jsxs)(`span`,{className:`caps-radio`,"data-checked":c,"data-custom-indicator":t!==void 0||void 0,children:[(0,Y.jsx)(`input`,{...a,"aria-checked":c,checked:c,className:L(`caps-radio-input`,e),disabled:s.disabled||a.disabled,name:s.name,onChange:l,onClick:r,ref:o,type:`radio`,value:i}),t===void 0?(0,Y.jsx)(xi,{checked:c}):t]})}),Ti=(0,J.forwardRef)(function({description:e,id:t,meta:n,title:r,...i},a){let o=(0,J.useContext)(Si),s=(0,J.useId)(),c=t??s,l=o?.value===i.value,u=o?.disabled===!0||i.disabled===!0;return(0,Y.jsxs)(`label`,{className:`caps-choice-card`,"data-checked":l,"data-disabled":u||void 0,htmlFor:c,children:[(0,Y.jsx)(wi,{...i,"aria-describedby":e?`${c}-description`:void 0,"aria-labelledby":`${c}-title`,id:c,ref:a}),(0,Y.jsxs)(`span`,{className:`caps-choice-card-copy`,children:[(0,Y.jsx)(`span`,{className:`caps-choice-card-title`,id:`${c}-title`,children:r}),e?(0,Y.jsx)(`span`,{className:`caps-choice-card-description`,id:`${c}-description`,children:e}):null]}),n?(0,Y.jsx)(`span`,{className:`caps-choice-card-meta`,children:n}):null]})}),Ei=(0,J.forwardRef)(function({label:e,icon:t,caption:n,art:r=`dim`,className:i,...a},o){return(0,Y.jsx)(`label`,{className:`caps-icon-choice`,"data-art":r===`color`?r:void 0,children:(0,Y.jsx)(wi,{...a,"aria-label":e,className:L(`caps-icon-choice-input`,i),indicator:(0,Y.jsx)(_i,{icon:t,caption:n}),ref:o})})});(0,J.forwardRef)(function({label:e,color:t,className:n,...r},i){return(0,Y.jsx)(`label`,{className:`caps-icon-choice`,"data-art":`color`,"data-swatch":``,title:e,children:(0,Y.jsx)(wi,{...r,"aria-label":e,className:L(`caps-icon-choice-input`,n),indicator:(0,Y.jsx)(_i,{icon:(0,Y.jsx)(`span`,{className:`caps-swatch-dot`,style:{backgroundColor:t}})}),ref:i})})});var Di=(0,J.forwardRef)(function({className:e,invalid:t,...n},r){return(0,Y.jsxs)(`span`,{className:`caps-select-shell`,children:[(0,Y.jsx)(`select`,{...n,"aria-invalid":t?!0:n[`aria-invalid`]===!1?void 0:n[`aria-invalid`],className:L(`select select-bordered caps-select w-full`,t&&`select-error`,e),ref:r}),!n.multiple&&(!n.size||n.size<=1)?(0,Y.jsx)(yn,{className:`caps-select-chevron`,"aria-hidden":`true`}):null]})});function Oi({checked:e}){let t=`caps-switch-${(0,J.useId)().replaceAll(`:`,``)}`,n=(0,J.useRef)(null),r=(0,J.useRef)(null),i=(0,J.useRef)(e).current,a=(0,J.useRef)(e),o=S();return(0,J.useLayoutEffect)(()=>{if(!n.current||!r.current)return;let t=o||a.current===e;a.current=e;let i=e?16:8,s=Te(n.current),c=An(s,{bounce:.25,duration:440}),l=q(s,{ease:`inOutSine`,duration:100}),u=en(n.current,t?{x:2,y:2,width:i,height:8,duration:0}:{x:[{to:e?2.5:1.5,...l},{to:2,...c}],y:[{to:1.5,...l},{to:2,...c}],height:[{to:9,...l},{to:8,...c}],width:[{to:e?7:16.5,...l},{to:i,...c}]}),d=en(r.current,{gradientTransform:e?`matrix(2 0 0 1 10 6)`:`matrix(1 0 0 1 6 6)`,...t?{duration:0}:{delay:l.duration,...c}});return()=>{u.cancel(),d.cancel()}},[e,o]),(0,Y.jsxs)(`svg`,{className:`caps-switch-visual`,width:`40`,height:`24`,viewBox:`0 0 20 12`,"aria-hidden":`true`,focusable:`false`,children:[(0,Y.jsxs)(`defs`,{children:[(0,Y.jsx)(He,{ref:r,id:`${t}-surface`,transform:i?`matrix(2 0 0 1 10 6)`:`matrix(1 0 0 1 6 6)`}),(0,Y.jsx)(ot,{id:`${t}-shadow`}),(0,Y.jsx)(lt,{id:`${t}-inset`}),(0,Y.jsx)(`clipPath`,{id:`${t}-track`,children:(0,Y.jsx)(`rect`,{x:`1`,y:`1`,width:`18`,height:`10`,rx:`5`})})]}),(0,Y.jsx)(`rect`,{className:`caps-switch-track`,filter:`url(#${t}-inset)`,x:`0.5`,y:`0.5`,width:`19`,height:`11`,rx:`5.5`}),(0,Y.jsx)(`g`,{clipPath:`url(#${t}-track)`,children:(0,Y.jsx)(`rect`,{ref:n,x:`2`,y:`2`,width:i?16:8,height:`8`,rx:`4`,fill:`url(#${t}-surface)`,filter:`url(#${t}-shadow)`})})]})}var ki=(0,J.forwardRef)(function({className:e,checked:t,defaultChecked:n=!1,onChange:r,onCheckedChange:i,...a},o){let s=(0,J.useRef)(null),[c,l]=(0,J.useState)(n),u=t??c;return(0,J.useImperativeHandle)(o,()=>{if(!s.current)throw Error(`Switch input is not mounted`);return s.current},[]),(0,J.useEffect)(()=>{let e=s.current?.form;if(!e||t!==void 0)return;let r=e=>{queueMicrotask(()=>{!e.defaultPrevented&&s.current&&l(n)})};return e.addEventListener(`reset`,r),()=>{e.removeEventListener(`reset`,r)}},[t,n,a.form]),(0,Y.jsxs)(`span`,{className:`caps-switch`,"data-checked":u,children:[(0,Y.jsx)(`input`,{...a,checked:u,className:L(`caps-switch-input`,e),onChange:e=>{t===void 0&&l(e.target.checked),r?.(e),i?.(e.target.checked)},ref:s,role:`switch`,type:`checkbox`}),(0,Y.jsx)(Oi,{checked:u})]})}),Ai=(0,J.forwardRef)(function({className:e,invalid:t,...n},r){return(0,Y.jsx)(`textarea`,{...n,"aria-invalid":t?!0:n[`aria-invalid`]===!1?void 0:n[`aria-invalid`],className:L(`textarea textarea-bordered w-full`,t&&`textarea-error`,e),ref:r})}),ji=K(H),Mi=K(r),Ni=K(We(et)),Pi=K(de(H)),Fi=de(_e(File)),Ii=K(Fi),Li=At([H,et,r,dt,rt,de(H),Fi]),Ri=K(Li),$=e=>V(ji(e.state.value),()=>``),zi=e=>V(Mi(e.state.value),()=>!1),Bi=e=>V(Ni(e.state.value),()=>null),Vi=e=>V(Pi(e.state.value),()=>[]),Hi=e=>V(Ii(e.state.value),()=>[]),Ui=e=>V(Ri(e.state.value),()=>null);function Wi({field:e,spec:t,locked:n,...r}){let[i,a]=(0,J.useState)(!1);return(0,Y.jsxs)(Pn,{children:[(0,Y.jsx)(Bn,{...r,name:t.name,disabled:n,type:i?`text`:`password`,autoComplete:`off`,spellCheck:!1,className:`caps-field-secret`,placeholder:t.placeholder,readOnly:t.readOnly,value:$(e),onBlur:e.handleBlur,onChange:t=>{e.handleChange(t.currentTarget.value)}}),(0,Y.jsx)(U,{type:`button`,variant:`outline`,size:`icon`,"aria-label":i?`Hide`:`Show`,"aria-pressed":i,disabled:n,onClick:()=>{a(e=>!e)},children:i?(0,Y.jsx)(tr,{"aria-hidden":`true`}):(0,Y.jsx)(nr,{"aria-hidden":`true`})})]})}var Gi={text:`text`,email:`email`,url:`url`,tel:`tel`};function Ki({spec:e,field:t,locked:n,...r}){let i=Hi(t),a=n||e.readOnly===!0,o=(0,J.useRef)(null);return(0,Y.jsxs)(`div`,{className:`flex flex-col gap-sm`,children:[(0,Y.jsx)(re,{asChild:!0,children:(0,Y.jsx)(`input`,{...r,ref:o,type:`file`,tabIndex:-1,required:r.required===!0&&i.length===0,name:e.name,accept:e.accept,multiple:e.multiple,disabled:a,onBlur:t.handleBlur,onChange:e=>{t.handleChange(Array.from(e.currentTarget.files??[])),e.currentTarget.value=``}})}),(0,Y.jsx)(U,{type:`button`,variant:`outline`,"aria-label":`Choose files for ${e.label}`,"aria-describedby":r[`aria-describedby`],"aria-invalid":r[`aria-invalid`],disabled:a,onBlur:t.handleBlur,onClick:()=>{o.current?.click()},children:`Choose files`}),(0,Y.jsx)(Ir,{items:i.map((e,t)=>({id:String(t),name:e.name,preview:{kind:`file`},progress:0,progressLabel:`${String(e.size)} bytes`,statusLabel:`Selected`,actions:a?{}:{remove:{label:`Remove`,accessibleLabel:`Remove ${e.name}`}}})),onRemove:e=>{t.handleChange(i.filter((t,n)=>String(n)!==e))},onCancel:()=>void 0,onRetry:()=>void 0})]})}function qi({spec:e,field:t,locked:n,...r}){let i=e=>{t.handleChange(e)},a={...r,name:e.name,disabled:n,onBlur:t.handleBlur};switch(e.kind){case`text`:case`email`:case`url`:case`tel`:return(0,Y.jsx)(Bn,{...a,type:Gi[e.kind],inputMode:e.kind===`text`?void 0:e.kind,autoComplete:e.autoComplete,placeholder:e.placeholder,maxLength:e.maxLength,readOnly:e.readOnly,value:$(t),onChange:e=>{i(e.currentTarget.value)}});case`textarea`:return(0,Y.jsx)(Ai,{...a,rows:e.rows??3,placeholder:e.placeholder,maxLength:e.maxLength,readOnly:e.readOnly,value:$(t),onChange:e=>{i(e.currentTarget.value)}});case`secret`:return(0,Y.jsx)(Wi,{...r,field:t,spec:e,locked:n});case`money`:return(0,Y.jsxs)(Pn,{children:[(0,Y.jsx)(Fn,{className:`caps-field-currency`,children:e.currency??`USD`}),(0,Y.jsx)(Bn,{...a,inputMode:`decimal`,autoComplete:`off`,className:`caps-field-amount`,placeholder:e.placeholder??`0.00`,readOnly:e.readOnly,value:$(t),onChange:e=>{i(e.currentTarget.value)}})]});case`date`:return(0,Y.jsx)(Bn,{...a,type:`date`,readOnly:e.readOnly,value:$(t),onChange:e=>{i(e.currentTarget.value)}});case`number`:return(0,Y.jsx)(Wn,{...a,...e.min===void 0?{}:{min:e.min},...e.max===void 0?{}:{max:e.max},...e.step===void 0?{}:{step:e.step},...e.unit===void 0?{}:{unit:e.unit},...e.wrap===void 0?{}:{wrap:e.wrap},disabled:n||e.readOnly===!0,decrementLabel:`Decrease ${e.label}`,incrementLabel:`Increase ${e.label}`,value:Bi(t),onValueChange:e=>{t.handleChange(e)}});case`select`:return(0,Y.jsxs)(Di,{...a,value:$(t),onChange:e=>{i(e.currentTarget.value)},children:[e.placeholder===void 0?null:(0,Y.jsx)(`option`,{value:``,disabled:!0,children:e.placeholder}),e.options.map(e=>(0,Y.jsx)(`option`,{value:e.value,disabled:e.disabled,children:e.label},e.value))]});case`combobox`:return(0,Y.jsx)(gi,{id:r.id??e.name,"aria-describedby":r[`aria-describedby`],"aria-invalid":r[`aria-invalid`],"aria-required":r[`aria-required`],items:e.options,getKey:e=>e.value,getLabel:e=>e.label,isDisabled:t=>t.disabled||n||e.readOnly===!0,value:$(t),...e.placeholder===void 0?{}:{placeholder:e.placeholder},trigger:(0,Y.jsx)(mi,{name:e.name,disabled:n||e.readOnly===!0,onBlur:t.handleBlur,children:e.options.find(e=>e.value===$(t))?.label??e.placeholder??`Choose…`}),inputProps:{"aria-label":`Search ${e.label}`,disabled:n||e.readOnly===!0},onValueChange:e=>{i(e??``),t.handleBlur()}});case`file`:return(0,Y.jsx)(Ki,{...r,spec:e,field:t,locked:n});case`checkbox`:return(0,Y.jsx)(Wr,{...a,disabled:n||e.readOnly===!0,checked:zi(t),onChange:e=>{t.handleChange(e.currentTarget.checked)}});case`switch`:return(0,Y.jsx)(ki,{...a,disabled:n||e.readOnly===!0,checked:zi(t),onCheckedChange:e=>{t.handleChange(e)}});case`radio`:case`icon-radio`:case`checkboxes`:case`icon-checkboxes`:return null}}var Ji=new Set([`radio`,`icon-radio`,`checkboxes`,`icon-checkboxes`]);function Yi({spec:e,field:t,locked:n,error:r,layout:i}){let a=n||e.readOnly===!0,o=e.label;if(e.kind===`checkboxes`||e.kind===`icon-checkboxes`){let n=Vi(t),s=(e,r)=>{t.handleChange(r?[...n,e]:n.filter(t=>t!==e))};return(0,Y.jsx)(zn,{legend:o,icon:e.icon,layout:i,...i===`columns`?{legendTitle:o}:{},description:e.help,disabled:a,error:r??null,children:e.kind===`icon-checkboxes`?(0,Y.jsx)(`div`,{className:`caps-field-icon-choices`,children:e.options.map(r=>(0,Y.jsx)(vi,{name:e.name,value:r.value,label:r.label,...r.caption===void 0?{}:{caption:r.caption},icon:r.icon,disabled:r.disabled,checked:n.includes(r.value),onBlur:t.handleBlur,onChange:e=>{s(r.value,e.currentTarget.checked)}},r.value))}):(0,Y.jsx)(bi,{children:e.options.map(r=>(0,Y.jsx)(yi,{name:e.name,value:r.value,label:r.label,icon:r.icon,hint:r.description,disabled:r.disabled,checked:n.includes(r.value),onBlur:t.handleBlur,onChange:e=>{s(r.value,e.currentTarget.checked)}},r.value))})})}let s=e.options.some(e=>e.description!==void 0||e.meta!==void 0);return(0,Y.jsx)(zn,{legend:o,icon:e.icon,layout:i,...i===`columns`?{legendTitle:o}:{},description:e.help,disabled:a,error:r??null,children:(0,Y.jsx)(Ci,{name:e.name,"aria-label":o,value:$(t),onValueChange:e=>{t.handleChange(e),t.handleBlur()},orientation:e.kind===`icon-radio`||s?`horizontal`:`vertical`,children:e.options.map(t=>e.kind===`icon-radio`?(0,Y.jsx)(Ei,{value:t.value,label:t.label,...t.caption===void 0?{}:{caption:t.caption},icon:t.icon,disabled:t.disabled},t.value):s?(0,Y.jsx)(Ti,{value:t.value,title:t.label,description:t.description,meta:t.meta,disabled:t.disabled},t.value):(0,Y.jsx)(Mn,{label:t.label,orientation:`inline`,children:(0,Y.jsx)(wi,{value:t.value,disabled:t.disabled})},t.value))})})}function Xi({spec:e,field:t,locked:n,error:r,render:i,...a}){return i({name:e.name,label:e.label,help:e.help,value:Ui(t),onChange:e=>{t.handleChange(e)},onBlur:t.handleBlur,error:r,disabled:n,id:a.id??e.name,"aria-describedby":a[`aria-describedby`],"aria-invalid":r!==void 0})}function Zi({form:e,spec:t,locked:n,layout:r}){let i=Rn({form:e,name:t.name}),a=Vn(e.store,e=>e.submissionAttempts>0),o=i.state.meta.isBlurred||a?Nr(i.state.meta):void 0;if(t.render===void 0&&Ji.has(t.kind))return(0,Y.jsx)(Yi,{spec:t,field:i,locked:n,error:o,layout:r});let s=r===`columns`?t.kind===`switch`||t.kind===`checkbox`?`horizontal`:`vertical`:t.kind===`checkbox`?`inline`:(t.layout??(t.kind===`switch`?`row`:`stacked`))===`row`?`horizontal`:`vertical`;return(0,Y.jsx)(Mn,{label:t.label,...r===`columns`?{labelTitle:t.label}:{},description:t.help,icon:t.icon,orientation:s,error:o,...t.required===void 0?{}:{required:t.required},...t.optional===void 0?{}:{optional:t.optional},children:t.render===void 0?(0,Y.jsx)(qi,{spec:t,field:i,locked:n}):(0,Y.jsx)(Xi,{spec:t,field:i,locked:n,error:o,render:t.render})})}var Qi=K(Bt(H,Li));function $i({form:e,spec:t,locked:n,layout:r}){let i=t.when;return Vn(e.store,e=>i===void 0||i(V(Qi(e.values),()=>({}))))?(0,Y.jsx)(Zi,{form:e,spec:t,locked:n,layout:r}):null}function ea({form:e,section:t,locked:n,layout:r}){let i=t.fields.map(t=>(0,Y.jsx)($i,{form:e,spec:t,locked:n,layout:r},t.name));return t.title===void 0?i:(0,Y.jsx)(Ln,{title:t.title,description:t.description,layout:r,children:i})}function ta({model:e,names:t,disabled:n=!1,layout:r}){let i=e.form;return t===void 0?e.description.sections.map(e=>(0,Y.jsx)(ea,{form:i,section:e,locked:n,layout:r},e.id??``)):t.map(t=>{let a=e.description.fields.find(e=>e.name===t);return a===void 0?null:(0,Y.jsx)($i,{form:i,spec:a,locked:n,layout:r},t)})}var na=class{annotation;constructor(e){this.annotation=e}},ra=class{sections;constructor(e){this.sections=e}},ia=`caps/form`,aa=0;function oa(e){aa+=1;let t={[`${ia}:${String(aa)}`]:new na(e)};return e.label!==void 0&&(t.title=e.label),e.help!==void 0&&(t.description=e.help),t}H.annotate(oa({kind:`secret`})).pipe(ct(`Secret`));var sa=e=>{let t=e.replace(/([a-z0-9])([A-Z])/g,`$1 $2`).replace(/[-_]+/g,` `).toLowerCase();return t.charAt(0).toUpperCase()+t.slice(1)};function ca(e){return Object.values(e??{}).reduce((e,t)=>t instanceof na?{...e,...t.annotation}:e,{})}function la(e){return e.reduce((e,t)=>({...e,...ca(t)}),{})}function ua(e){let t=e?.[ia];return t instanceof ra?t.sections:{}}var da=K(H);function fa(e){if(ee(e))return tt(da(e.literal),{onNone:()=>null,onSome:e=>[e]});if(!Ce(e))return null;let t=[];for(let n of e.types){if(T(n))continue;let e=fa(n);if(e===null)return null;t.push(...e)}return t}function pa(e){if(De(e))return{type:`string`,literals:[]};if(rn(e))return{type:`number`,nullable:!1};if(A(e))return{type:`boolean`};let t=fa(e);if(t!==null)return{type:`string`,literals:t};if(v(e)){let[t]=e.rest;if(t===void 0)return null;if(De(t))return{type:`strings`,literals:[]};let n=fa(t);return n===null?null:{type:`strings`,literals:n}}if(Ce(e)){let t=e.types.filter(e=>!T(e)&&!pe(e)),n=e.types.some(e=>pe(e)),[r]=t;if(t.length!==1||r===void 0)return null;let i=pa(r);return i?.type===`number`?{type:`number`,nullable:n}:n?null:i}return null}function ma(e){let t=e.ast;if(!s(t))throw Error(`A schema form needs a Schema.Struct.`);return{fields:t.propertySignatures.map(e=>{let t=String(e.name),n=Pt(e.type),r=la([e.type.annotations,...(e.type.checks??[]).map(e=>e.annotations)]),i=r.kind===`file`?{type:`files`}:pa(n);if(i===null)throw Error(`Schema field "${t}" has no form control. Annotate it with field({ render }) or a kind.`);return{name:t,valueType:i,optional:e.type.context?.isOptional===!0,annotation:r,title:F(e.type),description:b(e.type)}}),sections:ua(je(t))}}function ha(e){let t=e,n=!1,r=!1;for(;;)if(t instanceof Jt)n=!0,t=t.unwrap();else if(t instanceof Vt)r=!0,t=t.unwrap();else if(t instanceof ft)t=t.unwrap();else if(t instanceof $e)t=t.in;else return{node:t,optional:n,nullable:r}}function ga(e){if(e instanceof St){let t=e.options.map(e=>ga(e));return t.some(e=>e===null)?null:t.flatMap(e=>e??[])}let t=e instanceof Ge?e.options:e instanceof Dt?[...e.values]:null;if(t===null)return null;let n=t.map(e=>da(e));return n.every(ue)?n.map(e=>e.value):null}function _a(e){let{node:t,nullable:n}=ha(e);if(t instanceof it)return{type:`string`,literals:[]};if(t instanceof Ye)return{type:`number`,nullable:n};if(t instanceof Lt)return{type:`boolean`};let r=ga(t);if(r!==null)return{type:`string`,literals:r};if(t instanceof Tt){let e=ha(t.element).node;if(e instanceof it)return{type:`strings`,literals:[]};let n=ga(e);return n===null?null:{type:`strings`,literals:n}}return null}function va(e){let t=[e];for(;;){let e=t[t.length-1];if(e===void 0)break;let n=e instanceof Jt||e instanceof Vt||e instanceof ft?e.unwrap():e instanceof $e?e.in:e;if(n===e)break;t.push(n)}return t.reverse().map(e=>te.get(e))}function ya(e){return va(e).reduce((e,t)=>({...e,...t}),{})}function ba(e){return Object.entries(e.shape)}function xa(e){let t=ha(e).node;if(!(t instanceof yt))throw Error(`A schema form needs a z.object.`);return{fields:ba(t).map(([e,t])=>{let n=la(va(t)),r=n.kind===`file`?{type:`files`}:_a(t);if(r===null)throw Error(`Schema field "${e}" has no form control. Annotate it with field({ render }) or a kind.`);let i=ya(t);return{name:e,valueType:r,optional:ha(t).optional,annotation:n,title:i.title,description:i.description}}),sections:ua(ya(e))}}function Sa(e,t){let n=t.options??{};return(e.length>0?e:Object.keys(n)).map(e=>{let t=n[e],r=t===void 0?{}:t instanceof Object?t:{label:t};return{value:e,label:r.label??sa(e),description:r.description,meta:r.meta,icon:r.icon,caption:r.caption,disabled:r.disabled===!0}})}function Ca(e,t){let n=t.some(e=>e.icon!==void 0);switch(e.type){case`boolean`:return`switch`;case`number`:return`number`;case`strings`:return n?`icon-checkboxes`:`checkboxes`;case`files`:return`file`;case`string`:return t.length===0?`text`:t.length>12?`combobox`:n?`icon-radio`:t.some(e=>e.description!==void 0||e.meta!==void 0)||t.length<=3?`radio`:`select`}}function wa(e,t){switch(e.type){case`boolean`:return!1;case`number`:return e.nullable?null:0;case`strings`:case`files`:return[];case`string`:return t[0]?.value??``}}function Ta(e){let t=e instanceof jt?xa(e):ma(e),n=t.fields.map((e,t)=>{let{kind:n,...r}=e.annotation,i=Sa(e.valueType.type===`string`||e.valueType.type===`strings`?e.valueType.literals:[],e.annotation),a=r.help??e.description;return{...r,name:e.name,label:r.label??e.title??sa(e.name),help:a,kind:n??Ca(e.valueType,i),options:i,optionalInSchema:e.optional,index:t}}),r={};t.fields.forEach((e,t)=>{let i=n[t];i&&(r[e.name]=wa(e.valueType,i.options))});let i=e=>e.order??e.index,a=e=>e.section!==void 0&&Object.hasOwn(t.sections,e.section)?e.section:null,o=e=>n.filter(t=>a(t)===e).sort((e,t)=>i(e)-i(t)),s=Object.entries(t.sections).map(([e,t])=>({id:e,title:t.title,description:t.description,fields:o(e)}));return{fields:n,sections:[{id:null,title:void 0,description:void 0,fields:o(null)},...s].filter(e=>e.fields.length>0),defaults:r}}function Ea(e){let t=e instanceof jt?e:ce(e);return{"~standard":{...t[`~standard`],validate:e=>{let n=t[`~standard`].validate(e);return n instanceof Promise?n.then(e=>Da(e)):Da(n)}}}}function Da(e){return e.issues===void 0?e:{issues:e.issues.map(e=>e.path===void 0?e:{...e,path:e.path.slice(0,1)})}}var Oa=`onServer`;function ka(e){let t=e.querySelector(`[aria-invalid="true"]`),n=t?.matches(`input, select, textarea, button, [tabindex]`)?t:t?.querySelector(`input, select, textarea, button`);return n?.focus(),n!=null}function Aa(e){if(ka(e))return()=>void 0;let t=new MutationObserver(()=>{ka(e)&&t.disconnect()});return t.observe(e,{subtree:!0,childList:!0,attributes:!0,attributeFilter:[`aria-invalid`]}),()=>{t.disconnect()}}function ja(e){return e.state.meta.errorMap.onServer!==void 0}function Ma(e){e.setMeta(e=>({...e,errorMap:{...e.errorMap,[Oa]:void 0}}))}function Na(e,t,n){e.setFieldMeta(t,e=>({...e,isBlurred:!0,errorMap:{...e.errorMap,[Oa]:n}}))}function Pa(e){let[t,n]=(0,J.useState)(null),[r,i]=(0,J.useState)(null),[a,o]=(0,J.useState)(e.defaultValues),[s,c]=(0,J.useState)(null);In(a,e.defaultValues)||(o(e.defaultValues),c(null));let{schema:l}=e,u=(0,J.useMemo)(()=>Ta(l),[l]),d=(0,J.useMemo)(()=>Ea(l),[l]),f=Un({defaultValues:s??a,validators:{onChange:d,onSubmit:d},listeners:{onChange:({fieldApi:e})=>{n(null),i(null),ja(e)&&Ma(e)}},onSubmit:async({value:t,formApi:r})=>{n(null),i(null);let a=await Ea(l)[`~standard`].validate(t);if(a.issues){n(a.issues[0]?.message??`Check the form and try again.`);return}let o;try{o=await e.onSubmit(a.value,t)??{kind:`saved`}}catch(t){console.error(`SchemaForm submit failed`,t),n(e.failure??`Couldn't save changes. Try again.`);return}if(o.kind===`refused`){n(o.error??null);let e=r;for(let[t,n]of Object.entries(o.fields??{}))n!==void 0&&n.length>0&&Na(e,t,n);return}let s=o.values??t;c(s),r.reset(s),i(o.message??`Saved`),e.onSaved?.(s)}});return{description:u,form:f,error:t,saved:r,discard:()=>{n(null),i(null),f.reset()},submit:()=>f.handleSubmit()}}function Fa(e){return{dirty:Vn(e.form.store,e=>!e.isDefaultValue),submitting:Vn(e.form.store,e=>e.isSubmitting),canSubmit:Vn(e.form.store,e=>e.canSubmit)}}function Ia({model:e,submitLabel:t=`Save changes`,discardLabel:n,onCancel:r,cancelLabel:i,allowClean:a,layout:o,footer:s,children:c,disabled:l=!1,...u}){let{submitting:d}=Fa(e),f=(0,J.useRef)(null),p=(0,J.useRef)(()=>void 0);return(0,J.useEffect)(()=>()=>{p.current()},[]),(0,Y.jsxs)(Hn,{...u,ref:f,layout:o,busy:d,noValidate:!0,onSubmit:t=>{t.preventDefault(),e.form.state.isSubmitting||e.submit().then(()=>{p.current();let t=f.current;t!==null&&!e.form.state.isValid&&(p.current=Aa(t))})},children:[c??(0,Y.jsx)(ta,{model:e,disabled:l,layout:o}),s===void 0?(0,Y.jsx)(za,{model:e,label:t,discardLabel:r===void 0?n:void 0,onCancel:r,cancelLabel:i,allowClean:a??r!==void 0,divider:r===void 0}):s]})}function La({schema:e,defaultValues:t,onSubmit:n,onSaved:r,failure:i,...a}){let o=Pa({schema:e,defaultValues:t,onSubmit:n,onSaved:r,failure:i});return(0,Y.jsx)(Ia,{...a,model:o})}function Ra(e){return`model`in e?(0,Y.jsx)(Ia,{...e}):(0,Y.jsx)(La,{...e})}function za({model:e,label:t,discardLabel:n,onCancel:r,cancelLabel:i=`Cancel`,allowClean:a=!1,dirtyLabel:o=`Unsaved changes`,buttonProps:s,...c}){let{dirty:l,submitting:u}=Fa(e),d=u?null:e.saved&&!l?(0,Y.jsx)(On,{tone:`success`,size:`compact`,label:e.saved}):l?(0,Y.jsx)(On,{tone:`neutral`,size:`compact`,label:o}):null;return(0,Y.jsxs)(Nn,{...c,error:e.error,status:d,children:[r?(0,Y.jsx)(U,{type:`button`,variant:`ghost`,disabled:u,onClick:r,children:i}):n&&l?(0,Y.jsx)(U,{type:`button`,variant:`ghost`,disabled:u,onClick:e.discard,children:n}):null,(0,Y.jsx)(U,{...s,type:`submit`,loading:u,disabled:u||!l&&!a,title:!l&&!a?`No changes to save`:void 0,children:t})]})}var Ba=qt.check(a(/^(?!\.{1,2}$)[^/]+$/u,{message:`Enter a single file or folder name.`})),Va={file:vt({name:Ba.annotate(oa({label:`File name`}))}),folder:vt({name:Ba.annotate(oa({label:`Folder name`}))})};function Ha(e){return(0,Y.jsx)(Ua,{...e},e.creation?`${e.creation.kind}:${e.creation.directory}:${e.creation.name??``}`:`closed`)}function Ua({creation:e,rootPath:t,onCreate:n,onClose:r}){let i=Pa({schema:Va[e?.kind??`file`],defaultValues:{name:e?.name??``},onSubmit:async t=>{if(!e)return;let i=await n(e,t.name);if(i)return i===`That name already exists in this directory.`?{kind:`refused`,fields:{name:i}}:{kind:`refused`,error:i};r()}}),{submitting:a}=Fa(i);return(0,Y.jsx)(Ue,{open:e!==null,onOpenChange:e=>{!e&&!i.form.state.isSubmitting&&r()},children:(0,Y.jsxs)(zt,{children:[(0,Y.jsxs)(Kt,{className:`mb-4`,children:[(0,Y.jsxs)(Qe,{children:[`New `,e?.kind===`folder`?`folder`:`file`]}),(0,Y.jsxs)(Je,{children:[`Create in `,e?.directory??t,` on this Computer.`]})]}),(0,Y.jsx)(Ra,{model:i,onSubmitCapture:()=>{i.form.state.isSubmitting||i.form.setFieldValue(`name`,e=>e)},footer:(0,Y.jsxs)(Nn,{divider:!1,error:i.error,children:[(0,Y.jsx)(U,{variant:`ghost`,type:`button`,disabled:a,onClick:r,children:`Cancel`}),(0,Y.jsx)(U,{type:`submit`,disabled:a,loading:a,children:a?`Creating…`:`Create`})]})})]})})}function Wa({files:e,patch:t,truncated:n,activeDiff:r,rowHeight:i,onOpenDiff:a}){let o=(0,J.useMemo)(()=>En(t),[t]);return e.length===0?(0,Y.jsx)(pn,{className:`inkcap-changes-empty`,variant:`quiet`,title:`No changes yet`,description:`Files the Agent edits show up here.`}):(0,Y.jsxs)(`div`,{className:`inkcap-changes-list`,children:[n?(0,Y.jsx)(`p`,{className:`inkcap-tree-note`,children:`Showing the first part of a large change. Review the rest in a terminal.`}):null,(0,Y.jsx)(`ul`,{children:e.map(e=>{let t=o.get(e.path);return(0,Y.jsx)(`li`,{children:(0,Y.jsxs)(U,{className:`inkcap-change-file`,style:{minHeight:i},size:`sm`,variant:`ghost`,"aria-current":r===e.path?`true`:void 0,title:`Review changes to ${e.path}`,onClick:()=>{a(e.path)},children:[(0,Y.jsx)(`span`,{className:`inkcap-change-mark`,"data-status":e.status,role:`img`,"aria-label":xn[e.status],children:wn[e.status]}),(0,Y.jsx)(`span`,{className:`inkcap-change-path`,children:e.path}),t?(0,Y.jsxs)(`span`,{className:`inkcap-change-counts`,children:[t.additions>0?(0,Y.jsxs)(`span`,{className:`inkcap-change-added`,children:[`+`,t.additions]}):null,t.deletions>0?(0,Y.jsxs)(`span`,{className:`inkcap-change-removed`,children:[`−`,t.deletions]}):null]}):null]})},`${e.status}:${e.path}`)})})]})}var Ga=`That name already exists in this directory.`;function Ka({app:e,onOpenFile:t,onOpenDiff:n,activeDiff:r=null,activePath:i,rootPath:a=`/`,rootLabel:o=`Computer`,onSelectPath:s,creationRequest:c=null,onCreationRequestHandled:u,rowHeight:d=32}){let[f,p]=(0,J.useState)(null),m=Ar({app:e,rootPath:a,rootLabel:o,rowHeight:d,activePath:i,onOpenFile:t,onSelectPath:e=>{p(e),s?.(e)}}),[h,g]=(0,J.useState)(null),_=e.capabilities.has(sn),[v,y]=(0,J.useState)(!1),b=e.capabilities.has(un),x=ln(vn(b?e:null,a)),S=x.data?.kind===`changes`?x.data:null;function C(){m.reloadRoot(),b&&x.refetch()}(0,J.useEffect)(()=>{x.isError&&e.ui.showToast({message:fe(x.error).message,tone:`error`}).catch(e=>{console.error(`Inkcap changes toast failed`,e)})},[e,x.isError,x.error]);function w(e,t){g({kind:e,directory:wt(t,a)})}(0,J.useEffect)(()=>{if(!c)return;let e={kind:c.kind,directory:wt(f??`${a}/`,a)};c.name!==void 0&&(e.name=c.name),c.immediate===!0&&c.name!==void 0?T(e,c.name):g(e),u?.()},[c,u,a,f]);async function T(e,n){let r=await E(e,n);r===Ga?t(ut(n,e.directory)):r!==void 0&&g(e)}async function E(n,r){let i=ut(r,n.directory);try{let a=0;for(;a!==null;){let t=a,i=await kn(e.capabilities,{path:n.directory,limit:256,offset:t});if(i.entries.some(e=>e.name===r))return Ga;if(i.nextOffset!==null&&i.nextOffset<=t)return`Could not verify that name is available.`;a=i.nextOffset}n.kind===`folder`?(await e.capabilities.require(sn).mkdir({path:i}),m.noteCreated(`${i}/`)):(await cn(e.capabilities,{path:i,content:new Blob([])},{}),m.noteCreated(i),t(i));return}catch(e){return e instanceof Error?fe(e).message:`Couldn't create ${n.kind}. Check Computer write access.`}}let D={flex:`1`,"--trees-item-height":`${String(d)}px`,"--trees-padding-inline-override":`var(--spacing-xs)`,"--trees-item-margin-x-override":`0px`,"--trees-item-padding-x-override":`var(--spacing-xs)`,"--trees-item-row-gap-override":`var(--spacing-xs)`,"--trees-bg-override":`var(--color-base-100)`,"--trees-fg-override":`var(--color-base-content)`,"--trees-bg-muted-override":`var(--color-base-200)`,"--trees-selected-bg-override":`var(--color-base-300)`,"--trees-border-radius-override":`var(--radius-field)`,"--trees-font-family-override":`var(--font-sans)`,"--trees-font-size-override":`12px`};return(0,Y.jsxs)(`aside`,{className:`inkcap-tree`,"aria-label":`File tree`,children:[(0,Y.jsxs)(`div`,{className:`inkcap-tree-toolbar`,children:[(0,Y.jsxs)(`span`,{children:[(0,Y.jsx)(Tn,{"aria-hidden":`true`}),` `,(0,Y.jsx)(`span`,{className:`inkcap-tree-title`,children:`Explorer`})]}),(0,Y.jsxs)(`span`,{className:`inkcap-tree-actions`,children:[(0,Y.jsx)(l,{icon:(0,Y.jsx)(mn,{}),"aria-label":`New file`,title:`New file`,variant:`ghost`,size:`responsive`,disabled:!_,onClick:()=>{w(`file`,f??`${a}/`)}}),(0,Y.jsx)(l,{icon:(0,Y.jsx)(ir,{}),"aria-label":`New folder`,title:`New folder`,variant:`ghost`,size:`responsive`,disabled:!_,onClick:()=>{w(`folder`,f??`${a}/`)}}),(0,Y.jsx)(l,{icon:(0,Y.jsx)(Kn,{}),"aria-label":`Refresh files`,title:`Refresh files`,variant:`ghost`,size:`responsive`,disabled:m.busy||x.isFetching,onClick:C})]})]}),S===null?x.isError?(0,Y.jsx)(U,{className:`inkcap-changes-retry`,size:`sm`,variant:`ghost`,onClick:()=>void x.refetch(),children:`Changes unavailable. Retry`}):null:(0,Y.jsx)(kr,{className:`inkcap-changes`,size:`row`,open:v,onOpenChange:y,summary:`Changes`,trailing:(0,Y.jsx)(Sn,{count:S.files.length}),children:(0,Y.jsx)(Wa,{files:S.files,patch:S.patch,truncated:S.truncated,activeDiff:r,rowHeight:d,onOpenDiff:e=>{n?.(e)}})}),m.error&&(0,Y.jsx)(fn,{message:m.error,onRetry:m.reloadRoot}),m.rootEmpty?(0,Y.jsx)(`p`,{className:`inkcap-tree-note`,children:`Empty folder`}):null,(0,Y.jsxs)(`div`,{className:`inkcap-tree-files`,children:[(0,Y.jsx)(Gn,{model:m.model,style:D,renderContextMenu:(e,t)=>(0,Y.jsxs)(`div`,{className:`flex min-w-36 flex-col gap-xs p-xs`,role:`menu`,children:[(0,Y.jsxs)(U,{className:`w-full justify-start`,disabled:!_,role:`menuitem`,title:_?void 0:`Computer write access is not granted.`,size:`sm`,variant:`ghost`,onClick:()=>{t.close({restoreFocus:!1}),w(`file`,e.path)},children:[(0,Y.jsx)(mn,{"aria-hidden":`true`}),` New file`]}),(0,Y.jsxs)(U,{className:`w-full justify-start`,disabled:!_,role:`menuitem`,title:_?void 0:`Computer write access is not granted.`,size:`sm`,variant:`ghost`,onClick:()=>{t.close({restoreFocus:!1}),w(`folder`,e.path)},children:[(0,Y.jsx)(ir,{"aria-hidden":`true`}),` New folder`]})]})}),m.page.next!==null&&(0,Y.jsxs)(U,{disabled:m.busy,onClick:m.loadNext,children:[`More in `,m.page.path]})]}),(0,Y.jsx)(Ha,{creation:h,rootPath:a,onCreate:E,onClose:()=>{g(null)}})]})}export{Ka as InkcapFileTree};
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{$ as t,$a as n,$i as r,A as i,Aa as a,B as o,Ba as s,Bi as c,Bn as l,Bt as u,C as d,Cn as f,D as p,Dn as m,E as h,En as g,F as _,Fa as v,G as y,Ga as b,Gi as x,Gr as S,Gt as C,H as w,Ha as T,Hi as E,Hr as D,Ht as O,I as k,Ia as A,J as j,Ji as M,Jr as N,K as P,Ka as F,Ki as I,Kr as L,L as R,La as ee,Li as te,Ln as ne,Lr as re,M as ie,N as ae,Nn as oe,O as se,P as z,Pa as ce,Q as le,Qa as ue,Qi as de,Qr as fe,Ra as pe,Ri as me,Rt as he,S as ge,Sa as _e,Sn as ve,St as ye,T as be,Tn as xe,U as Se,Ua as Ce,Ui as we,Ur as Te,Ut as B,V as Ee,Va as De,Vi as Oe,Vt as ke,W as Ae,Wa as je,Wi as Me,Wr as Ne,X as Pe,Xa as V,Xi as Fe,Y as Ie,Yr as Le,Za as Re,Zi as ze,Zt as Be,_n as Ve,_r as He,a as Ue,aa as We,ai as Ge,b as Ke,bt as qe,c as Je,ca as H,ci as Ye,cn as Xe,ct as Ze,d as Qe,di as $e,dr as U,ea as et,eo as tt,et as nt,fa as rt,fi as it,g as at,gr as ot,h as st,ha as ct,hr as lt,i as ut,ia as dt,ii as ft,in as pt,j as mt,jn as ht,k as gt,kn as _t,la as vt,li as yt,lr as bt,m as xt,mi as St,mr as Ct,n as wt,ni as Tt,nn as W,nt as Et,oi as Dt,on as Ot,p as kt,pa as At,pi as jt,pn as Mt,q as Nt,qa as Pt,qi as Ft,qt as It,ri as Lt,rt as Rt,s as zt,sa as Bt,si as Vt,st as Ht,tn as Ut,to as Wt,tt as Gt,u as Kt,ua as qt,ui as Jt,ur as G,ut as Yt,v as Xt,va as K,wn as Zt,x as Qt,y as $t,yr as en,yt as tn,z as nn,za as rn,zi as an,zn as on}from"./tree-path-CaOESv-X.js";import{C as sn,D as cn,Ft as ln,O as un,Rt as dn,_ as fn,a as pn,b as q,c as mn,f as hn,g as gn,h as _n,i as vn,l as yn,m as bn,n as xn,o as Sn,p as Cn,r as wn,s as Tn,t as En,u as Dn,v as On,w as kn,x as An,y as jn}from"./changes-patch-B9ZsK5Me.js";import{a as Mn,c as Nn,d as Pn,f as Fn,i as In,l as Ln,n as Rn,o as zn,p as Bn,r as Vn,s as Hn,t as Un,u as Wn}from"./useForm-B3Yg2hut.js";import{n as Gn,r as Kn,t as qn}from"./useFileTree-D3LWmisB.js";var Jn=M(`ZodMiniType`,(e,t)=>{if(!e._zod)throw Error(`Uninitialized schema in ZodMiniType.`);c.init(e,t),e.def=t,e.type=t.type,e.parse=(t,n)=>Oe(e,t,n,{callee:e.parse}),e.safeParse=(t,n)=>we(e,t,n),e.parseAsync=async(t,n)=>E(e,t,n,{callee:e.parseAsync}),e.safeParseAsync=async(t,n)=>Me(e,t,n),e.check=(...n)=>e.clone({...t,checks:[...t.checks??[],...n.map(e=>typeof e==`function`?{_zod:{check:e,def:{check:`custom`},onattach:[]}}:e)]},{parent:!0}),e.with=e.check,e.clone=(t,n)=>x(e,t,n),e.brand=()=>e,e.register=((t,n)=>(t.add(e,n),e)),e.apply=t=>t(e)}),Yn=M(`ZodMiniObject`,(e,t)=>{an.init(e,t),Jn.init(e,t),I(e,`shape`,()=>t.shape)});function Xn(e,t){return new Yn({type:`object`,shape:e??{},...Ft(t)})}var Zn=M(`ZodMiniLiteral`,(e,t)=>{me.init(e,t),Jn.init(e,t)});function Qn(e,t){return new Zn({type:`literal`,values:Array.isArray(e)?e:[e],...Ft(t)})}var $n=G(`Check`,[[`path`,{d:`M20 6 9 17l-5-5`,key:`1gmf2c`}]]),er=G(`ChevronRight`,[[`path`,{d:`m9 18 6-6-6-6`,key:`mthhwq`}]]),tr=G(`EyeOff`,[[`path`,{d:`M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49`,key:`ct8e1f`}],[`path`,{d:`M14.084 14.158a3 3 0 0 1-4.242-4.242`,key:`151rxh`}],[`path`,{d:`M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143`,key:`13bj9a`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}]]),nr=G(`Eye`,[[`path`,{d:`M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0`,key:`1nclc0`}],[`circle`,{cx:`12`,cy:`12`,r:`3`,key:`1v7zrd`}]]),rr=G(`FileImage`,[[`path`,{d:`M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z`,key:`1rqfz7`}],[`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`,key:`tnqrlb`}],[`circle`,{cx:`10`,cy:`12`,r:`2`,key:`737tya`}],[`path`,{d:`m20 17-1.296-1.296a2.41 2.41 0 0 0-3.408 0L9 22`,key:`wt3hpn`}]]),ir=G(`FolderPlus`,[[`path`,{d:`M12 10v6`,key:`1bos4e`}],[`path`,{d:`M9 13h6`,key:`1uhe8q`}],[`path`,{d:`M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z`,key:`1kt360`}]]),ar=G(`RotateCcw`,[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}]]),J=e(ze(),1);function or(e){let{open:t,defaultOpen:n=!1,onOpenChange:r,disabled:i}=e,[a,o]=Xe({controlled:t,default:n,name:`Collapsible`,state:`open`}),{mounted:s,setMounted:c,transitionStatus:l}=O(a,!0,!0),u=It(),[d,p]=J.useState(),m=d===null?void 0:d??u,h=W(e=>{let t=!a,n=C(f,e.nativeEvent);r(t,n),!n.isCanceled&&o(t)});return J.useMemo(()=>({defaultPanelId:u,disabled:i,handleTrigger:h,mounted:s,open:a,panelId:m,setMounted:c,setOpen:o,setPanelIdState:p,transitionStatus:l}),[u,i,h,s,a,m,c,o,p,l])}var sr=J.createContext(void 0);function cr(){let e=J.useContext(sr);if(e===void 0)throw Error(on(15));return e}var lr=`data-open`,ur=`data-closed`,dr=_t,fr=`data-panel-open`,pr={[lr]:``},mr={[ur]:``},hr={open(e){return e?{[fr]:``}:null}},gr={open(e){return e?pr:mr},...m},Y=Fe(),_r=J.forwardRef(function(e,t){let{render:n,className:r,defaultOpen:i=!1,disabled:a=!1,onOpenChange:o,open:s,style:c,...l}=e,u=W(o),d=or({open:s,defaultOpen:i,onOpenChange:u,disabled:a}),f=J.useMemo(()=>({open:d.open,disabled:d.disabled,transitionStatus:d.transitionStatus}),[d.open,d.disabled,d.transitionStatus]),p=J.useMemo(()=>({...d,onOpenChange:u,state:f}),[d,u,f]),m=ht(`div`,e,{state:f,ref:t,props:l,stateAttributesMapping:gr});return(0,Y.jsx)(sr.Provider,{value:p,children:m})}),vr={...hr,...m},yr=J.forwardRef(function(e,t){let{panelId:n,open:r,handleTrigger:i,state:a,disabled:o}=cr(),{className:s,disabled:c=o,render:l,nativeButton:u=!0,style:d,...f}=e,{getButtonProps:p,buttonRef:m}=Be({disabled:c,native:u});return ht(`button`,e,{state:a,ref:[t,m],props:[{"aria-controls":r?n:void 0,"aria-expanded":r,onClick:i},f,p],stateAttributesMapping:vr})}),X={height:void 0,width:void 0};function br(e){let{externalRef:t,hiddenUntilFound:n,id:r,keepMounted:i,mounted:a,onOpenChange:o,open:s,setMounted:c,setOpen:l,transitionStatus:d}=e,f=J.useRef(null),p=J.useRef(null),[m,h]=J.useState(X),g=J.useRef(X),_=J.useRef(!1),v=J.useRef(s),y=J.useRef(!1),[b,x]=J.useState(!1),S=J.useRef(null),w=ne(t,f),T=qe(s),E=ke(f),D=!s&&!a,O=b?`idle`:d,k=s&&(v.current||y.current),A=!s&&a&&p.current===`css-animation`&&m.height===void 0&&m.width===void 0?g.current:m,j=n&&D&&p.current!==`css-animation`,M=W((e,t=!0)=>{t&&(g.current=e),h(e)}),N=W(()=>{S.current?.(),S.current=null}),P=W(e=>{N(),S.current=()=>{S.current=null,e()}}),F=W(()=>{s&&a&&p.current===`css-animation`&&(y.current=!0)});Ut(()=>{!b||d===`starting`||x(!1)},[b,d]),J.useEffect(()=>()=>{F(),N()},[F,N]),Ut(()=>{s||(v.current=!1,y.current=!1);let e=f.current;if(!e)return;!s&&S.current&&N();let t=xr(e,k);if(p.current=t,s&&d===`idle`&&v.current&&t===`css-animation`){g.current=Z(e);return}if(s&&d===`starting`){let n=_.current;if(_.current=!1,t===`none`){M(Z(e)),x(!0);return}if(t===`css-transition`){let t=wr(e);if(M(Z(e)),!n)return t;let r=Cr(e,`transition-duration`,`0s`);return P(r),x(!0),t}M(Z(e));let r=Cr(e,`animation-name`,`none`);if(!n){r();return}let i=Cr(e,`animation-duration`,`0s`);r(),P(i),x(!0);return}if(!s&&a&&(d===`idle`||d===`starting`)){if(t===`none`){M(X,!1),c(!1);return}M(Z(e));return}if(d!==`ending`)return;if(t===`none`){c(!1);return}let n=Z(e);if(!(n.height>0||n.width>0)){c(!1);return}M(n),t===`css-animation`&&Cr(e,`animation-name`,`none`)()},[a,s,N,M,c,P,k,d]),u({enabled:s&&a&&O===`idle`,open:!0,ref:f,onComplete(){s&&M(X,!1)}}),J.useEffect(()=>{if(s||!a||O!==`ending`)return;if(!f.current){c(!1),M(X,!1);return}let e=new AbortController,t=-1;function n(){T.current||(c(!1),M(X,!1))}return t=B.request(()=>{E(n,e.signal)}),()=>{B.cancel(t),e.abort()}},[T,a,s,O,E,M,c]),Ut(()=>{let e=f.current;!e||!n||!D||e.setAttribute(`hidden`,`until-found`)},[D,n]),J.useEffect(function(){let e=f.current;if(!e)return;let t=he.create(),n=-1,r=(r,i)=>{t.start(0,()=>{T.current||(n=B.request(()=>{T.current||(r&&(_.current=!1),i&&e.setAttribute(dr,``),e.setAttribute(`hidden`,`until-found`))}))})},i=ye(e,`beforematch`,t=>{let n=C(Ve,t);if(o(!0,n),n.isCanceled){r(!1,!1);return}_.current=!0;let i=e.hasAttribute(dr);e.removeAttribute(dr),l(!0),r(!0,i)});return()=>{t.clear(),B.cancel(n),i()}},[T,o,l]);let I=i||n||a||s;return{height:A.height,props:{...j?{[dr]:``}:void 0,hidden:D,id:r},ref:w,shouldPreventOpenAnimation:k,shouldRender:I,transitionStatus:O,width:A.width}}function Z(e){return{height:e.scrollHeight,width:e.scrollWidth}}function xr(e,t){let n=pt(e).getComputedStyle(e),r=(n.animationName.split(`,`).map(e=>e.trim()).some(e=>e!==``&&e!==`none`)||t)&&Sr(n.animationDuration),i=Sr(n.transitionDuration);return r&&i||i?`css-transition`:r?`css-animation`:`none`}function Sr(e){return e.split(`,`).map(e=>e.trim()).some(e=>e!==``&&Number.parseFloat(e)>0)}function Cr(e,t,n){let r=e.style.getPropertyValue(t),i=e.style.getPropertyPriority(t);return e.style.setProperty(t,n),()=>{if(r===``){e.style.removeProperty(t);return}e.style.setProperty(t,r,i)}}function wr(e){let t={"justify-content":e.style.justifyContent,"align-items":e.style.alignItems,"align-content":e.style.alignContent,"justify-items":e.style.justifyItems};Object.keys(t).forEach(t=>{e.style.setProperty(t,`initial`,`important`)});function n(){Object.entries(t).forEach(([t,n])=>{if(n===``){e.style.removeProperty(t);return}e.style.setProperty(t,n)})}let r=B.request(n);return()=>{B.cancel(r),n()}}var Tr=`--collapsible-panel-height`,Er=`--collapsible-panel-width`,Dr=J.forwardRef(function(e,t){let{className:n,hiddenUntilFound:r,keepMounted:i,render:a,id:o,style:s,...c}=e,{defaultPanelId:l,mounted:u,onOpenChange:d,open:f,setMounted:p,setPanelIdState:m,setOpen:h,state:g,transitionStatus:_}=cr(),v=r??!1,y=i??!1,b=o||void 0,x=b??l;Ut(()=>(m(e=>b??(e===null?void 0:e)),()=>{m(e=>e===b?null:e)}),[b,m]);let{height:S,props:C,ref:w,shouldPreventOpenAnimation:T,shouldRender:E,transitionStatus:D,width:O}=br({externalRef:t,hiddenUntilFound:v,id:x,keepMounted:y,mounted:u,onOpenChange:d,open:f,setMounted:p,setOpen:h,transitionStatus:_}),k={...g,transitionStatus:D},A=oe(s,k),j=ht(`div`,{...e,style:void 0},{state:k,ref:w,props:[C,{style:{[Tr]:S===void 0?`auto`:`${S}px`,[Er]:O===void 0?`auto`:`${O}px`}},c,A?{style:A}:void 0,T?{style:{animationName:`none`}}:void 0],stateAttributesMapping:gr});return E?j:null}),Or=N(`caps-disclosure`,{variants:{tone:{neutral:``,error:`caps-disclosure-error`},size:{group:`caps-disclosure-group`,row:`caps-disclosure-row`}},defaultVariants:{tone:`neutral`,size:`group`}});function kr({open:e,onOpenChange:t,summary:n,leading:r,trailing:i,children:a,tone:o,size:s,className:c}){return(0,Y.jsxs)(_r,{className:L(Or({tone:o,size:s}),c),onOpenChange:t,open:e,children:[(0,Y.jsxs)(yr,{className:`caps-disclosure-trigger`,children:[r===void 0?null:(0,Y.jsx)(`span`,{className:`caps-disclosure-leading`,children:r}),(0,Y.jsx)(`span`,{className:`caps-disclosure-summary`,children:n}),i===void 0?null:(0,Y.jsx)(`span`,{className:`caps-disclosure-trailing`,children:i}),(0,Y.jsx)(er,{"aria-hidden":`true`,className:`caps-disclosure-chevron`,size:12})]}),(0,Y.jsx)(Dr,{className:`caps-disclosure-panel`,children:a})]})}function Ar({app:e,rootPath:t,rootLabel:n=`Computer`,activePath:r,onOpenFile:i,onSelectPath:a,rowHeight:o=32}){let{scope:s,snapshot:c,focusedPath:l,requestPage:u,reload:d}=gn({app:e,rootPath:t,activePath:r}),f=(0,J.useRef)({activePath:r,onOpenFile:i,onSelectPath:a,rootLabel:n});f.current={activePath:r,onOpenFile:i,onSelectPath:a,rootLabel:n};let p=(0,J.useRef)(u);p.current=u;let{model:m}=qn({paths:[],itemHeight:o,initialExpansion:2,flattenEmptyDirectories:!1,composition:{contextMenu:{enabled:!0}},renderRowDecoration:({row:e})=>e.path===`/`?{text:f.current.rootLabel}:null,unsafeCSS:`[data-item-section="content"] { display: flex; align-items: center; }[data-item-path="/"] [data-item-section="decoration"] { justify-content: flex-start; color: inherit; }`,onSelectionChange(e){let t=e[0];t&&(f.current.onSelectPath?.(t),t.endsWith(`/`)?p.current(t,0):t!==f.current.activePath&&f.current.onOpenFile(t))}}),h=(0,J.useRef)(Dn()),g=(0,J.useRef)(null);(0,J.useLayoutEffect)(()=>{Cn(m,h.current),g.current=null},[m,s]),(0,J.useLayoutEffect)(()=>{g.current=null;for(let e of m.getSelectedPaths())!e.endsWith(`/`)&&e!==r&&m.getItem(e)?.deselect()},[r,m]),(0,J.useLayoutEffect)(()=>{if(c.listings.length===0&&(g.current=null),_n(m,c.listings,h.current),!r||g.current===r)return;let e=bn(r,t);if(!e.every(e=>h.current.known.has(e)))return;for(let t of e){let e=m.getItem(t);e&&`expand`in e&&e.expand()}let n=m.getItem(r);n&&(g.current=r,n.select(),m.scrollToPath(r,{focus:!1}))},[r,m,t,s,c.listings]),(0,J.useEffect)(()=>{c.failure&&console.error(`Inkcap directory listing failed`,dn(c.failure))},[c.failure]);let _=c.listings.filter(({request:e})=>e.path===l).sort((e,t)=>e.request.offset-t.request.offset).at(-1)?.listing,v={path:_?.path??l,next:_?.nextOffset??null},y=c.listings.some(({request:e,listing:n})=>e.path===t&&e.offset===0&&n.entries.length===0&&n.nextOffset===null),b=d;return{model:m,page:v,error:c.failure?`${fe(c.failure).message} Your open files remain available.`:``,busy:c.busy,rootEmpty:y,reloadRoot:b,noteCreated:e=>{let t=e.split(`/`).filter(Boolean).at(-1)??``;!hn({name:t,type:``})&&!m.getItem(e)&&m.batch([{type:`add`,path:e}]),b()},loadNext:()=>{v.next!==null&&u(v.path,v.next)}}}var jr=K(H),Mr=K(vt({message:H}));function Nr(e){for(let t of e.errors){let e=Re(Wt(n(Mr(t),e=>e.message),()=>jr(t)));if(e!==void 0&&e.length>0)return e}}var Pr={neutral:`progress-neutral`,primary:`progress-primary`,secondary:`progress-secondary`,accent:`progress-accent`,success:`progress-success`,info:`progress-info`,warning:`progress-warning`,error:`progress-error`},Fr=(0,J.forwardRef)(function({className:e,tone:t=`primary`,...n},r){return(0,Y.jsx)(`progress`,{...n,"data-complete":n.value!==void 0&&Number(n.value)>=Number(n.max??1)?`true`:void 0,className:L(`progress caps-gooey-motion caps-gooey-progress w-full`,Pr[t],e),ref:r})});(0,J.forwardRef)(function({label:e,value:t,max:n,tone:r=`info`,className:i,...a},o){return(0,Y.jsxs)(`div`,{...a,ref:o,className:L(`caps-game-meter`,i),children:[(0,Y.jsxs)(`div`,{className:`caps-game-meter-readout`,children:[(0,Y.jsx)(`span`,{children:e}),(0,Y.jsxs)(`span`,{className:`caps-game-meter-value`,children:[t,` / `,n]})]}),(0,Y.jsx)(Fr,{"aria-label":e,value:t,max:n,tone:r})]})});function Ir({className:e,items:t,onCancel:n,onRemove:r,onRetry:i,rowClassName:a}){return t.length?(0,Y.jsx)(`div`,{"aria-live":`polite`,className:`caps-upload-queue flex w-full min-w-0 flex-col gap-sm ${e??``}`,"data-upload-rows":!0,children:t.map(e=>(0,Y.jsx)(zr,{item:e,onCancel:n,onRemove:r,onRetry:i,...a===void 0?{}:{rowClassName:a}},e.id))}):null}function Lr({action:e,id:t,onAction:n,retry:r=!1}){return e?(0,Y.jsx)(l,{"aria-label":e.accessibleLabel,title:e.label,variant:`ghost`,size:`xs`,className:`motion-reduce:transition-none`,icon:r?(0,Y.jsx)(ar,{}):(0,Y.jsx)(bt,{}),onClick:()=>void n(t),type:`button`}):null}function Rr({item:e}){return(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsx)(`span`,{className:`block min-w-0 truncate`,title:e.name,children:e.name}),(0,Y.jsx)(`div`,{className:`caps-upload-details`,children:(0,Y.jsxs)(`span`,{"aria-live":e.alert?`assertive`:void 0,className:`caps-upload-status min-w-0 break-words`,"data-upload-status":!0,role:e.alert?`alert`:void 0,children:[e.alert??e.statusLabel,` `,e.progressLabel]})})]})}function zr({item:e,onCancel:t,onRemove:n,onRetry:r,rowClassName:i}){return(0,Y.jsxs)(`div`,{className:`caps-upload-row grid w-full min-w-0 max-w-full grid-cols-[2rem_minmax(0,1fr)_auto] items-center gap-sm p-sm text-xs ${i??``}`,children:[e.preview.kind===`image`?(0,Y.jsx)(`img`,{alt:``,className:`caps-upload-preview mask mask-squircle size-8 shrink-0 object-cover`,src:e.preview.url}):(0,Y.jsx)(`span`,{"aria-hidden":`true`,className:`caps-upload-preview mask mask-squircle flex size-8 shrink-0 items-center justify-center bg-base-300`,children:(0,Y.jsx)(rr,{className:`size-4`})}),(0,Y.jsx)(Rr,{item:e}),(0,Y.jsx)(Br,{actions:e.actions,id:e.id,onCancel:t,onRemove:n,onRetry:r}),(0,Y.jsx)(Fr,{"aria-label":`${e.name} progress`,className:`caps-upload-progress`,tone:e.alert?`error`:e.progress===100?`success`:`accent`,max:100,value:e.progress??(e.alert?0:void 0)})]})}function Br({actions:e,id:t,onCancel:n,onRemove:r,onRetry:i}){return(0,Y.jsxs)(`div`,{className:`caps-upload-actions flex min-w-0 flex-wrap justify-end gap-xs`,children:[(0,Y.jsx)(Lr,{action:e.retry,id:t,onAction:i,retry:!0}),(0,Y.jsx)(Lr,{action:e.cancel,id:t,onAction:n}),(0,Y.jsx)(Lr,{action:e.remove,id:t,onAction:r})]})}var Vr={unchecked:`M3.25 5.9 L5.1 7.9 L8.8 3.8`,checked:`M3.25 5.9 L5.1 7.9 L8.8 3.8`,mixed:`M3.4 6 L6 6 L8.6 6`},Hr={blurStdDeviation:.22,alphaSlope:18,alphaIntercept:-8};function Ur({state:e}){let t=`caps-checkbox-${(0,J.useId)().replaceAll(`:`,``)}`,n=(0,J.useRef)(null),r=(0,J.useRef)(e).current,i=(0,J.useRef)(e),a=S();return(0,J.useLayoutEffect)(()=>{if(!n.current)return;let t=e!==`unchecked`,r=i.current!==`unchecked`,o=a||i.current===e;i.current=e;let s=Te(n.current),c=q(s,{ease:`inCubic`,duration:160}),l=en(n.current,{d:{to:Vr[e],...o?jn:q(s,{ease:`outCubic`,duration:200})},"stroke-dashoffset":{to:+!t,...o?jn:t?q(s,{ease:`inOutSine`,duration:260}):c},"stroke-width":o?{to:t?2.4:0,duration:0}:t&&!r?[{to:2.2,...q(s,{ease:`outCubic`,duration:65})},{to:2.4,delay:D(s,120),...An(s,{bounce:.35,duration:220})}]:{to:t?2.4:0,...c}});return()=>{l.cancel()}},[e,a]),(0,Y.jsxs)(`svg`,{className:`caps-checkbox-visual`,width:`24`,height:`24`,viewBox:`0 0 12 12`,"aria-hidden":`true`,focusable:`false`,children:[(0,Y.jsxs)(`defs`,{children:[(0,Y.jsx)(He,{id:`${t}-surface`,transform:`matrix(1 0 0 1 6 6)`}),(0,Y.jsx)(ot,{id:`${t}-shadow`}),(0,Y.jsx)(lt,{id:`${t}-inset`}),(0,Y.jsx)(Ct,{id:`${t}-goo`,values:Hr}),(0,Y.jsxs)(`filter`,{id:`${t}-relief`,x:`-25%`,y:`-25%`,width:`150%`,height:`150%`,colorInterpolationFilters:`sRGB`,children:[(0,Y.jsx)(`feGaussianBlur`,{in:`SourceAlpha`,stdDeviation:`0.28`,result:`relief`}),(0,Y.jsx)(`feSpecularLighting`,{in:`relief`,surfaceScale:`1.2`,specularConstant:`0.55`,specularExponent:`18`,lightingColor:`color-mix(in srgb, var(--color-white) calc(var(--depth) * 100%), var(--color-black))`,result:`light`,children:(0,Y.jsx)(`feDistantLight`,{azimuth:`225`,elevation:`55`})}),(0,Y.jsx)(`feComposite`,{in:`light`,in2:`SourceAlpha`,operator:`in`,result:`clipped-light`}),(0,Y.jsx)(`feBlend`,{in:`SourceGraphic`,in2:`clipped-light`,mode:`screen`})]}),(0,Y.jsx)(`mask`,{id:`${t}-contour`,maskUnits:`userSpaceOnUse`,x:`0`,y:`0`,width:`12`,height:`12`,style:{maskType:`alpha`},children:(0,Y.jsx)(`path`,{ref:n,d:Vr[r],fill:`none`,stroke:`var(--color-white)`,strokeWidth:r===`unchecked`?0:2.4,pathLength:`1`,strokeDasharray:`1`,strokeDashoffset:+(r===`unchecked`),strokeLinecap:`round`,strokeLinejoin:`round`,filter:e===`mixed`?void 0:`url(#${t}-goo)`})}),(0,Y.jsx)(`clipPath`,{id:`${t}-well`,children:(0,Y.jsx)(`rect`,{x:`1`,y:`1`,width:`10`,height:`10`,rx:`2.5`})})]}),(0,Y.jsx)(`rect`,{className:`caps-checkbox-track`,x:`0.5`,y:`0.5`,width:`11`,height:`11`,rx:`3`,filter:`url(#${t}-inset)`}),(0,Y.jsx)(`g`,{clipPath:`url(#${t}-well)`,children:(0,Y.jsx)(`g`,{filter:`url(#${t}-shadow)`,children:(0,Y.jsx)(`g`,{filter:`url(#${t}-relief)`,children:(0,Y.jsx)(`g`,{mask:`url(#${t}-contour)`,children:(0,Y.jsx)(`rect`,{x:`0`,y:`0`,width:`12`,height:`12`,fill:`url(#${t}-surface)`})})})})})]})}var Wr=(0,J.forwardRef)(function({className:e,appearance:t,indicator:n,invalid:r,indeterminate:i=!1,checked:a,defaultChecked:o=!1,onChange:s,...c},l){let u=(0,J.useRef)(null),[d,f]=(0,J.useState)(o),p=a??d,m=i?`mixed`:p?`checked`:`unchecked`;return(0,J.useImperativeHandle)(l,()=>{if(!u.current)throw Error(`Checkbox input is not mounted`);return u.current},[]),(0,J.useLayoutEffect)(()=>{u.current&&(u.current.indeterminate=i)},[i]),(0,J.useEffect)(()=>{let e=u.current?.form;if(!e||a!==void 0)return;let t=e=>{queueMicrotask(()=>{!e.defaultPrevented&&u.current&&f(o)})};return e.addEventListener(`reset`,t),()=>{e.removeEventListener(`reset`,t)}},[a,o,c.form]),(0,Y.jsxs)(`span`,{className:`caps-checkbox`,"data-appearance":t===`compact`?t:void 0,"data-state":m,"data-custom-indicator":n!==void 0||void 0,children:[(0,Y.jsx)(`input`,{...c,checked:p,"aria-checked":i?`mixed`:p,"aria-invalid":r?!0:c[`aria-invalid`]===!1?void 0:c[`aria-invalid`],className:L(`caps-checkbox-input`,e),onChange:e=>{a===void 0&&f(e.target.checked),s?.(e),e.currentTarget.indeterminate=i},ref:u,type:`checkbox`}),n===void 0?(0,Y.jsx)(Ur,{state:m}):n]})}),Gr=Xn({keyCode:Qn(229)});function Kr(e){return e.nativeEvent.isComposing||we(Gr,e.nativeEvent).success}var qr=J.createContext(void 0);function Q(e){let t=J.useContext(qr);if(t===void 0&&!e)throw Error(on(47));return t}var Jr=e(Le(),1),Yr={...z,disabled:e=>e.disabled,instantType:e=>e.instantType===`trigger-change`&&!z.open(e)?void 0:e.instantType,openMethod:e=>e.openMethod,openChangeReason:e=>e.openChangeReason,isPressOpenedByTrigger:(e,t)=>e.openChangeReason===`trigger-press`&&z.isOpenedByTrigger(e,t),isTouchPressOpen:(e,t)=>t&&e.openMethod===`touch`&&e.openChangeReason===`trigger-press`,hasTriggerFocusGuards:(e,t)=>z.isOpenedByTrigger(e,t)&&!e.focusManagerModal,modal:e=>e.modal,titleElementId:e=>e.titleElementId,descriptionElementId:e=>e.descriptionElementId,openOnHover:e=>e.openOnHover,closeDelay:e=>e.closeDelay,adaptiveOrigin:e=>e.adaptiveOrigin},Xr=class extends _{constructor(e,t,n){let r=new nn;super(Zr(e,r,t,n),Qr(r),Yr)}setOpen=(e,t)=>{let n=t.reason===ve,r=t.reason===`trigger-press`&&t.event.detail===0,i=!e&&(t.reason===`escape-key`||t.reason==null),a=w(t),o=this.select(`activeTriggerId`);if(!e&&t.reason===`close-press`&&t.trigger==null&&o!=null&&(t.trigger=this.context.triggerElements.getById(o)??this.select(`activeTriggerElement`)??void 0),this.context.onOpenChange?.(e,t),t.isCanceled)return;this.state.floatingRootContext.dispatchOpenChange(e,t);let s=()=>{let n=Ae(this.state,e,t.trigger,a());n.openChangeReason=t.reason,this.update(n)};n?(this.context.stickIfOpen=!0,this.context.stickIfOpenTimeout.start(500,()=>{this.context.stickIfOpen=!1}),Jr.flushSync(s)):s();let c;r?c=`click`:i?c=`dismiss`:t.reason===`focus-out`&&(c=`focus`),this.set(`instantType`,c)}};function Zr(e,t,n,r=!1){let i={...ae(t,n,r),disabled:!1,modal:!1,focusManagerModal:!1,instantType:void 0,openMethod:null,openChangeReason:null,titleElementId:void 0,descriptionElementId:void 0,openOnHover:!1,closeDelay:0,adaptiveOrigin:void 0,...e};return i.open&&e?.mounted===void 0&&(i.mounted=!0),i}function Qr(e){return{popupRef:J.createRef(),onOpenChange:void 0,onOpenChangeComplete:void 0,triggerFocusTargetRef:J.createRef(),beforeTriggerFocusGuardRef:J.createRef(),beforeContentFocusGuardRef:J.createRef(),stickIfOpenTimeout:new he,stickIfOpen:!0,triggerElements:e}}var $r=k(function({props:e}){let{children:t,open:n,defaultOpen:r=!1,onOpenChange:i,onOpenChangeComplete:a,modal:o=!1,handle:s,triggerId:c,defaultTriggerId:l=null}=e,u=ti(s,{modal:o,open:r,openProp:n,activeTriggerId:l,triggerIdProp:c});u.useControlledProp(`openProp`,n),u.useControlledProp(`triggerIdProp`,c);let d=u.useState(`open`),f=u.useState(`mounted`),p=u.useState(`payload`);u.useContextCallback(`onOpenChange`,i),u.useContextCallback(`onOpenChangeComplete`,a),Ie(u,d),y(u);let{forceUnmount:m}=P(d,u,()=>{u.context.stickIfOpen=!0,u.set(`openChangeReason`,null)});u.useSyncedValues({modal:o}),J.useEffect(()=>{d||u.context.stickIfOpenTimeout.clear()},[u,d]),J.useImperativeHandle(e.actionsRef,()=>({unmount:m,close:()=>u.setOpen(!1,C(Mt))}),[m,u]);let h=d||f||s!=null;return(0,Y.jsxs)(qr.Provider,{value:u,children:[s&&(0,Y.jsx)(Ee,{handle:s,store:u}),h&&(0,Y.jsx)(ni,{store:u,modal:o}),typeof t==`function`?t({payload:p}):t]})});function ei(e){return Q(!0)?(0,Y.jsx)($r,{props:e}):(0,Y.jsx)(Et,{children:(0,Y.jsx)($r,{props:e})})}function ti(e,t){let n=j((e,n)=>new Xr(t,e,n));return J.useEffect(()=>n.context.stickIfOpenTimeout.disposeEffect(),[n]),n}function ni({store:e,modal:t}){let n=e.useState(`floatingRootContext`),r=le(n,{outsidePressEvent:{mouse:t===`trap-focus`?`sloppy`:`intentional`,touch:`sloppy`}}),i=r.reference,a=r.floating;return Nt(e,{activeTriggerProps:i,inactiveTriggerProps:i,popupProps:a}),null}var ri=R(function(e,n){let{render:r,className:a,style:o,disabled:s=!1,nativeButton:c=!0,handle:l,payload:u,openOnHover:d=!1,delay:f=300,closeDelay:p=0,id:m,...h}=e,_=Q(!0),v=ie(l)??_;if(!v)throw Error(on(74));let y=It(m),b=v.useState(`isTriggerActive`,y),x=v.useState(`floatingRootContext`),S=v.useState(`isOpenedByTrigger`,y),C=v.useState(`triggerPopupId`,y),w=J.useRef(null),{registerTrigger:T,isMountedByThisTrigger:E}=Pe(y,w,v,{payload:u,disabled:s,openOnHover:d,closeDelay:p}),D=v.useState(`isPressOpenedByTrigger`,y),O=v.useState(`isTouchPressOpen`,d),k=v.useState(`hasTriggerFocusGuards`,y),A=i(x,{enabled:!s&&d&&!O,mouseOnly:!0,move:!1,handleClose:gt(),restMs:f,delay:{close:p},triggerElementRef:w,isActiveTrigger:b,isClosing:()=>v.select(`transitionStatus`)===`ending`}),j=W(()=>v.context.stickIfOpen),M=t(x,{stickIfOpen:j}),N=Xt(()=>v.select(`open`),e=>{v.set(`openMethod`,e)}),P=v.useState(`triggerProps`,E),{getButtonProps:F,buttonRef:I}=Be({disabled:s,native:c}),L={open(e){return D?xe.open(e):g.open(e)}},{handlePreFocusGuardFocus:R,handleFocusTargetFocus:ee}=at(v,w),te=ht(`button`,e,{state:{disabled:s,open:S},ref:[I,n,T,w],props:[M.reference,A,P,N,{[Ze]:``,id:y,"aria-haspopup":`dialog`,"aria-expanded":S,"aria-controls":C},h,F],stateAttributesMapping:L}),ne=(0,Y.jsx)(J.Fragment,{children:te},y);return k?(0,Y.jsxs)(J.Fragment,{children:[(0,Y.jsx)(tn,{ref:v.context.beforeTriggerFocusGuardRef,onFocus:R}),ne,(0,Y.jsx)(tn,{ref:v.context.triggerFocusTargetRef,onFocus:ee})]}):ne}),ii=J.createContext(void 0);function ai(){let e=J.useContext(ii);if(e===void 0)throw Error(on(45));return e}var oi=J.forwardRef(function(e,t){let{keepMounted:n=!1,...r}=e;return Q().useState(`mounted`)||n?(0,Y.jsx)(ii.Provider,{value:n,children:(0,Y.jsx)(Ht,{ref:t,...r})}):null}),si=J.createContext(void 0);function ci(){let e=J.useContext(si);if(!e)throw Error(on(46));return e}var li=J.forwardRef(function(e,t){let{render:n,className:r,style:i,anchor:a,positionMethod:o,side:s,align:c,sideOffset:l,alignOffset:u,collisionBoundary:f=`clipping-ancestors`,collisionPadding:p,arrowPadding:m,sticky:h,disableAnchorTracking:g=!1,collisionAvoidance:_=Yt,...v}=e,y=Q(),b=ai(),x=Rt(),S=y.useState(`floatingRootContext`),C=y.useState(`mounted`),w=y.useState(`open`),T=y.useState(`openChangeReason`),E=y.useState(`activeTriggerElement`),D=y.useState(`modal`),O=y.useState(`openMethod`),k=y.useState(`positionerElement`),A=y.useState(`instantType`),j=y.useState(`transitionStatus`),M=y.useState(`adaptiveOrigin`),N=d({anchor:a,floatingRootContext:S,positionMethod:o,mounted:C,side:s,sideOffset:l,align:c,alignOffset:u,arrowPadding:m,collisionBoundary:f,collisionPadding:p,sticky:h,disableAnchorTracking:g,keepMounted:b,nodeId:x,collisionAvoidance:_,adaptiveOrigin:M}),P=S.useState(`domReferenceElement`);Qt({store:y,domReference:P,positionerElement:k,open:w});let F=D===!0&&T!==`trigger-hover`;$t(w&&F,O===`touch`,k,E);let I=y.useStateSetter(`positionerElement`),L={open:w,side:N.side,align:N.align,anchorHidden:N.anchorHidden,instant:A},R=Ke(e,L,{styles:N.positionerStyles,transitionStatus:j,props:v,refs:[t,I],hidden:!C,inert:!w});return(0,Y.jsxs)(si.Provider,{value:N,children:[C&&F&&(0,Y.jsx)(ge,{inert:be(!w),cutout:E}),(0,Y.jsx)(Gt,{id:x,children:R})]})}),ui=J.createContext(void 0);function di(){let[e,t]=J.useState(0),n=W(()=>(t(e=>e+1),()=>{t(e=>Math.max(0,e-1))}));return{context:J.useMemo(()=>({register:n}),[n]),hasClosePart:e>0}}var fi=J.forwardRef(function(e,t){let{render:n,className:r,style:i,initialFocus:a,finalFocus:s,...c}=e,l=Q(),d=ci(),f=se(!0)!=null,{context:m,hasClosePart:g}=di(),_=l.useState(`open`),v=l.useState(`openMethod`),y=l.useState(`instantType`),b=l.useState(`transitionStatus`),x=l.useState(`popupProps`),S=l.useState(`titleElementId`),C=l.useState(`descriptionElementId`),w=l.useState(`modal`),T=l.useState(`mounted`),E=l.useState(`openChangeReason`),D=l.useState(`activeTriggerElement`),O=l.useState(`floatingRootContext`),k=O.useState(`floatingId`),A=l.useState(`disabled`),j=l.useState(`openOnHover`),M=l.useState(`closeDelay`);u({open:_,ref:l.context.popupRef,onComplete(){_&&l.context.onOpenChangeComplete?.(!0)}}),mt(O,{enabled:j&&!A,closeDelay:M});let N=a===void 0?Se(l.context.popupRef):a,P=w!==!1&&g;l.useSyncedValue(`focusManagerModal`,P);let F=l.useStateSetter(`popupElement`),I={open:_,side:d.side,align:d.align,instant:y,transitionStatus:b},L=ht(`div`,e,{state:I,ref:[t,l.context.popupRef,F],props:[x,{id:k,role:`dialog`,...o,"aria-labelledby":S,"aria-describedby":C,onKeyDown(e){f&&p.has(e.key)&&e.stopPropagation()}},h(b),c],stateAttributesMapping:Zt});return(0,Y.jsx)(nt,{context:O,openInteractionType:v,modal:P,disabled:!T||E===`trigger-hover`,initialFocus:N,returnFocus:s,restoreFocus:`popup`,getInsideElements:()=>[l.context.beforeTriggerFocusGuardRef.current],previousFocusableElement:Ot(D)?D:void 0,nextFocusableElement:l.context.triggerFocusTargetRef,beforeContentFocusGuardRef:l.context.beforeContentFocusGuardRef,children:(0,Y.jsx)(ui.Provider,{value:m,children:L})})});function pi({getKey:e,isDisabled:t=()=>!1,items:n,getFallbackKey:r}){let i=(0,J.useMemo)(()=>{let r=n.map(e);if(r.some(e=>!e))throw Error(`Selectable items require non-empty keys`);if(new Set(r).size!==r.length)throw Error(`Selectable items require unique keys`);return n.filter(e=>!t(e))},[e,t,n]),[a,o]=(0,J.useState)(null),s=r?.(i)??null,c=a!==null&&i.some(t=>e(t)===a)?a:s!==null&&i.some(t=>e(t)===s)?s:null;(0,J.useEffect)(()=>{a!==null&&!i.some(t=>e(t)===a)&&o(null)},[a,i,e]);let l=i.find(t=>e(t)===c),u=l?i.findIndex(t=>e(t)===c):-1;return{activeIndex:u,activeItem:l,activeKey:c,enabledItems:i,move:(t,n)=>{if(i.length===0)return;let r=n?n===`start`?0:i.length-1:u<0?t>0?0:i.length-1:(u+t+i.length)%i.length,a=i[r];a&&o(e(a))},setActiveKey:o}}var mi=(0,J.forwardRef)(function({children:e,className:t,type:n=`button`,...r},i){return(0,Y.jsxs)(`button`,{...r,ref:i,type:n,className:L(`select caps-select caps-combobox-trigger w-full`,t),children:[(0,Y.jsx)(`span`,{children:e}),(0,Y.jsx)(yn,{className:`caps-select-chevron`,"aria-hidden":`true`})]})});function hi({defaultInputValue:e,defaultOpen:t,defaultValue:n,getKey:r,getSearchText:i,groupBy:a,id:o,isDisabled:s,items:c,onOpenChange:l,onCommit:u,multiple:d,controlledOpen:f,controlledKeys:p,trigger:m}){let h=`${o}-listbox`,[g,_]=(0,J.useState)(e),[v,y]=(0,J.useState)(!1),[b,x]=(0,J.useState)(n),[S,C]=(0,J.useState)(t),w=p??(b===null?[]:[b]),T=m?f??S:!0,E=(0,J.useMemo)(()=>{let e=g.trim().toLowerCase();return e?c.filter(t=>i(t).toLowerCase().includes(e)):c},[i,c,g]),D=pi({getKey:r,isDisabled:s,items:E});(0,J.useEffect)(()=>{if(D.activeKey!==null)return;let e=D.enabledItems.find(e=>w.includes(r(e)))??D.enabledItems[0];e&&D.setActiveKey(r(e))},[D.activeKey,D.enabledItems,D.setActiveKey,r,w]);let O=e=>{y(!1),e||_(``),f===void 0&&C(e),l?.(e)},k=e=>`${h}-option-${encodeURIComponent(e)}`,A=e=>{let t=r(e);p===void 0&&x(t),u(e),m&&!d&&O(!1)},j=e=>{y(!0),_(e.target.value),D.setActiveKey(null)},M=e=>{if(Kr(e))return;let t;switch(e.key){case`ArrowDown`:t=[1,void 0];break;case`ArrowUp`:t=[-1,void 0];break;case`End`:t=[1,`end`];break;case`Home`:t=[-1,`start`]}t?(y(!0),e.preventDefault(),D.move(t[0],t[1])):e.key===`Enter`&&D.activeItem&&(e.preventDefault(),A(D.activeItem))},N=(0,J.useMemo)(()=>{if(!a)return[{label:``,items:E}];let e=new Map;for(let t of E){let n=a(t),r=e.get(n);r?r.push(t):e.set(n,[t])}return[...e].map(([e,t])=>({label:e,items:t}))},[E,a]);return{keyboardNavigation:v,onPointerMove:()=>{y(!1)},activeKey:D.activeKey,activeItem:D.activeItem,groups:N,inputValue:g,listboxId:h,onInputChange:j,onInputKeyDown:M,optionId:k,open:T,commit:A,selectedKeys:w,setOpen:O}}function gi(e){let{"aria-describedby":t,"aria-invalid":n,"aria-label":r,"aria-labelledby":i,"aria-required":a,activeTone:o=`neutral`,container:s,contentClassName:c,defaultInputValue:l=``,defaultOpen:u=!1,defaultValue:d=null,emptyMessage:f=`No matches`,getKey:p,getLabel:m,getSearchText:h=m,groupBy:g,id:_,inputProps:v,inputRef:y,isDisabled:b=()=>!1,items:x,onOpenChange:S,onValueChange:C,multiple:w,open:T,placeholder:E=`Search…`,renderItem:D,rootRef:O,trigger:k,triggerRef:A,value:j,...M}=e,N=e=>{let t=p(e);if(w){let e=j.includes(t)?j.filter(e=>e!==t):[...j,t];C?.(e,x.filter(t=>e.includes(p(t))))}else C?.(t,e)},P;w?P=j:j!==void 0&&(P=j===null?[]:[j]);let F=(0,J.useId)(),I=k?.props??v,R=_??I?.id??F,ee={id:R,"aria-describedby":[t,I?.[`aria-describedby`]].filter(Boolean).join(` `)||void 0,"aria-invalid":n??I?.[`aria-invalid`],"aria-label":I?.[`aria-label`]??r,"aria-labelledby":I?.[`aria-labelledby`]??i,"aria-required":a??I?.[`aria-required`]},{keyboardNavigation:te,onPointerMove:ne,activeItem:re,activeKey:ie,commit:ae,groups:oe,inputValue:se,listboxId:z,onInputChange:ce,onInputKeyDown:le,open:ue,optionId:de,selectedKeys:fe,setOpen:pe}=hi({defaultInputValue:l,defaultOpen:u,defaultValue:d,getKey:p,getSearchText:h,groupBy:g,id:R,isDisabled:b,items:x,onOpenChange:S,onCommit:N,multiple:w??!1,controlledOpen:T,controlledKeys:P,trigger:k});kt(()=>{k&&pe(!1)});let me=xt(`popover`),he=s===void 0?me:s,ge=st(`.caps-combobox-option[data-active="true"]:not(:disabled), [data-navigation="pointer"] .caps-combobox-option:hover:not(:disabled)`),_e=(0,Y.jsx)(Bn,{...v,...k?{}:ee,"aria-activedescendant":re?de(p(re)):void 0,"aria-autocomplete":`list`,"aria-controls":z,"aria-expanded":!0,className:L(`input-sm`,v?.className),id:k?v?.id??`${R}-input`:R,onChange:e=>{v?.onChange?.(e),ce(e)},onKeyDown:e=>{v?.onKeyDown?.(e),e.defaultPrevented||le(e)},placeholder:v?.placeholder??E,ref:y,role:`combobox`,value:se}),ve=(0,Y.jsx)(`div`,{id:z,ref:ge,className:`caps-combobox-list`,"data-navigation":te?`keyboard`:`pointer`,onPointerMove:ne,role:`listbox`,"aria-multiselectable":w??void 0,children:oe.every(e=>e.items.length===0)?(0,Y.jsx)(`div`,{className:`px-md py-md text-sm text-base-content`,children:f}):oe.map(e=>(0,Y.jsxs)(`div`,{"aria-label":e.label||void 0,role:e.label?`group`:void 0,children:[e.label?(0,Y.jsx)(`div`,{className:`px-md pb-xs pt-sm text-xs text-base-content uppercase tracking-wider`,children:e.label}):null,e.items.map(e=>{let t=p(e),n=b(e),r=ie===t,i={active:r,disabled:n,selected:fe.includes(t)};return(0,Y.jsxs)(`button`,{"aria-disabled":n||void 0,"aria-selected":i.selected,className:`caps-combobox-option`,"data-active":r&&te,disabled:n,id:de(t),onClick:()=>{ae(e)},onMouseDown:e=>{e.preventDefault()},role:`option`,tabIndex:-1,type:`button`,children:[(0,Y.jsx)(`span`,{"aria-hidden":`true`,className:`caps-combobox-check`,children:i.selected?(0,Y.jsx)($n,{}):null}),D?.(e,r,i)??m(e)]},t)})]},e.label))});return k?(0,Y.jsx)(`div`,{...M,className:L(M.className),ref:O,children:(0,Y.jsxs)(ei,{modal:!0,onOpenChange:pe,open:ue,children:[(0,Y.jsx)(ri,{...ee,"aria-haspopup":`dialog`,className:`btn`,ref:A,render:k}),he===null?null:(0,Y.jsx)(oi,{container:he,children:(0,Y.jsx)(li,{align:`start`,side:`bottom`,sideOffset:4,className:`z-(--stipe-layer-popover)`,children:(0,Y.jsxs)(fi,{"data-active-tone":o,className:L(`min-w-40 rounded-box border border-base-300 bg-base-100 p-xs shadow-lg outline-none caps-combobox-panel caps-combobox-popup`,c),children:[(0,Y.jsx)(`div`,{className:`caps-combobox-search`,children:_e}),ve]})})})]})}):(0,Y.jsx)(`div`,{...M,className:L(M.className),ref:O,children:(0,Y.jsxs)(`div`,{className:L(`caps-combobox-panel`,c),"data-active-tone":o,children:[(0,Y.jsx)(`div`,{className:`caps-combobox-search`,children:_e}),ve]})})}function _i({icon:e,caption:t}){return(0,Y.jsxs)(`span`,{className:`caps-icon-choice-mark`,"aria-hidden":`true`,children:[(0,Y.jsx)(`span`,{className:`caps-icon-choice-art`,children:e}),t?(0,Y.jsx)(`span`,{className:`caps-icon-choice-caption`,children:t}):null,(0,Y.jsx)(`span`,{className:`caps-icon-choice-lamp`})]})}var vi=(0,J.forwardRef)(function({label:e,icon:t,caption:n,appearance:r,className:i,...a},o){return(0,Y.jsx)(`label`,{className:`caps-icon-choice`,"data-appearance":r===`compact`?r:void 0,children:(0,Y.jsx)(Wr,{...a,appearance:r??`default`,"aria-label":e,className:L(`caps-icon-choice-input`,i),indicator:(0,Y.jsx)(_i,{icon:t,caption:n}),ref:o})})}),yi=(0,J.forwardRef)(function({label:e,icon:t,hint:n,className:r,...i},a){let o=(0,J.useId)(),s=[i[`aria-describedby`],n?o:null].filter(Boolean).join(` `)||void 0;return(0,Y.jsx)(`label`,{className:`caps-check-key`,children:(0,Y.jsx)(Wr,{...i,"aria-label":e,"aria-describedby":s,className:L(`caps-check-key-input`,r),indicator:(0,Y.jsxs)(`span`,{className:`caps-check-key-face`,"aria-hidden":`true`,children:[t?(0,Y.jsx)(`span`,{className:`caps-check-key-icon`,children:t}):null,(0,Y.jsxs)(`span`,{className:`caps-check-key-copy`,children:[(0,Y.jsx)(`span`,{className:`caps-check-key-label`,children:e}),n?(0,Y.jsx)(`span`,{className:`caps-check-key-hint`,id:o,children:n}):null]}),(0,Y.jsx)(`span`,{className:`caps-check-key-lamp`})]}),ref:a})})});function bi({className:e,...t}){return(0,Y.jsx)(`div`,{...t,className:L(`caps-check-keys`,e)})}function xi({checked:e}){let t=`caps-radio-${(0,J.useId)().replaceAll(`:`,``)}`,n=(0,J.useRef)(null),r=(0,J.useRef)(e).current,i=(0,J.useRef)(e),a=(0,J.useRef)(null),o=Ne(a),{reduced:s}=o;return(0,J.useLayoutEffect)(()=>{if(!n.current)return;let t=s||i.current===e;i.current=e;let r=e?4:0,a=q(o,{ease:`outCubic`,duration:75}),c=e?An(o,{bounce:.65,duration:300}):q(o,{ease:`inCubic`,duration:100}),l=en(n.current,t?{rx:r,ry:r,cy:6,duration:0}:{rx:[{to:e?3.5:4.15,...a},{to:r,...c}],ry:[{to:e?4.5:3.85,...a},{to:r,...c}],cy:[{to:e?5.85:6.1,...a},{to:6,...c}]});return()=>{l.cancel()}},[e,s,o]),(0,Y.jsxs)(`svg`,{ref:a,className:`caps-radio-visual`,width:`24`,height:`24`,viewBox:`0 0 12 12`,"aria-hidden":`true`,focusable:`false`,children:[(0,Y.jsxs)(`defs`,{children:[(0,Y.jsx)(He,{id:`${t}-surface`,transform:`matrix(1 0 0 1 6 6)`}),(0,Y.jsx)(ot,{id:`${t}-shadow`}),(0,Y.jsx)(lt,{id:`${t}-inset`}),(0,Y.jsx)(`clipPath`,{id:`${t}-well`,children:(0,Y.jsx)(`circle`,{cx:`6`,cy:`6`,r:`5`})})]}),(0,Y.jsx)(`circle`,{className:`caps-radio-track`,cx:`6`,cy:`6`,r:`5.5`,filter:`url(#${t}-inset)`}),(0,Y.jsx)(`g`,{clipPath:`url(#${t}-well)`,children:(0,Y.jsx)(`ellipse`,{ref:n,cx:`6`,cy:`6`,rx:r?4:0,ry:r?4:0,fill:`url(#${t}-surface)`,filter:`url(#${t}-shadow)`})})]})}var Si=(0,J.createContext)(null),Ci=(0,J.forwardRef)(function({children:e,className:t,defaultValue:n,disabled:r=!1,name:i,onValueChange:a,orientation:o=`vertical`,value:s,...c},l){let u=(0,J.useId)(),d=(0,J.useRef)(null);(0,J.useImperativeHandle)(l,()=>{if(!d.current)throw Error(`RadioGroup is not mounted`);return d.current},[]);let f=i??`radio-group-${u}`,[p,m]=(0,J.useState)(n),h=s??p;return(0,J.useEffect)(()=>{let e=d.current?.form;if(!e||s!==void 0)return;let t=e=>{queueMicrotask(()=>{e.defaultPrevented||m(n)})};return e.addEventListener(`reset`,t),()=>{e.removeEventListener(`reset`,t)}},[s,n,c.form]),(0,Y.jsx)(Si.Provider,{value:{disabled:r,name:f,onValueChange:e=>{s===void 0&&m(e),a?.(e)},value:h},children:(0,Y.jsx)(`fieldset`,{...c,className:L(`flex gap-md`,o===`horizontal`?`flex-row flex-wrap`:`flex-col`,t),disabled:r,role:c.role??`radiogroup`,ref:d,children:e})})}),wi=(0,J.forwardRef)(function({className:e,indicator:t,onChange:n,onClick:r,value:i,...a},o){let s=(0,J.useContext)(Si);if(!s)throw Error(`RadioGroupItem must be used inside <RadioGroup>`);let c=s.value===i,l=e=>{n?.(e),e.target.checked&&s.onValueChange?.(i)};return(0,Y.jsxs)(`span`,{className:`caps-radio`,"data-checked":c,"data-custom-indicator":t!==void 0||void 0,children:[(0,Y.jsx)(`input`,{...a,"aria-checked":c,checked:c,className:L(`caps-radio-input`,e),disabled:s.disabled||a.disabled,name:s.name,onChange:l,onClick:r,ref:o,type:`radio`,value:i}),t===void 0?(0,Y.jsx)(xi,{checked:c}):t]})}),Ti=(0,J.forwardRef)(function({description:e,id:t,meta:n,title:r,...i},a){let o=(0,J.useContext)(Si),s=(0,J.useId)(),c=t??s,l=o?.value===i.value,u=o?.disabled===!0||i.disabled===!0;return(0,Y.jsxs)(`label`,{className:`caps-choice-card`,"data-checked":l,"data-disabled":u||void 0,htmlFor:c,children:[(0,Y.jsx)(wi,{...i,"aria-describedby":e?`${c}-description`:void 0,"aria-labelledby":`${c}-title`,id:c,ref:a}),(0,Y.jsxs)(`span`,{className:`caps-choice-card-copy`,children:[(0,Y.jsx)(`span`,{className:`caps-choice-card-title`,id:`${c}-title`,children:r}),e?(0,Y.jsx)(`span`,{className:`caps-choice-card-description`,id:`${c}-description`,children:e}):null]}),n?(0,Y.jsx)(`span`,{className:`caps-choice-card-meta`,children:n}):null]})}),Ei=(0,J.forwardRef)(function({label:e,icon:t,caption:n,art:r=`dim`,className:i,...a},o){return(0,Y.jsx)(`label`,{className:`caps-icon-choice`,"data-art":r===`color`?r:void 0,children:(0,Y.jsx)(wi,{...a,"aria-label":e,className:L(`caps-icon-choice-input`,i),indicator:(0,Y.jsx)(_i,{icon:t,caption:n}),ref:o})})});(0,J.forwardRef)(function({label:e,color:t,className:n,...r},i){return(0,Y.jsx)(`label`,{className:`caps-icon-choice`,"data-art":`color`,"data-swatch":``,title:e,children:(0,Y.jsx)(wi,{...r,"aria-label":e,className:L(`caps-icon-choice-input`,n),indicator:(0,Y.jsx)(_i,{icon:(0,Y.jsx)(`span`,{className:`caps-swatch-dot`,style:{backgroundColor:t}})}),ref:i})})});var Di=(0,J.forwardRef)(function({className:e,invalid:t,...n},r){return(0,Y.jsxs)(`span`,{className:`caps-select-shell`,children:[(0,Y.jsx)(`select`,{...n,"aria-invalid":t?!0:n[`aria-invalid`]===!1?void 0:n[`aria-invalid`],className:L(`select select-bordered caps-select w-full`,t&&`select-error`,e),ref:r}),!n.multiple&&(!n.size||n.size<=1)?(0,Y.jsx)(yn,{className:`caps-select-chevron`,"aria-hidden":`true`}):null]})});function Oi({checked:e}){let t=`caps-switch-${(0,J.useId)().replaceAll(`:`,``)}`,n=(0,J.useRef)(null),r=(0,J.useRef)(null),i=(0,J.useRef)(e).current,a=(0,J.useRef)(e),o=S();return(0,J.useLayoutEffect)(()=>{if(!n.current||!r.current)return;let t=o||a.current===e;a.current=e;let i=e?16:8,s=Te(n.current),c=An(s,{bounce:.25,duration:440}),l=q(s,{ease:`inOutSine`,duration:100}),u=en(n.current,t?{x:2,y:2,width:i,height:8,duration:0}:{x:[{to:e?2.5:1.5,...l},{to:2,...c}],y:[{to:1.5,...l},{to:2,...c}],height:[{to:9,...l},{to:8,...c}],width:[{to:e?7:16.5,...l},{to:i,...c}]}),d=en(r.current,{gradientTransform:e?`matrix(2 0 0 1 10 6)`:`matrix(1 0 0 1 6 6)`,...t?{duration:0}:{delay:l.duration,...c}});return()=>{u.cancel(),d.cancel()}},[e,o]),(0,Y.jsxs)(`svg`,{className:`caps-switch-visual`,width:`40`,height:`24`,viewBox:`0 0 20 12`,"aria-hidden":`true`,focusable:`false`,children:[(0,Y.jsxs)(`defs`,{children:[(0,Y.jsx)(He,{ref:r,id:`${t}-surface`,transform:i?`matrix(2 0 0 1 10 6)`:`matrix(1 0 0 1 6 6)`}),(0,Y.jsx)(ot,{id:`${t}-shadow`}),(0,Y.jsx)(lt,{id:`${t}-inset`}),(0,Y.jsx)(`clipPath`,{id:`${t}-track`,children:(0,Y.jsx)(`rect`,{x:`1`,y:`1`,width:`18`,height:`10`,rx:`5`})})]}),(0,Y.jsx)(`rect`,{className:`caps-switch-track`,filter:`url(#${t}-inset)`,x:`0.5`,y:`0.5`,width:`19`,height:`11`,rx:`5.5`}),(0,Y.jsx)(`g`,{clipPath:`url(#${t}-track)`,children:(0,Y.jsx)(`rect`,{ref:n,x:`2`,y:`2`,width:i?16:8,height:`8`,rx:`4`,fill:`url(#${t}-surface)`,filter:`url(#${t}-shadow)`})})]})}var ki=(0,J.forwardRef)(function({className:e,checked:t,defaultChecked:n=!1,onChange:r,onCheckedChange:i,...a},o){let s=(0,J.useRef)(null),[c,l]=(0,J.useState)(n),u=t??c;return(0,J.useImperativeHandle)(o,()=>{if(!s.current)throw Error(`Switch input is not mounted`);return s.current},[]),(0,J.useEffect)(()=>{let e=s.current?.form;if(!e||t!==void 0)return;let r=e=>{queueMicrotask(()=>{!e.defaultPrevented&&s.current&&l(n)})};return e.addEventListener(`reset`,r),()=>{e.removeEventListener(`reset`,r)}},[t,n,a.form]),(0,Y.jsxs)(`span`,{className:`caps-switch`,"data-checked":u,children:[(0,Y.jsx)(`input`,{...a,checked:u,className:L(`caps-switch-input`,e),onChange:e=>{t===void 0&&l(e.target.checked),r?.(e),i?.(e.target.checked)},ref:s,role:`switch`,type:`checkbox`}),(0,Y.jsx)(Oi,{checked:u})]})}),Ai=(0,J.forwardRef)(function({className:e,invalid:t,...n},r){return(0,Y.jsx)(`textarea`,{...n,"aria-invalid":t?!0:n[`aria-invalid`]===!1?void 0:n[`aria-invalid`],className:L(`textarea textarea-bordered w-full`,t&&`textarea-error`,e),ref:r})}),ji=K(H),Mi=K(r),Ni=K(We(et)),Pi=K(de(H)),Fi=de(_e(File)),Ii=K(Fi),Li=At([H,et,r,dt,rt,de(H),Fi]),Ri=K(Li),$=e=>V(ji(e.state.value),()=>``),zi=e=>V(Mi(e.state.value),()=>!1),Bi=e=>V(Ni(e.state.value),()=>null),Vi=e=>V(Pi(e.state.value),()=>[]),Hi=e=>V(Ii(e.state.value),()=>[]),Ui=e=>V(Ri(e.state.value),()=>null);function Wi({field:e,spec:t,locked:n,...r}){let[i,a]=(0,J.useState)(!1);return(0,Y.jsxs)(Pn,{children:[(0,Y.jsx)(Bn,{...r,name:t.name,disabled:n,type:i?`text`:`password`,autoComplete:`off`,spellCheck:!1,className:`caps-field-secret`,placeholder:t.placeholder,readOnly:t.readOnly,value:$(e),onBlur:e.handleBlur,onChange:t=>{e.handleChange(t.currentTarget.value)}}),(0,Y.jsx)(U,{type:`button`,variant:`outline`,size:`icon`,"aria-label":i?`Hide`:`Show`,"aria-pressed":i,disabled:n,onClick:()=>{a(e=>!e)},children:i?(0,Y.jsx)(tr,{"aria-hidden":`true`}):(0,Y.jsx)(nr,{"aria-hidden":`true`})})]})}var Gi={text:`text`,email:`email`,url:`url`,tel:`tel`};function Ki({spec:e,field:t,locked:n,...r}){let i=Hi(t),a=n||e.readOnly===!0,o=(0,J.useRef)(null);return(0,Y.jsxs)(`div`,{className:`flex flex-col gap-sm`,children:[(0,Y.jsx)(re,{asChild:!0,children:(0,Y.jsx)(`input`,{...r,ref:o,type:`file`,tabIndex:-1,required:r.required===!0&&i.length===0,name:e.name,accept:e.accept,multiple:e.multiple,disabled:a,onBlur:t.handleBlur,onChange:e=>{t.handleChange(Array.from(e.currentTarget.files??[])),e.currentTarget.value=``}})}),(0,Y.jsx)(U,{type:`button`,variant:`outline`,"aria-label":`Choose files for ${e.label}`,"aria-describedby":r[`aria-describedby`],"aria-invalid":r[`aria-invalid`],disabled:a,onBlur:t.handleBlur,onClick:()=>{o.current?.click()},children:`Choose files`}),(0,Y.jsx)(Ir,{items:i.map((e,t)=>({id:String(t),name:e.name,preview:{kind:`file`},progress:0,progressLabel:`${String(e.size)} bytes`,statusLabel:`Selected`,actions:a?{}:{remove:{label:`Remove`,accessibleLabel:`Remove ${e.name}`}}})),onRemove:e=>{t.handleChange(i.filter((t,n)=>String(n)!==e))},onCancel:()=>void 0,onRetry:()=>void 0})]})}function qi({spec:e,field:t,locked:n,...r}){let i=e=>{t.handleChange(e)},a={...r,name:e.name,disabled:n,onBlur:t.handleBlur};switch(e.kind){case`text`:case`email`:case`url`:case`tel`:return(0,Y.jsx)(Bn,{...a,type:Gi[e.kind],inputMode:e.kind===`text`?void 0:e.kind,autoComplete:e.autoComplete,placeholder:e.placeholder,maxLength:e.maxLength,readOnly:e.readOnly,value:$(t),onChange:e=>{i(e.currentTarget.value)}});case`textarea`:return(0,Y.jsx)(Ai,{...a,rows:e.rows??3,placeholder:e.placeholder,maxLength:e.maxLength,readOnly:e.readOnly,value:$(t),onChange:e=>{i(e.currentTarget.value)}});case`secret`:return(0,Y.jsx)(Wi,{...r,field:t,spec:e,locked:n});case`money`:return(0,Y.jsxs)(Pn,{children:[(0,Y.jsx)(Fn,{className:`caps-field-currency`,children:e.currency??`USD`}),(0,Y.jsx)(Bn,{...a,inputMode:`decimal`,autoComplete:`off`,className:`caps-field-amount`,placeholder:e.placeholder??`0.00`,readOnly:e.readOnly,value:$(t),onChange:e=>{i(e.currentTarget.value)}})]});case`date`:return(0,Y.jsx)(Bn,{...a,type:`date`,readOnly:e.readOnly,value:$(t),onChange:e=>{i(e.currentTarget.value)}});case`number`:return(0,Y.jsx)(Wn,{...a,...e.min===void 0?{}:{min:e.min},...e.max===void 0?{}:{max:e.max},...e.step===void 0?{}:{step:e.step},...e.unit===void 0?{}:{unit:e.unit},...e.wrap===void 0?{}:{wrap:e.wrap},disabled:n||e.readOnly===!0,decrementLabel:`Decrease ${e.label}`,incrementLabel:`Increase ${e.label}`,value:Bi(t),onValueChange:e=>{t.handleChange(e)}});case`select`:return(0,Y.jsxs)(Di,{...a,value:$(t),onChange:e=>{i(e.currentTarget.value)},children:[e.placeholder===void 0?null:(0,Y.jsx)(`option`,{value:``,disabled:!0,children:e.placeholder}),e.options.map(e=>(0,Y.jsx)(`option`,{value:e.value,disabled:e.disabled,children:e.label},e.value))]});case`combobox`:return(0,Y.jsx)(gi,{id:r.id??e.name,"aria-describedby":r[`aria-describedby`],"aria-invalid":r[`aria-invalid`],"aria-required":r[`aria-required`],items:e.options,getKey:e=>e.value,getLabel:e=>e.label,isDisabled:t=>t.disabled||n||e.readOnly===!0,value:$(t),...e.placeholder===void 0?{}:{placeholder:e.placeholder},trigger:(0,Y.jsx)(mi,{name:e.name,disabled:n||e.readOnly===!0,onBlur:t.handleBlur,children:e.options.find(e=>e.value===$(t))?.label??e.placeholder??`Choose…`}),inputProps:{"aria-label":`Search ${e.label}`,disabled:n||e.readOnly===!0},onValueChange:e=>{i(e??``),t.handleBlur()}});case`file`:return(0,Y.jsx)(Ki,{...r,spec:e,field:t,locked:n});case`checkbox`:return(0,Y.jsx)(Wr,{...a,disabled:n||e.readOnly===!0,checked:zi(t),onChange:e=>{t.handleChange(e.currentTarget.checked)}});case`switch`:return(0,Y.jsx)(ki,{...a,disabled:n||e.readOnly===!0,checked:zi(t),onCheckedChange:e=>{t.handleChange(e)}});case`radio`:case`icon-radio`:case`checkboxes`:case`icon-checkboxes`:return null}}var Ji=new Set([`radio`,`icon-radio`,`checkboxes`,`icon-checkboxes`]);function Yi({spec:e,field:t,locked:n,error:r,layout:i}){let a=n||e.readOnly===!0,o=e.label;if(e.kind===`checkboxes`||e.kind===`icon-checkboxes`){let n=Vi(t),s=(e,r)=>{t.handleChange(r?[...n,e]:n.filter(t=>t!==e))};return(0,Y.jsx)(zn,{legend:o,icon:e.icon,layout:i,...i===`columns`?{legendTitle:o}:{},description:e.help,disabled:a,error:r??null,children:e.kind===`icon-checkboxes`?(0,Y.jsx)(`div`,{className:`caps-field-icon-choices`,children:e.options.map(r=>(0,Y.jsx)(vi,{name:e.name,value:r.value,label:r.label,...r.caption===void 0?{}:{caption:r.caption},icon:r.icon,disabled:r.disabled,checked:n.includes(r.value),onBlur:t.handleBlur,onChange:e=>{s(r.value,e.currentTarget.checked)}},r.value))}):(0,Y.jsx)(bi,{children:e.options.map(r=>(0,Y.jsx)(yi,{name:e.name,value:r.value,label:r.label,icon:r.icon,hint:r.description,disabled:r.disabled,checked:n.includes(r.value),onBlur:t.handleBlur,onChange:e=>{s(r.value,e.currentTarget.checked)}},r.value))})})}let s=e.options.some(e=>e.description!==void 0||e.meta!==void 0);return(0,Y.jsx)(zn,{legend:o,icon:e.icon,layout:i,...i===`columns`?{legendTitle:o}:{},description:e.help,disabled:a,error:r??null,children:(0,Y.jsx)(Ci,{name:e.name,"aria-label":o,value:$(t),onValueChange:e=>{t.handleChange(e),t.handleBlur()},orientation:e.kind===`icon-radio`||s?`horizontal`:`vertical`,children:e.options.map(t=>e.kind===`icon-radio`?(0,Y.jsx)(Ei,{value:t.value,label:t.label,...t.caption===void 0?{}:{caption:t.caption},icon:t.icon,disabled:t.disabled},t.value):s?(0,Y.jsx)(Ti,{value:t.value,title:t.label,description:t.description,meta:t.meta,disabled:t.disabled},t.value):(0,Y.jsx)(Mn,{label:t.label,orientation:`inline`,children:(0,Y.jsx)(wi,{value:t.value,disabled:t.disabled})},t.value))})})}function Xi({spec:e,field:t,locked:n,error:r,render:i,...a}){return i({name:e.name,label:e.label,help:e.help,value:Ui(t),onChange:e=>{t.handleChange(e)},onBlur:t.handleBlur,error:r,disabled:n,id:a.id??e.name,"aria-describedby":a[`aria-describedby`],"aria-invalid":r!==void 0})}function Zi({form:e,spec:t,locked:n,layout:r}){let i=Rn({form:e,name:t.name}),a=Vn(e.store,e=>e.submissionAttempts>0),o=i.state.meta.isBlurred||a?Nr(i.state.meta):void 0;if(t.render===void 0&&Ji.has(t.kind))return(0,Y.jsx)(Yi,{spec:t,field:i,locked:n,error:o,layout:r});let s=r===`columns`?t.kind===`switch`||t.kind===`checkbox`?`horizontal`:`vertical`:t.kind===`checkbox`?`inline`:(t.layout??(t.kind===`switch`?`row`:`stacked`))===`row`?`horizontal`:`vertical`;return(0,Y.jsx)(Mn,{label:t.label,...r===`columns`?{labelTitle:t.label}:{},description:t.help,icon:t.icon,orientation:s,error:o,...t.required===void 0?{}:{required:t.required},...t.optional===void 0?{}:{optional:t.optional},children:t.render===void 0?(0,Y.jsx)(qi,{spec:t,field:i,locked:n}):(0,Y.jsx)(Xi,{spec:t,field:i,locked:n,error:o,render:t.render})})}var Qi=K(Bt(H,Li));function $i({form:e,spec:t,locked:n,layout:r}){let i=t.when;return Vn(e.store,e=>i===void 0||i(V(Qi(e.values),()=>({}))))?(0,Y.jsx)(Zi,{form:e,spec:t,locked:n,layout:r}):null}function ea({form:e,section:t,locked:n,layout:r}){let i=t.fields.map(t=>(0,Y.jsx)($i,{form:e,spec:t,locked:n,layout:r},t.name));return t.title===void 0?i:(0,Y.jsx)(Ln,{title:t.title,description:t.description,layout:r,children:i})}function ta({model:e,names:t,disabled:n=!1,layout:r}){let i=e.form;return t===void 0?e.description.sections.map(e=>(0,Y.jsx)(ea,{form:i,section:e,locked:n,layout:r},e.id??``)):t.map(t=>{let a=e.description.fields.find(e=>e.name===t);return a===void 0?null:(0,Y.jsx)($i,{form:i,spec:a,locked:n,layout:r},t)})}var na=class{annotation;constructor(e){this.annotation=e}},ra=class{sections;constructor(e){this.sections=e}},ia=`caps/form`,aa=0;function oa(e){aa+=1;let t={[`${ia}:${String(aa)}`]:new na(e)};return e.label!==void 0&&(t.title=e.label),e.help!==void 0&&(t.description=e.help),t}H.annotate(oa({kind:`secret`})).pipe(ct(`Secret`));var sa=e=>{let t=e.replace(/([a-z0-9])([A-Z])/g,`$1 $2`).replace(/[-_]+/g,` `).toLowerCase();return t.charAt(0).toUpperCase()+t.slice(1)};function ca(e){return Object.values(e??{}).reduce((e,t)=>t instanceof na?{...e,...t.annotation}:e,{})}function la(e){return e.reduce((e,t)=>({...e,...ca(t)}),{})}function ua(e){let t=e?.[ia];return t instanceof ra?t.sections:{}}var da=K(H);function fa(e){if(ee(e))return tt(da(e.literal),{onNone:()=>null,onSome:e=>[e]});if(!Ce(e))return null;let t=[];for(let n of e.types){if(T(n))continue;let e=fa(n);if(e===null)return null;t.push(...e)}return t}function pa(e){if(De(e))return{type:`string`,literals:[]};if(rn(e))return{type:`number`,nullable:!1};if(A(e))return{type:`boolean`};let t=fa(e);if(t!==null)return{type:`string`,literals:t};if(v(e)){let[t]=e.rest;if(t===void 0)return null;if(De(t))return{type:`strings`,literals:[]};let n=fa(t);return n===null?null:{type:`strings`,literals:n}}if(Ce(e)){let t=e.types.filter(e=>!T(e)&&!pe(e)),n=e.types.some(e=>pe(e)),[r]=t;if(t.length!==1||r===void 0)return null;let i=pa(r);return i?.type===`number`?{type:`number`,nullable:n}:n?null:i}return null}function ma(e){let t=e.ast;if(!s(t))throw Error(`A schema form needs a Schema.Struct.`);return{fields:t.propertySignatures.map(e=>{let t=String(e.name),n=Pt(e.type),r=la([e.type.annotations,...(e.type.checks??[]).map(e=>e.annotations)]),i=r.kind===`file`?{type:`files`}:pa(n);if(i===null)throw Error(`Schema field "${t}" has no form control. Annotate it with field({ render }) or a kind.`);return{name:t,valueType:i,optional:e.type.context?.isOptional===!0,annotation:r,title:F(e.type),description:b(e.type)}}),sections:ua(je(t))}}function ha(e){let t=e,n=!1,r=!1;for(;;)if(t instanceof Jt)n=!0,t=t.unwrap();else if(t instanceof Vt)r=!0,t=t.unwrap();else if(t instanceof ft)t=t.unwrap();else if(t instanceof $e)t=t.in;else return{node:t,optional:n,nullable:r}}function ga(e){if(e instanceof St){let t=e.options.map(e=>ga(e));return t.some(e=>e===null)?null:t.flatMap(e=>e??[])}let t=e instanceof Ge?e.options:e instanceof Dt?[...e.values]:null;if(t===null)return null;let n=t.map(e=>da(e));return n.every(ue)?n.map(e=>e.value):null}function _a(e){let{node:t,nullable:n}=ha(e);if(t instanceof it)return{type:`string`,literals:[]};if(t instanceof Ye)return{type:`number`,nullable:n};if(t instanceof Lt)return{type:`boolean`};let r=ga(t);if(r!==null)return{type:`string`,literals:r};if(t instanceof Tt){let e=ha(t.element).node;if(e instanceof it)return{type:`strings`,literals:[]};let n=ga(e);return n===null?null:{type:`strings`,literals:n}}return null}function va(e){let t=[e];for(;;){let e=t[t.length-1];if(e===void 0)break;let n=e instanceof Jt||e instanceof Vt||e instanceof ft?e.unwrap():e instanceof $e?e.in:e;if(n===e)break;t.push(n)}return t.reverse().map(e=>te.get(e))}function ya(e){return va(e).reduce((e,t)=>({...e,...t}),{})}function ba(e){return Object.entries(e.shape)}function xa(e){let t=ha(e).node;if(!(t instanceof yt))throw Error(`A schema form needs a z.object.`);return{fields:ba(t).map(([e,t])=>{let n=la(va(t)),r=n.kind===`file`?{type:`files`}:_a(t);if(r===null)throw Error(`Schema field "${e}" has no form control. Annotate it with field({ render }) or a kind.`);let i=ya(t);return{name:e,valueType:r,optional:ha(t).optional,annotation:n,title:i.title,description:i.description}}),sections:ua(ya(e))}}function Sa(e,t){let n=t.options??{};return(e.length>0?e:Object.keys(n)).map(e=>{let t=n[e],r=t===void 0?{}:t instanceof Object?t:{label:t};return{value:e,label:r.label??sa(e),description:r.description,meta:r.meta,icon:r.icon,caption:r.caption,disabled:r.disabled===!0}})}function Ca(e,t){let n=t.some(e=>e.icon!==void 0);switch(e.type){case`boolean`:return`switch`;case`number`:return`number`;case`strings`:return n?`icon-checkboxes`:`checkboxes`;case`files`:return`file`;case`string`:return t.length===0?`text`:t.length>12?`combobox`:n?`icon-radio`:t.some(e=>e.description!==void 0||e.meta!==void 0)||t.length<=3?`radio`:`select`}}function wa(e,t){switch(e.type){case`boolean`:return!1;case`number`:return e.nullable?null:0;case`strings`:case`files`:return[];case`string`:return t[0]?.value??``}}function Ta(e){let t=e instanceof jt?xa(e):ma(e),n=t.fields.map((e,t)=>{let{kind:n,...r}=e.annotation,i=Sa(e.valueType.type===`string`||e.valueType.type===`strings`?e.valueType.literals:[],e.annotation),a=r.help??e.description;return{...r,name:e.name,label:r.label??e.title??sa(e.name),help:a,kind:n??Ca(e.valueType,i),options:i,optionalInSchema:e.optional,index:t}}),r={};t.fields.forEach((e,t)=>{let i=n[t];i&&(r[e.name]=wa(e.valueType,i.options))});let i=e=>e.order??e.index,a=e=>e.section!==void 0&&Object.hasOwn(t.sections,e.section)?e.section:null,o=e=>n.filter(t=>a(t)===e).sort((e,t)=>i(e)-i(t)),s=Object.entries(t.sections).map(([e,t])=>({id:e,title:t.title,description:t.description,fields:o(e)}));return{fields:n,sections:[{id:null,title:void 0,description:void 0,fields:o(null)},...s].filter(e=>e.fields.length>0),defaults:r}}function Ea(e){let t=e instanceof jt?e:ce(e);return{"~standard":{...t[`~standard`],validate:e=>{let n=t[`~standard`].validate(e);return n instanceof Promise?n.then(e=>Da(e)):Da(n)}}}}function Da(e){return e.issues===void 0?e:{issues:e.issues.map(e=>e.path===void 0?e:{...e,path:e.path.slice(0,1)})}}var Oa=`onServer`;function ka(e){let t=e.querySelector(`[aria-invalid="true"]`),n=t?.matches(`input, select, textarea, button, [tabindex]`)?t:t?.querySelector(`input, select, textarea, button`);return n?.focus(),n!=null}function Aa(e){if(ka(e))return()=>void 0;let t=new MutationObserver(()=>{ka(e)&&t.disconnect()});return t.observe(e,{subtree:!0,childList:!0,attributes:!0,attributeFilter:[`aria-invalid`]}),()=>{t.disconnect()}}function ja(e){return e.state.meta.errorMap.onServer!==void 0}function Ma(e){e.setMeta(e=>({...e,errorMap:{...e.errorMap,[Oa]:void 0}}))}function Na(e,t,n){e.setFieldMeta(t,e=>({...e,isBlurred:!0,errorMap:{...e.errorMap,[Oa]:n}}))}function Pa(e){let[t,n]=(0,J.useState)(null),[r,i]=(0,J.useState)(null),[a,o]=(0,J.useState)(e.defaultValues),[s,c]=(0,J.useState)(null);In(a,e.defaultValues)||(o(e.defaultValues),c(null));let{schema:l}=e,u=(0,J.useMemo)(()=>Ta(l),[l]),d=(0,J.useMemo)(()=>Ea(l),[l]),f=Un({defaultValues:s??a,validators:{onChange:d,onSubmit:d},listeners:{onChange:({fieldApi:e})=>{n(null),i(null),ja(e)&&Ma(e)}},onSubmit:async({value:t,formApi:r})=>{n(null),i(null);let a=await Ea(l)[`~standard`].validate(t);if(a.issues){n(a.issues[0]?.message??`Check the form and try again.`);return}let o;try{o=await e.onSubmit(a.value,t)??{kind:`saved`}}catch(t){console.error(`SchemaForm submit failed`,t),n(e.failure??`Couldn't save changes. Try again.`);return}if(o.kind===`refused`){n(o.error??null);let e=r;for(let[t,n]of Object.entries(o.fields??{}))n!==void 0&&n.length>0&&Na(e,t,n);return}let s=o.values??t;c(s),r.reset(s),i(o.message??`Saved`),e.onSaved?.(s)}});return{description:u,form:f,error:t,saved:r,discard:()=>{n(null),i(null),f.reset()},submit:()=>f.handleSubmit()}}function Fa(e){return{dirty:Vn(e.form.store,e=>!e.isDefaultValue),submitting:Vn(e.form.store,e=>e.isSubmitting),canSubmit:Vn(e.form.store,e=>e.canSubmit)}}function Ia({model:e,submitLabel:t=`Save changes`,discardLabel:n,onCancel:r,cancelLabel:i,allowClean:a,layout:o,footer:s,children:c,disabled:l=!1,...u}){let{submitting:d}=Fa(e),f=(0,J.useRef)(null),p=(0,J.useRef)(()=>void 0);return(0,J.useEffect)(()=>()=>{p.current()},[]),(0,Y.jsxs)(Hn,{...u,ref:f,layout:o,busy:d,noValidate:!0,onSubmit:t=>{t.preventDefault(),e.form.state.isSubmitting||e.submit().then(()=>{p.current();let t=f.current;t!==null&&!e.form.state.isValid&&(p.current=Aa(t))})},children:[c??(0,Y.jsx)(ta,{model:e,disabled:l,layout:o}),s===void 0?(0,Y.jsx)(za,{model:e,label:t,discardLabel:r===void 0?n:void 0,onCancel:r,cancelLabel:i,allowClean:a??r!==void 0,divider:r===void 0}):s]})}function La({schema:e,defaultValues:t,onSubmit:n,onSaved:r,failure:i,...a}){let o=Pa({schema:e,defaultValues:t,onSubmit:n,onSaved:r,failure:i});return(0,Y.jsx)(Ia,{...a,model:o})}function Ra(e){return`model`in e?(0,Y.jsx)(Ia,{...e}):(0,Y.jsx)(La,{...e})}function za({model:e,label:t,discardLabel:n,onCancel:r,cancelLabel:i=`Cancel`,allowClean:a=!1,dirtyLabel:o=`Unsaved changes`,buttonProps:s,...c}){let{dirty:l,submitting:u}=Fa(e),d=u?null:e.saved&&!l?(0,Y.jsx)(On,{tone:`success`,size:`compact`,label:e.saved}):l?(0,Y.jsx)(On,{tone:`neutral`,size:`compact`,label:o}):null;return(0,Y.jsxs)(Nn,{...c,error:e.error,status:d,children:[r?(0,Y.jsx)(U,{type:`button`,variant:`ghost`,disabled:u,onClick:r,children:i}):n&&l?(0,Y.jsx)(U,{type:`button`,variant:`ghost`,disabled:u,onClick:e.discard,children:n}):null,(0,Y.jsx)(U,{...s,type:`submit`,loading:u,disabled:u||!l&&!a,title:!l&&!a?`No changes to save`:void 0,children:t})]})}var Ba=qt.check(a(/^(?!\.{1,2}$)[^/]+$/u,{message:`Enter a single file or folder name.`})),Va={file:vt({name:Ba.annotate(oa({label:`File name`}))}),folder:vt({name:Ba.annotate(oa({label:`Folder name`}))})};function Ha(e){return(0,Y.jsx)(Ua,{...e},e.creation?`${e.creation.kind}:${e.creation.directory}:${e.creation.name??``}`:`closed`)}function Ua({creation:e,rootPath:t,onCreate:n,onClose:r}){let i=Pa({schema:Va[e?.kind??`file`],defaultValues:{name:e?.name??``},onSubmit:async t=>{if(!e)return;let i=await n(e,t.name);if(i)return i===`That name already exists in this directory.`?{kind:`refused`,fields:{name:i}}:{kind:`refused`,error:i};r()}}),{submitting:a}=Fa(i);return(0,Y.jsx)(Ue,{open:e!==null,onOpenChange:e=>{!e&&!i.form.state.isSubmitting&&r()},children:(0,Y.jsxs)(zt,{children:[(0,Y.jsxs)(Kt,{className:`mb-4`,children:[(0,Y.jsxs)(Qe,{children:[`New `,e?.kind===`folder`?`folder`:`file`]}),(0,Y.jsxs)(Je,{children:[`Create in `,e?.directory??t,` on this Computer.`]})]}),(0,Y.jsx)(Ra,{model:i,onSubmitCapture:()=>{i.form.state.isSubmitting||i.form.setFieldValue(`name`,e=>e)},footer:(0,Y.jsxs)(Nn,{divider:!1,error:i.error,children:[(0,Y.jsx)(U,{variant:`ghost`,type:`button`,disabled:a,onClick:r,children:`Cancel`}),(0,Y.jsx)(U,{type:`submit`,disabled:a,loading:a,children:a?`Creating…`:`Create`})]})})]})})}function Wa({files:e,patch:t,truncated:n,activeDiff:r,rowHeight:i,onOpenDiff:a}){let o=(0,J.useMemo)(()=>En(t),[t]);return e.length===0?(0,Y.jsx)(pn,{className:`inkcap-changes-empty`,variant:`quiet`,title:`No changes yet`,description:`Files the Agent edits show up here.`}):(0,Y.jsxs)(`div`,{className:`inkcap-changes-list`,children:[n?(0,Y.jsx)(`p`,{className:`inkcap-tree-note`,children:`Showing the first part of a large change. Review the rest in a terminal.`}):null,(0,Y.jsx)(`ul`,{children:e.map(e=>{let t=o.get(e.path);return(0,Y.jsx)(`li`,{children:(0,Y.jsxs)(U,{className:`inkcap-change-file`,style:{minHeight:i},size:`sm`,variant:`ghost`,"aria-current":r===e.path?`true`:void 0,title:`Review changes to ${e.path}`,onClick:()=>{a(e.path)},children:[(0,Y.jsx)(`span`,{className:`inkcap-change-mark`,"data-status":e.status,role:`img`,"aria-label":xn[e.status],children:wn[e.status]}),(0,Y.jsx)(`span`,{className:`inkcap-change-path`,children:e.path}),t?(0,Y.jsxs)(`span`,{className:`inkcap-change-counts`,children:[t.additions>0?(0,Y.jsxs)(`span`,{className:`inkcap-change-added`,children:[`+`,t.additions]}):null,t.deletions>0?(0,Y.jsxs)(`span`,{className:`inkcap-change-removed`,children:[`−`,t.deletions]}):null]}):null]})},`${e.status}:${e.path}`)})})]})}var Ga=`That name already exists in this directory.`;function Ka({app:e,onOpenFile:t,onOpenDiff:n,activeDiff:r=null,activePath:i,rootPath:a=`/`,rootLabel:o=`Computer`,onSelectPath:s,creationRequest:c=null,onCreationRequestHandled:u,rowHeight:d=32}){let[f,p]=(0,J.useState)(null),m=Ar({app:e,rootPath:a,rootLabel:o,rowHeight:d,activePath:i,onOpenFile:t,onSelectPath:e=>{p(e),s?.(e)}}),[h,g]=(0,J.useState)(null),_=e.capabilities.has(sn),[v,y]=(0,J.useState)(!1),b=e.capabilities.has(un),x=ln(vn(b?e:null,a)),S=x.data?.kind===`changes`?x.data:null;function C(){m.reloadRoot(),b&&x.refetch()}(0,J.useEffect)(()=>{x.isError&&e.ui.showToast({message:fe(x.error).message,tone:`error`}).catch(e=>{console.error(`Inkcap changes toast failed`,e)})},[e,x.isError,x.error]);function w(e,t){g({kind:e,directory:wt(t,a)})}(0,J.useEffect)(()=>{if(!c)return;let e={kind:c.kind,directory:wt(f??`${a}/`,a)};c.name!==void 0&&(e.name=c.name),c.immediate===!0&&c.name!==void 0?T(e,c.name):g(e),u?.()},[c,u,a,f]);async function T(e,n){let r=await E(e,n);r===Ga?t(ut(n,e.directory)):r!==void 0&&g(e)}async function E(n,r){let i=ut(r,n.directory);try{let a=0;for(;a!==null;){let t=a,i=await kn(e.capabilities,{path:n.directory,limit:256,offset:t});if(i.entries.some(e=>e.name===r))return Ga;if(i.nextOffset!==null&&i.nextOffset<=t)return`Could not verify that name is available.`;a=i.nextOffset}n.kind===`folder`?(await e.capabilities.require(sn).mkdir({path:i}),m.noteCreated(`${i}/`)):(await cn(e.capabilities,{path:i,content:new Blob([])},{}),m.noteCreated(i),t(i));return}catch(e){return e instanceof Error?fe(e).message:`Couldn't create ${n.kind}. Check Computer write access.`}}let D={flex:`1`,"--trees-item-height":`${String(d)}px`,"--trees-padding-inline-override":`var(--spacing-xs)`,"--trees-item-margin-x-override":`0px`,"--trees-item-padding-x-override":`var(--spacing-xs)`,"--trees-item-row-gap-override":`var(--spacing-xs)`,"--trees-bg-override":`var(--color-base-100)`,"--trees-fg-override":`var(--color-base-content)`,"--trees-bg-muted-override":`var(--color-base-200)`,"--trees-selected-bg-override":`var(--color-base-300)`,"--trees-border-radius-override":`var(--radius-field)`,"--trees-font-family-override":`var(--font-sans)`,"--trees-font-size-override":`12px`};return(0,Y.jsxs)(`aside`,{className:`inkcap-tree`,"aria-label":`File tree`,children:[(0,Y.jsxs)(`div`,{className:`inkcap-tree-toolbar`,children:[(0,Y.jsxs)(`span`,{children:[(0,Y.jsx)(Tn,{"aria-hidden":`true`}),` `,(0,Y.jsx)(`span`,{className:`inkcap-tree-title`,children:`Explorer`})]}),(0,Y.jsxs)(`span`,{className:`inkcap-tree-actions`,children:[(0,Y.jsx)(l,{icon:(0,Y.jsx)(mn,{}),"aria-label":`New file`,title:`New file`,variant:`ghost`,size:`responsive`,disabled:!_,onClick:()=>{w(`file`,f??`${a}/`)}}),(0,Y.jsx)(l,{icon:(0,Y.jsx)(ir,{}),"aria-label":`New folder`,title:`New folder`,variant:`ghost`,size:`responsive`,disabled:!_,onClick:()=>{w(`folder`,f??`${a}/`)}}),(0,Y.jsx)(l,{icon:(0,Y.jsx)(Kn,{}),"aria-label":`Refresh files`,title:`Refresh files`,variant:`ghost`,size:`responsive`,disabled:m.busy||x.isFetching,onClick:C})]})]}),S===null?x.isError?(0,Y.jsx)(U,{className:`inkcap-changes-retry`,size:`sm`,variant:`ghost`,onClick:()=>void x.refetch(),children:`Changes unavailable. Retry`}):null:(0,Y.jsx)(kr,{className:`inkcap-changes`,size:`row`,open:v,onOpenChange:y,summary:`Changes`,trailing:(0,Y.jsx)(Sn,{count:S.files.length}),children:(0,Y.jsx)(Wa,{files:S.files,patch:S.patch,truncated:S.truncated,activeDiff:r,rowHeight:d,onOpenDiff:e=>{n?.(e)}})}),m.error&&(0,Y.jsx)(fn,{message:m.error,onRetry:m.reloadRoot}),m.rootEmpty?(0,Y.jsx)(`p`,{className:`inkcap-tree-note`,children:`Empty folder`}):null,(0,Y.jsxs)(`div`,{className:`inkcap-tree-files`,children:[(0,Y.jsx)(Gn,{model:m.model,style:D,renderContextMenu:(e,t)=>(0,Y.jsxs)(`div`,{className:`flex min-w-36 flex-col gap-xs p-xs`,role:`menu`,children:[(0,Y.jsxs)(U,{className:`w-full justify-start`,disabled:!_,role:`menuitem`,title:_?void 0:`Computer write access is not granted.`,size:`sm`,variant:`ghost`,onClick:()=>{t.close({restoreFocus:!1}),w(`file`,e.path)},children:[(0,Y.jsx)(mn,{"aria-hidden":`true`}),` New file`]}),(0,Y.jsxs)(U,{className:`w-full justify-start`,disabled:!_,role:`menuitem`,title:_?void 0:`Computer write access is not granted.`,size:`sm`,variant:`ghost`,onClick:()=>{t.close({restoreFocus:!1}),w(`folder`,e.path)},children:[(0,Y.jsx)(ir,{"aria-hidden":`true`}),` New folder`]})]})}),m.page.next!==null&&(0,Y.jsxs)(U,{disabled:m.busy,onClick:m.loadNext,children:[`More in `,m.page.path]})]}),(0,Y.jsx)(Ha,{creation:h,rootPath:a,onCreate:E,onClose:()=>{g(null)}})]})}export{Ka as InkcapFileTree};
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Bn as t,Qr as n,Xi as r,Xr as i,Zi as a,a as o,c as s,d as c,dr as l,s as u,u as d,ur as f}from"./tree-path-DQAnGoeW.js";import{Ft as p,Lt as m,_ as h,s as g}from"./changes-patch-DhbNb84Y.js";import{Wt as _}from"./dropdown-menu-BlFqxqxM.js";import{n as v,r as y,t as b}from"./useFileTree-D7u_RYsd.js";import{a as x,c as S,d as C,f as w,h as T,i as E,l as D,m as O,n as k,o as A,p as j,r as M,s as N,t as P,u as F}from"./index-DEbu5E0M.js";var I=f(`GitBranch`,[[`line`,{x1:`6`,x2:`6`,y1:`3`,y2:`15`,key:`17qcm7`}],[`circle`,{cx:`18`,cy:`6`,r:`3`,key:`1h7g24`}],[`circle`,{cx:`6`,cy:`18`,r:`3`,key:`fqmcym`}],[`path`,{d:`M18 9a9 9 0 0 1-9 9`,key:`n2h4wq`}]]),L=f(`History`,[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}],[`path`,{d:`M12 7v5l4 2`,key:`1fdv2h`}]]),R=e(a(),1),z=256;async function B(e,t,n,r,a){r.throwIfAborted();let o=await n(e,t);if(!j.safeParse(o).success)return o;a(!0);try{let a=null,o=!1;for(let e=0;e<z&&!o;e++){r.throwIfAborted();let e=x.parse(await n(`rebuildCopies`,{cursor:a}));o=e.done,a=e.cursor}if(!o)throw new i(`Bonsai is still preparing this repository. Try again shortly.`,{code:`TIMEOUT`,retryable:!0});r.throwIfAborted();let s=await n(e,t);if(j.safeParse(s).success)throw Error(`The repository changed while loading. Refresh to retry.`);return s}finally{a(!1)}}function V({repository:e,branch:t,request:n,onSaved:r,onSaveState:a}){let o=new Map;async function s(r,a){a.throwIfAborted();let o=A.parse(await n(`files.read`,{repo:e,ref:t,path:r}));if(a.throwIfAborted(),o.binary)throw Error(`This Bonsai file is not a text document.`);if(o.text===null&&o.blob!==null)throw new i(`This Bonsai file is too large to edit.`,{code:`FILE_TOO_LARGE`,retryable:!1});return o}async function c(s,c){c.throwIfAborted();let l=w.parse(await n(`files.sync`,{}));c.throwIfAborted();let u=l.settled.find(n=>n.repo===e&&n.branch===t&&n.path===s);if(u){if(u.result.kind===`refused`)throw new i(`Bonsai refused sync: ${u.result.reason}`,{code:`CAPABILITY_DENIED`,retryable:u.result.reason===`background-unavailable`});let e=o.get(s);if(u.result.revision!==e?.version)throw new i(`Your saved file changed. Compare before syncing.`,{code:`CONFLICT`,retryable:!0});a(s,u.result)}r()}async function l(l,u,d,f){f.throwIfAborted();let p=o.get(l);if(d===void 0){let e=await s(l,f);p={file:e,contents:e.pending?.text??e.text??``,version:e.version}}if(!p)throw Error(`Reopen this Bonsai file before saving.`);if(d!==void 0&&p.contents!==d)throw new i(`The file baseline changed. Compare before saving.`,{code:`CONFLICT`,retryable:!0});if(d!==void 0){let e=await s(l,f);if(e.version!==p.version||(e.pending?.text??e.text??``)!==p.contents)throw new i(`The file changed. Compare before saving.`,{code:`CONFLICT`,retryable:!0});e.pending===void 0&&(p.file=e)}let m=F.parse({repo:e,branch:t,path:l,baseCommit:p.file.commit,baseBlob:p.file.blob,text:u,revision:p.version}),h=C.parse(await n(`files.save`,m));if(h.kind===`refused`)throw new i(`Bonsai refused this save: ${h.reason}`,{code:`CAPABILITY_DENIED`,retryable:h.reason===`background-unavailable`});if(a(l,h),h.kind===`conflict`)throw new i(`Your saved file changed. Compare before saving.`,{code:`CONFLICT`,retryable:!0});o.set(l,{file:p.file,contents:u,version:h.revision}),r(),h.kind===`saved`&&c(l,f).catch(e=>{console.error(`Bonsai sync status could not be refreshed`,e),!(o.get(l)?.version!==h.revision||f.aborted)&&a(l,{kind:`failed`,revision:h.revision,reason:`sync_failed`})})}return{kind:`repository`,id:`${e}:${t}`,label:`${e} · ${t}`,async read(e,t,n){let r=n?.revision,i=await s(e,t);if(n?.closed)return{kind:`closed`};if(n&&n.revision!==r)return{kind:`changed`};let c=i.pending?.text??i.text??``;o.set(e,{file:i,contents:c,version:i.version});let l=i.pending;return l?.state===`pending`?a(e,{kind:`saved`,revision:l.revision,state:`pending`}):l?.state===`conflict`?a(e,{kind:`conflict`,revision:l.revision,theirs:l.theirs}):l?.state===`failed`?a(e,{kind:`failed`,revision:l.revision,reason:l.failure??`sync_failed`}):i.version!==null&&a(e,{kind:`synced`,revision:i.version,commit:i.commit}),{kind:`text`,contents:c}},replace:(e,t,n,r)=>l(e,t,n,r),write:(e,t,n)=>l(e,t,void 0,n),async exists(r,i){i.throwIfAborted();let a=D.parse(await n(`files.list`,{repo:e,ref:t}));if(i.throwIfAborted(),a.paths.includes(r))return!0;if(a.truncated)throw Error(`The repository file list is incomplete.`);return!1},retry:c,async discard(s,c){c.throwIfAborted();let l=o.get(s);if(!l)throw Error(`Reopen this saved file before discarding it.`);if(l.version===null)return;let u=N.parse({repo:e,branch:t,path:s,revision:l.version}),d=S.parse(await n(`files.discard`,u));if(c.throwIfAborted(),d.kind===`conflict`)throw new i(`Your saved file changed. Refresh before discarding.`,{code:`CONFLICT`,retryable:!0});o.delete(s),a(s,null),r()},async readCommitted(e,t){let n=await s(e,t),r=n.text??``;return o.has(e)||o.set(e,{file:n,contents:r,version:n.version}),r}}}async function H(e,t,n){let r={repo:t,ref:n},i=O.parse(await e(`files.tree`,{...r,path:``})),a=D.parse(await e(`files.list`,r)),o=E.parse(await e(`commits.list`,{...r,limit:20}));if(i.commit.hash!==a.commit.hash)throw Error(`The repository changed while loading. Refresh to retry.`);return{head:i.commit.hash,branch:n,files:a.paths.map(e=>({path:e})),history:o.commits.map(e=>e.commit),truncated:a.truncated}}var U=r();function W({files:e,rowHeight:n,dirtyPaths:r,activePath:i,busy:a,onRefresh:o,onOpenFile:s}){let c=(0,R.useRef)({files:e,onOpenFile:s});c.current={files:e,onOpenFile:s};let{model:l}=b({paths:[],initialExpansion:`open`,itemHeight:n,onSelectionChange(e){let t=e[0];t&&!t.endsWith(`/`)&&c.current.files.some(e=>e.path===t)&&c.current.onOpenFile(t)}}),u=(0,R.useMemo)(()=>{let t=new Set(r);return e.flatMap(e=>t.has(e.path)?[{path:e.path,status:`modified`}]:[])},[e,r]);(0,R.useEffect)(()=>{l.resetPaths(e.map(e=>e.path))},[l,e]),(0,R.useEffect)(()=>{l.setGitStatus(u)},[l,u]),(0,R.useEffect)(()=>{for(let e of l.getSelectedPaths())e!==i&&l.getItem(e)?.deselect();i&&l.getItem(i)?.select()},[l,i]);let d={flex:`1`,"--trees-item-height":`${String(n)}px`,"--trees-padding-inline-override":`var(--spacing-xs)`,"--trees-item-margin-x-override":`0px`,"--trees-item-padding-x-override":`var(--spacing-xs)`,"--trees-item-row-gap-override":`var(--spacing-xs)`,"--trees-border-radius-override":`var(--radius-field)`,"--trees-bg-override":`var(--color-base-100)`,"--trees-fg-override":`var(--color-base-content)`,"--trees-bg-muted-override":`var(--color-base-200)`,"--trees-selected-bg-override":`var(--color-base-300)`,"--trees-font-family-override":`var(--font-sans)`,"--trees-font-size-override":`12px`};return(0,U.jsxs)(`aside`,{className:`inkcap-tree`,"aria-label":`Repository files`,children:[(0,U.jsxs)(`div`,{className:`inkcap-tree-toolbar`,children:[(0,U.jsxs)(`span`,{children:[(0,U.jsx)(g,{"aria-hidden":`true`}),` Explorer`]}),(0,U.jsx)(t,{icon:(0,U.jsx)(y,{}),"aria-label":`Refresh repository`,variant:`ghost`,size:`responsive`,disabled:a,onClick:o})]}),(0,U.jsx)(`p`,{className:`inkcap-repository-legend`,children:`Changes in latest commit · drafts marked modified`}),(0,U.jsx)(v,{model:l,style:d})]})}var G={all:(e,t)=>[`inkcap-repository`,e,t],branch:(e,t,n)=>[...G.all(e,t),n]},K={branch_missing:`The repository branch no longer exists. Your text is saved; restore the branch before retrying.`,access_changed:`Repository access changed. Your text is saved; restore Bonsai's Git access before retrying.`,sync_failed:`Git could not publish this change. Your text is saved; retry sync.`,permanent_material:`The saved change no longer matches the repository state. Save again to publish your text from the current state.`};function q({connection:e,repository:t,initialBranch:r,initialPath:i,openRequestId:a,transport:f,onReady:g}){let v=m(),[y,b]=(0,R.useState)(!1),[x,S]=(0,R.useState)(0),[C,w]=(0,R.useState)(new Map),[E,D]=(0,R.useState)(``),O=(0,R.useRef)(new AbortController);(0,R.useEffect)(()=>{let e=new AbortController;return O.current=e,()=>{e.abort()}},[]);let A=(0,R.useCallback)((t,n)=>f?f(t,n):e.app.capabilities.require(T).call(`app_bonsai`,t,JSON.stringify(n)),[e.app,f]),j=(0,R.useCallback)((e,t)=>B(e,t,A,O.current.signal,e=>{S(t=>t+(e?1:-1))}),[A]),N=(0,R.useCallback)(()=>{v.invalidateQueries({queryKey:G.all(e.app.identity.surfaceId,t)})},[v,e.app,t]),F=(0,R.useRef)(new Map),z=(0,R.useMemo)(()=>{let n=`${e.app.identity.surfaceId}:${t}:${r}`,i=F.current.get(n);if(i?.app===e.app)return i;let a=V({repository:t,branch:r,request:j,onSaved:N,onSaveState:(e,n)=>{O.current.signal.aborted||w(i=>{let a=new Map(i),o=`${t}:${r}:${e}`;return n===null?a.delete(o):a.set(o,n),a})}}),o={app:e.app,source:a};return F.current.set(n,o),o},[t,r,j,N,e.app]),q=P({connection:z}),J=p({queryKey:G.branch(e.app.identity.surfaceId,t,r),queryFn:()=>H(j,t,r),refetchInterval:15e3});(0,R.useEffect)(()=>e.app.window.onBeforeClose(q.requestWindowClose),[e.app,q.requestWindowClose]),(0,R.useEffect)(()=>{g?.({requestWindowClose:q.requestWindowClose})},[g,q.requestWindowClose]);let Y=(0,R.useRef)(),X=(0,R.useRef)(new Map),Z=(0,R.useRef)(new Set);(0,R.useEffect)(()=>{if(!J.data)return;let e=`${z.app.identity.surfaceId}:${z.source.id}:${a}`;Y.current!==e&&(Y.current=e,q.onOpenFile(i));let t=X.current.get(z.source.id),n=t!==void 0&&t!==J.data.head;X.current.set(z.source.id,J.data.head);let r=new Set(q.tabs.map(e=>e.tabKey));for(let e of Z.current)r.has(e)||Z.current.delete(e);for(let e of q.tabs)if(!(e.target.closed||e.connection!==z||!n&&!Z.current.has(e.tabKey))){if(e.target.saving){Z.current.add(e.tabKey);continue}Z.current.delete(e.tabKey),e.target.dirty||q.onReopen(e,{background:!0})}},[J.data,z,i,a,q]);let Q=q.tabs.find(e=>e.tabKey===q.active),$=Q?.connection?.source?C.get(`${Q.connection.source.id}:${Q.path}`):void 0,ee=$?.kind===`saved`?`Saved · syncing`:$?.kind===`synced`?`Synced · ${$.commit.slice(0,7)}`:$?.kind===`conflict`?`Sync conflict · Compare`:$?.kind===`failed`?`Sync failed · Retry`:void 0;async function te(){if(!Q?.connection?.source)return;let e=F.current.get(`${Q.connection.app.identity.surfaceId}:${Q.connection.source.id}`);if(e)try{D(``),await e.source.retry(Q.path,O.current.signal)}catch(e){console.error(`Bonsai sync retry failed`,e),D(`${n(e).message} Your saved text remains in Bonsai.`)}}async function ne(){if(!Q?.connection?.source)return;let e=()=>!Q.target.dirty&&!Q.target.saving&&!Q.target.closed;if(!e())return;let t=F.current.get(`${Q.connection.app.identity.surfaceId}:${Q.connection.source.id}`);if(t)try{D(``);let n=await t.source.read(Q.path,O.current.signal);if(n.kind!==`text`)throw Error(`This saved text is unavailable.`);if(!e())return;await t.source.replace(Q.path,n.contents,n.contents,O.current.signal)}catch(e){console.error(`Bonsai explicit re-save failed`,e),D(`${n(e).message} Your saved text and open edits remain available.`)}}return(0,U.jsxs)(`div`,{className:`inkcap-repository`,children:[(0,U.jsxs)(`div`,{className:`inkcap-repository-toolbar`,children:[(0,U.jsxs)(`span`,{className:`inkcap-repository-name`,children:[(0,U.jsx)(I,{"aria-hidden":`true`}),` `,t,` · `,r]}),(0,U.jsxs)(l,{size:`sm`,variant:`outline`,onClick:()=>{b(!0)},children:[(0,U.jsx)(L,{"aria-hidden":`true`,className:`size-[var(--stipe-icon-size-sm)]`}),` `,`History`]})]}),x>0&&(0,U.jsx)(M,{message:`Loading this repository…`}),J.data?.truncated&&(0,U.jsx)(_,{tone:`info`,title:`Only the indexed files are shown`}),E&&(0,U.jsx)(h,{message:E,onDismiss:()=>{D(``)}}),$?.kind===`failed`&&!E&&(0,U.jsx)(_,{tone:`warning`,title:$.reason===`permanent_material`?`Sync needs a new save`:`Sync failed`,description:K[$.reason],action:(0,U.jsx)(l,{size:`sm`,disabled:$.reason===`permanent_material`&&Q!==void 0&&(Q.target.dirty||Q.target.saving),onClick:()=>void($.reason===`permanent_material`?ne():te()),children:$.reason===`permanent_material`?`Save again`:`Retry`})}),(0,U.jsx)(k,{model:{...q,repositoryStatus:ee,repositoryStates:C,canList:!0,sourceLabel:z.source.label,onReadCurrent:async(e,t)=>{if(e.connection?.source?.kind!==`repository`)return q.onReadCurrent(e);let n=F.current.get(`${e.connection.app.identity.surfaceId}:${e.connection.source.id}`);if(!n||e.target.closed)throw Error(`This Bonsai file is no longer open.`);return t&&await n.source.discard(e.path,O.current.signal),n.source.readCommitted(e.path,O.current.signal)},error:J.error?`${n(J.error).message} Your open edits remain available.`:void 0,fileTree:(e,t)=>(0,U.jsx)(W,{rowHeight:t?44:32,files:J.data?.files??[],dirtyPaths:q.tabs.filter(e=>e.connection===z&&e.dirty).map(e=>e.path),activePath:Q?.connection===z?Q.path:null,busy:J.isFetching,onRefresh:N,onOpenFile:e},t?`phone`:`desktop`)}}),(0,U.jsx)(o,{open:y,onOpenChange:b,children:(0,U.jsxs)(u,{children:[(0,U.jsxs)(d,{children:[(0,U.jsx)(c,{children:`Commit history`}),(0,U.jsxs)(s,{children:[t,` · `,r]})]}),(0,U.jsx)(`ol`,{className:`inkcap-repository-history`,children:J.data?.history.map(e=>(0,U.jsxs)(`li`,{children:[(0,U.jsx)(`code`,{children:e.hash.slice(0,7)}),` `,e.message,(0,U.jsx)(`span`,{className:`text-dim`,children:e.author.name})]},e.hash))})]})})]})}export{q as InkcapRepositoryApp};
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Bn as t,Qr as n,Xi as r,Xr as i,Zi as a,a as o,c as s,d as c,dr as l,s as u,u as d,ur as f}from"./tree-path-CaOESv-X.js";import{Ft as p,Lt as m,_ as h,s as g}from"./changes-patch-B9ZsK5Me.js";import{Wt as _}from"./dropdown-menu-DKDqc_fC.js";import{n as v,r as y,t as b}from"./useFileTree-D3LWmisB.js";import{a as x,c as S,d as C,f as w,h as T,i as E,l as D,m as O,n as k,o as A,p as j,r as M,s as N,t as P,u as F}from"./index-CDh5tW42.js";var I=f(`GitBranch`,[[`line`,{x1:`6`,x2:`6`,y1:`3`,y2:`15`,key:`17qcm7`}],[`circle`,{cx:`18`,cy:`6`,r:`3`,key:`1h7g24`}],[`circle`,{cx:`6`,cy:`18`,r:`3`,key:`fqmcym`}],[`path`,{d:`M18 9a9 9 0 0 1-9 9`,key:`n2h4wq`}]]),L=f(`History`,[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}],[`path`,{d:`M12 7v5l4 2`,key:`1fdv2h`}]]),R=e(a(),1),z=256;async function B(e,t,n,r,a){r.throwIfAborted();let o=await n(e,t);if(!j.safeParse(o).success)return o;a(!0);try{let a=null,o=!1;for(let e=0;e<z&&!o;e++){r.throwIfAborted();let e=x.parse(await n(`rebuildCopies`,{cursor:a}));o=e.done,a=e.cursor}if(!o)throw new i(`Bonsai is still preparing this repository. Try again shortly.`,{code:`TIMEOUT`,retryable:!0});r.throwIfAborted();let s=await n(e,t);if(j.safeParse(s).success)throw Error(`The repository changed while loading. Refresh to retry.`);return s}finally{a(!1)}}function V({repository:e,branch:t,request:n,onSaved:r,onSaveState:a}){let o=new Map;async function s(r,a){a.throwIfAborted();let o=A.parse(await n(`files.read`,{repo:e,ref:t,path:r}));if(a.throwIfAborted(),o.binary)throw Error(`This Bonsai file is not a text document.`);if(o.text===null&&o.blob!==null)throw new i(`This Bonsai file is too large to edit.`,{code:`FILE_TOO_LARGE`,retryable:!1});return o}async function c(s,c){c.throwIfAborted();let l=w.parse(await n(`files.sync`,{}));c.throwIfAborted();let u=l.settled.find(n=>n.repo===e&&n.branch===t&&n.path===s);if(u){if(u.result.kind===`refused`)throw new i(`Bonsai refused sync: ${u.result.reason}`,{code:`CAPABILITY_DENIED`,retryable:u.result.reason===`background-unavailable`});let e=o.get(s);if(u.result.revision!==e?.version)throw new i(`Your saved file changed. Compare before syncing.`,{code:`CONFLICT`,retryable:!0});a(s,u.result)}r()}async function l(l,u,d,f){f.throwIfAborted();let p=o.get(l);if(d===void 0){let e=await s(l,f);p={file:e,contents:e.pending?.text??e.text??``,version:e.version}}if(!p)throw Error(`Reopen this Bonsai file before saving.`);if(d!==void 0&&p.contents!==d)throw new i(`The file baseline changed. Compare before saving.`,{code:`CONFLICT`,retryable:!0});if(d!==void 0){let e=await s(l,f);if(e.version!==p.version||(e.pending?.text??e.text??``)!==p.contents)throw new i(`The file changed. Compare before saving.`,{code:`CONFLICT`,retryable:!0});e.pending===void 0&&(p.file=e)}let m=F.parse({repo:e,branch:t,path:l,baseCommit:p.file.commit,baseBlob:p.file.blob,text:u,revision:p.version}),h=C.parse(await n(`files.save`,m));if(h.kind===`refused`)throw new i(`Bonsai refused this save: ${h.reason}`,{code:`CAPABILITY_DENIED`,retryable:h.reason===`background-unavailable`});if(a(l,h),h.kind===`conflict`)throw new i(`Your saved file changed. Compare before saving.`,{code:`CONFLICT`,retryable:!0});o.set(l,{file:p.file,contents:u,version:h.revision}),r(),h.kind===`saved`&&c(l,f).catch(e=>{console.error(`Bonsai sync status could not be refreshed`,e),!(o.get(l)?.version!==h.revision||f.aborted)&&a(l,{kind:`failed`,revision:h.revision,reason:`sync_failed`})})}return{kind:`repository`,id:`${e}:${t}`,label:`${e} · ${t}`,async read(e,t,n){let r=n?.revision,i=await s(e,t);if(n?.closed)return{kind:`closed`};if(n&&n.revision!==r)return{kind:`changed`};let c=i.pending?.text??i.text??``;o.set(e,{file:i,contents:c,version:i.version});let l=i.pending;return l?.state===`pending`?a(e,{kind:`saved`,revision:l.revision,state:`pending`}):l?.state===`conflict`?a(e,{kind:`conflict`,revision:l.revision,theirs:l.theirs}):l?.state===`failed`?a(e,{kind:`failed`,revision:l.revision,reason:l.failure??`sync_failed`}):i.version!==null&&a(e,{kind:`synced`,revision:i.version,commit:i.commit}),{kind:`text`,contents:c}},replace:(e,t,n,r)=>l(e,t,n,r),write:(e,t,n)=>l(e,t,void 0,n),async exists(r,i){i.throwIfAborted();let a=D.parse(await n(`files.list`,{repo:e,ref:t}));if(i.throwIfAborted(),a.paths.includes(r))return!0;if(a.truncated)throw Error(`The repository file list is incomplete.`);return!1},retry:c,async discard(s,c){c.throwIfAborted();let l=o.get(s);if(!l)throw Error(`Reopen this saved file before discarding it.`);if(l.version===null)return;let u=N.parse({repo:e,branch:t,path:s,revision:l.version}),d=S.parse(await n(`files.discard`,u));if(c.throwIfAborted(),d.kind===`conflict`)throw new i(`Your saved file changed. Refresh before discarding.`,{code:`CONFLICT`,retryable:!0});o.delete(s),a(s,null),r()},async readCommitted(e,t){let n=await s(e,t),r=n.text??``;return o.has(e)||o.set(e,{file:n,contents:r,version:n.version}),r}}}async function H(e,t,n){let r={repo:t,ref:n},i=O.parse(await e(`files.tree`,{...r,path:``})),a=D.parse(await e(`files.list`,r)),o=E.parse(await e(`commits.list`,{...r,limit:20}));if(i.commit.hash!==a.commit.hash)throw Error(`The repository changed while loading. Refresh to retry.`);return{head:i.commit.hash,branch:n,files:a.paths.map(e=>({path:e})),history:o.commits.map(e=>e.commit),truncated:a.truncated}}var U=r();function W({files:e,rowHeight:n,dirtyPaths:r,activePath:i,busy:a,onRefresh:o,onOpenFile:s}){let c=(0,R.useRef)({files:e,onOpenFile:s});c.current={files:e,onOpenFile:s};let{model:l}=b({paths:[],initialExpansion:`open`,itemHeight:n,onSelectionChange(e){let t=e[0];t&&!t.endsWith(`/`)&&c.current.files.some(e=>e.path===t)&&c.current.onOpenFile(t)}}),u=(0,R.useMemo)(()=>{let t=new Set(r);return e.flatMap(e=>t.has(e.path)?[{path:e.path,status:`modified`}]:[])},[e,r]);(0,R.useEffect)(()=>{l.resetPaths(e.map(e=>e.path))},[l,e]),(0,R.useEffect)(()=>{l.setGitStatus(u)},[l,u]),(0,R.useEffect)(()=>{for(let e of l.getSelectedPaths())e!==i&&l.getItem(e)?.deselect();i&&l.getItem(i)?.select()},[l,i]);let d={flex:`1`,"--trees-item-height":`${String(n)}px`,"--trees-padding-inline-override":`var(--spacing-xs)`,"--trees-item-margin-x-override":`0px`,"--trees-item-padding-x-override":`var(--spacing-xs)`,"--trees-item-row-gap-override":`var(--spacing-xs)`,"--trees-border-radius-override":`var(--radius-field)`,"--trees-bg-override":`var(--color-base-100)`,"--trees-fg-override":`var(--color-base-content)`,"--trees-bg-muted-override":`var(--color-base-200)`,"--trees-selected-bg-override":`var(--color-base-300)`,"--trees-font-family-override":`var(--font-sans)`,"--trees-font-size-override":`12px`};return(0,U.jsxs)(`aside`,{className:`inkcap-tree`,"aria-label":`Repository files`,children:[(0,U.jsxs)(`div`,{className:`inkcap-tree-toolbar`,children:[(0,U.jsxs)(`span`,{children:[(0,U.jsx)(g,{"aria-hidden":`true`}),` Explorer`]}),(0,U.jsx)(t,{icon:(0,U.jsx)(y,{}),"aria-label":`Refresh repository`,variant:`ghost`,size:`responsive`,disabled:a,onClick:o})]}),(0,U.jsx)(`p`,{className:`inkcap-repository-legend`,children:`Changes in latest commit · drafts marked modified`}),(0,U.jsx)(v,{model:l,style:d})]})}var G={all:(e,t)=>[`inkcap-repository`,e,t],branch:(e,t,n)=>[...G.all(e,t),n]},K={branch_missing:`The repository branch no longer exists. Your text is saved; restore the branch before retrying.`,access_changed:`Repository access changed. Your text is saved; restore Bonsai's Git access before retrying.`,sync_failed:`Git could not publish this change. Your text is saved; retry sync.`,permanent_material:`The saved change no longer matches the repository state. Save again to publish your text from the current state.`};function q({connection:e,repository:t,initialBranch:r,initialPath:i,openRequestId:a,transport:f,onReady:g}){let v=m(),[y,b]=(0,R.useState)(!1),[x,S]=(0,R.useState)(0),[C,w]=(0,R.useState)(new Map),[E,D]=(0,R.useState)(``),O=(0,R.useRef)(new AbortController);(0,R.useEffect)(()=>{let e=new AbortController;return O.current=e,()=>{e.abort()}},[]);let A=(0,R.useCallback)((t,n)=>f?f(t,n):e.app.capabilities.require(T).call(`app_bonsai`,t,JSON.stringify(n)),[e.app,f]),j=(0,R.useCallback)((e,t)=>B(e,t,A,O.current.signal,e=>{S(t=>t+(e?1:-1))}),[A]),N=(0,R.useCallback)(()=>{v.invalidateQueries({queryKey:G.all(e.app.identity.surfaceId,t)})},[v,e.app,t]),F=(0,R.useRef)(new Map),z=(0,R.useMemo)(()=>{let n=`${e.app.identity.surfaceId}:${t}:${r}`,i=F.current.get(n);if(i?.app===e.app)return i;let a=V({repository:t,branch:r,request:j,onSaved:N,onSaveState:(e,n)=>{O.current.signal.aborted||w(i=>{let a=new Map(i),o=`${t}:${r}:${e}`;return n===null?a.delete(o):a.set(o,n),a})}}),o={app:e.app,source:a};return F.current.set(n,o),o},[t,r,j,N,e.app]),q=P({connection:z}),J=p({queryKey:G.branch(e.app.identity.surfaceId,t,r),queryFn:()=>H(j,t,r),refetchInterval:15e3});(0,R.useEffect)(()=>e.app.window.onBeforeClose(q.requestWindowClose),[e.app,q.requestWindowClose]),(0,R.useEffect)(()=>{g?.({requestWindowClose:q.requestWindowClose})},[g,q.requestWindowClose]);let Y=(0,R.useRef)(),X=(0,R.useRef)(new Map),Z=(0,R.useRef)(new Set);(0,R.useEffect)(()=>{if(!J.data)return;let e=`${z.app.identity.surfaceId}:${z.source.id}:${a}`;Y.current!==e&&(Y.current=e,q.onOpenFile(i));let t=X.current.get(z.source.id),n=t!==void 0&&t!==J.data.head;X.current.set(z.source.id,J.data.head);let r=new Set(q.tabs.map(e=>e.tabKey));for(let e of Z.current)r.has(e)||Z.current.delete(e);for(let e of q.tabs)if(!(e.target.closed||e.connection!==z||!n&&!Z.current.has(e.tabKey))){if(e.target.saving){Z.current.add(e.tabKey);continue}Z.current.delete(e.tabKey),e.target.dirty||q.onReopen(e,{background:!0})}},[J.data,z,i,a,q]);let Q=q.tabs.find(e=>e.tabKey===q.active),$=Q?.connection?.source?C.get(`${Q.connection.source.id}:${Q.path}`):void 0,ee=$?.kind===`saved`?`Saved · syncing`:$?.kind===`synced`?`Synced · ${$.commit.slice(0,7)}`:$?.kind===`conflict`?`Sync conflict · Compare`:$?.kind===`failed`?`Sync failed · Retry`:void 0;async function te(){if(!Q?.connection?.source)return;let e=F.current.get(`${Q.connection.app.identity.surfaceId}:${Q.connection.source.id}`);if(e)try{D(``),await e.source.retry(Q.path,O.current.signal)}catch(e){console.error(`Bonsai sync retry failed`,e),D(`${n(e).message} Your saved text remains in Bonsai.`)}}async function ne(){if(!Q?.connection?.source)return;let e=()=>!Q.target.dirty&&!Q.target.saving&&!Q.target.closed;if(!e())return;let t=F.current.get(`${Q.connection.app.identity.surfaceId}:${Q.connection.source.id}`);if(t)try{D(``);let n=await t.source.read(Q.path,O.current.signal);if(n.kind!==`text`)throw Error(`This saved text is unavailable.`);if(!e())return;await t.source.replace(Q.path,n.contents,n.contents,O.current.signal)}catch(e){console.error(`Bonsai explicit re-save failed`,e),D(`${n(e).message} Your saved text and open edits remain available.`)}}return(0,U.jsxs)(`div`,{className:`inkcap-repository`,children:[(0,U.jsxs)(`div`,{className:`inkcap-repository-toolbar`,children:[(0,U.jsxs)(`span`,{className:`inkcap-repository-name`,children:[(0,U.jsx)(I,{"aria-hidden":`true`}),` `,t,` · `,r]}),(0,U.jsxs)(l,{size:`sm`,variant:`outline`,onClick:()=>{b(!0)},children:[(0,U.jsx)(L,{"aria-hidden":`true`,className:`size-[var(--stipe-icon-size-sm)]`}),` `,`History`]})]}),x>0&&(0,U.jsx)(M,{message:`Loading this repository…`}),J.data?.truncated&&(0,U.jsx)(_,{tone:`info`,title:`Only the indexed files are shown`}),E&&(0,U.jsx)(h,{message:E,onDismiss:()=>{D(``)}}),$?.kind===`failed`&&!E&&(0,U.jsx)(_,{tone:`warning`,title:$.reason===`permanent_material`?`Sync needs a new save`:`Sync failed`,description:K[$.reason],action:(0,U.jsx)(l,{size:`sm`,disabled:$.reason===`permanent_material`&&Q!==void 0&&(Q.target.dirty||Q.target.saving),onClick:()=>void($.reason===`permanent_material`?ne():te()),children:$.reason===`permanent_material`?`Save again`:`Retry`})}),(0,U.jsx)(k,{model:{...q,repositoryStatus:ee,repositoryStates:C,canList:!0,sourceLabel:z.source.label,onReadCurrent:async(e,t)=>{if(e.connection?.source?.kind!==`repository`)return q.onReadCurrent(e);let n=F.current.get(`${e.connection.app.identity.surfaceId}:${e.connection.source.id}`);if(!n||e.target.closed)throw Error(`This Bonsai file is no longer open.`);return t&&await n.source.discard(e.path,O.current.signal),n.source.readCommitted(e.path,O.current.signal)},error:J.error?`${n(J.error).message} Your open edits remain available.`:void 0,fileTree:(e,t)=>(0,U.jsx)(W,{rowHeight:t?44:32,files:J.data?.files??[],dirtyPaths:q.tabs.filter(e=>e.connection===z&&e.dirty).map(e=>e.path),activePath:Q?.connection===z?Q.path:null,busy:J.isFetching,onRefresh:N,onOpenFile:e},t?`phone`:`desktop`)}}),(0,U.jsx)(o,{open:y,onOpenChange:b,children:(0,U.jsxs)(u,{children:[(0,U.jsxs)(d,{children:[(0,U.jsx)(c,{children:`Commit history`}),(0,U.jsxs)(s,{children:[t,` · `,r]})]}),(0,U.jsx)(`ol`,{className:`inkcap-repository-history`,children:J.data?.history.map(e=>(0,U.jsxs)(`li`,{children:[(0,U.jsx)(`code`,{children:e.hash.slice(0,7)}),` `,e.message,(0,U.jsx)(`span`,{className:`text-dim`,children:e.author.name})]},e.hash))})]})})]})}export{q as InkcapRepositoryApp};