@pierre/diffs 1.5.2 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -3
- package/dist/components/CodeView.d.ts +3 -2
- package/dist/components/CodeView.d.ts.map +1 -1
- package/dist/components/CodeView.js +24 -19
- package/dist/components/CodeView.js.map +1 -1
- package/dist/components/File.d.ts +31 -9
- package/dist/components/File.d.ts.map +1 -1
- package/dist/components/File.js +176 -90
- package/dist/components/File.js.map +1 -1
- package/dist/components/FileDiff.d.ts +32 -9
- package/dist/components/FileDiff.d.ts.map +1 -1
- package/dist/components/FileDiff.js +225 -131
- package/dist/components/FileDiff.js.map +1 -1
- package/dist/components/FileStream.d.ts +6 -4
- package/dist/components/FileStream.d.ts.map +1 -1
- package/dist/components/FileStream.js +49 -36
- package/dist/components/FileStream.js.map +1 -1
- package/dist/components/UnresolvedFile.d.ts +14 -4
- package/dist/components/UnresolvedFile.d.ts.map +1 -1
- package/dist/components/UnresolvedFile.js +35 -16
- package/dist/components/UnresolvedFile.js.map +1 -1
- package/dist/components/VirtualizedFile.d.ts +3 -2
- package/dist/components/VirtualizedFile.d.ts.map +1 -1
- package/dist/components/VirtualizedFile.js +28 -20
- package/dist/components/VirtualizedFile.js.map +1 -1
- package/dist/components/VirtualizedFileDiff.d.ts +3 -2
- package/dist/components/VirtualizedFileDiff.d.ts.map +1 -1
- package/dist/components/VirtualizedFileDiff.js +31 -24
- package/dist/components/VirtualizedFileDiff.js.map +1 -1
- package/dist/constants.d.ts +4 -2
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +3 -1
- package/dist/constants.js.map +1 -1
- package/dist/editor/editor.d.ts +2 -1
- package/dist/editor/editor.d.ts.map +1 -1
- package/dist/editor/editor.js +5 -1
- package/dist/editor/editor.js.map +1 -1
- package/dist/editor/platform.d.ts +1 -1
- package/dist/editor/platform.js +5 -4
- package/dist/editor/platform.js.map +1 -1
- package/dist/editor/selection.d.ts +2 -2
- package/dist/editor/selection.d.ts.map +1 -1
- package/dist/editor/selection.js +31 -6
- package/dist/editor/selection.js.map +1 -1
- package/dist/editor/tokenizer.d.ts +6 -4
- package/dist/editor/tokenizer.d.ts.map +1 -1
- package/dist/editor/tokenizer.js +25 -470
- package/dist/editor/tokenizer.js.map +1 -1
- package/dist/highlighter/DiffsEditorTokenizer.d.ts +16 -0
- package/dist/highlighter/DiffsEditorTokenizer.d.ts.map +1 -0
- package/dist/highlighter/DiffsEditorTokenizer.js +0 -0
- package/dist/highlighter/DiffsHighlighter.d.ts +41 -0
- package/dist/highlighter/DiffsHighlighter.d.ts.map +1 -0
- package/dist/highlighter/DiffsHighlighter.js +39 -0
- package/dist/highlighter/DiffsHighlighter.js.map +1 -0
- package/dist/highlighter/backends/highlights.d.ts +26 -0
- package/dist/highlighter/backends/highlights.d.ts.map +1 -0
- package/dist/highlighter/backends/highlights.js +71 -0
- package/dist/highlighter/backends/highlights.js.map +1 -0
- package/dist/highlighter/backends/shiki.d.ts +27 -0
- package/dist/highlighter/backends/shiki.d.ts.map +1 -0
- package/dist/highlighter/backends/shiki.js +107 -0
- package/dist/highlighter/backends/shiki.js.map +1 -0
- package/dist/highlighter/highlighterType.d.ts +13 -0
- package/dist/highlighter/highlighterType.d.ts.map +1 -0
- package/dist/highlighter/highlighterType.js +32 -0
- package/dist/highlighter/highlighterType.js.map +1 -0
- package/dist/highlighter/highlights-editor.d.ts +24 -0
- package/dist/highlighter/highlights-editor.d.ts.map +1 -0
- package/dist/highlighter/highlights-editor.js +166 -0
- package/dist/highlighter/highlights-editor.js.map +1 -0
- package/dist/highlighter/highlights-stream.d.ts +20 -0
- package/dist/highlighter/highlights-stream.d.ts.map +1 -0
- package/dist/highlighter/highlights-stream.js +93 -0
- package/dist/highlighter/highlights-stream.js.map +1 -0
- package/dist/highlighter/languages/areLanguagesAttached.d.ts +2 -1
- package/dist/highlighter/languages/areLanguagesAttached.d.ts.map +1 -1
- package/dist/highlighter/languages/areLanguagesAttached.js +4 -6
- package/dist/highlighter/languages/areLanguagesAttached.js.map +1 -1
- package/dist/highlighter/languages/attachResolvedLanguages.d.ts +6 -1
- package/dist/highlighter/languages/attachResolvedLanguages.d.ts.map +1 -1
- package/dist/highlighter/languages/attachResolvedLanguages.js +6 -11
- package/dist/highlighter/languages/attachResolvedLanguages.js.map +1 -1
- package/dist/highlighter/languages/constants.d.ts +1 -1
- package/dist/highlighter/languages/getResolvedLanguages.d.ts +1 -1
- package/dist/highlighter/languages/getResolvedOrResolveLanguage.d.ts +1 -1
- 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 +19 -16
- package/dist/highlighter/languages/resolveLanguage.js.map +1 -1
- package/dist/highlighter/languages/resolveLanguages.d.ts +1 -1
- package/dist/highlighter/shared_highlighter.d.ts +24 -9
- package/dist/highlighter/shared_highlighter.d.ts.map +1 -1
- package/dist/highlighter/shared_highlighter.js +59 -47
- package/dist/highlighter/shared_highlighter.js.map +1 -1
- package/dist/highlighter/shiki-editor.d.ts +25 -0
- package/dist/highlighter/shiki-editor.d.ts.map +1 -0
- package/dist/highlighter/shiki-editor.js +483 -0
- package/dist/highlighter/shiki-editor.js.map +1 -0
- package/dist/highlighter/shiki-stream.d.ts +20 -0
- package/dist/highlighter/shiki-stream.d.ts.map +1 -0
- package/dist/highlighter/shiki-stream.js +60 -0
- package/dist/highlighter/shiki-stream.js.map +1 -0
- package/dist/highlighter/stream-tokenizer.d.ts +40 -0
- package/dist/highlighter/stream-tokenizer.d.ts.map +1 -0
- package/dist/highlighter/stream-tokenizer.js +70 -0
- package/dist/highlighter/stream-tokenizer.js.map +1 -0
- package/dist/highlighter/themes/areThemesAttached.d.ts +3 -2
- package/dist/highlighter/themes/areThemesAttached.d.ts.map +1 -1
- package/dist/highlighter/themes/areThemesAttached.js +5 -4
- package/dist/highlighter/themes/areThemesAttached.js.map +1 -1
- package/dist/highlighter/themes/attachResolvedThemes.d.ts +5 -2
- package/dist/highlighter/themes/attachResolvedThemes.d.ts.map +1 -1
- package/dist/highlighter/themes/attachResolvedThemes.js +4 -16
- package/dist/highlighter/themes/attachResolvedThemes.js.map +1 -1
- package/dist/highlighter/themes/cleanUpResolvedThemes.d.ts +3 -1
- package/dist/highlighter/themes/cleanUpResolvedThemes.d.ts.map +1 -1
- package/dist/highlighter/themes/cleanUpResolvedThemes.js +8 -5
- package/dist/highlighter/themes/cleanUpResolvedThemes.js.map +1 -1
- package/dist/highlighter/themes/createCSSVariablesTheme.d.ts +7 -0
- package/dist/highlighter/themes/createCSSVariablesTheme.d.ts.map +1 -0
- package/dist/highlighter/themes/createCSSVariablesTheme.js +89 -0
- package/dist/highlighter/themes/createCSSVariablesTheme.js.map +1 -0
- package/dist/highlighter/themes/createCachedLoader.d.ts +5 -0
- package/dist/highlighter/themes/createCachedLoader.d.ts.map +1 -0
- package/dist/highlighter/themes/createCachedLoader.js +15 -0
- package/dist/highlighter/themes/createCachedLoader.js.map +1 -0
- package/dist/highlighter/themes/getResolvedOrResolveTheme.d.ts +3 -2
- package/dist/highlighter/themes/getResolvedOrResolveTheme.d.ts.map +1 -1
- package/dist/highlighter/themes/getResolvedOrResolveTheme.js +4 -4
- package/dist/highlighter/themes/getResolvedOrResolveTheme.js.map +1 -1
- package/dist/highlighter/themes/getResolvedThemes.d.ts +3 -2
- package/dist/highlighter/themes/getResolvedThemes.d.ts.map +1 -1
- package/dist/highlighter/themes/getResolvedThemes.js +4 -3
- package/dist/highlighter/themes/getResolvedThemes.js.map +1 -1
- package/dist/highlighter/themes/hasResolvedThemes.d.ts +2 -2
- package/dist/highlighter/themes/hasResolvedThemes.d.ts.map +1 -1
- package/dist/highlighter/themes/hasResolvedThemes.js +4 -3
- package/dist/highlighter/themes/hasResolvedThemes.js.map +1 -1
- package/dist/highlighter/themes/registerCustomCSSVariableTheme.d.ts.map +1 -1
- package/dist/highlighter/themes/registerCustomCSSVariableTheme.js +3 -3
- package/dist/highlighter/themes/registerCustomCSSVariableTheme.js.map +1 -1
- package/dist/highlighter/themes/registerCustomTheme.d.ts +9 -4
- package/dist/highlighter/themes/registerCustomTheme.d.ts.map +1 -1
- package/dist/highlighter/themes/registerCustomTheme.js +8 -16
- package/dist/highlighter/themes/registerCustomTheme.js.map +1 -1
- package/dist/highlighter/themes/resolveTheme.d.ts +3 -2
- package/dist/highlighter/themes/resolveTheme.d.ts.map +1 -1
- package/dist/highlighter/themes/resolveTheme.js +4 -7
- package/dist/highlighter/themes/resolveTheme.js.map +1 -1
- package/dist/highlighter/themes/resolveThemes.d.ts +3 -2
- package/dist/highlighter/themes/resolveThemes.d.ts.map +1 -1
- package/dist/highlighter/themes/resolveThemes.js +4 -7
- package/dist/highlighter/themes/resolveThemes.js.map +1 -1
- package/dist/highlighter/themes/themeResolver.d.ts +10 -4
- package/dist/highlighter/themes/themeResolver.d.ts.map +1 -1
- package/dist/highlighter/themes/themeResolver.js +141 -2
- package/dist/highlighter/themes/themeResolver.js.map +1 -1
- package/dist/highlighter/themes/types.d.ts +23 -0
- package/dist/highlighter/themes/types.d.ts.map +1 -0
- package/dist/highlighter/themes/types.js +0 -0
- package/dist/highlighter/tokenizer-types.d.ts +35 -0
- package/dist/highlighter/tokenizer-types.d.ts.map +1 -0
- package/dist/highlighter/tokenizer-types.js +0 -0
- package/dist/highlighter/types.d.ts +55 -0
- package/dist/highlighter/types.d.ts.map +1 -0
- package/dist/highlighter/types.js +0 -0
- package/dist/index.d.ts +22 -13
- package/dist/index.js +21 -18
- package/dist/managers/InteractionManager.d.ts.map +1 -1
- package/dist/managers/InteractionManager.js +2 -2
- package/dist/managers/InteractionManager.js.map +1 -1
- package/dist/node_modules/.pnpm/@types_hast@3.0.4/node_modules/@types/hast/index.d.ts +9 -1
- package/dist/node_modules/.pnpm/@types_hast@3.0.4/node_modules/@types/hast/index.d.ts.map +1 -1
- package/dist/react/CodeView.d.ts +4 -3
- package/dist/react/CodeView.d.ts.map +1 -1
- package/dist/react/CodeView.js +47 -38
- package/dist/react/CodeView.js.map +1 -1
- package/dist/react/File.js +3 -3
- package/dist/react/File.js.map +1 -1
- package/dist/react/FileDiff.js +3 -3
- package/dist/react/FileDiff.js.map +1 -1
- package/dist/react/MultiFileDiff.js +2 -2
- package/dist/react/MultiFileDiff.js.map +1 -1
- package/dist/react/PatchDiff.js +3 -3
- package/dist/react/PatchDiff.js.map +1 -1
- package/dist/react/UnresolvedFile.js +2 -2
- package/dist/react/UnresolvedFile.js.map +1 -1
- package/dist/react/index.d.ts +9 -4
- package/dist/react/types.d.ts +4 -2
- package/dist/react/types.d.ts.map +1 -1
- package/dist/react/utils/renderDiffChildren.js +1 -1
- package/dist/react/utils/renderDiffChildren.js.map +1 -1
- package/dist/react/utils/renderFileChildren.js +1 -1
- package/dist/react/utils/renderFileChildren.js.map +1 -1
- package/dist/react/utils/useFileDiffInstance.d.ts +1 -0
- package/dist/react/utils/useFileDiffInstance.d.ts.map +1 -1
- package/dist/react/utils/useFileDiffInstance.js +29 -24
- package/dist/react/utils/useFileDiffInstance.js.map +1 -1
- package/dist/react/utils/useFileInstance.d.ts +2 -0
- package/dist/react/utils/useFileInstance.d.ts.map +1 -1
- package/dist/react/utils/useFileInstance.js +38 -28
- package/dist/react/utils/useFileInstance.js.map +1 -1
- package/dist/react/utils/useForceUpdate.d.ts +5 -0
- package/dist/react/utils/useForceUpdate.d.ts.map +1 -0
- package/dist/react/utils/useForceUpdate.js +27 -0
- package/dist/react/utils/useForceUpdate.js.map +1 -0
- package/dist/react/utils/useNextRenderData.d.ts +9 -0
- package/dist/react/utils/useNextRenderData.d.ts.map +1 -0
- package/dist/react/utils/useNextRenderData.js +9 -0
- package/dist/react/utils/useNextRenderData.js.map +1 -0
- package/dist/react/utils/useUnresolvedFileInstance.d.ts +1 -0
- package/dist/react/utils/useUnresolvedFileInstance.d.ts.map +1 -1
- package/dist/react/utils/useUnresolvedFileInstance.js +26 -11
- package/dist/react/utils/useUnresolvedFileInstance.js.map +1 -1
- package/dist/renderers/DiffHunksRenderer.d.ts +4 -2
- package/dist/renderers/DiffHunksRenderer.d.ts.map +1 -1
- package/dist/renderers/DiffHunksRenderer.js +82 -43
- package/dist/renderers/DiffHunksRenderer.js.map +1 -1
- package/dist/renderers/FileRenderer.d.ts +6 -2
- package/dist/renderers/FileRenderer.d.ts.map +1 -1
- package/dist/renderers/FileRenderer.js +77 -43
- package/dist/renderers/FileRenderer.js.map +1 -1
- package/dist/renderers/UnresolvedFileHunksRenderer.d.ts.map +1 -1
- package/dist/renderers/UnresolvedFileHunksRenderer.js +1 -1
- package/dist/renderers/UnresolvedFileHunksRenderer.js.map +1 -1
- package/dist/shiki-stream/index.d.ts +3 -3
- package/dist/shiki-stream/index.js +1 -2
- package/dist/shiki-stream/stream.d.ts +4 -4
- package/dist/shiki-stream/stream.d.ts.map +1 -1
- package/dist/shiki-stream/stream.js +20 -9
- package/dist/shiki-stream/stream.js.map +1 -1
- package/dist/shiki-stream/types.d.ts +7 -38
- package/dist/shiki-stream/types.d.ts.map +1 -1
- package/dist/ssr/index.d.ts +7 -2
- package/dist/ssr/renderHTML.js +2 -2
- package/dist/ssr/renderHTML.js.map +1 -1
- package/dist/style.js +1 -1
- package/dist/style.js.map +1 -1
- package/dist/types.d.ts +20 -11
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/canUseWASM.d.ts +13 -0
- package/dist/utils/canUseWASM.d.ts.map +1 -0
- package/dist/utils/canUseWASM.js +59 -0
- package/dist/utils/canUseWASM.js.map +1 -0
- package/dist/utils/createSpanNodeFromToken.d.ts +3 -2
- package/dist/utils/createSpanNodeFromToken.d.ts.map +1 -1
- package/dist/utils/createSpanNodeFromToken.js +4 -5
- package/dist/utils/createSpanNodeFromToken.js.map +1 -1
- package/dist/utils/cssWrappers.d.ts.map +1 -1
- package/dist/utils/cssWrappers.js +12 -0
- package/dist/utils/cssWrappers.js.map +1 -1
- package/dist/utils/getCodeViewItemRenderData.d.ts +10 -0
- package/dist/utils/getCodeViewItemRenderData.d.ts.map +1 -0
- package/dist/utils/getCodeViewItemRenderData.js +19 -0
- package/dist/utils/getCodeViewItemRenderData.js.map +1 -0
- package/dist/utils/getHighlighterOptions.d.ts.map +1 -1
- package/dist/utils/getHighlighterOptions.js +3 -2
- package/dist/utils/getHighlighterOptions.js.map +1 -1
- package/dist/utils/getHighlighterThemeStyles.d.ts +2 -1
- package/dist/utils/getHighlighterThemeStyles.d.ts.map +1 -1
- package/dist/utils/getHighlighterThemeStyles.js +13 -3
- package/dist/utils/getHighlighterThemeStyles.js.map +1 -1
- package/dist/utils/getTokenOptions.d.ts +7 -0
- package/dist/utils/getTokenOptions.d.ts.map +1 -0
- package/dist/utils/getTokenOptions.js +16 -0
- package/dist/utils/getTokenOptions.js.map +1 -0
- package/dist/utils/hastToHtml.d.ts +10 -0
- package/dist/utils/hastToHtml.d.ts.map +1 -0
- package/dist/utils/hastToHtml.js +125 -0
- package/dist/utils/hastToHtml.js.map +1 -0
- package/dist/utils/hydratePartialDiff.js +4 -0
- package/dist/utils/hydratePartialDiff.js.map +1 -1
- package/dist/utils/parseDiffDecorations.d.ts +2 -1
- package/dist/utils/parseDiffDecorations.d.ts.map +1 -1
- package/dist/utils/parseMergeConflictDiffFromFile.d.ts.map +1 -1
- package/dist/utils/parseMergeConflictDiffFromFile.js +2 -0
- package/dist/utils/parseMergeConflictDiffFromFile.js.map +1 -1
- package/dist/utils/parsePatchFiles.d.ts.map +1 -1
- package/dist/utils/parsePatchFiles.js +24 -4
- package/dist/utils/parsePatchFiles.js.map +1 -1
- package/dist/utils/renderDiffWithHighlighter.d.ts +3 -2
- package/dist/utils/renderDiffWithHighlighter.d.ts.map +1 -1
- package/dist/utils/renderDiffWithHighlighter.js +33 -48
- package/dist/utils/renderDiffWithHighlighter.js.map +1 -1
- package/dist/utils/renderFileWithHighlighter.d.ts +3 -2
- package/dist/utils/renderFileWithHighlighter.d.ts.map +1 -1
- package/dist/utils/renderFileWithHighlighter.js +10 -26
- package/dist/utils/renderFileWithHighlighter.js.map +1 -1
- package/dist/utils/renderTokenLines.d.ts +22 -0
- package/dist/utils/renderTokenLines.d.ts.map +1 -0
- package/dist/utils/renderTokenLines.js +250 -0
- package/dist/utils/renderTokenLines.js.map +1 -0
- package/dist/utils/resolvePreferredHighlighter.d.ts +13 -0
- package/dist/utils/resolvePreferredHighlighter.d.ts.map +1 -0
- package/dist/utils/resolvePreferredHighlighter.js +11 -0
- package/dist/utils/resolvePreferredHighlighter.js.map +1 -0
- package/dist/utils/resolveRegion.js +20 -10
- package/dist/utils/resolveRegion.js.map +1 -1
- package/dist/utils/setDeferredArrayItem.d.ts +5 -0
- package/dist/utils/setDeferredArrayItem.d.ts.map +1 -0
- package/dist/utils/setDeferredArrayItem.js +39 -0
- package/dist/utils/setDeferredArrayItem.js.map +1 -0
- package/dist/utils/tokenStyle.d.ts +11 -0
- package/dist/utils/tokenStyle.d.ts.map +1 -0
- package/dist/utils/tokenStyle.js +32 -0
- package/dist/utils/tokenStyle.js.map +1 -0
- package/dist/utils/tokensToHtml.d.ts +11 -0
- package/dist/utils/tokensToHtml.d.ts.map +1 -0
- package/dist/utils/tokensToHtml.js +48 -0
- package/dist/utils/tokensToHtml.js.map +1 -0
- package/dist/utils/updateDiffHunks.d.ts +2 -2
- package/dist/utils/updateDiffHunks.d.ts.map +1 -1
- package/dist/utils/updateDiffHunks.js +7 -3
- package/dist/utils/updateDiffHunks.js.map +1 -1
- package/dist/utils/wrapTokenFragments.js.map +1 -1
- package/dist/worker/WorkerPoolManager.d.ts +14 -2
- package/dist/worker/WorkerPoolManager.d.ts.map +1 -1
- package/dist/worker/WorkerPoolManager.js +155 -67
- package/dist/worker/WorkerPoolManager.js.map +1 -1
- package/dist/worker/hastLinesTransport.d.ts +14 -0
- package/dist/worker/hastLinesTransport.d.ts.map +1 -0
- package/dist/worker/hastLinesTransport.js +156 -0
- package/dist/worker/hastLinesTransport.js.map +1 -0
- package/dist/worker/highlights-CpZm9DAR.js +317 -0
- package/dist/worker/highlights-CpZm9DAR.js.map +1 -0
- package/dist/worker/index.d.ts +1 -1
- package/dist/worker/shiki-Ci4cdHsM.js +697 -0
- package/dist/worker/shiki-Ci4cdHsM.js.map +1 -0
- package/dist/worker/stream-tokenizer-DK9xp5M5.js +427 -0
- package/dist/worker/stream-tokenizer-DK9xp5M5.js.map +1 -0
- package/dist/worker/types.d.ts +16 -3
- package/dist/worker/types.d.ts.map +1 -1
- package/dist/worker/worker-portable.js +41 -13337
- package/dist/worker/worker-portable.js.map +1 -1
- package/dist/worker/worker.js +681 -349
- package/dist/worker/worker.js.map +1 -1
- package/dist/worker/workerMessage.d.ts +24 -0
- package/dist/worker/workerMessage.d.ts.map +1 -0
- package/dist/worker/workerMessage.js +0 -0
- package/package.json +5 -3
- package/dist/highlighter/themes/constants.d.ts +0 -5
- package/dist/highlighter/themes/constants.d.ts.map +0 -1
- package/dist/highlighter/themes/constants.js +0 -6
- package/dist/highlighter/themes/constants.js.map +0 -1
- package/dist/highlighter/themes/themeResolution.d.ts +0 -7
- package/dist/highlighter/themes/themeResolution.d.ts.map +0 -1
- package/dist/highlighter/themes/themeResolution.js +0 -21
- package/dist/highlighter/themes/themeResolution.js.map +0 -1
- package/dist/shiki-stream/tokenizer.d.ts +0 -23
- package/dist/shiki-stream/tokenizer.d.ts.map +0 -1
- package/dist/shiki-stream/tokenizer.js +0 -72
- package/dist/shiki-stream/tokenizer.js.map +0 -1
- package/dist/utils/createTransformerWithState.d.ts +0 -12
- package/dist/utils/createTransformerWithState.d.ts.map +0 -1
- package/dist/utils/createTransformerWithState.js +0 -89
- package/dist/utils/createTransformerWithState.js.map +0 -1
- package/dist/worker/wasm-B9ZqxnKj.js +0 -8
- package/dist/worker/wasm-B9ZqxnKj.js.map +0 -1
|
@@ -6,7 +6,7 @@ function getHighlighterThemeStyles({ theme = DEFAULT_THEMES, highlighter, prefix
|
|
|
6
6
|
let styles = "";
|
|
7
7
|
if (typeof theme === "string") {
|
|
8
8
|
const themeData = highlighter.getTheme(theme);
|
|
9
|
-
const normalized =
|
|
9
|
+
const normalized = getThemeColors(themeData, highlighter);
|
|
10
10
|
styles += `color:${normalized.fg};`;
|
|
11
11
|
styles += `background-color:${normalized.bg};`;
|
|
12
12
|
styles += `${formatCSSVariablePrefix("global")}fg:${normalized.fg};`;
|
|
@@ -14,18 +14,28 @@ function getHighlighterThemeStyles({ theme = DEFAULT_THEMES, highlighter, prefix
|
|
|
14
14
|
styles += getGitVariables(themeData, prefix);
|
|
15
15
|
} else {
|
|
16
16
|
let themeData = highlighter.getTheme(theme.dark);
|
|
17
|
-
let normalized =
|
|
17
|
+
let normalized = getThemeColors(themeData, highlighter);
|
|
18
18
|
styles += `${formatCSSVariablePrefix("global")}dark:${normalized.fg};`;
|
|
19
19
|
styles += `${formatCSSVariablePrefix("global")}dark-bg:${normalized.bg};`;
|
|
20
20
|
styles += getGitVariables(themeData, "dark");
|
|
21
21
|
themeData = highlighter.getTheme(theme.light);
|
|
22
|
-
normalized =
|
|
22
|
+
normalized = getThemeColors(themeData, highlighter);
|
|
23
23
|
styles += `${formatCSSVariablePrefix("global")}light:${normalized.fg};`;
|
|
24
24
|
styles += `${formatCSSVariablePrefix("global")}light-bg:${normalized.bg};`;
|
|
25
25
|
styles += getGitVariables(themeData, "light");
|
|
26
26
|
}
|
|
27
27
|
return styles;
|
|
28
28
|
}
|
|
29
|
+
function getThemeColors(theme, highlighter) {
|
|
30
|
+
if (highlighter.name === "highlights" && theme.zed?.cssVariables === true) {
|
|
31
|
+
const prefix = formatCSSVariablePrefix("token");
|
|
32
|
+
return {
|
|
33
|
+
fg: `var(${prefix}foreground)`,
|
|
34
|
+
bg: `var(${prefix}background)`
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
return normalizeThemeColors(theme);
|
|
38
|
+
}
|
|
29
39
|
function getGitVariables(themeData, modePrefix) {
|
|
30
40
|
modePrefix = modePrefix != null ? `${modePrefix}-` : "";
|
|
31
41
|
let styles = "";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getHighlighterThemeStyles.js","names":[],"sources":["../../src/utils/getHighlighterThemeStyles.ts"],"sourcesContent":["import { normalizeThemeColors } from '@pierre/theming/color';\n\nimport { DEFAULT_THEMES } from '../constants';\nimport type {\n DiffsHighlighter,\n
|
|
1
|
+
{"version":3,"file":"getHighlighterThemeStyles.js","names":[],"sources":["../../src/utils/getHighlighterThemeStyles.ts"],"sourcesContent":["import { normalizeThemeColors } from '@pierre/theming/color';\n\nimport { DEFAULT_THEMES } from '../constants';\nimport type {\n DiffsHighlighter,\n DiffsTheme,\n DiffsThemeNames,\n ThemesType,\n} from '../types';\nimport { formatCSSVariablePrefix } from './formatCSSVariablePrefix';\n\ninterface GetHighlighterThemeStylesProps {\n theme?: DiffsThemeNames | ThemesType;\n highlighter: DiffsHighlighter;\n prefix?: string;\n}\n\nexport function getHighlighterThemeStyles({\n theme = DEFAULT_THEMES,\n highlighter,\n prefix,\n}: GetHighlighterThemeStylesProps): string {\n let styles = '';\n if (typeof theme === 'string') {\n const themeData = highlighter.getTheme(theme);\n const normalized = getThemeColors(themeData, highlighter);\n styles += `color:${normalized.fg};`;\n styles += `background-color:${normalized.bg};`;\n styles += `${formatCSSVariablePrefix('global')}fg:${normalized.fg};`;\n styles += `${formatCSSVariablePrefix('global')}bg:${normalized.bg};`;\n styles += getGitVariables(themeData, prefix);\n } else {\n let themeData = highlighter.getTheme(theme.dark);\n let normalized = getThemeColors(themeData, highlighter);\n styles += `${formatCSSVariablePrefix('global')}dark:${normalized.fg};`;\n styles += `${formatCSSVariablePrefix('global')}dark-bg:${normalized.bg};`;\n styles += getGitVariables(themeData, 'dark');\n\n themeData = highlighter.getTheme(theme.light);\n normalized = getThemeColors(themeData, highlighter);\n styles += `${formatCSSVariablePrefix('global')}light:${normalized.fg};`;\n styles += `${formatCSSVariablePrefix('global')}light-bg:${normalized.bg};`;\n styles += getGitVariables(themeData, 'light');\n }\n return styles;\n}\n\n// cssVariables: true must use the same prefix for backgrounds and tokens.\n// Object palettes already include their configured prefix and defaults.\nfunction getThemeColors(theme: DiffsTheme, highlighter: DiffsHighlighter) {\n if (highlighter.name === 'highlights' && theme.zed?.cssVariables === true) {\n const prefix = formatCSSVariablePrefix('token');\n return { fg: `var(${prefix}foreground)`, bg: `var(${prefix}background)` };\n }\n return normalizeThemeColors(theme);\n}\n\n// Keep the gitDecoration → terminal.ansi fallback; adding editorGutter colors\n// here would change diff backgrounds for existing themes.\nfunction getGitVariables(themeData: DiffsTheme, modePrefix?: string) {\n modePrefix = modePrefix != null ? `${modePrefix}-` : '';\n let styles = '';\n const additionGreen =\n themeData.colors?.['gitDecoration.addedResourceForeground'] ??\n themeData.colors?.['terminal.ansiGreen'];\n if (additionGreen != null) {\n styles += `${formatCSSVariablePrefix('global')}${modePrefix}addition-color:${additionGreen};`;\n }\n const deletionRed =\n themeData.colors?.['gitDecoration.deletedResourceForeground'] ??\n themeData.colors?.['terminal.ansiRed'];\n if (deletionRed != null) {\n styles += `${formatCSSVariablePrefix('global')}${modePrefix}deletion-color:${deletionRed};`;\n }\n const modifiedBlue =\n themeData.colors?.['gitDecoration.modifiedResourceForeground'] ??\n themeData.colors?.['terminal.ansiBlue'];\n if (modifiedBlue != null) {\n styles += `${formatCSSVariablePrefix('global')}${modePrefix}modified-color:${modifiedBlue};`;\n }\n return styles;\n}\n"],"mappings":";;;;AAiBA,SAAgB,0BAA0B,EACxC,QAAQ,gBACR,aACA,UACyC;CACzC,IAAI,SAAS;CACb,IAAI,OAAO,UAAU,UAAU;EAC7B,MAAM,YAAY,YAAY,SAAS,KAAK;EAC5C,MAAM,aAAa,eAAe,WAAW,WAAW;EACxD,UAAU,SAAS,WAAW,GAAG;EACjC,UAAU,oBAAoB,WAAW,GAAG;EAC5C,UAAU,GAAG,wBAAwB,QAAQ,EAAE,KAAK,WAAW,GAAG;EAClE,UAAU,GAAG,wBAAwB,QAAQ,EAAE,KAAK,WAAW,GAAG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5F,OAAO;AACT"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { CodeToTokensOptions } from "../highlighter/types.js";
|
|
2
|
+
import { DiffsThemeNames, SupportedLanguages, ThemesType } from "../types.js";
|
|
3
|
+
//#region src/utils/getTokenOptions.d.ts
|
|
4
|
+
declare function getTokenOptions(lang: SupportedLanguages, theme: DiffsThemeNames | ThemesType, tokenizeMaxLineLength: number | undefined): CodeToTokensOptions;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { getTokenOptions };
|
|
7
|
+
//# sourceMappingURL=getTokenOptions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getTokenOptions.d.ts","names":[],"sources":["../../src/utils/getTokenOptions.ts"],"mappings":";;;iBAQgB,gBACd,MAAM,oBACN,OAAO,kBAAkB,YACzB,4CACC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { formatCSSVariablePrefix } from "./formatCSSVariablePrefix.js";
|
|
2
|
+
//#region src/utils/getTokenOptions.ts
|
|
3
|
+
function getTokenOptions(lang, theme, tokenizeMaxLineLength) {
|
|
4
|
+
return {
|
|
5
|
+
lang,
|
|
6
|
+
...typeof theme === "string" ? { theme } : { themes: theme },
|
|
7
|
+
defaultColor: false,
|
|
8
|
+
cssVariablePrefix: formatCSSVariablePrefix("token"),
|
|
9
|
+
tokenizeMaxLineLength,
|
|
10
|
+
tokenizeTimeLimit: 0
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
//#endregion
|
|
14
|
+
export { getTokenOptions };
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=getTokenOptions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getTokenOptions.js","names":[],"sources":["../../src/utils/getTokenOptions.ts"],"sourcesContent":["import type {\n CodeToTokensOptions,\n DiffsThemeNames,\n SupportedLanguages,\n ThemesType,\n} from '../types';\nimport { formatCSSVariablePrefix } from './formatCSSVariablePrefix';\n\nexport function getTokenOptions(\n lang: SupportedLanguages,\n theme: DiffsThemeNames | ThemesType,\n tokenizeMaxLineLength: number | undefined\n): CodeToTokensOptions {\n return {\n lang,\n ...(typeof theme === 'string' ? { theme } : { themes: theme }),\n defaultColor: false,\n cssVariablePrefix: formatCSSVariablePrefix('token'),\n tokenizeMaxLineLength,\n // Timed aborts can leave incomplete tokens; limit line length instead.\n tokenizeTimeLimit: 0,\n };\n}\n"],"mappings":";;AAQA,SAAgB,gBACd,MACA,OACA,uBACqB;CACrB,OAAO;EACL;EACA,GAAI,OAAO,UAAU,WAAW,EAAE,MAAM,IAAI,EAAE,QAAQ,MAAM;EAC5D,cAAc;EACd,mBAAmB,wBAAwB,OAAO;EAClD;EAEA,mBAAmB;CACrB;AACF"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Nodes, RootContent } from "../node_modules/.pnpm/@types_hast@3.0.4/node_modules/@types/hast/index.js";
|
|
2
|
+
//#region src/utils/hastToHtml.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Serializes a HAST node or node array to HTML. Common token spans use a fast
|
|
5
|
+
* path; other nodes and attributes use hast-util-to-html's default serialization.
|
|
6
|
+
*/
|
|
7
|
+
declare function hastToHtml(tree: Nodes | RootContent[]): string;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { hastToHtml };
|
|
10
|
+
//# sourceMappingURL=hastToHtml.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hastToHtml.d.ts","names":[],"sources":["../../src/utils/hastToHtml.ts"],"mappings":";;;;;;iBA4DgB,WAAW,MAAM,QAAQ"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { toHtml } from "hast-util-to-html";
|
|
2
|
+
//#region src/utils/hastToHtml.ts
|
|
3
|
+
const VOID_ELEMENTS = /* @__PURE__ */ new Set([
|
|
4
|
+
"area",
|
|
5
|
+
"base",
|
|
6
|
+
"basefont",
|
|
7
|
+
"bgsound",
|
|
8
|
+
"br",
|
|
9
|
+
"col",
|
|
10
|
+
"command",
|
|
11
|
+
"embed",
|
|
12
|
+
"frame",
|
|
13
|
+
"hr",
|
|
14
|
+
"image",
|
|
15
|
+
"img",
|
|
16
|
+
"input",
|
|
17
|
+
"keygen",
|
|
18
|
+
"link",
|
|
19
|
+
"meta",
|
|
20
|
+
"param",
|
|
21
|
+
"source",
|
|
22
|
+
"track",
|
|
23
|
+
"wbr"
|
|
24
|
+
]);
|
|
25
|
+
const DELEGATED_TAGS = /* @__PURE__ */ new Set([
|
|
26
|
+
"svg",
|
|
27
|
+
"template",
|
|
28
|
+
"script",
|
|
29
|
+
"style"
|
|
30
|
+
]);
|
|
31
|
+
const ATTRIBUTE_NAMES = {
|
|
32
|
+
class: "class",
|
|
33
|
+
className: "class",
|
|
34
|
+
id: "id",
|
|
35
|
+
role: "role",
|
|
36
|
+
style: "style",
|
|
37
|
+
tabIndex: "tabindex",
|
|
38
|
+
tabindex: "tabindex",
|
|
39
|
+
title: "title"
|
|
40
|
+
};
|
|
41
|
+
const DATA_ATTRIBUTE = /^data-[\w.:-]+$/;
|
|
42
|
+
const TEXT_ESCAPE = /[<&]/g;
|
|
43
|
+
const ATTRIBUTE_ESCAPE = /[\0"&'`]/g;
|
|
44
|
+
const CHARACTER_REFERENCES = {
|
|
45
|
+
"<": "<",
|
|
46
|
+
"&": "&",
|
|
47
|
+
"\"": """,
|
|
48
|
+
"'": "'",
|
|
49
|
+
"`": "`",
|
|
50
|
+
"\0": "�"
|
|
51
|
+
};
|
|
52
|
+
const MAX_CACHED_STYLES = 256;
|
|
53
|
+
/**
|
|
54
|
+
* Serializes a HAST node or node array to HTML. Common token spans use a fast
|
|
55
|
+
* path; other nodes and attributes use hast-util-to-html's default serialization.
|
|
56
|
+
*/
|
|
57
|
+
function hastToHtml(tree) {
|
|
58
|
+
const styles = /* @__PURE__ */ new Map();
|
|
59
|
+
return Array.isArray(tree) ? serializeChildren(tree, styles) : serializeNode(tree, styles);
|
|
60
|
+
}
|
|
61
|
+
function serializeChildren(children, styles) {
|
|
62
|
+
let html = "";
|
|
63
|
+
for (const child of children) html += serializeNode(child, styles);
|
|
64
|
+
return html;
|
|
65
|
+
}
|
|
66
|
+
function serializeNode(node, styles) {
|
|
67
|
+
switch (node.type) {
|
|
68
|
+
case "text": return escapeText(node.value);
|
|
69
|
+
case "element": return serializeElement(node, styles);
|
|
70
|
+
case "root": return serializeChildren(node.children, styles);
|
|
71
|
+
default: return toHtml(node);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function serializeElement(node, styles) {
|
|
75
|
+
const { tagName } = node;
|
|
76
|
+
if (tagName === "span" && node.children.length === 1 && node.children[0].type === "text" && typeof node.properties?.style === "string") {
|
|
77
|
+
let styleOnly = true;
|
|
78
|
+
for (const key in node.properties) if (key !== "style" && node.properties[key] != null) {
|
|
79
|
+
styleOnly = false;
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
if (styleOnly) return `<span ${serializeStyle(node.properties.style, styles)}>${escapeText(node.children[0].value)}</span>`;
|
|
83
|
+
}
|
|
84
|
+
if (DELEGATED_TAGS.has(tagName)) return toHtml(node);
|
|
85
|
+
const attributes = serializeAttributes(node.properties, styles);
|
|
86
|
+
if (attributes == null) return toHtml(node);
|
|
87
|
+
const open = attributes === "" ? `<${tagName}>` : `<${tagName} ${attributes}>`;
|
|
88
|
+
const content = serializeChildren(node.children, styles);
|
|
89
|
+
if (content === "" && VOID_ELEMENTS.has(tagName.toLowerCase())) return open;
|
|
90
|
+
return `${open}${content}</${tagName}>`;
|
|
91
|
+
}
|
|
92
|
+
function serializeStyle(value, styles) {
|
|
93
|
+
let attribute = styles.get(value);
|
|
94
|
+
if (attribute == null) {
|
|
95
|
+
attribute = `style="${escapeAttribute(value)}"`;
|
|
96
|
+
if (styles.size < MAX_CACHED_STYLES) styles.set(value, attribute);
|
|
97
|
+
}
|
|
98
|
+
return attribute;
|
|
99
|
+
}
|
|
100
|
+
function serializeAttributes(properties, styles) {
|
|
101
|
+
let attributes = "";
|
|
102
|
+
for (const key in properties) {
|
|
103
|
+
const value = properties[key];
|
|
104
|
+
if (value == null) continue;
|
|
105
|
+
const name = ATTRIBUTE_NAMES[key] ?? (DATA_ATTRIBUTE.test(key) ? key : void 0);
|
|
106
|
+
if (name == null) return;
|
|
107
|
+
if (value === false || typeof value === "number" && Number.isNaN(value)) continue;
|
|
108
|
+
const attribute = key === "style" && typeof value === "string" ? serializeStyle(value, styles) : value === true ? name : `${name}="${escapeAttribute(Array.isArray(value) ? value.join(" ").trim() : String(value))}"`;
|
|
109
|
+
attributes += attributes === "" ? attribute : ` ${attribute}`;
|
|
110
|
+
}
|
|
111
|
+
return attributes;
|
|
112
|
+
}
|
|
113
|
+
function escapeText(value) {
|
|
114
|
+
return value.indexOf("<") < 0 && value.indexOf("&") < 0 ? value : value.replace(TEXT_ESCAPE, toCharacterReference);
|
|
115
|
+
}
|
|
116
|
+
function escapeAttribute(value) {
|
|
117
|
+
return value.replace(ATTRIBUTE_ESCAPE, toCharacterReference);
|
|
118
|
+
}
|
|
119
|
+
function toCharacterReference(character) {
|
|
120
|
+
return CHARACTER_REFERENCES[character];
|
|
121
|
+
}
|
|
122
|
+
//#endregion
|
|
123
|
+
export { hastToHtml };
|
|
124
|
+
|
|
125
|
+
//# sourceMappingURL=hastToHtml.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hastToHtml.js","names":[],"sources":["../../src/utils/hastToHtml.ts"],"sourcesContent":["import type { Element, Nodes, Properties, RootContent } from 'hast';\nimport { toHtml } from 'hast-util-to-html';\n\n// Must match the html-void-elements list used by toHtml().\nconst VOID_ELEMENTS = new Set([\n 'area',\n 'base',\n 'basefont',\n 'bgsound',\n 'br',\n 'col',\n 'command',\n 'embed',\n 'frame',\n 'hr',\n 'image',\n 'img',\n 'input',\n 'keygen',\n 'link',\n 'meta',\n 'param',\n 'source',\n 'track',\n 'wbr',\n]);\n\n// These elements require schema, fragment or raw-text handling in toHtml().\nconst DELEGATED_TAGS = new Set(['svg', 'template', 'script', 'style']);\n\n// Boolean and comma-separated attributes require the full HTML schema.\nconst ATTRIBUTE_NAMES: Record<string, string | undefined> = {\n class: 'class',\n className: 'class',\n id: 'id',\n role: 'role',\n style: 'style',\n tabIndex: 'tabindex',\n tabindex: 'tabindex',\n title: 'title',\n};\nconst DATA_ATTRIBUTE = /^data-[\\w.:-]+$/;\n\nconst TEXT_ESCAPE = /[<&]/g;\nconst ATTRIBUTE_ESCAPE = /[\\0\"&'`]/g;\n// Must match stringify-entities' default hexadecimal encoding.\nconst CHARACTER_REFERENCES: Record<string, string> = {\n '<': '<',\n '&': '&',\n '\"': '"',\n \"'\": ''',\n '`': '`',\n '\\0': '�',\n};\nconst MAX_CACHED_STYLES = 256;\n\n/**\n * Serializes a HAST node or node array to HTML. Common token spans use a fast\n * path; other nodes and attributes use hast-util-to-html's default serialization.\n */\nexport function hastToHtml(tree: Nodes | RootContent[]): string {\n const styles = new Map<string, string>();\n return Array.isArray(tree)\n ? serializeChildren(tree, styles)\n : serializeNode(tree, styles);\n}\n\nfunction serializeChildren(\n children: readonly RootContent[],\n styles: Map<string, string>\n): string {\n let html = '';\n for (const child of children) {\n html += serializeNode(child, styles);\n }\n return html;\n}\n\nfunction serializeNode(node: Nodes, styles: Map<string, string>): string {\n switch (node.type) {\n case 'text':\n return escapeText(node.value);\n case 'element':\n return serializeElement(node, styles);\n case 'root':\n return serializeChildren(node.children, styles);\n default:\n return toHtml(node);\n }\n}\n\nfunction serializeElement(node: Element, styles: Map<string, string>): string {\n const { tagName } = node;\n if (\n tagName === 'span' &&\n node.children.length === 1 &&\n node.children[0].type === 'text' &&\n typeof node.properties?.style === 'string'\n ) {\n let styleOnly = true;\n for (const key in node.properties) {\n if (key !== 'style' && node.properties[key] != null) {\n styleOnly = false;\n break;\n }\n }\n if (styleOnly) {\n return `<span ${serializeStyle(node.properties.style, styles)}>${escapeText(node.children[0].value)}</span>`;\n }\n }\n if (DELEGATED_TAGS.has(tagName)) {\n return toHtml(node);\n }\n const attributes = serializeAttributes(node.properties, styles);\n if (attributes == null) {\n return toHtml(node);\n }\n const open =\n attributes === '' ? `<${tagName}>` : `<${tagName} ${attributes}>`;\n const content = serializeChildren(node.children, styles);\n if (content === '' && VOID_ELEMENTS.has(tagName.toLowerCase())) {\n return open;\n }\n return `${open}${content}</${tagName}>`;\n}\n\n// Cap the per-render cache because custom styles may be unique per token.\nfunction serializeStyle(value: string, styles: Map<string, string>): string {\n let attribute = styles.get(value);\n if (attribute == null) {\n attribute = `style=\"${escapeAttribute(value)}\"`;\n if (styles.size < MAX_CACHED_STYLES) styles.set(value, attribute);\n }\n return attribute;\n}\n\n// Returns undefined when a property needs the HTML schema to serialize.\nfunction serializeAttributes(\n properties: Properties | undefined,\n styles: Map<string, string>\n): string | undefined {\n let attributes = '';\n for (const key in properties) {\n const value = properties[key];\n if (value == null) {\n continue;\n }\n const name =\n ATTRIBUTE_NAMES[key] ?? (DATA_ATTRIBUTE.test(key) ? key : undefined);\n if (name == null) {\n return undefined;\n }\n if (value === false || (typeof value === 'number' && Number.isNaN(value))) {\n continue;\n }\n const attribute =\n key === 'style' && typeof value === 'string'\n ? serializeStyle(value, styles)\n : value === true\n ? name\n : `${name}=\"${escapeAttribute(\n Array.isArray(value) ? value.join(' ').trim() : String(value)\n )}\"`;\n attributes += attributes === '' ? attribute : ` ${attribute}`;\n }\n return attributes;\n}\n\nfunction escapeText(value: string): string {\n return value.indexOf('<') < 0 && value.indexOf('&') < 0\n ? value\n : value.replace(TEXT_ESCAPE, toCharacterReference);\n}\n\nfunction escapeAttribute(value: string): string {\n return value.replace(ATTRIBUTE_ESCAPE, toCharacterReference);\n}\n\nfunction toCharacterReference(character: string): string {\n return CHARACTER_REFERENCES[character];\n}\n"],"mappings":";;AAIA,MAAM,gCAAgB,IAAI,IAAI;CAC5B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;C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OAAuB;CACzC,OAAO,MAAM,QAAQ,GAAG,IAAI,KAAK,MAAM,QAAQ,GAAG,IAAI,IAClD,QACA,MAAM,QAAQ,aAAa,oBAAoB;AACrD;AAEA,SAAS,gBAAgB,OAAuB;CAC9C,OAAO,MAAM,QAAQ,kBAAkB,oBAAoB;AAC7D;AAEA,SAAS,qBAAqB,WAA2B;CACvD,OAAO,qBAAqB;AAC9B"}
|
|
@@ -19,6 +19,8 @@ function hydratePartialDiff(type, fileDiff, files) {
|
|
|
19
19
|
targetFileDiff.isPartial = false;
|
|
20
20
|
targetFileDiff.deletionLines = lines;
|
|
21
21
|
targetFileDiff.additionLines = lines;
|
|
22
|
+
targetFileDiff.deletionCharacterCount = newFile.contents.length;
|
|
23
|
+
targetFileDiff.additionCharacterCount = newFile.contents.length;
|
|
22
24
|
setHydratedCacheKey(targetFileDiff, null, newFile);
|
|
23
25
|
return targetFileDiff;
|
|
24
26
|
}
|
|
@@ -35,6 +37,8 @@ function hydrateTwoSidedFileDiff(fileDiff, oldFile, newFile) {
|
|
|
35
37
|
fileDiff.isPartial = false;
|
|
36
38
|
fileDiff.deletionLines = deletionLines;
|
|
37
39
|
fileDiff.additionLines = additionLines;
|
|
40
|
+
fileDiff.deletionCharacterCount = oldFile.contents.length;
|
|
41
|
+
fileDiff.additionCharacterCount = newFile.contents.length;
|
|
38
42
|
setHydratedCacheKey(fileDiff, oldFile, newFile);
|
|
39
43
|
return fileDiff;
|
|
40
44
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hydratePartialDiff.js","names":[],"sources":["../../src/utils/hydratePartialDiff.ts"],"sourcesContent":["import type {\n FileContents,\n FileDiffLoadedFiles,\n FileDiffMetadata,\n Hunk,\n} from '../types';\nimport { cloneFileDiffMetadata } from './cloneFileDiffMetadata';\nimport { composeCacheKey } from './composeCacheKey';\nimport {\n getHunkSideEndBoundary,\n getHunkSideStartBoundary,\n} from './getHunkSideBoundaries';\nimport { splitFileContents } from './splitFileContents';\n\ninterface HydratedHunksResult {\n hunks: Hunk[];\n splitLineCount: number;\n unifiedLineCount: number;\n}\n\n/**\n * Hydrates a partial diff in place with full file line arrays.\n */\nexport function hydratePartialDiff(\n type: 'clone' | 'merge',\n fileDiff: FileDiffMetadata,\n files: FileDiffLoadedFiles\n): FileDiffMetadata {\n const targetFileDiff =\n type === 'clone' ? cloneFileDiffMetadata(fileDiff) : fileDiff;\n\n if (!targetFileDiff.isPartial) {\n throw new Error('hydratePartialDiff: fileDiff must be partial');\n }\n\n switch (targetFileDiff.type) {\n case 'change':\n case 'rename-changed': {\n const oldFile = requireOldFile(targetFileDiff, files);\n const newFile = requireNewFile(targetFileDiff, files);\n return hydrateTwoSidedFileDiff(targetFileDiff, oldFile, newFile);\n }\n case 'rename-pure': {\n const newFile = requireNewFile(targetFileDiff, files);\n requireMissingOldFile(targetFileDiff, files);\n const lines = splitFileContents(newFile.contents);\n targetFileDiff.isPartial = false;\n targetFileDiff.deletionLines = lines;\n targetFileDiff.additionLines = lines;\n setHydratedCacheKey(targetFileDiff, null, newFile);\n return targetFileDiff;\n }\n }\n throw new Error(\n `hydratePartialDiff: ${targetFileDiff.type} diffs cannot be hydrated from loaded files`\n );\n}\n\nfunction hydrateTwoSidedFileDiff(\n fileDiff: FileDiffMetadata,\n oldFile: FileContents,\n newFile: FileContents\n): FileDiffMetadata {\n const deletionLines = splitFileContents(oldFile.contents);\n const additionLines = splitFileContents(newFile.contents);\n const { hunks, splitLineCount, unifiedLineCount } = hydrateHunks(\n fileDiff.hunks,\n additionLines.length\n );\n\n fileDiff.hunks = hunks;\n fileDiff.splitLineCount = splitLineCount;\n fileDiff.unifiedLineCount = unifiedLineCount;\n fileDiff.isPartial = false;\n fileDiff.deletionLines = deletionLines;\n fileDiff.additionLines = additionLines;\n setHydratedCacheKey(fileDiff, oldFile, newFile);\n return fileDiff;\n}\n\nfunction hydrateHunks(\n hunks: Hunk[],\n totalAdditionLines: number\n): HydratedHunksResult {\n let splitLineCount = 0;\n let unifiedLineCount = 0;\n let lastHunkAdditionEnd = 0;\n\n const hydratedHunks: Hunk[] = [];\n\n for (const hunk of hunks) {\n const additionLineIndex = Math.max(hunk.additionStart - 1, 0);\n const deletionLineIndex = Math.max(hunk.deletionStart - 1, 0);\n let contentAdditionLineIndex = additionLineIndex;\n let contentDeletionLineIndex = deletionLineIndex;\n let hunkAdditionLines = 0;\n let hunkDeletionLines = 0;\n let hunkSplitLineCount = 0;\n let hunkUnifiedLineCount = 0;\n const hunkContent: Hunk['hunkContent'] = [];\n\n for (const content of hunk.hunkContent) {\n if (content.type === 'context') {\n hunkContent.push({\n ...content,\n additionLineIndex: contentAdditionLineIndex,\n deletionLineIndex: contentDeletionLineIndex,\n });\n contentAdditionLineIndex += content.lines;\n contentDeletionLineIndex += content.lines;\n hunkSplitLineCount += content.lines;\n hunkUnifiedLineCount += content.lines;\n continue;\n }\n\n hunkContent.push({\n ...content,\n additionLineIndex: contentAdditionLineIndex,\n deletionLineIndex: contentDeletionLineIndex,\n });\n contentAdditionLineIndex += content.additions;\n contentDeletionLineIndex += content.deletions;\n hunkAdditionLines += content.additions;\n hunkDeletionLines += content.deletions;\n hunkSplitLineCount += Math.max(content.additions, content.deletions);\n hunkUnifiedLineCount += content.additions + content.deletions;\n }\n\n const collapsedBefore = Math.max(\n getHunkSideStartBoundary(hunk.additionStart, hunk.additionCount) -\n lastHunkAdditionEnd,\n 0\n );\n hydratedHunks.push({\n ...hunk,\n collapsedBefore,\n additionLineIndex,\n deletionLineIndex,\n additionLines: hunkAdditionLines,\n deletionLines: hunkDeletionLines,\n hunkContent,\n splitLineStart: splitLineCount + collapsedBefore,\n unifiedLineStart: unifiedLineCount + collapsedBefore,\n splitLineCount: hunkSplitLineCount,\n unifiedLineCount: hunkUnifiedLineCount,\n });\n\n splitLineCount += collapsedBefore + hunkSplitLineCount;\n unifiedLineCount += collapsedBefore + hunkUnifiedLineCount;\n lastHunkAdditionEnd = getHunkSideEndBoundary(\n hunk.additionStart,\n hunk.additionCount\n );\n }\n\n if (hydratedHunks.length > 0) {\n const lastHunk = hydratedHunks[hydratedHunks.length - 1];\n const lastHunkEnd = getHunkSideEndBoundary(\n lastHunk.additionStart,\n lastHunk.additionCount\n );\n const collapsedAfter = Math.max(totalAdditionLines - lastHunkEnd, 0);\n splitLineCount += collapsedAfter;\n unifiedLineCount += collapsedAfter;\n }\n\n return { hunks: hydratedHunks, splitLineCount, unifiedLineCount };\n}\n\nfunction requireOldFile(\n fileDiff: FileDiffMetadata,\n files: FileDiffLoadedFiles\n): FileContents {\n if (files.oldFile == null) {\n throw new Error(\n `hydratePartialDiff: ${fileDiff.type} diff for ${fileDiff.name} requires oldFile`\n );\n }\n return files.oldFile;\n}\n\nfunction requireNewFile(\n fileDiff: FileDiffMetadata,\n files: FileDiffLoadedFiles\n): FileContents {\n if (files.newFile == null) {\n throw new Error(\n `hydratePartialDiff: ${fileDiff.type} diff for ${fileDiff.name} requires newFile`\n );\n }\n return files.newFile;\n}\n\nfunction requireMissingOldFile(\n fileDiff: FileDiffMetadata,\n files: FileDiffLoadedFiles\n): void {\n if (files.oldFile !== null) {\n throw new Error(\n `hydratePartialDiff: ${fileDiff.type} diff for ${fileDiff.name} requires oldFile to be null`\n );\n }\n}\n\nfunction getHydratedCacheKey(\n fileDiff: FileDiffMetadata,\n oldFile: FileContents | null,\n newFile: FileContents | null\n): string | undefined {\n if (fileDiff.cacheKey != null) {\n return `${fileDiff.cacheKey}:hydrated`;\n }\n return getLoadedFileCacheKey(oldFile, newFile);\n}\n\nfunction setHydratedCacheKey(\n fileDiff: FileDiffMetadata,\n oldFile: FileContents | null,\n newFile: FileContents | null\n): void {\n const cacheKey = getHydratedCacheKey(fileDiff, oldFile, newFile);\n if (cacheKey == null) {\n delete fileDiff.cacheKey;\n return;\n }\n fileDiff.cacheKey = cacheKey;\n}\n\nfunction getLoadedFileCacheKey(\n oldFile: FileContents | null,\n newFile: FileContents | null\n): string | undefined {\n if (oldFile != null && newFile != null) {\n return oldFile.cacheKey != null && newFile.cacheKey != null\n ? composeCacheKey('hydrated-files', oldFile.cacheKey, newFile.cacheKey)\n : undefined;\n }\n return oldFile?.cacheKey ?? newFile?.cacheKey;\n}\n"],"mappings":";;;;;;;;AAuBA,SAAgB,mBACd,MACA,UACA,OACkB;CAClB,MAAM,iBACJ,SAAS,UAAU,sBAAsB,QAAQ,IAAI;CAEvD,IAAI,CAAC,eAAe,WAClB,MAAM,IAAI,MAAM,8CAA8C;CAGhE,QAAQ,eAAe,MAAvB;EACE,KAAK;EACL,KAAK,kBAGH,OAAO,wBAAwB,gBAFf,eAAe,gBAAgB,KAEM,GADrC,eAAe,gBAAgB,KACe,CAAC;EAEjE,KAAK,eAAe;GAClB,MAAM,UAAU,eAAe,gBAAgB,KAAK;GACpD,sBAAsB,gBAAgB,KAAK;GAC3C,MAAM,QAAQ,kBAAkB,QAAQ,QAAQ;GAChD,eAAe,YAAY;GAC3B,eAAe,gBAAgB;GAC/B,eAAe,gBAAgB;GAC/B,oBAAoB,gBAAgB,MAAM,OAAO;GACjD,OAAO;EACT;CACF;CACA,MAAM,IAAI,MACR,uBAAuB,eAAe,KAAK,4CAC7C;AACF;AAEA,SAAS,wBACP,UACA,SACA,SACkB;CAClB,MAAM,gBAAgB,kBAAkB,QAAQ,QAAQ;CACxD,MAAM,gBAAgB,kBAAkB,QAAQ,QAAQ;CACxD,MAAM,EAAE,OAAO,gBAAgB,qBAAqB,aAClD,SAAS,OACT,cAAc,MAChB;CAEA,SAAS,QAAQ;CACjB,SAAS,iBAAiB;CAC1B,SAAS,mBAAmB;CAC5B,SAAS,YAAY;CACrB,SAAS,gBAAgB;CACzB,SAAS,gBAAgB;CACzB,oBAAoB,UAAU,SAAS,OAAO;CAC9C,OAAO;AACT;AAEA,SAAS,aACP,OACA,oBACqB;CACrB,IAAI,iBAAiB;CACrB,IAAI,mBAAmB;CACvB,IAAI,sBAAsB;CAE1B,MAAM,gBAAwB,CAAC;CAE/B,KAAK,MAAM,QA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B,KAAK,IAAI,qBAAqB,aAAa,CAAC;EACnE,kBAAkB;EAClB,oBAAoB;CACtB;CAEA,OAAO;EAAE,OAAO;EAAe;EAAgB;CAAiB;AAClE;AAEA,SAAS,eACP,UACA,OACc;CACd,IAAI,MAAM,WAAW,MACnB,MAAM,IAAI,MACR,uBAAuB,SAAS,KAAK,YAAY,SAAS,KAAK,kBACjE;CAEF,OAAO,MAAM;AACf;AAEA,SAAS,eACP,UACA,OACc;CACd,IAAI,MAAM,WAAW,MACnB,MAAM,IAAI,MACR,uBAAuB,SAAS,KAAK,YAAY,SAAS,KAAK,kBACjE;CAEF,OAAO,MAAM;AACf;AAEA,SAAS,sBACP,UACA,OACM;CACN,IAAI,MAAM,YAAY,MACpB,MAAM,IAAI,MACR,uBAAuB,SAAS,KAAK,YAAY,SAAS,KAAK,6BACjE;AAEJ;AAEA,SAAS,oBACP,UACA,SACA,SACoB;CACpB,IAAI,SAAS,YAAY,MACvB,OAAO,GAAG,SAAS,SAAS;CAE9B,OAAO,sBAAsB,SAAS,OAAO;AAC/C;AAEA,SAAS,oBACP,UACA,SACA,SACM;CACN,MAAM,WAAW,oBAAoB,UAAU,SAAS,OAAO;CAC/D,IAAI,YAAY,MAAM;EACpB,OAAO,SAAS;EAChB;CACF;CACA,SAAS,WAAW;AACtB;AAEA,SAAS,sBACP,SACA,SACoB;CACpB,IAAI,WAAW,QAAQ,WAAW,MAChC,OAAO,QAAQ,YAAY,QAAQ,QAAQ,YAAY,OACnD,gBAAgB,kBAAkB,QAAQ,UAAU,QAAQ,QAAQ,IACpE,KAAA;CAEN,OAAO,SAAS,YAAY,SAAS;AACvC"}
|
|
1
|
+
{"version":3,"file":"hydratePartialDiff.js","names":[],"sources":["../../src/utils/hydratePartialDiff.ts"],"sourcesContent":["import type {\n FileContents,\n FileDiffLoadedFiles,\n FileDiffMetadata,\n Hunk,\n} from '../types';\nimport { cloneFileDiffMetadata } from './cloneFileDiffMetadata';\nimport { composeCacheKey } from './composeCacheKey';\nimport {\n getHunkSideEndBoundary,\n getHunkSideStartBoundary,\n} from './getHunkSideBoundaries';\nimport { splitFileContents } from './splitFileContents';\n\ninterface HydratedHunksResult {\n hunks: Hunk[];\n splitLineCount: number;\n unifiedLineCount: number;\n}\n\n/**\n * Hydrates a partial diff in place with full file line arrays.\n */\nexport function hydratePartialDiff(\n type: 'clone' | 'merge',\n fileDiff: FileDiffMetadata,\n files: FileDiffLoadedFiles\n): FileDiffMetadata {\n const targetFileDiff =\n type === 'clone' ? cloneFileDiffMetadata(fileDiff) : fileDiff;\n\n if (!targetFileDiff.isPartial) {\n throw new Error('hydratePartialDiff: fileDiff must be partial');\n }\n\n switch (targetFileDiff.type) {\n case 'change':\n case 'rename-changed': {\n const oldFile = requireOldFile(targetFileDiff, files);\n const newFile = requireNewFile(targetFileDiff, files);\n return hydrateTwoSidedFileDiff(targetFileDiff, oldFile, newFile);\n }\n case 'rename-pure': {\n const newFile = requireNewFile(targetFileDiff, files);\n requireMissingOldFile(targetFileDiff, files);\n const lines = splitFileContents(newFile.contents);\n targetFileDiff.isPartial = false;\n targetFileDiff.deletionLines = lines;\n targetFileDiff.additionLines = lines;\n targetFileDiff.deletionCharacterCount = newFile.contents.length;\n targetFileDiff.additionCharacterCount = newFile.contents.length;\n setHydratedCacheKey(targetFileDiff, null, newFile);\n return targetFileDiff;\n }\n }\n throw new Error(\n `hydratePartialDiff: ${targetFileDiff.type} diffs cannot be hydrated from loaded files`\n );\n}\n\nfunction hydrateTwoSidedFileDiff(\n fileDiff: FileDiffMetadata,\n oldFile: FileContents,\n newFile: FileContents\n): FileDiffMetadata {\n const deletionLines = splitFileContents(oldFile.contents);\n const additionLines = splitFileContents(newFile.contents);\n const { hunks, splitLineCount, unifiedLineCount } = hydrateHunks(\n fileDiff.hunks,\n additionLines.length\n );\n\n fileDiff.hunks = hunks;\n fileDiff.splitLineCount = splitLineCount;\n fileDiff.unifiedLineCount = unifiedLineCount;\n fileDiff.isPartial = false;\n fileDiff.deletionLines = deletionLines;\n fileDiff.additionLines = additionLines;\n fileDiff.deletionCharacterCount = oldFile.contents.length;\n fileDiff.additionCharacterCount = newFile.contents.length;\n setHydratedCacheKey(fileDiff, oldFile, newFile);\n return fileDiff;\n}\n\nfunction hydrateHunks(\n hunks: Hunk[],\n totalAdditionLines: number\n): HydratedHunksResult {\n let splitLineCount = 0;\n let unifiedLineCount = 0;\n let lastHunkAdditionEnd = 0;\n\n const hydratedHunks: Hunk[] = [];\n\n for (const hunk of hunks) {\n const additionLineIndex = Math.max(hunk.additionStart - 1, 0);\n const deletionLineIndex = Math.max(hunk.deletionStart - 1, 0);\n let contentAdditionLineIndex = additionLineIndex;\n let contentDeletionLineIndex = deletionLineIndex;\n let hunkAdditionLines = 0;\n let hunkDeletionLines = 0;\n let hunkSplitLineCount = 0;\n let hunkUnifiedLineCount = 0;\n const hunkContent: Hunk['hunkContent'] = [];\n\n for (const content of hunk.hunkContent) {\n if (content.type === 'context') {\n hunkContent.push({\n ...content,\n additionLineIndex: contentAdditionLineIndex,\n deletionLineIndex: contentDeletionLineIndex,\n });\n contentAdditionLineIndex += content.lines;\n contentDeletionLineIndex += content.lines;\n hunkSplitLineCount += content.lines;\n hunkUnifiedLineCount += content.lines;\n continue;\n }\n\n hunkContent.push({\n ...content,\n additionLineIndex: contentAdditionLineIndex,\n deletionLineIndex: contentDeletionLineIndex,\n });\n contentAdditionLineIndex += content.additions;\n contentDeletionLineIndex += content.deletions;\n hunkAdditionLines += content.additions;\n hunkDeletionLines += content.deletions;\n hunkSplitLineCount += Math.max(content.additions, content.deletions);\n hunkUnifiedLineCount += content.additions + content.deletions;\n }\n\n const collapsedBefore = Math.max(\n getHunkSideStartBoundary(hunk.additionStart, hunk.additionCount) -\n lastHunkAdditionEnd,\n 0\n );\n hydratedHunks.push({\n ...hunk,\n collapsedBefore,\n additionLineIndex,\n deletionLineIndex,\n additionLines: hunkAdditionLines,\n deletionLines: hunkDeletionLines,\n hunkContent,\n splitLineStart: splitLineCount + collapsedBefore,\n unifiedLineStart: unifiedLineCount + collapsedBefore,\n splitLineCount: hunkSplitLineCount,\n unifiedLineCount: hunkUnifiedLineCount,\n });\n\n splitLineCount += collapsedBefore + hunkSplitLineCount;\n unifiedLineCount += collapsedBefore + hunkUnifiedLineCount;\n lastHunkAdditionEnd = getHunkSideEndBoundary(\n hunk.additionStart,\n hunk.additionCount\n );\n }\n\n if (hydratedHunks.length > 0) {\n const lastHunk = hydratedHunks[hydratedHunks.length - 1];\n const lastHunkEnd = getHunkSideEndBoundary(\n lastHunk.additionStart,\n lastHunk.additionCount\n );\n const collapsedAfter = Math.max(totalAdditionLines - lastHunkEnd, 0);\n splitLineCount += collapsedAfter;\n unifiedLineCount += collapsedAfter;\n }\n\n return { hunks: hydratedHunks, splitLineCount, unifiedLineCount };\n}\n\nfunction requireOldFile(\n fileDiff: FileDiffMetadata,\n files: FileDiffLoadedFiles\n): FileContents {\n if (files.oldFile == null) {\n throw new Error(\n `hydratePartialDiff: ${fileDiff.type} diff for ${fileDiff.name} requires oldFile`\n );\n }\n return files.oldFile;\n}\n\nfunction requireNewFile(\n fileDiff: FileDiffMetadata,\n files: FileDiffLoadedFiles\n): FileContents {\n if (files.newFile == null) {\n throw new Error(\n `hydratePartialDiff: ${fileDiff.type} diff for ${fileDiff.name} requires newFile`\n );\n }\n return files.newFile;\n}\n\nfunction requireMissingOldFile(\n fileDiff: FileDiffMetadata,\n files: FileDiffLoadedFiles\n): void {\n if (files.oldFile !== null) {\n throw new Error(\n `hydratePartialDiff: ${fileDiff.type} diff for ${fileDiff.name} requires oldFile to be null`\n );\n }\n}\n\nfunction getHydratedCacheKey(\n fileDiff: FileDiffMetadata,\n oldFile: FileContents | null,\n newFile: FileContents | null\n): string | undefined {\n if (fileDiff.cacheKey != null) {\n return `${fileDiff.cacheKey}:hydrated`;\n }\n return getLoadedFileCacheKey(oldFile, newFile);\n}\n\nfunction setHydratedCacheKey(\n fileDiff: FileDiffMetadata,\n oldFile: FileContents | null,\n newFile: FileContents | null\n): void {\n const cacheKey = getHydratedCacheKey(fileDiff, oldFile, newFile);\n if (cacheKey == null) {\n delete fileDiff.cacheKey;\n return;\n }\n fileDiff.cacheKey = cacheKey;\n}\n\nfunction getLoadedFileCacheKey(\n oldFile: FileContents | null,\n newFile: FileContents | null\n): string | undefined {\n if (oldFile != null && newFile != null) {\n return oldFile.cacheKey != null && newFile.cacheKey != null\n ? composeCacheKey('hydrated-files', oldFile.cacheKey, newFile.cacheKey)\n : undefined;\n }\n return oldFile?.cacheKey ?? newFile?.cacheKey;\n}\n"],"mappings":";;;;;;;;AAuBA,SAAgB,mBACd,MACA,UACA,OACkB;CAClB,MAAM,iBACJ,SAAS,UAAU,sBAAsB,QAAQ,IAAI;CAEvD,IAAI,CAAC,eAAe,WAClB,MAAM,IAAI,MAAM,8CAA8C;CAGhE,QAAQ,eAAe,MAAvB;EACE,KAAK;EACL,KAAK,kBAGH,OAAO,wBAAwB,gBAFf,eAAe,gBAAgB,KAEM,GADrC,eAAe,gBAAgB,KACe,CAAC;EAEjE,KAAK,eAAe;GAClB,MAAM,UAAU,eAAe,gBAAgB,KAAK;GACpD,sBAAsB,gBAAgB,KAAK;GAC3C,MAAM,QAAQ,kBAAkB,QAAQ,QAAQ;GAChD,eAAe,YAAY;GAC3B,eAAe,gBAAgB;GAC/B,eAAe,gBAAgB;GAC/B,eAAe,yBAAyB,QAAQ,SAAS;GACzD,eAAe,yBAAyB,QAAQ,SAAS;GACzD,oBAAoB,gBAAgB,MAAM,OAAO;GACjD,OAAO;EACT;CACF;CACA,MAAM,IAAI,MACR,uBAAuB,eAAe,KAAK,4CAC7C;AACF;AAEA,SAAS,wBACP,UACA,SACA,SACkB;CAClB,MAAM,gBAAgB,kBAAkB,QAAQ,QAAQ;CACxD,MAAM,gBAAgB,kBAAkB,QAAQ,QAAQ;CACxD,MAAM,EAAE,OAAO,gBAAgB,qBAAqB,aAClD,SAAS,OACT,cAAc,MAChB;CAEA,SAAS,QAAQ;CACjB,S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O,QAAQ,YAAY,QAAQ,QAAQ,YAAY,OACnD,gBAAgB,kBAAkB,QAAQ,UAAU,QAAQ,QAAQ,IACpE,KAAA;CAEN,OAAO,SAAS,YAAY,SAAS;AACvC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseDiffDecorations.d.ts","names":[],"sources":["../../src/utils/parseDiffDecorations.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"parseDiffDecorations.d.ts","names":[],"sources":["../../src/utils/parseDiffDecorations.ts"],"mappings":";;;;UAIU;EACR;EACA;EACA;;iBAGc,2BACd,MACA,WACA,cACC,gCAAgC;UASzB;EACR,MAAM;EACN;EACA;EACA;EACA;;iBAQc,iBACd,MACA,KACA,YACA,WACA,cACC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseMergeConflictDiffFromFile.d.ts","names":[],"sources":["../../src/utils/parseMergeConflictDiffFromFile.ts"],"mappings":";;UAsDiB;EACf,UAAU;EACV,aAAa;EACb,cAAc;EACd,UAAU;EACV,YAAY;;UAGG,gCAAgC;EAG/C,UAAU;EACV;EACA;IACE;IACA;IACA;IACA;;;UAIM;EACR;EACA;;iBAqGc,6BACd,QAAQ,yBACR,UAAU,mBACT;iBAoBa,+BACd,MAAM,cACN,2BACC;
|
|
1
|
+
{"version":3,"file":"parseMergeConflictDiffFromFile.d.ts","names":[],"sources":["../../src/utils/parseMergeConflictDiffFromFile.ts"],"mappings":";;UAsDiB;EACf,UAAU;EACV,aAAa;EACb,cAAc;EACd,UAAU;EACV,YAAY;;UAGG,gCAAgC;EAG/C,UAAU;EACV;EACA;IACE;IACA;IACA;IACA;;;UAIM;EACR;EACA;;iBAqGc,6BACd,QAAQ,yBACR,UAAU,mBACT;iBAoBa,+BACd,MAAM,cACN,2BACC;iBAk0Ba,6BACd,UAAU,kBACV,UAAU,yCACT"}
|
|
@@ -71,6 +71,8 @@ function parseMergeConflictDiffFromFile(file, maxContextLines = 6) {
|
|
|
71
71
|
isPartial: false,
|
|
72
72
|
deletionLines: s.deletionLines,
|
|
73
73
|
additionLines: s.additionLines,
|
|
74
|
+
deletionCharacterCount: currentContents.length,
|
|
75
|
+
additionCharacterCount: incomingContents.length,
|
|
74
76
|
cacheKey: file.cacheKey != null ? `${file.cacheKey}:merge-conflict-diff` : void 0
|
|
75
77
|
};
|
|
76
78
|
return {
|