@pierre/diffs 1.0.10 → 1.1.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/AdvancedVirtualizedFileDiff.d.ts +40 -0
- package/dist/components/AdvancedVirtualizedFileDiff.d.ts.map +1 -0
- package/dist/components/AdvancedVirtualizedFileDiff.js +145 -0
- package/dist/components/AdvancedVirtualizedFileDiff.js.map +1 -0
- package/dist/components/AdvancedVirtualizer.d.ts +38 -0
- package/dist/components/AdvancedVirtualizer.d.ts.map +1 -0
- package/dist/components/AdvancedVirtualizer.js +201 -0
- package/dist/components/AdvancedVirtualizer.js.map +1 -0
- package/dist/components/File.d.ts +59 -32
- package/dist/components/File.d.ts.map +1 -1
- package/dist/components/File.js +297 -53
- package/dist/components/File.js.map +1 -1
- package/dist/components/FileDiff.d.ts +87 -39
- package/dist/components/FileDiff.d.ts.map +1 -1
- package/dist/components/FileDiff.js +687 -109
- package/dist/components/FileDiff.js.map +1 -1
- package/dist/components/FileStream.d.ts +6 -0
- package/dist/components/FileStream.d.ts.map +1 -1
- package/dist/components/FileStream.js +74 -12
- package/dist/components/FileStream.js.map +1 -1
- package/dist/components/VirtualizedFile.d.ts +33 -0
- package/dist/components/VirtualizedFile.d.ts.map +1 -0
- package/dist/components/VirtualizedFile.js +227 -0
- package/dist/components/VirtualizedFile.js.map +1 -0
- package/dist/components/VirtualizedFileDiff.d.ts +39 -0
- package/dist/components/VirtualizedFileDiff.d.ts.map +1 -0
- package/dist/components/VirtualizedFileDiff.js +316 -0
- package/dist/components/VirtualizedFileDiff.js.map +1 -0
- package/dist/components/Virtualizer.d.ts +63 -0
- package/dist/components/Virtualizer.d.ts.map +1 -0
- package/dist/components/Virtualizer.js +369 -0
- package/dist/components/Virtualizer.js.map +1 -0
- package/dist/components/VirtulizerDevelopment.d.ts +14 -0
- package/dist/components/VirtulizerDevelopment.d.ts.map +1 -0
- package/dist/components/web-components.d.ts +1 -1
- package/dist/components/web-components.d.ts.map +1 -1
- package/dist/constants.d.ts +7 -3
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +20 -2
- package/dist/constants.js.map +1 -1
- package/dist/highlighter/languages/areLanguagesAttached.d.ts.map +1 -1
- package/dist/highlighter/languages/attachResolvedLanguages.d.ts.map +1 -1
- package/dist/highlighter/languages/cleanUpResolvedLanguages.d.ts.map +1 -1
- package/dist/highlighter/languages/constants.d.ts +3 -1
- package/dist/highlighter/languages/constants.d.ts.map +1 -1
- package/dist/highlighter/languages/constants.js +2 -1
- package/dist/highlighter/languages/constants.js.map +1 -1
- package/dist/highlighter/languages/getResolvedLanguages.d.ts.map +1 -1
- package/dist/highlighter/languages/getResolvedOrResolveLanguage.d.ts +1 -1
- package/dist/highlighter/languages/getResolvedOrResolveLanguage.d.ts.map +1 -1
- package/dist/highlighter/languages/hasResolvedLanguages.d.ts.map +1 -1
- package/dist/highlighter/languages/registerCustomLanguage.d.ts +19 -0
- package/dist/highlighter/languages/registerCustomLanguage.d.ts.map +1 -0
- package/dist/highlighter/languages/registerCustomLanguage.js +21 -0
- package/dist/highlighter/languages/registerCustomLanguage.js.map +1 -0
- package/dist/highlighter/languages/resolveLanguage.d.ts +1 -1
- package/dist/highlighter/languages/resolveLanguage.d.ts.map +1 -1
- package/dist/highlighter/languages/resolveLanguage.js +4 -3
- package/dist/highlighter/languages/resolveLanguage.js.map +1 -1
- package/dist/highlighter/languages/resolveLanguages.d.ts.map +1 -1
- package/dist/highlighter/shared_highlighter.d.ts.map +1 -1
- package/dist/highlighter/shared_highlighter.js.map +1 -1
- package/dist/highlighter/themes/areThemesAttached.d.ts.map +1 -1
- package/dist/highlighter/themes/attachResolvedThemes.d.ts.map +1 -1
- package/dist/highlighter/themes/cleanUpResolvedThemes.d.ts.map +1 -1
- package/dist/highlighter/themes/constants.d.ts.map +1 -1
- package/dist/highlighter/themes/getResolvedOrResolveTheme.d.ts.map +1 -1
- package/dist/highlighter/themes/getResolvedThemes.d.ts.map +1 -1
- package/dist/highlighter/themes/hasResolvedThemes.d.ts.map +1 -1
- package/dist/highlighter/themes/registerCustomCSSVariableTheme.d.ts.map +1 -1
- package/dist/highlighter/themes/registerCustomTheme.d.ts.map +1 -1
- package/dist/highlighter/themes/resolveTheme.d.ts.map +1 -1
- package/dist/highlighter/themes/resolveThemes.d.ts.map +1 -1
- package/dist/index.d.ts +27 -13
- package/dist/index.js +22 -8
- package/dist/managers/LineSelectionManager.d.ts +14 -15
- package/dist/managers/LineSelectionManager.d.ts.map +1 -1
- package/dist/managers/LineSelectionManager.js +66 -78
- package/dist/managers/LineSelectionManager.js.map +1 -1
- package/dist/managers/MouseEventManager.d.ts +13 -6
- package/dist/managers/MouseEventManager.d.ts.map +1 -1
- package/dist/managers/MouseEventManager.js +161 -47
- package/dist/managers/MouseEventManager.js.map +1 -1
- package/dist/managers/ResizeManager.d.ts +6 -1
- package/dist/managers/ResizeManager.d.ts.map +1 -1
- package/dist/managers/ResizeManager.js +114 -64
- package/dist/managers/ResizeManager.js.map +1 -1
- package/dist/managers/ScrollSyncManager.d.ts.map +1 -1
- package/dist/managers/UniversalRenderingManager.d.ts.map +1 -1
- package/dist/react/File.d.ts +1 -0
- package/dist/react/File.d.ts.map +1 -1
- package/dist/react/File.js +2 -1
- package/dist/react/File.js.map +1 -1
- package/dist/react/FileDiff.d.ts +1 -0
- package/dist/react/FileDiff.d.ts.map +1 -1
- package/dist/react/FileDiff.js +2 -1
- package/dist/react/FileDiff.js.map +1 -1
- package/dist/react/MultiFileDiff.d.ts +1 -0
- package/dist/react/MultiFileDiff.d.ts.map +1 -1
- package/dist/react/MultiFileDiff.js +4 -3
- package/dist/react/MultiFileDiff.js.map +1 -1
- package/dist/react/PatchDiff.d.ts +1 -0
- package/dist/react/PatchDiff.d.ts.map +1 -1
- package/dist/react/PatchDiff.js +3 -2
- package/dist/react/PatchDiff.js.map +1 -1
- package/dist/react/Virtualizer.d.ts +25 -0
- package/dist/react/Virtualizer.d.ts.map +1 -0
- package/dist/react/Virtualizer.js +38 -0
- package/dist/react/Virtualizer.js.map +1 -0
- package/dist/react/WorkerPoolContext.d.ts.map +1 -1
- package/dist/react/WorkerPoolContext.js +1 -1
- package/dist/react/WorkerPoolContext.js.map +1 -1
- package/dist/react/constants.d.ts.map +1 -1
- package/dist/react/index.d.ts +3 -2
- package/dist/react/index.js +2 -1
- package/dist/react/jsx.d.ts.map +1 -1
- package/dist/react/types.d.ts +5 -3
- package/dist/react/types.d.ts.map +1 -1
- package/dist/react/utils/renderDiffChildren.d.ts +9 -9
- package/dist/react/utils/renderDiffChildren.d.ts.map +1 -1
- package/dist/react/utils/renderDiffChildren.js +3 -3
- package/dist/react/utils/renderDiffChildren.js.map +1 -1
- package/dist/react/utils/renderFileChildren.d.ts +5 -5
- package/dist/react/utils/renderFileChildren.d.ts.map +1 -1
- package/dist/react/utils/templateRender.d.ts.map +1 -1
- package/dist/react/utils/useFileDiffInstance.d.ts +5 -3
- package/dist/react/utils/useFileDiffInstance.d.ts.map +1 -1
- package/dist/react/utils/useFileDiffInstance.js +6 -2
- package/dist/react/utils/useFileDiffInstance.js.map +1 -1
- package/dist/react/utils/useFileInstance.d.ts +5 -3
- package/dist/react/utils/useFileInstance.d.ts.map +1 -1
- package/dist/react/utils/useFileInstance.js +6 -2
- package/dist/react/utils/useFileInstance.js.map +1 -1
- package/dist/react/utils/useStableCallback.d.ts.map +1 -1
- package/dist/react/utils/useStableCallback.js.map +1 -1
- package/dist/renderers/DiffHunksRenderer.d.ts +21 -15
- package/dist/renderers/DiffHunksRenderer.d.ts.map +1 -1
- package/dist/renderers/DiffHunksRenderer.js +392 -357
- package/dist/renderers/DiffHunksRenderer.js.map +1 -1
- package/dist/renderers/FileRenderer.d.ts +13 -5
- package/dist/renderers/FileRenderer.d.ts.map +1 -1
- package/dist/renderers/FileRenderer.js +101 -35
- package/dist/renderers/FileRenderer.js.map +1 -1
- package/dist/shiki-stream/stream.d.ts +2 -2
- package/dist/shiki-stream/stream.d.ts.map +1 -1
- package/dist/shiki-stream/stream.js.map +1 -1
- package/dist/shiki-stream/tokenizer.d.ts +2 -2
- package/dist/shiki-stream/tokenizer.d.ts.map +1 -1
- package/dist/shiki-stream/tokenizer.js.map +1 -1
- package/dist/shiki-stream/types.d.ts +18 -18
- package/dist/shiki-stream/types.d.ts.map +1 -1
- package/dist/sprite.d.ts +1 -1
- package/dist/sprite.d.ts.map +1 -1
- package/dist/ssr/FileDiffReact.d.ts.map +1 -1
- package/dist/ssr/FileDiffReact.js +1 -1
- package/dist/ssr/index.d.ts +2 -2
- package/dist/ssr/preloadDiffs.d.ts.map +1 -1
- package/dist/ssr/preloadFile.d.ts.map +1 -1
- package/dist/ssr/preloadPatchFile.d.ts.map +1 -1
- package/dist/ssr/preloadPatchFile.js.map +1 -1
- package/dist/ssr/renderHTML.d.ts.map +1 -1
- package/dist/style.js +1 -1
- package/dist/style.js.map +1 -1
- package/dist/types.d.ts +311 -74
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/areDiffLineAnnotationsEqual.d.ts +7 -0
- package/dist/utils/areDiffLineAnnotationsEqual.d.ts.map +1 -0
- package/dist/utils/areDiffLineAnnotationsEqual.js +8 -0
- package/dist/utils/areDiffLineAnnotationsEqual.js.map +1 -0
- package/dist/utils/areFilesEqual.d.ts.map +1 -1
- package/dist/utils/areHunkDataEqual.d.ts +7 -0
- package/dist/utils/areHunkDataEqual.d.ts.map +1 -0
- package/dist/utils/areHunkDataEqual.js +8 -0
- package/dist/utils/areHunkDataEqual.js.map +1 -0
- package/dist/utils/areLineAnnotationsEqual.d.ts +7 -0
- package/dist/utils/areLineAnnotationsEqual.d.ts.map +1 -0
- package/dist/utils/areLineAnnotationsEqual.js +8 -0
- package/dist/utils/areLineAnnotationsEqual.js.map +1 -0
- package/dist/utils/areObjectsEqual.d.ts.map +1 -1
- package/dist/utils/areOptionsEqual.d.ts +1 -1
- package/dist/utils/areOptionsEqual.d.ts.map +1 -1
- package/dist/utils/arePrePropertiesEqual.d.ts +7 -0
- package/dist/utils/arePrePropertiesEqual.d.ts.map +1 -0
- package/dist/utils/arePrePropertiesEqual.js +9 -0
- package/dist/utils/arePrePropertiesEqual.js.map +1 -0
- package/dist/utils/areRenderRangesEqual.d.ts +7 -0
- package/dist/utils/areRenderRangesEqual.d.ts.map +1 -0
- package/dist/utils/areRenderRangesEqual.js +9 -0
- package/dist/utils/areRenderRangesEqual.js.map +1 -0
- package/dist/utils/areSelectionsEqual.d.ts.map +1 -1
- package/dist/utils/areThemesEqual.d.ts.map +1 -1
- package/dist/utils/areVirtualWindowSpecsEqual.d.ts +7 -0
- package/dist/utils/areVirtualWindowSpecsEqual.d.ts.map +1 -0
- package/dist/utils/areVirtualWindowSpecsEqual.js +9 -0
- package/dist/utils/areVirtualWindowSpecsEqual.js.map +1 -0
- package/dist/utils/areWorkerStatsEqual.d.ts +8 -0
- package/dist/utils/areWorkerStatsEqual.d.ts.map +1 -0
- package/dist/utils/areWorkerStatsEqual.js +9 -0
- package/dist/utils/areWorkerStatsEqual.js.map +1 -0
- package/dist/utils/cleanLastNewline.d.ts.map +1 -1
- package/dist/utils/createAnnotationElement.d.ts.map +1 -1
- package/dist/utils/createAnnotationWrapperNode.d.ts.map +1 -1
- package/dist/utils/createContentColumn.d.ts +7 -0
- package/dist/utils/createContentColumn.d.ts.map +1 -0
- package/dist/utils/createContentColumn.js +17 -0
- package/dist/utils/createContentColumn.js.map +1 -0
- package/dist/utils/createEmptyRowBuffer.d.ts.map +1 -1
- package/dist/utils/createEmptyRowBuffer.js +2 -1
- package/dist/utils/createEmptyRowBuffer.js.map +1 -1
- package/dist/utils/createFileHeaderElement.d.ts.map +1 -1
- package/dist/utils/createHoverContentNode.d.ts.map +1 -1
- package/dist/utils/createNoNewlineElement.d.ts +2 -1
- package/dist/utils/createNoNewlineElement.d.ts.map +1 -1
- package/dist/utils/createNoNewlineElement.js +3 -6
- package/dist/utils/createNoNewlineElement.js.map +1 -1
- package/dist/utils/createPreElement.d.ts +2 -1
- package/dist/utils/createPreElement.d.ts.map +1 -1
- package/dist/utils/createPreElement.js +4 -3
- package/dist/utils/createPreElement.js.map +1 -1
- package/dist/utils/createRowNodes.d.ts.map +1 -1
- package/dist/utils/createSeparator.d.ts.map +1 -1
- package/dist/utils/createSeparator.js +2 -2
- package/dist/utils/createSeparator.js.map +1 -1
- package/dist/utils/createSpanNodeFromToken.d.ts.map +1 -1
- package/dist/utils/createSpanNodeFromToken.js.map +1 -1
- package/dist/utils/createStyleElement.d.ts.map +1 -1
- package/dist/utils/createTransformerWithState.d.ts.map +1 -1
- package/dist/utils/createTransformerWithState.js +1 -1
- package/dist/utils/createTransformerWithState.js.map +1 -1
- package/dist/utils/createUnsafeCSSStyleNode.d.ts.map +1 -1
- package/dist/utils/createWindowFromScrollPosition.d.ts +22 -0
- package/dist/utils/createWindowFromScrollPosition.d.ts.map +1 -0
- package/dist/utils/createWindowFromScrollPosition.js +26 -0
- package/dist/utils/createWindowFromScrollPosition.js.map +1 -0
- package/dist/utils/cssWrappers.d.ts.map +1 -1
- package/dist/utils/diffAcceptRejectHunk.d.ts +1 -1
- package/dist/utils/diffAcceptRejectHunk.d.ts.map +1 -1
- package/dist/utils/diffAcceptRejectHunk.js +36 -21
- package/dist/utils/diffAcceptRejectHunk.js.map +1 -1
- package/dist/utils/formatCSSVariablePrefix.d.ts +1 -1
- package/dist/utils/formatCSSVariablePrefix.d.ts.map +1 -1
- package/dist/utils/getFiletypeFromFileName.d.ts +2 -1
- package/dist/utils/getFiletypeFromFileName.d.ts.map +1 -1
- package/dist/utils/getFiletypeFromFileName.js +14 -4
- package/dist/utils/getFiletypeFromFileName.js.map +1 -1
- package/dist/utils/getHighlighterOptions.d.ts.map +1 -1
- package/dist/utils/getHighlighterThemeStyles.d.ts.map +1 -1
- package/dist/utils/getHunkSeparatorSlotName.d.ts +3 -1
- package/dist/utils/getHunkSeparatorSlotName.d.ts.map +1 -1
- package/dist/utils/getHunkSeparatorSlotName.js.map +1 -1
- package/dist/utils/getIconForType.d.ts +1 -1
- package/dist/utils/getIconForType.d.ts.map +1 -1
- package/dist/utils/getLineAnnotationName.d.ts.map +1 -1
- package/dist/utils/getLineEndingType.d.ts +1 -1
- package/dist/utils/getLineEndingType.d.ts.map +1 -1
- package/dist/utils/getLineNodes.d.ts.map +1 -1
- package/dist/utils/getOrCreateCodeNode.d.ts +16 -0
- package/dist/utils/getOrCreateCodeNode.d.ts.map +1 -0
- package/dist/utils/getOrCreateCodeNode.js +16 -0
- package/dist/utils/getOrCreateCodeNode.js.map +1 -0
- package/dist/utils/getSingularPatch.d.ts.map +1 -1
- package/dist/utils/getThemes.d.ts.map +1 -1
- package/dist/utils/getTotalLineCountFromHunks.d.ts.map +1 -1
- package/dist/utils/getTotalLineCountFromHunks.js +1 -1
- package/dist/utils/getTotalLineCountFromHunks.js.map +1 -1
- package/dist/utils/hast_utils.d.ts +6 -2
- package/dist/utils/hast_utils.d.ts.map +1 -1
- package/dist/utils/hast_utils.js +34 -1
- package/dist/utils/hast_utils.js.map +1 -1
- package/dist/utils/isDefaultRenderRange.d.ts +7 -0
- package/dist/utils/isDefaultRenderRange.d.ts.map +1 -0
- package/dist/utils/isDefaultRenderRange.js +8 -0
- package/dist/utils/isDefaultRenderRange.js.map +1 -0
- package/dist/utils/isWorkerContext.d.ts.map +1 -1
- package/dist/utils/iterateOverDiff.d.ts +54 -0
- package/dist/utils/iterateOverDiff.d.ts.map +1 -0
- package/dist/utils/iterateOverDiff.js +397 -0
- package/dist/utils/iterateOverDiff.js.map +1 -0
- package/dist/utils/iterateOverFile.d.ts +50 -0
- package/dist/utils/iterateOverFile.d.ts.map +1 -0
- package/dist/utils/iterateOverFile.js +49 -0
- package/dist/utils/iterateOverFile.js.map +1 -0
- package/dist/utils/parseDiffDecorations.d.ts.map +1 -1
- package/dist/utils/parseDiffFromFile.d.ts +6 -6
- package/dist/utils/parseDiffFromFile.d.ts.map +1 -1
- package/dist/utils/parseDiffFromFile.js +10 -7
- package/dist/utils/parseDiffFromFile.js.map +1 -1
- package/dist/utils/parseLineType.d.ts +1 -1
- package/dist/utils/parseLineType.d.ts.map +1 -1
- package/dist/utils/parsePatchFiles.d.ts +25 -11
- package/dist/utils/parsePatchFiles.d.ts.map +1 -1
- package/dist/utils/parsePatchFiles.js +221 -163
- package/dist/utils/parsePatchFiles.js.map +1 -1
- package/dist/utils/prerenderHTMLIfNecessary.d.ts.map +1 -1
- package/dist/utils/processLine.d.ts.map +1 -1
- package/dist/utils/processLine.js +11 -27
- package/dist/utils/processLine.js.map +1 -1
- package/dist/utils/renderDiffWithHighlighter.d.ts +8 -2
- package/dist/utils/renderDiffWithHighlighter.d.ts.map +1 -1
- package/dist/utils/renderDiffWithHighlighter.js +152 -228
- package/dist/utils/renderDiffWithHighlighter.js.map +1 -1
- package/dist/utils/renderFileWithHighlighter.d.ts +7 -2
- package/dist/utils/renderFileWithHighlighter.d.ts.map +1 -1
- package/dist/utils/renderFileWithHighlighter.js +30 -4
- package/dist/utils/renderFileWithHighlighter.js.map +1 -1
- package/dist/utils/resolveVirtualFileMetrics.d.ts +7 -0
- package/dist/utils/resolveVirtualFileMetrics.d.ts.map +1 -0
- package/dist/utils/resolveVirtualFileMetrics.js +25 -0
- package/dist/utils/resolveVirtualFileMetrics.js.map +1 -0
- package/dist/utils/setLanguageOverride.d.ts +2 -1
- package/dist/utils/setLanguageOverride.d.ts.map +1 -1
- package/dist/utils/setLanguageOverride.js.map +1 -1
- package/dist/utils/setWrapperNodeProps.d.ts +4 -7
- package/dist/utils/setWrapperNodeProps.d.ts.map +1 -1
- package/dist/utils/setWrapperNodeProps.js +19 -12
- package/dist/utils/setWrapperNodeProps.js.map +1 -1
- package/dist/utils/splitFileContents.d.ts +12 -0
- package/dist/utils/splitFileContents.d.ts.map +1 -0
- package/dist/utils/splitFileContents.js +17 -0
- package/dist/utils/splitFileContents.js.map +1 -0
- package/dist/utils/trimPatchContext.d.ts +11 -0
- package/dist/utils/trimPatchContext.d.ts.map +1 -0
- package/dist/utils/trimPatchContext.js +99 -0
- package/dist/utils/trimPatchContext.js.map +1 -0
- package/dist/worker/WorkerPoolManager.d.ts +11 -4
- package/dist/worker/WorkerPoolManager.d.ts.map +1 -1
- package/dist/worker/WorkerPoolManager.js +153 -61
- package/dist/worker/WorkerPoolManager.js.map +1 -1
- package/dist/worker/getOrCreateWorkerPoolSingleton.d.ts.map +1 -1
- package/dist/worker/getOrCreateWorkerPoolSingleton.js.map +1 -1
- package/dist/worker/types.d.ts +32 -25
- package/dist/worker/types.d.ts.map +1 -1
- package/dist/worker/worker-portable.js +902 -312
- package/dist/worker/worker-portable.js.map +1 -1
- package/dist/worker/worker.js +657 -268
- package/dist/worker/worker.js.map +1 -1
- package/package.json +52 -50
- package/dist/utils/createCodeNode.d.ts +0 -12
- package/dist/utils/createCodeNode.d.ts.map +0 -1
- package/dist/utils/createCodeNode.js +0 -12
- package/dist/utils/createCodeNode.js.map +0 -1
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { DEFAULT_THEMES } from "../constants.js";
|
|
1
|
+
import { DEFAULT_COLLAPSED_CONTEXT_THRESHOLD, DEFAULT_EXPANDED_REGION, DEFAULT_RENDER_RANGE, DEFAULT_THEMES } from "../constants.js";
|
|
2
2
|
import { areLanguagesAttached } from "../highlighter/languages/areLanguagesAttached.js";
|
|
3
3
|
import { getHighlighterIfLoaded, getSharedHighlighter } from "../highlighter/shared_highlighter.js";
|
|
4
4
|
import { areThemesAttached } from "../highlighter/themes/areThemesAttached.js";
|
|
5
|
+
import { areRenderRangesEqual } from "../utils/areRenderRangesEqual.js";
|
|
5
6
|
import { areThemesEqual } from "../utils/areThemesEqual.js";
|
|
6
|
-
import { createHastElement } from "../utils/hast_utils.js";
|
|
7
|
+
import { createGutterGap, createGutterItem, createGutterWrapper, createHastElement } from "../utils/hast_utils.js";
|
|
7
8
|
import { createAnnotationElement } from "../utils/createAnnotationElement.js";
|
|
9
|
+
import { createContentColumn } from "../utils/createContentColumn.js";
|
|
8
10
|
import { createFileHeaderElement } from "../utils/createFileHeaderElement.js";
|
|
9
11
|
import { createPreElement } from "../utils/createPreElement.js";
|
|
10
12
|
import { getFiletypeFromFileName } from "../utils/getFiletypeFromFileName.js";
|
|
@@ -15,15 +17,15 @@ import { createNoNewlineElement } from "../utils/createNoNewlineElement.js";
|
|
|
15
17
|
import { createSeparator } from "../utils/createSeparator.js";
|
|
16
18
|
import { getHunkSeparatorSlotName } from "../utils/getHunkSeparatorSlotName.js";
|
|
17
19
|
import { getTotalLineCountFromHunks } from "../utils/getTotalLineCountFromHunks.js";
|
|
20
|
+
import { isDefaultRenderRange } from "../utils/isDefaultRenderRange.js";
|
|
21
|
+
import { iterateOverDiff } from "../utils/iterateOverDiff.js";
|
|
18
22
|
import { renderDiffWithHighlighter } from "../utils/renderDiffWithHighlighter.js";
|
|
19
23
|
import { toHtml } from "hast-util-to-html";
|
|
20
24
|
|
|
21
25
|
//#region src/renderers/DiffHunksRenderer.ts
|
|
22
|
-
|
|
23
|
-
fromStart: 0,
|
|
24
|
-
fromEnd: 0
|
|
25
|
-
};
|
|
26
|
+
let instanceId = -1;
|
|
26
27
|
var DiffHunksRenderer = class {
|
|
28
|
+
__id = `diff-hunks-renderer:${++instanceId}`;
|
|
27
29
|
highlighter;
|
|
28
30
|
diff;
|
|
29
31
|
expandedHunks = /* @__PURE__ */ new Map();
|
|
@@ -41,9 +43,16 @@ var DiffHunksRenderer = class {
|
|
|
41
43
|
this.highlighter = void 0;
|
|
42
44
|
this.diff = void 0;
|
|
43
45
|
this.renderCache = void 0;
|
|
46
|
+
this.workerManager?.cleanUpPendingTasks(this);
|
|
44
47
|
this.workerManager = void 0;
|
|
45
48
|
this.onRenderUpdate = void 0;
|
|
46
49
|
}
|
|
50
|
+
recycle() {
|
|
51
|
+
this.highlighter = void 0;
|
|
52
|
+
this.diff = void 0;
|
|
53
|
+
this.renderCache = void 0;
|
|
54
|
+
this.workerManager?.cleanUpPendingTasks(this);
|
|
55
|
+
}
|
|
47
56
|
setOptions(options) {
|
|
48
57
|
this.options = options;
|
|
49
58
|
}
|
|
@@ -59,14 +68,21 @@ var DiffHunksRenderer = class {
|
|
|
59
68
|
}
|
|
60
69
|
expandHunk(index, direction) {
|
|
61
70
|
const { expansionLineCount } = this.getOptionsWithDefaults();
|
|
62
|
-
const region = this.expandedHunks.get(index) ?? {
|
|
71
|
+
const region = { ...this.expandedHunks.get(index) ?? {
|
|
63
72
|
fromStart: 0,
|
|
64
73
|
fromEnd: 0
|
|
65
|
-
};
|
|
74
|
+
} };
|
|
66
75
|
if (direction === "up" || direction === "both") region.fromStart += expansionLineCount;
|
|
67
76
|
if (direction === "down" || direction === "both") region.fromEnd += expansionLineCount;
|
|
77
|
+
if (this.renderCache?.highlighted !== true) this.renderCache = void 0;
|
|
68
78
|
this.expandedHunks.set(index, region);
|
|
69
79
|
}
|
|
80
|
+
getExpandedHunk(hunkIndex) {
|
|
81
|
+
return this.expandedHunks.get(hunkIndex) ?? DEFAULT_EXPANDED_REGION;
|
|
82
|
+
}
|
|
83
|
+
getExpandedHunksMap() {
|
|
84
|
+
return this.expandedHunks;
|
|
85
|
+
}
|
|
70
86
|
setLineAnnotations(lineAnnotations) {
|
|
71
87
|
this.additionAnnotations = {};
|
|
72
88
|
this.deletionAnnotations = {};
|
|
@@ -83,14 +99,16 @@ var DiffHunksRenderer = class {
|
|
|
83
99
|
}
|
|
84
100
|
}
|
|
85
101
|
getOptionsWithDefaults() {
|
|
86
|
-
const { diffIndicators = "bars", diffStyle = "split", disableBackground = false, disableFileHeader = false, disableLineNumbers = false, expandUnchanged = false, expansionLineCount = 100, hunkSeparators = "line-info", lineDiffType = "word-alt", maxLineDiffLength = 1e3, overflow = "scroll", theme = DEFAULT_THEMES, themeType = "system", tokenizeMaxLineLength = 1e3, useCSSClasses = false } = this.options;
|
|
102
|
+
const { diffIndicators = "bars", diffStyle = "split", disableBackground = false, disableFileHeader = false, disableLineNumbers = false, disableVirtualizationBuffers = false, expandUnchanged = false, collapsedContextThreshold = DEFAULT_COLLAPSED_CONTEXT_THRESHOLD, expansionLineCount = 100, hunkSeparators = "line-info", lineDiffType = "word-alt", maxLineDiffLength = 1e3, overflow = "scroll", theme = DEFAULT_THEMES, themeType = "system", tokenizeMaxLineLength = 1e3, useCSSClasses = false } = this.options;
|
|
87
103
|
return {
|
|
88
104
|
diffIndicators,
|
|
89
105
|
diffStyle,
|
|
90
106
|
disableBackground,
|
|
91
107
|
disableFileHeader,
|
|
92
108
|
disableLineNumbers,
|
|
109
|
+
disableVirtualizationBuffers,
|
|
93
110
|
expandUnchanged,
|
|
111
|
+
collapsedContextThreshold,
|
|
94
112
|
expansionLineCount,
|
|
95
113
|
hunkSeparators,
|
|
96
114
|
lineDiffType,
|
|
@@ -116,7 +134,8 @@ var DiffHunksRenderer = class {
|
|
|
116
134
|
diff,
|
|
117
135
|
highlighted: true,
|
|
118
136
|
options,
|
|
119
|
-
result: cache?.result
|
|
137
|
+
result: cache?.result,
|
|
138
|
+
renderRange: void 0
|
|
120
139
|
};
|
|
121
140
|
if (this.workerManager?.isWorkingPool() === true && this.renderCache.result == null) this.workerManager.highlightDiffAST(this, this.diff);
|
|
122
141
|
else this.asyncHighlight(diff).then(({ result, options: options$1 }) => {
|
|
@@ -148,12 +167,14 @@ var DiffHunksRenderer = class {
|
|
|
148
167
|
forceRender: false
|
|
149
168
|
};
|
|
150
169
|
}
|
|
151
|
-
renderDiff(diff = this.renderCache?.diff) {
|
|
170
|
+
renderDiff(diff = this.renderCache?.diff, renderRange = DEFAULT_RENDER_RANGE) {
|
|
152
171
|
if (diff == null) return;
|
|
172
|
+
const { expandUnchanged = false, collapsedContextThreshold } = this.getOptionsWithDefaults();
|
|
153
173
|
const cache = this.workerManager?.getDiffResultCache(diff);
|
|
154
174
|
if (cache != null && this.renderCache == null) this.renderCache = {
|
|
155
175
|
diff,
|
|
156
176
|
highlighted: true,
|
|
177
|
+
renderRange: void 0,
|
|
157
178
|
...cache
|
|
158
179
|
};
|
|
159
180
|
const { options, forceRender } = this.getRenderOptions(diff);
|
|
@@ -161,11 +182,15 @@ var DiffHunksRenderer = class {
|
|
|
161
182
|
diff,
|
|
162
183
|
highlighted: false,
|
|
163
184
|
options,
|
|
164
|
-
result: void 0
|
|
185
|
+
result: void 0,
|
|
186
|
+
renderRange: void 0
|
|
165
187
|
};
|
|
166
188
|
if (this.workerManager?.isWorkingPool() === true) {
|
|
167
|
-
this.renderCache.result
|
|
168
|
-
|
|
189
|
+
if (this.renderCache.result == null || !this.renderCache.highlighted && !areRenderRangesEqual(this.renderCache.renderRange, renderRange)) {
|
|
190
|
+
this.renderCache.result = this.workerManager.getPlainDiffAST(diff, renderRange.startingLine, renderRange.totalLines, isDefaultRenderRange(renderRange) ? true : expandUnchanged ? true : this.expandedHunks, collapsedContextThreshold);
|
|
191
|
+
this.renderCache.renderRange = renderRange;
|
|
192
|
+
}
|
|
193
|
+
if (renderRange.totalLines > 0 && (!this.renderCache.highlighted || forceRender)) this.workerManager.highlightDiffAST(this, diff);
|
|
169
194
|
} else {
|
|
170
195
|
this.computedLang = diff.lang ?? getFiletypeFromFileName(diff.name);
|
|
171
196
|
const hasThemes = this.highlighter != null && areThemesAttached(options.theme);
|
|
@@ -176,22 +201,24 @@ var DiffHunksRenderer = class {
|
|
|
176
201
|
diff,
|
|
177
202
|
options: options$1,
|
|
178
203
|
highlighted: hasLangs,
|
|
179
|
-
result
|
|
204
|
+
result,
|
|
205
|
+
renderRange: void 0
|
|
180
206
|
};
|
|
181
207
|
}
|
|
182
208
|
if (!hasThemes || !hasLangs) this.asyncHighlight(diff).then(({ result, options: options$1 }) => {
|
|
183
209
|
this.onHighlightSuccess(diff, result, options$1);
|
|
184
210
|
});
|
|
185
211
|
}
|
|
186
|
-
return this.renderCache.result != null ? this.processDiffResult(this.renderCache.diff, this.renderCache.result) : void 0;
|
|
212
|
+
return this.renderCache.result != null ? this.processDiffResult(this.renderCache.diff, renderRange, this.renderCache.result) : void 0;
|
|
187
213
|
}
|
|
188
|
-
async asyncRender(diff) {
|
|
214
|
+
async asyncRender(diff, renderRange = DEFAULT_RENDER_RANGE) {
|
|
189
215
|
const { result } = await this.asyncHighlight(diff);
|
|
190
|
-
return this.processDiffResult(diff, result);
|
|
216
|
+
return this.processDiffResult(diff, renderRange, result);
|
|
191
217
|
}
|
|
192
218
|
createPreElement(split, totalLines, themeStyles, baseThemeType) {
|
|
193
219
|
const { diffIndicators, disableBackground, disableLineNumbers, overflow, themeType } = this.getOptionsWithDefaults();
|
|
194
220
|
return createPreElement({
|
|
221
|
+
type: "diff",
|
|
195
222
|
diffIndicators,
|
|
196
223
|
disableBackground,
|
|
197
224
|
disableLineNumbers,
|
|
@@ -209,10 +236,15 @@ var DiffHunksRenderer = class {
|
|
|
209
236
|
if (this.highlighter == null || !hasThemes || !hasLangs) this.highlighter = await this.initializeHighlighter();
|
|
210
237
|
return this.renderDiffWithHighlighter(diff, this.highlighter);
|
|
211
238
|
}
|
|
212
|
-
renderDiffWithHighlighter(diff, highlighter,
|
|
239
|
+
renderDiffWithHighlighter(diff, highlighter, forcePlainText = false) {
|
|
213
240
|
const { options } = this.getRenderOptions(diff);
|
|
241
|
+
const { collapsedContextThreshold } = this.getOptionsWithDefaults();
|
|
214
242
|
return {
|
|
215
|
-
result: renderDiffWithHighlighter(diff, highlighter, options,
|
|
243
|
+
result: renderDiffWithHighlighter(diff, highlighter, options, {
|
|
244
|
+
forcePlainText,
|
|
245
|
+
expandedHunks: forcePlainText ? true : void 0,
|
|
246
|
+
collapsedContextThreshold
|
|
247
|
+
}),
|
|
216
248
|
options
|
|
217
249
|
};
|
|
218
250
|
}
|
|
@@ -223,79 +255,263 @@ var DiffHunksRenderer = class {
|
|
|
223
255
|
diff,
|
|
224
256
|
options,
|
|
225
257
|
highlighted: true,
|
|
226
|
-
result
|
|
258
|
+
result,
|
|
259
|
+
renderRange: void 0
|
|
227
260
|
};
|
|
228
261
|
if (triggerRenderUpdate) this.onRenderUpdate?.();
|
|
229
262
|
}
|
|
230
263
|
onHighlightError(error) {
|
|
231
264
|
console.error(error);
|
|
232
265
|
}
|
|
233
|
-
processDiffResult(fileDiff, { code, themeStyles, baseThemeType }) {
|
|
234
|
-
const { diffStyle, disableFileHeader } = this.getOptionsWithDefaults();
|
|
266
|
+
processDiffResult(fileDiff, renderRange, { code, themeStyles, baseThemeType }) {
|
|
267
|
+
const { diffStyle, disableFileHeader, expandUnchanged, expansionLineCount, collapsedContextThreshold, hunkSeparators } = this.getOptionsWithDefaults();
|
|
235
268
|
this.diff = fileDiff;
|
|
236
269
|
const unified = diffStyle === "unified";
|
|
237
|
-
let
|
|
238
|
-
let
|
|
239
|
-
let
|
|
240
|
-
let hunkIndex = 0;
|
|
270
|
+
let additionsContentAST = [];
|
|
271
|
+
let deletionsContentAST = [];
|
|
272
|
+
let unifiedContentAST = [];
|
|
241
273
|
const hunkData = [];
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
274
|
+
const { additionLines, deletionLines } = code;
|
|
275
|
+
const context = {
|
|
276
|
+
rowCount: 0,
|
|
277
|
+
hunkSeparators,
|
|
278
|
+
additionsContentAST,
|
|
279
|
+
deletionsContentAST,
|
|
280
|
+
unifiedContentAST,
|
|
281
|
+
unifiedGutterAST: createGutterWrapper(),
|
|
282
|
+
deletionsGutterAST: createGutterWrapper(),
|
|
283
|
+
additionsGutterAST: createGutterWrapper(),
|
|
284
|
+
expansionLineCount,
|
|
285
|
+
hunkData,
|
|
286
|
+
incrementRowCount(count = 1) {
|
|
287
|
+
context.rowCount += count;
|
|
288
|
+
},
|
|
289
|
+
pushToGutter(type, element) {
|
|
290
|
+
switch (type) {
|
|
291
|
+
case "unified":
|
|
292
|
+
context.unifiedGutterAST.children.push(element);
|
|
293
|
+
break;
|
|
294
|
+
case "deletions":
|
|
295
|
+
context.deletionsGutterAST.children.push(element);
|
|
296
|
+
break;
|
|
297
|
+
case "additions":
|
|
298
|
+
context.additionsGutterAST.children.push(element);
|
|
299
|
+
break;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
const trailingRangeSize = calculateTrailingRangeSize(fileDiff);
|
|
304
|
+
let pendingSplitSpanSize = 0;
|
|
305
|
+
let pendingSplitMissing;
|
|
306
|
+
function pushGutterLineNumber(type, lineType, lineNumber, lineIndex) {
|
|
307
|
+
context.pushToGutter(type, createGutterItem(lineType, lineNumber, lineIndex));
|
|
308
|
+
}
|
|
309
|
+
function flushSplitSpan() {
|
|
310
|
+
if (diffStyle === "unified") return;
|
|
311
|
+
if (pendingSplitSpanSize <= 0 || pendingSplitMissing == null) {
|
|
312
|
+
pendingSplitSpanSize = 0;
|
|
313
|
+
pendingSplitMissing = void 0;
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
if (pendingSplitMissing === "additions") {
|
|
317
|
+
context.pushToGutter("additions", createGutterGap(void 0, "buffer", pendingSplitSpanSize));
|
|
318
|
+
additionsContentAST?.push(createEmptyRowBuffer(pendingSplitSpanSize));
|
|
319
|
+
} else {
|
|
320
|
+
context.pushToGutter("deletions", createGutterGap(void 0, "buffer", pendingSplitSpanSize));
|
|
321
|
+
deletionsContentAST?.push(createEmptyRowBuffer(pendingSplitSpanSize));
|
|
322
|
+
}
|
|
323
|
+
pendingSplitSpanSize = 0;
|
|
324
|
+
pendingSplitMissing = void 0;
|
|
260
325
|
}
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
326
|
+
function pushSeparators(props) {
|
|
327
|
+
flushSplitSpan();
|
|
328
|
+
if (diffStyle === "unified") pushSeparator("unified", props, context);
|
|
329
|
+
else {
|
|
330
|
+
pushSeparator("deletions", props, context);
|
|
331
|
+
pushSeparator("additions", props, context);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
iterateOverDiff({
|
|
335
|
+
diff: fileDiff,
|
|
336
|
+
diffStyle,
|
|
337
|
+
startingLine: renderRange.startingLine,
|
|
338
|
+
totalLines: renderRange.totalLines,
|
|
339
|
+
expandedHunks: expandUnchanged ? true : this.expandedHunks,
|
|
340
|
+
collapsedContextThreshold,
|
|
341
|
+
callback: ({ hunkIndex, hunk, collapsedBefore, collapsedAfter, additionLine, deletionLine, type }) => {
|
|
342
|
+
const splitLineIndex = deletionLine != null ? deletionLine.splitLineIndex : additionLine.splitLineIndex;
|
|
343
|
+
const unifiedLineIndex = additionLine != null ? additionLine.unifiedLineIndex : deletionLine.unifiedLineIndex;
|
|
344
|
+
if (diffStyle === "split" && type !== "change") flushSplitSpan();
|
|
345
|
+
if (collapsedBefore > 0) pushSeparators({
|
|
346
|
+
hunkIndex,
|
|
347
|
+
collapsedLines: collapsedBefore,
|
|
348
|
+
rangeSize: Math.max(hunk?.collapsedBefore ?? 0, 0),
|
|
349
|
+
hunkSpecs: hunk?.hunkSpecs,
|
|
350
|
+
isFirstHunk: hunkIndex === 0,
|
|
351
|
+
isLastHunk: false,
|
|
352
|
+
isExpandable: !fileDiff.isPartial
|
|
353
|
+
});
|
|
354
|
+
const lineIndex = diffStyle === "unified" ? unifiedLineIndex : splitLineIndex;
|
|
355
|
+
if (diffStyle === "unified") {
|
|
356
|
+
const deletionLineContent = deletionLine != null ? deletionLines[deletionLine.lineIndex] : void 0;
|
|
357
|
+
const additionLineContent = additionLine != null ? additionLines[additionLine.lineIndex] : void 0;
|
|
358
|
+
if (deletionLineContent == null && additionLineContent == null) {
|
|
359
|
+
const errorMessage = "DiffHunksRenderer.processDiffResult: deletionLine and additionLine are null, something is wrong";
|
|
360
|
+
console.error(errorMessage, { file: fileDiff.name });
|
|
361
|
+
throw new Error(errorMessage);
|
|
362
|
+
}
|
|
363
|
+
pushGutterLineNumber("unified", type === "change" ? additionLine != null ? "change-addition" : "change-deletion" : type, additionLine != null ? additionLine.lineNumber : deletionLine.lineNumber, `${unifiedLineIndex},${splitLineIndex}`);
|
|
364
|
+
pushLineWithAnnotation({
|
|
365
|
+
diffStyle: "unified",
|
|
366
|
+
type,
|
|
367
|
+
deletionLine: deletionLineContent,
|
|
368
|
+
additionLine: additionLineContent,
|
|
369
|
+
unifiedSpan: this.getAnnotations("unified", deletionLine?.lineNumber, additionLine?.lineNumber, hunkIndex, lineIndex),
|
|
370
|
+
context
|
|
371
|
+
});
|
|
372
|
+
} else {
|
|
373
|
+
const deletionLineContent = deletionLine != null ? deletionLines[deletionLine.lineIndex] : void 0;
|
|
374
|
+
const additionLineContent = additionLine != null ? additionLines[additionLine.lineIndex] : void 0;
|
|
375
|
+
if (deletionLineContent == null && additionLineContent == null) {
|
|
376
|
+
const errorMessage = "DiffHunksRenderer.processDiffResult: deletionLine and additionLine are null, something is wrong";
|
|
377
|
+
console.error(errorMessage, { file: fileDiff.name });
|
|
378
|
+
throw new Error(errorMessage);
|
|
379
|
+
}
|
|
380
|
+
const missingSide = (() => {
|
|
381
|
+
if (type === "change") {
|
|
382
|
+
if (additionLineContent == null) return "additions";
|
|
383
|
+
else if (deletionLineContent == null) return "deletions";
|
|
384
|
+
}
|
|
385
|
+
})();
|
|
386
|
+
if (missingSide != null) {
|
|
387
|
+
if (pendingSplitMissing != null && pendingSplitMissing !== missingSide) throw new Error("DiffHunksRenderer.processDiffResult: iterateOverDiff, invalid pending splits");
|
|
388
|
+
pendingSplitMissing = missingSide;
|
|
389
|
+
pendingSplitSpanSize++;
|
|
390
|
+
}
|
|
391
|
+
const annotationSpans = this.getAnnotations("split", deletionLine?.lineNumber, additionLine?.lineNumber, hunkIndex, lineIndex);
|
|
392
|
+
if (annotationSpans != null && pendingSplitSpanSize > 0) flushSplitSpan();
|
|
393
|
+
if (deletionLine != null) pushGutterLineNumber("deletions", type === "change" ? "change-deletion" : type, deletionLine.lineNumber, `${deletionLine.unifiedLineIndex},${splitLineIndex}`);
|
|
394
|
+
if (additionLine != null) pushGutterLineNumber("additions", type === "change" ? "change-addition" : type, additionLine.lineNumber, `${additionLine.unifiedLineIndex},${splitLineIndex}`);
|
|
395
|
+
pushLineWithAnnotation({
|
|
396
|
+
diffStyle: "split",
|
|
397
|
+
type,
|
|
398
|
+
additionLine: additionLineContent,
|
|
399
|
+
deletionLine: deletionLineContent,
|
|
400
|
+
...annotationSpans,
|
|
401
|
+
context
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
const noEOFCRDeletion = deletionLine?.noEOFCR ?? false;
|
|
405
|
+
const noEOFCRAddition = additionLine?.noEOFCR ?? false;
|
|
406
|
+
if (noEOFCRAddition || noEOFCRDeletion) {
|
|
407
|
+
if (noEOFCRDeletion) {
|
|
408
|
+
const noEOFType = type === "context" || type === "context-expanded" ? type : "change-deletion";
|
|
409
|
+
if (diffStyle === "unified") {
|
|
410
|
+
context.unifiedContentAST.push(createNoNewlineElement(noEOFType));
|
|
411
|
+
context.pushToGutter("unified", createGutterGap(noEOFType, "metadata", 1));
|
|
412
|
+
} else {
|
|
413
|
+
context.deletionsContentAST.push(createNoNewlineElement(noEOFType));
|
|
414
|
+
context.pushToGutter("deletions", createGutterGap(noEOFType, "metadata", 1));
|
|
415
|
+
if (!noEOFCRAddition) {
|
|
416
|
+
context.pushToGutter("additions", createGutterGap(void 0, "buffer", 1));
|
|
417
|
+
context.additionsContentAST.push(createEmptyRowBuffer(1));
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
if (noEOFCRAddition) {
|
|
422
|
+
const noEOFType = type === "context" || type === "context-expanded" ? type : "change-addition";
|
|
423
|
+
if (diffStyle === "unified") {
|
|
424
|
+
context.unifiedContentAST.push(createNoNewlineElement(noEOFType));
|
|
425
|
+
context.pushToGutter("unified", createGutterGap(noEOFType, "metadata", 1));
|
|
426
|
+
} else {
|
|
427
|
+
context.additionsContentAST.push(createNoNewlineElement(noEOFType));
|
|
428
|
+
context.pushToGutter("additions", createGutterGap(noEOFType, "metadata", 1));
|
|
429
|
+
if (!noEOFCRDeletion) {
|
|
430
|
+
context.pushToGutter("deletions", createGutterGap(void 0, "buffer", 1));
|
|
431
|
+
context.deletionsContentAST.push(createEmptyRowBuffer(1));
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
context.incrementRowCount(1);
|
|
436
|
+
}
|
|
437
|
+
if (collapsedAfter > 0 && hunkSeparators !== "simple") pushSeparators({
|
|
438
|
+
hunkIndex: type === "context-expanded" ? hunkIndex : hunkIndex + 1,
|
|
439
|
+
collapsedLines: collapsedAfter,
|
|
440
|
+
rangeSize: trailingRangeSize,
|
|
441
|
+
hunkSpecs: void 0,
|
|
442
|
+
isFirstHunk: false,
|
|
443
|
+
isLastHunk: true,
|
|
444
|
+
isExpandable: !fileDiff.isPartial
|
|
445
|
+
});
|
|
446
|
+
context.incrementRowCount(1);
|
|
447
|
+
}
|
|
448
|
+
});
|
|
449
|
+
if (diffStyle === "split") flushSplitSpan();
|
|
450
|
+
const totalLines = Math.max(getTotalLineCountFromHunks(fileDiff.hunks), fileDiff.additionLines.length ?? 0, fileDiff.deletionLines.length ?? 0);
|
|
451
|
+
const hasBuffer = renderRange.bufferBefore > 0 || renderRange.bufferAfter > 0;
|
|
452
|
+
const shouldIncludeAdditions = !unified && fileDiff.type !== "deleted";
|
|
453
|
+
const shouldIncludeDeletions = !unified && fileDiff.type !== "new";
|
|
454
|
+
const hasContent = context.rowCount > 0 || hasBuffer;
|
|
455
|
+
additionsContentAST = shouldIncludeAdditions && hasContent ? additionsContentAST : void 0;
|
|
456
|
+
deletionsContentAST = shouldIncludeDeletions && hasContent ? deletionsContentAST : void 0;
|
|
457
|
+
unifiedContentAST = unified && hasContent ? unifiedContentAST : void 0;
|
|
458
|
+
const preNode = this.createPreElement(deletionsContentAST != null && additionsContentAST != null, totalLines, themeStyles, baseThemeType);
|
|
266
459
|
return {
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
460
|
+
unifiedGutterAST: unified && hasContent ? context.unifiedGutterAST.children : void 0,
|
|
461
|
+
unifiedContentAST,
|
|
462
|
+
deletionsGutterAST: shouldIncludeDeletions && hasContent ? context.deletionsGutterAST.children : void 0,
|
|
463
|
+
deletionsContentAST,
|
|
464
|
+
additionsGutterAST: shouldIncludeAdditions && hasContent ? context.additionsGutterAST.children : void 0,
|
|
465
|
+
additionsContentAST,
|
|
270
466
|
hunkData,
|
|
271
467
|
preNode,
|
|
272
468
|
themeStyles,
|
|
273
469
|
baseThemeType,
|
|
274
470
|
headerElement: !disableFileHeader ? this.renderHeader(this.diff, themeStyles, baseThemeType) : void 0,
|
|
275
471
|
totalLines,
|
|
472
|
+
rowCount: context.rowCount,
|
|
473
|
+
bufferBefore: renderRange.bufferBefore,
|
|
474
|
+
bufferAfter: renderRange.bufferAfter,
|
|
276
475
|
css: ""
|
|
277
476
|
};
|
|
278
477
|
}
|
|
478
|
+
renderCodeAST(type, result) {
|
|
479
|
+
const gutterAST = type === "unified" ? result.unifiedGutterAST : type === "deletions" ? result.deletionsGutterAST : result.additionsGutterAST;
|
|
480
|
+
const contentAST = type === "unified" ? result.unifiedContentAST : type === "deletions" ? result.deletionsContentAST : result.additionsContentAST;
|
|
481
|
+
if (gutterAST == null || contentAST == null) return;
|
|
482
|
+
const gutter = createGutterWrapper(gutterAST);
|
|
483
|
+
gutter.properties.style = `grid-row: span ${result.rowCount}`;
|
|
484
|
+
return [gutter, createContentColumn(contentAST, result.rowCount)];
|
|
485
|
+
}
|
|
279
486
|
renderFullAST(result, children = []) {
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
children
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
487
|
+
const unifiedAST = this.renderCodeAST("unified", result);
|
|
488
|
+
if (unifiedAST != null) {
|
|
489
|
+
children.push(createHastElement({
|
|
490
|
+
tagName: "code",
|
|
491
|
+
children: unifiedAST,
|
|
492
|
+
properties: {
|
|
493
|
+
"data-code": "",
|
|
494
|
+
"data-unified": ""
|
|
495
|
+
}
|
|
496
|
+
}));
|
|
497
|
+
return {
|
|
498
|
+
...result.preNode,
|
|
499
|
+
children
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
const deletionsAST = this.renderCodeAST("deletions", result);
|
|
503
|
+
if (deletionsAST != null) children.push(createHastElement({
|
|
289
504
|
tagName: "code",
|
|
290
|
-
children:
|
|
505
|
+
children: deletionsAST,
|
|
291
506
|
properties: {
|
|
292
507
|
"data-code": "",
|
|
293
508
|
"data-deletions": ""
|
|
294
509
|
}
|
|
295
510
|
}));
|
|
296
|
-
|
|
511
|
+
const additionsAST = this.renderCodeAST("additions", result);
|
|
512
|
+
if (additionsAST != null) children.push(createHastElement({
|
|
297
513
|
tagName: "code",
|
|
298
|
-
children:
|
|
514
|
+
children: additionsAST,
|
|
299
515
|
properties: {
|
|
300
516
|
"data-code": "",
|
|
301
517
|
"data-additions": ""
|
|
@@ -320,310 +536,21 @@ var DiffHunksRenderer = class {
|
|
|
320
536
|
}
|
|
321
537
|
}));
|
|
322
538
|
}
|
|
323
|
-
|
|
324
|
-
if (rangeSize <= 0) return;
|
|
325
|
-
const { hunkSeparators, expandUnchanged, diffStyle, expansionLineCount } = this.getOptionsWithDefaults();
|
|
326
|
-
const expandable = ast.hunks == null && ast.newLines.length > 0 && ast.oldLines.length > 0;
|
|
327
|
-
const expandedRegion = this.expandedHunks.get(hunkIndex) ?? EXPANDED_REGION;
|
|
328
|
-
const chunked = rangeSize > expansionLineCount;
|
|
329
|
-
const collapsedLines = Math.max(!expandUnchanged ? rangeSize - (expandedRegion.fromEnd + expandedRegion.fromStart) : 0, 0);
|
|
330
|
-
const pushHunkSeparator = ({ type, linesAST }) => {
|
|
331
|
-
if (hunkSeparators === "line-info" || hunkSeparators === "custom") {
|
|
332
|
-
const slotName = getHunkSeparatorSlotName(type, hunkIndex);
|
|
333
|
-
linesAST.push(createSeparator({
|
|
334
|
-
type: hunkSeparators,
|
|
335
|
-
content: getModifiedLinesString(collapsedLines),
|
|
336
|
-
expandIndex: expandable ? hunkIndex : void 0,
|
|
337
|
-
chunked,
|
|
338
|
-
slotName,
|
|
339
|
-
isFirstHunk,
|
|
340
|
-
isLastHunk
|
|
341
|
-
}));
|
|
342
|
-
hunkData.push({
|
|
343
|
-
slotName,
|
|
344
|
-
hunkIndex,
|
|
345
|
-
lines: collapsedLines,
|
|
346
|
-
type,
|
|
347
|
-
expandable: expandable ? {
|
|
348
|
-
up: expandable && !isFirstHunk,
|
|
349
|
-
down: expandable,
|
|
350
|
-
chunked
|
|
351
|
-
} : void 0
|
|
352
|
-
});
|
|
353
|
-
} else if (hunkSeparators === "metadata" && hunkSpecs != null) linesAST.push(createSeparator({
|
|
354
|
-
type: "metadata",
|
|
355
|
-
content: hunkSpecs,
|
|
356
|
-
isFirstHunk,
|
|
357
|
-
isLastHunk
|
|
358
|
-
}));
|
|
359
|
-
else if (hunkSeparators === "simple" && hunkIndex > 0) linesAST.push(createSeparator({
|
|
360
|
-
type: "simple",
|
|
361
|
-
isFirstHunk,
|
|
362
|
-
isLastHunk: false
|
|
363
|
-
}));
|
|
364
|
-
};
|
|
365
|
-
const renderRange = ({ rangeLen, fromStart }) => {
|
|
366
|
-
if (ast.newLines == null || ast.oldLines == null) return;
|
|
367
|
-
const offset = isLastHunk ? 0 : fromStart ? rangeSize : rangeLen;
|
|
368
|
-
let dLineNumber = deletionLineNumber - offset;
|
|
369
|
-
let aLineNumber = additionLineNumber - offset;
|
|
370
|
-
let lIndex = lineIndex - offset;
|
|
371
|
-
for (let i = 0; i < rangeLen; i++) {
|
|
372
|
-
const oldLine = ast.oldLines[dLineNumber];
|
|
373
|
-
const newLine = ast.newLines[aLineNumber];
|
|
374
|
-
if (oldLine == null || newLine == null) {
|
|
375
|
-
console.error({
|
|
376
|
-
aLineNumber,
|
|
377
|
-
dLineNumber,
|
|
378
|
-
ast
|
|
379
|
-
});
|
|
380
|
-
throw new Error("DiffHunksRenderer.renderHunks prefill context invalid. Must include data for old and new lines");
|
|
381
|
-
}
|
|
382
|
-
dLineNumber++;
|
|
383
|
-
aLineNumber++;
|
|
384
|
-
if (diffStyle === "unified") this.pushLineWithAnnotation({
|
|
385
|
-
newLine,
|
|
386
|
-
unifiedAST,
|
|
387
|
-
unifiedSpan: this.getAnnotations("unified", dLineNumber, aLineNumber, hunkIndex, lIndex)
|
|
388
|
-
});
|
|
389
|
-
else this.pushLineWithAnnotation({
|
|
390
|
-
newLine,
|
|
391
|
-
oldLine,
|
|
392
|
-
additionsAST,
|
|
393
|
-
deletionsAST,
|
|
394
|
-
...this.getAnnotations("split", dLineNumber, aLineNumber, hunkIndex, lIndex)
|
|
395
|
-
});
|
|
396
|
-
lIndex++;
|
|
397
|
-
}
|
|
398
|
-
};
|
|
399
|
-
if (expandable) renderRange({
|
|
400
|
-
rangeLen: Math.min(collapsedLines === 0 || expandUnchanged ? rangeSize : expandedRegion.fromStart, rangeSize),
|
|
401
|
-
fromStart: true
|
|
402
|
-
});
|
|
403
|
-
if (collapsedLines > 0) if (diffStyle === "unified") pushHunkSeparator({
|
|
404
|
-
type: "unified",
|
|
405
|
-
linesAST: unifiedAST
|
|
406
|
-
});
|
|
407
|
-
else {
|
|
408
|
-
pushHunkSeparator({
|
|
409
|
-
type: "deletions",
|
|
410
|
-
linesAST: deletionsAST
|
|
411
|
-
});
|
|
412
|
-
pushHunkSeparator({
|
|
413
|
-
type: "additions",
|
|
414
|
-
linesAST: additionsAST
|
|
415
|
-
});
|
|
416
|
-
}
|
|
417
|
-
if (collapsedLines > 0 && expandedRegion.fromEnd > 0 && !isLastHunk) renderRange({
|
|
418
|
-
rangeLen: Math.min(expandedRegion.fromEnd, rangeSize),
|
|
419
|
-
fromStart: false
|
|
420
|
-
});
|
|
421
|
-
}
|
|
422
|
-
renderHunks({ hunk, hunkData, hunkIndex, lineIndex, isLastHunk, prevHunk, ast, deletionsAST, additionsAST, unifiedAST }) {
|
|
423
|
-
const { diffStyle } = this.getOptionsWithDefaults();
|
|
424
|
-
const unified = diffStyle === "unified";
|
|
425
|
-
let additionLineNumber = hunk.additionStart - 1;
|
|
426
|
-
let deletionLineNumber = hunk.deletionStart - 1;
|
|
427
|
-
this.renderCollapsedHunks({
|
|
428
|
-
additionLineNumber,
|
|
429
|
-
additionsAST,
|
|
430
|
-
ast,
|
|
431
|
-
deletionLineNumber,
|
|
432
|
-
deletionsAST,
|
|
433
|
-
hunkData,
|
|
434
|
-
hunkIndex,
|
|
435
|
-
hunkSpecs: hunk.hunkSpecs,
|
|
436
|
-
isFirstHunk: prevHunk == null,
|
|
437
|
-
isLastHunk: false,
|
|
438
|
-
lineIndex,
|
|
439
|
-
rangeSize: Math.max(hunk.collapsedBefore, 0),
|
|
440
|
-
unifiedAST
|
|
441
|
-
});
|
|
442
|
-
let { oldLines, newLines, oldIndex, newIndex } = (() => {
|
|
443
|
-
if (ast.hunks != null) {
|
|
444
|
-
const lineHunk = ast.hunks[hunkIndex];
|
|
445
|
-
if (lineHunk == null) {
|
|
446
|
-
console.error({
|
|
447
|
-
ast,
|
|
448
|
-
hunkIndex
|
|
449
|
-
});
|
|
450
|
-
throw new Error(`DiffHunksRenderer.renderHunks: lineHunk doesn't exist`);
|
|
451
|
-
}
|
|
452
|
-
return {
|
|
453
|
-
oldLines: lineHunk.oldLines,
|
|
454
|
-
newLines: lineHunk.newLines,
|
|
455
|
-
oldIndex: 0,
|
|
456
|
-
newIndex: 0
|
|
457
|
-
};
|
|
458
|
-
}
|
|
459
|
-
return {
|
|
460
|
-
oldLines: ast.oldLines,
|
|
461
|
-
newLines: ast.newLines,
|
|
462
|
-
oldIndex: deletionLineNumber,
|
|
463
|
-
newIndex: additionLineNumber
|
|
464
|
-
};
|
|
465
|
-
})();
|
|
466
|
-
for (const hunkContent of hunk.hunkContent) if (hunkContent.type === "context") {
|
|
467
|
-
const { length: len } = hunkContent.lines;
|
|
468
|
-
for (let i = 0; i < len; i++) {
|
|
469
|
-
const oldLine = oldLines[oldIndex];
|
|
470
|
-
const newLine = newLines[newIndex];
|
|
471
|
-
oldIndex++;
|
|
472
|
-
newIndex++;
|
|
473
|
-
additionLineNumber++;
|
|
474
|
-
deletionLineNumber++;
|
|
475
|
-
if (unified) {
|
|
476
|
-
if (newLine == null) throw new Error("DiffHunksRenderer.renderHunks: newLine doesnt exist for context...");
|
|
477
|
-
this.pushLineWithAnnotation({
|
|
478
|
-
newLine,
|
|
479
|
-
unifiedAST,
|
|
480
|
-
unifiedSpan: this.getAnnotations("unified", deletionLineNumber, additionLineNumber, hunkIndex, lineIndex)
|
|
481
|
-
});
|
|
482
|
-
} else {
|
|
483
|
-
if (newLine == null || oldLine == null) throw new Error("DiffHunksRenderer.renderHunks: newLine or oldLine doesnt exist for context...");
|
|
484
|
-
this.pushLineWithAnnotation({
|
|
485
|
-
oldLine,
|
|
486
|
-
newLine,
|
|
487
|
-
deletionsAST,
|
|
488
|
-
additionsAST,
|
|
489
|
-
...this.getAnnotations("split", deletionLineNumber, additionLineNumber, hunkIndex, lineIndex)
|
|
490
|
-
});
|
|
491
|
-
}
|
|
492
|
-
lineIndex++;
|
|
493
|
-
}
|
|
494
|
-
if (hunkContent.noEOFCR) {
|
|
495
|
-
const node = createNoNewlineElement("context");
|
|
496
|
-
if (unified) unifiedAST.push(node);
|
|
497
|
-
else {
|
|
498
|
-
deletionsAST.push(node);
|
|
499
|
-
additionsAST.push(node);
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
} else {
|
|
503
|
-
const { length: dLen } = hunkContent.deletions;
|
|
504
|
-
const { length: aLen } = hunkContent.additions;
|
|
505
|
-
const len = unified ? dLen + aLen : Math.max(dLen, aLen);
|
|
506
|
-
let spanSize = 0;
|
|
507
|
-
for (let i = 0; i < len; i++) {
|
|
508
|
-
const { oldLine, newLine } = (() => {
|
|
509
|
-
let oldLine$1 = oldLines[oldIndex];
|
|
510
|
-
let newLine$1 = newLines[newIndex];
|
|
511
|
-
if (unified) if (i < dLen) newLine$1 = void 0;
|
|
512
|
-
else oldLine$1 = void 0;
|
|
513
|
-
else {
|
|
514
|
-
if (i >= dLen) oldLine$1 = void 0;
|
|
515
|
-
if (i >= aLen) newLine$1 = void 0;
|
|
516
|
-
}
|
|
517
|
-
if (oldLine$1 == null && newLine$1 == null) {
|
|
518
|
-
console.error({
|
|
519
|
-
i,
|
|
520
|
-
len,
|
|
521
|
-
ast,
|
|
522
|
-
hunkContent
|
|
523
|
-
});
|
|
524
|
-
throw new Error("renderHunks: oldLine and newLine are null, something is wrong");
|
|
525
|
-
}
|
|
526
|
-
return {
|
|
527
|
-
oldLine: oldLine$1,
|
|
528
|
-
newLine: newLine$1
|
|
529
|
-
};
|
|
530
|
-
})();
|
|
531
|
-
if (oldLine != null) {
|
|
532
|
-
oldIndex++;
|
|
533
|
-
deletionLineNumber++;
|
|
534
|
-
}
|
|
535
|
-
if (newLine != null) {
|
|
536
|
-
newIndex++;
|
|
537
|
-
additionLineNumber++;
|
|
538
|
-
}
|
|
539
|
-
if (unified) {
|
|
540
|
-
this.pushLineWithAnnotation({
|
|
541
|
-
oldLine,
|
|
542
|
-
newLine,
|
|
543
|
-
unifiedAST,
|
|
544
|
-
unifiedSpan: this.getAnnotations("unified", oldLine != null ? deletionLineNumber : void 0, newLine != null ? additionLineNumber : void 0, hunkIndex, lineIndex)
|
|
545
|
-
});
|
|
546
|
-
lineIndex++;
|
|
547
|
-
} else {
|
|
548
|
-
if (oldLine == null || newLine == null) spanSize++;
|
|
549
|
-
const annotationSpans = this.getAnnotations("split", oldLine != null ? deletionLineNumber : void 0, newLine != null ? additionLineNumber : void 0, hunkIndex, lineIndex);
|
|
550
|
-
if (annotationSpans != null) {
|
|
551
|
-
if (spanSize > 0) {
|
|
552
|
-
if (aLen > dLen) deletionsAST.push(createEmptyRowBuffer(spanSize));
|
|
553
|
-
else additionsAST.push(createEmptyRowBuffer(spanSize));
|
|
554
|
-
spanSize = 0;
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
this.pushLineWithAnnotation({
|
|
558
|
-
newLine,
|
|
559
|
-
oldLine,
|
|
560
|
-
deletionsAST,
|
|
561
|
-
additionsAST,
|
|
562
|
-
...annotationSpans
|
|
563
|
-
});
|
|
564
|
-
lineIndex++;
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
if (!unified) {
|
|
568
|
-
if (spanSize > 0) {
|
|
569
|
-
if (aLen > dLen) deletionsAST.push(createEmptyRowBuffer(spanSize));
|
|
570
|
-
else additionsAST.push(createEmptyRowBuffer(spanSize));
|
|
571
|
-
spanSize = 0;
|
|
572
|
-
}
|
|
573
|
-
if (hunkContent.noEOFCRDeletions) {
|
|
574
|
-
deletionsAST.push(createNoNewlineElement("change-deletion"));
|
|
575
|
-
if (!hunkContent.noEOFCRAdditions) additionsAST.push(createEmptyRowBuffer(1));
|
|
576
|
-
}
|
|
577
|
-
if (hunkContent.noEOFCRAdditions) {
|
|
578
|
-
additionsAST.push(createNoNewlineElement("change-addition"));
|
|
579
|
-
if (!hunkContent.noEOFCRDeletions) deletionsAST.push(createEmptyRowBuffer(1));
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
}
|
|
583
|
-
if (isLastHunk && ast.newLines != null && ast.newLines.length > 0) this.renderCollapsedHunks({
|
|
584
|
-
additionLineNumber,
|
|
585
|
-
additionsAST,
|
|
586
|
-
ast,
|
|
587
|
-
deletionLineNumber,
|
|
588
|
-
deletionsAST,
|
|
589
|
-
hunkData,
|
|
590
|
-
hunkIndex: hunkIndex + 1,
|
|
591
|
-
hunkSpecs: void 0,
|
|
592
|
-
isFirstHunk: false,
|
|
593
|
-
isLastHunk: true,
|
|
594
|
-
lineIndex,
|
|
595
|
-
rangeSize: Math.max(ast.newLines.length - Math.max(hunk.additionStart + hunk.additionCount - 1, 0), 0),
|
|
596
|
-
unifiedAST
|
|
597
|
-
});
|
|
598
|
-
return lineIndex;
|
|
599
|
-
}
|
|
600
|
-
pushLineWithAnnotation({ newLine, oldLine, unifiedAST, additionsAST, deletionsAST, unifiedSpan, deletionSpan, additionSpan }) {
|
|
601
|
-
if (unifiedAST != null) {
|
|
602
|
-
if (oldLine != null) unifiedAST.push(oldLine);
|
|
603
|
-
else if (newLine != null) unifiedAST.push(newLine);
|
|
604
|
-
if (unifiedSpan != null) unifiedAST.push(createAnnotationElement(unifiedSpan));
|
|
605
|
-
} else if (deletionsAST != null && additionsAST != null) {
|
|
606
|
-
if (oldLine != null) deletionsAST.push(oldLine);
|
|
607
|
-
if (newLine != null) additionsAST.push(newLine);
|
|
608
|
-
if (deletionSpan != null) deletionsAST.push(createAnnotationElement(deletionSpan));
|
|
609
|
-
if (additionSpan != null) additionsAST.push(createAnnotationElement(additionSpan));
|
|
610
|
-
}
|
|
611
|
-
}
|
|
612
|
-
getAnnotations(type, oldLineNumber, newLineNumber, hunkIndex, lineIndex) {
|
|
539
|
+
getAnnotations(type, deletionLineNumber, additionLineNumber, hunkIndex, lineIndex) {
|
|
613
540
|
const deletionSpan = {
|
|
614
541
|
type: "annotation",
|
|
615
542
|
hunkIndex,
|
|
616
543
|
lineIndex,
|
|
617
544
|
annotations: []
|
|
618
545
|
};
|
|
619
|
-
if (
|
|
546
|
+
if (deletionLineNumber != null) for (const anno of this.deletionAnnotations[deletionLineNumber] ?? []) deletionSpan.annotations.push(getLineAnnotationName(anno));
|
|
620
547
|
const additionSpan = {
|
|
621
548
|
type: "annotation",
|
|
622
549
|
hunkIndex,
|
|
623
550
|
lineIndex,
|
|
624
551
|
annotations: []
|
|
625
552
|
};
|
|
626
|
-
if (
|
|
553
|
+
if (additionLineNumber != null) for (const anno of this.additionAnnotations[additionLineNumber] ?? []) (type === "unified" ? deletionSpan : additionSpan).annotations.push(getLineAnnotationName(anno));
|
|
627
554
|
if (type === "unified") {
|
|
628
555
|
if (deletionSpan.annotations.length > 0) return deletionSpan;
|
|
629
556
|
return;
|
|
@@ -649,6 +576,114 @@ function areRenderOptionsEqual(optionsA, optionsB) {
|
|
|
649
576
|
function getModifiedLinesString(lines) {
|
|
650
577
|
return `${lines} unmodified line${lines > 1 ? "s" : ""}`;
|
|
651
578
|
}
|
|
579
|
+
function pushLineWithAnnotation({ diffStyle, type, deletionLine, additionLine, unifiedSpan, deletionSpan, additionSpan, context }) {
|
|
580
|
+
let hasAnnotationRow = false;
|
|
581
|
+
if (diffStyle === "unified") {
|
|
582
|
+
if (additionLine != null) context.unifiedContentAST.push(additionLine);
|
|
583
|
+
else if (deletionLine != null) context.unifiedContentAST.push(deletionLine);
|
|
584
|
+
if (unifiedSpan != null) {
|
|
585
|
+
const lineType = type === "change" ? deletionLine != null ? "change-deletion" : "change-addition" : type;
|
|
586
|
+
context.unifiedContentAST.push(createAnnotationElement(unifiedSpan));
|
|
587
|
+
context.pushToGutter("unified", createGutterGap(lineType, "annotation", 1));
|
|
588
|
+
hasAnnotationRow = true;
|
|
589
|
+
}
|
|
590
|
+
} else if (diffStyle === "split") {
|
|
591
|
+
if (deletionLine != null) context.deletionsContentAST.push(deletionLine);
|
|
592
|
+
if (additionLine != null) context.additionsContentAST.push(additionLine);
|
|
593
|
+
if (deletionSpan != null) {
|
|
594
|
+
const lineType = type === "change" ? deletionLine != null ? "change-deletion" : "context" : type;
|
|
595
|
+
context.deletionsContentAST.push(createAnnotationElement(deletionSpan));
|
|
596
|
+
context.pushToGutter("deletions", createGutterGap(lineType, "annotation", 1));
|
|
597
|
+
hasAnnotationRow = true;
|
|
598
|
+
}
|
|
599
|
+
if (additionSpan != null) {
|
|
600
|
+
const lineType = type === "change" ? additionLine != null ? "change-addition" : "context" : type;
|
|
601
|
+
context.additionsContentAST.push(createAnnotationElement(additionSpan));
|
|
602
|
+
context.pushToGutter("additions", createGutterGap(lineType, "annotation", 1));
|
|
603
|
+
hasAnnotationRow = true;
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
if (hasAnnotationRow) context.incrementRowCount(1);
|
|
607
|
+
}
|
|
608
|
+
function pushSeparator(type, { hunkIndex, collapsedLines, rangeSize, hunkSpecs, isFirstHunk, isLastHunk, isExpandable }, context) {
|
|
609
|
+
if (collapsedLines <= 0) return;
|
|
610
|
+
const linesAST = type === "unified" ? context.unifiedContentAST : type === "deletions" ? context.deletionsContentAST : context.additionsContentAST;
|
|
611
|
+
if (context.hunkSeparators === "metadata") {
|
|
612
|
+
if (hunkSpecs != null) {
|
|
613
|
+
context.pushToGutter(type, createSeparator({
|
|
614
|
+
type: "metadata",
|
|
615
|
+
content: hunkSpecs,
|
|
616
|
+
isFirstHunk,
|
|
617
|
+
isLastHunk
|
|
618
|
+
}));
|
|
619
|
+
linesAST.push(createSeparator({
|
|
620
|
+
type: "metadata",
|
|
621
|
+
content: hunkSpecs,
|
|
622
|
+
isFirstHunk,
|
|
623
|
+
isLastHunk
|
|
624
|
+
}));
|
|
625
|
+
if (type !== "additions") context.incrementRowCount(1);
|
|
626
|
+
}
|
|
627
|
+
return;
|
|
628
|
+
}
|
|
629
|
+
if (context.hunkSeparators === "simple") {
|
|
630
|
+
if (hunkIndex > 0) {
|
|
631
|
+
context.pushToGutter(type, createSeparator({
|
|
632
|
+
type: "simple",
|
|
633
|
+
isFirstHunk,
|
|
634
|
+
isLastHunk: false
|
|
635
|
+
}));
|
|
636
|
+
linesAST.push(createSeparator({
|
|
637
|
+
type: "simple",
|
|
638
|
+
isFirstHunk,
|
|
639
|
+
isLastHunk: false
|
|
640
|
+
}));
|
|
641
|
+
if (type !== "additions") context.incrementRowCount(1);
|
|
642
|
+
}
|
|
643
|
+
return;
|
|
644
|
+
}
|
|
645
|
+
const slotName = getHunkSeparatorSlotName(type, hunkIndex);
|
|
646
|
+
const chunked = rangeSize > context.expansionLineCount;
|
|
647
|
+
const expandIndex = isExpandable ? hunkIndex : void 0;
|
|
648
|
+
context.pushToGutter(type, createSeparator({
|
|
649
|
+
type: context.hunkSeparators,
|
|
650
|
+
content: getModifiedLinesString(collapsedLines),
|
|
651
|
+
expandIndex,
|
|
652
|
+
chunked,
|
|
653
|
+
slotName,
|
|
654
|
+
isFirstHunk,
|
|
655
|
+
isLastHunk
|
|
656
|
+
}));
|
|
657
|
+
linesAST.push(createSeparator({
|
|
658
|
+
type: context.hunkSeparators,
|
|
659
|
+
content: getModifiedLinesString(collapsedLines),
|
|
660
|
+
expandIndex,
|
|
661
|
+
chunked,
|
|
662
|
+
slotName,
|
|
663
|
+
isFirstHunk,
|
|
664
|
+
isLastHunk
|
|
665
|
+
}));
|
|
666
|
+
if (type !== "additions") context.incrementRowCount(1);
|
|
667
|
+
context.hunkData.push({
|
|
668
|
+
slotName,
|
|
669
|
+
hunkIndex,
|
|
670
|
+
lines: collapsedLines,
|
|
671
|
+
type,
|
|
672
|
+
expandable: isExpandable ? {
|
|
673
|
+
up: !isFirstHunk,
|
|
674
|
+
down: !isLastHunk,
|
|
675
|
+
chunked
|
|
676
|
+
} : void 0
|
|
677
|
+
});
|
|
678
|
+
}
|
|
679
|
+
function calculateTrailingRangeSize(fileDiff) {
|
|
680
|
+
const lastHunk = fileDiff.hunks.at(-1);
|
|
681
|
+
if (lastHunk == null || fileDiff.isPartial || fileDiff.additionLines.length === 0 || fileDiff.deletionLines.length === 0) return 0;
|
|
682
|
+
const additionRemaining = fileDiff.additionLines.length - (lastHunk.additionLineIndex + lastHunk.additionCount);
|
|
683
|
+
const deletionRemaining = fileDiff.deletionLines.length - (lastHunk.deletionLineIndex + lastHunk.deletionCount);
|
|
684
|
+
if (additionRemaining !== deletionRemaining) throw new Error(`DiffHunksRenderer.processDiffResult: trailing context mismatch (additions=${additionRemaining}, deletions=${deletionRemaining}) for ${fileDiff.name}`);
|
|
685
|
+
return Math.min(additionRemaining, deletionRemaining);
|
|
686
|
+
}
|
|
652
687
|
|
|
653
688
|
//#endregion
|
|
654
689
|
export { DiffHunksRenderer };
|