@pi-chamber/web 0.1.9 → 0.2.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.
Files changed (79) hide show
  1. package/bin/cli.test.js +48 -0
  2. package/bin/lib/DOCUMENTATION.md +2 -2
  3. package/bin/lib/cli-args.js +38 -11
  4. package/bin/lib/cli-startup.js +60 -13
  5. package/bin/lib/commands-startup.js +20 -5
  6. package/bin/lib/commands-update.js +91 -34
  7. package/bin/lib/commands-update.test.js +57 -42
  8. package/dist/assets/CommitSection-LewzHfDH.js +1 -0
  9. package/dist/assets/DiagramEditor-BOIJVnh3.js +1 -0
  10. package/dist/assets/DiagramView-CdNHezna.js +1 -0
  11. package/dist/assets/{DiffView-k3lX2PiV.js → DiffView-Cmw-RHIH.js} +2 -2
  12. package/dist/assets/{FilesView-C39IOFfs.js → FilesView-BODbL0Xm.js} +6 -6
  13. package/dist/assets/{GitView-CkztSaT7.js → GitView-DqYF-n_h.js} +4 -4
  14. package/dist/assets/JsonTreeView-DzEjA1ht.js +1 -0
  15. package/dist/assets/{MarkdownRendererImpl-CF12jEtB.js → MarkdownRendererImpl-Bfq0bOSM.js} +2 -2
  16. package/dist/assets/PatchDiff-CtVByTC4.js +1 -0
  17. package/dist/assets/{PierreDiffViewer-DSQwk05R.js → PierreDiffViewer-Cwoewmiu.js} +2 -2
  18. package/dist/assets/{useAppFontEffects-DqOhrZWx.js → SessionSwitcherDropdown-DNjCJjzF.js} +97 -97
  19. package/dist/assets/{SettingsView-Bf4vWwVK.js → SettingsView-BtLvHlj4.js} +1 -1
  20. package/dist/assets/SettingsWindow-CPd7JmJs.js +1 -0
  21. package/dist/assets/{ToolOutputDialog-Brg2Humk.js → ToolOutputDialog-CFFC5eI-.js} +6 -6
  22. package/dist/assets/ToolPartDiffPreview-yFq1DKSA.js +8 -0
  23. package/dist/assets/{VirtualizedFileDiff-BELx71mz.js → VirtualizedFileDiff-CC5lTPJS.js} +1 -1
  24. package/dist/assets/collapsible-D_555Hw_.js +1 -0
  25. package/dist/assets/computeVirtualFileMetrics-BcVuV0Ic.js +3 -0
  26. package/dist/assets/contextFileOpenGuard-BygvjHuE.js +1 -0
  27. package/dist/assets/index-C9CLY-is.js +1 -0
  28. package/dist/assets/{index-Dnby-sDS.js → index-DQr8-8RF.js} +2 -2
  29. package/dist/assets/index-DYrJXRkU.css +1 -0
  30. package/dist/assets/isDiffPlainText-Bher0UxW.js +1 -0
  31. package/dist/assets/isFilePlainText-EIViqOlI.js +1 -0
  32. package/dist/assets/main-1bIgjP48.js +2 -0
  33. package/dist/assets/main-JDtt2bQS.js +133 -0
  34. package/dist/assets/{markdownCore-BK98alzY.js → markdownCore-Bm4FxtK1.js} +2 -2
  35. package/dist/assets/miniChat-B7kKqKHH.js +2 -0
  36. package/dist/assets/mobile-DZPRce5z.js +2 -0
  37. package/dist/assets/renderElectronMiniChatApp-Dq0GdThJ.js +1 -0
  38. package/dist/assets/renderMobileApp-DlKnjObC.js +23 -0
  39. package/dist/assets/{runtimeSurface-DMXukysz.js → runtimeSurface-B6sKTjo7.js} +1 -1
  40. package/dist/assets/{useInlineCommentController-ruw8wb2Y.js → useInlineCommentController-CSR_Ju0a.js} +2 -2
  41. package/dist/assets/usePanelSlide-BkonU4LS.js +47 -0
  42. package/dist/assets/{useWindowTitle-qt23iibv.js → useWindowTitle-rt_8xbd9.js} +3 -3
  43. package/dist/assets/{vendor-codemirror-language-data-DVYP3hf_.js → vendor-codemirror-language-data-Be-zDX0u.js} +2 -2
  44. package/dist/assets/{web-components-P2py0R8j.js → web-components-DgFD1Jms.js} +4 -4
  45. package/dist/index.html +4 -4
  46. package/dist/mini-chat.html +3 -3
  47. package/dist/mobile.html +3 -3
  48. package/package.json +1 -1
  49. package/server/lib/package-manager.js +44 -65
  50. package/server/lib/package-manager.test.js +27 -0
  51. package/server/lib/pi/routes.js +6 -0
  52. package/server/lib/pi/routes.test.js +32 -0
  53. package/server/lib/pi/session-daemon/DOCUMENTATION.md +1 -1
  54. package/server/lib/pi/session-daemon/session-daemon.js +11 -4
  55. package/server/lib/pi/session-daemon/session-daemon.test.js +24 -0
  56. package/dist/assets/CommitSection-DSFuOWuL.js +0 -1
  57. package/dist/assets/DiagramEditor-D6W6zeV7.js +0 -1
  58. package/dist/assets/DiagramView-r89Qi5ON.js +0 -1
  59. package/dist/assets/JsonTreeView-C6qt2uIj.js +0 -1
  60. package/dist/assets/PatchDiff-D6In_lUU.js +0 -1
  61. package/dist/assets/SessionSwitcherDropdown-CvE7hsxG.js +0 -1
  62. package/dist/assets/SettingsWindow-B8IV35H4.js +0 -1
  63. package/dist/assets/ToolPartDiffPreview-rlz2ipa2.js +0 -8
  64. package/dist/assets/collapsible-QoPrpZP_.js +0 -1
  65. package/dist/assets/computeVirtualFileMetrics-CInbUZiB.js +0 -3
  66. package/dist/assets/contextFileOpenGuard-BOtkNMZy.js +0 -1
  67. package/dist/assets/index-4sRd3SSM.js +0 -1
  68. package/dist/assets/index-NYG3k04a.css +0 -1
  69. package/dist/assets/isDiffPlainText-BquUayus.js +0 -1
  70. package/dist/assets/isFilePlainText-D4iUTBdr.js +0 -1
  71. package/dist/assets/main-Cp3YZZm1.js +0 -2
  72. package/dist/assets/main-CyshB9VI.js +0 -134
  73. package/dist/assets/miniChat-C_A4lnrT.js +0 -2
  74. package/dist/assets/mobile-2dXx6cUI.js +0 -2
  75. package/dist/assets/renderElectronMiniChatApp-HL15h5xo.js +0 -1
  76. package/dist/assets/renderMobileApp-w6YFCJhq.js +0 -23
  77. package/dist/assets/runtimeEndpointReset-DiVqZFZB.js +0 -46
  78. package/dist/assets/useOpenInAppsStore-DVr2oGEm.js +0 -1
  79. /package/dist/assets/{runtimeEndpointReset-BV3KOtdA.css → usePanelSlide-BV3KOtdA.css} +0 -0
