@pi-chamber/web 0.3.1 → 0.3.2

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 (59) hide show
  1. package/bin/lib/cli-startup.js +53 -10
  2. package/bin/lib/cli-startup.test.js +42 -0
  3. package/dist/assets/{CommitSection-C336377Z.js → CommitSection-DLIvjYbM.js} +1 -1
  4. package/dist/assets/{DiagramEditor-gHLCXHtr.js → DiagramEditor-Tw3ZWHML.js} +1 -1
  5. package/dist/assets/{DiagramView-DlHzRRBc.js → DiagramView-CK6R7taL.js} +1 -1
  6. package/dist/assets/{DiffView-5wHwK-lg.js → DiffView-vrxi5oWp.js} +2 -2
  7. package/dist/assets/{FilesView-5bswI3JZ.js → FilesView-BD_h3EVr.js} +6 -6
  8. package/dist/assets/{GitView-BfykGpGh.js → GitView-BwNKqK0K.js} +4 -4
  9. package/dist/assets/{JsonTreeView-HVwQS7qG.js → JsonTreeView-CmY7QgEX.js} +1 -1
  10. package/dist/assets/{MarkdownRendererImpl-kjd4e0N8.js → MarkdownRendererImpl-CpI-25Xk.js} +1 -1
  11. package/dist/assets/{PatchDiff-Dlm4RU8n.js → PatchDiff-CrIWbYj7.js} +1 -1
  12. package/dist/assets/{PierreDiffViewer-St32rXlD.js → PierreDiffViewer-B410mdbq.js} +2 -2
  13. package/dist/assets/{SessionSwitcherDropdown-D5bWfZNA.js → SessionSwitcherDropdown-DROjbyIu.js} +93 -93
  14. package/dist/assets/SettingsView-CsJItYZh.js +4 -0
  15. package/dist/assets/{SettingsWindow-Ck_uhTnx.js → SettingsWindow-C9s4AX72.js} +1 -1
  16. package/dist/assets/{ToolOutputDialog-BCONUv3r.js → ToolOutputDialog-b_R4tAZu.js} +6 -6
  17. package/dist/assets/{ToolPartDiffPreview-BdVuk2kc.js → ToolPartDiffPreview-CfnliaE9.js} +1 -1
  18. package/dist/assets/{VirtualizedFileDiff-BsAZM0jo.js → VirtualizedFileDiff-CQz2fSZI.js} +4 -4
  19. package/dist/assets/{collapsible-Wnmq-13H.js → collapsible-CR4U9tjw.js} +1 -1
  20. package/dist/assets/{computeVirtualFileMetrics-skbyL2Az.js → computeVirtualFileMetrics-C7vXPUYT.js} +2 -2
  21. package/dist/assets/{contextFileOpenGuard-BsxQITMZ.js → contextFileOpenGuard-DtTHRnq1.js} +1 -1
  22. package/dist/assets/{index-8TL2HlaR.js → index-BAqpUCjs.js} +4 -4
  23. package/dist/assets/{index-Bfp6eYap.js → index-DZG82DE1.js} +1 -1
  24. package/dist/assets/{isDiffPlainText-dZkfk3yG.js → isDiffPlainText-zTq-4A04.js} +1 -1
  25. package/dist/assets/{isFilePlainText-UL_tMQZx.js → isFilePlainText-CLgIdzE5.js} +1 -1
  26. package/dist/assets/{main-CHQfoyRP.js → main-BVWtJYSk.js} +2 -2
  27. package/dist/assets/main-DXYHsqzA.js +133 -0
  28. package/dist/assets/{markdownCore-qX3mJFkL.js → markdownCore-CN0pApQE.js} +2 -2
  29. package/dist/assets/{miniChat-3QtCNwHl.js → miniChat-BrbRq5NQ.js} +2 -2
  30. package/dist/assets/{mobile-B_CyfRAX.js → mobile-DTPtCn5N.js} +2 -2
  31. package/dist/assets/{renderElectronMiniChatApp-OToslrv-.js → renderElectronMiniChatApp-CM8qBaye.js} +1 -1
  32. package/dist/assets/{renderMobileApp-BD_wep_I.js → renderMobileApp-KS_pt-qc.js} +4 -4
  33. package/dist/assets/{runtimeSurface-CkdOpqo7.js → runtimeSurface-CkHYYg0E.js} +1 -1
  34. package/dist/assets/{useInlineCommentController-DVif5Fr8.js → useInlineCommentController-CwNNjgc7.js} +2 -2
  35. package/dist/assets/usePanelSlide-DkorgQJ5.js +56 -0
  36. package/dist/assets/{useWindowTitle-BZVlLMCy.js → useWindowTitle-B9wt_3ZQ.js} +3 -3
  37. package/dist/assets/{vendor-codemirror-language-data-C-924Z4o.js → vendor-codemirror-language-data-x89A7Wy0.js} +2 -2
  38. package/dist/assets/{web-components-BG-6PEN4.js → web-components-BEPfE4kU.js} +4 -4
  39. package/dist/index.html +3 -3
  40. package/dist/mini-chat.html +2 -2
  41. package/dist/mobile.html +2 -2
  42. package/package.json +1 -1
  43. package/server/index.js +33 -0
  44. package/server/lib/pi/routes.js +5 -1
  45. package/server/lib/pi/session-daemon/DOCUMENTATION.md +1 -1
  46. package/server/lib/pi/session-daemon/session-daemon.js +111 -9
  47. package/server/lib/pi/session-daemon/session-daemon.test.js +75 -0
  48. package/server/lib/pi/settings-store.js +17 -0
  49. package/server/lib/pi/settings-store.test.js +33 -0
  50. package/server/lib/server/core-routes.js +36 -4
  51. package/server/lib/server/tunnel-service.DOCUMENTATION.md +74 -0
  52. package/server/lib/server/tunnel-service.js +228 -0
  53. package/server/lib/server/tunnel-service.test.js +61 -0
  54. package/server/lib/ui-auth/DOCUMENTATION.md +2 -0
  55. package/server/lib/ui-auth/ui-auth.js +5 -1
  56. package/server/lib/ui-auth/ui-auth.test.js +17 -0
  57. package/dist/assets/SettingsView-FGe5TEQq.js +0 -4
  58. package/dist/assets/main-DbnYXZeK.js +0 -133
  59. package/dist/assets/usePanelSlide-C_PJmPXW.js +0 -56
