@pierre/diffs 1.2.9 → 1.2.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -6
- package/dist/components/CodeView.js +6 -6
- package/dist/components/CodeView.js.map +1 -1
- package/dist/components/File.d.ts.map +1 -1
- package/dist/components/File.js +6 -1
- package/dist/components/File.js.map +1 -1
- package/dist/components/FileDiff.js +1 -1
- package/dist/components/FileDiff.js.map +1 -1
- package/dist/components/FileStream.js +4 -2
- package/dist/components/FileStream.js.map +1 -1
- package/dist/components/UnresolvedFile.d.ts.map +1 -1
- package/dist/components/VirtualizedFile.d.ts +6 -2
- package/dist/components/VirtualizedFile.d.ts.map +1 -1
- package/dist/components/VirtualizedFile.js +82 -21
- package/dist/components/VirtualizedFile.js.map +1 -1
- package/dist/components/VirtualizedFileDiff.d.ts +7 -2
- package/dist/components/VirtualizedFileDiff.d.ts.map +1 -1
- package/dist/components/VirtualizedFileDiff.js +77 -15
- package/dist/components/VirtualizedFileDiff.js.map +1 -1
- package/dist/components/VirtulizerDevelopment.d.ts.map +1 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/highlighter/themes/themeResolver.d.ts +4 -1
- package/dist/highlighter/themes/themeResolver.d.ts.map +1 -1
- package/dist/managers/InteractionManager.js +1 -1
- package/dist/managers/InteractionManager.js.map +1 -1
- package/dist/managers/ResizeManager.js +1 -1
- package/dist/managers/ResizeManager.js.map +1 -1
- package/dist/react/jsx.d.ts.map +1 -1
- package/dist/renderers/DiffHunksRenderer.d.ts +3 -2
- package/dist/renderers/DiffHunksRenderer.d.ts.map +1 -1
- package/dist/renderers/DiffHunksRenderer.js +49 -2
- package/dist/renderers/DiffHunksRenderer.js.map +1 -1
- package/dist/renderers/FileRenderer.js +12 -0
- package/dist/renderers/FileRenderer.js.map +1 -1
- package/dist/types.d.ts +8 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/includesFileAnnotations.d.ts +17 -0
- package/dist/utils/includesFileAnnotations.d.ts.map +1 -0
- package/dist/utils/includesFileAnnotations.js +19 -0
- package/dist/utils/includesFileAnnotations.js.map +1 -0
- package/dist/utils/parseMergeConflictDiffFromFile.js.map +1 -1
- package/dist/utils/renderDiffWithHighlighter.js +4 -2
- package/dist/utils/renderDiffWithHighlighter.js.map +1 -1
- package/dist/utils/renderFileWithHighlighter.js +4 -2
- package/dist/utils/renderFileWithHighlighter.js.map +1 -1
- package/dist/worker/{wasm-BaDzIkIn.js → wasm-qE0LgnY3.js} +2 -2
- package/dist/worker/{wasm-BaDzIkIn.js.map → wasm-qE0LgnY3.js.map} +1 -1
- package/dist/worker/worker-portable.js +991 -266
- package/dist/worker/worker-portable.js.map +1 -1
- package/dist/worker/worker.js +8 -4
- package/dist/worker/worker.js.map +1 -1
- package/package.json +4 -10
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileRenderer.js","names":["options: FileRendererOptions","onRenderUpdate?: () => unknown","workerManager?: WorkerPoolManager | undefined","options: RenderFileOptions","options","contentArray: ElementContent[]"],"sources":["../../src/renderers/FileRenderer.ts"],"sourcesContent":["import type { ElementContent, Element as HASTElement } from 'hast';\nimport { toHtml } from 'hast-util-to-html';\n\nimport {\n DEFAULT_RENDER_RANGE,\n DEFAULT_THEMES,\n DEFAULT_TOKENIZE_MAX_LENGTH,\n} from '../constants';\nimport { areLanguagesAttached } from '../highlighter/languages/areLanguagesAttached';\nimport {\n getHighlighterIfLoaded,\n getSharedHighlighter,\n} from '../highlighter/shared_highlighter';\nimport { areThemesAttached } from '../highlighter/themes/areThemesAttached';\nimport { hasResolvedThemes } from '../highlighter/themes/hasResolvedThemes';\nimport type {\n BaseCodeOptions,\n DiffsHighlighter,\n FileContents,\n FileHeaderRenderMode,\n LineAnnotation,\n RenderedFileASTCache,\n RenderFileOptions,\n RenderFileResult,\n RenderRange,\n SupportedLanguages,\n ThemedFileResult,\n} from '../types';\nimport { areFileRenderOptionsEqual } from '../utils/areFileRenderOptionsEqual';\nimport { areFilesEqual } from '../utils/areFilesEqual';\nimport { areRenderRangesEqual } from '../utils/areRenderRangesEqual';\nimport { createAnnotationElement } from '../utils/createAnnotationElement';\nimport { createContentColumn } from '../utils/createContentColumn';\nimport { createFileHeaderElement } from '../utils/createFileHeaderElement';\nimport { createPreElement } from '../utils/createPreElement';\nimport { getFiletypeFromFileName } from '../utils/getFiletypeFromFileName';\nimport { getHighlighterOptions } from '../utils/getHighlighterOptions';\nimport { getLineAnnotationName } from '../utils/getLineAnnotationName';\nimport { getThemes } from '../utils/getThemes';\nimport {\n createGutterGap,\n createGutterItem,\n createGutterWrapper,\n createHastElement,\n} from '../utils/hast_utils';\nimport { isFilePlainText } from '../utils/isFilePlainText';\nimport { iterateOverFile } from '../utils/iterateOverFile';\nimport { renderFileWithHighlighter } from '../utils/renderFileWithHighlighter';\nimport { shouldUseTokenTransformer } from '../utils/shouldUseTokenTransformer';\nimport { splitFileContents } from '../utils/splitFileContents';\nimport type { WorkerPoolManager } from '../worker';\n\ntype AnnotationLineMap<LAnnotation> = Record<\n number,\n LineAnnotation<LAnnotation>[] | undefined\n>;\n\ninterface GetRenderOptionsReturn {\n options: RenderFileOptions;\n forceHighlight: boolean;\n}\n\nexport interface FileRenderResult {\n gutterAST: ElementContent[];\n contentAST: ElementContent[];\n preAST: HASTElement;\n headerAST: HASTElement | undefined;\n css: string;\n totalLines: number;\n themeStyles: string;\n baseThemeType: 'light' | 'dark' | undefined;\n rowCount: number;\n bufferBefore: number;\n bufferAfter: number;\n}\n\ninterface LineCache {\n cacheKey: string | undefined;\n lines: string[];\n}\n\nexport interface FileRendererOptions extends BaseCodeOptions {\n headerRenderMode?: FileHeaderRenderMode;\n}\n\nlet instanceId = -1;\n\nexport class FileRenderer<LAnnotation = undefined> {\n readonly __id: string = `file-renderer:${++instanceId}`;\n\n private highlighter: DiffsHighlighter | undefined;\n private renderCache: RenderedFileASTCache | undefined;\n private computedLang: SupportedLanguages = 'text';\n private lineAnnotations: AnnotationLineMap<LAnnotation> = {};\n private lineCache: LineCache | undefined;\n\n constructor(\n public options: FileRendererOptions = { theme: DEFAULT_THEMES },\n private onRenderUpdate?: () => unknown,\n private workerManager?: WorkerPoolManager | undefined\n ) {\n if (workerManager?.isWorkingPool() !== true) {\n this.highlighter = areThemesAttached(options.theme ?? DEFAULT_THEMES)\n ? getHighlighterIfLoaded()\n : undefined;\n }\n }\n\n public setOptions(options: FileRendererOptions): void {\n this.options = options;\n }\n\n public mergeOptions(options: Partial<FileRendererOptions>): void {\n this.options = { ...this.options, ...options };\n }\n\n public setLineAnnotations(\n lineAnnotations: LineAnnotation<LAnnotation>[]\n ): void {\n this.lineAnnotations = {};\n for (const annotation of lineAnnotations) {\n const arr = this.lineAnnotations[annotation.lineNumber] ?? [];\n this.lineAnnotations[annotation.lineNumber] = arr;\n arr.push(annotation);\n }\n }\n\n public cleanUp(): void {\n this.recycle();\n this.workerManager = undefined;\n this.onRenderUpdate = undefined;\n }\n\n public recycle(): void {\n this.clearRenderCache();\n this.highlighter = undefined;\n this.workerManager?.cleanUpTasks(this);\n this.lineCache = undefined;\n }\n\n public clearRenderCache(): void {\n this.renderCache = undefined;\n }\n\n public hydrate(file: FileContents): void {\n const { options } = this.getRenderOptions(file);\n const lines = this.getOrCreateLineCache(file);\n const massiveFile = isFileMassive(\n lines.length,\n this.getTokenizeMaxLength()\n );\n let cache = this.workerManager?.getFileResultCache(file);\n if (cache != null && !areFileRenderOptionsEqual(options, cache.options)) {\n cache = undefined;\n }\n this.renderCache ??= {\n file,\n options,\n highlighted: !massiveFile && !isFilePlainText(file),\n result: massiveFile ? undefined : cache?.result,\n // FIXME(amadeus): Add support for renderRanges\n renderRange: undefined,\n };\n if (this.workerManager?.isWorkingPool() === true) {\n if (this.renderCache.result == null && !massiveFile) {\n // We should only kick off a preload of the AST if we have a WorkerPool\n this.workerManager.highlightFileAST(this, file);\n }\n }\n // Lets attempt to get the highlighter/languages ready immediately\n else if (this.highlighter == null) {\n this.computedLang = file.lang ?? getFiletypeFromFileName(file.name);\n void this.initializeHighlighter();\n }\n }\n\n private getRenderOptions(file: FileContents): GetRenderOptionsReturn {\n const options: RenderFileOptions = (() => {\n if (this.workerManager?.isWorkingPool() === true) {\n return this.workerManager.getFileRenderOptions();\n }\n const { theme = DEFAULT_THEMES, tokenizeMaxLineLength = 1000 } =\n this.options;\n return {\n theme,\n useTokenTransformer: shouldUseTokenTransformer(this.options),\n tokenizeMaxLineLength,\n };\n })();\n const { renderCache } = this;\n if (renderCache?.result == null) {\n return { options, forceHighlight: true };\n }\n if (\n !areFilesEqual(file, renderCache.file) ||\n !areFileRenderOptionsEqual(options, renderCache.options)\n ) {\n return { options, forceHighlight: true };\n }\n return { options, forceHighlight: false };\n }\n\n public getOrCreateLineCache(file: FileContents): string[] {\n // Uncached files will get split every time, not the greatest experience\n // tbh... but something people should try to optimize away\n if (file.cacheKey == null) {\n this.lineCache = undefined;\n return splitFileContents(file.contents);\n }\n\n let { lineCache } = this;\n if (lineCache == null || lineCache.cacheKey !== file.cacheKey) {\n lineCache = {\n cacheKey: file.cacheKey,\n lines: splitFileContents(file.contents),\n };\n }\n this.lineCache = lineCache;\n return lineCache.lines;\n }\n\n public renderFile(\n file: FileContents | undefined = this.renderCache?.file,\n renderRange: RenderRange = DEFAULT_RENDER_RANGE\n ): FileRenderResult | undefined {\n if (file == null) {\n return undefined;\n }\n let { options, forceHighlight } = this.getRenderOptions(file);\n const cache = this.getMatchingWorkerResultCache(file, options);\n if (cache != null && !this.hasHighlightedRenderCache(file, options)) {\n this.renderCache = {\n file,\n highlighted: true,\n renderRange: undefined,\n ...cache,\n };\n forceHighlight = false;\n }\n this.renderCache ??= {\n file,\n highlighted: false,\n options,\n result: undefined,\n renderRange: undefined,\n };\n const lines = this.getOrCreateLineCache(file);\n const hasContent = file.contents.length > 0;\n const forcePlainText =\n !hasContent ||\n isFilePlainText(file) ||\n isFileMassive(lines.length, this.getTokenizeMaxLength());\n const newContent = !areFilesEqual(file, this.renderCache.file);\n const newRenderRange = !areRenderRangesEqual(\n this.renderCache.renderRange,\n renderRange\n );\n if (this.workerManager?.isWorkingPool() === true) {\n // Cache invalidation based on renderRange comparison\n if (\n forcePlainText ||\n this.renderCache.result == null ||\n (!this.renderCache.highlighted && (newContent || newRenderRange))\n ) {\n this.renderCache.file = file;\n this.renderCache.options = options;\n this.renderCache.highlighted = false;\n if (\n this.renderCache.result == null ||\n newContent ||\n newRenderRange ||\n forceHighlight\n ) {\n this.renderCache.result = this.workerManager.getPlainFileAST(\n file,\n renderRange.startingLine,\n renderRange.totalLines,\n lines\n );\n }\n this.renderCache.renderRange = renderRange;\n }\n\n if (\n !forcePlainText &&\n hasContent &&\n (!this.renderCache.highlighted || forceHighlight)\n ) {\n this.workerManager.highlightFileAST(this, file);\n }\n } else {\n this.computedLang = file.lang ?? getFiletypeFromFileName(file.name);\n const hasThemes =\n this.highlighter != null && areThemesAttached(options.theme);\n const hasLangs =\n this.highlighter != null && areLanguagesAttached(this.computedLang);\n const canHighlight = !forcePlainText && hasLangs;\n\n // If we have any semblance of a highlighter with the correct theme(s)\n // attached, we can kick off some form of rendering. If we don't have\n // the correct language, then we can render plain text and after kick off\n // an async job to get the highlighted AST\n if (\n this.highlighter != null &&\n hasThemes &&\n (forceHighlight ||\n forcePlainText ||\n (!this.renderCache.highlighted && canHighlight) ||\n this.renderCache.result == null)\n ) {\n const { result, options } = this.renderFileWithHighlighter(\n file,\n this.highlighter,\n forcePlainText || !hasLangs\n );\n this.renderCache = {\n file,\n options,\n highlighted: canHighlight,\n result,\n renderRange: undefined,\n };\n }\n\n // If we get in here it means we'll have to kick off an async highlight\n // process which will involve initializing the highlighter with new themes\n // and languages\n if (!hasThemes || (!forcePlainText && !hasLangs)) {\n void this.asyncHighlight(file).then(({ result, options }) => {\n // In this case we need to force a re-render, so we can do that by\n // reaching into renderCache\n if (this.renderCache != null) {\n this.renderCache.highlighted = false;\n }\n this.onHighlightSuccess(file, result, options, !forcePlainText);\n });\n }\n }\n\n return this.renderCache.result != null\n ? this.processFileResult(\n this.renderCache.file,\n renderRange,\n this.renderCache.result\n )\n : undefined;\n }\n\n async asyncRender(\n file: FileContents,\n renderRange: RenderRange = DEFAULT_RENDER_RANGE\n ): Promise<FileRenderResult> {\n const { result } = await this.asyncHighlight(file);\n return this.processFileResult(file, renderRange, result);\n }\n\n private async asyncHighlight(file: FileContents): Promise<RenderFileResult> {\n const lines = this.getOrCreateLineCache(file);\n const forcePlainText = isFileMassive(\n lines.length,\n this.getTokenizeMaxLength()\n );\n this.computedLang = forcePlainText\n ? 'text'\n : (file.lang ?? getFiletypeFromFileName(file.name));\n const hasThemes =\n this.highlighter != null &&\n hasResolvedThemes(getThemes(this.options.theme));\n const hasLangs =\n forcePlainText ||\n (this.highlighter != null && areLanguagesAttached(this.computedLang));\n // If we don't have the required langs or themes, then we need to\n // initialize the highlighter to load the appropriate languages and themes\n if (this.highlighter == null || !hasThemes || !hasLangs) {\n this.highlighter = await this.initializeHighlighter();\n }\n return this.renderFileWithHighlighter(\n file,\n this.highlighter,\n forcePlainText\n );\n }\n\n private renderFileWithHighlighter(\n file: FileContents,\n highlighter: DiffsHighlighter,\n forcePlainText = false\n ): RenderFileResult {\n const { options } = this.getRenderOptions(file);\n const result = renderFileWithHighlighter(file, highlighter, options, {\n forcePlainText,\n });\n return { result, options };\n }\n\n private processFileResult(\n file: FileContents,\n renderRange: RenderRange,\n { code, themeStyles, baseThemeType }: ThemedFileResult\n ): FileRenderResult {\n const { disableFileHeader = false } = this.options;\n const contentArray: ElementContent[] = [];\n const gutter = createGutterWrapper();\n const lines = this.getOrCreateLineCache(file);\n let rowCount = 0;\n\n iterateOverFile({\n lines,\n startingLine: renderRange.startingLine,\n totalLines: renderRange.totalLines,\n callback: ({ lineIndex, lineNumber }) => {\n // Sparse array - directly indexed by lineIndex\n const line = code[lineIndex];\n if (line == null) {\n const message = 'FileRenderer.processFileResult: Line doesnt exist';\n console.error(message, {\n name: file.name,\n lineIndex,\n lineNumber,\n lines,\n });\n throw new Error(message);\n }\n\n if (line != null) {\n // Add gutter line number\n gutter.children.push(\n createGutterItem('context', lineNumber, `${lineIndex}`)\n );\n contentArray.push(line);\n rowCount++;\n\n // Check annotations using ACTUAL line number from file\n const annotations = this.lineAnnotations[lineNumber];\n if (annotations != null) {\n gutter.children.push(createGutterGap('context', 'annotation', 1));\n contentArray.push(\n createAnnotationElement({\n type: 'annotation',\n hunkIndex: 0,\n lineIndex: lineNumber,\n annotations: annotations.map((annotation) =>\n getLineAnnotationName(annotation)\n ),\n })\n );\n rowCount++;\n }\n }\n },\n });\n\n // Finalize: wrap gutter and content\n gutter.properties.style = `grid-row: span ${rowCount}`;\n return {\n gutterAST: gutter.children ?? [],\n contentAST: contentArray,\n preAST: this.createPreElement(lines.length),\n headerAST: !disableFileHeader ? this.renderHeader(file) : undefined,\n totalLines: lines.length,\n rowCount,\n themeStyles: themeStyles,\n baseThemeType,\n bufferBefore: renderRange.bufferBefore,\n bufferAfter: renderRange.bufferAfter,\n css: '',\n };\n }\n\n private renderHeader(file: FileContents) {\n const { headerRenderMode = 'default', stickyHeader = false } = this.options;\n return createFileHeaderElement({\n fileOrDiff: file,\n mode: headerRenderMode,\n stickyHeader,\n });\n }\n\n public renderFullHTML(result: FileRenderResult): string {\n return toHtml(this.renderFullAST(result));\n }\n\n public renderFullAST(\n result: FileRenderResult,\n children: ElementContent[] = []\n ): HASTElement {\n children.push(\n createHastElement({\n tagName: 'code',\n children: this.renderCodeAST(result),\n properties: { 'data-code': '' },\n })\n );\n return { ...result.preAST, children };\n }\n\n public renderCodeAST(result: FileRenderResult): ElementContent[] {\n const gutter = createGutterWrapper();\n gutter.children = result.gutterAST;\n gutter.properties.style = `grid-row: span ${result.rowCount}`;\n const contentColumn = createContentColumn(\n result.contentAST,\n result.rowCount\n );\n return [gutter, contentColumn];\n }\n\n public renderPartialHTML(\n children: ElementContent[],\n includeCodeNode: boolean = false\n ): string {\n if (!includeCodeNode) {\n return toHtml(children);\n }\n return toHtml(\n createHastElement({\n tagName: 'code',\n children,\n properties: { 'data-code': '' },\n })\n );\n }\n\n public async initializeHighlighter(): Promise<DiffsHighlighter> {\n this.highlighter = await getSharedHighlighter(\n getHighlighterOptions(this.computedLang, this.options)\n );\n return this.highlighter;\n }\n\n public onHighlightSuccess(\n file: FileContents,\n result: ThemedFileResult,\n options: RenderFileOptions,\n highlighted = true\n ): void {\n if (this.renderCache == null) {\n return;\n }\n const triggerRenderUpdate =\n !areFilesEqual(file, this.renderCache.file) ||\n !this.renderCache.highlighted ||\n !areFileRenderOptionsEqual(options, this.renderCache.options);\n\n this.renderCache = {\n file,\n options,\n highlighted,\n result,\n renderRange: undefined,\n };\n\n if (triggerRenderUpdate) {\n this.onRenderUpdate?.();\n }\n }\n\n private getMatchingWorkerResultCache(\n file: FileContents,\n options: RenderFileOptions\n ): RenderFileResult | undefined {\n const cache = this.workerManager?.getFileResultCache(file);\n if (cache == null || !areFileRenderOptionsEqual(options, cache.options)) {\n return undefined;\n }\n return cache;\n }\n\n private hasHighlightedRenderCache(\n file: FileContents,\n options: RenderFileOptions\n ): boolean {\n const { renderCache } = this;\n return (\n renderCache?.result != null &&\n renderCache.highlighted &&\n areFilesEqual(file, renderCache.file) &&\n areFileRenderOptionsEqual(options, renderCache.options)\n );\n }\n\n public onHighlightError(error: unknown): void {\n console.error(error);\n }\n\n private getTokenizeMaxLength(): number {\n return this.options.tokenizeMaxLength ?? DEFAULT_TOKENIZE_MAX_LENGTH;\n }\n\n private createPreElement(totalLines: number): HASTElement {\n const { disableLineNumbers = false, overflow = 'scroll' } = this.options;\n return createPreElement({\n type: 'file',\n diffIndicators: 'none',\n disableBackground: true,\n disableLineNumbers,\n overflow,\n split: false,\n totalLines,\n });\n }\n}\n\nfunction isFileMassive(lineCount: number, tokenizeMaxLength: number): boolean {\n return lineCount > tokenizeMaxLength;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAqFA,IAAI,aAAa;AAEjB,IAAa,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AAU,QACvB,YAAY,eACZ,cAAc,MAAM,YAAY,KAAK,IACrC,0BAA0B,SAAS,YAAY,QAAQ;;CAI3D,AAAO,iBAAiB,OAAsB;AAC5C,UAAQ,MAAM,MAAM;;CAGtB,AAAQ,uBAA+B;AACrC,SAAO,KAAK,QAAQ,qBAAqB;;CAG3C,AAAQ,iBAAiB,YAAiC;EACxD,MAAM,EAAE,qBAAqB,OAAO,WAAW,aAAa,KAAK;AACjE,SAAO,iBAAiB;GACtB,MAAM;GACN,gBAAgB;GAChB,mBAAmB;GACnB;GACA;GACA,OAAO;GACP;GACD,CAAC;;;AAIN,SAAS,cAAc,WAAmB,mBAAoC;AAC5E,QAAO,YAAY"}
|
|
1
|
+
{"version":3,"file":"FileRenderer.js","names":["options: FileRendererOptions","onRenderUpdate?: () => unknown","workerManager?: WorkerPoolManager | undefined","options: RenderFileOptions","options","contentArray: ElementContent[]"],"sources":["../../src/renderers/FileRenderer.ts"],"sourcesContent":["import type { ElementContent, Element as HASTElement } from 'hast';\nimport { toHtml } from 'hast-util-to-html';\n\nimport {\n DEFAULT_RENDER_RANGE,\n DEFAULT_THEMES,\n DEFAULT_TOKENIZE_MAX_LENGTH,\n} from '../constants';\nimport { areLanguagesAttached } from '../highlighter/languages/areLanguagesAttached';\nimport {\n getHighlighterIfLoaded,\n getSharedHighlighter,\n} from '../highlighter/shared_highlighter';\nimport { areThemesAttached } from '../highlighter/themes/areThemesAttached';\nimport { hasResolvedThemes } from '../highlighter/themes/hasResolvedThemes';\nimport type {\n BaseCodeOptions,\n DiffsHighlighter,\n FileContents,\n FileHeaderRenderMode,\n LineAnnotation,\n RenderedFileASTCache,\n RenderFileOptions,\n RenderFileResult,\n RenderRange,\n SupportedLanguages,\n ThemedFileResult,\n} from '../types';\nimport { areFileRenderOptionsEqual } from '../utils/areFileRenderOptionsEqual';\nimport { areFilesEqual } from '../utils/areFilesEqual';\nimport { areRenderRangesEqual } from '../utils/areRenderRangesEqual';\nimport { createAnnotationElement } from '../utils/createAnnotationElement';\nimport { createContentColumn } from '../utils/createContentColumn';\nimport { createFileHeaderElement } from '../utils/createFileHeaderElement';\nimport { createPreElement } from '../utils/createPreElement';\nimport { getFiletypeFromFileName } from '../utils/getFiletypeFromFileName';\nimport { getHighlighterOptions } from '../utils/getHighlighterOptions';\nimport { getLineAnnotationName } from '../utils/getLineAnnotationName';\nimport { getThemes } from '../utils/getThemes';\nimport {\n createGutterGap,\n createGutterItem,\n createGutterWrapper,\n createHastElement,\n} from '../utils/hast_utils';\nimport {\n FILE_ANNOTATION_HUNK_INDEX,\n FILE_ANNOTATION_LINE_INDEX,\n getFileAnnotations,\n shouldRenderFileAnnotations,\n} from '../utils/includesFileAnnotations';\nimport { isFilePlainText } from '../utils/isFilePlainText';\nimport { iterateOverFile } from '../utils/iterateOverFile';\nimport { renderFileWithHighlighter } from '../utils/renderFileWithHighlighter';\nimport { shouldUseTokenTransformer } from '../utils/shouldUseTokenTransformer';\nimport { splitFileContents } from '../utils/splitFileContents';\nimport type { WorkerPoolManager } from '../worker';\n\ntype AnnotationLineMap<LAnnotation> = Record<\n number,\n LineAnnotation<LAnnotation>[] | undefined\n>;\n\ninterface GetRenderOptionsReturn {\n options: RenderFileOptions;\n forceHighlight: boolean;\n}\n\nexport interface FileRenderResult {\n gutterAST: ElementContent[];\n contentAST: ElementContent[];\n preAST: HASTElement;\n headerAST: HASTElement | undefined;\n css: string;\n totalLines: number;\n themeStyles: string;\n baseThemeType: 'light' | 'dark' | undefined;\n rowCount: number;\n bufferBefore: number;\n bufferAfter: number;\n}\n\ninterface LineCache {\n cacheKey: string | undefined;\n lines: string[];\n}\n\nexport interface FileRendererOptions extends BaseCodeOptions {\n headerRenderMode?: FileHeaderRenderMode;\n}\n\nlet instanceId = -1;\n\nexport class FileRenderer<LAnnotation = undefined> {\n readonly __id: string = `file-renderer:${++instanceId}`;\n\n private highlighter: DiffsHighlighter | undefined;\n private renderCache: RenderedFileASTCache | undefined;\n private computedLang: SupportedLanguages = 'text';\n private lineAnnotations: AnnotationLineMap<LAnnotation> = {};\n private lineCache: LineCache | undefined;\n\n constructor(\n public options: FileRendererOptions = { theme: DEFAULT_THEMES },\n private onRenderUpdate?: () => unknown,\n private workerManager?: WorkerPoolManager | undefined\n ) {\n if (workerManager?.isWorkingPool() !== true) {\n this.highlighter = areThemesAttached(options.theme ?? DEFAULT_THEMES)\n ? getHighlighterIfLoaded()\n : undefined;\n }\n }\n\n public setOptions(options: FileRendererOptions): void {\n this.options = options;\n }\n\n public mergeOptions(options: Partial<FileRendererOptions>): void {\n this.options = { ...this.options, ...options };\n }\n\n public setLineAnnotations(\n lineAnnotations: LineAnnotation<LAnnotation>[]\n ): void {\n this.lineAnnotations = {};\n for (const annotation of lineAnnotations) {\n const arr = this.lineAnnotations[annotation.lineNumber] ?? [];\n this.lineAnnotations[annotation.lineNumber] = arr;\n arr.push(annotation);\n }\n }\n\n public cleanUp(): void {\n this.recycle();\n this.workerManager = undefined;\n this.onRenderUpdate = undefined;\n }\n\n public recycle(): void {\n this.clearRenderCache();\n this.highlighter = undefined;\n this.workerManager?.cleanUpTasks(this);\n this.lineCache = undefined;\n }\n\n public clearRenderCache(): void {\n this.renderCache = undefined;\n }\n\n public hydrate(file: FileContents): void {\n const { options } = this.getRenderOptions(file);\n const lines = this.getOrCreateLineCache(file);\n const massiveFile = isFileMassive(\n lines.length,\n this.getTokenizeMaxLength()\n );\n let cache = this.workerManager?.getFileResultCache(file);\n if (cache != null && !areFileRenderOptionsEqual(options, cache.options)) {\n cache = undefined;\n }\n this.renderCache ??= {\n file,\n options,\n highlighted: !massiveFile && !isFilePlainText(file),\n result: massiveFile ? undefined : cache?.result,\n // FIXME(amadeus): Add support for renderRanges\n renderRange: undefined,\n };\n if (this.workerManager?.isWorkingPool() === true) {\n if (this.renderCache.result == null && !massiveFile) {\n // We should only kick off a preload of the AST if we have a WorkerPool\n this.workerManager.highlightFileAST(this, file);\n }\n }\n // Lets attempt to get the highlighter/languages ready immediately\n else if (this.highlighter == null) {\n this.computedLang = file.lang ?? getFiletypeFromFileName(file.name);\n void this.initializeHighlighter();\n }\n }\n\n private getRenderOptions(file: FileContents): GetRenderOptionsReturn {\n const options: RenderFileOptions = (() => {\n if (this.workerManager?.isWorkingPool() === true) {\n return this.workerManager.getFileRenderOptions();\n }\n const { theme = DEFAULT_THEMES, tokenizeMaxLineLength = 1000 } =\n this.options;\n return {\n theme,\n useTokenTransformer: shouldUseTokenTransformer(this.options),\n tokenizeMaxLineLength,\n };\n })();\n const { renderCache } = this;\n if (renderCache?.result == null) {\n return { options, forceHighlight: true };\n }\n if (\n !areFilesEqual(file, renderCache.file) ||\n !areFileRenderOptionsEqual(options, renderCache.options)\n ) {\n return { options, forceHighlight: true };\n }\n return { options, forceHighlight: false };\n }\n\n public getOrCreateLineCache(file: FileContents): string[] {\n // Uncached files will get split every time, not the greatest experience\n // tbh... but something people should try to optimize away\n if (file.cacheKey == null) {\n this.lineCache = undefined;\n return splitFileContents(file.contents);\n }\n\n let { lineCache } = this;\n if (lineCache == null || lineCache.cacheKey !== file.cacheKey) {\n lineCache = {\n cacheKey: file.cacheKey,\n lines: splitFileContents(file.contents),\n };\n }\n this.lineCache = lineCache;\n return lineCache.lines;\n }\n\n public renderFile(\n file: FileContents | undefined = this.renderCache?.file,\n renderRange: RenderRange = DEFAULT_RENDER_RANGE\n ): FileRenderResult | undefined {\n if (file == null) {\n return undefined;\n }\n let { options, forceHighlight } = this.getRenderOptions(file);\n const cache = this.getMatchingWorkerResultCache(file, options);\n if (cache != null && !this.hasHighlightedRenderCache(file, options)) {\n this.renderCache = {\n file,\n highlighted: true,\n renderRange: undefined,\n ...cache,\n };\n forceHighlight = false;\n }\n this.renderCache ??= {\n file,\n highlighted: false,\n options,\n result: undefined,\n renderRange: undefined,\n };\n const lines = this.getOrCreateLineCache(file);\n const hasContent = file.contents.length > 0;\n const forcePlainText =\n !hasContent ||\n isFilePlainText(file) ||\n isFileMassive(lines.length, this.getTokenizeMaxLength());\n const newContent = !areFilesEqual(file, this.renderCache.file);\n const newRenderRange = !areRenderRangesEqual(\n this.renderCache.renderRange,\n renderRange\n );\n if (this.workerManager?.isWorkingPool() === true) {\n // Cache invalidation based on renderRange comparison\n if (\n forcePlainText ||\n this.renderCache.result == null ||\n (!this.renderCache.highlighted && (newContent || newRenderRange))\n ) {\n this.renderCache.file = file;\n this.renderCache.options = options;\n this.renderCache.highlighted = false;\n if (\n this.renderCache.result == null ||\n newContent ||\n newRenderRange ||\n forceHighlight\n ) {\n this.renderCache.result = this.workerManager.getPlainFileAST(\n file,\n renderRange.startingLine,\n renderRange.totalLines,\n lines\n );\n }\n this.renderCache.renderRange = renderRange;\n }\n\n if (\n !forcePlainText &&\n hasContent &&\n (!this.renderCache.highlighted || forceHighlight)\n ) {\n this.workerManager.highlightFileAST(this, file);\n }\n } else {\n this.computedLang = file.lang ?? getFiletypeFromFileName(file.name);\n const hasThemes =\n this.highlighter != null && areThemesAttached(options.theme);\n const hasLangs =\n this.highlighter != null && areLanguagesAttached(this.computedLang);\n const canHighlight = !forcePlainText && hasLangs;\n\n // If we have any semblance of a highlighter with the correct theme(s)\n // attached, we can kick off some form of rendering. If we don't have\n // the correct language, then we can render plain text and after kick off\n // an async job to get the highlighted AST\n if (\n this.highlighter != null &&\n hasThemes &&\n (forceHighlight ||\n forcePlainText ||\n (!this.renderCache.highlighted && canHighlight) ||\n this.renderCache.result == null)\n ) {\n const { result, options } = this.renderFileWithHighlighter(\n file,\n this.highlighter,\n forcePlainText || !hasLangs\n );\n this.renderCache = {\n file,\n options,\n highlighted: canHighlight,\n result,\n renderRange: undefined,\n };\n }\n\n // If we get in here it means we'll have to kick off an async highlight\n // process which will involve initializing the highlighter with new themes\n // and languages\n if (!hasThemes || (!forcePlainText && !hasLangs)) {\n void this.asyncHighlight(file).then(({ result, options }) => {\n // In this case we need to force a re-render, so we can do that by\n // reaching into renderCache\n if (this.renderCache != null) {\n this.renderCache.highlighted = false;\n }\n this.onHighlightSuccess(file, result, options, !forcePlainText);\n });\n }\n }\n\n return this.renderCache.result != null\n ? this.processFileResult(\n this.renderCache.file,\n renderRange,\n this.renderCache.result\n )\n : undefined;\n }\n\n async asyncRender(\n file: FileContents,\n renderRange: RenderRange = DEFAULT_RENDER_RANGE\n ): Promise<FileRenderResult> {\n const { result } = await this.asyncHighlight(file);\n return this.processFileResult(file, renderRange, result);\n }\n\n private async asyncHighlight(file: FileContents): Promise<RenderFileResult> {\n const lines = this.getOrCreateLineCache(file);\n const forcePlainText = isFileMassive(\n lines.length,\n this.getTokenizeMaxLength()\n );\n this.computedLang = forcePlainText\n ? 'text'\n : (file.lang ?? getFiletypeFromFileName(file.name));\n const hasThemes =\n this.highlighter != null &&\n hasResolvedThemes(getThemes(this.options.theme));\n const hasLangs =\n forcePlainText ||\n (this.highlighter != null && areLanguagesAttached(this.computedLang));\n // If we don't have the required langs or themes, then we need to\n // initialize the highlighter to load the appropriate languages and themes\n if (this.highlighter == null || !hasThemes || !hasLangs) {\n this.highlighter = await this.initializeHighlighter();\n }\n return this.renderFileWithHighlighter(\n file,\n this.highlighter,\n forcePlainText\n );\n }\n\n private renderFileWithHighlighter(\n file: FileContents,\n highlighter: DiffsHighlighter,\n forcePlainText = false\n ): RenderFileResult {\n const { options } = this.getRenderOptions(file);\n const result = renderFileWithHighlighter(file, highlighter, options, {\n forcePlainText,\n });\n return { result, options };\n }\n\n private processFileResult(\n file: FileContents,\n renderRange: RenderRange,\n { code, themeStyles, baseThemeType }: ThemedFileResult\n ): FileRenderResult {\n const { disableFileHeader = false } = this.options;\n const contentArray: ElementContent[] = [];\n const gutter = createGutterWrapper();\n const lines = this.getOrCreateLineCache(file);\n let rowCount = 0;\n\n const fileLevelAnnotations = shouldRenderFileAnnotations(renderRange)\n ? getFileAnnotations(this.lineAnnotations)\n : undefined;\n if (fileLevelAnnotations != null) {\n gutter.children.push(createGutterGap('context', 'annotation', 1));\n contentArray.push(\n createAnnotationElement({\n type: 'annotation',\n hunkIndex: FILE_ANNOTATION_HUNK_INDEX,\n lineIndex: FILE_ANNOTATION_LINE_INDEX,\n annotations: fileLevelAnnotations.map((annotation) =>\n getLineAnnotationName(annotation)\n ),\n })\n );\n rowCount++;\n }\n\n iterateOverFile({\n lines,\n startingLine: renderRange.startingLine,\n totalLines: renderRange.totalLines,\n callback: ({ lineIndex, lineNumber }) => {\n // Sparse array - directly indexed by lineIndex\n const line = code[lineIndex];\n if (line == null) {\n const message = 'FileRenderer.processFileResult: Line doesnt exist';\n console.error(message, {\n name: file.name,\n lineIndex,\n lineNumber,\n lines,\n });\n throw new Error(message);\n }\n\n if (line != null) {\n // Add gutter line number\n gutter.children.push(\n createGutterItem('context', lineNumber, `${lineIndex}`)\n );\n contentArray.push(line);\n rowCount++;\n\n // Check annotations using ACTUAL line number from file\n const annotations = this.lineAnnotations[lineNumber];\n if (annotations != null) {\n gutter.children.push(createGutterGap('context', 'annotation', 1));\n contentArray.push(\n createAnnotationElement({\n type: 'annotation',\n hunkIndex: 0,\n lineIndex: lineNumber,\n annotations: annotations.map((annotation) =>\n getLineAnnotationName(annotation)\n ),\n })\n );\n rowCount++;\n }\n }\n },\n });\n\n // Finalize: wrap gutter and content\n gutter.properties.style = `grid-row: span ${rowCount}`;\n return {\n gutterAST: gutter.children ?? [],\n contentAST: contentArray,\n preAST: this.createPreElement(lines.length),\n headerAST: !disableFileHeader ? this.renderHeader(file) : undefined,\n totalLines: lines.length,\n rowCount,\n themeStyles: themeStyles,\n baseThemeType,\n bufferBefore: renderRange.bufferBefore,\n bufferAfter: renderRange.bufferAfter,\n css: '',\n };\n }\n\n private renderHeader(file: FileContents) {\n const { headerRenderMode = 'default', stickyHeader = false } = this.options;\n return createFileHeaderElement({\n fileOrDiff: file,\n mode: headerRenderMode,\n stickyHeader,\n });\n }\n\n public renderFullHTML(result: FileRenderResult): string {\n return toHtml(this.renderFullAST(result));\n }\n\n public renderFullAST(\n result: FileRenderResult,\n children: ElementContent[] = []\n ): HASTElement {\n children.push(\n createHastElement({\n tagName: 'code',\n children: this.renderCodeAST(result),\n properties: { 'data-code': '' },\n })\n );\n return { ...result.preAST, children };\n }\n\n public renderCodeAST(result: FileRenderResult): ElementContent[] {\n const gutter = createGutterWrapper();\n gutter.children = result.gutterAST;\n gutter.properties.style = `grid-row: span ${result.rowCount}`;\n const contentColumn = createContentColumn(\n result.contentAST,\n result.rowCount\n );\n return [gutter, contentColumn];\n }\n\n public renderPartialHTML(\n children: ElementContent[],\n includeCodeNode: boolean = false\n ): string {\n if (!includeCodeNode) {\n return toHtml(children);\n }\n return toHtml(\n createHastElement({\n tagName: 'code',\n children,\n properties: { 'data-code': '' },\n })\n );\n }\n\n public async initializeHighlighter(): Promise<DiffsHighlighter> {\n this.highlighter = await getSharedHighlighter(\n getHighlighterOptions(this.computedLang, this.options)\n );\n return this.highlighter;\n }\n\n public onHighlightSuccess(\n file: FileContents,\n result: ThemedFileResult,\n options: RenderFileOptions,\n highlighted = true\n ): void {\n if (this.renderCache == null) {\n return;\n }\n const triggerRenderUpdate =\n !areFilesEqual(file, this.renderCache.file) ||\n !this.renderCache.highlighted ||\n !areFileRenderOptionsEqual(options, this.renderCache.options);\n\n this.renderCache = {\n file,\n options,\n highlighted,\n result,\n renderRange: undefined,\n };\n\n if (triggerRenderUpdate) {\n this.onRenderUpdate?.();\n }\n }\n\n private getMatchingWorkerResultCache(\n file: FileContents,\n options: RenderFileOptions\n ): RenderFileResult | undefined {\n const cache = this.workerManager?.getFileResultCache(file);\n if (cache == null || !areFileRenderOptionsEqual(options, cache.options)) {\n return undefined;\n }\n return cache;\n }\n\n private hasHighlightedRenderCache(\n file: FileContents,\n options: RenderFileOptions\n ): boolean {\n const { renderCache } = this;\n return (\n renderCache?.result != null &&\n renderCache.highlighted &&\n areFilesEqual(file, renderCache.file) &&\n areFileRenderOptionsEqual(options, renderCache.options)\n );\n }\n\n public onHighlightError(error: unknown): void {\n console.error(error);\n }\n\n private getTokenizeMaxLength(): number {\n return this.options.tokenizeMaxLength ?? DEFAULT_TOKENIZE_MAX_LENGTH;\n }\n\n private createPreElement(totalLines: number): HASTElement {\n const { disableLineNumbers = false, overflow = 'scroll' } = this.options;\n return createPreElement({\n type: 'file',\n diffIndicators: 'none',\n disableBackground: true,\n disableLineNumbers,\n overflow,\n split: false,\n totalLines,\n });\n }\n}\n\nfunction isFileMassive(lineCount: number, tokenizeMaxLength: number): boolean {\n return lineCount > tokenizeMaxLength;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA2FA,IAAI,aAAa;AAEjB,IAAa,eAAb,MAAmD;CACjD,AAAS,OAAe,iBAAiB,EAAE;CAE3C,AAAQ;CACR,AAAQ;CACR,AAAQ,eAAmC;CAC3C,AAAQ,kBAAkD,EAAE;CAC5D,AAAQ;CAER,YACE,AAAOA,UAA+B,EAAE,OAAO,gBAAgB,EAC/D,AAAQC,gBACR,AAAQC,eACR;EAHO;EACC;EACA;AAER,MAAI,eAAe,eAAe,KAAK,KACrC,MAAK,cAAc,kBAAkB,QAAQ,SAAS,eAAe,GACjE,wBAAwB,GACxB;;CAIR,AAAO,WAAW,SAAoC;AACpD,OAAK,UAAU;;CAGjB,AAAO,aAAa,SAA6C;AAC/D,OAAK,UAAU;GAAE,GAAG,KAAK;GAAS,GAAG;GAAS;;CAGhD,AAAO,mBACL,iBACM;AACN,OAAK,kBAAkB,EAAE;AACzB,OAAK,MAAM,cAAc,iBAAiB;GACxC,MAAM,MAAM,KAAK,gBAAgB,WAAW,eAAe,EAAE;AAC7D,QAAK,gBAAgB,WAAW,cAAc;AAC9C,OAAI,KAAK,WAAW;;;CAIxB,AAAO,UAAgB;AACrB,OAAK,SAAS;AACd,OAAK,gBAAgB;AACrB,OAAK,iBAAiB;;CAGxB,AAAO,UAAgB;AACrB,OAAK,kBAAkB;AACvB,OAAK,cAAc;AACnB,OAAK,eAAe,aAAa,KAAK;AACtC,OAAK,YAAY;;CAGnB,AAAO,mBAAyB;AAC9B,OAAK,cAAc;;CAGrB,AAAO,QAAQ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H,MAAa,wBAAmD;AAC9D,OAAK,cAAc,MAAM,qBACvB,sBAAsB,KAAK,cAAc,KAAK,QAAQ,CACvD;AACD,SAAO,KAAK;;CAGd,AAAO,mBACL,MACA,QACA,SACA,cAAc,MACR;AACN,MAAI,KAAK,eAAe,KACtB;EAEF,MAAM,sBACJ,CAAC,cAAc,MAAM,KAAK,YAAY,KAAK,IAC3C,CAAC,KAAK,YAAY,eAClB,CAAC,0BAA0B,SAAS,KAAK,YAAY,QAAQ;AAE/D,OAAK,cAAc;GACjB;GACA;GACA;GACA;GACA,aAAa;GACd;AAED,MAAI,oBACF,MAAK,kBAAkB;;CAI3B,AAAQ,6BACN,MACA,SAC8B;EAC9B,MAAM,QAAQ,KAAK,eAAe,mBAAmB,KAAK;AAC1D,MAAI,SAAS,QAAQ,CAAC,0BAA0B,SAAS,MAAM,QAAQ,CACrE;AAEF,SAAO;;CAGT,AAAQ,0BACN,MACA,SACS;EACT,MAAM,EAAE,gBAAgB;AACxB,SACE,aAAa,UAAU,QACvB,YAAY,eACZ,cAAc,MAAM,YAAY,KAAK,IACrC,0BAA0B,SAAS,YAAY,QAAQ;;CAI3D,AAAO,iBAAiB,OAAsB;AAC5C,UAAQ,MAAM,MAAM;;CAGtB,AAAQ,uBAA+B;AACrC,SAAO,KAAK,QAAQ,qBAAqB;;CAG3C,AAAQ,iBAAiB,YAAiC;EACxD,MAAM,EAAE,qBAAqB,OAAO,WAAW,aAAa,KAAK;AACjE,SAAO,iBAAiB;GACtB,MAAM;GACN,gBAAgB;GAChB,mBAAmB;GACnB;GACA;GACA,OAAO;GACP;GACD,CAAC;;;AAIN,SAAS,cAAc,WAAmB,mBAAoC;AAC5E,QAAO,YAAY"}
|
package/dist/types.d.ts
CHANGED
|
@@ -342,9 +342,17 @@ type OptionalMetadata<T> = T extends undefined ? {
|
|
|
342
342
|
} : {
|
|
343
343
|
metadata: T;
|
|
344
344
|
};
|
|
345
|
+
/**
|
|
346
|
+
* Annotation rendered for a file line. Use `lineNumber: 0` to render a
|
|
347
|
+
* file-level annotation above the first rendered file line.
|
|
348
|
+
*/
|
|
345
349
|
type LineAnnotation<T = undefined> = {
|
|
346
350
|
lineNumber: number;
|
|
347
351
|
} & OptionalMetadata<T>;
|
|
352
|
+
/**
|
|
353
|
+
* Annotation rendered for one side of a diff line. Use `lineNumber: 0` to
|
|
354
|
+
* render a side-specific file-level annotation above the first hunk/separator.
|
|
355
|
+
*/
|
|
348
356
|
type DiffLineAnnotation<T = undefined> = {
|
|
349
357
|
side: AnnotationSide;
|
|
350
358
|
lineNumber: number;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","names":["CreatePatchOptionsNonabortable","ElementContent","BundledLanguage","BundledTheme","CodeToHastOptions","DecorationItem","HighlighterGeneric","LanguageRegistration","ShikiTransformer","ThemedToken","ThemeRegistration","ThemeRegistrationResolved","CodeViewScrollBehavior","FileContents","SupportedLanguages","HighlighterTypes","DiffsThemeNames","ThemesType","Record","DiffsHighlighter","ChangeTypes","ParsedPatch","FileDiffMetadata","ContextContent","ChangeContent","Hunk","MergeConflictMarkerRowType","MergeConflictMarkerRow","HunkLineType","ThemeTypes","PostRenderPhase","HunkSeparators","LineDiffTypes","DiffIndicators","BaseCodeOptions","BaseDiffOptions","BaseDiffOptionsWithDefaults","Omit","Required","CustomPreProperties","PrePropertiesConfig","Pick","FileHeaderRenderMode","RenderHeaderMetadataCallback","Element","RenderHeaderPrefixCallback","RenderFileMetadata","ExtensionFormatMap","AnnotationSide","SelectionSide","SelectedLineRange","OptionalMetadata","T","LineAnnotation","DiffLineAnnotation","CodeViewFileItem","CodeViewDiffItem","CodeViewItem","CodeViewPositionScrollTarget","CodeViewLineScrollTarget","CodeViewRangeScrollTarget","NumericScrollLineAnchor","CodeViewItemScrollTarget","CodeViewScrollTarget","MergeConflictResolution","MergeConflictRegion","MergeConflictActionPayload","GapSpan","LineSpans","AnnotationSpan","LineTypes","LineInfo","SharedRenderState","LineEventBaseProps","HTMLElement","DiffLineEventBaseProps","TokenEventBase","DiffTokenEventBaseProps","ObservedAnnotationNodes","ObservedGridNodes","CodeColumnType","HunkData","AnnotationLineMap","LAnnotation","ExpansionDirections","ThemedFileResult","RenderDiffFilesResult","ThemedDiffResult","HunkExpansionRegion","ForceDiffPlainTextOptions","Map","ForceFilePlainTextOptions","RenderFileOptions","RenderDiffOptions","RenderFileResult","RenderDiffResult","RenderedFileASTCache","RenderRange","RenderedDiffASTCache","RenderWindow","VirtualWindowSpecs","VirtualFileMetrics","PendingCodeViewLayoutReset","CodeViewLayout","SmoothScrollSettings","SelectionPoint","DiffAcceptRejectHunkType","ConflictResolverTypes","DiffAcceptRejectHunkConfig","ProcessFileConflictData","AppliedThemeStyleCache","StickySpecs"],"sources":["../src/types.d.ts"],"sourcesContent":["import type { CreatePatchOptionsNonabortable } from 'diff';\nimport type { ElementContent } from 'hast';\nimport type { BundledLanguage, BundledTheme, CodeToHastOptions, DecorationItem, HighlighterGeneric, LanguageRegistration, ShikiTransformer, ThemedToken, ThemeRegistration, ThemeRegistrationResolved } from 'shiki';\nexport type { CreatePatchOptionsNonabortable };\nexport type CodeViewScrollBehavior = 'instant' | 'smooth' | 'smooth-auto';\n/**\n * Represents a file's contents for generating diffs via `parseDiffFromFile` or\n * for when rendering a file directly using the File components\n */\nexport interface FileContents {\n /** Filename used for display in headers and for inferring the language for\n * syntax highlighting. */\n name: string;\n /** The raw text contents of the file. */\n contents: string;\n /** Explicitly set the syntax highlighting language instead of inferring from\n * filename. Generally you should not be setting this. */\n lang?: SupportedLanguages;\n /** Optional header passed to the jsdiff library's `createTwoFilesPatch`. */\n header?: string;\n /** This unique key is only used for Worker Pools to avoid subsequent requests\n * if we've already highlighted the file. Please note that if you modify the\n * `contents` or `name`, you must update the `cacheKey`. */\n cacheKey?: string;\n}\nexport type HighlighterTypes = 'shiki-js' | 'shiki-wasm';\nexport type { BundledLanguage, CodeToHastOptions, DecorationItem, LanguageRegistration, ShikiTransformer, ThemeRegistrationResolved, ThemeRegistration, ThemedToken, };\nexport type DiffsThemeNames = BundledTheme | (string & {});\nexport type ThemesType = Record<'dark' | 'light', DiffsThemeNames>;\n/**\n * A Shiki highlighter instance configured with the library's supported\n * languages and themes. Used internally to generate syntax-highlighted AST\n * from file contents. By default diffs will ensure that only 1 highlighter is\n * instantiated per thread and shared for all syntax highlighting. This\n * applies to the main thread and worker threads.\n */\nexport type DiffsHighlighter = HighlighterGeneric<SupportedLanguages, DiffsThemeNames>;\n/**\n * Describes the type of change for a file in a diff.\n * - `change`: File content was modified, name unchanged.\n * - `rename-pure`: File was renamed/moved without content changes (100% similarity).\n * - `rename-changed`: File was renamed/moved and content was also modified.\n * - `new`: A new file was added.\n * - `deleted`: An existing file was removed.\n */\nexport type ChangeTypes = 'change' | 'rename-pure' | 'rename-changed' | 'new' | 'deleted';\n/**\n * Represents a parsed patch file, typically corresponding to a single commit.\n * Returned by `parsePatchFiles` when parsing raw patch/diff strings.\n */\nexport interface ParsedPatch {\n /** Optional raw introductory text before the file diffs that may have been\n * included in the patch (e.g., commit message, author, date). */\n patchMetadata?: string;\n /** Array of file changes contained in the patch. */\n files: FileDiffMetadata[];\n}\n/**\n * Represents a block of unchanged context lines within a hunk. Basically a\n * batch of lines in a hunk that are prefixed with a space ` `. Consecutive\n * lines prefixed with a ` ` are grouped together into a single ContextContent.\n */\nexport interface ContextContent {\n type: 'context';\n /** Number of unchanged lines in this context block. */\n lines: number;\n /**\n * Zero-based index into `FileDiffMetadata.additionLines` where this context\n * block starts.\n */\n additionLineIndex: number;\n /**\n * Zero-based index into `FileDiffMetadata.deletionLines` where this context\n * block starts.\n */\n deletionLineIndex: number;\n}\n/**\n * Represents a block of changes (additions and/or deletions) within a hunk.\n * Consecutive `+` and `-` lines are grouped together into a single\n * ChangeContent.\n */\nexport interface ChangeContent {\n type: 'change';\n /** Number of lines prefixed with `-` in this change block. */\n deletions: number;\n /**\n * Zero-based index into `FileDiffMetadata.deletionLines` where the deleted\n * lines start.\n */\n deletionLineIndex: number;\n /** Number of lines prefixed with `+` in this change block. */\n additions: number;\n /**\n * Zero-based index into `FileDiffMetadata.additionLines` where the added\n * lines start.\n */\n additionLineIndex: number;\n}\n/**\n * Represents a single hunk from a diff, corresponding to\n * one `@@ ... @@` block.\n */\nexport interface Hunk {\n /**\n * Number of unchanged lines between the previous hunk (or file start) and\n * this hunk.\n */\n collapsedBefore: number;\n /**\n * Starting line number in the new file version, parsed from the `+X`\n * in the hunk header.\n */\n additionStart: number;\n /**\n * Total line count in the new file version for this hunk, parsed from\n * `+X,count` in the hunk header. If this hunk was viewed in `diffStyle:\n * split` this would correspond to the number of lines in the right\n * `additions` column. It includes both `context` lines and lines\n * prefixed with `+`.\n */\n additionCount: number;\n /** This corresponds to the number of lines prefixed with `+` in this hunk. */\n additionLines: number;\n /**\n * Zero-based index into `FileDiffMetadata.additionLines` where this hunk's\n * content starts.\n */\n additionLineIndex: number;\n /**\n * Starting line number in the old file version, parsed from the `-X`\n * in the hunk header.\n */\n deletionStart: number;\n /**\n * Total line count in the old file version for this hunk, parsed from\n * `-X,count` in the hunk header. If this hunk was viewed in `diffStyle:\n * split` this would correspond to the number of lines in the left\n * `deletions` column. It includes both `context` lines and lines\n * prefixed with `-`.\n */\n deletionCount: number;\n /** This corresponds to the number of lines prefixed with `-` in this hunk. */\n deletionLines: number;\n /**\n * Zero-based index into `FileDiffMetadata.deletionLines` where this hunk's\n * content starts.\n */\n deletionLineIndex: number;\n /**\n * Array of content segments within this hunk, each representing either\n * a context line group or a change group.\n */\n hunkContent: (ContextContent | ChangeContent)[];\n /**\n * Function/method name that appears after the `@@` markers if it existed in\n * the diff.\n */\n hunkContext?: string;\n /** Raw hunk header string (e.g., `@@ -1,5 +1,7 @@`). */\n hunkSpecs?: string;\n /**\n * Starting line index for this hunk when rendered in split (side-by-side)\n * view.\n */\n splitLineStart: number;\n /** Total rendered line count for this hunk in split view. */\n splitLineCount: number;\n /** Starting line index for this hunk when rendered in unified view. */\n unifiedLineStart: number;\n /** Total rendered line count for this hunk in unified view. */\n unifiedLineCount: number;\n /**\n * True if the old file version has no trailing newline at end of file. This\n * is parsed from the patch file directly at the end of the hunk. If the\n * final hunkContent is a `context` group, then both values will be true or\n * false together. If it's from a `change` content group, then it may differ\n * depending on the patch.\n */\n noEOFCRDeletions: boolean;\n /**\n * True if the new file version has no trailing newline at end of file. This\n * is parsed from the patch file directly at the end of the hunk. If the\n * final hunkContent is a `context` group, then both values will be true or\n * false together. If it's from a `change` content group, then it may differ\n * depending on the patch.\n */\n noEOFCRAdditions: boolean;\n}\n/**\n * Metadata and content for a single file's diff. Think of this as a JSON\n * compatible representation of a diff for a single file.\n */\nexport interface FileDiffMetadata {\n /** The file's name and path. */\n name: string;\n /** Previous file path, present only if file was renamed or moved. */\n prevName?: string;\n /**\n * Explicitly override the syntax highlighting language instead of inferring\n * from filename. This will never be set by default, since all internal diff\n * APIs will attempt to detect the language automatically. If you'd like to\n * specify a language override, you can do so via the method `setLanguageOverride`\n */\n lang?: SupportedLanguages;\n /**\n * Object ID for the new file content parsed from the `index` line in a\n * patch file.\n */\n newObjectId?: string;\n /**\n * Object ID for the previous file content parsed from the `index` line in a\n * patch file.\n */\n prevObjectId?: string;\n /**\n * Git file mode parsed from the diff (e.g., `100644` for regular files) when\n * present in the patch metadata.\n */\n mode?: string;\n /** Previous git file mode, present if the mode changed. */\n prevMode?: string;\n /** The type of change for this file. */\n type: ChangeTypes;\n /** Array of diff hunks containing line-level change information. Each hunk\n * corresponds to a `@@ -X,X +X,X @@` group in a diff. */\n hunks: Hunk[];\n /** Pre-computed line size for this diff if rendered in `split` diffStyle. */\n splitLineCount: number;\n /** Pre-computed line size for this diff if rendered in `unified` diffStyle. */\n unifiedLineCount: number;\n /**\n * Whether the diff was parsed from a patch file (true) or generated from\n * full file contents (false).\n *\n * When true, `deletionLines`/`additionLines` contain only the lines present\n * in the patch and hunk expansion is unavailable.\n *\n * When false, they contain the complete file contents.\n */\n isPartial: boolean;\n /**\n * Array of lines from previous version of the file. If `isPartial` is false,\n * it means that `deletionLines` can be considered the entire contents of the\n * old version of the file. Otherwise `deletionLines` will just be an array\n * of all the content processed from the `context` and `deletion` lines of\n * the patch.\n */\n deletionLines: string[];\n /**\n * Array of lines from new version of the file. If `isPartial` is false, it\n * means that `additionLines` can be considered the entire contents of the\n * new version of the file. Otherwise `additionLines` will just be an array\n * of all the content processed from the `context` and `addition` lines of\n * the patch.\n */\n additionLines: string[];\n /**\n * This unique key is only used for Worker Pools to avoid subsequent requests\n * to highlight if we've already highlighted the diff. Please note that if\n * you modify the contents of the diff in any way, you will need to update\n * the `cacheKey`.\n */\n cacheKey?: string;\n}\nexport type MergeConflictMarkerRowType = 'marker-start' | 'marker-base' | 'marker-separator' | 'marker-end';\nexport interface MergeConflictMarkerRow {\n type: MergeConflictMarkerRowType;\n hunkIndex: number;\n /** Index into `hunk.hunkContent` for the structural block this row belongs to. */\n contentIndex: number;\n conflictIndex: number;\n lineText: string;\n /** Unified rendered-row index where this virtual row should be injected. */\n lineIndex: number;\n}\nexport type SupportedLanguages = BundledLanguage | 'text' | 'ansi' | (string & {});\nexport type HunkLineType = 'context' | 'expanded' | 'addition' | 'deletion' | 'metadata';\nexport type ThemeTypes = 'system' | 'light' | 'dark';\nexport type PostRenderPhase = 'mount' | 'update' | 'unmount';\n/**\n * The `'custom'` variant is deprecated and will be removed in a future version.\n */\nexport type HunkSeparators = 'simple' | 'metadata' | 'line-info' | 'line-info-basic' | 'custom';\nexport type LineDiffTypes = 'word-alt' | 'word' | 'char' | 'none';\nexport type DiffIndicators = 'classic' | 'bars' | 'none';\nexport interface BaseCodeOptions {\n theme?: DiffsThemeNames | ThemesType;\n disableLineNumbers?: boolean;\n overflow?: 'scroll' | 'wrap';\n themeType?: ThemeTypes;\n collapsed?: boolean;\n disableFileHeader?: boolean;\n disableVirtualizationBuffers?: boolean;\n stickyHeader?: boolean;\n preferredHighlighter?: HighlighterTypes;\n useCSSClasses?: boolean;\n useTokenTransformer?: boolean;\n tokenizeMaxLineLength?: number;\n tokenizeMaxLength?: number;\n unsafeCSS?: string;\n}\nexport interface BaseDiffOptions extends BaseCodeOptions {\n diffStyle?: 'unified' | 'split';\n diffIndicators?: DiffIndicators;\n disableBackground?: boolean;\n hunkSeparators?: HunkSeparators;\n expandUnchanged?: boolean;\n collapsedContextThreshold?: number;\n lineDiffType?: LineDiffTypes;\n maxLineDiffLength?: number;\n expansionLineCount?: number;\n /**\n * Options forwarded to the underlying diff algorithm when computing diffs\n * from file contents (oldFile/newFile). Has no effect on pre-parsed patches.\n */\n parseDiffOptions?: CreatePatchOptionsNonabortable;\n}\nexport type BaseDiffOptionsWithDefaults = Required<Omit<BaseDiffOptions, 'unsafeCSS' | 'preferredHighlighter' | 'parseDiffOptions'>>;\nexport type CustomPreProperties = Record<string, string | number | undefined>;\nexport interface PrePropertiesConfig extends Required<Pick<BaseDiffOptions, 'diffIndicators' | 'disableBackground' | 'disableLineNumbers' | 'overflow'>> {\n type: 'diff' | 'file';\n split: boolean;\n totalLines: number;\n customProperties?: CustomPreProperties;\n}\nexport type FileHeaderRenderMode = 'default' | 'custom';\nexport type RenderHeaderMetadataCallback = (fileDiff: FileDiffMetadata) => Element | string | number | null | undefined;\nexport type RenderHeaderPrefixCallback = (fileDiff: FileDiffMetadata) => Element | string | number | null | undefined;\nexport type RenderFileMetadata = (file: FileContents) => Element | string | number | null | undefined;\nexport type ExtensionFormatMap = Record<string, SupportedLanguages | undefined>;\nexport type AnnotationSide = 'deletions' | 'additions';\nexport type SelectionSide = 'deletions' | 'additions';\nexport interface SelectedLineRange {\n start: number;\n side?: SelectionSide;\n end: number;\n endSide?: SelectionSide;\n}\ntype OptionalMetadata<T> = T extends undefined ? {\n metadata?: undefined;\n} : {\n metadata: T;\n};\nexport type LineAnnotation<T = undefined> = {\n lineNumber: number;\n} & OptionalMetadata<T>;\nexport type DiffLineAnnotation<T = undefined> = {\n side: AnnotationSide;\n lineNumber: number;\n} & OptionalMetadata<T>;\nexport type CodeViewFileItem<T = undefined> = {\n id: string;\n type: 'file';\n file: FileContents;\n annotations?: LineAnnotation<T>[];\n version?: number;\n collapsed?: boolean;\n};\nexport type CodeViewDiffItem<T = undefined> = {\n id: string;\n type: 'diff';\n fileDiff: FileDiffMetadata;\n annotations?: DiffLineAnnotation<T>[];\n version?: number;\n collapsed?: boolean;\n};\nexport type CodeViewItem<T = undefined> = CodeViewFileItem<T> | CodeViewDiffItem<T>;\nexport interface CodeViewPositionScrollTarget {\n type: 'position';\n position: number;\n behavior?: CodeViewScrollBehavior;\n}\nexport interface CodeViewLineScrollTarget {\n type: 'line';\n id: string;\n lineNumber: number;\n side?: SelectionSide;\n align?: 'start' | 'center' | 'end' | 'nearest';\n offset?: number;\n behavior?: CodeViewScrollBehavior;\n}\nexport interface CodeViewRangeScrollTarget {\n type: 'range';\n id: string;\n range: SelectedLineRange;\n align?: 'start' | 'center' | 'end' | 'nearest';\n offset?: number;\n behavior?: CodeViewScrollBehavior;\n}\nexport interface NumericScrollLineAnchor {\n lineNumber: number;\n top: number;\n side?: SelectionSide;\n}\nexport interface CodeViewItemScrollTarget {\n type: 'item';\n id: string;\n align?: 'start' | 'center' | 'end' | 'nearest';\n offset?: number;\n behavior?: CodeViewScrollBehavior;\n}\nexport type CodeViewScrollTarget = CodeViewPositionScrollTarget | CodeViewLineScrollTarget | CodeViewRangeScrollTarget | CodeViewItemScrollTarget;\nexport type MergeConflictResolution = 'current' | 'incoming' | 'both';\nexport interface MergeConflictRegion {\n conflictIndex: number;\n startLineIndex: number;\n startLineNumber: number;\n separatorLineIndex: number;\n separatorLineNumber: number;\n endLineIndex: number;\n endLineNumber: number;\n baseMarkerLineIndex?: number;\n baseMarkerLineNumber?: number;\n}\nexport interface MergeConflictActionPayload {\n resolution: MergeConflictResolution;\n conflict: MergeConflictRegion;\n}\nexport interface GapSpan {\n type: 'gap';\n rows: number;\n}\nexport type LineSpans = GapSpan | AnnotationSpan;\nexport type LineTypes = 'change-deletion' | 'change-addition' | 'context' | 'context-expanded';\nexport interface LineInfo {\n type: LineTypes;\n lineNumber: number;\n altLineNumber?: number;\n lineIndex: number | `${number},${number}`;\n}\nexport interface SharedRenderState {\n lineInfo: (LineInfo | undefined)[] | ((shikiLineNumber: number) => LineInfo);\n}\nexport interface AnnotationSpan {\n type: 'annotation';\n hunkIndex: number;\n lineIndex: number;\n annotations: string[];\n}\nexport interface LineEventBaseProps {\n type: 'line';\n lineNumber: number;\n lineElement: HTMLElement;\n numberElement: HTMLElement;\n numberColumn: boolean;\n}\nexport interface DiffLineEventBaseProps extends Omit<LineEventBaseProps, 'type'> {\n type: 'diff-line';\n annotationSide: AnnotationSide;\n lineType: LineTypes;\n}\nexport interface TokenEventBase {\n type: 'token';\n lineNumber: number;\n lineCharStart: number;\n lineCharEnd: number;\n tokenText: string;\n tokenElement: HTMLElement;\n}\nexport interface DiffTokenEventBaseProps extends TokenEventBase {\n side: AnnotationSide;\n}\nexport interface ObservedAnnotationNodes {\n type: 'annotations';\n column1: {\n container: HTMLElement;\n child: HTMLElement;\n childHeight: number;\n };\n column2: {\n container: HTMLElement;\n child: HTMLElement;\n childHeight: number;\n };\n currentHeight: number | 'auto';\n}\nexport interface ObservedGridNodes {\n type: 'code';\n codeElement: HTMLElement;\n numberElement: HTMLElement | null;\n codeWidth: number | 'auto';\n numberWidth: number;\n}\nexport type CodeColumnType = 'unified' | 'additions' | 'deletions';\nexport interface HunkData {\n slotName: string;\n hunkIndex: number;\n lines: number;\n type: CodeColumnType;\n expandable?: {\n chunked: boolean;\n up: boolean;\n down: boolean;\n };\n}\nexport type AnnotationLineMap<LAnnotation> = Record<number, DiffLineAnnotation<LAnnotation>[] | undefined>;\nexport type ExpansionDirections = 'up' | 'down' | 'both';\nexport interface ThemedFileResult {\n code: ElementContent[];\n themeStyles: string;\n baseThemeType: 'light' | 'dark' | undefined;\n}\nexport interface RenderDiffFilesResult {\n deletionLines: ElementContent[];\n additionLines: ElementContent[];\n}\nexport interface ThemedDiffResult {\n code: RenderDiffFilesResult;\n themeStyles: string;\n baseThemeType: 'light' | 'dark' | undefined;\n}\nexport interface HunkExpansionRegion {\n fromStart: number;\n fromEnd: number;\n}\nexport interface ForceDiffPlainTextOptions {\n forcePlainText: boolean;\n startingLine?: number;\n totalLines?: number;\n expandedHunks?: Map<number, HunkExpansionRegion> | true;\n collapsedContextThreshold?: number;\n}\nexport interface ForceFilePlainTextOptions {\n forcePlainText: boolean;\n startingLine?: number;\n totalLines?: number;\n lines?: string[];\n}\nexport interface RenderFileOptions {\n theme: DiffsThemeNames | Record<'dark' | 'light', DiffsThemeNames>;\n useTokenTransformer: boolean;\n tokenizeMaxLineLength: number;\n}\nexport interface RenderDiffOptions {\n theme: DiffsThemeNames | Record<'dark' | 'light', DiffsThemeNames>;\n useTokenTransformer: boolean;\n tokenizeMaxLineLength: number;\n lineDiffType: LineDiffTypes;\n maxLineDiffLength: number;\n}\nexport interface RenderFileResult {\n result: ThemedFileResult;\n options: RenderFileOptions;\n}\nexport interface RenderDiffResult {\n result: ThemedDiffResult;\n options: RenderDiffOptions;\n}\nexport interface RenderedFileASTCache {\n file: FileContents;\n highlighted: boolean;\n options: RenderFileOptions;\n result: ThemedFileResult | undefined;\n renderRange: RenderRange | undefined;\n}\nexport interface RenderedDiffASTCache {\n diff: FileDiffMetadata;\n highlighted: boolean;\n options: RenderDiffOptions;\n result: ThemedDiffResult | undefined;\n renderRange: RenderRange | undefined;\n}\nexport interface RenderRange {\n startingLine: number;\n totalLines: number;\n bufferBefore: number;\n bufferAfter: number;\n}\nexport interface RenderWindow {\n top: number;\n bottom: number;\n}\nexport interface VirtualWindowSpecs {\n /** Absolute top edge of the active virtual window in scroll-space pixels. */\n top: number;\n /** Absolute bottom edge of the active virtual window in scroll-space pixels. */\n bottom: number;\n}\nexport interface VirtualFileMetrics {\n /** Number of rendered lines per hunk chunk when virtualization batches line rendering. */\n hunkLineCount: number;\n /** Estimated single-line row height used before a line is measured. */\n lineHeight: number;\n /** Height reserved for the file or diff header region. */\n diffHeaderHeight: number;\n /** Height reserved for each collapsed-context separator row. Only set this\n * if you customized the size of hunk separators via unsafeCSS */\n hunkSeparatorHeight?: number;\n /** Vertical spacing used around hunks and file-level padding. You should not\n * change this from the default if you aren't applying custom CSS */\n spacing: number;\n /** Optional top padding applied after the file header, or before content\n * when the header is disabled. Defaults to 0 with a header, otherwise\n * defaults to spacing if header is disabled */\n paddingTop?: number;\n /** Optional bottom padding applied after file content, and only if there is\n * code for the diff. Defaults to spacing if none provided */\n paddingBottom?: number;\n}\nexport interface PendingCodeViewLayoutReset {\n metrics?: VirtualFileMetrics;\n resetFileLayoutCache: boolean;\n resetDiffLayoutCache: boolean;\n includeEstimatedDiffHeights: boolean;\n}\nexport interface CodeViewLayout {\n /** Top padding applied to the CodeView sticky container offset. */\n paddingTop: number;\n /** Bottom padding added after the final rendered item in CodeView. */\n paddingBottom: number;\n /** Vertical gap between virtualized CodeView items. */\n gap: number;\n}\nexport interface SmoothScrollSettings {\n /**\n * Natural frequency of the critically-damped spring, in rad/ms. 99% settle\n * takes roughly `6.6 / omega`; 0.015 gives ~440ms. Raise for a snappier\n * animation; lower for a longer glide.\n */\n omega: number;\n /**\n * Distance from destination (in CSS pixels) below which the spring is\n * considered settled. Must also clear `velocityEpsilon` before the\n * animation actually stops and snaps to destination.\n */\n positionEpsilon: number;\n /**\n * Velocity magnitude (in CSS pixels per millisecond) below which the\n * spring is considered effectively stationary. Pairs with\n * `positionEpsilon` to gate the settle transition.\n */\n velocityEpsilon: number;\n}\nexport interface SelectionPoint {\n lineNumber: number;\n side: SelectionSide | undefined;\n}\nexport type DiffAcceptRejectHunkType = 'accept' | 'reject' | 'both';\nexport type ConflictResolverTypes = 'current' | 'incoming' | 'both';\nexport interface DiffAcceptRejectHunkConfig {\n type: DiffAcceptRejectHunkType;\n changeIndex: number;\n}\n/**\n * Unresolved merge conflict indexes use three different coordinate spaces:\n * - source line indexes live on `conflict.*LineIndex`\n * - hunk-content indexes live on the fields below, with `startContentIndex`\n * serving as both the conflict-range start and the start-marker anchor\n * - rendered row indexes live on unresolved `markerRows`\n */\nexport interface ProcessFileConflictData {\n /** Index of the hunk that owns this unresolved conflict. */\n hunkIndex: number;\n /** First hunk-content entry that belongs to the conflict region. */\n startContentIndex: number;\n /** Last hunk-content entry that belongs to the conflict region. */\n endContentIndex: number;\n /** Hunk-content index for the current/ours change block. */\n currentContentIndex?: number;\n /** Hunk-content index for the optional base context block. */\n baseContentIndex?: number;\n /** Hunk-content index for the incoming/theirs change block. */\n incomingContentIndex?: number;\n /** Hunk-content index that anchors the end marker row. */\n endMarkerContentIndex: number;\n}\nexport interface AppliedThemeStyleCache {\n theme: DiffsThemeNames | ThemesType;\n themeStyles: string;\n themeType: ThemeTypes;\n baseThemeType: 'light' | 'dark' | undefined;\n scrollbarGutter: number | undefined;\n}\nexport interface StickySpecs {\n topOffset: number;\n height: number;\n}\n//# sourceMappingURL=types.d.ts.map"],"mappings":";;;;;KAIYY,sBAAAA;AAAZ;AAKA;AAgBA;AAEA;AACYK,UAnBKJ,YAAAA,CAmBiCG;EAQtCG;;EAA0DH,IAAAA,EAAAA,MAAAA;EAAvCV;EAAkB,QAAA,EAAA,MAAA;EASrCc;AAKZ;EAYiBG,IAAAA,CAAAA,EA7CNT,kBA6CoB;EAoBdU;EAqBAC,MAAAA,CAAI,EAAA,MAAA;EA0FJH;;;EAiCNG,QAAAA,CAAAA,EAAAA,MAAAA;;AAuCCC,KAhPAX,gBAAAA,GAgPAW,UAA0B,GAAA,YAAA;AAW1BZ,KAzPAE,eAAAA,GAAkBb,YAyPGD,GAAAA,CAAAA,MAAAA,GAAe,CAAA,CAAA,CAAA;AACpC0B,KAzPAX,UAAAA,GAAaC,MAyPD,CAAA,MAAA,GAAA,OAAA,EAzP0BF,eAyP1B,CAAA;AACxB;AACA;AAIA;AACA;AACA;AACA;;AAC8BC,KA3PlBE,gBAAAA,GAAmBb,kBA2PDW,CA3PoB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GD8D,gBAAAA;UACLT;WACCO;;UAEIG,gBAAAA;UACLR;WACCM;;UAEIG,oBAAAA;QACPnF;;WAEG+E;UACDP;eACKY;;UAEAC,oBAAAA;QACP5E;;WAEGuE;UACDN;eACKU;;UAEAA,WAAAA;;;;;;UAMAE,YAAAA;;;;UAIAC,kBAAAA;;;;;;UAMAC,kBAAAA;;;;;;;;;;;;;;;;;;;;;UAqBAC,0BAAAA;YACHD;;;;;UAKGE,cAAAA;;;;;;;;UAQAC,oBAAAA;;;;;;;;;;;;;;;;;;;;UAoBAC,cAAAA;;QAEPxD;;KAEEyD,wBAAAA;KACAC,qBAAAA;UACKC,0BAAAA;QACPF;;;;;;;;;;UAUOG,uBAAAA;;;;;;;;;;;;;;;;UAgBAC,sBAAAA;SACN9F,kBAAkBC;;aAEdY;;;;UAIEkF,WAAAA"}
|
|
1
|
+
{"version":3,"file":"types.d.ts","names":["CreatePatchOptionsNonabortable","ElementContent","BundledLanguage","BundledTheme","CodeToHastOptions","DecorationItem","HighlighterGeneric","LanguageRegistration","ShikiTransformer","ThemedToken","ThemeRegistration","ThemeRegistrationResolved","CodeViewScrollBehavior","FileContents","SupportedLanguages","HighlighterTypes","DiffsThemeNames","ThemesType","Record","DiffsHighlighter","ChangeTypes","ParsedPatch","FileDiffMetadata","ContextContent","ChangeContent","Hunk","MergeConflictMarkerRowType","MergeConflictMarkerRow","HunkLineType","ThemeTypes","PostRenderPhase","HunkSeparators","LineDiffTypes","DiffIndicators","BaseCodeOptions","BaseDiffOptions","BaseDiffOptionsWithDefaults","Omit","Required","CustomPreProperties","PrePropertiesConfig","Pick","FileHeaderRenderMode","RenderHeaderMetadataCallback","Element","RenderHeaderPrefixCallback","RenderFileMetadata","ExtensionFormatMap","AnnotationSide","SelectionSide","SelectedLineRange","OptionalMetadata","T","LineAnnotation","DiffLineAnnotation","CodeViewFileItem","CodeViewDiffItem","CodeViewItem","CodeViewPositionScrollTarget","CodeViewLineScrollTarget","CodeViewRangeScrollTarget","NumericScrollLineAnchor","CodeViewItemScrollTarget","CodeViewScrollTarget","MergeConflictResolution","MergeConflictRegion","MergeConflictActionPayload","GapSpan","LineSpans","AnnotationSpan","LineTypes","LineInfo","SharedRenderState","LineEventBaseProps","HTMLElement","DiffLineEventBaseProps","TokenEventBase","DiffTokenEventBaseProps","ObservedAnnotationNodes","ObservedGridNodes","CodeColumnType","HunkData","AnnotationLineMap","LAnnotation","ExpansionDirections","ThemedFileResult","RenderDiffFilesResult","ThemedDiffResult","HunkExpansionRegion","ForceDiffPlainTextOptions","Map","ForceFilePlainTextOptions","RenderFileOptions","RenderDiffOptions","RenderFileResult","RenderDiffResult","RenderedFileASTCache","RenderRange","RenderedDiffASTCache","RenderWindow","VirtualWindowSpecs","VirtualFileMetrics","PendingCodeViewLayoutReset","CodeViewLayout","SmoothScrollSettings","SelectionPoint","DiffAcceptRejectHunkType","ConflictResolverTypes","DiffAcceptRejectHunkConfig","ProcessFileConflictData","AppliedThemeStyleCache","StickySpecs"],"sources":["../src/types.d.ts"],"sourcesContent":["import type { CreatePatchOptionsNonabortable } from 'diff';\nimport type { ElementContent } from 'hast';\nimport type { BundledLanguage, BundledTheme, CodeToHastOptions, DecorationItem, HighlighterGeneric, LanguageRegistration, ShikiTransformer, ThemedToken, ThemeRegistration, ThemeRegistrationResolved } from 'shiki';\nexport type { CreatePatchOptionsNonabortable };\nexport type CodeViewScrollBehavior = 'instant' | 'smooth' | 'smooth-auto';\n/**\n * Represents a file's contents for generating diffs via `parseDiffFromFile` or\n * for when rendering a file directly using the File components\n */\nexport interface FileContents {\n /** Filename used for display in headers and for inferring the language for\n * syntax highlighting. */\n name: string;\n /** The raw text contents of the file. */\n contents: string;\n /** Explicitly set the syntax highlighting language instead of inferring from\n * filename. Generally you should not be setting this. */\n lang?: SupportedLanguages;\n /** Optional header passed to the jsdiff library's `createTwoFilesPatch`. */\n header?: string;\n /** This unique key is only used for Worker Pools to avoid subsequent requests\n * if we've already highlighted the file. Please note that if you modify the\n * `contents` or `name`, you must update the `cacheKey`. */\n cacheKey?: string;\n}\nexport type HighlighterTypes = 'shiki-js' | 'shiki-wasm';\nexport type { BundledLanguage, CodeToHastOptions, DecorationItem, LanguageRegistration, ShikiTransformer, ThemeRegistrationResolved, ThemeRegistration, ThemedToken, };\nexport type DiffsThemeNames = BundledTheme | (string & {});\nexport type ThemesType = Record<'dark' | 'light', DiffsThemeNames>;\n/**\n * A Shiki highlighter instance configured with the library's supported\n * languages and themes. Used internally to generate syntax-highlighted AST\n * from file contents. By default diffs will ensure that only 1 highlighter is\n * instantiated per thread and shared for all syntax highlighting. This\n * applies to the main thread and worker threads.\n */\nexport type DiffsHighlighter = HighlighterGeneric<SupportedLanguages, DiffsThemeNames>;\n/**\n * Describes the type of change for a file in a diff.\n * - `change`: File content was modified, name unchanged.\n * - `rename-pure`: File was renamed/moved without content changes (100% similarity).\n * - `rename-changed`: File was renamed/moved and content was also modified.\n * - `new`: A new file was added.\n * - `deleted`: An existing file was removed.\n */\nexport type ChangeTypes = 'change' | 'rename-pure' | 'rename-changed' | 'new' | 'deleted';\n/**\n * Represents a parsed patch file, typically corresponding to a single commit.\n * Returned by `parsePatchFiles` when parsing raw patch/diff strings.\n */\nexport interface ParsedPatch {\n /** Optional raw introductory text before the file diffs that may have been\n * included in the patch (e.g., commit message, author, date). */\n patchMetadata?: string;\n /** Array of file changes contained in the patch. */\n files: FileDiffMetadata[];\n}\n/**\n * Represents a block of unchanged context lines within a hunk. Basically a\n * batch of lines in a hunk that are prefixed with a space ` `. Consecutive\n * lines prefixed with a ` ` are grouped together into a single ContextContent.\n */\nexport interface ContextContent {\n type: 'context';\n /** Number of unchanged lines in this context block. */\n lines: number;\n /**\n * Zero-based index into `FileDiffMetadata.additionLines` where this context\n * block starts.\n */\n additionLineIndex: number;\n /**\n * Zero-based index into `FileDiffMetadata.deletionLines` where this context\n * block starts.\n */\n deletionLineIndex: number;\n}\n/**\n * Represents a block of changes (additions and/or deletions) within a hunk.\n * Consecutive `+` and `-` lines are grouped together into a single\n * ChangeContent.\n */\nexport interface ChangeContent {\n type: 'change';\n /** Number of lines prefixed with `-` in this change block. */\n deletions: number;\n /**\n * Zero-based index into `FileDiffMetadata.deletionLines` where the deleted\n * lines start.\n */\n deletionLineIndex: number;\n /** Number of lines prefixed with `+` in this change block. */\n additions: number;\n /**\n * Zero-based index into `FileDiffMetadata.additionLines` where the added\n * lines start.\n */\n additionLineIndex: number;\n}\n/**\n * Represents a single hunk from a diff, corresponding to\n * one `@@ ... @@` block.\n */\nexport interface Hunk {\n /**\n * Number of unchanged lines between the previous hunk (or file start) and\n * this hunk.\n */\n collapsedBefore: number;\n /**\n * Starting line number in the new file version, parsed from the `+X`\n * in the hunk header.\n */\n additionStart: number;\n /**\n * Total line count in the new file version for this hunk, parsed from\n * `+X,count` in the hunk header. If this hunk was viewed in `diffStyle:\n * split` this would correspond to the number of lines in the right\n * `additions` column. It includes both `context` lines and lines\n * prefixed with `+`.\n */\n additionCount: number;\n /** This corresponds to the number of lines prefixed with `+` in this hunk. */\n additionLines: number;\n /**\n * Zero-based index into `FileDiffMetadata.additionLines` where this hunk's\n * content starts.\n */\n additionLineIndex: number;\n /**\n * Starting line number in the old file version, parsed from the `-X`\n * in the hunk header.\n */\n deletionStart: number;\n /**\n * Total line count in the old file version for this hunk, parsed from\n * `-X,count` in the hunk header. If this hunk was viewed in `diffStyle:\n * split` this would correspond to the number of lines in the left\n * `deletions` column. It includes both `context` lines and lines\n * prefixed with `-`.\n */\n deletionCount: number;\n /** This corresponds to the number of lines prefixed with `-` in this hunk. */\n deletionLines: number;\n /**\n * Zero-based index into `FileDiffMetadata.deletionLines` where this hunk's\n * content starts.\n */\n deletionLineIndex: number;\n /**\n * Array of content segments within this hunk, each representing either\n * a context line group or a change group.\n */\n hunkContent: (ContextContent | ChangeContent)[];\n /**\n * Function/method name that appears after the `@@` markers if it existed in\n * the diff.\n */\n hunkContext?: string;\n /** Raw hunk header string (e.g., `@@ -1,5 +1,7 @@`). */\n hunkSpecs?: string;\n /**\n * Starting line index for this hunk when rendered in split (side-by-side)\n * view.\n */\n splitLineStart: number;\n /** Total rendered line count for this hunk in split view. */\n splitLineCount: number;\n /** Starting line index for this hunk when rendered in unified view. */\n unifiedLineStart: number;\n /** Total rendered line count for this hunk in unified view. */\n unifiedLineCount: number;\n /**\n * True if the old file version has no trailing newline at end of file. This\n * is parsed from the patch file directly at the end of the hunk. If the\n * final hunkContent is a `context` group, then both values will be true or\n * false together. If it's from a `change` content group, then it may differ\n * depending on the patch.\n */\n noEOFCRDeletions: boolean;\n /**\n * True if the new file version has no trailing newline at end of file. This\n * is parsed from the patch file directly at the end of the hunk. If the\n * final hunkContent is a `context` group, then both values will be true or\n * false together. If it's from a `change` content group, then it may differ\n * depending on the patch.\n */\n noEOFCRAdditions: boolean;\n}\n/**\n * Metadata and content for a single file's diff. Think of this as a JSON\n * compatible representation of a diff for a single file.\n */\nexport interface FileDiffMetadata {\n /** The file's name and path. */\n name: string;\n /** Previous file path, present only if file was renamed or moved. */\n prevName?: string;\n /**\n * Explicitly override the syntax highlighting language instead of inferring\n * from filename. This will never be set by default, since all internal diff\n * APIs will attempt to detect the language automatically. If you'd like to\n * specify a language override, you can do so via the method `setLanguageOverride`\n */\n lang?: SupportedLanguages;\n /**\n * Object ID for the new file content parsed from the `index` line in a\n * patch file.\n */\n newObjectId?: string;\n /**\n * Object ID for the previous file content parsed from the `index` line in a\n * patch file.\n */\n prevObjectId?: string;\n /**\n * Git file mode parsed from the diff (e.g., `100644` for regular files) when\n * present in the patch metadata.\n */\n mode?: string;\n /** Previous git file mode, present if the mode changed. */\n prevMode?: string;\n /** The type of change for this file. */\n type: ChangeTypes;\n /** Array of diff hunks containing line-level change information. Each hunk\n * corresponds to a `@@ -X,X +X,X @@` group in a diff. */\n hunks: Hunk[];\n /** Pre-computed line size for this diff if rendered in `split` diffStyle. */\n splitLineCount: number;\n /** Pre-computed line size for this diff if rendered in `unified` diffStyle. */\n unifiedLineCount: number;\n /**\n * Whether the diff was parsed from a patch file (true) or generated from\n * full file contents (false).\n *\n * When true, `deletionLines`/`additionLines` contain only the lines present\n * in the patch and hunk expansion is unavailable.\n *\n * When false, they contain the complete file contents.\n */\n isPartial: boolean;\n /**\n * Array of lines from previous version of the file. If `isPartial` is false,\n * it means that `deletionLines` can be considered the entire contents of the\n * old version of the file. Otherwise `deletionLines` will just be an array\n * of all the content processed from the `context` and `deletion` lines of\n * the patch.\n */\n deletionLines: string[];\n /**\n * Array of lines from new version of the file. If `isPartial` is false, it\n * means that `additionLines` can be considered the entire contents of the\n * new version of the file. Otherwise `additionLines` will just be an array\n * of all the content processed from the `context` and `addition` lines of\n * the patch.\n */\n additionLines: string[];\n /**\n * This unique key is only used for Worker Pools to avoid subsequent requests\n * to highlight if we've already highlighted the diff. Please note that if\n * you modify the contents of the diff in any way, you will need to update\n * the `cacheKey`.\n */\n cacheKey?: string;\n}\nexport type MergeConflictMarkerRowType = 'marker-start' | 'marker-base' | 'marker-separator' | 'marker-end';\nexport interface MergeConflictMarkerRow {\n type: MergeConflictMarkerRowType;\n hunkIndex: number;\n /** Index into `hunk.hunkContent` for the structural block this row belongs to. */\n contentIndex: number;\n conflictIndex: number;\n lineText: string;\n /** Unified rendered-row index where this virtual row should be injected. */\n lineIndex: number;\n}\nexport type SupportedLanguages = BundledLanguage | 'text' | 'ansi' | (string & {});\nexport type HunkLineType = 'context' | 'expanded' | 'addition' | 'deletion' | 'metadata';\nexport type ThemeTypes = 'system' | 'light' | 'dark';\nexport type PostRenderPhase = 'mount' | 'update' | 'unmount';\n/**\n * The `'custom'` variant is deprecated and will be removed in a future version.\n */\nexport type HunkSeparators = 'simple' | 'metadata' | 'line-info' | 'line-info-basic' | 'custom';\nexport type LineDiffTypes = 'word-alt' | 'word' | 'char' | 'none';\nexport type DiffIndicators = 'classic' | 'bars' | 'none';\nexport interface BaseCodeOptions {\n theme?: DiffsThemeNames | ThemesType;\n disableLineNumbers?: boolean;\n overflow?: 'scroll' | 'wrap';\n themeType?: ThemeTypes;\n collapsed?: boolean;\n disableFileHeader?: boolean;\n disableVirtualizationBuffers?: boolean;\n stickyHeader?: boolean;\n preferredHighlighter?: HighlighterTypes;\n useCSSClasses?: boolean;\n useTokenTransformer?: boolean;\n tokenizeMaxLineLength?: number;\n tokenizeMaxLength?: number;\n unsafeCSS?: string;\n}\nexport interface BaseDiffOptions extends BaseCodeOptions {\n diffStyle?: 'unified' | 'split';\n diffIndicators?: DiffIndicators;\n disableBackground?: boolean;\n hunkSeparators?: HunkSeparators;\n expandUnchanged?: boolean;\n collapsedContextThreshold?: number;\n lineDiffType?: LineDiffTypes;\n maxLineDiffLength?: number;\n expansionLineCount?: number;\n /**\n * Options forwarded to the underlying diff algorithm when computing diffs\n * from file contents (oldFile/newFile). Has no effect on pre-parsed patches.\n */\n parseDiffOptions?: CreatePatchOptionsNonabortable;\n}\nexport type BaseDiffOptionsWithDefaults = Required<Omit<BaseDiffOptions, 'unsafeCSS' | 'preferredHighlighter' | 'parseDiffOptions'>>;\nexport type CustomPreProperties = Record<string, string | number | undefined>;\nexport interface PrePropertiesConfig extends Required<Pick<BaseDiffOptions, 'diffIndicators' | 'disableBackground' | 'disableLineNumbers' | 'overflow'>> {\n type: 'diff' | 'file';\n split: boolean;\n totalLines: number;\n customProperties?: CustomPreProperties;\n}\nexport type FileHeaderRenderMode = 'default' | 'custom';\nexport type RenderHeaderMetadataCallback = (fileDiff: FileDiffMetadata) => Element | string | number | null | undefined;\nexport type RenderHeaderPrefixCallback = (fileDiff: FileDiffMetadata) => Element | string | number | null | undefined;\nexport type RenderFileMetadata = (file: FileContents) => Element | string | number | null | undefined;\nexport type ExtensionFormatMap = Record<string, SupportedLanguages | undefined>;\nexport type AnnotationSide = 'deletions' | 'additions';\nexport type SelectionSide = 'deletions' | 'additions';\nexport interface SelectedLineRange {\n start: number;\n side?: SelectionSide;\n end: number;\n endSide?: SelectionSide;\n}\ntype OptionalMetadata<T> = T extends undefined ? {\n metadata?: undefined;\n} : {\n metadata: T;\n};\n/**\n * Annotation rendered for a file line. Use `lineNumber: 0` to render a\n * file-level annotation above the first rendered file line.\n */\nexport type LineAnnotation<T = undefined> = {\n lineNumber: number;\n} & OptionalMetadata<T>;\n/**\n * Annotation rendered for one side of a diff line. Use `lineNumber: 0` to\n * render a side-specific file-level annotation above the first hunk/separator.\n */\nexport type DiffLineAnnotation<T = undefined> = {\n side: AnnotationSide;\n lineNumber: number;\n} & OptionalMetadata<T>;\nexport type CodeViewFileItem<T = undefined> = {\n id: string;\n type: 'file';\n file: FileContents;\n annotations?: LineAnnotation<T>[];\n version?: number;\n collapsed?: boolean;\n};\nexport type CodeViewDiffItem<T = undefined> = {\n id: string;\n type: 'diff';\n fileDiff: FileDiffMetadata;\n annotations?: DiffLineAnnotation<T>[];\n version?: number;\n collapsed?: boolean;\n};\nexport type CodeViewItem<T = undefined> = CodeViewFileItem<T> | CodeViewDiffItem<T>;\nexport interface CodeViewPositionScrollTarget {\n type: 'position';\n position: number;\n behavior?: CodeViewScrollBehavior;\n}\nexport interface CodeViewLineScrollTarget {\n type: 'line';\n id: string;\n lineNumber: number;\n side?: SelectionSide;\n align?: 'start' | 'center' | 'end' | 'nearest';\n offset?: number;\n behavior?: CodeViewScrollBehavior;\n}\nexport interface CodeViewRangeScrollTarget {\n type: 'range';\n id: string;\n range: SelectedLineRange;\n align?: 'start' | 'center' | 'end' | 'nearest';\n offset?: number;\n behavior?: CodeViewScrollBehavior;\n}\nexport interface NumericScrollLineAnchor {\n lineNumber: number;\n top: number;\n side?: SelectionSide;\n}\nexport interface CodeViewItemScrollTarget {\n type: 'item';\n id: string;\n align?: 'start' | 'center' | 'end' | 'nearest';\n offset?: number;\n behavior?: CodeViewScrollBehavior;\n}\nexport type CodeViewScrollTarget = CodeViewPositionScrollTarget | CodeViewLineScrollTarget | CodeViewRangeScrollTarget | CodeViewItemScrollTarget;\nexport type MergeConflictResolution = 'current' | 'incoming' | 'both';\nexport interface MergeConflictRegion {\n conflictIndex: number;\n startLineIndex: number;\n startLineNumber: number;\n separatorLineIndex: number;\n separatorLineNumber: number;\n endLineIndex: number;\n endLineNumber: number;\n baseMarkerLineIndex?: number;\n baseMarkerLineNumber?: number;\n}\nexport interface MergeConflictActionPayload {\n resolution: MergeConflictResolution;\n conflict: MergeConflictRegion;\n}\nexport interface GapSpan {\n type: 'gap';\n rows: number;\n}\nexport type LineSpans = GapSpan | AnnotationSpan;\nexport type LineTypes = 'change-deletion' | 'change-addition' | 'context' | 'context-expanded';\nexport interface LineInfo {\n type: LineTypes;\n lineNumber: number;\n altLineNumber?: number;\n lineIndex: number | `${number},${number}`;\n}\nexport interface SharedRenderState {\n lineInfo: (LineInfo | undefined)[] | ((shikiLineNumber: number) => LineInfo);\n}\nexport interface AnnotationSpan {\n type: 'annotation';\n hunkIndex: number;\n lineIndex: number;\n annotations: string[];\n}\nexport interface LineEventBaseProps {\n type: 'line';\n lineNumber: number;\n lineElement: HTMLElement;\n numberElement: HTMLElement;\n numberColumn: boolean;\n}\nexport interface DiffLineEventBaseProps extends Omit<LineEventBaseProps, 'type'> {\n type: 'diff-line';\n annotationSide: AnnotationSide;\n lineType: LineTypes;\n}\nexport interface TokenEventBase {\n type: 'token';\n lineNumber: number;\n lineCharStart: number;\n lineCharEnd: number;\n tokenText: string;\n tokenElement: HTMLElement;\n}\nexport interface DiffTokenEventBaseProps extends TokenEventBase {\n side: AnnotationSide;\n}\nexport interface ObservedAnnotationNodes {\n type: 'annotations';\n column1: {\n container: HTMLElement;\n child: HTMLElement;\n childHeight: number;\n };\n column2: {\n container: HTMLElement;\n child: HTMLElement;\n childHeight: number;\n };\n currentHeight: number | 'auto';\n}\nexport interface ObservedGridNodes {\n type: 'code';\n codeElement: HTMLElement;\n numberElement: HTMLElement | null;\n codeWidth: number | 'auto';\n numberWidth: number;\n}\nexport type CodeColumnType = 'unified' | 'additions' | 'deletions';\nexport interface HunkData {\n slotName: string;\n hunkIndex: number;\n lines: number;\n type: CodeColumnType;\n expandable?: {\n chunked: boolean;\n up: boolean;\n down: boolean;\n };\n}\nexport type AnnotationLineMap<LAnnotation> = Record<number, DiffLineAnnotation<LAnnotation>[] | undefined>;\nexport type ExpansionDirections = 'up' | 'down' | 'both';\nexport interface ThemedFileResult {\n code: ElementContent[];\n themeStyles: string;\n baseThemeType: 'light' | 'dark' | undefined;\n}\nexport interface RenderDiffFilesResult {\n deletionLines: ElementContent[];\n additionLines: ElementContent[];\n}\nexport interface ThemedDiffResult {\n code: RenderDiffFilesResult;\n themeStyles: string;\n baseThemeType: 'light' | 'dark' | undefined;\n}\nexport interface HunkExpansionRegion {\n fromStart: number;\n fromEnd: number;\n}\nexport interface ForceDiffPlainTextOptions {\n forcePlainText: boolean;\n startingLine?: number;\n totalLines?: number;\n expandedHunks?: Map<number, HunkExpansionRegion> | true;\n collapsedContextThreshold?: number;\n}\nexport interface ForceFilePlainTextOptions {\n forcePlainText: boolean;\n startingLine?: number;\n totalLines?: number;\n lines?: string[];\n}\nexport interface RenderFileOptions {\n theme: DiffsThemeNames | Record<'dark' | 'light', DiffsThemeNames>;\n useTokenTransformer: boolean;\n tokenizeMaxLineLength: number;\n}\nexport interface RenderDiffOptions {\n theme: DiffsThemeNames | Record<'dark' | 'light', DiffsThemeNames>;\n useTokenTransformer: boolean;\n tokenizeMaxLineLength: number;\n lineDiffType: LineDiffTypes;\n maxLineDiffLength: number;\n}\nexport interface RenderFileResult {\n result: ThemedFileResult;\n options: RenderFileOptions;\n}\nexport interface RenderDiffResult {\n result: ThemedDiffResult;\n options: RenderDiffOptions;\n}\nexport interface RenderedFileASTCache {\n file: FileContents;\n highlighted: boolean;\n options: RenderFileOptions;\n result: ThemedFileResult | undefined;\n renderRange: RenderRange | undefined;\n}\nexport interface RenderedDiffASTCache {\n diff: FileDiffMetadata;\n highlighted: boolean;\n options: RenderDiffOptions;\n result: ThemedDiffResult | undefined;\n renderRange: RenderRange | undefined;\n}\nexport interface RenderRange {\n startingLine: number;\n totalLines: number;\n bufferBefore: number;\n bufferAfter: number;\n}\nexport interface RenderWindow {\n top: number;\n bottom: number;\n}\nexport interface VirtualWindowSpecs {\n /** Absolute top edge of the active virtual window in scroll-space pixels. */\n top: number;\n /** Absolute bottom edge of the active virtual window in scroll-space pixels. */\n bottom: number;\n}\nexport interface VirtualFileMetrics {\n /** Number of rendered lines per hunk chunk when virtualization batches line rendering. */\n hunkLineCount: number;\n /** Estimated single-line row height used before a line is measured. */\n lineHeight: number;\n /** Height reserved for the file or diff header region. */\n diffHeaderHeight: number;\n /** Height reserved for each collapsed-context separator row. Only set this\n * if you customized the size of hunk separators via unsafeCSS */\n hunkSeparatorHeight?: number;\n /** Vertical spacing used around hunks and file-level padding. You should not\n * change this from the default if you aren't applying custom CSS */\n spacing: number;\n /** Optional top padding applied after the file header, or before content\n * when the header is disabled. Defaults to 0 with a header, otherwise\n * defaults to spacing if header is disabled */\n paddingTop?: number;\n /** Optional bottom padding applied after file content, and only if there is\n * code for the diff. Defaults to spacing if none provided */\n paddingBottom?: number;\n}\nexport interface PendingCodeViewLayoutReset {\n metrics?: VirtualFileMetrics;\n resetFileLayoutCache: boolean;\n resetDiffLayoutCache: boolean;\n includeEstimatedDiffHeights: boolean;\n}\nexport interface CodeViewLayout {\n /** Top padding applied to the CodeView sticky container offset. */\n paddingTop: number;\n /** Bottom padding added after the final rendered item in CodeView. */\n paddingBottom: number;\n /** Vertical gap between virtualized CodeView items. */\n gap: number;\n}\nexport interface SmoothScrollSettings {\n /**\n * Natural frequency of the critically-damped spring, in rad/ms. 99% settle\n * takes roughly `6.6 / omega`; 0.015 gives ~440ms. Raise for a snappier\n * animation; lower for a longer glide.\n */\n omega: number;\n /**\n * Distance from destination (in CSS pixels) below which the spring is\n * considered settled. Must also clear `velocityEpsilon` before the\n * animation actually stops and snaps to destination.\n */\n positionEpsilon: number;\n /**\n * Velocity magnitude (in CSS pixels per millisecond) below which the\n * spring is considered effectively stationary. Pairs with\n * `positionEpsilon` to gate the settle transition.\n */\n velocityEpsilon: number;\n}\nexport interface SelectionPoint {\n lineNumber: number;\n side: SelectionSide | undefined;\n}\nexport type DiffAcceptRejectHunkType = 'accept' | 'reject' | 'both';\nexport type ConflictResolverTypes = 'current' | 'incoming' | 'both';\nexport interface DiffAcceptRejectHunkConfig {\n type: DiffAcceptRejectHunkType;\n changeIndex: number;\n}\n/**\n * Unresolved merge conflict indexes use three different coordinate spaces:\n * - source line indexes live on `conflict.*LineIndex`\n * - hunk-content indexes live on the fields below, with `startContentIndex`\n * serving as both the conflict-range start and the start-marker anchor\n * - rendered row indexes live on unresolved `markerRows`\n */\nexport interface ProcessFileConflictData {\n /** Index of the hunk that owns this unresolved conflict. */\n hunkIndex: number;\n /** First hunk-content entry that belongs to the conflict region. */\n startContentIndex: number;\n /** Last hunk-content entry that belongs to the conflict region. */\n endContentIndex: number;\n /** Hunk-content index for the current/ours change block. */\n currentContentIndex?: number;\n /** Hunk-content index for the optional base context block. */\n baseContentIndex?: number;\n /** Hunk-content index for the incoming/theirs change block. */\n incomingContentIndex?: number;\n /** Hunk-content index that anchors the end marker row. */\n endMarkerContentIndex: number;\n}\nexport interface AppliedThemeStyleCache {\n theme: DiffsThemeNames | ThemesType;\n themeStyles: string;\n themeType: ThemeTypes;\n baseThemeType: 'light' | 'dark' | undefined;\n scrollbarGutter: number | undefined;\n}\nexport interface StickySpecs {\n topOffset: number;\n height: number;\n}\n//# sourceMappingURL=types.d.ts.map"],"mappings":";;;;;KAIYY,sBAAAA;AAAZ;AAKA;AAgBA;AAEA;AACYK,UAnBKJ,YAAAA,CAmBiCG;EAQtCG;;EAA0DH,IAAAA,EAAAA,MAAAA;EAAvCV;EAAkB,QAAA,EAAA,MAAA;EASrCc;AAKZ;EAYiBG,IAAAA,CAAAA,EA7CNT,kBA6CoB;EAoBdU;EAqBAC,MAAAA,CAAI,EAAA,MAAA;EA0FJH;;;EAiCNG,QAAAA,CAAAA,EAAAA,MAAAA;;AAuCCC,KAhPAX,gBAAAA,GAgPAW,UAA0B,GAAA,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A;UACKC,gBAAAA;QACPpF;;;;UAIOqF,qBAAAA;iBACErF;iBACAA;;UAEFsF,gBAAAA;QACPD;;;;UAIOE,mBAAAA;;;;UAIAC,yBAAAA;;;;kBAIGC,YAAYF;;;UAGfG,yBAAAA;;;;;;UAMAC,iBAAAA;SACN5E,kBAAkBE,yBAAyBF;;;;UAIrC6E,iBAAAA;SACN7E,kBAAkBE,yBAAyBF;;;gBAGpCgB;;;UAGD8D,gBAAAA;UACLT;WACCO;;UAEIG,gBAAAA;UACLR;WACCM;;UAEIG,oBAAAA;QACPnF;;WAEG+E;UACDP;eACKY;;UAEAC,oBAAAA;QACP5E;;WAEGuE;UACDN;eACKU;;UAEAA,WAAAA;;;;;;UAMAE,YAAAA;;;;UAIAC,kBAAAA;;;;;;UAMAC,kBAAAA;;;;;;;;;;;;;;;;;;;;;UAqBAC,0BAAAA;YACHD;;;;;UAKGE,cAAAA;;;;;;;;UAQAC,oBAAAA;;;;;;;;;;;;;;;;;;;;UAoBAC,cAAAA;;QAEPxD;;KAEEyD,wBAAAA;KACAC,qBAAAA;UACKC,0BAAAA;QACPF;;;;;;;;;;UAUOG,uBAAAA;;;;;;;;;;;;;;;;UAgBAC,sBAAAA;SACN9F,kBAAkBC;;aAEdY;;;;UAIEkF,WAAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { RenderRange } from "../types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/includesFileAnnotations.d.ts
|
|
4
|
+
declare const FILE_ANNOTATION_LINE_NUMBER = 0;
|
|
5
|
+
declare const FILE_ANNOTATION_HUNK_INDEX = -1;
|
|
6
|
+
declare const FILE_ANNOTATION_LINE_INDEX = -1;
|
|
7
|
+
declare const FILE_ANNOTATION_DOM_KEY: string;
|
|
8
|
+
type AnnotationLineMap<TAnnotation> = Record<number, TAnnotation[] | undefined>;
|
|
9
|
+
type FileLevelAnnotationLike = {
|
|
10
|
+
lineNumber: number;
|
|
11
|
+
};
|
|
12
|
+
declare function includesFileAnnotations(annotations: readonly FileLevelAnnotationLike[] | undefined): boolean;
|
|
13
|
+
declare function getFileAnnotations<TAnnotation>(annotations: AnnotationLineMap<TAnnotation>): TAnnotation[] | undefined;
|
|
14
|
+
declare function shouldRenderFileAnnotations(renderRange: RenderRange): boolean;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { FILE_ANNOTATION_DOM_KEY, FILE_ANNOTATION_HUNK_INDEX, FILE_ANNOTATION_LINE_INDEX, FILE_ANNOTATION_LINE_NUMBER, getFileAnnotations, includesFileAnnotations, shouldRenderFileAnnotations };
|
|
17
|
+
//# sourceMappingURL=includesFileAnnotations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"includesFileAnnotations.d.ts","names":["RenderRange","FILE_ANNOTATION_LINE_NUMBER","FILE_ANNOTATION_HUNK_INDEX","FILE_ANNOTATION_LINE_INDEX","FILE_ANNOTATION_DOM_KEY","AnnotationLineMap","TAnnotation","Record","FileLevelAnnotationLike","includesFileAnnotations","getFileAnnotations","shouldRenderFileAnnotations"],"sources":["../../src/utils/includesFileAnnotations.d.ts"],"sourcesContent":["import type { RenderRange } from '../types';\nexport declare const FILE_ANNOTATION_LINE_NUMBER = 0;\nexport declare const FILE_ANNOTATION_HUNK_INDEX = -1;\nexport declare const FILE_ANNOTATION_LINE_INDEX = -1;\nexport declare const FILE_ANNOTATION_DOM_KEY: string;\ntype AnnotationLineMap<TAnnotation> = Record<number, TAnnotation[] | undefined>;\ntype FileLevelAnnotationLike = {\n lineNumber: number;\n};\nexport declare function includesFileAnnotations(annotations: readonly FileLevelAnnotationLike[] | undefined): boolean;\nexport declare function getFileAnnotations<TAnnotation>(annotations: AnnotationLineMap<TAnnotation>): TAnnotation[] | undefined;\nexport declare function shouldRenderFileAnnotations(renderRange: RenderRange): boolean;\nexport {};\n//# sourceMappingURL=includesFileAnnotations.d.ts.map"],"mappings":";;;cACqBC,2BAAAA;cACAC,0BAAAA;AADAD,cAEAE,0BAAAA,GAF2B,CAAA,CAAA;AAC3BD,cAEAE,uBAF0B,EAAA,MAAA;AAC/C,KAEKC,iBAFgBF,CAAAA,WAA0B,CAAA,GAETI,MAFS,CAAA,MAAA,EAEMD,WAFN,EAAA,GAAA,SAAA,CAAA;AAC/C,KAEKE,uBAAAA,GAF+C;EAC/CH,UAAAA,EAAAA,MAAAA;AAAuC,CAAA;AAIpBI,iBAAAA,uBAAAA,CAA8CD,WAAAA,EAAAA,SAAAA,uBAAuB,EAAA,GAAA,SAAA,CAAA,EAAA,OAAA;AACrEE,iBAAAA,kBAAkBJ,CAAAA,WAAA,CAAA,CAAA,WAAA,EAA2BD,iBAA3B,CAA6CC,WAA7C,CAAA,CAAA,EAA4DA,WAA5D,EAAA,GAAA,SAAA;AAA6CA,iBAC/DK,2BAAAA,CAD+DL,WAAAA,EACtBN,WADsBM,CAAAA,EAAAA,OAAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//#region src/utils/includesFileAnnotations.ts
|
|
2
|
+
const FILE_ANNOTATION_LINE_NUMBER = 0;
|
|
3
|
+
const FILE_ANNOTATION_HUNK_INDEX = -1;
|
|
4
|
+
const FILE_ANNOTATION_LINE_INDEX = -1;
|
|
5
|
+
const FILE_ANNOTATION_DOM_KEY = `${FILE_ANNOTATION_HUNK_INDEX},${FILE_ANNOTATION_LINE_INDEX}`;
|
|
6
|
+
function includesFileAnnotations(annotations) {
|
|
7
|
+
return annotations?.some((annotation) => annotation.lineNumber === FILE_ANNOTATION_LINE_NUMBER) ?? false;
|
|
8
|
+
}
|
|
9
|
+
function getFileAnnotations(annotations) {
|
|
10
|
+
const fileAnnotations = annotations[FILE_ANNOTATION_LINE_NUMBER];
|
|
11
|
+
return fileAnnotations != null && fileAnnotations.length > 0 ? fileAnnotations : void 0;
|
|
12
|
+
}
|
|
13
|
+
function shouldRenderFileAnnotations(renderRange) {
|
|
14
|
+
return renderRange.startingLine === FILE_ANNOTATION_LINE_NUMBER && renderRange.totalLines > 0;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
export { FILE_ANNOTATION_DOM_KEY, FILE_ANNOTATION_HUNK_INDEX, FILE_ANNOTATION_LINE_INDEX, FILE_ANNOTATION_LINE_NUMBER, getFileAnnotations, includesFileAnnotations, shouldRenderFileAnnotations };
|
|
19
|
+
//# sourceMappingURL=includesFileAnnotations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"includesFileAnnotations.js","names":["FILE_ANNOTATION_DOM_KEY: string"],"sources":["../../src/utils/includesFileAnnotations.ts"],"sourcesContent":["import type { RenderRange } from '../types';\n\nexport const FILE_ANNOTATION_LINE_NUMBER = 0;\nexport const FILE_ANNOTATION_HUNK_INDEX = -1;\nexport const FILE_ANNOTATION_LINE_INDEX = -1;\nexport const FILE_ANNOTATION_DOM_KEY: string = `${FILE_ANNOTATION_HUNK_INDEX},${FILE_ANNOTATION_LINE_INDEX}`;\n\ntype AnnotationLineMap<TAnnotation> = Record<number, TAnnotation[] | undefined>;\ntype FileLevelAnnotationLike = { lineNumber: number };\n\nexport function includesFileAnnotations(\n annotations: readonly FileLevelAnnotationLike[] | undefined\n): boolean {\n return (\n annotations?.some(\n (annotation) => annotation.lineNumber === FILE_ANNOTATION_LINE_NUMBER\n ) ?? false\n );\n}\n\nexport function getFileAnnotations<TAnnotation>(\n annotations: AnnotationLineMap<TAnnotation>\n): TAnnotation[] | undefined {\n const fileAnnotations = annotations[FILE_ANNOTATION_LINE_NUMBER];\n return fileAnnotations != null && fileAnnotations.length > 0\n ? fileAnnotations\n : undefined;\n}\n\nexport function shouldRenderFileAnnotations(renderRange: RenderRange): boolean {\n return (\n renderRange.startingLine === FILE_ANNOTATION_LINE_NUMBER &&\n renderRange.totalLines > 0\n );\n}\n"],"mappings":";AAEA,MAAa,8BAA8B;AAC3C,MAAa,6BAA6B;AAC1C,MAAa,6BAA6B;AAC1C,MAAaA,0BAAkC,GAAG,2BAA2B,GAAG;AAKhF,SAAgB,wBACd,aACS;AACT,QACE,aAAa,MACV,eAAe,WAAW,eAAe,4BAC3C,IAAI;;AAIT,SAAgB,mBACd,aAC2B;CAC3B,MAAM,kBAAkB,YAAY;AACpC,QAAO,mBAAmB,QAAQ,gBAAgB,SAAS,IACvD,kBACA;;AAGN,SAAgB,4BAA4B,aAAmC;AAC7E,QACE,YAAY,iBAAiB,+BAC7B,YAAY,aAAa"}
|