@fungi.computer/inkcap 0.16.16 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{FileTab-CcQMxbWO.js → FileTab-Dh_MXYyL.js} +1 -1
- package/dist/assets/{InkcapFileTree-ghHjvI3s.js → InkcapFileTree-BOkmSC0u.js} +1 -1
- package/dist/assets/{InkcapRepositoryApp-oM5Lntgb.js → InkcapRepositoryApp-D0pW-5wq.js} +1 -1
- package/dist/assets/{dropdown-menu-Dq1aB5_o.js → dropdown-menu-D1-KaUEJ.js} +1 -1
- package/dist/assets/index-BsHPJca6.css +2 -0
- package/dist/assets/index-DqkwqNVw.js +2 -0
- package/dist/index.html +3 -3
- package/package.json +3 -3
- package/dist/assets/index-CqQimK4E.css +0 -2
- package/dist/assets/index-D_l_wXCU.js +0 -2
|
@@ -1515,4 +1515,4 @@ XID_Start XIDS`.split(/\s/).map(e=>[Yu(e),e])),Hd=new Map([[`s`,Dd(383)],[Dd(383
|
|
|
1515
1515
|
`;if(t.endsWith(`
|
|
1516
1516
|
`))return`
|
|
1517
1517
|
`;if(t.endsWith(`\r`))return`\r`}return`
|
|
1518
|
-
`}function zv(e,t){return Math.max(e.additionLines.length,e.deletionLines.length)>t}function Bv(e,t){return e.isPartial&&t&&(e.type===`change`||e.type===`rename-changed`)}function Vv(e,t){return e.lineNumber===t.lineNumber&&e.side===t.side&&e.metadata===t.metadata}function Hv(e,t){return e.slotName===t.slotName&&e.hunkIndex===t.hunkIndex&&e.lines===t.lines&&e.lineCountKnown===t.lineCountKnown&&e.type===t.type&&e.expandable?.chunked===t.expandable?.chunked&&e.expandable?.up===t.expandable?.up&&e.expandable?.down===t.expandable?.down}function Uv(e){return{theme:e?.theme,disableLineNumbers:e?.disableLineNumbers,overflow:e?.overflow,collapsed:e?.collapsed,disableFileHeader:e?.disableFileHeader,disableVirtualizationBuffers:e?.disableVirtualizationBuffers,stickyHeader:e?.stickyHeader,preferredHighlighter:e?.preferredHighlighter,useCSSClasses:e?.useCSSClasses,useTokenTransformer:V_(e),tokenizeMaxLineLength:e?.tokenizeMaxLineLength,tokenizeMaxLength:e?.tokenizeMaxLength,diffStyle:e?.diffStyle,diffIndicators:e?.diffIndicators,disableBackground:e?.disableBackground,hunkSeparators:typeof e?.hunkSeparators==`function`?`custom`:e?.hunkSeparators,expandUnchanged:e?.expandUnchanged,loadDiffFiles:e?.loadDiffFiles,collapsedContextThreshold:e?.collapsedContextThreshold,lineDiffType:e?.lineDiffType,maxLineDiffLength:e?.maxLineDiffLength,expansionLineCount:e?.expansionLineCount,headerRenderMode:e?.renderCustomHeader==null?`default`:`custom`}}function Wv(e){return e.isPartial&&(e.type===`change`||e.type===`rename-changed`||e.type===`rename-pure`)}var Gv=-1,Kv=class{options;workerManager;isContainerManaged;static LoadedCustomComponent=!0;__id=`file-diff:${++Gv}`;type=`file-diff`;fileContainer;spriteSVG;pre;codeUnified;codeDeletions;codeAdditions;bufferBefore;bufferAfter;themeCSSStyle;appliedThemeCSS;hasAdoptedThemeCSS=!1;unsafeCSSStyle;appliedUnsafeCSS;gutterUtilityContent;headerElement;headerPrefix;headerFilenameSuffix;headerMetadata;headerCustom;separatorCache=new Map;errorWrapper;placeHolder;hunksRenderer;resizeManager;scrollSyncManager;interactionManager;annotationCache=new Map;lineAnnotations=[];managersDirty=!1;deletionFile;additionFile;fileDiff;renderRange;pendingFiles;appliedPreAttributes;lastRenderedHeaderHTML;cachedHeaderHTML;lastRowCount;mounted=!1;enabled=!0;editor;refreshViewTimeout;lineStateRefreshPending=!1;deferredSelectedLines;deferredEditorActiveLine;constructor(e={theme:V},t,n=!1){this.options=e,this.workerManager=t,this.isContainerManaged=n,this.hunksRenderer=this.createHunksRenderer(e),this.resizeManager=new r_,this.scrollSyncManager=new hv,this.interactionManager=new Lg(`diff`,Rg(e,typeof e.hunkSeparators==`function`||(e.hunkSeparators??`line-info`)===`line-info`||e.hunkSeparators===`line-info-basic`?this.handleExpandHunk:void 0,this.getLineIndex)),this.workerManager?.subscribeToThemeChanges(this),this.enabled=!0}handleHighlightRender=()=>{this.rerender()};getHunksRendererOptions(e){return Uv(e)}createHunksRenderer(e){return new wv(this.getHunksRendererOptions(e),this.handleHighlightRender,this.workerManager)}getLineIndex=(e,t=`additions`)=>{let n=this.fileDiffCache;if(n==null)return;let r=n.hunks.at(-1),i,a;hunkIterator:for(let o of n.hunks){let n=t===`deletions`?o.deletionStart:o.additionStart,s=t===`deletions`?o.deletionCount:o.additionCount,c=x(n,s)+1,l=o.splitLineStart,u=o.unifiedLineStart;if(e<c){let t=c-e;i=Math.max(u-t,0),a=Math.max(l-t,0);break hunkIterator}if(e>=c+s){if(o===r){let t=e-(c+s);i=u+o.unifiedLineCount+t,a=l+o.splitLineCount+t;break hunkIterator}continue}for(let n of o.hunkContent)if(n.type===`context`){if(e<c+n.lines){let t=e-c;a=l+t,i=u+t;break hunkIterator}c+=n.lines,l+=n.lines,u+=n.lines}else{let r=t===`deletions`?n.deletions:n.additions;if(e<c+r){let r=e-c;i=u+(t===`additions`?n.deletions:0)+r,a=l+r;break hunkIterator}c+=r,l+=Math.max(n.deletions,n.additions),u+=n.deletions+n.additions}break hunkIterator}if(i!=null&&a!=null)return[i,a]};setOptions(e){e!=null&&(this.options=e,this.cachedHeaderHTML=void 0,this.hunksRenderer.setOptions(this.getHunksRendererOptions(e)),this.syncInteractionOptions())}syncInteractionOptions(){this.interactionManager.setOptions(Rg(this.options,typeof this.options.hunkSeparators==`function`||(this.options.hunkSeparators??`line-info`)===`line-info`||this.options.hunkSeparators===`line-info-basic`?this.handleExpandHunk:void 0,this.getLineIndex))}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&&!An(this.appliedThemeCSS.theme,this.options.theme??V)}getHoveredLine=()=>this.interactionManager.getHoveredLine();setLineAnnotations(e){this.lineAnnotations=e}canPartiallyRender(e,t,n){return!(e||t||n||typeof this.options.hunkSeparators==`function`)}setSelectedLines(e,t){this.lineStateRefreshPending?this.deferredSelectedLines=[e,t]:this.interactionManager.setSelection(e,t)}setEditorActiveLine(e,t){this.lineStateRefreshPending?this.deferredEditorActiveLine=[e,t]:this.interactionManager.setEditorActiveLine(e,{lineNumberOnly:t?.lineNumberOnly,side:t?.side??`additions`})}flushDeferredLineState(){let{deferredEditorActiveLine:e,deferredSelectedLines:t}=this;this.lineStateRefreshPending=!1,this.deferredEditorActiveLine=void 0,this.deferredSelectedLines=void 0,e!=null&&this.setEditorActiveLine(...e),t!=null&&this.interactionManager.setSelection(...t)}flushManagers(){if(!this.managersDirty||this.pre==null){this.managersDirty=!1;return}let{diffStyle:e=`split`,overflow:t=`scroll`}=this.options;this.interactionManager.setup(this.pre),this.resizeManager.setup(this.pre,{disableAnnotations:t===`wrap`,columnVariables:this.shouldApplyColumnVariables(t)?`apply`:`measure`}),t===`scroll`&&e===`split`?this.scrollSyncManager.setup(this.pre,this.codeDeletions,this.codeAdditions):this.scrollSyncManager.cleanUp(),this.managersDirty=!1}shouldApplyColumnVariables(e){return typeof this.options.hunkSeparators==`function`||e===`scroll`&&(this.lineAnnotations.length>0||this.pre?.hasAttribute(`data-has-merge-conflict`)===!0)}getCodeScrollLeft(){return Math.max(this.codeUnified?.scrollLeft??0,this.codeDeletions?.scrollLeft??0,this.codeAdditions?.scrollLeft??0)}setCodeScrollLeft(e){this.codeUnified!=null&&(this.codeUnified.scrollLeft=e),this.codeAdditions!=null&&(this.codeAdditions.scrollLeft=e),this.codeDeletions!=null&&(this.codeDeletions.scrollLeft=e)}__getEffectiveCodeOptions(){return{...this.options,...this.hunksRenderer.getEffectiveCodeOptions()}}cleanUp(e=!1){jh(this.handleEditSessionRender),this.emitPostRender(!0),this.editor?.cleanUp(e),this.editor=void 0,this.resizeManager.cleanUp(),this.interactionManager.cleanUp(),this.scrollSyncManager.cleanUp(),this.managersDirty=!1,this.workerManager?.unsubscribeToThemeChanges(this),this.renderRange=void 0,this.pendingFiles=void 0,this.isContainerManaged||this.fileContainer?.remove(),this.fileContainer=void 0,this.mounted=!1,e||(this.lineAnnotations=[]),this.clearAuxiliaryNodes(),this.annotationCache.clear(),this.pre=void 0,this.codeUnified=void 0,this.codeDeletions=void 0,this.codeAdditions=void 0,this.bufferBefore?.remove(),this.bufferBefore=void 0,this.bufferAfter?.remove(),this.bufferAfter=void 0,this.appliedPreAttributes=void 0,this.headerElement=void 0,this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0,this.headerCustom=void 0,this.placeHolder?.remove(),this.placeHolder=void 0,this.lastRenderedHeaderHTML=void 0,e||(this.cachedHeaderHTML=void 0),this.errorWrapper?.remove(),this.errorWrapper=void 0,this.spriteSVG=void 0,this.lastRowCount=void 0,this.themeCSSStyle=void 0,this.appliedThemeCSS=void 0,this.hasAdoptedThemeCSS=!1,this.unsafeCSSStyle=void 0,this.appliedUnsafeCSS=void 0,e?this.hunksRenderer.recycle():(this.hunksRenderer.cleanUp(),this.workerManager=void 0,this.fileDiff=void 0,this.deletionFile=void 0,this.additionFile=void 0),this.refreshViewTimeout!=null&&(clearTimeout(this.refreshViewTimeout),this.refreshViewTimeout=void 0),this.lineStateRefreshPending=!1,this.deferredEditorActiveLine=void 0,this.deferredSelectedLines=void 0,this.enabled=!1}virtualizedSetup(){this.enabled=!0,this.workerManager?.subscribeToThemeChanges(this)}hydrate({fileContainer:e,prerenderedHTML:t,preventEmit:n=!1,lineAnnotations:r,fileDiff:i,...a}){if(!this.enabled)throw Error(`FileDiff.hydrate: attempting to call hydrate after cleaned up`);if(this.fileContainer!=null)throw Error(`FileDiff.hydrate: hydrate can only be called before the instance has rendered or hydrated`);let o=rv(a,`FileDiff.hydrate`),s=o?.oldFile,c=o?.newFile;this.hydrateElements(e,t),Xv(this.pre,Jv({fileDiff:i,oldFile:s,newFile:c}),this.options.collapsed)||Zv(this.headerElement,Yv({fileDiff:i,oldFile:s,newFile:c}),this.options.disableFileHeader)?this.render({...a,fileContainer:e,lineAnnotations:r,fileDiff:i,preventEmit:!0}):this.hydrationSetup({fileDiff:i,lineAnnotations:r,...o}),n||this.emitPostRender()}hydrateElements(e,t){this.fileContainer!==e&&this.emitPostRender(!0),Z_(e,t);for(let t of e.shadowRoot?.children??[]){if(t instanceof SVGElement){this.spriteSVG=t;continue}if(t instanceof HTMLElement){if(t instanceof HTMLPreElement){this.pre=t;for(let e of t.children)!(e instanceof HTMLElement)||e.tagName.toLowerCase()!==`code`||(`deletions`in e.dataset&&(this.codeDeletions=e),`additions`in e.dataset&&(this.codeAdditions=e),`unified`in e.dataset&&(this.codeUnified=e));continue}if(`diffsHeader`in t.dataset){this.headerElement=t;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}}}this.pre!=null&&(this.syncCodeNodesFromPre(this.pre),this.pre.removeAttribute(`data-dehydrated`)),this.fileContainer=e,this.hydrateMeasuredScrollbar()}hydrationSetup({fileDiff:e,oldFile:t,newFile:n,lineAnnotations:r}){this.lineAnnotations=r??this.lineAnnotations,this.additionFile=n,this.deletionFile=t,this.fileDiff=e??(t!==void 0&&n!==void 0?Fh(t,n,this.options.parseDiffOptions):void 0),this.pre!=null&&(this.syncInteractionOptions(),this.hunksRenderer.hydrate(this.fileDiff),this.renderAnnotations(),this.renderGutterUtility(),this.injectUnsafeCSS(),this.managersDirty=!0,this.flushManagers())}rerender(){!this.enabled||this.fileDiff==null&&this.additionFile==null&&this.deletionFile==null||this.render({forceRender:!0,renderRange:this.renderRange})}onThemeChange(){this.hunksRenderer.clearRenderCache(),this.rerender()}handleExpandHunk=(e,t,n)=>{this.expandHunk(e,t,n)};expandHunk=(e,t,n)=>{this.hunksRenderer.expandHunk(e,t,n),this.loadFilesIfNecessary(),this.rerender()};loadFilesIfNecessary(){let{fileDiff:e,options:{loadDiffFiles:t}}=this;e==null||t==null||!Wv(e)||this.pendingFiles?.fileDiff===e||(this.pendingFiles={fileDiff:e,promise:this.loadFilesForDiff(e,t)})}async loadFilesForDiff(e,t){try{let n=await t(e);if(!this.enabled||this.fileDiff!==e)return;await this.handleFilesLoaded(e,n)}catch(e){if(this.options.disableErrorHandling===!0)throw e;console.error(e)}finally{this.pendingFiles?.fileDiff===e&&(this.pendingFiles=void 0)}}async handleFilesLoaded(e,t){this.fileDiff!==e||!e.isPartial||(ov(`merge`,e,t),this.setHydratedState(t),await $_(()=>this.primeHighlightCache(e)),!(!this.enabled||this.fileDiff!==e)&&this.rerender())}setHydratedState(e){this.deletionFile=e.oldFile,this.additionFile=e.newFile,this.workerManager?.cleanUpTasks(this.hunksRenderer),this.hunksRenderer.clearRenderCache()}render({fileDiff:e,deferManagers:t=!1,forceRender:n=!1,preventEmit:r=!1,lineAnnotations:i,fileContainer:a,containerWrapper:o,renderRange:s,...c}){let l=rv(c,`FileDiff.render`),u=l?.oldFile,d=l?.newFile;if(!this.enabled)throw Error(`FileDiff.render: attempting to call render after cleaned up`);e!=null&&e.cacheKey===void 0&&(e.cacheKey=e.prevName==null?e.name:e.prevName+`:`+e.name),this.editor?.__postponeBgTokenizeToNextFrame();let{collapsed:f=!1,themeType:p=`system`,expandUnchanged:m=!1}=this.options,h=f?void 0:s,g=this.hasThemeChanged(),_=l!=null,v=_&&(!qv(u,this.deletionFile)||!qv(d,this.additionFile)),y=e!=null&&e!==this.fileDiff,b=i!=null&&(i.length>0||this.lineAnnotations.length>0)&&i!==this.lineAnnotations;if(!f&&d_(h,this.renderRange)&&!n&&!b&&!g&&(e!=null&&e===this.fileDiff||e==null&&!v))return this.applyCachedThemeState(p);let x;e==null&&_&&(v||this.fileDiff==null)&&(x=Fh(l.oldFile,l.newFile,this.options.parseDiffOptions));let{renderRange:S}=this;if(this.renderRange=h,_?(this.deletionFile=u,this.additionFile=d):e!=null&&(this.deletionFile=void 0,this.additionFile=void 0),e==null?x!=null&&(y=!0,this.fileDiff=x):this.fileDiff=e,y&&(this.cachedHeaderHTML=void 0),i!=null&&this.setLineAnnotations(i),this.fileDiff==null)return!1;this.fileDiff.editSessionDirty===!0&&this.shouldSelfHealEditSession()&&(pg(this.fileDiff,this.options.parseDiffOptions),this.hunksRenderer.refreshHighlightedResult()),m&&this.loadFilesIfNecessary(),this.hunksRenderer.setOptions(this.getHunksRendererOptions(this.options)),this.syncInteractionOptions(),this.hunksRenderer.setLineAnnotations(this.lineAnnotations);let{disableErrorHandling:C=!1,disableFileHeader:ee=!1}=this.options;if(ee&&(this.headerElement!=null&&(this.headerElement.remove(),this.headerElement=void 0,this.lastRenderedHeaderHTML=void 0),this.clearHeaderSlots()),a=this.getOrCreateFileContainer(a,o),this.applyCachedThemeState(p),f){this.removeRenderedCode(),this.clearAuxiliaryNodes();try{let e=this.hunksRenderer.renderDiff(this.fileDiff,Mt);e!=null&&this.applyThemeState(a,e.themeStyles,p,e.baseThemeType),e?.headerElement!=null&&this.applyHeaderToDOM(e.headerElement,a),this.renderSeparators([]),this.injectUnsafeCSS()}catch(e){if(C)throw e;console.error(e),e instanceof Error&&this.applyErrorToDOM(e,a)}return r||this.emitPostRender(),!0}try{let e=this.getOrCreatePreNode(a);if(!(this.canPartiallyRender(n,b,v||y||g)&&this.applyPartialRender({previousRenderRange:S,renderRange:h}))){let t=this.hunksRenderer.renderDiff(this.fileDiff,h);if(t==null)return this.workerManager?.isInitialized()===!1&&this.workerManager.initialize().then(()=>this.rerender()),!1;this.applyThemeState(a,t.themeStyles,p,t.baseThemeType),t.headerElement!=null&&this.applyHeaderToDOM(t.headerElement,a),t.additionsContentAST!=null||t.deletionsContentAST!=null||t.unifiedContentAST!=null?this.applyHunksToDOM(e,t):this.pre!=null&&(this.pre.remove(),this.pre=void 0),this.renderSeparators(t.hunkData)}this.applyBuffers(e,h),this.injectUnsafeCSS(),this.renderAnnotations(),this.renderGutterUtility(),this.managersDirty=!0,t||this.flushManagers(),this.editor!=null&&this.syncRenderViewToEditor()}catch(e){if(C)throw e;console.error(e),e instanceof Error&&this.applyErrorToDOM(e,a)}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;this.options.onPostRender?.(t,this,`unmount`);return}if(t==null)return;let r=this.mounted?`update`:`mount`;this.mounted=!0,n?.(t,this,r)}get fileDiffCache(){return this.hunksRenderer.diffCache??this.fileDiff}syncRenderViewToEditor(){let e=this.editor,t=this.fileContainer,n=this.fileDiffCache,r=this.lineAnnotations,i=this.computeEditorRenderRange(this.renderRange);e!=null&&t!=null&&n!=null&&!n.isPartial&&this.hunksRenderer.initializeHighlighter().then(a=>{!this.enabled||this.editor!==e||this.fileContainer!==t||this.fileDiffCache!==n||e.__syncRenderView(a,t,n,r,i)})}computeEditorRenderRange(e){let t=this.fileDiffCache;if(e==null||t==null||gv(e))return e;let{diffStyle:n=`split`,expandUnchanged:r=!1,collapsedContextThreshold:i=1}=this.options,a,o;return Mm({diff:t,diffStyle:n,startingLine:e.startingLine,totalLines:e.totalLines,expandedHunks:r?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:i,callback:({additionLine:e})=>{e!=null&&(a??=e.lineNumber,o=e.lineNumber)}}),a==null||o==null?{...e,startingLine:0,totalLines:0}:{...e,startingLine:a-1,totalLines:o-a+1}}attachEditor(e){if(this.type!==`file-diff`)throw Error(`FileDiff.attachEditor: cannot attach an editor to a "${this.type}" diff`);return this.editor?.cleanUp(),this.editor=e,this.hunksRenderer.beginEditSession(),this.fileDiff?.isPartial===!0&&this.loadFilesIfNecessary(),this.hunksRenderer.editorRenderReady()?this.syncRenderViewToEditor():this.rerender(),e=>{this.editor=void 0,e!==!0&&this.finishEditSession()}}finishEditSession(){this.hunksRenderer.endEditSession(),this.completeEditSession()}completeEditSession(){let e=this.fileDiffCache;if(e==null||e.editSessionDirty!==!0)return!1;let{collapsedContextThreshold:t=1}=this.options,n=dg(e,this.hunksRenderer.getExpandedHunksMap(),t);return pg(e,this.options.parseDiffOptions),this.hunksRenderer.setExpandedHunksMap(fg(e,n)),this.hunksRenderer.refreshHighlightedResult(),this.escalateEditSessionRender(),!0}applyDocumentChange(e,t){this.hunksRenderer.applyDocumentChange(e);let n=this.hunksRenderer.diffCache;if(n!=null){let e=this.fileDiff?.cacheKey;e!=null&&n.cacheKey==null&&(n.cacheKey=e),this.fileDiff=n}t!==void 0&&t!==this.lineAnnotations&&(this.setLineAnnotations(t),this.hunksRenderer.setLineAnnotations(this.lineAnnotations),this.renderAnnotations()),this.rerender(),this.interactionManager.setSelectionDirty()}updateRenderCache(e,t,n={}){let{shouldRefreshDiffsView:r,lineCountChangeInFlight:i}=n;if(this.hunksRenderer.updateRenderCache(e,t,i)){this.refreshViewTimeout!=null&&(clearTimeout(this.refreshViewTimeout),this.refreshViewTimeout=void 0),this.lineStateRefreshPending=!0,this.escalateEditSessionRender();return}r===!0&&(this.refreshViewTimeout!=null&&clearTimeout(this.refreshViewTimeout),this.lineStateRefreshPending=!0,this.refreshViewTimeout=setTimeout(()=>{this.refreshViewTimeout=void 0,this.options.diffStyle===`split`?this.refreshSplitDiffView():this.refreshUnifiedDiffView(),this.flushDeferredLineState()},150))}isLineRenderable(e){let t=this.fileDiffCache;if(t==null)return!0;let{expandUnchanged:n=!1,collapsedContextThreshold:r=1}=this.options;return wm({fileDiff:t,lineNumber:e,expandedHunks:n?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:r})}getNearestRenderableLine(e,t){let n=this.fileDiffCache;if(n==null)return e;let{expandUnchanged:r=!1,collapsedContextThreshold:i=1}=this.options;return Tm({fileDiff:n,lineNumber:e,direction:t,expandedHunks:r?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:i})}revealLine(e){let t=this.fileDiffCache,{expandUnchanged:n=!1,collapsedContextThreshold:r=1,expansionLineCount:i=100}=this.options;if(t==null||t.isPartial||n)return!1;let a=this.hunksRenderer.getExpandedHunksMap();for(let[n,o]of t.hunks.entries()){let[s,c]=ym(o);if(e<s){let c=bm({isPartial:t.isPartial,rangeSize:o.collapsedBefore,expandedHunks:a,hunkIndex:n,collapsedContextThreshold:r}),l=s-c.rangeSize;if(c.renderAll||e<l+c.fromStart||e>=s-c.fromEnd)return!1;let u=e-(l+c.fromStart)+1,d=s-c.fromEnd-e;return u<=d?this.expandHunk(n,`up`,u+i):this.expandHunk(n,`down`,d+i),!0}if(e<c)return!1}let o=Cm({fileDiff:t,hunkIndex:t.hunks.length-1,expandedHunks:a,collapsedContextThreshold:r,errorPrefix:`FileDiff.revealLine`});if(o==null||o.renderAll)return!1;let s=t.hunks[t.hunks.length-1],[,c]=ym(s);return e<c+o.fromStart||e>=c+o.rangeSize?!1:(this.expandHunk(t.hunks.length,`up`,e-(c+o.fromStart)+1+i),!0)}shouldSelfHealEditSession(){return this.editor==null}escalateEditSessionRender(){Ah(this.handleEditSessionRender)}handleEditSessionRender=()=>{this.rerender(),this.flushDeferredLineState()};removeRenderedCode(){this.resizeManager.cleanUp(),this.scrollSyncManager.cleanUp(),this.interactionManager.cleanUp(),this.bufferBefore?.remove(),this.bufferBefore=void 0,this.bufferAfter?.remove(),this.bufferAfter=void 0,this.codeUnified?.remove(),this.codeUnified=void 0,this.codeDeletions?.remove(),this.codeDeletions=void 0,this.codeAdditions?.remove(),this.codeAdditions=void 0,this.pre?.remove(),this.pre=void 0,this.appliedPreAttributes=void 0,this.lastRowCount=void 0}clearAuxiliaryNodes(){for(let{element:e}of this.separatorCache.values())e.remove();this.separatorCache.clear();for(let{element:e}of this.annotationCache.values())e.remove();this.annotationCache.clear(),this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0}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.fileDiff){let{workerManager:t}=this;if(e==null||t==null||!t.isWorkingPool()||e.cacheKey==null||pm(e))return;let n=this.options.tokenizeMaxLength??1e5;Math.max(e.additionLines.length,e.deletionLines.length)>n||await t.primeDiffHighlightCache(e).catch(e=>{console.error(e)})}cleanChildNodes(){this.resizeManager.cleanUp(),this.scrollSyncManager.cleanUp(),this.interactionManager.cleanUp(),this.clearAuxiliaryNodes(),this.bufferAfter?.remove(),this.bufferBefore?.remove(),this.codeAdditions?.remove(),this.codeDeletions?.remove(),this.codeUnified?.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.codeAdditions=void 0,this.codeDeletions=void 0,this.codeUnified=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}renderSeparators(e){let{hunkSeparators:t}=this.options;if(this.isContainerManaged||this.fileContainer==null||typeof t!=`function`){for(let{element:e}of this.separatorCache.values())e.remove();this.separatorCache.clear();return}let n=new Map(this.separatorCache);for(let r of e){let e=r.slotName,i=this.separatorCache.get(e);if(i==null||!Hv(r,i.hunkData)){i?.element.remove();let n=document.createElement(`div`);n.style.display=`contents`,n.slot=r.slotName;let a=t(r,this);a!=null&&n.appendChild(a),this.fileContainer.appendChild(n),i={element:n,hunkData:r},this.separatorCache.set(e,i)}n.delete(e)}for(let[e,{element:t}]of n.entries())this.separatorCache.delete(e),t.remove()}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}-${wn(r)}`,a=this.annotationCache.get(i);if(a==null||!Vv(r,a.annotation)){a?.element.remove();let e=t(r);if(e==null)continue;a={element:O_(wn(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=k_();n.appendChild(t),this.fileContainer.appendChild(n),this.gutterUtilityContent=n}getOrCreateFileContainer(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:kg(e)&&e.hasAttribute(`data-theme-css`)?(this.themeCSSStyle??=e,this.hasAdoptedThemeCSS=!0):kg(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=w_;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.codeUnified=void 0,this.codeDeletions=void 0,this.codeAdditions=void 0,t.appendChild(this.pre)):this.pre.parentNode!==t&&(this.editor?.__captureFocusForDOMReplacement(),t.appendChild(this.pre),this.appliedPreAttributes=void 0),this.placeHolder?.remove(),this.placeHolder=void 0,this.pre}syncCodeNodesFromPre(e){this.codeUnified=void 0,this.codeDeletions=void 0,this.codeAdditions=void 0;for(let t of Array.from(e.children))t instanceof HTMLElement&&(t.hasAttribute(`data-unified`)?this.codeUnified=t:t.hasAttribute(`data-deletions`)?this.codeDeletions=t:t.hasAttribute(`data-additions`)&&(this.codeAdditions=t))}applyHeaderToDOM(e,t){this.cleanupErrorWrapper(),this.placeHolder?.remove(),this.placeHolder=void 0;let{fileDiff:n}=this,r=this.cachedHeaderHTML??dc(e);if(this.cachedHeaderHTML=r,r!==this.lastRenderedHeaderHTML){let e=document.createElement(`div`);e.innerHTML=r;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=r}if(this.isContainerManaged||n==null)return;let{renderCustomHeader:i,renderHeaderPrefix:a,renderHeaderFilenameSuffix:o,renderHeaderMetadata:s}=this.options;if(i!=null){let e=i(n)??void 0;this.headerCustom=this.upsertHeaderSlotElement(t,this.headerCustom,M,e),this.headerPrefix?.remove(),this.headerFilenameSuffix?.remove(),this.headerMetadata?.remove(),this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0;return}let c=a?.(n)??void 0,l=o?.(n)??void 0,u=s?.(n)??void 0;this.headerPrefix=this.upsertHeaderSlotElement(t,this.headerPrefix,Fe,c),this.headerFilenameSuffix=this.upsertHeaderSlotElement(t,this.headerFilenameSuffix,Et,l),this.headerMetadata=this.upsertHeaderSlotElement(t,this.headerMetadata,tt,u),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}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??=A_(),this.unsafeCSSStyle.parentNode!==t&&t.appendChild(this.unsafeCSSStyle),this.unsafeCSSStyle.textContent=L_(e),this.appliedUnsafeCSS=e)}}applyThemeState(e,t,n,r){let i=e.shadowRoot??e.attachShadow({mode:`open`}),a=r??n,o=this.options.theme??V,s=typeof o==`string`?o:{...o},c=M_(i);if(this.themeCSSStyle?.parentNode===i&&this.appliedThemeCSS?.themeStyles===t&&this.appliedThemeCSS.themeType===a&&this.appliedThemeCSS.scrollbarGutter===c){this.appliedThemeCSS.theme=s;return}if(this.hasAdoptedThemeCSS&&this.themeCSSStyle?.parentNode===i){this.hasAdoptedThemeCSS=!1,this.appliedThemeCSS={theme:s,themeStyles:t,themeType:a,baseThemeType:r,scrollbarGutter:c};return}this.themeCSSStyle=W_({shadowRoot:i,currentNode:this.themeCSSStyle,themeCSS:R_(t,a,c)}),this.appliedThemeCSS=this.themeCSSStyle==null?void 0:{theme:s,themeStyles:t,themeType:a,baseThemeType:r,scrollbarGutter:c}}hydrateMeasuredScrollbar(){let e=this.fileContainer?.shadowRoot;e!=null&&this.themeCSSStyle!=null&&(this.themeCSSStyle.textContent=z_(this.themeCSSStyle.textContent??``,M_(e)))}shouldGuardRebuildScroll(){return this.editor!=null&&Y_()}applyHunksToDOM(e,t){this.shouldGuardRebuildScroll()?U_(e,()=>this.replaceCodeColumns(e,t)):this.replaceCodeColumns(e,t)}applyCodeColumnsInPlace(e,t,n){let r=this.getColumnPair(e);if(r==null)return!1;let i=Qv(t[0]),a=Qv(t[1]);return i==null||a==null?!1:(r.gutter.innerHTML=dc(i),r.content.innerHTML=dc(a),n!==this.lastRowCount&&(r.gutter.style.setProperty(`grid-row`,`span ${n}`),r.content.style.setProperty(`grid-row`,`span ${n}`)),!0)}replaceCodeColumns(e,t){let{overflow:n=`scroll`}=this.options,r=(this.options.hunkSeparators??`line-info`)===`line-info`,i=n===`wrap`?t.rowCount:void 0;this.cleanupErrorWrapper(),this.applyPreNodeAttributes(e,t);let a=!1,o=[],s=this.hunksRenderer.renderCodeAST(`unified`,t),c=this.hunksRenderer.renderCodeAST(`deletions`,t),l=this.hunksRenderer.renderCodeAST(`additions`,t);this.editor?.__captureFocusForDOMReplacement(),s==null?c!=null||l!=null?(c==null?(this.codeDeletions?.remove(),this.codeDeletions=void 0):(a=this.codeDeletions==null||this.codeUnified!=null,this.codeUnified?.remove(),this.codeUnified=void 0,this.codeDeletions=H_({code:this.codeDeletions,columnType:`deletions`,rowSpan:i,containerSize:r}),this.applyCodeColumnsInPlace(this.codeDeletions,c,t.rowCount)||(this.codeDeletions.innerHTML=this.hunksRenderer.renderPartialHTML(c)),o.push(this.codeDeletions)),l==null?(this.codeAdditions?.remove(),this.codeAdditions=void 0):(a=a||this.codeAdditions==null||this.codeUnified!=null,this.codeUnified?.remove(),this.codeUnified=void 0,this.codeAdditions=H_({code:this.codeAdditions,columnType:`additions`,rowSpan:i,containerSize:r}),this.applyCodeColumnsInPlace(this.codeAdditions,l,t.rowCount)||(this.codeAdditions.innerHTML=this.hunksRenderer.renderPartialHTML(l)),o.push(this.codeAdditions))):(this.codeUnified?.remove(),this.codeUnified=void 0,this.codeDeletions?.remove(),this.codeDeletions=void 0,this.codeAdditions?.remove(),this.codeAdditions=void 0):(a=this.codeUnified==null||this.codeAdditions!=null||this.codeDeletions!=null,this.codeDeletions?.remove(),this.codeDeletions=void 0,this.codeAdditions?.remove(),this.codeAdditions=void 0,this.codeUnified=H_({code:this.codeUnified,columnType:`unified`,rowSpan:i,containerSize:r}),this.applyCodeColumnsInPlace(this.codeUnified,s,t.rowCount)||(this.codeUnified.innerHTML=this.hunksRenderer.renderPartialHTML(s)),o.push(this.codeUnified)),o.length===0?e.textContent=``:a&&e.replaceChildren(...o),this.lastRowCount=t.rowCount}applyPartialRender({previousRenderRange:e,renderRange:t}){let{pre:n,codeUnified:r,codeAdditions:i,codeDeletions:a,options:{diffStyle:o=`split`}}=this;if(n==null||e==null||t==null||!Number.isFinite(e.totalLines)||!Number.isFinite(t.totalLines)||this.lastRowCount==null)return!1;let s=this.getCodeColumns(o,r,a,i);if(s==null)return!1;let c=e.startingLine,l=t.startingLine,u=c+e.totalLines,d=l+t.totalLines,f=Math.max(c,l),p=Math.min(u,d);if(p<=f)return!1;let m=Math.max(0,f-c),h=Math.max(0,u-p),g=this.trimColumns({columns:s,trimStart:m,trimEnd:h,previousStart:c,overlapStart:f,overlapEnd:p,diffStyle:o});if(g<0)throw Error(`FileDiff.applyPartialRender: failed to trim to overlap`);if(this.lastRowCount<g)throw Error(`FileDiff.applyPartialRender: trimmed beyond DOM row count`);let _=this.lastRowCount-g,v=(e,t)=>{if(!(t<=0||this.fileDiff==null))return this.hunksRenderer.renderDiff(this.fileDiff,{startingLine:e,totalLines:t,bufferBefore:0,bufferAfter:0})},y=v(l,Math.max(f-l,0));if(y==null&&l<f)return!1;let b=v(p,Math.max(d-p,0));if(b==null&&d>p)return!1;let x=(e,t)=>{if(e!=null){if(o===`unified`&&!Array.isArray(s))this.insertPartialHTML(o,s,e,t);else if(o===`split`&&Array.isArray(s))this.insertPartialHTML(o,s,e,t);else throw Error(`FileDiff.applyPartialRender.applyChunk: invalid chunk application`);_+=e.rowCount}};return this.cleanupErrorWrapper(),x(y,`afterbegin`),x(b,`beforeend`),this.lastRowCount!==_&&(this.applyRowSpan(o,s,_),this.lastRowCount=_),!0}insertPartialHTML(e,t,n,r){if(e===`unified`&&!Array.isArray(t)){let e=this.hunksRenderer.renderCodeAST(`unified`,n);this.renderPartialColumn(t,e,r)}else if(e===`split`&&Array.isArray(t)){let e=this.hunksRenderer.renderCodeAST(`deletions`,n),i=this.hunksRenderer.renderCodeAST(`additions`,n);this.renderPartialColumn(t[0],e,r),this.renderPartialColumn(t[1],i,r)}else throw Error(`FileDiff.insertPartialHTML: Invalid argument composition`)}refreshSplitDiffView(){if(this.options.diffStyle!==`split`)return;let e=this.hunksRenderer.renderDiff(this.fileDiff,this.renderRange);if(e==null)return;let t=this.getCodeColumns(`split`,this.codeUnified,this.codeDeletions,this.codeAdditions);if(!Array.isArray(t))return;let n=(t,n)=>{if(n==null)return;let r=this.hunksRenderer.renderCodeAST(t,e),i=Qv(r?.[0]),a=Qv(r?.[1]);for(let[e,t]of[[n.gutter,i],[n.content,a]])if(t!=null&&e.childElementCount===t.length)for(let n=0;n<t.length;n++){let r=e.children[n],i=t[n].properties[`data-line-type`];i!=null&&r.dataset.lineType!==i&&(r.dataset.lineType=i)}};n(`deletions`,t[0]),n(`additions`,t[1])}refreshUnifiedDiffView(){if(this.options.diffStyle!==`unified`)return;let e=this.hunksRenderer.renderDiff(this.fileDiff,this.renderRange);if(e==null)return;let t=this.getCodeColumns(`unified`,this.codeUnified,this.codeDeletions,this.codeAdditions);if(t==null||Array.isArray(t))return;let n=this.hunksRenderer.renderCodeAST(`unified`,e),r=Qv(n?.[0]),i=Qv(n?.[1]),a=()=>{for(let[e,n]of[[t.gutter,r],[t.content,i]])n!=null&&(e.innerHTML=dc(n));e.rowCount!==this.lastRowCount&&(this.applyRowSpan(`unified`,t,e.rowCount),this.lastRowCount=e.rowCount)};this.shouldGuardRebuildScroll()?U_(this.pre,a):a(),this.renderSeparators(e.hunkData),this.managersDirty=!0,this.flushManagers(),this.syncRenderViewToEditor()}renderPartialColumn(e,t,n){if(e==null||t==null)return;let r=Qv(t[0]),i=Qv(t[1]);if(r==null||i==null)throw Error(`FileDiff.insertPartialHTML: Unexpected AST structure`);let a=i.at(0);n===`beforeend`&&a?.type===`element`&&typeof a.properties[`data-buffer-size`]==`number`&&this.mergeBuffersIfNecessary(a.properties[`data-buffer-size`],e.content.children[e.content.children.length-1],e.gutter.children[e.gutter.children.length-1],r,i,!0);let o=i.at(-1);n===`afterbegin`&&o?.type===`element`&&typeof o.properties[`data-buffer-size`]==`number`&&this.mergeBuffersIfNecessary(o.properties[`data-buffer-size`],e.content.children[0],e.gutter.children[0],r,i,!1),e.gutter.insertAdjacentHTML(n,this.hunksRenderer.renderPartialHTML(r)),e.content.insertAdjacentHTML(n,this.hunksRenderer.renderPartialHTML(i))}mergeBuffersIfNecessary(e,t,n,r,i,a){if(!(t instanceof HTMLElement)||!(n instanceof HTMLElement))return;let o=this.getBufferSize(t.dataset);o!=null&&(a?(r.shift(),i.shift()):(r.pop(),i.pop()),this.updateBufferSize(t,o+e),this.updateBufferSize(n,o+e))}applyRowSpan(e,t,n){let r=e=>{e!=null&&(e.gutter.style.setProperty(`grid-row`,`span ${n}`),e.content.style.setProperty(`grid-row`,`span ${n}`))};if(e===`unified`&&!Array.isArray(t))r(t);else if(e===`split`&&Array.isArray(t))r(t[0]),r(t[1]);else throw Error(`dun fuuuuked up`)}trimColumnRows(e,t,n){let r=0,i=0,a=0,o=!1,s=n>=0;if(e==null)return 0;let c=Array.from(e.content.children),l=Array.from(e.gutter.children);if(c.length!==l.length)throw Error(`FileDiff.trimColumnRows: columns do not match`);for(;a<c.length&&!(t<=0&&!s&&!o);){let e=l[a],u=c[a];if(a++,!(e instanceof HTMLElement)||!(u instanceof HTMLElement))throw console.error({gutterElement:e,contentElement:u}),Error(`FileDiff.trimColumnRows: invalid row elements`);if(o&&(o=!1,e.dataset.gutterBuffer===`annotation`&&`lineAnnotation`in u.dataset||e.dataset.gutterBuffer===`metadata`&&`noNewline`in u.dataset)){e.remove(),u.remove(),i++;continue}if(`lineIndex`in e.dataset&&`lineIndex`in u.dataset){(t>0||s&&r>=n)&&(e.remove(),u.remove(),t>0&&(t--,t===0&&(o=!0)),i++),r++;continue}if(`separator`in e.dataset&&`separator`in u.dataset){(t>0||s&&r>=n)&&(e.remove(),u.remove(),i++);continue}if(e.dataset.gutterBuffer===`annotation`&&`lineAnnotation`in u.dataset){(t>0||s&&r>=n)&&(e.remove(),u.remove(),i++);continue}if(e.dataset.gutterBuffer===`metadata`&&`noNewline`in u.dataset){(t>0||s&&r>=n)&&(e.remove(),u.remove(),i++);continue}if(e.dataset.gutterBuffer===`buffer`&&`contentBuffer`in u.dataset){let a=this.getBufferSize(u.dataset);if(a==null)throw Error(`FileDiff.trimColumnRows: invalid element`);if(t>0){let n=Math.min(t,a),r=a-n;r>0?(this.updateBufferSize(e,r),this.updateBufferSize(u,r),i+=n):(e.remove(),u.remove(),i+=a),t-=n,t===0&&r===0&&(o=!0)}else if(s){let t=r,o=r+a-1;if(n<=t)e.remove(),u.remove(),i+=a;else if(n<=o){let t=o-n+1,r=a-t;this.updateBufferSize(e,r),this.updateBufferSize(u,r),i+=t}}r+=a;continue}throw console.error({gutterElement:e,contentElement:u}),Error(`FileDiff.trimColumnRows: unknown row elements`)}return i}trimColumns({columns:e,diffStyle:t,overlapEnd:n,overlapStart:r,previousStart:i,trimEnd:a,trimStart:o}){let s=Math.max(0,r-i),c=n-i;if(c<0)throw Error(`FileDiff.trimColumns: overlap ends before previous`);let l=o>0,u=a>0;if(!l&&!u)return 0;let d=l?s:0,f=u?c:-1;if(t===`unified`&&!Array.isArray(e))return this.trimColumnRows(e,d,f);if(t===`split`&&Array.isArray(e)){let t=this.trimColumnRows(e[0],d,f),n=this.trimColumnRows(e[1],d,f);if(e[0]!=null&&e[1]!=null&&t!==n)throw Error(`FileDiff.trimColumns: split columns out of sync`);return e[0]==null?n:t}throw console.error({diffStyle:t,columns:e}),Error(`FileDiff.trimColumns: Invalid columns for diffType`)}getBufferSize(e){let t=Number.parseInt(e?.bufferSize??``,10);return Number.isNaN(t)?void 0:t}updateBufferSize(e,t){e.dataset.bufferSize=`${t}`,e.style.setProperty(`grid-row`,`span ${t}`),e.style.setProperty(`min-height`,`calc(${t} * 1lh)`)}getColumnPair(e){if(e==null)return;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}}getCodeColumns(e,t,n,r){if(e===`unified`)return this.getColumnPair(t);{let e=this.getColumnPair(n),t=this.getColumnPair(r);return e!=null||t!=null?[e,t]:void 0}}updateBuffers(e){this.pre!=null&&this.applyBuffers(this.pre,e)}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}applyPreNodeAttributes(e,{additionsContentAST:t,deletionsContentAST:n,totalLines:r},i){let{diffIndicators:a=`bars`,disableBackground:o=!1,disableLineNumbers:s=!1,overflow:c=`scroll`,diffStyle:l=`split`}=this.options,u={type:`diff`,diffIndicators:a,disableBackground:o,disableLineNumbers:s,overflow:c,split:l!==`unified`&&t!=null&&n!=null,totalLines:r,customProperties:i};T_(u,this.appliedPreAttributes)||(Q_(e,u),this.appliedPreAttributes=u)}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 qv(e,t){return e==null||t==null?e==null&&t==null:jn(e,t)}function Jv({fileDiff:e,oldFile:t,newFile:n}){return e!=null&&e.hunks.length>0||t!=null||n!=null}function Yv({fileDiff:e,oldFile:t,newFile:n}){return e!=null||t!=null||n!=null}function Xv(e,t,n=!1){return!n&&e==null&&t}function Zv(e,t,n=!1){return e==null&&t&&!n}function Qv(e){if(e!=null&&e.type===`element`)return e.children??[]}var $v=3e3,ey=-1,ty=class extends Kv{__id=`little-virtualized-file-diff:${++ey}`;top;height=0;metrics;cache={heightDeltas:new Map,measuredHeightDeltaTotal:0,estimatedSplitHeight:void 0,estimatedUnifiedHeight:void 0,checkpoints:[],totalLines:0,fileAnnotationHeight:0};isVisible=!1;isSetup=!1;virtualizer;layoutDirty=!0;forceRenderOverride;currentCollapsed;currentExpandUnchanged;pendingHydratedDiff;pendingExpansions;constructor(e,t,n,r,i=!1){super(e,r,i),this.virtualizer=t,this.metrics=mm(n)}setMetrics(e,t=!1){let n=mm(e);!t&&Th(this.metrics,n)||(this.metrics=n,this.resetLayoutCache({includeEstimatedHeights:!0}))}setLineAnnotations(e){this.syncLineAnnotations(e)&&this.resetLayoutCache({includeEstimatedHeights:!1})}syncLineAnnotations(e){return e==null||e===this.lineAnnotations||e.length===0&&this.lineAnnotations.length===0?!1:(super.setLineAnnotations(e),!0)}setFileAnnotationHeight(e){let t=this.cache.fileAnnotationHeight;return e!==t&&(this.cache.fileAnnotationHeight=e,this.cache.measuredHeightDeltaTotal+=e-t,!0)}hasFileAnnotations(e=this.fileDiff){return e==null||!jg(this.lineAnnotations)?!1:this.lineAnnotations.some(t=>t.lineNumber===0?e.type===`new`?t.side===`additions`:e.type!==`deleted`||t.side===`deletions`:!1)}getLineHeight(e,t=!1){return this.getEstimatedLineHeight(t)+(this.cache.heightDeltas.get(e)??0)}getEstimatedLineHeight(e=!1){let t=e?2:1;return this.metrics.lineHeight*t}setOptions(e){if(this.isAdvancedMode())throw Error(`VirtualizedFileDiff.setOptions cannot be used inside CodeView. Update CodeView options instead.`);if(e==null)return;let{options:t}=this,n=!Eh(t,e),r=n&&ly(t,e);super.setOptions(e),r&&this.resetLayoutCache({forceSimpleRecompute:!0,includeEstimatedHeights:uy(t,e)}),n&&(this.forceRenderOverride=!0),n&&this.isSimpleMode()&&this.virtualizer.instanceChanged(this,r)}setThemeType(e){if(this.isAdvancedMode())throw Error(`VirtualizedFileDiff.setThemeType cannot be used inside CodeView. Update CodeView options instead.`);super.setThemeType(e)}resetLayoutCache({forceSimpleRecompute:e=!1,includeEstimatedHeights:t=!1,resetRenderRange:n=!0}={}){this.layoutDirty=!0,this.cache.fileAnnotationHeight=0,this.cache.heightDeltas.size>0&&this.cache.heightDeltas.clear(),this.cache.measuredHeightDeltaTotal!==0&&(this.cache.measuredHeightDeltaTotal=0),this.invalidateDerivedLayoutCache(t,n),e&&this.isSimpleMode()&&this.computeApproximateSize()}invalidateDerivedLayoutCache(e,t=!0){this.layoutDirty=!0,this.cache.checkpoints.length>0&&(this.cache.checkpoints.length=0),this.cache.totalLines!==0&&(this.cache.totalLines=0),e&&(this.cache.estimatedSplitHeight=void 0,this.cache.estimatedUnifiedHeight=void 0),this.renderRange!=null&&t&&(this.renderRange=void 0)}reconcileHeights(){let e=!1,{overflow:t=`scroll`}=this.options;if(this.fileContainer==null||this.fileDiff==null)return this.height!==0&&(e=!0),this.height=0,e;if(this.top=this.getVirtualizedTop(),t===`scroll`&&this.lineAnnotations.length===0&&!this.isResizeDebuggingEnabled())return e;let n=this.getDiffStyle(),r=n===`split`?[this.codeDeletions,this.codeAdditions]:[this.codeUnified],i=this.hasFileAnnotations(this.fileDiff);if(this.renderRange!=null&&i&&Ng(this.renderRange)){let t=ny(r)??0;this.setFileAnnotationHeight(t)&&(e=!0)}else!i&&this.setFileAnnotationHeight(0)&&(e=!0);for(let t of r){if(t==null)continue;let r=t.children[1];if(r instanceof HTMLElement)for(let t of r.children){if(!(t instanceof HTMLElement))continue;let r=t.dataset.lineIndex;if(r==null)continue;let i=my(r,n),a=t.getBoundingClientRect().height,o=!1;t.nextElementSibling instanceof HTMLElement&&(`lineAnnotation`in t.nextElementSibling.dataset||`noNewline`in t.nextElementSibling.dataset)&&(`noNewline`in t.nextElementSibling.dataset&&(o=!0),a+=t.nextElementSibling.getBoundingClientRect().height);let s=this.getEstimatedLineHeight(o),c=this.cache.heightDeltas.get(i)??0,l=a-s;l!==c&&(e=!0,this.cache.measuredHeightDeltaTotal+=l-c,l===0?this.cache.heightDeltas.delete(i):this.cache.heightDeltas.set(i,l))}}return(e||this.isResizeDebuggingEnabled())&&this.computeApproximateSize(!0),e}onRender=e=>this.fileContainer!=null&&(e&&(this.top=this.getVirtualizedTop()),this.render());flushManagers(){super.flushManagers(),this.lineStateRefreshPending&&this.flushDeferredLineState()}prepareCodeViewItem(e,t,n,r){let i=!dm(this.fileDiff,e),a=this.syncLineAnnotations(r),o=n?.resetDiffLayoutCache===!0||i||a,s=i||n?.resetDiffLayoutCache===!0&&n.includeEstimatedDiffHeights;n?.metrics!=null&&(this.metrics=mm(n.metrics),o=!0,s=!0);let{collapsed:c=!1,expandUnchanged:l=!1}=this.options;return this.currentCollapsed!==c&&(this.currentCollapsed=c,o=!0),this.currentExpandUnchanged!==l&&(this.currentExpandUnchanged=l,o=!0,s=!0),o&&this.resetLayoutCache({includeEstimatedHeights:s}),this.fileDiff=e,this.top=t,this.computeApproximateSize(),this.height}getLinePosition(e,t=`additions`){if(this.fileDiff==null||e<1)return;let n=this.getLineIndex(e,t);if(n==null)return;let{disableFileHeader:r=!1,expandUnchanged:i=!1,collapsed:a=!1,collapsedContextThreshold:o=1}=this.options,s=this.getDiffStyle(),c=this.getHunkSeparatorType(),l=s===`split`?n[1]:n[0];this.approximateLayoutCheckpoints();let u=hm(this.metrics,r),d=this.getLayoutCheckpointBeforeLineIndex(l),f=d?.top??u+this.cache.fileAnnotationHeight;if(a)return{top:u,height:0};let p;return Mm({diff:this.fileDiff,diffStyle:s,startingLine:d?.renderedLineIndex??0,expandedHunks:i?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:o,callback:({hunkIndex:e,hunk:t,collapsedBefore:n,collapsedAfter:r,deletionLine:i,additionLine:a})=>{let o=s===`split`?a?.splitLineIndex??i?.splitLineIndex:a?.unifiedLineIndex??i?.unifiedLineIndex;if(o==null)throw Error(`VirtualizedFileDiff.getLinePosition: missing line index data`);if(n>0){let r=Am({type:c,metrics:this.metrics,hunkIndex:e,hunkSpecs:t?.hunkSpecs});if(r!=null){if(f+=r.gapBefore,l>=o-n&&l<o)return p={top:f,height:r.height},!0;f+=r.height+r.gapAfter}}let u=this.getLineHeight(o,(a?.noEOFCR??!1)||(i?.noEOFCR??!1));if(o===l)return p={top:f,height:u},!0;if(f+=u,r>0){let e=jm({type:c,metrics:this.metrics});if(e!=null){if(l>o&&l<=o+r)return p={top:f+e.gapBefore,height:e.height},!0;f+=e.totalHeight}}return!1}}),p}getEditorViewport(){return this.virtualizer.type===`simple`?this.virtualizer.getRoot():this.virtualizer.getContainerElement()}getNumericScrollAnchor(e){if(this.fileDiff==null)return;let{disableFileHeader:t=!1,expandUnchanged:n=!1,collapsed:r=!1,collapsedContextThreshold:i=1}=this.options;if(r)return;let a=this.getDiffStyle(),o=this.getHunkSeparatorType();this.approximateLayoutCheckpoints();let s=this.getLayoutCheckpointBeforeTop(e),c=s?.top??hm(this.metrics,t)+this.cache.fileAnnotationHeight,l;return Mm({diff:this.fileDiff,diffStyle:a,startingLine:s?.renderedLineIndex??0,expandedHunks:n?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:i,callback:({hunkIndex:t,hunk:n,collapsedBefore:r,collapsedAfter:i,deletionLine:s,additionLine:u})=>{let d=a===`split`?u?.splitLineIndex??s?.splitLineIndex:u?.unifiedLineIndex??s?.unifiedLineIndex;if(d==null)throw Error(`VirtualizedFileDiff.getNumericScrollAnchor: missing line index data`);if(r>0){let e=Am({type:o,metrics:this.metrics,hunkIndex:t,hunkSpecs:n?.hunkSpecs});e!=null&&(c+=e.totalHeight)}if(c>=e&&(s==null?u!=null&&(l={lineNumber:u.lineNumber,side:`additions`,top:c}):l={lineNumber:s.lineNumber,side:`deletions`,top:c},l!=null))return!0;let f=this.getLineHeight(d,(u?.noEOFCR??!1)||(s?.noEOFCR??!1));if(c+=f,i>0){let e=jm({type:o,metrics:this.metrics});e!=null&&(c+=e.totalHeight)}return!1}}),l}getVirtualizedHeight(){return this.height}getAdvancedStickySpecs(e){if(this.top==null||this.fileDiff==null)return;if(this.options.collapsed===!0)return{topOffset:this.top,height:this.height};let t=e==null?this.renderRange:this.computeRenderRangeFromWindow(this.fileDiff,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({includeEstimatedHeights:!0}),this.pendingExpansions=void 0,this.pendingHydratedDiff=void 0),this.isSetup=!1,super.cleanUp(e)}expandHunk=(e,t,n)=>{this.fileDiff!=null&&(this.isAdvancedMode()?(this.pendingExpansions??=[],this.pendingExpansions.push({hunkIndex:e,direction:t,expansionLineCountOverride:n})):(this.hunksRenderer.expandHunk(e,t,n),this.resetLayoutCache({includeEstimatedHeights:!0}),this.computeApproximateSize()),this.loadFilesIfNecessary(),this.forceRenderOverride=!0,this.virtualizer.instanceChanged(this,!0))};async handleFilesLoaded(e,t){if(!(this.fileDiff!==e||!e.isPartial)){if(this.isAdvancedMode()){let n=ov(`clone`,e,t);if(await $_(()=>this.primeHighlightCache(n)),!this.enabled||this.fileDiff!==e)return;this.pendingHydratedDiff={expectedDiff:e,nextDiff:n,files:t}}else{if(ov(`merge`,e,t),this.setHydratedState(t),await $_(()=>this.primeHighlightCache(e)),!this.enabled||this.fileDiff!==e)return;this.resetLayoutCache({includeEstimatedHeights:!0}),this.computeApproximateSize()}this.forceRenderOverride=!0,this.virtualizer.instanceChanged(this,!0)}}consumeCodeViewLayoutChanges(e){let t=!1,n,{pendingExpansions:r,pendingHydratedDiff:i}=this;if(r!=null){this.pendingExpansions=void 0;for(let e of r)this.hunksRenderer.expandHunk(e.hunkIndex,e.direction,e.expansionLineCountOverride),t=!0}return i!=null&&(this.pendingHydratedDiff=void 0,i.expectedDiff===e&&(this.setHydratedState(i.files),n=i.nextDiff)),n==null?t&&(this.forceRenderOverride=!0,this.invalidateDerivedLayoutCache(!0)):(this.forceRenderOverride=!0,this.resetLayoutCache({includeEstimatedHeights:!0})),n}loadFilesIfNecessary(){if(this.pendingHydratedDiff!=null){if(this.pendingHydratedDiff.expectedDiff===this.fileDiff)return;this.pendingHydratedDiff=void 0}super.loadFilesIfNecessary()}isLineRenderable(e){if(super.isLineRenderable(e))return!0;let{pendingExpansions:t}=this,n=this.fileDiffCache;if(t==null||t.length===0||n==null)return!1;let{expansionLineCount:r=100,collapsedContextThreshold:i=1}=this.options,a=new Map(this.hunksRenderer.getExpandedHunksMap());for(let e of t){let t={...a.get(e.hunkIndex)??{fromStart:0,fromEnd:0}},n=e.expansionLineCountOverride??r;(e.direction===`up`||e.direction===`both`)&&(t.fromStart+=n),(e.direction===`down`||e.direction===`both`)&&(t.fromEnd+=n),a.set(e.hunkIndex,t)}return wm({fileDiff:n,lineNumber:e,expandedHunks:a,collapsedContextThreshold:i})}invalidateEditSessionLayout(){this.getSimpleVirtualizer()?.markDOMDirty(),this.resetLayoutCache({forceSimpleRecompute:this.isSimpleMode(),includeEstimatedHeights:!0,resetRenderRange:!1}),this.isSimpleMode()||this.computeApproximateSize(!0),this.getSimpleVirtualizer()?.requestHeightReconcile(this)}escalateEditSessionRender(){this.invalidateEditSessionLayout(),!(!this.enabled||this.fileDiff==null)&&(this.forceRenderOverride=!0,this.virtualizer.instanceChanged(this,!0))}shouldSelfHealEditSession(){return!this.isAdvancedMode()&&super.shouldSelfHealEditSession()}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.fileDiff==null&&this.additionFile==null&&this.deletionFile==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({forceSimpleRecompute:this.isSimpleMode(),includeEstimatedHeights:!0,resetRenderRange:!1}),!this.isSimpleMode())this.computeApproximateSize(!0);else if(n&&r!==void 0&&this.fileDiff!==void 0){let e=this.virtualizer.getWindowSpecs(),t=this.computeRenderRangeFromWindow(this.fileDiff,this.top??0,e);t.bufferAfter!==r.bufferAfter&&this.updateBuffers(t)}this.forceRenderOverride=!0,this.virtualizer.instanceChanged(this,!0)}computeApproximateSize(e=!1,t=this.fileDiff){let n=this.isResizeDebuggingEnabled();if(!e&&!this.layoutDirty&&!n)return;let r=this.height===0;if(this.height=0,this.cache.checkpoints=[],this.cache.totalLines=0,t==null){this.layoutDirty=!1;return}let{disableFileHeader:i=!1,collapsed:a=!1}=this.options,o=hm(this.metrics,i);if(this.height+=o,a){this.layoutDirty=!1;return}this.height=this.getActiveEstimatedHeight(t)+this.cache.measuredHeightDeltaTotal,n&&!r&&this.validateComputedHeight(t),this.layoutDirty=!1}getActiveEstimatedHeight(e=this.fileDiff){this.ensureEstimatedDiffHeights(e);let t=this.getDiffStyle()===`split`?this.cache.estimatedSplitHeight:this.cache.estimatedUnifiedHeight;if(t==null)throw Error(`VirtualizedFileDiff.getActiveEstimatedHeight: missing estimated height`);return t}ensureEstimatedDiffHeights(e=this.fileDiff){if(e==null){this.cache.estimatedSplitHeight=void 0,this.cache.estimatedUnifiedHeight=void 0;return}if(this.cache.estimatedSplitHeight!=null&&this.cache.estimatedUnifiedHeight!=null)return;let{disableFileHeader:t=!1,expandUnchanged:n=!1,collapsedContextThreshold:r=1}=this.options,{splitHeight:i,unifiedHeight:a}=ev({fileDiff:e,metrics:this.metrics,disableFileHeader:t,hunkSeparators:this.getHunkSeparatorType(),expandUnchanged:n,expandedHunks:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:r,canHydratePartialDiff:dy(e,this.options.loadDiffFiles!=null)});this.cache.estimatedSplitHeight=i,this.cache.estimatedUnifiedHeight=a}validateComputedHeight(e=this.fileDiff){if(this.fileContainer==null||e==null)return;let t=this.fileContainer.getBoundingClientRect();t.height===this.height?console.log(`VirtualizedFileDiff.computeApproximateSize: computed height IS CORRECT`):console.log(`VirtualizedFileDiff.computeApproximateSize: computed height doesnt match`,{name:e.name,elementHeight:t.height,computedHeight:this.height})}render({fileContainer:e,fileDiff:t,forceRender:n=!1,lineAnnotations:r,...i}={}){let a=rv(i,`VirtualizedFileDiff.render`),o=a!=null,s=a?.oldFile,c=a?.newFile,l=o&&(!py(s,this.deletionFile)||!py(c,this.additionFile)),u=t??this.fileDiff;t==null&&o&&(l||this.fileDiff==null)&&(u=Fh(a.oldFile,a.newFile,this.options.parseDiffOptions));let{forceRenderOverride:d,isSetup:f}=this;this.forceRenderOverride=void 0;let p=this.syncLineAnnotations(r);p&&this.resetLayoutCache({includeEstimatedHeights:!1});let m=t!=null&&t!==this.fileDiff,h=u!=null&&!dm(this.fileDiff,u),g=m||l;if(h&&this.resetLayoutCache({includeEstimatedHeights:!0}),e=this.getOrCreateFileContainer(e),u==null)return console.error(`VirtualizedFileDiff.render: attempting to virtually render when we dont have the correct data`),!1;if(f)this.top??=this.getVirtualizedTop(),h&&(this.getSimpleVirtualizer()?.markDOMDirty(),this.computeApproximateSize(!1,u));else{this.computeApproximateSize(!1,u);let t=this.getSimpleVirtualizer();if(this.top??=this.getVirtualizedTop(),this.isAdvancedMode())this.isVisible=!0;else{if(t==null)throw Error(`VirtualizedFileDiff.render: simple virtualizer is not available`);t.connect(e,this),this.isVisible=t.isInstanceVisible(this.top??0,this.height)}this.isSetup=!0}if(!this.isVisible&&this.isSimpleMode()&&(!g||!f))return this.fileDiff=u,a!=null&&(this.deletionFile=s,this.additionFile=c),h&&(this.cachedHeaderHTML=void 0),this.renderPlaceholder(this.height);let _=this.virtualizer.getWindowSpecs(),v=this.top??0,y=this.computeRenderRangeFromWindow(u,v,_),b=super.render({fileDiff:u,fileContainer:e,renderRange:y,lineAnnotations:r,forceRender:(d??n)||p||h,...a,...i});return this.isSimpleMode()&&b&&this.getSimpleVirtualizer()?.requestHeightReconcile(this),b}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`}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}getDiffStyle(){return this.options.diffStyle??`split`}getHunkSeparatorType(){return fy(this.options.hunkSeparators)}approximateLayoutCheckpoints(e=this.fileDiff){if(!this.layoutDirty&&this.cache.checkpoints.length>0||e==null||e.hunks.length===0||this.options.collapsed===!0)return;let{disableFileHeader:t=!1,expandUnchanged:n=!1,collapsedContextThreshold:r=1}=this.options,i=e.hunks.length-1,a=dy(e,this.options.loadDiffFiles!=null),o=this.getDiffStyle(),s=this.getHunkSeparatorType(),c=n?!0:this.hunksRenderer.getExpandedHunksMap(),l=ry(this.cache.heightDeltas),u=hm(this.metrics,t)+this.cache.fileAnnotationHeight,d=0,f=({rowCount:e,startLineIndex:t,preSeparatorHeight:n=0,postSeparatorHeight:r=0,metadataOffsets:i=[]})=>{if(e<=0)return;let a=d,o=d+e,s=oy(a);for(;s<o;){let e=s-a,r=u+(e>0?n:0)+e*this.metrics.lineHeight+sy(i,e)*this.metrics.lineHeight+iy(l,t,t+e);this.cache.checkpoints.push({renderedLineIndex:s,lineIndex:t+e,top:r}),s+=$v}u+=n+e*this.metrics.lineHeight+i.length*this.metrics.lineHeight+iy(l,t,t+e)+r,d=o};for(let t=0;t<e.hunks.length;t++){let n=e.hunks[t];if(n==null)throw Error(`VirtualizedFileDiff.approximateLayoutCheckpoints: invalid hunk index`);let l=bm({isPartial:e.isPartial,rangeSize:n.collapsedBefore,expandedHunks:c,hunkIndex:t,collapsedContextThreshold:r}),u=l.collapsedLines>0?Am({type:s,metrics:this.metrics,hunkIndex:t,hunkSpecs:n.hunkSpecs})?.totalHeight??0:0;f({rowCount:l.fromStart,startLineIndex:(o===`split`?n.splitLineStart:n.unifiedLineStart)-l.rangeSize});let d=u;f({rowCount:l.fromEnd,startLineIndex:(o===`split`?n.splitLineStart:n.unifiedLineStart)-l.fromEnd,preSeparatorHeight:d}),l.fromEnd>0&&(d=0);let p=t===i?Cm({fileDiff:e,hunkIndex:t,expandedHunks:c,collapsedContextThreshold:r,errorPrefix:`VirtualizedFileDiff`}):void 0,m=p!=null&&p.collapsedLines>0||t===i&&a?jm({type:s,metrics:this.metrics})?.totalHeight??0:0,h=p==null?0:p.fromStart+p.fromEnd,g=o===`split`?n.splitLineCount:n.unifiedLineCount,_=o===`split`?n.splitLineStart:n.unifiedLineStart;f({rowCount:g,startLineIndex:_,preSeparatorHeight:d,postSeparatorHeight:h===0?m:0,metadataOffsets:cy({diffStyle:o,hunk:n,rowCount:g})}),p!=null&&h>0&&f({rowCount:h,startLineIndex:_+g,postSeparatorHeight:m})}this.cache.totalLines=d}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(`VirtualizedFileDiff: 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(`VirtualizedFileDiff: 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(`VirtualizedFileDiff: invalid checkpoint index`);if(n.renderedLineIndex%t===0)return n}}getExpandedLineCount(e,t){let n=0;if(e.isPartial){for(let r of e.hunks)n+=t===`split`?r.splitLineCount:r.unifiedLineCount;return n}let{expandUnchanged:r=!1,collapsedContextThreshold:i=1}=this.options,a=r?!0:this.hunksRenderer.getExpandedHunksMap();for(let[r,o]of e.hunks.entries()){let s=t===`split`?o.splitLineCount:o.unifiedLineCount;n+=s;let c=Math.max(o.collapsedBefore,0),{fromStart:l,fromEnd:u,renderAll:d}=bm({isPartial:e.isPartial,rangeSize:c,expandedHunks:a,hunkIndex:r,collapsedContextThreshold:i});c>0&&(n+=d?c:l+u)}let o=Cm({fileDiff:e,hunkIndex:e.hunks.length-1,expandedHunks:a,collapsedContextThreshold:i,errorPrefix:`VirtualizedFileDiff`});return o!=null&&(n+=o.fromStart+o.fromEnd),n}getLayoutLineCount(e,t){let n=this.getExpandedLineCount(e,t),r=t===`split`?e.splitLineCount:e.unifiedLineCount;return Math.max(n,r,e.additionLines.length,e.deletionLines.length,this.cache.totalLines)}computeRenderRangeFromWindow(e,t,{top:n,bottom:r}){let{disableFileHeader:i=!1,expandUnchanged:a=!1,collapsedContextThreshold:o=1}=this.options,{hunkLineCount:s,lineHeight:c}=this.metrics,l=this.getDiffStyle(),u=this.getHunkSeparatorType(),d=dy(e,this.options.loadDiffFiles!=null),f=this.height,p=this.getLayoutLineCount(e,l),m=hm(this.metrics,i),h=e.hunks.length>0?_m(this.metrics):0,{fileAnnotationHeight:g}=this.cache,_=m+g,v=Math.max(0,f-m-g-h),y=this.hasFileAnnotations(e),b=t+m,x=g>0&&y&&b<r&&b+g>n;if(t<n-f||t>r)return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:f-m-h};if(p<=s||e.hunks.length===0)return{startingLine:0,totalLines:s,bufferBefore:0,bufferAfter:0};this.approximateLayoutCheckpoints(e),p=this.getLayoutLineCount(e,l);let S=Math.ceil(Math.max(r-n,0)/c),C=Math.ceil(S/s)*s+s,ee=C/s,w=ee,T=[],E=(n+r)/2,D=this.getLayoutCheckpointBeforeTop(Math.max(0,n-t-C*c*2),s),O=t+(D?.top??_),k=D?.renderedLineIndex??0,A,j,M;if(Mm({diff:e,diffStyle:l,startingLine:D?.renderedLineIndex??0,expandedHunks:a?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:o,callback:({hunkIndex:i,hunk:a,collapsedBefore:o,collapsedAfter:c,deletionLine:f,additionLine:p})=>{let m=p==null?f.splitLineIndex:p.splitLineIndex,h=p==null?f.unifiedLineIndex:p.unifiedLineIndex,g=(p?.noEOFCR??!1)||(f?.noEOFCR??!1),v=i===e.hunks.length-1&&a!=null&&(l===`split`?m===a.splitLineStart+a.splitLineCount-1:h===a.unifiedLineStart+a.unifiedLineCount-1),y=(o>0?Am({type:u,metrics:this.metrics,hunkIndex:i,hunkSpecs:a?.hunkSpecs}):void 0)?.totalHeight??0;O+=y;let b=k%s===0,x=Math.floor(k/s);if(b&&(T[x]=O-(t+_+y),M!=null)){if(M<=0)return!0;M--}let S=this.getLineHeight(l===`split`?m:h,g);if(O>n-S&&O<r&&(A??=x),j==null&&O+S>E&&(j=x),M==null&&O>=r&&b&&(M=w),k++,O+=S,c>0||v&&d){let e=jm({type:u,metrics:this.metrics});e!=null&&(O<r&&O+e.totalHeight>n&&(A??=x),j==null&&O+e.totalHeight>E&&(j=x),O+=e.totalHeight)}return!1}}),A==null){if(x)A=0,j=0;else return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:f-m-h}}j??=A;let N=Math.round(j-ee/2),te=Math.max(0,Math.ceil(p/s)-ee),ne=Math.max(0,Math.min(N,te)),re=ne*s,P=N<0?C+N*s:C,ie=T[ne]??0,ae=re===0?0:g+ie,F=ne+P/s,oe=F<T.length?v-T[F]:v-(O-t-_);return{startingLine:re,totalLines:P,bufferBefore:ae,bufferAfter:Math.max(0,oe)}}};function ny(e){let t;for(let n of e){if(n==null)continue;let e=n.children[1];if(e instanceof HTMLElement)for(let n of e.children)n instanceof HTMLElement&&n.dataset.lineAnnotation===Ag&&(t=Math.max(t??0,n.getBoundingClientRect().height))}return t}function ry(e){let t=Array.from(e).sort((e,t)=>e[0]-t[0]),n=[],r=[0],i=0;for(let[e,a]of t)n.push(e),i+=a,r.push(i);return{lineIndexes:n,prefixTotals:r}}function iy({lineIndexes:e,prefixTotals:t},n,r){if(n>=r||e.length===0)return 0;let i=ay(e,n);return(t[ay(e,r)]??0)-(t[i]??0)}function ay(e,t){let n=0,r=e.length;for(;n<r;){let i=n+r>>1,a=e[i];if(a==null)throw Error(`VirtualizedFileDiff: invalid prefix index`);a<t?n=i+1:r=i}return n}function oy(e){return Math.ceil(e/$v)*$v}function sy(e,t){let n=0;for(let r of e)r<t&&n++;return n}function cy({diffStyle:e,hunk:t,rowCount:n}){if(n<=0||!t.noEOFCRAdditions&&!t.noEOFCRDeletions)return[];let r=t.hunkContent.at(-1);if(r==null)return[];if(r.type===`context`)return[n-1];let i=Math.max(r.deletions,r.additions),a=r.deletions+r.additions;if(e===`split`)return i>0&&(t.noEOFCRAdditions||t.noEOFCRDeletions)?[n-1]:[];let o=[],s=n-a;return r.deletions>0&&t.noEOFCRDeletions&&o.push(s+r.deletions-1),r.additions>0&&t.noEOFCRAdditions&&o.push(n-1),o}function ly(e,t){return(e.diffStyle??`split`)!==(t.diffStyle??`split`)||(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.diffIndicators??`bars`)!==(t.diffIndicators??`bars`)||(e.hunkSeparators??`line-info`)!==(t.hunkSeparators??`line-info`)||!!e.loadDiffFiles!=!!t.loadDiffFiles||(e.expandUnchanged??!1)!==(t.expandUnchanged??!1)||(e.collapsedContextThreshold??1)!==(t.collapsedContextThreshold??1)||e.unsafeCSS!==t.unsafeCSS}function uy(e,t){return(e.disableFileHeader??!1)!==(t.disableFileHeader??!1)||(e.hunkSeparators??`line-info`)!==(t.hunkSeparators??`line-info`)||!!e.loadDiffFiles!=!!t.loadDiffFiles||(e.expandUnchanged??!1)!==(t.expandUnchanged??!1)||(e.collapsedContextThreshold??1)!==(t.collapsedContextThreshold??1)}function dy(e,t){return e.isPartial&&t&&(e.type===`change`||e.type===`rename-changed`)}function fy(e){return typeof e==`function`?`custom`:e??`line-info`}function py(e,t){return e==null||t==null?e==null&&t==null:jn(e,t)}function my(e,t){let[n,r]=e.split(`,`).map(Number);return t===`split`?r:n}function hy(e,t){return typeof window>`u`&&t!=null?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`template`,{shadowrootmode:`open`,dangerouslySetInnerHTML:{__html:t}}),e]}):(0,U.jsx)(U.Fragment,{children:e})}var gy=(0,W.createContext)(void 0);function _y(){return(0,W.useContext)(gy)}var vy=typeof window>`u`?W.useEffect:W.useLayoutEffect;function yy({fileDiff:e,options:t,editorOptions:n,lineAnnotations:r,selectedLines:i,prerenderedHTML:a,metrics:o,hasGutterRenderUtility:s,hasCustomHeader:c,disableWorkerPool:l,edit:u}){let d=_y(),f=i!==void 0,p=(0,W.useContext)(wh),m=bn(),h=(0,W.useRef)(null),g=_n(n=>{if(n!=null){if(h.current!=null)throw Error(`useFileDiffInstance: An instance should not already exist when a node is created`);d==null?h.current=new Kv(by({controlledSelection:f,hasCustomHeader:c,hasGutterRenderUtility:s,options:t}),l?void 0:p,!0):h.current=new ty(by({controlledSelection:f,hasCustomHeader:c,hasGutterRenderUtility:s,options:t}),d,o,l?void 0:p,!0),h.current.hydrate({fileDiff:e,fileContainer:n,lineAnnotations:r,prerenderedHTML:a})}else{if(h.current==null)throw Error(`useFileDiffInstance: A FileDiff instance should exist when unmounting`);h.current.cleanUp(),h.current=null}});return vy(()=>{let{current:n}=h;if(n==null)return;let a=by({controlledSelection:f,hasCustomHeader:c,hasGutterRenderUtility:s,options:t}),o=a!==void 0&&!Eh(n.options,a);n.setOptions(a),n.render({forceRender:o,fileDiff:e,lineAnnotations:r}),i!==void 0&&n.setSelectedLines(i)}),vy(()=>{if(u&&h.current!=null){if(m===void 0)throw Error(`FileDiff: EditContext is not attached`);let e=m(n??{});if(e==null)throw Error(`FileDiff: EditProvider.createEditor must return an editor instance`);try{return e.edit(h.current)}catch(t){throw e.cleanUp(),t}}},[u]),{ref:g,getHoveredLine:(0,W.useCallback)(()=>h.current?.getHoveredLine(),[])}}function by({options:e,controlledSelection:t,hasCustomHeader:n,hasGutterRenderUtility:r}){return t||r||n?{...e,controlledSelection:t,renderCustomHeader:n?Cn:e?.renderCustomHeader,renderGutterUtility:r?Cn:e?.renderGutterUtility}:e}var xy=W.createContext(void 0);function Sy(e){let t=W.useContext(xy);if(t===void 0&&!e)throw Error(Kt(33));return t}var Cy=W.createContext(void 0);function wy(e){let t=W.useContext(Cy);if(t===void 0&&!e)throw Error(Kt(36));return t}var Ty=W.createContext(void 0);function Ey(e=!0){let t=W.useContext(Ty);if(t===void 0&&!e)throw Error(Kt(25));return t}var Dy=W.createContext(null);function Oy(e=`root`){let t=W.useContext(Dy),n=W.useContext(Cy);return t===null||n===void 0?null:(e===`submenu-trigger`?n.virtualFocus||n.parentVirtualFocus:n.virtualFocus)?t:null}var ky={visible:!0,ref:null};function Ay(){return ky}function jy(e,t,n=`root`){let r=Oy(n),i=((n===`submenu-trigger`?r?.useSubmenuTrigger:r?.useItem)??Ay)({label:e.label,children:e.children,render:e.render}),a=re(t,i.ref);return{visible:i.visible,ref:a,props:i.props}}var My=W.createContext(void 0);function Ny(){let e=W.useContext(My);if(e===void 0)throw Error(Kt(30));return e}function Py(e){e.preventDefault()}function Fy(e){let{closeOnClick:t,highlighted:n,id:r,nodeId:i,store:a,typingRef:o,itemRef:s,itemMetadata:c}=e,l=wy(),u=Ey(!0),d=c.type===`submenu-trigger`,f=d?l.parentVirtualFocus:l.virtualFocus,p=(d&&l.parent.type===`menu`?l.parent.store:l.store).useState(`webkitAriaSelected`,n),{events:m}=a.useState(`floatingTreeRoot`),h=a.useState(`open`),g=u!==void 0,_=!f&&h&&n?0:-1;return W.useMemo(()=>({id:r,role:`menuitem`,tabIndex:_,"aria-selected":p,onMouseDown:f?Py:void 0,onKeyDown(e){e.key===` `&&o?.current&&e.preventDefault()},onMouseMove(e){i&&m.emit(`itemhover`,{nodeId:i,target:e.currentTarget})},onClick(e){t&&m.emit(`close`,{domEvent:e.nativeEvent,reason:dt})},onMouseUp(e){if(u){let t=u.initialCursorPointRef.current;if(u.initialCursorPointRef.current=null,g&&t&&Math.abs(e.clientX-t.x)<=1&&Math.abs(e.clientY-t.y)<=1||g&&!Te&&e.button===2)return}s.current&&a.context.allowMouseUpTriggerRef.current&&(!g||e.button===2)&&c.type===`regular-item`&&de(s.current,e,{detail:1,pointerType:`mouse`})}}),[t,_,r,m,i,a.context.allowMouseUpTriggerRef,o,s,u,g,c.type,p,f])}var Iy={type:`regular-item`};function Ly(e){let{closeOnClick:t,disabled:n,highlighted:r,id:i,store:a,typingRef:o=a.context.typingRef,nativeButton:s,itemMetadata:c,nodeId:l}=e,u=W.useRef(null),{getButtonProps:d,buttonRef:f}=Ae({disabled:n,focusableWhenDisabled:!0,native:s,composite:!0}),p=Fy({closeOnClick:t,highlighted:r,id:i,nodeId:l,store:a,typingRef:o,itemRef:u,itemMetadata:c}),m=W.useCallback(e=>ae(p,{onMouseEnter(e){c.type===`submenu-trigger`&&c.setActive(e.nativeEvent)}},e,d),[p,d,c]),h=re(u,f);return W.useMemo(()=>({getItemProps:m,itemRef:h}),[m,h])}var Ry=W.createContext({register:()=>{},unregister:()=>{},subscribeMapChange:()=>()=>{},nextIndexRef:{current:0}});function zy(){return W.useContext(Ry)}function By(e={}){let{guess:t,label:n,metadata:r,textRef:i,index:a}=e,{register:o,unregister:s,subscribeMapChange:c,nextIndexRef:l}=zy(),u=W.useRef(-1),[d,f]=W.useState(a==null&&t?()=>{if(u.current===-1){let e=l.current;l.current+=1,u.current=e}return u.current}:-1),p=a??d,m=W.useRef(null),h=W.useCallback(e=>{let t=m.current;t&&s(t),m.current=e,e&&o(e,{metadata:r??null,index:a??null,label:n,textRef:i})},[a,o,s,r,n,i]);return jt(()=>{if(a==null)return c(e=>{let t=m.current?e.get(m.current)?.index:null;t!=null&&f(t)})},[a,c]),{ref:h,index:p}}var Vy=`data-checked`,Hy=`data-unchecked`,Uy={checked(e){return e?{[Vy]:``}:{[Hy]:``}},...p},Wy=W.forwardRef(function(e,t){let{render:n,className:r,id:i,label:a,nativeButton:o=!1,disabled:s=!1,closeOnClick:c=!1,checked:l=!1,onCheckedChange:u,style:d,...f}=e,{store:p}=wy(),m=By({guess:!0,label:a}),h=wt(i),g=p.useState(`disabled`),_=p.useState(`isActive`,m.index),v=p.useState(`floatingNodeId`),y=p.useState(`itemProps`),b=s||g,{getItemProps:x,itemRef:C}=Ly({closeOnClick:c,disabled:b,highlighted:_,id:h,store:p,nativeButton:o,nodeId:v,itemMetadata:Iy}),ee=W.useMemo(()=>({disabled:b,highlighted:_,checked:l}),[b,_,l]);function w(e){let t=S(dt,e.nativeEvent,void 0,{preventUnmountOnClose:E});u?.(!l,t)}let T=it(`div`,e,{state:ee,stateAttributesMapping:Uy,props:[y,{role:`menuitemcheckbox`,"aria-checked":l,onClick:w},f,x],ref:[C,t,m.ref]});return(0,U.jsx)(My.Provider,{value:ee,children:T})}),Gy=W.forwardRef(function(e,t){let{checked:n,defaultChecked:r,onCheckedChange:i,...a}=e,[o,s]=Be({controlled:n,default:r??!1,name:`MenuCheckboxItem`,state:`checked`}),c=jy(e,t);function l(e,t){i?.(e,t),t.isCanceled||s(e)}return c.visible?(0,U.jsx)(Wy,{...a,checked:o,onCheckedChange:l,ref:c.ref}):null}),Ky=W.forwardRef(function(e,t){let{render:n,className:r,style:i,keepMounted:a=!1,...o}=e,s=Ny(),c=W.useRef(null),{transitionStatus:u,mounted:d,setMounted:f}=w(s.checked);l({batch:!0,enabled:!s.checked,open:s.checked,ref:c,onComplete(){s.checked||f(!1)}});let p={checked:s.checked,disabled:s.disabled,highlighted:s.highlighted,transitionStatus:u};return it(`span`,e,{state:p,ref:[t,c],stateAttributesMapping:Uy,props:{"aria-hidden":!0,...o},enabled:a||d})}),qy=W.createContext(void 0);function Jy(){let e=W.useContext(qy);if(e===void 0)throw Error(Kt(31));return e}var Yy=W.forwardRef(function(e,t){let{render:n,className:r,style:i,id:a,...o}=e,s=wt(a),c=Jy();return jt(()=>(c(s),()=>{c(e=>e===s?void 0:e)}),[c,s]),it(`div`,e,{ref:t,props:{id:s,"aria-hidden":!0,...o}})}),Xy=W.forwardRef(function(e,t){let{render:n,className:r,id:i,label:a,nativeButton:o=!1,disabled:s=!1,closeOnClick:c=!0,style:l,...u}=e,{store:d}=wy(),f=By({guess:!0,label:a}),p=wt(i),m=d.useState(`disabled`),h=d.useState(`isActive`,f.index),g=d.useState(`floatingNodeId`),_=d.useState(`itemProps`),v=s||m,{getItemProps:y,itemRef:b}=Ly({closeOnClick:c,disabled:v,highlighted:h,id:p,store:d,nativeButton:o,nodeId:g,itemMetadata:Iy});return it(`div`,e,{state:{disabled:v,highlighted:h},props:[_,u,y],ref:[b,t,f.ref]})}),Zy=W.forwardRef(function(e,t){let n=jy(e,t);return n.visible?(0,U.jsx)(Xy,{...e,ref:n.ref}):null}),Qy=Te&&De;function $y(e,t={}){let{enabled:n=!0,delay:r}=t,{events:a,dataRef:o}=e.context,s=W.useRef(!1),c=W.useRef(null),l=W.useRef(!0),u=qt();W.useEffect(()=>{let t=e.select(`domReferenceElement`);if(!n)return;let r=et(t);function a(){let t=e.select(`domReferenceElement`);!e.select(`open`)&&mt(t)&&t===F(i(t))&&(s.current=!0,c.current=t)}function o(){l.current=!0}function u(){l.current=!1}return Vt(me(r,`blur`,a),Qy&&me(r,`keydown`,o,!0),Qy&&me(r,`pointerdown`,u,!0))},[e,n]),W.useEffect(()=>{if(!n)return;function t(t){if(t.reason===`trigger-press`||t.reason===`escape-key`){let t=e.select(`domReferenceElement`);Pe(t)&&(c.current=t,s.current=!0)}}return a.on(`openchange`,t),()=>{a.off(`openchange`,t)}},[a,n,e]);let d=W.useMemo(()=>{function t(){s.current=!1,c.current=null}return{onMouseLeave(){t()},onFocus(n){let i=n.currentTarget;if(s.current){if(c.current===i)return;t()}let a=le(n.nativeEvent);if(Pe(a)){if(Qy&&!n.relatedTarget){if(!l.current&&!g(a))return}else if(!m(a))return}let o=Rt(n.relatedTarget,e.context.triggerElements),{nativeEvent:d,currentTarget:f}=n;if(e.select(`open`)&&o||!r){e.setOpen(!0,S(Bt,d,f));return}u.start(r,()=>{s.current||e.setOpen(!0,S(Bt,d,f))})},onBlur(n){t();let r=n.relatedTarget,a=n.nativeEvent,s=Pe(r)&&r.hasAttribute(qe(`focus-guard`))&&r.getAttribute(`data-type`)===`outside`;u.start(0,()=>{let t=e.select(`domReferenceElement`),n=F(i(t));!r&&n===t||se(o.current.floatingContext?.refs.floating.current,n)||se(t,n)||s||Rt(r??n,e.context.triggerElements)||e.setOpen(!1,S(Bt,a))})}}},[o,r,e,u]);return W.useMemo(()=>n?{reference:d,trigger:d}:{},[n,d])}function eb(e){return De&&e.movementX===0&&e.movementY===0}function tb(e,t,n){switch(e){case`vertical`:return t;case`horizontal`:return n;default:return t||n}}function nb(e,t){return tb(t,e===`ArrowUp`||e===`ArrowDown`,e===`ArrowLeft`||e===`ArrowRight`)}function rb(e,t,n){return tb(t,e===`ArrowDown`,n?e===`ArrowLeft`:e===`ArrowRight`)||e===`Enter`||e===` `||e===``}function ib(e,t,n){return tb(t,n?e===st:e===s,e===L)}function ab(e,t,n,r){return t===`both`||t===`horizontal`&&r?e===`Escape`:tb(t,n?e===s:e===st,e===at)}function ob(e,t){let{listRef:n,activeIndex:r,onNavigate:a=()=>{},enabled:o=!0,selectedIndex:s=null,allowEscape:c=!1,loopFocus:l=!1,nested:u=!1,rtl:f=!1,virtual:p=!1,focusItemOnOpen:m=`auto`,focusItemOnHover:h=!0,openOnArrowKeyDown:_=!0,disabledIndices:v=void 0,orientation:b=`vertical`,triggerOrientation:x=b,parentOrientation:C,id:ee,resetOnPointerLeave:w=!0,externalTree:T,nestedReturnFocusRef:E,grid:O}=t,k=O!=null,A=e.useState(`open`),j=e.useState(`floatingElement`),M=e.useState(`domReferenceElement`),N=e.context.dataRef,te=d(j),ne=B(M),re=ze(te),ie=nt(),ae=Ie(T),oe=W.useRef(m),I=W.useRef(s??-1),L=W.useRef(null),ce=W.useRef(!0),R=H(e=>{a(I.current===-1?null:I.current,e)}),ue=W.useRef(!!j),z=W.useRef(A),de=W.useRef(!1),fe=W.useRef(!1),pe=W.useRef(null),me=ze(v),he=ze(A),ge=ze(s),_e=ze(w),ve=Se(),ye=Se(),be=H(()=>{ve.cancel();function e(e){p||(pe.current=He(e,{sync:de.current,preventScroll:!0}))}let t=n.current[I.current],r=fe.current;t&&e(t),(de.current?e=>e():e=>ve.request(e))(()=>{let i=n.current[I.current]||t;i&&(t||e(i),V&&(r||!ce.current)&&i.scrollIntoView?.({block:`nearest`,inline:`nearest`}))})});jt(()=>{N.current.orientation=b},[N,b]),jt(()=>{A||(L.current=null),(!A||m!==`auto`)&&(oe.current=m)},[A,m]),jt(()=>{o&&(A&&j?(I.current=s??-1,oe.current&&s!=null&&(fe.current=!0,R())):ue.current&&(I.current=-1,R()))},[o,A,j,s,R]),jt(()=>{if(o){if(!A){de.current=!1;return}if(j){if(r==null){if(de.current=!1,ge.current!=null)return;if(ue.current&&(I.current=-1,be()),(!z.current||!ue.current)&&oe.current&&(L.current!=null||oe.current===!0&&L.current==null)){let e=0,t=()=>{n.current[0]==null?(e<2&&(e?e=>ye.request(e):queueMicrotask)(t),e+=1):(I.current=L.current==null||rb(L.current,x,f)||u?ft(n):bt(n),L.current=null,R())};t()}}else Ne(n.current,r)||(I.current=r,be(),fe.current=!1)}}},[o,A,j,r,ge,u,n,x,f,R,be,ye]),jt(()=>{if(!o||j||!ae||p||!ue.current)return;let e=ae.nodesRef.current,t=e.find(e=>e.id===ie)?.context?.elements.floating,n=F(i(M??t??null)),r=e.some(e=>e.context&&se(e.context.elements.floating,n));t&&!r&&ce.current&&t.focus({preventScroll:!0})},[o,j,M,ae,ie,p]),jt(()=>{z.current=A,ue.current=!!j});let xe=r!=null,Ce=H(e=>{if(!he.current)return;let t=n.current.indexOf(e.currentTarget);t!==-1&&(I.current!==t||r!==t)&&(I.current=t,R(e))}),we=H(()=>C??ae?.nodesRef.current.find(e=>e.id===ie)?.context?.dataRef?.current.orientation),Te=H(()=>ft(n,me.current)),Ee=H(t=>{if(ce.current=!1,de.current=!0,t.which===229||!he.current&&t.currentTarget===re.current)return;if(u&&ab(t.key,b,f,k)){nb(t.key,we())||P(t),e.setOpen(!1,S(Ye,t.nativeEvent));let n=E?.current??M;mt(n)&&n.focus();return}r!=null&&r!==I.current&&!Ne(n.current,r)&&(I.current=r);let i=I.current,a=ft(n,v),o=bt(n,v);if(ne||(t.key===`Home`&&(P(t),I.current=a,R(t)),t.key===`End`&&(P(t),I.current=o,R(t))),O!=null){let e=O(t,I.current,n,b,l,f,v,a,o);if(e!=null&&e!==I.current&&(I.current=e,R(t)),b===`both`)return}if(nb(t.key,b)){P(t);let e=F(t.currentTarget.ownerDocument);if(A&&!p&&se(t.currentTarget,e)&&!n.current.some(t=>t!=null&&se(t,e))){I.current=rb(t.key,b,f)?a:o,R(t),r===I.current&&be();return}let{index:s,wrapped:u}=$e(n.current,i,{decrement:!rb(t.key,b,f),loopFocus:l,allowEscape:c,disabledIndices:v,minIndex:a,maxIndex:o});u&&(de.current=!1),I.current=s,R(t)}}),V=W.useMemo(()=>({onFocus(e){de.current=!0,Ce(e)},onClick({currentTarget:e}){p||e.focus({preventScroll:!0})},onMouseMove(e){eb(e)||(de.current=!0,fe.current=!1,h&&Ce(e))},onPointerLeave(e){if(!he.current||!ce.current||e.pointerType===`touch`)return;de.current=!0;let t=e.relatedTarget;if(!(!h||n.current.includes(t))&&_e.current&&(pe.current?.(),pe.current=null,I.current=-1,R(e),!p)){let e=re.current,t=F(i(e));e&&se(e,t)&&e.focus({preventScroll:!0})}}}),[Ce,he,re,h,n,R,_e,p]),De=W.useMemo(()=>p&&A&&xe&&{"aria-activedescendant":`${ee}-${r}`},[p,A,xe,ee,r]),Oe=W.useMemo(()=>({...ne?{}:De,onKeyDown(t){if(t.key===`Tab`&&t.shiftKey&&A&&!p){let n=le(t.nativeEvent);if(n&&!se(re.current,n))return;P(t);let r=S(Ke,t.nativeEvent);e.setOpen(!1,r);let i=E?.current??M;!r.isCanceled&&mt(i)&&i.focus();return}Ee(t)},onPointerMove(e){eb(e)||(ce.current=!0)}}),[De,Ee,re,ne,e,A,p,M,E]),ke=W.useMemo(()=>{function t(t){e.setOpen(!0,S(Ye,t.nativeEvent,t.currentTarget))}function n(e){m===`auto`&&y(e.nativeEvent)&&(oe.current=!p)}function r(e){oe.current=m,m===`auto`&&D(e.nativeEvent)&&(oe.current=!0)}return{onKeyDown(n){let r=e.select(`open`);ce.current=!1;let i=n.key.startsWith(`Arrow`),a=ib(n.key,we(),f),o=nb(n.key,r?b:x),s=(u?a:o)||n.key===`Enter`||n.key.trim()===``;if(p&&r&&(!u||g(n.currentTarget)))return Ee(n);if(!(!r&&!_&&i)){if(s){let e=nb(n.key,we());L.current=u&&e?null:n.key}if(u){a&&(P(n),r?(I.current=Te(),R(n),p&&re.current?.focus()):t(n));return}o&&(ge.current!=null&&(I.current=ge.current),P(n),!r&&_?t(n):Ee(n),r&&R(n))}},onFocus(t){t.target===t.currentTarget&&e.select(`open`)&&!p&&(I.current=-1,R(t))},onPointerDown:r,onPointerEnter:r,onMouseDown:n,onClick:n}},[Ee,m,Te,u,R,e,_,b,x,we,f,ge,p,re]),Ae=W.useMemo(()=>({...De,...ke}),[De,ke]);return W.useMemo(()=>o?{reference:Ae,floating:Oe,item:V,trigger:ke}:{},[o,Ae,Oe,ke,V])}function sb(e,t){let{listRef:n,elementsRef:r,activeIndex:i,onMatch:a,disabledIndices:o,onTyping:s,enabled:c=!0,resetMs:l=750,selectedIndex:u=null}=t,d=H(s),f=e.useState(`open`),p=qt(),m=W.useRef(``),h=W.useRef(u??i??-1),g=W.useRef(null),_=H(e=>{function t(e){return r?.current[e]}function s(e){let n=t(e);return n&&!Xe(n)||n?.matches(`:disabled`)?!1:o==null||!Ft(R,e,o)}function c(e,t,n=0){if(e.length===0)return-1;let r=(n%e.length+e.length)%e.length,i=t.toLowerCase();for(let t=0;t<e.length;t+=1){let n=(r+t)%e.length;if(!(!e[n]?.toLowerCase().startsWith(i)||!s(n)))return n}return-1}let _=n.current;if(m.current.length>0&&e.key===` `&&(P(e),d?.(!0)),m.current.length>0&&m.current[0]!==` `&&c(_,m.current)===-1&&e.key!==` `&&d?.(!1),_==null||e.key.length!==1||e.ctrlKey||e.metaKey||e.altKey)return;f&&e.key!==` `&&(P(e),d?.(!0));let v=m.current===``;v&&(h.current=u??i??-1),_.every((e,t)=>e&&s(t)?e[0]?.toLowerCase()!==e[1]?.toLowerCase():!0)&&m.current===e.key&&(m.current=``,h.current=g.current),m.current+=e.key,p.start(l,()=>{m.current=``,h.current=g.current,d?.(!1)});let y=((v?u??i??-1:h.current)??0)+1,b=c(_,m.current,y);b===-1?e.key!==` `&&(m.current=``,d?.(!1)):(a?.(b,e),g.current=b)}),v=H(t=>{let n=t.relatedTarget,r=e.select(`domReferenceElement`),i=e.select(`floatingElement`);se(r,n)||se(i,n)||(p.clear(),m.current=``,h.current=g.current,d?.(!1))});jt(()=>{!f&&u!==null||(p.clear(),g.current=null,m.current!==``&&(m.current=``,d?.(!1)))},[f,u,p,d]);let y=W.useMemo(()=>({onKeyDown:_,onBlur:v}),[_,v]);return W.useMemo(()=>c?{reference:y,floating:y}:{},[c,y])}var cb=W.createContext(void 0);function lb(){return W.useContext(cb)}function ub(e,t){let n=o(e.render);if(W.isValidElement(n)){let e=n.props;if(Object.hasOwn(e,`id`))return e.id??``}return e.id??t}function db(e,t,n){let r=ub(e,t),i=r===t?void 0:r;return[r,W.useCallback(e=>n?.(e?i:void 0),[i,n])]}function fb(e,t,n){let r=o(e.render),i=W.isValidElement(r)?r.props:void 0,a=e[`aria-label`]??i?.[`aria-label`],s=e[`aria-labelledby`]??i?.[`aria-labelledby`];return s==null&&!a&&(s=t?t.id||void 0:n||void 0),s}var pb=W.forwardRef(function(e,t){let{render:n,className:r,style:i,finalFocus:a,id:o,initialFocus:s,...c}=e,{store:u,defaultFloatingId:d,setRenderedFloatingId:p,virtualFocus:m,orientation:g}=wy(),_=lb(),{side:v,align:y}=Sy(),b=I(!0)!=null,x=u.useState(`open`),C=u.useState(`transitionStatus`),ee=u.useState(`popupProps`),w=u.useState(`mounted`),T=u.useState(`instantType`),E=u.useState(`activeTriggerElement`),D=u.useState(`parent`),O=u.useState(`lastOpenChangeReason`),k=u.useState(`rootId`),A=u.useState(`floatingRootContext`),j=u.useState(`floatingTreeRoot`),M=u.useState(`closeDelay`),N=u.useState(`hoverEnabled`),te=u.useState(`disabled`),ne=u.useState(`openMethod`),re=u.useState(`activeTriggerId`),P=u.useState(`listElement`),[ie,ae]=db(e,d,p),F=fb(e,E,re),oe=D.type===`menu`?_:void 0,se=D.type===`context-menu`,L=s??D.type!==`menu`;s===void 0&&P&&D.type!==`menu`&&(L=()=>u.state.activeIndex===null&&P),l({open:x,ref:u.context.popupRef,onComplete(){x&&u.context.onOpenChangeComplete?.(!0)}}),W.useEffect(()=>{function e(e){u.setOpen(!1,S(e.reason,e.domEvent))}return j.events.on(`close`,e),()=>{j.events.off(`close`,e)}},[j.events,u]),rt(A,{enabled:N&&!te&&!se&&D.type!==`menubar`,closeDelay:M});let ce=u.useStateSetter(`popupElement`),{parentVirtualFocusRef:R,handleFocus:le}=(W.useContext(Dy)?.useParentHandoff??hb)(u,D,x,m),ue={transitionStatus:C,side:v,align:y,open:x,nested:D.type===`menu`,instant:T},z=it(`div`,e,{state:ue,ref:[t,u.context.popupRef,ce,ae],stateAttributesMapping:Lt,props:[ee,{id:ie,...P?{role:`presentation`}:{role:`menu`,"aria-orientation":g===`horizontal`?`horizontal`:void 0,"aria-labelledby":F},onKeyDown(e){oe?.onPopupKeyDown?.(e),b&&f.has(e.key)&&e.stopPropagation()},onFocus:le},h(C),c,{"data-rootownerid":k}]}),de=D.type===void 0||se;(E||D.type===`menubar`&&O!==`outside-press`)&&(de=!0);let fe=oe?.getReturnElement??R;return(0,U.jsx)(Ge,{context:A,openInteractionType:ne,modal:se,disabled:!w,returnFocus:a??fe??de,explicitReturnFocus:a===void 0&&fe?!1:void 0,initialFocus:L,restoreFocus:!0,getInsideElements:D.type===void 0?()=>[u.context.beforeTriggerFocusGuardRef.current]:void 0,externalTree:D.type===`menubar`?void 0:j,previousFocusableElement:E,nextFocusableElement:D.type===void 0?u.context.triggerFocusTargetRef:void 0,beforeContentFocusGuardRef:u.context.beforeContentFocusGuardRef,children:z})}),mb={parentVirtualFocusRef:void 0,handleFocus:void 0};function hb(){return mb}var gb=W.forwardRef(function(e,t){let n=Oy()?.Popup??pb;return(0,U.jsx)(n,{...e,ref:t})}),_b=W.createContext(void 0);function vb(){let e=W.useContext(_b);if(e===void 0)throw Error(Kt(32));return e}var yb=W.forwardRef(function(e,t){let{keepMounted:n=!1,...r}=e,{store:i,parent:a}=wy();if(!(i.useState(`mounted`)||n))return null;let o=a.type===`menu`||a.type===`menubar`?`group`:void 0;return(0,U.jsx)(_b.Provider,{value:n,children:(0,U.jsx)(At,{ref:t,...r,portalOwnerRole:o})})});function bb(e){let{children:t,elementsRef:n,labelsRef:r,onMapChange:i}=e,a=H(i),[,o]=W.useState(0),s=fe(Sb).current,c=fe(xb).current,l=W.useRef(0),u=W.useRef(!0),d=W.useRef(null),f=W.useRef(null),p=H(()=>{u.current||(u.current=!0,o(e=>e+1))}),m=H((e,t)=>{c.set(e,t),p()}),h=H(e=>{c.delete(e),p()}),g=H(e=>{let t=new Map;return n.current.length=0,r&&(r.current.length=0),e.forEach(e=>{t.set(e.element,{...e.registration.metadata??{},index:e.index}),n.current[e.index]=e.element,r&&(r.current[e.index]=e.registration.label===void 0?e.registration.textRef?.current?.textContent??e.element.textContent:e.registration.label)}),l.current=n.current.length,t});function _(e){if(f.current?.disconnect(),f.current=null,typeof MutationObserver!=`function`||e.length<2)return;let t=new MutationObserver(n=>{if(!Tb(n))return;let r=null;for(let n of e)if(n.isConnected){if(r&&Eb(r,n)>0){t.disconnect(),p();return}r=n}});f.current=t;let n=new Set;for(let t=1;t<e.length;t+=1){let r=wb(e[t-1],e[t]);r&&n.add(r)}n.forEach(e=>t.observe(e,{childList:!0}))}let v=H(()=>{let[e,t]=Cb(c),n=g(e),r=d.current,i=!r||r.length!==e.length||e.some((e,t)=>{let n=r[t];return e.index!==n.index||e.element!==n.element||e.registration.index!==n.registration.index||e.registration.metadata!==n.registration.metadata});_(t),d.current=e,u.current=!1,i&&(s.forEach(e=>e(n)),a(n))});jt(()=>(!u.current&&d.current&&g(d.current),()=>{n.current=[],r&&(r.current=[])}),[n,r,g]),jt(()=>{u.current&&v()}),jt(()=>()=>{f.current?.disconnect(),u.current=!0},[]);let y=H(e=>(s.add(e),()=>{s.delete(e)})),b=W.useMemo(()=>({register:m,unregister:h,subscribeMapChange:y,nextIndexRef:l}),[m,h,y,l]);return(0,U.jsx)(Ry.Provider,{value:b,children:t})}function xb(){return new Map}function Sb(){return new Set}function Cb(e){let t=new Set,n=[],r=[];e.forEach((e,i)=>{if(!i.isConnected)return;let a=e.index,o={index:a??-1,element:i,registration:e};a===null?r.push(o):a>=0&&(t.add(a),n.push(o))});let i=0;return r.sort((e,t)=>Eb(e.element,t.element)),r.forEach(e=>{for(;t.has(i);)i+=1;e.index=i,n.push(e),i+=1}),t.size>0&&n.sort((e,t)=>e.index-t.index),[n,r.map(e=>e.element)]}function wb(e,t){let n=e.parentElement;for(;n&&!n.contains(t);)n=n.parentElement;return n}function Tb(e){for(let t of e)for(let e=0;e<t.removedNodes.length;e+=1)if(t.removedNodes[e].isConnected)return!0;return!1}function Eb(e,t){return e.nextElementSibling===t?-1:t.nextElementSibling===e?1:e.compareDocumentPosition(t)&Node.DOCUMENT_POSITION_FOLLOWING?-1:1}var Db=W.forwardRef(function(e,t){let{anchor:n,positionMethod:r=`absolute`,className:i,render:a,side:o,align:s,sideOffset:c=0,alignOffset:l=0,collisionBoundary:d=`clipping-ancestors`,collisionPadding:f=5,arrowPadding:p=5,sticky:m=!1,disableAnchorTracking:h=!1,collisionAvoidance:g=lt,style:_,...v}=e,{store:y,virtualFocus:b,syncHighlightedItem:x}=wy(),C=vb(),ee=Ey(!0),w=y.useState(`parent`),T=y.useState(`floatingRootContext`),E=y.useState(`floatingTreeRoot`),D=y.useState(`mounted`),O=y.useState(`open`),k=y.useState(`modal`),A=y.useState(`openMethod`),j=y.useState(`activeTriggerElement`),M=y.useState(`transitionStatus`),N=y.useState(`positionerElement`),te=y.useState(`instantType`),ne=y.useState(`adaptiveOrigin`),re=y.useState(`lastOpenChangeReason`),P=y.useState(`floatingNodeId`),ie=y.useState(`floatingParentNodeId`),ae=T.useState(`domReferenceElement`),F=n,oe=c,se=l,I=s,L=g;w.type===`context-menu`&&(F=n??w.context?.anchor,I??=`start`,!o&&I!==`center`&&(se=e.alignOffset??2,oe=e.sideOffset??-5));let ce=o,R=I;w.type===`menu`?(ce??=`inline-end`,R??=`start`,L=e.collisionAvoidance??Pt):w.type===`menubar`&&(ce??=w.context.orientation===`vertical`?`inline-end`:`bottom`,R??=`start`);let le=w.type===`context-menu`,ue=u({anchor:F,floatingRootContext:T,positionMethod:ee?`fixed`:r,mounted:D,side:ce,sideOffset:oe,align:R,alignOffset:se,arrowPadding:le?0:p,collisionBoundary:d,collisionPadding:f,sticky:m,nodeId:P,keepMounted:C,disableAnchorTracking:h,collisionAvoidance:L,shift:le?{crossAxis:!(`side`in L&&L.side===`flip`),rootBoundary:`layoutViewport`}:void 0,externalTree:E,adaptiveOrigin:ne,lazyFlip:b?`placement`:!1});W.useEffect(()=>{function e(e){e.open&&(e.parentNodeId===P&&y.set(`hoverEnabled`,!1),e.nodeId!==P&&e.parentNodeId===y.select(`floatingParentNodeId`)&&y.setOpen(!1,S(Re)))}return E.events.on(`menuopenchange`,e),()=>{E.events.off(`menuopenchange`,e)}},[y,E.events,P]),W.useEffect(()=>{if(y.select(`floatingParentNodeId`)==null)return;function e(e){if(e.open||e.nodeId!==y.select(`floatingParentNodeId`))return;let t=e.reason??`sibling-open`;y.setOpen(!1,S(t))}return E.events.on(`menuopenchange`,e),()=>{E.events.off(`menuopenchange`,e)}},[E.events,y]);let z=qt();W.useEffect(()=>{O||z.clear()},[O,z]),W.useEffect(()=>{function e(e){if(!(!O||e.nodeId!==y.select(`floatingParentNodeId`))){if(e.target&&j&&j!==e.target){let e=y.select(`closeDelay`);e>0?z.isStarted()||z.start(e,()=>{y.setOpen(!1,S(Re))}):y.setOpen(!1,S(Re))}else z.clear()}}return E.events.on(`itemhover`,e),()=>{E.events.off(`itemhover`,e)}},[E.events,O,j,y,z]),W.useEffect(()=>{let e={open:O,nodeId:P,parentNodeId:ie,reason:y.select(`lastOpenChangeReason`)};E.events.emit(`menuopenchange`,e)},[E.events,O,y,P,ie]),zt({store:y,domReference:ae,positionerElement:N,open:O});let de={open:O,side:ue.side,align:ue.align,anchorHidden:ue.anchorHidden,nested:w.type===`menu`,instant:te},fe=w.type===`menubar`&&w.context.modal;Ht(O&&(fe||k&&re!==`trigger-hover`),A===`touch`,N,j);let me=Le(e,de,{styles:ue.positionerStyles,transitionStatus:M,props:v,refs:[t,y.useStateSetter(`positionerElement`)],hidden:!D,inert:!O}),ge=D&&w.type!==`menu`&&(w.type!==`menubar`&&k&&re!==`trigger-hover`||w.type===`menubar`&&w.context.modal),B=null;return w.type===`menubar`?B=w.context.contentElement:w.type===void 0&&(B=j),(0,U.jsxs)(xy.Provider,{value:ue,children:[ge&&(0,U.jsx)(pe,{ref:w.type===`context-menu`||w.type===`nested-context-menu`?w.context.internalBackdropRef:null,inert:he(!O),cutout:B}),(0,U.jsx)(Nt,{id:P,children:(0,U.jsx)(bb,{elementsRef:y.context.itemDomElements,labelsRef:y.context.itemLabels,onMapChange:x,children:me})})]})}),Ob=W.createContext(null);function kb(e){let t=W.useContext(Ob);if(t===null&&!e)throw Error(Kt(5));return t}function Ab(e){return e==null?Me:e.type.startsWith(`key`)?Qe:e.type.startsWith(`mouse`)||e.type.startsWith(`pointer`)?Ut:Me}var jb={...ce,disabled:e=>e.parent.type===`menubar`&&e.parent.context.disabled||e.disabled,modal:e=>(e.parent.type===void 0||e.parent.type===`context-menu`)&&(e.modal??!0),openMethod:e=>e.openMethod,keyboardOpen:e=>e.keyboardOpen,allowMouseEnter:e=>e.allowMouseEnter,highlightItemOnHover:e=>e.highlightItemOnHover,parent:e=>e.parent,rootId:e=>e.parent.type===`menu`?e.parent.store.select(`rootId`):e.parent.type===void 0?e.rootId:e.parent.context.rootId,activeIndex:e=>e.activeIndex,listElement:e=>e.listElement,triggerControlsId:(e,t)=>{let n=ce.triggerPopupId(e,t);return n?e.listElement?.id||n:void 0},filterTriggerProps:e=>e.filterTriggerProps,inputProps:e=>e.inputProps,webkitAriaSelected:(e,t)=>De&&e.inputFocused&&t?!0:void 0,highlightedItemId:e=>e.highlightedItem?.id||void 0,isActive:(e,t)=>e.activeIndex===t,hoverEnabled:e=>e.hoverEnabled,instantType:e=>e.instantType===`trigger-change`&&!ce.open(e)?void 0:e.instantType,lastOpenChangeReason:e=>e.openChangeReason,floatingTreeRoot:e=>e.parent.type===`menu`?e.parent.store.select(`floatingTreeRoot`):e.floatingTreeRoot,floatingNodeId:e=>e.floatingNodeId,floatingParentNodeId:e=>e.floatingParentNodeId,itemProps:e=>e.itemProps,closeDelay:e=>e.closeDelay,adaptiveOrigin:e=>e.adaptiveOrigin,keyboardEventRelay:e=>{if(e.keyboardEventRelay)return e.keyboardEventRelay;if(e.parent.type===`menu`)return e.parent.store.select(`keyboardEventRelay`)}},Mb=class extends _{constructor(e,t,n=!1){let r=new Gt,i=Pb(r,t,n,e);super(i,Nb(r),jb),this.observe(`parent`,e=>{e.type===`menu`?this.context.allowMouseUpTriggerRef=e.store.context.allowMouseUpTriggerRef:e.type!==void 0&&(this.context.allowMouseUpTriggerRef=e.context.allowMouseUpTriggerRef)})}subscribeToParentMenu(){let e=this.state.parent;if(e.type!==`menu`)return;let t=e.store.select(`rootId`),n=e.store.select(`floatingTreeRoot`),r=e.store.select(`keyboardEventRelay`);return e.store.subscribe(()=>{let i=e.store.select(`rootId`),a=e.store.select(`floatingTreeRoot`),o=e.store.select(`keyboardEventRelay`);(t!==i||n!==a||r!==o)&&(t=i,n=a,r=o,this.notifyAll())})}setOpen(e,t){this.state.floatingRootContext.context.events.emit(`setOpen`,{open:e,eventDetails:t})}setActiveIndex(e,t,n){if(this.state.activeIndex!==e){let r=(e===null?void 0:this.context.itemDomElements.current[e])===this.context.reportedItem;this.context.highlightReason=r?`none`:t,this.context.highlightEvent=r?void 0:n}this.set(`activeIndex`,e)}highlightItem(e,t,n){let r=this.context.itemDomElements.current.indexOf(e);r>-1&&this.setActiveIndex(r,t,n)}};function Nb(e){return{positionerRef:W.createRef(),popupRef:W.createRef(),typingRef:{current:!1},itemDomElements:{current:[]},itemLabels:{current:[]},highlightReason:`none`,highlightEvent:void 0,reportedItem:void 0,allowMouseUpTriggerRef:{current:!1},virtualFocusRef:void 0,triggerFocusTargetRef:W.createRef(),beforeTriggerFocusGuardRef:W.createRef(),beforeContentFocusGuardRef:W.createRef(),onOpenChangeComplete:void 0,triggerElements:e}}function Pb(e,t,n=!1,r){return{...oe(e,t,n),disabled:!1,modal:!0,openMethod:null,keyboardOpen:!1,allowMouseEnter:!1,highlightItemOnHover:!0,parent:{type:void 0},rootId:void 0,activeIndex:null,listElement:null,filterTriggerProps:v,inputProps:v,inputFocused:!1,highlightedItem:void 0,hoverEnabled:!0,instantType:void 0,openChangeReason:null,floatingTreeRoot:new gt,floatingNodeId:void 0,floatingParentNodeId:null,itemProps:v,keyboardEventRelay:void 0,closeDelay:0,adaptiveOrigin:void 0,...r}}var Fb=W.createContext(null);function Ib(e,t){return(e===`trigger-press`||e===`item-press`)&&t?.detail===0}function Lb(e,t){return e===`list-navigation`||Ib(e,t)}var Rb=T(function(e){let{children:t,open:n,onOpenChange:r,onOpenChangeComplete:i,onItemHighlighted:a,defaultOpen:o=!1,disabled:s=!1,modal:l,loopFocus:u=!0,orientation:d=`vertical`,actionsRef:f,closeParentOnEsc:p=!1,handle:m,triggerId:h,defaultTriggerId:g=null,highlightItemOnHover:_=!0,isSubmenu:y=!1,virtualFocus:x=!1,virtualFocusRef:ee,allowEscape:w=!0,resetOnPointerLeave:T=!0}=e,E=Ey(!0),D=wy(!0),O=kb(!0),k=D?.store,A=D?.virtualFocus??!1,M=W.useMemo(()=>y&&k?{type:`menu`,store:k}:O?{type:`menubar`,context:O}:E&&!k?{type:`context-menu`,context:E}:{type:void 0},[E,k,O,y]),N=wt(),ne=wt(),[re,P]=W.useState(void 0),ie=(re??ne)||void 0,F=nt(),oe=M.type===`menu`?M.store:void 0,se=(n??o)&&oe?.state.transitionStatus===`starting`,I=fe(()=>se?oe?.state.instantType:void 0).current,L=fe(()=>{let e=new Mb({open:o,openProp:n,activeTriggerId:g,triggerIdProp:h,parent:M,disabled:s,highlightItemOnHover:_,modal:M.type===void 0?l:void 0,rootId:N,instantType:I},ie,F!=null);return e.context.virtualFocusRef=ee,e}).current;L.useControlledProp(`openProp`,n),L.useControlledProp(`triggerIdProp`,h),L.useContextCallback(`onOpenChangeComplete`,i);let ce=L.useState(`floatingTreeRoot`),le=Dt(ce),z=L.useState(`open`),de=L.useState(`activeTriggerElement`),pe=L.useState(`positionerElement`),me=L.useState(`hoverEnabled`),he=L.useState(`disabled`),ge=L.useState(`lastOpenChangeReason`),B=L.useState(`parent`),_e=L.useState(`activeIndex`),xe=L.useState(`keyboardOpen`),Se=L.useState(`payload`),Ce=L.useState(`floatingParentNodeId`),we=W.useRef(null),Te=W.useRef(B.type!==`context-menu`),Ee=qt(),V=W.useRef(!0),De=qt(),ke=Ce!=null,{openMethod:Ae,triggerProps:Ne}=je(z);L.useSyncedValues({disabled:s,highlightItemOnHover:_,modal:B.type===void 0?l:void 0,openMethod:Ae,rootId:N}),b(L);let{forceUnmount:Pe,transitionStatus:Fe}=j(z,L,()=>{L.set(`allowMouseEnter`,!1)},se),Ie=ye(L.context.popupRef);W.useEffect(()=>{if(I===void 0)return;let e=()=>{L.state.instantType===I&&L.set(`instantType`,void 0)};if(!z){e();return}if(Fe!==void 0)return;if(L.context.popupRef.current==null){e();return}let t=new AbortController;return Ie(e,t.signal),()=>{t.abort()}},[I,z,Fe,Ie,L]),jt(()=>{E&&!D?L.update({parent:{type:`context-menu`,context:E},floatingNodeId:le,floatingParentNodeId:F}):(D||!L.select(`activeTriggerElement`))&&L.update({floatingNodeId:le,floatingParentNodeId:F})},[E,D,le,F,de,L]),W.useEffect(()=>{if(z||(we.current=null),B.type===`context-menu`){if(!z){Ee.clear(),Te.current=!1;return}Ee.start(500,()=>{Te.current=!0})}},[Ee,z,B.type]),jt(()=>{!z&&!me&&L.set(`hoverEnabled`,!0)},[z,me,L]);let Le=H((e,t)=>{let n=t.reason;if(!e&&!L.select(`open`)||z===e&&t.trigger===de&&ge===n)return;let i=C(t);if(!e&&t.trigger==null&&(t.trigger=de??void 0),r?.(e,t),t.isCanceled)return;L.state.floatingRootContext.dispatchOpenChange(e,t);let a=t.event;if(e===!1&&n!==`item-press`&&a?.type===`click`&&a.pointerType===`touch`&&!V.current)return;e&&n===`trigger-focus`?(V.current=!1,De.start(300,()=>{V.current=!0})):(V.current=!0,De.clear());let o=!e&&(n===`escape-key`||n==null);we.current=t.event;let s=be(L.state,e,t.trigger,i());s.openChangeReason=n,s.keyboardOpen=e&&Lb(n,a),s.instantType=B.type===`menubar`&&(n===`trigger-focus`||n===`focus-out`||n===`trigger-hover`||n===`list-navigation`||n===`sibling-open`)?`group`:Ib(n,a)?`click`:o?`dismiss`:void 0,L.update(s)}),Re=Oe({popupStore:L,floatingRootContext:L.state.floatingRootContext,floatingId:ie,nested:F!=null,onOpenChange:Le}),ze=Re.context.events;jt(()=>{let e=({open:e,eventDetails:t})=>Le(e,t);return ze.on(`setOpen`,e),()=>{ze?.off(`setOpen`,e)}},[ze,Le]),jt(()=>L.subscribeToParentMenu(),[L]);let Be=W.useCallback(()=>{L.setOpen(!1,S(yt))},[L]);W.useImperativeHandle(f,()=>({unmount:Pe,close:Be}),[Pe,Be]);let Ve;B.type===`context-menu`&&(Ve=B.context),W.useImperativeHandle(Ve?.positionerRef,()=>pe,[pe]),W.useImperativeHandle(Ve?.actionsRef,()=>({setOpen:Le}),[Le]);let He=ue(Re,{enabled:!he,bubbles:{escapeKey:p&&B.type===`menu`},outsidePress(){return B.type!==`context-menu`||we.current?.type===`contextmenu`||Te.current},externalTree:ke?ce:void 0}),Ue=It(),We=ob(Re,{enabled:!he,listRef:L.context.itemDomElements,activeIndex:_e,virtual:x,nested:B.type===`menubar`||!x&&B.type!==void 0,parentOrientation:B.type===`menubar`?B.context.orientation:void 0,loopFocus:u,focusItemOnOpen:x?xe:void 0,allowEscape:x&&u&&w,orientation:d,triggerOrientation:x?`vertical`:d,rtl:Ue===`rtl`,disabledIndices:R,onNavigate(e,t){L.setActiveIndex(e,Ab(t),t?.nativeEvent)},openOnArrowKeyDown:B.type!==`context-menu`&&!(x&&y),externalTree:!x&&ke?ce:void 0,nestedReturnFocusRef:oe?.context.virtualFocusRef,focusItemOnHover:_,resetOnPointerLeave:T}),Ge=W.useCallback(e=>{L.context.typingRef.current=e},[L]),Ke=sb(Re,{enabled:!he&&!x,listRef:L.context.itemLabels,elementsRef:L.context.itemDomElements,activeIndex:_e,resetMs:500,onMatch:(e,t)=>{z&&e!==_e&&L.setActiveIndex(e,Qe,t.nativeEvent)},onTyping:Ge}),qe=H(a),Je=W.useRef(-1),Ye=H(()=>{let e=L.state.activeIndex,t=e===null?void 0:L.context.itemDomElements.current[e]??void 0;if(t?.isConnected===!1)return;let n=t===void 0?-1:e;if(Je.current===n&&L.context.reportedItem===t)return;Je.current=n,L.context.reportedItem=t,x&&L.set(`highlightedItem`,t);let{highlightReason:r,highlightEvent:i}=L.context;L.context.highlightReason=Me,L.context.highlightEvent=void 0,a&&qe(t,te(r,i,{label:t===void 0?void 0:L.context.itemLabels.current[n]??void 0}))});jt(()=>{Ye()},[_e,Ye]);let Xe=W.useMemo(()=>{if(!x)return We.reference;if(!We.trigger)return v;let{onFocus:e,...t}=We.trigger;return t},[x,We.reference,We.trigger]);L.useSyncedValue(`inputProps`,x?We.reference??v:v);let Ze=W.useMemo(()=>{let e=ae(Ke.reference,Xe,He.reference,{onMouseMove(){L.set(`allowMouseEnter`,!0)}},Ne);return e[`aria-haspopup`]=`menu`,e[`aria-expanded`]=z,e},[L,Ke.reference,Xe,He.reference,Ne,z]),$e=W.useMemo(()=>{let e=ae(We.trigger,He.trigger,Ne);return e[`aria-haspopup`]=`menu`,e[`aria-expanded`]=!1,e},[We.trigger,He.trigger,Ne]);fe(()=>(L.update({inactiveTriggerProps:$e}),null));let et=W.useMemo(()=>ae(c,{onMouseMove(){L.set(`allowMouseEnter`,!0),B.type===`menu`&&L.set(`hoverEnabled`,!1)},onClick(){L.select(`hoverEnabled`)&&L.set(`hoverEnabled`,!1)},onKeyDown(e){let t=L.select(`keyboardEventRelay`);t&&!e.isPropagationStopped()&&t(e)}},Ke.floating,We.floating,He.floating),[B.type,L,Ke.floating,We.floating,He.floating]),tt=We.item??v;xt(L,{floatingRootContext:Re,activeTriggerProps:Ze,inactiveTriggerProps:$e,popupProps:et,itemProps:tt});let rt=W.useMemo(()=>({store:L,parent:M,orientation:d,loopFocus:u,allowEscape:w,defaultFloatingId:ne,setRenderedFloatingId:P,virtualFocus:x,parentVirtualFocus:A,syncHighlightedItem:Ye}),[L,M,d,u,w,ne,x,A,Ye]),it=typeof t==`function`?t({payload:Se}):t,at=(0,U.jsxs)(Cy.Provider,{value:rt,children:[m&&(0,U.jsx)(ve,{handle:m,store:L}),it]});return(B.type===void 0||B.type===`context-menu`)&&(at=(0,U.jsx)(pt,{externalTree:ce,children:at})),at});function zb(e){let t=W.useContext(Fb);if(t===null)return(0,U.jsx)(Rb,{...e});let n=t.Root;return(0,U.jsx)(Fb.Provider,{value:null,children:(0,U.jsx)(n,{...t.options,...e})})}var Bb=5;function Vb(e,t){let n=Hb(t);return e.clientX>=n.left-Bb&&e.clientX<=n.right+Bb&&e.clientY>=n.top-Bb&&e.clientY<=n.bottom+Bb}function Hb(e){let t=e.getBoundingClientRect(),n=et(e);if(A)return t;let r=n.getComputedStyle(e,`::before`),i=n.getComputedStyle(e,`::after`);if(r.content===`none`&&i.content===`none`)return t;let a=parseFloat(r.width)||0,o=parseFloat(r.height)||0,s=parseFloat(i.width)||0,c=parseFloat(i.height)||0,l=Math.max(t.width,a,s),u=Math.max(t.height,o,c),d=l-t.width,f=u-t.height;return{left:t.left-d/2,right:t.right+d/2,top:t.top-f/2,bottom:t.bottom+f/2}}function Ub(e={}){let{highlightItemOnHover:t,highlightedIndex:n,onHighlightedIndexChange:r}=Ue(),{ref:i,index:a}=By(e),o=n===a,s=W.useRef(null),c=re(i,s);return{compositeProps:{tabIndex:o?0:-1,onFocus(){r(a)},onMouseMove(){let e=s.current;if(!t||!e)return;let n=e.hasAttribute(`disabled`)||e.ariaDisabled===`true`;!o&&!n&&e.focus()}},compositeRef:c,index:a}}function Wb(e){let{render:t,className:n,style:r,state:i=v,props:a=R,refs:o=R,metadata:s,stateAttributesMapping:c,tag:l=`div`,...u}=e,{compositeProps:d,compositeRef:f}=Ub({metadata:s});return it(l,e,{state:i,ref:[f,...o],props:[d,...a,u],stateAttributesMapping:c})}function Gb(e){if(mt(e)&&e.hasAttribute(`data-rootownerid`))return e.getAttribute(`data-rootownerid`);if(!Ot(e))return Gb(Tt(e))}function Kb(e){let{enabled:t=!0,mouseDownAction:n,open:r}=e,a=W.useRef(!1);return W.useMemo(()=>t?{onMouseDown:e=>{(n===`open`&&!r||n===`close`&&r)&&(a.current=!0,i(e.currentTarget).addEventListener(`click`,()=>{a.current=!1},{once:!0}))},onClick:e=>{a.current&&(a.current=!1,e.preventBaseUIHandler())}}:v,[t,n,r])}var qb=ne(function(e,t){let{render:r,className:o,style:s,disabled:c=!1,nativeButton:l=!0,id:u,openOnHover:d,delay:f=100,closeDelay:p=0,handle:m,payload:h,...g}=e,_=wy(!0),y=ie(m)??_?.store;if(!y)throw Error(Kt(85));let b=wt(u),x=y.useState(`isTriggerActive`,b),S=y.useState(`floatingRootContext`),C=y.useState(`isOpenedByTrigger`,b),ee=y.useState(`triggerControlsId`,b),w=W.useRef(null),T=Yb(),E=Ue(!0),D=Ie(),O=W.useMemo(()=>D??new gt,[D]),k=Dt(O),A=nt(),{registerTrigger:j,isMountedByThisTrigger:M}=Ce(b,w,y,{payload:h,closeDelay:p,parent:T,floatingTreeRoot:O,floatingNodeId:k,floatingParentNodeId:A,keyboardEventRelay:E?.relayKeyboardEvent}),N=T.type===`menubar`,te=y.useState(`disabled`),ne=c||te||N&&T.context.disabled,{getButtonProps:re,buttonRef:P}=Ae({disabled:ne,native:l});W.useEffect(()=>{!C&&T.type===void 0&&(y.context.allowMouseUpTriggerRef.current=!1)},[y,C,T.type]);let F=W.useRef(null),oe=qt(),I=H(e=>{if(!F.current)return;oe.clear(),y.context.allowMouseUpTriggerRef.current=!1;let t=e.target;se(F.current,t)||se(y.select(`positionerElement`),t)||t===F.current||(t==null||Gb(t)!==y.select(`rootId`))&&(Vb(e,F.current)||O.events.emit(`close`,{domEvent:e,reason:ct}))});W.useEffect(()=>{let e=i(F.current);if(C&&y.select(`lastOpenChangeReason`)===`trigger-hover`)return e.addEventListener(`mouseup`,I,{once:!0}),()=>{e.removeEventListener(`mouseup`,I)}},[C,I,y]);let L=N&&T.context.hasSubmenuOpen,ce=a(S,{enabled:(d??L)&&!ne&&(!N||L&&!M),handleClose:ot({blockPointerEvents:!N}),mouseOnly:!0,move:!1,restMs:T.type===void 0?f:void 0,delay:{close:p},triggerElementRef:w,externalTree:O,isActiveTrigger:x,isClosing:()=>y.select(`transitionStatus`)===`ending`}),R=Jb(C,y.select(`lastOpenChangeReason`)),le=n(S,{enabled:!ne,event:C&&N?`click`:`mousedown`,toggle:!0,ignoreMouse:!1,stickIfOpen:T.type===void 0&&R}),ue=$y(S,{enabled:!ne&&L}),z=Kb({open:C,enabled:N,mouseDownAction:`open`}),de=W.useMemo(()=>ae(ue.reference,le.reference),[ue.reference,le.reference]),fe=y.useState(`triggerProps`,M),pe=y.useState(`filterTriggerProps`),{handlePreFocusGuardFocus:me,handleFocusTargetFocus:he}=Je(y,w),B={disabled:ne,open:C},_e=[F,t,P,j,w],ve=[de,ce??v,fe,{"aria-haspopup":`menu`,"aria-controls":ee,id:b,onMouseDown:e=>{y.select(`open`)||(oe.start(200,()=>{y.context.allowMouseUpTriggerRef.current=!0}),i(e.currentTarget).addEventListener(`mouseup`,I,{once:!0}))}},pe,N?{role:`menuitem`}:{},z,g,re],ye=it(`button`,e,{enabled:!N,stateAttributesMapping:ge,state:B,ref:_e,props:ve});return N?(0,U.jsx)(Wb,{tag:`button`,render:r,className:o,style:s,state:B,refs:_e,props:ve,stateAttributesMapping:ge}):C?(0,U.jsxs)(W.Fragment,{children:[(0,U.jsx)(Wt,{ref:y.context.beforeTriggerFocusGuardRef,onFocus:me},`${b}-pre-focus-guard`),(0,U.jsx)(W.Fragment,{children:ye},b),(0,U.jsx)(Wt,{ref:y.context.triggerFocusTargetRef,onFocus:he},`${b}-post-focus-guard`)]}):(0,U.jsx)(W.Fragment,{children:ye},b)});function Jb(e,t){let n=qt(),[r,i]=W.useState(!1);return jt(()=>{e&&t===`trigger-hover`?(i(!0),n.start(500,()=>{i(!1)})):e||(n.clear(),i(!1))},[e,t,n]),r}function Yb(){let e=kb(!0);return W.useMemo(()=>e?{type:`menubar`,context:e}:{type:void 0},[e])}var Xb=W.forwardRef(function(e,t){let{className:n,render:r,orientation:i=`horizontal`,style:a,...o}=e;return it(`div`,e,{state:{orientation:i},ref:t,props:[{role:`separator`,"aria-orientation":i},o]})}),Zb=(0,W.createContext)(null);function Qb({actionsRef:e,children:t,interactionOwner:n=`local`,onOpenChange:r,...i}){let a=(0,W.useRef)(null),o=e??a;return _t(()=>o.current?.close()),(0,U.jsx)(Zb.Provider,{value:{actionsRef:o,interactionOwner:n},children:(0,U.jsx)(zb,{...i,actionsRef:o,onOpenChange:(e,t)=>{if(n===`host`&&!e&&t.reason===`escape-key`){t.cancel(),t.allowPropagation();return}r?.(e,t)},children:t})})}function $b(){let e=(0,W.useContext)(Zb);if(!e)throw Error(`DropdownMenu parts must be used inside <DropdownMenu>`);return e}var ex=(0,W.forwardRef)(function({className:e,render:t,type:n=`button`,...r},i){return(0,U.jsx)(qb,{...r,className:t=>N(`btn caps-dropdown-trigger`,Ct(e,t)),ref:i,render:t,type:n})}),tx=(0,W.forwardRef)(function({container:e,...t},n){let r=ut(`popover`);return e==null&&r===null?null:(0,U.jsx)(yb,{...t,container:e??r,ref:n})}),nx=(0,W.forwardRef)(function({collisionBoundary:e,...t},n){let r=ut(`popover`);return(0,U.jsx)(Db,{...t,collisionBoundary:e??(r&&r!==document.body?r:void 0),ref:n})}),rx=(0,W.forwardRef)(function({className:e,finalFocus:t,...n},r){let{interactionOwner:i}=$b(),a=(0,W.useRef)(null);(0,W.useImperativeHandle)(r,()=>a.current);let o=Ze(`.caps-dropdown-item[data-highlighted]`),s=(0,W.useCallback)(e=>{a.current=e,o(e)},[o]);return(0,U.jsx)(gb,{...n,className:t=>N(`caps-dropdown-popup min-w-40 rounded-box border border-base-300 bg-base-100 p-xs shadow-lg outline-none`,Ct(e,t)),finalFocus:i===`host`?!1:t??!0,ref:s})}),ix=(0,W.forwardRef)(function({align:e=`end`,alignOffset:t,children:n,container:r,keepMounted:i,side:a=`bottom`,sideOffset:o=4,...s},c){return(0,U.jsx)(tx,{container:r,keepMounted:i,children:(0,U.jsx)(nx,{align:e,alignOffset:t,side:a,sideOffset:o,children:(0,U.jsx)(rx,{...s,ref:c,children:n})})})}),ax=`caps-dropdown-item flex min-h-2xl w-full items-center gap-sm rounded-field px-md py-xs text-left text-sm outline-none transition-colors hover:bg-base-200 focus-visible:bg-base-200 aria-[current=page]:bg-base-200 aria-[current=page]:font-semibold disabled:cursor-not-allowed disabled:text-base-content/40 data-disabled:cursor-not-allowed data-disabled:text-base-content/40`,ox=(0,W.forwardRef)(function({className:e,onClick:t,onSelect:n,variant:r=`default`,...i},a){return(0,U.jsx)(Zy,{...i,className:t=>N(ax,r===`destructive`&&`text-error hover:bg-error hover:text-error-content focus-visible:bg-error focus-visible:text-error-content`,Ct(e,t)),onClick:e=>{t?.(e),e.defaultPrevented||n?.(e)},ref:a})}),sx=(0,W.forwardRef)(function({children:e,className:t,onClick:n,onSelect:r,...i},a){return(0,U.jsxs)(Gy,{...i,className:e=>N(ax,Ct(t,e)),onClick:e=>{n?.(e),e.defaultPrevented||r?.(e)},ref:a,children:[(0,U.jsx)(`span`,{className:`min-w-0 flex-1`,children:e}),(0,U.jsx)(Ky,{"aria-hidden":`true`,className:`shrink-0`,children:`✓`})]})}),cx=(0,W.forwardRef)(function({className:e,...t},n){return(0,U.jsx)(Xb,{...t,className:t=>N(`my-xs h-px bg-base-300`,Ct(e,t)),ref:n})});(0,W.forwardRef)(function({className:e,...t},n){return(0,U.jsx)(Yy,{...t,className:t=>N(`px-md pb-xs pt-sm text-xs font-semibold text-base-content/60`,Ct(e,t)),ref:n})});export{_m as $,g_ as A,xn as At,Ag as B,an as Bt,k_ as C,Sa as Ct,C_ as D,An as Dt,w_ as E,jn as Et,d_ as F,fn as Ft,Fh as G,Zt as Gt,jg as H,un as Ht,r_ as I,gn as It,Eh as J,jh as K,Qt as Kt,Lg as L,mn as Lt,m_ as M,yn as Mt,p_ as N,bn as Nt,x_ as O,On as Ot,f_ as P,_n as Pt,hm as Q,Rg as R,hn as Rt,A_ as S,mi as St,T_ as T,Un as Tt,Ng as U,ln as Ut,Mg as V,cn as Vt,kg as W,tn as Wt,wh as X,Th as Y,mm as Z,V_ as _,wp as _t,cx as a,em as at,L_ as b,vp as bt,_y as c,tm as ct,Z_ as d,Up as dt,um as et,J_ as f,Bp as ft,H_ as g,$ as gt,U_ as h,Op as ht,ox as i,nm as it,h_ as j,Cn as jt,v_ as k,wn as kt,hy as l,Jp as lt,W_ as m,kp as mt,sx as n,Xp as nt,ex as o,Qp as ot,Y_ as p,Ap as pt,Ah as q,$t as qt,ix as r,Yp as rt,yy as s,Zp as st,Qb as t,cm as tt,Q_ as u,$p as ut,z_ as v,xp as vt,O_ as w,G as wt,M_ as x,dc as xt,R_ as y,yp as yt,Ig as z,sn as zt};
|
|
1518
|
+
`}function zv(e,t){return Math.max(e.additionLines.length,e.deletionLines.length)>t}function Bv(e,t){return e.isPartial&&t&&(e.type===`change`||e.type===`rename-changed`)}function Vv(e,t){return e.lineNumber===t.lineNumber&&e.side===t.side&&e.metadata===t.metadata}function Hv(e,t){return e.slotName===t.slotName&&e.hunkIndex===t.hunkIndex&&e.lines===t.lines&&e.lineCountKnown===t.lineCountKnown&&e.type===t.type&&e.expandable?.chunked===t.expandable?.chunked&&e.expandable?.up===t.expandable?.up&&e.expandable?.down===t.expandable?.down}function Uv(e){return{theme:e?.theme,disableLineNumbers:e?.disableLineNumbers,overflow:e?.overflow,collapsed:e?.collapsed,disableFileHeader:e?.disableFileHeader,disableVirtualizationBuffers:e?.disableVirtualizationBuffers,stickyHeader:e?.stickyHeader,preferredHighlighter:e?.preferredHighlighter,useCSSClasses:e?.useCSSClasses,useTokenTransformer:V_(e),tokenizeMaxLineLength:e?.tokenizeMaxLineLength,tokenizeMaxLength:e?.tokenizeMaxLength,diffStyle:e?.diffStyle,diffIndicators:e?.diffIndicators,disableBackground:e?.disableBackground,hunkSeparators:typeof e?.hunkSeparators==`function`?`custom`:e?.hunkSeparators,expandUnchanged:e?.expandUnchanged,loadDiffFiles:e?.loadDiffFiles,collapsedContextThreshold:e?.collapsedContextThreshold,lineDiffType:e?.lineDiffType,maxLineDiffLength:e?.maxLineDiffLength,expansionLineCount:e?.expansionLineCount,headerRenderMode:e?.renderCustomHeader==null?`default`:`custom`}}function Wv(e){return e.isPartial&&(e.type===`change`||e.type===`rename-changed`||e.type===`rename-pure`)}var Gv=-1,Kv=class{options;workerManager;isContainerManaged;static LoadedCustomComponent=!0;__id=`file-diff:${++Gv}`;type=`file-diff`;fileContainer;spriteSVG;pre;codeUnified;codeDeletions;codeAdditions;bufferBefore;bufferAfter;themeCSSStyle;appliedThemeCSS;hasAdoptedThemeCSS=!1;unsafeCSSStyle;appliedUnsafeCSS;gutterUtilityContent;headerElement;headerPrefix;headerFilenameSuffix;headerMetadata;headerCustom;separatorCache=new Map;errorWrapper;placeHolder;hunksRenderer;resizeManager;scrollSyncManager;interactionManager;annotationCache=new Map;lineAnnotations=[];managersDirty=!1;deletionFile;additionFile;fileDiff;renderRange;pendingFiles;appliedPreAttributes;lastRenderedHeaderHTML;cachedHeaderHTML;lastRowCount;mounted=!1;enabled=!0;editor;refreshViewTimeout;lineStateRefreshPending=!1;deferredSelectedLines;deferredEditorActiveLine;constructor(e={theme:V},t,n=!1){this.options=e,this.workerManager=t,this.isContainerManaged=n,this.hunksRenderer=this.createHunksRenderer(e),this.resizeManager=new r_,this.scrollSyncManager=new hv,this.interactionManager=new Lg(`diff`,Rg(e,typeof e.hunkSeparators==`function`||(e.hunkSeparators??`line-info`)===`line-info`||e.hunkSeparators===`line-info-basic`?this.handleExpandHunk:void 0,this.getLineIndex)),this.workerManager?.subscribeToThemeChanges(this),this.enabled=!0}handleHighlightRender=()=>{this.rerender()};getHunksRendererOptions(e){return Uv(e)}createHunksRenderer(e){return new wv(this.getHunksRendererOptions(e),this.handleHighlightRender,this.workerManager)}getLineIndex=(e,t=`additions`)=>{let n=this.fileDiffCache;if(n==null)return;let r=n.hunks.at(-1),i,a;hunkIterator:for(let o of n.hunks){let n=t===`deletions`?o.deletionStart:o.additionStart,s=t===`deletions`?o.deletionCount:o.additionCount,c=x(n,s)+1,l=o.splitLineStart,u=o.unifiedLineStart;if(e<c){let t=c-e;i=Math.max(u-t,0),a=Math.max(l-t,0);break hunkIterator}if(e>=c+s){if(o===r){let t=e-(c+s);i=u+o.unifiedLineCount+t,a=l+o.splitLineCount+t;break hunkIterator}continue}for(let n of o.hunkContent)if(n.type===`context`){if(e<c+n.lines){let t=e-c;a=l+t,i=u+t;break hunkIterator}c+=n.lines,l+=n.lines,u+=n.lines}else{let r=t===`deletions`?n.deletions:n.additions;if(e<c+r){let r=e-c;i=u+(t===`additions`?n.deletions:0)+r,a=l+r;break hunkIterator}c+=r,l+=Math.max(n.deletions,n.additions),u+=n.deletions+n.additions}break hunkIterator}if(i!=null&&a!=null)return[i,a]};setOptions(e){e!=null&&(this.options=e,this.cachedHeaderHTML=void 0,this.hunksRenderer.setOptions(this.getHunksRendererOptions(e)),this.syncInteractionOptions())}syncInteractionOptions(){this.interactionManager.setOptions(Rg(this.options,typeof this.options.hunkSeparators==`function`||(this.options.hunkSeparators??`line-info`)===`line-info`||this.options.hunkSeparators===`line-info-basic`?this.handleExpandHunk:void 0,this.getLineIndex))}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&&!An(this.appliedThemeCSS.theme,this.options.theme??V)}getHoveredLine=()=>this.interactionManager.getHoveredLine();setLineAnnotations(e){this.lineAnnotations=e}canPartiallyRender(e,t,n){return!(e||t||n||typeof this.options.hunkSeparators==`function`)}setSelectedLines(e,t){this.lineStateRefreshPending?this.deferredSelectedLines=[e,t]:this.interactionManager.setSelection(e,t)}setEditorActiveLine(e,t){this.lineStateRefreshPending?this.deferredEditorActiveLine=[e,t]:this.interactionManager.setEditorActiveLine(e,{lineNumberOnly:t?.lineNumberOnly,side:t?.side??`additions`})}flushDeferredLineState(){let{deferredEditorActiveLine:e,deferredSelectedLines:t}=this;this.lineStateRefreshPending=!1,this.deferredEditorActiveLine=void 0,this.deferredSelectedLines=void 0,e!=null&&this.setEditorActiveLine(...e),t!=null&&this.interactionManager.setSelection(...t)}flushManagers(){if(!this.managersDirty||this.pre==null){this.managersDirty=!1;return}let{diffStyle:e=`split`,overflow:t=`scroll`}=this.options;this.interactionManager.setup(this.pre),this.resizeManager.setup(this.pre,{disableAnnotations:t===`wrap`,columnVariables:this.shouldApplyColumnVariables(t)?`apply`:`measure`}),t===`scroll`&&e===`split`?this.scrollSyncManager.setup(this.pre,this.codeDeletions,this.codeAdditions):this.scrollSyncManager.cleanUp(),this.managersDirty=!1}shouldApplyColumnVariables(e){return typeof this.options.hunkSeparators==`function`||e===`scroll`&&(this.lineAnnotations.length>0||this.pre?.hasAttribute(`data-has-merge-conflict`)===!0)}getCodeScrollLeft(){return Math.max(this.codeUnified?.scrollLeft??0,this.codeDeletions?.scrollLeft??0,this.codeAdditions?.scrollLeft??0)}setCodeScrollLeft(e){this.codeUnified!=null&&(this.codeUnified.scrollLeft=e),this.codeAdditions!=null&&(this.codeAdditions.scrollLeft=e),this.codeDeletions!=null&&(this.codeDeletions.scrollLeft=e)}__getEffectiveCodeOptions(){return{...this.options,...this.hunksRenderer.getEffectiveCodeOptions()}}cleanUp(e=!1){jh(this.handleEditSessionRender),this.emitPostRender(!0),this.editor?.cleanUp(e),this.editor=void 0,this.resizeManager.cleanUp(),this.interactionManager.cleanUp(),this.scrollSyncManager.cleanUp(),this.managersDirty=!1,this.workerManager?.unsubscribeToThemeChanges(this),this.renderRange=void 0,this.pendingFiles=void 0,this.isContainerManaged||this.fileContainer?.remove(),this.fileContainer=void 0,this.mounted=!1,e||(this.lineAnnotations=[]),this.clearAuxiliaryNodes(),this.annotationCache.clear(),this.pre=void 0,this.codeUnified=void 0,this.codeDeletions=void 0,this.codeAdditions=void 0,this.bufferBefore?.remove(),this.bufferBefore=void 0,this.bufferAfter?.remove(),this.bufferAfter=void 0,this.appliedPreAttributes=void 0,this.headerElement=void 0,this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0,this.headerCustom=void 0,this.placeHolder?.remove(),this.placeHolder=void 0,this.lastRenderedHeaderHTML=void 0,e||(this.cachedHeaderHTML=void 0),this.errorWrapper?.remove(),this.errorWrapper=void 0,this.spriteSVG=void 0,this.lastRowCount=void 0,this.themeCSSStyle=void 0,this.appliedThemeCSS=void 0,this.hasAdoptedThemeCSS=!1,this.unsafeCSSStyle=void 0,this.appliedUnsafeCSS=void 0,e?this.hunksRenderer.recycle():(this.hunksRenderer.cleanUp(),this.workerManager=void 0,this.fileDiff=void 0,this.deletionFile=void 0,this.additionFile=void 0),this.refreshViewTimeout!=null&&(clearTimeout(this.refreshViewTimeout),this.refreshViewTimeout=void 0),this.lineStateRefreshPending=!1,this.deferredEditorActiveLine=void 0,this.deferredSelectedLines=void 0,this.enabled=!1}virtualizedSetup(){this.enabled=!0,this.workerManager?.subscribeToThemeChanges(this)}hydrate({fileContainer:e,prerenderedHTML:t,preventEmit:n=!1,lineAnnotations:r,fileDiff:i,...a}){if(!this.enabled)throw Error(`FileDiff.hydrate: attempting to call hydrate after cleaned up`);if(this.fileContainer!=null)throw Error(`FileDiff.hydrate: hydrate can only be called before the instance has rendered or hydrated`);let o=rv(a,`FileDiff.hydrate`),s=o?.oldFile,c=o?.newFile;this.hydrateElements(e,t),Xv(this.pre,Jv({fileDiff:i,oldFile:s,newFile:c}),this.options.collapsed)||Zv(this.headerElement,Yv({fileDiff:i,oldFile:s,newFile:c}),this.options.disableFileHeader)?this.render({...a,fileContainer:e,lineAnnotations:r,fileDiff:i,preventEmit:!0}):this.hydrationSetup({fileDiff:i,lineAnnotations:r,...o}),n||this.emitPostRender()}hydrateElements(e,t){this.fileContainer!==e&&this.emitPostRender(!0),Z_(e,t);for(let t of e.shadowRoot?.children??[]){if(t instanceof SVGElement){this.spriteSVG=t;continue}if(t instanceof HTMLElement){if(t instanceof HTMLPreElement){this.pre=t;for(let e of t.children)!(e instanceof HTMLElement)||e.tagName.toLowerCase()!==`code`||(`deletions`in e.dataset&&(this.codeDeletions=e),`additions`in e.dataset&&(this.codeAdditions=e),`unified`in e.dataset&&(this.codeUnified=e));continue}if(`diffsHeader`in t.dataset){this.headerElement=t;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}}}this.pre!=null&&(this.syncCodeNodesFromPre(this.pre),this.pre.removeAttribute(`data-dehydrated`)),this.fileContainer=e,this.hydrateMeasuredScrollbar()}hydrationSetup({fileDiff:e,oldFile:t,newFile:n,lineAnnotations:r}){this.lineAnnotations=r??this.lineAnnotations,this.additionFile=n,this.deletionFile=t,this.fileDiff=e??(t!==void 0&&n!==void 0?Fh(t,n,this.options.parseDiffOptions):void 0),this.pre!=null&&(this.syncInteractionOptions(),this.hunksRenderer.hydrate(this.fileDiff),this.renderAnnotations(),this.renderGutterUtility(),this.injectUnsafeCSS(),this.managersDirty=!0,this.flushManagers())}rerender(){!this.enabled||this.fileDiff==null&&this.additionFile==null&&this.deletionFile==null||this.render({forceRender:!0,renderRange:this.renderRange})}onThemeChange(){this.hunksRenderer.clearRenderCache(),this.rerender()}handleExpandHunk=(e,t,n)=>{this.expandHunk(e,t,n)};expandHunk=(e,t,n)=>{this.hunksRenderer.expandHunk(e,t,n),this.loadFilesIfNecessary(),this.rerender()};loadFilesIfNecessary(){let{fileDiff:e,options:{loadDiffFiles:t}}=this;e==null||t==null||!Wv(e)||this.pendingFiles?.fileDiff===e||(this.pendingFiles={fileDiff:e,promise:this.loadFilesForDiff(e,t)})}async loadFilesForDiff(e,t){try{let n=await t(e);if(!this.enabled||this.fileDiff!==e)return;await this.handleFilesLoaded(e,n)}catch(e){if(this.options.disableErrorHandling===!0)throw e;console.error(e)}finally{this.pendingFiles?.fileDiff===e&&(this.pendingFiles=void 0)}}async handleFilesLoaded(e,t){this.fileDiff!==e||!e.isPartial||(ov(`merge`,e,t),this.setHydratedState(t),await $_(()=>this.primeHighlightCache(e)),!(!this.enabled||this.fileDiff!==e)&&this.rerender())}setHydratedState(e){this.deletionFile=e.oldFile,this.additionFile=e.newFile,this.workerManager?.cleanUpTasks(this.hunksRenderer),this.hunksRenderer.clearRenderCache()}render({fileDiff:e,deferManagers:t=!1,forceRender:n=!1,preventEmit:r=!1,lineAnnotations:i,fileContainer:a,containerWrapper:o,renderRange:s,...c}){let l=rv(c,`FileDiff.render`),u=l?.oldFile,d=l?.newFile;if(!this.enabled)throw Error(`FileDiff.render: attempting to call render after cleaned up`);e!=null&&e.cacheKey===void 0&&(e.cacheKey=e.prevName==null?e.name:e.prevName+`:`+e.name),this.editor?.__postponeBgTokenizeToNextFrame();let{collapsed:f=!1,themeType:p=`system`,expandUnchanged:m=!1}=this.options,h=f?void 0:s,g=this.hasThemeChanged(),_=l!=null,v=_&&(!qv(u,this.deletionFile)||!qv(d,this.additionFile)),y=e!=null&&e!==this.fileDiff,b=i!=null&&(i.length>0||this.lineAnnotations.length>0)&&i!==this.lineAnnotations;if(!f&&d_(h,this.renderRange)&&!n&&!b&&!g&&(e!=null&&e===this.fileDiff||e==null&&!v))return this.applyCachedThemeState(p);let x;e==null&&_&&(v||this.fileDiff==null)&&(x=Fh(l.oldFile,l.newFile,this.options.parseDiffOptions));let{renderRange:S}=this;if(this.renderRange=h,_?(this.deletionFile=u,this.additionFile=d):e!=null&&(this.deletionFile=void 0,this.additionFile=void 0),e==null?x!=null&&(y=!0,this.fileDiff=x):this.fileDiff=e,y&&(this.cachedHeaderHTML=void 0),i!=null&&this.setLineAnnotations(i),this.fileDiff==null)return!1;this.fileDiff.editSessionDirty===!0&&this.shouldSelfHealEditSession()&&(pg(this.fileDiff,this.options.parseDiffOptions),this.hunksRenderer.refreshHighlightedResult()),m&&this.loadFilesIfNecessary(),this.hunksRenderer.setOptions(this.getHunksRendererOptions(this.options)),this.syncInteractionOptions(),this.hunksRenderer.setLineAnnotations(this.lineAnnotations);let{disableErrorHandling:C=!1,disableFileHeader:ee=!1}=this.options;if(ee&&(this.headerElement!=null&&(this.headerElement.remove(),this.headerElement=void 0,this.lastRenderedHeaderHTML=void 0),this.clearHeaderSlots()),a=this.getOrCreateFileContainer(a,o),this.applyCachedThemeState(p),f){this.removeRenderedCode(),this.clearAuxiliaryNodes();try{let e=this.hunksRenderer.renderDiff(this.fileDiff,Mt);e!=null&&this.applyThemeState(a,e.themeStyles,p,e.baseThemeType),e?.headerElement!=null&&this.applyHeaderToDOM(e.headerElement,a),this.renderSeparators([]),this.injectUnsafeCSS()}catch(e){if(C)throw e;console.error(e),e instanceof Error&&this.applyErrorToDOM(e,a)}return r||this.emitPostRender(),!0}try{let e=this.getOrCreatePreNode(a);if(!(this.canPartiallyRender(n,b,v||y||g)&&this.applyPartialRender({previousRenderRange:S,renderRange:h}))){let t=this.hunksRenderer.renderDiff(this.fileDiff,h);if(t==null)return this.workerManager?.isInitialized()===!1&&this.workerManager.initialize().then(()=>this.rerender()),!1;this.applyThemeState(a,t.themeStyles,p,t.baseThemeType),t.headerElement!=null&&this.applyHeaderToDOM(t.headerElement,a),t.additionsContentAST!=null||t.deletionsContentAST!=null||t.unifiedContentAST!=null?this.applyHunksToDOM(e,t):this.pre!=null&&(this.pre.remove(),this.pre=void 0),this.renderSeparators(t.hunkData)}this.applyBuffers(e,h),this.injectUnsafeCSS(),this.renderAnnotations(),this.renderGutterUtility(),this.managersDirty=!0,t||this.flushManagers(),this.editor!=null&&this.syncRenderViewToEditor()}catch(e){if(C)throw e;console.error(e),e instanceof Error&&this.applyErrorToDOM(e,a)}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;this.options.onPostRender?.(t,this,`unmount`);return}if(t==null)return;let r=this.mounted?`update`:`mount`;this.mounted=!0,n?.(t,this,r)}get fileDiffCache(){return this.hunksRenderer.diffCache??this.fileDiff}syncRenderViewToEditor(){let e=this.editor,t=this.fileContainer,n=this.fileDiffCache,r=this.lineAnnotations,i=this.computeEditorRenderRange(this.renderRange);e!=null&&t!=null&&n!=null&&!n.isPartial&&this.hunksRenderer.initializeHighlighter().then(a=>{!this.enabled||this.editor!==e||this.fileContainer!==t||this.fileDiffCache!==n||e.__syncRenderView(a,t,n,r,i)})}computeEditorRenderRange(e){let t=this.fileDiffCache;if(e==null||t==null||gv(e))return e;let{diffStyle:n=`split`,expandUnchanged:r=!1,collapsedContextThreshold:i=1}=this.options,a,o;return Mm({diff:t,diffStyle:n,startingLine:e.startingLine,totalLines:e.totalLines,expandedHunks:r?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:i,callback:({additionLine:e})=>{e!=null&&(a??=e.lineNumber,o=e.lineNumber)}}),a==null||o==null?{...e,startingLine:0,totalLines:0}:{...e,startingLine:a-1,totalLines:o-a+1}}attachEditor(e){if(this.type!==`file-diff`)throw Error(`FileDiff.attachEditor: cannot attach an editor to a "${this.type}" diff`);return this.editor?.cleanUp(),this.editor=e,this.hunksRenderer.beginEditSession(),this.fileDiff?.isPartial===!0&&this.loadFilesIfNecessary(),this.hunksRenderer.editorRenderReady()?this.syncRenderViewToEditor():this.rerender(),e=>{this.editor=void 0,e!==!0&&this.finishEditSession()}}finishEditSession(){this.hunksRenderer.endEditSession(),this.completeEditSession()}completeEditSession(){let e=this.fileDiffCache;if(e==null||e.editSessionDirty!==!0)return!1;let{collapsedContextThreshold:t=1}=this.options,n=dg(e,this.hunksRenderer.getExpandedHunksMap(),t);return pg(e,this.options.parseDiffOptions),this.hunksRenderer.setExpandedHunksMap(fg(e,n)),this.hunksRenderer.refreshHighlightedResult(),this.escalateEditSessionRender(),!0}applyDocumentChange(e,t){this.hunksRenderer.applyDocumentChange(e);let n=this.hunksRenderer.diffCache;if(n!=null){let e=this.fileDiff?.cacheKey;e!=null&&n.cacheKey==null&&(n.cacheKey=e),this.fileDiff=n}t!==void 0&&t!==this.lineAnnotations&&(this.setLineAnnotations(t),this.hunksRenderer.setLineAnnotations(this.lineAnnotations),this.renderAnnotations()),this.rerender(),this.interactionManager.setSelectionDirty()}updateRenderCache(e,t,n={}){let{shouldRefreshDiffsView:r,lineCountChangeInFlight:i}=n;if(this.hunksRenderer.updateRenderCache(e,t,i)){this.refreshViewTimeout!=null&&(clearTimeout(this.refreshViewTimeout),this.refreshViewTimeout=void 0),this.lineStateRefreshPending=!0,this.escalateEditSessionRender();return}r===!0&&(this.refreshViewTimeout!=null&&clearTimeout(this.refreshViewTimeout),this.lineStateRefreshPending=!0,this.refreshViewTimeout=setTimeout(()=>{this.refreshViewTimeout=void 0,this.options.diffStyle===`split`?this.refreshSplitDiffView():this.refreshUnifiedDiffView(),this.flushDeferredLineState()},150))}isLineRenderable(e){let t=this.fileDiffCache;if(t==null)return!0;let{expandUnchanged:n=!1,collapsedContextThreshold:r=1}=this.options;return wm({fileDiff:t,lineNumber:e,expandedHunks:n?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:r})}getNearestRenderableLine(e,t){let n=this.fileDiffCache;if(n==null)return e;let{expandUnchanged:r=!1,collapsedContextThreshold:i=1}=this.options;return Tm({fileDiff:n,lineNumber:e,direction:t,expandedHunks:r?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:i})}revealLine(e){let t=this.fileDiffCache,{expandUnchanged:n=!1,collapsedContextThreshold:r=1,expansionLineCount:i=100}=this.options;if(t==null||t.isPartial||n)return!1;let a=this.hunksRenderer.getExpandedHunksMap();for(let[n,o]of t.hunks.entries()){let[s,c]=ym(o);if(e<s){let c=bm({isPartial:t.isPartial,rangeSize:o.collapsedBefore,expandedHunks:a,hunkIndex:n,collapsedContextThreshold:r}),l=s-c.rangeSize;if(c.renderAll||e<l+c.fromStart||e>=s-c.fromEnd)return!1;let u=e-(l+c.fromStart)+1,d=s-c.fromEnd-e;return u<=d?this.expandHunk(n,`up`,u+i):this.expandHunk(n,`down`,d+i),!0}if(e<c)return!1}let o=Cm({fileDiff:t,hunkIndex:t.hunks.length-1,expandedHunks:a,collapsedContextThreshold:r,errorPrefix:`FileDiff.revealLine`});if(o==null||o.renderAll)return!1;let s=t.hunks[t.hunks.length-1],[,c]=ym(s);return e<c+o.fromStart||e>=c+o.rangeSize?!1:(this.expandHunk(t.hunks.length,`up`,e-(c+o.fromStart)+1+i),!0)}shouldSelfHealEditSession(){return this.editor==null}escalateEditSessionRender(){Ah(this.handleEditSessionRender)}handleEditSessionRender=()=>{this.rerender(),this.flushDeferredLineState()};removeRenderedCode(){this.resizeManager.cleanUp(),this.scrollSyncManager.cleanUp(),this.interactionManager.cleanUp(),this.bufferBefore?.remove(),this.bufferBefore=void 0,this.bufferAfter?.remove(),this.bufferAfter=void 0,this.codeUnified?.remove(),this.codeUnified=void 0,this.codeDeletions?.remove(),this.codeDeletions=void 0,this.codeAdditions?.remove(),this.codeAdditions=void 0,this.pre?.remove(),this.pre=void 0,this.appliedPreAttributes=void 0,this.lastRowCount=void 0}clearAuxiliaryNodes(){for(let{element:e}of this.separatorCache.values())e.remove();this.separatorCache.clear();for(let{element:e}of this.annotationCache.values())e.remove();this.annotationCache.clear(),this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0}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.fileDiff){let{workerManager:t}=this;if(e==null||t==null||!t.isWorkingPool()||e.cacheKey==null||pm(e))return;let n=this.options.tokenizeMaxLength??1e5;Math.max(e.additionLines.length,e.deletionLines.length)>n||await t.primeDiffHighlightCache(e).catch(e=>{console.error(e)})}cleanChildNodes(){this.resizeManager.cleanUp(),this.scrollSyncManager.cleanUp(),this.interactionManager.cleanUp(),this.clearAuxiliaryNodes(),this.bufferAfter?.remove(),this.bufferBefore?.remove(),this.codeAdditions?.remove(),this.codeDeletions?.remove(),this.codeUnified?.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.codeAdditions=void 0,this.codeDeletions=void 0,this.codeUnified=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}renderSeparators(e){let{hunkSeparators:t}=this.options;if(this.isContainerManaged||this.fileContainer==null||typeof t!=`function`){for(let{element:e}of this.separatorCache.values())e.remove();this.separatorCache.clear();return}let n=new Map(this.separatorCache);for(let r of e){let e=r.slotName,i=this.separatorCache.get(e);if(i==null||!Hv(r,i.hunkData)){i?.element.remove();let n=document.createElement(`div`);n.style.display=`contents`,n.slot=r.slotName;let a=t(r,this);a!=null&&n.appendChild(a),this.fileContainer.appendChild(n),i={element:n,hunkData:r},this.separatorCache.set(e,i)}n.delete(e)}for(let[e,{element:t}]of n.entries())this.separatorCache.delete(e),t.remove()}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}-${wn(r)}`,a=this.annotationCache.get(i);if(a==null||!Vv(r,a.annotation)){a?.element.remove();let e=t(r);if(e==null)continue;a={element:O_(wn(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=k_();n.appendChild(t),this.fileContainer.appendChild(n),this.gutterUtilityContent=n}getOrCreateFileContainer(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:kg(e)&&e.hasAttribute(`data-theme-css`)?(this.themeCSSStyle??=e,this.hasAdoptedThemeCSS=!0):kg(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=w_;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.codeUnified=void 0,this.codeDeletions=void 0,this.codeAdditions=void 0,t.appendChild(this.pre)):this.pre.parentNode!==t&&(this.editor?.__captureFocusForDOMReplacement(),t.appendChild(this.pre),this.appliedPreAttributes=void 0),this.placeHolder?.remove(),this.placeHolder=void 0,this.pre}syncCodeNodesFromPre(e){this.codeUnified=void 0,this.codeDeletions=void 0,this.codeAdditions=void 0;for(let t of Array.from(e.children))t instanceof HTMLElement&&(t.hasAttribute(`data-unified`)?this.codeUnified=t:t.hasAttribute(`data-deletions`)?this.codeDeletions=t:t.hasAttribute(`data-additions`)&&(this.codeAdditions=t))}applyHeaderToDOM(e,t){this.cleanupErrorWrapper(),this.placeHolder?.remove(),this.placeHolder=void 0;let{fileDiff:n}=this,r=this.cachedHeaderHTML??dc(e);if(this.cachedHeaderHTML=r,r!==this.lastRenderedHeaderHTML){let e=document.createElement(`div`);e.innerHTML=r;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=r}if(this.isContainerManaged||n==null)return;let{renderCustomHeader:i,renderHeaderPrefix:a,renderHeaderFilenameSuffix:o,renderHeaderMetadata:s}=this.options;if(i!=null){let e=i(n)??void 0;this.headerCustom=this.upsertHeaderSlotElement(t,this.headerCustom,M,e),this.headerPrefix?.remove(),this.headerFilenameSuffix?.remove(),this.headerMetadata?.remove(),this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0;return}let c=a?.(n)??void 0,l=o?.(n)??void 0,u=s?.(n)??void 0;this.headerPrefix=this.upsertHeaderSlotElement(t,this.headerPrefix,Fe,c),this.headerFilenameSuffix=this.upsertHeaderSlotElement(t,this.headerFilenameSuffix,Et,l),this.headerMetadata=this.upsertHeaderSlotElement(t,this.headerMetadata,tt,u),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}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??=A_(),this.unsafeCSSStyle.parentNode!==t&&t.appendChild(this.unsafeCSSStyle),this.unsafeCSSStyle.textContent=L_(e),this.appliedUnsafeCSS=e)}}applyThemeState(e,t,n,r){let i=e.shadowRoot??e.attachShadow({mode:`open`}),a=r??n,o=this.options.theme??V,s=typeof o==`string`?o:{...o},c=M_(i);if(this.themeCSSStyle?.parentNode===i&&this.appliedThemeCSS?.themeStyles===t&&this.appliedThemeCSS.themeType===a&&this.appliedThemeCSS.scrollbarGutter===c){this.appliedThemeCSS.theme=s;return}if(this.hasAdoptedThemeCSS&&this.themeCSSStyle?.parentNode===i){this.hasAdoptedThemeCSS=!1,this.appliedThemeCSS={theme:s,themeStyles:t,themeType:a,baseThemeType:r,scrollbarGutter:c};return}this.themeCSSStyle=W_({shadowRoot:i,currentNode:this.themeCSSStyle,themeCSS:R_(t,a,c)}),this.appliedThemeCSS=this.themeCSSStyle==null?void 0:{theme:s,themeStyles:t,themeType:a,baseThemeType:r,scrollbarGutter:c}}hydrateMeasuredScrollbar(){let e=this.fileContainer?.shadowRoot;e!=null&&this.themeCSSStyle!=null&&(this.themeCSSStyle.textContent=z_(this.themeCSSStyle.textContent??``,M_(e)))}shouldGuardRebuildScroll(){return this.editor!=null&&Y_()}applyHunksToDOM(e,t){this.shouldGuardRebuildScroll()?U_(e,()=>this.replaceCodeColumns(e,t)):this.replaceCodeColumns(e,t)}applyCodeColumnsInPlace(e,t,n){let r=this.getColumnPair(e);if(r==null)return!1;let i=Qv(t[0]),a=Qv(t[1]);return i==null||a==null?!1:(r.gutter.innerHTML=dc(i),r.content.innerHTML=dc(a),n!==this.lastRowCount&&(r.gutter.style.setProperty(`grid-row`,`span ${n}`),r.content.style.setProperty(`grid-row`,`span ${n}`)),!0)}replaceCodeColumns(e,t){let{overflow:n=`scroll`}=this.options,r=(this.options.hunkSeparators??`line-info`)===`line-info`,i=n===`wrap`?t.rowCount:void 0;this.cleanupErrorWrapper(),this.applyPreNodeAttributes(e,t);let a=!1,o=[],s=this.hunksRenderer.renderCodeAST(`unified`,t),c=this.hunksRenderer.renderCodeAST(`deletions`,t),l=this.hunksRenderer.renderCodeAST(`additions`,t);this.editor?.__captureFocusForDOMReplacement(),s==null?c!=null||l!=null?(c==null?(this.codeDeletions?.remove(),this.codeDeletions=void 0):(a=this.codeDeletions==null||this.codeUnified!=null,this.codeUnified?.remove(),this.codeUnified=void 0,this.codeDeletions=H_({code:this.codeDeletions,columnType:`deletions`,rowSpan:i,containerSize:r}),this.applyCodeColumnsInPlace(this.codeDeletions,c,t.rowCount)||(this.codeDeletions.innerHTML=this.hunksRenderer.renderPartialHTML(c)),o.push(this.codeDeletions)),l==null?(this.codeAdditions?.remove(),this.codeAdditions=void 0):(a=a||this.codeAdditions==null||this.codeUnified!=null,this.codeUnified?.remove(),this.codeUnified=void 0,this.codeAdditions=H_({code:this.codeAdditions,columnType:`additions`,rowSpan:i,containerSize:r}),this.applyCodeColumnsInPlace(this.codeAdditions,l,t.rowCount)||(this.codeAdditions.innerHTML=this.hunksRenderer.renderPartialHTML(l)),o.push(this.codeAdditions))):(this.codeUnified?.remove(),this.codeUnified=void 0,this.codeDeletions?.remove(),this.codeDeletions=void 0,this.codeAdditions?.remove(),this.codeAdditions=void 0):(a=this.codeUnified==null||this.codeAdditions!=null||this.codeDeletions!=null,this.codeDeletions?.remove(),this.codeDeletions=void 0,this.codeAdditions?.remove(),this.codeAdditions=void 0,this.codeUnified=H_({code:this.codeUnified,columnType:`unified`,rowSpan:i,containerSize:r}),this.applyCodeColumnsInPlace(this.codeUnified,s,t.rowCount)||(this.codeUnified.innerHTML=this.hunksRenderer.renderPartialHTML(s)),o.push(this.codeUnified)),o.length===0?e.textContent=``:a&&e.replaceChildren(...o),this.lastRowCount=t.rowCount}applyPartialRender({previousRenderRange:e,renderRange:t}){let{pre:n,codeUnified:r,codeAdditions:i,codeDeletions:a,options:{diffStyle:o=`split`}}=this;if(n==null||e==null||t==null||!Number.isFinite(e.totalLines)||!Number.isFinite(t.totalLines)||this.lastRowCount==null)return!1;let s=this.getCodeColumns(o,r,a,i);if(s==null)return!1;let c=e.startingLine,l=t.startingLine,u=c+e.totalLines,d=l+t.totalLines,f=Math.max(c,l),p=Math.min(u,d);if(p<=f)return!1;let m=Math.max(0,f-c),h=Math.max(0,u-p),g=this.trimColumns({columns:s,trimStart:m,trimEnd:h,previousStart:c,overlapStart:f,overlapEnd:p,diffStyle:o});if(g<0)throw Error(`FileDiff.applyPartialRender: failed to trim to overlap`);if(this.lastRowCount<g)throw Error(`FileDiff.applyPartialRender: trimmed beyond DOM row count`);let _=this.lastRowCount-g,v=(e,t)=>{if(!(t<=0||this.fileDiff==null))return this.hunksRenderer.renderDiff(this.fileDiff,{startingLine:e,totalLines:t,bufferBefore:0,bufferAfter:0})},y=v(l,Math.max(f-l,0));if(y==null&&l<f)return!1;let b=v(p,Math.max(d-p,0));if(b==null&&d>p)return!1;let x=(e,t)=>{if(e!=null){if(o===`unified`&&!Array.isArray(s))this.insertPartialHTML(o,s,e,t);else if(o===`split`&&Array.isArray(s))this.insertPartialHTML(o,s,e,t);else throw Error(`FileDiff.applyPartialRender.applyChunk: invalid chunk application`);_+=e.rowCount}};return this.cleanupErrorWrapper(),x(y,`afterbegin`),x(b,`beforeend`),this.lastRowCount!==_&&(this.applyRowSpan(o,s,_),this.lastRowCount=_),!0}insertPartialHTML(e,t,n,r){if(e===`unified`&&!Array.isArray(t)){let e=this.hunksRenderer.renderCodeAST(`unified`,n);this.renderPartialColumn(t,e,r)}else if(e===`split`&&Array.isArray(t)){let e=this.hunksRenderer.renderCodeAST(`deletions`,n),i=this.hunksRenderer.renderCodeAST(`additions`,n);this.renderPartialColumn(t[0],e,r),this.renderPartialColumn(t[1],i,r)}else throw Error(`FileDiff.insertPartialHTML: Invalid argument composition`)}refreshSplitDiffView(){if(this.options.diffStyle!==`split`)return;let e=this.hunksRenderer.renderDiff(this.fileDiff,this.renderRange);if(e==null)return;let t=this.getCodeColumns(`split`,this.codeUnified,this.codeDeletions,this.codeAdditions);if(!Array.isArray(t))return;let n=(t,n)=>{if(n==null)return;let r=this.hunksRenderer.renderCodeAST(t,e),i=Qv(r?.[0]),a=Qv(r?.[1]);for(let[e,t]of[[n.gutter,i],[n.content,a]])if(t!=null&&e.childElementCount===t.length)for(let n=0;n<t.length;n++){let r=e.children[n],i=t[n].properties[`data-line-type`];i!=null&&r.dataset.lineType!==i&&(r.dataset.lineType=i)}};n(`deletions`,t[0]),n(`additions`,t[1])}refreshUnifiedDiffView(){if(this.options.diffStyle!==`unified`)return;let e=this.hunksRenderer.renderDiff(this.fileDiff,this.renderRange);if(e==null)return;let t=this.getCodeColumns(`unified`,this.codeUnified,this.codeDeletions,this.codeAdditions);if(t==null||Array.isArray(t))return;let n=this.hunksRenderer.renderCodeAST(`unified`,e),r=Qv(n?.[0]),i=Qv(n?.[1]),a=()=>{for(let[e,n]of[[t.gutter,r],[t.content,i]])n!=null&&(e.innerHTML=dc(n));e.rowCount!==this.lastRowCount&&(this.applyRowSpan(`unified`,t,e.rowCount),this.lastRowCount=e.rowCount)};this.shouldGuardRebuildScroll()?U_(this.pre,a):a(),this.renderSeparators(e.hunkData),this.managersDirty=!0,this.flushManagers(),this.syncRenderViewToEditor()}renderPartialColumn(e,t,n){if(e==null||t==null)return;let r=Qv(t[0]),i=Qv(t[1]);if(r==null||i==null)throw Error(`FileDiff.insertPartialHTML: Unexpected AST structure`);let a=i.at(0);n===`beforeend`&&a?.type===`element`&&typeof a.properties[`data-buffer-size`]==`number`&&this.mergeBuffersIfNecessary(a.properties[`data-buffer-size`],e.content.children[e.content.children.length-1],e.gutter.children[e.gutter.children.length-1],r,i,!0);let o=i.at(-1);n===`afterbegin`&&o?.type===`element`&&typeof o.properties[`data-buffer-size`]==`number`&&this.mergeBuffersIfNecessary(o.properties[`data-buffer-size`],e.content.children[0],e.gutter.children[0],r,i,!1),e.gutter.insertAdjacentHTML(n,this.hunksRenderer.renderPartialHTML(r)),e.content.insertAdjacentHTML(n,this.hunksRenderer.renderPartialHTML(i))}mergeBuffersIfNecessary(e,t,n,r,i,a){if(!(t instanceof HTMLElement)||!(n instanceof HTMLElement))return;let o=this.getBufferSize(t.dataset);o!=null&&(a?(r.shift(),i.shift()):(r.pop(),i.pop()),this.updateBufferSize(t,o+e),this.updateBufferSize(n,o+e))}applyRowSpan(e,t,n){let r=e=>{e!=null&&(e.gutter.style.setProperty(`grid-row`,`span ${n}`),e.content.style.setProperty(`grid-row`,`span ${n}`))};if(e===`unified`&&!Array.isArray(t))r(t);else if(e===`split`&&Array.isArray(t))r(t[0]),r(t[1]);else throw Error(`dun fuuuuked up`)}trimColumnRows(e,t,n){let r=0,i=0,a=0,o=!1,s=n>=0;if(e==null)return 0;let c=Array.from(e.content.children),l=Array.from(e.gutter.children);if(c.length!==l.length)throw Error(`FileDiff.trimColumnRows: columns do not match`);for(;a<c.length&&!(t<=0&&!s&&!o);){let e=l[a],u=c[a];if(a++,!(e instanceof HTMLElement)||!(u instanceof HTMLElement))throw console.error({gutterElement:e,contentElement:u}),Error(`FileDiff.trimColumnRows: invalid row elements`);if(o&&(o=!1,e.dataset.gutterBuffer===`annotation`&&`lineAnnotation`in u.dataset||e.dataset.gutterBuffer===`metadata`&&`noNewline`in u.dataset)){e.remove(),u.remove(),i++;continue}if(`lineIndex`in e.dataset&&`lineIndex`in u.dataset){(t>0||s&&r>=n)&&(e.remove(),u.remove(),t>0&&(t--,t===0&&(o=!0)),i++),r++;continue}if(`separator`in e.dataset&&`separator`in u.dataset){(t>0||s&&r>=n)&&(e.remove(),u.remove(),i++);continue}if(e.dataset.gutterBuffer===`annotation`&&`lineAnnotation`in u.dataset){(t>0||s&&r>=n)&&(e.remove(),u.remove(),i++);continue}if(e.dataset.gutterBuffer===`metadata`&&`noNewline`in u.dataset){(t>0||s&&r>=n)&&(e.remove(),u.remove(),i++);continue}if(e.dataset.gutterBuffer===`buffer`&&`contentBuffer`in u.dataset){let a=this.getBufferSize(u.dataset);if(a==null)throw Error(`FileDiff.trimColumnRows: invalid element`);if(t>0){let n=Math.min(t,a),r=a-n;r>0?(this.updateBufferSize(e,r),this.updateBufferSize(u,r),i+=n):(e.remove(),u.remove(),i+=a),t-=n,t===0&&r===0&&(o=!0)}else if(s){let t=r,o=r+a-1;if(n<=t)e.remove(),u.remove(),i+=a;else if(n<=o){let t=o-n+1,r=a-t;this.updateBufferSize(e,r),this.updateBufferSize(u,r),i+=t}}r+=a;continue}throw console.error({gutterElement:e,contentElement:u}),Error(`FileDiff.trimColumnRows: unknown row elements`)}return i}trimColumns({columns:e,diffStyle:t,overlapEnd:n,overlapStart:r,previousStart:i,trimEnd:a,trimStart:o}){let s=Math.max(0,r-i),c=n-i;if(c<0)throw Error(`FileDiff.trimColumns: overlap ends before previous`);let l=o>0,u=a>0;if(!l&&!u)return 0;let d=l?s:0,f=u?c:-1;if(t===`unified`&&!Array.isArray(e))return this.trimColumnRows(e,d,f);if(t===`split`&&Array.isArray(e)){let t=this.trimColumnRows(e[0],d,f),n=this.trimColumnRows(e[1],d,f);if(e[0]!=null&&e[1]!=null&&t!==n)throw Error(`FileDiff.trimColumns: split columns out of sync`);return e[0]==null?n:t}throw console.error({diffStyle:t,columns:e}),Error(`FileDiff.trimColumns: Invalid columns for diffType`)}getBufferSize(e){let t=Number.parseInt(e?.bufferSize??``,10);return Number.isNaN(t)?void 0:t}updateBufferSize(e,t){e.dataset.bufferSize=`${t}`,e.style.setProperty(`grid-row`,`span ${t}`),e.style.setProperty(`min-height`,`calc(${t} * 1lh)`)}getColumnPair(e){if(e==null)return;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}}getCodeColumns(e,t,n,r){if(e===`unified`)return this.getColumnPair(t);{let e=this.getColumnPair(n),t=this.getColumnPair(r);return e!=null||t!=null?[e,t]:void 0}}updateBuffers(e){this.pre!=null&&this.applyBuffers(this.pre,e)}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}applyPreNodeAttributes(e,{additionsContentAST:t,deletionsContentAST:n,totalLines:r},i){let{diffIndicators:a=`bars`,disableBackground:o=!1,disableLineNumbers:s=!1,overflow:c=`scroll`,diffStyle:l=`split`}=this.options,u={type:`diff`,diffIndicators:a,disableBackground:o,disableLineNumbers:s,overflow:c,split:l!==`unified`&&t!=null&&n!=null,totalLines:r,customProperties:i};T_(u,this.appliedPreAttributes)||(Q_(e,u),this.appliedPreAttributes=u)}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 qv(e,t){return e==null||t==null?e==null&&t==null:jn(e,t)}function Jv({fileDiff:e,oldFile:t,newFile:n}){return e!=null&&e.hunks.length>0||t!=null||n!=null}function Yv({fileDiff:e,oldFile:t,newFile:n}){return e!=null||t!=null||n!=null}function Xv(e,t,n=!1){return!n&&e==null&&t}function Zv(e,t,n=!1){return e==null&&t&&!n}function Qv(e){if(e!=null&&e.type===`element`)return e.children??[]}var $v=3e3,ey=-1,ty=class extends Kv{__id=`little-virtualized-file-diff:${++ey}`;top;height=0;metrics;cache={heightDeltas:new Map,measuredHeightDeltaTotal:0,estimatedSplitHeight:void 0,estimatedUnifiedHeight:void 0,checkpoints:[],totalLines:0,fileAnnotationHeight:0};isVisible=!1;isSetup=!1;virtualizer;layoutDirty=!0;forceRenderOverride;currentCollapsed;currentExpandUnchanged;pendingHydratedDiff;pendingExpansions;constructor(e,t,n,r,i=!1){super(e,r,i),this.virtualizer=t,this.metrics=mm(n)}setMetrics(e,t=!1){let n=mm(e);!t&&Th(this.metrics,n)||(this.metrics=n,this.resetLayoutCache({includeEstimatedHeights:!0}))}setLineAnnotations(e){this.syncLineAnnotations(e)&&this.resetLayoutCache({includeEstimatedHeights:!1})}syncLineAnnotations(e){return e==null||e===this.lineAnnotations||e.length===0&&this.lineAnnotations.length===0?!1:(super.setLineAnnotations(e),!0)}setFileAnnotationHeight(e){let t=this.cache.fileAnnotationHeight;return e!==t&&(this.cache.fileAnnotationHeight=e,this.cache.measuredHeightDeltaTotal+=e-t,!0)}hasFileAnnotations(e=this.fileDiff){return e==null||!jg(this.lineAnnotations)?!1:this.lineAnnotations.some(t=>t.lineNumber===0?e.type===`new`?t.side===`additions`:e.type!==`deleted`||t.side===`deletions`:!1)}getLineHeight(e,t=!1){return this.getEstimatedLineHeight(t)+(this.cache.heightDeltas.get(e)??0)}getEstimatedLineHeight(e=!1){let t=e?2:1;return this.metrics.lineHeight*t}setOptions(e){if(this.isAdvancedMode())throw Error(`VirtualizedFileDiff.setOptions cannot be used inside CodeView. Update CodeView options instead.`);if(e==null)return;let{options:t}=this,n=!Eh(t,e),r=n&&ly(t,e);super.setOptions(e),r&&this.resetLayoutCache({forceSimpleRecompute:!0,includeEstimatedHeights:uy(t,e)}),n&&(this.forceRenderOverride=!0),n&&this.isSimpleMode()&&this.virtualizer.instanceChanged(this,r)}setThemeType(e){if(this.isAdvancedMode())throw Error(`VirtualizedFileDiff.setThemeType cannot be used inside CodeView. Update CodeView options instead.`);super.setThemeType(e)}resetLayoutCache({forceSimpleRecompute:e=!1,includeEstimatedHeights:t=!1,resetRenderRange:n=!0}={}){this.layoutDirty=!0,this.cache.fileAnnotationHeight=0,this.cache.heightDeltas.size>0&&this.cache.heightDeltas.clear(),this.cache.measuredHeightDeltaTotal!==0&&(this.cache.measuredHeightDeltaTotal=0),this.invalidateDerivedLayoutCache(t,n),e&&this.isSimpleMode()&&this.computeApproximateSize()}invalidateDerivedLayoutCache(e,t=!0){this.layoutDirty=!0,this.cache.checkpoints.length>0&&(this.cache.checkpoints.length=0),this.cache.totalLines!==0&&(this.cache.totalLines=0),e&&(this.cache.estimatedSplitHeight=void 0,this.cache.estimatedUnifiedHeight=void 0),this.renderRange!=null&&t&&(this.renderRange=void 0)}reconcileHeights(){let e=!1,{overflow:t=`scroll`}=this.options;if(this.fileContainer==null||this.fileDiff==null)return this.height!==0&&(e=!0),this.height=0,e;if(this.top=this.getVirtualizedTop(),t===`scroll`&&this.lineAnnotations.length===0&&!this.isResizeDebuggingEnabled())return e;let n=this.getDiffStyle(),r=n===`split`?[this.codeDeletions,this.codeAdditions]:[this.codeUnified],i=this.hasFileAnnotations(this.fileDiff);if(this.renderRange!=null&&i&&Ng(this.renderRange)){let t=ny(r)??0;this.setFileAnnotationHeight(t)&&(e=!0)}else!i&&this.setFileAnnotationHeight(0)&&(e=!0);for(let t of r){if(t==null)continue;let r=t.children[1];if(r instanceof HTMLElement)for(let t of r.children){if(!(t instanceof HTMLElement))continue;let r=t.dataset.lineIndex;if(r==null)continue;let i=my(r,n),a=t.getBoundingClientRect().height,o=!1;t.nextElementSibling instanceof HTMLElement&&(`lineAnnotation`in t.nextElementSibling.dataset||`noNewline`in t.nextElementSibling.dataset)&&(`noNewline`in t.nextElementSibling.dataset&&(o=!0),a+=t.nextElementSibling.getBoundingClientRect().height);let s=this.getEstimatedLineHeight(o),c=this.cache.heightDeltas.get(i)??0,l=a-s;l!==c&&(e=!0,this.cache.measuredHeightDeltaTotal+=l-c,l===0?this.cache.heightDeltas.delete(i):this.cache.heightDeltas.set(i,l))}}return(e||this.isResizeDebuggingEnabled())&&this.computeApproximateSize(!0),e}onRender=e=>this.fileContainer!=null&&(e&&(this.top=this.getVirtualizedTop()),this.render());flushManagers(){super.flushManagers(),this.lineStateRefreshPending&&this.flushDeferredLineState()}prepareCodeViewItem(e,t,n,r){let i=!dm(this.fileDiff,e),a=this.syncLineAnnotations(r),o=n?.resetDiffLayoutCache===!0||i||a,s=i||n?.resetDiffLayoutCache===!0&&n.includeEstimatedDiffHeights;n?.metrics!=null&&(this.metrics=mm(n.metrics),o=!0,s=!0);let{collapsed:c=!1,expandUnchanged:l=!1}=this.options;return this.currentCollapsed!==c&&(this.currentCollapsed=c,o=!0),this.currentExpandUnchanged!==l&&(this.currentExpandUnchanged=l,o=!0,s=!0),o&&this.resetLayoutCache({includeEstimatedHeights:s}),this.fileDiff=e,this.top=t,this.computeApproximateSize(),this.height}getLinePosition(e,t=`additions`){if(this.fileDiff==null||e<1)return;let n=this.getLineIndex(e,t);if(n==null)return;let{disableFileHeader:r=!1,expandUnchanged:i=!1,collapsed:a=!1,collapsedContextThreshold:o=1}=this.options,s=this.getDiffStyle(),c=this.getHunkSeparatorType(),l=s===`split`?n[1]:n[0];this.approximateLayoutCheckpoints();let u=hm(this.metrics,r),d=this.getLayoutCheckpointBeforeLineIndex(l),f=d?.top??u+this.cache.fileAnnotationHeight;if(a)return{top:u,height:0};let p;return Mm({diff:this.fileDiff,diffStyle:s,startingLine:d?.renderedLineIndex??0,expandedHunks:i?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:o,callback:({hunkIndex:e,hunk:t,collapsedBefore:n,collapsedAfter:r,deletionLine:i,additionLine:a})=>{let o=s===`split`?a?.splitLineIndex??i?.splitLineIndex:a?.unifiedLineIndex??i?.unifiedLineIndex;if(o==null)throw Error(`VirtualizedFileDiff.getLinePosition: missing line index data`);if(n>0){let r=Am({type:c,metrics:this.metrics,hunkIndex:e,hunkSpecs:t?.hunkSpecs});if(r!=null){if(f+=r.gapBefore,l>=o-n&&l<o)return p={top:f,height:r.height},!0;f+=r.height+r.gapAfter}}let u=this.getLineHeight(o,(a?.noEOFCR??!1)||(i?.noEOFCR??!1));if(o===l)return p={top:f,height:u},!0;if(f+=u,r>0){let e=jm({type:c,metrics:this.metrics});if(e!=null){if(l>o&&l<=o+r)return p={top:f+e.gapBefore,height:e.height},!0;f+=e.totalHeight}}return!1}}),p}getEditorViewport(){return this.virtualizer.type===`simple`?this.virtualizer.getRoot():this.virtualizer.getContainerElement()}getNumericScrollAnchor(e){if(this.fileDiff==null)return;let{disableFileHeader:t=!1,expandUnchanged:n=!1,collapsed:r=!1,collapsedContextThreshold:i=1}=this.options;if(r)return;let a=this.getDiffStyle(),o=this.getHunkSeparatorType();this.approximateLayoutCheckpoints();let s=this.getLayoutCheckpointBeforeTop(e),c=s?.top??hm(this.metrics,t)+this.cache.fileAnnotationHeight,l;return Mm({diff:this.fileDiff,diffStyle:a,startingLine:s?.renderedLineIndex??0,expandedHunks:n?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:i,callback:({hunkIndex:t,hunk:n,collapsedBefore:r,collapsedAfter:i,deletionLine:s,additionLine:u})=>{let d=a===`split`?u?.splitLineIndex??s?.splitLineIndex:u?.unifiedLineIndex??s?.unifiedLineIndex;if(d==null)throw Error(`VirtualizedFileDiff.getNumericScrollAnchor: missing line index data`);if(r>0){let e=Am({type:o,metrics:this.metrics,hunkIndex:t,hunkSpecs:n?.hunkSpecs});e!=null&&(c+=e.totalHeight)}if(c>=e&&(s==null?u!=null&&(l={lineNumber:u.lineNumber,side:`additions`,top:c}):l={lineNumber:s.lineNumber,side:`deletions`,top:c},l!=null))return!0;let f=this.getLineHeight(d,(u?.noEOFCR??!1)||(s?.noEOFCR??!1));if(c+=f,i>0){let e=jm({type:o,metrics:this.metrics});e!=null&&(c+=e.totalHeight)}return!1}}),l}getVirtualizedHeight(){return this.height}getAdvancedStickySpecs(e){if(this.top==null||this.fileDiff==null)return;if(this.options.collapsed===!0)return{topOffset:this.top,height:this.height};let t=e==null?this.renderRange:this.computeRenderRangeFromWindow(this.fileDiff,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({includeEstimatedHeights:!0}),this.pendingExpansions=void 0,this.pendingHydratedDiff=void 0),this.isSetup=!1,super.cleanUp(e)}expandHunk=(e,t,n)=>{this.fileDiff!=null&&(this.isAdvancedMode()?(this.pendingExpansions??=[],this.pendingExpansions.push({hunkIndex:e,direction:t,expansionLineCountOverride:n})):(this.hunksRenderer.expandHunk(e,t,n),this.resetLayoutCache({includeEstimatedHeights:!0}),this.computeApproximateSize()),this.loadFilesIfNecessary(),this.forceRenderOverride=!0,this.virtualizer.instanceChanged(this,!0))};async handleFilesLoaded(e,t){if(!(this.fileDiff!==e||!e.isPartial)){if(this.isAdvancedMode()){let n=ov(`clone`,e,t);if(await $_(()=>this.primeHighlightCache(n)),!this.enabled||this.fileDiff!==e)return;this.pendingHydratedDiff={expectedDiff:e,nextDiff:n,files:t}}else{if(ov(`merge`,e,t),this.setHydratedState(t),await $_(()=>this.primeHighlightCache(e)),!this.enabled||this.fileDiff!==e)return;this.resetLayoutCache({includeEstimatedHeights:!0}),this.computeApproximateSize()}this.forceRenderOverride=!0,this.virtualizer.instanceChanged(this,!0)}}consumeCodeViewLayoutChanges(e){let t=!1,n,{pendingExpansions:r,pendingHydratedDiff:i}=this;if(r!=null){this.pendingExpansions=void 0;for(let e of r)this.hunksRenderer.expandHunk(e.hunkIndex,e.direction,e.expansionLineCountOverride),t=!0}return i!=null&&(this.pendingHydratedDiff=void 0,i.expectedDiff===e&&(this.setHydratedState(i.files),n=i.nextDiff)),n==null?t&&(this.forceRenderOverride=!0,this.invalidateDerivedLayoutCache(!0)):(this.forceRenderOverride=!0,this.resetLayoutCache({includeEstimatedHeights:!0})),n}loadFilesIfNecessary(){if(this.pendingHydratedDiff!=null){if(this.pendingHydratedDiff.expectedDiff===this.fileDiff)return;this.pendingHydratedDiff=void 0}super.loadFilesIfNecessary()}isLineRenderable(e){if(super.isLineRenderable(e))return!0;let{pendingExpansions:t}=this,n=this.fileDiffCache;if(t==null||t.length===0||n==null)return!1;let{expansionLineCount:r=100,collapsedContextThreshold:i=1}=this.options,a=new Map(this.hunksRenderer.getExpandedHunksMap());for(let e of t){let t={...a.get(e.hunkIndex)??{fromStart:0,fromEnd:0}},n=e.expansionLineCountOverride??r;(e.direction===`up`||e.direction===`both`)&&(t.fromStart+=n),(e.direction===`down`||e.direction===`both`)&&(t.fromEnd+=n),a.set(e.hunkIndex,t)}return wm({fileDiff:n,lineNumber:e,expandedHunks:a,collapsedContextThreshold:i})}invalidateEditSessionLayout(){this.getSimpleVirtualizer()?.markDOMDirty(),this.resetLayoutCache({forceSimpleRecompute:this.isSimpleMode(),includeEstimatedHeights:!0,resetRenderRange:!1}),this.isSimpleMode()||this.computeApproximateSize(!0),this.getSimpleVirtualizer()?.requestHeightReconcile(this)}escalateEditSessionRender(){this.invalidateEditSessionLayout(),!(!this.enabled||this.fileDiff==null)&&(this.forceRenderOverride=!0,this.virtualizer.instanceChanged(this,!0))}shouldSelfHealEditSession(){return!this.isAdvancedMode()&&super.shouldSelfHealEditSession()}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.fileDiff==null&&this.additionFile==null&&this.deletionFile==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({forceSimpleRecompute:this.isSimpleMode(),includeEstimatedHeights:!0,resetRenderRange:!1}),!this.isSimpleMode())this.computeApproximateSize(!0);else if(n&&r!==void 0&&this.fileDiff!==void 0){let e=this.virtualizer.getWindowSpecs(),t=this.computeRenderRangeFromWindow(this.fileDiff,this.top??0,e);t.bufferAfter!==r.bufferAfter&&this.updateBuffers(t)}this.forceRenderOverride=!0,this.virtualizer.instanceChanged(this,!0)}computeApproximateSize(e=!1,t=this.fileDiff){let n=this.isResizeDebuggingEnabled();if(!e&&!this.layoutDirty&&!n)return;let r=this.height===0;if(this.height=0,this.cache.checkpoints=[],this.cache.totalLines=0,t==null){this.layoutDirty=!1;return}let{disableFileHeader:i=!1,collapsed:a=!1}=this.options,o=hm(this.metrics,i);if(this.height+=o,a){this.layoutDirty=!1;return}this.height=this.getActiveEstimatedHeight(t)+this.cache.measuredHeightDeltaTotal,n&&!r&&this.validateComputedHeight(t),this.layoutDirty=!1}getActiveEstimatedHeight(e=this.fileDiff){this.ensureEstimatedDiffHeights(e);let t=this.getDiffStyle()===`split`?this.cache.estimatedSplitHeight:this.cache.estimatedUnifiedHeight;if(t==null)throw Error(`VirtualizedFileDiff.getActiveEstimatedHeight: missing estimated height`);return t}ensureEstimatedDiffHeights(e=this.fileDiff){if(e==null){this.cache.estimatedSplitHeight=void 0,this.cache.estimatedUnifiedHeight=void 0;return}if(this.cache.estimatedSplitHeight!=null&&this.cache.estimatedUnifiedHeight!=null)return;let{disableFileHeader:t=!1,expandUnchanged:n=!1,collapsedContextThreshold:r=1}=this.options,{splitHeight:i,unifiedHeight:a}=ev({fileDiff:e,metrics:this.metrics,disableFileHeader:t,hunkSeparators:this.getHunkSeparatorType(),expandUnchanged:n,expandedHunks:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:r,canHydratePartialDiff:dy(e,this.options.loadDiffFiles!=null)});this.cache.estimatedSplitHeight=i,this.cache.estimatedUnifiedHeight=a}validateComputedHeight(e=this.fileDiff){if(this.fileContainer==null||e==null)return;let t=this.fileContainer.getBoundingClientRect();t.height===this.height?console.log(`VirtualizedFileDiff.computeApproximateSize: computed height IS CORRECT`):console.log(`VirtualizedFileDiff.computeApproximateSize: computed height doesnt match`,{name:e.name,elementHeight:t.height,computedHeight:this.height})}render({fileContainer:e,fileDiff:t,forceRender:n=!1,lineAnnotations:r,...i}={}){let a=rv(i,`VirtualizedFileDiff.render`),o=a!=null,s=a?.oldFile,c=a?.newFile,l=o&&(!py(s,this.deletionFile)||!py(c,this.additionFile)),u=t??this.fileDiff;t==null&&o&&(l||this.fileDiff==null)&&(u=Fh(a.oldFile,a.newFile,this.options.parseDiffOptions));let{forceRenderOverride:d,isSetup:f}=this;this.forceRenderOverride=void 0;let p=this.syncLineAnnotations(r);p&&this.resetLayoutCache({includeEstimatedHeights:!1});let m=t!=null&&t!==this.fileDiff,h=u!=null&&!dm(this.fileDiff,u),g=m||l;if(h&&this.resetLayoutCache({includeEstimatedHeights:!0}),e=this.getOrCreateFileContainer(e),u==null)return console.error(`VirtualizedFileDiff.render: attempting to virtually render when we dont have the correct data`),!1;if(f)this.top??=this.getVirtualizedTop(),h&&(this.getSimpleVirtualizer()?.markDOMDirty(),this.computeApproximateSize(!1,u));else{this.computeApproximateSize(!1,u);let t=this.getSimpleVirtualizer();if(this.top??=this.getVirtualizedTop(),this.isAdvancedMode())this.isVisible=!0;else{if(t==null)throw Error(`VirtualizedFileDiff.render: simple virtualizer is not available`);t.connect(e,this),this.isVisible=t.isInstanceVisible(this.top??0,this.height)}this.isSetup=!0}if(!this.isVisible&&this.isSimpleMode()&&(!g||!f))return this.fileDiff=u,a!=null&&(this.deletionFile=s,this.additionFile=c),h&&(this.cachedHeaderHTML=void 0),this.renderPlaceholder(this.height);let _=this.virtualizer.getWindowSpecs(),v=this.top??0,y=this.computeRenderRangeFromWindow(u,v,_),b=super.render({fileDiff:u,fileContainer:e,renderRange:y,lineAnnotations:r,forceRender:(d??n)||p||h,...a,...i});return this.isSimpleMode()&&b&&this.getSimpleVirtualizer()?.requestHeightReconcile(this),b}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`}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}getDiffStyle(){return this.options.diffStyle??`split`}getHunkSeparatorType(){return fy(this.options.hunkSeparators)}approximateLayoutCheckpoints(e=this.fileDiff){if(!this.layoutDirty&&this.cache.checkpoints.length>0||e==null||e.hunks.length===0||this.options.collapsed===!0)return;let{disableFileHeader:t=!1,expandUnchanged:n=!1,collapsedContextThreshold:r=1}=this.options,i=e.hunks.length-1,a=dy(e,this.options.loadDiffFiles!=null),o=this.getDiffStyle(),s=this.getHunkSeparatorType(),c=n?!0:this.hunksRenderer.getExpandedHunksMap(),l=ry(this.cache.heightDeltas),u=hm(this.metrics,t)+this.cache.fileAnnotationHeight,d=0,f=({rowCount:e,startLineIndex:t,preSeparatorHeight:n=0,postSeparatorHeight:r=0,metadataOffsets:i=[]})=>{if(e<=0)return;let a=d,o=d+e,s=oy(a);for(;s<o;){let e=s-a,r=u+(e>0?n:0)+e*this.metrics.lineHeight+sy(i,e)*this.metrics.lineHeight+iy(l,t,t+e);this.cache.checkpoints.push({renderedLineIndex:s,lineIndex:t+e,top:r}),s+=$v}u+=n+e*this.metrics.lineHeight+i.length*this.metrics.lineHeight+iy(l,t,t+e)+r,d=o};for(let t=0;t<e.hunks.length;t++){let n=e.hunks[t];if(n==null)throw Error(`VirtualizedFileDiff.approximateLayoutCheckpoints: invalid hunk index`);let l=bm({isPartial:e.isPartial,rangeSize:n.collapsedBefore,expandedHunks:c,hunkIndex:t,collapsedContextThreshold:r}),u=l.collapsedLines>0?Am({type:s,metrics:this.metrics,hunkIndex:t,hunkSpecs:n.hunkSpecs})?.totalHeight??0:0;f({rowCount:l.fromStart,startLineIndex:(o===`split`?n.splitLineStart:n.unifiedLineStart)-l.rangeSize});let d=u;f({rowCount:l.fromEnd,startLineIndex:(o===`split`?n.splitLineStart:n.unifiedLineStart)-l.fromEnd,preSeparatorHeight:d}),l.fromEnd>0&&(d=0);let p=t===i?Cm({fileDiff:e,hunkIndex:t,expandedHunks:c,collapsedContextThreshold:r,errorPrefix:`VirtualizedFileDiff`}):void 0,m=p!=null&&p.collapsedLines>0||t===i&&a?jm({type:s,metrics:this.metrics})?.totalHeight??0:0,h=p==null?0:p.fromStart+p.fromEnd,g=o===`split`?n.splitLineCount:n.unifiedLineCount,_=o===`split`?n.splitLineStart:n.unifiedLineStart;f({rowCount:g,startLineIndex:_,preSeparatorHeight:d,postSeparatorHeight:h===0?m:0,metadataOffsets:cy({diffStyle:o,hunk:n,rowCount:g})}),p!=null&&h>0&&f({rowCount:h,startLineIndex:_+g,postSeparatorHeight:m})}this.cache.totalLines=d}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(`VirtualizedFileDiff: 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(`VirtualizedFileDiff: 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(`VirtualizedFileDiff: invalid checkpoint index`);if(n.renderedLineIndex%t===0)return n}}getExpandedLineCount(e,t){let n=0;if(e.isPartial){for(let r of e.hunks)n+=t===`split`?r.splitLineCount:r.unifiedLineCount;return n}let{expandUnchanged:r=!1,collapsedContextThreshold:i=1}=this.options,a=r?!0:this.hunksRenderer.getExpandedHunksMap();for(let[r,o]of e.hunks.entries()){let s=t===`split`?o.splitLineCount:o.unifiedLineCount;n+=s;let c=Math.max(o.collapsedBefore,0),{fromStart:l,fromEnd:u,renderAll:d}=bm({isPartial:e.isPartial,rangeSize:c,expandedHunks:a,hunkIndex:r,collapsedContextThreshold:i});c>0&&(n+=d?c:l+u)}let o=Cm({fileDiff:e,hunkIndex:e.hunks.length-1,expandedHunks:a,collapsedContextThreshold:i,errorPrefix:`VirtualizedFileDiff`});return o!=null&&(n+=o.fromStart+o.fromEnd),n}getLayoutLineCount(e,t){let n=this.getExpandedLineCount(e,t),r=t===`split`?e.splitLineCount:e.unifiedLineCount;return Math.max(n,r,e.additionLines.length,e.deletionLines.length,this.cache.totalLines)}computeRenderRangeFromWindow(e,t,{top:n,bottom:r}){let{disableFileHeader:i=!1,expandUnchanged:a=!1,collapsedContextThreshold:o=1}=this.options,{hunkLineCount:s,lineHeight:c}=this.metrics,l=this.getDiffStyle(),u=this.getHunkSeparatorType(),d=dy(e,this.options.loadDiffFiles!=null),f=this.height,p=this.getLayoutLineCount(e,l),m=hm(this.metrics,i),h=e.hunks.length>0?_m(this.metrics):0,{fileAnnotationHeight:g}=this.cache,_=m+g,v=Math.max(0,f-m-g-h),y=this.hasFileAnnotations(e),b=t+m,x=g>0&&y&&b<r&&b+g>n;if(t<n-f||t>r)return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:f-m-h};if(p<=s||e.hunks.length===0)return{startingLine:0,totalLines:s,bufferBefore:0,bufferAfter:0};this.approximateLayoutCheckpoints(e),p=this.getLayoutLineCount(e,l);let S=Math.ceil(Math.max(r-n,0)/c),C=Math.ceil(S/s)*s+s,ee=C/s,w=ee,T=[],E=(n+r)/2,D=this.getLayoutCheckpointBeforeTop(Math.max(0,n-t-C*c*2),s),O=t+(D?.top??_),k=D?.renderedLineIndex??0,A,j,M;if(Mm({diff:e,diffStyle:l,startingLine:D?.renderedLineIndex??0,expandedHunks:a?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:o,callback:({hunkIndex:i,hunk:a,collapsedBefore:o,collapsedAfter:c,deletionLine:f,additionLine:p})=>{let m=p==null?f.splitLineIndex:p.splitLineIndex,h=p==null?f.unifiedLineIndex:p.unifiedLineIndex,g=(p?.noEOFCR??!1)||(f?.noEOFCR??!1),v=i===e.hunks.length-1&&a!=null&&(l===`split`?m===a.splitLineStart+a.splitLineCount-1:h===a.unifiedLineStart+a.unifiedLineCount-1),y=(o>0?Am({type:u,metrics:this.metrics,hunkIndex:i,hunkSpecs:a?.hunkSpecs}):void 0)?.totalHeight??0;O+=y;let b=k%s===0,x=Math.floor(k/s);if(b&&(T[x]=O-(t+_+y),M!=null)){if(M<=0)return!0;M--}let S=this.getLineHeight(l===`split`?m:h,g);if(O>n-S&&O<r&&(A??=x),j==null&&O+S>E&&(j=x),M==null&&O>=r&&b&&(M=w),k++,O+=S,c>0||v&&d){let e=jm({type:u,metrics:this.metrics});e!=null&&(O<r&&O+e.totalHeight>n&&(A??=x),j==null&&O+e.totalHeight>E&&(j=x),O+=e.totalHeight)}return!1}}),A==null){if(x)A=0,j=0;else return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:f-m-h}}j??=A;let N=Math.round(j-ee/2),te=Math.max(0,Math.ceil(p/s)-ee),ne=Math.max(0,Math.min(N,te)),re=ne*s,P=N<0?C+N*s:C,ie=T[ne]??0,ae=re===0?0:g+ie,F=ne+P/s,oe=F<T.length?v-T[F]:v-(O-t-_);return{startingLine:re,totalLines:P,bufferBefore:ae,bufferAfter:Math.max(0,oe)}}};function ny(e){let t;for(let n of e){if(n==null)continue;let e=n.children[1];if(e instanceof HTMLElement)for(let n of e.children)n instanceof HTMLElement&&n.dataset.lineAnnotation===Ag&&(t=Math.max(t??0,n.getBoundingClientRect().height))}return t}function ry(e){let t=Array.from(e).sort((e,t)=>e[0]-t[0]),n=[],r=[0],i=0;for(let[e,a]of t)n.push(e),i+=a,r.push(i);return{lineIndexes:n,prefixTotals:r}}function iy({lineIndexes:e,prefixTotals:t},n,r){if(n>=r||e.length===0)return 0;let i=ay(e,n);return(t[ay(e,r)]??0)-(t[i]??0)}function ay(e,t){let n=0,r=e.length;for(;n<r;){let i=n+r>>1,a=e[i];if(a==null)throw Error(`VirtualizedFileDiff: invalid prefix index`);a<t?n=i+1:r=i}return n}function oy(e){return Math.ceil(e/$v)*$v}function sy(e,t){let n=0;for(let r of e)r<t&&n++;return n}function cy({diffStyle:e,hunk:t,rowCount:n}){if(n<=0||!t.noEOFCRAdditions&&!t.noEOFCRDeletions)return[];let r=t.hunkContent.at(-1);if(r==null)return[];if(r.type===`context`)return[n-1];let i=Math.max(r.deletions,r.additions),a=r.deletions+r.additions;if(e===`split`)return i>0&&(t.noEOFCRAdditions||t.noEOFCRDeletions)?[n-1]:[];let o=[],s=n-a;return r.deletions>0&&t.noEOFCRDeletions&&o.push(s+r.deletions-1),r.additions>0&&t.noEOFCRAdditions&&o.push(n-1),o}function ly(e,t){return(e.diffStyle??`split`)!==(t.diffStyle??`split`)||(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.diffIndicators??`bars`)!==(t.diffIndicators??`bars`)||(e.hunkSeparators??`line-info`)!==(t.hunkSeparators??`line-info`)||!!e.loadDiffFiles!=!!t.loadDiffFiles||(e.expandUnchanged??!1)!==(t.expandUnchanged??!1)||(e.collapsedContextThreshold??1)!==(t.collapsedContextThreshold??1)||e.unsafeCSS!==t.unsafeCSS}function uy(e,t){return(e.disableFileHeader??!1)!==(t.disableFileHeader??!1)||(e.hunkSeparators??`line-info`)!==(t.hunkSeparators??`line-info`)||!!e.loadDiffFiles!=!!t.loadDiffFiles||(e.expandUnchanged??!1)!==(t.expandUnchanged??!1)||(e.collapsedContextThreshold??1)!==(t.collapsedContextThreshold??1)}function dy(e,t){return e.isPartial&&t&&(e.type===`change`||e.type===`rename-changed`)}function fy(e){return typeof e==`function`?`custom`:e??`line-info`}function py(e,t){return e==null||t==null?e==null&&t==null:jn(e,t)}function my(e,t){let[n,r]=e.split(`,`).map(Number);return t===`split`?r:n}function hy(e,t){return typeof window>`u`&&t!=null?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`template`,{shadowrootmode:`open`,dangerouslySetInnerHTML:{__html:t}}),e]}):(0,U.jsx)(U.Fragment,{children:e})}var gy=(0,W.createContext)(void 0);function _y(){return(0,W.useContext)(gy)}var vy=typeof window>`u`?W.useEffect:W.useLayoutEffect;function yy({fileDiff:e,options:t,editorOptions:n,lineAnnotations:r,selectedLines:i,prerenderedHTML:a,metrics:o,hasGutterRenderUtility:s,hasCustomHeader:c,disableWorkerPool:l,edit:u}){let d=_y(),f=i!==void 0,p=(0,W.useContext)(wh),m=bn(),h=(0,W.useRef)(null),g=_n(n=>{if(n!=null){if(h.current!=null)throw Error(`useFileDiffInstance: An instance should not already exist when a node is created`);d==null?h.current=new Kv(by({controlledSelection:f,hasCustomHeader:c,hasGutterRenderUtility:s,options:t}),l?void 0:p,!0):h.current=new ty(by({controlledSelection:f,hasCustomHeader:c,hasGutterRenderUtility:s,options:t}),d,o,l?void 0:p,!0),h.current.hydrate({fileDiff:e,fileContainer:n,lineAnnotations:r,prerenderedHTML:a})}else{if(h.current==null)throw Error(`useFileDiffInstance: A FileDiff instance should exist when unmounting`);h.current.cleanUp(),h.current=null}});return vy(()=>{let{current:n}=h;if(n==null)return;let a=by({controlledSelection:f,hasCustomHeader:c,hasGutterRenderUtility:s,options:t}),o=a!==void 0&&!Eh(n.options,a);n.setOptions(a),n.render({forceRender:o,fileDiff:e,lineAnnotations:r}),i!==void 0&&n.setSelectedLines(i)}),vy(()=>{if(u&&h.current!=null){if(m===void 0)throw Error(`FileDiff: EditContext is not attached`);let e=m(n??{});if(e==null)throw Error(`FileDiff: EditProvider.createEditor must return an editor instance`);try{return e.edit(h.current)}catch(t){throw e.cleanUp(),t}}},[u]),{ref:g,getHoveredLine:(0,W.useCallback)(()=>h.current?.getHoveredLine(),[])}}function by({options:e,controlledSelection:t,hasCustomHeader:n,hasGutterRenderUtility:r}){return t||r||n?{...e,controlledSelection:t,renderCustomHeader:n?Cn:e?.renderCustomHeader,renderGutterUtility:r?Cn:e?.renderGutterUtility}:e}var xy=W.createContext(void 0);function Sy(e){let t=W.useContext(xy);if(t===void 0&&!e)throw Error(Kt(33));return t}var Cy=W.createContext(void 0);function wy(e){let t=W.useContext(Cy);if(t===void 0&&!e)throw Error(Kt(36));return t}var Ty=W.createContext(void 0);function Ey(e=!0){let t=W.useContext(Ty);if(t===void 0&&!e)throw Error(Kt(25));return t}var Dy=W.createContext(null);function Oy(e=`root`){let t=W.useContext(Dy),n=W.useContext(Cy);return t===null||n===void 0?null:(e===`submenu-trigger`?n.virtualFocus||n.parentVirtualFocus:n.virtualFocus)?t:null}var ky={visible:!0,ref:null};function Ay(){return ky}function jy(e,t,n=`root`){let r=Oy(n),i=((n===`submenu-trigger`?r?.useSubmenuTrigger:r?.useItem)??Ay)({label:e.label,children:e.children,render:e.render}),a=re(t,i.ref);return{visible:i.visible,ref:a,props:i.props}}var My=W.createContext(void 0);function Ny(){let e=W.useContext(My);if(e===void 0)throw Error(Kt(30));return e}function Py(e){e.preventDefault()}function Fy(e){let{closeOnClick:t,highlighted:n,id:r,nodeId:i,store:a,typingRef:o,itemRef:s,itemMetadata:c}=e,l=wy(),u=Ey(!0),d=c.type===`submenu-trigger`,f=d?l.parentVirtualFocus:l.virtualFocus,p=(d&&l.parent.type===`menu`?l.parent.store:l.store).useState(`webkitAriaSelected`,n),{events:m}=a.useState(`floatingTreeRoot`),h=a.useState(`open`),g=u!==void 0,_=!f&&h&&n?0:-1;return W.useMemo(()=>({id:r,role:`menuitem`,tabIndex:_,"aria-selected":p,onMouseDown:f?Py:void 0,onKeyDown(e){e.key===` `&&o?.current&&e.preventDefault()},onMouseMove(e){i&&m.emit(`itemhover`,{nodeId:i,target:e.currentTarget})},onClick(e){t&&m.emit(`close`,{domEvent:e.nativeEvent,reason:dt})},onMouseUp(e){if(u){let t=u.initialCursorPointRef.current;if(u.initialCursorPointRef.current=null,g&&t&&Math.abs(e.clientX-t.x)<=1&&Math.abs(e.clientY-t.y)<=1||g&&!Te&&e.button===2)return}s.current&&a.context.allowMouseUpTriggerRef.current&&(!g||e.button===2)&&c.type===`regular-item`&&de(s.current,e,{detail:1,pointerType:`mouse`})}}),[t,_,r,m,i,a.context.allowMouseUpTriggerRef,o,s,u,g,c.type,p,f])}var Iy={type:`regular-item`};function Ly(e){let{closeOnClick:t,disabled:n,highlighted:r,id:i,store:a,typingRef:o=a.context.typingRef,nativeButton:s,itemMetadata:c,nodeId:l}=e,u=W.useRef(null),{getButtonProps:d,buttonRef:f}=Ae({disabled:n,focusableWhenDisabled:!0,native:s,composite:!0}),p=Fy({closeOnClick:t,highlighted:r,id:i,nodeId:l,store:a,typingRef:o,itemRef:u,itemMetadata:c}),m=W.useCallback(e=>ae(p,{onMouseEnter(e){c.type===`submenu-trigger`&&c.setActive(e.nativeEvent)}},e,d),[p,d,c]),h=re(u,f);return W.useMemo(()=>({getItemProps:m,itemRef:h}),[m,h])}var Ry=W.createContext({register:()=>{},unregister:()=>{},subscribeMapChange:()=>()=>{},nextIndexRef:{current:0}});function zy(){return W.useContext(Ry)}function By(e={}){let{guess:t,label:n,metadata:r,textRef:i,index:a}=e,{register:o,unregister:s,subscribeMapChange:c,nextIndexRef:l}=zy(),u=W.useRef(-1),[d,f]=W.useState(a==null&&t?()=>{if(u.current===-1){let e=l.current;l.current+=1,u.current=e}return u.current}:-1),p=a??d,m=W.useRef(null),h=W.useCallback(e=>{let t=m.current;t&&s(t),m.current=e,e&&o(e,{metadata:r??null,index:a??null,label:n,textRef:i})},[a,o,s,r,n,i]);return jt(()=>{if(a==null)return c(e=>{let t=m.current?e.get(m.current)?.index:null;t!=null&&f(t)})},[a,c]),{ref:h,index:p}}var Vy=`data-checked`,Hy=`data-unchecked`,Uy={checked(e){return e?{[Vy]:``}:{[Hy]:``}},...p},Wy=W.forwardRef(function(e,t){let{render:n,className:r,id:i,label:a,nativeButton:o=!1,disabled:s=!1,closeOnClick:c=!1,checked:l=!1,onCheckedChange:u,style:d,...f}=e,{store:p}=wy(),m=By({guess:!0,label:a}),h=wt(i),g=p.useState(`disabled`),_=p.useState(`isActive`,m.index),v=p.useState(`floatingNodeId`),y=p.useState(`itemProps`),b=s||g,{getItemProps:x,itemRef:C}=Ly({closeOnClick:c,disabled:b,highlighted:_,id:h,store:p,nativeButton:o,nodeId:v,itemMetadata:Iy}),ee=W.useMemo(()=>({disabled:b,highlighted:_,checked:l}),[b,_,l]);function w(e){let t=S(dt,e.nativeEvent,void 0,{preventUnmountOnClose:E});u?.(!l,t)}let T=it(`div`,e,{state:ee,stateAttributesMapping:Uy,props:[y,{role:`menuitemcheckbox`,"aria-checked":l,onClick:w},f,x],ref:[C,t,m.ref]});return(0,U.jsx)(My.Provider,{value:ee,children:T})}),Gy=W.forwardRef(function(e,t){let{checked:n,defaultChecked:r,onCheckedChange:i,...a}=e,[o,s]=Be({controlled:n,default:r??!1,name:`MenuCheckboxItem`,state:`checked`}),c=jy(e,t);function l(e,t){i?.(e,t),t.isCanceled||s(e)}return c.visible?(0,U.jsx)(Wy,{...a,checked:o,onCheckedChange:l,ref:c.ref}):null}),Ky=W.forwardRef(function(e,t){let{render:n,className:r,style:i,keepMounted:a=!1,...o}=e,s=Ny(),c=W.useRef(null),{transitionStatus:u,mounted:d,setMounted:f}=w(s.checked);l({batch:!0,enabled:!s.checked,open:s.checked,ref:c,onComplete(){s.checked||f(!1)}});let p={checked:s.checked,disabled:s.disabled,highlighted:s.highlighted,transitionStatus:u};return it(`span`,e,{state:p,ref:[t,c],stateAttributesMapping:Uy,props:{"aria-hidden":!0,...o},enabled:a||d})}),qy=W.createContext(void 0);function Jy(){let e=W.useContext(qy);if(e===void 0)throw Error(Kt(31));return e}var Yy=W.forwardRef(function(e,t){let{render:n,className:r,style:i,id:a,...o}=e,s=wt(a),c=Jy();return jt(()=>(c(s),()=>{c(e=>e===s?void 0:e)}),[c,s]),it(`div`,e,{ref:t,props:{id:s,"aria-hidden":!0,...o}})}),Xy=W.forwardRef(function(e,t){let{render:n,className:r,id:i,label:a,nativeButton:o=!1,disabled:s=!1,closeOnClick:c=!0,style:l,...u}=e,{store:d}=wy(),f=By({guess:!0,label:a}),p=wt(i),m=d.useState(`disabled`),h=d.useState(`isActive`,f.index),g=d.useState(`floatingNodeId`),_=d.useState(`itemProps`),v=s||m,{getItemProps:y,itemRef:b}=Ly({closeOnClick:c,disabled:v,highlighted:h,id:p,store:d,nativeButton:o,nodeId:g,itemMetadata:Iy});return it(`div`,e,{state:{disabled:v,highlighted:h},props:[_,u,y],ref:[b,t,f.ref]})}),Zy=W.forwardRef(function(e,t){let n=jy(e,t);return n.visible?(0,U.jsx)(Xy,{...e,ref:n.ref}):null}),Qy=Te&&De;function $y(e,t={}){let{enabled:n=!0,delay:r}=t,{events:a,dataRef:o}=e.context,s=W.useRef(!1),c=W.useRef(null),l=W.useRef(!0),u=qt();W.useEffect(()=>{let t=e.select(`domReferenceElement`);if(!n)return;let r=et(t);function a(){let t=e.select(`domReferenceElement`);!e.select(`open`)&&mt(t)&&t===F(i(t))&&(s.current=!0,c.current=t)}function o(){l.current=!0}function u(){l.current=!1}return Vt(me(r,`blur`,a),Qy&&me(r,`keydown`,o,!0),Qy&&me(r,`pointerdown`,u,!0))},[e,n]),W.useEffect(()=>{if(!n)return;function t(t){if(t.reason===`trigger-press`||t.reason===`escape-key`){let t=e.select(`domReferenceElement`);Pe(t)&&(c.current=t,s.current=!0)}}return a.on(`openchange`,t),()=>{a.off(`openchange`,t)}},[a,n,e]);let d=W.useMemo(()=>{function t(){s.current=!1,c.current=null}return{onMouseLeave(){t()},onFocus(n){let i=n.currentTarget;if(s.current){if(c.current===i)return;t()}let a=le(n.nativeEvent);if(Pe(a)){if(Qy&&!n.relatedTarget){if(!l.current&&!g(a))return}else if(!m(a))return}let o=Rt(n.relatedTarget,e.context.triggerElements),{nativeEvent:d,currentTarget:f}=n;if(e.select(`open`)&&o||!r){e.setOpen(!0,S(Bt,d,f));return}u.start(r,()=>{s.current||e.setOpen(!0,S(Bt,d,f))})},onBlur(n){t();let r=n.relatedTarget,a=n.nativeEvent,s=Pe(r)&&r.hasAttribute(qe(`focus-guard`))&&r.getAttribute(`data-type`)===`outside`;u.start(0,()=>{let t=e.select(`domReferenceElement`),n=F(i(t));!r&&n===t||se(o.current.floatingContext?.refs.floating.current,n)||se(t,n)||s||Rt(r??n,e.context.triggerElements)||e.setOpen(!1,S(Bt,a))})}}},[o,r,e,u]);return W.useMemo(()=>n?{reference:d,trigger:d}:{},[n,d])}function eb(e){return De&&e.movementX===0&&e.movementY===0}function tb(e,t,n){switch(e){case`vertical`:return t;case`horizontal`:return n;default:return t||n}}function nb(e,t){return tb(t,e===`ArrowUp`||e===`ArrowDown`,e===`ArrowLeft`||e===`ArrowRight`)}function rb(e,t,n){return tb(t,e===`ArrowDown`,n?e===`ArrowLeft`:e===`ArrowRight`)||e===`Enter`||e===` `||e===``}function ib(e,t,n){return tb(t,n?e===st:e===s,e===L)}function ab(e,t,n,r){return t===`both`||t===`horizontal`&&r?e===`Escape`:tb(t,n?e===s:e===st,e===at)}function ob(e,t){let{listRef:n,activeIndex:r,onNavigate:a=()=>{},enabled:o=!0,selectedIndex:s=null,allowEscape:c=!1,loopFocus:l=!1,nested:u=!1,rtl:f=!1,virtual:p=!1,focusItemOnOpen:m=`auto`,focusItemOnHover:h=!0,openOnArrowKeyDown:_=!0,disabledIndices:v=void 0,orientation:b=`vertical`,triggerOrientation:x=b,parentOrientation:C,id:ee,resetOnPointerLeave:w=!0,externalTree:T,nestedReturnFocusRef:E,grid:O}=t,k=O!=null,A=e.useState(`open`),j=e.useState(`floatingElement`),M=e.useState(`domReferenceElement`),N=e.context.dataRef,te=d(j),ne=B(M),re=ze(te),ie=nt(),ae=Ie(T),oe=W.useRef(m),I=W.useRef(s??-1),L=W.useRef(null),ce=W.useRef(!0),R=H(e=>{a(I.current===-1?null:I.current,e)}),ue=W.useRef(!!j),z=W.useRef(A),de=W.useRef(!1),fe=W.useRef(!1),pe=W.useRef(null),me=ze(v),he=ze(A),ge=ze(s),_e=ze(w),ve=Se(),ye=Se(),be=H(()=>{ve.cancel();function e(e){p||(pe.current=He(e,{sync:de.current,preventScroll:!0}))}let t=n.current[I.current],r=fe.current;t&&e(t),(de.current?e=>e():e=>ve.request(e))(()=>{let i=n.current[I.current]||t;i&&(t||e(i),V&&(r||!ce.current)&&i.scrollIntoView?.({block:`nearest`,inline:`nearest`}))})});jt(()=>{N.current.orientation=b},[N,b]),jt(()=>{A||(L.current=null),(!A||m!==`auto`)&&(oe.current=m)},[A,m]),jt(()=>{o&&(A&&j?(I.current=s??-1,oe.current&&s!=null&&(fe.current=!0,R())):ue.current&&(I.current=-1,R()))},[o,A,j,s,R]),jt(()=>{if(o){if(!A){de.current=!1;return}if(j){if(r==null){if(de.current=!1,ge.current!=null)return;if(ue.current&&(I.current=-1,be()),(!z.current||!ue.current)&&oe.current&&(L.current!=null||oe.current===!0&&L.current==null)){let e=0,t=()=>{n.current[0]==null?(e<2&&(e?e=>ye.request(e):queueMicrotask)(t),e+=1):(I.current=L.current==null||rb(L.current,x,f)||u?ft(n):bt(n),L.current=null,R())};t()}}else Ne(n.current,r)||(I.current=r,be(),fe.current=!1)}}},[o,A,j,r,ge,u,n,x,f,R,be,ye]),jt(()=>{if(!o||j||!ae||p||!ue.current)return;let e=ae.nodesRef.current,t=e.find(e=>e.id===ie)?.context?.elements.floating,n=F(i(M??t??null)),r=e.some(e=>e.context&&se(e.context.elements.floating,n));t&&!r&&ce.current&&t.focus({preventScroll:!0})},[o,j,M,ae,ie,p]),jt(()=>{z.current=A,ue.current=!!j});let xe=r!=null,Ce=H(e=>{if(!he.current)return;let t=n.current.indexOf(e.currentTarget);t!==-1&&(I.current!==t||r!==t)&&(I.current=t,R(e))}),we=H(()=>C??ae?.nodesRef.current.find(e=>e.id===ie)?.context?.dataRef?.current.orientation),Te=H(()=>ft(n,me.current)),Ee=H(t=>{if(ce.current=!1,de.current=!0,t.which===229||!he.current&&t.currentTarget===re.current)return;if(u&&ab(t.key,b,f,k)){nb(t.key,we())||P(t),e.setOpen(!1,S(Ye,t.nativeEvent));let n=E?.current??M;mt(n)&&n.focus();return}r!=null&&r!==I.current&&!Ne(n.current,r)&&(I.current=r);let i=I.current,a=ft(n,v),o=bt(n,v);if(ne||(t.key===`Home`&&(P(t),I.current=a,R(t)),t.key===`End`&&(P(t),I.current=o,R(t))),O!=null){let e=O(t,I.current,n,b,l,f,v,a,o);if(e!=null&&e!==I.current&&(I.current=e,R(t)),b===`both`)return}if(nb(t.key,b)){P(t);let e=F(t.currentTarget.ownerDocument);if(A&&!p&&se(t.currentTarget,e)&&!n.current.some(t=>t!=null&&se(t,e))){I.current=rb(t.key,b,f)?a:o,R(t),r===I.current&&be();return}let{index:s,wrapped:u}=$e(n.current,i,{decrement:!rb(t.key,b,f),loopFocus:l,allowEscape:c,disabledIndices:v,minIndex:a,maxIndex:o});u&&(de.current=!1),I.current=s,R(t)}}),V=W.useMemo(()=>({onFocus(e){de.current=!0,Ce(e)},onClick({currentTarget:e}){p||e.focus({preventScroll:!0})},onMouseMove(e){eb(e)||(de.current=!0,fe.current=!1,h&&Ce(e))},onPointerLeave(e){if(!he.current||!ce.current||e.pointerType===`touch`)return;de.current=!0;let t=e.relatedTarget;if(!(!h||n.current.includes(t))&&_e.current&&(pe.current?.(),pe.current=null,I.current=-1,R(e),!p)){let e=re.current,t=F(i(e));e&&se(e,t)&&e.focus({preventScroll:!0})}}}),[Ce,he,re,h,n,R,_e,p]),De=W.useMemo(()=>p&&A&&xe&&{"aria-activedescendant":`${ee}-${r}`},[p,A,xe,ee,r]),Oe=W.useMemo(()=>({...ne?{}:De,onKeyDown(t){if(t.key===`Tab`&&t.shiftKey&&A&&!p){let n=le(t.nativeEvent);if(n&&!se(re.current,n))return;P(t);let r=S(Ke,t.nativeEvent);e.setOpen(!1,r);let i=E?.current??M;!r.isCanceled&&mt(i)&&i.focus();return}Ee(t)},onPointerMove(e){eb(e)||(ce.current=!0)}}),[De,Ee,re,ne,e,A,p,M,E]),ke=W.useMemo(()=>{function t(t){e.setOpen(!0,S(Ye,t.nativeEvent,t.currentTarget))}function n(e){m===`auto`&&y(e.nativeEvent)&&(oe.current=!p)}function r(e){oe.current=m,m===`auto`&&D(e.nativeEvent)&&(oe.current=!0)}return{onKeyDown(n){let r=e.select(`open`);ce.current=!1;let i=n.key.startsWith(`Arrow`),a=ib(n.key,we(),f),o=nb(n.key,r?b:x),s=(u?a:o)||n.key===`Enter`||n.key.trim()===``;if(p&&r&&(!u||g(n.currentTarget)))return Ee(n);if(!(!r&&!_&&i)){if(s){let e=nb(n.key,we());L.current=u&&e?null:n.key}if(u){a&&(P(n),r?(I.current=Te(),R(n),p&&re.current?.focus()):t(n));return}o&&(ge.current!=null&&(I.current=ge.current),P(n),!r&&_?t(n):Ee(n),r&&R(n))}},onFocus(t){t.target===t.currentTarget&&e.select(`open`)&&!p&&(I.current=-1,R(t))},onPointerDown:r,onPointerEnter:r,onMouseDown:n,onClick:n}},[Ee,m,Te,u,R,e,_,b,x,we,f,ge,p,re]),Ae=W.useMemo(()=>({...De,...ke}),[De,ke]);return W.useMemo(()=>o?{reference:Ae,floating:Oe,item:V,trigger:ke}:{},[o,Ae,Oe,ke,V])}function sb(e,t){let{listRef:n,elementsRef:r,activeIndex:i,onMatch:a,disabledIndices:o,onTyping:s,enabled:c=!0,resetMs:l=750,selectedIndex:u=null}=t,d=H(s),f=e.useState(`open`),p=qt(),m=W.useRef(``),h=W.useRef(u??i??-1),g=W.useRef(null),_=H(e=>{function t(e){return r?.current[e]}function s(e){let n=t(e);return n&&!Xe(n)||n?.matches(`:disabled`)?!1:o==null||!Ft(R,e,o)}function c(e,t,n=0){if(e.length===0)return-1;let r=(n%e.length+e.length)%e.length,i=t.toLowerCase();for(let t=0;t<e.length;t+=1){let n=(r+t)%e.length;if(!(!e[n]?.toLowerCase().startsWith(i)||!s(n)))return n}return-1}let _=n.current;if(m.current.length>0&&e.key===` `&&(P(e),d?.(!0)),m.current.length>0&&m.current[0]!==` `&&c(_,m.current)===-1&&e.key!==` `&&d?.(!1),_==null||e.key.length!==1||e.ctrlKey||e.metaKey||e.altKey)return;f&&e.key!==` `&&(P(e),d?.(!0));let v=m.current===``;v&&(h.current=u??i??-1),_.every((e,t)=>e&&s(t)?e[0]?.toLowerCase()!==e[1]?.toLowerCase():!0)&&m.current===e.key&&(m.current=``,h.current=g.current),m.current+=e.key,p.start(l,()=>{m.current=``,h.current=g.current,d?.(!1)});let y=((v?u??i??-1:h.current)??0)+1,b=c(_,m.current,y);b===-1?e.key!==` `&&(m.current=``,d?.(!1)):(a?.(b,e),g.current=b)}),v=H(t=>{let n=t.relatedTarget,r=e.select(`domReferenceElement`),i=e.select(`floatingElement`);se(r,n)||se(i,n)||(p.clear(),m.current=``,h.current=g.current,d?.(!1))});jt(()=>{!f&&u!==null||(p.clear(),g.current=null,m.current!==``&&(m.current=``,d?.(!1)))},[f,u,p,d]);let y=W.useMemo(()=>({onKeyDown:_,onBlur:v}),[_,v]);return W.useMemo(()=>c?{reference:y,floating:y}:{},[c,y])}var cb=W.createContext(void 0);function lb(){return W.useContext(cb)}function ub(e,t){let n=o(e.render);if(W.isValidElement(n)){let e=n.props;if(Object.hasOwn(e,`id`))return e.id??``}return e.id??t}function db(e,t,n){let r=ub(e,t),i=r===t?void 0:r;return[r,W.useCallback(e=>n?.(e?i:void 0),[i,n])]}function fb(e,t,n){let r=o(e.render),i=W.isValidElement(r)?r.props:void 0,a=e[`aria-label`]??i?.[`aria-label`],s=e[`aria-labelledby`]??i?.[`aria-labelledby`];return s==null&&!a&&(s=t?t.id||void 0:n||void 0),s}var pb=W.forwardRef(function(e,t){let{render:n,className:r,style:i,finalFocus:a,id:o,initialFocus:s,...c}=e,{store:u,defaultFloatingId:d,setRenderedFloatingId:p,virtualFocus:m,orientation:g}=wy(),_=lb(),{side:v,align:y}=Sy(),b=I(!0)!=null,x=u.useState(`open`),C=u.useState(`transitionStatus`),ee=u.useState(`popupProps`),w=u.useState(`mounted`),T=u.useState(`instantType`),E=u.useState(`activeTriggerElement`),D=u.useState(`parent`),O=u.useState(`lastOpenChangeReason`),k=u.useState(`rootId`),A=u.useState(`floatingRootContext`),j=u.useState(`floatingTreeRoot`),M=u.useState(`closeDelay`),N=u.useState(`hoverEnabled`),te=u.useState(`disabled`),ne=u.useState(`openMethod`),re=u.useState(`activeTriggerId`),P=u.useState(`listElement`),[ie,ae]=db(e,d,p),F=fb(e,E,re),oe=D.type===`menu`?_:void 0,se=D.type===`context-menu`,L=s??D.type!==`menu`;s===void 0&&P&&D.type!==`menu`&&(L=()=>u.state.activeIndex===null&&P),l({open:x,ref:u.context.popupRef,onComplete(){x&&u.context.onOpenChangeComplete?.(!0)}}),W.useEffect(()=>{function e(e){u.setOpen(!1,S(e.reason,e.domEvent))}return j.events.on(`close`,e),()=>{j.events.off(`close`,e)}},[j.events,u]),rt(A,{enabled:N&&!te&&!se&&D.type!==`menubar`,closeDelay:M});let ce=u.useStateSetter(`popupElement`),{parentVirtualFocusRef:R,handleFocus:le}=(W.useContext(Dy)?.useParentHandoff??hb)(u,D,x,m),ue={transitionStatus:C,side:v,align:y,open:x,nested:D.type===`menu`,instant:T},z=it(`div`,e,{state:ue,ref:[t,u.context.popupRef,ce,ae],stateAttributesMapping:Lt,props:[ee,{id:ie,...P?{role:`presentation`}:{role:`menu`,"aria-orientation":g===`horizontal`?`horizontal`:void 0,"aria-labelledby":F},onKeyDown(e){oe?.onPopupKeyDown?.(e),b&&f.has(e.key)&&e.stopPropagation()},onFocus:le},h(C),c,{"data-rootownerid":k}]}),de=D.type===void 0||se;(E||D.type===`menubar`&&O!==`outside-press`)&&(de=!0);let fe=oe?.getReturnElement??R;return(0,U.jsx)(Ge,{context:A,openInteractionType:ne,modal:se,disabled:!w,returnFocus:a??fe??de,explicitReturnFocus:a===void 0&&fe?!1:void 0,initialFocus:L,restoreFocus:!0,getInsideElements:D.type===void 0?()=>[u.context.beforeTriggerFocusGuardRef.current]:void 0,externalTree:D.type===`menubar`?void 0:j,previousFocusableElement:E,nextFocusableElement:D.type===void 0?u.context.triggerFocusTargetRef:void 0,beforeContentFocusGuardRef:u.context.beforeContentFocusGuardRef,children:z})}),mb={parentVirtualFocusRef:void 0,handleFocus:void 0};function hb(){return mb}var gb=W.forwardRef(function(e,t){let n=Oy()?.Popup??pb;return(0,U.jsx)(n,{...e,ref:t})}),_b=W.createContext(void 0);function vb(){let e=W.useContext(_b);if(e===void 0)throw Error(Kt(32));return e}var yb=W.forwardRef(function(e,t){let{keepMounted:n=!1,...r}=e,{store:i,parent:a}=wy();if(!(i.useState(`mounted`)||n))return null;let o=a.type===`menu`||a.type===`menubar`?`group`:void 0;return(0,U.jsx)(_b.Provider,{value:n,children:(0,U.jsx)(At,{ref:t,...r,portalOwnerRole:o})})});function bb(e){let{children:t,elementsRef:n,labelsRef:r,onMapChange:i}=e,a=H(i),[,o]=W.useState(0),s=fe(Sb).current,c=fe(xb).current,l=W.useRef(0),u=W.useRef(!0),d=W.useRef(null),f=W.useRef(null),p=H(()=>{u.current||(u.current=!0,o(e=>e+1))}),m=H((e,t)=>{c.set(e,t),p()}),h=H(e=>{c.delete(e),p()}),g=H(e=>{let t=new Map;return n.current.length=0,r&&(r.current.length=0),e.forEach(e=>{t.set(e.element,{...e.registration.metadata??{},index:e.index}),n.current[e.index]=e.element,r&&(r.current[e.index]=e.registration.label===void 0?e.registration.textRef?.current?.textContent??e.element.textContent:e.registration.label)}),l.current=n.current.length,t});function _(e){if(f.current?.disconnect(),f.current=null,typeof MutationObserver!=`function`||e.length<2)return;let t=new MutationObserver(n=>{if(!Tb(n))return;let r=null;for(let n of e)if(n.isConnected){if(r&&Eb(r,n)>0){t.disconnect(),p();return}r=n}});f.current=t;let n=new Set;for(let t=1;t<e.length;t+=1){let r=wb(e[t-1],e[t]);r&&n.add(r)}n.forEach(e=>t.observe(e,{childList:!0}))}let v=H(()=>{let[e,t]=Cb(c),n=g(e),r=d.current,i=!r||r.length!==e.length||e.some((e,t)=>{let n=r[t];return e.index!==n.index||e.element!==n.element||e.registration.index!==n.registration.index||e.registration.metadata!==n.registration.metadata});_(t),d.current=e,u.current=!1,i&&(s.forEach(e=>e(n)),a(n))});jt(()=>(!u.current&&d.current&&g(d.current),()=>{n.current=[],r&&(r.current=[])}),[n,r,g]),jt(()=>{u.current&&v()}),jt(()=>()=>{f.current?.disconnect(),u.current=!0},[]);let y=H(e=>(s.add(e),()=>{s.delete(e)})),b=W.useMemo(()=>({register:m,unregister:h,subscribeMapChange:y,nextIndexRef:l}),[m,h,y,l]);return(0,U.jsx)(Ry.Provider,{value:b,children:t})}function xb(){return new Map}function Sb(){return new Set}function Cb(e){let t=new Set,n=[],r=[];e.forEach((e,i)=>{if(!i.isConnected)return;let a=e.index,o={index:a??-1,element:i,registration:e};a===null?r.push(o):a>=0&&(t.add(a),n.push(o))});let i=0;return r.sort((e,t)=>Eb(e.element,t.element)),r.forEach(e=>{for(;t.has(i);)i+=1;e.index=i,n.push(e),i+=1}),t.size>0&&n.sort((e,t)=>e.index-t.index),[n,r.map(e=>e.element)]}function wb(e,t){let n=e.parentElement;for(;n&&!n.contains(t);)n=n.parentElement;return n}function Tb(e){for(let t of e)for(let e=0;e<t.removedNodes.length;e+=1)if(t.removedNodes[e].isConnected)return!0;return!1}function Eb(e,t){return e.nextElementSibling===t?-1:t.nextElementSibling===e?1:e.compareDocumentPosition(t)&Node.DOCUMENT_POSITION_FOLLOWING?-1:1}var Db=W.forwardRef(function(e,t){let{anchor:n,positionMethod:r=`absolute`,className:i,render:a,side:o,align:s,sideOffset:c=0,alignOffset:l=0,collisionBoundary:d=`clipping-ancestors`,collisionPadding:f=5,arrowPadding:p=5,sticky:m=!1,disableAnchorTracking:h=!1,collisionAvoidance:g=lt,style:_,...v}=e,{store:y,virtualFocus:b,syncHighlightedItem:x}=wy(),C=vb(),ee=Ey(!0),w=y.useState(`parent`),T=y.useState(`floatingRootContext`),E=y.useState(`floatingTreeRoot`),D=y.useState(`mounted`),O=y.useState(`open`),k=y.useState(`modal`),A=y.useState(`openMethod`),j=y.useState(`activeTriggerElement`),M=y.useState(`transitionStatus`),N=y.useState(`positionerElement`),te=y.useState(`instantType`),ne=y.useState(`adaptiveOrigin`),re=y.useState(`lastOpenChangeReason`),P=y.useState(`floatingNodeId`),ie=y.useState(`floatingParentNodeId`),ae=T.useState(`domReferenceElement`),F=n,oe=c,se=l,I=s,L=g;w.type===`context-menu`&&(F=n??w.context?.anchor,I??=`start`,!o&&I!==`center`&&(se=e.alignOffset??2,oe=e.sideOffset??-5));let ce=o,R=I;w.type===`menu`?(ce??=`inline-end`,R??=`start`,L=e.collisionAvoidance??Pt):w.type===`menubar`&&(ce??=w.context.orientation===`vertical`?`inline-end`:`bottom`,R??=`start`);let le=w.type===`context-menu`,ue=u({anchor:F,floatingRootContext:T,positionMethod:ee?`fixed`:r,mounted:D,side:ce,sideOffset:oe,align:R,alignOffset:se,arrowPadding:le?0:p,collisionBoundary:d,collisionPadding:f,sticky:m,nodeId:P,keepMounted:C,disableAnchorTracking:h,collisionAvoidance:L,shift:le?{crossAxis:!(`side`in L&&L.side===`flip`),rootBoundary:`layoutViewport`}:void 0,externalTree:E,adaptiveOrigin:ne,lazyFlip:b?`placement`:!1});W.useEffect(()=>{function e(e){e.open&&(e.parentNodeId===P&&y.set(`hoverEnabled`,!1),e.nodeId!==P&&e.parentNodeId===y.select(`floatingParentNodeId`)&&y.setOpen(!1,S(Re)))}return E.events.on(`menuopenchange`,e),()=>{E.events.off(`menuopenchange`,e)}},[y,E.events,P]),W.useEffect(()=>{if(y.select(`floatingParentNodeId`)==null)return;function e(e){if(e.open||e.nodeId!==y.select(`floatingParentNodeId`))return;let t=e.reason??`sibling-open`;y.setOpen(!1,S(t))}return E.events.on(`menuopenchange`,e),()=>{E.events.off(`menuopenchange`,e)}},[E.events,y]);let z=qt();W.useEffect(()=>{O||z.clear()},[O,z]),W.useEffect(()=>{function e(e){if(!(!O||e.nodeId!==y.select(`floatingParentNodeId`))){if(e.target&&j&&j!==e.target){let e=y.select(`closeDelay`);e>0?z.isStarted()||z.start(e,()=>{y.setOpen(!1,S(Re))}):y.setOpen(!1,S(Re))}else z.clear()}}return E.events.on(`itemhover`,e),()=>{E.events.off(`itemhover`,e)}},[E.events,O,j,y,z]),W.useEffect(()=>{let e={open:O,nodeId:P,parentNodeId:ie,reason:y.select(`lastOpenChangeReason`)};E.events.emit(`menuopenchange`,e)},[E.events,O,y,P,ie]),zt({store:y,domReference:ae,positionerElement:N,open:O});let de={open:O,side:ue.side,align:ue.align,anchorHidden:ue.anchorHidden,nested:w.type===`menu`,instant:te},fe=w.type===`menubar`&&w.context.modal;Ht(O&&(fe||k&&re!==`trigger-hover`),A===`touch`,N,j);let me=Le(e,de,{styles:ue.positionerStyles,transitionStatus:M,props:v,refs:[t,y.useStateSetter(`positionerElement`)],hidden:!D,inert:!O}),ge=D&&w.type!==`menu`&&(w.type!==`menubar`&&k&&re!==`trigger-hover`||w.type===`menubar`&&w.context.modal),B=null;return w.type===`menubar`?B=w.context.contentElement:w.type===void 0&&(B=j),(0,U.jsxs)(xy.Provider,{value:ue,children:[ge&&(0,U.jsx)(pe,{ref:w.type===`context-menu`||w.type===`nested-context-menu`?w.context.internalBackdropRef:null,inert:he(!O),cutout:B}),(0,U.jsx)(Nt,{id:P,children:(0,U.jsx)(bb,{elementsRef:y.context.itemDomElements,labelsRef:y.context.itemLabels,onMapChange:x,children:me})})]})}),Ob=W.createContext(null);function kb(e){let t=W.useContext(Ob);if(t===null&&!e)throw Error(Kt(5));return t}function Ab(e){return e==null?Me:e.type.startsWith(`key`)?Qe:e.type.startsWith(`mouse`)||e.type.startsWith(`pointer`)?Ut:Me}var jb={...ce,disabled:e=>e.parent.type===`menubar`&&e.parent.context.disabled||e.disabled,modal:e=>(e.parent.type===void 0||e.parent.type===`context-menu`)&&(e.modal??!0),openMethod:e=>e.openMethod,keyboardOpen:e=>e.keyboardOpen,allowMouseEnter:e=>e.allowMouseEnter,highlightItemOnHover:e=>e.highlightItemOnHover,parent:e=>e.parent,rootId:e=>e.parent.type===`menu`?e.parent.store.select(`rootId`):e.parent.type===void 0?e.rootId:e.parent.context.rootId,activeIndex:e=>e.activeIndex,listElement:e=>e.listElement,triggerControlsId:(e,t)=>{let n=ce.triggerPopupId(e,t);return n?e.listElement?.id||n:void 0},filterTriggerProps:e=>e.filterTriggerProps,inputProps:e=>e.inputProps,webkitAriaSelected:(e,t)=>De&&e.inputFocused&&t?!0:void 0,highlightedItemId:e=>e.highlightedItem?.id||void 0,isActive:(e,t)=>e.activeIndex===t,hoverEnabled:e=>e.hoverEnabled,instantType:e=>e.instantType===`trigger-change`&&!ce.open(e)?void 0:e.instantType,lastOpenChangeReason:e=>e.openChangeReason,floatingTreeRoot:e=>e.parent.type===`menu`?e.parent.store.select(`floatingTreeRoot`):e.floatingTreeRoot,floatingNodeId:e=>e.floatingNodeId,floatingParentNodeId:e=>e.floatingParentNodeId,itemProps:e=>e.itemProps,closeDelay:e=>e.closeDelay,adaptiveOrigin:e=>e.adaptiveOrigin,keyboardEventRelay:e=>{if(e.keyboardEventRelay)return e.keyboardEventRelay;if(e.parent.type===`menu`)return e.parent.store.select(`keyboardEventRelay`)}},Mb=class extends _{constructor(e,t,n=!1){let r=new Gt,i=Pb(r,t,n,e);super(i,Nb(r),jb),this.observe(`parent`,e=>{e.type===`menu`?this.context.allowMouseUpTriggerRef=e.store.context.allowMouseUpTriggerRef:e.type!==void 0&&(this.context.allowMouseUpTriggerRef=e.context.allowMouseUpTriggerRef)})}subscribeToParentMenu(){let e=this.state.parent;if(e.type!==`menu`)return;let t=e.store.select(`rootId`),n=e.store.select(`floatingTreeRoot`),r=e.store.select(`keyboardEventRelay`);return e.store.subscribe(()=>{let i=e.store.select(`rootId`),a=e.store.select(`floatingTreeRoot`),o=e.store.select(`keyboardEventRelay`);(t!==i||n!==a||r!==o)&&(t=i,n=a,r=o,this.notifyAll())})}setOpen(e,t){this.state.floatingRootContext.context.events.emit(`setOpen`,{open:e,eventDetails:t})}setActiveIndex(e,t,n){if(this.state.activeIndex!==e){let r=(e===null?void 0:this.context.itemDomElements.current[e])===this.context.reportedItem;this.context.highlightReason=r?`none`:t,this.context.highlightEvent=r?void 0:n}this.set(`activeIndex`,e)}highlightItem(e,t,n){let r=this.context.itemDomElements.current.indexOf(e);r>-1&&this.setActiveIndex(r,t,n)}};function Nb(e){return{positionerRef:W.createRef(),popupRef:W.createRef(),typingRef:{current:!1},itemDomElements:{current:[]},itemLabels:{current:[]},highlightReason:`none`,highlightEvent:void 0,reportedItem:void 0,allowMouseUpTriggerRef:{current:!1},virtualFocusRef:void 0,triggerFocusTargetRef:W.createRef(),beforeTriggerFocusGuardRef:W.createRef(),beforeContentFocusGuardRef:W.createRef(),onOpenChangeComplete:void 0,triggerElements:e}}function Pb(e,t,n=!1,r){return{...oe(e,t,n),disabled:!1,modal:!0,openMethod:null,keyboardOpen:!1,allowMouseEnter:!1,highlightItemOnHover:!0,parent:{type:void 0},rootId:void 0,activeIndex:null,listElement:null,filterTriggerProps:v,inputProps:v,inputFocused:!1,highlightedItem:void 0,hoverEnabled:!0,instantType:void 0,openChangeReason:null,floatingTreeRoot:new gt,floatingNodeId:void 0,floatingParentNodeId:null,itemProps:v,keyboardEventRelay:void 0,closeDelay:0,adaptiveOrigin:void 0,...r}}var Fb=W.createContext(null);function Ib(e,t){return(e===`trigger-press`||e===`item-press`)&&t?.detail===0}function Lb(e,t){return e===`list-navigation`||Ib(e,t)}var Rb=T(function(e){let{children:t,open:n,onOpenChange:r,onOpenChangeComplete:i,onItemHighlighted:a,defaultOpen:o=!1,disabled:s=!1,modal:l,loopFocus:u=!0,orientation:d=`vertical`,actionsRef:f,closeParentOnEsc:p=!1,handle:m,triggerId:h,defaultTriggerId:g=null,highlightItemOnHover:_=!0,isSubmenu:y=!1,virtualFocus:x=!1,virtualFocusRef:ee,allowEscape:w=!0,resetOnPointerLeave:T=!0}=e,E=Ey(!0),D=wy(!0),O=kb(!0),k=D?.store,A=D?.virtualFocus??!1,M=W.useMemo(()=>y&&k?{type:`menu`,store:k}:O?{type:`menubar`,context:O}:E&&!k?{type:`context-menu`,context:E}:{type:void 0},[E,k,O,y]),N=wt(),ne=wt(),[re,P]=W.useState(void 0),ie=(re??ne)||void 0,F=nt(),oe=M.type===`menu`?M.store:void 0,se=(n??o)&&oe?.state.transitionStatus===`starting`,I=fe(()=>se?oe?.state.instantType:void 0).current,L=fe(()=>{let e=new Mb({open:o,openProp:n,activeTriggerId:g,triggerIdProp:h,parent:M,disabled:s,highlightItemOnHover:_,modal:M.type===void 0?l:void 0,rootId:N,instantType:I},ie,F!=null);return e.context.virtualFocusRef=ee,e}).current;L.useControlledProp(`openProp`,n),L.useControlledProp(`triggerIdProp`,h),L.useContextCallback(`onOpenChangeComplete`,i);let ce=L.useState(`floatingTreeRoot`),le=Dt(ce),z=L.useState(`open`),de=L.useState(`activeTriggerElement`),pe=L.useState(`positionerElement`),me=L.useState(`hoverEnabled`),he=L.useState(`disabled`),ge=L.useState(`lastOpenChangeReason`),B=L.useState(`parent`),_e=L.useState(`activeIndex`),xe=L.useState(`keyboardOpen`),Se=L.useState(`payload`),Ce=L.useState(`floatingParentNodeId`),we=W.useRef(null),Te=W.useRef(B.type!==`context-menu`),Ee=qt(),V=W.useRef(!0),De=qt(),ke=Ce!=null,{openMethod:Ae,triggerProps:Ne}=je(z);L.useSyncedValues({disabled:s,highlightItemOnHover:_,modal:B.type===void 0?l:void 0,openMethod:Ae,rootId:N}),b(L);let{forceUnmount:Pe,transitionStatus:Fe}=j(z,L,()=>{L.set(`allowMouseEnter`,!1)},se),Ie=ye(L.context.popupRef);W.useEffect(()=>{if(I===void 0)return;let e=()=>{L.state.instantType===I&&L.set(`instantType`,void 0)};if(!z){e();return}if(Fe!==void 0)return;if(L.context.popupRef.current==null){e();return}let t=new AbortController;return Ie(e,t.signal),()=>{t.abort()}},[I,z,Fe,Ie,L]),jt(()=>{E&&!D?L.update({parent:{type:`context-menu`,context:E},floatingNodeId:le,floatingParentNodeId:F}):(D||!L.select(`activeTriggerElement`))&&L.update({floatingNodeId:le,floatingParentNodeId:F})},[E,D,le,F,de,L]),W.useEffect(()=>{if(z||(we.current=null),B.type===`context-menu`){if(!z){Ee.clear(),Te.current=!1;return}Ee.start(500,()=>{Te.current=!0})}},[Ee,z,B.type]),jt(()=>{!z&&!me&&L.set(`hoverEnabled`,!0)},[z,me,L]);let Le=H((e,t)=>{let n=t.reason;if(!e&&!L.select(`open`)||z===e&&t.trigger===de&&ge===n)return;let i=C(t);if(!e&&t.trigger==null&&(t.trigger=de??void 0),r?.(e,t),t.isCanceled)return;L.state.floatingRootContext.dispatchOpenChange(e,t);let a=t.event;if(e===!1&&n!==`item-press`&&a?.type===`click`&&a.pointerType===`touch`&&!V.current)return;e&&n===`trigger-focus`?(V.current=!1,De.start(300,()=>{V.current=!0})):(V.current=!0,De.clear());let o=!e&&(n===`escape-key`||n==null);we.current=t.event;let s=be(L.state,e,t.trigger,i());s.openChangeReason=n,s.keyboardOpen=e&&Lb(n,a),s.instantType=B.type===`menubar`&&(n===`trigger-focus`||n===`focus-out`||n===`trigger-hover`||n===`list-navigation`||n===`sibling-open`)?`group`:Ib(n,a)?`click`:o?`dismiss`:void 0,L.update(s)}),Re=Oe({popupStore:L,floatingRootContext:L.state.floatingRootContext,floatingId:ie,nested:F!=null,onOpenChange:Le}),ze=Re.context.events;jt(()=>{let e=({open:e,eventDetails:t})=>Le(e,t);return ze.on(`setOpen`,e),()=>{ze?.off(`setOpen`,e)}},[ze,Le]),jt(()=>L.subscribeToParentMenu(),[L]);let Be=W.useCallback(()=>{L.setOpen(!1,S(yt))},[L]);W.useImperativeHandle(f,()=>({unmount:Pe,close:Be}),[Pe,Be]);let Ve;B.type===`context-menu`&&(Ve=B.context),W.useImperativeHandle(Ve?.positionerRef,()=>pe,[pe]),W.useImperativeHandle(Ve?.actionsRef,()=>({setOpen:Le}),[Le]);let He=ue(Re,{enabled:!he,bubbles:{escapeKey:p&&B.type===`menu`},outsidePress(){return B.type!==`context-menu`||we.current?.type===`contextmenu`||Te.current},externalTree:ke?ce:void 0}),Ue=It(),We=ob(Re,{enabled:!he,listRef:L.context.itemDomElements,activeIndex:_e,virtual:x,nested:B.type===`menubar`||!x&&B.type!==void 0,parentOrientation:B.type===`menubar`?B.context.orientation:void 0,loopFocus:u,focusItemOnOpen:x?xe:void 0,allowEscape:x&&u&&w,orientation:d,triggerOrientation:x?`vertical`:d,rtl:Ue===`rtl`,disabledIndices:R,onNavigate(e,t){L.setActiveIndex(e,Ab(t),t?.nativeEvent)},openOnArrowKeyDown:B.type!==`context-menu`&&!(x&&y),externalTree:!x&&ke?ce:void 0,nestedReturnFocusRef:oe?.context.virtualFocusRef,focusItemOnHover:_,resetOnPointerLeave:T}),Ge=W.useCallback(e=>{L.context.typingRef.current=e},[L]),Ke=sb(Re,{enabled:!he&&!x,listRef:L.context.itemLabels,elementsRef:L.context.itemDomElements,activeIndex:_e,resetMs:500,onMatch:(e,t)=>{z&&e!==_e&&L.setActiveIndex(e,Qe,t.nativeEvent)},onTyping:Ge}),qe=H(a),Je=W.useRef(-1),Ye=H(()=>{let e=L.state.activeIndex,t=e===null?void 0:L.context.itemDomElements.current[e]??void 0;if(t?.isConnected===!1)return;let n=t===void 0?-1:e;if(Je.current===n&&L.context.reportedItem===t)return;Je.current=n,L.context.reportedItem=t,x&&L.set(`highlightedItem`,t);let{highlightReason:r,highlightEvent:i}=L.context;L.context.highlightReason=Me,L.context.highlightEvent=void 0,a&&qe(t,te(r,i,{label:t===void 0?void 0:L.context.itemLabels.current[n]??void 0}))});jt(()=>{Ye()},[_e,Ye]);let Xe=W.useMemo(()=>{if(!x)return We.reference;if(!We.trigger)return v;let{onFocus:e,...t}=We.trigger;return t},[x,We.reference,We.trigger]);L.useSyncedValue(`inputProps`,x?We.reference??v:v);let Ze=W.useMemo(()=>{let e=ae(Ke.reference,Xe,He.reference,{onMouseMove(){L.set(`allowMouseEnter`,!0)}},Ne);return e[`aria-haspopup`]=`menu`,e[`aria-expanded`]=z,e},[L,Ke.reference,Xe,He.reference,Ne,z]),$e=W.useMemo(()=>{let e=ae(We.trigger,He.trigger,Ne);return e[`aria-haspopup`]=`menu`,e[`aria-expanded`]=!1,e},[We.trigger,He.trigger,Ne]);fe(()=>(L.update({inactiveTriggerProps:$e}),null));let et=W.useMemo(()=>ae(c,{onMouseMove(){L.set(`allowMouseEnter`,!0),B.type===`menu`&&L.set(`hoverEnabled`,!1)},onClick(){L.select(`hoverEnabled`)&&L.set(`hoverEnabled`,!1)},onKeyDown(e){let t=L.select(`keyboardEventRelay`);t&&!e.isPropagationStopped()&&t(e)}},Ke.floating,We.floating,He.floating),[B.type,L,Ke.floating,We.floating,He.floating]),tt=We.item??v;xt(L,{floatingRootContext:Re,activeTriggerProps:Ze,inactiveTriggerProps:$e,popupProps:et,itemProps:tt});let rt=W.useMemo(()=>({store:L,parent:M,orientation:d,loopFocus:u,allowEscape:w,defaultFloatingId:ne,setRenderedFloatingId:P,virtualFocus:x,parentVirtualFocus:A,syncHighlightedItem:Ye}),[L,M,d,u,w,ne,x,A,Ye]),it=typeof t==`function`?t({payload:Se}):t,at=(0,U.jsxs)(Cy.Provider,{value:rt,children:[m&&(0,U.jsx)(ve,{handle:m,store:L}),it]});return(B.type===void 0||B.type===`context-menu`)&&(at=(0,U.jsx)(pt,{externalTree:ce,children:at})),at});function zb(e){let t=W.useContext(Fb);if(t===null)return(0,U.jsx)(Rb,{...e});let n=t.Root;return(0,U.jsx)(Fb.Provider,{value:null,children:(0,U.jsx)(n,{...t.options,...e})})}var Bb=5;function Vb(e,t){let n=Hb(t);return e.clientX>=n.left-Bb&&e.clientX<=n.right+Bb&&e.clientY>=n.top-Bb&&e.clientY<=n.bottom+Bb}function Hb(e){let t=e.getBoundingClientRect(),n=et(e);if(A)return t;let r=n.getComputedStyle(e,`::before`),i=n.getComputedStyle(e,`::after`);if(r.content===`none`&&i.content===`none`)return t;let a=parseFloat(r.width)||0,o=parseFloat(r.height)||0,s=parseFloat(i.width)||0,c=parseFloat(i.height)||0,l=Math.max(t.width,a,s),u=Math.max(t.height,o,c),d=l-t.width,f=u-t.height;return{left:t.left-d/2,right:t.right+d/2,top:t.top-f/2,bottom:t.bottom+f/2}}function Ub(e={}){let{highlightItemOnHover:t,highlightedIndex:n,onHighlightedIndexChange:r}=Ue(),{ref:i,index:a}=By(e),o=n===a,s=W.useRef(null),c=re(i,s);return{compositeProps:{tabIndex:o?0:-1,onFocus(){r(a)},onMouseMove(){let e=s.current;if(!t||!e)return;let n=e.hasAttribute(`disabled`)||e.ariaDisabled===`true`;!o&&!n&&e.focus()}},compositeRef:c,index:a}}function Wb(e){let{render:t,className:n,style:r,state:i=v,props:a=R,refs:o=R,metadata:s,stateAttributesMapping:c,tag:l=`div`,...u}=e,{compositeProps:d,compositeRef:f}=Ub({metadata:s});return it(l,e,{state:i,ref:[f,...o],props:[d,...a,u],stateAttributesMapping:c})}function Gb(e){if(mt(e)&&e.hasAttribute(`data-rootownerid`))return e.getAttribute(`data-rootownerid`);if(!Ot(e))return Gb(Tt(e))}function Kb(e){let{enabled:t=!0,mouseDownAction:n,open:r}=e,a=W.useRef(!1);return W.useMemo(()=>t?{onMouseDown:e=>{(n===`open`&&!r||n===`close`&&r)&&(a.current=!0,i(e.currentTarget).addEventListener(`click`,()=>{a.current=!1},{once:!0}))},onClick:e=>{a.current&&(a.current=!1,e.preventBaseUIHandler())}}:v,[t,n,r])}var qb=ne(function(e,t){let{render:r,className:o,style:s,disabled:c=!1,nativeButton:l=!0,id:u,openOnHover:d,delay:f=100,closeDelay:p=0,handle:m,payload:h,...g}=e,_=wy(!0),y=ie(m)??_?.store;if(!y)throw Error(Kt(85));let b=wt(u),x=y.useState(`isTriggerActive`,b),S=y.useState(`floatingRootContext`),C=y.useState(`isOpenedByTrigger`,b),ee=y.useState(`triggerControlsId`,b),w=W.useRef(null),T=Yb(),E=Ue(!0),D=Ie(),O=W.useMemo(()=>D??new gt,[D]),k=Dt(O),A=nt(),{registerTrigger:j,isMountedByThisTrigger:M}=Ce(b,w,y,{payload:h,closeDelay:p,parent:T,floatingTreeRoot:O,floatingNodeId:k,floatingParentNodeId:A,keyboardEventRelay:E?.relayKeyboardEvent}),N=T.type===`menubar`,te=y.useState(`disabled`),ne=c||te||N&&T.context.disabled,{getButtonProps:re,buttonRef:P}=Ae({disabled:ne,native:l});W.useEffect(()=>{!C&&T.type===void 0&&(y.context.allowMouseUpTriggerRef.current=!1)},[y,C,T.type]);let F=W.useRef(null),oe=qt(),I=H(e=>{if(!F.current)return;oe.clear(),y.context.allowMouseUpTriggerRef.current=!1;let t=e.target;se(F.current,t)||se(y.select(`positionerElement`),t)||t===F.current||(t==null||Gb(t)!==y.select(`rootId`))&&(Vb(e,F.current)||O.events.emit(`close`,{domEvent:e,reason:ct}))});W.useEffect(()=>{let e=i(F.current);if(C&&y.select(`lastOpenChangeReason`)===`trigger-hover`)return e.addEventListener(`mouseup`,I,{once:!0}),()=>{e.removeEventListener(`mouseup`,I)}},[C,I,y]);let L=N&&T.context.hasSubmenuOpen,ce=a(S,{enabled:(d??L)&&!ne&&(!N||L&&!M),handleClose:ot({blockPointerEvents:!N}),mouseOnly:!0,move:!1,restMs:T.type===void 0?f:void 0,delay:{close:p},triggerElementRef:w,externalTree:O,isActiveTrigger:x,isClosing:()=>y.select(`transitionStatus`)===`ending`}),R=Jb(C,y.select(`lastOpenChangeReason`)),le=n(S,{enabled:!ne,event:C&&N?`click`:`mousedown`,toggle:!0,ignoreMouse:!1,stickIfOpen:T.type===void 0&&R}),ue=$y(S,{enabled:!ne&&L}),z=Kb({open:C,enabled:N,mouseDownAction:`open`}),de=W.useMemo(()=>ae(ue.reference,le.reference),[ue.reference,le.reference]),fe=y.useState(`triggerProps`,M),pe=y.useState(`filterTriggerProps`),{handlePreFocusGuardFocus:me,handleFocusTargetFocus:he}=Je(y,w),B={disabled:ne,open:C},_e=[F,t,P,j,w],ve=[de,ce??v,fe,{"aria-haspopup":`menu`,"aria-controls":ee,id:b,onMouseDown:e=>{y.select(`open`)||(oe.start(200,()=>{y.context.allowMouseUpTriggerRef.current=!0}),i(e.currentTarget).addEventListener(`mouseup`,I,{once:!0}))}},pe,N?{role:`menuitem`}:{},z,g,re],ye=it(`button`,e,{enabled:!N,stateAttributesMapping:ge,state:B,ref:_e,props:ve});return N?(0,U.jsx)(Wb,{tag:`button`,render:r,className:o,style:s,state:B,refs:_e,props:ve,stateAttributesMapping:ge}):C?(0,U.jsxs)(W.Fragment,{children:[(0,U.jsx)(Wt,{ref:y.context.beforeTriggerFocusGuardRef,onFocus:me},`${b}-pre-focus-guard`),(0,U.jsx)(W.Fragment,{children:ye},b),(0,U.jsx)(Wt,{ref:y.context.triggerFocusTargetRef,onFocus:he},`${b}-post-focus-guard`)]}):(0,U.jsx)(W.Fragment,{children:ye},b)});function Jb(e,t){let n=qt(),[r,i]=W.useState(!1);return jt(()=>{e&&t===`trigger-hover`?(i(!0),n.start(500,()=>{i(!1)})):e||(n.clear(),i(!1))},[e,t,n]),r}function Yb(){let e=kb(!0);return W.useMemo(()=>e?{type:`menubar`,context:e}:{type:void 0},[e])}var Xb=W.forwardRef(function(e,t){let{className:n,render:r,orientation:i=`horizontal`,style:a,...o}=e;return it(`div`,e,{state:{orientation:i},ref:t,props:[{role:`separator`,"aria-orientation":i},o]})}),Zb=(0,W.createContext)(null);function Qb({actionsRef:e,children:t,interactionOwner:n=`local`,onOpenChange:r,...i}){let a=(0,W.useRef)(null),o=e??a;return _t(()=>o.current?.close()),(0,U.jsx)(Zb.Provider,{value:{actionsRef:o,interactionOwner:n},children:(0,U.jsx)(zb,{...i,actionsRef:o,onOpenChange:(e,t)=>{if(n===`host`&&!e&&t.reason===`escape-key`){t.cancel(),t.allowPropagation();return}r?.(e,t)},children:t})})}function $b(){let e=(0,W.useContext)(Zb);if(!e)throw Error(`DropdownMenu parts must be used inside <DropdownMenu>`);return e}var ex=(0,W.forwardRef)(function({className:e,render:t,type:n=`button`,...r},i){return(0,U.jsx)(qb,{...r,className:t=>N(`btn caps-dropdown-trigger`,Ct(e,t)),ref:i,render:t,type:n})}),tx=(0,W.forwardRef)(function({container:e,...t},n){let r=ut(`popover`);return e==null&&r===null?null:(0,U.jsx)(yb,{...t,container:e??r,ref:n})}),nx=(0,W.forwardRef)(function({className:e,collisionBoundary:t,...n},r){let i=ut(`popover`);return(0,U.jsx)(Db,{...n,className:t=>N(`z-(--stipe-layer-popover)`,Ct(e,t)),collisionBoundary:t??(i&&i!==document.body?i:void 0),ref:r})}),rx=(0,W.forwardRef)(function({className:e,finalFocus:t,...n},r){let{interactionOwner:i}=$b(),a=(0,W.useRef)(null);(0,W.useImperativeHandle)(r,()=>a.current);let o=Ze(`.caps-dropdown-item[data-highlighted]`),s=(0,W.useCallback)(e=>{a.current=e,o(e)},[o]);return(0,U.jsx)(gb,{...n,className:t=>N(`caps-dropdown-popup min-w-40 rounded-box border border-base-300 bg-base-100 p-xs shadow-lg outline-none`,Ct(e,t)),finalFocus:i===`host`?!1:t??!0,ref:s})}),ix=(0,W.forwardRef)(function({align:e=`end`,alignOffset:t,children:n,container:r,keepMounted:i,side:a=`bottom`,sideOffset:o=4,...s},c){return(0,U.jsx)(tx,{container:r,keepMounted:i,children:(0,U.jsx)(nx,{align:e,alignOffset:t,side:a,sideOffset:o,children:(0,U.jsx)(rx,{...s,ref:c,children:n})})})}),ax=`caps-dropdown-item flex min-h-2xl w-full items-center gap-sm rounded-field px-md py-xs text-left text-sm outline-none transition-colors hover:bg-base-200 focus-visible:bg-base-200 aria-[current=page]:bg-base-200 aria-[current=page]:font-semibold disabled:cursor-not-allowed disabled:text-base-content/40 data-disabled:cursor-not-allowed data-disabled:text-base-content/40`,ox=(0,W.forwardRef)(function({className:e,onClick:t,onSelect:n,variant:r=`default`,...i},a){return(0,U.jsx)(Zy,{...i,className:t=>N(ax,r===`destructive`&&`text-error hover:bg-error hover:text-error-content focus-visible:bg-error focus-visible:text-error-content`,Ct(e,t)),onClick:e=>{t?.(e),e.defaultPrevented||n?.(e)},ref:a})}),sx=(0,W.forwardRef)(function({children:e,className:t,onClick:n,onSelect:r,...i},a){return(0,U.jsxs)(Gy,{...i,className:e=>N(ax,Ct(t,e)),onClick:e=>{n?.(e),e.defaultPrevented||r?.(e)},ref:a,children:[(0,U.jsx)(`span`,{className:`min-w-0 flex-1`,children:e}),(0,U.jsx)(Ky,{"aria-hidden":`true`,className:`shrink-0`,children:`✓`})]})}),cx=(0,W.forwardRef)(function({className:e,...t},n){return(0,U.jsx)(Xb,{...t,className:t=>N(`my-xs h-px bg-base-300`,Ct(e,t)),ref:n})});(0,W.forwardRef)(function({className:e,...t},n){return(0,U.jsx)(Yy,{...t,className:t=>N(`px-md pb-xs pt-sm text-xs font-semibold text-base-content/60`,Ct(e,t)),ref:n})});export{_m as $,g_ as A,xn as At,Ag as B,an as Bt,k_ as C,Sa as Ct,C_ as D,An as Dt,w_ as E,jn as Et,d_ as F,fn as Ft,Fh as G,Zt as Gt,jg as H,un as Ht,r_ as I,gn as It,Eh as J,jh as K,Qt as Kt,Lg as L,mn as Lt,m_ as M,yn as Mt,p_ as N,bn as Nt,x_ as O,On as Ot,f_ as P,_n as Pt,hm as Q,Rg as R,hn as Rt,A_ as S,mi as St,T_ as T,Un as Tt,Ng as U,ln as Ut,Mg as V,cn as Vt,kg as W,tn as Wt,wh as X,Th as Y,mm as Z,V_ as _,wp as _t,cx as a,em as at,L_ as b,vp as bt,_y as c,tm as ct,Z_ as d,Up as dt,um as et,J_ as f,Bp as ft,H_ as g,$ as gt,U_ as h,Op as ht,ox as i,nm as it,h_ as j,Cn as jt,v_ as k,wn as kt,hy as l,Jp as lt,W_ as m,kp as mt,sx as n,Xp as nt,ex as o,Qp as ot,Y_ as p,Ap as pt,Ah as q,$t as qt,ix as r,Yp as rt,yy as s,Zp as st,Qb as t,cm as tt,Q_ as u,$p as ut,z_ as v,xp as vt,O_ as w,G as wt,M_ as x,dc as xt,R_ as y,yp as yt,Ig as z,sn as zt};
|