@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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderDiffWithHighlighter.js","names":["hunks: RenderDiffFilesResult[]","deletionSpans: [0 | 1, string][]","additionSpans: [0 | 1, string][]","oldInfo: Record<number, LineInfo | undefined>","newInfo: Record<number, LineInfo | undefined>","oldDecorations: DecorationItem[]","newDecorations: DecorationItem[]","hastConfig: CodeToHastOptions<DiffsThemeNames>"],"sources":["../../src/utils/renderDiffWithHighlighter.ts"],"sourcesContent":["import { diffChars, diffWordsWithSpace } from 'diff';\n\nimport { DEFAULT_THEMES } from '../constants';\nimport type {\n CodeToHastOptions,\n DecorationItem,\n DiffsHighlighter,\n DiffsThemeNames,\n FileContents,\n FileDiffMetadata,\n Hunk,\n LineDiffTypes,\n LineInfo,\n RenderDiffFilesResult,\n RenderDiffOptions,\n SupportedLanguages,\n ThemedDiffResult,\n} from '../types';\nimport { cleanLastNewline } from './cleanLastNewline';\nimport { createTransformerWithState } from './createTransformerWithState';\nimport { formatCSSVariablePrefix } from './formatCSSVariablePrefix';\nimport { getFiletypeFromFileName } from './getFiletypeFromFileName';\nimport { getHighlighterThemeStyles } from './getHighlighterThemeStyles';\nimport { getLineNodes } from './getLineNodes';\nimport {\n createDiffSpanDecoration,\n pushOrJoinSpan,\n} from './parseDiffDecorations';\n\nexport function renderDiffWithHighlighter(\n diff: FileDiffMetadata,\n highlighter: DiffsHighlighter,\n options: RenderDiffOptions,\n forcePlainText = false\n): ThemedDiffResult {\n const baseThemeType = (() => {\n const theme = options.theme ?? DEFAULT_THEMES;\n if (typeof theme === 'string') {\n return highlighter.getTheme(theme).type;\n }\n return undefined;\n })();\n const themeStyles = getHighlighterThemeStyles({\n theme: options.theme,\n highlighter,\n });\n // If we've received a diff with both files\n if (diff.newLines != null && diff.oldLines != null) {\n const {\n oldContent,\n newContent,\n oldInfo,\n newInfo,\n oldDecorations,\n newDecorations,\n } = processLines({\n hunks: diff.hunks,\n oldLines: diff.oldLines,\n newLines: diff.newLines,\n lineDiffType: options.lineDiffType,\n });\n const oldFile = {\n name: diff.prevName ?? diff.name,\n contents: oldContent,\n };\n const newFile = {\n name: diff.name,\n contents: newContent,\n };\n const code = renderTwoFiles({\n oldFile,\n oldInfo,\n oldDecorations,\n\n newFile,\n newInfo,\n newDecorations,\n\n highlighter,\n options,\n languageOverride: forcePlainText ? 'text' : diff.lang,\n });\n return { code, themeStyles, baseThemeType };\n }\n const hunks: RenderDiffFilesResult[] = [];\n let splitLineIndex = 0;\n let unifiedLineIndex = 0;\n for (const hunk of diff.hunks) {\n const {\n oldContent,\n newContent,\n oldInfo,\n newInfo,\n oldDecorations,\n newDecorations,\n splitLineIndex: newSplitLineIndex,\n unifiedLineIndex: newUnifiedLineIndex,\n } = processLines({\n hunks: [hunk],\n splitLineIndex,\n unifiedLineIndex,\n lineDiffType: options.lineDiffType,\n });\n const oldFile = {\n name: diff.prevName ?? diff.name,\n contents: oldContent,\n };\n const newFile = {\n name: diff.name,\n contents: newContent,\n };\n hunks.push(\n renderTwoFiles({\n oldFile,\n oldInfo,\n oldDecorations,\n\n newFile,\n newInfo,\n newDecorations,\n\n highlighter,\n options,\n languageOverride: forcePlainText ? 'text' : diff.lang,\n })\n );\n splitLineIndex = newSplitLineIndex;\n unifiedLineIndex = newUnifiedLineIndex;\n }\n\n const code = (() => {\n if (hunks.length <= 1) {\n const hunk = hunks[0] ?? { oldLines: [], newLines: [] };\n if (hunk.newLines.length === 0 || hunk.oldLines.length === 0) {\n return hunk;\n }\n }\n return { hunks };\n })();\n\n return { code, themeStyles, baseThemeType };\n}\n\ninterface ProcessLineDiffProps {\n oldLine: string | undefined;\n newLine: string | undefined;\n oldLineIndex: number;\n newLineIndex: number;\n oldDecorations: DecorationItem[];\n newDecorations: DecorationItem[];\n lineDiffType: LineDiffTypes;\n}\n\nfunction computeLineDiffDecorations({\n oldLine,\n newLine,\n oldLineIndex,\n newLineIndex,\n oldDecorations,\n newDecorations,\n lineDiffType,\n}: ProcessLineDiffProps) {\n if (oldLine == null || newLine == null || lineDiffType === 'none') {\n return;\n }\n oldLine = cleanLastNewline(oldLine);\n newLine = cleanLastNewline(newLine);\n // NOTE(amadeus): Because we visually trim trailing newlines when rendering,\n // we also gotta make sure the diff parsing doesn't include the newline\n // character that could be there...\n const lineDiff =\n lineDiffType === 'char'\n ? diffChars(oldLine, newLine)\n : diffWordsWithSpace(oldLine, newLine);\n const deletionSpans: [0 | 1, string][] = [];\n const additionSpans: [0 | 1, string][] = [];\n const enableJoin = lineDiffType === 'word-alt';\n for (const item of lineDiff) {\n const isLastItem = item === lineDiff[lineDiff.length - 1];\n if (!item.added && !item.removed) {\n pushOrJoinSpan({\n item,\n arr: deletionSpans,\n enableJoin,\n isNeutral: true,\n isLastItem,\n });\n pushOrJoinSpan({\n item,\n arr: additionSpans,\n enableJoin,\n isNeutral: true,\n isLastItem,\n });\n } else if (item.removed) {\n pushOrJoinSpan({ item, arr: deletionSpans, enableJoin, isLastItem });\n } else {\n pushOrJoinSpan({ item, arr: additionSpans, enableJoin, isLastItem });\n }\n }\n let spanIndex = 0;\n for (const span of deletionSpans) {\n if (span[0] === 1) {\n oldDecorations.push(\n createDiffSpanDecoration({\n // Decoration indexes start at 0\n line: oldLineIndex - 1,\n spanStart: spanIndex,\n spanLength: span[1].length,\n })\n );\n }\n spanIndex += span[1].length;\n }\n spanIndex = 0;\n for (const span of additionSpans) {\n if (span[0] === 1) {\n newDecorations.push(\n createDiffSpanDecoration({\n // Decoration indexes start at 0\n line: newLineIndex - 1,\n spanStart: spanIndex,\n spanLength: span[1].length,\n })\n );\n }\n spanIndex += span[1].length;\n }\n}\n\ninterface ProcessLinesProps {\n hunks: Hunk[];\n oldLines?: string[];\n newLines?: string[];\n splitLineIndex?: number;\n unifiedLineIndex?: number;\n newLineIndex?: number;\n oldLineIndex?: number;\n lineDiffType: LineDiffTypes;\n}\n\nfunction processLines({\n hunks,\n oldLines,\n newLines,\n splitLineIndex = 0,\n unifiedLineIndex = 0,\n lineDiffType,\n}: ProcessLinesProps) {\n const oldInfo: Record<number, LineInfo | undefined> = {};\n const newInfo: Record<number, LineInfo | undefined> = {};\n const oldDecorations: DecorationItem[] = [];\n const newDecorations: DecorationItem[] = [];\n let newLineIndex = 1;\n let oldLineIndex = 1;\n let newLineNumber = 1;\n let oldLineNumber = 1;\n let oldContent = '';\n let newContent = '';\n for (const hunk of hunks) {\n // If there's content prior to the hunk, lets fill it up\n while (\n oldLines != null &&\n newLines != null &&\n newLineIndex < hunk.additionStart &&\n oldLineIndex < hunk.deletionStart\n ) {\n oldInfo[oldLineIndex] = {\n type: 'context-expanded',\n lineNumber: oldLineNumber,\n altLineNumber: newLineNumber,\n lineIndex: `${unifiedLineIndex},${splitLineIndex}`,\n };\n newInfo[newLineIndex] = {\n type: 'context-expanded',\n lineNumber: newLineNumber,\n altLineNumber: oldLineNumber,\n lineIndex: `${unifiedLineIndex},${splitLineIndex}`,\n };\n oldContent += oldLines[oldLineIndex - 1];\n newContent += newLines[newLineIndex - 1];\n oldLineIndex++;\n newLineIndex++;\n oldLineNumber++;\n newLineNumber++;\n splitLineIndex++;\n unifiedLineIndex++;\n }\n oldLineNumber = hunk.deletionStart;\n newLineNumber = hunk.additionStart;\n\n // Lets process the actual hunk content\n for (const hunkContent of hunk.hunkContent) {\n if (hunkContent.type === 'context') {\n for (const line of hunkContent.lines) {\n oldInfo[oldLineIndex] = {\n type: 'context',\n lineNumber: oldLineNumber,\n altLineNumber: newLineNumber,\n lineIndex: `${unifiedLineIndex},${splitLineIndex}`,\n };\n newInfo[newLineIndex] = {\n type: 'context',\n lineNumber: newLineNumber,\n altLineNumber: oldLineNumber,\n lineIndex: `${unifiedLineIndex},${splitLineIndex}`,\n };\n oldContent += line;\n newContent += line;\n oldLineIndex++;\n newLineIndex++;\n newLineNumber++;\n oldLineNumber++;\n splitLineIndex++;\n unifiedLineIndex++;\n }\n } else {\n const len = Math.max(\n hunkContent.additions.length,\n hunkContent.deletions.length\n );\n let i = 0;\n // NOTE(amadeus): Since we iterate through deletions and additions\n // simultaneously, we have to create a secondary iterator for\n // unifiedLineIndex, and then when we're done, add the combined lengths\n // of additions/deletions to the main variable\n let _unifiedLineIndex = unifiedLineIndex;\n while (i < len) {\n const oldLine = hunkContent.deletions[i];\n const newLine = hunkContent.additions[i];\n computeLineDiffDecorations({\n newLine,\n oldLine,\n oldLineIndex,\n newLineIndex,\n oldDecorations,\n newDecorations,\n lineDiffType,\n });\n if (oldLine != null) {\n oldInfo[oldLineIndex] = {\n type: 'change-deletion',\n lineNumber: oldLineNumber,\n lineIndex: `${_unifiedLineIndex},${splitLineIndex}`,\n };\n oldContent += oldLine;\n oldLineIndex++;\n oldLineNumber++;\n }\n if (newLine != null) {\n newInfo[newLineIndex] = {\n type: 'change-addition',\n lineNumber: newLineNumber,\n lineIndex: `${_unifiedLineIndex + hunkContent.deletions.length},${splitLineIndex}`,\n };\n newContent += newLine;\n newLineIndex++;\n newLineNumber++;\n }\n splitLineIndex++;\n _unifiedLineIndex++;\n i++;\n }\n unifiedLineIndex +=\n hunkContent.additions.length + hunkContent.deletions.length;\n }\n }\n\n if (\n oldLines == null ||\n newLines == null ||\n hunk !== hunks[hunks.length - 1]\n )\n continue;\n // If we are on the last hunk, we should fully iterate through the rest\n // of the lines\n while (oldLineIndex <= oldLines.length || newLineIndex <= oldLines.length) {\n const oldLine = oldLines[oldLineIndex - 1];\n const newLine = newLines[newLineIndex - 1];\n if (oldLine == null && newLine == null) {\n break;\n }\n if (oldLine != null) {\n oldInfo[oldLineIndex] = {\n type: 'context-expanded',\n lineNumber: oldLineNumber,\n altLineNumber: newLineNumber,\n lineIndex: `${unifiedLineIndex},${splitLineIndex}`,\n };\n oldContent += oldLine;\n oldLineIndex++;\n oldLineNumber++;\n }\n if (newLine != null) {\n newInfo[newLineIndex] = {\n type: 'context-expanded',\n lineNumber: newLineNumber,\n altLineNumber: oldLineNumber,\n lineIndex: `${unifiedLineIndex},${splitLineIndex}`,\n };\n newContent += newLine;\n newLineIndex++;\n newLineNumber++;\n }\n splitLineIndex++;\n unifiedLineIndex++;\n }\n }\n return {\n oldContent,\n newContent,\n oldInfo,\n newInfo,\n oldDecorations,\n newDecorations,\n splitLineIndex,\n unifiedLineIndex,\n };\n}\n\ninterface RenderTwoFilesProps {\n oldFile: FileContents;\n newFile: FileContents;\n oldInfo: Record<number, LineInfo | undefined>;\n newInfo: Record<number, LineInfo | undefined>;\n oldDecorations: DecorationItem[];\n newDecorations: DecorationItem[];\n options: RenderDiffOptions;\n highlighter: DiffsHighlighter;\n languageOverride: SupportedLanguages | undefined;\n}\n\nfunction renderTwoFiles({\n oldFile,\n newFile,\n oldInfo,\n newInfo,\n highlighter,\n oldDecorations,\n newDecorations,\n languageOverride,\n options: { theme: themeOrThemes = DEFAULT_THEMES, ...options },\n}: RenderTwoFilesProps) {\n const oldLang = languageOverride ?? getFiletypeFromFileName(oldFile.name);\n const newLang = languageOverride ?? getFiletypeFromFileName(newFile.name);\n const { state, transformers } = createTransformerWithState();\n const hastConfig: CodeToHastOptions<DiffsThemeNames> = (() => {\n return typeof themeOrThemes === 'string'\n ? {\n ...options,\n // language will be overwritten for each highlight\n lang: 'text',\n theme: themeOrThemes,\n transformers,\n decorations: undefined,\n defaultColor: false,\n cssVariablePrefix: formatCSSVariablePrefix('token'),\n }\n : {\n ...options,\n // language will be overwritten for each highlight\n lang: 'text',\n themes: themeOrThemes,\n transformers,\n decorations: undefined,\n defaultColor: false,\n cssVariablePrefix: formatCSSVariablePrefix('token'),\n };\n })();\n\n const oldLines = (() => {\n if (oldFile.contents === '') {\n return [];\n }\n hastConfig.lang = oldLang;\n state.lineInfo = oldInfo;\n hastConfig.decorations = oldDecorations;\n return getLineNodes(\n highlighter.codeToHast(cleanLastNewline(oldFile.contents), hastConfig)\n );\n })();\n const newLines = (() => {\n if (newFile.contents === '') {\n return [];\n }\n hastConfig.lang = newLang;\n hastConfig.decorations = newDecorations;\n state.lineInfo = newInfo;\n return getLineNodes(\n highlighter.codeToHast(cleanLastNewline(newFile.contents), hastConfig)\n );\n })();\n\n return { oldLines, newLines };\n}\n"],"mappings":";;;;;;;;;;;AA6BA,SAAgB,0BACd,MACA,aACA,SACA,iBAAiB,OACC;CAClB,MAAM,uBAAuB;EAC3B,MAAM,QAAQ,QAAQ,SAAS;AAC/B,MAAI,OAAO,UAAU,SACnB,QAAO,YAAY,SAAS,MAAM,CAAC;KAGnC;CACJ,MAAM,cAAc,0BAA0B;EAC5C,OAAO,QAAQ;EACf;EACD,CAAC;AAEF,KAAI,KAAK,YAAY,QAAQ,KAAK,YAAY,MAAM;EAClD,MAAM,EACJ,YACA,YACA,SACA,SACA,gBACA,mBACE,aAAa;GACf,OAAO,KAAK;GACZ,UAAU,KAAK;GACf,UAAU,KAAK;GACf,cAAc,QAAQ;GACvB,CAAC;AAsBF,SAAO;GAAE,MAbI,eAAe;IAC1B,SATc;KACd,MAAM,KAAK,YAAY,KAAK;KAC5B,UAAU;KACX;IAOC;IACA;IAEA,SATc;KACd,MAAM,KAAK;KACX,UAAU;KACX;IAOC;IACA;IAEA;I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AAW;AACjB,UAAO,aACL,YAAY,WAAW,iBAAiB,QAAQ,SAAS,EAAE,WAAW,CACvE;MACC;EAEyB"}
|
|
1
|
+
{"version":3,"file":"renderDiffWithHighlighter.js","names":["DEFAULT_PLAIN_TEXT_OPTIONS: ForceDiffPlainTextOptions","code: RenderDiffFilesResult","deletionSpans: [0 | 1, string][]","additionSpans: [0 | 1, string][]","hastConfig: CodeToHastOptions<DiffsThemeNames>"],"sources":["../../src/utils/renderDiffWithHighlighter.ts"],"sourcesContent":["import { diffChars, diffWordsWithSpace } from 'diff';\n\nimport {\n DEFAULT_COLLAPSED_CONTEXT_THRESHOLD,\n DEFAULT_THEMES,\n} from '../constants';\nimport type {\n CodeToHastOptions,\n DecorationItem,\n DiffsHighlighter,\n DiffsThemeNames,\n FileContents,\n FileDiffMetadata,\n ForceDiffPlainTextOptions,\n LineDiffTypes,\n LineInfo,\n RenderDiffFilesResult,\n RenderDiffOptions,\n SupportedLanguages,\n ThemedDiffResult,\n} from '../types';\nimport { cleanLastNewline } from './cleanLastNewline';\nimport { createTransformerWithState } from './createTransformerWithState';\nimport { formatCSSVariablePrefix } from './formatCSSVariablePrefix';\nimport { getFiletypeFromFileName } from './getFiletypeFromFileName';\nimport { getHighlighterThemeStyles } from './getHighlighterThemeStyles';\nimport { getLineNodes } from './getLineNodes';\nimport { iterateOverDiff } from './iterateOverDiff';\nimport {\n createDiffSpanDecoration,\n pushOrJoinSpan,\n} from './parseDiffDecorations';\n\nconst DEFAULT_PLAIN_TEXT_OPTIONS: ForceDiffPlainTextOptions = {\n forcePlainText: false,\n};\n\nexport function renderDiffWithHighlighter(\n diff: FileDiffMetadata,\n highlighter: DiffsHighlighter,\n options: RenderDiffOptions,\n {\n forcePlainText,\n startingLine,\n totalLines,\n expandedHunks,\n collapsedContextThreshold = DEFAULT_COLLAPSED_CONTEXT_THRESHOLD,\n }: ForceDiffPlainTextOptions = DEFAULT_PLAIN_TEXT_OPTIONS\n): ThemedDiffResult {\n if (forcePlainText) {\n startingLine ??= 0;\n totalLines ??= Infinity;\n } else {\n // If we aren't forcing plain text, then we intentionally do not support\n // ranges for highlighting as that could break the syntax highlighting, we\n // we override any values that may have been passed in. Maybe one day we\n // warn about this?\n startingLine = 0;\n totalLines = Infinity;\n }\n const isWindowedHighlight = startingLine > 0 || totalLines < Infinity;\n const baseThemeType = (() => {\n const theme = options.theme ?? DEFAULT_THEMES;\n if (typeof theme === 'string') {\n return highlighter.getTheme(theme).type;\n }\n return undefined;\n })();\n const themeStyles = getHighlighterThemeStyles({\n theme: options.theme,\n highlighter,\n });\n\n // If we have a large file and we are rendering the WHOLE plain diff ast,\n // then we should remove the lineDiffType to make sure things render quickly.\n // For highlighted ASTs or windowed highlights, we should just inherit the\n // setting\n const lineDiffType =\n forcePlainText &&\n !isWindowedHighlight &&\n (diff.unifiedLineCount > 1000 || diff.splitLineCount > 1000)\n ? 'none'\n : options.lineDiffType;\n\n const code: RenderDiffFilesResult = {\n deletionLines: [],\n additionLines: [],\n };\n\n const shouldGroupAll = !forcePlainText && !diff.isPartial;\n const expandedHunksForIteration = forcePlainText ? expandedHunks : undefined;\n const buckets = new Map<number, RenderBucket>();\n function getBucketForHunk(hunkIndex: number) {\n const index = shouldGroupAll ? 0 : hunkIndex;\n const bucket = buckets.get(index) ?? createBucket();\n buckets.set(index, bucket);\n return bucket;\n }\n\n function appendContent(\n lineContent: string,\n lineIndex: number,\n segments: HighlightSegment[],\n contentWrapper: FakeArrayType\n ) {\n if (isWindowedHighlight) {\n let segment = segments.at(-1);\n if (\n segment == null ||\n segment.targetIndex + segment.count !== lineIndex\n ) {\n segment = {\n targetIndex: lineIndex,\n originalOffset: contentWrapper.length,\n count: 0,\n };\n segments.push(segment);\n }\n segment.count++;\n }\n contentWrapper.push(lineContent);\n }\n\n iterateOverDiff({\n diff,\n diffStyle: 'both',\n startingLine,\n totalLines,\n expandedHunks: isWindowedHighlight ? expandedHunksForIteration : true,\n collapsedContextThreshold,\n callback: ({ hunkIndex, additionLine, deletionLine, type }) => {\n const bucket = getBucketForHunk(hunkIndex);\n const splitLineIndex =\n additionLine != null\n ? additionLine.splitLineIndex\n : deletionLine.splitLineIndex;\n\n if (type === 'change' && additionLine != null && deletionLine != null) {\n computeLineDiffDecorations({\n additionLine: diff.additionLines[additionLine.lineIndex],\n deletionLine: diff.deletionLines[deletionLine.lineIndex],\n deletionLineIndex: bucket.deletionContent.length,\n additionLineIndex: bucket.additionContent.length,\n deletionDecorations: bucket.deletionDecorations,\n additionDecorations: bucket.additionDecorations,\n lineDiffType,\n });\n }\n\n if (deletionLine != null) {\n appendContent(\n diff.deletionLines[deletionLine.lineIndex],\n deletionLine.lineIndex,\n bucket.deletionSegments,\n bucket.deletionContent\n );\n bucket.deletionInfo.push({\n type: type === 'change' ? 'change-deletion' : type,\n lineNumber: deletionLine.lineNumber,\n altLineNumber:\n type === 'change'\n ? undefined\n : (additionLine.lineNumber ?? undefined),\n lineIndex: `${deletionLine.unifiedLineIndex},${splitLineIndex}`,\n });\n }\n\n if (additionLine != null) {\n appendContent(\n diff.additionLines[additionLine.lineIndex],\n additionLine.lineIndex,\n bucket.additionSegments,\n bucket.additionContent\n );\n bucket.additionInfo.push({\n type: type === 'change' ? 'change-addition' : type,\n lineNumber: additionLine.lineNumber,\n altLineNumber:\n type === 'change'\n ? undefined\n : (deletionLine.lineNumber ?? undefined),\n lineIndex: `${additionLine.unifiedLineIndex},${splitLineIndex}`,\n });\n }\n },\n });\n\n for (const bucket of buckets.values()) {\n if (\n bucket.deletionContent.length === 0 &&\n bucket.additionContent.length === 0\n ) {\n continue;\n }\n\n const deletionFile = {\n name: diff.prevName ?? diff.name,\n contents: bucket.deletionContent.value,\n };\n const additionFile = {\n name: diff.name,\n contents: bucket.additionContent.value,\n };\n const { deletionLines, additionLines } = renderTwoFiles({\n deletionFile,\n deletionInfo: bucket.deletionInfo,\n deletionDecorations: bucket.deletionDecorations,\n\n additionFile,\n additionInfo: bucket.additionInfo,\n additionDecorations: bucket.additionDecorations,\n\n highlighter,\n options,\n languageOverride: forcePlainText ? 'text' : diff.lang,\n });\n\n if (shouldGroupAll) {\n code.deletionLines = deletionLines;\n code.additionLines = additionLines;\n continue;\n }\n\n if (bucket.deletionSegments.length > 0) {\n for (const seg of bucket.deletionSegments) {\n for (let i = 0; i < seg.count; i++) {\n code.deletionLines[seg.targetIndex + i] =\n deletionLines[seg.originalOffset + i];\n }\n }\n } else {\n code.deletionLines.push(...deletionLines);\n }\n if (bucket.additionSegments.length > 0) {\n for (const seg of bucket.additionSegments) {\n for (let i = 0; i < seg.count; i++) {\n code.additionLines[seg.targetIndex + i] =\n additionLines[seg.originalOffset + i];\n }\n }\n } else {\n code.additionLines.push(...additionLines);\n }\n }\n\n return { code, themeStyles, baseThemeType };\n}\n\ninterface ProcessLineDiffProps {\n deletionLine: string | undefined;\n additionLine: string | undefined;\n deletionLineIndex: number;\n additionLineIndex: number;\n deletionDecorations: DecorationItem[];\n additionDecorations: DecorationItem[];\n lineDiffType: LineDiffTypes;\n}\n\nfunction computeLineDiffDecorations({\n deletionLine,\n additionLine,\n deletionLineIndex,\n additionLineIndex,\n deletionDecorations,\n additionDecorations,\n lineDiffType,\n}: ProcessLineDiffProps) {\n if (deletionLine == null || additionLine == null || lineDiffType === 'none') {\n return;\n }\n deletionLine = cleanLastNewline(deletionLine);\n additionLine = cleanLastNewline(additionLine);\n // NOTE(amadeus): Because we visually trim trailing newlines when rendering,\n // we also gotta make sure the diff parsing doesn't include the newline\n // character that could be there...\n const lineDiff =\n lineDiffType === 'char'\n ? diffChars(deletionLine, additionLine)\n : diffWordsWithSpace(deletionLine, additionLine);\n const deletionSpans: [0 | 1, string][] = [];\n const additionSpans: [0 | 1, string][] = [];\n const enableJoin = lineDiffType === 'word-alt';\n const lastItem = lineDiff.at(-1);\n for (const item of lineDiff) {\n const isLastItem = item === lastItem;\n if (!item.added && !item.removed) {\n pushOrJoinSpan({\n item,\n arr: deletionSpans,\n enableJoin,\n isNeutral: true,\n isLastItem,\n });\n pushOrJoinSpan({\n item,\n arr: additionSpans,\n enableJoin,\n isNeutral: true,\n isLastItem,\n });\n } else if (item.removed) {\n pushOrJoinSpan({ item, arr: deletionSpans, enableJoin, isLastItem });\n } else {\n pushOrJoinSpan({ item, arr: additionSpans, enableJoin, isLastItem });\n }\n }\n let spanIndex = 0;\n for (const span of deletionSpans) {\n if (span[0] === 1) {\n deletionDecorations.push(\n createDiffSpanDecoration({\n line: deletionLineIndex,\n spanStart: spanIndex,\n spanLength: span[1].length,\n })\n );\n }\n spanIndex += span[1].length;\n }\n spanIndex = 0;\n for (const span of additionSpans) {\n if (span[0] === 1) {\n additionDecorations.push(\n createDiffSpanDecoration({\n line: additionLineIndex,\n spanStart: spanIndex,\n spanLength: span[1].length,\n })\n );\n }\n spanIndex += span[1].length;\n }\n}\n\ninterface HighlightSegment {\n // The where the highlighted region starts\n originalOffset: number;\n // Where to place the highlighted line in RenderDiffFilesResult\n targetIndex: number;\n // Number of highlighted lines\n count: number;\n}\n\ninterface FakeArrayType {\n push(value: string): void;\n value: string;\n length: number;\n}\n\ninterface RenderBucket {\n deletionContent: FakeArrayType;\n additionContent: FakeArrayType;\n deletionInfo: (LineInfo | undefined)[];\n additionInfo: (LineInfo | undefined)[];\n deletionDecorations: DecorationItem[];\n additionDecorations: DecorationItem[];\n deletionSegments: HighlightSegment[];\n additionSegments: HighlightSegment[];\n}\n\nfunction createBucket(): RenderBucket {\n return {\n deletionContent: {\n push(value: string) {\n this.value += value;\n this.length++;\n },\n value: '',\n length: 0,\n },\n additionContent: {\n push(value: string) {\n this.value += value;\n this.length++;\n },\n value: '',\n length: 0,\n },\n deletionInfo: [],\n additionInfo: [],\n deletionDecorations: [],\n additionDecorations: [],\n deletionSegments: [],\n additionSegments: [],\n };\n}\n\ninterface RenderTwoFilesProps {\n deletionFile: FileContents;\n additionFile: FileContents;\n deletionInfo: (LineInfo | undefined)[];\n additionInfo: (LineInfo | undefined)[];\n deletionDecorations: DecorationItem[];\n additionDecorations: DecorationItem[];\n options: RenderDiffOptions;\n highlighter: DiffsHighlighter;\n languageOverride: SupportedLanguages | undefined;\n}\n\nfunction renderTwoFiles({\n deletionFile,\n additionFile,\n deletionInfo,\n additionInfo,\n highlighter,\n deletionDecorations,\n additionDecorations,\n languageOverride,\n options: { theme: themeOrThemes = DEFAULT_THEMES, ...options },\n}: RenderTwoFilesProps): RenderDiffFilesResult {\n const deletionLang =\n languageOverride ?? getFiletypeFromFileName(deletionFile.name);\n const additionLang =\n languageOverride ?? getFiletypeFromFileName(additionFile.name);\n const { state, transformers } = createTransformerWithState();\n const hastConfig: CodeToHastOptions<DiffsThemeNames> = (() => {\n return typeof themeOrThemes === 'string'\n ? {\n ...options,\n // language will be overwritten for each highlight\n lang: 'text',\n theme: themeOrThemes,\n transformers,\n decorations: undefined,\n defaultColor: false,\n cssVariablePrefix: formatCSSVariablePrefix('token'),\n }\n : {\n ...options,\n // language will be overwritten for each highlight\n lang: 'text',\n themes: themeOrThemes,\n transformers,\n decorations: undefined,\n defaultColor: false,\n cssVariablePrefix: formatCSSVariablePrefix('token'),\n };\n })();\n\n const deletionLines = (() => {\n if (deletionFile.contents === '') {\n return [];\n }\n hastConfig.lang = deletionLang;\n state.lineInfo = deletionInfo;\n hastConfig.decorations = deletionDecorations;\n return getLineNodes(\n highlighter.codeToHast(\n cleanLastNewline(deletionFile.contents),\n hastConfig\n )\n );\n })();\n const additionLines = (() => {\n if (additionFile.contents === '') {\n return [];\n }\n hastConfig.lang = additionLang;\n hastConfig.decorations = additionDecorations;\n state.lineInfo = additionInfo;\n return getLineNodes(\n highlighter.codeToHast(\n cleanLastNewline(additionFile.contents),\n hastConfig\n )\n );\n })();\n\n return { deletionLines, additionLines };\n}\n"],"mappings":";;;;;;;;;;;;AAiCA,MAAMA,6BAAwD,EAC5D,gBAAgB,OACjB;AAED,SAAgB,0BACd,MACA,aACA,SACA,EACE,gBACA,cACA,YACA,eACA,4BAA4B,wCACC,4BACb;AAClB,KAAI,gBA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aAAa,aAAa,GAC5B,QAAO,EAAE;AAEX,cAAW,OAAO;AAClB,SAAM,WAAW;AACjB,cAAW,cAAc;AACzB,UAAO,aACL,YAAY,WACV,iBAAiB,aAAa,SAAS,EACvC,WACD,CACF;MACC;EAgBoB,sBAfK;AAC3B,OAAI,aAAa,aAAa,GAC5B,QAAO,EAAE;AAEX,cAAW,OAAO;AAClB,cAAW,cAAc;AACzB,SAAM,WAAW;AACjB,UAAO,aACL,YAAY,WACV,iBAAiB,aAAa,SAAS,EACvC,WACD,CACF;MACC;EAEmC"}
|
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
import { DiffsHighlighter, FileContents, RenderFileOptions, ThemedFileResult } from "../types.js";
|
|
1
|
+
import { DiffsHighlighter, FileContents, ForceFilePlainTextOptions, RenderFileOptions, ThemedFileResult } from "../types.js";
|
|
2
2
|
|
|
3
3
|
//#region src/utils/renderFileWithHighlighter.d.ts
|
|
4
4
|
declare function renderFileWithHighlighter(file: FileContents, highlighter: DiffsHighlighter, {
|
|
5
5
|
theme,
|
|
6
6
|
tokenizeMaxLineLength
|
|
7
|
-
}: RenderFileOptions,
|
|
7
|
+
}: RenderFileOptions, {
|
|
8
|
+
forcePlainText,
|
|
9
|
+
startingLine,
|
|
10
|
+
totalLines,
|
|
11
|
+
lines
|
|
12
|
+
}?: ForceFilePlainTextOptions): ThemedFileResult;
|
|
8
13
|
//#endregion
|
|
9
14
|
export { renderFileWithHighlighter };
|
|
10
15
|
//# sourceMappingURL=renderFileWithHighlighter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderFileWithHighlighter.d.ts","names":[],"sources":["../../src/utils/renderFileWithHighlighter.ts"],"sourcesContent":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"renderFileWithHighlighter.d.ts","names":["DiffsHighlighter","FileContents","ForceFilePlainTextOptions","RenderFileOptions","ThemedFileResult","renderFileWithHighlighter","theme","tokenizeMaxLineLength","forcePlainText","startingLine","totalLines","lines"],"sources":["../../src/utils/renderFileWithHighlighter.d.ts"],"sourcesContent":["import type { DiffsHighlighter, FileContents, ForceFilePlainTextOptions, RenderFileOptions, ThemedFileResult } from '../types';\nexport declare function renderFileWithHighlighter(file: FileContents, highlighter: DiffsHighlighter, { theme, tokenizeMaxLineLength }: RenderFileOptions, { forcePlainText, startingLine, totalLines, lines }?: ForceFilePlainTextOptions): ThemedFileResult;\n//# sourceMappingURL=renderFileWithHighlighter.d.ts.map"],"mappings":";;;iBACwBK,yBAAAA,OAAgCJ,2BAA2BD;;;GAAoDG;;;;;IAAyED,4BAA4BE"}
|
|
@@ -1,13 +1,24 @@
|
|
|
1
1
|
import { DEFAULT_THEMES } from "../constants.js";
|
|
2
2
|
import { getFiletypeFromFileName } from "./getFiletypeFromFileName.js";
|
|
3
|
+
import { iterateOverFile } from "./iterateOverFile.js";
|
|
3
4
|
import { cleanLastNewline } from "./cleanLastNewline.js";
|
|
4
5
|
import { createTransformerWithState } from "./createTransformerWithState.js";
|
|
5
6
|
import { formatCSSVariablePrefix } from "./formatCSSVariablePrefix.js";
|
|
6
7
|
import { getHighlighterThemeStyles } from "./getHighlighterThemeStyles.js";
|
|
7
8
|
import { getLineNodes } from "./getLineNodes.js";
|
|
9
|
+
import { splitFileContents } from "./splitFileContents.js";
|
|
8
10
|
|
|
9
11
|
//#region src/utils/renderFileWithHighlighter.ts
|
|
10
|
-
|
|
12
|
+
const DEFAULT_PLAIN_TEXT_OPTIONS = { forcePlainText: false };
|
|
13
|
+
function renderFileWithHighlighter(file, highlighter, { theme = DEFAULT_THEMES, tokenizeMaxLineLength }, { forcePlainText, startingLine, totalLines, lines } = DEFAULT_PLAIN_TEXT_OPTIONS) {
|
|
14
|
+
if (forcePlainText) {
|
|
15
|
+
startingLine ??= 0;
|
|
16
|
+
totalLines ??= Infinity;
|
|
17
|
+
} else {
|
|
18
|
+
startingLine = 0;
|
|
19
|
+
totalLines = Infinity;
|
|
20
|
+
}
|
|
21
|
+
const isWindowedHighlight = startingLine > 0 || totalLines < Infinity;
|
|
11
22
|
const { state, transformers } = createTransformerWithState();
|
|
12
23
|
const lang = forcePlainText ? "text" : file.lang ?? getFiletypeFromFileName(file.name);
|
|
13
24
|
const baseThemeType = (() => {
|
|
@@ -19,8 +30,8 @@ function renderFileWithHighlighter(file, highlighter, { theme = DEFAULT_THEMES,
|
|
|
19
30
|
});
|
|
20
31
|
state.lineInfo = (shikiLineNumber) => ({
|
|
21
32
|
type: "context",
|
|
22
|
-
lineIndex: shikiLineNumber - 1,
|
|
23
|
-
lineNumber: shikiLineNumber
|
|
33
|
+
lineIndex: shikiLineNumber - 1 + startingLine,
|
|
34
|
+
lineNumber: shikiLineNumber + startingLine
|
|
24
35
|
});
|
|
25
36
|
const hastConfig = (() => {
|
|
26
37
|
if (typeof theme === "string") return {
|
|
@@ -40,12 +51,27 @@ function renderFileWithHighlighter(file, highlighter, { theme = DEFAULT_THEMES,
|
|
|
40
51
|
tokenizeMaxLineLength
|
|
41
52
|
};
|
|
42
53
|
})();
|
|
54
|
+
const highlightedLines = getLineNodes(highlighter.codeToHast(isWindowedHighlight ? extractWindowedFileContent(lines ?? splitFileContents(file.contents), startingLine, totalLines) : cleanLastNewline(file.contents), hastConfig));
|
|
55
|
+
const code = isWindowedHighlight ? new Array(startingLine) : highlightedLines;
|
|
56
|
+
if (isWindowedHighlight) code.push(...highlightedLines);
|
|
43
57
|
return {
|
|
44
|
-
code
|
|
58
|
+
code,
|
|
45
59
|
themeStyles,
|
|
46
60
|
baseThemeType
|
|
47
61
|
};
|
|
48
62
|
}
|
|
63
|
+
function extractWindowedFileContent(lines, startingLine, totalLines) {
|
|
64
|
+
let windowContent = "";
|
|
65
|
+
iterateOverFile({
|
|
66
|
+
lines,
|
|
67
|
+
startingLine,
|
|
68
|
+
totalLines,
|
|
69
|
+
callback({ content }) {
|
|
70
|
+
windowContent += content;
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
return windowContent;
|
|
74
|
+
}
|
|
49
75
|
|
|
50
76
|
//#endregion
|
|
51
77
|
export { renderFileWithHighlighter };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderFileWithHighlighter.js","names":["hastConfig: CodeToHastOptions<DiffsThemeNames>"],"sources":["../../src/utils/renderFileWithHighlighter.ts"],"sourcesContent":["import { DEFAULT_THEMES } from '../constants';\nimport type {\n CodeToHastOptions,\n DiffsHighlighter,\n DiffsThemeNames,\n FileContents,\n RenderFileOptions,\n ThemedFileResult,\n} from '../types';\nimport { cleanLastNewline } from './cleanLastNewline';\nimport { createTransformerWithState } from './createTransformerWithState';\nimport { formatCSSVariablePrefix } from './formatCSSVariablePrefix';\nimport { getFiletypeFromFileName } from './getFiletypeFromFileName';\nimport { getHighlighterThemeStyles } from './getHighlighterThemeStyles';\nimport { getLineNodes } from './getLineNodes';\n\nexport function renderFileWithHighlighter(\n file: FileContents,\n highlighter: DiffsHighlighter,\n { theme = DEFAULT_THEMES, tokenizeMaxLineLength }: RenderFileOptions,\n forcePlainText =
|
|
1
|
+
{"version":3,"file":"renderFileWithHighlighter.js","names":["DEFAULT_PLAIN_TEXT_OPTIONS: ForceFilePlainTextOptions","hastConfig: CodeToHastOptions<DiffsThemeNames>","windowContent: string"],"sources":["../../src/utils/renderFileWithHighlighter.ts"],"sourcesContent":["import { DEFAULT_THEMES } from '../constants';\nimport type {\n CodeToHastOptions,\n DiffsHighlighter,\n DiffsThemeNames,\n FileContents,\n ForceFilePlainTextOptions,\n RenderFileOptions,\n ThemedFileResult,\n} from '../types';\nimport { cleanLastNewline } from './cleanLastNewline';\nimport { createTransformerWithState } from './createTransformerWithState';\nimport { formatCSSVariablePrefix } from './formatCSSVariablePrefix';\nimport { getFiletypeFromFileName } from './getFiletypeFromFileName';\nimport { getHighlighterThemeStyles } from './getHighlighterThemeStyles';\nimport { getLineNodes } from './getLineNodes';\nimport { iterateOverFile } from './iterateOverFile';\nimport { splitFileContents } from './splitFileContents';\n\nconst DEFAULT_PLAIN_TEXT_OPTIONS: ForceFilePlainTextOptions = {\n forcePlainText: false,\n};\n\nexport function renderFileWithHighlighter(\n file: FileContents,\n highlighter: DiffsHighlighter,\n { theme = DEFAULT_THEMES, tokenizeMaxLineLength }: RenderFileOptions,\n {\n forcePlainText,\n startingLine,\n totalLines,\n lines,\n }: ForceFilePlainTextOptions = DEFAULT_PLAIN_TEXT_OPTIONS\n): ThemedFileResult {\n if (forcePlainText) {\n startingLine ??= 0;\n totalLines ??= Infinity;\n } else {\n // If we aren't forcing plain text, then we intentionally do not support\n // ranges for highlighting as that could break the syntax highlighting, we\n // we override any values that may have been passed in. Maybe one day we\n // warn about this?\n startingLine = 0;\n totalLines = Infinity;\n }\n const isWindowedHighlight = startingLine > 0 || totalLines < Infinity;\n const { state, transformers } = createTransformerWithState();\n const lang = forcePlainText\n ? 'text'\n : (file.lang ?? getFiletypeFromFileName(file.name));\n const baseThemeType = (() => {\n if (typeof theme === 'string') {\n return highlighter.getTheme(theme).type;\n }\n return undefined;\n })();\n const themeStyles = getHighlighterThemeStyles({\n theme,\n highlighter,\n });\n state.lineInfo = (shikiLineNumber: number) => ({\n type: 'context',\n lineIndex: shikiLineNumber - 1 + startingLine,\n lineNumber: shikiLineNumber + startingLine,\n });\n const hastConfig: CodeToHastOptions<DiffsThemeNames> = (() => {\n if (typeof theme === 'string') {\n return {\n lang,\n theme,\n transformers,\n defaultColor: false,\n cssVariablePrefix: formatCSSVariablePrefix('token'),\n tokenizeMaxLineLength,\n };\n }\n return {\n lang,\n themes: theme,\n transformers,\n defaultColor: false,\n cssVariablePrefix: formatCSSVariablePrefix('token'),\n tokenizeMaxLineLength,\n };\n })();\n const highlightedLines = getLineNodes(\n highlighter.codeToHast(\n isWindowedHighlight\n ? extractWindowedFileContent(\n lines ?? splitFileContents(file.contents),\n startingLine,\n totalLines\n )\n : cleanLastNewline(file.contents),\n hastConfig\n )\n );\n\n // Create sparse array for windowed rendering\n const code = isWindowedHighlight ? new Array(startingLine) : highlightedLines;\n if (isWindowedHighlight) {\n code.push(...highlightedLines);\n }\n\n return { code, themeStyles, baseThemeType };\n}\n\nfunction extractWindowedFileContent(\n lines: string[],\n startingLine: number,\n totalLines: number\n): string {\n let windowContent: string = '';\n iterateOverFile({\n lines,\n startingLine,\n totalLines,\n callback({ content }) {\n windowContent += content;\n },\n });\n return windowContent;\n}\n"],"mappings":";;;;;;;;;;;AAmBA,MAAMA,6BAAwD,EAC5D,gBAAgB,OACjB;AAED,SAAgB,0BACd,MACA,aACA,EAAE,QAAQ,gBAAgB,yBAC1B,EACE,gBACA,cACA,YACA,UAC6B,4BACb;AAClB,KAAI,gBAAgB;AAClB,mBAAiB;AACjB,iBAAe;QACV;AAKL,iBAAe;AACf,eAAa;;CAEf,MAAM,sBAAsB,eAAe,KAAK,aAAa;CAC7D,MAAM,EAAE,OAAO,iBAAiB,4BAA4B;CAC5D,MAAM,OAAO,iBACT,SACC,KAAK,QAAQ,wBAAwB,KAAK,KAAK;CACpD,MAAM,uBAAuB;AAC3B,MAAI,OAAO,UAAU,SACnB,QAAO,YAAY,SAAS,MAAM,CAAC;KAGnC;CACJ,MAAM,cAAc,0BAA0B;EAC5C;EACA;EACD,CAAC;AACF,OAAM,YAAY,qBAA6B;EAC7C,MAAM;EACN,WAAW,kBAAkB,IAAI;EACjC,YAAY,kBAAkB;EAC/B;CACD,MAAMC,oBAAwD;AAC5D,MAAI,OAAO,UAAU,SACnB,QAAO;GACL;GACA;GACA;GACA,cAAc;GACd,mBAAmB,wBAAwB,QAAQ;GACnD;GACD;AAEH,SAAO;GACL;GACA,QAAQ;GACR;GACA,cAAc;GACd,mBAAmB,wBAAwB,QAAQ;GACnD;GACD;KACC;CACJ,MAAM,mBAAmB,aACvB,YAAY,WACV,sBACI,2BACE,SAAS,kBAAkB,KAAK,SAAS,EACzC,cACA,WACD,GACD,iBAAiB,KAAK,SAAS,EACnC,WACD,CACF;CAGD,MAAM,OAAO,sBAAsB,IAAI,MAAM,aAAa,GAAG;AAC7D,KAAI,oBACF,MAAK,KAAK,GAAG,iBAAiB;AAGhC,QAAO;EAAE;EAAM;EAAa;EAAe;;AAG7C,SAAS,2BACP,OACA,cACA,YACQ;CACR,IAAIC,gBAAwB;AAC5B,iBAAgB;EACd;EACA;EACA;EACA,SAAS,EAAE,WAAW;AACpB,oBAAiB;;EAEpB,CAAC;AACF,QAAO"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { HunkSeparators, VirtualFileMetrics } from "../types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/resolveVirtualFileMetrics.d.ts
|
|
4
|
+
declare function resolveVirtualFileMetrics(hunkSeparators: HunkSeparators, metricsOverride?: Partial<VirtualFileMetrics>): VirtualFileMetrics;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { resolveVirtualFileMetrics };
|
|
7
|
+
//# sourceMappingURL=resolveVirtualFileMetrics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveVirtualFileMetrics.d.ts","names":["HunkSeparators","VirtualFileMetrics","resolveVirtualFileMetrics","Partial"],"sources":["../../src/utils/resolveVirtualFileMetrics.d.ts"],"sourcesContent":["import type { HunkSeparators, VirtualFileMetrics } from '../types';\nexport declare function resolveVirtualFileMetrics(hunkSeparators: HunkSeparators, metricsOverride?: Partial<VirtualFileMetrics>): VirtualFileMetrics;\n//# sourceMappingURL=resolveVirtualFileMetrics.d.ts.map"],"mappings":";;;iBACwBE,yBAAAA,iBAA0CF,kCAAkCG,QAAQF,sBAAsBA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { DEFAULT_VIRTUAL_FILE_METRICS } from "../constants.js";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/resolveVirtualFileMetrics.ts
|
|
4
|
+
function resolveVirtualFileMetrics(hunkSeparators, metricsOverride) {
|
|
5
|
+
const metrics = {
|
|
6
|
+
...DEFAULT_VIRTUAL_FILE_METRICS,
|
|
7
|
+
...metricsOverride
|
|
8
|
+
};
|
|
9
|
+
metrics.hunkSeparatorHeight = getHunkSeparatorHeight(hunkSeparators, metricsOverride?.hunkSeparatorHeight);
|
|
10
|
+
return metrics;
|
|
11
|
+
}
|
|
12
|
+
function getHunkSeparatorHeight(type, customHeight) {
|
|
13
|
+
if (customHeight != null) return customHeight;
|
|
14
|
+
switch (type) {
|
|
15
|
+
case "simple": return 4;
|
|
16
|
+
case "metadata":
|
|
17
|
+
case "line-info":
|
|
18
|
+
case "line-info-basic":
|
|
19
|
+
case "custom": return 32;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
export { resolveVirtualFileMetrics };
|
|
25
|
+
//# sourceMappingURL=resolveVirtualFileMetrics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveVirtualFileMetrics.js","names":["metrics: VirtualFileMetrics"],"sources":["../../src/utils/resolveVirtualFileMetrics.ts"],"sourcesContent":["import { DEFAULT_VIRTUAL_FILE_METRICS } from '../constants';\nimport type { HunkSeparators, VirtualFileMetrics } from '../types';\n\nexport function resolveVirtualFileMetrics(\n hunkSeparators: HunkSeparators,\n metricsOverride?: Partial<VirtualFileMetrics>\n): VirtualFileMetrics {\n const metrics: VirtualFileMetrics = {\n ...DEFAULT_VIRTUAL_FILE_METRICS,\n ...metricsOverride,\n };\n metrics.hunkSeparatorHeight = getHunkSeparatorHeight(\n hunkSeparators,\n metricsOverride?.hunkSeparatorHeight\n );\n return metrics;\n}\n\nfunction getHunkSeparatorHeight(\n type: HunkSeparators,\n customHeight: number | undefined\n): number {\n if (customHeight != null) {\n return customHeight;\n }\n switch (type) {\n case 'simple':\n return 4;\n case 'metadata':\n case 'line-info':\n case 'line-info-basic':\n case 'custom':\n return 32;\n }\n}\n"],"mappings":";;;AAGA,SAAgB,0BACd,gBACA,iBACoB;CACpB,MAAMA,UAA8B;EAClC,GAAG;EACH,GAAG;EACJ;AACD,SAAQ,sBAAsB,uBAC5B,gBACA,iBAAiB,oBAClB;AACD,QAAO;;AAGT,SAAS,uBACP,MACA,cACQ;AACR,KAAI,gBAAgB,KAClB,QAAO;AAET,SAAQ,MAAR;EACE,KAAK,SACH,QAAO;EACT,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK,SACH,QAAO"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { FileContents, FileDiffMetadata, SupportedLanguages } from "../types.js";
|
|
2
2
|
|
|
3
3
|
//#region src/utils/setLanguageOverride.d.ts
|
|
4
|
-
declare function setLanguageOverride
|
|
4
|
+
declare function setLanguageOverride(fileOrDiff: FileContents, lang: SupportedLanguages): FileContents;
|
|
5
|
+
declare function setLanguageOverride(fileOrDiff: FileDiffMetadata, lang: SupportedLanguages): FileDiffMetadata;
|
|
5
6
|
//#endregion
|
|
6
7
|
export { setLanguageOverride };
|
|
7
8
|
//# sourceMappingURL=setLanguageOverride.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setLanguageOverride.d.ts","names":[],"sources":["../../src/utils/setLanguageOverride.ts"],"sourcesContent":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"setLanguageOverride.d.ts","names":["FileContents","FileDiffMetadata","SupportedLanguages","setLanguageOverride"],"sources":["../../src/utils/setLanguageOverride.d.ts"],"sourcesContent":["import type { FileContents, FileDiffMetadata, SupportedLanguages } from '../types';\nexport declare function setLanguageOverride(fileOrDiff: FileContents, lang: SupportedLanguages): FileContents;\nexport declare function setLanguageOverride(fileOrDiff: FileDiffMetadata, lang: SupportedLanguages): FileDiffMetadata;\n//# sourceMappingURL=setLanguageOverride.d.ts.map"],"mappings":";;;iBACwBG,mBAAAA,aAAgCH,oBAAoBE,qBAAqBF;iBACzEG,mBAAAA,aAAgCF,wBAAwBC,qBAAqBD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setLanguageOverride.js","names":[],"sources":["../../src/utils/setLanguageOverride.ts"],"sourcesContent":["import type {\n FileContents,\n FileDiffMetadata,\n SupportedLanguages,\n} from '../types';\n\nexport function setLanguageOverride
|
|
1
|
+
{"version":3,"file":"setLanguageOverride.js","names":[],"sources":["../../src/utils/setLanguageOverride.ts"],"sourcesContent":["import type {\n FileContents,\n FileDiffMetadata,\n SupportedLanguages,\n} from '../types';\n\nexport function setLanguageOverride(\n fileOrDiff: FileContents,\n lang: SupportedLanguages\n): FileContents;\nexport function setLanguageOverride(\n fileOrDiff: FileDiffMetadata,\n lang: SupportedLanguages\n): FileDiffMetadata;\nexport function setLanguageOverride(\n fileOrDiff: FileContents | FileDiffMetadata,\n lang: SupportedLanguages\n): FileContents | FileDiffMetadata {\n return { ...fileOrDiff, lang };\n}\n"],"mappings":";AAcA,SAAgB,oBACd,YACA,MACiC;AACjC,QAAO;EAAE,GAAG;EAAY;EAAM"}
|
|
@@ -1,20 +1,17 @@
|
|
|
1
1
|
import { PrePropertiesConfig } from "../types.js";
|
|
2
2
|
|
|
3
3
|
//#region src/utils/setWrapperNodeProps.d.ts
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
declare function setPreNodeProperties({
|
|
4
|
+
declare function setPreNodeProperties(pre: HTMLPreElement, {
|
|
5
|
+
type,
|
|
8
6
|
diffIndicators,
|
|
9
7
|
disableBackground,
|
|
10
8
|
disableLineNumbers,
|
|
11
9
|
overflow,
|
|
12
|
-
pre,
|
|
13
10
|
split,
|
|
14
11
|
themeStyles,
|
|
15
12
|
themeType,
|
|
16
13
|
totalLines
|
|
17
|
-
}:
|
|
14
|
+
}: PrePropertiesConfig): HTMLPreElement;
|
|
18
15
|
//#endregion
|
|
19
|
-
export {
|
|
16
|
+
export { setPreNodeProperties };
|
|
20
17
|
//# sourceMappingURL=setWrapperNodeProps.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setWrapperNodeProps.d.ts","names":[],"sources":["../../src/utils/setWrapperNodeProps.ts"],"sourcesContent":[
|
|
1
|
+
{"version":3,"file":"setWrapperNodeProps.d.ts","names":["PrePropertiesConfig","setPreNodeProperties","HTMLPreElement","type","diffIndicators","disableBackground","disableLineNumbers","overflow","split","themeStyles","themeType","totalLines"],"sources":["../../src/utils/setWrapperNodeProps.d.ts"],"sourcesContent":["import type { PrePropertiesConfig } from '../types';\nexport declare function setPreNodeProperties(pre: HTMLPreElement, { type, diffIndicators, disableBackground, disableLineNumbers, overflow, split, themeStyles, themeType, totalLines }: PrePropertiesConfig): HTMLPreElement;\n//# sourceMappingURL=setWrapperNodeProps.d.ts.map"],"mappings":";;;iBACwBC,oBAAAA,MAA0BC;;;;;;;;;;GAAsIF,sBAAsBE"}
|
|
@@ -1,23 +1,30 @@
|
|
|
1
1
|
//#region src/utils/setWrapperNodeProps.ts
|
|
2
|
-
function setPreNodeProperties({ diffIndicators, disableBackground, disableLineNumbers, overflow,
|
|
3
|
-
if (
|
|
4
|
-
|
|
2
|
+
function setPreNodeProperties(pre, { type, diffIndicators, disableBackground, disableLineNumbers, overflow, split, themeStyles, themeType, totalLines }) {
|
|
3
|
+
if (type === "diff") {
|
|
4
|
+
pre.setAttribute("data-diff", "");
|
|
5
|
+
pre.removeAttribute("data-file");
|
|
6
|
+
} else {
|
|
7
|
+
pre.setAttribute("data-file", "");
|
|
8
|
+
pre.removeAttribute("data-diff");
|
|
9
|
+
}
|
|
10
|
+
if (themeType === "system") pre.removeAttribute("data-theme-type");
|
|
11
|
+
else pre.setAttribute("data-theme-type", themeType);
|
|
5
12
|
switch (diffIndicators) {
|
|
6
13
|
case "bars":
|
|
7
14
|
case "classic":
|
|
8
|
-
pre.
|
|
15
|
+
pre.setAttribute("data-indicators", diffIndicators);
|
|
9
16
|
break;
|
|
10
17
|
case "none":
|
|
11
|
-
|
|
18
|
+
pre.removeAttribute("data-indicators");
|
|
12
19
|
break;
|
|
13
20
|
}
|
|
14
|
-
if (disableLineNumbers) pre.
|
|
15
|
-
else
|
|
16
|
-
if (disableBackground)
|
|
17
|
-
else pre.
|
|
18
|
-
pre.
|
|
19
|
-
pre.
|
|
20
|
-
pre.
|
|
21
|
+
if (disableLineNumbers) pre.setAttribute("data-disable-line-numbers", "");
|
|
22
|
+
else pre.removeAttribute("data-disable-line-numbers");
|
|
23
|
+
if (disableBackground) pre.removeAttribute("data-background");
|
|
24
|
+
else pre.setAttribute("data-background", "");
|
|
25
|
+
if (type === "diff") pre.setAttribute("data-diff-type", split ? "split" : "single");
|
|
26
|
+
else pre.removeAttribute("data-diff-type");
|
|
27
|
+
pre.setAttribute("data-overflow", overflow);
|
|
21
28
|
pre.tabIndex = 0;
|
|
22
29
|
pre.style = themeStyles;
|
|
23
30
|
pre.style.setProperty("--diffs-min-number-column-width-default", `${`${totalLines}`.length}ch`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setWrapperNodeProps.js","names":[],"sources":["../../src/utils/setWrapperNodeProps.ts"],"sourcesContent":["import type { PrePropertiesConfig } from '../types';\n\nexport
|
|
1
|
+
{"version":3,"file":"setWrapperNodeProps.js","names":[],"sources":["../../src/utils/setWrapperNodeProps.ts"],"sourcesContent":["import type { PrePropertiesConfig } from '../types';\n\nexport function setPreNodeProperties(\n pre: HTMLPreElement,\n {\n type,\n diffIndicators,\n disableBackground,\n disableLineNumbers,\n overflow,\n split,\n themeStyles,\n themeType,\n totalLines,\n }: PrePropertiesConfig\n): HTMLPreElement {\n if (type === 'diff') {\n pre.setAttribute('data-diff', '');\n pre.removeAttribute('data-file');\n } else {\n pre.setAttribute('data-file', '');\n pre.removeAttribute('data-diff');\n }\n if (themeType === 'system') {\n pre.removeAttribute('data-theme-type');\n } else {\n pre.setAttribute('data-theme-type', themeType);\n }\n switch (diffIndicators) {\n case 'bars':\n case 'classic':\n pre.setAttribute('data-indicators', diffIndicators);\n break;\n case 'none':\n pre.removeAttribute('data-indicators');\n break;\n }\n if (disableLineNumbers) {\n pre.setAttribute('data-disable-line-numbers', '');\n } else {\n pre.removeAttribute('data-disable-line-numbers');\n }\n if (disableBackground) {\n pre.removeAttribute('data-background');\n } else {\n pre.setAttribute('data-background', '');\n }\n if (type === 'diff') {\n pre.setAttribute('data-diff-type', split ? 'split' : 'single');\n } else {\n pre.removeAttribute('data-diff-type');\n }\n pre.setAttribute('data-overflow', overflow);\n pre.tabIndex = 0;\n // Set theme color custom properties as inline styles on pre element\n pre.style = themeStyles;\n // Set CSS custom property for line number column width\n pre.style.setProperty(\n '--diffs-min-number-column-width-default',\n `${`${totalLines}`.length}ch`\n );\n return pre;\n}\n"],"mappings":";AAEA,SAAgB,qBACd,KACA,EACE,MACA,gBACA,mBACA,oBACA,UACA,OACA,aACA,WACA,cAEc;AAChB,KAAI,SAAS,QAAQ;AACnB,MAAI,aAAa,aAAa,GAAG;AACjC,MAAI,gBAAgB,YAAY;QAC3B;AACL,MAAI,aAAa,aAAa,GAAG;AACjC,MAAI,gBAAgB,YAAY;;AAElC,KAAI,cAAc,SAChB,KAAI,gBAAgB,kBAAkB;KAEtC,KAAI,aAAa,mBAAmB,UAAU;AAEhD,SAAQ,gBAAR;EACE,KAAK;EACL,KAAK;AACH,OAAI,aAAa,mBAAmB,eAAe;AACnD;EACF,KAAK;AACH,OAAI,gBAAgB,kBAAkB;AACtC;;AAEJ,KAAI,mBACF,KAAI,aAAa,6BAA6B,GAAG;KAEjD,KAAI,gBAAgB,4BAA4B;AAElD,KAAI,kBACF,KAAI,gBAAgB,kBAAkB;KAEtC,KAAI,aAAa,mBAAmB,GAAG;AAEzC,KAAI,SAAS,OACX,KAAI,aAAa,kBAAkB,QAAQ,UAAU,SAAS;KAE9D,KAAI,gBAAgB,iBAAiB;AAEvC,KAAI,aAAa,iBAAiB,SAAS;AAC3C,KAAI,WAAW;AAEf,KAAI,QAAQ;AAEZ,KAAI,MAAM,YACR,2CACA,GAAG,GAAG,aAAa,OAAO,IAC3B;AACD,QAAO"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/utils/splitFileContents.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Splits file contents into lines using the same logic as diff parsing.
|
|
4
|
+
* - Preserves trailing newlines on each line
|
|
5
|
+
*
|
|
6
|
+
* @param contents - The raw file contents string
|
|
7
|
+
* @returns Array of lines with newlines preserved
|
|
8
|
+
*/
|
|
9
|
+
declare function splitFileContents(contents: string): string[];
|
|
10
|
+
//#endregion
|
|
11
|
+
export { splitFileContents };
|
|
12
|
+
//# sourceMappingURL=splitFileContents.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"splitFileContents.d.ts","names":["splitFileContents"],"sources":["../../src/utils/splitFileContents.d.ts"],"sourcesContent":["/**\n * Splits file contents into lines using the same logic as diff parsing.\n * - Preserves trailing newlines on each line\n *\n * @param contents - The raw file contents string\n * @returns Array of lines with newlines preserved\n */\nexport declare function splitFileContents(contents: string): string[];\n//# sourceMappingURL=splitFileContents.d.ts.map"],"mappings":";;AAOA;;;;;;iBAAwBA,iBAAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { SPLIT_WITH_NEWLINES } from "../constants.js";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/splitFileContents.ts
|
|
4
|
+
/**
|
|
5
|
+
* Splits file contents into lines using the same logic as diff parsing.
|
|
6
|
+
* - Preserves trailing newlines on each line
|
|
7
|
+
*
|
|
8
|
+
* @param contents - The raw file contents string
|
|
9
|
+
* @returns Array of lines with newlines preserved
|
|
10
|
+
*/
|
|
11
|
+
function splitFileContents(contents) {
|
|
12
|
+
return contents !== "" ? contents.split(SPLIT_WITH_NEWLINES) : [];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
export { splitFileContents };
|
|
17
|
+
//# sourceMappingURL=splitFileContents.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"splitFileContents.js","names":[],"sources":["../../src/utils/splitFileContents.ts"],"sourcesContent":["import { SPLIT_WITH_NEWLINES } from '../constants';\n\n/**\n * Splits file contents into lines using the same logic as diff parsing.\n * - Preserves trailing newlines on each line\n *\n * @param contents - The raw file contents string\n * @returns Array of lines with newlines preserved\n */\nexport function splitFileContents(contents: string): string[] {\n return contents !== '' ? contents.split(SPLIT_WITH_NEWLINES) : [];\n}\n"],"mappings":";;;;;;;;;;AASA,SAAgB,kBAAkB,UAA4B;AAC5D,QAAO,aAAa,KAAK,SAAS,MAAM,oBAAoB,GAAG,EAAE"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/utils/trimPatchContext.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* A utility function to trim out excess context lines from a patch file. It
|
|
4
|
+
* will maintain line numbers, and properly update the hunk context markers, as
|
|
5
|
+
* well as be able to create new hunks where necessary if there's excessive
|
|
6
|
+
* context between changes
|
|
7
|
+
*/
|
|
8
|
+
declare function trimPatchContext(patch: string, contextSize?: number): string;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { trimPatchContext };
|
|
11
|
+
//# sourceMappingURL=trimPatchContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trimPatchContext.d.ts","names":["trimPatchContext"],"sources":["../../src/utils/trimPatchContext.d.ts"],"sourcesContent":["/**\n * A utility function to trim out excess context lines from a patch file. It\n * will maintain line numbers, and properly update the hunk context markers, as\n * well as be able to create new hunks where necessary if there's excessive\n * context between changes\n */\nexport declare function trimPatchContext(patch: string, contextSize?: number): string;\n//# sourceMappingURL=trimPatchContext.d.ts.map"],"mappings":";;AAMA;;;;;iBAAwBA,gBAAAA"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { HUNK_HEADER } from "../constants.js";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/trimPatchContext.ts
|
|
4
|
+
/**
|
|
5
|
+
* A utility function to trim out excess context lines from a patch file. It
|
|
6
|
+
* will maintain line numbers, and properly update the hunk context markers, as
|
|
7
|
+
* well as be able to create new hunks where necessary if there's excessive
|
|
8
|
+
* context between changes
|
|
9
|
+
*/
|
|
10
|
+
function trimPatchContext(patch, contextSize = 10) {
|
|
11
|
+
const lines = [];
|
|
12
|
+
let currentHunk;
|
|
13
|
+
for (const line of patch.split("\n")) {
|
|
14
|
+
const parsedHunkHeader = line.match(HUNK_HEADER);
|
|
15
|
+
if (parsedHunkHeader != null) {
|
|
16
|
+
if (currentHunk != null) {
|
|
17
|
+
if (currentHunk.hunkLines.length > 0) {
|
|
18
|
+
flushContextLines(currentHunk, contextSize);
|
|
19
|
+
flushHunk(currentHunk, lines);
|
|
20
|
+
}
|
|
21
|
+
currentHunk = void 0;
|
|
22
|
+
}
|
|
23
|
+
const additionStart = parseInt(parsedHunkHeader[3]);
|
|
24
|
+
const deletionStart = parseInt(parsedHunkHeader[1]);
|
|
25
|
+
const additionCount = parseInt(parsedHunkHeader[4] ?? "1");
|
|
26
|
+
const deletionCount = parseInt(parsedHunkHeader[2] ?? "1");
|
|
27
|
+
if (isNaN(additionStart) || isNaN(deletionStart) || isNaN(additionCount) || isNaN(deletionCount)) lines.push(line);
|
|
28
|
+
else currentHunk = {
|
|
29
|
+
hunkContextString: parsedHunkHeader[5] ?? "",
|
|
30
|
+
additionStart,
|
|
31
|
+
deletionStart,
|
|
32
|
+
additionCount: 0,
|
|
33
|
+
deletionCount: 0,
|
|
34
|
+
hunkLines: [],
|
|
35
|
+
contextLines: []
|
|
36
|
+
};
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
if (currentHunk == null) {
|
|
40
|
+
lines.push(line);
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
if (line.startsWith(" ")) {
|
|
44
|
+
currentHunk.contextLines.push(line);
|
|
45
|
+
if (currentHunk.hunkLines.length > 0 && currentHunk.contextLines.length === contextSize * 2 + 1) {
|
|
46
|
+
const removedItems = currentHunk.contextLines.slice(contextSize);
|
|
47
|
+
flushContextLines(currentHunk, contextSize);
|
|
48
|
+
const { additionCount: emittedAdditionCount, deletionCount: emittedDeletionCount } = currentHunk;
|
|
49
|
+
flushHunk(currentHunk, lines);
|
|
50
|
+
removedItems.shift();
|
|
51
|
+
currentHunk = {
|
|
52
|
+
hunkContextString: "",
|
|
53
|
+
additionStart: currentHunk.additionStart + emittedAdditionCount + 1,
|
|
54
|
+
deletionStart: currentHunk.deletionStart + emittedDeletionCount + 1,
|
|
55
|
+
deletionCount: 0,
|
|
56
|
+
additionCount: 0,
|
|
57
|
+
contextLines: removedItems,
|
|
58
|
+
hunkLines: []
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
} else if (line !== "") {
|
|
62
|
+
flushContextLines(currentHunk, contextSize);
|
|
63
|
+
currentHunk.hunkLines.push(line);
|
|
64
|
+
if (line.startsWith("+")) currentHunk.additionCount += 1;
|
|
65
|
+
else if (line.startsWith("-")) currentHunk.deletionCount += 1;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (currentHunk != null && currentHunk.hunkLines.length > 0) {
|
|
69
|
+
flushContextLines(currentHunk, contextSize);
|
|
70
|
+
flushHunk(currentHunk, lines);
|
|
71
|
+
}
|
|
72
|
+
return lines.join("\n");
|
|
73
|
+
}
|
|
74
|
+
function flushContextLines(hunk, contextSize) {
|
|
75
|
+
if (hunk.contextLines.length > contextSize) if (hunk.hunkLines.length === 0) {
|
|
76
|
+
const difference = hunk.contextLines.length - contextSize;
|
|
77
|
+
hunk.contextLines.splice(0, difference);
|
|
78
|
+
hunk.additionStart += difference;
|
|
79
|
+
hunk.deletionStart += difference;
|
|
80
|
+
} else hunk.contextLines.length = contextSize;
|
|
81
|
+
if (hunk.contextLines.length > 0) {
|
|
82
|
+
hunk.hunkLines.push(...hunk.contextLines);
|
|
83
|
+
hunk.additionCount += hunk.contextLines.length;
|
|
84
|
+
hunk.deletionCount += hunk.contextLines.length;
|
|
85
|
+
hunk.contextLines.length = 0;
|
|
86
|
+
}
|
|
87
|
+
return hunk;
|
|
88
|
+
}
|
|
89
|
+
function flushHunk(hunk, lines) {
|
|
90
|
+
lines.push(`@@ -${formatHunkRange(hunk.deletionStart, hunk.deletionCount)} +${formatHunkRange(hunk.additionStart, hunk.additionCount)} @@${hunk.hunkContextString !== "" ? ` ${hunk.hunkContextString}` : ""}`);
|
|
91
|
+
lines.push(...hunk.hunkLines);
|
|
92
|
+
}
|
|
93
|
+
function formatHunkRange(start, count) {
|
|
94
|
+
return count === 1 ? `${start}` : `${start},${count}`;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
//#endregion
|
|
98
|
+
export { trimPatchContext };
|
|
99
|
+
//# sourceMappingURL=trimPatchContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trimPatchContext.js","names":["lines: string[]","currentHunk: CurrentHunk | undefined"],"sources":["../../src/utils/trimPatchContext.ts"],"sourcesContent":["import { HUNK_HEADER } from '../constants';\n\ninterface CurrentHunk {\n hunkContextString: string;\n additionStart: number;\n deletionStart: number;\n additionCount: number;\n deletionCount: number;\n hunkLines: string[];\n contextLines: string[];\n}\n\n/**\n * A utility function to trim out excess context lines from a patch file. It\n * will maintain line numbers, and properly update the hunk context markers, as\n * well as be able to create new hunks where necessary if there's excessive\n * context between changes\n */\nexport function trimPatchContext(patch: string, contextSize = 10): string {\n const lines: string[] = [];\n\n let currentHunk: CurrentHunk | undefined;\n for (const line of patch.split('\\n')) {\n const parsedHunkHeader = line.match(HUNK_HEADER);\n // If we've come across a new hunk boundary, then we should close out the\n // current hunk and setup a new one\n if (parsedHunkHeader != null) {\n if (currentHunk != null) {\n if (currentHunk.hunkLines.length > 0) {\n flushContextLines(currentHunk, contextSize);\n flushHunk(currentHunk, lines);\n }\n currentHunk = undefined;\n }\n\n const additionStart = parseInt(parsedHunkHeader[3]);\n const deletionStart = parseInt(parsedHunkHeader[1]);\n const additionCount = parseInt(parsedHunkHeader[4] ?? '1');\n const deletionCount = parseInt(parsedHunkHeader[2] ?? '1');\n\n // If we can't parse valid numbers out of the hunk header\n // lets just skip the hunk altogether\n if (\n isNaN(additionStart) ||\n isNaN(deletionStart) ||\n isNaN(additionCount) ||\n isNaN(deletionCount)\n ) {\n lines.push(line);\n } else {\n currentHunk = {\n hunkContextString: parsedHunkHeader[5] ?? '',\n additionStart,\n deletionStart,\n additionCount: 0,\n deletionCount: 0,\n hunkLines: [],\n contextLines: [],\n };\n }\n continue;\n }\n\n // If we don't have a current hunk, then we should just assume this is\n // general metadata\n if (currentHunk == null) {\n lines.push(line);\n continue;\n }\n\n // If we are dealing with a context line...\n if (line.startsWith(' ')) {\n currentHunk.contextLines.push(line);\n // If we've exceeded double our context window size + 1, that means we\n // should create a new hunk...\n if (\n currentHunk.hunkLines.length > 0 &&\n currentHunk.contextLines.length === contextSize * 2 + 1\n ) {\n const removedItems = currentHunk.contextLines.slice(contextSize);\n flushContextLines(currentHunk, contextSize);\n const {\n additionCount: emittedAdditionCount,\n deletionCount: emittedDeletionCount,\n } = currentHunk;\n flushHunk(currentHunk, lines);\n\n removedItems.shift();\n currentHunk = {\n // NOTE(amadeus): Not sure there's an easy way to manage this context\n // string stuff, so lets just remove it from auto generated hunks\n hunkContextString: '',\n additionStart: currentHunk.additionStart + emittedAdditionCount + 1,\n deletionStart: currentHunk.deletionStart + emittedDeletionCount + 1,\n deletionCount: 0,\n additionCount: 0,\n contextLines: removedItems,\n hunkLines: [],\n };\n }\n } else if (line !== '') {\n flushContextLines(currentHunk, contextSize);\n currentHunk.hunkLines.push(line);\n if (line.startsWith('+')) {\n currentHunk.additionCount += 1;\n } else if (line.startsWith('-')) {\n currentHunk.deletionCount += 1;\n }\n }\n }\n\n if (currentHunk != null && currentHunk.hunkLines.length > 0) {\n flushContextLines(currentHunk, contextSize);\n flushHunk(currentHunk, lines);\n }\n\n return lines.join('\\n');\n}\n\nfunction flushContextLines(hunk: CurrentHunk, contextSize: number) {\n if (hunk.contextLines.length > contextSize) {\n // If this context group is at the beginning of the hunk, truncate from the\n // beginning\n if (hunk.hunkLines.length === 0) {\n const difference = hunk.contextLines.length - contextSize;\n hunk.contextLines.splice(0, difference);\n hunk.additionStart += difference;\n hunk.deletionStart += difference;\n }\n // Otherwise truncate from the end\n else {\n hunk.contextLines.length = contextSize;\n }\n }\n if (hunk.contextLines.length > 0) {\n hunk.hunkLines.push(...hunk.contextLines);\n hunk.additionCount += hunk.contextLines.length;\n hunk.deletionCount += hunk.contextLines.length;\n hunk.contextLines.length = 0;\n }\n return hunk;\n}\n\nfunction flushHunk(hunk: CurrentHunk, lines: string[]) {\n lines.push(\n `@@ -${formatHunkRange(hunk.deletionStart, hunk.deletionCount)} +${formatHunkRange(hunk.additionStart, hunk.additionCount)} @@${hunk.hunkContextString !== '' ? ` ${hunk.hunkContextString}` : ''}`\n );\n lines.push(...hunk.hunkLines);\n}\n\nfunction formatHunkRange(start: number, count: number): string {\n return count === 1 ? `${start}` : `${start},${count}`;\n}\n"],"mappings":";;;;;;;;;AAkBA,SAAgB,iBAAiB,OAAe,cAAc,IAAY;CACxE,MAAMA,QAAkB,EAAE;CAE1B,IAAIC;AACJ,MAAK,MAAM,QAAQ,MAAM,MAAM,KAAK,EAAE;EACpC,MAAM,mBAAmB,KAAK,MAAM,YAAY;AAGhD,MAAI,oBAAoB,MAAM;AAC5B,OAAI,eAAe,MAAM;AACvB,QAAI,YAAY,UAAU,SAAS,GAAG;AACpC,uBAAkB,aAAa,YAAY;AAC3C,eAAU,aAAa,MAAM;;AAE/B,kBAAc;;GAGhB,MAAM,gBAAgB,SAAS,iBAAiB,GAAG;GACnD,MAAM,gBAAgB,SAAS,iBAAiB,GAAG;GACnD,MAAM,gBAAgB,SAAS,iBAAiB,MAAM,IAAI;GAC1D,MAAM,gBAAgB,SAAS,iBAAiB,MAAM,IAAI;AAI1D,OACE,MAAM,cAAc,IACpB,MAAM,cAAc,IACpB,MAAM,cAAc,IACpB,MAAM,cAAc,CAEpB,OAAM,KAAK,KAAK;OAEhB,eAAc;IACZ,mBAAmB,iBAAiB,MAAM;IAC1C;IACA;IACA,eAAe;IACf,eAAe;IACf,WAAW,EAAE;IAC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AACxC,OAAK,aAAa,SAAS;;AAE7B,QAAO;;AAGT,SAAS,UAAU,MAAmB,OAAiB;AACrD,OAAM,KACJ,OAAO,gBAAgB,KAAK,eAAe,KAAK,cAAc,CAAC,IAAI,gBAAgB,KAAK,eAAe,KAAK,cAAc,CAAC,KAAK,KAAK,sBAAsB,KAAK,IAAI,KAAK,sBAAsB,KAChM;AACD,OAAM,KAAK,GAAG,KAAK,UAAU;;AAG/B,SAAS,gBAAgB,OAAe,OAAuB;AAC7D,QAAO,UAAU,IAAI,GAAG,UAAU,GAAG,MAAM,GAAG"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FileContents, FileDiffMetadata, RenderDiffOptions, RenderDiffResult, RenderFileOptions, RenderFileResult, SupportedLanguages, ThemedDiffResult, ThemedFileResult } from "../types.js";
|
|
1
|
+
import { FileContents, FileDiffMetadata, HunkExpansionRegion, RenderDiffOptions, RenderDiffResult, RenderFileOptions, RenderFileResult, SupportedLanguages, ThemedDiffResult, ThemedFileResult } from "../types.js";
|
|
2
2
|
import { DiffRendererInstance, FileRendererInstance, WorkerInitializationRenderOptions, WorkerPoolOptions, WorkerRenderingOptions, WorkerStats } from "./types.js";
|
|
3
3
|
import LRUMapPkg from "lru_map";
|
|
4
4
|
|
|
@@ -22,8 +22,10 @@ declare class WorkerPoolManager {
|
|
|
22
22
|
private themeSubscribers;
|
|
23
23
|
private workersFailed;
|
|
24
24
|
private instanceRequestMap;
|
|
25
|
+
private statSubscribers;
|
|
25
26
|
private fileCache;
|
|
26
27
|
private diffCache;
|
|
28
|
+
private _queuedBroadcast;
|
|
27
29
|
constructor(options: WorkerPoolOptions, {
|
|
28
30
|
langs,
|
|
29
31
|
theme,
|
|
@@ -46,23 +48,28 @@ declare class WorkerPoolManager {
|
|
|
46
48
|
private setRenderOptionsOnWorkers;
|
|
47
49
|
subscribeToThemeChanges(instance: ThemeSubscriber): () => void;
|
|
48
50
|
unsubscribeToThemeChanges(instance: ThemeSubscriber): void;
|
|
51
|
+
subscribeToStatChanges(callback: (stats: WorkerStats) => unknown): () => void;
|
|
52
|
+
private queueBroadcastStateChanges;
|
|
53
|
+
private _broadcastStateChanges;
|
|
54
|
+
cleanUpPendingTasks(instance: FileRendererInstance | DiffRendererInstance): void;
|
|
49
55
|
isInitialized(): boolean;
|
|
50
56
|
initialize(languages?: SupportedLanguages[]): Promise<void>;
|
|
51
57
|
private initializeWorkers;
|
|
52
58
|
private drainQueue;
|
|
53
59
|
highlightFileAST(instance: FileRendererInstance, file: FileContents): void;
|
|
54
|
-
getPlainFileAST(file: FileContents): ThemedFileResult | undefined;
|
|
60
|
+
getPlainFileAST(file: FileContents, startingLine: number, totalLines: number, lines?: string[]): ThemedFileResult | undefined;
|
|
55
61
|
highlightDiffAST(instance: DiffRendererInstance, diff: FileDiffMetadata): void;
|
|
56
|
-
getPlainDiffAST(diff: FileDiffMetadata): ThemedDiffResult | undefined;
|
|
62
|
+
getPlainDiffAST(diff: FileDiffMetadata, startingLine: number, totalLines: number, expandedHunks?: Map<number, HunkExpansionRegion> | true, collapsedContextThreshold?: number): ThemedDiffResult | undefined;
|
|
57
63
|
terminate(): void;
|
|
58
64
|
private terminateWorkers;
|
|
59
65
|
getStats(): WorkerStats;
|
|
60
66
|
private submitTask;
|
|
61
|
-
private submitTask;
|
|
62
67
|
private resolveLanguagesAndExecuteTask;
|
|
63
68
|
private handleWorkerMessage;
|
|
64
69
|
private _queuedDrain;
|
|
65
70
|
private queueDrain;
|
|
71
|
+
private assignWorkerToTask;
|
|
72
|
+
private clearWorkerTask;
|
|
66
73
|
private executeTask;
|
|
67
74
|
private getAvailableWorker;
|
|
68
75
|
private generateRequestId;
|