@openclaw/diffs 2026.10.2 → 2026.10.5-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/dist/.setup/{browser.runtime-B8JeyUXz.mjs → browser.runtime-BfvyJ76b.mjs} +7 -11
  2. package/dist/assets/viewer-runtime.js +97 -1316
  3. package/dist/index.js +19 -42
  4. package/node_modules/@pierre/diffs/dist/components/CodeView.d.ts +2 -4
  5. package/node_modules/@pierre/diffs/dist/components/CodeView.d.ts.map +1 -1
  6. package/node_modules/@pierre/diffs/dist/components/CodeView.js +23 -12
  7. package/node_modules/@pierre/diffs/dist/components/CodeView.js.map +1 -1
  8. package/node_modules/@pierre/diffs/dist/components/File.d.ts +2 -0
  9. package/node_modules/@pierre/diffs/dist/components/File.d.ts.map +1 -1
  10. package/node_modules/@pierre/diffs/dist/components/File.js +6 -0
  11. package/node_modules/@pierre/diffs/dist/components/File.js.map +1 -1
  12. package/node_modules/@pierre/diffs/dist/components/FileDiff.d.ts +18 -1
  13. package/node_modules/@pierre/diffs/dist/components/FileDiff.d.ts.map +1 -1
  14. package/node_modules/@pierre/diffs/dist/components/FileDiff.js +47 -15
  15. package/node_modules/@pierre/diffs/dist/components/FileDiff.js.map +1 -1
  16. package/node_modules/@pierre/diffs/dist/components/VirtualizedFile.d.ts.map +1 -1
  17. package/node_modules/@pierre/diffs/dist/components/VirtualizedFile.js +11 -11
  18. package/node_modules/@pierre/diffs/dist/components/VirtualizedFile.js.map +1 -1
  19. package/node_modules/@pierre/diffs/dist/components/VirtualizedFileDiff.d.ts.map +1 -1
  20. package/node_modules/@pierre/diffs/dist/components/VirtualizedFileDiff.js +18 -17
  21. package/node_modules/@pierre/diffs/dist/components/VirtualizedFileDiff.js.map +1 -1
  22. package/node_modules/@pierre/diffs/dist/constants.d.ts +1 -3
  23. package/node_modules/@pierre/diffs/dist/constants.d.ts.map +1 -1
  24. package/node_modules/@pierre/diffs/dist/constants.js +1 -3
  25. package/node_modules/@pierre/diffs/dist/constants.js.map +1 -1
  26. package/node_modules/@pierre/diffs/dist/editor/editor.d.ts.map +1 -1
  27. package/node_modules/@pierre/diffs/dist/editor/editor.js +16 -3
  28. package/node_modules/@pierre/diffs/dist/editor/editor.js.map +1 -1
  29. package/node_modules/@pierre/diffs/dist/editor/editor2.js +1 -1
  30. package/node_modules/@pierre/diffs/dist/index.d.ts +2 -2
  31. package/node_modules/@pierre/diffs/dist/index.js +2 -2
  32. package/node_modules/@pierre/diffs/dist/react/utils/useFileDiffInstance.d.ts.map +1 -1
  33. package/node_modules/@pierre/diffs/dist/react/utils/useFileDiffInstance.js +47 -11
  34. package/node_modules/@pierre/diffs/dist/react/utils/useFileDiffInstance.js.map +1 -1
  35. package/node_modules/@pierre/diffs/dist/renderers/DiffHunksRenderer.d.ts.map +1 -1
  36. package/node_modules/@pierre/diffs/dist/renderers/DiffHunksRenderer.js +20 -13
  37. package/node_modules/@pierre/diffs/dist/renderers/DiffHunksRenderer.js.map +1 -1
  38. package/node_modules/@pierre/diffs/dist/renderers/FileRenderer.d.ts.map +1 -1
  39. package/node_modules/@pierre/diffs/dist/renderers/FileRenderer.js +30 -11
  40. package/node_modules/@pierre/diffs/dist/renderers/FileRenderer.js.map +1 -1
  41. package/node_modules/@pierre/diffs/dist/sprite.d.ts +2 -2
  42. package/node_modules/@pierre/diffs/dist/sprite.d.ts.map +1 -1
  43. package/node_modules/@pierre/diffs/dist/sprite.js +57 -0
  44. package/node_modules/@pierre/diffs/dist/sprite.js.map +1 -1
  45. package/node_modules/@pierre/diffs/dist/style.js +1 -1
  46. package/node_modules/@pierre/diffs/dist/types.d.ts +1 -1
  47. package/node_modules/@pierre/diffs/dist/types.d.ts.map +1 -1
  48. package/node_modules/@pierre/diffs/dist/utils/editSessionHunks.d.ts +5 -4
  49. package/node_modules/@pierre/diffs/dist/utils/editSessionHunks.d.ts.map +1 -1
  50. package/node_modules/@pierre/diffs/dist/utils/editSessionHunks.js +32 -9
  51. package/node_modules/@pierre/diffs/dist/utils/editSessionHunks.js.map +1 -1
  52. package/node_modules/@pierre/diffs/dist/utils/parsePatchFiles.d.ts.map +1 -1
  53. package/node_modules/@pierre/diffs/dist/utils/parsePatchFiles.js +21 -13
  54. package/node_modules/@pierre/diffs/dist/utils/parsePatchFiles.js.map +1 -1
  55. package/node_modules/@pierre/diffs/dist/utils/parseQuotedDiffFileName.d.ts +8 -0
  56. package/node_modules/@pierre/diffs/dist/utils/parseQuotedDiffFileName.d.ts.map +1 -0
  57. package/node_modules/@pierre/diffs/dist/utils/parseQuotedDiffFileName.js +54 -0
  58. package/node_modules/@pierre/diffs/dist/utils/parseQuotedDiffFileName.js.map +1 -0
  59. package/node_modules/@pierre/diffs/dist/utils/realignChangeContent.d.ts +13 -10
  60. package/node_modules/@pierre/diffs/dist/utils/realignChangeContent.d.ts.map +1 -1
  61. package/node_modules/@pierre/diffs/dist/utils/realignChangeContent.js +23 -19
  62. package/node_modules/@pierre/diffs/dist/utils/realignChangeContent.js.map +1 -1
  63. package/node_modules/@pierre/diffs/dist/utils/renderDiffWithHighlighter.js +39 -0
  64. package/node_modules/@pierre/diffs/dist/utils/renderDiffWithHighlighter.js.map +1 -1
  65. package/node_modules/@pierre/diffs/dist/worker/worker-portable.js +39 -0
  66. package/node_modules/@pierre/diffs/dist/worker/worker-portable.js.map +1 -1
  67. package/node_modules/@pierre/diffs/dist/worker/worker.js +39 -0
  68. package/node_modules/@pierre/diffs/dist/worker/worker.js.map +1 -1
  69. package/node_modules/@pierre/diffs/node_modules/@shikijs/core/dist/index.d.mts +28 -28
  70. package/node_modules/@pierre/diffs/node_modules/@shikijs/core/dist/index.mjs +15 -12
  71. package/node_modules/@pierre/diffs/node_modules/@shikijs/core/package.json +4 -4
  72. package/node_modules/@pierre/diffs/node_modules/@shikijs/engine-javascript/dist/{engine-compile-Bdn9ihA2.d.mts → engine-compile-CtqiSkRk.d.mts} +5 -0
  73. package/node_modules/@pierre/diffs/node_modules/@shikijs/engine-javascript/dist/engine-compile.d.mts +1 -1
  74. package/node_modules/@pierre/diffs/node_modules/@shikijs/engine-javascript/dist/engine-compile.mjs +2 -4
  75. package/node_modules/@pierre/diffs/node_modules/@shikijs/engine-javascript/dist/engine-raw.d.mts +2 -3
  76. package/node_modules/@pierre/diffs/node_modules/@shikijs/engine-javascript/dist/engine-raw.mjs +2 -4
  77. package/node_modules/@pierre/diffs/node_modules/@shikijs/engine-javascript/dist/index.d.mts +1 -1
  78. package/node_modules/@pierre/diffs/node_modules/@shikijs/engine-javascript/dist/index.mjs +1 -1
  79. package/node_modules/@pierre/diffs/node_modules/@shikijs/engine-javascript/dist/string-TLTPtCPs.mjs +115 -0
  80. package/node_modules/@pierre/diffs/node_modules/@shikijs/engine-javascript/package.json +3 -3
  81. package/node_modules/@pierre/diffs/node_modules/@shikijs/engine-oniguruma/package.json +3 -3
  82. package/node_modules/@pierre/diffs/node_modules/@shikijs/primitive/dist/index.d.mts +31 -32
  83. package/node_modules/@pierre/diffs/node_modules/@shikijs/primitive/dist/index.mjs +2 -1
  84. package/node_modules/@pierre/diffs/node_modules/@shikijs/primitive/package.json +3 -3
  85. package/node_modules/@pierre/diffs/node_modules/@shikijs/themes/dist/monokai.mjs +1 -1
  86. package/node_modules/@pierre/diffs/node_modules/@shikijs/themes/dist/one-dark-pro.mjs +1 -1
  87. package/node_modules/@pierre/diffs/node_modules/@shikijs/themes/dist/red.mjs +1 -1
  88. package/node_modules/@pierre/diffs/node_modules/@shikijs/themes/dist/solarized-dark.mjs +1 -1
  89. package/node_modules/@pierre/diffs/node_modules/@shikijs/themes/dist/solarized-light.mjs +1 -1
  90. package/node_modules/@pierre/diffs/node_modules/@shikijs/themes/package.json +3 -3
  91. package/node_modules/@pierre/diffs/node_modules/@shikijs/transformers/dist/index.d.mts +58 -35
  92. package/node_modules/@pierre/diffs/node_modules/@shikijs/transformers/dist/index.mjs +35 -4
  93. package/node_modules/@pierre/diffs/node_modules/@shikijs/transformers/package.json +3 -3
  94. package/node_modules/@pierre/diffs/node_modules/@shikijs/types/dist/index.d.mts +76 -76
  95. package/node_modules/@pierre/diffs/node_modules/@shikijs/types/package.json +1 -1
  96. package/node_modules/@pierre/diffs/node_modules/micromark-util-types/index.d.ts +6 -3
  97. package/node_modules/@pierre/diffs/node_modules/micromark-util-types/package.json +2 -36
  98. package/node_modules/@pierre/diffs/node_modules/shiki/dist/bundle-full.d.mts +4 -4
  99. package/node_modules/@pierre/diffs/node_modules/shiki/dist/bundle-web.d.mts +9 -9
  100. package/node_modules/@pierre/diffs/node_modules/shiki/dist/types.d.mts +3 -3
  101. package/node_modules/@pierre/diffs/node_modules/shiki/package.json +10 -10
  102. package/node_modules/@pierre/diffs/package.json +1 -1
  103. package/node_modules/@shikijs/langs/dist/ada.mjs +1 -1
  104. package/node_modules/@shikijs/langs/dist/ahk.mjs +1 -1
  105. package/node_modules/@shikijs/langs/dist/beancount.mjs +1 -1
  106. package/node_modules/@shikijs/langs/dist/coq.mjs +1 -1
  107. package/node_modules/@shikijs/langs/dist/csharp.mjs +1 -1
  108. package/node_modules/@shikijs/langs/dist/css.mjs +1 -1
  109. package/node_modules/@shikijs/langs/dist/dart.mjs +1 -1
  110. package/node_modules/@shikijs/langs/dist/dotenv.mjs +1 -1
  111. package/node_modules/@shikijs/langs/dist/emacs-lisp.mjs +1 -1
  112. package/node_modules/@shikijs/langs/dist/gn.mjs +1 -1
  113. package/node_modules/@shikijs/langs/dist/handlebars.mjs +1 -1
  114. package/node_modules/@shikijs/langs/dist/julia.mjs +1 -1
  115. package/node_modules/@shikijs/langs/dist/latex.mjs +1 -1
  116. package/node_modules/@shikijs/langs/dist/luau.mjs +1 -1
  117. package/node_modules/@shikijs/langs/dist/marko.mjs +1 -1
  118. package/node_modules/@shikijs/langs/dist/moonbit.mjs +1 -1
  119. package/node_modules/@shikijs/langs/dist/nextflow-groovy.mjs +1 -1
  120. package/node_modules/@shikijs/langs/dist/nextflow.mjs +1 -1
  121. package/node_modules/@shikijs/langs/dist/nushell.mjs +1 -1
  122. package/node_modules/@shikijs/langs/dist/php.mjs +1 -1
  123. package/node_modules/@shikijs/langs/dist/powershell.mjs +1 -1
  124. package/node_modules/@shikijs/langs/dist/ruby.mjs +1 -1
  125. package/node_modules/@shikijs/langs/dist/rust.mjs +1 -1
  126. package/node_modules/@shikijs/langs/dist/sql.mjs +1 -1
  127. package/node_modules/@shikijs/langs/dist/svelte.mjs +1 -1
  128. package/node_modules/@shikijs/langs/dist/twig.mjs +3 -3
  129. package/node_modules/@shikijs/langs/dist/typespec.mjs +1 -1
  130. package/node_modules/@shikijs/langs/node_modules/@shikijs/types/dist/index.d.mts +76 -76
  131. package/node_modules/@shikijs/langs/node_modules/@shikijs/types/package.json +1 -1
  132. package/node_modules/@shikijs/langs/package.json +3 -3
  133. package/package.json +6 -6
  134. package/node_modules/@pierre/diffs/node_modules/@shikijs/engine-javascript/dist/scanner-DX8LRFGE.mjs +0 -77
