@pierre/diffs 1.3.0-beta.3 → 1.3.0-beta.5

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 (161) hide show
  1. package/README.md +6 -6
  2. package/dist/components/CodeView.js +6 -6
  3. package/dist/components/CodeView.js.map +1 -1
  4. package/dist/components/File.d.ts +3 -2
  5. package/dist/components/File.d.ts.map +1 -1
  6. package/dist/components/File.js +35 -21
  7. package/dist/components/File.js.map +1 -1
  8. package/dist/components/FileDiff.d.ts +8 -4
  9. package/dist/components/FileDiff.d.ts.map +1 -1
  10. package/dist/components/FileDiff.js +66 -56
  11. package/dist/components/FileDiff.js.map +1 -1
  12. package/dist/components/FileStream.js +4 -2
  13. package/dist/components/FileStream.js.map +1 -1
  14. package/dist/components/UnresolvedFile.js +1 -1
  15. package/dist/components/VirtualizedFile.d.ts +6 -2
  16. package/dist/components/VirtualizedFile.d.ts.map +1 -1
  17. package/dist/components/VirtualizedFile.js +89 -24
  18. package/dist/components/VirtualizedFile.js.map +1 -1
  19. package/dist/components/VirtualizedFileDiff.d.ts +8 -2
  20. package/dist/components/VirtualizedFileDiff.d.ts.map +1 -1
  21. package/dist/components/VirtualizedFileDiff.js +91 -15
  22. package/dist/components/VirtualizedFileDiff.js.map +1 -1
  23. package/dist/editor/command.d.ts +1 -1
  24. package/dist/editor/command.d.ts.map +1 -1
  25. package/dist/editor/command.js +3 -3
  26. package/dist/editor/command.js.map +1 -1
  27. package/dist/editor/editStack.d.ts +1 -1
  28. package/dist/editor/editor.d.ts +37 -9
  29. package/dist/editor/editor.d.ts.map +1 -1
  30. package/dist/editor/editor.js +558 -449
  31. package/dist/editor/editor.js.map +1 -1
  32. package/dist/editor/editor2.js +1 -1
  33. package/dist/editor/editor2.js.map +1 -1
  34. package/dist/editor/index.d.ts +2 -2
  35. package/dist/editor/lineAnnotations.d.ts +2 -1
  36. package/dist/editor/lineAnnotations.d.ts.map +1 -1
  37. package/dist/editor/lineAnnotations.js +111 -1
  38. package/dist/editor/lineAnnotations.js.map +1 -1
  39. package/dist/editor/marker.d.ts +33 -0
  40. package/dist/editor/marker.d.ts.map +1 -0
  41. package/dist/editor/marker.js +185 -0
  42. package/dist/editor/marker.js.map +1 -0
  43. package/dist/editor/pieceTable.d.ts +8 -3
  44. package/dist/editor/pieceTable.d.ts.map +1 -1
  45. package/dist/editor/pieceTable.js +74 -12
  46. package/dist/editor/pieceTable.js.map +1 -1
  47. package/dist/editor/searchPanel.d.ts +12 -3
  48. package/dist/editor/searchPanel.d.ts.map +1 -1
  49. package/dist/editor/searchPanel.js +168 -54
  50. package/dist/editor/searchPanel.js.map +1 -1
  51. package/dist/editor/selection.d.ts +19 -3
  52. package/dist/editor/selection.d.ts.map +1 -1
  53. package/dist/editor/selection.js +188 -37
  54. package/dist/editor/selection.js.map +1 -1
  55. package/dist/editor/{quickEdit.d.ts → selectionAction.d.ts} +8 -8
  56. package/dist/editor/selectionAction.d.ts.map +1 -0
  57. package/dist/editor/{quickEdit.js → selectionAction.js} +18 -18
  58. package/dist/editor/selectionAction.js.map +1 -0
  59. package/dist/editor/sprite.d.ts +4 -3
  60. package/dist/editor/sprite.d.ts.map +1 -1
  61. package/dist/editor/sprite.js +19 -5
  62. package/dist/editor/sprite.js.map +1 -1
  63. package/dist/editor/textDocument.d.ts +4 -4
  64. package/dist/editor/textDocument.d.ts.map +1 -1
  65. package/dist/editor/textDocument.js +7 -7
  66. package/dist/editor/textDocument.js.map +1 -1
  67. package/dist/editor/textMeasure.d.ts +1 -0
  68. package/dist/editor/textMeasure.d.ts.map +1 -1
  69. package/dist/editor/textMeasure.js +6 -0
  70. package/dist/editor/textMeasure.js.map +1 -1
  71. package/dist/editor/tokenzier.js +20 -9
  72. package/dist/editor/tokenzier.js.map +1 -1
  73. package/dist/editor/utils.d.ts +3 -1
  74. package/dist/editor/utils.d.ts.map +1 -1
  75. package/dist/editor/utils.js +16 -1
  76. package/dist/editor/utils.js.map +1 -1
  77. package/dist/highlighter/shared_highlighter.js +3 -29
  78. package/dist/highlighter/shared_highlighter.js.map +1 -1
  79. package/dist/highlighter/themes/attachResolvedThemes.js +4 -3
  80. package/dist/highlighter/themes/attachResolvedThemes.js.map +1 -1
  81. package/dist/highlighter/themes/cleanUpResolvedThemes.js +3 -2
  82. package/dist/highlighter/themes/cleanUpResolvedThemes.js.map +1 -1
  83. package/dist/highlighter/themes/constants.d.ts +1 -7
  84. package/dist/highlighter/themes/constants.d.ts.map +1 -1
  85. package/dist/highlighter/themes/constants.js +1 -4
  86. package/dist/highlighter/themes/constants.js.map +1 -1
  87. package/dist/highlighter/themes/getResolvedOrResolveTheme.js +2 -2
  88. package/dist/highlighter/themes/getResolvedOrResolveTheme.js.map +1 -1
  89. package/dist/highlighter/themes/getResolvedThemes.js +2 -8
  90. package/dist/highlighter/themes/getResolvedThemes.js.map +1 -1
  91. package/dist/highlighter/themes/hasResolvedThemes.js +2 -3
  92. package/dist/highlighter/themes/hasResolvedThemes.js.map +1 -1
  93. package/dist/highlighter/themes/registerCustomCSSVariableTheme.js +1 -1
  94. package/dist/highlighter/themes/registerCustomTheme.d.ts +5 -3
  95. package/dist/highlighter/themes/registerCustomTheme.d.ts.map +1 -1
  96. package/dist/highlighter/themes/registerCustomTheme.js +15 -5
  97. package/dist/highlighter/themes/registerCustomTheme.js.map +1 -1
  98. package/dist/highlighter/themes/resolveTheme.js +6 -27
  99. package/dist/highlighter/themes/resolveTheme.js.map +1 -1
  100. package/dist/highlighter/themes/resolveThemes.js +5 -12
  101. package/dist/highlighter/themes/resolveThemes.js.map +1 -1
  102. package/dist/highlighter/themes/themeResolution.d.ts +8 -0
  103. package/dist/highlighter/themes/themeResolution.d.ts.map +1 -0
  104. package/dist/highlighter/themes/themeResolution.js +22 -0
  105. package/dist/highlighter/themes/themeResolution.js.map +1 -0
  106. package/dist/highlighter/themes/themeResolver.d.ts +8 -0
  107. package/dist/highlighter/themes/themeResolver.d.ts.map +1 -0
  108. package/dist/highlighter/themes/themeResolver.js +8 -0
  109. package/dist/highlighter/themes/themeResolver.js.map +1 -0
  110. package/dist/index.d.ts +4 -4
  111. package/dist/index.js +3 -3
  112. package/dist/managers/InteractionManager.js +1 -1
  113. package/dist/managers/InteractionManager.js.map +1 -1
  114. package/dist/managers/ResizeManager.js +1 -1
  115. package/dist/managers/ResizeManager.js.map +1 -1
  116. package/dist/react/CodeView.js +1 -1
  117. package/dist/react/index.d.ts +2 -2
  118. package/dist/react/utils/useFileDiffInstance.js +1 -0
  119. package/dist/react/utils/useFileDiffInstance.js.map +1 -1
  120. package/dist/renderers/DiffHunksRenderer.d.ts +6 -2
  121. package/dist/renderers/DiffHunksRenderer.d.ts.map +1 -1
  122. package/dist/renderers/DiffHunksRenderer.js +183 -12
  123. package/dist/renderers/DiffHunksRenderer.js.map +1 -1
  124. package/dist/renderers/FileRenderer.d.ts +2 -2
  125. package/dist/renderers/FileRenderer.d.ts.map +1 -1
  126. package/dist/renderers/FileRenderer.js +17 -5
  127. package/dist/renderers/FileRenderer.js.map +1 -1
  128. package/dist/ssr/FileDiffReact.js +1 -1
  129. package/dist/ssr/index.d.ts +2 -2
  130. package/dist/types.d.ts +25 -8
  131. package/dist/types.d.ts.map +1 -1
  132. package/dist/utils/getHighlighterThemeStyles.js +16 -12
  133. package/dist/utils/getHighlighterThemeStyles.js.map +1 -1
  134. package/dist/utils/includesFileAnnotations.d.ts +17 -0
  135. package/dist/utils/includesFileAnnotations.d.ts.map +1 -0
  136. package/dist/utils/includesFileAnnotations.js +19 -0
  137. package/dist/utils/includesFileAnnotations.js.map +1 -0
  138. package/dist/utils/parseMergeConflictDiffFromFile.js.map +1 -1
  139. package/dist/utils/parsePatchFiles.js +93 -4
  140. package/dist/utils/parsePatchFiles.js.map +1 -1
  141. package/dist/utils/renderDiffWithHighlighter.js +4 -2
  142. package/dist/utils/renderDiffWithHighlighter.js.map +1 -1
  143. package/dist/utils/renderFileWithHighlighter.js +4 -2
  144. package/dist/utils/renderFileWithHighlighter.js.map +1 -1
  145. package/dist/utils/updateDiffHunks.d.ts +13 -0
  146. package/dist/utils/updateDiffHunks.d.ts.map +1 -0
  147. package/dist/utils/updateDiffHunks.js +171 -0
  148. package/dist/utils/updateDiffHunks.js.map +1 -0
  149. package/dist/utils/virtualDiffLayout.d.ts +2 -1
  150. package/dist/utils/virtualDiffLayout.d.ts.map +1 -1
  151. package/dist/utils/virtualDiffLayout.js +9 -1
  152. package/dist/utils/virtualDiffLayout.js.map +1 -1
  153. package/dist/worker/{wasm-BaDzIkIn.js → wasm-qE0LgnY3.js} +2 -2
  154. package/dist/worker/{wasm-BaDzIkIn.js.map → wasm-qE0LgnY3.js.map} +1 -1
  155. package/dist/worker/worker-portable.js +1016 -275
  156. package/dist/worker/worker-portable.js.map +1 -1
  157. package/dist/worker/worker.js +31 -19
  158. package/dist/worker/worker.js.map +1 -1
  159. package/package.json +5 -10
  160. package/dist/editor/quickEdit.d.ts.map +0 -1
  161. package/dist/editor/quickEdit.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"FileStream.js","names":["options: FileStreamOptions"],"sources":["../../src/components/FileStream.ts"],"sourcesContent":["import { DEFAULT_THEMES, DIFFS_TAG_NAME } from '../constants';\nimport { getSharedHighlighter } from '../highlighter/shared_highlighter';\nimport { queueRender } from '../managers/UniversalRenderingManager';\nimport { CodeToTokenTransformStream, type RecallToken } from '../shiki-stream';\nimport type {\n AppliedThemeStyleCache,\n BaseCodeOptions,\n DiffsHighlighter,\n SupportedLanguages,\n ThemedToken,\n ThemeTypes,\n} from '../types';\nimport { createSpanFromToken } from '../utils/createSpanNodeFromToken';\nimport { wrapThemeCSS } from '../utils/cssWrappers';\nimport { formatCSSVariablePrefix } from '../utils/formatCSSVariablePrefix';\nimport { getHighlighterOptions } from '../utils/getHighlighterOptions';\nimport { getHighlighterThemeStyles } from '../utils/getHighlighterThemeStyles';\nimport { getOrCreateCodeNode } from '../utils/getOrCreateCodeNode';\nimport { upsertHostThemeStyle } from '../utils/hostTheme';\nimport { getMeasuredScrollbarGutter } from '../utils/scrollbarGutter';\nimport { setPreNodeProperties } from '../utils/setWrapperNodeProps';\n\nexport interface FileStreamOptions extends BaseCodeOptions {\n lang?: SupportedLanguages;\n startingLineIndex?: number;\n\n onPreRender?(instance: FileStream): unknown;\n onPostRender?(instance: FileStream): unknown;\n\n onStreamStart?(controller: WritableStreamDefaultController): unknown;\n onStreamWrite?(token: ThemedToken | RecallToken): unknown;\n onStreamClose?(): unknown;\n onStreamAbort?(reason: unknown): unknown;\n}\n\nlet instanceId = -1;\n\nexport class FileStream {\n readonly __id: string = `file-stream:${++instanceId}`;\n\n private highlighter: DiffsHighlighter | undefined;\n private stream: ReadableStream<string> | undefined;\n private abortController: AbortController | undefined;\n private fileContainer: HTMLElement | undefined;\n private pre: HTMLPreElement | undefined;\n private code: HTMLElement | undefined;\n private gutterElement: HTMLElement | undefined;\n private contentElement: HTMLElement | undefined;\n private themeCSSStyle: HTMLStyleElement | undefined;\n private appliedThemeCSS: AppliedThemeStyleCache | undefined;\n private currentRowCount = 0;\n\n constructor(public options: FileStreamOptions = { theme: DEFAULT_THEMES }) {\n this.currentLineIndex = this.options.startingLineIndex ?? 1;\n }\n\n cleanUp(): void {\n this.abortController?.abort();\n this.abortController = undefined;\n }\n\n setThemeType(themeType: ThemeTypes): void {\n if ((this.options.themeType ?? 'system') === themeType) {\n return;\n }\n this.options = { ...this.options, themeType };\n if (\n typeof this.options.theme === 'string' ||\n this.fileContainer == null ||\n this.appliedThemeCSS == null\n ) {\n return;\n }\n this.applyThemeState(\n this.fileContainer,\n this.appliedThemeCSS.themeStyles,\n themeType,\n this.appliedThemeCSS.baseThemeType\n );\n }\n\n private async initializeHighlighter(): Promise<DiffsHighlighter> {\n this.highlighter = await getSharedHighlighter(\n getHighlighterOptions(this.options.lang, this.options)\n );\n return this.highlighter;\n }\n\n private queuedSetupArgs: [ReadableStream<string>, HTMLElement] | undefined;\n async setup(\n _source: ReadableStream<string>,\n _wrapper: HTMLElement\n ): Promise<void> {\n const isSettingUp = this.queuedSetupArgs != null;\n this.queuedSetupArgs = [_source, _wrapper];\n if (isSettingUp) {\n // TODO(amadeus): Make it so that this function can be properly\n // awaitable, maybe?\n return;\n }\n this.highlighter ??= await this.initializeHighlighter();\n\n const [source, wrapper] = this.queuedSetupArgs;\n this.queuedSetupArgs = undefined;\n\n const stream = source;\n\n this.setupStream(stream, wrapper, this.highlighter);\n }\n\n private setupStream(\n stream: ReadableStream<string>,\n wrapper: HTMLElement,\n highlighter: DiffsHighlighter\n ): void {\n const {\n disableLineNumbers = false,\n overflow = 'scroll',\n theme = DEFAULT_THEMES,\n themeType = 'system',\n } = this.options;\n const fileContainer = this.getOrCreateFileContainer();\n if (fileContainer.parentElement == null) {\n wrapper.appendChild(fileContainer);\n }\n this.pre ??= document.createElement('pre');\n if (this.pre.parentElement == null) {\n fileContainer.shadowRoot?.appendChild(this.pre);\n }\n const baseThemeType =\n typeof theme === 'string' ? highlighter.getTheme(theme).type : undefined;\n const themeStyles = getHighlighterThemeStyles({ theme, highlighter });\n this.applyThemeState(fileContainer, themeStyles, themeType, baseThemeType);\n const pre = setPreNodeProperties(this.pre, {\n type: 'file',\n diffIndicators: 'none',\n disableBackground: true,\n disableLineNumbers,\n overflow,\n split: false,\n totalLines: 0,\n });\n pre.textContent = '';\n\n this.pre = pre;\n this.code = getOrCreateCodeNode({ code: this.code, pre });\n this.gutterElement = undefined;\n this.contentElement = undefined;\n this.currentRowCount = 0;\n this.currentLineElement = undefined;\n this.currentLineIndex = this.options.startingLineIndex ?? 1;\n this.abortController?.abort();\n this.abortController = new AbortController();\n const { onStreamStart, onStreamClose, onStreamAbort } = this.options;\n // Cancel the prior source so upstream producers stop generating tokens.\n // Swallow AbortError / locked-stream rejections since we're tearing down.\n this.stream?.cancel().catch(() => {});\n this.stream = stream;\n this.stream\n .pipeThrough(\n typeof theme === 'string'\n ? new CodeToTokenTransformStream({\n ...this.options,\n theme,\n highlighter,\n allowRecalls: true,\n defaultColor: false,\n cssVariablePrefix: formatCSSVariablePrefix('token'),\n })\n : new CodeToTokenTransformStream({\n ...this.options,\n themes: theme,\n highlighter,\n allowRecalls: true,\n defaultColor: false,\n cssVariablePrefix: formatCSSVariablePrefix('token'),\n })\n )\n .pipeTo(\n new WritableStream({\n start(controller) {\n onStreamStart?.(controller);\n },\n close() {\n onStreamClose?.();\n },\n abort(reason) {\n onStreamAbort?.(reason);\n },\n write: this.handleWrite,\n }),\n { signal: this.abortController.signal }\n )\n .catch((error) => {\n // Ignore AbortError - it's expected when cleaning up\n if (error.name !== 'AbortError') {\n console.error('FileStream pipe error:', error);\n }\n });\n }\n\n private queuedTokens: (ThemedToken | RecallToken)[] = [];\n private handleWrite = (token: ThemedToken | RecallToken) => {\n // If we've recalled tokens we haven't rendered yet, we can just yeet them\n // and never apply them\n if ('recall' in token && this.queuedTokens.length >= token.recall) {\n this.queuedTokens.length = this.queuedTokens.length - token.recall;\n } else {\n this.queuedTokens.push(token);\n }\n queueRender(this.render);\n this.options.onStreamWrite?.(token);\n };\n\n private currentLineIndex: number;\n private currentLineElement: HTMLElement | undefined;\n private render = () => {\n this.options.onPreRender?.(this);\n const { gutter, content } = this.getOrCreateStreamColumns();\n const gutterFragment = document.createDocumentFragment();\n const contentFragment = document.createDocumentFragment();\n for (const token of this.queuedTokens) {\n if ('recall' in token) {\n if (this.currentLineElement == null) {\n throw new Error(\n 'FileStream.render: no current line element, shouldnt be possible to get here'\n );\n }\n if (token.recall > this.currentLineElement.childNodes.length) {\n throw new Error(\n `FileStream.render: Token recall exceed the current line, there's probably a bug...`\n );\n }\n for (let i = 0; i < token.recall; i++) {\n this.currentLineElement.lastChild?.remove();\n }\n } else {\n const span = createSpanFromToken(token);\n if (this.currentLineElement == null) {\n const { gutterLine, contentLine } = this.createLine();\n gutterFragment.appendChild(gutterLine);\n contentFragment.appendChild(contentLine);\n }\n this.currentLineElement?.appendChild(span);\n if (token.content === '\\n') {\n this.currentLineIndex++;\n const { gutterLine, contentLine } = this.createLine();\n gutterFragment.appendChild(gutterLine);\n contentFragment.appendChild(contentLine);\n }\n }\n }\n if (gutterFragment.childNodes.length > 0) {\n gutter.appendChild(gutterFragment);\n }\n if (contentFragment.childNodes.length > 0) {\n content.appendChild(contentFragment);\n }\n this.queuedTokens.length = 0;\n this.options.onPostRender?.(this);\n };\n\n private getOrCreateStreamColumns(): {\n gutter: HTMLElement;\n content: HTMLElement;\n } {\n if (this.code == null) {\n throw new Error('FileStream: expected code element to exist');\n }\n if (this.gutterElement != null && this.contentElement != null) {\n return { gutter: this.gutterElement, content: this.contentElement };\n }\n const gutter = document.createElement('div');\n gutter.dataset.gutter = '';\n const content = document.createElement('div');\n content.dataset.content = '';\n this.code.appendChild(gutter);\n this.code.appendChild(content);\n this.gutterElement = gutter;\n this.contentElement = content;\n return { gutter, content };\n }\n\n private updateRowSpan(): void {\n if (this.gutterElement != null) {\n this.gutterElement.style.gridRow = `span ${this.currentRowCount}`;\n }\n if (this.contentElement != null) {\n this.contentElement.style.gridRow = `span ${this.currentRowCount}`;\n }\n }\n\n private createLine(): { gutterLine: HTMLElement; contentLine: HTMLElement } {\n const lineNumber = this.currentLineIndex;\n const lineIndex = `${lineNumber - 1}`;\n const gutterLine = document.createElement('div');\n gutterLine.dataset.columnNumber = `${lineNumber}`;\n gutterLine.dataset.lineType = 'context';\n gutterLine.dataset.lineIndex = lineIndex;\n\n const numberContent = document.createElement('span');\n numberContent.dataset.lineNumberContent = '';\n numberContent.textContent = `${lineNumber}`;\n gutterLine.appendChild(numberContent);\n\n const contentLine = document.createElement('div');\n contentLine.dataset.line = `${lineNumber}`;\n contentLine.dataset.lineType = 'context';\n contentLine.dataset.lineIndex = lineIndex;\n\n this.currentRowCount += 1;\n this.updateRowSpan();\n this.currentLineElement = contentLine;\n return { gutterLine, contentLine };\n }\n\n private getOrCreateFileContainer(fileContainer?: HTMLElement): HTMLElement {\n if (\n (fileContainer != null && fileContainer === this.fileContainer) ||\n (fileContainer == null && this.fileContainer != null)\n ) {\n return this.fileContainer;\n }\n if (\n this.fileContainer != null &&\n fileContainer != null &&\n fileContainer !== this.fileContainer\n ) {\n this.themeCSSStyle = undefined;\n this.appliedThemeCSS = undefined;\n }\n this.fileContainer =\n fileContainer ?? document.createElement(DIFFS_TAG_NAME);\n return this.fileContainer;\n }\n\n private applyThemeState(\n container: HTMLElement,\n themeStyles: string,\n themeType: ThemeTypes,\n baseThemeType?: 'light' | 'dark'\n ): void {\n const shadowRoot =\n container.shadowRoot ?? container.attachShadow({ mode: 'open' });\n const effectiveThemeType = baseThemeType ?? themeType;\n const currentTheme = this.options.theme ?? DEFAULT_THEMES;\n const theme =\n typeof currentTheme === 'string' ? currentTheme : { ...currentTheme };\n const scrollbarGutter = getMeasuredScrollbarGutter(shadowRoot);\n if (\n this.themeCSSStyle?.parentNode === shadowRoot &&\n this.appliedThemeCSS?.themeStyles === themeStyles &&\n this.appliedThemeCSS.themeType === effectiveThemeType &&\n this.appliedThemeCSS.scrollbarGutter === scrollbarGutter\n ) {\n this.appliedThemeCSS.theme = theme;\n return;\n }\n this.themeCSSStyle = upsertHostThemeStyle({\n shadowRoot,\n currentNode: this.themeCSSStyle,\n themeCSS: wrapThemeCSS(themeStyles, effectiveThemeType, scrollbarGutter),\n });\n this.appliedThemeCSS =\n this.themeCSSStyle != null\n ? {\n theme,\n themeStyles,\n themeType: effectiveThemeType,\n baseThemeType,\n scrollbarGutter,\n }\n : undefined;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAmCA,IAAI,aAAa;AAEjB,IAAa,aAAb,MAAwB;CACtB,AAAS,OAAe,eAAe,EAAE;CAEzC,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ,kBAAkB;CAE1B,YAAY,AAAOA,UAA6B,EAAE,OAAO,gBAAgB,EAAE;EAAxD;AACjB,OAAK,mBA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BACH,iBAAiB,SAAS,cAAc,eAAe;AACzD,SAAO,KAAK;;CAGd,AAAQ,gBACN,WACA,aACA,WACA,eACM;EACN,MAAM,aACJ,UAAU,cAAc,UAAU,aAAa,EAAE,MAAM,QAAQ,CAAC;EAClE,MAAM,qBAAqB,iBAAiB;EAC5C,MAAM,eAAe,KAAK,QAAQ,SAAS;EAC3C,MAAM,QACJ,OAAO,iBAAiB,WAAW,eAAe,EAAE,GAAG,cAAc;EACvE,MAAM,kBAAkB,2BAA2B,WAAW;AAC9D,MACE,KAAK,eAAe,eAAe,cACnC,KAAK,iBAAiB,gBAAgB,eACtC,KAAK,gBAAgB,cAAc,sBACnC,KAAK,gBAAgB,oBAAoB,iBACzC;AACA,QAAK,gBAAgB,QAAQ;AAC7B;;AAEF,OAAK,gBAAgB,qBAAqB;GACxC;GACA,aAAa,KAAK;GAClB,UAAU,aAAa,aAAa,oBAAoB,gBAAgB;GACzE,CAAC;AACF,OAAK,kBACH,KAAK,iBAAiB,OAClB;GACE;GACA;GACA,WAAW;GACX;GACA;GACD,GACD"}