@@ -0,0 +1 @@
1
+ import{dg as M,dV as Q,dW as Fe,dX as Ce,dY as ke,dZ as Ie,d_ as ze,d$ as Ne,e0 as Oe,B as ee,I as te,e1 as Ve}from"./SessionSwitcherDropdown-DNjCJjzF.js";import{a as ie,s as Pe,b as Se,c as ne,d as ve,g as Be,e as re,f as I,h as De,i as Ue,j as _e,k as We,R as Ge,I as je,p as se,l as $e,m as qe,n as Ke,o as Ye,w as Je,q as ae,u as Xe,r as Ze,t as Qe,v as et,x as oe,S as tt,y as it,z as nt,A as rt,B as ye,C as he,F as st}from"./web-components-DgFD1Jms.js";import{G as at,u as ot,W as ht,a as lt,b as dt,n as le,t as ct}from"./Virtualizer-BxW2CJGB.js";import{j as C,r as k,R as L}from"./vendor-react-DYyjh7Q0.js";import{j as ut,i as j,f as A,a as ft,k as de,l as pt,m as ce,d as gt,n as ue,b as mt,o as B,q as fe}from"./computeVirtualFileMetrics-BcVuV0Ic.js";import{a as F,i as K,l as pe,h as Ct,r as St}from"./isFilePlainText-EIViqOlI.js";import{t as H}from"./vendor-hast-util-to-html-BKBhbTDb.js";let vt=-1;var yt=class{options;onRenderUpdate;workerManager;__id=`file-renderer:${++vt}`;highlighter;renderCache;computedLang="text";lineAnnotations={};lineCache;textDoucmentCache=new WeakMap;constructor(i={theme:M},e,t){this.options=i,this.onRenderUpdate=e,this.workerManager=t,t?.isWorkingPool()!==!0&&(this.highlighter=ie(i.theme??M)?ut():void 0)}setOptions(i){this.options=i}mergeOptions(i){this.options={...this.options,...i}}setLineAnnotations(i){this.lineAnnotations={};for(const e of i){const t=this.lineAnnotations[e.lineNumber]??[];this.lineAnnotations[e.lineNumber]=t,t.push(e)}}cleanUp(){this.recycle(),this.workerManager=void 0,this.onRenderUpdate=void 0}recycle(){this.clearRenderCache(),this.highlighter=void 0,this.workerManager?.cleanUpTasks(this),this.lineCache=void 0}clearRenderCache(){const i=this.renderCache;this.renderCache=void 0,i!=null&&i.isDirty===!0&&i.file.cacheKey!=null&&this.workerManager?.evictFileFromCache(i.file.cacheKey)}hydrate(i){const{options:e}=this.getRenderOptions(i),t=$(this.getOrCreateLineCache(i).length,this.getTokenizeMaxLength());let n=this.workerManager?.getFileResultCache(i);n!=null&&!F(e,n.options)&&(n=void 0),this.renderCache??={file:i,options:e,highlighted:!t&&!K(i),result:t?void 0:n?.result,renderRange:void 0},this.workerManager?.isWorkingPool()===!0?this.renderCache.result==null&&!t&&this.workerManager.highlightFileAST(this,i):this.highlighter==null&&(this.computedLang=i.lang??j(i.name),this.initializeHighlighter())}getRenderOptions(i){const e=(()=>{if(this.workerManager?.isWorkingPool()===!0)return this.workerManager.getFileRenderOptions();const{theme:n=M,tokenizeMaxLineLength:r=1e3}=this.options;return{theme:n,useTokenTransformer:Pe(this.options),tokenizeMaxLineLength:r}})(),{renderCache:t}=this;return t?.result==null?{options:e,forceHighlight:!0}:!A(i,t.file)||!F(e,t.options)?{options:e,forceHighlight:!0}:{options:e,forceHighlight:!1}}getOrCreateLineCache(i){if(i.cacheKey==null)return this.lineCache=void 0,pe(i.contents);let{lineCache:e}=this;return(e==null||e.cacheKey!==i.cacheKey)&&(e={cacheKey:i.cacheKey,lines:pe(i.contents)}),this.lineCache=e,e.lines}getLineCount(i){return this.textDoucmentCache.get(i)?.lineCount??this.getOrCreateLineCache(i).length}updateRenderCache(i,e){if(this.renderCache==null)return;const{result:t}=this.renderCache;if(t!=null){for(const[n,r]of i)t.code[n]={type:"element",tagName:"div",properties:{"data-line":n+1,"data-line-type":"context","data-line-index":n},children:r.map(([s,a,o])=>s===0&&a===""?o===""?{type:"element",tagName:"br",properties:{},children:[]}:{type:"text",value:o}:{type:"element",tagName:"span",properties:{"data-char":s,style:`--diffs-token-${e}:${a};`},children:[{type:"text",value:o}]})};t.baseThemeType=e,this.renderCache.isDirty=!0}}applyDocumentChange(i){if(this.renderCache==null)return;const{file:e,result:t}=this.renderCache;if(t!=null&&t.code.length!==i.lineCount){t.code.length=Math.min(t.code.length,i.lineCount);for(let n=t.code.length;n<i.lineCount;n++)t.code.push({type:"element",tagName:"div",properties:{"data-line":n+1,"data-line-type":"context","data-line-index":n},children:[{type:"element",tagName:"span",properties:{"data-char":0},children:[{type:"text",value:i.getLineText(n)}]}]});this.renderCache.isDirty=!0}this.textDoucmentCache.set(e,i)}renderFile(i=this.renderCache?.file,e=Q){if(i==null)return;let{options:t,forceHighlight:n}=this.getRenderOptions(i);const r=this.getMatchingWorkerResultCache(i,t);r!=null&&!this.hasHighlightedRenderCache(i,t)&&(this.renderCache={file:i,highlighted:!0,renderRange:void 0,...r},n=!1),this.renderCache??={file:i,highlighted:!1,options:t,result:void 0,renderRange:void 0};const s=this.getOrCreateLineCache(i),a=i.contents.length>0,o=!a||K(i)||$(s.length,this.getTokenizeMaxLength()),h=!A(i,this.renderCache.file),d=!Se(this.renderCache.renderRange,e);if(this.workerManager?.isWorkingPool()===!0)(o||this.renderCache.result==null||!this.renderCache.highlighted&&(h||d))&&(this.renderCache.file=i,this.renderCache.options=t,this.renderCache.highlighted=!1,(this.renderCache.result==null||h||d||n)&&(this.renderCache.result=this.workerManager.getPlainFileAST(i,e.startingLine,e.totalLines,s)),this.renderCache.renderRange=e),!o&&a&&(!this.renderCache.highlighted||n)&&this.workerManager.highlightFileAST(this,i);else{this.computedLang=i.lang??j(i.name);const l=this.highlighter!=null&&ie(t.theme),c=this.highlighter!=null&&ne(this.computedLang),u=!o&&c;if(this.highlighter!=null&&l&&(n||o||!this.renderCache.highlighted&&u||this.renderCache.result==null)){const{result:p,options:f}=this.renderFileWithHighlighter(i,this.highlighter,o||!c);this.renderCache={file:i,options:f,highlighted:u,result:p,renderRange:void 0}}(!l||!o&&!c)&&this.asyncHighlight(i).then(({result:p,options:f})=>{this.renderCache!=null&&(this.renderCache.highlighted=!1),this.onHighlightSuccess(i,p,f,!o)})}return this.renderCache.result!=null?this.processFileResult(this.renderCache.file,e,this.renderCache.result):void 0}async asyncRender(i,e=Q){const{result:t}=await this.asyncHighlight(i);return this.processFileResult(i,e,t)}async asyncHighlight(i){const e=$(this.getOrCreateLineCache(i).length,this.getTokenizeMaxLength());this.computedLang=e?"text":i.lang??j(i.name);const t=this.highlighter!=null&&Ct(ft(this.options.theme)),n=e||this.highlighter!=null&&ne(this.computedLang);return(this.highlighter==null||!t||!n)&&(this.highlighter=await this.initializeHighlighter()),this.renderFileWithHighlighter(i,this.highlighter,e)}renderFileWithHighlighter(i,e,t=!1){const{options:n}=this.getRenderOptions(i);return{result:St(i,e,n,{forcePlainText:t}),options:n}}processFileResult(i,e,{code:t,themeStyles:n,baseThemeType:r}){const s=this.getLineCount(i),{disableFileHeader:a=!1}=this.options,o=[],h=ue(),d=Math.min(e.startingLine+e.totalLines,s);let l=0;const c=ve(e)?Be(this.lineAnnotations):void 0;c!=null&&(h.children.push(de("context","annotation",1)),o.push(re({hunkIndex:-1,lineIndex:-1,annotations:c.map(u=>I(u))})),l++);for(let u=e.startingLine;u<d;u++){const p=u+1,f=t[u];if(f==null){const g="FileRenderer.processFileResult: Line doesnt exist";throw console.error(g,{name:i.name,lineIndex:u,lineNumber:p}),new Error(g)}h.children.push(pt("context",p,`${u}`)),o.push(f),l++;const S=this.lineAnnotations[p];S!=null&&(h.children.push(de("context","annotation",1)),o.push(re({hunkIndex:0,lineIndex:p,annotations:S.map(g=>I(g))})),l++)}return h.properties.style=`grid-row: span ${l}`,{gutterAST:h.children??[],contentAST:o,preAST:this.createPreElement(s),headerAST:a?void 0:this.renderHeader(i),totalLines:s,rowCount:l,themeStyles:n,baseThemeType:r,bufferBefore:e.bufferBefore,bufferAfter:e.bufferAfter,css:""}}renderHeader(i){const{headerRenderMode:e="default",stickyHeader:t=!1}=this.options;return De({fileOrDiff:i,mode:e,stickyHeader:t})}renderFullHTML(i){return H(this.renderFullAST(i))}renderFullAST(i,e=[]){return e.push(ce({tagName:"code",children:this.renderCodeAST(i),properties:{"data-code":""}})),{...i.preAST,children:e}}renderCodeAST(i){const e=ue();return e.children=i.gutterAST,e.properties.style=`grid-row: span ${i.rowCount}`,[e,Ue(i.contentAST,i.rowCount)]}renderPartialHTML(i,e=!1){return e?H(ce({tagName:"code",children:i,properties:{"data-code":""}})):H(i)}async initializeHighlighter(){return this.highlighter=await gt(_e(this.computedLang,this.options)),this.highlighter}onHighlightSuccess(i,e,t,n=!0){if(this.renderCache==null)return;const r=!A(i,this.renderCache.file)||!this.renderCache.highlighted||!F(t,this.renderCache.options);this.renderCache={file:i,options:t,highlighted:n,result:e,renderRange:void 0},r&&this.onRenderUpdate?.()}getMatchingWorkerResultCache(i,e){const t=this.workerManager?.getFileResultCache(i);if(!(t==null||!F(e,t.options)))return t}hasHighlightedRenderCache(i,e){const{renderCache:t}=this;return t?.result!=null&&t.highlighted&&A(i,t.file)&&F(e,t.options)}onHighlightError(i){console.error(i)}getTokenizeMaxLength(){return this.options.tokenizeMaxLength??1e5}createPreElement(i){const{disableLineNumbers:e=!1,overflow:t="scroll"}=this.options;return We({type:"file",diffIndicators:"none",disableBackground:!0,disableLineNumbers:e,overflow:t,split:!1,totalLines:i})}};function $(i,e){return i>e}function Tt(i,e){return i.lineNumber===e.lineNumber&&i.metadata===e.metadata}function ge(i){return{theme:i?.theme,disableLineNumbers:i?.disableLineNumbers,overflow:i?.overflow,themeType:i?.themeType,collapsed:i?.collapsed,disableFileHeader:i?.disableFileHeader,disableVirtualizationBuffers:i?.disableVirtualizationBuffers,stickyHeader:i?.stickyHeader,preferredHighlighter:i?.preferredHighlighter,useCSSClasses:i?.useCSSClasses,useTokenTransformer:i?.useTokenTransformer,tokenizeMaxLineLength:i?.tokenizeMaxLineLength,tokenizeMaxLength:i?.tokenizeMaxLength,unsafeCSS:i?.unsafeCSS,headerRenderMode:i?.renderCustomHeader!=null?"custom":"default"}}const bt=[""];let Rt=-1;var Te=class{options;workerManager;isContainerManaged;static LoadedCustomComponent=!0;__id=`file:${++Rt}`;type="file";fileContainer;spriteSVG;pre;code;bufferBefore;bufferAfter;themeCSSStyle;appliedThemeCSS;hasAdoptedThemeCSS=!1;unsafeCSSStyle;appliedUnsafeCSS;gutterUtilityContent;errorWrapper;placeHolder;lastRenderedHeaderHTML;cachedHeaderHTML;appliedPreAttributes;lastRowCount;mounted=!1;headerElement;headerCustom;headerPrefix;headerFilenameSuffix;headerMetadata;fileRenderer;resizeManager;interactionManager;annotationCache=new Map;lineAnnotations=[];managersDirty=!1;file;renderRange;enabled=!0;editor;constructor(e={theme:M},t,n=!1){this.options=e,this.workerManager=t,this.isContainerManaged=n,this.fileRenderer=new yt(e,this.handleHighlightRender,this.workerManager),this.resizeManager=new Ge,this.interactionManager=new je("file",se(e)),this.workerManager?.subscribeToThemeChanges(this)}handleHighlightRender=()=>{this.rerender()};rerender(){!this.enabled||this.file==null||this.render({file:this.file,forceRender:!0,renderRange:this.renderRange})}onThemeChange(){this.fileRenderer.clearRenderCache(),this.rerender()}setOptions(e){e!=null&&(this.options=e,this.cachedHeaderHTML=void 0,this.syncInteractionOptions())}syncInteractionOptions(){this.interactionManager.setOptions(se(this.options))}mergeOptions(e){this.options={...this.options,...e}}setThemeType(e){(this.options.themeType??"system")!==e&&(this.mergeOptions({themeType:e}),this.applyCachedThemeState(e))}applyCachedThemeState(e){if(typeof this.options.theme=="string"||this.fileContainer==null||this.appliedThemeCSS==null)return!1;const t=this.appliedThemeCSS.baseThemeType??e;return this.appliedThemeCSS.themeType===t?!1:(this.applyThemeState(this.fileContainer,this.appliedThemeCSS.themeStyles,e,this.appliedThemeCSS.baseThemeType),!0)}hasThemeChanged(){return this.appliedThemeCSS!=null&&!mt(this.appliedThemeCSS.theme,this.options.theme??M)}getHoveredLine=()=>this.interactionManager.getHoveredLine();setLineAnnotations(e){this.lineAnnotations=e}setSelectedLines(e,t){this.interactionManager.setSelection(e,t)}flushManagers(){if(!this.managersDirty||this.pre==null){this.managersDirty=!1;return}const{overflow:e="scroll"}=this.options;this.interactionManager.setup(this.pre),this.resizeManager.setup(this.pre,e==="wrap"),this.managersDirty=!1}cleanUp(e=!1){this.emitPostRender(!0),this.resizeManager.cleanUp(),this.interactionManager.cleanUp(),this.managersDirty=!1,this.workerManager?.unsubscribeToThemeChanges(this),this.renderRange=void 0,this.isContainerManaged||this.fileContainer?.remove(),this.fileContainer=void 0,this.mounted=!1,e||(this.lineAnnotations=[]),this.annotationCache.clear(),this.pre=void 0,this.bufferBefore?.remove(),this.bufferBefore=void 0,this.bufferAfter?.remove(),this.bufferAfter=void 0,this.appliedPreAttributes=void 0,this.lastRowCount=void 0,this.headerElement=void 0,this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0,this.headerCustom=void 0,this.lastRenderedHeaderHTML=void 0,e||(this.cachedHeaderHTML=void 0),this.errorWrapper=void 0,this.themeCSSStyle=void 0,this.appliedThemeCSS=void 0,this.hasAdoptedThemeCSS=!1,this.unsafeCSSStyle=void 0,this.appliedUnsafeCSS=void 0,this.placeHolder=void 0,this.unsafeCSSStyle=void 0,e?this.fileRenderer.recycle():(this.fileRenderer.cleanUp(),this.workerManager=void 0,this.file=void 0),this.enabled=!1,this.editor?.cleanUp(),this.editor=void 0}virtualizedSetup(){this.enabled=!0,this.workerManager?.subscribeToThemeChanges(this)}hydrate(e){const{fileContainer:t,prerenderedHTML:n,preventEmit:r=!1,file:s,lineAnnotations:a}=e;this.hydrateElements(t,n),Lt(this.pre,s,this.options.collapsed)||At(this.headerElement,s,this.options.disableFileHeader)?this.render({...e,preventEmit:!0}):this.hydrationSetup({file:s,lineAnnotations:a}),r||this.emitPostRender()}hydrateElements(e,t){this.fileContainer!==e&&this.emitPostRender(!0),$e(e,t);for(const n of Array.from(e.shadowRoot?.children??[])){if(n instanceof SVGElement){this.spriteSVG=n;continue}if(n instanceof HTMLElement){if(n instanceof HTMLPreElement){this.pre=n,this.appliedPreAttributes=void 0;continue}if(n instanceof HTMLStyleElement&&n.hasAttribute("data-theme-css")){this.themeCSSStyle=n;continue}if(n instanceof HTMLStyleElement&&n.hasAttribute("data-unsafe-css")){this.unsafeCSSStyle=n,this.appliedUnsafeCSS=n.textContent;continue}if("diffsHeader"in n.dataset){this.headerElement=n,this.lastRenderedHeaderHTML=void 0;continue}}}this.pre!=null&&(this.syncCodeNodeFromPre(this.pre),this.pre.removeAttribute("data-dehydrated")),this.fileContainer=e,this.hydrateMeasuredScrollbar()}hydrationSetup({file:e,lineAnnotations:t}){this.lineAnnotations=t??this.lineAnnotations,this.file=e,this.fileRenderer.setOptions(ge(this.options)),this.syncInteractionOptions(),this.pre!=null&&(this.fileRenderer.hydrate(e),this.renderAnnotations(),this.renderGutterUtility(),this.injectUnsafeCSS(),this.managersDirty=!0,this.flushManagers())}getOrCreateLineCache(e=this.file){return e!=null?this.fileRenderer.getOrCreateLineCache(e):bt}updateBuffers(e){this.pre!=null&&this.applyBuffers(this.pre,e)}syncRenderViewToEditor(){const e=this.editor,t=this.fileContainer,n=this.file;e!=null&&t!=null&&n!=null&&this.fileRenderer.initializeHighlighter().then(r=>{e.__syncRenderView(r,t,n,this.lineAnnotations,this.renderRange)})}attachEditor(e){return this.editor?.cleanUp(),this.editor=e,this.interactionManager.setEditorAttached(!0),this.syncRenderViewToEditor(),()=>{this.editor=void 0,this.interactionManager.setEditorAttached(!1)}}applyDocumentChange(e,t){this.fileRenderer.applyDocumentChange(e),t!=null&&t!==this.lineAnnotations&&this.file!=null&&(this.setLineAnnotations(t),this.fileRenderer.setLineAnnotations(this.lineAnnotations),this.renderAnnotations())}updateRenderCache(e,t){this.fileRenderer.updateRenderCache(e,t)}render({file:e,fileContainer:t,forceRender:n=!1,preventEmit:r=!1,containerWrapper:s,deferManagers:a=!1,lineAnnotations:o,renderRange:h}){if(!this.enabled)throw new Error("File.render: attempting to call render after cleaned up");this.editor?.__postponeBackgroundTokenizeToNextFrame();const{collapsed:d=!1,themeType:l="system"}=this.options,c=d?void 0:h,u=this.renderRange,p=this.hasThemeChanged(),f=o!=null&&(o.length>0||this.lineAnnotations.length>0)?o!==this.lineAnnotations:!1,S=!A(this.file,e);if(!d&&!n&&Se(c,this.renderRange)&&!S&&!f&&!p)return this.applyCachedThemeState(l);this.renderRange=c,S&&(this.cachedHeaderHTML=void 0),this.file=e,this.fileRenderer.setOptions(ge(this.options)),this.syncInteractionOptions(),o!=null&&this.setLineAnnotations(o),this.fileRenderer.setLineAnnotations(this.lineAnnotations);const{disableErrorHandling:g=!1,disableFileHeader:y=!1}=this.options;if(y&&(this.headerElement!=null&&(this.headerElement.remove(),this.headerElement=void 0,this.lastRenderedHeaderHTML=void 0),this.clearHeaderSlots()),t=this.getOrCreateFileContainerNode(t,s),this.applyCachedThemeState(l),d){this.removeRenderedCode(),this.clearAuxiliaryNodes();try{const m=this.fileRenderer.renderFile(e,Fe);m!=null&&this.applyThemeState(t,m.themeStyles,l,m.baseThemeType),m?.headerAST!=null&&this.applyHeaderToDOM(m.headerAST,t),this.injectUnsafeCSS()}catch(m){if(g)throw m;console.error(m),m instanceof Error&&this.applyErrorToDOM(m,t)}return r||this.emitPostRender(),!0}try{const m=this.getOrCreatePreNode(t);if(!this.canPartiallyRender(n,f,S||p)||!this.applyPartialRender(u,c)){const v=this.fileRenderer.renderFile(e,c);if(v==null)return this.workerManager?.isInitialized()===!1&&this.workerManager.initialize().then(()=>this.rerender()),!1;this.applyThemeState(t,v.themeStyles,l,v.baseThemeType),v.headerAST!=null&&this.applyHeaderToDOM(v.headerAST,t),this.applyFullRender(v,m)}this.applyBuffers(m,c),this.injectUnsafeCSS(),this.managersDirty=!0,a||this.flushManagers(),this.renderAnnotations(),this.renderGutterUtility(),this.editor!=null&&this.syncRenderViewToEditor()}catch(m){if(g)throw m;console.error(m),m instanceof Error&&this.applyErrorToDOM(m,t)}return r||this.emitPostRender(),!0}emitPostRender(e=!1){const{fileContainer:t,options:{onPostRender:n}}=this;if(e){if(!this.mounted||(this.mounted=!1,t==null))return;n?.(t,this,"unmount");return}if(t==null)return;const r=this.mounted?"update":"mount";this.mounted=!0,n?.(t,this,r)}removeRenderedCode(){this.resizeManager.cleanUp(),this.interactionManager.cleanUp(),this.bufferBefore?.remove(),this.bufferBefore=void 0,this.bufferAfter?.remove(),this.bufferAfter=void 0,this.code?.remove(),this.code=void 0,this.pre?.remove(),this.pre=void 0,this.appliedPreAttributes=void 0,this.lastRowCount=void 0}clearAuxiliaryNodes(){for(const{element:e}of this.annotationCache.values())e.remove();this.annotationCache.clear(),this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0}canPartiallyRender(e,t,n){return!(e||t||n)}renderPlaceholder(e){if(this.fileContainer==null)return!1;if(this.emitPostRender(!0),this.cleanChildNodes(),this.placeHolder==null){const t=this.fileContainer.shadowRoot??this.fileContainer.attachShadow({mode:"open"});this.placeHolder=document.createElement("div"),this.placeHolder.dataset.placeholder="",t.appendChild(this.placeHolder)}return this.placeHolder.style.setProperty("height",`${e}px`),!0}primeHighlightCache(){const{file:e,workerManager:t}=this;e==null||e.cacheKey==null||t==null||K(e)||this.fileRenderer.getOrCreateLineCache(e).length>(this.options.tokenizeMaxLength??1e5)||t.primeFileHighlightCache(e)}cleanChildNodes(){this.resizeManager.cleanUp(),this.interactionManager.cleanUp(),this.bufferAfter?.remove(),this.bufferBefore?.remove(),this.code?.remove(),this.errorWrapper?.remove(),this.headerElement?.remove(),this.gutterUtilityContent?.remove(),this.headerPrefix?.remove(),this.headerFilenameSuffix?.remove(),this.headerMetadata?.remove(),this.headerCustom?.remove(),this.pre?.remove(),this.spriteSVG?.remove(),this.themeCSSStyle?.remove(),this.unsafeCSSStyle?.remove(),this.bufferAfter=void 0,this.bufferBefore=void 0,this.code=void 0,this.errorWrapper=void 0,this.headerElement=void 0,this.gutterUtilityContent=void 0,this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0,this.headerCustom=void 0,this.pre=void 0,this.spriteSVG=void 0,this.themeCSSStyle=void 0,this.appliedThemeCSS=void 0,this.hasAdoptedThemeCSS=!1,this.unsafeCSSStyle=void 0,this.appliedUnsafeCSS=void 0,this.lastRenderedHeaderHTML=void 0,this.lastRowCount=void 0,this.mounted=!1}renderAnnotations(){if(this.isContainerManaged||this.fileContainer==null){for(const{element:n}of this.annotationCache.values())n.remove();this.annotationCache.clear();return}const e=new Map(this.annotationCache),{renderAnnotation:t}=this.options;if(t!=null&&this.lineAnnotations.length>0)for(const[n,r]of this.lineAnnotations.entries()){const s=`${n}-${I(r)}`;let a=this.annotationCache.get(s);if(a==null||!Tt(r,a.annotation)){a?.element.remove();const o=t(r);if(o==null)continue;a={element:qe(I(r)),annotation:r},a.element.appendChild(o),this.fileContainer.appendChild(a.element),this.annotationCache.set(s,a)}e.delete(s)}for(const[n,{element:r}]of e.entries())this.annotationCache.delete(n),r.remove()}renderGutterUtility(){const{renderGutterUtility:e}=this.options;if(this.fileContainer==null||e==null){this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0;return}const t=e(this.interactionManager.getHoveredLine);if(t!=null&&this.gutterUtilityContent!=null)return;if(t==null){this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0;return}const n=Ke();n.appendChild(t),this.fileContainer.appendChild(n),this.gutterUtilityContent=n}injectUnsafeCSS(){const{unsafeCSS:e}=this.options,t=this.fileContainer?.shadowRoot;if(t!=null){if(e==null||e===""){this.unsafeCSSStyle!=null&&(this.unsafeCSSStyle.remove(),this.unsafeCSSStyle=void 0),this.appliedUnsafeCSS=void 0;return}this.unsafeCSSStyle?.parentNode===t&&this.appliedUnsafeCSS===e||(this.unsafeCSSStyle??=Ye(),this.unsafeCSSStyle.parentNode!==t&&t.appendChild(this.unsafeCSSStyle),this.unsafeCSSStyle.textContent=Je(e),this.appliedUnsafeCSS=e)}}applyThemeState(e,t,n,r){const s=e.shadowRoot??e.attachShadow({mode:"open"}),a=r??n,o=this.options.theme??M,h=typeof o=="string"?o:{...o},d=ae(s);if(this.themeCSSStyle?.parentNode===s&&this.appliedThemeCSS?.themeStyles===t&&this.appliedThemeCSS.themeType===a&&this.appliedThemeCSS.scrollbarGutter===d){this.appliedThemeCSS.theme=h;return}if(this.hasAdoptedThemeCSS&&this.themeCSSStyle?.parentNode===s){this.hasAdoptedThemeCSS=!1,this.appliedThemeCSS={theme:h,themeStyles:t,themeType:a,baseThemeType:r,scrollbarGutter:d};return}this.themeCSSStyle=Xe({shadowRoot:s,currentNode:this.themeCSSStyle,themeCSS:Ze(t,a,d)}),this.appliedThemeCSS=this.themeCSSStyle!=null?{theme:h,themeStyles:t,themeType:a,baseThemeType:r,scrollbarGutter:d}:void 0}hydrateMeasuredScrollbar(){const e=this.fileContainer?.shadowRoot;e==null||this.themeCSSStyle==null||(this.themeCSSStyle.textContent=Qe(this.themeCSSStyle.textContent??"",ae(e)))}applyFullRender(e,t){this.cleanupErrorWrapper(),this.applyPreNodeAttributes(t,e),this.code=et({code:this.code});const n=this.fileRenderer.renderCodeAST(e);if(this.code.childElementCount>=2)for(let r=0;r<2;r++){const s=this.code.children[r],a=n[r];s.innerHTML=H(a.children),s.style.cssText=a.properties.style}else this.code.innerHTML=H(n);t.contains(this.code)||t.replaceChildren(this.code),this.lastRowCount=e.rowCount}applyPartialRender(e,t){if(e==null||t==null)return!1;const{file:n,code:r}=this,s=r!=null?this.getColumns(r):void 0;if(n==null||r==null||s==null)return!1;const a=e.startingLine,o=t.startingLine,h=e.totalLines===1/0?Number.POSITIVE_INFINITY:a+e.totalLines,d=t.totalLines===1/0?Number.POSITIVE_INFINITY:o+t.totalLines,l=Math.max(a,o),c=Math.min(h,d);if(c<=l||!this.trimDOMToOverlap(s.gutter,l,c)||!this.trimDOMToOverlap(s.content,l,c))return!1;let{length:u}=s.content.children;const p=(y,m)=>{if(!(m<=0))return this.fileRenderer.renderFile(n,{startingLine:y,totalLines:m,bufferBefore:0,bufferAfter:0})},f=o<l?p(o,l-o):void 0;if(f===void 0&&o<l)return!1;const S=d===Number.POSITIVE_INFINITY?Number.POSITIVE_INFINITY:Math.max(0,d-c),g=d>c?p(c,S):void 0;return g===void 0&&d>c?!1:(this.cleanupErrorWrapper(),f!=null&&(s.gutter.insertAdjacentHTML("afterbegin",this.fileRenderer.renderPartialHTML(f.gutterAST)),s.content.insertAdjacentHTML("afterbegin",this.fileRenderer.renderPartialHTML(f.contentAST)),u+=f.rowCount),g!=null&&(s.gutter.insertAdjacentHTML("beforeend",this.fileRenderer.renderPartialHTML(g.gutterAST)),s.content.insertAdjacentHTML("beforeend",this.fileRenderer.renderPartialHTML(g.contentAST)),u+=g.rowCount),this.lastRowCount!==u&&(s.gutter.style.setProperty("grid-row",`span ${u}`),s.content.style.setProperty("grid-row",`span ${u}`),this.lastRowCount=u),!0)}getColumns(e){const t=e.children[0],n=e.children[1];if(!(!(t instanceof HTMLElement)||!(n instanceof HTMLElement)||t.dataset.gutter==null||n.dataset.content==null))return{gutter:t,content:n}}trimDOMToOverlap(e,t,n){const r=this.getDOMBoundaryIndices(e,[t,n]),s=r.get(t)??e.children.length,a=r.get(n)??e.children.length;if(s>a)return!1;for(let o=e.children.length-1;o>=a;o-=1)e.children[o]?.remove();for(let o=s-1;o>=0;o-=1)e.children[o]?.remove();return!0}getDOMBoundaryIndices(e,t){const n=[...new Set(t)].sort((h,d)=>h-d),r=new Map;if(n.length===0)return r;let s=0,a=n[s];const{children:o}=e;a===0&&(r.set(0,0),s+=1,a=n[s]);for(let h=0;h<o.length;h+=1){const d=o[h];if(!(d instanceof HTMLElement))continue;const l=this.getLineIndexFromDOMNode(d);if(l!=null){for(;a!=null&&l>=a;)r.set(a,h),s+=1,a=n[s];if(s>=n.length)break}}for(const h of n)r.has(h)||r.set(h,o.length);return r}getLineIndexFromDOMNode(e){const t=e.dataset.lineIndex;if(t==null)return;const n=Number(t);return Number.isNaN(n)?void 0:n}applyBuffers(e,t){if(t==null||this.shouldDisableVirtualizationBuffers()){this.bufferBefore!=null&&(this.bufferBefore.remove(),this.bufferBefore=void 0),this.bufferAfter!=null&&(this.bufferAfter.remove(),this.bufferAfter=void 0);return}t.bufferBefore>0?(this.bufferBefore==null&&(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==null&&(this.bufferAfter=document.createElement("div"),this.bufferAfter.dataset.virtualizerBuffer="after",e.after(this.bufferAfter)),this.bufferAfter.style.setProperty("height",`${t.bufferAfter}px`),this.bufferAfter.style.setProperty("contain","strict")):this.bufferAfter!=null&&(this.bufferAfter.remove(),this.bufferAfter=void 0)}shouldDisableVirtualizationBuffers(){return this.options.disableVirtualizationBuffers??!1}applyHeaderToDOM(e,t){const{file:n}=this;if(n==null)return;this.cleanupErrorWrapper(),this.placeHolder?.remove(),this.placeHolder=void 0;const r=this.cachedHeaderHTML??H(e);if(this.cachedHeaderHTML=r,r!==this.lastRenderedHeaderHTML){const d=document.createElement("div");d.innerHTML=r;const l=d.firstElementChild;if(!(l instanceof HTMLElement))return;this.headerElement!=null?t.shadowRoot?.replaceChild(l,this.headerElement):t.shadowRoot?.prepend(l),this.headerElement=l,this.lastRenderedHeaderHTML=r}if(this.isContainerManaged)return;const{renderHeaderPrefix:s,renderHeaderFilenameSuffix:a,renderCustomHeader:o,renderHeaderMetadata:h}=this.options;if(o!=null){const d=o(n)??void 0;this.headerCustom=this.upsertHeaderSlotElement(t,this.headerCustom,Ce,d),this.headerPrefix?.remove(),this.headerFilenameSuffix?.remove(),this.headerMetadata?.remove(),this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0}else{const d=s?.(n)??void 0,l=a?.(n)??void 0,c=h?.(n)??void 0;this.headerPrefix=this.upsertHeaderSlotElement(t,this.headerPrefix,ke,d),this.headerFilenameSuffix=this.upsertHeaderSlotElement(t,this.headerFilenameSuffix,Ie,l),this.headerMetadata=this.upsertHeaderSlotElement(t,this.headerMetadata,ze,c),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}const s=t??this.createHeaderSlotElement(n);return t==null&&e.appendChild(s),this.replaceHeaderSlotContent(s,r),s}replaceHeaderSlotContent(e,t){e.replaceChildren(),t instanceof Element?e.appendChild(t):e.innerText=`${t}`}createHeaderSlotElement(e){const t=document.createElement("div");return t.slot=e,t}getOrCreateFileContainerNode(e,t){const{fileContainer:n}=this,r=e??n??document.createElement("diffs-container"),s=n!==r;return s&&this.emitPostRender(!0),this.fileContainer=r,n!=null&&s&&(this.lastRenderedHeaderHTML=void 0,this.headerElement=void 0),t!=null&&this.fileContainer.parentNode!==t&&t.appendChild(this.fileContainer),s&&this.adoptReusableShellElements(this.fileContainer),this.ensureSpriteSVG(this.fileContainer),this.fileContainer}adoptReusableShellElements(e){const{shadowRoot:t}=e;if(t!=null)for(const n of t.children)n instanceof SVGElement?this.spriteSVG??=n:oe(n)&&n.hasAttribute("data-theme-css")?(this.themeCSSStyle??=n,this.hasAdoptedThemeCSS=!0):oe(n)&&n.hasAttribute("data-unsafe-css")&&(this.unsafeCSSStyle??=n,this.appliedUnsafeCSS??=this.options.unsafeCSS??void 0)}ensureSpriteSVG(e){const t=e.shadowRoot??e.attachShadow({mode:"open"});if(this.spriteSVG==null){const n=document.createElement("div");n.innerHTML=tt;const r=n.firstChild;r instanceof SVGElement&&(this.spriteSVG=r)}this.spriteSVG!=null&&this.spriteSVG.parentNode!==t&&t.appendChild(this.spriteSVG)}getOrCreatePreNode(e){const t=e.shadowRoot??e.attachShadow({mode:"open"});return this.pre==null?(this.pre=document.createElement("pre"),this.appliedPreAttributes=void 0,this.code=void 0,t.appendChild(this.pre)):this.pre.parentNode!==t&&(e.shadowRoot?.appendChild(this.pre),this.appliedPreAttributes=void 0),this.placeHolder?.remove(),this.placeHolder=void 0,this.pre}syncCodeNodeFromPre(e){this.code=void 0;for(const t of Array.from(e.children))if(t instanceof HTMLElement&&t.hasAttribute("data-code")){this.code=t;return}}applyPreNodeAttributes(e,{totalLines:t}){const{overflow:n="scroll",disableLineNumbers:r=!1}=this.options,s={type:"file",split:!1,overflow:n,disableLineNumbers:r,diffIndicators:"none",disableBackground:!0,totalLines:t};it(s,this.appliedPreAttributes)||(nt(e,s),this.appliedPreAttributes=s)}applyErrorToDOM(e,t){this.cleanupErrorWrapper(),this.pre?.remove(),this.pre=void 0,this.appliedPreAttributes=void 0;const n=t.shadowRoot??t.attachShadow({mode:"open"});this.errorWrapper??=document.createElement("div"),this.errorWrapper.dataset.errorWrapper="",this.errorWrapper.textContent="",n.appendChild(this.errorWrapper);const r=document.createElement("div");r.dataset.errorMessage="",r.innerText=e.message,this.errorWrapper.appendChild(r);const s=document.createElement("pre");s.dataset.errorStack="",s.innerText=e.stack??"No Error Stack",this.errorWrapper.appendChild(s)}cleanupErrorWrapper(){this.errorWrapper?.remove(),this.errorWrapper=void 0}};function Lt(i,e,t=!1){return!t&&i==null&&e!=null}function At(i,e,t=!1){return i==null&&e!=null&&!t}const Mt=5e3;let Ht=-1;function xt(i,e){return(i.overflow??"scroll")!==(e.overflow??"scroll")||(i.collapsed??!1)!==(e.collapsed??!1)||(i.disableLineNumbers??!1)!==(e.disableLineNumbers??!1)||(i.disableFileHeader??!1)!==(e.disableFileHeader??!1)||i.unsafeCSS!==e.unsafeCSS}var wt=class extends Te{virtualizer;metrics;__id=`virtualized-file:${++Ht}`;top;height=0;cache={heights:new Map,checkpoints:[],fileAnnotationHeight:0};isVisible=!1;isSetup=!1;layoutDirty=!0;forceRenderOverride;currentCollapsed;constructor(i,e,t=Ne,n,r=!1){super(i,n,r),this.virtualizer=e,this.metrics=t}setMetrics(i,e=!1){!e&&rt(this.metrics,i)||(this.metrics=i,this.resetLayoutCache())}setLineAnnotations(i){this.syncLineAnnotations(i)&&this.resetLayoutCache()}syncLineAnnotations(i){return i==null||i===this.lineAnnotations||i.length===0&&this.lineAnnotations.length===0?!1:(super.setLineAnnotations(i),!0)}hasLineAnnotations(){return this.lineAnnotations.some(i=>i.lineNumber>0)}getLineHeight(i,e=!1){const t=this.cache.heights.get(i);if(t!=null)return t;const n=e?2:1;return this.metrics.lineHeight*n}setOptions(i){if(this.isAdvancedMode())throw new Error("VirtualizedFile.setOptions cannot be used inside CodeView. Update CodeView options instead.");if(i==null)return;const{options:e}=this,t=!ye(e,i),n=xt(e,i);super.setOptions(i),n&&this.resetLayoutCache(!0),t&&(this.forceRenderOverride=!0),t&&this.virtualizer.instanceChanged(this,n)}setThemeType(i){if(this.isAdvancedMode())throw new Error("VirtualizedFile.setThemeType cannot be used inside CodeView. Update CodeView options instead.");super.setThemeType(i)}resetLayoutCache(i=!1){this.layoutDirty=!0,this.cache.fileAnnotationHeight=0,this.cache.heights.size>0&&this.cache.heights.clear(),this.cache.checkpoints.length>0&&(this.cache.checkpoints.length=0),this.renderRange!=null&&(this.renderRange=void 0),i&&this.isSimpleMode()&&this.computeApproximateSize()}reconcileHeights(){let i=!1;if(this.fileContainer==null||this.file==null)return this.height!==0&&(i=!0),this.height=0,i;const{overflow:e="scroll"}=this.options;if(this.top=this.getVirtualizedTop(),e==="scroll"&&this.lineAnnotations.length===0&&!this.isResizeDebuggingEnabled()||this.code==null)return i;const t=this.code.children[1];if(!(t instanceof HTMLElement))return i;const n=he(this.lineAnnotations);if(this.renderRange!=null&&n&&ve(this.renderRange)){const r=Et(t)??0;r!==this.cache.fileAnnotationHeight&&(this.cache.fileAnnotationHeight=r,i=!0)}else!n&&this.cache.fileAnnotationHeight!==0&&(this.cache.fileAnnotationHeight=0,i=!0);for(const r of t.children){if(!(r instanceof HTMLElement))continue;const s=r.dataset.lineIndex;if(s==null)continue;const a=Number(s);let o=r.getBoundingClientRect().height,h=!1;r.nextElementSibling instanceof HTMLElement&&("lineAnnotation"in r.nextElementSibling.dataset||"noNewline"in r.nextElementSibling.dataset)&&("noNewline"in r.nextElementSibling.dataset&&(h=!0),o+=r.nextElementSibling.getBoundingClientRect().height);const d=this.getLineHeight(a,h);o!==d&&(i=!0,o===this.metrics.lineHeight*(h?2:1)?this.cache.heights.delete(a):this.cache.heights.set(a,o))}return(i||this.isResizeDebuggingEnabled())&&this.computeApproximateSize(!0),i}onRender=i=>this.fileContainer==null||this.file==null?!1:(i&&(this.top=this.getVirtualizedTop()),this.render({file:this.file}));prepareCodeViewItem(i,e,t,n){const r=this.syncLineAnnotations(n);let s=t?.resetFileLayoutCache===!0||r;t?.metrics!=null&&(this.metrics=t.metrics,s=!0);const{collapsed:a=!1}=this.options;return this.currentCollapsed!==a&&(this.currentCollapsed=a,s=!0),s&&this.resetLayoutCache(),this.file!==i&&(this.layoutDirty=!0),this.file=i,this.top=e,this.computeApproximateSize(),this.height}getLinePosition(i){if(this.file==null||i<1)return;const{disableFileHeader:e=!1,collapsed:t=!1}=this.options,n=this.fileRenderer.getLineCount(this.file)-1;let r=B(this.metrics,e);if(t||n<0)return{top:r,height:0};const s=Math.min(Math.max(i-1,0),n),{overflow:a="scroll"}=this.options,{lineHeight:o}=this.metrics;if(r+=this.cache.fileAnnotationHeight,a==="scroll"&&!this.hasLineAnnotations())return{top:r+s*o,height:o};const h=this.getLayoutCheckpointBeforeLineIndex(s);r=h?.top??r;for(let d=h?.lineIndex??0;d<s;d++)r+=this.getLineHeight(d,!1);return{top:r,height:this.getLineHeight(s,!1)}}getNumericScrollAnchor(i){if(this.file==null||this.renderRange==null)return;const{disableFileHeader:e=!1,collapsed:t=!1,overflow:n="scroll"}=this.options;if(t||this.renderRange.totalLines<=0)return;const r=this.fileRenderer.getLineCount(this.file)-1;if(r<0)return;const s=B(this.metrics,e),a=Math.min(this.renderRange.startingLine,r),o=Math.min(a+this.renderRange.totalLines-1,r);if(o<a)return;const{fileAnnotationHeight:h}=this.cache;if(n==="scroll"&&!this.hasLineAnnotations()){const{lineHeight:l}=this.metrics,c=s+(a===0?h:this.renderRange.bufferBefore),u=a+Math.max(Math.ceil((i-c)/l),0);return u>o?void 0:{lineNumber:u+1,top:s+h+u*l}}let d=s+(a===0?h:this.renderRange.bufferBefore);for(let l=a;l<=o;l++){if(d>=i)return{lineNumber:l+1,top:d};d+=this.getLineHeight(l)}}getVirtualizedHeight(){return this.height}getAdvancedStickySpecs(i){if(this.top==null||this.file==null)return;if(this.options.collapsed===!0)return{topOffset:this.top,height:this.height};const e=i!=null?this.computeRenderRangeFromWindow(this.file,this.top,i):this.renderRange;if(e==null)return;const{bufferBefore:t,bufferAfter:n,totalLines:r}=e;let s=0;if(r===0){const a=i??this.virtualizer.getWindowSpecs();this.top<a.top&&(s=n)}return{topOffset:this.top+t+s,height:this.height-(t+n)}}cleanUp(i=!1){this.fileContainer!=null&&this.isSimpleMode()&&this.getSimpleVirtualizer()?.disconnect(this.fileContainer),i||this.resetLayoutCache(),this.isSetup=!1,super.cleanUp(i)}computeApproximateSize(i=!1){const e=this.isResizeDebuggingEnabled();if(!i&&!this.layoutDirty&&!e)return;const t=this.height===0;if(this.height=0,this.cache.checkpoints=[],this.file==null){this.layoutDirty=!1;return}const{disableFileHeader:n=!1,collapsed:r=!1,overflow:s="scroll"}=this.options,{lineHeight:a}=this.metrics,o=this.fileRenderer.getLineCount(this.file),h=B(this.metrics,n),d=fe(this.metrics);if(this.height+=h,r){this.layoutDirty=!1;return}if(this.height+=this.cache.fileAnnotationHeight,s==="scroll"&&!this.hasLineAnnotations())this.height+=o*a;else for(let l=0;l<o;l++)this.addLayoutCheckpoint(l,this.height),this.height+=this.getLineHeight(l,!1);if(o>0&&(this.height+=d),this.fileContainer!=null&&e&&!t){const l=this.fileContainer.getBoundingClientRect();l.height!==this.height?console.log("VirtualizedFile.computeApproximateSize: computed height doesnt match",{name:this.file.name,elementHeight:l.height,computedHeight:this.height}):console.log("VirtualizedFile.computeApproximateSize: computed height IS CORRECT")}this.layoutDirty=!1}setVisibility(i){this.isAdvancedMode()||this.fileContainer==null||(i&&!this.isVisible?(this.top=this.getVirtualizedTop(),this.isVisible=!0):!i&&this.isVisible&&(this.isVisible=!1,this.rerender()))}rerender(){!this.enabled||this.file==null||(this.forceRenderOverride=!0,this.virtualizer.instanceChanged(this,!1))}applyDocumentChange(i,e,t=!1){const{heights:n,checkpoints:r}=this.cache,s=this.renderRange;if(super.applyDocumentChange(i,e),this.getSimpleVirtualizer()?.markDOMDirty(),this.layoutDirty=!0,n.size>0&&n.clear(),r.length>0&&(r.length=0),this.isSimpleMode()&&this.computeApproximateSize(),t&&s!==void 0&&this.file!==void 0){const a=this.virtualizer.getWindowSpecs(),o=this.computeRenderRangeFromWindow(this.file,this.top??0,a);o.bufferAfter!==s.bufferAfter&&this.updateBuffers(o)}}render({fileContainer:i,file:e,forceRender:t=!1,lineAnnotations:n,...r}){const s=this.file==null||!A(this.file,e),{forceRenderOverride:a,isSetup:o}=this;this.forceRenderOverride=void 0;const h=this.syncLineAnnotations(n);if(h&&this.resetLayoutCache(),this.file=e,i=this.getOrCreateFileContainerNode(i),this.file==null)return console.error("VirtualizedFile.render: attempting to virtually render when we dont have file"),!1;if(o)this.top??=this.getVirtualizedTop(),s&&this.isSimpleMode()&&(this.getSimpleVirtualizer()?.markDOMDirty(),this.resetLayoutCache(!0));else{this.computeApproximateSize();const u=this.getSimpleVirtualizer();if(this.top??=this.getVirtualizedTop(),this.isAdvancedMode())this.isVisible=!0;else{if(u==null)throw new Error("VirtualizedFile.render: simple virtualizer is not available");u.connect(i,this),this.isVisible=u.isInstanceVisible(this.top??0,this.height)}this.isSetup=!0}if(!this.isVisible&&this.isSimpleMode())return this.renderPlaceholder(this.height);const d=this.virtualizer.getWindowSpecs(),l=this.top??0,c=this.computeRenderRangeFromWindow(this.file,l,d);return super.render({file:this.file,fileContainer:i,renderRange:c,lineAnnotations:n,forceRender:(a??t)||h,...r})}syncVirtualizedTop(){this.top=this.getVirtualizedTop()}shouldDisableVirtualizationBuffers(){return this.isAdvancedMode()||super.shouldDisableVirtualizationBuffers()}isSimpleMode(){return this.virtualizer.type==="simple"}isAdvancedMode(){return this.virtualizer.type==="advanced"}addLayoutCheckpoint(i,e){i%Mt===0&&this.cache.checkpoints.push({lineIndex:i,top:e})}getLayoutCheckpointBeforeLineIndex(i){if(i<=0||this.cache.checkpoints.length===0)return;let e=0,t=this.cache.checkpoints.length-1,n;for(;e<=t;){const r=e+t>>1,s=this.cache.checkpoints[r];if(s==null)throw new Error("VirtualizedFile: invalid checkpoint index");s.lineIndex<=i?(n=s,e=r+1):t=r-1}return n}getLayoutCheckpointBeforeTop(i,e){let t=0,n=this.cache.checkpoints.length-1,r=-1;for(;t<=n;){const s=t+n>>1,a=this.cache.checkpoints[s];if(a==null)throw new Error("VirtualizedFile: invalid checkpoint index");a.top<=i?(r=s,t=s+1):n=s-1}if(e==null)return r>=0?this.cache.checkpoints[r]:void 0;for(let s=r;s>=0;s--){const a=this.cache.checkpoints[s];if(a==null)throw new Error("VirtualizedFile: invalid checkpoint index");if(a.lineIndex%e===0)return a}}getVirtualizedTop(){return this.virtualizer.type==="advanced"?this.virtualizer.getLocalTopForInstance(this):this.fileContainer!=null?this.virtualizer.getOffsetInScrollContainer(this.fileContainer):0}getSimpleVirtualizer(){return this.virtualizer.type==="simple"?this.virtualizer:void 0}isResizeDebuggingEnabled(){return this.getSimpleVirtualizer()?.config.resizeDebugging??!1}computeRenderRangeFromWindow(i,e,{top:t,bottom:n}){const{disableFileHeader:r=!1,overflow:s="scroll"}=this.options,{hunkLineCount:a,lineHeight:o}=this.metrics,h=this.fileRenderer.getLineCount(i),d=this.height,l=B(this.metrics,r),c=h>0?fe(this.metrics):0,{fileAnnotationHeight:u}=this.cache,p=l+u,f=Math.max(0,d-l-u-c),S=he(this.lineAnnotations),g=e+l,y=u>0&&S&&g<n&&g+u>t;if(e<t-d||e>n)return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:d-l-c};if(h<=a)return{startingLine:0,totalLines:a,bufferBefore:0,bufferAfter:0};const m=Math.ceil(Math.max(n-t,0)/o),v=Math.ceil(m/a)*a+a*2,z=v/a,D=(t+n)/2;if(s==="scroll"&&!this.hasLineAnnotations()){const R=e+p,P=R+f;if(!y&&!(R<n&&P>t))return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:d-l-c};const w=Math.floor(y&&D<e+p?0:(D-(e+p))/o),b=Math.floor(w/a)-Math.floor(z/2),xe=Math.ceil(h/a),E=Math.max(0,Math.min(b,xe))*a,Z=b<0?v+b*a:v,we=E===0?0:u+E*o,Ee=Math.min(Z,h-E);return{startingLine:E,totalLines:Z,bufferBefore:we,bufferAfter:Math.max(0,(h-E-Ee)*o)}}const be=z,N=[],U=this.getLayoutCheckpointBeforeTop(Math.max(0,t-e-v*o*2),a);let T=e+(U?.top??p),_=U?.lineIndex??0,O,V,x;const Re=U?.lineIndex??0;for(let R=Re;R<h;R++){const P=_%a===0,w=Math.floor(_/a);if(P&&(N[w]=T-(e+p),x!=null)){if(x<=0)break;x--}const b=this.getLineHeight(R,!1);T>t-b&&T<n&&(O??=w),T+b>D&&(V??=w),x==null&&T>=n&&P&&(x=be),_++,T+=b}if(O==null)if(y)O=0,V=0;else return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:d-l-c};V??=O;const W=Math.round(V-z/2),Le=Math.max(0,Math.ceil(h/a)-z),G=Math.max(0,Math.min(W,Le)),Y=G*a,J=W<0?v+W*a:v,Ae=N[G]??0,Me=Y===0?0:u+Ae,X=G+J/a,He=X<N.length?f-N[X]:f-(T-e-p);return{startingLine:Y,totalLines:J,bufferBefore:Me,bufferAfter:Math.max(0,He)}}};function Et(i){let e;for(const t of i.children)t instanceof HTMLElement&&t.dataset.lineAnnotation===st&&(e=Math.max(e??0,t.getBoundingClientRect().height));return e}function Ft({file:i,renderCustomHeader:e,renderHeaderPrefix:t,renderHeaderFilenameSuffix:n,renderHeaderMetadata:r,renderAnnotation:s,lineAnnotations:a,renderGutterUtility:o,getHoveredLine:h}){const d=e?.(i),l=t?.(i),c=n?.(i),u=r?.(i);return C.jsxs(C.Fragment,{children:[d!=null?C.jsx("div",{slot:Ce,children:d}):C.jsxs(C.Fragment,{children:[l!=null&&C.jsx("div",{slot:"header-prefix",children:l}),c!=null&&C.jsx("div",{slot:"header-filename-suffix",children:c}),u!=null&&C.jsx("div",{slot:"header-metadata",children:u})]}),s!=null&&a?.map((p,f)=>C.jsx("div",{slot:I(p),children:s(p)},f)),o!=null&&C.jsx("div",{slot:"gutter-utility-slot",style:at,children:o(h)})]})}const me=typeof window>"u"?k.useEffect:k.useLayoutEffect;function kt({file:i,options:e,lineAnnotations:t,selectedLines:n,prerenderedHTML:r,metrics:s,hasGutterRenderUtility:a,hasCustomHeader:o,disableWorkerPool:h,contentEditable:d}){const l=ot(),c=n!==void 0,u=k.useContext(ht),p=lt(),f=k.useRef(null),S=dt(g=>{if(g!=null){if(f.current!=null)throw new Error("File: An instance should not already exist when a node is created");l!=null?f.current=new wt(q({controlledSelection:c,contentEditable:d,hasCustomHeader:o,hasEditor:p!==void 0,hasGutterRenderUtility:a,options:e}),l,s,h?void 0:u,!0):f.current=new Te(q({controlledSelection:c,contentEditable:d,hasCustomHeader:o,hasEditor:p!==void 0,hasGutterRenderUtility:a,options:e}),h?void 0:u,!0),f.current.hydrate({file:i,fileContainer:g,lineAnnotations:t,prerenderedHTML:r})}else{if(f.current==null)throw new Error("File: A File instance should exist when unmounting");f.current.cleanUp(),f.current=null}});return me(()=>{if(f.current==null)return;const g=q({controlledSelection:c,contentEditable:d,hasCustomHeader:o,hasEditor:p!==void 0,hasGutterRenderUtility:a,options:e}),y=!ye(f.current.options,g);f.current.setOptions(g),f.current.render({file:i,lineAnnotations:t,forceRender:y}),n!==void 0&&f.current.setSelectedLines(n)}),me(()=>{if(d&&f.current!=null){if(p===void 0)throw new Error("File: Editor is not attached");return p.edit(f.current)}},[d,p]),{ref:S,getHoveredLine:k.useCallback(()=>f.current?.getHoveredLine(),[])}}function q({options:i,controlledSelection:e,contentEditable:t,hasCustomHeader:n,hasEditor:r,hasGutterRenderUtility:s}){const a=t&&r,o=e||s||n;if(!o&&!a)return i;let h={...i};return o&&(h={...h,controlledSelection:e,renderCustomHeader:n?le:i?.renderCustomHeader,renderGutterUtility:s?le:i?.renderGutterUtility}),a&&(h={...h,useTokenTransformer:!0,enableGutterUtility:!1,enableLineSelection:!1,lineHoverHighlight:"disabled"}),h}function Ut({file:i,lineAnnotations:e,selectedLines:t,options:n,metrics:r,className:s,style:a,renderAnnotation:o,renderCustomHeader:h,renderHeaderPrefix:d,renderHeaderFilenameSuffix:l,renderHeaderMetadata:c,prerenderedHTML:u,renderGutterUtility:p,disableWorkerPool:f=!1,contentEditable:S=!1}){const{ref:g,getHoveredLine:y}=kt({file:i,options:n,metrics:r,lineAnnotations:e,selectedLines:t,prerenderedHTML:u,hasGutterRenderUtility:p!=null,hasCustomHeader:h!=null,disableWorkerPool:f,contentEditable:S});return C.jsx(Oe,{ref:g,className:s,style:a,children:ct(Ft({file:i,renderAnnotation:o,renderCustomHeader:h,renderHeaderPrefix:d,renderHeaderFilenameSuffix:l,renderHeaderMetadata:c,renderGutterUtility:p,lineAnnotations:e,getHoveredLine:y}),u)})}const _t=L.memo(function({jsonString:e,className:t,maxHeight:n="100%",initiallyExpandedDepth:r=2}){const s=L.useRef(null),[a,o]=L.useState(null),h=L.useMemo(()=>{try{const c=e.trim();if(!c)return o("Empty JSON content"),null;const u=JSON.parse(c);return o(null),u}catch(c){return o(c instanceof Error?c.message:"Invalid JSON"),null}},[e]),d=L.useCallback(()=>{s.current?.expandAll()},[]),l=L.useCallback(()=>{s.current?.collapseAll()},[]);return a?C.jsx("div",{className:t,children:C.jsxs("div",{className:"rounded-md border border-[var(--interactive-border)] bg-[var(--syntax-base-background)] p-4",children:[C.jsx("div",{className:"mb-1 font-medium text-[var(--surface-foreground)]",children:"Invalid JSON"}),C.jsx("div",{className:"font-mono text-xs text-[var(--surface-mutedForeground)]",children:a})]})}):h===null?null:C.jsxs("div",{className:t,children:[C.jsxs("div",{className:"flex items-center gap-1 border-b border-[var(--interactive-border)] px-2 py-1",children:[C.jsxs(ee,{variant:"ghost",size:"xs",onClick:d,className:"gap-1 text-xs text-muted-foreground",children:[C.jsx(te,{name:"arrow-down-s",className:"h-3 w-3"}),"Expand All"]}),C.jsxs(ee,{variant:"ghost",size:"xs",onClick:l,className:"gap-1 text-xs text-muted-foreground",children:[C.jsx(te,{name:"arrow-up-s",className:"h-3 w-3"}),"Collapse All"]})]}),C.jsx("div",{className:"bg-[var(--syntax-base-background)] py-1",style:{maxHeight:n,overflow:"auto"},children:C.jsx(Ve,{ref:s,data:h,maxHeight:n,initiallyExpandedDepth:r})})]})});export{Ut as F,_t as J};
@@ -1,4 +1,4 @@
1
- import{R as y,j as _}from"./vendor-react-DYyjh7Q0.js";import{m as Ke}from"./vendor-morphdom-B7dS_VPB.js";import{r as Ue,a as Ze}from"./vendor-beautiful-mermaid-r4GK_usS.js";import{dd as ve,de as Xe,df as Ge,aB as H,b_ as Ye,b$ as Je,dg as Qe,dh as et,K as ke,L as Ce,di as Ee,f as X,dj as tt,by as rt,o as ot,dk as te,dl as nt,dm as at,dn as it}from"./useAppFontEffects-DqOhrZWx.js";import{B as re,bq as st,u as T,V as oe,x as lt,y as ct,r as dt}from"./index-Dnby-sDS.js";import{i as mt}from"./runtimeSurface-DMXukysz.js";import{r as ut,s as pt,i as ft,a as ht,b as gt}from"./markdownCore-BK98alzY.js";import{r as bt}from"./registerCustomTheme-BBXUCRnG.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-elkjs-CRCLNXjf.js";import"./vendor-entities-C3BA0AJP.js";import"./vendor-zustand-CnsBKjP5.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-base-ui-DwfTg5wD.js";import"./vendor-floating-ui-utils-BzXdqYpP.js";import"./vendor-floating-ui-react-dom-sVFnuruh.js";import"./vendor-floating-ui-dom-Bkw82kL9.js";import"./vendor-floating-ui-core-CXmKXOXc.js";import"./vendor-use-sync-external-store-B7OScDIw.js";import"./vendor-dnd-kit-core-GipZW2tY.js";import"./vendor-dnd-kit-utilities-CrOcp0Bp.js";import"./vendor-dnd-kit-accessibility-Cv52zwWT.js";import"./vendor-dnd-kit-sortable-Ct2QxIHb.js";import"./vendor-cmdk-BCEUzcHE.js";import"./vendor-radix-ui-react-dialog-jX3Dld8c.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-D1GnwnP9.js";import"./vendor-radix-ui-react-context-CM4yFQ2I.js";import"./vendor-radix-ui-react-id-BcxRjnbX.js";import"./vendor-radix-ui-react-use-layout-effect-0fyGwS2_.js";import"./vendor-radix-ui-react-use-controllable-state-C_ecoh35.js";import"./vendor-radix-ui-react-dismissable-layer-M7LsH3yL.js";import"./vendor-radix-ui-react-primitive-CfpW6_IT.js";import"./vendor-radix-ui-react-slot-BxUc3Pvz.js";import"./vendor-radix-ui-react-use-callback-ref-UKEWHtoP.js";import"./vendor-radix-ui-react-use-escape-keydown-Co13lHGj.js";import"./vendor-radix-ui-react-focus-scope-C2K7lNPv.js";import"./vendor-radix-ui-react-portal-xlJWBfDg.js";import"./vendor-radix-ui-react-presence-Btn-Dp7L.js";import"./vendor-radix-ui-react-focus-guards-D5MZ0nQs.js";import"./vendor-react-remove-scroll-CfeMe0DL.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-C9YRs2nU.js";import"./vendor-react-style-singleton-B1H4bWSG.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-C-AuTczP.js";import"./vendor-use-callback-ref-CJB0R85I.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-BuDklWi8.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-codemirror-state-Wdz6Qsow.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-view-pXtfpqbT.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-CrbeaEAU.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-3xMyV7a2.js";import"./vendor-codemirror-lang-json-BTvAjwkJ.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-C4jEScp7.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-C1Svvdey.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-BloD9GN-.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-DVYP3hf_.js";import"./vendor-codemirror-lang-python-CR2g6ukK.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-Bzf12ODH.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-tanstack-react-virtual-IrbCBGJ4.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-framer-motion-DJASDzNt.js";import"./vendor-motion-dom-DJLgZh4Q.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-sonner-dWA7qvjr.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-marked-i_gIkIP3.js";import"./vendor-katex-CHD9BdDO.js";import"./vendor-dompurify-r8glNMJW.js";import"./vendor-remend-BWYYytN3.js";import"./themeResolver-BmJyTmjJ.js";import"./vendor-pierre-theming-C6Z4M5_u.js";import"./vendor-shikijs-core-CGM_jqPK.js";import"./vendor-shikijs-types-CPSbSeK6.js";import"./vendor-shikijs-vscode-textmate-BgLrS_2D.js";import"./vendor-hast-util-to-html-BKBhbTDb.js";import"./vendor-html-void-elements-CkdplsNl.js";import"./vendor-property-information-rJCbAzvX.js";import"./vendor-zwitch-C2o2j-tx.js";import"./vendor-stringify-entities-CsH1VEn9.js";import"./vendor-character-entities-legacy-BpoLgcEt.js";import"./vendor-character-entities-html4-D7taRCQ7.js";import"./vendor-ccount-c2V3InAJ.js";import"./vendor-comma-separated-tokens-D8TqSuIK.js";import"./vendor-space-separated-tokens-DD3iYX1K.js";import"./vendor-hast-util-whitespace-D4Wp6AEg.js";const Le="pichamber-md",wt={name:Le,colors:{"editor.background":"transparent","editor.foreground":"var(--md-syntax-foreground)"},tokenColors:[{scope:["comment","punctuation.definition.comment","string.comment"],settings:{foreground:"var(--md-syntax-comment)",fontStyle:"italic"}},{scope:["string","punctuation.definition.string","string.template"],settings:{foreground:"var(--md-syntax-string)"}},{scope:["constant.numeric","constant.language","constant.character","constant"],settings:{foreground:"var(--md-syntax-number)"}},{scope:["keyword","storage","storage.type","storage.modifier","keyword.control"],settings:{foreground:"var(--md-syntax-keyword)"}},{scope:["keyword.operator","punctuation.separator","punctuation.terminator"],settings:{foreground:"var(--md-syntax-operator)"}},{scope:["entity.name.function","support.function","meta.function-call"],settings:{foreground:"var(--md-syntax-function)"}},{scope:["entity.name.type","entity.name.class","support.type","support.class","entity.other.inherited-class"],settings:{foreground:"var(--md-syntax-type)"}},{scope:["variable","variable.other","variable.parameter","meta.definition.variable"],settings:{foreground:"var(--md-syntax-variable)"}},{scope:["variable.other.property","meta.property-name","support.type.property-name"],settings:{foreground:"var(--md-syntax-property)"}},{scope:["entity.name.tag","punctuation.definition.tag"],settings:{foreground:"var(--md-syntax-keyword)"}},{scope:["entity.other.attribute-name"],settings:{foreground:"var(--md-syntax-property)"}},{scope:["markup.bold","punctuation.definition.bold"],settings:{fontStyle:"bold"}},{scope:["markup.italic","punctuation.definition.italic"],settings:{fontStyle:"italic"}},{scope:["markup.heading","markup.heading entity.name"],settings:{foreground:"var(--md-syntax-keyword)",fontStyle:"bold"}},{scope:["markup.inserted","punctuation.definition.inserted"],settings:{foreground:"var(--md-syntax-inserted)"}},{scope:["markup.deleted","punctuation.definition.deleted"],settings:{foreground:"var(--md-syntax-deleted)"}},{scope:["invalid","invalid.illegal"],settings:{foreground:"var(--md-syntax-deleted)"}}]};let ne=!1;const yt=()=>{ne||(ne=!0,bt(Le,()=>Promise.resolve(wt)))},k=t=>Number.isFinite(t)&&t>0,ae=t=>{if(typeof t=="number")return k(t)?t:null;if(typeof t!="string")return null;const e=t.trim().match(/^([+-]?(?:(?:\d+\.?\d*)|(?:\.\d+))(?:[eE][+-]?\d+)?)(?:px)?$/);if(!e)return null;const o=Number(e[1]);return k(o)?o:null},V=(t,e,o)=>Math.min(o,Math.max(e,t)),At=6,ie=1.25,vt=1.0015,kt=.5,Ct=12,se=3,Et=400,F='[data-markdown="mermaid-block"]',S=t=>t.querySelector(F)!==null,Lt=t=>[t.x,t.y,t.width,t.height].map(e=>{const o=Number(e.toFixed(At));return Object.is(o,-0)?"0":String(o)}).join(" "),St=t=>{const e=t.viewBox?.trim().split(/[\s,]+/).map(s=>Number.parseFloat(s));if(e?.length===4){const[s,n,a,i]=e;if(Number.isFinite(s)&&Number.isFinite(n)&&k(a)&&k(i))return{x:s,y:n,width:a,height:i}}const o=ae(t.width),r=ae(t.height);return o===null||r===null?null:{x:0,y:0,width:o,height:r}},Mt=t=>{let e=2166136261;for(let o=0;o<t.length;o+=1)e^=t.charCodeAt(o),e=Math.imul(e,16777619);return(e>>>0).toString(36)},Nt=t=>{const e=t.renderMode||"unknown",o=t.svgMarkup??"";if(!o){const r=[t.viewBox??"",t.width??"",t.height??""];return r.some(s=>s!=="")?`${e}:bounds:${r.join(":")}`:`${e}:no-svg`}return[e,Mt(o)].join(":")},Se=(t,e)=>{if(!k(e.width)||!k(e.height))return t;const o=t.width/t.height,r=e.width/e.height;if(o>r){const n=t.width/r;return{x:t.x,y:t.y-(n-t.height)/2,width:t.width,height:n}}const s=t.height*r;return{x:t.x-(s-t.width)/2,y:t.y,width:s,height:t.height}},xt=({currentBox:t,viewport:e,delta:o})=>!k(e.width)||!k(e.height)||!k(t.width)||!k(t.height)?t:{x:t.x-o.x/e.width*t.width,y:t.y-o.y/e.height*t.height,width:t.width,height:t.height},Tt=(t,e)=>{const o=e.x-t.x,r=e.y-t.y;return o*o+r*r>se*se},Pt=({currentBox:t,contentBox:e,viewport:o,pointer:r,zoomFactor:s,minScale:n,maxScale:a})=>{if(!k(o.width)||!k(o.height)||!k(s)||!k(t.width)||!k(t.height)||!k(e.width)||!k(e.height)||!k(n)||!k(a))return t;const i=Math.min(n,a),l=Math.max(n,a),d=Se(e,o),c=d.width/t.width,p=V(c*s,i,l),u=d.width/p,f=u/(t.width/t.height),h=V(r.x/o.width,0,1),A=V(r.y/o.height,0,1),v=t.x+h*t.width,w=t.y+A*t.height;return{x:v-h*u,y:w-A*f,width:u,height:f}},G=new WeakMap,Rt=t=>t instanceof HTMLElement?G.get(t)??null:null,It=t=>t.querySelector('[data-markdown="mermaid-viewport"]')??t.querySelector('[data-markdown="mermaid"]'),le=t=>{const e=t.querySelector('[data-markdown="mermaid"] svg'),o=t.querySelector('[data-markdown="mermaid"]');return Nt({renderMode:t.getAttribute("data-mermaid-render"),svgMarkup:o?.getAttribute("data-md-original-svg")??e?.outerHTML??null,viewBox:e?.getAttribute("viewBox"),width:e?.getAttribute("width"),height:e?.getAttribute("height")})},I=t=>{const e=t.getBoundingClientRect();return{width:e.width,height:e.height}},_t=(t,e)=>{const o=e.getBoundingClientRect();return{x:t.clientX-o.left,y:t.clientY-o.top}},Ft=t=>t instanceof Element&&!!t.closest('button, a, [role="button"]'),Ot=t=>{const e=It(t),o=t.querySelector('[data-markdown="mermaid"] svg');if(!e||!o)return null;const r=St({viewBox:o.getAttribute("viewBox"),width:o.getAttribute("width"),height:o.getAttribute("height")});if(!r)return null;let s=r,n=null,a=null,i=null,l=null;const d=m=>{s=m,o.setAttribute("viewBox",Lt(m)),o.removeAttribute("width"),o.removeAttribute("height")},c=()=>{d(Se(r,I(e)))},p=(m,C)=>{d(Pt({currentBox:s,contentBox:r,viewport:I(e),pointer:m,zoomFactor:C,minScale:kt,maxScale:Ct}))},u=()=>{const m=I(e);p({x:m.width/2,y:m.height/2},ie)},f=()=>{const m=I(e);p({x:m.width/2,y:m.height/2},1/ie)},h=m=>{!m.ctrlKey&&!m.metaKey||(m.preventDefault(),m.stopPropagation(),p(_t(m,e),Math.pow(vt,-m.deltaY)))},A=m=>{m.button!==0||Ft(m.target)||(n=m.pointerId,a={x:m.clientX,y:m.clientY},i=a,l!==null&&(window.clearTimeout(l),l=null),t.removeAttribute("data-mermaid-suppress-click"),e.setPointerCapture?.(m.pointerId),t.setAttribute("data-mermaid-panning","true"),m.preventDefault())},v=m=>{if(n!==m.pointerId||!i)return;const C={x:m.clientX,y:m.clientY};d(xt({currentBox:s,viewport:I(e),delta:{x:C.x-i.x,y:C.y-i.y}})),i=C,a&&Tt(a,C)&&t.setAttribute("data-mermaid-suppress-click","true"),m.preventDefault()},w=m=>{n===m.pointerId&&(e.releasePointerCapture?.(m.pointerId),n=null,a=null,i=null,t.removeAttribute("data-mermaid-panning"),t.hasAttribute("data-mermaid-suppress-click")&&(l=window.setTimeout(()=>{t.removeAttribute("data-mermaid-suppress-click"),l=null},Et)))},g=()=>{c()};e.addEventListener("wheel",h,{passive:!1}),e.addEventListener("pointerdown",A),e.addEventListener("pointermove",v),e.addEventListener("pointerup",w),e.addEventListener("pointercancel",w),window.addEventListener("resize",g);const b=typeof ResizeObserver>"u"?null:new ResizeObserver(g);return b?.observe(e),c(),{zoomIn:u,zoomOut:f,fit:c,cleanup:()=>{e.removeEventListener("wheel",h),e.removeEventListener("pointerdown",A),e.removeEventListener("pointermove",v),e.removeEventListener("pointerup",w),e.removeEventListener("pointercancel",w),window.removeEventListener("resize",g),b?.disconnect(),l!==null&&window.clearTimeout(l),t.removeAttribute("data-mermaid-panning"),t.removeAttribute("data-mermaid-suppress-click"),G.delete(t)}}},Dt=t=>{const e=new Map,o=new Map,r=()=>{for(const[n,a]of Array.from(e.entries())){const i=le(n);(!t.contains(n)||i!==o.get(n))&&(a.cleanup(),e.delete(n),o.delete(n))}for(const n of Array.from(t.querySelectorAll(F))){if(e.has(n)||n.querySelector('[data-markdown="mermaid"] svg')===null)continue;const a=Ot(n);a&&(e.set(n,a),o.set(n,le(n)),G.set(n,a))}},s=()=>{for(const n of e.values())n.cleanup();e.clear(),o.clear()};return r(),{refresh:r,cleanup:s}},M=t=>`<svg class="remixicon size-3.5" viewBox="0 0 24 24" aria-hidden="true"><use href="#oc-${t}"></use></svg>`,q={copy:M("file-copy"),check:M("check"),download:M("download"),zoomIn:M("add"),zoomOut:M("subtract"),fit:M("refresh"),textWrap:M("text-wrap")},Me="p-1 rounded hover:bg-interactive-hover/60 text-muted-foreground hover:text-foreground transition-colors focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[var(--interactive-focus-ring)]",B=(t,e)=>{t.innerHTML=e},L=(t,e,o)=>{const r=document.createElement("button");return r.type="button",r.className=Me,r.setAttribute("data-md-action",o),r.setAttribute("title",e),r.setAttribute("aria-label",e),B(r,q[t]),r},Ne=(t,e,o)=>{const r=t.querySelector("[data-md-code-body]"),s=t.querySelector("pre"),n=t.querySelector("pre code"),a=t.querySelectorAll("[data-md-code-line-content]"),i=t.querySelector('[data-md-action="toggle-code-wrap"]');t.setAttribute("data-code-wrap",e?"true":"false"),r?.classList.toggle("overflow-x-auto",!e),r?.classList.toggle("overflow-x-hidden",e),s?.classList.toggle("whitespace-pre-wrap",e),s?.classList.toggle("break-words",e),n?.classList.toggle("whitespace-pre-wrap",e),n?.classList.toggle("break-words",e),s&&(s.style.whiteSpace=e?"pre-wrap":"pre",s.style.overflowWrap=e?"anywhere":"normal"),n&&(n.style.whiteSpace=e?"pre-wrap":"pre",n.style.overflowWrap=e?"anywhere":"normal");for(const l of Array.from(a))l.style.whiteSpace=e?"pre-wrap":"pre",l.style.overflowWrap=e?"anywhere":"normal";if(i){const l=e?o.disableCodeWrap:o.enableCodeWrap;i.setAttribute("title",l),i.setAttribute("aria-label",l),i.classList.toggle("text-foreground",e),i.classList.toggle("opacity-100",e),i.classList.toggle("text-muted-foreground",!e),i.classList.toggle("opacity-65",!e),i.setAttribute("aria-pressed",e?"true":"false")}},xe=t=>{const e=t.querySelector(":scope > code");if(!e||e.hasAttribute("data-md-code-lines"))return;const o=e.textContent??"",r=o.endsWith(`
1
+ import{R as y,j as _}from"./vendor-react-DYyjh7Q0.js";import{m as Ve}from"./vendor-morphdom-B7dS_VPB.js";import{r as Ue,a as Ze}from"./vendor-beautiful-mermaid-r4GK_usS.js";import{dh as ve,di as Xe,dj as Ge,az as H,bM as Ye,bN as Je,dk as Qe,dl as et,K as ke,L as Ce,dm as Ee,f as X,dn as tt,bj as rt,o as ot,dp as te,dq as nt,dr as at,ds as it}from"./SessionSwitcherDropdown-DNjCJjzF.js";import{a1 as re,br as st,u as T,M as oe,K as lt,R as ct,r as dt}from"./index-DQr8-8RF.js";import{i as mt}from"./runtimeSurface-B6sKTjo7.js";import{r as ut,s as pt,i as ft,a as ht,b as gt}from"./markdownCore-Bm4FxtK1.js";import{r as bt}from"./registerCustomTheme-BBXUCRnG.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-elkjs-CRCLNXjf.js";import"./vendor-entities-C3BA0AJP.js";import"./vendor-zustand-CnsBKjP5.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-dnd-kit-core-GipZW2tY.js";import"./vendor-dnd-kit-utilities-CrOcp0Bp.js";import"./vendor-dnd-kit-accessibility-Cv52zwWT.js";import"./vendor-dnd-kit-sortable-Ct2QxIHb.js";import"./vendor-base-ui-DwfTg5wD.js";import"./vendor-floating-ui-utils-BzXdqYpP.js";import"./vendor-floating-ui-react-dom-sVFnuruh.js";import"./vendor-floating-ui-dom-Bkw82kL9.js";import"./vendor-floating-ui-core-CXmKXOXc.js";import"./vendor-use-sync-external-store-B7OScDIw.js";import"./vendor-cmdk-BCEUzcHE.js";import"./vendor-radix-ui-react-dialog-jX3Dld8c.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-D1GnwnP9.js";import"./vendor-radix-ui-react-context-CM4yFQ2I.js";import"./vendor-radix-ui-react-id-BcxRjnbX.js";import"./vendor-radix-ui-react-use-layout-effect-0fyGwS2_.js";import"./vendor-radix-ui-react-use-controllable-state-C_ecoh35.js";import"./vendor-radix-ui-react-dismissable-layer-M7LsH3yL.js";import"./vendor-radix-ui-react-primitive-CfpW6_IT.js";import"./vendor-radix-ui-react-slot-BxUc3Pvz.js";import"./vendor-radix-ui-react-use-callback-ref-UKEWHtoP.js";import"./vendor-radix-ui-react-use-escape-keydown-Co13lHGj.js";import"./vendor-radix-ui-react-focus-scope-C2K7lNPv.js";import"./vendor-radix-ui-react-portal-xlJWBfDg.js";import"./vendor-radix-ui-react-presence-Btn-Dp7L.js";import"./vendor-radix-ui-react-focus-guards-D5MZ0nQs.js";import"./vendor-react-remove-scroll-CfeMe0DL.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-C9YRs2nU.js";import"./vendor-react-style-singleton-B1H4bWSG.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-C-AuTczP.js";import"./vendor-use-callback-ref-CJB0R85I.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-BuDklWi8.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-codemirror-state-Wdz6Qsow.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-view-pXtfpqbT.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-CrbeaEAU.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-3xMyV7a2.js";import"./vendor-codemirror-lang-json-BTvAjwkJ.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-C4jEScp7.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-C1Svvdey.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-BloD9GN-.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-Be-zDX0u.js";import"./vendor-codemirror-lang-python-CR2g6ukK.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-Bzf12ODH.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-tanstack-react-virtual-IrbCBGJ4.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-framer-motion-DJASDzNt.js";import"./vendor-motion-dom-DJLgZh4Q.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-sonner-dWA7qvjr.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-marked-i_gIkIP3.js";import"./vendor-katex-CHD9BdDO.js";import"./vendor-dompurify-r8glNMJW.js";import"./vendor-remend-BWYYytN3.js";import"./themeResolver-BmJyTmjJ.js";import"./vendor-pierre-theming-C6Z4M5_u.js";import"./vendor-shikijs-core-CGM_jqPK.js";import"./vendor-shikijs-types-CPSbSeK6.js";import"./vendor-shikijs-vscode-textmate-BgLrS_2D.js";import"./vendor-hast-util-to-html-BKBhbTDb.js";import"./vendor-html-void-elements-CkdplsNl.js";import"./vendor-property-information-rJCbAzvX.js";import"./vendor-zwitch-C2o2j-tx.js";import"./vendor-stringify-entities-CsH1VEn9.js";import"./vendor-character-entities-legacy-BpoLgcEt.js";import"./vendor-character-entities-html4-D7taRCQ7.js";import"./vendor-ccount-c2V3InAJ.js";import"./vendor-comma-separated-tokens-D8TqSuIK.js";import"./vendor-space-separated-tokens-DD3iYX1K.js";import"./vendor-hast-util-whitespace-D4Wp6AEg.js";const Le="pichamber-md",wt={name:Le,colors:{"editor.background":"transparent","editor.foreground":"var(--md-syntax-foreground)"},tokenColors:[{scope:["comment","punctuation.definition.comment","string.comment"],settings:{foreground:"var(--md-syntax-comment)",fontStyle:"italic"}},{scope:["string","punctuation.definition.string","string.template"],settings:{foreground:"var(--md-syntax-string)"}},{scope:["constant.numeric","constant.language","constant.character","constant"],settings:{foreground:"var(--md-syntax-number)"}},{scope:["keyword","storage","storage.type","storage.modifier","keyword.control"],settings:{foreground:"var(--md-syntax-keyword)"}},{scope:["keyword.operator","punctuation.separator","punctuation.terminator"],settings:{foreground:"var(--md-syntax-operator)"}},{scope:["entity.name.function","support.function","meta.function-call"],settings:{foreground:"var(--md-syntax-function)"}},{scope:["entity.name.type","entity.name.class","support.type","support.class","entity.other.inherited-class"],settings:{foreground:"var(--md-syntax-type)"}},{scope:["variable","variable.other","variable.parameter","meta.definition.variable"],settings:{foreground:"var(--md-syntax-variable)"}},{scope:["variable.other.property","meta.property-name","support.type.property-name"],settings:{foreground:"var(--md-syntax-property)"}},{scope:["entity.name.tag","punctuation.definition.tag"],settings:{foreground:"var(--md-syntax-keyword)"}},{scope:["entity.other.attribute-name"],settings:{foreground:"var(--md-syntax-property)"}},{scope:["markup.bold","punctuation.definition.bold"],settings:{fontStyle:"bold"}},{scope:["markup.italic","punctuation.definition.italic"],settings:{fontStyle:"italic"}},{scope:["markup.heading","markup.heading entity.name"],settings:{foreground:"var(--md-syntax-keyword)",fontStyle:"bold"}},{scope:["markup.inserted","punctuation.definition.inserted"],settings:{foreground:"var(--md-syntax-inserted)"}},{scope:["markup.deleted","punctuation.definition.deleted"],settings:{foreground:"var(--md-syntax-deleted)"}},{scope:["invalid","invalid.illegal"],settings:{foreground:"var(--md-syntax-deleted)"}}]};let ne=!1;const yt=()=>{ne||(ne=!0,bt(Le,()=>Promise.resolve(wt)))},k=t=>Number.isFinite(t)&&t>0,ae=t=>{if(typeof t=="number")return k(t)?t:null;if(typeof t!="string")return null;const e=t.trim().match(/^([+-]?(?:(?:\d+\.?\d*)|(?:\.\d+))(?:[eE][+-]?\d+)?)(?:px)?$/);if(!e)return null;const o=Number(e[1]);return k(o)?o:null},j=(t,e,o)=>Math.min(o,Math.max(e,t)),At=6,ie=1.25,vt=1.0015,kt=.5,Ct=12,se=3,Et=400,F='[data-markdown="mermaid-block"]',S=t=>t.querySelector(F)!==null,Lt=t=>[t.x,t.y,t.width,t.height].map(e=>{const o=Number(e.toFixed(At));return Object.is(o,-0)?"0":String(o)}).join(" "),St=t=>{const e=t.viewBox?.trim().split(/[\s,]+/).map(s=>Number.parseFloat(s));if(e?.length===4){const[s,n,a,i]=e;if(Number.isFinite(s)&&Number.isFinite(n)&&k(a)&&k(i))return{x:s,y:n,width:a,height:i}}const o=ae(t.width),r=ae(t.height);return o===null||r===null?null:{x:0,y:0,width:o,height:r}},Mt=t=>{let e=2166136261;for(let o=0;o<t.length;o+=1)e^=t.charCodeAt(o),e=Math.imul(e,16777619);return(e>>>0).toString(36)},Nt=t=>{const e=t.renderMode||"unknown",o=t.svgMarkup??"";if(!o){const r=[t.viewBox??"",t.width??"",t.height??""];return r.some(s=>s!=="")?`${e}:bounds:${r.join(":")}`:`${e}:no-svg`}return[e,Mt(o)].join(":")},Se=(t,e)=>{if(!k(e.width)||!k(e.height))return t;const o=t.width/t.height,r=e.width/e.height;if(o>r){const n=t.width/r;return{x:t.x,y:t.y-(n-t.height)/2,width:t.width,height:n}}const s=t.height*r;return{x:t.x-(s-t.width)/2,y:t.y,width:s,height:t.height}},xt=({currentBox:t,viewport:e,delta:o})=>!k(e.width)||!k(e.height)||!k(t.width)||!k(t.height)?t:{x:t.x-o.x/e.width*t.width,y:t.y-o.y/e.height*t.height,width:t.width,height:t.height},Tt=(t,e)=>{const o=e.x-t.x,r=e.y-t.y;return o*o+r*r>se*se},Pt=({currentBox:t,contentBox:e,viewport:o,pointer:r,zoomFactor:s,minScale:n,maxScale:a})=>{if(!k(o.width)||!k(o.height)||!k(s)||!k(t.width)||!k(t.height)||!k(e.width)||!k(e.height)||!k(n)||!k(a))return t;const i=Math.min(n,a),l=Math.max(n,a),d=Se(e,o),c=d.width/t.width,p=j(c*s,i,l),u=d.width/p,f=u/(t.width/t.height),h=j(r.x/o.width,0,1),A=j(r.y/o.height,0,1),v=t.x+h*t.width,w=t.y+A*t.height;return{x:v-h*u,y:w-A*f,width:u,height:f}},G=new WeakMap,Rt=t=>t instanceof HTMLElement?G.get(t)??null:null,It=t=>t.querySelector('[data-markdown="mermaid-viewport"]')??t.querySelector('[data-markdown="mermaid"]'),le=t=>{const e=t.querySelector('[data-markdown="mermaid"] svg'),o=t.querySelector('[data-markdown="mermaid"]');return Nt({renderMode:t.getAttribute("data-mermaid-render"),svgMarkup:o?.getAttribute("data-md-original-svg")??e?.outerHTML??null,viewBox:e?.getAttribute("viewBox"),width:e?.getAttribute("width"),height:e?.getAttribute("height")})},I=t=>{const e=t.getBoundingClientRect();return{width:e.width,height:e.height}},_t=(t,e)=>{const o=e.getBoundingClientRect();return{x:t.clientX-o.left,y:t.clientY-o.top}},Ft=t=>t instanceof Element&&!!t.closest('button, a, [role="button"]'),Ot=t=>{const e=It(t),o=t.querySelector('[data-markdown="mermaid"] svg');if(!e||!o)return null;const r=St({viewBox:o.getAttribute("viewBox"),width:o.getAttribute("width"),height:o.getAttribute("height")});if(!r)return null;let s=r,n=null,a=null,i=null,l=null;const d=m=>{s=m,o.setAttribute("viewBox",Lt(m)),o.removeAttribute("width"),o.removeAttribute("height")},c=()=>{d(Se(r,I(e)))},p=(m,C)=>{d(Pt({currentBox:s,contentBox:r,viewport:I(e),pointer:m,zoomFactor:C,minScale:kt,maxScale:Ct}))},u=()=>{const m=I(e);p({x:m.width/2,y:m.height/2},ie)},f=()=>{const m=I(e);p({x:m.width/2,y:m.height/2},1/ie)},h=m=>{!m.ctrlKey&&!m.metaKey||(m.preventDefault(),m.stopPropagation(),p(_t(m,e),Math.pow(vt,-m.deltaY)))},A=m=>{m.button!==0||Ft(m.target)||(n=m.pointerId,a={x:m.clientX,y:m.clientY},i=a,l!==null&&(window.clearTimeout(l),l=null),t.removeAttribute("data-mermaid-suppress-click"),e.setPointerCapture?.(m.pointerId),t.setAttribute("data-mermaid-panning","true"),m.preventDefault())},v=m=>{if(n!==m.pointerId||!i)return;const C={x:m.clientX,y:m.clientY};d(xt({currentBox:s,viewport:I(e),delta:{x:C.x-i.x,y:C.y-i.y}})),i=C,a&&Tt(a,C)&&t.setAttribute("data-mermaid-suppress-click","true"),m.preventDefault()},w=m=>{n===m.pointerId&&(e.releasePointerCapture?.(m.pointerId),n=null,a=null,i=null,t.removeAttribute("data-mermaid-panning"),t.hasAttribute("data-mermaid-suppress-click")&&(l=window.setTimeout(()=>{t.removeAttribute("data-mermaid-suppress-click"),l=null},Et)))},g=()=>{c()};e.addEventListener("wheel",h,{passive:!1}),e.addEventListener("pointerdown",A),e.addEventListener("pointermove",v),e.addEventListener("pointerup",w),e.addEventListener("pointercancel",w),window.addEventListener("resize",g);const b=typeof ResizeObserver>"u"?null:new ResizeObserver(g);return b?.observe(e),c(),{zoomIn:u,zoomOut:f,fit:c,cleanup:()=>{e.removeEventListener("wheel",h),e.removeEventListener("pointerdown",A),e.removeEventListener("pointermove",v),e.removeEventListener("pointerup",w),e.removeEventListener("pointercancel",w),window.removeEventListener("resize",g),b?.disconnect(),l!==null&&window.clearTimeout(l),t.removeAttribute("data-mermaid-panning"),t.removeAttribute("data-mermaid-suppress-click"),G.delete(t)}}},Dt=t=>{const e=new Map,o=new Map,r=()=>{for(const[n,a]of Array.from(e.entries())){const i=le(n);(!t.contains(n)||i!==o.get(n))&&(a.cleanup(),e.delete(n),o.delete(n))}for(const n of Array.from(t.querySelectorAll(F))){if(e.has(n)||n.querySelector('[data-markdown="mermaid"] svg')===null)continue;const a=Ot(n);a&&(e.set(n,a),o.set(n,le(n)),G.set(n,a))}},s=()=>{for(const n of e.values())n.cleanup();e.clear(),o.clear()};return r(),{refresh:r,cleanup:s}},M=t=>`<svg class="remixicon size-3.5" viewBox="0 0 24 24" aria-hidden="true"><use href="#oc-${t}"></use></svg>`,q={copy:M("file-copy"),check:M("check"),download:M("download"),zoomIn:M("add"),zoomOut:M("subtract"),fit:M("refresh"),textWrap:M("text-wrap")},Me="p-1 rounded hover:bg-interactive-hover/60 text-muted-foreground hover:text-foreground transition-colors focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[var(--interactive-focus-ring)]",B=(t,e)=>{t.innerHTML=e},L=(t,e,o)=>{const r=document.createElement("button");return r.type="button",r.className=Me,r.setAttribute("data-md-action",o),r.setAttribute("title",e),r.setAttribute("aria-label",e),B(r,q[t]),r},Ne=(t,e,o)=>{const r=t.querySelector("[data-md-code-body]"),s=t.querySelector("pre"),n=t.querySelector("pre code"),a=t.querySelectorAll("[data-md-code-line-content]"),i=t.querySelector('[data-md-action="toggle-code-wrap"]');t.setAttribute("data-code-wrap",e?"true":"false"),r?.classList.toggle("overflow-x-auto",!e),r?.classList.toggle("overflow-x-hidden",e),s?.classList.toggle("whitespace-pre-wrap",e),s?.classList.toggle("break-words",e),n?.classList.toggle("whitespace-pre-wrap",e),n?.classList.toggle("break-words",e),s&&(s.style.whiteSpace=e?"pre-wrap":"pre",s.style.overflowWrap=e?"anywhere":"normal"),n&&(n.style.whiteSpace=e?"pre-wrap":"pre",n.style.overflowWrap=e?"anywhere":"normal");for(const l of Array.from(a))l.style.whiteSpace=e?"pre-wrap":"pre",l.style.overflowWrap=e?"anywhere":"normal";if(i){const l=e?o.disableCodeWrap:o.enableCodeWrap;i.setAttribute("title",l),i.setAttribute("aria-label",l),i.classList.toggle("text-foreground",e),i.classList.toggle("opacity-100",e),i.classList.toggle("text-muted-foreground",!e),i.classList.toggle("opacity-65",!e),i.setAttribute("aria-pressed",e?"true":"false")}},xe=t=>{const e=t.querySelector(":scope > code");if(!e||e.hasAttribute("data-md-code-lines"))return;const o=e.textContent??"",r=o.endsWith(`
2
2
  `),s=r?o.slice(0,-1).split(`
3
3
  `):o.split(`
4
4
  `),n=s.length>0?s:[""],a=Array.from(e.children).filter(d=>d.classList.contains("line"));r&&a.length===n.length+1&&a.at(-1)?.textContent===""&&a.pop();const i=a.length===n.length,l=document.createDocumentFragment();n.forEach((d,c)=>{const p=document.createElement("span");p.setAttribute("data-md-code-line","");const u=document.createElement("span");u.setAttribute("data-md-code-line-number",""),u.setAttribute("aria-hidden","true"),u.textContent=String(c+1);const f=document.createElement("span");if(f.setAttribute("data-md-code-line-content",""),i){const h=a[c];h&&f.append(...Array.from(h.childNodes))}else f.textContent=d;if(p.append(u,f),l.appendChild(p),c<n.length-1||r){const h=document.createElement("span");h.setAttribute("data-md-code-line-break",""),h.textContent=`
@@ -9,4 +9,4 @@ import{R as y,j as _}from"./vendor-react-DYyjh7Q0.js";import{m as Ke}from"./vend
9
9
  `),ue=({headers:t,rows:e})=>{const o=`| ${t.join(" | ")} |`,r=`| ${t.map(()=>"---").join(" | ")} |`,s=e.map(n=>`| ${n.join(" | ")} |`).join(`
10
10
  `);return`${o}
11
11
  ${r}
12
- ${s}`},pe=(t,e)=>{const o=document.createElement("div");o.className=`absolute top-full right-0 mt-1 hidden ${Ye}`,o.style.backgroundColor="var(--surface-elevated)",o.style.color="var(--surface-elevated-foreground)",o.setAttribute("data-md-menu",t);for(const r of e){const s=document.createElement("button");s.type="button",s.className=`w-full text-left ${Je}`,s.setAttribute("data-md-action",`${t}-${r.key}`),s.textContent=r.label,o.appendChild(s)}return o},Ht=(t,e)=>{const o=t.querySelectorAll("table");for(const r of Array.from(o)){if(r.closest('[data-markdown="table-wrapper"]'))continue;const n=document.createElement("div");n.className="group my-4 flex flex-col space-y-2",n.setAttribute("data-markdown","table-wrapper");const a=document.createElement("div");a.className="flex items-center justify-end gap-1";const i=document.createElement("div");i.className="relative",i.appendChild(L("copy",e.copyTable,"table-copy-toggle")),i.appendChild(pe("table-copy",[{key:"csv",label:"CSV"},{key:"tsv",label:"TSV"},{key:"markdown",label:"Markdown"}]));const l=document.createElement("div");l.className="relative",l.appendChild(L("download",e.downloadTable,"table-download-toggle")),l.appendChild(pe("table-download",[{key:"csv",label:"CSV"},{key:"markdown",label:"Markdown"}])),a.appendChild(i),a.appendChild(l);const d=document.createElement("div");d.className="overflow-x-auto rounded-lg border border-border/80 bg-[var(--surface-elevated)]";const c=r.parentElement;if(!c)continue;c.replaceChild(n,r),r.setAttribute("data-markdown","table"),r.classList.add("w-full","border-collapse","text-sm");for(const u of Array.from(r.querySelectorAll("tr")))u.classList.add("border-b","border-border/60");const p=r.querySelector("tbody tr:last-child");p?.classList.remove("border-b"),p?.classList.add("border-0");for(const u of Array.from(r.querySelectorAll("th")))u.classList.add("border-r","border-border/60","px-4","py-2.5","text-left","align-middle","font-semibold","text-foreground","last:border-r-0");for(const u of Array.from(r.querySelectorAll("td")))u.classList.add("border-r","border-border/60","px-4","py-2.5","align-middle","text-foreground/90","last:border-r-0");d.appendChild(r),n.appendChild(a),n.appendChild(d)}},Vt=(t,e)=>{const o=t.querySelectorAll("pre > code.language-mermaid");for(const r of Array.from(o)){const s=r.parentElement;if(!s)continue;const n=(r.textContent??"").replace(/\s+$/,""),a=e.renderMermaid(n),i=document.createElement("div");i.setAttribute("data-markdown","mermaid-block"),i.setAttribute("data-md-source",n),i.className="group relative";const l=document.createElement("div");l.setAttribute("data-markdown","mermaid-scroll");const d=document.createElement("div");if(d.setAttribute("data-markdown","mermaid-toolbar"),d.className="absolute top-1 right-2 flex items-center gap-1 opacity-0 group-hover:opacity-100 group-focus-within:opacity-100 transition-opacity",a.svg){i.setAttribute("data-mermaid-render","svg");const p=document.createElement("div");p.setAttribute("data-markdown","mermaid-viewport");const u=document.createElement("div");if(u.setAttribute("data-markdown","mermaid"),u.setAttribute("data-md-original-svg",a.svg),u.innerHTML=a.svg,p.appendChild(u),l.appendChild(p),e.mermaidControls.showPanZoomControls&&(d.appendChild(L("zoomIn",e.labels.zoomInDiagram,"mermaid-zoom-in")),d.appendChild(L("zoomOut",e.labels.zoomOutDiagram,"mermaid-zoom-out")),d.appendChild(L("fit",e.labels.resetDiagramView,"mermaid-fit"))),e.mermaidControls.copy){const f=L("copy",e.labels.copyDiagram,"mermaid-copy");f.setAttribute("data-md-source",n),d.appendChild(f)}if(e.mermaidControls.download){const f=L("download",e.labels.downloadDiagram,"mermaid-download");f.setAttribute("data-md-svg","1"),d.appendChild(f)}}else{i.setAttribute("data-mermaid-render","ascii");const p=document.createElement("pre");if(p.setAttribute("data-markdown","mermaid-ascii"),p.textContent=a.ascii||n,l.appendChild(p),e.mermaidControls.copy){const u=L("copy",e.labels.copyDiagram,"mermaid-copy");u.setAttribute("data-md-source",a.ascii||n),d.appendChild(u)}}i.appendChild(l),i.appendChild(d);const c=s.parentElement;c&&c.replaceChild(i,s)}},jt=(t,e)=>{const o=t.querySelectorAll("a[href]");for(const r of Array.from(o)){if(r.getAttribute("data-md-link-decorated")==="true"||r.getAttribute("data-pichamber-file-link")==="true")continue;const s=r.getAttribute("href")??"";if(!ve(s))continue;r.setAttribute("data-md-link-decorated","true");const n=Xe(s);if(n){const a=document.createElement("span");a.className="mr-1 inline-flex size-[18px] items-center justify-center rounded border border-[var(--border)] bg-[var(--interactive-hover)] align-middle";const i=document.createElement("img");i.src=n,i.alt="",i.setAttribute("aria-hidden","true"),i.loading="lazy",i.decoding="async",i.className="size-3.5 rounded-sm",i.addEventListener("error",()=>a.remove(),{once:!0}),a.appendChild(i),r.parentNode?.insertBefore(a,r)}if(e.onPreviewLoopback&&Ge(s)){const a=document.createElement("button");a.type="button",a.className=`ml-1 align-middle ${Me}`,a.setAttribute("data-md-action","preview-loopback"),a.setAttribute("data-md-url",s),a.setAttribute("title",e.labels.previewTitle),a.setAttribute("aria-label",e.labels.previewLabel),B(a,q.download),r.parentNode?.insertBefore(a,r.nextSibling)}}},fe=(t,e)=>{qt(t),Vt(t,e),Bt(t,e),Ht(t,e.labels),jt(t,e)},he=(t,e,o)=>{const r=new Blob([e],{type:o}),s=URL.createObjectURL(r),n=document.createElement("a");n.href=s,n.download=t,document.body.appendChild(n),n.click(),document.body.removeChild(n),URL.revokeObjectURL(s)},O=t=>{for(const e of Array.from(t.querySelectorAll("[data-md-menu]")))e.classList.add("hidden")},Kt=(t,e)=>{const o=r=>{const s=r.target;if(!(s instanceof Element))return;const n=s.closest("[data-md-action]");if(!n){O(t);return}const a=n.getAttribute("data-md-action")??"";if(a==="copy-code"){const i=n.closest('[data-component="markdown-code"]')?.querySelector("code"),l=i?Te(i):"";l&&H(l).then(()=>ce(n,e.labels.copied,"copy",e.labels.copy));return}if(a==="toggle-code-wrap"){r.preventDefault(),e.onToggleCodeBlockLineWrap?.();return}if(a==="table-copy-toggle"||a==="table-download-toggle"){r.preventDefault();const i=n.parentElement?.querySelector("[data-md-menu]")??null,l=i?.classList.contains("hidden")??!1;O(t),i&&l&&i.classList.remove("hidden");return}if(a.startsWith("table-copy-")){const i=a.replace("table-copy-",""),l=n.closest('[data-markdown="table-wrapper"]')?.querySelector("table");if(l instanceof HTMLTableElement){const d=de(l),c=i==="csv"?me(d):i==="tsv"?zt(d):ue(d);H(c)}O(t);return}if(a.startsWith("table-download-")){const i=a.replace("table-download-",""),l=n.closest('[data-markdown="table-wrapper"]')?.querySelector("table");if(l instanceof HTMLTableElement){const d=de(l),c=i==="csv"?me(d):ue(d);he(i==="csv"?"table.csv":"table.md",c,i==="csv"?"text/csv":"text/markdown")}O(t);return}if(a==="mermaid-copy"){const i=n.getAttribute("data-md-source")??"";i&&H(i).then(()=>ce(n,e.labels.copied,"copy",e.labels.copyDiagram));return}if(a==="mermaid-zoom-in"||a==="mermaid-zoom-out"||a==="mermaid-fit"){r.preventDefault();const i=n.closest('[data-markdown="mermaid-block"]'),l=Rt(i);a==="mermaid-zoom-in"?l?.zoomIn():a==="mermaid-zoom-out"?l?.zoomOut():l?.fit();return}if(a==="mermaid-download"){const i=n.closest('[data-markdown="mermaid-block"]')?.querySelector('[data-markdown="mermaid"]'),l=i?.getAttribute("data-md-original-svg")??i?.innerHTML??"";l&&he("diagram.svg",l,"image/svg+xml;charset=utf-8");return}if(a==="preview-loopback"){r.preventDefault();const i=n.getAttribute("data-md-url")??"";i&&e.onPreviewLoopback?.(i);return}};return t.addEventListener("click",o),()=>t.removeEventListener("click",o)},ge=(t,e,o)=>{let r=0;for(const n of t){const a=r+n.data.length;if(e<a||e===a&&o==="left")return{node:n,offset:Math.max(0,e-r)};r=a}const s=t.at(-1);return s?{node:s,offset:s.data.length}:null},Ut=new Set(["dockerfile","makefile","readme","license",".env",".gitignore",".npmrc"]),be=Array.from(Ut).map(t=>t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join("|"),Zt=t=>et(t),Xt=t=>Qe(t),$=t=>{let e=(t||"").trim();return e?((e.startsWith("`")&&e.endsWith("`")||e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'"))&&(e=e.slice(1,-1).trim()),e=e.replace(/[.,;!?]+$/g,""),e.endsWith(")")&&!e.includes("(")&&(e=e.slice(0,-1)),e.endsWith("]")&&!e.includes("[")&&(e=e.slice(0,-1)),e):""},D=t=>{let e=$(t);if(!e)return"";const o=e.indexOf(";");o>=0&&(e=e.slice(0,o)),e=e.replace(/#.*$/,"");const r=e.match(/^(.*\.[A-Za-z0-9_-]{1,16}):.*$/);r&&(e=r[1]??e);const s=be.length>0?e.match(new RegExp(`^(.*(?:/|^)(${be})):.*$`,"i")):null;return s&&(e=s[1]??e),$(e)},Pe=t=>{const e=$(t);if(!e)return null;const o=e.indexOf(";"),r=o>=0?$(e.slice(0,o)):e;if(!r)return null;const s=r.match(/^(.*?):(\d+)-(\d+)$/);if(s){const l=D(s[1]??""),d=Number.parseInt(s[2]??"",10),c=Number.parseInt(s[3]??"",10);return!l||!Number.isFinite(d)||!Number.isFinite(c)||c<d?null:{path:l,line:d,endLine:c}}const n=r.match(/^(.*)#L(\d+)(?:C(\d+))?$/i);if(n){const l=D(n[1]??""),d=Number.parseInt(n[2]??"",10),c=n[3]?Number.parseInt(n[3],10):void 0;return!l||!Number.isFinite(d)?null:{path:l,line:d,column:Number.isFinite(c??Number.NaN)?c:void 0}}const a=r.match(/^(.*?):(\d+)(?::(\d+))?$/);if(a){const l=D(a[1]??""),d=Number.parseInt(a[2]??"",10),c=a[3]?Number.parseInt(a[3],10):void 0;return!l||!Number.isFinite(d)?null:{path:l,line:d,column:Number.isFinite(c??Number.NaN)?c:void 0}}const i=D(r);return i?{path:i}:null},j=/(?:[A-Za-z]:[\\/])?[\w.\-/@+]*[\w\-/@+]\.[A-Za-z0-9]{1,8}(?::\d+(?:-\d+)?(?::\d+)?)?/g,Re=()=>{const t=rt(),e=oe(!1),o=oe(!0);return t?.currentTheme??(typeof window<"u"&&window.matchMedia("(prefers-color-scheme: dark)").matches?o:e)},Ie=({containerRef:t,enabled:e})=>{y.useEffect(()=>{if(e===!1)return;const o=t.current;if(!o)return;const r=s=>{if(s.defaultPrevented||s.button!==0||s.metaKey||s.ctrlKey||s.altKey||s.shiftKey)return;const n=s.target;if(!(n instanceof Element))return;const a=n.closest("a[href]");if(!(a instanceof HTMLAnchorElement)||a.getAttribute("data-pichamber-file-link")==="true")return;const i=a.getAttribute("href")??"";ve(i)&&(s.preventDefault(),s.stopPropagation(),ot(i))};return o.addEventListener("click",r),()=>{o.removeEventListener("click",r)}},[t,e])},R={download:!0,copy:!0,showPanZoomControls:!0},_e=!0,Gt=t=>{const e=t.match(/^(?:\uFEFF)?(---|\+\+\+)[^\S\r\n]*\r?\n[\s\S]*?\r?\n\1[^\S\r\n]*(?:\r?\n|$)/);return e?t.slice(e[0].length):t},we='[data-pichamber-file-link="true"]',Fe="data-pichamber-block-path-token",Oe=`[${Fe}]`,P="data-pichamber-block-paths-scanned",Yt=2e5,Jt=4,Qt=1e3,er=80,ye=160,N=new Map;let W=0;const Ae=[],tr=()=>Qt,rr=()=>er,or=new Set(["dockerfile","makefile","readme","license",".env",".gitignore",".npmrc"]),Y=t=>Zt(t),nr=t=>Xt(t),ar=(t,e)=>it(t,e),ir=t=>{const e=t.split("/").filter(Boolean).pop()??"";return!e||e.endsWith(".")?!1:/\.[A-Za-z0-9_-]{1,16}$/.test(e)},De=t=>{if(!t||t.startsWith("--")||t.includes("://")||/[<>]/.test(t)||/\s{2,}/.test(t))return!1;const e=Y(t),o=e.split("/").filter(Boolean).pop()??e;if(!o||o==="."||o==="..")return!1;const r=o.toLowerCase();return or.has(r)||r.startsWith(".")&&r.length>1?!0:ir(e)},We=t=>{const e=Pe(t);return e?De(e.path):!1},sr=t=>{const e=t.querySelectorAll(Oe);for(const r of Array.from(e))r.replaceWith(t.ownerDocument.createTextNode(r.textContent??""));const o=t.querySelectorAll(`code[${P}]`);for(const r of Array.from(o))r.removeAttribute(P),r.normalize()},K=t=>{if(t.tagName.toLowerCase()==="a"){const e=t.getAttribute("href")?.trim();if(e&&We(e))return e}return(t.textContent||"").trim()},lr=t=>{const e=t.querySelectorAll("pre code");if(e.length===0)return;const o=t.ownerDocument;if(o)for(const r of Array.from(e)){if(r.getAttribute(P)==="true")continue;if((r.textContent??"").length>Yt){r.setAttribute(P,"true");continue}const s=o.createTreeWalker(r,NodeFilter.SHOW_TEXT),n=[];let a=s.nextNode();for(;a;){const c=a;c.parentElement?.closest("[data-md-code-line-number]")||n.push(c),a=s.nextNode()}const i=Te(r);if(!i.includes(".")){r.setAttribute(P,"true");continue}j.lastIndex=0;const l=[];let d=j.exec(i);for(;d;){const c=d[0];c&&We(c)&&l.push({start:d.index,end:d.index+c.length,raw:c}),d=j.exec(i)}for(const{start:c,end:p,raw:u}of l.reverse()){const f=ge(n,c,"right"),h=ge(n,p,"left");if(!f||!h)continue;const A=o.createRange();A.setStart(f.node,f.offset),A.setEnd(h.node,h.offset);const v=o.createElement("span");v.setAttribute(Fe,"true"),v.textContent=u,A.deleteContents(),A.insertNode(v)}r.setAttribute(P,"true")}},U=(t,e)=>{const o=Pe(t);if(!o||!De(o.path))return null;const r=nr(o.path)?Y(o.path):ar(e,o.path);return r?{...o,resolvedPath:r}:null},cr=t=>{const e=Y(t);if(!e)return Promise.resolve(!1);const o=N.get(e);if(o)return N.delete(e),N.set(e,o),o;const r=new Promise(n=>{const a=()=>{W+=1,dt(`/api/fs/stat?path=${encodeURIComponent(e)}&optional=true`,{method:"GET",cache:"no-store"}).then(async i=>{if(!i.ok){n(!1);return}const l=await i.json().catch(()=>null);n(l?.exists!==!1)}).catch(()=>n(!1)).finally(()=>{W=Math.max(0,W-1),Ae.shift()?.()})};if(W<Jt){a();return}Ae.push(a)}),s=tr();for(;N.size>=s;){const n=N.keys().next().value;if(typeof n!="string")break;N.delete(n)}return N.set(e,r),r},dr=(t,e)=>t||at(t,e),qe=({containerRef:t,effectiveDirectory:e,editor:o,preferRuntimeEditor:r,enabled:s})=>{const n=y.useRef(null);y.useEffect(()=>{const a=t.current;if(!a)return;let i=!1;const l=rr(),d=s&&!mt(),c=g=>{g.removeAttribute("data-pichamber-file-link"),g.removeAttribute("data-pichamber-file-ref"),g.removeAttribute("data-pichamber-file-path"),g.getAttribute("title")==="Open file"&&g.removeAttribute("title"),g.tagName.toLowerCase()!=="a"&&(g.removeAttribute("role"),g.removeAttribute("tabindex"))},p=()=>{const g=a.querySelectorAll(we);for(const b of Array.from(g))c(b);sr(a)};if(!d){p();return}const u=(g=0)=>{if(n.current!==null&&typeof window<"u"&&window.clearTimeout(n.current),typeof window>"u"){f();return}n.current=window.setTimeout(()=>{n.current=null,window.requestAnimationFrame(()=>{i||f()})},g)},f=()=>{d&&lr(a);const g=a.querySelectorAll(`[data-markdown="inline-code"], a, ${Oe}`);let b=0;for(const m of Array.from(g)){const C=K(m),E=U(C,e);if(c(m),!E||b>=l)continue;b+=1,(lt()&&ct()&&!te(E.resolvedPath,e)?Promise.resolve(!0):cr(E.resolvedPath)).then(je=>{if(i||!je||!a.contains(m))return;const ee=K(m),z=U(ee,e);!z||z.resolvedPath!==E.resolvedPath||(m.setAttribute("data-pichamber-file-link","true"),m.setAttribute("data-pichamber-file-ref",ee),m.setAttribute("data-pichamber-file-path",z.resolvedPath),m.setAttribute("title","Open file"),m.tagName.toLowerCase()!=="a"&&(m.setAttribute("role","button"),m.setAttribute("tabindex","0")))})}},h=async g=>{const b=g.getAttribute("data-pichamber-file-ref")||K(g),m=U(b,e);if(!m)return;const C=dr(e,m.resolvedPath);te(m.resolvedPath,e)||await nt(m.resolvedPath,e);const E=T.getState();Number.isFinite(m.line??Number.NaN)?E.openContextFileAtLine(C,m.resolvedPath,Math.max(1,Math.trunc(m.line)),Number.isFinite(m.column??Number.NaN)?Math.max(1,Math.trunc(m.column)):1):E.openContextFile(C,m.resolvedPath)},A=g=>{const b=g.target;if(!(b instanceof Element))return;const m=b.closest(we);m instanceof HTMLElement&&(g.preventDefault(),g.stopPropagation(),h(m))},v=g=>{if(g.key!=="Enter"&&g.key!==" ")return;const b=g.target;!(b instanceof HTMLElement)||b.getAttribute("data-pichamber-file-link")!=="true"||(g.preventDefault(),g.stopPropagation(),h(b))};u(ye);const w=new MutationObserver(()=>{u(ye)});return w.observe(a,{childList:!0,subtree:!0}),a.addEventListener("click",A),a.addEventListener("keydown",v),()=>{i=!0,n.current!==null&&typeof window<"u"&&window.clearTimeout(n.current),n.current=null,w.disconnect(),a.removeEventListener("click",A),a.removeEventListener("keydown",v)}},[t,o,e,r,s])},Be=({containerRef:t,onShowPopup:e,enableFullscreen:o,enablePanZoom:r,allowMermaidWheelEvents:s})=>{y.useEffect(()=>{const n=t.current;if(!n)return;const a=l=>{if(!e)return;const d=l.target;if(!(d instanceof Element)||d.closest('button, a, [role="button"]'))return;const c=d.closest(F);if(!c)return;if(c instanceof HTMLElement&&c.hasAttribute("data-mermaid-suppress-click")){c.removeAttribute("data-mermaid-suppress-click");return}const u=Array.from(n.querySelectorAll(F)).indexOf(c);if(u<0)return;const f=c instanceof HTMLElement?c.getAttribute("data-md-source"):null;if(!f||f.trim().length===0)return;const h=`Diagram ${u+1}`;e({open:!0,title:h,content:"",metadata:{tool:"mermaid-preview",filename:h},mermaid:{url:`data:text/plain;charset=utf-8,${encodeURIComponent(f)}`,source:f,filename:h}})},i=l=>{if(s||(l.ctrlKey||l.metaKey)&&r)return;const d=l.target;!(d instanceof Element)||!d.closest(F)||l.stopPropagation()};return n.addEventListener("click",a),n.addEventListener("wheel",i,{capture:!0,passive:!0}),()=>{n.removeEventListener("click",a),n.removeEventListener("wheel",i,!0)}},[s,t,o,r,e])},x=new Map,mr=100,ur=(t,e)=>{const o=x.get(t);if(o)return x.delete(t),x.set(t,o),o;const r=e();if(x.set(t,r),x.size>mr){const s=x.keys().next().value;s&&x.delete(s)}return r},pr=t=>({bg:t.colors.surface.elevated,fg:t.colors.surface.foreground,line:t.colors.interactive.border,accent:t.colors.primary.base,muted:t.colors.surface.mutedForeground,surface:t.colors.surface.muted,border:t.colors.interactive.border,transparent:!0,font:"system-ui, sans-serif"}),$e=(t,e,o,r=R)=>{const s=y.useMemo(()=>({copy:"Copy code",copied:"Copied",enableCodeWrap:"Enable line wrap",disableCodeWrap:"Disable line wrap",copyTable:"Copy table",downloadTable:"Download table",copyDiagram:"Copy source",downloadDiagram:"Download SVG",zoomInDiagram:"Zoom in",zoomOutDiagram:"Zoom out",resetDiagramView:"Reset view",previewLabel:"Preview",previewTitle:"Open preview pane"}),[]),n=T(l=>l.codeBlockLineWrap),a=T(l=>l.setCodeBlockLineWrap),i=y.useCallback(()=>{a(!T.getState().codeBlockLineWrap)},[a]);return y.useMemo(()=>{const l=pr(t),d=T.getState().mermaidRenderingMode,c=t.metadata?.id??"theme";return{labels:s,mermaidControls:r,codeBlockLineWrap:n,deferCodeLineNumberSync:e,onToggleCodeBlockLineWrap:i,renderMermaid:u=>ur(`${c}:${d}:${u}`,()=>{try{return d==="ascii"?{ascii:Ue(u)}:{svg:Ze(u,l)}}catch{return{}}}),onPreviewLoopback:o}},[t,s,r,n,e,i,o])},ze=t=>{t.style.display="contents",t.style.width="",t.style.minWidth="",t.style.maxWidth=""},Z=(t,e)=>{ze(t);const o=gt(e);let r=t.querySelector(":scope > [data-md-live]");const s=r?.hasAttribute("data-md-live-pre")===!0;(!r||s!==o)&&(t.replaceChildren(),r=document.createElement(o?"div":"p"),r.setAttribute("data-md-live",""),o&&r.setAttribute("data-md-live-pre",""),r.className=o?"w-full min-w-0 whitespace-pre-wrap break-words":"w-full min-w-0 break-words",r.appendChild(document.createTextNode("")),t.appendChild(r));const n=r.firstChild;if(!(n instanceof globalThis.Text)){r.replaceChildren(document.createTextNode(e));return}if(e.startsWith(n.data)){const a=e.slice(n.data.length);a.length>0&&n.appendData(a);return}n.data=e},He=({containerRef:t,text:e,streaming:o,cacheKey:r,syntaxVars:s,ctx:n})=>{y.useEffect(()=>{yt()},[]);const a=y.useRef(null),i=y.useRef(null),l=y.useRef(r);l.current!==r&&(l.current=r,i.current=null);const d=y.useCallback(()=>{const c=t.current;if(c){if(!a.current){if(!S(c))return;a.current=Dt(c);return}a.current.refresh()}},[t]);y.useLayoutEffect(()=>{const c=t.current,p=c?.querySelector("[data-markdown-content]")??c;if(p&&e&&p.childNodes.length===0){const u=document.createElement("div");if(u.setAttribute("data-md-block",""),u.style.display="contents",o){Z(u,e),p.appendChild(u);return}u.innerHTML=ut(e),fe(u,n),p.appendChild(u),S(u)&&d()}},[t,e,o,n,d]),y.useEffect(()=>()=>{a.current?.cleanup(),a.current=null},[]),y.useEffect(()=>{const c=t.current;if(!c)return;const p=c.querySelector("[data-markdown-content]")??c;let u=!0;if(o&&i.current){const f=pt(r).update(e);if(ft(i.current,f)){const h=f[f.length-1],A=p.querySelectorAll(":scope > [data-md-block]")[f.length-1];if(h&&A){Z(A,h.raw),A.setAttribute("data-md-id",`live:${f.length-1}`),i.current=i.current.map((v,w)=>w===f.length-1?{...v,raw:h.raw,id:`live:${w}`,mode:"live"}:v);return}}}return ht(e,o,r).then(f=>{if(!u)return;const h=Array.from(p.querySelectorAll(":scope > [data-md-block]"));f.forEach((w,g)=>{let b=h[g];if(b||(b=document.createElement("div"),b.setAttribute("data-md-block",""),b.style.display="contents",p.appendChild(b)),w.mode==="live"){Z(b,w.raw),b.setAttribute("data-md-id",w.id);return}if(ze(b),b.getAttribute("data-md-id")===w.id)return;const m=document.createElement("div");m.innerHTML=w.html,fe(m,n);const C=S(b),E=S(m);Ke(b,m,{childrenOnly:!0,onBeforeElUpdated:(J,Q)=>!J.isEqualNode(Q)}),b.setAttribute("data-md-id",w.id),(C||E||S(b))&&d()});const A=S(p);let v=!1;for(let w=h.length-1;w>=f.length;w-=1){const g=h[w];g&&S(g)&&(v=!0),g?.remove()}(v||h.length>f.length&&A)&&d(),i.current=f}),()=>{u=!1}},[t,e,o,r,n,d]),y.useEffect(()=>{const c=t.current;if(c)return Kt(c,n)},[t,n]),y.useEffect(()=>{const c=t.current,p=c?.querySelector("[data-markdown-content]")??c;if(p)for(const[u,f]of Object.entries(s))p.style.setProperty(u,f)},[t,s]),y.useEffect(()=>{const c=t.current,p=c?.querySelector("[data-markdown-content]")??c;p&&(n.deferCodeLineNumberSync||Wt(p,n.codeBlockLineWrap,n.labels))},[t,n.codeBlockLineWrap,n.deferCodeLineNumberSync,n.labels])},Ve=(t,e)=>X("w-full min-w-0",t==="tool"?"markdown-content markdown-tool":t==="reasoning"?"markdown-content markdown-reasoning":"markdown-content leading-relaxed",e&&"markdown-streaming"),fr=({content:t,part:e,messageId:o,isAnimated:r=!0,skipFadeIn:s=!1,className:n,isStreaming:a=!1,disableStreamAnimation:i=!1,variant:l="assistant",onShowPopup:d,enableFileReferences:c=!0})=>{re("ui.markdown_renderer.render"),a&&re("ui.markdown_renderer.render.streaming"),st("ui.markdown_renderer.content_len",t.length);const p=Re(),{editor:u}=ke(),f=y.useRef(null),h=Ce()??"",A=T(E=>E.openContextPreview),v=y.useCallback(E=>{h&&A(h,E)},[h,A]),w=a&&!i;Be({containerRef:f,onShowPopup:d,enableFullscreen:_e,enablePanZoom:R.showPanZoomControls}),qe({containerRef:f,effectiveDirectory:h,editor:u,preferRuntimeEditor:!1,enabled:c&&!a}),Ie({containerRef:f});const g=y.useMemo(()=>Ee(p),[p]),b=$e(p,w,h?v:void 0,R),m=`markdown-${e?.id?`part-${e.id}`:`message-${o}`}`;He({containerRef:f,text:t,streaming:w,cacheKey:m,syntaxVars:g,ctx:b});const C=_.jsx("div",{className:X("break-words w-full min-w-0",n),ref:f,children:_.jsx("div",{className:Ve(l,w),"data-markdown-content":!0})});return r?_.jsx(tt,{skipAnimation:s,children:C},m):C},fn=y.memo(fr,(t,e)=>t.content===e.content&&t.isStreaming===e.isStreaming&&t.disableStreamAnimation===e.disableStreamAnimation&&t.variant===e.variant&&t.isAnimated===e.isAnimated&&t.skipFadeIn===e.skipFadeIn&&t.className===e.className&&t.messageId===e.messageId&&t.onShowPopup===e.onShowPopup&&t.enableFileReferences===e.enableFileReferences&&t.part?.id===e.part?.id),hr=({content:t,className:e,variant:o="assistant",disableLinkSafety:r,stripFrontmatter:s=!1,onShowPopup:n,mermaidControls:a=R,allowMermaidWheelEvents:i=!1,enableFileReferences:l=!0})=>{const{editor:d}=ke(),c=Re(),p=y.useRef(null),u=Ce()??"",f=y.useMemo(()=>s?Gt(t):t,[t,s]);Be({containerRef:p,onShowPopup:n,enableFullscreen:_e,enablePanZoom:a.showPanZoomControls,allowMermaidWheelEvents:i}),qe({containerRef:p,effectiveDirectory:u,editor:d,preferRuntimeEditor:!1,enabled:l}),Ie({containerRef:p,enabled:!r});const h=y.useMemo(()=>Ee(c),[c]),A=$e(c,!1,void 0,a);return He({containerRef:p,text:f,streaming:!1,cacheKey:`simple:${o}`,syntaxVars:h,ctx:A}),_.jsx("div",{className:X("break-words w-full min-w-0",e),ref:p,children:_.jsx("div",{className:Ve(o),"data-markdown-content":!0})})},hn=y.memo(hr,(t,e)=>{const o=t.mermaidControls??R,r=e.mermaidControls??R;return t.content===e.content&&t.variant===e.variant&&t.className===e.className&&t.disableLinkSafety===e.disableLinkSafety&&t.stripFrontmatter===e.stripFrontmatter&&t.onShowPopup===e.onShowPopup&&o.download===r.download&&o.copy===r.copy&&o.showPanZoomControls===r.showPanZoomControls&&t.allowMermaidWheelEvents===e.allowMermaidWheelEvents&&t.enableFileReferences===e.enableFileReferences});export{fn as MarkdownRenderer,hn as SimpleMarkdownRenderer};
12
+ ${s}`},pe=(t,e)=>{const o=document.createElement("div");o.className=`absolute top-full right-0 mt-1 hidden ${Ye}`,o.style.backgroundColor="var(--surface-elevated)",o.style.color="var(--surface-elevated-foreground)",o.setAttribute("data-md-menu",t);for(const r of e){const s=document.createElement("button");s.type="button",s.className=`w-full text-left ${Je}`,s.setAttribute("data-md-action",`${t}-${r.key}`),s.textContent=r.label,o.appendChild(s)}return o},Ht=(t,e)=>{const o=t.querySelectorAll("table");for(const r of Array.from(o)){if(r.closest('[data-markdown="table-wrapper"]'))continue;const n=document.createElement("div");n.className="group my-4 flex flex-col space-y-2",n.setAttribute("data-markdown","table-wrapper");const a=document.createElement("div");a.className="flex items-center justify-end gap-1";const i=document.createElement("div");i.className="relative",i.appendChild(L("copy",e.copyTable,"table-copy-toggle")),i.appendChild(pe("table-copy",[{key:"csv",label:"CSV"},{key:"tsv",label:"TSV"},{key:"markdown",label:"Markdown"}]));const l=document.createElement("div");l.className="relative",l.appendChild(L("download",e.downloadTable,"table-download-toggle")),l.appendChild(pe("table-download",[{key:"csv",label:"CSV"},{key:"markdown",label:"Markdown"}])),a.appendChild(i),a.appendChild(l);const d=document.createElement("div");d.className="overflow-x-auto rounded-lg border border-border/80 bg-[var(--surface-elevated)]";const c=r.parentElement;if(!c)continue;c.replaceChild(n,r),r.setAttribute("data-markdown","table"),r.classList.add("w-full","border-collapse","text-sm");for(const u of Array.from(r.querySelectorAll("tr")))u.classList.add("border-b","border-border/60");const p=r.querySelector("tbody tr:last-child");p?.classList.remove("border-b"),p?.classList.add("border-0");for(const u of Array.from(r.querySelectorAll("th")))u.classList.add("border-r","border-border/60","px-4","py-2.5","text-left","align-middle","font-semibold","text-foreground","last:border-r-0");for(const u of Array.from(r.querySelectorAll("td")))u.classList.add("border-r","border-border/60","px-4","py-2.5","align-middle","text-foreground/90","last:border-r-0");d.appendChild(r),n.appendChild(a),n.appendChild(d)}},jt=(t,e)=>{const o=t.querySelectorAll("pre > code.language-mermaid");for(const r of Array.from(o)){const s=r.parentElement;if(!s)continue;const n=(r.textContent??"").replace(/\s+$/,""),a=e.renderMermaid(n),i=document.createElement("div");i.setAttribute("data-markdown","mermaid-block"),i.setAttribute("data-md-source",n),i.className="group relative";const l=document.createElement("div");l.setAttribute("data-markdown","mermaid-scroll");const d=document.createElement("div");if(d.setAttribute("data-markdown","mermaid-toolbar"),d.className="absolute top-1 right-2 flex items-center gap-1 opacity-0 group-hover:opacity-100 group-focus-within:opacity-100 transition-opacity",a.svg){i.setAttribute("data-mermaid-render","svg");const p=document.createElement("div");p.setAttribute("data-markdown","mermaid-viewport");const u=document.createElement("div");if(u.setAttribute("data-markdown","mermaid"),u.setAttribute("data-md-original-svg",a.svg),u.innerHTML=a.svg,p.appendChild(u),l.appendChild(p),e.mermaidControls.showPanZoomControls&&(d.appendChild(L("zoomIn",e.labels.zoomInDiagram,"mermaid-zoom-in")),d.appendChild(L("zoomOut",e.labels.zoomOutDiagram,"mermaid-zoom-out")),d.appendChild(L("fit",e.labels.resetDiagramView,"mermaid-fit"))),e.mermaidControls.copy){const f=L("copy",e.labels.copyDiagram,"mermaid-copy");f.setAttribute("data-md-source",n),d.appendChild(f)}if(e.mermaidControls.download){const f=L("download",e.labels.downloadDiagram,"mermaid-download");f.setAttribute("data-md-svg","1"),d.appendChild(f)}}else{i.setAttribute("data-mermaid-render","ascii");const p=document.createElement("pre");if(p.setAttribute("data-markdown","mermaid-ascii"),p.textContent=a.ascii||n,l.appendChild(p),e.mermaidControls.copy){const u=L("copy",e.labels.copyDiagram,"mermaid-copy");u.setAttribute("data-md-source",a.ascii||n),d.appendChild(u)}}i.appendChild(l),i.appendChild(d);const c=s.parentElement;c&&c.replaceChild(i,s)}},Kt=(t,e)=>{const o=t.querySelectorAll("a[href]");for(const r of Array.from(o)){if(r.getAttribute("data-md-link-decorated")==="true"||r.getAttribute("data-pichamber-file-link")==="true")continue;const s=r.getAttribute("href")??"";if(!ve(s))continue;r.setAttribute("data-md-link-decorated","true");const n=Xe(s);if(n){const a=document.createElement("span");a.className="mr-1 inline-flex size-[18px] items-center justify-center rounded border border-[var(--border)] bg-[var(--interactive-hover)] align-middle";const i=document.createElement("img");i.src=n,i.alt="",i.setAttribute("aria-hidden","true"),i.loading="lazy",i.decoding="async",i.className="size-3.5 rounded-sm",i.addEventListener("error",()=>a.remove(),{once:!0}),a.appendChild(i),r.parentNode?.insertBefore(a,r)}if(e.onPreviewLoopback&&Ge(s)){const a=document.createElement("button");a.type="button",a.className=`ml-1 align-middle ${Me}`,a.setAttribute("data-md-action","preview-loopback"),a.setAttribute("data-md-url",s),a.setAttribute("title",e.labels.previewTitle),a.setAttribute("aria-label",e.labels.previewLabel),B(a,q.download),r.parentNode?.insertBefore(a,r.nextSibling)}}},fe=(t,e)=>{qt(t),jt(t,e),Bt(t,e),Ht(t,e.labels),Kt(t,e)},he=(t,e,o)=>{const r=new Blob([e],{type:o}),s=URL.createObjectURL(r),n=document.createElement("a");n.href=s,n.download=t,document.body.appendChild(n),n.click(),document.body.removeChild(n),URL.revokeObjectURL(s)},O=t=>{for(const e of Array.from(t.querySelectorAll("[data-md-menu]")))e.classList.add("hidden")},Vt=(t,e)=>{const o=r=>{const s=r.target;if(!(s instanceof Element))return;const n=s.closest("[data-md-action]");if(!n){O(t);return}const a=n.getAttribute("data-md-action")??"";if(a==="copy-code"){const i=n.closest('[data-component="markdown-code"]')?.querySelector("code"),l=i?Te(i):"";l&&H(l).then(()=>ce(n,e.labels.copied,"copy",e.labels.copy));return}if(a==="toggle-code-wrap"){r.preventDefault(),e.onToggleCodeBlockLineWrap?.();return}if(a==="table-copy-toggle"||a==="table-download-toggle"){r.preventDefault();const i=n.parentElement?.querySelector("[data-md-menu]")??null,l=i?.classList.contains("hidden")??!1;O(t),i&&l&&i.classList.remove("hidden");return}if(a.startsWith("table-copy-")){const i=a.replace("table-copy-",""),l=n.closest('[data-markdown="table-wrapper"]')?.querySelector("table");if(l instanceof HTMLTableElement){const d=de(l),c=i==="csv"?me(d):i==="tsv"?zt(d):ue(d);H(c)}O(t);return}if(a.startsWith("table-download-")){const i=a.replace("table-download-",""),l=n.closest('[data-markdown="table-wrapper"]')?.querySelector("table");if(l instanceof HTMLTableElement){const d=de(l),c=i==="csv"?me(d):ue(d);he(i==="csv"?"table.csv":"table.md",c,i==="csv"?"text/csv":"text/markdown")}O(t);return}if(a==="mermaid-copy"){const i=n.getAttribute("data-md-source")??"";i&&H(i).then(()=>ce(n,e.labels.copied,"copy",e.labels.copyDiagram));return}if(a==="mermaid-zoom-in"||a==="mermaid-zoom-out"||a==="mermaid-fit"){r.preventDefault();const i=n.closest('[data-markdown="mermaid-block"]'),l=Rt(i);a==="mermaid-zoom-in"?l?.zoomIn():a==="mermaid-zoom-out"?l?.zoomOut():l?.fit();return}if(a==="mermaid-download"){const i=n.closest('[data-markdown="mermaid-block"]')?.querySelector('[data-markdown="mermaid"]'),l=i?.getAttribute("data-md-original-svg")??i?.innerHTML??"";l&&he("diagram.svg",l,"image/svg+xml;charset=utf-8");return}if(a==="preview-loopback"){r.preventDefault();const i=n.getAttribute("data-md-url")??"";i&&e.onPreviewLoopback?.(i);return}};return t.addEventListener("click",o),()=>t.removeEventListener("click",o)},ge=(t,e,o)=>{let r=0;for(const n of t){const a=r+n.data.length;if(e<a||e===a&&o==="left")return{node:n,offset:Math.max(0,e-r)};r=a}const s=t.at(-1);return s?{node:s,offset:s.data.length}:null},Ut=new Set(["dockerfile","makefile","readme","license",".env",".gitignore",".npmrc"]),be=Array.from(Ut).map(t=>t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join("|"),Zt=t=>et(t),Xt=t=>Qe(t),$=t=>{let e=(t||"").trim();return e?((e.startsWith("`")&&e.endsWith("`")||e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'"))&&(e=e.slice(1,-1).trim()),e=e.replace(/[.,;!?]+$/g,""),e.endsWith(")")&&!e.includes("(")&&(e=e.slice(0,-1)),e.endsWith("]")&&!e.includes("[")&&(e=e.slice(0,-1)),e):""},D=t=>{let e=$(t);if(!e)return"";const o=e.indexOf(";");o>=0&&(e=e.slice(0,o)),e=e.replace(/#.*$/,"");const r=e.match(/^(.*\.[A-Za-z0-9_-]{1,16}):.*$/);r&&(e=r[1]??e);const s=be.length>0?e.match(new RegExp(`^(.*(?:/|^)(${be})):.*$`,"i")):null;return s&&(e=s[1]??e),$(e)},Pe=t=>{const e=$(t);if(!e)return null;const o=e.indexOf(";"),r=o>=0?$(e.slice(0,o)):e;if(!r)return null;const s=r.match(/^(.*?):(\d+)-(\d+)$/);if(s){const l=D(s[1]??""),d=Number.parseInt(s[2]??"",10),c=Number.parseInt(s[3]??"",10);return!l||!Number.isFinite(d)||!Number.isFinite(c)||c<d?null:{path:l,line:d,endLine:c}}const n=r.match(/^(.*)#L(\d+)(?:C(\d+))?$/i);if(n){const l=D(n[1]??""),d=Number.parseInt(n[2]??"",10),c=n[3]?Number.parseInt(n[3],10):void 0;return!l||!Number.isFinite(d)?null:{path:l,line:d,column:Number.isFinite(c??Number.NaN)?c:void 0}}const a=r.match(/^(.*?):(\d+)(?::(\d+))?$/);if(a){const l=D(a[1]??""),d=Number.parseInt(a[2]??"",10),c=a[3]?Number.parseInt(a[3],10):void 0;return!l||!Number.isFinite(d)?null:{path:l,line:d,column:Number.isFinite(c??Number.NaN)?c:void 0}}const i=D(r);return i?{path:i}:null},K=/(?:[A-Za-z]:[\\/])?[\w.\-/@+]*[\w\-/@+]\.[A-Za-z0-9]{1,8}(?::\d+(?:-\d+)?(?::\d+)?)?/g,Re=()=>{const t=rt(),e=oe(!1),o=oe(!0);return t?.currentTheme??(typeof window<"u"&&window.matchMedia("(prefers-color-scheme: dark)").matches?o:e)},Ie=({containerRef:t,enabled:e})=>{y.useEffect(()=>{if(e===!1)return;const o=t.current;if(!o)return;const r=s=>{if(s.defaultPrevented||s.button!==0||s.metaKey||s.ctrlKey||s.altKey||s.shiftKey)return;const n=s.target;if(!(n instanceof Element))return;const a=n.closest("a[href]");if(!(a instanceof HTMLAnchorElement)||a.getAttribute("data-pichamber-file-link")==="true")return;const i=a.getAttribute("href")??"";ve(i)&&(s.preventDefault(),s.stopPropagation(),ot(i))};return o.addEventListener("click",r),()=>{o.removeEventListener("click",r)}},[t,e])},R={download:!0,copy:!0,showPanZoomControls:!0},_e=!0,Gt=t=>{const e=t.match(/^(?:\uFEFF)?(---|\+\+\+)[^\S\r\n]*\r?\n[\s\S]*?\r?\n\1[^\S\r\n]*(?:\r?\n|$)/);return e?t.slice(e[0].length):t},we='[data-pichamber-file-link="true"]',Fe="data-pichamber-block-path-token",Oe=`[${Fe}]`,P="data-pichamber-block-paths-scanned",Yt=2e5,Jt=4,Qt=1e3,er=80,ye=160,N=new Map;let W=0;const Ae=[],tr=()=>Qt,rr=()=>er,or=new Set(["dockerfile","makefile","readme","license",".env",".gitignore",".npmrc"]),Y=t=>Zt(t),nr=t=>Xt(t),ar=(t,e)=>it(t,e),ir=t=>{const e=t.split("/").filter(Boolean).pop()??"";return!e||e.endsWith(".")?!1:/\.[A-Za-z0-9_-]{1,16}$/.test(e)},De=t=>{if(!t||t.startsWith("--")||t.includes("://")||/[<>]/.test(t)||/\s{2,}/.test(t))return!1;const e=Y(t),o=e.split("/").filter(Boolean).pop()??e;if(!o||o==="."||o==="..")return!1;const r=o.toLowerCase();return or.has(r)||r.startsWith(".")&&r.length>1?!0:ir(e)},We=t=>{const e=Pe(t);return e?De(e.path):!1},sr=t=>{const e=t.querySelectorAll(Oe);for(const r of Array.from(e))r.replaceWith(t.ownerDocument.createTextNode(r.textContent??""));const o=t.querySelectorAll(`code[${P}]`);for(const r of Array.from(o))r.removeAttribute(P),r.normalize()},V=t=>{if(t.tagName.toLowerCase()==="a"){const e=t.getAttribute("href")?.trim();if(e&&We(e))return e}return(t.textContent||"").trim()},lr=t=>{const e=t.querySelectorAll("pre code");if(e.length===0)return;const o=t.ownerDocument;if(o)for(const r of Array.from(e)){if(r.getAttribute(P)==="true")continue;if((r.textContent??"").length>Yt){r.setAttribute(P,"true");continue}const s=o.createTreeWalker(r,NodeFilter.SHOW_TEXT),n=[];let a=s.nextNode();for(;a;){const c=a;c.parentElement?.closest("[data-md-code-line-number]")||n.push(c),a=s.nextNode()}const i=Te(r);if(!i.includes(".")){r.setAttribute(P,"true");continue}K.lastIndex=0;const l=[];let d=K.exec(i);for(;d;){const c=d[0];c&&We(c)&&l.push({start:d.index,end:d.index+c.length,raw:c}),d=K.exec(i)}for(const{start:c,end:p,raw:u}of l.reverse()){const f=ge(n,c,"right"),h=ge(n,p,"left");if(!f||!h)continue;const A=o.createRange();A.setStart(f.node,f.offset),A.setEnd(h.node,h.offset);const v=o.createElement("span");v.setAttribute(Fe,"true"),v.textContent=u,A.deleteContents(),A.insertNode(v)}r.setAttribute(P,"true")}},U=(t,e)=>{const o=Pe(t);if(!o||!De(o.path))return null;const r=nr(o.path)?Y(o.path):ar(e,o.path);return r?{...o,resolvedPath:r}:null},cr=t=>{const e=Y(t);if(!e)return Promise.resolve(!1);const o=N.get(e);if(o)return N.delete(e),N.set(e,o),o;const r=new Promise(n=>{const a=()=>{W+=1,dt(`/api/fs/stat?path=${encodeURIComponent(e)}&optional=true`,{method:"GET",cache:"no-store"}).then(async i=>{if(!i.ok){n(!1);return}const l=await i.json().catch(()=>null);n(l?.exists!==!1)}).catch(()=>n(!1)).finally(()=>{W=Math.max(0,W-1),Ae.shift()?.()})};if(W<Jt){a();return}Ae.push(a)}),s=tr();for(;N.size>=s;){const n=N.keys().next().value;if(typeof n!="string")break;N.delete(n)}return N.set(e,r),r},dr=(t,e)=>t||at(t,e),qe=({containerRef:t,effectiveDirectory:e,editor:o,preferRuntimeEditor:r,enabled:s})=>{const n=y.useRef(null);y.useEffect(()=>{const a=t.current;if(!a)return;let i=!1;const l=rr(),d=s&&!mt(),c=g=>{g.removeAttribute("data-pichamber-file-link"),g.removeAttribute("data-pichamber-file-ref"),g.removeAttribute("data-pichamber-file-path"),g.getAttribute("title")==="Open file"&&g.removeAttribute("title"),g.tagName.toLowerCase()!=="a"&&(g.removeAttribute("role"),g.removeAttribute("tabindex"))},p=()=>{const g=a.querySelectorAll(we);for(const b of Array.from(g))c(b);sr(a)};if(!d){p();return}const u=(g=0)=>{if(n.current!==null&&typeof window<"u"&&window.clearTimeout(n.current),typeof window>"u"){f();return}n.current=window.setTimeout(()=>{n.current=null,window.requestAnimationFrame(()=>{i||f()})},g)},f=()=>{d&&lr(a);const g=a.querySelectorAll(`[data-markdown="inline-code"], a, ${Oe}`);let b=0;for(const m of Array.from(g)){const C=V(m),E=U(C,e);if(c(m),!E||b>=l)continue;b+=1,(lt()&&ct()&&!te(E.resolvedPath,e)?Promise.resolve(!0):cr(E.resolvedPath)).then(Ke=>{if(i||!Ke||!a.contains(m))return;const ee=V(m),z=U(ee,e);!z||z.resolvedPath!==E.resolvedPath||(m.setAttribute("data-pichamber-file-link","true"),m.setAttribute("data-pichamber-file-ref",ee),m.setAttribute("data-pichamber-file-path",z.resolvedPath),m.setAttribute("title","Open file"),m.tagName.toLowerCase()!=="a"&&(m.setAttribute("role","button"),m.setAttribute("tabindex","0")))})}},h=async g=>{const b=g.getAttribute("data-pichamber-file-ref")||V(g),m=U(b,e);if(!m)return;const C=dr(e,m.resolvedPath);te(m.resolvedPath,e)||await nt(m.resolvedPath,e);const E=T.getState();Number.isFinite(m.line??Number.NaN)?E.openContextFileAtLine(C,m.resolvedPath,Math.max(1,Math.trunc(m.line)),Number.isFinite(m.column??Number.NaN)?Math.max(1,Math.trunc(m.column)):1):E.openContextFile(C,m.resolvedPath)},A=g=>{const b=g.target;if(!(b instanceof Element))return;const m=b.closest(we);m instanceof HTMLElement&&(g.preventDefault(),g.stopPropagation(),h(m))},v=g=>{if(g.key!=="Enter"&&g.key!==" ")return;const b=g.target;!(b instanceof HTMLElement)||b.getAttribute("data-pichamber-file-link")!=="true"||(g.preventDefault(),g.stopPropagation(),h(b))};u(ye);const w=new MutationObserver(()=>{u(ye)});return w.observe(a,{childList:!0,subtree:!0}),a.addEventListener("click",A),a.addEventListener("keydown",v),()=>{i=!0,n.current!==null&&typeof window<"u"&&window.clearTimeout(n.current),n.current=null,w.disconnect(),a.removeEventListener("click",A),a.removeEventListener("keydown",v)}},[t,o,e,r,s])},Be=({containerRef:t,onShowPopup:e,enableFullscreen:o,enablePanZoom:r,allowMermaidWheelEvents:s})=>{y.useEffect(()=>{const n=t.current;if(!n)return;const a=l=>{if(!e)return;const d=l.target;if(!(d instanceof Element)||d.closest('button, a, [role="button"]'))return;const c=d.closest(F);if(!c)return;if(c instanceof HTMLElement&&c.hasAttribute("data-mermaid-suppress-click")){c.removeAttribute("data-mermaid-suppress-click");return}const u=Array.from(n.querySelectorAll(F)).indexOf(c);if(u<0)return;const f=c instanceof HTMLElement?c.getAttribute("data-md-source"):null;if(!f||f.trim().length===0)return;const h=`Diagram ${u+1}`;e({open:!0,title:h,content:"",metadata:{tool:"mermaid-preview",filename:h},mermaid:{url:`data:text/plain;charset=utf-8,${encodeURIComponent(f)}`,source:f,filename:h}})},i=l=>{if(s||(l.ctrlKey||l.metaKey)&&r)return;const d=l.target;!(d instanceof Element)||!d.closest(F)||l.stopPropagation()};return n.addEventListener("click",a),n.addEventListener("wheel",i,{capture:!0,passive:!0}),()=>{n.removeEventListener("click",a),n.removeEventListener("wheel",i,!0)}},[s,t,o,r,e])},x=new Map,mr=100,ur=(t,e)=>{const o=x.get(t);if(o)return x.delete(t),x.set(t,o),o;const r=e();if(x.set(t,r),x.size>mr){const s=x.keys().next().value;s&&x.delete(s)}return r},pr=t=>({bg:t.colors.surface.elevated,fg:t.colors.surface.foreground,line:t.colors.interactive.border,accent:t.colors.primary.base,muted:t.colors.surface.mutedForeground,surface:t.colors.surface.muted,border:t.colors.interactive.border,transparent:!0,font:"system-ui, sans-serif"}),$e=(t,e,o,r=R)=>{const s=y.useMemo(()=>({copy:"Copy code",copied:"Copied",enableCodeWrap:"Enable line wrap",disableCodeWrap:"Disable line wrap",copyTable:"Copy table",downloadTable:"Download table",copyDiagram:"Copy source",downloadDiagram:"Download SVG",zoomInDiagram:"Zoom in",zoomOutDiagram:"Zoom out",resetDiagramView:"Reset view",previewLabel:"Preview",previewTitle:"Open preview pane"}),[]),n=T(l=>l.codeBlockLineWrap),a=T(l=>l.setCodeBlockLineWrap),i=y.useCallback(()=>{a(!T.getState().codeBlockLineWrap)},[a]);return y.useMemo(()=>{const l=pr(t),d=T.getState().mermaidRenderingMode,c=t.metadata?.id??"theme";return{labels:s,mermaidControls:r,codeBlockLineWrap:n,deferCodeLineNumberSync:e,onToggleCodeBlockLineWrap:i,renderMermaid:u=>ur(`${c}:${d}:${u}`,()=>{try{return d==="ascii"?{ascii:Ue(u)}:{svg:Ze(u,l)}}catch{return{}}}),onPreviewLoopback:o}},[t,s,r,n,e,i,o])},ze=t=>{t.style.display="contents",t.style.width="",t.style.minWidth="",t.style.maxWidth=""},Z=(t,e)=>{ze(t);const o=gt(e);let r=t.querySelector(":scope > [data-md-live]");const s=r?.hasAttribute("data-md-live-pre")===!0;(!r||s!==o)&&(t.replaceChildren(),r=document.createElement(o?"div":"p"),r.setAttribute("data-md-live",""),o&&r.setAttribute("data-md-live-pre",""),r.className=o?"w-full min-w-0 whitespace-pre-wrap break-words":"w-full min-w-0 break-words",r.appendChild(document.createTextNode("")),t.appendChild(r));const n=r.firstChild;if(!(n instanceof globalThis.Text)){r.replaceChildren(document.createTextNode(e));return}if(e.startsWith(n.data)){const a=e.slice(n.data.length);a.length>0&&n.appendData(a);return}n.data=e},He=({containerRef:t,text:e,streaming:o,cacheKey:r,syntaxVars:s,ctx:n})=>{y.useEffect(()=>{yt()},[]);const a=y.useRef(null),i=y.useRef(null),l=y.useRef(r);l.current!==r&&(l.current=r,i.current=null);const d=y.useCallback(()=>{const c=t.current;if(c){if(!a.current){if(!S(c))return;a.current=Dt(c);return}a.current.refresh()}},[t]);y.useLayoutEffect(()=>{const c=t.current,p=c?.querySelector("[data-markdown-content]")??c;if(p&&e&&p.childNodes.length===0){const u=document.createElement("div");if(u.setAttribute("data-md-block",""),u.style.display="contents",o){Z(u,e),p.appendChild(u);return}u.innerHTML=ut(e),fe(u,n),p.appendChild(u),S(u)&&d()}},[t,e,o,n,d]),y.useEffect(()=>()=>{a.current?.cleanup(),a.current=null},[]),y.useEffect(()=>{const c=t.current;if(!c)return;const p=c.querySelector("[data-markdown-content]")??c;let u=!0;if(o&&i.current){const f=pt(r).update(e);if(ft(i.current,f)){const h=f[f.length-1],A=p.querySelectorAll(":scope > [data-md-block]")[f.length-1];if(h&&A){Z(A,h.raw),A.setAttribute("data-md-id",`live:${f.length-1}`),i.current=i.current.map((v,w)=>w===f.length-1?{...v,raw:h.raw,id:`live:${w}`,mode:"live"}:v);return}}}return ht(e,o,r).then(f=>{if(!u)return;const h=Array.from(p.querySelectorAll(":scope > [data-md-block]"));f.forEach((w,g)=>{let b=h[g];if(b||(b=document.createElement("div"),b.setAttribute("data-md-block",""),b.style.display="contents",p.appendChild(b)),w.mode==="live"){Z(b,w.raw),b.setAttribute("data-md-id",w.id);return}if(ze(b),b.getAttribute("data-md-id")===w.id)return;const m=document.createElement("div");m.innerHTML=w.html,fe(m,n);const C=S(b),E=S(m);Ve(b,m,{childrenOnly:!0,onBeforeElUpdated:(J,Q)=>!J.isEqualNode(Q)}),b.setAttribute("data-md-id",w.id),(C||E||S(b))&&d()});const A=S(p);let v=!1;for(let w=h.length-1;w>=f.length;w-=1){const g=h[w];g&&S(g)&&(v=!0),g?.remove()}(v||h.length>f.length&&A)&&d(),i.current=f}),()=>{u=!1}},[t,e,o,r,n,d]),y.useEffect(()=>{const c=t.current;if(c)return Vt(c,n)},[t,n]),y.useEffect(()=>{const c=t.current,p=c?.querySelector("[data-markdown-content]")??c;if(p)for(const[u,f]of Object.entries(s))p.style.setProperty(u,f)},[t,s]),y.useEffect(()=>{const c=t.current,p=c?.querySelector("[data-markdown-content]")??c;p&&(n.deferCodeLineNumberSync||Wt(p,n.codeBlockLineWrap,n.labels))},[t,n.codeBlockLineWrap,n.deferCodeLineNumberSync,n.labels])},je=(t,e)=>X("w-full min-w-0",t==="tool"?"markdown-content markdown-tool":t==="reasoning"?"markdown-content markdown-reasoning":"markdown-content leading-relaxed",e&&"markdown-streaming"),fr=({content:t,part:e,messageId:o,isAnimated:r=!0,skipFadeIn:s=!1,className:n,isStreaming:a=!1,disableStreamAnimation:i=!1,variant:l="assistant",onShowPopup:d,enableFileReferences:c=!0})=>{re("ui.markdown_renderer.render"),a&&re("ui.markdown_renderer.render.streaming"),st("ui.markdown_renderer.content_len",t.length);const p=Re(),{editor:u}=ke(),f=y.useRef(null),h=Ce()??"",A=T(E=>E.openContextPreview),v=y.useCallback(E=>{h&&A(h,E)},[h,A]),w=a&&!i;Be({containerRef:f,onShowPopup:d,enableFullscreen:_e,enablePanZoom:R.showPanZoomControls}),qe({containerRef:f,effectiveDirectory:h,editor:u,preferRuntimeEditor:!1,enabled:c&&!a}),Ie({containerRef:f});const g=y.useMemo(()=>Ee(p),[p]),b=$e(p,w,h?v:void 0,R),m=`markdown-${e?.id?`part-${e.id}`:`message-${o}`}`;He({containerRef:f,text:t,streaming:w,cacheKey:m,syntaxVars:g,ctx:b});const C=_.jsx("div",{className:X("break-words w-full min-w-0",n),ref:f,children:_.jsx("div",{className:je(l,w),"data-markdown-content":!0})});return r?_.jsx(tt,{skipAnimation:s,children:C},m):C},fn=y.memo(fr,(t,e)=>t.content===e.content&&t.isStreaming===e.isStreaming&&t.disableStreamAnimation===e.disableStreamAnimation&&t.variant===e.variant&&t.isAnimated===e.isAnimated&&t.skipFadeIn===e.skipFadeIn&&t.className===e.className&&t.messageId===e.messageId&&t.onShowPopup===e.onShowPopup&&t.enableFileReferences===e.enableFileReferences&&t.part?.id===e.part?.id),hr=({content:t,className:e,variant:o="assistant",disableLinkSafety:r,stripFrontmatter:s=!1,onShowPopup:n,mermaidControls:a=R,allowMermaidWheelEvents:i=!1,enableFileReferences:l=!0})=>{const{editor:d}=ke(),c=Re(),p=y.useRef(null),u=Ce()??"",f=y.useMemo(()=>s?Gt(t):t,[t,s]);Be({containerRef:p,onShowPopup:n,enableFullscreen:_e,enablePanZoom:a.showPanZoomControls,allowMermaidWheelEvents:i}),qe({containerRef:p,effectiveDirectory:u,editor:d,preferRuntimeEditor:!1,enabled:l}),Ie({containerRef:p,enabled:!r});const h=y.useMemo(()=>Ee(c),[c]),A=$e(c,!1,void 0,a);return He({containerRef:p,text:f,streaming:!1,cacheKey:`simple:${o}`,syntaxVars:h,ctx:A}),_.jsx("div",{className:X("break-words w-full min-w-0",e),ref:p,children:_.jsx("div",{className:je(o),"data-markdown-content":!0})})},hn=y.memo(hr,(t,e)=>{const o=t.mermaidControls??R,r=e.mermaidControls??R;return t.content===e.content&&t.variant===e.variant&&t.className===e.className&&t.disableLinkSafety===e.disableLinkSafety&&t.stripFrontmatter===e.stripFrontmatter&&t.onShowPopup===e.onShowPopup&&o.download===r.download&&o.copy===r.copy&&o.showPanZoomControls===r.showPanZoomControls&&t.allowMermaidWheelEvents===e.allowMermaidWheelEvents&&t.enableFileReferences===e.enableFileReferences});export{fn as MarkdownRenderer,hn as SimpleMarkdownRenderer};
@@ -0,0 +1 @@
1
+ import{dv as j,dX as y,e0 as D}from"./SessionSwitcherDropdown-DNjCJjzF.js";import{f as k,B as C}from"./web-components-DgFD1Jms.js";import{M as P,G as O,u as L,W as A,a as M,b as R,n as F,t as H}from"./Virtualizer-BxW2CJGB.js";import{j as d,r as w}from"./vendor-react-DYyjh7Q0.js";import{V as _,F as N}from"./VirtualizedFileDiff-CC5lTPJS.js";function T({hunkIndex:e,lineIndex:t,conflictIndex:n}){return`merge-conflict-action-${e}-${t}-${n}`}function V(e,t){const n=t.hunks[e.hunkIndex];if(n!=null)return{hunkIndex:e.hunkIndex,lineIndex:z(n,e.startContentIndex)}}function z(e,t){let n=e.unifiedLineStart;for(let l=0;l<t;l++){const o=e.hunkContent[l];n+=o.type==="context"?o.lines:o.deletions+o.additions}return n}function U(e){const t=j(e);if(t.length!==1)throw console.error(t),new Error("PatchDiff: Provided patch must include only 1 patch, with 1 diff");const{files:n}=t[0];if(n.length!==1)throw console.error(n),new Error("FileDiff: Provided patch must contain exactly 1 file diff");return n[0]}function $({fileDiff:e,actions:t,renderCustomHeader:n,renderHeaderPrefix:l,renderHeaderFilenameSuffix:o,renderHeaderMetadata:x,renderAnnotation:f,renderGutterUtility:u,renderMergeConflictUtility:s,lineAnnotations:a,getHoveredLine:p,getInstance:m}){const g=n?.(e),c=l?.(e),i=o?.(e),v=x?.(e);return d.jsxs(d.Fragment,{children:[g!=null?d.jsx("div",{slot:y,children:g}):d.jsxs(d.Fragment,{children:[c!=null&&d.jsx("div",{slot:"header-prefix",children:c}),i!=null&&d.jsx("div",{slot:"header-filename-suffix",children:i}),v!=null&&d.jsx("div",{slot:"header-metadata",children:v})]}),f!=null&&a?.map((r,h)=>d.jsx("div",{slot:k(r),children:f(r)},h)),t!=null&&s!=null&&m!=null&&t.map(r=>{if(r==null)return;const h=b(r,e);return d.jsx("div",{slot:h,style:P,children:s(r,m)},h)}),u!=null&&d.jsx("div",{slot:"gutter-utility-slot",style:O,children:u(p)})]})}function b(e,t){const n=V(e,t);return n!=null?T({hunkIndex:n.hunkIndex,lineIndex:n.lineIndex,conflictIndex:e.conflictIndex}):void 0}const S=typeof window>"u"?w.useEffect:w.useLayoutEffect;function G({fileDiff:e,options:t,lineAnnotations:n,selectedLines:l,prerenderedHTML:o,metrics:x,hasGutterRenderUtility:f,hasCustomHeader:u,disableWorkerPool:s,contentEditable:a}){const p=L(),m=l!==void 0,g=w.useContext(A),c=M(),i=w.useRef(null),v=R(r=>{if(r!=null){if(i.current!=null)throw new Error("useFileDiffInstance: An instance should not already exist when a node is created");p!=null?i.current=new _(E({controlledSelection:m,contentEditable:a,hasCustomHeader:u,hasEditor:c!==void 0,hasGutterRenderUtility:f,options:t}),p,x,s?void 0:g,!0):i.current=new N(E({controlledSelection:m,contentEditable:a,hasCustomHeader:u,hasEditor:c!==void 0,hasGutterRenderUtility:f,options:t}),s?void 0:g,!0),i.current.hydrate({fileDiff:e,fileContainer:r,lineAnnotations:n,prerenderedHTML:o})}else{if(i.current==null)throw new Error("useFileDiffInstance: A FileDiff instance should exist when unmounting");i.current.cleanUp(),i.current=null}});return S(()=>{const{current:r}=i;if(r==null)return;const h=E({controlledSelection:m,contentEditable:a,hasCustomHeader:u,hasEditor:c!==void 0,hasGutterRenderUtility:f,options:t}),I=!C(r.options,h);r.setOptions(h),r.render({forceRender:I,fileDiff:e,lineAnnotations:n}),l!==void 0&&r.setSelectedLines(l)}),S(()=>{if(a&&i.current!=null){if(c===void 0)throw new Error("FileDiff: Editor is not attached");return c.edit(i.current)}},[a,c]),{ref:v,getHoveredLine:w.useCallback(()=>i.current?.getHoveredLine(),[])}}function E({options:e,controlledSelection:t,contentEditable:n,hasCustomHeader:l,hasEditor:o,hasGutterRenderUtility:x}){const f=n&&o,u=t||x||l;if(!u&&!f)return e;let s={...e};return u&&(s={...s,controlledSelection:t,renderCustomHeader:l?F:e?.renderCustomHeader,renderGutterUtility:x?F:e?.renderGutterUtility}),f&&(s={...s,useTokenTransformer:!0,enableGutterUtility:!1,enableLineSelection:!1,expandUnchanged:!0,lineHoverHighlight:"disabled"}),s}function Q({patch:e,options:t,metrics:n,lineAnnotations:l,selectedLines:o,className:x,style:f,prerenderedHTML:u,renderAnnotation:s,renderCustomHeader:a,renderHeaderPrefix:p,renderHeaderFilenameSuffix:m,renderHeaderMetadata:g,renderGutterUtility:c,disableWorkerPool:i=!1,contentEditable:v=!1}){const r=q(e),{ref:h,getHoveredLine:I}=G({fileDiff:r,options:t,metrics:n,lineAnnotations:l,selectedLines:o,prerenderedHTML:u,hasGutterRenderUtility:c!=null,hasCustomHeader:a!=null,disableWorkerPool:i,contentEditable:v});return d.jsx(D,{ref:h,className:x,style:f,children:H($({fileDiff:r,renderCustomHeader:a,renderHeaderPrefix:p,renderHeaderFilenameSuffix:m,renderHeaderMetadata:g,renderAnnotation:s,lineAnnotations:l,renderGutterUtility:c,getHoveredLine:I}),u)})}function q(e){return w.useMemo(()=>U(e),[e])}export{Q as P};
@@ -1,4 +1,4 @@
1
- import{R as F,j as O,b as we,r as d}from"./vendor-react-DYyjh7Q0.js";import{B as $e}from"./web-components-P2py0R8j.js";import{f as Te}from"./computeVirtualFileMetrics-CInbUZiB.js";import{V as Ne,F as Be}from"./VirtualizedFileDiff-BELx71mz.js";import{by as je,aD as Ue,aY as Ge,f as ke}from"./useAppFontEffects-DqOhrZWx.js";import{ah as Qe}from"./runtimeEndpointReset-DiVqZFZB.js";import{I as Ce,a as Ke,u as Ye}from"./useInlineCommentController-ruw8wb2Y.js";import{ensurePierreThemeRegistered as Me,getResolvedShikiTheme as Oe}from"./appThemeRegistry-BK0dHKa6.js";import{V as De}from"./index-Dnby-sDS.js";const he=new Set;let Re=null;function I(s){he.add(s),Re??=requestAnimationFrame(Pe)}function Pe(s){const e=new Set(he);he.clear();for(const t of e)try{t(s)}catch(n){console.error(n)}he.size>0?Re=requestAnimationFrame(Pe):Re=null}function Le({scrollTop:s,scrollHeight:e,height:t,fitPerfectly:n=!1,fitPerfectlyOverscroll:r=0,overscrollSize:l}){const u=t+l*2,h=n?t+r*2:u;if(e=Math.max(e,h),u>=e||n){const m=Math.max(s-r,0),S=Math.min(s+h,e);return{top:m,bottom:Math.max(S,m)}}let a=s+t/2-u/2,g=a+u;return a<0&&(a=0),g>e&&(g=e),a=Math.floor(Math.max(a,0)),{top:a,bottom:Math.ceil(Math.max(Math.min(g,e),a))}}function Ze(s,e){return s==null||e==null?s===e:s.top===e.top&&s.bottom===e.bottom}const He=1e3,Xe=He*4,Je=[0,1e-6,.99999,1],et={overscrollSize:He,intersectionObserverMargin:Xe,resizeDebugging:!1};let ue=0,tt=-1;var nt=class H{static __STOP=!1;static __lastScrollPosition=0;__id=`virtualizer-${++tt}`;config;type="simple";intersectionObserver;scrollTop=0;height=0;scrollHeight=0;windowSpecs={top:0,bottom:0};root;contentContainer;resizeObserver;observers=new Map;visibleInstances=new Map;visibleInstancesDirty=!1;instancesChanged=new Set;scrollDirty=!0;heightDirty=!0;scrollHeightDirty=!0;renderedObservers=0;connectQueue=new Map;constructor(e){this.config={...et,...e}}setup(e,t){if(this.root==null){this.root=e,this.resizeObserver=new ResizeObserver(this.handleContainerResize),this.intersectionObserver=new IntersectionObserver(this.handleIntersectionChange,{root:this.root,threshold:Je,rootMargin:`${this.config.intersectionObserverMargin}px 0px ${this.config.intersectionObserverMargin}px 0px`}),e instanceof Document?this.setupWindow():this.setupElement(t),window.__INSTANCE=this,window.__TOGGLE=()=>{H.__STOP?(H.__STOP=!1,(this.getScrollContainerElement()??window).scrollTo({top:H.__lastScrollPosition}),I(this.computeRenderRangeAndEmit)):(H.__lastScrollPosition=this.getScrollTop(),H.__STOP=!0)};for(const[n,r]of this.connectQueue.entries())this.connect(n,r);this.connectQueue.clear(),this.markDOMDirty(),I(this.computeRenderRangeAndEmit)}}instanceChanged(e,t){this.instancesChanged.add(e),t&&this.markDOMDirty(),I(this.computeRenderRangeAndEmit)}getWindowSpecs(){return this.windowSpecs.top===0&&this.windowSpecs.bottom===0&&(this.windowSpecs=Le({scrollTop:this.getScrollTop(),height:this.getHeight(),scrollHeight:this.getScrollHeight(),overscrollSize:this.config.overscrollSize})),this.windowSpecs}isInstanceVisible(e,t){const n=this.getScrollTop(),r=this.getHeight(),l=this.config.intersectionObserverMargin,u=n-l,h=n+r+l;return!(e<u-t||e>h)}handleContainerResize=e=>{if(this.root==null)return;let t=!1;for(const n of e){const r=n.borderBoxSize[0].blockSize;this.root instanceof Document?r!==this.scrollHeight&&(this.scrollHeightDirty=!0,t=!0,this.config.resizeDebugging&&(console.log("Virtualizer: content size change",this.__id,{sizeChange:r-ue,newSize:r}),ue=r)):n.target===this.root?r!==this.height&&(this.heightDirty=!0,t=!0):n.target===this.contentContainer&&(this.scrollHeightDirty=!0,t=!0,this.config.resizeDebugging&&(console.log("Virtualizer: scroller size change",this.__id,{sizeChange:r-ue,newSize:r}),ue=r))}t&&I(this.computeRenderRangeAndEmit)};setupWindow(){if(this.root==null||!(this.root instanceof Document))throw new Error("Virtualizer.setupWindow: Invalid setup method");window.addEventListener("scroll",this.handleWindowScroll,{passive:!0}),window.addEventListener("resize",this.handleWindowResize,{passive:!0}),this.resizeObserver?.observe(this.root.documentElement)}setupElement(e){if(this.root==null||this.root instanceof Document)throw new Error("Virtualizer.setupElement: Invalid setup method");this.root.addEventListener("scroll",this.handleElementScroll,{passive:!0}),this.resizeObserver?.observe(this.root),e??=this.root.firstElementChild??void 0,e instanceof HTMLElement&&(this.contentContainer=e,this.resizeObserver?.observe(e))}cleanUp(){this.resizeObserver?.disconnect(),this.resizeObserver=void 0,this.intersectionObserver?.disconnect(),this.intersectionObserver=void 0,this.root?.removeEventListener("scroll",this.handleElementScroll),window.removeEventListener("scroll",this.handleWindowScroll),window.removeEventListener("resize",this.handleWindowResize),this.root=void 0,this.contentContainer=void 0,this.observers.clear(),this.visibleInstances.clear(),this.instancesChanged.clear(),this.connectQueue.clear(),this.visibleInstancesDirty=!1,this.windowSpecs={top:0,bottom:0},this.scrollTop=0,this.height=0,this.scrollHeight=0}getOffsetInScrollContainer(e){return this.getScrollTop()+se(e,this.getScrollContainerElement())}connect(e,t){if(this.observers.has(e))throw new Error("Virtualizer.connect: instance is already connected...");return this.intersectionObserver==null?this.connectQueue.set(e,t):(this.intersectionObserver.observe(e),this.observers.set(e,t),this.instancesChanged.add(t),this.markDOMDirty(),I(this.computeRenderRangeAndEmit)),()=>this.disconnect(e)}disconnect(e){const t=this.observers.get(e);this.connectQueue.delete(e),t!=null&&(this.intersectionObserver?.unobserve(e),this.observers.delete(e),this.visibleInstances.delete(e)&&(this.visibleInstancesDirty=!0),this.markDOMDirty(),I(this.computeRenderRangeAndEmit))}handleWindowResize=()=>{H.__STOP||window.innerHeight===this.height||(this.heightDirty=!0,I(this.computeRenderRangeAndEmit))};handleWindowScroll=()=>{H.__STOP||this.root==null||!(this.root instanceof Document)||(this.scrollDirty=!0,I(this.computeRenderRangeAndEmit))};handleElementScroll=()=>{H.__STOP||this.root==null||this.root instanceof Document||(this.scrollDirty=!0,I(this.computeRenderRangeAndEmit))};computeRenderRangeAndEmit=()=>{if(H.__STOP)return;const e=this.heightDirty||this.scrollHeightDirty;if(!this.scrollDirty&&!this.scrollHeightDirty&&!this.heightDirty&&this.renderedObservers===this.observers.size&&!this.visibleInstancesDirty&&this.instancesChanged.size===0)return;let t=this.instancesChanged.size>0;if(this.instancesChanged.size===0){const l=Le({scrollTop:this.getScrollTop(),height:this.getHeight(),scrollHeight:this.getScrollHeight(),overscrollSize:this.config.overscrollSize});if(!e&&Ze(this.windowSpecs,l)&&this.renderedObservers===this.observers.size&&!this.visibleInstancesDirty)return;this.windowSpecs=l}this.visibleInstancesDirty=!1,this.renderedObservers=this.observers.size;const n=this.getScrollAnchor(this.height),r=new Set;for(const l of e?this.observers.values():this.visibleInstances.values())l.onRender(e)&&r.add(l);for(const l of this.instancesChanged)r.has(l)||l.onRender(e)&&r.add(l);this.scrollFix(n);for(const l of r)l.reconcileHeights();t||=this.instancesChanged.size>0,t&&this.markDOMDirty(),(t||e)&&I(this.computeRenderRangeAndEmit),r.clear(),this.instancesChanged.clear()};scrollFix(e){if(e==null)return;const t=this.getScrollContainerElement(),{lineIndex:n,lineOffset:r,fileElement:l,fileOffset:u,fileTypeOffset:h}=e;if(n!=null&&r!=null){const g=l.shadowRoot?.querySelector(`[data-line][data-line-index="${n}"]`);if(g instanceof HTMLElement){const m=se(g,t);if(m!==r){const S=m-r;this.applyScrollFix(S)}return}}const a=se(l,t);if(h==="top")a!==u&&this.applyScrollFix(a-u);else{const g=a+l.getBoundingClientRect().height;g!==u&&this.applyScrollFix(g-u)}}applyScrollFix(e){this.root==null||this.root instanceof Document?window.scrollTo({top:window.scrollY+e,behavior:"instant"}):this.root.scrollTo({top:this.root.scrollTop+e,behavior:"instant"}),this.markDOMDirty()}getScrollAnchor(e){const t=this.getScrollContainerElement();let n;for(const[r]of this.visibleInstances.entries()){const l=se(r,t),u=l+r.offsetHeight;let h,a;u<=0?(h=u,a="bottom"):(h=l,a="top");let g,m;if(u>0&&l<e)for(const D of r.shadowRoot?.querySelectorAll("[data-line][data-line-index]")??[]){if(!(D instanceof HTMLElement))continue;const B=D.dataset.lineIndex;if(B==null)continue;const j=se(D,t);if(!(j<0)){g=B,m=j;break}}if(n?.lineOffset!=null&&m==null)continue;let S=!1;(n==null||m!=null&&(n.lineOffset==null||m<n.lineOffset)||m==null&&n.lineOffset==null&&(h>=0&&(n.fileOffset<0||h<n.fileOffset)||h<0&&n.fileOffset<0&&h>n.fileOffset))&&(S=!0),S&&(n={fileElement:r,fileTypeOffset:a,fileOffset:h,lineIndex:g,lineOffset:m})}return n}handleIntersectionChange=e=>{this.scrollDirty=!0;for(const{target:t,isIntersecting:n}of e){if(!(t instanceof HTMLElement))throw new Error("Virtualizer.handleIntersectionChange: target not an HTMLElement");const r=this.observers.get(t);r!=null&&(n&&!this.visibleInstances.has(t)?(r.setVisibility(!0),this.visibleInstances.set(t,r),this.visibleInstancesDirty=!0):!n&&this.visibleInstances.has(t)&&(r.setVisibility(!1),this.visibleInstances.delete(t),this.visibleInstancesDirty=!0))}this.visibleInstancesDirty&&I(this.computeRenderRangeAndEmit)};getScrollTop(){if(!this.scrollDirty)return this.scrollTop;this.scrollDirty=!1;let e=this.root==null?0:this.root instanceof Document?window.scrollY:this.root.scrollTop;return e=Math.max(0,Math.min(e,this.getScrollHeight()-this.getHeight())),this.scrollTop=e,e}getScrollHeight(){return this.scrollHeightDirty?(this.scrollHeightDirty=!1,this.scrollHeight=this.root==null?0:this.root instanceof Document?this.root.documentElement.scrollHeight:this.root.scrollHeight,this.scrollHeight):this.scrollHeight}getHeight(){return this.heightDirty?(this.heightDirty=!1,this.height=this.root==null?0:this.root instanceof Document?globalThis.innerHeight:this.root.getBoundingClientRect().height,this.height):this.height}markDOMDirty(){this.scrollDirty=!0,this.scrollHeightDirty=!0,this.heightDirty=!0}getScrollContainerElement(){return this.root==null||this.root instanceof Document?void 0:this.root}};function se(s,e){const t=s.getBoundingClientRect(),n=e?.getBoundingClientRect().top??0;return t.top-n}const pe=s=>{if(s.type==="new"){const e=Math.min(s.selection.start,s.selection.end),t=Math.max(s.selection.start,s.selection.end);return`new-comment-${s.selection.side??"additions"}-${e}-${t}`}return`draft-${s.draft.id}`},it=s=>{const{drafts:e,editingDraftId:t,selection:n}=s,r=[];for(const l of e){if(!Number.isFinite(l.endLine))continue;const u=Math.max(1,Math.floor(l.endLine)),h=l.side==="original"?"deletions":"additions";r.push({lineNumber:u,side:h,metadata:{type:l.id===t?"edit":"saved",draft:l}})}return n&&!t&&r.push({lineNumber:Math.max(n.start,n.end),side:n.side??"additions",metadata:{type:"new",selection:n}}),r};function rt(s){const e=s.trim();if(!e)return null;if(/^-?\d+(\.\d+)?$/.test(e)){const t=Number.parseFloat(e);return Number.isFinite(t)?t:null}if(e.endsWith("px")){const t=Number.parseFloat(e.slice(0,-2));return Number.isFinite(t)?t:null}return null}function ze(s){if(!(!s||s<=0))return Math.max(200,Math.floor(s))}function st(s){const{diffRootRef:e,drafts:t,selection:n,editingDraftId:r,commentText:l,onTextChange:u,fileLabel:h,onSave:a,onCancel:g,onEdit:m,onDelete:S}=s,[D,B]=F.useState(0),[j,X]=F.useState(null),b=F.useMemo(()=>!n||r?null:pe({type:"new",selection:n}),[r,n]),_=F.useMemo(()=>{const c=t.map(y=>pe({type:y.id===r?"edit":"saved",draft:y}));return b&&c.push(b),c},[t,r,b]),$=F.useCallback(c=>{const y=e.current;if(!y)return null;const w=y.querySelector("diffs-container");if(!(w instanceof HTMLElement))return null;const k=w.querySelector(`[data-annotation-id="${c}"]`);if(k instanceof HTMLElement)return k;const A=w.shadowRoot;return A?A.querySelector(`[data-annotation-id="${c}"]`):null},[e]);F.useEffect(()=>{if(_.length===0)return;let c=!1,y=0;const w=12,k=()=>{c||_.every(L=>!!$(L))||y>=w||(y+=1,requestAnimationFrame(()=>{c||(B(L=>L+1),k())}))};return k(),()=>{c=!0}},[_,$]),F.useEffect(()=>{const c=e.current;if(!c)return;const y=()=>{const k=getComputedStyle(c),A=rt(k.getPropertyValue("--oc-context-panel-width")),L=c.getBoundingClientRect(),N=A??L.width;X(N>0?N:null)};y();const w=new ResizeObserver(()=>{y()});return w.observe(c),window.addEventListener("resize",y),()=>{w.disconnect(),window.removeEventListener("resize",y)}},[e]);const G=F.useCallback(c=>{const w=e.current?.getBoundingClientRect(),k=c.closest("[data-annotation-content]"),A=k instanceof HTMLElement?k.getBoundingClientRect():c.getBoundingClientRect(),L=[A.width];w&&L.push(w.right-A.left);const N=L.filter(J=>Number.isFinite(J)&&J>0);return N.length>0?ze(Math.min(...N)):ze(j)},[e,j]);return O.jsxs(O.Fragment,{children:[t.map(c=>{const y=pe({type:c.id===r?"edit":"saved",draft:c}),w=$(y);if(!w)return null;const k=G(w);return c.id===r?we.createPortal(O.jsx(Ce,{initialText:l,onTextChange:u,fileLabel:h,lineRange:{start:c.startLine,end:c.endLine,side:c.side==="original"?"deletions":"additions"},isEditing:!0,onSave:a,onCancel:g,maxWidth:k}),w,`draft-edit-${c.id}`):we.createPortal(O.jsx(Ke,{draft:c,onEdit:()=>m(c),onDelete:()=>S(c),maxWidth:k}),w,`draft-card-${c.id}`)}),n&&!r&&b&&(()=>{const c=$(b);if(!c)return null;const y=G(c);return we.createPortal(O.jsx(Ce,{initialText:l,onTextChange:u,fileLabel:h,lineRange:n,isEditing:!1,onSave:a,onCancel:g,maxWidth:y}),c,b)})()]})}const Ie=5e5,ot=`
1
+ import{R as F,j as O,b as we,r as d}from"./vendor-react-DYyjh7Q0.js";import{B as $e}from"./web-components-DgFD1Jms.js";import{f as Te}from"./computeVirtualFileMetrics-BcVuV0Ic.js";import{V as Ne,F as Be}from"./VirtualizedFileDiff-CC5lTPJS.js";import{bj as je,aW as Ue,aC as Ge,f as ke}from"./SessionSwitcherDropdown-DNjCJjzF.js";import{ac as Qe}from"./usePanelSlide-BkonU4LS.js";import{I as Ce,a as Ke,u as Ye}from"./useInlineCommentController-CSR_Ju0a.js";import{ensurePierreThemeRegistered as Me,getResolvedShikiTheme as Oe}from"./appThemeRegistry-BK0dHKa6.js";import{M as Le}from"./index-DQr8-8RF.js";const he=new Set;let Re=null;function I(s){he.add(s),Re??=requestAnimationFrame(Pe)}function Pe(s){const e=new Set(he);he.clear();for(const t of e)try{t(s)}catch(n){console.error(n)}he.size>0?Re=requestAnimationFrame(Pe):Re=null}function De({scrollTop:s,scrollHeight:e,height:t,fitPerfectly:n=!1,fitPerfectlyOverscroll:r=0,overscrollSize:l}){const u=t+l*2,h=n?t+r*2:u;if(e=Math.max(e,h),u>=e||n){const m=Math.max(s-r,0),S=Math.min(s+h,e);return{top:m,bottom:Math.max(S,m)}}let a=s+t/2-u/2,g=a+u;return a<0&&(a=0),g>e&&(g=e),a=Math.floor(Math.max(a,0)),{top:a,bottom:Math.ceil(Math.max(Math.min(g,e),a))}}function Ze(s,e){return s==null||e==null?s===e:s.top===e.top&&s.bottom===e.bottom}const He=1e3,Xe=He*4,Je=[0,1e-6,.99999,1],et={overscrollSize:He,intersectionObserverMargin:Xe,resizeDebugging:!1};let ue=0,tt=-1;var nt=class H{static __STOP=!1;static __lastScrollPosition=0;__id=`virtualizer-${++tt}`;config;type="simple";intersectionObserver;scrollTop=0;height=0;scrollHeight=0;windowSpecs={top:0,bottom:0};root;contentContainer;resizeObserver;observers=new Map;visibleInstances=new Map;visibleInstancesDirty=!1;instancesChanged=new Set;scrollDirty=!0;heightDirty=!0;scrollHeightDirty=!0;renderedObservers=0;connectQueue=new Map;constructor(e){this.config={...et,...e}}setup(e,t){if(this.root==null){this.root=e,this.resizeObserver=new ResizeObserver(this.handleContainerResize),this.intersectionObserver=new IntersectionObserver(this.handleIntersectionChange,{root:this.root,threshold:Je,rootMargin:`${this.config.intersectionObserverMargin}px 0px ${this.config.intersectionObserverMargin}px 0px`}),e instanceof Document?this.setupWindow():this.setupElement(t),window.__INSTANCE=this,window.__TOGGLE=()=>{H.__STOP?(H.__STOP=!1,(this.getScrollContainerElement()??window).scrollTo({top:H.__lastScrollPosition}),I(this.computeRenderRangeAndEmit)):(H.__lastScrollPosition=this.getScrollTop(),H.__STOP=!0)};for(const[n,r]of this.connectQueue.entries())this.connect(n,r);this.connectQueue.clear(),this.markDOMDirty(),I(this.computeRenderRangeAndEmit)}}instanceChanged(e,t){this.instancesChanged.add(e),t&&this.markDOMDirty(),I(this.computeRenderRangeAndEmit)}getWindowSpecs(){return this.windowSpecs.top===0&&this.windowSpecs.bottom===0&&(this.windowSpecs=De({scrollTop:this.getScrollTop(),height:this.getHeight(),scrollHeight:this.getScrollHeight(),overscrollSize:this.config.overscrollSize})),this.windowSpecs}isInstanceVisible(e,t){const n=this.getScrollTop(),r=this.getHeight(),l=this.config.intersectionObserverMargin,u=n-l,h=n+r+l;return!(e<u-t||e>h)}handleContainerResize=e=>{if(this.root==null)return;let t=!1;for(const n of e){const r=n.borderBoxSize[0].blockSize;this.root instanceof Document?r!==this.scrollHeight&&(this.scrollHeightDirty=!0,t=!0,this.config.resizeDebugging&&(console.log("Virtualizer: content size change",this.__id,{sizeChange:r-ue,newSize:r}),ue=r)):n.target===this.root?r!==this.height&&(this.heightDirty=!0,t=!0):n.target===this.contentContainer&&(this.scrollHeightDirty=!0,t=!0,this.config.resizeDebugging&&(console.log("Virtualizer: scroller size change",this.__id,{sizeChange:r-ue,newSize:r}),ue=r))}t&&I(this.computeRenderRangeAndEmit)};setupWindow(){if(this.root==null||!(this.root instanceof Document))throw new Error("Virtualizer.setupWindow: Invalid setup method");window.addEventListener("scroll",this.handleWindowScroll,{passive:!0}),window.addEventListener("resize",this.handleWindowResize,{passive:!0}),this.resizeObserver?.observe(this.root.documentElement)}setupElement(e){if(this.root==null||this.root instanceof Document)throw new Error("Virtualizer.setupElement: Invalid setup method");this.root.addEventListener("scroll",this.handleElementScroll,{passive:!0}),this.resizeObserver?.observe(this.root),e??=this.root.firstElementChild??void 0,e instanceof HTMLElement&&(this.contentContainer=e,this.resizeObserver?.observe(e))}cleanUp(){this.resizeObserver?.disconnect(),this.resizeObserver=void 0,this.intersectionObserver?.disconnect(),this.intersectionObserver=void 0,this.root?.removeEventListener("scroll",this.handleElementScroll),window.removeEventListener("scroll",this.handleWindowScroll),window.removeEventListener("resize",this.handleWindowResize),this.root=void 0,this.contentContainer=void 0,this.observers.clear(),this.visibleInstances.clear(),this.instancesChanged.clear(),this.connectQueue.clear(),this.visibleInstancesDirty=!1,this.windowSpecs={top:0,bottom:0},this.scrollTop=0,this.height=0,this.scrollHeight=0}getOffsetInScrollContainer(e){return this.getScrollTop()+se(e,this.getScrollContainerElement())}connect(e,t){if(this.observers.has(e))throw new Error("Virtualizer.connect: instance is already connected...");return this.intersectionObserver==null?this.connectQueue.set(e,t):(this.intersectionObserver.observe(e),this.observers.set(e,t),this.instancesChanged.add(t),this.markDOMDirty(),I(this.computeRenderRangeAndEmit)),()=>this.disconnect(e)}disconnect(e){const t=this.observers.get(e);this.connectQueue.delete(e),t!=null&&(this.intersectionObserver?.unobserve(e),this.observers.delete(e),this.visibleInstances.delete(e)&&(this.visibleInstancesDirty=!0),this.markDOMDirty(),I(this.computeRenderRangeAndEmit))}handleWindowResize=()=>{H.__STOP||window.innerHeight===this.height||(this.heightDirty=!0,I(this.computeRenderRangeAndEmit))};handleWindowScroll=()=>{H.__STOP||this.root==null||!(this.root instanceof Document)||(this.scrollDirty=!0,I(this.computeRenderRangeAndEmit))};handleElementScroll=()=>{H.__STOP||this.root==null||this.root instanceof Document||(this.scrollDirty=!0,I(this.computeRenderRangeAndEmit))};computeRenderRangeAndEmit=()=>{if(H.__STOP)return;const e=this.heightDirty||this.scrollHeightDirty;if(!this.scrollDirty&&!this.scrollHeightDirty&&!this.heightDirty&&this.renderedObservers===this.observers.size&&!this.visibleInstancesDirty&&this.instancesChanged.size===0)return;let t=this.instancesChanged.size>0;if(this.instancesChanged.size===0){const l=De({scrollTop:this.getScrollTop(),height:this.getHeight(),scrollHeight:this.getScrollHeight(),overscrollSize:this.config.overscrollSize});if(!e&&Ze(this.windowSpecs,l)&&this.renderedObservers===this.observers.size&&!this.visibleInstancesDirty)return;this.windowSpecs=l}this.visibleInstancesDirty=!1,this.renderedObservers=this.observers.size;const n=this.getScrollAnchor(this.height),r=new Set;for(const l of e?this.observers.values():this.visibleInstances.values())l.onRender(e)&&r.add(l);for(const l of this.instancesChanged)r.has(l)||l.onRender(e)&&r.add(l);this.scrollFix(n);for(const l of r)l.reconcileHeights();t||=this.instancesChanged.size>0,t&&this.markDOMDirty(),(t||e)&&I(this.computeRenderRangeAndEmit),r.clear(),this.instancesChanged.clear()};scrollFix(e){if(e==null)return;const t=this.getScrollContainerElement(),{lineIndex:n,lineOffset:r,fileElement:l,fileOffset:u,fileTypeOffset:h}=e;if(n!=null&&r!=null){const g=l.shadowRoot?.querySelector(`[data-line][data-line-index="${n}"]`);if(g instanceof HTMLElement){const m=se(g,t);if(m!==r){const S=m-r;this.applyScrollFix(S)}return}}const a=se(l,t);if(h==="top")a!==u&&this.applyScrollFix(a-u);else{const g=a+l.getBoundingClientRect().height;g!==u&&this.applyScrollFix(g-u)}}applyScrollFix(e){this.root==null||this.root instanceof Document?window.scrollTo({top:window.scrollY+e,behavior:"instant"}):this.root.scrollTo({top:this.root.scrollTop+e,behavior:"instant"}),this.markDOMDirty()}getScrollAnchor(e){const t=this.getScrollContainerElement();let n;for(const[r]of this.visibleInstances.entries()){const l=se(r,t),u=l+r.offsetHeight;let h,a;u<=0?(h=u,a="bottom"):(h=l,a="top");let g,m;if(u>0&&l<e)for(const L of r.shadowRoot?.querySelectorAll("[data-line][data-line-index]")??[]){if(!(L instanceof HTMLElement))continue;const B=L.dataset.lineIndex;if(B==null)continue;const j=se(L,t);if(!(j<0)){g=B,m=j;break}}if(n?.lineOffset!=null&&m==null)continue;let S=!1;(n==null||m!=null&&(n.lineOffset==null||m<n.lineOffset)||m==null&&n.lineOffset==null&&(h>=0&&(n.fileOffset<0||h<n.fileOffset)||h<0&&n.fileOffset<0&&h>n.fileOffset))&&(S=!0),S&&(n={fileElement:r,fileTypeOffset:a,fileOffset:h,lineIndex:g,lineOffset:m})}return n}handleIntersectionChange=e=>{this.scrollDirty=!0;for(const{target:t,isIntersecting:n}of e){if(!(t instanceof HTMLElement))throw new Error("Virtualizer.handleIntersectionChange: target not an HTMLElement");const r=this.observers.get(t);r!=null&&(n&&!this.visibleInstances.has(t)?(r.setVisibility(!0),this.visibleInstances.set(t,r),this.visibleInstancesDirty=!0):!n&&this.visibleInstances.has(t)&&(r.setVisibility(!1),this.visibleInstances.delete(t),this.visibleInstancesDirty=!0))}this.visibleInstancesDirty&&I(this.computeRenderRangeAndEmit)};getScrollTop(){if(!this.scrollDirty)return this.scrollTop;this.scrollDirty=!1;let e=this.root==null?0:this.root instanceof Document?window.scrollY:this.root.scrollTop;return e=Math.max(0,Math.min(e,this.getScrollHeight()-this.getHeight())),this.scrollTop=e,e}getScrollHeight(){return this.scrollHeightDirty?(this.scrollHeightDirty=!1,this.scrollHeight=this.root==null?0:this.root instanceof Document?this.root.documentElement.scrollHeight:this.root.scrollHeight,this.scrollHeight):this.scrollHeight}getHeight(){return this.heightDirty?(this.heightDirty=!1,this.height=this.root==null?0:this.root instanceof Document?globalThis.innerHeight:this.root.getBoundingClientRect().height,this.height):this.height}markDOMDirty(){this.scrollDirty=!0,this.scrollHeightDirty=!0,this.heightDirty=!0}getScrollContainerElement(){return this.root==null||this.root instanceof Document?void 0:this.root}};function se(s,e){const t=s.getBoundingClientRect(),n=e?.getBoundingClientRect().top??0;return t.top-n}const pe=s=>{if(s.type==="new"){const e=Math.min(s.selection.start,s.selection.end),t=Math.max(s.selection.start,s.selection.end);return`new-comment-${s.selection.side??"additions"}-${e}-${t}`}return`draft-${s.draft.id}`},it=s=>{const{drafts:e,editingDraftId:t,selection:n}=s,r=[];for(const l of e){if(!Number.isFinite(l.endLine))continue;const u=Math.max(1,Math.floor(l.endLine)),h=l.side==="original"?"deletions":"additions";r.push({lineNumber:u,side:h,metadata:{type:l.id===t?"edit":"saved",draft:l}})}return n&&!t&&r.push({lineNumber:Math.max(n.start,n.end),side:n.side??"additions",metadata:{type:"new",selection:n}}),r};function rt(s){const e=s.trim();if(!e)return null;if(/^-?\d+(\.\d+)?$/.test(e)){const t=Number.parseFloat(e);return Number.isFinite(t)?t:null}if(e.endsWith("px")){const t=Number.parseFloat(e.slice(0,-2));return Number.isFinite(t)?t:null}return null}function ze(s){if(!(!s||s<=0))return Math.max(200,Math.floor(s))}function st(s){const{diffRootRef:e,drafts:t,selection:n,editingDraftId:r,commentText:l,onTextChange:u,fileLabel:h,onSave:a,onCancel:g,onEdit:m,onDelete:S}=s,[L,B]=F.useState(0),[j,X]=F.useState(null),b=F.useMemo(()=>!n||r?null:pe({type:"new",selection:n}),[r,n]),_=F.useMemo(()=>{const c=t.map(y=>pe({type:y.id===r?"edit":"saved",draft:y}));return b&&c.push(b),c},[t,r,b]),$=F.useCallback(c=>{const y=e.current;if(!y)return null;const w=y.querySelector("diffs-container");if(!(w instanceof HTMLElement))return null;const k=w.querySelector(`[data-annotation-id="${c}"]`);if(k instanceof HTMLElement)return k;const A=w.shadowRoot;return A?A.querySelector(`[data-annotation-id="${c}"]`):null},[e]);F.useEffect(()=>{if(_.length===0)return;let c=!1,y=0;const w=12,k=()=>{c||_.every(D=>!!$(D))||y>=w||(y+=1,requestAnimationFrame(()=>{c||(B(D=>D+1),k())}))};return k(),()=>{c=!0}},[_,$]),F.useEffect(()=>{const c=e.current;if(!c)return;const y=()=>{const k=getComputedStyle(c),A=rt(k.getPropertyValue("--oc-context-panel-width")),D=c.getBoundingClientRect(),N=A??D.width;X(N>0?N:null)};y();const w=new ResizeObserver(()=>{y()});return w.observe(c),window.addEventListener("resize",y),()=>{w.disconnect(),window.removeEventListener("resize",y)}},[e]);const G=F.useCallback(c=>{const w=e.current?.getBoundingClientRect(),k=c.closest("[data-annotation-content]"),A=k instanceof HTMLElement?k.getBoundingClientRect():c.getBoundingClientRect(),D=[A.width];w&&D.push(w.right-A.left);const N=D.filter(J=>Number.isFinite(J)&&J>0);return N.length>0?ze(Math.min(...N)):ze(j)},[e,j]);return O.jsxs(O.Fragment,{children:[t.map(c=>{const y=pe({type:c.id===r?"edit":"saved",draft:c}),w=$(y);if(!w)return null;const k=G(w);return c.id===r?we.createPortal(O.jsx(Ce,{initialText:l,onTextChange:u,fileLabel:h,lineRange:{start:c.startLine,end:c.endLine,side:c.side==="original"?"deletions":"additions"},isEditing:!0,onSave:a,onCancel:g,maxWidth:k}),w,`draft-edit-${c.id}`):we.createPortal(O.jsx(Ke,{draft:c,onEdit:()=>m(c),onDelete:()=>S(c),maxWidth:k}),w,`draft-card-${c.id}`)}),n&&!r&&b&&(()=>{const c=$(b);if(!c)return null;const y=G(c);return we.createPortal(O.jsx(Ce,{initialText:l,onTextChange:u,fileLabel:h,lineRange:n,isEditing:!1,onSave:a,onCancel:g,maxWidth:y}),c,b)})()]})}const Ie=5e5,ot=`
2
2
  :host {
3
3
  font-family: var(--font-mono);
4
4
  font-size: var(--text-code);
@@ -133,4 +133,4 @@ import{R as F,j as O,b as we,r as d}from"./vendor-react-DYyjh7Q0.js";import{B as
133
133
  }
134
134
  `;function at(s){let e=2166136261;for(let t=0;t<s.length;t+=1)e^=s.charCodeAt(t),e=e+((e<<1)+(e<<4)+(e<<7)+(e<<8)+(e<<24))>>>0;return e.toString(16)}function Ae(s){const e=s.length>400?`${s.slice(0,200)}${s.slice(-200)}`:s;return`${s.length}:${at(e)}`}const ct=(s,e,t,n)=>{const r=n.side==="deletions",u=(t?(r?t.deletionLines:t.additionLines).join(""):r?s:e).split(`
135
135
  `),h=Math.min(n.start,n.end),a=Math.max(n.start,n.end),g=Math.max(1,h),m=Math.min(u.length,a);return g>m?"":u.slice(g-1,m).join(`
136
- `)},dt=(s,e)=>s===e?!0:!s||!e?!1:s.start===e.start&&s.end===e.end&&s.side===e.side,ut=s=>s==="auto"||s==="scroll"||s==="overlay",ft=s=>{let e=s?.parentElement??null;for(;e;){const t=window.getComputedStyle(e);if(ut(t.overflowY))return e;e=e.parentElement}return null},ht=(s,e)=>{if(!s||!e||typeof window>"u")return()=>{};const t=ft(s);if(!t)return()=>{};const n=e.getBoundingClientRect().height;if(!n)return()=>{};const r=s.getBoundingClientRect().top-t.getBoundingClientRect().top,l=e.style.minHeight;e.style.minHeight=`${Math.ceil(n)}px`;let u=!1;return()=>{if(u)return;u=!0,e.style.minHeight=l;const a=s.getBoundingClientRect().top-t.getBoundingClientRect().top-r;a&&(t.scrollTop+=a)}},pt=(s,e)=>{if(typeof window>"u")return()=>{};let t=null,n=null,r=!1;const l=()=>{r||(n?.disconnect(),n=null,t=window.requestAnimationFrame(()=>{t=window.requestAnimationFrame(()=>{r||e()})}))},u=()=>s.querySelector("diffs-container")?.shadowRoot??void 0,h=(a=u())=>!!a?.querySelector("[data-line]");return h()?l():typeof MutationObserver<"u"?(n=new MutationObserver(()=>{const a=u();if(a){if(h(a)){l();return}n?.disconnect(),n=new MutationObserver(()=>{h(a)&&l()}),n.observe(a,{childList:!0,subtree:!0})}}),n.observe(s,{childList:!0,subtree:!0})):t=window.requestAnimationFrame(l),()=>{r=!0,n?.disconnect(),t!==null&&window.cancelAnimationFrame(t)}},fe=new WeakMap,mt={lineHeight:24,hunkSeparatorHeight:24,spacing:0};function gt(s){const e=s.closest("[data-diff-virtual-root]");if(e instanceof HTMLElement){const t=e.querySelector("[data-diff-virtual-content]");return{key:e,root:e,content:t instanceof HTMLElement?t:void 0}}return{key:document,root:document,content:void 0}}function vt(s){if(typeof document>"u")return null;const e=gt(s);let t=fe.get(e.key);if(!t){const r=new nt;r.setup(e.root,e.content),t={virtualizer:r,refs:0},fe.set(e.key,t)}t.refs+=1;let n=!1;return{virtualizer:t.virtualizer,root:e.root,release:()=>{if(n)return;n=!0;const r=fe.get(e.key);r&&(r.refs-=1,!(r.refs>0)&&(r.virtualizer.cleanUp(),fe.delete(e.key)))}}}const yt=(s,e,t)=>{if(typeof window>"u")return()=>{};const n=[],r=()=>{try{s.rerender()}catch{}const l=e?.root;l instanceof HTMLElement?l.dispatchEvent(new Event("scroll",{bubbles:!1})):document.dispatchEvent(new Event("scroll",{bubbles:!1})),window.dispatchEvent(new Event("resize")),t()};return n.push(window.requestAnimationFrame(r)),n.push(window.requestAnimationFrame(()=>{n.push(window.requestAnimationFrame(r))})),()=>{for(const l of n)window.cancelAnimationFrame(l)}},Ot=({original:s,modified:e,fileDiff:t,language:n,fileName:r,renderSideBySide:l,wrapLines:u,layout:h="fill",enableComments:a=!0})=>{const g=je(),m=g?.currentTheme.metadata.variant==="dark",S=g?.availableThemes.find(i=>i.metadata.id===g.lightThemeId)??De(!1),D=g?.availableThemes.find(i=>i.metadata.id===g.darkThemeId)??De(!0),{isMobile:B}=Ue(),j=Ye({source:"diff",fileLabel:r||"unknown",language:n,getCodeForRange:i=>ct(s,e,t,i),toStoreRange:i=>({startLine:i.start,endLine:i.end,side:i.side==="deletions"?"original":"modified"}),fromDraftRange:i=>({start:i.startLine,end:i.endLine,side:i.side==="original"?"deletions":"additions"})}),{drafts:X,selection:b,setSelection:_,commentText:$,setCommentText:G,editingDraftId:c,saveComment:y,cancel:w,startEdit:k,deleteDraft:A}=j,L=d.useRef(null),N=d.useRef(null),J=d.useRef(""),ee=d.useRef(!1),oe=d.useRef(null);d.useEffect(()=>{L.current=b},[b]),d.useEffect(()=>{N.current=c},[c]),d.useEffect(()=>{J.current=$},[$]);const le=d.useCallback(i=>{if(!a||ee.current)return;const o=L.current;if(!(!i&&o&&J.current.trim())){if(B&&o&&i&&i.side===o.side){const f=Math.min(o.start,i.start),p=Math.max(o.end,i.end);_({...i,start:f,end:p})}else _(i);i&&(N.current||G(""))}},[a,B,G,_]),Fe=d.useCallback(()=>{w()},[w]),Se=d.useCallback(i=>{const o=document.createElement("div");o.style.position="relative";const f=pe(i.metadata);return o.dataset.annotationId=f,o.dataset.annotationSide=i.side,o.dataset.annotationLine=String(i.lineNumber),o},[]),_e=d.useCallback((i,o)=>{y(i,o??b??void 0)},[y,b]),We=d.useCallback(i=>{_(i);const o=P.current;if(o)try{ee.current=!0,o.setSelectedLines(i),oe.current=i}catch{}finally{ee.current=!1}},[_]),Ee=d.useCallback(i=>{const o=i.closest("[data-line-type]")?.getAttribute("data-line-type")??i.getAttribute("data-line-type");if(o==="change-deletion")return"deletions";if(o==="change-addition")return"additions";const f=i.getAttribute("data-column-side")??i.getAttribute("data-side")??i.closest("[data-column-side]")?.getAttribute("data-column-side");if(f==="deletions"||f==="left"||f==="original")return"deletions";if(f==="additions"||f==="right"||f==="modified")return"additions";const p=i.closest("[data-line-type]");if(p instanceof HTMLElement){const E=p.getBoundingClientRect(),v=i.getBoundingClientRect(),R=E.left+E.width/2;return v.left+v.width/2<R?"deletions":"additions"}return"additions"},[]);Me(S),Me(D);const Q=`${S.metadata.id}:${D.metadata.id}:${m?"dark":"light"}`,te=d.useMemo(()=>{if(t){const i=t.deletionLines.reduce((f,p)=>f+p.length,0),o=t.additionLines.reduce((f,p)=>f+p.length,0);return Math.max(i,o)>Ie}return Math.max(s.length,e.length)>Ie},[t,e.length,s.length]),ne=d.useRef(null),K=d.useRef(null),P=d.useRef(null),ie=d.useRef(null),me=d.useRef(null),ge=d.useRef(null),ve=d.useRef(void 0),ae=d.useRef(void 0),ce=d.useRef(void 0),de=d.useRef(void 0),[,ye]=F.useReducer(i=>i+1,0),Y=Qe(te?"unified":l?"split":"unified"),W=d.useMemo(()=>Oe(S),[S]),q=d.useMemo(()=>Oe(D),[D]);F.useLayoutEffect(()=>{const i=ne.current;if(!i)return;const o=i.querySelector("diffs-container");if(!o)return;const f=m?q:W,p=(qe,Ve)=>qe.colors?.[Ve],E=p(W,"terminal.ansiGreen"),v=p(W,"terminal.ansiRed"),R=p(W,"terminal.ansiBlue"),C=p(q,"terminal.ansiGreen"),M=p(q,"terminal.ansiRed"),z=p(q,"terminal.ansiBlue");o.style.setProperty("--shiki-light",W.fg),o.style.setProperty("--shiki-light-bg",W.bg),E&&o.style.setProperty("--shiki-light-addition-color",E),v&&o.style.setProperty("--shiki-light-deletion-color",v),R&&o.style.setProperty("--shiki-light-modified-color",R),o.style.setProperty("--shiki-dark",q.fg),o.style.setProperty("--shiki-dark-bg",q.bg),C&&o.style.setProperty("--shiki-dark-addition-color",C),M&&o.style.setProperty("--shiki-dark-deletion-color",M),z&&o.style.setProperty("--shiki-dark-modified-color",z),o.style.setProperty("--diffs-bg",f.bg),o.style.setProperty("--diffs-fg",f.fg);const x=m?C:E,V=m?M:v,Z=m?z:R;x&&o.style.setProperty("--diffs-addition-color-override",x),V&&o.style.setProperty("--diffs-deletion-color-override",V),Z&&o.style.setProperty("--diffs-modified-color-override",Z);const T=o.shadowRoot?.querySelector("pre");T&&(T.style.setProperty("--shiki-light",W.fg),T.style.setProperty("--shiki-light-bg",W.bg),E&&T.style.setProperty("--shiki-light-addition-color",E),v&&T.style.setProperty("--shiki-light-deletion-color",v),R&&T.style.setProperty("--shiki-light-modified-color",R),T.style.setProperty("--shiki-dark",q.fg),T.style.setProperty("--shiki-dark-bg",q.bg),C&&T.style.setProperty("--shiki-dark-addition-color",C),M&&T.style.setProperty("--shiki-dark-deletion-color",M),z&&T.style.setProperty("--shiki-dark-modified-color",z),T.style.setProperty("--diffs-bg",f.bg),T.style.setProperty("--diffs-fg",f.fg),x&&T.style.setProperty("--diffs-addition-color-override",x),V&&T.style.setProperty("--diffs-deletion-color-override",V),Z&&T.style.setProperty("--diffs-modified-color-override",Z))},[q,Q,m,W]);const U=d.useMemo(()=>({theme:{dark:D.metadata.id,light:S.metadata.id},themeType:m?"dark":"light",diffStyle:l?"split":"unified",diffIndicators:"none",hunkSeparators:"line-info-basic",lineDiffType:"none",maxLineDiffLength:te?0:1e3,maxLineLengthForHighlighting:te?1:1e3,tokenizeMaxLineLength:te?1:1e3,collapsedContextThreshold:0,expansionLineCount:20,overflow:u?"wrap":"scroll",disableFileHeader:!0,enableLineSelection:a,enableHoverUtility:!1,onLineSelected:a?le:void 0,unsafeCSS:lt,renderAnnotation:a?Se:void 0}),[D.metadata.id,a,m,te,S.metadata.id,l,u,le,Se]),re=d.useMemo(()=>a?it({drafts:X,editingDraftId:c,selection:b}):[],[c,a,X,b]),be=d.useRef(re);if(d.useEffect(()=>{be.current=re},[re]),d.useEffect(()=>{const i=K.current;return()=>{P.current?.cleanUp(),P.current=null,ie.current?.release(),ie.current=null,me.current=null,ge.current=null,ve.current=void 0,ae.current=void 0,ce.current=void 0,de.current=void 0,i&&(i.innerHTML="")}},[]),d.useEffect(()=>{if(typeof window>"u")return;const i=K.current,o=ne.current;if(!i||!Y)return;const f=ht(o,i);let p=ie.current;p||(p=vt(i),ie.current=p),ie.current=p;const E=p?.virtualizer??null,v=t?void 0:{name:r||"",contents:s,lang:n,cacheKey:`old:${Q}:${r}:${Ae(s)}`},R=t?void 0:{name:r||"",contents:e,lang:n,cacheKey:`new:${Q}:${r}:${Ae(e)}`},C=t?ae.current!==t:ae.current!==void 0||!v||!R||!ce.current||!de.current||!Te(ce.current,v)||!Te(de.current,R),M=P.current,z=!!(M&&(me.current!==E||ge.current!==Y||E&&(ve.current!==U.hunkSeparators||C)));z&&(M?.cleanUp(),P.current=null,i.innerHTML="");let x=P.current;const V=!z&&M?!$e(M.options,U):!1;if(x?x.setOptions(U):(x=p?new Ne(U,p.virtualizer,mt,Y):new Be(U,Y),P.current=x,oe.current=null),me.current=E,ge.current=Y,ve.current=E?U.hunkSeparators:void 0,ae.current=t,ce.current=v,de.current=R,t)x.render({fileDiff:t,forceRender:V,lineAnnotations:be.current,containerWrapper:i});else{if(!v||!R)return;x.render({oldFile:v,newFile:R,forceRender:V,lineAnnotations:be.current,containerWrapper:i})}const Z=pt(i,()=>{f(),yt(x,p,ye)});return()=>{Z(),f()}},[Q,t,r,n,e,U,s,Y]),d.useEffect(()=>{const i=P.current;if(i){try{i.setLineAnnotations(re)}catch(o){console.error("Failed to apply diff line annotations",o);try{i.setLineAnnotations([])}catch{}}requestAnimationFrame(()=>{if(P.current===i){try{i.rerender()}catch{}ye()}})}},[re]),d.useEffect(()=>{const i=P.current;if(!i||b!==null)return;const o=oe.current;if(!dt(b,o))try{ee.current=!0,i.setSelectedLines(b),oe.current=b}catch{}finally{ee.current=!1}},[b]),d.useEffect(()=>{if(!a)return;const i=K.current;if(!i)return;let o=null,f=()=>{};const p=()=>{const v=i.querySelector("diffs-container")?.shadowRoot;if(!v){o=requestAnimationFrame(p);return}const R=C=>{if(!(C instanceof MouseEvent)||C.button!==0||!(C.target instanceof Element))return;const M=C.target.closest("[data-column-number]");if(!(M instanceof HTMLElement))return;const z=M.getAttribute("data-column-number"),x=z?parseInt(z,10):NaN;if(Number.isNaN(x))return;const V=Ee(M);le({start:x,end:x,side:V}),C.preventDefault(),C.stopPropagation()};v.addEventListener("click",R,!0),f=()=>{v.removeEventListener("click",R,!0)}};return p(),()=>{o!==null&&cancelAnimationFrame(o),f()}},[Q,a,r,le,Ee]),d.useEffect(()=>{const i=K.current;if(!i)return;let o=null,f=null;const E=setTimeout(()=>{const v=i.querySelector("diffs-container");if(!(v instanceof HTMLElement))return;const R=v.shadowRoot;o=new MutationObserver(()=>{f&&cancelAnimationFrame(f),f=requestAnimationFrame(()=>{ye(),f=null})}),o.observe(v,{childList:!0,subtree:!0}),R&&o.observe(R,{childList:!0,subtree:!0})},100);return()=>{clearTimeout(E),f&&cancelAnimationFrame(f),o?.disconnect()}},[Q,r]),typeof window>"u")return null;const xe=a?O.jsx(st,{diffRootRef:ne,drafts:X,selection:b,editingDraftId:c,commentText:$,onTextChange:G,fileLabel:r?.split("/").pop()??"",onSave:_e,onCancel:Fe,onEdit:i=>{We({start:i.startLine,end:i.endLine,side:i.side==="original"?"deletions":"additions"}),k(i)},onDelete:A}):null;return h==="fill"?O.jsx("div",{className:ke("flex flex-col relative","size-full"),"data-diff-virtual-root":!0,children:O.jsxs("div",{className:"flex-1 relative min-h-0",children:[O.jsx(Ge,{outerClassName:"pierre-diff-wrapper size-full",disableHorizontal:!1,fillContainer:!0,"data-diff-virtual-content":!0,children:O.jsx("div",{ref:ne,className:"size-full relative",children:O.jsx("div",{ref:K,className:"size-full"})})}),xe]})}):O.jsxs("div",{className:ke("relative","w-full"),children:[O.jsx("div",{ref:ne,className:"pierre-diff-wrapper w-full overflow-x-auto overflow-y-visible relative",children:O.jsx("div",{ref:K,className:"w-full"})}),xe]})};export{Ot as P};
136
+ `)},dt=(s,e)=>s===e?!0:!s||!e?!1:s.start===e.start&&s.end===e.end&&s.side===e.side,ut=s=>s==="auto"||s==="scroll"||s==="overlay",ft=s=>{let e=s?.parentElement??null;for(;e;){const t=window.getComputedStyle(e);if(ut(t.overflowY))return e;e=e.parentElement}return null},ht=(s,e)=>{if(!s||!e||typeof window>"u")return()=>{};const t=ft(s);if(!t)return()=>{};const n=e.getBoundingClientRect().height;if(!n)return()=>{};const r=s.getBoundingClientRect().top-t.getBoundingClientRect().top,l=e.style.minHeight;e.style.minHeight=`${Math.ceil(n)}px`;let u=!1;return()=>{if(u)return;u=!0,e.style.minHeight=l;const a=s.getBoundingClientRect().top-t.getBoundingClientRect().top-r;a&&(t.scrollTop+=a)}},pt=(s,e)=>{if(typeof window>"u")return()=>{};let t=null,n=null,r=!1;const l=()=>{r||(n?.disconnect(),n=null,t=window.requestAnimationFrame(()=>{t=window.requestAnimationFrame(()=>{r||e()})}))},u=()=>s.querySelector("diffs-container")?.shadowRoot??void 0,h=(a=u())=>!!a?.querySelector("[data-line]");return h()?l():typeof MutationObserver<"u"?(n=new MutationObserver(()=>{const a=u();if(a){if(h(a)){l();return}n?.disconnect(),n=new MutationObserver(()=>{h(a)&&l()}),n.observe(a,{childList:!0,subtree:!0})}}),n.observe(s,{childList:!0,subtree:!0})):t=window.requestAnimationFrame(l),()=>{r=!0,n?.disconnect(),t!==null&&window.cancelAnimationFrame(t)}},fe=new WeakMap,mt={lineHeight:24,hunkSeparatorHeight:24,spacing:0};function gt(s){const e=s.closest("[data-diff-virtual-root]");if(e instanceof HTMLElement){const t=e.querySelector("[data-diff-virtual-content]");return{key:e,root:e,content:t instanceof HTMLElement?t:void 0}}return{key:document,root:document,content:void 0}}function vt(s){if(typeof document>"u")return null;const e=gt(s);let t=fe.get(e.key);if(!t){const r=new nt;r.setup(e.root,e.content),t={virtualizer:r,refs:0},fe.set(e.key,t)}t.refs+=1;let n=!1;return{virtualizer:t.virtualizer,root:e.root,release:()=>{if(n)return;n=!0;const r=fe.get(e.key);r&&(r.refs-=1,!(r.refs>0)&&(r.virtualizer.cleanUp(),fe.delete(e.key)))}}}const yt=(s,e,t)=>{if(typeof window>"u")return()=>{};const n=[],r=()=>{try{s.rerender()}catch{}const l=e?.root;l instanceof HTMLElement?l.dispatchEvent(new Event("scroll",{bubbles:!1})):document.dispatchEvent(new Event("scroll",{bubbles:!1})),window.dispatchEvent(new Event("resize")),t()};return n.push(window.requestAnimationFrame(r)),n.push(window.requestAnimationFrame(()=>{n.push(window.requestAnimationFrame(r))})),()=>{for(const l of n)window.cancelAnimationFrame(l)}},Ot=({original:s,modified:e,fileDiff:t,language:n,fileName:r,renderSideBySide:l,wrapLines:u,layout:h="fill",enableComments:a=!0})=>{const g=je(),m=g?.currentTheme.metadata.variant==="dark",S=g?.availableThemes.find(i=>i.metadata.id===g.lightThemeId)??Le(!1),L=g?.availableThemes.find(i=>i.metadata.id===g.darkThemeId)??Le(!0),{isMobile:B}=Ue(),j=Ye({source:"diff",fileLabel:r||"unknown",language:n,getCodeForRange:i=>ct(s,e,t,i),toStoreRange:i=>({startLine:i.start,endLine:i.end,side:i.side==="deletions"?"original":"modified"}),fromDraftRange:i=>({start:i.startLine,end:i.endLine,side:i.side==="original"?"deletions":"additions"})}),{drafts:X,selection:b,setSelection:_,commentText:$,setCommentText:G,editingDraftId:c,saveComment:y,cancel:w,startEdit:k,deleteDraft:A}=j,D=d.useRef(null),N=d.useRef(null),J=d.useRef(""),ee=d.useRef(!1),oe=d.useRef(null);d.useEffect(()=>{D.current=b},[b]),d.useEffect(()=>{N.current=c},[c]),d.useEffect(()=>{J.current=$},[$]);const le=d.useCallback(i=>{if(!a||ee.current)return;const o=D.current;if(!(!i&&o&&J.current.trim())){if(B&&o&&i&&i.side===o.side){const f=Math.min(o.start,i.start),p=Math.max(o.end,i.end);_({...i,start:f,end:p})}else _(i);i&&(N.current||G(""))}},[a,B,G,_]),Fe=d.useCallback(()=>{w()},[w]),Se=d.useCallback(i=>{const o=document.createElement("div");o.style.position="relative";const f=pe(i.metadata);return o.dataset.annotationId=f,o.dataset.annotationSide=i.side,o.dataset.annotationLine=String(i.lineNumber),o},[]),_e=d.useCallback((i,o)=>{y(i,o??b??void 0)},[y,b]),We=d.useCallback(i=>{_(i);const o=P.current;if(o)try{ee.current=!0,o.setSelectedLines(i),oe.current=i}catch{}finally{ee.current=!1}},[_]),Ee=d.useCallback(i=>{const o=i.closest("[data-line-type]")?.getAttribute("data-line-type")??i.getAttribute("data-line-type");if(o==="change-deletion")return"deletions";if(o==="change-addition")return"additions";const f=i.getAttribute("data-column-side")??i.getAttribute("data-side")??i.closest("[data-column-side]")?.getAttribute("data-column-side");if(f==="deletions"||f==="left"||f==="original")return"deletions";if(f==="additions"||f==="right"||f==="modified")return"additions";const p=i.closest("[data-line-type]");if(p instanceof HTMLElement){const E=p.getBoundingClientRect(),v=i.getBoundingClientRect(),R=E.left+E.width/2;return v.left+v.width/2<R?"deletions":"additions"}return"additions"},[]);Me(S),Me(L);const Q=`${S.metadata.id}:${L.metadata.id}:${m?"dark":"light"}`,te=d.useMemo(()=>{if(t){const i=t.deletionLines.reduce((f,p)=>f+p.length,0),o=t.additionLines.reduce((f,p)=>f+p.length,0);return Math.max(i,o)>Ie}return Math.max(s.length,e.length)>Ie},[t,e.length,s.length]),ne=d.useRef(null),K=d.useRef(null),P=d.useRef(null),ie=d.useRef(null),me=d.useRef(null),ge=d.useRef(null),ve=d.useRef(void 0),ae=d.useRef(void 0),ce=d.useRef(void 0),de=d.useRef(void 0),[,ye]=F.useReducer(i=>i+1,0),Y=Qe(te?"unified":l?"split":"unified"),W=d.useMemo(()=>Oe(S),[S]),q=d.useMemo(()=>Oe(L),[L]);F.useLayoutEffect(()=>{const i=ne.current;if(!i)return;const o=i.querySelector("diffs-container");if(!o)return;const f=m?q:W,p=(qe,Ve)=>qe.colors?.[Ve],E=p(W,"terminal.ansiGreen"),v=p(W,"terminal.ansiRed"),R=p(W,"terminal.ansiBlue"),C=p(q,"terminal.ansiGreen"),M=p(q,"terminal.ansiRed"),z=p(q,"terminal.ansiBlue");o.style.setProperty("--shiki-light",W.fg),o.style.setProperty("--shiki-light-bg",W.bg),E&&o.style.setProperty("--shiki-light-addition-color",E),v&&o.style.setProperty("--shiki-light-deletion-color",v),R&&o.style.setProperty("--shiki-light-modified-color",R),o.style.setProperty("--shiki-dark",q.fg),o.style.setProperty("--shiki-dark-bg",q.bg),C&&o.style.setProperty("--shiki-dark-addition-color",C),M&&o.style.setProperty("--shiki-dark-deletion-color",M),z&&o.style.setProperty("--shiki-dark-modified-color",z),o.style.setProperty("--diffs-bg",f.bg),o.style.setProperty("--diffs-fg",f.fg);const x=m?C:E,V=m?M:v,Z=m?z:R;x&&o.style.setProperty("--diffs-addition-color-override",x),V&&o.style.setProperty("--diffs-deletion-color-override",V),Z&&o.style.setProperty("--diffs-modified-color-override",Z);const T=o.shadowRoot?.querySelector("pre");T&&(T.style.setProperty("--shiki-light",W.fg),T.style.setProperty("--shiki-light-bg",W.bg),E&&T.style.setProperty("--shiki-light-addition-color",E),v&&T.style.setProperty("--shiki-light-deletion-color",v),R&&T.style.setProperty("--shiki-light-modified-color",R),T.style.setProperty("--shiki-dark",q.fg),T.style.setProperty("--shiki-dark-bg",q.bg),C&&T.style.setProperty("--shiki-dark-addition-color",C),M&&T.style.setProperty("--shiki-dark-deletion-color",M),z&&T.style.setProperty("--shiki-dark-modified-color",z),T.style.setProperty("--diffs-bg",f.bg),T.style.setProperty("--diffs-fg",f.fg),x&&T.style.setProperty("--diffs-addition-color-override",x),V&&T.style.setProperty("--diffs-deletion-color-override",V),Z&&T.style.setProperty("--diffs-modified-color-override",Z))},[q,Q,m,W]);const U=d.useMemo(()=>({theme:{dark:L.metadata.id,light:S.metadata.id},themeType:m?"dark":"light",diffStyle:l?"split":"unified",diffIndicators:"none",hunkSeparators:"line-info-basic",lineDiffType:"none",maxLineDiffLength:te?0:1e3,maxLineLengthForHighlighting:te?1:1e3,tokenizeMaxLineLength:te?1:1e3,collapsedContextThreshold:0,expansionLineCount:20,overflow:u?"wrap":"scroll",disableFileHeader:!0,enableLineSelection:a,enableHoverUtility:!1,onLineSelected:a?le:void 0,unsafeCSS:lt,renderAnnotation:a?Se:void 0}),[L.metadata.id,a,m,te,S.metadata.id,l,u,le,Se]),re=d.useMemo(()=>a?it({drafts:X,editingDraftId:c,selection:b}):[],[c,a,X,b]),be=d.useRef(re);if(d.useEffect(()=>{be.current=re},[re]),d.useEffect(()=>{const i=K.current;return()=>{P.current?.cleanUp(),P.current=null,ie.current?.release(),ie.current=null,me.current=null,ge.current=null,ve.current=void 0,ae.current=void 0,ce.current=void 0,de.current=void 0,i&&(i.innerHTML="")}},[]),d.useEffect(()=>{if(typeof window>"u")return;const i=K.current,o=ne.current;if(!i||!Y)return;const f=ht(o,i);let p=ie.current;p||(p=vt(i),ie.current=p),ie.current=p;const E=p?.virtualizer??null,v=t?void 0:{name:r||"",contents:s,lang:n,cacheKey:`old:${Q}:${r}:${Ae(s)}`},R=t?void 0:{name:r||"",contents:e,lang:n,cacheKey:`new:${Q}:${r}:${Ae(e)}`},C=t?ae.current!==t:ae.current!==void 0||!v||!R||!ce.current||!de.current||!Te(ce.current,v)||!Te(de.current,R),M=P.current,z=!!(M&&(me.current!==E||ge.current!==Y||E&&(ve.current!==U.hunkSeparators||C)));z&&(M?.cleanUp(),P.current=null,i.innerHTML="");let x=P.current;const V=!z&&M?!$e(M.options,U):!1;if(x?x.setOptions(U):(x=p?new Ne(U,p.virtualizer,mt,Y):new Be(U,Y),P.current=x,oe.current=null),me.current=E,ge.current=Y,ve.current=E?U.hunkSeparators:void 0,ae.current=t,ce.current=v,de.current=R,t)x.render({fileDiff:t,forceRender:V,lineAnnotations:be.current,containerWrapper:i});else{if(!v||!R)return;x.render({oldFile:v,newFile:R,forceRender:V,lineAnnotations:be.current,containerWrapper:i})}const Z=pt(i,()=>{f(),yt(x,p,ye)});return()=>{Z(),f()}},[Q,t,r,n,e,U,s,Y]),d.useEffect(()=>{const i=P.current;if(i){try{i.setLineAnnotations(re)}catch(o){console.error("Failed to apply diff line annotations",o);try{i.setLineAnnotations([])}catch{}}requestAnimationFrame(()=>{if(P.current===i){try{i.rerender()}catch{}ye()}})}},[re]),d.useEffect(()=>{const i=P.current;if(!i||b!==null)return;const o=oe.current;if(!dt(b,o))try{ee.current=!0,i.setSelectedLines(b),oe.current=b}catch{}finally{ee.current=!1}},[b]),d.useEffect(()=>{if(!a)return;const i=K.current;if(!i)return;let o=null,f=()=>{};const p=()=>{const v=i.querySelector("diffs-container")?.shadowRoot;if(!v){o=requestAnimationFrame(p);return}const R=C=>{if(!(C instanceof MouseEvent)||C.button!==0||!(C.target instanceof Element))return;const M=C.target.closest("[data-column-number]");if(!(M instanceof HTMLElement))return;const z=M.getAttribute("data-column-number"),x=z?parseInt(z,10):NaN;if(Number.isNaN(x))return;const V=Ee(M);le({start:x,end:x,side:V}),C.preventDefault(),C.stopPropagation()};v.addEventListener("click",R,!0),f=()=>{v.removeEventListener("click",R,!0)}};return p(),()=>{o!==null&&cancelAnimationFrame(o),f()}},[Q,a,r,le,Ee]),d.useEffect(()=>{const i=K.current;if(!i)return;let o=null,f=null;const E=setTimeout(()=>{const v=i.querySelector("diffs-container");if(!(v instanceof HTMLElement))return;const R=v.shadowRoot;o=new MutationObserver(()=>{f&&cancelAnimationFrame(f),f=requestAnimationFrame(()=>{ye(),f=null})}),o.observe(v,{childList:!0,subtree:!0}),R&&o.observe(R,{childList:!0,subtree:!0})},100);return()=>{clearTimeout(E),f&&cancelAnimationFrame(f),o?.disconnect()}},[Q,r]),typeof window>"u")return null;const xe=a?O.jsx(st,{diffRootRef:ne,drafts:X,selection:b,editingDraftId:c,commentText:$,onTextChange:G,fileLabel:r?.split("/").pop()??"",onSave:_e,onCancel:Fe,onEdit:i=>{We({start:i.startLine,end:i.endLine,side:i.side==="original"?"deletions":"additions"}),k(i)},onDelete:A}):null;return h==="fill"?O.jsx("div",{className:ke("flex flex-col relative","size-full"),"data-diff-virtual-root":!0,children:O.jsxs("div",{className:"flex-1 relative min-h-0",children:[O.jsx(Ge,{outerClassName:"pierre-diff-wrapper size-full",disableHorizontal:!1,fillContainer:!0,"data-diff-virtual-content":!0,children:O.jsx("div",{ref:ne,className:"size-full relative",children:O.jsx("div",{ref:K,className:"size-full"})})}),xe]})}):O.jsxs("div",{className:ke("relative","w-full"),children:[O.jsx("div",{ref:ne,className:"pierre-diff-wrapper w-full overflow-x-auto overflow-y-visible relative",children:O.jsx("div",{ref:K,className:"w-full"})}),xe]})};export{Ot as P};