@@ -1 +1 @@
1
- {"version":3,"file":"renderDiffWithHighlighter.js","names":[],"sources":["../../src/utils/renderDiffWithHighlighter.ts"],"sourcesContent":["import { diffChars, diffWordsWithSpace } from 'diff';\n\nimport { DEFAULT_COLLAPSED_CONTEXT_THRESHOLD } 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 { appendItems } from './appendItems';\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 typeof options.theme === 'string'\n ? highlighter.getTheme(options.theme).type\n : undefined;\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 { maxLineDiffLength } = options;\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 maxLineDiffLength,\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 appendItems(code.deletionLines, 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 appendItems(code.additionLines, 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 maxLineDiffLength: number;\n}\n\nfunction computeLineDiffDecorations({\n deletionLine,\n additionLine,\n deletionLineIndex,\n additionLineIndex,\n deletionDecorations,\n additionDecorations,\n lineDiffType,\n maxLineDiffLength,\n}: ProcessLineDiffProps) {\n if (deletionLine == null || additionLine == null || lineDiffType === 'none') {\n return;\n }\n deletionLine = cleanLastNewline(deletionLine);\n additionLine = cleanLastNewline(additionLine);\n // If we have really long lines, we probably shouldn't compute diffs on them.\n if (\n deletionLine.length > maxLineDiffLength ||\n additionLine.length > maxLineDiffLength\n ) {\n return;\n }\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, ...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 options.useTokenTransformer\n );\n // tokenizeTimeLimit: 0 — never trade silently-wrong token colors for\n // latency; see renderFileWithHighlighter for the full rationale.\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 tokenizeTimeLimit: 0,\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 tokenizeTimeLimit: 0,\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":";;;;;;;;;;;;AA+BA,MAAM,6BAAwD,EAC5D,gBAAgB,MAClB;AAEA,SAAgB,0BACd,MACA,aACA,SACA,EACE,gBACA,cACA,YACA,eACA,4BAAA,MAC6B,4BACb;CAClB,IAAI,gBAAgB;EAClB,iBAAiB;EACjB,eAAe;CACjB,OAAO;EAKL,eAAe;EACf,aAAa;CACf;CACA,MAAM,sBAAsB,eAAe,KAAK,aAAa;CAC7D,MAAM,gBACJ,OAAO,QAAQ,UAAU,WACrB,YAAY,SAAS,QAAQ,KAAK,CAAC,CAAC,OACpC,KAAA;CACN,MAAM,cAAc,0BAA0B;EAC5C,OAAO,QAAQ;EACf;CACF,CAAC;CAMD,MAAM,eACJ,kBACA,CAAC,wBACA,KAAK,mBAAmB,OAAQ,KAAK,iBAAiB,OACnD,SACA,QAAQ;CAEd,MAAM,OAA8B;EAClC,eAAe,CAAC;EAChB,eAAe,CAAC;CAClB;CAEA,MAAM,EAAE,sBAAsB;CAC9B,MAAM,iBAAiB,CAAC,kBAAkB,CAAC,KAAK;CAChD,MAAM,4BAA4B,iBAAiB,gBAAgB,KAAA;CACnE,MAAM,0BAAU,IAAI,IAA0B;CAC9C,SAAS,iBAAiB,WAAmB;EAC3C,MAAM,QAAQ,i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names":[],"sources":["../../src/utils/renderDiffWithHighlighter.ts"],"sourcesContent":["import { type ChangeObject, diffChars, diffWordsWithSpace } from 'diff';\n\nimport { DEFAULT_COLLAPSED_CONTEXT_THRESHOLD } 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 { appendItems } from './appendItems';\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 typeof options.theme === 'string'\n ? highlighter.getTheme(options.theme).type\n : undefined;\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 { maxLineDiffLength } = options;\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 maxLineDiffLength,\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 appendItems(code.deletionLines, 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 appendItems(code.additionLines, additionLines);\n }\n }\n\n return { code, themeStyles, baseThemeType };\n}\n\n// The line indexes and decoration arrays a line diff writes its highlights to\ninterface LineDiffDecorationTargets {\n deletionLineIndex: number;\n additionLineIndex: number;\n deletionDecorations: DecorationItem[];\n additionDecorations: DecorationItem[];\n}\n\ninterface ProcessLineDiffProps extends LineDiffDecorationTargets {\n deletionLine: string | undefined;\n additionLine: string | undefined;\n lineDiffType: LineDiffTypes;\n maxLineDiffLength: number;\n}\n\n// Push one decoration per side covering the first through last changed\n// token, so each line only has one highlight. Offsets come straight from the\n// diff items, skipping the span arrays the other word modes build.\nfunction pushWordLineDecorations(\n lineDiff: ChangeObject<string>[],\n {\n deletionLineIndex,\n additionLineIndex,\n deletionDecorations,\n additionDecorations,\n }: LineDiffDecorationTargets\n): void {\n let deletionOffset = 0;\n let additionOffset = 0;\n let deletionStart = -1;\n let deletionEnd = 0;\n let additionStart = -1;\n let additionEnd = 0;\n for (const { value, added, removed } of lineDiff) {\n if (removed) {\n if (deletionStart === -1) deletionStart = deletionOffset;\n deletionOffset += value.length;\n deletionEnd = deletionOffset;\n } else if (added) {\n if (additionStart === -1) additionStart = additionOffset;\n additionOffset += value.length;\n additionEnd = additionOffset;\n } else {\n deletionOffset += value.length;\n additionOffset += value.length;\n }\n }\n if (deletionStart !== -1) {\n deletionDecorations.push(\n createDiffSpanDecoration({\n line: deletionLineIndex,\n spanStart: deletionStart,\n spanLength: deletionEnd - deletionStart,\n })\n );\n }\n if (additionStart !== -1) {\n additionDecorations.push(\n createDiffSpanDecoration({\n line: additionLineIndex,\n spanStart: additionStart,\n spanLength: additionEnd - additionStart,\n })\n );\n }\n}\n\nfunction computeLineDiffDecorations({\n deletionLine,\n additionLine,\n deletionLineIndex,\n additionLineIndex,\n deletionDecorations,\n additionDecorations,\n lineDiffType,\n maxLineDiffLength,\n}: ProcessLineDiffProps) {\n if (deletionLine == null || additionLine == null || lineDiffType === 'none') {\n return;\n }\n deletionLine = cleanLastNewline(deletionLine);\n additionLine = cleanLastNewline(additionLine);\n // If we have really long lines, we probably shouldn't compute diffs on them.\n if (\n deletionLine.length > maxLineDiffLength ||\n additionLine.length > maxLineDiffLength\n ) {\n return;\n }\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 if (lineDiffType === 'word-line') {\n pushWordLineDecorations(lineDiff, {\n deletionLineIndex,\n additionLineIndex,\n deletionDecorations,\n additionDecorations,\n });\n return;\n }\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, ...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 options.useTokenTransformer\n );\n // tokenizeTimeLimit: 0 — never trade silently-wrong token colors for\n // latency; see renderFileWithHighlighter for the full rationale.\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 tokenizeTimeLimit: 0,\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 tokenizeTimeLimit: 0,\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":";;;;;;;;;;;;AA+BA,MAAM,6BAAwD,EAC5D,gBAAgB,MAClB;AAEA,SAAgB,0BACd,MACA,aACA,SACA,EACE,gBACA,cACA,YACA,eACA,4BAAA,MAC6B,4BACb;CAClB,IAAI,gBAAgB;EAClB,iBAAiB;EACjB,eAAe;CACjB,OAAO;EAKL,eAAe;EACf,aAAa;CACf;CACA,MAAM,sBAAsB,eAAe,KAAK,aAAa;CAC7D,MAAM,gBACJ,OAAO,QAAQ,UAAU,WACrB,YAAY,SAAS,QAAQ,KAAK,CAAC,CAAC,OACpC,KAAA;CACN,MAAM,cAAc,0BAA0B;EAC5C,OAAO,QAAQ;EACf;CACF,CAAC;CAMD,MAAM,eACJ,kBACA,CAAC,wBACA,KAAK,mBAAmB,OAAQ,KAAK,iBAAiB,OACnD,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CAAC;CACrB;AACF;AAcA,SAAS,eAAe,EACtB,cACA,cACA,cACA,cACA,aACA,qBACA,qBACA,kBACA,SAAS,EAAE,OAAO,eAAe,GAAG,aACS;CAC7C,MAAM,eACJ,oBAAoB,wBAAwB,aAAa,IAAI;CAC/D,MAAM,eACJ,oBAAoB,wBAAwB,aAAa,IAAI;CAC/D,MAAM,EAAE,OAAO,iBAAiB,2BAC9B,QAAQ,mBACV;CAGA,MAAM,oBAAwD;EAC5D,OAAO,OAAO,kBAAkB,WAC5B;GACE,GAAG;GAEH,MAAM;GACN,OAAO;GACP;GACA,aAAa,KAAA;GACb,cAAc;GACd,mBAAmB,wBAAwB,OAAO;GAClD,mBAAmB;EACrB,IACA;GACE,GAAG;GAEH,MAAM;GACN,QAAQ;GACR;GACA,aAAa,KAAA;GACb,cAAc;GACd,mBAAmB,wBAAwB,OAAO;GAClD,mBAAmB;EACrB;CACN,EAAA,CAAG;CA+BH,OAAO;EAAE,sBA7BoB;GAC3B,IAAI,aAAa,aAAa,IAC5B,OAAO,CAAC;GAEV,WAAW,OAAO;GAClB,MAAM,WAAW;GACjB,WAAW,cAAc;GACzB,OAAO,aACL,YAAY,WACV,iBAAiB,aAAa,QAAQ,GACtC,UACF,CACF;EACF,EAAA,CAgBqB;EAAG,sBAfK;GAC3B,IAAI,aAAa,aAAa,IAC5B,OAAO,CAAC;GAEV,WAAW,OAAO;GAClB,WAAW,cAAc;GACzB,MAAM,WAAW;GACjB,OAAO,aACL,YAAY,WACV,iBAAiB,aAAa,QAAQ,GACtC,UACF,CACF;EACF,EAAA,CAEoC;CAAE;AACxC"}
@@ -13017,12 +13017,51 @@ function renderDiffWithHighlighter(diff, highlighter, options, { forcePlainText,
13017
13017
  baseThemeType
13018
13018
  };
13019
13019
  }
13020
+ function pushWordLineDecorations(lineDiff, { deletionLineIndex, additionLineIndex, deletionDecorations, additionDecorations }) {
13021
+ let deletionOffset = 0;
13022
+ let additionOffset = 0;
13023
+ let deletionStart = -1;
13024
+ let deletionEnd = 0;
13025
+ let additionStart = -1;
13026
+ let additionEnd = 0;
13027
+ for (const { value, added, removed } of lineDiff) if (removed) {
13028
+ if (deletionStart === -1) deletionStart = deletionOffset;
13029
+ deletionOffset += value.length;
13030
+ deletionEnd = deletionOffset;
13031
+ } else if (added) {
13032
+ if (additionStart === -1) additionStart = additionOffset;
13033
+ additionOffset += value.length;
13034
+ additionEnd = additionOffset;
13035
+ } else {
13036
+ deletionOffset += value.length;
13037
+ additionOffset += value.length;
13038
+ }
13039
+ if (deletionStart !== -1) deletionDecorations.push(createDiffSpanDecoration({
13040
+ line: deletionLineIndex,
13041
+ spanStart: deletionStart,
13042
+ spanLength: deletionEnd - deletionStart
13043
+ }));
13044
+ if (additionStart !== -1) additionDecorations.push(createDiffSpanDecoration({
13045
+ line: additionLineIndex,
13046
+ spanStart: additionStart,
13047
+ spanLength: additionEnd - additionStart
13048
+ }));
13049
+ }
13020
13050
  function computeLineDiffDecorations({ deletionLine, additionLine, deletionLineIndex, additionLineIndex, deletionDecorations, additionDecorations, lineDiffType, maxLineDiffLength }) {
13021
13051
  if (deletionLine == null || additionLine == null || lineDiffType === "none") return;
13022
13052
  deletionLine = cleanLastNewline(deletionLine);
13023
13053
  additionLine = cleanLastNewline(additionLine);
13024
13054
  if (deletionLine.length > maxLineDiffLength || additionLine.length > maxLineDiffLength) return;
13025
13055
  const lineDiff = lineDiffType === "char" ? diffChars(deletionLine, additionLine) : diffWordsWithSpace(deletionLine, additionLine);
13056
+ if (lineDiffType === "word-line") {
13057
+ pushWordLineDecorations(lineDiff, {
13058
+ deletionLineIndex,
13059
+ additionLineIndex,
13060
+ deletionDecorations,
13061
+ additionDecorations
13062
+ });
13063
+ return;
13064
+ }
13026
13065
  const deletionSpans = [];
13027
13066
  const additionSpans = [];
13028
13067
  const enableJoin = lineDiffType === "word-alt";