1
+ {"version":3,"file":"FileStream.js","names":["options: FileStreamOptions"],"sources":["../../src/components/FileStream.ts"],"sourcesContent":["import { DEFAULT_THEMES, DIFFS_TAG_NAME } from '../constants';\nimport { getSharedHighlighter } from '../highlighter/shared_highlighter';\nimport { queueRender } from '../managers/UniversalRenderingManager';\nimport { CodeToTokenTransformStream, type RecallToken } from '../shiki-stream';\nimport type {\n AppliedThemeStyleCache,\n BaseCodeOptions,\n DiffsHighlighter,\n SupportedLanguages,\n ThemedToken,\n ThemeTypes,\n} from '../types';\nimport { createSpanFromToken } from '../utils/createSpanNodeFromToken';\nimport { wrapThemeCSS } from '../utils/cssWrappers';\nimport { formatCSSVariablePrefix } from '../utils/formatCSSVariablePrefix';\nimport { getHighlighterOptions } from '../utils/getHighlighterOptions';\nimport { getHighlighterThemeStyles } from '../utils/getHighlighterThemeStyles';\nimport { getOrCreateCodeNode } from '../utils/getOrCreateCodeNode';\nimport { upsertHostThemeStyle } from '../utils/hostTheme';\nimport { getMeasuredScrollbarGutter } from '../utils/scrollbarGutter';\nimport { setPreNodeProperties } from '../utils/setWrapperNodeProps';\n\nexport interface FileStreamOptions extends BaseCodeOptions {\n lang?: SupportedLanguages;\n startingLineIndex?: number;\n\n onPreRender?(instance: FileStream): unknown;\n onPostRender?(instance: FileStream): unknown;\n\n onStreamStart?(controller: WritableStreamDefaultController): unknown;\n onStreamWrite?(token: ThemedToken | RecallToken): unknown;\n onStreamClose?(): unknown;\n onStreamAbort?(reason: unknown): unknown;\n}\n\nlet instanceId = -1;\n\nexport class FileStream {\n readonly __id: string = `file-stream:${++instanceId}`;\n\n private highlighter: DiffsHighlighter | undefined;\n private stream: ReadableStream<string> | undefined;\n private abortController: AbortController | undefined;\n private fileContainer: HTMLElement | undefined;\n private pre: HTMLPreElement | undefined;\n private code: HTMLElement | undefined;\n private gutterElement: HTMLElement | undefined;\n private contentElement: HTMLElement | undefined;\n private themeCSSStyle: HTMLStyleElement | undefined;\n private appliedThemeCSS: AppliedThemeStyleCache | undefined;\n private currentRowCount = 0;\n\n constructor(public options: FileStreamOptions = { theme: DEFAULT_THEMES }) {\n this.currentLineIndex = this.options.startingLineIndex ?? 1;\n }\n\n cleanUp(): void {\n this.abortController?.abort();\n this.abortController = undefined;\n }\n\n setThemeType(themeType: ThemeTypes): void {\n if ((this.options.themeType ?? 'system') === themeType) {\n return;\n }\n this.options = { ...this.options, themeType };\n if (\n typeof this.options.theme === 'string' ||\n this.fileContainer == null ||\n this.appliedThemeCSS == null\n ) {\n return;\n }\n this.applyThemeState(\n this.fileContainer,\n this.appliedThemeCSS.themeStyles,\n themeType,\n this.appliedThemeCSS.baseThemeType\n );\n }\n\n private async initializeHighlighter(): Promise<DiffsHighlighter> {\n this.highlighter = await getSharedHighlighter(\n getHighlighterOptions(this.options.lang, this.options)\n );\n return this.highlighter;\n }\n\n private queuedSetupArgs: [ReadableStream<string>, HTMLElement] | undefined;\n async setup(\n _source: ReadableStream<string>,\n _wrapper: HTMLElement\n ): Promise<void> {\n const isSettingUp = this.queuedSetupArgs != null;\n this.queuedSetupArgs = [_source, _wrapper];\n if (isSettingUp) {\n // TODO(amadeus): Make it so that this function can be properly\n // awaitable, maybe?\n return;\n }\n this.highlighter ??= await this.initializeHighlighter();\n\n const [source, wrapper] = this.queuedSetupArgs;\n this.queuedSetupArgs = undefined;\n\n const stream = source;\n\n this.setupStream(stream, wrapper, this.highlighter);\n }\n\n private setupStream(\n stream: ReadableStream<string>,\n wrapper: HTMLElement,\n highlighter: DiffsHighlighter\n ): void {\n const {\n disableLineNumbers = false,\n overflow = 'scroll',\n theme = DEFAULT_THEMES,\n themeType = 'system',\n } = this.options;\n const fileContainer = this.getOrCreateFileContainer();\n if (fileContainer.parentElement == null) {\n wrapper.appendChild(fileContainer);\n }\n this.pre ??= document.createElement('pre');\n if (this.pre.parentElement == null) {\n fileContainer.shadowRoot?.appendChild(this.pre);\n }\n const baseThemeType =\n typeof theme === 'string' ? highlighter.getTheme(theme).type : undefined;\n const themeStyles = getHighlighterThemeStyles({ theme, highlighter });\n this.applyThemeState(fileContainer, themeStyles, themeType, baseThemeType);\n const pre = setPreNodeProperties(this.pre, {\n type: 'file',\n diffIndicators: 'none',\n disableBackground: true,\n disableLineNumbers,\n overflow,\n split: false,\n totalLines: 0,\n });\n pre.textContent = '';\n\n this.pre = pre;\n this.code = getOrCreateCodeNode({ code: this.code, pre });\n this.gutterElement = undefined;\n this.contentElement = undefined;\n this.currentRowCount = 0;\n this.currentLineElement = undefined;\n this.currentLineIndex = this.options.startingLineIndex ?? 1;\n this.abortController?.abort();\n this.abortController = new AbortController();\n const { onStreamStart, onStreamClose, onStreamAbort } = this.options;\n // Cancel the prior source so upstream producers stop generating tokens.\n // Swallow AbortError / locked-stream rejections since we're tearing down.\n this.stream?.cancel().catch(() => {});\n this.stream = stream;\n this.stream\n // tokenizeTimeLimit: 0 — never trade silently-wrong token colors for\n // latency; see renderFileWithHighlighter for the full rationale.\n .pipeThrough(\n typeof theme === 'string'\n ? new CodeToTokenTransformStream({\n ...this.options,\n theme,\n highlighter,\n allowRecalls: true,\n defaultColor: false,\n cssVariablePrefix: formatCSSVariablePrefix('token'),\n tokenizeTimeLimit: 0,\n })\n : new CodeToTokenTransformStream({\n ...this.options,\n themes: theme,\n highlighter,\n allowRecalls: true,\n defaultColor: false,\n cssVariablePrefix: formatCSSVariablePrefix('token'),\n tokenizeTimeLimit: 0,\n })\n )\n .pipeTo(\n new WritableStream({\n start(controller) {\n onStreamStart?.(controller);\n },\n close() {\n onStreamClose?.();\n },\n abort(reason) {\n onStreamAbort?.(reason);\n },\n write: this.handleWrite,\n }),\n { signal: this.abortController.signal }\n )\n .catch((error) => {\n // Ignore AbortError - it's expected when cleaning up\n if (error.name !== 'AbortError') {\n console.error('FileStream pipe error:', error);\n }\n });\n }\n\n private queuedTokens: (ThemedToken | RecallToken)[] = [];\n private handleWrite = (token: ThemedToken | RecallToken) => {\n // If we've recalled tokens we haven't rendered yet, we can just yeet them\n // and never apply them\n if ('recall' in token && this.queuedTokens.length >= token.recall) {\n this.queuedTokens.length = this.queuedTokens.length - token.recall;\n } else {\n this.queuedTokens.push(token);\n }\n queueRender(this.render);\n this.options.onStreamWrite?.(token);\n };\n\n private currentLineIndex: number;\n private currentLineElement: HTMLElement | undefined;\n private render = () => {\n this.options.onPreRender?.(this);\n const { gutter, content } = this.getOrCreateStreamColumns();\n const gutterFragment = document.createDocumentFragment();\n const contentFragment = document.createDocumentFragment();\n for (const token of this.queuedTokens) {\n if ('recall' in token) {\n if (this.currentLineElement == null) {\n throw new Error(\n 'FileStream.render: no current line element, shouldnt be possible to get here'\n );\n }\n if (token.recall > this.currentLineElement.childNodes.length) {\n throw new Error(\n `FileStream.render: Token recall exceed the current line, there's probably a bug...`\n );\n }\n for (let i = 0; i < token.recall; i++) {\n this.currentLineElement.lastChild?.remove();\n }\n } else {\n const span = createSpanFromToken(token);\n if (this.currentLineElement == null) {\n const { gutterLine, contentLine } = this.createLine();\n gutterFragment.appendChild(gutterLine);\n contentFragment.appendChild(contentLine);\n }\n this.currentLineElement?.appendChild(span);\n if (token.content === '\\n') {\n this.currentLineIndex++;\n const { gutterLine, contentLine } = this.createLine();\n gutterFragment.appendChild(gutterLine);\n contentFragment.appendChild(contentLine);\n }\n }\n }\n if (gutterFragment.childNodes.length > 0) {\n gutter.appendChild(gutterFragment);\n }\n if (contentFragment.childNodes.length > 0) {\n content.appendChild(contentFragment);\n }\n this.queuedTokens.length = 0;\n this.options.onPostRender?.(this);\n };\n\n private getOrCreateStreamColumns(): {\n gutter: HTMLElement;\n content: HTMLElement;\n } {\n if (this.code == null) {\n throw new Error('FileStream: expected code element to exist');\n }\n if (this.gutterElement != null && this.contentElement != null) {\n return { gutter: this.gutterElement, content: this.contentElement };\n }\n const gutter = document.createElement('div');\n gutter.dataset.gutter = '';\n const content = document.createElement('div');\n content.dataset.content = '';\n this.code.appendChild(gutter);\n this.code.appendChild(content);\n this.gutterElement = gutter;\n this.contentElement = content;\n return { gutter, content };\n }\n\n private updateRowSpan(): void {\n if (this.gutterElement != null) {\n this.gutterElement.style.gridRow = `span ${this.currentRowCount}`;\n }\n if (this.contentElement != null) {\n this.contentElement.style.gridRow = `span ${this.currentRowCount}`;\n }\n }\n\n private createLine(): { gutterLine: HTMLElement; contentLine: HTMLElement } {\n const lineNumber = this.currentLineIndex;\n const lineIndex = `${lineNumber - 1}`;\n const gutterLine = document.createElement('div');\n gutterLine.dataset.columnNumber = `${lineNumber}`;\n gutterLine.dataset.lineType = 'context';\n gutterLine.dataset.lineIndex = lineIndex;\n\n const numberContent = document.createElement('span');\n numberContent.dataset.lineNumberContent = '';\n numberContent.textContent = `${lineNumber}`;\n gutterLine.appendChild(numberContent);\n\n const contentLine = document.createElement('div');\n contentLine.dataset.line = `${lineNumber}`;\n contentLine.dataset.lineType = 'context';\n contentLine.dataset.lineIndex = lineIndex;\n\n this.currentRowCount += 1;\n this.updateRowSpan();\n this.currentLineElement = contentLine;\n return { gutterLine, contentLine };\n }\n\n private getOrCreateFileContainer(fileContainer?: HTMLElement): HTMLElement {\n if (\n (fileContainer != null && fileContainer === this.fileContainer) ||\n (fileContainer == null && this.fileContainer != null)\n ) {\n return this.fileContainer;\n }\n if (\n this.fileContainer != null &&\n fileContainer != null &&\n fileContainer !== this.fileContainer\n ) {\n this.themeCSSStyle = undefined;\n this.appliedThemeCSS = undefined;\n }\n this.fileContainer =\n fileContainer ?? document.createElement(DIFFS_TAG_NAME);\n return this.fileContainer;\n }\n\n private applyThemeState(\n container: HTMLElement,\n themeStyles: string,\n themeType: ThemeTypes,\n baseThemeType?: 'light' | 'dark'\n ): void {\n const shadowRoot =\n container.shadowRoot ?? container.attachShadow({ mode: 'open' });\n const effectiveThemeType = baseThemeType ?? themeType;\n const currentTheme = this.options.theme ?? DEFAULT_THEMES;\n const theme =\n typeof currentTheme === 'string' ? currentTheme : { ...currentTheme };\n const scrollbarGutter = getMeasuredScrollbarGutter(shadowRoot);\n if (\n this.themeCSSStyle?.parentNode === shadowRoot &&\n this.appliedThemeCSS?.themeStyles === themeStyles &&\n this.appliedThemeCSS.themeType === effectiveThemeType &&\n this.appliedThemeCSS.scrollbarGutter === scrollbarGutter\n ) {\n this.appliedThemeCSS.theme = theme;\n return;\n }\n this.themeCSSStyle = upsertHostThemeStyle({\n shadowRoot,\n currentNode: this.themeCSSStyle,\n themeCSS: wrapThemeCSS(themeStyles, effectiveThemeType, scrollbarGutter),\n });\n this.appliedThemeCSS =\n this.themeCSSStyle != null\n ? {\n theme,\n themeStyles,\n themeType: effectiveThemeType,\n baseThemeType,\n scrollbarGutter,\n }\n : undefined;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAmCA,IAAI,aAAa;AAEjB,IAAa,aAAb,MAAwB;CACtB,AAAS,OAAe,eAAe,EAAE;CAEzC,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AA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AAiB,QAAQ,KAAK,iBAAiB,KAEhD,QAAO,KAAK;AAEd,MACE,KAAK,iBAAiB,QACtB,iBAAiB,QACjB,kBAAkB,KAAK,eACvB;AACA,QAAK,gBAAgB;AACrB,QAAK,kBAAkB;;AAEzB,OAAK,gBACH,iBAAiB,SAAS,cAAc,eAAe;AACzD,SAAO,KAAK;;CAGd,AAAQ,gBACN,WACA,aACA,WACA,eACM;EACN,MAAM,aACJ,UAAU,cAAc,UAAU,aAAa,EAAE,MAAM,QAAQ,CAAC;EAClE,MAAM,qBAAqB,iBAAiB;EAC5C,MAAM,eAAe,KAAK,QAAQ,SAAS;EAC3C,MAAM,QACJ,OAAO,iBAAiB,WAAW,eAAe,EAAE,GAAG,cAAc;EACvE,MAAM,kBAAkB,2BAA2B,WAAW;AAC9D,MACE,KAAK,eAAe,eAAe,cACnC,KAAK,iBAAiB,gBAAgB,eACtC,KAAK,gBAAgB,cAAc,sBACnC,KAAK,gBAAgB,oBAAoB,iBACzC;AACA,QAAK,gBAAgB,QAAQ;AAC7B;;AAEF,OAAK,gBAAgB,qBAAqB;GACxC;GACA,aAAa,KAAK;GAClB,UAAU,aAAa,aAAa,oBAAoB,gBAAgB;GACzE,CAAC;AACF,OAAK,kBACH,KAAK,iBAAiB,OAClB;GACE;GACA;GACA,WAAW;GACX;GACA;GACD,GACD"}
@@ -2,13 +2,13 @@ import { DEFAULT_THEMES } from "../constants.js";
2
2
  import { areFilesEqual } from "../utils/areFilesEqual.js";
3
3
  import { pluckInteractionOptions } from "../managers/InteractionManager.js";
4
4
  import { createAnnotationWrapperNode } from "../utils/createAnnotationWrapperNode.js";
5
+ import { splitFileContents } from "../utils/splitFileContents.js";
5
6
  import { FileDiff } from "./FileDiff.js";
6
7
  import { getMergeConflictActionSlotName } from "../utils/getMergeConflictActionSlotName.js";
7
8
  import { buildMergeConflictMarkerRows, getMergeConflictActionAnchor, parseMergeConflictDiffFromFile } from "../utils/parseMergeConflictDiffFromFile.js";
8
9
  import { UnresolvedFileHunksRenderer } from "../renderers/UnresolvedFileHunksRenderer.js";
9
10
  import { areMergeConflictActionsEqual } from "../utils/areMergeConflictActionsEqual.js";
10
11
  import { resolveConflict } from "../utils/resolveConflict.js";
11
- import { splitFileContents } from "../utils/splitFileContents.js";
12
12
 
13
13
  //#region src/components/UnresolvedFile.ts
14
14
  let instanceId = -1;
@@ -20,13 +20,16 @@ declare class VirtualizedFile<LAnnotation = undefined> extends File<LAnnotation>
20
20
  private currentCollapsed;
21
21
  constructor(options: FileOptions<LAnnotation> | undefined, virtualizer: Virtualizer | CodeView<LAnnotation>, metrics?: VirtualFileMetrics, workerManager?: WorkerPoolManager, isContainerManaged?: boolean);
22
22
  setMetrics(metrics: VirtualFileMetrics, force?: boolean): void;
23
+ setLineAnnotations(lineAnnotations: LineAnnotation<LAnnotation>[]): void;
24
+ private syncLineAnnotations;
25
+ private hasLineAnnotations;
23
26
  getLineHeight(lineIndex: number, hasMetadataLine?: boolean): number;
24
27
  setOptions(options: FileOptions<LAnnotation> | undefined): void;
25
28
  setThemeType(themeType: ThemeTypes): void;
26
29
  private resetLayoutCache;
27
30
  reconcileHeights(): boolean;
28
31
  onRender: (dirty: boolean) => boolean;
29
- prepareCodeViewItem(file: FileContents, top: number, reset?: PendingCodeViewLayoutReset): number;
32
+ prepareCodeViewItem(file: FileContents, top: number, reset?: PendingCodeViewLayoutReset, lineAnnotations?: LineAnnotation<LAnnotation>[]): number;
30
33
  getLinePosition(lineNumber: number): {
31
34
  top: number;
32
35
  height: number;
@@ -38,11 +41,12 @@ declare class VirtualizedFile<LAnnotation = undefined> extends File<LAnnotation>
38
41
  private computeApproximateSize;
39
42
  setVisibility(visible: boolean): void;
40
43
  rerender(): void;
41
- applyLayoutChange(textDocument: DiffsTextDocument, newLineAnnotations?: LineAnnotation<LAnnotation>[], shouldUpdateBuffer?: boolean): void;
44
+ applyDocumentChange(textDocument: DiffsTextDocument, newLineAnnotations?: LineAnnotation<LAnnotation>[], shouldUpdateBuffer?: boolean): void;
42
45
  render({
43
46
  fileContainer,
44
47
  file,
45
48
  forceRender,
49
+ lineAnnotations,
46
50
  ...props
47
51
  }: FileRenderProps<LAnnotation>): boolean;
48
52
  syncVirtualizedTop(): void;
@@ -1 +1 @@
1
- {"version":3,"file":"VirtualizedFile.d.ts","names":["DiffsTextDocument","FileContents","LineAnnotation","NumericScrollLineAnchor","PendingCodeViewLayoutReset","RenderWindow","StickySpecs","ThemeTypes","VirtualFileMetrics","WorkerPoolManager","CodeView","File","FileOptions","FileRenderProps","Virtualizer","VirtualizedFile","LAnnotation","fileContainer","file","forceRender"],"sources":["../../src/components/VirtualizedFile.d.ts"],"sourcesContent":["import type { DiffsTextDocument, FileContents, LineAnnotation, NumericScrollLineAnchor, PendingCodeViewLayoutReset, RenderWindow, StickySpecs, ThemeTypes, VirtualFileMetrics } from '../types';\nimport type { WorkerPoolManager } from '../worker';\nimport type { CodeView } from './CodeView';\nimport { File, type FileOptions, type FileRenderProps } from './File';\nimport type { Virtualizer } from './Virtualizer';\nexport declare class VirtualizedFile<LAnnotation = undefined> extends File<LAnnotation> {\n private virtualizer;\n private metrics;\n readonly __id: string;\n top: number | undefined;\n height: number;\n private cache;\n private isVisible;\n private isSetup;\n private layoutDirty;\n private forceRenderOverride;\n private currentCollapsed;\n constructor(options: FileOptions<LAnnotation> | undefined, virtualizer: Virtualizer | CodeView<LAnnotation>, metrics?: VirtualFileMetrics, workerManager?: WorkerPoolManager, isContainerManaged?: boolean);\n setMetrics(metrics: VirtualFileMetrics, force?: boolean): void;\n getLineHeight(lineIndex: number, hasMetadataLine?: boolean): number;\n setOptions(options: FileOptions<LAnnotation> | undefined): void;\n setThemeType(themeType: ThemeTypes): void;\n private resetLayoutCache;\n reconcileHeights(): boolean;\n onRender: (dirty: boolean) => boolean;\n prepareCodeViewItem(file: FileContents, top: number, reset?: PendingCodeViewLayoutReset): number;\n getLinePosition(lineNumber: number): {\n top: number;\n height: number;\n } | undefined;\n getNumericScrollAnchor(localViewportTop: number): NumericScrollLineAnchor | undefined;\n getVirtualizedHeight(): number;\n getAdvancedStickySpecs(windowSpecs?: RenderWindow): StickySpecs | undefined;\n cleanUp(recycle?: boolean): void;\n private computeApproximateSize;\n setVisibility(visible: boolean): void;\n rerender(): void;\n applyLayoutChange(textDocument: DiffsTextDocument, newLineAnnotations?: LineAnnotation<LAnnotation>[], shouldUpdateBuffer?: boolean): void;\n render({ fileContainer, file, forceRender, ...props }: FileRenderProps<LAnnotation>): boolean;\n syncVirtualizedTop(): void;\n protected shouldDisableVirtualizationBuffers(): boolean;\n private isSimpleMode;\n private isAdvancedMode;\n private addLayoutCheckpoint;\n private getLayoutCheckpointBeforeLineIndex;\n private getLayoutCheckpointBeforeTop;\n private getVirtualizedTop;\n private getSimpleVirtualizer;\n private isResizeDebuggingEnabled;\n private computeRenderRangeFromWindow;\n}\n//# sourceMappingURL=VirtualizedFile.d.ts.map"],"mappings":";;;;;;;;cAKqBe,iDAAiDJ,KAAKK;;;EAAtDD,SAAAA,IAAAA,EAAAA,MAAe;EAAuCC,GAAAA,EAAAA,MAAAA,GAAAA,SAAAA;EAYtCA,MAAAA,EAAAA,MAAAA;EAAZJ,QAAAA,KAAAA;EAAmDE,QAAAA,SAAAA;EAAuBE,QAAAA,OAAAA;EAATN,QAAAA,WAAAA;EAAiCF,QAAAA,mBAAAA;EAAoCC,QAAAA,gBAAAA;EACvID,WAAAA,CAAAA,OAAAA,EADCI,WACDJ,CADaQ,WACbR,CAAAA,GAAAA,SAAAA,EAAAA,WAAAA,EADoDM,WACpDN,GADkEE,QAClEF,CAD2EQ,WAC3ER,CAAAA,EAAAA,OAAAA,CAAAA,EADmGA,kBACnGA,EAAAA,aAAAA,CAAAA,EADuIC,iBACvID,EAAAA,kBAAAA,CAAAA,EAAAA,OAAAA;EAEYQ,UAAAA,CAAAA,OAAAA,EAFZR,kBAEYQ,EAAAA,KAAAA,CAAAA,EAAAA,OAAAA,CAAAA,EAAAA,IAAAA;EAAZJ,aAAAA,CAAAA,SAAAA,EAAAA,MAAAA,EAAAA,eAAAA,CAAAA,EAAAA,OAAAA,CAAAA,EAAAA,MAAAA;EACIL,UAAAA,CAAAA,OAAAA,EADJK,WACIL,CADQS,WACRT,CAAAA,GAAAA,SAAAA,CAAAA,EAAAA,IAAAA;EAIEN,YAAAA,CAAAA,SAAAA,EAJFM,UAIEN,CAAAA,EAAAA,IAAAA;EAAmCG,QAAAA,gBAAAA;EAKXD,gBAAAA,CAAAA,CAAAA,EAAAA,OAAAA;EAEbE,QAAAA,EAAAA,CAAAA,KAAAA,EAAAA,OAAAA,EAAAA,GAAAA,OAAAA;EAAeC,mBAAAA,CAAAA,IAAAA,EAP1BL,YAO0BK,EAAAA,GAAAA,EAAAA,MAAAA,EAAAA,KAAAA,CAAAA,EAPSF,0BAOTE,CAAAA,EAAAA,MAAAA;EAKpBN,eAAAA,CAAAA,UAAAA,EAAAA,MAAAA,CAAAA,EAAAA;IAAuDgB,GAAAA,EAAAA,MAAAA;IAAfd,MAAAA,EAAAA,MAAAA;EAC/De,CAAAA,GAAAA,SAAAA;EAAeC,sBAAAA,CAAAA,gBAAAA,EAAAA,MAAAA,CAAAA,EAR0Bf,uBAQ1Be,GAAAA,SAAAA;EAAMC,oBAAAA,CAAAA,CAAAA,EAAAA,MAAAA;EAAyCH,sBAAAA,CAAAA,WAAAA,CAAAA,EANlCX,YAMkCW,CAAAA,EANnBV,WAMmBU,GAAAA,SAAAA;EAAhBH,OAAAA,CAAAA,OAAAA,CAAAA,EAAAA,OAAAA,CAAAA,EAAAA,IAAAA;EAjCWF,QAAAA,sBAAAA;EAAI,aAAA,CAAA,OAAA,EAAA,OAAA,CAAA,EAAA,IAAA;;kCAgCtCX,wCAAwCE,eAAec;;;;;;KAChCH,gBAAgBG"}
1
+ {"version":3,"file":"VirtualizedFile.d.ts","names":["DiffsTextDocument","FileContents","LineAnnotation","NumericScrollLineAnchor","PendingCodeViewLayoutReset","RenderWindow","StickySpecs","ThemeTypes","VirtualFileMetrics","WorkerPoolManager","CodeView","File","FileOptions","FileRenderProps","Virtualizer","VirtualizedFile","LAnnotation","fileContainer","file","forceRender","lineAnnotations"],"sources":["../../src/components/VirtualizedFile.d.ts"],"sourcesContent":["import type { DiffsTextDocument, FileContents, LineAnnotation, NumericScrollLineAnchor, PendingCodeViewLayoutReset, RenderWindow, StickySpecs, ThemeTypes, VirtualFileMetrics } from '../types';\nimport type { WorkerPoolManager } from '../worker';\nimport type { CodeView } from './CodeView';\nimport { File, type FileOptions, type FileRenderProps } from './File';\nimport type { Virtualizer } from './Virtualizer';\nexport declare class VirtualizedFile<LAnnotation = undefined> extends File<LAnnotation> {\n private virtualizer;\n private metrics;\n readonly __id: string;\n top: number | undefined;\n height: number;\n private cache;\n private isVisible;\n private isSetup;\n private layoutDirty;\n private forceRenderOverride;\n private currentCollapsed;\n constructor(options: FileOptions<LAnnotation> | undefined, virtualizer: Virtualizer | CodeView<LAnnotation>, metrics?: VirtualFileMetrics, workerManager?: WorkerPoolManager, isContainerManaged?: boolean);\n setMetrics(metrics: VirtualFileMetrics, force?: boolean): void;\n setLineAnnotations(lineAnnotations: LineAnnotation<LAnnotation>[]): void;\n private syncLineAnnotations;\n private hasLineAnnotations;\n getLineHeight(lineIndex: number, hasMetadataLine?: boolean): number;\n setOptions(options: FileOptions<LAnnotation> | undefined): void;\n setThemeType(themeType: ThemeTypes): void;\n private resetLayoutCache;\n reconcileHeights(): boolean;\n onRender: (dirty: boolean) => boolean;\n prepareCodeViewItem(file: FileContents, top: number, reset?: PendingCodeViewLayoutReset, lineAnnotations?: LineAnnotation<LAnnotation>[]): number;\n getLinePosition(lineNumber: number): {\n top: number;\n height: number;\n } | undefined;\n getNumericScrollAnchor(localViewportTop: number): NumericScrollLineAnchor | undefined;\n getVirtualizedHeight(): number;\n getAdvancedStickySpecs(windowSpecs?: RenderWindow): StickySpecs | undefined;\n cleanUp(recycle?: boolean): void;\n private computeApproximateSize;\n setVisibility(visible: boolean): void;\n rerender(): void;\n applyDocumentChange(textDocument: DiffsTextDocument, newLineAnnotations?: LineAnnotation<LAnnotation>[], shouldUpdateBuffer?: boolean): void;\n render({ fileContainer, file, forceRender, lineAnnotations, ...props }: FileRenderProps<LAnnotation>): boolean;\n syncVirtualizedTop(): void;\n protected shouldDisableVirtualizationBuffers(): boolean;\n private isSimpleMode;\n private isAdvancedMode;\n private addLayoutCheckpoint;\n private getLayoutCheckpointBeforeLineIndex;\n private getLayoutCheckpointBeforeTop;\n private getVirtualizedTop;\n private getSimpleVirtualizer;\n private isResizeDebuggingEnabled;\n private computeRenderRangeFromWindow;\n}\n//# sourceMappingURL=VirtualizedFile.d.ts.map"],"mappings":";;;;;;;;cAKqBe,iDAAiDJ,KAAKK;;;EAAtDD,SAAAA,IAAAA,EAAAA,MAAe;EAAuCC,GAAAA,EAAAA,MAAAA,GAAAA,SAAAA;EAYtCA,MAAAA,EAAAA,MAAAA;EAAZJ,QAAAA,KAAAA;EAAmDE,QAAAA,SAAAA;EAAuBE,QAAAA,OAAAA;EAATN,QAAAA,WAAAA;EAAiCF,QAAAA,mBAAAA;EAAoCC,QAAAA,gBAAAA;EACvID,WAAAA,CAAAA,OAAAA,EADCI,WACDJ,CADaQ,WACbR,CAAAA,GAAAA,SAAAA,EAAAA,WAAAA,EADoDM,WACpDN,GADkEE,QAClEF,CAD2EQ,WAC3ER,CAAAA,EAAAA,OAAAA,CAAAA,EADmGA,kBACnGA,EAAAA,aAAAA,CAAAA,EADuIC,iBACvID,EAAAA,kBAAAA,CAAAA,EAAAA,OAAAA;EAC+BQ,UAAAA,CAAAA,OAAAA,EAD/BR,kBAC+BQ,EAAAA,KAAAA,CAAAA,EAAAA,OAAAA,CAAAA,EAAAA,IAAAA;EAAfd,kBAAAA,CAAAA,eAAAA,EAAAA,cAAAA,CAAec,WAAfd,CAAAA,EAAAA,CAAAA,EAAAA,IAAAA;EAIJc,QAAAA,mBAAAA;EAAZJ,QAAAA,kBAAAA;EACIL,aAAAA,CAAAA,SAAAA,EA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CJ,CAmCmBc,WAnCnB,CAAA,EAAA,EAAA,kBAAA,CAAA,EAAA,OAAA,CAAA,EAAA,IAAA;;;;;;;KAoCEH,gBAAgBG"}
@@ -3,6 +3,7 @@ import { areObjectsEqual } from "../utils/areObjectsEqual.js";
3
3
  import { areOptionsEqual } from "../utils/areOptionsEqual.js";
4
4
  import { areFilesEqual } from "../utils/areFilesEqual.js";
5
5
  import { getVirtualFileHeaderRegion, getVirtualFilePaddingBottom } from "../utils/computeVirtualFileMetrics.js";
6
+ import { FILE_ANNOTATION_DOM_KEY, FILE_ANNOTATION_LINE_NUMBER, includesFileAnnotations, shouldRenderFileAnnotations } from "../utils/includesFileAnnotations.js";
6
7
  import { File } from "./File.js";
7
8
 
8
9
  //#region src/components/VirtualizedFile.ts
@@ -17,7 +18,8 @@ var VirtualizedFile = class extends File {
17
18
  height = 0;
18
19
  cache = {
19
20
  heights: /* @__PURE__ */ new Map(),
20
- checkpoints: []
21
+ checkpoints: [],
22
+ fileAnnotationHeight: 0
21
23
  };
22
24
  isVisible = false;
23
25
  isSetup = false;
@@ -34,6 +36,18 @@ var VirtualizedFile = class extends File {
34
36
  this.metrics = metrics;
35
37
  this.resetLayoutCache();
36
38
  }
39
+ setLineAnnotations(lineAnnotations) {
40
+ if (this.syncLineAnnotations(lineAnnotations)) this.resetLayoutCache();
41
+ }
42
+ syncLineAnnotations(lineAnnotations) {
43
+ if (lineAnnotations == null || lineAnnotations === this.lineAnnotations) return false;
44
+ if (lineAnnotations.length === 0 && this.lineAnnotations.length === 0) return false;
45
+ super.setLineAnnotations(lineAnnotations);
46
+ return true;
47
+ }
48
+ hasLineAnnotations() {
49
+ return this.lineAnnotations.some((annotation) => annotation.lineNumber > FILE_ANNOTATION_LINE_NUMBER);
50
+ }
37
51
  getLineHeight(lineIndex, hasMetadataLine = false) {
38
52
  const cached = this.cache.heights.get(lineIndex);
39
53
  if (cached != null) return cached;
@@ -57,6 +71,7 @@ var VirtualizedFile = class extends File {
57
71
  }
58
72
  resetLayoutCache(recompute = false) {
59
73
  this.layoutDirty = true;
74
+ this.cache.fileAnnotationHeight = 0;
60
75
  if (this.cache.heights.size > 0) this.cache.heights.clear();
61
76
  if (this.cache.checkpoints.length > 0) this.cache.checkpoints.length = 0;
62
77
  if (this.renderRange != null) this.renderRange = void 0;
@@ -75,6 +90,17 @@ var VirtualizedFile = class extends File {
75
90
  if (this.code == null) return hasHeightChange;
76
91
  const content = this.code.children[1];
77
92
  if (!(content instanceof HTMLElement)) return hasHeightChange;
93
+ const hasFileAnnotations = includesFileAnnotations(this.lineAnnotations);
94
+ if (this.renderRange != null && hasFileAnnotations && shouldRenderFileAnnotations(this.renderRange)) {
95
+ const nextFileAnnotationHeight = measureFileAnnotationHeight(content) ?? 0;
96
+ if (nextFileAnnotationHeight !== this.cache.fileAnnotationHeight) {
97
+ this.cache.fileAnnotationHeight = nextFileAnnotationHeight;
98
+ hasHeightChange = true;
99
+ }
100
+ } else if (!hasFileAnnotations && this.cache.fileAnnotationHeight !== 0) {
101
+ this.cache.fileAnnotationHeight = 0;
102
+ hasHeightChange = true;
103
+ }
78
104
  for (const line of content.children) {
79
105
  if (!(line instanceof HTMLElement)) continue;
80
106
  const lineIndexAttr = line.dataset.lineIndex;
@@ -100,8 +126,9 @@ var VirtualizedFile = class extends File {
100
126
  if (dirty) this.top = this.getVirtualizedTop();
101
127
  return this.render({ file: this.file });
102
128
  };
103
- prepareCodeViewItem(file, top, reset) {
104
- let shouldResetLayoutCache = reset?.resetFileLayoutCache === true;
129
+ prepareCodeViewItem(file, top, reset, lineAnnotations) {
130
+ const annotationsChanged = this.syncLineAnnotations(lineAnnotations);
131
+ let shouldResetLayoutCache = reset?.resetFileLayoutCache === true || annotationsChanged;
105
132
  if (reset?.metrics != null) {
106
133
  this.metrics = reset.metrics;
107
134
  shouldResetLayoutCache = true;
@@ -119,7 +146,7 @@ var VirtualizedFile = class extends File {
119
146
  return this.height;
120
147
  }
121
148
  getLinePosition(lineNumber) {
122
- if (this.file == null) return;
149
+ if (this.file == null || lineNumber < 1) return;
123
150
  const { disableFileHeader = false, collapsed = false } = this.options;
124
151
  const lastLineIndex = this.fileRenderer.getLineCount(this.file) - 1;
125
152
  let top = getVirtualFileHeaderRegion(this.metrics, disableFileHeader);
@@ -130,7 +157,8 @@ var VirtualizedFile = class extends File {
130
157
  const clampedLineIndex = Math.min(Math.max(lineNumber - 1, 0), lastLineIndex);
131
158
  const { overflow = "scroll" } = this.options;
132
159
  const { lineHeight } = this.metrics;
133
- if (overflow === "scroll" && this.lineAnnotations.length === 0) return {
160
+ top += this.cache.fileAnnotationHeight;
161
+ if (overflow === "scroll" && !this.hasLineAnnotations()) return {
134
162
  top: top + clampedLineIndex * lineHeight,
135
163
  height: lineHeight
136
164
  };
@@ -152,17 +180,18 @@ var VirtualizedFile = class extends File {
152
180
  const firstRenderedLineIndex = Math.min(this.renderRange.startingLine, lastLineIndex);
153
181
  const lastRenderedLineIndex = Math.min(firstRenderedLineIndex + this.renderRange.totalLines - 1, lastLineIndex);
154
182
  if (lastRenderedLineIndex < firstRenderedLineIndex) return;
155
- if (overflow === "scroll" && this.lineAnnotations.length === 0) {
183
+ const { fileAnnotationHeight } = this.cache;
184
+ if (overflow === "scroll" && !this.hasLineAnnotations()) {
156
185
  const { lineHeight } = this.metrics;
157
- const firstRenderedLineTop = headerRegion + this.renderRange.bufferBefore;
186
+ const firstRenderedLineTop = headerRegion + (firstRenderedLineIndex === 0 ? fileAnnotationHeight : this.renderRange.bufferBefore);
158
187
  const lineIndex = firstRenderedLineIndex + Math.max(Math.ceil((localViewportTop - firstRenderedLineTop) / lineHeight), 0);
159
188
  if (lineIndex > lastRenderedLineIndex) return;
160
189
  return {
161
190
  lineNumber: lineIndex + 1,
162
- top: headerRegion + lineIndex * lineHeight
191
+ top: headerRegion + fileAnnotationHeight + lineIndex * lineHeight
163
192
  };
164
193
  }
165
- let top = headerRegion + this.renderRange.bufferBefore;
194
+ let top = headerRegion + (firstRenderedLineIndex === 0 ? fileAnnotationHeight : this.renderRange.bufferBefore);
166
195
  for (let lineIndex = firstRenderedLineIndex; lineIndex <= lastRenderedLineIndex; lineIndex++) {
167
196
  if (top >= localViewportTop) return {
168
197
  lineNumber: lineIndex + 1,
@@ -195,7 +224,7 @@ var VirtualizedFile = class extends File {
195
224
  }
196
225
  cleanUp(recycle = false) {
197
226
  if (this.fileContainer != null && this.isSimpleMode()) this.getSimpleVirtualizer()?.disconnect(this.fileContainer);
198
- if (!recycle) this.layoutDirty = true;
227
+ if (!recycle) this.resetLayoutCache();
199
228
  this.isSetup = false;
200
229
  super.cleanUp(recycle);
201
230
  }
@@ -219,7 +248,8 @@ var VirtualizedFile = class extends File {
219
248
  this.layoutDirty = false;
220
249
  return;
221
250
  }
222
- if (overflow === "scroll" && this.lineAnnotations.length === 0) this.height += lineCount * lineHeight;
251
+ this.height += this.cache.fileAnnotationHeight;
252
+ if (overflow === "scroll" && !this.hasLineAnnotations()) this.height += lineCount * lineHeight;
223
253
  else for (let lineIndex = 0; lineIndex < lineCount; lineIndex++) {
224
254
  this.addLayoutCheckpoint(lineIndex, this.height);
225
255
  this.height += this.getLineHeight(lineIndex, false);
@@ -251,21 +281,27 @@ var VirtualizedFile = class extends File {
251
281
  this.forceRenderOverride = true;
252
282
  this.virtualizer.instanceChanged(this, false);
253
283
  }
254
- applyLayoutChange(textDocument, newLineAnnotations, shouldUpdateBuffer = false) {
284
+ applyDocumentChange(textDocument, newLineAnnotations, shouldUpdateBuffer = false) {
285
+ const { heights, checkpoints } = this.cache;
255
286
  const previousRenderRange = this.renderRange;
256
- super.applyLayoutChange(textDocument, newLineAnnotations);
287
+ super.applyDocumentChange(textDocument, newLineAnnotations);
257
288
  this.getSimpleVirtualizer()?.markDOMDirty();
258
- this.resetLayoutCache(true);
289
+ this.layoutDirty = true;
290
+ if (heights.size > 0) heights.clear();
291
+ if (checkpoints.length > 0) checkpoints.length = 0;
292
+ if (this.isSimpleMode()) this.computeApproximateSize();
259
293
  if (shouldUpdateBuffer && previousRenderRange !== void 0 && this.file !== void 0) {
260
294
  const windowSpecs = this.virtualizer.getWindowSpecs();
261
295
  const renderRange = this.computeRenderRangeFromWindow(this.file, this.top ?? 0, windowSpecs);
262
296
  if (renderRange.bufferAfter !== previousRenderRange.bufferAfter) this.updateBuffers(renderRange);
263
297
  }
264
298
  }
265
- render({ fileContainer, file, forceRender = false,...props }) {
299
+ render({ fileContainer, file, forceRender = false, lineAnnotations,...props }) {
266
300
  const didFileChange = this.file == null || !areFilesEqual(this.file, file);
267
301
  const { forceRenderOverride, isSetup } = this;
268
302
  this.forceRenderOverride = void 0;
303
+ const annotationsChanged = this.syncLineAnnotations(lineAnnotations);
304
+ if (annotationsChanged) this.resetLayoutCache();
269
305
  this.file = file;
270
306
  fileContainer = this.getOrCreateFileContainerNode(fileContainer);
271
307
  if (this.file == null) {
@@ -298,7 +334,8 @@ var VirtualizedFile = class extends File {
298
334
  file: this.file,
299
335
  fileContainer,
300
336
  renderRange,
301
- forceRender: forceRenderOverride ?? forceRender,
337
+ lineAnnotations,
338
+ forceRender: (forceRenderOverride ?? forceRender) || annotationsChanged,
302
339
  ...props
303
340
  });
304
341
  }
@@ -374,6 +411,12 @@ var VirtualizedFile = class extends File {
374
411
  const fileHeight = this.height;
375
412
  const headerRegion = getVirtualFileHeaderRegion(this.metrics, disableFileHeader);
376
413
  const paddingBottom = lineCount > 0 ? getVirtualFilePaddingBottom(this.metrics) : 0;
414
+ const { fileAnnotationHeight } = this.cache;
415
+ const codeRegionTop = headerRegion + fileAnnotationHeight;
416
+ const codeRowsHeight = Math.max(0, fileHeight - headerRegion - fileAnnotationHeight - paddingBottom);
417
+ const hasFileAnnotations = includesFileAnnotations(this.lineAnnotations);
418
+ const fileAnnotationTop = fileTop + headerRegion;
419
+ const measuredFileAnnotationVisible = fileAnnotationHeight > 0 && hasFileAnnotations && fileAnnotationTop < bottom && fileAnnotationTop + fileAnnotationHeight > top;
377
420
  if (fileTop < top - fileHeight || fileTop > bottom) return {
378
421
  startingLine: 0,
379
422
  totalLines: 0,
@@ -390,13 +433,21 @@ var VirtualizedFile = class extends File {
390
433
  const totalLines = Math.ceil(estimatedTargetLines / hunkLineCount) * hunkLineCount + hunkLineCount * 2;
391
434
  const totalHunks = totalLines / hunkLineCount;
392
435
  const viewportCenter = (top + bottom) / 2;
393
- if (overflow === "scroll" && this.lineAnnotations.length === 0) {
394
- const centerLine = Math.floor((viewportCenter - (fileTop + headerRegion)) / lineHeight);
436
+ if (overflow === "scroll" && !this.hasLineAnnotations()) {
437
+ const sourceRowsTop = fileTop + codeRegionTop;
438
+ const sourceRowsBottom = sourceRowsTop + codeRowsHeight;
439
+ if (!measuredFileAnnotationVisible && !(sourceRowsTop < bottom && sourceRowsBottom > top)) return {
440
+ startingLine: 0,
441
+ totalLines: 0,
442
+ bufferBefore: 0,
443
+ bufferAfter: fileHeight - headerRegion - paddingBottom
444
+ };
445
+ const centerLine = Math.floor(measuredFileAnnotationVisible && viewportCenter < fileTop + codeRegionTop ? 0 : (viewportCenter - (fileTop + codeRegionTop)) / lineHeight);
395
446
  const idealStartHunk$1 = Math.floor(centerLine / hunkLineCount) - Math.floor(totalHunks / 2);
396
447
  const totalHunksInFile = Math.ceil(lineCount / hunkLineCount);
397
448
  const startingLine$1 = Math.max(0, Math.min(idealStartHunk$1, totalHunksInFile)) * hunkLineCount;
398
449
  const clampedTotalLines$1 = idealStartHunk$1 < 0 ? totalLines + idealStartHunk$1 * hunkLineCount : totalLines;
399
- const bufferBefore$1 = startingLine$1 * lineHeight;
450
+ const bufferBefore$1 = startingLine$1 === 0 ? 0 : fileAnnotationHeight + startingLine$1 * lineHeight;
400
451
  const renderedLines = Math.min(clampedTotalLines$1, lineCount - startingLine$1);
401
452
  return {
402
453
  startingLine: startingLine$1,
@@ -408,7 +459,7 @@ var VirtualizedFile = class extends File {
408
459
  const overflowHunks = totalHunks;
409
460
  const hunkOffsets = [];
410
461
  const checkpoint = this.getLayoutCheckpointBeforeTop(Math.max(0, top - fileTop - totalLines * lineHeight * 2), hunkLineCount);
411
- let absoluteLineTop = fileTop + (checkpoint?.top ?? headerRegion);
462
+ let absoluteLineTop = fileTop + (checkpoint?.top ?? codeRegionTop);
412
463
  let currentLine = checkpoint?.lineIndex ?? 0;
413
464
  let firstVisibleHunk;
414
465
  let centerHunk;
@@ -418,7 +469,7 @@ var VirtualizedFile = class extends File {
418
469
  const isAtHunkBoundary = currentLine % hunkLineCount === 0;
419
470
  const currentHunk = Math.floor(currentLine / hunkLineCount);
420
471
  if (isAtHunkBoundary) {
421
- hunkOffsets[currentHunk] = absoluteLineTop - (fileTop + headerRegion);
472
+ hunkOffsets[currentHunk] = absoluteLineTop - (fileTop + codeRegionTop);
422
473
  if (overflowCounter != null) {
423
474
  if (overflowCounter <= 0) break;
424
475
  overflowCounter--;
@@ -431,7 +482,10 @@ var VirtualizedFile = class extends File {
431
482
  currentLine++;
432
483
  absoluteLineTop += lineHeight$1;
433
484
  }
434
- if (firstVisibleHunk == null) return {
485
+ if (firstVisibleHunk == null) if (measuredFileAnnotationVisible) {
486
+ firstVisibleHunk = 0;
487
+ centerHunk = 0;
488
+ } else return {
435
489
  startingLine: 0,
436
490
  totalLines: 0,
437
491
  bufferBefore: 0,
@@ -443,16 +497,27 @@ var VirtualizedFile = class extends File {
443
497
  const startHunk = Math.max(0, Math.min(idealStartHunk, maxStartHunk));
444
498
  const startingLine = startHunk * hunkLineCount;
445
499
  const clampedTotalLines = idealStartHunk < 0 ? totalLines + idealStartHunk * hunkLineCount : totalLines;
446
- const bufferBefore = hunkOffsets[startHunk] ?? 0;
500
+ const codeBufferBefore = hunkOffsets[startHunk] ?? 0;
501
+ const bufferBefore = startingLine === 0 ? 0 : fileAnnotationHeight + codeBufferBefore;
447
502
  const finalHunkIndex = startHunk + clampedTotalLines / hunkLineCount;
503
+ const bufferAfter = finalHunkIndex < hunkOffsets.length ? codeRowsHeight - hunkOffsets[finalHunkIndex] : codeRowsHeight - (absoluteLineTop - fileTop - codeRegionTop);
448
504
  return {
449
505
  startingLine,
450
506
  totalLines: clampedTotalLines,
451
507
  bufferBefore,
452
- bufferAfter: finalHunkIndex < hunkOffsets.length ? fileHeight - headerRegion - hunkOffsets[finalHunkIndex] - paddingBottom : fileHeight - (absoluteLineTop - fileTop) - paddingBottom
508
+ bufferAfter: Math.max(0, bufferAfter)
453
509
  };
454
510
  }
455
511
  };
512
+ function measureFileAnnotationHeight(content) {
513
+ let height;
514
+ for (const child of content.children) {
515
+ if (!(child instanceof HTMLElement)) continue;
516
+ if (child.dataset.lineAnnotation !== FILE_ANNOTATION_DOM_KEY) continue;
517
+ height = Math.max(height ?? 0, child.getBoundingClientRect().height);
518
+ }
519
+ return height;
520
+ }
456
521
 
457
522
  //#endregion
458
523
  export { VirtualizedFile };