@@ -1,10 +1,10 @@
1
- import{a as Te,e as Qe,j as et,s as tt,b as Xe,c as Fe,k as it,i as nt,d as Ye,g as Ne,f as he,h as st,R as rt,I as ot,p as Ue,l as at,m as lt,n as ht,x as Pe,S as dt,o as ut,w as ft,q as Oe,u as ct,t as pt,v as Ae,y as gt,z as mt,r as Ct,A as St,C as vt,B as yt,F as Ht}from"./web-components-BG-6PEN4.js";import{m as w,z as Se,x as Lt,j as Tt,d as At,i as ke,k as U,n as ce,l as kt,b as Rt,f as Be,o as Y,q as Ze,B as Re}from"./computeVirtualFileMetrics-skbyL2Az.js";import{h as xt,a as se,i as be,b as re,r as Dt,g as Et,c as ve,d as we,e as oe,f as Me,j as ae}from"./isDiffPlainText-dZkfk3yG.js";import{dt as bt,eB as wt,eC as Ie,df as _,eD as Mt,eE as It,dU as Ve,dV as zt,dW as Ft,dX as Nt,dY as Ut,dZ as Pt}from"./SessionSwitcherDropdown-D5bWfZNA.js";import{c as Ot}from"./vendor-diff-C3JhlQdm.js";import{t as le}from"./vendor-hast-util-to-html-BKBhbTDb.js";function Z(e,t,i,n=!1){const s=bt(Ot(e.name,t.name,e.contents,t.contents,e.header,t.header,i),{cacheKey:(()=>{if(e.cacheKey!=null&&t.cacheKey!=null)return`${e.cacheKey}:${t.cacheKey}`})(),oldFile:e,newFile:t,throwOnError:n});if(s==null)throw new Error("parseDiffFrom: FileInvalid diff -- probably need to fix something -- if the files are the same maybe?");return t.lang!=null&&(s.lang=t.lang),s}var Bt=class{isDeletionsScrolling=!1;isAdditionsScrolling=!1;timeoutId=-1;codeDeletions;codeAdditions;enabled=!1;cleanUp(){this.enabled&&(this.codeDeletions?.removeEventListener("scroll",this.handleDeletionsScroll),this.codeAdditions?.removeEventListener("scroll",this.handleAdditionsScroll),clearTimeout(this.timeoutId),this.codeDeletions=void 0,this.codeAdditions=void 0,this.enabled=!1)}setup(e,t,i){if(t==null||i==null)for(const n of e.children??[])n instanceof HTMLElement&&("deletions"in n.dataset?t=n:"additions"in n.dataset&&(i=n));if(i==null||t==null){this.cleanUp();return}this.codeDeletions!==t&&(this.codeDeletions?.removeEventListener("scroll",this.handleDeletionsScroll),this.codeDeletions=t,t.addEventListener("scroll",this.handleDeletionsScroll,{passive:!0})),this.codeAdditions!==i&&(this.codeAdditions?.removeEventListener("scroll",this.handleAdditionsScroll),this.codeAdditions=i,i.addEventListener("scroll",this.handleAdditionsScroll,{passive:!0})),this.enabled=!0}handleDeletionsScroll=()=>{this.isAdditionsScrolling||(this.isDeletionsScrolling=!0,clearTimeout(this.timeoutId),this.timeoutId=setTimeout(()=>{this.isDeletionsScrolling=!1},300),this.codeAdditions?.scrollTo({left:this.codeDeletions?.scrollLeft}))};handleAdditionsScroll=()=>{this.isDeletionsScrolling||(this.isAdditionsScrolling=!0,clearTimeout(this.timeoutId),this.timeoutId=setTimeout(()=>{this.isAdditionsScrolling=!1},300),this.codeDeletions?.scrollTo({left:this.codeAdditions?.scrollLeft}))}};function pe(e){return w({tagName:"div",properties:{"data-content-buffer":"","data-buffer-size":e,style:`grid-row: span ${e};min-height:calc(${e} * 1lh)`}})}function ge(e){return w({tagName:"div",children:[w({tagName:"span",children:[Se("No newline at end of file")]})],properties:{"data-no-newline":"","data-line-type":e,"data-column-content":""}})}function xe(e){return w({tagName:"div",children:[Lt({name:e==="both"?"diffs-icon-expand-all":"diffs-icon-expand",properties:{"data-icon":""}})],properties:{role:"button","data-expand-button":"","data-expand-both":e==="both"?"":void 0,"data-expand-up":e==="up"?"":void 0,"data-expand-down":e==="down"?"":void 0}})}function K({type:e,content:t,expandIndex:i,chunked:n=!1,slotName:s,isFirstHunk:r,isLastHunk:o}){let a=0;const l=[];if(e==="metadata"&&t!=null&&l.push(w({tagName:"div",children:[Se(t)],properties:{"data-separator-wrapper":""}})),(e==="line-info"||e==="line-info-basic")&&t!=null){const u=[];i!=null&&(n?(r||(u.push(xe("up")),a++),o||(u.push(xe("down")),a++)):(u.push(xe(!r&&!o?"both":r?"down":"up")),a++)),u.push(w({tagName:"div",children:[w({tagName:"span",children:[Se(t)],properties:{"data-unmodified-lines":""}})],properties:{"data-separator-content":""}})),n&&i!=null&&u.push(w({tagName:"div",children:[Se("Expand all")],properties:{role:"button","data-expand-button":"","data-expand-all-button":""}})),l.push(w({tagName:"div",children:u,properties:{"data-separator-wrapper":"","data-separator-multi-button":a>1?"":void 0}}))}return e==="custom"&&s!=null&&l.push(w({tagName:"slot",properties:{name:s}})),w({tagName:"div",children:l,properties:{"data-separator":l.length===0?"simple":e,"data-expand-index":i,"data-separator-first":r?"":void 0,"data-separator-last":o?"":void 0}})}function Vt(e,t){return`hunk-separator-${e}-${t}`}function Gt(e){const t=e.at(-1);return t==null?0:Math.max(t.additionStart+t.additionCount,t.deletionStart+t.deletionCount)}function Wt(e){return e.startingLine===0&&e.totalLines===1/0&&e.bufferBefore===0&&e.bufferAfter===0}function $t(e){return e!==""?e.split(wt):[]}function G(e,t){const i=Z({name:e.prevName??e.name,contents:e.deletionLines.join("")},{name:e.name,contents:e.additionLines.join(""),lang:e.lang},t);return{hunks:i.hunks,splitLineCount:i.splitLineCount,unifiedLineCount:i.unifiedLineCount,additionLines:i.additionLines,deletionLines:i.deletionLines,type:i.type}}function _t(e,t){const i=e.deletionLines.join(""),n=i===`
1
+ import{a as Te,e as Je,j as et,s as tt,b as Xe,c as Fe,k as it,i as nt,d as Ye,g as Ne,f as he,h as st,R as rt,I as ot,p as Ue,l as at,m as lt,n as ht,x as Pe,S as dt,o as ut,w as ft,q as Oe,u as ct,t as pt,v as Ae,y as gt,z as mt,r as Ct,A as St,C as vt,B as yt,F as Ht}from"./web-components-BEPfE4kU.js";import{m as w,z as Se,x as Lt,j as Tt,d as At,i as ke,k as U,n as ce,l as kt,b as Rt,f as Be,o as Y,q as Qe,B as Re}from"./computeVirtualFileMetrics-C7vXPUYT.js";import{h as xt,a as se,i as be,b as re,r as Dt,g as Et,c as ve,d as we,e as oe,f as Me,j as ae}from"./isDiffPlainText-zTq-4A04.js";import{dn as bt,ew as wt,ex as Ie,da as _,ey as Mt,ez as It,dP as Ve,dQ as zt,dR as Ft,dS as Nt,dT as Ut,dU as Pt}from"./SessionSwitcherDropdown-DROjbyIu.js";import{c as Ot}from"./vendor-diff-C3JhlQdm.js";import{t as le}from"./vendor-hast-util-to-html-BKBhbTDb.js";function Q(e,t,i,n=!1){const s=bt(Ot(e.name,t.name,e.contents,t.contents,e.header,t.header,i),{cacheKey:(()=>{if(e.cacheKey!=null&&t.cacheKey!=null)return`${e.cacheKey}:${t.cacheKey}`})(),oldFile:e,newFile:t,throwOnError:n});if(s==null)throw new Error("parseDiffFrom: FileInvalid diff -- probably need to fix something -- if the files are the same maybe?");return t.lang!=null&&(s.lang=t.lang),s}var Bt=class{isDeletionsScrolling=!1;isAdditionsScrolling=!1;timeoutId=-1;codeDeletions;codeAdditions;enabled=!1;cleanUp(){this.enabled&&(this.codeDeletions?.removeEventListener("scroll",this.handleDeletionsScroll),this.codeAdditions?.removeEventListener("scroll",this.handleAdditionsScroll),clearTimeout(this.timeoutId),this.codeDeletions=void 0,this.codeAdditions=void 0,this.enabled=!1)}setup(e,t,i){if(t==null||i==null)for(const n of e.children??[])n instanceof HTMLElement&&("deletions"in n.dataset?t=n:"additions"in n.dataset&&(i=n));if(i==null||t==null){this.cleanUp();return}this.codeDeletions!==t&&(this.codeDeletions?.removeEventListener("scroll",this.handleDeletionsScroll),this.codeDeletions=t,t.addEventListener("scroll",this.handleDeletionsScroll,{passive:!0})),this.codeAdditions!==i&&(this.codeAdditions?.removeEventListener("scroll",this.handleAdditionsScroll),this.codeAdditions=i,i.addEventListener("scroll",this.handleAdditionsScroll,{passive:!0})),this.enabled=!0}handleDeletionsScroll=()=>{this.isAdditionsScrolling||(this.isDeletionsScrolling=!0,clearTimeout(this.timeoutId),this.timeoutId=setTimeout(()=>{this.isDeletionsScrolling=!1},300),this.codeAdditions?.scrollTo({left:this.codeDeletions?.scrollLeft}))};handleAdditionsScroll=()=>{this.isDeletionsScrolling||(this.isAdditionsScrolling=!0,clearTimeout(this.timeoutId),this.timeoutId=setTimeout(()=>{this.isAdditionsScrolling=!1},300),this.codeDeletions?.scrollTo({left:this.codeAdditions?.scrollLeft}))}};function pe(e){return w({tagName:"div",properties:{"data-content-buffer":"","data-buffer-size":e,style:`grid-row: span ${e};min-height:calc(${e} * 1lh)`}})}function ge(e){return w({tagName:"div",children:[w({tagName:"span",children:[Se("No newline at end of file")]})],properties:{"data-no-newline":"","data-line-type":e,"data-column-content":""}})}function xe(e){return w({tagName:"div",children:[Lt({name:e==="both"?"diffs-icon-expand-all":"diffs-icon-expand",properties:{"data-icon":""}})],properties:{role:"button","data-expand-button":"","data-expand-both":e==="both"?"":void 0,"data-expand-up":e==="up"?"":void 0,"data-expand-down":e==="down"?"":void 0}})}function K({type:e,content:t,expandIndex:i,chunked:n=!1,slotName:s,isFirstHunk:r,isLastHunk:o}){let a=0;const l=[];if(e==="metadata"&&t!=null&&l.push(w({tagName:"div",children:[Se(t)],properties:{"data-separator-wrapper":""}})),(e==="line-info"||e==="line-info-basic")&&t!=null){const u=[];i!=null&&(n?(r||(u.push(xe("up")),a++),o||(u.push(xe("down")),a++)):(u.push(xe(!r&&!o?"both":r?"down":"up")),a++)),u.push(w({tagName:"div",children:[w({tagName:"span",children:[Se(t)],properties:{"data-unmodified-lines":""}})],properties:{"data-separator-content":""}})),n&&i!=null&&u.push(w({tagName:"div",children:[Se("Expand all")],properties:{role:"button","data-expand-button":"","data-expand-all-button":""}})),l.push(w({tagName:"div",children:u,properties:{"data-separator-wrapper":"","data-separator-multi-button":a>1?"":void 0}}))}return e==="custom"&&s!=null&&l.push(w({tagName:"slot",properties:{name:s}})),w({tagName:"div",children:l,properties:{"data-separator":l.length===0?"simple":e,"data-expand-index":i,"data-separator-first":r?"":void 0,"data-separator-last":o?"":void 0}})}function Vt(e,t){return`hunk-separator-${e}-${t}`}function Gt(e){const t=e.at(-1);return t==null?0:Math.max(t.additionStart+t.additionCount,t.deletionStart+t.deletionCount)}function Wt(e){return e.startingLine===0&&e.totalLines===1/0&&e.bufferBefore===0&&e.bufferAfter===0}function $t(e){return e!==""?e.split(wt):[]}function G(e,t){const i=Q({name:e.prevName??e.name,contents:e.deletionLines.join("")},{name:e.name,contents:e.additionLines.join(""),lang:e.lang},t);return{hunks:i.hunks,splitLineCount:i.splitLineCount,unifiedLineCount:i.unifiedLineCount,additionLines:i.additionLines,deletionLines:i.deletionLines,type:i.type}}function _t(e,t){const i=e.deletionLines.join(""),n=i===`
2
2
  `?`
3
3
  `:`
4
- `,s=Z({name:e.prevName??e.name,contents:i},{name:e.name,contents:n,lang:e.lang},t);return{hunks:s.hunks,splitLineCount:s.splitLineCount,unifiedLineCount:s.unifiedLineCount,additionLines:[""],deletionLines:s.deletionLines,type:s.type}}function jt(e,t,i){if(e.isPartial||e.deletionLines.length!==e.additionLines.length)return B(e,G(e,i));const n=Array.from(t);if(n.length===0)return B(e,{hunks:e.hunks,splitLineCount:e.splitLineCount,unifiedLineCount:e.unifiedLineCount,type:e.type});for(const r of n){const o=e.additionLines[r],a=e.deletionLines[r];if(o==null||a==null||Ie(o)===Ie(a))return B(e,G(e,i))}const s=qt(e,n);if(s.size===0)return B(e,G(e,i));for(const r of s)if(!Xt(e,r,i))return B(e,G(e,i));return Qt(e),xt(e)?B(e,G(e,i)):B(e,{hunks:e.hunks,splitLineCount:e.splitLineCount,unifiedLineCount:e.unifiedLineCount,type:e.type})}function B(e,t){return Object.assign(e,t),t}function qt(e,t){const i=new Set;for(const n of t){const s=Kt(e,n);if(s==null)return new Set;i.add(s)}return i}function Kt(e,t){for(const[i,n]of e.hunks.entries()){const s=n.additionLineIndex+n.additionCount;if(t>=n.additionLineIndex&&t<s)return i}}function Xt(e,t,i){const n=e.hunks[t];if(n==null)return!1;const s=e.deletionLines.slice(n.deletionLineIndex,n.deletionLineIndex+n.deletionCount),r=e.additionLines.slice(n.additionLineIndex,n.additionLineIndex+n.additionCount),o=Z({name:e.prevName??e.name,contents:s.join("")},{name:e.name,contents:r.join(""),lang:e.lang},{...i,context:0}),a=o.hunks[0];return a==null||o.hunks.length!==1?!1:(Zt(n,a),Yt(e,t),!0)}function Yt(e,t){const i=e.hunks[t];if(i==null)return;if(t!==e.hunks.length-1){i.noEOFCRAdditions=!1,i.noEOFCRDeletions=!1;return}const n=e.additionLines.at(-1),s=e.deletionLines.at(-1);i.noEOFCRAdditions=n!=null&&n!==""&&!n.endsWith(`
4
+ `,s=Q({name:e.prevName??e.name,contents:i},{name:e.name,contents:n,lang:e.lang},t);return{hunks:s.hunks,splitLineCount:s.splitLineCount,unifiedLineCount:s.unifiedLineCount,additionLines:[""],deletionLines:s.deletionLines,type:s.type}}function jt(e,t,i){if(e.isPartial||e.deletionLines.length!==e.additionLines.length)return B(e,G(e,i));const n=Array.from(t);if(n.length===0)return B(e,{hunks:e.hunks,splitLineCount:e.splitLineCount,unifiedLineCount:e.unifiedLineCount,type:e.type});for(const r of n){const o=e.additionLines[r],a=e.deletionLines[r];if(o==null||a==null||Ie(o)===Ie(a))return B(e,G(e,i))}const s=qt(e,n);if(s.size===0)return B(e,G(e,i));for(const r of s)if(!Xt(e,r,i))return B(e,G(e,i));return Jt(e),xt(e)?B(e,G(e,i)):B(e,{hunks:e.hunks,splitLineCount:e.splitLineCount,unifiedLineCount:e.unifiedLineCount,type:e.type})}function B(e,t){return Object.assign(e,t),t}function qt(e,t){const i=new Set;for(const n of t){const s=Kt(e,n);if(s==null)return new Set;i.add(s)}return i}function Kt(e,t){for(const[i,n]of e.hunks.entries()){const s=n.additionLineIndex+n.additionCount;if(t>=n.additionLineIndex&&t<s)return i}}function Xt(e,t,i){const n=e.hunks[t];if(n==null)return!1;const s=e.deletionLines.slice(n.deletionLineIndex,n.deletionLineIndex+n.deletionCount),r=e.additionLines.slice(n.additionLineIndex,n.additionLineIndex+n.additionCount),o=Q({name:e.prevName??e.name,contents:s.join("")},{name:e.name,contents:r.join(""),lang:e.lang},{...i,context:0}),a=o.hunks[0];return a==null||o.hunks.length!==1?!1:(Qt(n,a),Yt(e,t),!0)}function Yt(e,t){const i=e.hunks[t];if(i==null)return;if(t!==e.hunks.length-1){i.noEOFCRAdditions=!1,i.noEOFCRDeletions=!1;return}const n=e.additionLines.at(-1),s=e.deletionLines.at(-1);i.noEOFCRAdditions=n!=null&&n!==""&&!n.endsWith(`
5
5
  `),i.noEOFCRDeletions=s!=null&&s!==""&&!s.endsWith(`
6
- `)}function Zt(e,t){const i=e.additionLineIndex,n=e.deletionLineIndex;e.hunkContent=t.hunkContent.map(s=>Jt(s,i,n)),e.additionLineIndex=i+t.additionLineIndex,e.additionStart=e.additionStart+t.additionLineIndex,e.additionCount=t.additionCount,e.additionLines=t.additionLines,t.deletionLineIndex>=0&&(e.deletionLineIndex=n+t.deletionLineIndex,e.deletionStart=e.deletionStart+t.deletionLineIndex),e.deletionCount=t.deletionCount,e.deletionLines=t.deletionLines,e.noEOFCRAdditions=t.noEOFCRAdditions,e.noEOFCRDeletions=t.noEOFCRDeletions,Je(e)}function Jt(e,t,i){return{...e,additionLineIndex:e.additionLineIndex+t,deletionLineIndex:e.deletionLineIndex+i}}function Je(e){let t=0,i=0;for(const n of e.hunkContent)n.type==="context"?(t+=n.lines,i+=n.lines):(t+=Math.max(n.additions,n.deletions),i+=n.additions+n.deletions);e.splitLineCount=t,e.unifiedLineCount=i}function Qt(e){let t=0,i=0,n=0;for(const s of e.hunks)s.collapsedBefore=Math.max(s.additionStart-1-n,0),s.splitLineStart=t+s.collapsedBefore,s.unifiedLineStart=i+s.collapsedBefore,Je(s),t+=s.collapsedBefore+s.splitLineCount,i+=s.collapsedBefore+s.unifiedLineCount,n=s.additionStart+s.additionCount-1;if(e.hunks.length>0){const s=e.hunks[e.hunks.length-1],r=Math.max(e.additionLines.length-(s.additionLineIndex+s.additionCount),0);t+=r,i+=r}e.splitLineCount=t,e.unifiedLineCount=i}let ei=-1;var ti=class{options;onRenderUpdate;workerManager;__id=`diff-hunks-renderer:${++ei}`;highlighter;diff;expandedHunks=new Map;deletionAnnotations={};additionAnnotations={};computedLang="text";renderCache;constructor(e={theme:_},t,i){this.options=e,this.onRenderUpdate=t,this.workerManager=i,i?.isWorkingPool()!==!0&&(this.highlighter=Te(e.theme??_)?Tt():void 0)}cleanUp(){this.recycle(),this.expandedHunks.clear(),this.workerManager=void 0,this.onRenderUpdate=void 0}recycle(){this.highlighter=void 0,this.diff=void 0,this.clearRenderCache(),this.additionAnnotations={},this.deletionAnnotations={},this.workerManager?.cleanUpTasks(this)}getRenderDiff(){return this.renderCache?.diff??this.diff}clearRenderCache(){const e=this.renderCache;this.renderCache=void 0,e!=null&&e.isDirty===!0&&e.diff.cacheKey!=null&&this.workerManager?.evictDiffFromCache(e.diff.cacheKey)}setOptions(e){this.options=e}mergeOptions(e){this.options={...this.options,...e}}expandHunk(e,t,i=this.getOptionsWithDefaults().expansionLineCount){const n={...this.expandedHunks.get(e)??{fromStart:0,fromEnd:0}};(t==="up"||t==="both")&&(n.fromStart+=i),(t==="down"||t==="both")&&(n.fromEnd+=i),this.renderCache?.highlighted!==!0&&this.clearRenderCache(),this.expandedHunks.set(e,n)}getExpandedHunk(e){return this.expandedHunks.get(e)??Mt}getExpandedHunksMap(){return this.expandedHunks}setLineAnnotations(e){this.additionAnnotations={},this.deletionAnnotations={};for(const t of e){const i=(()=>{switch(t.side){case"deletions":return this.deletionAnnotations;case"additions":return this.additionAnnotations}})(),n=i[t.lineNumber]??[];i[t.lineNumber]=n,n.push(t)}}updateRenderCache(e,t,i=!1){if(this.renderCache==null)return;const{result:n,diff:s}=this.renderCache;if(n==null)return;if(s.isPartial)throw new Error("Could not update render cache for partial diff");const r=n.code.additionLines,o=[];for(const[a,l]of e){const u=r[a]?.properties??{},f=l.map(g=>g[2]).join(""),h=a<s.additionLines.length,d=h?s.additionLines[a]??"":"",c=Ie(d);h&&(s.additionLines[a]=ni(d,f),c!==f&&o.push(a)),r[a]={type:"element",tagName:"div",properties:{"data-line":u["data-line"]??a+1,"data-line-index":u["data-line-index"]??a,"data-line-type":u["data-line-type"]??"context"},children:l.map(([g,m,C])=>g===0&&m===""?C===""?{type:"element",tagName:"br",properties:{},children:[]}:{type:"text",value:C}:{type:"element",tagName:"span",properties:{"data-char":g,style:`--diffs-token-${t}:${m};`},children:[{type:"text",value:C}]})}}!i&&o.length>0&&Object.assign(s,jt(s,o,this.options.parseDiffOptions)),n.baseThemeType=t,this.renderCache.isDirty=!0}applyDocumentChange(e){if(this.renderCache==null)return;const{diff:t,result:i}=this.renderCache;if(i==null)return;t.additionLines=$t(e.getText());const n=t.additionLines.length,s=i.code.additionLines,r=s.length;n<r&&(s.length=n);for(let o=r;o<n;o++)s[o]??=je(o,e);t.isPartial||(n===0?(Object.assign(t,_t(t,this.options.parseDiffOptions)),s[0]=je(0,e)):Object.assign(t,G(t,this.options.parseDiffOptions))),this.renderCache.isDirty=!0}getUnifiedLineDecoration({lineType:e}){return{gutterLineType:e,contentProperties:{"data-line-type":e}}}getSplitLineDecoration({side:e,type:t}){const i=t==="change"?e==="deletions"?"change-deletion":"change-addition":t;return{gutterLineType:i,contentProperties:{"data-line-type":i}}}createAnnotationElement=e=>Qe(e);getOptionsWithDefaults(){const{diffIndicators:e="bars",diffStyle:t="split",disableBackground:i=!1,disableFileHeader:n=!1,disableLineNumbers:s=!1,disableVirtualizationBuffers:r=!1,collapsed:o=!1,expandUnchanged:a=!1,collapsedContextThreshold:l=1,expansionLineCount:u=100,hunkSeparators:f="line-info",lineDiffType:h="word-alt",maxLineDiffLength:d=1e3,overflow:c="scroll",stickyHeader:g=!1,theme:m=_,headerRenderMode:C="default",tokenizeMaxLineLength:y=1e3,tokenizeMaxLength:v=It,useTokenTransformer:p=!1,useCSSClasses:S=!1}=this.options;return{diffIndicators:e,diffStyle:t,disableBackground:i,disableFileHeader:n,disableLineNumbers:s,disableVirtualizationBuffers:r,collapsed:o,expandUnchanged:a,collapsedContextThreshold:l,expansionLineCount:u,hunkSeparators:f,lineDiffType:h,maxLineDiffLength:d,overflow:c,stickyHeader:g,theme:this.workerManager?.getDiffRenderOptions().theme??m,headerRenderMode:C,tokenizeMaxLineLength:y,tokenizeMaxLength:v,useTokenTransformer:p,useCSSClasses:S}}async initializeHighlighter(){return this.highlighter=await At(et(this.computedLang,this.options)),this.highlighter}hydrate(e){if(e==null)return;this.diff=e;const{options:t}=this.getRenderOptions(e),i=Ee(e,this.getTokenizeMaxLength());let n=this.workerManager?.getDiffResultCache(e);n!=null&&!se(t,n.options)&&(n=void 0),this.renderCache??={diff:e,highlighted:!i&&!be(e),options:t,result:i?void 0:n?.result,renderRange:void 0},this.workerManager?.isWorkingPool()===!0?this.renderCache.result==null&&!i&&this.workerManager.highlightDiffAST(this,this.diff):this.highlighter==null&&(this.computedLang=e.lang??ke(e.name),this.initializeHighlighter())}getRenderOptions(e){const t=(()=>{if(this.workerManager?.isWorkingPool()===!0)return this.workerManager.getDiffRenderOptions();const{theme:n,tokenizeMaxLineLength:s,lineDiffType:r,maxLineDiffLength:o}=this.getOptionsWithDefaults();return{theme:n,useTokenTransformer:tt(this.options),tokenizeMaxLineLength:s,lineDiffType:r,maxLineDiffLength:o}})();this.getOptionsWithDefaults();const{renderCache:i}=this;return i?.result==null?{options:t,forceHighlight:!0}:!re(e,i.diff)||!se(t,i.options)?{options:t,forceHighlight:!0}:{options:t,forceHighlight:!1}}renderDiff(e=this.renderCache?.diff,t=Ve){if(e==null)return;const{expandUnchanged:i=!1,collapsedContextThreshold:n}=this.getOptionsWithDefaults();let{options:s,forceHighlight:r}=this.getRenderOptions(e);const o=this.getMatchingWorkerResultCache(e,s);o!=null&&!this.hasHighlightedRenderCache(e,s)&&(this.renderCache={diff:e,highlighted:!0,renderRange:void 0,...o},r=!1),this.renderCache??={diff:e,highlighted:!1,options:s,result:void 0,renderRange:void 0};const a=e.additionLines.length>0||e.deletionLines.length>0,l=!a||be(e)||Ee(e,this.getTokenizeMaxLength()),u=!re(e,this.renderCache.diff),f=!Xe(this.renderCache.renderRange,t);if(this.workerManager?.isWorkingPool()===!0)(l||this.renderCache.result==null||!this.renderCache.highlighted&&(u||f))&&(this.renderCache.diff=e,this.renderCache.options=s,this.renderCache.highlighted=!1,(this.renderCache.result==null||u||f||r)&&(this.renderCache.result=this.workerManager.getPlainDiffAST(e,t.startingLine,t.totalLines,Wt(t)||i?!0:this.expandedHunks,n)),this.renderCache.renderRange=t),!l&&a&&(!this.renderCache.highlighted||r)&&this.workerManager.highlightDiffAST(this,e);else{this.computedLang=e.lang??ke(e.name);const h=this.highlighter!=null&&Te(s.theme),d=this.highlighter!=null&&Fe(this.computedLang),c=!l&&d;if(this.highlighter!=null&&h&&(r||l||!this.renderCache.highlighted&&c||this.renderCache.result==null)){const{result:g,options:m}=this.renderDiffWithHighlighter(e,this.highlighter,l||!d);this.renderCache={diff:e,options:m,highlighted:c,result:g,renderRange:void 0}}(!h||!l&&!d)&&this.asyncHighlight(e).then(({result:g,options:m})=>{this.renderCache!=null&&(this.renderCache.highlighted=!1),this.onHighlightSuccess(e,g,m,!l)})}return this.renderCache.result!=null?this.processDiffResult(this.renderCache.diff,t,this.renderCache.result):void 0}async asyncRender(e,t=Ve){const{result:i}=await this.asyncHighlight(e);return this.processDiffResult(e,t,i)}createPreElement(e,t,i){const{diffIndicators:n,disableBackground:s,disableLineNumbers:r,overflow:o}=this.getOptionsWithDefaults();return it({type:"diff",diffIndicators:n,disableBackground:s,disableLineNumbers:r,overflow:o,split:e,totalLines:t,customProperties:i})}async asyncHighlight(e){const t=Ee(e,this.getTokenizeMaxLength());this.computedLang=t?"text":e.lang??ke(e.name);const i=this.highlighter!=null&&Te(this.options.theme??_),n=t||this.highlighter!=null&&Fe(this.computedLang);return(this.highlighter==null||!i||!n)&&(this.highlighter=await this.initializeHighlighter()),this.renderDiffWithHighlighter(e,this.highlighter,t)}renderDiffWithHighlighter(e,t,i=!1){const{options:n}=this.getRenderOptions(e),{collapsedContextThreshold:s}=this.getOptionsWithDefaults();return{result:Dt(e,t,n,{forcePlainText:i,expandedHunks:i?!0:void 0,collapsedContextThreshold:s}),options:n}}onHighlightSuccess(e,t,i,n=!0){if(this.renderCache==null)return;const s=!this.renderCache.highlighted||!se(this.renderCache.options,i)||!re(this.renderCache.diff,e);this.renderCache={diff:e,options:i,highlighted:n,result:t,renderRange:void 0},s&&this.onRenderUpdate?.()}getMatchingWorkerResultCache(e,t){const i=this.workerManager?.getDiffResultCache(e);if(!(i==null||!se(t,i.options)))return i}hasHighlightedRenderCache(e,t){const{renderCache:i}=this;return i?.result!=null&&i.highlighted&&re(e,i.diff)&&se(t,i.options)}onHighlightError(e){console.error(e)}getTokenizeMaxLength(){return this.options.tokenizeMaxLength??1e5}processDiffResult(e,t,{code:i,themeStyles:n,baseThemeType:s}){const{diffStyle:r,disableFileHeader:o,expandUnchanged:a,expansionLineCount:l,collapsedContextThreshold:u,hunkSeparators:f}=this.getOptionsWithDefaults(),h=this.renderCache?.isDirty??!1;this.diff=e;const d=r==="unified";let c=[],g=[],m=[];const C=[],{additionLines:y,deletionLines:v}=i,p={rowCount:0,hunkSeparators:f,additionsContentAST:c,deletionsContentAST:g,unifiedContentAST:m,unifiedGutterAST:ce(),deletionsGutterAST:ce(),additionsGutterAST:ce(),expansionLineCount:l,hunkData:C,incrementRowCount(R=1){p.rowCount+=R},pushToGutter(R,D){switch(R){case"unified":p.unifiedGutterAST.children.push(D);break;case"deletions":p.deletionsGutterAST.children.push(D);break;case"additions":p.additionsGutterAST.children.push(D);break}}},S=Et({fileDiff:e,errorPrefix:"DiffHunksRenderer.processDiffResult"}),H={size:0,side:void 0,increment(){this.size+=1},flush(){if(r!=="unified"){if(this.size<=0||this.side==null){this.side=void 0,this.size=0;return}this.side==="additions"?(p.pushToGutter("additions",U(void 0,"buffer",this.size)),c?.push(pe(this.size))):(p.pushToGutter("deletions",U(void 0,"buffer",this.size)),g?.push(pe(this.size))),this.size=0,this.side=void 0}}},T=(R,D,P,V,L)=>{p.pushToGutter(R,kt(D,P,V,L))};function F(R){H.flush(),r==="unified"?De("unified",R,p):(De("deletions",R,p),De("additions",R,p))}this.pushFileLevelAnnotations(e,r,t,p),ve({diff:e,diffStyle:r,startingLine:t.startingLine,totalLines:t.totalLines,expandedHunks:a?!0:this.expandedHunks,collapsedContextThreshold:u,callback:({hunkIndex:R,hunk:D,collapsedBefore:P,collapsedAfter:V,additionLine:L,deletionLine:A,type:x})=>{const I=A!=null?A.splitLineIndex:L.splitLineIndex,W=L!=null?L.unifiedLineIndex:A.unifiedLineIndex;r==="split"&&x!=="change"&&H.flush(),P>0&&F({hunkIndex:R,collapsedLines:P,rangeSize:Math.max(D?.collapsedBefore??0,0),hunkSpecs:D?.hunkSpecs,isFirstHunk:R===0,isLastHunk:!1,isExpandable:!e.isPartial});const Q=r==="unified"?W:I,ee={type:x,hunkIndex:R,lineIndex:Q,unifiedLineIndex:W,splitLineIndex:I,deletionLine:A,additionLine:L};if(r==="unified"){const k=this.getUnifiedInjectedRowsForLine?.(ee);k?.before!=null&&$e(k.before,p);let E=A!=null?v[A.lineIndex]:void 0,z=L!=null?y[L.lineIndex]:void 0;if(E==null&&z==null){const N="DiffHunksRenderer.processDiffResult: deletionLine and additionLine are null, something is wrong";throw console.error(N,{file:e.name}),new Error(N)}const $=x==="change"?L!=null?"change-addition":"change-deletion":x,O=this.getUnifiedLineDecoration({type:x,lineType:$,additionLineIndex:L?.lineIndex,deletionLineIndex:A?.lineIndex});T("unified",O.gutterLineType,L!=null?L.lineNumber:A.lineNumber,`${W},${I}`,O.gutterProperties),z!=null?z=Ce(z,O.contentProperties,h&&L!=null?{"data-line":L.lineNumber,"data-line-index":`${W},${I}`}:void 0):E!=null&&(E=Ce(E,O.contentProperties,h&&A!=null?{"data-line":A.lineNumber,"data-line-index":`${W},${I}`}:void 0)),me({diffStyle:"unified",type:x,deletionLine:E,additionLine:z,unifiedSpan:this.getAnnotations("unified",A?.lineNumber,L?.lineNumber,R,Q),createAnnotationElement:N=>this.createAnnotationElement(N),context:p}),k?.after!=null&&$e(k.after,p)}else{const k=this.getSplitInjectedRowsForLine?.(ee);k?.before!=null&&_e(k.before,p,H);let E=A!=null?v[A.lineIndex]:void 0,z=L!=null?y[L.lineIndex]:void 0;const $=this.getSplitLineDecoration({side:"deletions",type:x,lineIndex:A?.lineIndex}),O=this.getSplitLineDecoration({side:"additions",type:x,lineIndex:L?.lineIndex});if(E==null&&z==null){const M="DiffHunksRenderer.processDiffResult: deletionLine and additionLine are null, something is wrong";throw console.error(M,{file:e.name}),new Error(M)}const N=(()=>{if(x==="change"){if(z==null)return"additions";if(E==null)return"deletions"}})();if(N!=null){if(H.side!=null&&H.side!==N)throw new Error("DiffHunksRenderer.processDiffResult: iterateOverDiff, invalid pending splits");H.side=N,H.increment()}const ne=this.getAnnotations("split",A?.lineNumber,L?.lineNumber,R,Q);if(ne!=null&&H.size>0&&H.flush(),A!=null){const M=Ce(E,$.contentProperties,h?{"data-line":A.lineNumber,"data-line-index":`${A.unifiedLineIndex},${I}`}:void 0);T("deletions",$.gutterLineType,A.lineNumber,`${A.unifiedLineIndex},${I}`,$.gutterProperties),M!=null&&(E=M)}if(L!=null){const M=Ce(z,O.contentProperties,h?{"data-line":L.lineNumber,"data-line-index":`${L.unifiedLineIndex},${I}`}:void 0);T("additions",O.gutterLineType,L.lineNumber,`${L.unifiedLineIndex},${I}`,O.gutterProperties),M!=null&&(z=M)}me({diffStyle:"split",type:x,additionLine:z,deletionLine:E,...ne,createAnnotationElement:M=>this.createAnnotationElement(M),context:p}),k?.after!=null&&_e(k.after,p,H)}const fe=r==="split"&&D!=null&&I===D.splitLineStart+D.splitLineCount-1,ye=fe?D.noEOFCRDeletions:!1,He=fe?D.noEOFCRAdditions:!1,te=(A?.noEOFCR??!1)||ye,ie=(L?.noEOFCR??!1)||He;if(ie||te){if(r==="split"&&H.flush(),te){const k=x==="context"||x==="context-expanded"?x:"change-deletion";r==="unified"?(p.unifiedContentAST.push(ge(k)),p.pushToGutter("unified",U(k,"metadata",1))):(p.deletionsContentAST.push(ge(k)),p.pushToGutter("deletions",U(k,"metadata",1)),ie||(p.pushToGutter("additions",U(void 0,"buffer",1)),p.additionsContentAST.push(pe(1))))}if(ie){const k=x==="context"||x==="context-expanded"?x:"change-addition";r==="unified"?(p.unifiedContentAST.push(ge(k)),p.pushToGutter("unified",U(k,"metadata",1))):(p.additionsContentAST.push(ge(k)),p.pushToGutter("additions",U(k,"metadata",1)),te||(p.pushToGutter("deletions",U(void 0,"buffer",1)),p.deletionsContentAST.push(pe(1))))}p.incrementRowCount(1)}V>0&&f!=="simple"&&F({hunkIndex:x==="context-expanded"?R:R+1,collapsedLines:V,rangeSize:S,hunkSpecs:void 0,isFirstHunk:!1,isLastHunk:!0,isExpandable:!e.isPartial}),p.incrementRowCount(1)}}),r==="split"&&H.flush();const de=Math.max(Gt(e.hunks),e.additionLines.length??0,e.deletionLines.length??0),j=t.bufferBefore>0||t.bufferAfter>0,ue=!d&&e.type!=="deleted",q=!d&&e.type!=="new",b=p.rowCount>0||j;c=ue&&b?c:void 0,g=q&&b?g:void 0,m=d&&b?m:void 0;const J=this.createPreElement(g!=null&&c!=null,de);return{unifiedGutterAST:d&&b?p.unifiedGutterAST.children:void 0,unifiedContentAST:m,deletionsGutterAST:q&&b?p.deletionsGutterAST.children:void 0,deletionsContentAST:g,additionsGutterAST:ue&&b?p.additionsGutterAST.children:void 0,additionsContentAST:c,hunkData:C,preNode:J,themeStyles:n,baseThemeType:s,headerElement:o?void 0:this.renderHeader(this.diff),totalLines:de,rowCount:p.rowCount,bufferBefore:t.bufferBefore,bufferAfter:t.bufferAfter,css:""}}renderCodeAST(e,t){const i=e==="unified"?t.unifiedGutterAST:e==="deletions"?t.deletionsGutterAST:t.additionsGutterAST,n=e==="unified"?t.unifiedContentAST:e==="deletions"?t.deletionsContentAST:t.additionsContentAST;if(i==null||n==null)return;const s=ce(i);return s.properties.style=`grid-row: span ${t.rowCount}`,[s,nt(n,t.rowCount)]}renderFullAST(e,t=[]){const i=this.getOptionsWithDefaults().hunkSeparators==="line-info",n=this.renderCodeAST("unified",e);if(n!=null)return t.push(w({tagName:"code",children:n,properties:{"data-code":"","data-container-size":i?"":void 0,"data-unified":""}})),{...e.preNode,children:t};const s=this.renderCodeAST("deletions",e);s!=null&&t.push(w({tagName:"code",children:s,properties:{"data-code":"","data-container-size":i?"":void 0,"data-deletions":""}}));const r=this.renderCodeAST("additions",e);return r!=null&&t.push(w({tagName:"code",children:r,properties:{"data-code":"","data-container-size":i?"":void 0,"data-additions":""}})),{...e.preNode,children:t}}renderFullHTML(e,t=[]){return le(this.renderFullAST(e,t))}renderPartialHTML(e,t){return t==null?le(e):le(w({tagName:"code",children:e,properties:{"data-code":"","data-container-size":this.getOptionsWithDefaults().hunkSeparators==="line-info"?"":void 0,[`data-${t}`]:""}}))}pushFileLevelAnnotations(e,t,i,n){if(!Ye(i))return;const s=e.type!=="new"?Ge(Ne(this.deletionAnnotations)):[],r=e.type!=="deleted"?Ge(Ne(this.additionAnnotations)):[];if(s.length===0&&r.length===0)return;const o=-1,a=-1,{createAnnotationElement:l}=this;if(t==="unified"){me({diffStyle:t,type:"context",unifiedSpan:{type:"annotation",hunkIndex:o,lineIndex:a,annotations:s.concat(r)},createAnnotationElement:l,context:n});return}me({diffStyle:t,type:"context",deletionSpan:{type:"annotation",hunkIndex:o,lineIndex:a,annotations:s},additionSpan:{type:"annotation",hunkIndex:o,lineIndex:a,annotations:r},createAnnotationElement:l,context:n})}getAnnotations(e,t,i,n,s){const r={type:"annotation",hunkIndex:n,lineIndex:s,annotations:[]};if(t!=null)for(const a of this.deletionAnnotations[t]??[])r.annotations.push(he(a));const o={type:"annotation",hunkIndex:n,lineIndex:s,annotations:[]};if(i!=null)for(const a of this.additionAnnotations[i]??[])(e==="unified"?r:o).annotations.push(he(a));if(e==="unified")return r.annotations.length>0?r:void 0;if(!(o.annotations.length===0&&r.annotations.length===0))return{deletionSpan:r,additionSpan:o}}renderHeader(e){const{headerRenderMode:t,stickyHeader:i}=this.getOptionsWithDefaults();return st({fileOrDiff:e,mode:t,stickyHeader:i})}};function Ge(e){return e?.map(t=>he(t))??[]}const ii=new Intl.PluralRules("en-US");function We(e){return`${e} unmodified line${ii.select(e)==="one"?"":"s"}`}function $e(e,t){for(const i of e)t.unifiedContentAST.push(i.content),t.pushToGutter("unified",i.gutter),t.incrementRowCount(1)}function _e(e,t,i){for(const{deletion:n,addition:s}of e){if(n==null&&s==null)continue;const r=n!=null&&s!=null?void 0:n==null?"deletions":"additions";(r==null||i.side!==r)&&i.flush(),n!=null&&(t.deletionsContentAST.push(n.content),t.pushToGutter("deletions",n.gutter)),s!=null&&(t.additionsContentAST.push(s.content),t.pushToGutter("additions",s.gutter)),r!=null&&(i.side=r,i.increment()),t.incrementRowCount(1)}}function me({diffStyle:e,type:t,deletionLine:i,additionLine:n,unifiedSpan:s,deletionSpan:r,additionSpan:o,createAnnotationElement:a,context:l}){let u=!1;if(e==="unified"){if(n!=null?l.unifiedContentAST.push(n):i!=null&&l.unifiedContentAST.push(i),s!=null){const f=t==="change"?i!=null?"change-deletion":"change-addition":t;l.unifiedContentAST.push(a(s)),l.pushToGutter("unified",U(f,"annotation",1)),u=!0}}else if(e==="split"){if(i!=null&&l.deletionsContentAST.push(i),n!=null&&l.additionsContentAST.push(n),r!=null){const f=t==="change"?i!=null?"change-deletion":"context":t;l.deletionsContentAST.push(a(r)),l.pushToGutter("deletions",U(f,"annotation",1)),u=!0}if(o!=null){const f=t==="change"?n!=null?"change-addition":"context":t;l.additionsContentAST.push(a(o)),l.pushToGutter("additions",U(f,"annotation",1)),u=!0}}u&&l.incrementRowCount(1)}function De(e,{hunkIndex:t,collapsedLines:i,rangeSize:n,hunkSpecs:s,isFirstHunk:r,isLastHunk:o,isExpandable:a},l){if(i<=0)return;const u=e==="unified"?l.unifiedContentAST:e==="deletions"?l.deletionsContentAST:l.additionsContentAST;if(l.hunkSeparators==="metadata"){s!=null&&(l.pushToGutter(e,K({type:"metadata",content:s,isFirstHunk:r,isLastHunk:o})),u.push(K({type:"metadata",content:s,isFirstHunk:r,isLastHunk:o})),e!=="additions"&&l.incrementRowCount(1));return}if(l.hunkSeparators==="simple"){t>0&&(l.pushToGutter(e,K({type:"simple",isFirstHunk:r,isLastHunk:!1})),u.push(K({type:"simple",isFirstHunk:r,isLastHunk:!1})),e!=="additions"&&l.incrementRowCount(1));return}const f=Vt(e,t),h=n>l.expansionLineCount,d=a?t:void 0;l.pushToGutter(e,K({type:l.hunkSeparators,content:We(i),expandIndex:d,chunked:h,slotName:f,isFirstHunk:r,isLastHunk:o})),u.push(K({type:l.hunkSeparators,content:We(i),expandIndex:d,chunked:h,slotName:f,isFirstHunk:r,isLastHunk:o})),e!=="additions"&&l.incrementRowCount(1),l.hunkData.push({slotName:f,hunkIndex:t,lines:i,type:e,expandable:a?{up:!r,down:!o,chunked:h}:void 0})}function Ce(e,t,i){return e==null||e.type!=="element"||t==null&&i==null?e:{...e,properties:{...e.properties,...t,...i}}}function je(e,t){return{type:"element",tagName:"div",properties:{"data-line":e+1,"data-line-index":`${e},${e}`,"data-line-type":"context"},children:[{type:"element",tagName:"span",properties:{"data-char":0},children:[{type:"text",value:t.getLineText(e)}]}]}}function ni(e,t){return e.endsWith(`\r
6
+ `)}function Qt(e,t){const i=e.additionLineIndex,n=e.deletionLineIndex;e.hunkContent=t.hunkContent.map(s=>Zt(s,i,n)),e.additionLineIndex=i+t.additionLineIndex,e.additionStart=e.additionStart+t.additionLineIndex,e.additionCount=t.additionCount,e.additionLines=t.additionLines,t.deletionLineIndex>=0&&(e.deletionLineIndex=n+t.deletionLineIndex,e.deletionStart=e.deletionStart+t.deletionLineIndex),e.deletionCount=t.deletionCount,e.deletionLines=t.deletionLines,e.noEOFCRAdditions=t.noEOFCRAdditions,e.noEOFCRDeletions=t.noEOFCRDeletions,Ze(e)}function Zt(e,t,i){return{...e,additionLineIndex:e.additionLineIndex+t,deletionLineIndex:e.deletionLineIndex+i}}function Ze(e){let t=0,i=0;for(const n of e.hunkContent)n.type==="context"?(t+=n.lines,i+=n.lines):(t+=Math.max(n.additions,n.deletions),i+=n.additions+n.deletions);e.splitLineCount=t,e.unifiedLineCount=i}function Jt(e){let t=0,i=0,n=0;for(const s of e.hunks)s.collapsedBefore=Math.max(s.additionStart-1-n,0),s.splitLineStart=t+s.collapsedBefore,s.unifiedLineStart=i+s.collapsedBefore,Ze(s),t+=s.collapsedBefore+s.splitLineCount,i+=s.collapsedBefore+s.unifiedLineCount,n=s.additionStart+s.additionCount-1;if(e.hunks.length>0){const s=e.hunks[e.hunks.length-1],r=Math.max(e.additionLines.length-(s.additionLineIndex+s.additionCount),0);t+=r,i+=r}e.splitLineCount=t,e.unifiedLineCount=i}let ei=-1;var ti=class{options;onRenderUpdate;workerManager;__id=`diff-hunks-renderer:${++ei}`;highlighter;diff;expandedHunks=new Map;deletionAnnotations={};additionAnnotations={};computedLang="text";renderCache;constructor(e={theme:_},t,i){this.options=e,this.onRenderUpdate=t,this.workerManager=i,i?.isWorkingPool()!==!0&&(this.highlighter=Te(e.theme??_)?Tt():void 0)}cleanUp(){this.recycle(),this.expandedHunks.clear(),this.workerManager=void 0,this.onRenderUpdate=void 0}recycle(){this.highlighter=void 0,this.diff=void 0,this.clearRenderCache(),this.additionAnnotations={},this.deletionAnnotations={},this.workerManager?.cleanUpTasks(this)}getRenderDiff(){return this.renderCache?.diff??this.diff}clearRenderCache(){const e=this.renderCache;this.renderCache=void 0,e!=null&&e.isDirty===!0&&e.diff.cacheKey!=null&&this.workerManager?.evictDiffFromCache(e.diff.cacheKey)}setOptions(e){this.options=e}mergeOptions(e){this.options={...this.options,...e}}expandHunk(e,t,i=this.getOptionsWithDefaults().expansionLineCount){const n={...this.expandedHunks.get(e)??{fromStart:0,fromEnd:0}};(t==="up"||t==="both")&&(n.fromStart+=i),(t==="down"||t==="both")&&(n.fromEnd+=i),this.renderCache?.highlighted!==!0&&this.clearRenderCache(),this.expandedHunks.set(e,n)}getExpandedHunk(e){return this.expandedHunks.get(e)??Mt}getExpandedHunksMap(){return this.expandedHunks}setLineAnnotations(e){this.additionAnnotations={},this.deletionAnnotations={};for(const t of e){const i=(()=>{switch(t.side){case"deletions":return this.deletionAnnotations;case"additions":return this.additionAnnotations}})(),n=i[t.lineNumber]??[];i[t.lineNumber]=n,n.push(t)}}updateRenderCache(e,t,i=!1){if(this.renderCache==null)return;const{result:n,diff:s}=this.renderCache;if(n==null)return;if(s.isPartial)throw new Error("Could not update render cache for partial diff");const r=n.code.additionLines,o=[];for(const[a,l]of e){const u=r[a]?.properties??{},f=l.map(g=>g[2]).join(""),h=a<s.additionLines.length,d=h?s.additionLines[a]??"":"",c=Ie(d);h&&(s.additionLines[a]=ni(d,f),c!==f&&o.push(a)),r[a]={type:"element",tagName:"div",properties:{"data-line":u["data-line"]??a+1,"data-line-index":u["data-line-index"]??a,"data-line-type":u["data-line-type"]??"context"},children:l.map(([g,m,C])=>g===0&&m===""?C===""?{type:"element",tagName:"br",properties:{},children:[]}:{type:"text",value:C}:{type:"element",tagName:"span",properties:{"data-char":g,style:`--diffs-token-${t}:${m};`},children:[{type:"text",value:C}]})}}!i&&o.length>0&&Object.assign(s,jt(s,o,this.options.parseDiffOptions)),n.baseThemeType=t,this.renderCache.isDirty=!0}applyDocumentChange(e){if(this.renderCache==null)return;const{diff:t,result:i}=this.renderCache;if(i==null)return;t.additionLines=$t(e.getText());const n=t.additionLines.length,s=i.code.additionLines,r=s.length;n<r&&(s.length=n);for(let o=r;o<n;o++)s[o]??=je(o,e);t.isPartial||(n===0?(Object.assign(t,_t(t,this.options.parseDiffOptions)),s[0]=je(0,e)):Object.assign(t,G(t,this.options.parseDiffOptions))),this.renderCache.isDirty=!0}getUnifiedLineDecoration({lineType:e}){return{gutterLineType:e,contentProperties:{"data-line-type":e}}}getSplitLineDecoration({side:e,type:t}){const i=t==="change"?e==="deletions"?"change-deletion":"change-addition":t;return{gutterLineType:i,contentProperties:{"data-line-type":i}}}createAnnotationElement=e=>Je(e);getOptionsWithDefaults(){const{diffIndicators:e="bars",diffStyle:t="split",disableBackground:i=!1,disableFileHeader:n=!1,disableLineNumbers:s=!1,disableVirtualizationBuffers:r=!1,collapsed:o=!1,expandUnchanged:a=!1,collapsedContextThreshold:l=1,expansionLineCount:u=100,hunkSeparators:f="line-info",lineDiffType:h="word-alt",maxLineDiffLength:d=1e3,overflow:c="scroll",stickyHeader:g=!1,theme:m=_,headerRenderMode:C="default",tokenizeMaxLineLength:y=1e3,tokenizeMaxLength:v=It,useTokenTransformer:p=!1,useCSSClasses:S=!1}=this.options;return{diffIndicators:e,diffStyle:t,disableBackground:i,disableFileHeader:n,disableLineNumbers:s,disableVirtualizationBuffers:r,collapsed:o,expandUnchanged:a,collapsedContextThreshold:l,expansionLineCount:u,hunkSeparators:f,lineDiffType:h,maxLineDiffLength:d,overflow:c,stickyHeader:g,theme:this.workerManager?.getDiffRenderOptions().theme??m,headerRenderMode:C,tokenizeMaxLineLength:y,tokenizeMaxLength:v,useTokenTransformer:p,useCSSClasses:S}}async initializeHighlighter(){return this.highlighter=await At(et(this.computedLang,this.options)),this.highlighter}hydrate(e){if(e==null)return;this.diff=e;const{options:t}=this.getRenderOptions(e),i=Ee(e,this.getTokenizeMaxLength());let n=this.workerManager?.getDiffResultCache(e);n!=null&&!se(t,n.options)&&(n=void 0),this.renderCache??={diff:e,highlighted:!i&&!be(e),options:t,result:i?void 0:n?.result,renderRange:void 0},this.workerManager?.isWorkingPool()===!0?this.renderCache.result==null&&!i&&this.workerManager.highlightDiffAST(this,this.diff):this.highlighter==null&&(this.computedLang=e.lang??ke(e.name),this.initializeHighlighter())}getRenderOptions(e){const t=(()=>{if(this.workerManager?.isWorkingPool()===!0)return this.workerManager.getDiffRenderOptions();const{theme:n,tokenizeMaxLineLength:s,lineDiffType:r,maxLineDiffLength:o}=this.getOptionsWithDefaults();return{theme:n,useTokenTransformer:tt(this.options),tokenizeMaxLineLength:s,lineDiffType:r,maxLineDiffLength:o}})();this.getOptionsWithDefaults();const{renderCache:i}=this;return i?.result==null?{options:t,forceHighlight:!0}:!re(e,i.diff)||!se(t,i.options)?{options:t,forceHighlight:!0}:{options:t,forceHighlight:!1}}renderDiff(e=this.renderCache?.diff,t=Ve){if(e==null)return;const{expandUnchanged:i=!1,collapsedContextThreshold:n}=this.getOptionsWithDefaults();let{options:s,forceHighlight:r}=this.getRenderOptions(e);const o=this.getMatchingWorkerResultCache(e,s);o!=null&&!this.hasHighlightedRenderCache(e,s)&&(this.renderCache={diff:e,highlighted:!0,renderRange:void 0,...o},r=!1),this.renderCache??={diff:e,highlighted:!1,options:s,result:void 0,renderRange:void 0};const a=e.additionLines.length>0||e.deletionLines.length>0,l=!a||be(e)||Ee(e,this.getTokenizeMaxLength()),u=!re(e,this.renderCache.diff),f=!Xe(this.renderCache.renderRange,t);if(this.workerManager?.isWorkingPool()===!0)(l||this.renderCache.result==null||!this.renderCache.highlighted&&(u||f))&&(this.renderCache.diff=e,this.renderCache.options=s,this.renderCache.highlighted=!1,(this.renderCache.result==null||u||f||r)&&(this.renderCache.result=this.workerManager.getPlainDiffAST(e,t.startingLine,t.totalLines,Wt(t)||i?!0:this.expandedHunks,n)),this.renderCache.renderRange=t),!l&&a&&(!this.renderCache.highlighted||r)&&this.workerManager.highlightDiffAST(this,e);else{this.computedLang=e.lang??ke(e.name);const h=this.highlighter!=null&&Te(s.theme),d=this.highlighter!=null&&Fe(this.computedLang),c=!l&&d;if(this.highlighter!=null&&h&&(r||l||!this.renderCache.highlighted&&c||this.renderCache.result==null)){const{result:g,options:m}=this.renderDiffWithHighlighter(e,this.highlighter,l||!d);this.renderCache={diff:e,options:m,highlighted:c,result:g,renderRange:void 0}}(!h||!l&&!d)&&this.asyncHighlight(e).then(({result:g,options:m})=>{this.renderCache!=null&&(this.renderCache.highlighted=!1),this.onHighlightSuccess(e,g,m,!l)})}return this.renderCache.result!=null?this.processDiffResult(this.renderCache.diff,t,this.renderCache.result):void 0}async asyncRender(e,t=Ve){const{result:i}=await this.asyncHighlight(e);return this.processDiffResult(e,t,i)}createPreElement(e,t,i){const{diffIndicators:n,disableBackground:s,disableLineNumbers:r,overflow:o}=this.getOptionsWithDefaults();return it({type:"diff",diffIndicators:n,disableBackground:s,disableLineNumbers:r,overflow:o,split:e,totalLines:t,customProperties:i})}async asyncHighlight(e){const t=Ee(e,this.getTokenizeMaxLength());this.computedLang=t?"text":e.lang??ke(e.name);const i=this.highlighter!=null&&Te(this.options.theme??_),n=t||this.highlighter!=null&&Fe(this.computedLang);return(this.highlighter==null||!i||!n)&&(this.highlighter=await this.initializeHighlighter()),this.renderDiffWithHighlighter(e,this.highlighter,t)}renderDiffWithHighlighter(e,t,i=!1){const{options:n}=this.getRenderOptions(e),{collapsedContextThreshold:s}=this.getOptionsWithDefaults();return{result:Dt(e,t,n,{forcePlainText:i,expandedHunks:i?!0:void 0,collapsedContextThreshold:s}),options:n}}onHighlightSuccess(e,t,i,n=!0){if(this.renderCache==null)return;const s=!this.renderCache.highlighted||!se(this.renderCache.options,i)||!re(this.renderCache.diff,e);this.renderCache={diff:e,options:i,highlighted:n,result:t,renderRange:void 0},s&&this.onRenderUpdate?.()}getMatchingWorkerResultCache(e,t){const i=this.workerManager?.getDiffResultCache(e);if(!(i==null||!se(t,i.options)))return i}hasHighlightedRenderCache(e,t){const{renderCache:i}=this;return i?.result!=null&&i.highlighted&&re(e,i.diff)&&se(t,i.options)}onHighlightError(e){console.error(e)}getTokenizeMaxLength(){return this.options.tokenizeMaxLength??1e5}processDiffResult(e,t,{code:i,themeStyles:n,baseThemeType:s}){const{diffStyle:r,disableFileHeader:o,expandUnchanged:a,expansionLineCount:l,collapsedContextThreshold:u,hunkSeparators:f}=this.getOptionsWithDefaults(),h=this.renderCache?.isDirty??!1;this.diff=e;const d=r==="unified";let c=[],g=[],m=[];const C=[],{additionLines:y,deletionLines:v}=i,p={rowCount:0,hunkSeparators:f,additionsContentAST:c,deletionsContentAST:g,unifiedContentAST:m,unifiedGutterAST:ce(),deletionsGutterAST:ce(),additionsGutterAST:ce(),expansionLineCount:l,hunkData:C,incrementRowCount(R=1){p.rowCount+=R},pushToGutter(R,D){switch(R){case"unified":p.unifiedGutterAST.children.push(D);break;case"deletions":p.deletionsGutterAST.children.push(D);break;case"additions":p.additionsGutterAST.children.push(D);break}}},S=Et({fileDiff:e,errorPrefix:"DiffHunksRenderer.processDiffResult"}),H={size:0,side:void 0,increment(){this.size+=1},flush(){if(r!=="unified"){if(this.size<=0||this.side==null){this.side=void 0,this.size=0;return}this.side==="additions"?(p.pushToGutter("additions",U(void 0,"buffer",this.size)),c?.push(pe(this.size))):(p.pushToGutter("deletions",U(void 0,"buffer",this.size)),g?.push(pe(this.size))),this.size=0,this.side=void 0}}},T=(R,D,P,V,L)=>{p.pushToGutter(R,kt(D,P,V,L))};function F(R){H.flush(),r==="unified"?De("unified",R,p):(De("deletions",R,p),De("additions",R,p))}this.pushFileLevelAnnotations(e,r,t,p),ve({diff:e,diffStyle:r,startingLine:t.startingLine,totalLines:t.totalLines,expandedHunks:a?!0:this.expandedHunks,collapsedContextThreshold:u,callback:({hunkIndex:R,hunk:D,collapsedBefore:P,collapsedAfter:V,additionLine:L,deletionLine:A,type:x})=>{const I=A!=null?A.splitLineIndex:L.splitLineIndex,W=L!=null?L.unifiedLineIndex:A.unifiedLineIndex;r==="split"&&x!=="change"&&H.flush(),P>0&&F({hunkIndex:R,collapsedLines:P,rangeSize:Math.max(D?.collapsedBefore??0,0),hunkSpecs:D?.hunkSpecs,isFirstHunk:R===0,isLastHunk:!1,isExpandable:!e.isPartial});const J=r==="unified"?W:I,ee={type:x,hunkIndex:R,lineIndex:J,unifiedLineIndex:W,splitLineIndex:I,deletionLine:A,additionLine:L};if(r==="unified"){const k=this.getUnifiedInjectedRowsForLine?.(ee);k?.before!=null&&$e(k.before,p);let E=A!=null?v[A.lineIndex]:void 0,z=L!=null?y[L.lineIndex]:void 0;if(E==null&&z==null){const N="DiffHunksRenderer.processDiffResult: deletionLine and additionLine are null, something is wrong";throw console.error(N,{file:e.name}),new Error(N)}const $=x==="change"?L!=null?"change-addition":"change-deletion":x,O=this.getUnifiedLineDecoration({type:x,lineType:$,additionLineIndex:L?.lineIndex,deletionLineIndex:A?.lineIndex});T("unified",O.gutterLineType,L!=null?L.lineNumber:A.lineNumber,`${W},${I}`,O.gutterProperties),z!=null?z=Ce(z,O.contentProperties,h&&L!=null?{"data-line":L.lineNumber,"data-line-index":`${W},${I}`}:void 0):E!=null&&(E=Ce(E,O.contentProperties,h&&A!=null?{"data-line":A.lineNumber,"data-line-index":`${W},${I}`}:void 0)),me({diffStyle:"unified",type:x,deletionLine:E,additionLine:z,unifiedSpan:this.getAnnotations("unified",A?.lineNumber,L?.lineNumber,R,J),createAnnotationElement:N=>this.createAnnotationElement(N),context:p}),k?.after!=null&&$e(k.after,p)}else{const k=this.getSplitInjectedRowsForLine?.(ee);k?.before!=null&&_e(k.before,p,H);let E=A!=null?v[A.lineIndex]:void 0,z=L!=null?y[L.lineIndex]:void 0;const $=this.getSplitLineDecoration({side:"deletions",type:x,lineIndex:A?.lineIndex}),O=this.getSplitLineDecoration({side:"additions",type:x,lineIndex:L?.lineIndex});if(E==null&&z==null){const M="DiffHunksRenderer.processDiffResult: deletionLine and additionLine are null, something is wrong";throw console.error(M,{file:e.name}),new Error(M)}const N=(()=>{if(x==="change"){if(z==null)return"additions";if(E==null)return"deletions"}})();if(N!=null){if(H.side!=null&&H.side!==N)throw new Error("DiffHunksRenderer.processDiffResult: iterateOverDiff, invalid pending splits");H.side=N,H.increment()}const ne=this.getAnnotations("split",A?.lineNumber,L?.lineNumber,R,J);if(ne!=null&&H.size>0&&H.flush(),A!=null){const M=Ce(E,$.contentProperties,h?{"data-line":A.lineNumber,"data-line-index":`${A.unifiedLineIndex},${I}`}:void 0);T("deletions",$.gutterLineType,A.lineNumber,`${A.unifiedLineIndex},${I}`,$.gutterProperties),M!=null&&(E=M)}if(L!=null){const M=Ce(z,O.contentProperties,h?{"data-line":L.lineNumber,"data-line-index":`${L.unifiedLineIndex},${I}`}:void 0);T("additions",O.gutterLineType,L.lineNumber,`${L.unifiedLineIndex},${I}`,O.gutterProperties),M!=null&&(z=M)}me({diffStyle:"split",type:x,additionLine:z,deletionLine:E,...ne,createAnnotationElement:M=>this.createAnnotationElement(M),context:p}),k?.after!=null&&_e(k.after,p,H)}const fe=r==="split"&&D!=null&&I===D.splitLineStart+D.splitLineCount-1,ye=fe?D.noEOFCRDeletions:!1,He=fe?D.noEOFCRAdditions:!1,te=(A?.noEOFCR??!1)||ye,ie=(L?.noEOFCR??!1)||He;if(ie||te){if(r==="split"&&H.flush(),te){const k=x==="context"||x==="context-expanded"?x:"change-deletion";r==="unified"?(p.unifiedContentAST.push(ge(k)),p.pushToGutter("unified",U(k,"metadata",1))):(p.deletionsContentAST.push(ge(k)),p.pushToGutter("deletions",U(k,"metadata",1)),ie||(p.pushToGutter("additions",U(void 0,"buffer",1)),p.additionsContentAST.push(pe(1))))}if(ie){const k=x==="context"||x==="context-expanded"?x:"change-addition";r==="unified"?(p.unifiedContentAST.push(ge(k)),p.pushToGutter("unified",U(k,"metadata",1))):(p.additionsContentAST.push(ge(k)),p.pushToGutter("additions",U(k,"metadata",1)),te||(p.pushToGutter("deletions",U(void 0,"buffer",1)),p.deletionsContentAST.push(pe(1))))}p.incrementRowCount(1)}V>0&&f!=="simple"&&F({hunkIndex:x==="context-expanded"?R:R+1,collapsedLines:V,rangeSize:S,hunkSpecs:void 0,isFirstHunk:!1,isLastHunk:!0,isExpandable:!e.isPartial}),p.incrementRowCount(1)}}),r==="split"&&H.flush();const de=Math.max(Gt(e.hunks),e.additionLines.length??0,e.deletionLines.length??0),j=t.bufferBefore>0||t.bufferAfter>0,ue=!d&&e.type!=="deleted",q=!d&&e.type!=="new",b=p.rowCount>0||j;c=ue&&b?c:void 0,g=q&&b?g:void 0,m=d&&b?m:void 0;const Z=this.createPreElement(g!=null&&c!=null,de);return{unifiedGutterAST:d&&b?p.unifiedGutterAST.children:void 0,unifiedContentAST:m,deletionsGutterAST:q&&b?p.deletionsGutterAST.children:void 0,deletionsContentAST:g,additionsGutterAST:ue&&b?p.additionsGutterAST.children:void 0,additionsContentAST:c,hunkData:C,preNode:Z,themeStyles:n,baseThemeType:s,headerElement:o?void 0:this.renderHeader(this.diff),totalLines:de,rowCount:p.rowCount,bufferBefore:t.bufferBefore,bufferAfter:t.bufferAfter,css:""}}renderCodeAST(e,t){const i=e==="unified"?t.unifiedGutterAST:e==="deletions"?t.deletionsGutterAST:t.additionsGutterAST,n=e==="unified"?t.unifiedContentAST:e==="deletions"?t.deletionsContentAST:t.additionsContentAST;if(i==null||n==null)return;const s=ce(i);return s.properties.style=`grid-row: span ${t.rowCount}`,[s,nt(n,t.rowCount)]}renderFullAST(e,t=[]){const i=this.getOptionsWithDefaults().hunkSeparators==="line-info",n=this.renderCodeAST("unified",e);if(n!=null)return t.push(w({tagName:"code",children:n,properties:{"data-code":"","data-container-size":i?"":void 0,"data-unified":""}})),{...e.preNode,children:t};const s=this.renderCodeAST("deletions",e);s!=null&&t.push(w({tagName:"code",children:s,properties:{"data-code":"","data-container-size":i?"":void 0,"data-deletions":""}}));const r=this.renderCodeAST("additions",e);return r!=null&&t.push(w({tagName:"code",children:r,properties:{"data-code":"","data-container-size":i?"":void 0,"data-additions":""}})),{...e.preNode,children:t}}renderFullHTML(e,t=[]){return le(this.renderFullAST(e,t))}renderPartialHTML(e,t){return t==null?le(e):le(w({tagName:"code",children:e,properties:{"data-code":"","data-container-size":this.getOptionsWithDefaults().hunkSeparators==="line-info"?"":void 0,[`data-${t}`]:""}}))}pushFileLevelAnnotations(e,t,i,n){if(!Ye(i))return;const s=e.type!=="new"?Ge(Ne(this.deletionAnnotations)):[],r=e.type!=="deleted"?Ge(Ne(this.additionAnnotations)):[];if(s.length===0&&r.length===0)return;const o=-1,a=-1,{createAnnotationElement:l}=this;if(t==="unified"){me({diffStyle:t,type:"context",unifiedSpan:{type:"annotation",hunkIndex:o,lineIndex:a,annotations:s.concat(r)},createAnnotationElement:l,context:n});return}me({diffStyle:t,type:"context",deletionSpan:{type:"annotation",hunkIndex:o,lineIndex:a,annotations:s},additionSpan:{type:"annotation",hunkIndex:o,lineIndex:a,annotations:r},createAnnotationElement:l,context:n})}getAnnotations(e,t,i,n,s){const r={type:"annotation",hunkIndex:n,lineIndex:s,annotations:[]};if(t!=null)for(const a of this.deletionAnnotations[t]??[])r.annotations.push(he(a));const o={type:"annotation",hunkIndex:n,lineIndex:s,annotations:[]};if(i!=null)for(const a of this.additionAnnotations[i]??[])(e==="unified"?r:o).annotations.push(he(a));if(e==="unified")return r.annotations.length>0?r:void 0;if(!(o.annotations.length===0&&r.annotations.length===0))return{deletionSpan:r,additionSpan:o}}renderHeader(e){const{headerRenderMode:t,stickyHeader:i}=this.getOptionsWithDefaults();return st({fileOrDiff:e,mode:t,stickyHeader:i})}};function Ge(e){return e?.map(t=>he(t))??[]}const ii=new Intl.PluralRules("en-US");function We(e){return`${e} unmodified line${ii.select(e)==="one"?"":"s"}`}function $e(e,t){for(const i of e)t.unifiedContentAST.push(i.content),t.pushToGutter("unified",i.gutter),t.incrementRowCount(1)}function _e(e,t,i){for(const{deletion:n,addition:s}of e){if(n==null&&s==null)continue;const r=n!=null&&s!=null?void 0:n==null?"deletions":"additions";(r==null||i.side!==r)&&i.flush(),n!=null&&(t.deletionsContentAST.push(n.content),t.pushToGutter("deletions",n.gutter)),s!=null&&(t.additionsContentAST.push(s.content),t.pushToGutter("additions",s.gutter)),r!=null&&(i.side=r,i.increment()),t.incrementRowCount(1)}}function me({diffStyle:e,type:t,deletionLine:i,additionLine:n,unifiedSpan:s,deletionSpan:r,additionSpan:o,createAnnotationElement:a,context:l}){let u=!1;if(e==="unified"){if(n!=null?l.unifiedContentAST.push(n):i!=null&&l.unifiedContentAST.push(i),s!=null){const f=t==="change"?i!=null?"change-deletion":"change-addition":t;l.unifiedContentAST.push(a(s)),l.pushToGutter("unified",U(f,"annotation",1)),u=!0}}else if(e==="split"){if(i!=null&&l.deletionsContentAST.push(i),n!=null&&l.additionsContentAST.push(n),r!=null){const f=t==="change"?i!=null?"change-deletion":"context":t;l.deletionsContentAST.push(a(r)),l.pushToGutter("deletions",U(f,"annotation",1)),u=!0}if(o!=null){const f=t==="change"?n!=null?"change-addition":"context":t;l.additionsContentAST.push(a(o)),l.pushToGutter("additions",U(f,"annotation",1)),u=!0}}u&&l.incrementRowCount(1)}function De(e,{hunkIndex:t,collapsedLines:i,rangeSize:n,hunkSpecs:s,isFirstHunk:r,isLastHunk:o,isExpandable:a},l){if(i<=0)return;const u=e==="unified"?l.unifiedContentAST:e==="deletions"?l.deletionsContentAST:l.additionsContentAST;if(l.hunkSeparators==="metadata"){s!=null&&(l.pushToGutter(e,K({type:"metadata",content:s,isFirstHunk:r,isLastHunk:o})),u.push(K({type:"metadata",content:s,isFirstHunk:r,isLastHunk:o})),e!=="additions"&&l.incrementRowCount(1));return}if(l.hunkSeparators==="simple"){t>0&&(l.pushToGutter(e,K({type:"simple",isFirstHunk:r,isLastHunk:!1})),u.push(K({type:"simple",isFirstHunk:r,isLastHunk:!1})),e!=="additions"&&l.incrementRowCount(1));return}const f=Vt(e,t),h=n>l.expansionLineCount,d=a?t:void 0;l.pushToGutter(e,K({type:l.hunkSeparators,content:We(i),expandIndex:d,chunked:h,slotName:f,isFirstHunk:r,isLastHunk:o})),u.push(K({type:l.hunkSeparators,content:We(i),expandIndex:d,chunked:h,slotName:f,isFirstHunk:r,isLastHunk:o})),e!=="additions"&&l.incrementRowCount(1),l.hunkData.push({slotName:f,hunkIndex:t,lines:i,type:e,expandable:a?{up:!r,down:!o,chunked:h}:void 0})}function Ce(e,t,i){return e==null||e.type!=="element"||t==null&&i==null?e:{...e,properties:{...e.properties,...t,...i}}}function je(e,t){return{type:"element",tagName:"div",properties:{"data-line":e+1,"data-line-index":`${e},${e}`,"data-line-type":"context"},children:[{type:"element",tagName:"span",properties:{"data-char":0},children:[{type:"text",value:t.getLineText(e)}]}]}}function ni(e,t){return e.endsWith(`\r
7
7
  `)?t+`\r
8
8
  `:e.endsWith("\r")?t+"\r":e.endsWith(`
9
9
  `)?t+`
10
- `:t}function Ee(e,t){return Math.max(e.additionLines.length,e.deletionLines.length)>t}function si(e,t){return e.lineNumber===t.lineNumber&&e.side===t.side&&e.metadata===t.metadata}function ri(e,t){return e.slotName===t.slotName&&e.hunkIndex===t.hunkIndex&&e.lines===t.lines&&e.type===t.type&&e.expandable?.chunked===t.expandable?.chunked&&e.expandable?.up===t.expandable?.up&&e.expandable?.down===t.expandable?.down}function oi(e){return{theme:e?.theme,disableLineNumbers:e?.disableLineNumbers,overflow:e?.overflow,collapsed:e?.collapsed,disableFileHeader:e?.disableFileHeader,disableVirtualizationBuffers:e?.disableVirtualizationBuffers,stickyHeader:e?.stickyHeader,preferredHighlighter:e?.preferredHighlighter,useCSSClasses:e?.useCSSClasses,useTokenTransformer:e?.useTokenTransformer,tokenizeMaxLineLength:e?.tokenizeMaxLineLength,tokenizeMaxLength:e?.tokenizeMaxLength,diffStyle:e?.diffStyle,diffIndicators:e?.diffIndicators,disableBackground:e?.disableBackground,hunkSeparators:typeof e?.hunkSeparators=="function"?"custom":e?.hunkSeparators,expandUnchanged:e?.expandUnchanged,collapsedContextThreshold:e?.collapsedContextThreshold,lineDiffType:e?.lineDiffType,maxLineDiffLength:e?.maxLineDiffLength,expansionLineCount:e?.expansionLineCount,headerRenderMode:e?.renderCustomHeader!=null?"custom":"default"}}let ai=-1;var li=class{options;workerManager;isContainerManaged;static LoadedCustomComponent=!0;__id=`file-diff:${++ai}`;type="file-diff";fileContainer;spriteSVG;pre;codeUnified;codeDeletions;codeAdditions;bufferBefore;bufferAfter;themeCSSStyle;appliedThemeCSS;hasAdoptedThemeCSS=!1;unsafeCSSStyle;appliedUnsafeCSS;gutterUtilityContent;headerElement;headerPrefix;headerFilenameSuffix;headerMetadata;headerCustom;separatorCache=new Map;errorWrapper;placeHolder;hunksRenderer;resizeManager;scrollSyncManager;interactionManager;annotationCache=new Map;lineAnnotations=[];managersDirty=!1;deletionFile;additionFile;fileDiff;renderRange;appliedPreAttributes;lastRenderedHeaderHTML;cachedHeaderHTML;lastRowCount;mounted=!1;enabled=!0;editor;fastRefreshTimeout;constructor(e={theme:_},t,i=!1){this.options=e,this.workerManager=t,this.isContainerManaged=i,this.hunksRenderer=this.createHunksRenderer(e),this.resizeManager=new rt,this.scrollSyncManager=new Bt,this.interactionManager=new ot("diff",Ue(e,typeof e.hunkSeparators=="function"||(e.hunkSeparators??"line-info")==="line-info"||e.hunkSeparators==="line-info-basic"?this.handleExpandHunk:void 0,this.getLineIndex)),this.workerManager?.subscribeToThemeChanges(this),this.enabled=!0}handleHighlightRender=()=>{this.rerender()};getHunksRendererOptions(e){return oi(e)}createHunksRenderer(e){return new ti(this.getHunksRendererOptions(e),this.handleHighlightRender,this.workerManager)}getLineIndex=(e,t="additions")=>{const i=this.hunksRenderer.getRenderDiff()??this.fileDiff;if(i==null)return;const n=i.hunks.at(-1);let s,r;e:for(const o of i.hunks){let a=t==="deletions"?o.deletionStart:o.additionStart;const l=t==="deletions"?o.deletionCount:o.additionCount;let u=o.splitLineStart,f=o.unifiedLineStart;if(e<a){const h=a-e;s=Math.max(f-h,0),r=Math.max(u-h,0);break e}if(e>=a+l){if(o===n){const h=e-(a+l);s=f+o.unifiedLineCount+h,r=u+o.splitLineCount+h;break e}continue}for(const h of o.hunkContent)if(h.type==="context")if(e<a+h.lines){const d=e-a;r=u+d,s=f+d;break e}else a+=h.lines,u+=h.lines,f+=h.lines;else{const d=t==="deletions"?h.deletions:h.additions;if(e<a+d){const c=e-a;s=f+(t==="additions"?h.deletions:0)+c,r=u+c;break e}else a+=d,u+=Math.max(h.deletions,h.additions),f+=h.deletions+h.additions}break e}if(!(s==null||r==null))return[s,r]};setOptions(e){e!=null&&(this.options=e,this.cachedHeaderHTML=void 0,this.hunksRenderer.setOptions(this.getHunksRendererOptions(e)),this.syncInteractionOptions())}syncInteractionOptions(){this.interactionManager.setOptions(Ue(this.options,typeof this.options.hunkSeparators=="function"||(this.options.hunkSeparators??"line-info")==="line-info"||this.options.hunkSeparators==="line-info-basic"?this.handleExpandHunk:void 0,this.getLineIndex))}mergeOptions(e){this.options={...this.options,...e}}setThemeType(e){(this.options.themeType??"system")!==e&&(this.mergeOptions({themeType:e}),this.applyCachedThemeState(e))}applyCachedThemeState(e){if(typeof this.options.theme=="string"||this.fileContainer==null||this.appliedThemeCSS==null)return!1;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&&!Rt(this.appliedThemeCSS.theme,this.options.theme??_)}getHoveredLine=()=>this.interactionManager.getHoveredLine();setLineAnnotations(e){this.lineAnnotations=e}canPartiallyRender(e,t,i){return!(e||t||i||typeof this.options.hunkSeparators=="function")}setSelectedLines(e,t){this.interactionManager.setSelection(e,t)}flushManagers(){if(!this.managersDirty||this.pre==null){this.managersDirty=!1;return}const{diffStyle:e="split",overflow:t="scroll"}=this.options;this.interactionManager.setup(this.pre),this.resizeManager.setup(this.pre,t==="wrap"),t==="scroll"&&e==="split"?this.scrollSyncManager.setup(this.pre,this.codeDeletions,this.codeAdditions):this.scrollSyncManager.cleanUp(),this.managersDirty=!1}cleanUp(e=!1){this.emitPostRender(!0),this.resizeManager.cleanUp(),this.interactionManager.cleanUp(),this.scrollSyncManager.cleanUp(),this.managersDirty=!1,this.workerManager?.unsubscribeToThemeChanges(this),this.renderRange=void 0,this.isContainerManaged||this.fileContainer?.remove(),this.fileContainer=void 0,this.mounted=!1,e||(this.lineAnnotations=[]),this.clearAuxiliaryNodes(),this.annotationCache.clear(),this.pre=void 0,this.codeUnified=void 0,this.codeDeletions=void 0,this.codeAdditions=void 0,this.bufferBefore?.remove(),this.bufferBefore=void 0,this.bufferAfter?.remove(),this.bufferAfter=void 0,this.appliedPreAttributes=void 0,this.headerElement=void 0,this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0,this.headerCustom=void 0,this.placeHolder=void 0,this.lastRenderedHeaderHTML=void 0,e||(this.cachedHeaderHTML=void 0),this.errorWrapper=void 0,this.spriteSVG=void 0,this.lastRowCount=void 0,this.themeCSSStyle=void 0,this.appliedThemeCSS=void 0,this.hasAdoptedThemeCSS=!1,this.unsafeCSSStyle=void 0,this.appliedUnsafeCSS=void 0,e?this.hunksRenderer.recycle():(this.hunksRenderer.cleanUp(),this.workerManager=void 0,this.fileDiff=void 0,this.deletionFile=void 0,this.additionFile=void 0),this.enabled=!1,this.editor?.cleanUp(),this.editor=void 0,this.fastRefreshTimeout!=null&&(clearTimeout(this.fastRefreshTimeout),this.fastRefreshTimeout=void 0)}virtualizedSetup(){this.enabled=!0,this.workerManager?.subscribeToThemeChanges(this)}hydrate(e){const{fileContainer:t,prerenderedHTML:i,preventEmit:n=!1,lineAnnotations:s,oldFile:r,newFile:o,fileDiff:a}=e;this.hydrateElements(t,i),ui(this.pre,hi({fileDiff:a,oldFile:r,newFile:o}),this.options.collapsed)||fi(this.headerElement,di({fileDiff:a,oldFile:r,newFile:o}),this.options.disableFileHeader)?this.render({...e,preventEmit:!0}):this.hydrationSetup({fileDiff:a,oldFile:r,newFile:o,lineAnnotations:s}),n||this.emitPostRender()}hydrateElements(e,t){this.fileContainer!==e&&this.emitPostRender(!0),at(e,t);for(const i of e.shadowRoot?.children??[]){if(i instanceof SVGElement){this.spriteSVG=i;continue}if(i instanceof HTMLElement){if(i instanceof HTMLPreElement){this.pre=i;for(const n of i.children)!(n instanceof HTMLElement)||n.tagName.toLowerCase()!=="code"||("deletions"in n.dataset&&(this.codeDeletions=n),"additions"in n.dataset&&(this.codeAdditions=n),"unified"in n.dataset&&(this.codeUnified=n));continue}if("diffsHeader"in i.dataset){this.headerElement=i;continue}if(i instanceof HTMLStyleElement&&i.hasAttribute("data-theme-css")){this.themeCSSStyle=i;continue}if(i instanceof HTMLStyleElement&&i.hasAttribute("data-unsafe-css")){this.unsafeCSSStyle=i,this.appliedUnsafeCSS=i.textContent;continue}}}this.pre!=null&&(this.syncCodeNodesFromPre(this.pre),this.pre.removeAttribute("data-dehydrated")),this.fileContainer=e,this.hydrateMeasuredScrollbar()}hydrationSetup({fileDiff:e,oldFile:t,newFile:i,lineAnnotations:n}){this.lineAnnotations=n??this.lineAnnotations,this.additionFile=i,this.deletionFile=t,this.fileDiff=e??(t!=null&&i!=null?Z(t,i,this.options.parseDiffOptions):void 0),this.pre!=null&&(this.syncInteractionOptions(),this.hunksRenderer.hydrate(this.fileDiff),this.renderAnnotations(),this.renderGutterUtility(),this.injectUnsafeCSS(),this.managersDirty=!0,this.flushManagers())}rerender(){!this.enabled||this.fileDiff==null&&this.additionFile==null&&this.deletionFile==null||this.render({forceRender:!0,renderRange:this.renderRange})}onThemeChange(){this.hunksRenderer.clearRenderCache(),this.rerender()}handleExpandHunk=(e,t,i)=>{this.expandHunk(e,t,i)};expandHunk=(e,t,i)=>{this.hunksRenderer.expandHunk(e,t,i),this.rerender()};render({oldFile:e,newFile:t,fileDiff:i,deferManagers:n=!1,forceRender:s=!1,preventEmit:r=!1,lineAnnotations:o,fileContainer:a,containerWrapper:l,renderRange:u}){if(!this.enabled)throw new Error("FileDiff.render: attempting to call render after cleaned up");this.editor?.__postponeBackgroundTokenizeToNextFrame();const{collapsed:f=!1,themeType:h="system"}=this.options,d=f?void 0:u,c=this.hasThemeChanged(),g=e!=null&&t!=null&&(!Be(e,this.deletionFile)||!Be(t,this.additionFile));let m=i!=null&&i!==this.fileDiff;const C=o!=null&&(o.length>0||this.lineAnnotations.length>0)?o!==this.lineAnnotations:!1;if(!f&&Xe(d,this.renderRange)&&!s&&!C&&!c&&(i!=null&&i===this.fileDiff||i==null&&!g))return this.applyCachedThemeState(h);const{renderRange:y}=this;if(this.renderRange=d,this.deletionFile=e,this.additionFile=t,i!=null?this.fileDiff=i:e!=null&&t!=null&&g&&(m=!0,this.fileDiff=Z(e,t,this.options.parseDiffOptions)),m&&(this.cachedHeaderHTML=void 0),o!=null&&this.setLineAnnotations(o),this.fileDiff==null)return!1;this.hunksRenderer.setOptions(this.getHunksRendererOptions(this.options)),this.syncInteractionOptions(),this.hunksRenderer.setLineAnnotations(this.lineAnnotations);const{disableErrorHandling:v=!1,disableFileHeader:p=!1}=this.options;if(p&&(this.headerElement!=null&&(this.headerElement.remove(),this.headerElement=void 0,this.lastRenderedHeaderHTML=void 0),this.clearHeaderSlots()),a=this.getOrCreateFileContainer(a,l),this.applyCachedThemeState(h),f){this.removeRenderedCode(),this.clearAuxiliaryNodes();try{const S=this.hunksRenderer.renderDiff(this.fileDiff,zt);S!=null&&this.applyThemeState(a,S.themeStyles,h,S.baseThemeType),S?.headerElement!=null&&this.applyHeaderToDOM(S.headerElement,a),this.renderSeparators([]),this.injectUnsafeCSS()}catch(S){if(v)throw S;console.error(S),S instanceof Error&&this.applyErrorToDOM(S,a)}return r||this.emitPostRender(),!0}try{const S=this.getOrCreatePreNode(a);if(!(this.canPartiallyRender(s,C,g||m||c)&&this.applyPartialRender({previousRenderRange:y,renderRange:d}))){const H=this.hunksRenderer.renderDiff(this.fileDiff,d);if(H==null)return this.workerManager?.isInitialized()===!1&&this.workerManager.initialize().then(()=>this.rerender()),!1;this.applyThemeState(a,H.themeStyles,h,H.baseThemeType),H.headerElement!=null&&this.applyHeaderToDOM(H.headerElement,a),H.additionsContentAST!=null||H.deletionsContentAST!=null||H.unifiedContentAST!=null?this.applyHunksToDOM(S,H):this.pre!=null&&(this.pre.remove(),this.pre=void 0),this.renderSeparators(H.hunkData)}this.applyBuffers(S,d),this.injectUnsafeCSS(),this.renderAnnotations(),this.renderGutterUtility(),this.managersDirty=!0,n||this.flushManagers(),this.editor!=null&&this.syncRenderViewToEditor()}catch(S){if(v)throw S;console.error(S),S instanceof Error&&this.applyErrorToDOM(S,a)}return r||this.emitPostRender(),!0}emitPostRender(e=!1){const{fileContainer:t,options:{onPostRender:i}}=this;if(e){if(!this.mounted||(this.mounted=!1,t==null))return;this.options.onPostRender?.(t,this,"unmount");return}if(t==null)return;const n=this.mounted?"update":"mount";this.mounted=!0,i?.(t,this,n)}syncRenderViewToEditor(){const e=this.editor,t=this.fileContainer,i=this.fileDiff;e!=null&&t!=null&&i!=null&&!i.isPartial&&this.hunksRenderer.initializeHighlighter().then(n=>{e.__syncRenderView(n,t,i,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.hunksRenderer.applyDocumentChange(e);const i=this.hunksRenderer.getRenderDiff();i!=null&&(this.fileDiff=i),this.rerender(),this.interactionManager.setSelectionDirty(),t!==void 0&&t!==this.lineAnnotations&&(this.setLineAnnotations(t),this.hunksRenderer.setLineAnnotations(this.lineAnnotations),this.renderAnnotations())}rerenderFromDocument(e){this.hunksRenderer.applyDocumentChange(e);const t=this.hunksRenderer.getRenderDiff();t!=null&&(this.fileDiff=t),this.hunksRenderer.clearRenderCache(),this.rerender()}updateRenderCache(e,t,i,n){this.hunksRenderer.updateRenderCache(e,t,n),i===!0&&(this.options.diffStyle==="split"?(this.fastRefreshTimeout!=null&&clearTimeout(this.fastRefreshTimeout),this.fastRefreshTimeout=setTimeout(()=>{this.fastRefreshTimeout=void 0,this.fastRefreshDiffView()},100)):this.refreshDiffView())}removeRenderedCode(){this.resizeManager.cleanUp(),this.scrollSyncManager.cleanUp(),this.interactionManager.cleanUp(),this.bufferBefore?.remove(),this.bufferBefore=void 0,this.bufferAfter?.remove(),this.bufferAfter=void 0,this.codeUnified?.remove(),this.codeUnified=void 0,this.codeDeletions?.remove(),this.codeDeletions=void 0,this.codeAdditions?.remove(),this.codeAdditions=void 0,this.pre?.remove(),this.pre=void 0,this.appliedPreAttributes=void 0,this.lastRowCount=void 0}clearAuxiliaryNodes(){for(const{element:e}of this.separatorCache.values())e.remove();this.separatorCache.clear();for(const{element:e}of this.annotationCache.values())e.remove();this.annotationCache.clear(),this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0}renderPlaceholder(e){if(this.fileContainer==null)return!1;if(this.emitPostRender(!0),this.cleanChildNodes(),this.placeHolder==null){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{fileDiff:e,workerManager:t}=this;if(e==null||t==null||be(e))return;const i=this.options.tokenizeMaxLength??1e5;Math.max(e.additionLines.length,e.deletionLines.length)>i||t.primeDiffHighlightCache(e)}cleanChildNodes(){this.resizeManager.cleanUp(),this.scrollSyncManager.cleanUp(),this.interactionManager.cleanUp(),this.clearAuxiliaryNodes(),this.bufferAfter?.remove(),this.bufferBefore?.remove(),this.codeAdditions?.remove(),this.codeDeletions?.remove(),this.codeUnified?.remove(),this.errorWrapper?.remove(),this.headerElement?.remove(),this.headerPrefix?.remove(),this.headerFilenameSuffix?.remove(),this.headerMetadata?.remove(),this.headerCustom?.remove(),this.pre?.remove(),this.spriteSVG?.remove(),this.themeCSSStyle?.remove(),this.unsafeCSSStyle?.remove(),this.bufferAfter=void 0,this.bufferBefore=void 0,this.codeAdditions=void 0,this.codeDeletions=void 0,this.codeUnified=void 0,this.errorWrapper=void 0,this.headerElement=void 0,this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0,this.headerCustom=void 0,this.pre=void 0,this.spriteSVG=void 0,this.themeCSSStyle=void 0,this.appliedThemeCSS=void 0,this.hasAdoptedThemeCSS=!1,this.unsafeCSSStyle=void 0,this.appliedUnsafeCSS=void 0,this.lastRenderedHeaderHTML=void 0,this.lastRowCount=void 0,this.mounted=!1}renderSeparators(e){const{hunkSeparators:t}=this.options;if(this.isContainerManaged||this.fileContainer==null||typeof t!="function"){for(const{element:n}of this.separatorCache.values())n.remove();this.separatorCache.clear();return}const i=new Map(this.separatorCache);for(const n of e){const s=n.slotName;let r=this.separatorCache.get(s);if(r==null||!ri(n,r.hunkData)){r?.element.remove();const o=document.createElement("div");o.style.display="contents",o.slot=n.slotName;const a=t(n,this);a!=null&&o.appendChild(a),this.fileContainer.appendChild(o),r={element:o,hunkData:n},this.separatorCache.set(s,r)}i.delete(s)}for(const[n,{element:s}]of i.entries())this.separatorCache.delete(n),s.remove()}renderAnnotations(){if(this.isContainerManaged||this.fileContainer==null){for(const{element:i}of this.annotationCache.values())i.remove();this.annotationCache.clear();return}const e=new Map(this.annotationCache),{renderAnnotation:t}=this.options;if(t!=null&&this.lineAnnotations.length>0)for(const[i,n]of this.lineAnnotations.entries()){const s=`${i}-${he(n)}`;let r=this.annotationCache.get(s);if(r==null||!si(n,r.annotation)){r?.element.remove();const o=t(n);if(o==null)continue;r={element:lt(he(n)),annotation:n},r.element.appendChild(o),this.fileContainer.appendChild(r.element),this.annotationCache.set(s,r)}e.delete(s)}for(const[i,{element:n}]of e.entries())this.annotationCache.delete(i),n.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 i=ht();i.appendChild(t),this.fileContainer.appendChild(i),this.gutterUtilityContent=i}getOrCreateFileContainer(e,t){const{fileContainer:i}=this,n=e??i??document.createElement("diffs-container"),s=i!==n;return s&&this.emitPostRender(!0),this.fileContainer=n,i!=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 i of t.children)i instanceof SVGElement?this.spriteSVG??=i:Pe(i)&&i.hasAttribute("data-theme-css")?(this.themeCSSStyle??=i,this.hasAdoptedThemeCSS=!0):Pe(i)&&i.hasAttribute("data-unsafe-css")&&(this.unsafeCSSStyle??=i,this.appliedUnsafeCSS??=this.options.unsafeCSS??void 0)}ensureSpriteSVG(e){const t=e.shadowRoot??e.attachShadow({mode:"open"});if(this.spriteSVG==null){const i=document.createElement("div");i.innerHTML=dt;const n=i.firstChild;n instanceof SVGElement&&(this.spriteSVG=n)}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.codeUnified=void 0,this.codeDeletions=void 0,this.codeAdditions=void 0,t.appendChild(this.pre)):this.pre.parentNode!==t&&(t.appendChild(this.pre),this.appliedPreAttributes=void 0),this.placeHolder?.remove(),this.placeHolder=void 0,this.pre}syncCodeNodesFromPre(e){this.codeUnified=void 0,this.codeDeletions=void 0,this.codeAdditions=void 0;for(const t of Array.from(e.children))t instanceof HTMLElement&&(t.hasAttribute("data-unified")?this.codeUnified=t:t.hasAttribute("data-deletions")?this.codeDeletions=t:t.hasAttribute("data-additions")&&(this.codeAdditions=t))}applyHeaderToDOM(e,t){this.cleanupErrorWrapper(),this.placeHolder?.remove(),this.placeHolder=void 0;const{fileDiff:i}=this,n=this.cachedHeaderHTML??le(e);if(this.cachedHeaderHTML=n,n!==this.lastRenderedHeaderHTML){const h=document.createElement("div");h.innerHTML=n;const d=h.firstElementChild;if(!(d instanceof HTMLElement))return;this.headerElement!=null?t.shadowRoot?.replaceChild(d,this.headerElement):t.shadowRoot?.prepend(d),this.headerElement=d,this.lastRenderedHeaderHTML=n}if(this.isContainerManaged||i==null)return;const{renderCustomHeader:s,renderHeaderPrefix:r,renderHeaderFilenameSuffix:o,renderHeaderMetadata:a}=this.options;if(s!=null){const h=s(i)??void 0;this.headerCustom=this.upsertHeaderSlotElement(t,this.headerCustom,Ft,h),this.headerPrefix?.remove(),this.headerFilenameSuffix?.remove(),this.headerMetadata?.remove(),this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0;return}const l=r?.(i)??void 0,u=o?.(i)??void 0,f=a?.(i)??void 0;this.headerPrefix=this.upsertHeaderSlotElement(t,this.headerPrefix,Nt,l),this.headerFilenameSuffix=this.upsertHeaderSlotElement(t,this.headerFilenameSuffix,Ut,u),this.headerMetadata=this.upsertHeaderSlotElement(t,this.headerMetadata,Pt,f),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,i,n){if(n==null){t?.remove();return}const s=t??this.createHeaderSlotElement(i);return t==null&&e.appendChild(s),this.replaceHeaderSlotContent(s,n),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}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??=ut(),this.unsafeCSSStyle.parentNode!==t&&t.appendChild(this.unsafeCSSStyle),this.unsafeCSSStyle.textContent=ft(e),this.appliedUnsafeCSS=e)}}applyThemeState(e,t,i,n){const s=e.shadowRoot??e.attachShadow({mode:"open"}),r=n??i,o=this.options.theme??_,a=typeof o=="string"?o:{...o},l=Oe(s);if(this.themeCSSStyle?.parentNode===s&&this.appliedThemeCSS?.themeStyles===t&&this.appliedThemeCSS.themeType===r&&this.appliedThemeCSS.scrollbarGutter===l){this.appliedThemeCSS.theme=a;return}if(this.hasAdoptedThemeCSS&&this.themeCSSStyle?.parentNode===s){this.hasAdoptedThemeCSS=!1,this.appliedThemeCSS={theme:a,themeStyles:t,themeType:r,baseThemeType:n,scrollbarGutter:l};return}this.themeCSSStyle=ct({shadowRoot:s,currentNode:this.themeCSSStyle,themeCSS:Ct(t,r,l)}),this.appliedThemeCSS=this.themeCSSStyle!=null?{theme:a,themeStyles:t,themeType:r,baseThemeType:n,scrollbarGutter:l}:void 0}hydrateMeasuredScrollbar(){const e=this.fileContainer?.shadowRoot;e==null||this.themeCSSStyle==null||(this.themeCSSStyle.textContent=pt(this.themeCSSStyle.textContent??"",Oe(e)))}applyHunksToDOM(e,t){const{overflow:i="scroll"}=this.options,n=(this.options.hunkSeparators??"line-info")==="line-info",s=i==="wrap"?t.rowCount:void 0;this.cleanupErrorWrapper(),this.applyPreNodeAttributes(e,t);let r=!1;const o=[],a=this.hunksRenderer.renderCodeAST("unified",t),l=this.hunksRenderer.renderCodeAST("deletions",t),u=this.hunksRenderer.renderCodeAST("additions",t);a!=null?(r=this.codeUnified==null||this.codeAdditions!=null||this.codeDeletions!=null,this.codeDeletions?.remove(),this.codeDeletions=void 0,this.codeAdditions?.remove(),this.codeAdditions=void 0,this.codeUnified=Ae({code:this.codeUnified,columnType:"unified",rowSpan:s,containerSize:n}),this.codeUnified.innerHTML=this.hunksRenderer.renderPartialHTML(a),o.push(this.codeUnified)):l!=null||u!=null?(l!=null?(r=this.codeDeletions==null||this.codeUnified!=null,this.codeUnified?.remove(),this.codeUnified=void 0,this.codeDeletions=Ae({code:this.codeDeletions,columnType:"deletions",rowSpan:s,containerSize:n}),this.codeDeletions.innerHTML=this.hunksRenderer.renderPartialHTML(l),o.push(this.codeDeletions)):(this.codeDeletions?.remove(),this.codeDeletions=void 0),u!=null?(r=r||this.codeAdditions==null||this.codeUnified!=null,this.codeUnified?.remove(),this.codeUnified=void 0,this.codeAdditions=Ae({code:this.codeAdditions,columnType:"additions",rowSpan:s,containerSize:n}),this.codeAdditions.innerHTML=this.hunksRenderer.renderPartialHTML(u),o.push(this.codeAdditions)):(this.codeAdditions?.remove(),this.codeAdditions=void 0)):(this.codeUnified?.remove(),this.codeUnified=void 0,this.codeDeletions?.remove(),this.codeDeletions=void 0,this.codeAdditions?.remove(),this.codeAdditions=void 0),o.length===0?e.textContent="":r&&e.replaceChildren(...o),this.lastRowCount=t.rowCount}applyPartialRender({previousRenderRange:e,renderRange:t}){const{pre:i,codeUnified:n,codeAdditions:s,codeDeletions:r,options:{diffStyle:o="split"}}=this;if(i==null||e==null||t==null||!Number.isFinite(e.totalLines)||!Number.isFinite(t.totalLines)||this.lastRowCount==null)return!1;const a=this.getCodeColumns(o,n,r,s);if(a==null)return!1;const l=e.startingLine,u=t.startingLine,f=l+e.totalLines,h=u+t.totalLines,d=Math.max(l,u),c=Math.min(f,h);if(c<=d)return!1;const g=Math.max(0,d-l),m=Math.max(0,f-c),C=this.trimColumns({columns:a,trimStart:g,trimEnd:m,previousStart:l,overlapStart:d,overlapEnd:c,diffStyle:o});if(C<0)throw new Error("applyPartialRender: failed to trim to overlap");if(this.lastRowCount<C)throw new Error("applyPartialRender: trimmed beyond DOM row count");let y=this.lastRowCount-C;const v=(T,F)=>{if(!(F<=0||this.fileDiff==null))return this.hunksRenderer.renderDiff(this.fileDiff,{startingLine:T,totalLines:F,bufferBefore:0,bufferAfter:0})},p=v(u,Math.max(d-u,0));if(p==null&&u<d)return!1;const S=v(c,Math.max(h-c,0));if(S==null&&h>c)return!1;const H=(T,F)=>{if(T!=null){if(o==="unified"&&!Array.isArray(a))this.insertPartialHTML(o,a,T,F);else if(o==="split"&&Array.isArray(a))this.insertPartialHTML(o,a,T,F);else throw new Error("FileDiff.applyPartialRender.applyChunk: invalid chunk application");y+=T.rowCount}};return this.cleanupErrorWrapper(),H(p,"afterbegin"),H(S,"beforeend"),this.lastRowCount!==y&&(this.applyRowSpan(o,a,y),this.lastRowCount=y),!0}insertPartialHTML(e,t,i,n){if(e==="unified"&&!Array.isArray(t)){const s=this.hunksRenderer.renderCodeAST("unified",i);this.renderPartialColumn(t,s,n)}else if(e==="split"&&Array.isArray(t)){const s=this.hunksRenderer.renderCodeAST("deletions",i),r=this.hunksRenderer.renderCodeAST("additions",i);this.renderPartialColumn(t[0],s,n),this.renderPartialColumn(t[1],r,n)}else throw new Error("FileDiff.insertPartialHTML: Invalid argument composition")}fastRefreshDiffView(){if(this.options.diffStyle!=="split")return;const e=this.hunksRenderer.renderDiff(this.fileDiff,this.renderRange);if(e==null)return;const t=this.getCodeColumns("split",this.codeUnified,this.codeDeletions,this.codeAdditions);if(!Array.isArray(t))return;const i=(n,s)=>{if(s==null)return;const r=this.hunksRenderer.renderCodeAST(n,e),o=X(r?.[0]),a=X(r?.[1]);for(const[l,u]of[[s.gutter,o],[s.content,a]])if(u!=null&&l.childElementCount===u.length)for(let f=0;f<u.length;f++){const h=l.children[f],d=u[f].properties["data-line-type"];d!=null&&h.dataset.lineType!==d&&(h.dataset.lineType=d)}};i("deletions",t[0]),i("additions",t[1])}refreshDiffView(){const e=this.hunksRenderer.renderDiff(this.fileDiff,this.renderRange);if(e==null)return;const t=this.getCodeColumns(this.options.diffStyle??"split",this.codeUnified,this.codeDeletions,this.codeAdditions);if(t==null)return;const i=(n,s)=>{if(s==null)return;const r=this.hunksRenderer.renderCodeAST(n,e),o=X(r?.[0]),a=X(r?.[1]);for(const[l,u]of[[s.gutter,o],[s.content,a]])u!=null&&(l.innerHTML=le(u))};Array.isArray(t)?(i("deletions",t[0]),i("additions",t[1])):i("unified",t),this.syncRenderViewToEditor()}renderPartialColumn(e,t,i){if(e==null||t==null)return;const n=X(t[0]),s=X(t[1]);if(n==null||s==null)throw new Error("FileDiff.insertPartialHTML: Unexpected AST structure");const r=s.at(0);i==="beforeend"&&r?.type==="element"&&typeof r.properties["data-buffer-size"]=="number"&&this.mergeBuffersIfNecessary(r.properties["data-buffer-size"],e.content.children[e.content.children.length-1],e.gutter.children[e.gutter.children.length-1],n,s,!0);const o=s.at(-1);i==="afterbegin"&&o?.type==="element"&&typeof o.properties["data-buffer-size"]=="number"&&this.mergeBuffersIfNecessary(o.properties["data-buffer-size"],e.content.children[0],e.gutter.children[0],n,s,!1),e.gutter.insertAdjacentHTML(i,this.hunksRenderer.renderPartialHTML(n)),e.content.insertAdjacentHTML(i,this.hunksRenderer.renderPartialHTML(s))}mergeBuffersIfNecessary(e,t,i,n,s,r){if(!(t instanceof HTMLElement)||!(i instanceof HTMLElement))return;const o=this.getBufferSize(t.dataset);o!=null&&(r?(n.shift(),s.shift()):(n.pop(),s.pop()),this.updateBufferSize(t,o+e),this.updateBufferSize(i,o+e))}applyRowSpan(e,t,i){const n=s=>{s!=null&&(s.gutter.style.setProperty("grid-row",`span ${i}`),s.content.style.setProperty("grid-row",`span ${i}`))};if(e==="unified"&&!Array.isArray(t))n(t);else if(e==="split"&&Array.isArray(t))n(t[0]),n(t[1]);else throw new Error("dun fuuuuked up")}trimColumnRows(e,t,i){let n=0,s=0,r=0,o=!1;const a=i>=0;if(e==null)return 0;const l=Array.from(e.content.children),u=Array.from(e.gutter.children);if(l.length!==u.length)throw new Error("FileDiff.trimColumnRows: columns do not match");for(;r<l.length&&!(t<=0&&!a&&!o);){const f=u[r],h=l[r];if(r++,!(f instanceof HTMLElement)||!(h instanceof HTMLElement))throw console.error({gutterElement:f,contentElement:h}),new Error("FileDiff.trimColumnRows: invalid row elements");if(o&&(o=!1,f.dataset.gutterBuffer==="annotation"&&"lineAnnotation"in h.dataset||f.dataset.gutterBuffer==="metadata"&&"noNewline"in h.dataset)){f.remove(),h.remove(),s++;continue}if("lineIndex"in f.dataset&&"lineIndex"in h.dataset){(t>0||a&&n>=i)&&(f.remove(),h.remove(),t>0&&(t--,t===0&&(o=!0)),s++),n++;continue}if("separator"in f.dataset&&"separator"in h.dataset){(t>0||a&&n>=i)&&(f.remove(),h.remove(),s++);continue}if(f.dataset.gutterBuffer==="annotation"&&"lineAnnotation"in h.dataset){(t>0||a&&n>=i)&&(f.remove(),h.remove(),s++);continue}if(f.dataset.gutterBuffer==="metadata"&&"noNewline"in h.dataset){(t>0||a&&n>=i)&&(f.remove(),h.remove(),s++);continue}if(f.dataset.gutterBuffer==="buffer"&&"contentBuffer"in h.dataset){const d=this.getBufferSize(h.dataset);if(d==null)throw new Error("FileDiff.trimColumnRows: invalid element");if(t>0){const c=Math.min(t,d),g=d-c;g>0?(this.updateBufferSize(f,g),this.updateBufferSize(h,g),s+=c):(f.remove(),h.remove(),s+=d),t-=c,t===0&&g===0&&(o=!0)}else if(a){const c=n,g=n+d-1;if(i<=c)f.remove(),h.remove(),s+=d;else if(i<=g){const m=g-i+1,C=d-m;this.updateBufferSize(f,C),this.updateBufferSize(h,C),s+=m}}n+=d;continue}throw console.error({gutterElement:f,contentElement:h}),new Error("FileDiff.trimColumnRows: unknown row elements")}return s}trimColumns({columns:e,diffStyle:t,overlapEnd:i,overlapStart:n,previousStart:s,trimEnd:r,trimStart:o}){const a=Math.max(0,n-s),l=i-s;if(l<0)throw new Error("FileDiff.trimColumns: overlap ends before previous");const u=o>0,f=r>0;if(!u&&!f)return 0;const h=u?a:0,d=f?l:-1;if(t==="unified"&&!Array.isArray(e))return this.trimColumnRows(e,h,d);if(t==="split"&&Array.isArray(e)){const c=this.trimColumnRows(e[0],h,d),g=this.trimColumnRows(e[1],h,d);if(e[0]!=null&&e[1]!=null&&c!==g)throw new Error("FileDiff.trimColumns: split columns out of sync");return e[0]!=null?c:g}else throw console.error({diffStyle:t,columns:e}),new Error("FileDiff.trimColumns: Invalid columns for diffType")}getBufferSize(e){const t=Number.parseInt(e?.bufferSize??"",10);return Number.isNaN(t)?void 0:t}updateBufferSize(e,t){e.dataset.bufferSize=`${t}`,e.style.setProperty("grid-row",`span ${t}`),e.style.setProperty("min-height",`calc(${t} * 1lh)`)}getCodeColumns(e,t,i,n){function s(r){if(r==null)return;const o=r.children[0],a=r.children[1];if(!(!(o instanceof HTMLElement)||!(a instanceof HTMLElement)||o.dataset.gutter==null||a.dataset.content==null))return{gutter:o,content:a}}if(e==="unified")return s(t);{const r=s(i),o=s(n);return r!=null||o!=null?[r,o]:void 0}}updateBuffers(e){this.pre!=null&&this.applyBuffers(this.pre,e)}applyBuffers(e,t){if(t==null||this.shouldDisableVirtualizationBuffers()){this.bufferBefore!=null&&(this.bufferBefore.remove(),this.bufferBefore=void 0),this.bufferAfter!=null&&(this.bufferAfter.remove(),this.bufferAfter=void 0);return}t.bufferBefore>0?(this.bufferBefore==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}applyPreNodeAttributes(e,{additionsContentAST:t,deletionsContentAST:i,totalLines:n},s){const{diffIndicators:r="bars",disableBackground:o=!1,disableLineNumbers:a=!1,overflow:l="scroll",diffStyle:u="split"}=this.options,f={type:"diff",diffIndicators:r,disableBackground:o,disableLineNumbers:a,overflow:l,split:u==="unified"?!1:t!=null&&i!=null,totalLines:n,customProperties:s};gt(f,this.appliedPreAttributes)||(mt(e,f),this.appliedPreAttributes=f)}applyErrorToDOM(e,t){this.cleanupErrorWrapper(),this.pre?.remove(),this.pre=void 0,this.appliedPreAttributes=void 0;const i=t.shadowRoot??t.attachShadow({mode:"open"});this.errorWrapper??=document.createElement("div"),this.errorWrapper.dataset.errorWrapper="",this.errorWrapper.textContent="",i.appendChild(this.errorWrapper);const n=document.createElement("div");n.dataset.errorMessage="",n.innerText=e.message,this.errorWrapper.appendChild(n);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 hi({fileDiff:e,oldFile:t,newFile:i}){return e!=null&&e.hunks.length>0||t!=null||i!=null}function di({fileDiff:e,oldFile:t,newFile:i}){return e!=null||t!=null||i!=null}function ui(e,t,i=!1){return!i&&e==null&&t}function fi(e,t,i=!1){return e==null&&t&&!i}function X(e){if(!(e==null||e.type!=="element"))return e.children??[]}function ci({fileDiff:e,metrics:t,disableFileHeader:i,hunkSeparators:n,expandUnchanged:s,expandedHunks:r,collapsedContextThreshold:o}){let a=Y(t,i),l=a;const u=s?!0:r,f=e.hunks.length-1;for(let h=0;h<e.hunks.length;h++){const d=e.hunks[h];if(d==null)throw new Error("computeEstimatedDiffHeights: invalid hunk index");const c=we({isPartial:e.isPartial,rangeSize:d.collapsedBefore,expandedHunks:u,hunkIndex:h,collapsedContextThreshold:o}),g=(c.fromStart+c.fromEnd)*t.lineHeight;if(a+=g,l+=g,c.collapsedLines>0){const y=oe({type:n,metrics:t,hunkIndex:h,hunkSpecs:d.hunkSpecs})?.totalHeight??0;a+=y,l+=y}a+=d.splitLineCount*t.lineHeight,l+=d.unifiedLineCount*t.lineHeight;const m=pi(d);a+=m.split*t.lineHeight,l+=m.unified*t.lineHeight;const C=h===f?Me({fileDiff:e,hunkIndex:h,expandedHunks:u,collapsedContextThreshold:o,errorPrefix:"computeEstimatedDiffHeights"}):void 0;if(C!=null){const y=(C.fromStart+C.fromEnd)*t.lineHeight;if(a+=y,l+=y,C.collapsedLines>0){const v=ae({type:n,metrics:t})?.totalHeight??0;a+=v,l+=v}}}if(e.hunks.length>0){const h=Ze(t);a+=h,l+=h}return{splitHeight:a,unifiedHeight:l}}function pi(e){if(!e.noEOFCRAdditions&&!e.noEOFCRDeletions)return{split:0,unified:0};const t=e.hunkContent.at(-1);if(t==null)return{split:0,unified:0};if(t.type==="context"){const i=t.lines>0?1:0;return{split:i,unified:i}}return gi(e,t)}function gi(e,t){const i=(t.deletions>0&&e.noEOFCRDeletions?1:0)+(t.additions>0&&e.noEOFCRAdditions?1:0),n=t.deletions>0&&e.noEOFCRDeletions,s=t.additions>0&&e.noEOFCRAdditions;return{split:n||s?1:0,unified:i}}const ze=5e3;let mi=-1;var Mi=class extends li{__id=`little-virtualized-file-diff:${++mi}`;top;height=0;metrics;cache={heightDeltas:new Map,measuredHeightDeltaTotal:0,estimatedSplitHeight:void 0,estimatedUnifiedHeight:void 0,checkpoints:[],totalLines:0,fileAnnotationHeight:0};isVisible=!1;isSetup=!1;virtualizer;layoutDirty=!0;forceRenderOverride;currentCollapsed;constructor(e,t,i,n,s=!1){super(e,n,s),this.virtualizer=t,this.metrics=Re(i)}setMetrics(e,t=!1){const i=Re(e);!t&&St(this.metrics,i)||(this.metrics=i,this.resetLayoutCache({includeEstimatedHeights:!0}))}setLineAnnotations(e){this.syncLineAnnotations(e)&&this.resetLayoutCache({includeEstimatedHeights:!1})}syncLineAnnotations(e){return e==null||e===this.lineAnnotations||e.length===0&&this.lineAnnotations.length===0?!1:(super.setLineAnnotations(e),!0)}setFileAnnotationHeight(e){const t=this.cache.fileAnnotationHeight;return e===t?!1:(this.cache.fileAnnotationHeight=e,this.cache.measuredHeightDeltaTotal+=e-t,!0)}hasFileAnnotations(e=this.fileDiff){return e==null||!vt(this.lineAnnotations)?!1:this.lineAnnotations.some(t=>t.lineNumber!==0?!1:e.type==="new"?t.side==="additions":e.type==="deleted"?t.side==="deletions":!0)}getLineHeight(e,t=!1){return this.getEstimatedLineHeight(t)+(this.cache.heightDeltas.get(e)??0)}getEstimatedLineHeight(e=!1){const t=e?2:1;return this.metrics.lineHeight*t}setOptions(e){if(this.isAdvancedMode())throw new Error("VirtualizedFileDiff.setOptions cannot be used inside CodeView. Update CodeView options instead.");if(e==null)return;const{options:t}=this,i=!yt(t,e),n=i&&Li(t,e);super.setOptions(e),n&&this.resetLayoutCache({forceSimpleRecompute:!0,includeEstimatedHeights:Ti(t,e)}),i&&(this.forceRenderOverride=!0),i&&this.isSimpleMode()&&this.virtualizer.instanceChanged(this,n)}setThemeType(e){if(this.isAdvancedMode())throw new Error("VirtualizedFileDiff.setThemeType cannot be used inside CodeView. Update CodeView options instead.");super.setThemeType(e)}resetLayoutCache({forceSimpleRecompute:e=!1,includeEstimatedHeights:t=!1}={}){this.layoutDirty=!0,this.cache.fileAnnotationHeight=0,this.cache.heightDeltas.size>0&&this.cache.heightDeltas.clear(),this.cache.measuredHeightDeltaTotal!==0&&(this.cache.measuredHeightDeltaTotal=0),this.cache.checkpoints.length>0&&(this.cache.checkpoints.length=0),this.cache.totalLines!==0&&(this.cache.totalLines=0),t&&(this.cache.estimatedSplitHeight=void 0,this.cache.estimatedUnifiedHeight=void 0),this.renderRange!=null&&(this.renderRange=void 0),e&&this.isSimpleMode()&&this.computeApproximateSize()}reconcileHeights(){let e=!1;const{overflow:t="scroll"}=this.options;if(this.fileContainer==null||this.fileDiff==null)return this.height!==0&&(e=!0),this.height=0,e;if(this.top=this.getVirtualizedTop(),t==="scroll"&&this.lineAnnotations.length===0&&!this.isResizeDebuggingEnabled())return e;const i=this.getDiffStyle(),n=i==="split"?[this.codeDeletions,this.codeAdditions]:[this.codeUnified],s=this.hasFileAnnotations(this.fileDiff);if(this.renderRange!=null&&s&&Ye(this.renderRange)){const r=Ci(n)??0;this.setFileAnnotationHeight(r)&&(e=!0)}else!s&&this.setFileAnnotationHeight(0)&&(e=!0);for(const r of n){if(r==null)continue;const o=r.children[1];if(o instanceof HTMLElement)for(const a of o.children){if(!(a instanceof HTMLElement))continue;const l=a.dataset.lineIndex;if(l==null)continue;const u=ki(l,i);let f=a.getBoundingClientRect().height,h=!1;a.nextElementSibling instanceof HTMLElement&&("lineAnnotation"in a.nextElementSibling.dataset||"noNewline"in a.nextElementSibling.dataset)&&("noNewline"in a.nextElementSibling.dataset&&(h=!0),f+=a.nextElementSibling.getBoundingClientRect().height);const d=this.getEstimatedLineHeight(h),c=this.cache.heightDeltas.get(u)??0,g=f-d;g!==c&&(e=!0,this.cache.measuredHeightDeltaTotal+=g-c,g===0?this.cache.heightDeltas.delete(u):this.cache.heightDeltas.set(u,g))}}return(e||this.isResizeDebuggingEnabled())&&this.computeApproximateSize(!0),e}onRender=e=>this.fileContainer==null?!1:(e&&(this.top=this.getVirtualizedTop()),this.render());prepareCodeViewItem(e,t,i,n){const s=!re(this.fileDiff,e),r=this.syncLineAnnotations(n);let o=i?.resetDiffLayoutCache===!0||s||r,a=s||i?.resetDiffLayoutCache===!0&&i.includeEstimatedDiffHeights;i?.metrics!=null&&(this.metrics=Re(i.metrics),o=!0,a=!0);const{collapsed:l=!1}=this.options;return this.currentCollapsed!==l&&(this.currentCollapsed=l,o=!0),o&&this.resetLayoutCache({includeEstimatedHeights:a}),this.fileDiff=e,this.top=t,this.computeApproximateSize(),this.height}getLinePosition(e,t="additions"){if(this.fileDiff==null||e<1)return;const i=this.getLineIndex(e,t);if(i==null)return;const{disableFileHeader:n=!1,expandUnchanged:s=!1,collapsed:r=!1,collapsedContextThreshold:o=1}=this.options,a=this.getDiffStyle(),l=this.getHunkSeparatorType(),u=a==="split"?i[1]:i[0];this.approximateLayoutCheckpoints();const f=Y(this.metrics,n),h=this.getLayoutCheckpointBeforeLineIndex(u);let d=h?.top??f+this.cache.fileAnnotationHeight;if(r)return{top:f,height:0};let c;return ve({diff:this.fileDiff,diffStyle:a,startingLine:h?.renderedLineIndex??0,expandedHunks:s?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:o,callback:({hunkIndex:g,hunk:m,collapsedBefore:C,collapsedAfter:y,deletionLine:v,additionLine:p})=>{const S=a==="split"?p?.splitLineIndex??v?.splitLineIndex:p?.unifiedLineIndex??v?.unifiedLineIndex;if(S==null)throw new Error("VirtualizedFileDiff.getLinePosition: missing line index data");if(C>0){const T=oe({type:l,metrics:this.metrics,hunkIndex:g,hunkSpecs:m?.hunkSpecs});if(T!=null){if(d+=T.gapBefore,u>=S-C&&u<S)return c={top:d,height:T.height},!0;d+=T.height+T.gapAfter}}const H=this.getLineHeight(S,(p?.noEOFCR??!1)||(v?.noEOFCR??!1));if(S===u)return c={top:d,height:H},!0;if(d+=H,y>0){const T=ae({type:l,metrics:this.metrics});if(T!=null){if(u>S&&u<=S+y)return c={top:d+T.gapBefore,height:T.height},!0;d+=T.totalHeight}}return!1}}),c}getNumericScrollAnchor(e){if(this.fileDiff==null)return;const{disableFileHeader:t=!1,expandUnchanged:i=!1,collapsed:n=!1,collapsedContextThreshold:s=1}=this.options;if(n)return;const r=this.getDiffStyle(),o=this.getHunkSeparatorType();this.approximateLayoutCheckpoints();const a=this.getLayoutCheckpointBeforeTop(e);let l=a?.top??Y(this.metrics,t)+this.cache.fileAnnotationHeight,u;return ve({diff:this.fileDiff,diffStyle:r,startingLine:a?.renderedLineIndex??0,expandedHunks:i?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:s,callback:({hunkIndex:f,hunk:h,collapsedBefore:d,collapsedAfter:c,deletionLine:g,additionLine:m})=>{const C=r==="split"?m?.splitLineIndex??g?.splitLineIndex:m?.unifiedLineIndex??g?.unifiedLineIndex;if(C==null)throw new Error("VirtualizedFileDiff.getNumericScrollAnchor: missing line index data");if(d>0){const v=oe({type:o,metrics:this.metrics,hunkIndex:f,hunkSpecs:h?.hunkSpecs});v!=null&&(l+=v.totalHeight)}if(l>=e&&(g!=null?u={lineNumber:g.lineNumber,side:"deletions",top:l}:m!=null&&(u={lineNumber:m.lineNumber,side:"additions",top:l}),u!=null))return!0;const y=this.getLineHeight(C,(m?.noEOFCR??!1)||(g?.noEOFCR??!1));if(l+=y,c>0){const v=ae({type:o,metrics:this.metrics});v!=null&&(l+=v.totalHeight)}return!1}}),u}getVirtualizedHeight(){return this.height}getAdvancedStickySpecs(e){if(this.top==null||this.fileDiff==null)return;if(this.options.collapsed===!0)return{topOffset:this.top,height:this.height};const t=e!=null?this.computeRenderRangeFromWindow(this.fileDiff,this.top,e):this.renderRange;if(t==null)return;const{bufferBefore:i,bufferAfter:n,totalLines:s}=t;let r=0;if(s===0){const o=e??this.virtualizer.getWindowSpecs();this.top<o.top&&(r=n)}return{topOffset:this.top+i+r,height:this.height-(i+n)}}cleanUp(e=!1){this.fileContainer!=null&&this.isSimpleMode()&&this.getSimpleVirtualizer()?.disconnect(this.fileContainer),e||this.resetLayoutCache({includeEstimatedHeights:!0}),this.isSetup=!1,super.cleanUp(e)}expandHunk=(e,t,i)=>{this.hunksRenderer.expandHunk(e,t,i),this.forceRenderOverride=!0,this.resetLayoutCache({includeEstimatedHeights:!0}),this.isSimpleMode()&&this.computeApproximateSize(),this.virtualizer.instanceChanged(this,!0)};setVisibility(e){this.isAdvancedMode()||this.fileContainer==null||(this.renderRange=void 0,e&&!this.isVisible?(this.top=this.getVirtualizedTop(),this.isVisible=!0):!e&&this.isVisible&&(this.isVisible=!1,this.rerender()))}rerender(){!this.enabled||this.fileDiff==null&&this.additionFile==null&&this.deletionFile==null||(this.forceRenderOverride=!0,this.virtualizer.instanceChanged(this,!1))}applyDocumentChange(e,t,i=!1){const n=this.renderRange;if(super.applyDocumentChange(e,t),this.getSimpleVirtualizer()?.markDOMDirty(),this.resetLayoutCache({forceSimpleRecompute:this.isSimpleMode(),includeEstimatedHeights:!0}),i&&n!==void 0&&this.fileDiff!==void 0){const s=this.virtualizer.getWindowSpecs(),r=this.computeRenderRangeFromWindow(this.fileDiff,this.top??0,s);r.bufferAfter!==n.bufferAfter&&this.updateBuffers(r)}}computeApproximateSize(e=!1){const t=this.isResizeDebuggingEnabled();if(!e&&!this.layoutDirty&&!t)return;const i=this.height===0;if(this.height=0,this.cache.checkpoints=[],this.cache.totalLines=0,this.fileDiff==null){this.layoutDirty=!1;return}const{disableFileHeader:n=!1,collapsed:s=!1}=this.options,r=Y(this.metrics,n);if(this.height+=r,s){this.layoutDirty=!1;return}this.height=this.getActiveEstimatedHeight()+this.cache.measuredHeightDeltaTotal,t&&!i&&this.validateComputedHeight(),this.layoutDirty=!1}getActiveEstimatedHeight(){this.ensureEstimatedDiffHeights();const e=this.getDiffStyle()==="split"?this.cache.estimatedSplitHeight:this.cache.estimatedUnifiedHeight;if(e==null)throw new Error("VirtualizedFileDiff.getActiveEstimatedHeight: missing estimated height");return e}ensureEstimatedDiffHeights(){if(this.fileDiff==null){this.cache.estimatedSplitHeight=void 0,this.cache.estimatedUnifiedHeight=void 0;return}if(this.cache.estimatedSplitHeight!=null&&this.cache.estimatedUnifiedHeight!=null)return;const{disableFileHeader:e=!1,expandUnchanged:t=!1,collapsedContextThreshold:i=1}=this.options,{splitHeight:n,unifiedHeight:s}=ci({fileDiff:this.fileDiff,metrics:this.metrics,disableFileHeader:e,hunkSeparators:this.getHunkSeparatorType(),expandUnchanged:t,expandedHunks:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:i});this.cache.estimatedSplitHeight=n,this.cache.estimatedUnifiedHeight=s}validateComputedHeight(){if(this.fileContainer==null||this.fileDiff==null)return;const e=this.fileContainer.getBoundingClientRect();e.height!==this.height?console.log("VirtualizedFileDiff.computeApproximateSize: computed height doesnt match",{name:this.fileDiff.name,elementHeight:e.height,computedHeight:this.height}):console.log("VirtualizedFileDiff.computeApproximateSize: computed height IS CORRECT")}render({fileContainer:e,oldFile:t,newFile:i,fileDiff:n,forceRender:s=!1,lineAnnotations:r,...o}={}){const{forceRenderOverride:a,isSetup:l}=this;this.forceRenderOverride=void 0;const u=this.syncLineAnnotations(r);if(u&&this.resetLayoutCache({includeEstimatedHeights:!1}),this.fileDiff??=n??(t!=null&&i!=null?Z(t,i,this.options.parseDiffOptions):void 0),e=this.getOrCreateFileContainer(e),this.fileDiff==null)return console.error("VirtualizedFileDiff.render: attempting to virtually render when we dont have the correct data"),!1;if(l)this.top??=this.getVirtualizedTop();else{this.computeApproximateSize();const c=this.getSimpleVirtualizer();if(this.top??=this.getVirtualizedTop(),this.isAdvancedMode())this.isVisible=!0;else{if(c==null)throw new Error("VirtualizedFileDiff.render: simple virtualizer is not available");c.connect(e,this),this.isVisible=c.isInstanceVisible(this.top??0,this.height)}this.isSetup=!0}if(!this.isVisible&&this.isSimpleMode())return this.renderPlaceholder(this.height);const f=this.virtualizer.getWindowSpecs(),h=this.top??0,d=this.computeRenderRangeFromWindow(this.fileDiff,h,f);return super.render({fileDiff:this.fileDiff,fileContainer:e,renderRange:d,oldFile:t,newFile:i,lineAnnotations:r,forceRender:(a??s)||u,...o})}syncVirtualizedTop(){this.top=this.getVirtualizedTop()}shouldDisableVirtualizationBuffers(){return this.isAdvancedMode()||super.shouldDisableVirtualizationBuffers()}isSimpleMode(){return this.virtualizer.type==="simple"}isAdvancedMode(){return this.virtualizer.type==="advanced"}getVirtualizedTop(){return this.virtualizer.type==="advanced"?this.virtualizer.getLocalTopForInstance(this):this.fileContainer!=null?this.virtualizer.getOffsetInScrollContainer(this.fileContainer):0}getSimpleVirtualizer(){return this.virtualizer.type==="simple"?this.virtualizer:void 0}isResizeDebuggingEnabled(){return this.getSimpleVirtualizer()?.config.resizeDebugging??!1}getDiffStyle(){return this.options.diffStyle??"split"}getHunkSeparatorType(){return Ai(this.options.hunkSeparators)}approximateLayoutCheckpoints(){if(this.cache.checkpoints.length>0||this.fileDiff==null||this.fileDiff.hunks.length===0||this.options.collapsed===!0)return;const{disableFileHeader:e=!1,expandUnchanged:t=!1,collapsedContextThreshold:i=1}=this.options,n=this.fileDiff.hunks.length-1,s=this.getDiffStyle(),r=this.getHunkSeparatorType(),o=t?!0:this.hunksRenderer.getExpandedHunksMap(),a=Si(this.cache.heightDeltas);let l=Y(this.metrics,e)+this.cache.fileAnnotationHeight,u=0;const f=({rowCount:h,startLineIndex:d,preSeparatorHeight:c=0,postSeparatorHeight:g=0,metadataOffsets:m=[]})=>{if(h<=0)return;const C=u,y=u+h;let v=vi(C);for(;v<y;){const p=v-C,S=l+(p>0?c:0)+p*this.metrics.lineHeight+yi(m,p)*this.metrics.lineHeight+qe(a,d,d+p);this.cache.checkpoints.push({renderedLineIndex:v,lineIndex:d+p,top:S}),v+=ze}l+=c+h*this.metrics.lineHeight+m.length*this.metrics.lineHeight+qe(a,d,d+h)+g,u=y};for(let h=0;h<this.fileDiff.hunks.length;h++){const d=this.fileDiff.hunks[h];if(d==null)throw new Error("VirtualizedFileDiff.approximateLayoutCheckpoints: invalid hunk index");const c=we({isPartial:this.fileDiff.isPartial,rangeSize:d.collapsedBefore,expandedHunks:o,hunkIndex:h,collapsedContextThreshold:i}),g=c.collapsedLines>0?oe({type:r,metrics:this.metrics,hunkIndex:h,hunkSpecs:d.hunkSpecs})?.totalHeight??0:0;f({rowCount:c.fromStart,startLineIndex:(s==="split"?d.splitLineStart:d.unifiedLineStart)-c.rangeSize});let m=g;f({rowCount:c.fromEnd,startLineIndex:(s==="split"?d.splitLineStart:d.unifiedLineStart)-c.fromEnd,preSeparatorHeight:m}),c.fromEnd>0&&(m=0);const C=h===n?Me({fileDiff:this.fileDiff,hunkIndex:h,expandedHunks:o,collapsedContextThreshold:i,errorPrefix:"VirtualizedFileDiff"}):void 0,y=C!=null&&C.collapsedLines>0?ae({type:r,metrics:this.metrics})?.totalHeight??0:0,v=C!=null?C.fromStart+C.fromEnd:0,p=s==="split"?d.splitLineCount:d.unifiedLineCount,S=s==="split"?d.splitLineStart:d.unifiedLineStart;f({rowCount:p,startLineIndex:S,preSeparatorHeight:m,postSeparatorHeight:v===0?y:0,metadataOffsets:Hi({diffStyle:s,hunk:d,rowCount:p})}),C!=null&&v>0&&f({rowCount:v,startLineIndex:S+p,postSeparatorHeight:y})}this.cache.totalLines=u}getLayoutCheckpointBeforeLineIndex(e){if(e<=0||this.cache.checkpoints.length===0)return;let t=0,i=this.cache.checkpoints.length-1,n;for(;t<=i;){const s=t+i>>1,r=this.cache.checkpoints[s];if(r==null)throw new Error("VirtualizedFileDiff: invalid checkpoint index");r.lineIndex<=e?(n=r,t=s+1):i=s-1}return n}getLayoutCheckpointBeforeTop(e,t){let i=0,n=this.cache.checkpoints.length-1,s=-1;for(;i<=n;){const r=i+n>>1,o=this.cache.checkpoints[r];if(o==null)throw new Error("VirtualizedFileDiff: invalid checkpoint index");o.top<=e?(s=r,i=r+1):n=r-1}if(t==null)return s>=0?this.cache.checkpoints[s]:void 0;for(let r=s;r>=0;r--){const o=this.cache.checkpoints[r];if(o==null)throw new Error("VirtualizedFileDiff: invalid checkpoint index");if(o.renderedLineIndex%t===0)return o}}getExpandedLineCount(e,t){let i=0;if(e.isPartial){for(const a of e.hunks)i+=t==="split"?a.splitLineCount:a.unifiedLineCount;return i}const{expandUnchanged:n=!1,collapsedContextThreshold:s=1}=this.options,r=n?!0:this.hunksRenderer.getExpandedHunksMap();for(const[a,l]of e.hunks.entries()){const u=t==="split"?l.splitLineCount:l.unifiedLineCount;i+=u;const f=Math.max(l.collapsedBefore,0),{fromStart:h,fromEnd:d,renderAll:c}=we({isPartial:e.isPartial,rangeSize:f,expandedHunks:r,hunkIndex:a,collapsedContextThreshold:s});f>0&&(i+=c?f:h+d)}const o=Me({fileDiff:e,hunkIndex:e.hunks.length-1,expandedHunks:r,collapsedContextThreshold:s,errorPrefix:"VirtualizedFileDiff"});return o!=null&&(i+=o.fromStart+o.fromEnd),i}computeRenderRangeFromWindow(e,t,{top:i,bottom:n}){const{disableFileHeader:s=!1,expandUnchanged:r=!1,collapsedContextThreshold:o=1}=this.options,{hunkLineCount:a,lineHeight:l}=this.metrics,u=this.getDiffStyle(),f=this.getHunkSeparatorType(),h=this.height;let d=this.cache.totalLines>0?this.cache.totalLines:this.getExpandedLineCount(e,u);const c=Y(this.metrics,s),g=e.hunks.length>0?Ze(this.metrics):0,{fileAnnotationHeight:m}=this.cache,C=c+m,y=Math.max(0,h-c-m-g),v=this.hasFileAnnotations(e),p=t+c,S=m>0&&v&&p<n&&p+m>i;if(t<i-h||t>n)return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:h-c-g};if(d<=a||e.hunks.length===0)return{startingLine:0,totalLines:a,bufferBefore:0,bufferAfter:0};this.approximateLayoutCheckpoints(),d=this.cache.totalLines>0?this.cache.totalLines:d;const H=Math.ceil(Math.max(n-i,0)/l),T=Math.ceil(H/a)*a+a,F=T/a,de=F,j=[],ue=(i+n)/2,q=this.getLayoutCheckpointBeforeTop(Math.max(0,i-t-T*l*2),a);let b=t+(q?.top??C),J=q?.renderedLineIndex??0,R,D,P;if(ve({diff:e,diffStyle:u,startingLine:q?.renderedLineIndex??0,expandedHunks:r?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:o,callback:({hunkIndex:ye,hunk:He,collapsedBefore:te,collapsedAfter:ie,deletionLine:k,additionLine:E})=>{const z=E!=null?E.splitLineIndex:k.splitLineIndex,$=E!=null?E.unifiedLineIndex:k.unifiedLineIndex,O=(E?.noEOFCR??!1)||(k?.noEOFCR??!1),N=(te>0?oe({type:f,metrics:this.metrics,hunkIndex:ye,hunkSpecs:He?.hunkSpecs}):void 0)?.totalHeight??0;b+=N;const ne=J%a===0,M=Math.floor(J/a);if(ne&&(j[M]=b-(t+C+N),P!=null)){if(P<=0)return!0;P--}const Le=this.getLineHeight(u==="split"?z:$,O);return b>i-Le&&b<n&&(R??=M),D==null&&b+Le>ue&&(D=M),P==null&&b>=n&&ne&&(P=de),J++,b+=Le,ie>0&&(b+=ae({type:f,metrics:this.metrics})?.totalHeight??0),!1}}),R==null)if(S)R=0,D=0;else return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:h-c-g};D??=R;const V=Math.round(D-F/2),L=Math.max(0,Math.ceil(d/a)-F),A=Math.max(0,Math.min(V,L)),x=A*a,I=V<0?T+V*a:T,W=j[A]??0,Q=x===0?0:m+W,ee=A+I/a,fe=ee<j.length?y-j[ee]:y-(b-t-C);return{startingLine:x,totalLines:I,bufferBefore:Q,bufferAfter:Math.max(0,fe)}}};function Ci(e){let t;for(const i of e){if(i==null)continue;const n=i.children[1];if(n instanceof HTMLElement)for(const s of n.children)s instanceof HTMLElement&&s.dataset.lineAnnotation===Ht&&(t=Math.max(t??0,s.getBoundingClientRect().height))}return t}function Si(e){const t=Array.from(e).sort((r,o)=>r[0]-o[0]),i=[],n=[0];let s=0;for(const[r,o]of t)i.push(r),s+=o,n.push(s);return{lineIndexes:i,prefixTotals:n}}function qe({lineIndexes:e,prefixTotals:t},i,n){if(i>=n||e.length===0)return 0;const s=Ke(e,i);return(t[Ke(e,n)]??0)-(t[s]??0)}function Ke(e,t){let i=0,n=e.length;for(;i<n;){const s=i+n>>1,r=e[s];if(r==null)throw new Error("VirtualizedFileDiff: invalid prefix index");r<t?i=s+1:n=s}return i}function vi(e){return Math.ceil(e/ze)*ze}function yi(e,t){let i=0;for(const n of e)n<t&&i++;return i}function Hi({diffStyle:e,hunk:t,rowCount:i}){if(i<=0||!t.noEOFCRAdditions&&!t.noEOFCRDeletions)return[];const n=t.hunkContent.at(-1);if(n==null)return[];if(n.type==="context")return[i-1];const s=Math.max(n.deletions,n.additions),r=n.deletions+n.additions;if(e==="split")return s>0&&(t.noEOFCRAdditions||t.noEOFCRDeletions)?[i-1]:[];const o=[],a=i-r;return n.deletions>0&&t.noEOFCRDeletions&&o.push(a+n.deletions-1),n.additions>0&&t.noEOFCRAdditions&&o.push(i-1),o}function Li(e,t){return(e.diffStyle??"split")!==(t.diffStyle??"split")||(e.overflow??"scroll")!==(t.overflow??"scroll")||(e.collapsed??!1)!==(t.collapsed??!1)||(e.disableLineNumbers??!1)!==(t.disableLineNumbers??!1)||(e.disableFileHeader??!1)!==(t.disableFileHeader??!1)||(e.diffIndicators??"bars")!==(t.diffIndicators??"bars")||(e.hunkSeparators??"line-info")!==(t.hunkSeparators??"line-info")||(e.expandUnchanged??!1)!==(t.expandUnchanged??!1)||(e.collapsedContextThreshold??1)!==(t.collapsedContextThreshold??1)||e.unsafeCSS!==t.unsafeCSS}function Ti(e,t){return(e.disableFileHeader??!1)!==(t.disableFileHeader??!1)||(e.hunkSeparators??"line-info")!==(t.hunkSeparators??"line-info")||(e.expandUnchanged??!1)!==(t.expandUnchanged??!1)||(e.collapsedContextThreshold??1)!==(t.collapsedContextThreshold??1)}function Ai(e){return typeof e=="function"?"custom":e??"line-info"}function ki(e,t){const[i,n]=e.split(",").map(Number);return t==="split"?n:i}export{li as F,Mi as V,Z as p};
10
+ `:t}function Ee(e,t){return Math.max(e.additionLines.length,e.deletionLines.length)>t}function si(e,t){return e.lineNumber===t.lineNumber&&e.side===t.side&&e.metadata===t.metadata}function ri(e,t){return e.slotName===t.slotName&&e.hunkIndex===t.hunkIndex&&e.lines===t.lines&&e.type===t.type&&e.expandable?.chunked===t.expandable?.chunked&&e.expandable?.up===t.expandable?.up&&e.expandable?.down===t.expandable?.down}function oi(e){return{theme:e?.theme,disableLineNumbers:e?.disableLineNumbers,overflow:e?.overflow,collapsed:e?.collapsed,disableFileHeader:e?.disableFileHeader,disableVirtualizationBuffers:e?.disableVirtualizationBuffers,stickyHeader:e?.stickyHeader,preferredHighlighter:e?.preferredHighlighter,useCSSClasses:e?.useCSSClasses,useTokenTransformer:e?.useTokenTransformer,tokenizeMaxLineLength:e?.tokenizeMaxLineLength,tokenizeMaxLength:e?.tokenizeMaxLength,diffStyle:e?.diffStyle,diffIndicators:e?.diffIndicators,disableBackground:e?.disableBackground,hunkSeparators:typeof e?.hunkSeparators=="function"?"custom":e?.hunkSeparators,expandUnchanged:e?.expandUnchanged,collapsedContextThreshold:e?.collapsedContextThreshold,lineDiffType:e?.lineDiffType,maxLineDiffLength:e?.maxLineDiffLength,expansionLineCount:e?.expansionLineCount,headerRenderMode:e?.renderCustomHeader!=null?"custom":"default"}}let ai=-1;var li=class{options;workerManager;isContainerManaged;static LoadedCustomComponent=!0;__id=`file-diff:${++ai}`;type="file-diff";fileContainer;spriteSVG;pre;codeUnified;codeDeletions;codeAdditions;bufferBefore;bufferAfter;themeCSSStyle;appliedThemeCSS;hasAdoptedThemeCSS=!1;unsafeCSSStyle;appliedUnsafeCSS;gutterUtilityContent;headerElement;headerPrefix;headerFilenameSuffix;headerMetadata;headerCustom;separatorCache=new Map;errorWrapper;placeHolder;hunksRenderer;resizeManager;scrollSyncManager;interactionManager;annotationCache=new Map;lineAnnotations=[];managersDirty=!1;deletionFile;additionFile;fileDiff;renderRange;appliedPreAttributes;lastRenderedHeaderHTML;cachedHeaderHTML;lastRowCount;mounted=!1;enabled=!0;editor;fastRefreshTimeout;constructor(e={theme:_},t,i=!1){this.options=e,this.workerManager=t,this.isContainerManaged=i,this.hunksRenderer=this.createHunksRenderer(e),this.resizeManager=new rt,this.scrollSyncManager=new Bt,this.interactionManager=new ot("diff",Ue(e,typeof e.hunkSeparators=="function"||(e.hunkSeparators??"line-info")==="line-info"||e.hunkSeparators==="line-info-basic"?this.handleExpandHunk:void 0,this.getLineIndex)),this.workerManager?.subscribeToThemeChanges(this),this.enabled=!0}handleHighlightRender=()=>{this.rerender()};getHunksRendererOptions(e){return oi(e)}createHunksRenderer(e){return new ti(this.getHunksRendererOptions(e),this.handleHighlightRender,this.workerManager)}getLineIndex=(e,t="additions")=>{const i=this.hunksRenderer.getRenderDiff()??this.fileDiff;if(i==null)return;const n=i.hunks.at(-1);let s,r;e:for(const o of i.hunks){let a=t==="deletions"?o.deletionStart:o.additionStart;const l=t==="deletions"?o.deletionCount:o.additionCount;let u=o.splitLineStart,f=o.unifiedLineStart;if(e<a){const h=a-e;s=Math.max(f-h,0),r=Math.max(u-h,0);break e}if(e>=a+l){if(o===n){const h=e-(a+l);s=f+o.unifiedLineCount+h,r=u+o.splitLineCount+h;break e}continue}for(const h of o.hunkContent)if(h.type==="context")if(e<a+h.lines){const d=e-a;r=u+d,s=f+d;break e}else a+=h.lines,u+=h.lines,f+=h.lines;else{const d=t==="deletions"?h.deletions:h.additions;if(e<a+d){const c=e-a;s=f+(t==="additions"?h.deletions:0)+c,r=u+c;break e}else a+=d,u+=Math.max(h.deletions,h.additions),f+=h.deletions+h.additions}break e}if(!(s==null||r==null))return[s,r]};setOptions(e){e!=null&&(this.options=e,this.cachedHeaderHTML=void 0,this.hunksRenderer.setOptions(this.getHunksRendererOptions(e)),this.syncInteractionOptions())}syncInteractionOptions(){this.interactionManager.setOptions(Ue(this.options,typeof this.options.hunkSeparators=="function"||(this.options.hunkSeparators??"line-info")==="line-info"||this.options.hunkSeparators==="line-info-basic"?this.handleExpandHunk:void 0,this.getLineIndex))}mergeOptions(e){this.options={...this.options,...e}}setThemeType(e){(this.options.themeType??"system")!==e&&(this.mergeOptions({themeType:e}),this.applyCachedThemeState(e))}applyCachedThemeState(e){if(typeof this.options.theme=="string"||this.fileContainer==null||this.appliedThemeCSS==null)return!1;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&&!Rt(this.appliedThemeCSS.theme,this.options.theme??_)}getHoveredLine=()=>this.interactionManager.getHoveredLine();setLineAnnotations(e){this.lineAnnotations=e}canPartiallyRender(e,t,i){return!(e||t||i||typeof this.options.hunkSeparators=="function")}setSelectedLines(e,t){this.interactionManager.setSelection(e,t)}flushManagers(){if(!this.managersDirty||this.pre==null){this.managersDirty=!1;return}const{diffStyle:e="split",overflow:t="scroll"}=this.options;this.interactionManager.setup(this.pre),this.resizeManager.setup(this.pre,t==="wrap"),t==="scroll"&&e==="split"?this.scrollSyncManager.setup(this.pre,this.codeDeletions,this.codeAdditions):this.scrollSyncManager.cleanUp(),this.managersDirty=!1}cleanUp(e=!1){this.emitPostRender(!0),this.resizeManager.cleanUp(),this.interactionManager.cleanUp(),this.scrollSyncManager.cleanUp(),this.managersDirty=!1,this.workerManager?.unsubscribeToThemeChanges(this),this.renderRange=void 0,this.isContainerManaged||this.fileContainer?.remove(),this.fileContainer=void 0,this.mounted=!1,e||(this.lineAnnotations=[]),this.clearAuxiliaryNodes(),this.annotationCache.clear(),this.pre=void 0,this.codeUnified=void 0,this.codeDeletions=void 0,this.codeAdditions=void 0,this.bufferBefore?.remove(),this.bufferBefore=void 0,this.bufferAfter?.remove(),this.bufferAfter=void 0,this.appliedPreAttributes=void 0,this.headerElement=void 0,this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0,this.headerCustom=void 0,this.placeHolder=void 0,this.lastRenderedHeaderHTML=void 0,e||(this.cachedHeaderHTML=void 0),this.errorWrapper=void 0,this.spriteSVG=void 0,this.lastRowCount=void 0,this.themeCSSStyle=void 0,this.appliedThemeCSS=void 0,this.hasAdoptedThemeCSS=!1,this.unsafeCSSStyle=void 0,this.appliedUnsafeCSS=void 0,e?this.hunksRenderer.recycle():(this.hunksRenderer.cleanUp(),this.workerManager=void 0,this.fileDiff=void 0,this.deletionFile=void 0,this.additionFile=void 0),this.enabled=!1,this.editor?.cleanUp(),this.editor=void 0,this.fastRefreshTimeout!=null&&(clearTimeout(this.fastRefreshTimeout),this.fastRefreshTimeout=void 0)}virtualizedSetup(){this.enabled=!0,this.workerManager?.subscribeToThemeChanges(this)}hydrate(e){const{fileContainer:t,prerenderedHTML:i,preventEmit:n=!1,lineAnnotations:s,oldFile:r,newFile:o,fileDiff:a}=e;this.hydrateElements(t,i),ui(this.pre,hi({fileDiff:a,oldFile:r,newFile:o}),this.options.collapsed)||fi(this.headerElement,di({fileDiff:a,oldFile:r,newFile:o}),this.options.disableFileHeader)?this.render({...e,preventEmit:!0}):this.hydrationSetup({fileDiff:a,oldFile:r,newFile:o,lineAnnotations:s}),n||this.emitPostRender()}hydrateElements(e,t){this.fileContainer!==e&&this.emitPostRender(!0),at(e,t);for(const i of e.shadowRoot?.children??[]){if(i instanceof SVGElement){this.spriteSVG=i;continue}if(i instanceof HTMLElement){if(i instanceof HTMLPreElement){this.pre=i;for(const n of i.children)!(n instanceof HTMLElement)||n.tagName.toLowerCase()!=="code"||("deletions"in n.dataset&&(this.codeDeletions=n),"additions"in n.dataset&&(this.codeAdditions=n),"unified"in n.dataset&&(this.codeUnified=n));continue}if("diffsHeader"in i.dataset){this.headerElement=i;continue}if(i instanceof HTMLStyleElement&&i.hasAttribute("data-theme-css")){this.themeCSSStyle=i;continue}if(i instanceof HTMLStyleElement&&i.hasAttribute("data-unsafe-css")){this.unsafeCSSStyle=i,this.appliedUnsafeCSS=i.textContent;continue}}}this.pre!=null&&(this.syncCodeNodesFromPre(this.pre),this.pre.removeAttribute("data-dehydrated")),this.fileContainer=e,this.hydrateMeasuredScrollbar()}hydrationSetup({fileDiff:e,oldFile:t,newFile:i,lineAnnotations:n}){this.lineAnnotations=n??this.lineAnnotations,this.additionFile=i,this.deletionFile=t,this.fileDiff=e??(t!=null&&i!=null?Q(t,i,this.options.parseDiffOptions):void 0),this.pre!=null&&(this.syncInteractionOptions(),this.hunksRenderer.hydrate(this.fileDiff),this.renderAnnotations(),this.renderGutterUtility(),this.injectUnsafeCSS(),this.managersDirty=!0,this.flushManagers())}rerender(){!this.enabled||this.fileDiff==null&&this.additionFile==null&&this.deletionFile==null||this.render({forceRender:!0,renderRange:this.renderRange})}onThemeChange(){this.hunksRenderer.clearRenderCache(),this.rerender()}handleExpandHunk=(e,t,i)=>{this.expandHunk(e,t,i)};expandHunk=(e,t,i)=>{this.hunksRenderer.expandHunk(e,t,i),this.rerender()};render({oldFile:e,newFile:t,fileDiff:i,deferManagers:n=!1,forceRender:s=!1,preventEmit:r=!1,lineAnnotations:o,fileContainer:a,containerWrapper:l,renderRange:u}){if(!this.enabled)throw new Error("FileDiff.render: attempting to call render after cleaned up");this.editor?.__postponeBackgroundTokenizeToNextFrame();const{collapsed:f=!1,themeType:h="system"}=this.options,d=f?void 0:u,c=this.hasThemeChanged(),g=e!=null&&t!=null&&(!Be(e,this.deletionFile)||!Be(t,this.additionFile));let m=i!=null&&i!==this.fileDiff;const C=o!=null&&(o.length>0||this.lineAnnotations.length>0)?o!==this.lineAnnotations:!1;if(!f&&Xe(d,this.renderRange)&&!s&&!C&&!c&&(i!=null&&i===this.fileDiff||i==null&&!g))return this.applyCachedThemeState(h);const{renderRange:y}=this;if(this.renderRange=d,this.deletionFile=e,this.additionFile=t,i!=null?this.fileDiff=i:e!=null&&t!=null&&g&&(m=!0,this.fileDiff=Q(e,t,this.options.parseDiffOptions)),m&&(this.cachedHeaderHTML=void 0),o!=null&&this.setLineAnnotations(o),this.fileDiff==null)return!1;this.hunksRenderer.setOptions(this.getHunksRendererOptions(this.options)),this.syncInteractionOptions(),this.hunksRenderer.setLineAnnotations(this.lineAnnotations);const{disableErrorHandling:v=!1,disableFileHeader:p=!1}=this.options;if(p&&(this.headerElement!=null&&(this.headerElement.remove(),this.headerElement=void 0,this.lastRenderedHeaderHTML=void 0),this.clearHeaderSlots()),a=this.getOrCreateFileContainer(a,l),this.applyCachedThemeState(h),f){this.removeRenderedCode(),this.clearAuxiliaryNodes();try{const S=this.hunksRenderer.renderDiff(this.fileDiff,zt);S!=null&&this.applyThemeState(a,S.themeStyles,h,S.baseThemeType),S?.headerElement!=null&&this.applyHeaderToDOM(S.headerElement,a),this.renderSeparators([]),this.injectUnsafeCSS()}catch(S){if(v)throw S;console.error(S),S instanceof Error&&this.applyErrorToDOM(S,a)}return r||this.emitPostRender(),!0}try{const S=this.getOrCreatePreNode(a);if(!(this.canPartiallyRender(s,C,g||m||c)&&this.applyPartialRender({previousRenderRange:y,renderRange:d}))){const H=this.hunksRenderer.renderDiff(this.fileDiff,d);if(H==null)return this.workerManager?.isInitialized()===!1&&this.workerManager.initialize().then(()=>this.rerender()),!1;this.applyThemeState(a,H.themeStyles,h,H.baseThemeType),H.headerElement!=null&&this.applyHeaderToDOM(H.headerElement,a),H.additionsContentAST!=null||H.deletionsContentAST!=null||H.unifiedContentAST!=null?this.applyHunksToDOM(S,H):this.pre!=null&&(this.pre.remove(),this.pre=void 0),this.renderSeparators(H.hunkData)}this.applyBuffers(S,d),this.injectUnsafeCSS(),this.renderAnnotations(),this.renderGutterUtility(),this.managersDirty=!0,n||this.flushManagers(),this.editor!=null&&this.syncRenderViewToEditor()}catch(S){if(v)throw S;console.error(S),S instanceof Error&&this.applyErrorToDOM(S,a)}return r||this.emitPostRender(),!0}emitPostRender(e=!1){const{fileContainer:t,options:{onPostRender:i}}=this;if(e){if(!this.mounted||(this.mounted=!1,t==null))return;this.options.onPostRender?.(t,this,"unmount");return}if(t==null)return;const n=this.mounted?"update":"mount";this.mounted=!0,i?.(t,this,n)}syncRenderViewToEditor(){const e=this.editor,t=this.fileContainer,i=this.fileDiff;e!=null&&t!=null&&i!=null&&!i.isPartial&&this.hunksRenderer.initializeHighlighter().then(n=>{e.__syncRenderView(n,t,i,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.hunksRenderer.applyDocumentChange(e);const i=this.hunksRenderer.getRenderDiff();i!=null&&(this.fileDiff=i),this.rerender(),this.interactionManager.setSelectionDirty(),t!==void 0&&t!==this.lineAnnotations&&(this.setLineAnnotations(t),this.hunksRenderer.setLineAnnotations(this.lineAnnotations),this.renderAnnotations())}rerenderFromDocument(e){this.hunksRenderer.applyDocumentChange(e);const t=this.hunksRenderer.getRenderDiff();t!=null&&(this.fileDiff=t),this.hunksRenderer.clearRenderCache(),this.rerender()}updateRenderCache(e,t,i,n){this.hunksRenderer.updateRenderCache(e,t,n),i===!0&&(this.options.diffStyle==="split"?(this.fastRefreshTimeout!=null&&clearTimeout(this.fastRefreshTimeout),this.fastRefreshTimeout=setTimeout(()=>{this.fastRefreshTimeout=void 0,this.fastRefreshDiffView()},100)):this.refreshDiffView())}removeRenderedCode(){this.resizeManager.cleanUp(),this.scrollSyncManager.cleanUp(),this.interactionManager.cleanUp(),this.bufferBefore?.remove(),this.bufferBefore=void 0,this.bufferAfter?.remove(),this.bufferAfter=void 0,this.codeUnified?.remove(),this.codeUnified=void 0,this.codeDeletions?.remove(),this.codeDeletions=void 0,this.codeAdditions?.remove(),this.codeAdditions=void 0,this.pre?.remove(),this.pre=void 0,this.appliedPreAttributes=void 0,this.lastRowCount=void 0}clearAuxiliaryNodes(){for(const{element:e}of this.separatorCache.values())e.remove();this.separatorCache.clear();for(const{element:e}of this.annotationCache.values())e.remove();this.annotationCache.clear(),this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0}renderPlaceholder(e){if(this.fileContainer==null)return!1;if(this.emitPostRender(!0),this.cleanChildNodes(),this.placeHolder==null){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{fileDiff:e,workerManager:t}=this;if(e==null||t==null||be(e))return;const i=this.options.tokenizeMaxLength??1e5;Math.max(e.additionLines.length,e.deletionLines.length)>i||t.primeDiffHighlightCache(e)}cleanChildNodes(){this.resizeManager.cleanUp(),this.scrollSyncManager.cleanUp(),this.interactionManager.cleanUp(),this.clearAuxiliaryNodes(),this.bufferAfter?.remove(),this.bufferBefore?.remove(),this.codeAdditions?.remove(),this.codeDeletions?.remove(),this.codeUnified?.remove(),this.errorWrapper?.remove(),this.headerElement?.remove(),this.headerPrefix?.remove(),this.headerFilenameSuffix?.remove(),this.headerMetadata?.remove(),this.headerCustom?.remove(),this.pre?.remove(),this.spriteSVG?.remove(),this.themeCSSStyle?.remove(),this.unsafeCSSStyle?.remove(),this.bufferAfter=void 0,this.bufferBefore=void 0,this.codeAdditions=void 0,this.codeDeletions=void 0,this.codeUnified=void 0,this.errorWrapper=void 0,this.headerElement=void 0,this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0,this.headerCustom=void 0,this.pre=void 0,this.spriteSVG=void 0,this.themeCSSStyle=void 0,this.appliedThemeCSS=void 0,this.hasAdoptedThemeCSS=!1,this.unsafeCSSStyle=void 0,this.appliedUnsafeCSS=void 0,this.lastRenderedHeaderHTML=void 0,this.lastRowCount=void 0,this.mounted=!1}renderSeparators(e){const{hunkSeparators:t}=this.options;if(this.isContainerManaged||this.fileContainer==null||typeof t!="function"){for(const{element:n}of this.separatorCache.values())n.remove();this.separatorCache.clear();return}const i=new Map(this.separatorCache);for(const n of e){const s=n.slotName;let r=this.separatorCache.get(s);if(r==null||!ri(n,r.hunkData)){r?.element.remove();const o=document.createElement("div");o.style.display="contents",o.slot=n.slotName;const a=t(n,this);a!=null&&o.appendChild(a),this.fileContainer.appendChild(o),r={element:o,hunkData:n},this.separatorCache.set(s,r)}i.delete(s)}for(const[n,{element:s}]of i.entries())this.separatorCache.delete(n),s.remove()}renderAnnotations(){if(this.isContainerManaged||this.fileContainer==null){for(const{element:i}of this.annotationCache.values())i.remove();this.annotationCache.clear();return}const e=new Map(this.annotationCache),{renderAnnotation:t}=this.options;if(t!=null&&this.lineAnnotations.length>0)for(const[i,n]of this.lineAnnotations.entries()){const s=`${i}-${he(n)}`;let r=this.annotationCache.get(s);if(r==null||!si(n,r.annotation)){r?.element.remove();const o=t(n);if(o==null)continue;r={element:lt(he(n)),annotation:n},r.element.appendChild(o),this.fileContainer.appendChild(r.element),this.annotationCache.set(s,r)}e.delete(s)}for(const[i,{element:n}]of e.entries())this.annotationCache.delete(i),n.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 i=ht();i.appendChild(t),this.fileContainer.appendChild(i),this.gutterUtilityContent=i}getOrCreateFileContainer(e,t){const{fileContainer:i}=this,n=e??i??document.createElement("diffs-container"),s=i!==n;return s&&this.emitPostRender(!0),this.fileContainer=n,i!=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 i of t.children)i instanceof SVGElement?this.spriteSVG??=i:Pe(i)&&i.hasAttribute("data-theme-css")?(this.themeCSSStyle??=i,this.hasAdoptedThemeCSS=!0):Pe(i)&&i.hasAttribute("data-unsafe-css")&&(this.unsafeCSSStyle??=i,this.appliedUnsafeCSS??=this.options.unsafeCSS??void 0)}ensureSpriteSVG(e){const t=e.shadowRoot??e.attachShadow({mode:"open"});if(this.spriteSVG==null){const i=document.createElement("div");i.innerHTML=dt;const n=i.firstChild;n instanceof SVGElement&&(this.spriteSVG=n)}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.codeUnified=void 0,this.codeDeletions=void 0,this.codeAdditions=void 0,t.appendChild(this.pre)):this.pre.parentNode!==t&&(t.appendChild(this.pre),this.appliedPreAttributes=void 0),this.placeHolder?.remove(),this.placeHolder=void 0,this.pre}syncCodeNodesFromPre(e){this.codeUnified=void 0,this.codeDeletions=void 0,this.codeAdditions=void 0;for(const t of Array.from(e.children))t instanceof HTMLElement&&(t.hasAttribute("data-unified")?this.codeUnified=t:t.hasAttribute("data-deletions")?this.codeDeletions=t:t.hasAttribute("data-additions")&&(this.codeAdditions=t))}applyHeaderToDOM(e,t){this.cleanupErrorWrapper(),this.placeHolder?.remove(),this.placeHolder=void 0;const{fileDiff:i}=this,n=this.cachedHeaderHTML??le(e);if(this.cachedHeaderHTML=n,n!==this.lastRenderedHeaderHTML){const h=document.createElement("div");h.innerHTML=n;const d=h.firstElementChild;if(!(d instanceof HTMLElement))return;this.headerElement!=null?t.shadowRoot?.replaceChild(d,this.headerElement):t.shadowRoot?.prepend(d),this.headerElement=d,this.lastRenderedHeaderHTML=n}if(this.isContainerManaged||i==null)return;const{renderCustomHeader:s,renderHeaderPrefix:r,renderHeaderFilenameSuffix:o,renderHeaderMetadata:a}=this.options;if(s!=null){const h=s(i)??void 0;this.headerCustom=this.upsertHeaderSlotElement(t,this.headerCustom,Ft,h),this.headerPrefix?.remove(),this.headerFilenameSuffix?.remove(),this.headerMetadata?.remove(),this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0;return}const l=r?.(i)??void 0,u=o?.(i)??void 0,f=a?.(i)??void 0;this.headerPrefix=this.upsertHeaderSlotElement(t,this.headerPrefix,Nt,l),this.headerFilenameSuffix=this.upsertHeaderSlotElement(t,this.headerFilenameSuffix,Ut,u),this.headerMetadata=this.upsertHeaderSlotElement(t,this.headerMetadata,Pt,f),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,i,n){if(n==null){t?.remove();return}const s=t??this.createHeaderSlotElement(i);return t==null&&e.appendChild(s),this.replaceHeaderSlotContent(s,n),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}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??=ut(),this.unsafeCSSStyle.parentNode!==t&&t.appendChild(this.unsafeCSSStyle),this.unsafeCSSStyle.textContent=ft(e),this.appliedUnsafeCSS=e)}}applyThemeState(e,t,i,n){const s=e.shadowRoot??e.attachShadow({mode:"open"}),r=n??i,o=this.options.theme??_,a=typeof o=="string"?o:{...o},l=Oe(s);if(this.themeCSSStyle?.parentNode===s&&this.appliedThemeCSS?.themeStyles===t&&this.appliedThemeCSS.themeType===r&&this.appliedThemeCSS.scrollbarGutter===l){this.appliedThemeCSS.theme=a;return}if(this.hasAdoptedThemeCSS&&this.themeCSSStyle?.parentNode===s){this.hasAdoptedThemeCSS=!1,this.appliedThemeCSS={theme:a,themeStyles:t,themeType:r,baseThemeType:n,scrollbarGutter:l};return}this.themeCSSStyle=ct({shadowRoot:s,currentNode:this.themeCSSStyle,themeCSS:Ct(t,r,l)}),this.appliedThemeCSS=this.themeCSSStyle!=null?{theme:a,themeStyles:t,themeType:r,baseThemeType:n,scrollbarGutter:l}:void 0}hydrateMeasuredScrollbar(){const e=this.fileContainer?.shadowRoot;e==null||this.themeCSSStyle==null||(this.themeCSSStyle.textContent=pt(this.themeCSSStyle.textContent??"",Oe(e)))}applyHunksToDOM(e,t){const{overflow:i="scroll"}=this.options,n=(this.options.hunkSeparators??"line-info")==="line-info",s=i==="wrap"?t.rowCount:void 0;this.cleanupErrorWrapper(),this.applyPreNodeAttributes(e,t);let r=!1;const o=[],a=this.hunksRenderer.renderCodeAST("unified",t),l=this.hunksRenderer.renderCodeAST("deletions",t),u=this.hunksRenderer.renderCodeAST("additions",t);a!=null?(r=this.codeUnified==null||this.codeAdditions!=null||this.codeDeletions!=null,this.codeDeletions?.remove(),this.codeDeletions=void 0,this.codeAdditions?.remove(),this.codeAdditions=void 0,this.codeUnified=Ae({code:this.codeUnified,columnType:"unified",rowSpan:s,containerSize:n}),this.codeUnified.innerHTML=this.hunksRenderer.renderPartialHTML(a),o.push(this.codeUnified)):l!=null||u!=null?(l!=null?(r=this.codeDeletions==null||this.codeUnified!=null,this.codeUnified?.remove(),this.codeUnified=void 0,this.codeDeletions=Ae({code:this.codeDeletions,columnType:"deletions",rowSpan:s,containerSize:n}),this.codeDeletions.innerHTML=this.hunksRenderer.renderPartialHTML(l),o.push(this.codeDeletions)):(this.codeDeletions?.remove(),this.codeDeletions=void 0),u!=null?(r=r||this.codeAdditions==null||this.codeUnified!=null,this.codeUnified?.remove(),this.codeUnified=void 0,this.codeAdditions=Ae({code:this.codeAdditions,columnType:"additions",rowSpan:s,containerSize:n}),this.codeAdditions.innerHTML=this.hunksRenderer.renderPartialHTML(u),o.push(this.codeAdditions)):(this.codeAdditions?.remove(),this.codeAdditions=void 0)):(this.codeUnified?.remove(),this.codeUnified=void 0,this.codeDeletions?.remove(),this.codeDeletions=void 0,this.codeAdditions?.remove(),this.codeAdditions=void 0),o.length===0?e.textContent="":r&&e.replaceChildren(...o),this.lastRowCount=t.rowCount}applyPartialRender({previousRenderRange:e,renderRange:t}){const{pre:i,codeUnified:n,codeAdditions:s,codeDeletions:r,options:{diffStyle:o="split"}}=this;if(i==null||e==null||t==null||!Number.isFinite(e.totalLines)||!Number.isFinite(t.totalLines)||this.lastRowCount==null)return!1;const a=this.getCodeColumns(o,n,r,s);if(a==null)return!1;const l=e.startingLine,u=t.startingLine,f=l+e.totalLines,h=u+t.totalLines,d=Math.max(l,u),c=Math.min(f,h);if(c<=d)return!1;const g=Math.max(0,d-l),m=Math.max(0,f-c),C=this.trimColumns({columns:a,trimStart:g,trimEnd:m,previousStart:l,overlapStart:d,overlapEnd:c,diffStyle:o});if(C<0)throw new Error("applyPartialRender: failed to trim to overlap");if(this.lastRowCount<C)throw new Error("applyPartialRender: trimmed beyond DOM row count");let y=this.lastRowCount-C;const v=(T,F)=>{if(!(F<=0||this.fileDiff==null))return this.hunksRenderer.renderDiff(this.fileDiff,{startingLine:T,totalLines:F,bufferBefore:0,bufferAfter:0})},p=v(u,Math.max(d-u,0));if(p==null&&u<d)return!1;const S=v(c,Math.max(h-c,0));if(S==null&&h>c)return!1;const H=(T,F)=>{if(T!=null){if(o==="unified"&&!Array.isArray(a))this.insertPartialHTML(o,a,T,F);else if(o==="split"&&Array.isArray(a))this.insertPartialHTML(o,a,T,F);else throw new Error("FileDiff.applyPartialRender.applyChunk: invalid chunk application");y+=T.rowCount}};return this.cleanupErrorWrapper(),H(p,"afterbegin"),H(S,"beforeend"),this.lastRowCount!==y&&(this.applyRowSpan(o,a,y),this.lastRowCount=y),!0}insertPartialHTML(e,t,i,n){if(e==="unified"&&!Array.isArray(t)){const s=this.hunksRenderer.renderCodeAST("unified",i);this.renderPartialColumn(t,s,n)}else if(e==="split"&&Array.isArray(t)){const s=this.hunksRenderer.renderCodeAST("deletions",i),r=this.hunksRenderer.renderCodeAST("additions",i);this.renderPartialColumn(t[0],s,n),this.renderPartialColumn(t[1],r,n)}else throw new Error("FileDiff.insertPartialHTML: Invalid argument composition")}fastRefreshDiffView(){if(this.options.diffStyle!=="split")return;const e=this.hunksRenderer.renderDiff(this.fileDiff,this.renderRange);if(e==null)return;const t=this.getCodeColumns("split",this.codeUnified,this.codeDeletions,this.codeAdditions);if(!Array.isArray(t))return;const i=(n,s)=>{if(s==null)return;const r=this.hunksRenderer.renderCodeAST(n,e),o=X(r?.[0]),a=X(r?.[1]);for(const[l,u]of[[s.gutter,o],[s.content,a]])if(u!=null&&l.childElementCount===u.length)for(let f=0;f<u.length;f++){const h=l.children[f],d=u[f].properties["data-line-type"];d!=null&&h.dataset.lineType!==d&&(h.dataset.lineType=d)}};i("deletions",t[0]),i("additions",t[1])}refreshDiffView(){const e=this.hunksRenderer.renderDiff(this.fileDiff,this.renderRange);if(e==null)return;const t=this.getCodeColumns(this.options.diffStyle??"split",this.codeUnified,this.codeDeletions,this.codeAdditions);if(t==null)return;const i=(n,s)=>{if(s==null)return;const r=this.hunksRenderer.renderCodeAST(n,e),o=X(r?.[0]),a=X(r?.[1]);for(const[l,u]of[[s.gutter,o],[s.content,a]])u!=null&&(l.innerHTML=le(u))};Array.isArray(t)?(i("deletions",t[0]),i("additions",t[1])):i("unified",t),this.syncRenderViewToEditor()}renderPartialColumn(e,t,i){if(e==null||t==null)return;const n=X(t[0]),s=X(t[1]);if(n==null||s==null)throw new Error("FileDiff.insertPartialHTML: Unexpected AST structure");const r=s.at(0);i==="beforeend"&&r?.type==="element"&&typeof r.properties["data-buffer-size"]=="number"&&this.mergeBuffersIfNecessary(r.properties["data-buffer-size"],e.content.children[e.content.children.length-1],e.gutter.children[e.gutter.children.length-1],n,s,!0);const o=s.at(-1);i==="afterbegin"&&o?.type==="element"&&typeof o.properties["data-buffer-size"]=="number"&&this.mergeBuffersIfNecessary(o.properties["data-buffer-size"],e.content.children[0],e.gutter.children[0],n,s,!1),e.gutter.insertAdjacentHTML(i,this.hunksRenderer.renderPartialHTML(n)),e.content.insertAdjacentHTML(i,this.hunksRenderer.renderPartialHTML(s))}mergeBuffersIfNecessary(e,t,i,n,s,r){if(!(t instanceof HTMLElement)||!(i instanceof HTMLElement))return;const o=this.getBufferSize(t.dataset);o!=null&&(r?(n.shift(),s.shift()):(n.pop(),s.pop()),this.updateBufferSize(t,o+e),this.updateBufferSize(i,o+e))}applyRowSpan(e,t,i){const n=s=>{s!=null&&(s.gutter.style.setProperty("grid-row",`span ${i}`),s.content.style.setProperty("grid-row",`span ${i}`))};if(e==="unified"&&!Array.isArray(t))n(t);else if(e==="split"&&Array.isArray(t))n(t[0]),n(t[1]);else throw new Error("dun fuuuuked up")}trimColumnRows(e,t,i){let n=0,s=0,r=0,o=!1;const a=i>=0;if(e==null)return 0;const l=Array.from(e.content.children),u=Array.from(e.gutter.children);if(l.length!==u.length)throw new Error("FileDiff.trimColumnRows: columns do not match");for(;r<l.length&&!(t<=0&&!a&&!o);){const f=u[r],h=l[r];if(r++,!(f instanceof HTMLElement)||!(h instanceof HTMLElement))throw console.error({gutterElement:f,contentElement:h}),new Error("FileDiff.trimColumnRows: invalid row elements");if(o&&(o=!1,f.dataset.gutterBuffer==="annotation"&&"lineAnnotation"in h.dataset||f.dataset.gutterBuffer==="metadata"&&"noNewline"in h.dataset)){f.remove(),h.remove(),s++;continue}if("lineIndex"in f.dataset&&"lineIndex"in h.dataset){(t>0||a&&n>=i)&&(f.remove(),h.remove(),t>0&&(t--,t===0&&(o=!0)),s++),n++;continue}if("separator"in f.dataset&&"separator"in h.dataset){(t>0||a&&n>=i)&&(f.remove(),h.remove(),s++);continue}if(f.dataset.gutterBuffer==="annotation"&&"lineAnnotation"in h.dataset){(t>0||a&&n>=i)&&(f.remove(),h.remove(),s++);continue}if(f.dataset.gutterBuffer==="metadata"&&"noNewline"in h.dataset){(t>0||a&&n>=i)&&(f.remove(),h.remove(),s++);continue}if(f.dataset.gutterBuffer==="buffer"&&"contentBuffer"in h.dataset){const d=this.getBufferSize(h.dataset);if(d==null)throw new Error("FileDiff.trimColumnRows: invalid element");if(t>0){const c=Math.min(t,d),g=d-c;g>0?(this.updateBufferSize(f,g),this.updateBufferSize(h,g),s+=c):(f.remove(),h.remove(),s+=d),t-=c,t===0&&g===0&&(o=!0)}else if(a){const c=n,g=n+d-1;if(i<=c)f.remove(),h.remove(),s+=d;else if(i<=g){const m=g-i+1,C=d-m;this.updateBufferSize(f,C),this.updateBufferSize(h,C),s+=m}}n+=d;continue}throw console.error({gutterElement:f,contentElement:h}),new Error("FileDiff.trimColumnRows: unknown row elements")}return s}trimColumns({columns:e,diffStyle:t,overlapEnd:i,overlapStart:n,previousStart:s,trimEnd:r,trimStart:o}){const a=Math.max(0,n-s),l=i-s;if(l<0)throw new Error("FileDiff.trimColumns: overlap ends before previous");const u=o>0,f=r>0;if(!u&&!f)return 0;const h=u?a:0,d=f?l:-1;if(t==="unified"&&!Array.isArray(e))return this.trimColumnRows(e,h,d);if(t==="split"&&Array.isArray(e)){const c=this.trimColumnRows(e[0],h,d),g=this.trimColumnRows(e[1],h,d);if(e[0]!=null&&e[1]!=null&&c!==g)throw new Error("FileDiff.trimColumns: split columns out of sync");return e[0]!=null?c:g}else throw console.error({diffStyle:t,columns:e}),new Error("FileDiff.trimColumns: Invalid columns for diffType")}getBufferSize(e){const t=Number.parseInt(e?.bufferSize??"",10);return Number.isNaN(t)?void 0:t}updateBufferSize(e,t){e.dataset.bufferSize=`${t}`,e.style.setProperty("grid-row",`span ${t}`),e.style.setProperty("min-height",`calc(${t} * 1lh)`)}getCodeColumns(e,t,i,n){function s(r){if(r==null)return;const o=r.children[0],a=r.children[1];if(!(!(o instanceof HTMLElement)||!(a instanceof HTMLElement)||o.dataset.gutter==null||a.dataset.content==null))return{gutter:o,content:a}}if(e==="unified")return s(t);{const r=s(i),o=s(n);return r!=null||o!=null?[r,o]:void 0}}updateBuffers(e){this.pre!=null&&this.applyBuffers(this.pre,e)}applyBuffers(e,t){if(t==null||this.shouldDisableVirtualizationBuffers()){this.bufferBefore!=null&&(this.bufferBefore.remove(),this.bufferBefore=void 0),this.bufferAfter!=null&&(this.bufferAfter.remove(),this.bufferAfter=void 0);return}t.bufferBefore>0?(this.bufferBefore==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}applyPreNodeAttributes(e,{additionsContentAST:t,deletionsContentAST:i,totalLines:n},s){const{diffIndicators:r="bars",disableBackground:o=!1,disableLineNumbers:a=!1,overflow:l="scroll",diffStyle:u="split"}=this.options,f={type:"diff",diffIndicators:r,disableBackground:o,disableLineNumbers:a,overflow:l,split:u==="unified"?!1:t!=null&&i!=null,totalLines:n,customProperties:s};gt(f,this.appliedPreAttributes)||(mt(e,f),this.appliedPreAttributes=f)}applyErrorToDOM(e,t){this.cleanupErrorWrapper(),this.pre?.remove(),this.pre=void 0,this.appliedPreAttributes=void 0;const i=t.shadowRoot??t.attachShadow({mode:"open"});this.errorWrapper??=document.createElement("div"),this.errorWrapper.dataset.errorWrapper="",this.errorWrapper.textContent="",i.appendChild(this.errorWrapper);const n=document.createElement("div");n.dataset.errorMessage="",n.innerText=e.message,this.errorWrapper.appendChild(n);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 hi({fileDiff:e,oldFile:t,newFile:i}){return e!=null&&e.hunks.length>0||t!=null||i!=null}function di({fileDiff:e,oldFile:t,newFile:i}){return e!=null||t!=null||i!=null}function ui(e,t,i=!1){return!i&&e==null&&t}function fi(e,t,i=!1){return e==null&&t&&!i}function X(e){if(!(e==null||e.type!=="element"))return e.children??[]}function ci({fileDiff:e,metrics:t,disableFileHeader:i,hunkSeparators:n,expandUnchanged:s,expandedHunks:r,collapsedContextThreshold:o}){let a=Y(t,i),l=a;const u=s?!0:r,f=e.hunks.length-1;for(let h=0;h<e.hunks.length;h++){const d=e.hunks[h];if(d==null)throw new Error("computeEstimatedDiffHeights: invalid hunk index");const c=we({isPartial:e.isPartial,rangeSize:d.collapsedBefore,expandedHunks:u,hunkIndex:h,collapsedContextThreshold:o}),g=(c.fromStart+c.fromEnd)*t.lineHeight;if(a+=g,l+=g,c.collapsedLines>0){const y=oe({type:n,metrics:t,hunkIndex:h,hunkSpecs:d.hunkSpecs})?.totalHeight??0;a+=y,l+=y}a+=d.splitLineCount*t.lineHeight,l+=d.unifiedLineCount*t.lineHeight;const m=pi(d);a+=m.split*t.lineHeight,l+=m.unified*t.lineHeight;const C=h===f?Me({fileDiff:e,hunkIndex:h,expandedHunks:u,collapsedContextThreshold:o,errorPrefix:"computeEstimatedDiffHeights"}):void 0;if(C!=null){const y=(C.fromStart+C.fromEnd)*t.lineHeight;if(a+=y,l+=y,C.collapsedLines>0){const v=ae({type:n,metrics:t})?.totalHeight??0;a+=v,l+=v}}}if(e.hunks.length>0){const h=Qe(t);a+=h,l+=h}return{splitHeight:a,unifiedHeight:l}}function pi(e){if(!e.noEOFCRAdditions&&!e.noEOFCRDeletions)return{split:0,unified:0};const t=e.hunkContent.at(-1);if(t==null)return{split:0,unified:0};if(t.type==="context"){const i=t.lines>0?1:0;return{split:i,unified:i}}return gi(e,t)}function gi(e,t){const i=(t.deletions>0&&e.noEOFCRDeletions?1:0)+(t.additions>0&&e.noEOFCRAdditions?1:0),n=t.deletions>0&&e.noEOFCRDeletions,s=t.additions>0&&e.noEOFCRAdditions;return{split:n||s?1:0,unified:i}}const ze=5e3;let mi=-1;var Mi=class extends li{__id=`little-virtualized-file-diff:${++mi}`;top;height=0;metrics;cache={heightDeltas:new Map,measuredHeightDeltaTotal:0,estimatedSplitHeight:void 0,estimatedUnifiedHeight:void 0,checkpoints:[],totalLines:0,fileAnnotationHeight:0};isVisible=!1;isSetup=!1;virtualizer;layoutDirty=!0;forceRenderOverride;currentCollapsed;constructor(e,t,i,n,s=!1){super(e,n,s),this.virtualizer=t,this.metrics=Re(i)}setMetrics(e,t=!1){const i=Re(e);!t&&St(this.metrics,i)||(this.metrics=i,this.resetLayoutCache({includeEstimatedHeights:!0}))}setLineAnnotations(e){this.syncLineAnnotations(e)&&this.resetLayoutCache({includeEstimatedHeights:!1})}syncLineAnnotations(e){return e==null||e===this.lineAnnotations||e.length===0&&this.lineAnnotations.length===0?!1:(super.setLineAnnotations(e),!0)}setFileAnnotationHeight(e){const t=this.cache.fileAnnotationHeight;return e===t?!1:(this.cache.fileAnnotationHeight=e,this.cache.measuredHeightDeltaTotal+=e-t,!0)}hasFileAnnotations(e=this.fileDiff){return e==null||!vt(this.lineAnnotations)?!1:this.lineAnnotations.some(t=>t.lineNumber!==0?!1:e.type==="new"?t.side==="additions":e.type==="deleted"?t.side==="deletions":!0)}getLineHeight(e,t=!1){return this.getEstimatedLineHeight(t)+(this.cache.heightDeltas.get(e)??0)}getEstimatedLineHeight(e=!1){const t=e?2:1;return this.metrics.lineHeight*t}setOptions(e){if(this.isAdvancedMode())throw new Error("VirtualizedFileDiff.setOptions cannot be used inside CodeView. Update CodeView options instead.");if(e==null)return;const{options:t}=this,i=!yt(t,e),n=i&&Li(t,e);super.setOptions(e),n&&this.resetLayoutCache({forceSimpleRecompute:!0,includeEstimatedHeights:Ti(t,e)}),i&&(this.forceRenderOverride=!0),i&&this.isSimpleMode()&&this.virtualizer.instanceChanged(this,n)}setThemeType(e){if(this.isAdvancedMode())throw new Error("VirtualizedFileDiff.setThemeType cannot be used inside CodeView. Update CodeView options instead.");super.setThemeType(e)}resetLayoutCache({forceSimpleRecompute:e=!1,includeEstimatedHeights:t=!1}={}){this.layoutDirty=!0,this.cache.fileAnnotationHeight=0,this.cache.heightDeltas.size>0&&this.cache.heightDeltas.clear(),this.cache.measuredHeightDeltaTotal!==0&&(this.cache.measuredHeightDeltaTotal=0),this.cache.checkpoints.length>0&&(this.cache.checkpoints.length=0),this.cache.totalLines!==0&&(this.cache.totalLines=0),t&&(this.cache.estimatedSplitHeight=void 0,this.cache.estimatedUnifiedHeight=void 0),this.renderRange!=null&&(this.renderRange=void 0),e&&this.isSimpleMode()&&this.computeApproximateSize()}reconcileHeights(){let e=!1;const{overflow:t="scroll"}=this.options;if(this.fileContainer==null||this.fileDiff==null)return this.height!==0&&(e=!0),this.height=0,e;if(this.top=this.getVirtualizedTop(),t==="scroll"&&this.lineAnnotations.length===0&&!this.isResizeDebuggingEnabled())return e;const i=this.getDiffStyle(),n=i==="split"?[this.codeDeletions,this.codeAdditions]:[this.codeUnified],s=this.hasFileAnnotations(this.fileDiff);if(this.renderRange!=null&&s&&Ye(this.renderRange)){const r=Ci(n)??0;this.setFileAnnotationHeight(r)&&(e=!0)}else!s&&this.setFileAnnotationHeight(0)&&(e=!0);for(const r of n){if(r==null)continue;const o=r.children[1];if(o instanceof HTMLElement)for(const a of o.children){if(!(a instanceof HTMLElement))continue;const l=a.dataset.lineIndex;if(l==null)continue;const u=ki(l,i);let f=a.getBoundingClientRect().height,h=!1;a.nextElementSibling instanceof HTMLElement&&("lineAnnotation"in a.nextElementSibling.dataset||"noNewline"in a.nextElementSibling.dataset)&&("noNewline"in a.nextElementSibling.dataset&&(h=!0),f+=a.nextElementSibling.getBoundingClientRect().height);const d=this.getEstimatedLineHeight(h),c=this.cache.heightDeltas.get(u)??0,g=f-d;g!==c&&(e=!0,this.cache.measuredHeightDeltaTotal+=g-c,g===0?this.cache.heightDeltas.delete(u):this.cache.heightDeltas.set(u,g))}}return(e||this.isResizeDebuggingEnabled())&&this.computeApproximateSize(!0),e}onRender=e=>this.fileContainer==null?!1:(e&&(this.top=this.getVirtualizedTop()),this.render());prepareCodeViewItem(e,t,i,n){const s=!re(this.fileDiff,e),r=this.syncLineAnnotations(n);let o=i?.resetDiffLayoutCache===!0||s||r,a=s||i?.resetDiffLayoutCache===!0&&i.includeEstimatedDiffHeights;i?.metrics!=null&&(this.metrics=Re(i.metrics),o=!0,a=!0);const{collapsed:l=!1}=this.options;return this.currentCollapsed!==l&&(this.currentCollapsed=l,o=!0),o&&this.resetLayoutCache({includeEstimatedHeights:a}),this.fileDiff=e,this.top=t,this.computeApproximateSize(),this.height}getLinePosition(e,t="additions"){if(this.fileDiff==null||e<1)return;const i=this.getLineIndex(e,t);if(i==null)return;const{disableFileHeader:n=!1,expandUnchanged:s=!1,collapsed:r=!1,collapsedContextThreshold:o=1}=this.options,a=this.getDiffStyle(),l=this.getHunkSeparatorType(),u=a==="split"?i[1]:i[0];this.approximateLayoutCheckpoints();const f=Y(this.metrics,n),h=this.getLayoutCheckpointBeforeLineIndex(u);let d=h?.top??f+this.cache.fileAnnotationHeight;if(r)return{top:f,height:0};let c;return ve({diff:this.fileDiff,diffStyle:a,startingLine:h?.renderedLineIndex??0,expandedHunks:s?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:o,callback:({hunkIndex:g,hunk:m,collapsedBefore:C,collapsedAfter:y,deletionLine:v,additionLine:p})=>{const S=a==="split"?p?.splitLineIndex??v?.splitLineIndex:p?.unifiedLineIndex??v?.unifiedLineIndex;if(S==null)throw new Error("VirtualizedFileDiff.getLinePosition: missing line index data");if(C>0){const T=oe({type:l,metrics:this.metrics,hunkIndex:g,hunkSpecs:m?.hunkSpecs});if(T!=null){if(d+=T.gapBefore,u>=S-C&&u<S)return c={top:d,height:T.height},!0;d+=T.height+T.gapAfter}}const H=this.getLineHeight(S,(p?.noEOFCR??!1)||(v?.noEOFCR??!1));if(S===u)return c={top:d,height:H},!0;if(d+=H,y>0){const T=ae({type:l,metrics:this.metrics});if(T!=null){if(u>S&&u<=S+y)return c={top:d+T.gapBefore,height:T.height},!0;d+=T.totalHeight}}return!1}}),c}getNumericScrollAnchor(e){if(this.fileDiff==null)return;const{disableFileHeader:t=!1,expandUnchanged:i=!1,collapsed:n=!1,collapsedContextThreshold:s=1}=this.options;if(n)return;const r=this.getDiffStyle(),o=this.getHunkSeparatorType();this.approximateLayoutCheckpoints();const a=this.getLayoutCheckpointBeforeTop(e);let l=a?.top??Y(this.metrics,t)+this.cache.fileAnnotationHeight,u;return ve({diff:this.fileDiff,diffStyle:r,startingLine:a?.renderedLineIndex??0,expandedHunks:i?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:s,callback:({hunkIndex:f,hunk:h,collapsedBefore:d,collapsedAfter:c,deletionLine:g,additionLine:m})=>{const C=r==="split"?m?.splitLineIndex??g?.splitLineIndex:m?.unifiedLineIndex??g?.unifiedLineIndex;if(C==null)throw new Error("VirtualizedFileDiff.getNumericScrollAnchor: missing line index data");if(d>0){const v=oe({type:o,metrics:this.metrics,hunkIndex:f,hunkSpecs:h?.hunkSpecs});v!=null&&(l+=v.totalHeight)}if(l>=e&&(g!=null?u={lineNumber:g.lineNumber,side:"deletions",top:l}:m!=null&&(u={lineNumber:m.lineNumber,side:"additions",top:l}),u!=null))return!0;const y=this.getLineHeight(C,(m?.noEOFCR??!1)||(g?.noEOFCR??!1));if(l+=y,c>0){const v=ae({type:o,metrics:this.metrics});v!=null&&(l+=v.totalHeight)}return!1}}),u}getVirtualizedHeight(){return this.height}getAdvancedStickySpecs(e){if(this.top==null||this.fileDiff==null)return;if(this.options.collapsed===!0)return{topOffset:this.top,height:this.height};const t=e!=null?this.computeRenderRangeFromWindow(this.fileDiff,this.top,e):this.renderRange;if(t==null)return;const{bufferBefore:i,bufferAfter:n,totalLines:s}=t;let r=0;if(s===0){const o=e??this.virtualizer.getWindowSpecs();this.top<o.top&&(r=n)}return{topOffset:this.top+i+r,height:this.height-(i+n)}}cleanUp(e=!1){this.fileContainer!=null&&this.isSimpleMode()&&this.getSimpleVirtualizer()?.disconnect(this.fileContainer),e||this.resetLayoutCache({includeEstimatedHeights:!0}),this.isSetup=!1,super.cleanUp(e)}expandHunk=(e,t,i)=>{this.hunksRenderer.expandHunk(e,t,i),this.forceRenderOverride=!0,this.resetLayoutCache({includeEstimatedHeights:!0}),this.isSimpleMode()&&this.computeApproximateSize(),this.virtualizer.instanceChanged(this,!0)};setVisibility(e){this.isAdvancedMode()||this.fileContainer==null||(this.renderRange=void 0,e&&!this.isVisible?(this.top=this.getVirtualizedTop(),this.isVisible=!0):!e&&this.isVisible&&(this.isVisible=!1,this.rerender()))}rerender(){!this.enabled||this.fileDiff==null&&this.additionFile==null&&this.deletionFile==null||(this.forceRenderOverride=!0,this.virtualizer.instanceChanged(this,!1))}applyDocumentChange(e,t,i=!1){const n=this.renderRange;if(super.applyDocumentChange(e,t),this.getSimpleVirtualizer()?.markDOMDirty(),this.resetLayoutCache({forceSimpleRecompute:this.isSimpleMode(),includeEstimatedHeights:!0}),i&&n!==void 0&&this.fileDiff!==void 0){const s=this.virtualizer.getWindowSpecs(),r=this.computeRenderRangeFromWindow(this.fileDiff,this.top??0,s);r.bufferAfter!==n.bufferAfter&&this.updateBuffers(r)}}computeApproximateSize(e=!1){const t=this.isResizeDebuggingEnabled();if(!e&&!this.layoutDirty&&!t)return;const i=this.height===0;if(this.height=0,this.cache.checkpoints=[],this.cache.totalLines=0,this.fileDiff==null){this.layoutDirty=!1;return}const{disableFileHeader:n=!1,collapsed:s=!1}=this.options,r=Y(this.metrics,n);if(this.height+=r,s){this.layoutDirty=!1;return}this.height=this.getActiveEstimatedHeight()+this.cache.measuredHeightDeltaTotal,t&&!i&&this.validateComputedHeight(),this.layoutDirty=!1}getActiveEstimatedHeight(){this.ensureEstimatedDiffHeights();const e=this.getDiffStyle()==="split"?this.cache.estimatedSplitHeight:this.cache.estimatedUnifiedHeight;if(e==null)throw new Error("VirtualizedFileDiff.getActiveEstimatedHeight: missing estimated height");return e}ensureEstimatedDiffHeights(){if(this.fileDiff==null){this.cache.estimatedSplitHeight=void 0,this.cache.estimatedUnifiedHeight=void 0;return}if(this.cache.estimatedSplitHeight!=null&&this.cache.estimatedUnifiedHeight!=null)return;const{disableFileHeader:e=!1,expandUnchanged:t=!1,collapsedContextThreshold:i=1}=this.options,{splitHeight:n,unifiedHeight:s}=ci({fileDiff:this.fileDiff,metrics:this.metrics,disableFileHeader:e,hunkSeparators:this.getHunkSeparatorType(),expandUnchanged:t,expandedHunks:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:i});this.cache.estimatedSplitHeight=n,this.cache.estimatedUnifiedHeight=s}validateComputedHeight(){if(this.fileContainer==null||this.fileDiff==null)return;const e=this.fileContainer.getBoundingClientRect();e.height!==this.height?console.log("VirtualizedFileDiff.computeApproximateSize: computed height doesnt match",{name:this.fileDiff.name,elementHeight:e.height,computedHeight:this.height}):console.log("VirtualizedFileDiff.computeApproximateSize: computed height IS CORRECT")}render({fileContainer:e,oldFile:t,newFile:i,fileDiff:n,forceRender:s=!1,lineAnnotations:r,...o}={}){const{forceRenderOverride:a,isSetup:l}=this;this.forceRenderOverride=void 0;const u=this.syncLineAnnotations(r);if(u&&this.resetLayoutCache({includeEstimatedHeights:!1}),this.fileDiff??=n??(t!=null&&i!=null?Q(t,i,this.options.parseDiffOptions):void 0),e=this.getOrCreateFileContainer(e),this.fileDiff==null)return console.error("VirtualizedFileDiff.render: attempting to virtually render when we dont have the correct data"),!1;if(l)this.top??=this.getVirtualizedTop();else{this.computeApproximateSize();const c=this.getSimpleVirtualizer();if(this.top??=this.getVirtualizedTop(),this.isAdvancedMode())this.isVisible=!0;else{if(c==null)throw new Error("VirtualizedFileDiff.render: simple virtualizer is not available");c.connect(e,this),this.isVisible=c.isInstanceVisible(this.top??0,this.height)}this.isSetup=!0}if(!this.isVisible&&this.isSimpleMode())return this.renderPlaceholder(this.height);const f=this.virtualizer.getWindowSpecs(),h=this.top??0,d=this.computeRenderRangeFromWindow(this.fileDiff,h,f);return super.render({fileDiff:this.fileDiff,fileContainer:e,renderRange:d,oldFile:t,newFile:i,lineAnnotations:r,forceRender:(a??s)||u,...o})}syncVirtualizedTop(){this.top=this.getVirtualizedTop()}shouldDisableVirtualizationBuffers(){return this.isAdvancedMode()||super.shouldDisableVirtualizationBuffers()}isSimpleMode(){return this.virtualizer.type==="simple"}isAdvancedMode(){return this.virtualizer.type==="advanced"}getVirtualizedTop(){return this.virtualizer.type==="advanced"?this.virtualizer.getLocalTopForInstance(this):this.fileContainer!=null?this.virtualizer.getOffsetInScrollContainer(this.fileContainer):0}getSimpleVirtualizer(){return this.virtualizer.type==="simple"?this.virtualizer:void 0}isResizeDebuggingEnabled(){return this.getSimpleVirtualizer()?.config.resizeDebugging??!1}getDiffStyle(){return this.options.diffStyle??"split"}getHunkSeparatorType(){return Ai(this.options.hunkSeparators)}approximateLayoutCheckpoints(){if(this.cache.checkpoints.length>0||this.fileDiff==null||this.fileDiff.hunks.length===0||this.options.collapsed===!0)return;const{disableFileHeader:e=!1,expandUnchanged:t=!1,collapsedContextThreshold:i=1}=this.options,n=this.fileDiff.hunks.length-1,s=this.getDiffStyle(),r=this.getHunkSeparatorType(),o=t?!0:this.hunksRenderer.getExpandedHunksMap(),a=Si(this.cache.heightDeltas);let l=Y(this.metrics,e)+this.cache.fileAnnotationHeight,u=0;const f=({rowCount:h,startLineIndex:d,preSeparatorHeight:c=0,postSeparatorHeight:g=0,metadataOffsets:m=[]})=>{if(h<=0)return;const C=u,y=u+h;let v=vi(C);for(;v<y;){const p=v-C,S=l+(p>0?c:0)+p*this.metrics.lineHeight+yi(m,p)*this.metrics.lineHeight+qe(a,d,d+p);this.cache.checkpoints.push({renderedLineIndex:v,lineIndex:d+p,top:S}),v+=ze}l+=c+h*this.metrics.lineHeight+m.length*this.metrics.lineHeight+qe(a,d,d+h)+g,u=y};for(let h=0;h<this.fileDiff.hunks.length;h++){const d=this.fileDiff.hunks[h];if(d==null)throw new Error("VirtualizedFileDiff.approximateLayoutCheckpoints: invalid hunk index");const c=we({isPartial:this.fileDiff.isPartial,rangeSize:d.collapsedBefore,expandedHunks:o,hunkIndex:h,collapsedContextThreshold:i}),g=c.collapsedLines>0?oe({type:r,metrics:this.metrics,hunkIndex:h,hunkSpecs:d.hunkSpecs})?.totalHeight??0:0;f({rowCount:c.fromStart,startLineIndex:(s==="split"?d.splitLineStart:d.unifiedLineStart)-c.rangeSize});let m=g;f({rowCount:c.fromEnd,startLineIndex:(s==="split"?d.splitLineStart:d.unifiedLineStart)-c.fromEnd,preSeparatorHeight:m}),c.fromEnd>0&&(m=0);const C=h===n?Me({fileDiff:this.fileDiff,hunkIndex:h,expandedHunks:o,collapsedContextThreshold:i,errorPrefix:"VirtualizedFileDiff"}):void 0,y=C!=null&&C.collapsedLines>0?ae({type:r,metrics:this.metrics})?.totalHeight??0:0,v=C!=null?C.fromStart+C.fromEnd:0,p=s==="split"?d.splitLineCount:d.unifiedLineCount,S=s==="split"?d.splitLineStart:d.unifiedLineStart;f({rowCount:p,startLineIndex:S,preSeparatorHeight:m,postSeparatorHeight:v===0?y:0,metadataOffsets:Hi({diffStyle:s,hunk:d,rowCount:p})}),C!=null&&v>0&&f({rowCount:v,startLineIndex:S+p,postSeparatorHeight:y})}this.cache.totalLines=u}getLayoutCheckpointBeforeLineIndex(e){if(e<=0||this.cache.checkpoints.length===0)return;let t=0,i=this.cache.checkpoints.length-1,n;for(;t<=i;){const s=t+i>>1,r=this.cache.checkpoints[s];if(r==null)throw new Error("VirtualizedFileDiff: invalid checkpoint index");r.lineIndex<=e?(n=r,t=s+1):i=s-1}return n}getLayoutCheckpointBeforeTop(e,t){let i=0,n=this.cache.checkpoints.length-1,s=-1;for(;i<=n;){const r=i+n>>1,o=this.cache.checkpoints[r];if(o==null)throw new Error("VirtualizedFileDiff: invalid checkpoint index");o.top<=e?(s=r,i=r+1):n=r-1}if(t==null)return s>=0?this.cache.checkpoints[s]:void 0;for(let r=s;r>=0;r--){const o=this.cache.checkpoints[r];if(o==null)throw new Error("VirtualizedFileDiff: invalid checkpoint index");if(o.renderedLineIndex%t===0)return o}}getExpandedLineCount(e,t){let i=0;if(e.isPartial){for(const a of e.hunks)i+=t==="split"?a.splitLineCount:a.unifiedLineCount;return i}const{expandUnchanged:n=!1,collapsedContextThreshold:s=1}=this.options,r=n?!0:this.hunksRenderer.getExpandedHunksMap();for(const[a,l]of e.hunks.entries()){const u=t==="split"?l.splitLineCount:l.unifiedLineCount;i+=u;const f=Math.max(l.collapsedBefore,0),{fromStart:h,fromEnd:d,renderAll:c}=we({isPartial:e.isPartial,rangeSize:f,expandedHunks:r,hunkIndex:a,collapsedContextThreshold:s});f>0&&(i+=c?f:h+d)}const o=Me({fileDiff:e,hunkIndex:e.hunks.length-1,expandedHunks:r,collapsedContextThreshold:s,errorPrefix:"VirtualizedFileDiff"});return o!=null&&(i+=o.fromStart+o.fromEnd),i}computeRenderRangeFromWindow(e,t,{top:i,bottom:n}){const{disableFileHeader:s=!1,expandUnchanged:r=!1,collapsedContextThreshold:o=1}=this.options,{hunkLineCount:a,lineHeight:l}=this.metrics,u=this.getDiffStyle(),f=this.getHunkSeparatorType(),h=this.height;let d=this.cache.totalLines>0?this.cache.totalLines:this.getExpandedLineCount(e,u);const c=Y(this.metrics,s),g=e.hunks.length>0?Qe(this.metrics):0,{fileAnnotationHeight:m}=this.cache,C=c+m,y=Math.max(0,h-c-m-g),v=this.hasFileAnnotations(e),p=t+c,S=m>0&&v&&p<n&&p+m>i;if(t<i-h||t>n)return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:h-c-g};if(d<=a||e.hunks.length===0)return{startingLine:0,totalLines:a,bufferBefore:0,bufferAfter:0};this.approximateLayoutCheckpoints(),d=this.cache.totalLines>0?this.cache.totalLines:d;const H=Math.ceil(Math.max(n-i,0)/l),T=Math.ceil(H/a)*a+a,F=T/a,de=F,j=[],ue=(i+n)/2,q=this.getLayoutCheckpointBeforeTop(Math.max(0,i-t-T*l*2),a);let b=t+(q?.top??C),Z=q?.renderedLineIndex??0,R,D,P;if(ve({diff:e,diffStyle:u,startingLine:q?.renderedLineIndex??0,expandedHunks:r?!0:this.hunksRenderer.getExpandedHunksMap(),collapsedContextThreshold:o,callback:({hunkIndex:ye,hunk:He,collapsedBefore:te,collapsedAfter:ie,deletionLine:k,additionLine:E})=>{const z=E!=null?E.splitLineIndex:k.splitLineIndex,$=E!=null?E.unifiedLineIndex:k.unifiedLineIndex,O=(E?.noEOFCR??!1)||(k?.noEOFCR??!1),N=(te>0?oe({type:f,metrics:this.metrics,hunkIndex:ye,hunkSpecs:He?.hunkSpecs}):void 0)?.totalHeight??0;b+=N;const ne=Z%a===0,M=Math.floor(Z/a);if(ne&&(j[M]=b-(t+C+N),P!=null)){if(P<=0)return!0;P--}const Le=this.getLineHeight(u==="split"?z:$,O);return b>i-Le&&b<n&&(R??=M),D==null&&b+Le>ue&&(D=M),P==null&&b>=n&&ne&&(P=de),Z++,b+=Le,ie>0&&(b+=ae({type:f,metrics:this.metrics})?.totalHeight??0),!1}}),R==null)if(S)R=0,D=0;else return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:h-c-g};D??=R;const V=Math.round(D-F/2),L=Math.max(0,Math.ceil(d/a)-F),A=Math.max(0,Math.min(V,L)),x=A*a,I=V<0?T+V*a:T,W=j[A]??0,J=x===0?0:m+W,ee=A+I/a,fe=ee<j.length?y-j[ee]:y-(b-t-C);return{startingLine:x,totalLines:I,bufferBefore:J,bufferAfter:Math.max(0,fe)}}};function Ci(e){let t;for(const i of e){if(i==null)continue;const n=i.children[1];if(n instanceof HTMLElement)for(const s of n.children)s instanceof HTMLElement&&s.dataset.lineAnnotation===Ht&&(t=Math.max(t??0,s.getBoundingClientRect().height))}return t}function Si(e){const t=Array.from(e).sort((r,o)=>r[0]-o[0]),i=[],n=[0];let s=0;for(const[r,o]of t)i.push(r),s+=o,n.push(s);return{lineIndexes:i,prefixTotals:n}}function qe({lineIndexes:e,prefixTotals:t},i,n){if(i>=n||e.length===0)return 0;const s=Ke(e,i);return(t[Ke(e,n)]??0)-(t[s]??0)}function Ke(e,t){let i=0,n=e.length;for(;i<n;){const s=i+n>>1,r=e[s];if(r==null)throw new Error("VirtualizedFileDiff: invalid prefix index");r<t?i=s+1:n=s}return i}function vi(e){return Math.ceil(e/ze)*ze}function yi(e,t){let i=0;for(const n of e)n<t&&i++;return i}function Hi({diffStyle:e,hunk:t,rowCount:i}){if(i<=0||!t.noEOFCRAdditions&&!t.noEOFCRDeletions)return[];const n=t.hunkContent.at(-1);if(n==null)return[];if(n.type==="context")return[i-1];const s=Math.max(n.deletions,n.additions),r=n.deletions+n.additions;if(e==="split")return s>0&&(t.noEOFCRAdditions||t.noEOFCRDeletions)?[i-1]:[];const o=[],a=i-r;return n.deletions>0&&t.noEOFCRDeletions&&o.push(a+n.deletions-1),n.additions>0&&t.noEOFCRAdditions&&o.push(i-1),o}function Li(e,t){return(e.diffStyle??"split")!==(t.diffStyle??"split")||(e.overflow??"scroll")!==(t.overflow??"scroll")||(e.collapsed??!1)!==(t.collapsed??!1)||(e.disableLineNumbers??!1)!==(t.disableLineNumbers??!1)||(e.disableFileHeader??!1)!==(t.disableFileHeader??!1)||(e.diffIndicators??"bars")!==(t.diffIndicators??"bars")||(e.hunkSeparators??"line-info")!==(t.hunkSeparators??"line-info")||(e.expandUnchanged??!1)!==(t.expandUnchanged??!1)||(e.collapsedContextThreshold??1)!==(t.collapsedContextThreshold??1)||e.unsafeCSS!==t.unsafeCSS}function Ti(e,t){return(e.disableFileHeader??!1)!==(t.disableFileHeader??!1)||(e.hunkSeparators??"line-info")!==(t.hunkSeparators??"line-info")||(e.expandUnchanged??!1)!==(t.expandUnchanged??!1)||(e.collapsedContextThreshold??1)!==(t.collapsedContextThreshold??1)}function Ai(e){return typeof e=="function"?"custom":e??"line-info"}function ki(e,t){const[i,n]=e.split(",").map(Number);return t==="split"?n:i}export{li as F,Mi as V,Q as p};
@@ -1 +1 @@
1
- import{r as i,j as l}from"./vendor-react-DYyjh7Q0.js";import{f as a}from"./SessionSwitcherDropdown-D5bWfZNA.js";import{Y as n,Z as p,_ as b}from"./vendor-base-ui-DL8r2fgQ.js";const u=n,d=({className:e,asChild:s,children:o,...t})=>{const r=s&&i.isValidElement(o)?{render:o}:{children:o};return l.jsx(p,{className:a("flex w-full items-center justify-between rounded-lg px-2 py-1.5 text-left text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",e),...t,...r})},x=({className:e,...s})=>l.jsx(b,{className:a("overflow-hidden data-[closed]:animate-collapsible-up data-[open]:animate-collapsible-down",e),...s});export{u as C,d as a,x as b};
1
+ import{r as i,j as l}from"./vendor-react-DYyjh7Q0.js";import{f as a}from"./SessionSwitcherDropdown-DROjbyIu.js";import{Y as n,Z as p,_ as b}from"./vendor-base-ui-DL8r2fgQ.js";const u=n,d=({className:e,asChild:s,children:o,...t})=>{const r=s&&i.isValidElement(o)?{render:o}:{children:o};return l.jsx(p,{className:a("flex w-full items-center justify-between rounded-lg px-2 py-1.5 text-left text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",e),...t,...r})},x=({className:e,...s})=>l.jsx(b,{className:a("overflow-hidden data-[closed]:animate-collapsible-up data-[open]:animate-collapsible-down",e),...s});export{u as C,d as a,x as b};
@@ -1,3 +1,3 @@
1
1
  const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/vendor-shiki-Bbf2GEcE.js","assets/vendor-vite-runtime-DD1OZmLC.js","assets/vendor-shikijs-core-CGM_jqPK.js","assets/vendor-shikijs-types-CPSbSeK6.js","assets/vendor-shikijs-vscode-textmate-BgLrS_2D.js","assets/vendor-hast-util-to-html-BKBhbTDb.js","assets/vendor-html-void-elements-CkdplsNl.js","assets/vendor-property-information-rJCbAzvX.js","assets/vendor-zwitch-C2o2j-tx.js","assets/vendor-stringify-entities-CsH1VEn9.js","assets/vendor-character-entities-legacy-BpoLgcEt.js","assets/vendor-character-entities-html4-D7taRCQ7.js","assets/vendor-ccount-c2V3InAJ.js","assets/vendor-comma-separated-tokens-D8TqSuIK.js","assets/vendor-space-separated-tokens-DD3iYX1K.js","assets/vendor-hast-util-whitespace-D4Wp6AEg.js","assets/vendor-shikijs-engine-oniguruma-DPWuIF1G.js"])))=>i.map(i=>d[i]);
2
- import{_ as I}from"./vendor-vite-runtime-DD1OZmLC.js";import{b as j,c as O}from"./vendor-shiki-Bbf2GEcE.js";import{t as f}from"./themeResolver-BmJyTmjJ.js";import{s as M,p as F,n as v}from"./vendor-pierre-theming-C6Z4M5_u.js";import{c as N}from"./vendor-shikijs-engine-oniguruma-DPWuIF1G.js";import{c as z}from"./vendor-shikijs-engine-javascript-Cme4830A.js";import{df as L,d_ as G}from"./SessionSwitcherDropdown-D5bWfZNA.js";import{t as H}from"./vendor-shikijs-transformers-CZWsLLKm.js";function pe(e,t){return e==null||t==null||typeof e=="string"||typeof t=="string"?e===t:e.dark===t.dark&&e.light===t.light}function ue(e,t){return e?.cacheKey===t?.cacheKey&&e?.contents===t?.contents&&e?.name===t?.name&&e?.lang===t?.lang}function S(e){return{type:"text",value:e}}function m({tagName:e,children:t=[],properties:r={}}){return{type:"element",tagName:e,properties:r,children:t}}function fe({name:e,width:t=16,height:r=16,properties:n}){return m({tagName:"svg",properties:{width:t,height:r,viewBox:"0 0 16 16",...n},children:[m({tagName:"use",properties:{href:`#${e.replace(/^#/,"")}`}})]})}function V(e){let t=e.children[0];for(;t!=null;){if(t.type==="element"&&t.tagName==="code")return t;"children"in t?t=t.children[0]:t=null}}function de(e){return m({tagName:"div",properties:{"data-gutter":""},children:e})}function me(e,t,r,n={}){return m({tagName:"div",properties:{"data-line-type":e,"data-column-number":t,"data-line-index":r,...n},children:t!=null?[m({tagName:"span",properties:{"data-line-number-content":""},children:[S(`${t}`)]})]:void 0})}function he(e,t,r){return m({tagName:"div",properties:{"data-gutter-buffer":t,"data-buffer-size":r,"data-line-type":t==="annotation"?void 0:e,style:t==="annotation"?`grid-row: span ${r};`:`grid-row: span ${r};min-height:calc(${r} * 1lh);`}})}const g=new Map,k=new Map,A=new Map,T=new Set;function E(e,t){e=Array.isArray(e)?e:[e];for(const r of e){if(T.has(r.name))continue;let n=g.get(r.name);n==null&&(n=r,g.set(r.name,n)),T.add(n.name),t.loadLanguageSync(n.data)}}function q(){return typeof WorkerGlobalScope<"u"&&typeof self<"u"&&self instanceof WorkerGlobalScope}async function D(e){if(q())throw new Error(`resolveLanguage("${e}") cannot be called from a worker context. Languages must be pre-resolved on the main thread and passed to the worker via the resolvedLanguages parameter.`);const t=k.get(e);if(t!=null)return t;try{let r=A.get(e);if(r==null&&Object.prototype.hasOwnProperty.call(j,e)&&(r=j[e]),r==null)throw new Error(`resolveLanguage: "${e}" not found in bundled or custom languages`);const n=r().then(({default:o})=>{const s={name:e,data:o};return g.has(e)||g.set(e,s),s});return k.set(e,n),await n}finally{k.delete(e)}}function W(e){return g.get(e)??D(e)}const $=new Set;function R(e,t){e=Array.isArray(e)?e:[e];for(let r of e){let n;if(typeof r=="string"){if(n=f.getResolvedTheme(r),n==null)throw new Error(`loadResolvedThemes: ${r} is not resolved, you must resolve it before calling loadResolvedThemes`)}else n=r,r=r.name,f.getResolvedTheme(r)==null&&f.seedResolvedTheme(r,n);$.has(r)||($.add(r),t.loadThemeSync(n))}}function P(e){if(q())throw new Error(`Theme "${e}" cannot be resolved from a worker context. Themes must be pre-resolved on the main thread and passed to the worker via the resolvedLanguages parameter.`);if(f.hasRegisteredTheme(e))return;const t=M.getTheme(e);if(t!=null){f.registerThemeIfAbsent(t.name,t.load);return}throw new Error(`No valid theme loader registered for "${e}"`)}function U(e,t){if(t.name!==e)throw new Error(`resolvedTheme: themeName: ${e} does not match theme.name: ${t.name}`)}async function K(e){P(e);const t=await f.resolveTheme(e);return U(e,t),t}function X(e){return f.getResolvedTheme(e)??K(e)}let c;async function ge({themes:e,langs:t,preferredHighlighter:r="shiki-js"}){c??=O({themes:[],langs:["text"],engine:r==="shiki-wasm"?N(I(()=>import("./vendor-shiki-Bbf2GEcE.js").then(a=>a.w),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]))):z()});const n=B(c)?await c:c;c=n;const o=[];for(const a of t){if(a==="text"||a==="ansi")continue;const i=W(a);"then"in i?o.push(i):E(i,n)}const s=[];for(const a of e){const i=X(a);"then"in i?s.push(i):R(i,c)}return(o.length>0||s.length>0)&&await Promise.all([Promise.all(o).then(a=>{E(a,n)}),Promise.all(s).then(a=>{R(a,n)})]),n}function be(){if(c!=null&&!("then"in c))return c}function B(e=c){return e!=null&&"then"in e}for(const e of F.getThemes())f.registerThemeIfAbsent(e.name,e.load);function ye(e=L){const t=[];return typeof e=="string"?t.push(e):(t.push(e.dark),t.push(e.light)),t}const d=new Map;let J=0;const h={"1c":"1c",abap:"abap",as:"actionscript-3",ada:"ada",adb:"ada",ads:"ada",adoc:"asciidoc",asciidoc:"asciidoc","component.html":"angular-html","component.ts":"angular-ts",conf:"nginx",htaccess:"apache",cls:"tex",trigger:"apex",apl:"apl",applescript:"applescript",scpt:"applescript",ara:"ara",asm:"asm",s:"riscv",astro:"astro",awk:"awk",bal:"ballerina",sh:"zsh",bash:"zsh",bat:"cmd",cmd:"cmd",be:"berry",beancount:"beancount",bib:"bibtex",bicep:"bicep","blade.php":"blade",bsl:"bsl",c:"c",h:"objective-cpp",cs:"csharp",cpp:"cpp",hpp:"cpp",cc:"cpp",cxx:"cpp",hh:"cpp",cdc:"cdc",cairo:"cairo",clar:"clarity",clj:"clojure",cljs:"clojure",cljc:"clojure",soy:"soy",cmake:"cmake","CMakeLists.txt":"cmake",cob:"cobol",cbl:"cobol",cobol:"cobol",CODEOWNERS:"codeowners",ql:"ql",coffee:"coffeescript",lisp:"lisp",cl:"lisp",lsp:"lisp",log:"log",v:"verilog",cql:"cql",cr:"crystal",css:"css",csv:"csv",cue:"cue",cypher:"cypher",cyp:"cypher",d:"d",dart:"dart",dax:"dax",desktop:"desktop",diff:"diff",patch:"diff",Dockerfile:"dockerfile",dockerfile:"dockerfile",env:"dotenv",dm:"dream-maker",edge:"edge",el:"emacs-lisp",ex:"elixir",exs:"elixir",elm:"elm",erb:"erb",erl:"erlang",hrl:"erlang",f:"fortran-fixed-form",for:"fortran-fixed-form",fs:"fsharp",fsi:"fsharp",fsx:"fsharp",f03:"f03",f08:"f08",f18:"f18",f77:"f77",f90:"fortran-free-form",f95:"fortran-free-form",fnl:"fennel",fish:"fish",ftl:"ftl",tres:"gdresource",res:"gdresource",gd:"gdscript",gdshader:"gdshader",gs:"genie",feature:"gherkin",COMMIT_EDITMSG:"git-commit","git-rebase-todo":"git-rebase",gjs:"glimmer-js",gleam:"gleam",gts:"glimmer-ts",glsl:"glsl",vert:"glsl",frag:"glsl",shader:"shaderlab",gp:"gnuplot",plt:"gnuplot",gnuplot:"gnuplot",go:"go",graphql:"graphql",gql:"graphql",groovy:"groovy",gvy:"groovy",hack:"hack",haml:"haml",hbs:"handlebars",handlebars:"handlebars",hs:"haskell",lhs:"haskell",hx:"haxe",hcl:"hcl",hjson:"hjson",hlsl:"hlsl",fx:"hlsl",html:"html",htm:"html",http:"http",rest:"http",hxml:"hxml",hy:"hy",imba:"imba",ini:"ini",cfg:"ini",jade:"pug",pug:"pug",java:"java",js:"javascript",mjs:"javascript",cjs:"javascript",jinja:"jinja",jinja2:"jinja",j2:"jinja",jison:"jison",jl:"julia",json:"json",json5:"json5",jsonc:"jsonc",jsonl:"jsonl",jsonnet:"jsonnet",libsonnet:"jsonnet",jssm:"jssm",jsx:"jsx",kt:"kotlin",kts:"kts",kql:"kusto",tex:"tex",ltx:"tex",lean:"lean4",less:"less",liquid:"liquid",lit:"lit",ll:"llvm",logo:"logo",lua:"lua",luau:"luau",Makefile:"makefile",mk:"makefile",makefile:"makefile",md:"markdown",markdown:"markdown",marko:"marko",m:"wolfram",mat:"matlab",mdc:"mdc",mdx:"mdx",wiki:"wikitext",mediawiki:"wikitext",mmd:"mermaid",mermaid:"mermaid",mips:"mipsasm",mojo:"mojo","🔥":"mojo",move:"move",nar:"narrat",nf:"nextflow",nim:"nim",nims:"nim",nimble:"nim",nix:"nix",nu:"nushell",mm:"objective-cpp",ml:"ocaml",mli:"ocaml",mll:"ocaml",mly:"ocaml",pas:"pascal",p:"pascal",pl:"prolog",pm:"perl",t:"perl",raku:"raku",p6:"raku",pl6:"raku",php:"php",phtml:"php",pls:"plsql",sql:"sql",po:"po",polar:"polar",pcss:"postcss",pot:"pot",potx:"potx",pq:"powerquery",pqm:"powerquery",ps1:"powershell",psm1:"powershell",psd1:"powershell",prisma:"prisma",pro:"prolog",P:"prolog",properties:"properties",proto:"protobuf",pp:"puppet",purs:"purescript",py:"python",pyw:"python",pyi:"python",qml:"qml",qmldir:"qmldir",qss:"qss",r:"r",R:"r",rkt:"racket",rktl:"racket",razor:"razor",cshtml:"razor",rb:"ruby",rbw:"ruby",reg:"reg",regex:"regexp",rel:"rel",rs:"rust",rst:"rst",rake:"ruby",gemspec:"ruby",jbuilder:"ruby",builder:"ruby",rabl:"ruby",arb:"ruby",ru:"ruby",podspec:"ruby",Gemfile:"ruby",Rakefile:"ruby",Guardfile:"ruby",Capfile:"ruby",Berksfile:"ruby",Brewfile:"ruby",Vagrantfile:"ruby",Thorfile:"ruby",Appraisals:"ruby",Dangerfile:"ruby",sas:"sas",sass:"sass",scala:"scala",sc:"scala",scm:"scheme",ss:"scheme",sld:"scheme",scss:"scss",sdbl:"sdbl",shadergraph:"shader",st:"smalltalk",sol:"solidity",sparql:"sparql",rq:"sparql",spl:"splunk",config:"ssh-config",do:"stata",ado:"stata",dta:"stata",styl:"stylus",stylus:"stylus",svelte:"svelte",swift:"swift",sv:"system-verilog",svh:"system-verilog",service:"systemd",socket:"systemd",device:"systemd",timer:"systemd",talon:"talonscript",tasl:"tasl",tcl:"tcl",templ:"templ",tf:"tf",tfvars:"tfvars",toml:"toml",ts:"typescript",tsp:"typespec",tsv:"tsv",tsx:"tsx",ttl:"turtle",twig:"twig",typ:"typst",vv:"v",vala:"vala",vapi:"vala",vb:"vb",vbs:"vb",bas:"vb",vh:"verilog",vhd:"vhdl",vhdl:"vhdl",vim:"vimscript",vue:"vue","vine.ts":"vue-vine",vy:"vyper",wasm:"wasm",wat:"wasm",wy:"文言",wgsl:"wgsl",wit:"wit",wl:"wolfram",nb:"wolfram",xml:"xml",xsl:"xsl",xslt:"xsl",yaml:"yaml",yml:"yml",zs:"zenscript",zig:"zig",zsh:"zsh",sty:"tex"};function ve(e){if(d.has(e))return d.get(e)??"text";if(h[e]!=null)return h[e];const t=e.match(/\.([^/\\]+\.[^/\\]+)$/);if(t!=null){if(d.has(t[1]))return d.get(t[1])??"text";if(h[t[1]]!=null)return h[t[1]]??"text"}const r=e.match(/\.([^.]+)$/)?.[1]??"";return d.has(r)?d.get(r)??"text":h[r]??"text"}function ke(){return J}function we(){return Object.fromEntries(d)}function Q(e,t,r){const n=typeof r.lineInfo=="function"?r.lineInfo(t):r.lineInfo[t-1];if(n==null){const o=`processLine: line ${t}, contains no state.lineInfo`;throw console.error(o,{node:e,line:t,state:r}),new Error(o)}return e.tagName="div",e.properties["data-line"]=n.lineNumber,e.properties["data-alt-line"]=n.altLineNumber,e.properties["data-line-type"]=n.type,e.properties["data-line-index"]=n.lineIndex,e.children.length===0&&e.children.push(S(`
3
- `)),e}const b=Symbol("no-token"),w=Symbol("multiple-tokens");function _(e){const t=Y(e);if(t!=null)return t;let r=b;const n=[];let o=[],s;const a=()=>{if(o.length===0||s==null){o=[],s=void 0;return}if(o.length===1){const l=o[0];if(l?.type==="element"){Z(l,s);for(const p of l.children)y(p)}else y(l);n.push(l),o=[],s=void 0;return}for(const l of o)y(l);n.push(m({tagName:"span",properties:{"data-char":s},children:o})),o=[],s=void 0},i=l=>{if(l!==b){if(l===w){r=w;return}if(r===b){r=l;return}r!==l&&(r=w)}};for(const l of e.children){const p=l.type==="element"?_(l):b;if(i(p),typeof p!="number"){a(),n.push(l);continue}s!=null&&s!==p&&a(),s??=p,o.push(l)}return a(),e.children=n,r}function Y(e){const t=e.properties["data-char"];if(typeof t=="number")return t}function y(e){if(e.type==="element"){e.properties["data-char"]=void 0;for(const t of e.children)y(t)}}function Z(e,t){e.properties["data-char"]=t}function xe(e=!1,t=!1){const r={lineInfo:[]},n=[{line(o){return delete o.properties.class,o},pre(o){const s=V(o),a=[];if(s!=null){let i=1;for(const l of s.children)l.type==="element"&&(e&&_(l),a.push(Q(l,i,r)),i++);s.children=a}return o},...e?{tokens(o){for(const s of o){let a=0;for(const i of s){const l=i;l.__lineChar??=a,a+=i.content.length}}},preprocess(o,s){s.mergeWhitespaces="never"},span(o,s,a,i,l){if(l?.offset!=null&&l.content!=null){const p=l.__lineChar;return p!=null&&(o.properties["data-char"]=p),o}return o}}:null}];return t&&n.push(ee,C),e&&n.push({line:o=>(o.type==="element"&&o.children.length===0&&o.children.push({type:"element",tagName:"br",properties:{},children:[]}),o)}),{state:r,transformers:n,toClass:C}}const C=H({classPrefix:"hl-"}),ee={name:"token-style-normalizer",tokens(e){for(const t of e)for(const r of t){if(r.htmlStyle!=null)continue;const n={};r.color!=null&&(n.color=r.color),r.bgColor!=null&&(n["background-color"]=r.bgColor),r.fontStyle!=null&&r.fontStyle!==0&&((r.fontStyle&1)!==0&&(n["font-style"]="italic"),(r.fontStyle&2)!==0&&(n["font-weight"]="bold"),(r.fontStyle&4)!==0&&(n["text-decoration"]="underline")),Object.keys(n).length>0&&(r.htmlStyle=n)}}};function u(e){return`--${e==="token"?"diffs-token":"diffs"}-`}function je({theme:e=L,highlighter:t,prefix:r}){let n="";if(typeof e=="string"){const o=t.getTheme(e),s=v(o);n+=`color:${s.fg};`,n+=`background-color:${s.bg};`,n+=`${u("global")}fg:${s.fg};`,n+=`${u("global")}bg:${s.bg};`,n+=x(o,r)}else{let o=t.getTheme(e.dark),s=v(o);n+=`${u("global")}dark:${s.fg};`,n+=`${u("global")}dark-bg:${s.bg};`,n+=x(o,"dark"),o=t.getTheme(e.light),s=v(o),n+=`${u("global")}light:${s.fg};`,n+=`${u("global")}light-bg:${s.bg};`,n+=x(o,"light")}return n}function x(e,t){t=t!=null?`${t}-`:"";let r="";const n=e.colors?.["gitDecoration.addedResourceForeground"]??e.colors?.["terminal.ansiGreen"];n!=null&&(r+=`${u("global")}${t}addition-color:${n};`);const o=e.colors?.["gitDecoration.deletedResourceForeground"]??e.colors?.["terminal.ansiRed"];o!=null&&(r+=`${u("global")}${t}deletion-color:${o};`);const s=e.colors?.["gitDecoration.modifiedResourceForeground"]??e.colors?.["terminal.ansiBlue"];return s!=null&&(r+=`${u("global")}${t}modified-color:${s};`),r}function Te(e){let t=e.children[0];for(;t!=null;){if(t.type==="element"&&t.tagName==="code")return t.children;"children"in t?t=t.children[0]:t=null}throw console.error(e),new Error("getLineNodes: Unable to find children")}function Ee(e){return{...G,...e}}function $e(e,t){const r=te(e,t);return t?r:e.diffHeaderHeight+r}function te(e,t){return e.paddingTop??(t?e.spacing:0)}function Re(e){return e.paddingBottom??e.spacing}function Ce(e){switch(e){case"simple":return 4;case"metadata":case"line-info":case"line-info-basic":case"custom":return 32}}export{T as A,Ee as B,Ce as C,g as R,ye as a,pe as b,R as c,ge as d,we as e,ue as f,W as g,ke as h,ve as i,be as j,he as k,me as l,m,de as n,$e as o,P as p,Re as q,D as r,xe as s,je as t,Te as u,U as v,u as w,fe as x,$ as y,S as z};
2
+ import{_ as I}from"./vendor-vite-runtime-DD1OZmLC.js";import{b as j,c as O}from"./vendor-shiki-Bbf2GEcE.js";import{t as f}from"./themeResolver-BmJyTmjJ.js";import{s as M,p as F,n as v}from"./vendor-pierre-theming-C6Z4M5_u.js";import{c as N}from"./vendor-shikijs-engine-oniguruma-DPWuIF1G.js";import{c as z}from"./vendor-shikijs-engine-javascript-Cme4830A.js";import{da as L,dV as G}from"./SessionSwitcherDropdown-DROjbyIu.js";import{t as V}from"./vendor-shikijs-transformers-CZWsLLKm.js";function pe(e,t){return e==null||t==null||typeof e=="string"||typeof t=="string"?e===t:e.dark===t.dark&&e.light===t.light}function ue(e,t){return e?.cacheKey===t?.cacheKey&&e?.contents===t?.contents&&e?.name===t?.name&&e?.lang===t?.lang}function S(e){return{type:"text",value:e}}function m({tagName:e,children:t=[],properties:r={}}){return{type:"element",tagName:e,properties:r,children:t}}function fe({name:e,width:t=16,height:r=16,properties:n}){return m({tagName:"svg",properties:{width:t,height:r,viewBox:"0 0 16 16",...n},children:[m({tagName:"use",properties:{href:`#${e.replace(/^#/,"")}`}})]})}function H(e){let t=e.children[0];for(;t!=null;){if(t.type==="element"&&t.tagName==="code")return t;"children"in t?t=t.children[0]:t=null}}function de(e){return m({tagName:"div",properties:{"data-gutter":""},children:e})}function me(e,t,r,n={}){return m({tagName:"div",properties:{"data-line-type":e,"data-column-number":t,"data-line-index":r,...n},children:t!=null?[m({tagName:"span",properties:{"data-line-number-content":""},children:[S(`${t}`)]})]:void 0})}function he(e,t,r){return m({tagName:"div",properties:{"data-gutter-buffer":t,"data-buffer-size":r,"data-line-type":t==="annotation"?void 0:e,style:t==="annotation"?`grid-row: span ${r};`:`grid-row: span ${r};min-height:calc(${r} * 1lh);`}})}const g=new Map,k=new Map,A=new Map,T=new Set;function E(e,t){e=Array.isArray(e)?e:[e];for(const r of e){if(T.has(r.name))continue;let n=g.get(r.name);n==null&&(n=r,g.set(r.name,n)),T.add(n.name),t.loadLanguageSync(n.data)}}function q(){return typeof WorkerGlobalScope<"u"&&typeof self<"u"&&self instanceof WorkerGlobalScope}async function D(e){if(q())throw new Error(`resolveLanguage("${e}") cannot be called from a worker context. Languages must be pre-resolved on the main thread and passed to the worker via the resolvedLanguages parameter.`);const t=k.get(e);if(t!=null)return t;try{let r=A.get(e);if(r==null&&Object.prototype.hasOwnProperty.call(j,e)&&(r=j[e]),r==null)throw new Error(`resolveLanguage: "${e}" not found in bundled or custom languages`);const n=r().then(({default:o})=>{const s={name:e,data:o};return g.has(e)||g.set(e,s),s});return k.set(e,n),await n}finally{k.delete(e)}}function W(e){return g.get(e)??D(e)}const $=new Set;function R(e,t){e=Array.isArray(e)?e:[e];for(let r of e){let n;if(typeof r=="string"){if(n=f.getResolvedTheme(r),n==null)throw new Error(`loadResolvedThemes: ${r} is not resolved, you must resolve it before calling loadResolvedThemes`)}else n=r,r=r.name,f.getResolvedTheme(r)==null&&f.seedResolvedTheme(r,n);$.has(r)||($.add(r),t.loadThemeSync(n))}}function P(e){if(q())throw new Error(`Theme "${e}" cannot be resolved from a worker context. Themes must be pre-resolved on the main thread and passed to the worker via the resolvedLanguages parameter.`);if(f.hasRegisteredTheme(e))return;const t=M.getTheme(e);if(t!=null){f.registerThemeIfAbsent(t.name,t.load);return}throw new Error(`No valid theme loader registered for "${e}"`)}function U(e,t){if(t.name!==e)throw new Error(`resolvedTheme: themeName: ${e} does not match theme.name: ${t.name}`)}async function K(e){P(e);const t=await f.resolveTheme(e);return U(e,t),t}function X(e){return f.getResolvedTheme(e)??K(e)}let c;async function ge({themes:e,langs:t,preferredHighlighter:r="shiki-js"}){c??=O({themes:[],langs:["text"],engine:r==="shiki-wasm"?N(I(()=>import("./vendor-shiki-Bbf2GEcE.js").then(a=>a.w),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]))):z()});const n=B(c)?await c:c;c=n;const o=[];for(const a of t){if(a==="text"||a==="ansi")continue;const i=W(a);"then"in i?o.push(i):E(i,n)}const s=[];for(const a of e){const i=X(a);"then"in i?s.push(i):R(i,c)}return(o.length>0||s.length>0)&&await Promise.all([Promise.all(o).then(a=>{E(a,n)}),Promise.all(s).then(a=>{R(a,n)})]),n}function be(){if(c!=null&&!("then"in c))return c}function B(e=c){return e!=null&&"then"in e}for(const e of F.getThemes())f.registerThemeIfAbsent(e.name,e.load);function ye(e=L){const t=[];return typeof e=="string"?t.push(e):(t.push(e.dark),t.push(e.light)),t}const d=new Map;let J=0;const h={"1c":"1c",abap:"abap",as:"actionscript-3",ada:"ada",adb:"ada",ads:"ada",adoc:"asciidoc",asciidoc:"asciidoc","component.html":"angular-html","component.ts":"angular-ts",conf:"nginx",htaccess:"apache",cls:"tex",trigger:"apex",apl:"apl",applescript:"applescript",scpt:"applescript",ara:"ara",asm:"asm",s:"riscv",astro:"astro",awk:"awk",bal:"ballerina",sh:"zsh",bash:"zsh",bat:"cmd",cmd:"cmd",be:"berry",beancount:"beancount",bib:"bibtex",bicep:"bicep","blade.php":"blade",bsl:"bsl",c:"c",h:"objective-cpp",cs:"csharp",cpp:"cpp",hpp:"cpp",cc:"cpp",cxx:"cpp",hh:"cpp",cdc:"cdc",cairo:"cairo",clar:"clarity",clj:"clojure",cljs:"clojure",cljc:"clojure",soy:"soy",cmake:"cmake","CMakeLists.txt":"cmake",cob:"cobol",cbl:"cobol",cobol:"cobol",CODEOWNERS:"codeowners",ql:"ql",coffee:"coffeescript",lisp:"lisp",cl:"lisp",lsp:"lisp",log:"log",v:"verilog",cql:"cql",cr:"crystal",css:"css",csv:"csv",cue:"cue",cypher:"cypher",cyp:"cypher",d:"d",dart:"dart",dax:"dax",desktop:"desktop",diff:"diff",patch:"diff",Dockerfile:"dockerfile",dockerfile:"dockerfile",env:"dotenv",dm:"dream-maker",edge:"edge",el:"emacs-lisp",ex:"elixir",exs:"elixir",elm:"elm",erb:"erb",erl:"erlang",hrl:"erlang",f:"fortran-fixed-form",for:"fortran-fixed-form",fs:"fsharp",fsi:"fsharp",fsx:"fsharp",f03:"f03",f08:"f08",f18:"f18",f77:"f77",f90:"fortran-free-form",f95:"fortran-free-form",fnl:"fennel",fish:"fish",ftl:"ftl",tres:"gdresource",res:"gdresource",gd:"gdscript",gdshader:"gdshader",gs:"genie",feature:"gherkin",COMMIT_EDITMSG:"git-commit","git-rebase-todo":"git-rebase",gjs:"glimmer-js",gleam:"gleam",gts:"glimmer-ts",glsl:"glsl",vert:"glsl",frag:"glsl",shader:"shaderlab",gp:"gnuplot",plt:"gnuplot",gnuplot:"gnuplot",go:"go",graphql:"graphql",gql:"graphql",groovy:"groovy",gvy:"groovy",hack:"hack",haml:"haml",hbs:"handlebars",handlebars:"handlebars",hs:"haskell",lhs:"haskell",hx:"haxe",hcl:"hcl",hjson:"hjson",hlsl:"hlsl",fx:"hlsl",html:"html",htm:"html",http:"http",rest:"http",hxml:"hxml",hy:"hy",imba:"imba",ini:"ini",cfg:"ini",jade:"pug",pug:"pug",java:"java",js:"javascript",mjs:"javascript",cjs:"javascript",jinja:"jinja",jinja2:"jinja",j2:"jinja",jison:"jison",jl:"julia",json:"json",json5:"json5",jsonc:"jsonc",jsonl:"jsonl",jsonnet:"jsonnet",libsonnet:"jsonnet",jssm:"jssm",jsx:"jsx",kt:"kotlin",kts:"kts",kql:"kusto",tex:"tex",ltx:"tex",lean:"lean4",less:"less",liquid:"liquid",lit:"lit",ll:"llvm",logo:"logo",lua:"lua",luau:"luau",Makefile:"makefile",mk:"makefile",makefile:"makefile",md:"markdown",markdown:"markdown",marko:"marko",m:"wolfram",mat:"matlab",mdc:"mdc",mdx:"mdx",wiki:"wikitext",mediawiki:"wikitext",mmd:"mermaid",mermaid:"mermaid",mips:"mipsasm",mojo:"mojo","🔥":"mojo",move:"move",nar:"narrat",nf:"nextflow",nim:"nim",nims:"nim",nimble:"nim",nix:"nix",nu:"nushell",mm:"objective-cpp",ml:"ocaml",mli:"ocaml",mll:"ocaml",mly:"ocaml",pas:"pascal",p:"pascal",pl:"prolog",pm:"perl",t:"perl",raku:"raku",p6:"raku",pl6:"raku",php:"php",phtml:"php",pls:"plsql",sql:"sql",po:"po",polar:"polar",pcss:"postcss",pot:"pot",potx:"potx",pq:"powerquery",pqm:"powerquery",ps1:"powershell",psm1:"powershell",psd1:"powershell",prisma:"prisma",pro:"prolog",P:"prolog",properties:"properties",proto:"protobuf",pp:"puppet",purs:"purescript",py:"python",pyw:"python",pyi:"python",qml:"qml",qmldir:"qmldir",qss:"qss",r:"r",R:"r",rkt:"racket",rktl:"racket",razor:"razor",cshtml:"razor",rb:"ruby",rbw:"ruby",reg:"reg",regex:"regexp",rel:"rel",rs:"rust",rst:"rst",rake:"ruby",gemspec:"ruby",jbuilder:"ruby",builder:"ruby",rabl:"ruby",arb:"ruby",ru:"ruby",podspec:"ruby",Gemfile:"ruby",Rakefile:"ruby",Guardfile:"ruby",Capfile:"ruby",Berksfile:"ruby",Brewfile:"ruby",Vagrantfile:"ruby",Thorfile:"ruby",Appraisals:"ruby",Dangerfile:"ruby",sas:"sas",sass:"sass",scala:"scala",sc:"scala",scm:"scheme",ss:"scheme",sld:"scheme",scss:"scss",sdbl:"sdbl",shadergraph:"shader",st:"smalltalk",sol:"solidity",sparql:"sparql",rq:"sparql",spl:"splunk",config:"ssh-config",do:"stata",ado:"stata",dta:"stata",styl:"stylus",stylus:"stylus",svelte:"svelte",swift:"swift",sv:"system-verilog",svh:"system-verilog",service:"systemd",socket:"systemd",device:"systemd",timer:"systemd",talon:"talonscript",tasl:"tasl",tcl:"tcl",templ:"templ",tf:"tf",tfvars:"tfvars",toml:"toml",ts:"typescript",tsp:"typespec",tsv:"tsv",tsx:"tsx",ttl:"turtle",twig:"twig",typ:"typst",vv:"v",vala:"vala",vapi:"vala",vb:"vb",vbs:"vb",bas:"vb",vh:"verilog",vhd:"vhdl",vhdl:"vhdl",vim:"vimscript",vue:"vue","vine.ts":"vue-vine",vy:"vyper",wasm:"wasm",wat:"wasm",wy:"文言",wgsl:"wgsl",wit:"wit",wl:"wolfram",nb:"wolfram",xml:"xml",xsl:"xsl",xslt:"xsl",yaml:"yaml",yml:"yml",zs:"zenscript",zig:"zig",zsh:"zsh",sty:"tex"};function ve(e){if(d.has(e))return d.get(e)??"text";if(h[e]!=null)return h[e];const t=e.match(/\.([^/\\]+\.[^/\\]+)$/);if(t!=null){if(d.has(t[1]))return d.get(t[1])??"text";if(h[t[1]]!=null)return h[t[1]]??"text"}const r=e.match(/\.([^.]+)$/)?.[1]??"";return d.has(r)?d.get(r)??"text":h[r]??"text"}function ke(){return J}function we(){return Object.fromEntries(d)}function Q(e,t,r){const n=typeof r.lineInfo=="function"?r.lineInfo(t):r.lineInfo[t-1];if(n==null){const o=`processLine: line ${t}, contains no state.lineInfo`;throw console.error(o,{node:e,line:t,state:r}),new Error(o)}return e.tagName="div",e.properties["data-line"]=n.lineNumber,e.properties["data-alt-line"]=n.altLineNumber,e.properties["data-line-type"]=n.type,e.properties["data-line-index"]=n.lineIndex,e.children.length===0&&e.children.push(S(`
3
+ `)),e}const b=Symbol("no-token"),w=Symbol("multiple-tokens");function _(e){const t=Y(e);if(t!=null)return t;let r=b;const n=[];let o=[],s;const a=()=>{if(o.length===0||s==null){o=[],s=void 0;return}if(o.length===1){const l=o[0];if(l?.type==="element"){Z(l,s);for(const p of l.children)y(p)}else y(l);n.push(l),o=[],s=void 0;return}for(const l of o)y(l);n.push(m({tagName:"span",properties:{"data-char":s},children:o})),o=[],s=void 0},i=l=>{if(l!==b){if(l===w){r=w;return}if(r===b){r=l;return}r!==l&&(r=w)}};for(const l of e.children){const p=l.type==="element"?_(l):b;if(i(p),typeof p!="number"){a(),n.push(l);continue}s!=null&&s!==p&&a(),s??=p,o.push(l)}return a(),e.children=n,r}function Y(e){const t=e.properties["data-char"];if(typeof t=="number")return t}function y(e){if(e.type==="element"){e.properties["data-char"]=void 0;for(const t of e.children)y(t)}}function Z(e,t){e.properties["data-char"]=t}function xe(e=!1,t=!1){const r={lineInfo:[]},n=[{line(o){return delete o.properties.class,o},pre(o){const s=H(o),a=[];if(s!=null){let i=1;for(const l of s.children)l.type==="element"&&(e&&_(l),a.push(Q(l,i,r)),i++);s.children=a}return o},...e?{tokens(o){for(const s of o){let a=0;for(const i of s){const l=i;l.__lineChar??=a,a+=i.content.length}}},preprocess(o,s){s.mergeWhitespaces="never"},span(o,s,a,i,l){if(l?.offset!=null&&l.content!=null){const p=l.__lineChar;return p!=null&&(o.properties["data-char"]=p),o}return o}}:null}];return t&&n.push(ee,C),e&&n.push({line:o=>(o.type==="element"&&o.children.length===0&&o.children.push({type:"element",tagName:"br",properties:{},children:[]}),o)}),{state:r,transformers:n,toClass:C}}const C=V({classPrefix:"hl-"}),ee={name:"token-style-normalizer",tokens(e){for(const t of e)for(const r of t){if(r.htmlStyle!=null)continue;const n={};r.color!=null&&(n.color=r.color),r.bgColor!=null&&(n["background-color"]=r.bgColor),r.fontStyle!=null&&r.fontStyle!==0&&((r.fontStyle&1)!==0&&(n["font-style"]="italic"),(r.fontStyle&2)!==0&&(n["font-weight"]="bold"),(r.fontStyle&4)!==0&&(n["text-decoration"]="underline")),Object.keys(n).length>0&&(r.htmlStyle=n)}}};function u(e){return`--${e==="token"?"diffs-token":"diffs"}-`}function je({theme:e=L,highlighter:t,prefix:r}){let n="";if(typeof e=="string"){const o=t.getTheme(e),s=v(o);n+=`color:${s.fg};`,n+=`background-color:${s.bg};`,n+=`${u("global")}fg:${s.fg};`,n+=`${u("global")}bg:${s.bg};`,n+=x(o,r)}else{let o=t.getTheme(e.dark),s=v(o);n+=`${u("global")}dark:${s.fg};`,n+=`${u("global")}dark-bg:${s.bg};`,n+=x(o,"dark"),o=t.getTheme(e.light),s=v(o),n+=`${u("global")}light:${s.fg};`,n+=`${u("global")}light-bg:${s.bg};`,n+=x(o,"light")}return n}function x(e,t){t=t!=null?`${t}-`:"";let r="";const n=e.colors?.["gitDecoration.addedResourceForeground"]??e.colors?.["terminal.ansiGreen"];n!=null&&(r+=`${u("global")}${t}addition-color:${n};`);const o=e.colors?.["gitDecoration.deletedResourceForeground"]??e.colors?.["terminal.ansiRed"];o!=null&&(r+=`${u("global")}${t}deletion-color:${o};`);const s=e.colors?.["gitDecoration.modifiedResourceForeground"]??e.colors?.["terminal.ansiBlue"];return s!=null&&(r+=`${u("global")}${t}modified-color:${s};`),r}function Te(e){let t=e.children[0];for(;t!=null;){if(t.type==="element"&&t.tagName==="code")return t.children;"children"in t?t=t.children[0]:t=null}throw console.error(e),new Error("getLineNodes: Unable to find children")}function Ee(e){return{...G,...e}}function $e(e,t){const r=te(e,t);return t?r:e.diffHeaderHeight+r}function te(e,t){return e.paddingTop??(t?e.spacing:0)}function Re(e){return e.paddingBottom??e.spacing}function Ce(e){switch(e){case"simple":return 4;case"metadata":case"line-info":case"line-info-basic":case"custom":return 32}}export{T as A,Ee as B,Ce as C,g as R,ye as a,pe as b,R as c,ge as d,we as e,ue as f,W as g,ke as h,ve as i,be as j,he as k,me as l,m,de as n,$e as o,P as p,Re as q,D as r,xe as s,je as t,Te as u,U as v,u as w,fe as x,$ as y,S as z};
@@ -1 +1 @@
1
- import{r as a}from"./index-8TL2HlaR.js";import{dA as l,dB as c,W as d,dC as u}from"./SessionSwitcherDropdown-D5bWfZNA.js";const o=5e3,f=(r,t)=>{if(!r)return 1;let e=1;for(let n=0;n<r.length;n+=1)if(r.charCodeAt(n)===10&&(e+=1,e>t))return e;return e},y=r=>{const e=(r instanceof Error?r.message:String(r??"")).toLowerCase();return e.includes("file not found")||e.includes("not found")||e.includes("enoent")||e.includes("no such file")||e.includes("does not exist")?"missing":"unreadable"},g=async(r,t,e)=>{if(r.readFile)return(await r.readFile(t,{optional:!0,directory:e?.directory})).content??"";const n=new URLSearchParams({path:t,optional:"true"});e?.directory&&n.set("directory",e.directory);const i=await a(`/api/fs/read?${n.toString()}`,{cache:"no-store",headers:e?.directory?{"x-opencode-directory":e.directory}:void 0});if(!i.ok){const s=await i.json().catch(()=>({error:i.statusText}));throw new Error(s.error||"Failed to read file")}return i.text()},w=async(r,t,e)=>{if(l(t)||c(t)||d(t))return{ok:!0};try{const n=await g(r,t,e);return u(n)?{ok:!1,reason:"binary"}:f(n,o)>o?{ok:!1,reason:"too-large"}:{ok:!0}}catch(n){return{ok:!1,reason:y(n)}}},x=r=>r==="too-large"?`File is too large to open (>${o.toLocaleString("en-US")} lines)`:r==="missing"?"File not found":r==="binary"?"Cannot preview binary file":"Failed to open file";export{x as g,w as v};
1
+ import{r as a}from"./index-BAqpUCjs.js";import{dv as l,dw as c,W as d,dx as u}from"./SessionSwitcherDropdown-DROjbyIu.js";const o=5e3,f=(r,t)=>{if(!r)return 1;let e=1;for(let n=0;n<r.length;n+=1)if(r.charCodeAt(n)===10&&(e+=1,e>t))return e;return e},y=r=>{const e=(r instanceof Error?r.message:String(r??"")).toLowerCase();return e.includes("file not found")||e.includes("not found")||e.includes("enoent")||e.includes("no such file")||e.includes("does not exist")?"missing":"unreadable"},g=async(r,t,e)=>{if(r.readFile)return(await r.readFile(t,{optional:!0,directory:e?.directory})).content??"";const n=new URLSearchParams({path:t,optional:"true"});e?.directory&&n.set("directory",e.directory);const i=await a(`/api/fs/read?${n.toString()}`,{cache:"no-store",headers:e?.directory?{"x-opencode-directory":e.directory}:void 0});if(!i.ok){const s=await i.json().catch(()=>({error:i.statusText}));throw new Error(s.error||"Failed to read file")}return i.text()},w=async(r,t,e)=>{if(l(t)||c(t)||d(t))return{ok:!0};try{const n=await g(r,t,e);return u(n)?{ok:!1,reason:"binary"}:f(n,o)>o?{ok:!1,reason:"too-large"}:{ok:!0}}catch(n){return{ok:!1,reason:y(n)}}},x=r=>r==="too-large"?`File is too large to open (>${o.toLocaleString("en-US")} lines)`:r==="missing"?"File not found":r==="binary"?"Cannot preview binary file":"Failed to open file";export{x as g,w as v};