@pierre/diffs 1.0.7 → 1.1.0-beta.1

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 (128) hide show
  1. package/dist/components/File.d.ts +4 -2
  2. package/dist/components/File.d.ts.map +1 -1
  3. package/dist/components/File.js +80 -34
  4. package/dist/components/File.js.map +1 -1
  5. package/dist/components/FileDiff.d.ts +50 -28
  6. package/dist/components/FileDiff.d.ts.map +1 -1
  7. package/dist/components/FileDiff.js +220 -79
  8. package/dist/components/FileDiff.js.map +1 -1
  9. package/dist/components/FileStream.d.ts +1 -0
  10. package/dist/components/FileStream.d.ts.map +1 -1
  11. package/dist/components/FileStream.js +8 -4
  12. package/dist/components/FileStream.js.map +1 -1
  13. package/dist/constants.d.ts +8 -2
  14. package/dist/constants.d.ts.map +1 -1
  15. package/dist/constants.js +10 -1
  16. package/dist/constants.js.map +1 -1
  17. package/dist/index.d.ts +19 -10
  18. package/dist/index.js +14 -5
  19. package/dist/managers/LineSelectionManager.d.ts.map +1 -1
  20. package/dist/managers/LineSelectionManager.js +8 -9
  21. package/dist/managers/LineSelectionManager.js.map +1 -1
  22. package/dist/react/MultiFileDiff.js +2 -2
  23. package/dist/react/MultiFileDiff.js.map +1 -1
  24. package/dist/react/index.d.ts +2 -2
  25. package/dist/react/utils/renderDiffChildren.d.ts +4 -4
  26. package/dist/react/utils/renderDiffChildren.d.ts.map +1 -1
  27. package/dist/react/utils/renderDiffChildren.js +3 -3
  28. package/dist/react/utils/renderDiffChildren.js.map +1 -1
  29. package/dist/react/utils/useFileDiffInstance.js.map +1 -1
  30. package/dist/renderers/DiffHunksRenderer.d.ts +7 -6
  31. package/dist/renderers/DiffHunksRenderer.d.ts.map +1 -1
  32. package/dist/renderers/DiffHunksRenderer.js +263 -337
  33. package/dist/renderers/DiffHunksRenderer.js.map +1 -1
  34. package/dist/renderers/FileRenderer.d.ts +1 -0
  35. package/dist/renderers/FileRenderer.d.ts.map +1 -1
  36. package/dist/renderers/FileRenderer.js +11 -4
  37. package/dist/renderers/FileRenderer.js.map +1 -1
  38. package/dist/ssr/index.d.ts +2 -2
  39. package/dist/style.js +1 -1
  40. package/dist/style.js.map +1 -1
  41. package/dist/types.d.ts +246 -42
  42. package/dist/types.d.ts.map +1 -1
  43. package/dist/utils/areDiffLineAnnotationsEqual.d.ts +7 -0
  44. package/dist/utils/areDiffLineAnnotationsEqual.d.ts.map +1 -0
  45. package/dist/utils/areDiffLineAnnotationsEqual.js +8 -0
  46. package/dist/utils/areDiffLineAnnotationsEqual.js.map +1 -0
  47. package/dist/utils/areHunkDataEqual.d.ts +7 -0
  48. package/dist/utils/areHunkDataEqual.d.ts.map +1 -0
  49. package/dist/utils/areHunkDataEqual.js +8 -0
  50. package/dist/utils/areHunkDataEqual.js.map +1 -0
  51. package/dist/utils/areLineAnnotationsEqual.d.ts +7 -0
  52. package/dist/utils/areLineAnnotationsEqual.d.ts.map +1 -0
  53. package/dist/utils/areLineAnnotationsEqual.js +8 -0
  54. package/dist/utils/areLineAnnotationsEqual.js.map +1 -0
  55. package/dist/utils/arePrePropertiesEqual.d.ts +7 -0
  56. package/dist/utils/arePrePropertiesEqual.d.ts.map +1 -0
  57. package/dist/utils/arePrePropertiesEqual.js +9 -0
  58. package/dist/utils/arePrePropertiesEqual.js.map +1 -0
  59. package/dist/utils/areRenderRangesEqual.d.ts +7 -0
  60. package/dist/utils/areRenderRangesEqual.d.ts.map +1 -0
  61. package/dist/utils/areRenderRangesEqual.js +9 -0
  62. package/dist/utils/areRenderRangesEqual.js.map +1 -0
  63. package/dist/utils/areVirtualWindowSpecsEqual.d.ts +7 -0
  64. package/dist/utils/areVirtualWindowSpecsEqual.d.ts.map +1 -0
  65. package/dist/utils/areVirtualWindowSpecsEqual.js +9 -0
  66. package/dist/utils/areVirtualWindowSpecsEqual.js.map +1 -0
  67. package/dist/utils/areWorkerStatsEqual.d.ts +8 -0
  68. package/dist/utils/areWorkerStatsEqual.d.ts.map +1 -0
  69. package/dist/utils/areWorkerStatsEqual.js +9 -0
  70. package/dist/utils/areWorkerStatsEqual.js.map +1 -0
  71. package/dist/utils/createTransformerWithState.js +1 -1
  72. package/dist/utils/createTransformerWithState.js.map +1 -1
  73. package/dist/utils/createWindowFromScrollPosition.d.ts +22 -0
  74. package/dist/utils/createWindowFromScrollPosition.d.ts.map +1 -0
  75. package/dist/utils/createWindowFromScrollPosition.js +26 -0
  76. package/dist/utils/createWindowFromScrollPosition.js.map +1 -0
  77. package/dist/utils/diffAcceptRejectHunk.js +36 -21
  78. package/dist/utils/diffAcceptRejectHunk.js.map +1 -1
  79. package/dist/utils/getOrCreateCodeNode.d.ts +14 -0
  80. package/dist/utils/getOrCreateCodeNode.d.ts.map +1 -0
  81. package/dist/utils/getOrCreateCodeNode.js +13 -0
  82. package/dist/utils/getOrCreateCodeNode.js.map +1 -0
  83. package/dist/utils/getTotalLineCountFromHunks.js +1 -1
  84. package/dist/utils/getTotalLineCountFromHunks.js.map +1 -1
  85. package/dist/utils/hast_utils.d.ts +2 -1
  86. package/dist/utils/hast_utils.d.ts.map +1 -1
  87. package/dist/utils/hast_utils.js +10 -1
  88. package/dist/utils/hast_utils.js.map +1 -1
  89. package/dist/utils/isDefaultRenderRange.d.ts +7 -0
  90. package/dist/utils/isDefaultRenderRange.d.ts.map +1 -0
  91. package/dist/utils/isDefaultRenderRange.js +8 -0
  92. package/dist/utils/isDefaultRenderRange.js.map +1 -0
  93. package/dist/utils/iterateOverDiff.d.ts +39 -0
  94. package/dist/utils/iterateOverDiff.d.ts.map +1 -0
  95. package/dist/utils/iterateOverDiff.js +356 -0
  96. package/dist/utils/iterateOverDiff.js.map +1 -0
  97. package/dist/utils/parseDiffFromFile.d.ts.map +1 -1
  98. package/dist/utils/parseDiffFromFile.js +8 -6
  99. package/dist/utils/parseDiffFromFile.js.map +1 -1
  100. package/dist/utils/parsePatchFiles.d.ts +15 -3
  101. package/dist/utils/parsePatchFiles.d.ts.map +1 -1
  102. package/dist/utils/parsePatchFiles.js +207 -158
  103. package/dist/utils/parsePatchFiles.js.map +1 -1
  104. package/dist/utils/processLine.js +4 -3
  105. package/dist/utils/processLine.js.map +1 -1
  106. package/dist/utils/renderDiffWithHighlighter.d.ts +7 -2
  107. package/dist/utils/renderDiffWithHighlighter.d.ts.map +1 -1
  108. package/dist/utils/renderDiffWithHighlighter.js +149 -227
  109. package/dist/utils/renderDiffWithHighlighter.js.map +1 -1
  110. package/dist/utils/setWrapperNodeProps.d.ts +3 -7
  111. package/dist/utils/setWrapperNodeProps.d.ts.map +1 -1
  112. package/dist/utils/setWrapperNodeProps.js +1 -1
  113. package/dist/utils/setWrapperNodeProps.js.map +1 -1
  114. package/dist/worker/WorkerPoolManager.d.ts +9 -2
  115. package/dist/worker/WorkerPoolManager.d.ts.map +1 -1
  116. package/dist/worker/WorkerPoolManager.js +124 -45
  117. package/dist/worker/WorkerPoolManager.js.map +1 -1
  118. package/dist/worker/types.d.ts +7 -0
  119. package/dist/worker/types.d.ts.map +1 -1
  120. package/dist/worker/worker-portable.js +634 -242
  121. package/dist/worker/worker-portable.js.map +1 -1
  122. package/dist/worker/worker.js +511 -231
  123. package/dist/worker/worker.js.map +1 -1
  124. package/package.json +20 -1
  125. package/dist/utils/createCodeNode.d.ts +0 -12
  126. package/dist/utils/createCodeNode.d.ts.map +0 -1
  127. package/dist/utils/createCodeNode.js +0 -12
  128. package/dist/utils/createCodeNode.js.map +0 -1
@@ -11680,6 +11680,15 @@ const DEFAULT_THEMES = {
11680
11680
  };
11681
11681
  const UNSAFE_CSS_ATTRIBUTE = "data-unsafe-css";
11682
11682
  const CORE_CSS_ATTRIBUTE = "data-core-css";
11683
+ const LINE_HUNK_COUNT = 10;
11684
+ const LINE_HEIGHT = 20;
11685
+ const DIFF_HEADER_HEIGHT = 44;
11686
+ const HUNK_SEPARATOR_HEIGHT = 32;
11687
+ const FILE_GAP = 8;
11688
+ const DEFAULT_EXPANDED_REGION = Object.freeze({
11689
+ fromStart: 0,
11690
+ fromEnd: 0
11691
+ });
11683
11692
 
11684
11693
  //#endregion
11685
11694
  //#region src/highlighter/languages/constants.ts
@@ -13813,18 +13822,28 @@ function findCodeElement(nodes) {
13813
13822
  }
13814
13823
  return undefined;
13815
13824
  }
13825
+ function createBufferElement(type, height) {
13826
+ return createHastElement({
13827
+ tagName: "div",
13828
+ properties: {
13829
+ "data-virtualized-buffer": type,
13830
+ style: `height: ${height}px`
13831
+ }
13832
+ });
13833
+ }
13816
13834
 
13817
13835
  //#endregion
13818
13836
  //#region src/utils/processLine.ts
13819
13837
  function processLine(node, line, state) {
13820
- const lineInfo = typeof state.lineInfo === "function" ? state.lineInfo(line) : state.lineInfo[line];
13838
+ const lineInfo = typeof state.lineInfo === "function" ? state.lineInfo(line) : state.lineInfo[line - 1];
13821
13839
  if (lineInfo == null) {
13822
- console.error({
13840
+ const errorMessage = `processLine: line ${line}, contains no state.lineInfo`;
13841
+ console.error(errorMessage, {
13823
13842
  node,
13824
13843
  line,
13825
13844
  state
13826
13845
  });
13827
- throw new Error(`processLine: line ${line}, contains no state.lineInfo`);
13846
+ throw new Error(errorMessage);
13828
13847
  }
13829
13848
  node.tagName = "span";
13830
13849
  node.properties["data-column-content"] = "";
@@ -13858,7 +13877,7 @@ function processLine(node, line, state) {
13858
13877
  //#endregion
13859
13878
  //#region src/utils/createTransformerWithState.ts
13860
13879
  function createTransformerWithState(useCSSClasses = false) {
13861
- const state = { lineInfo: {} };
13880
+ const state = { lineInfo: [] };
13862
13881
  const transformers = [{
13863
13882
  line(node) {
13864
13883
  delete node.properties.class;
@@ -14334,6 +14353,451 @@ function getLineNodes(nodes) {
14334
14353
  throw new Error("getLineNodes: Unable to find children");
14335
14354
  }
14336
14355
 
14356
+ //#endregion
14357
+ //#region src/utils/iterateOverDiff.ts
14358
+ function iterateOverDiff({ diff, diffStyle, startingLine = 0, totalLines = Infinity, expandedHunks, callback }) {
14359
+ const state = {
14360
+ finalHunk: diff.hunks.at(-1),
14361
+ viewportStart: startingLine,
14362
+ viewportEnd: startingLine + totalLines,
14363
+ isWindowedHighlight: startingLine > 0 || totalLines < Infinity,
14364
+ splitCount: 0,
14365
+ unifiedCount: 0,
14366
+ shouldBreak() {
14367
+ if (!state.isWindowedHighlight) {
14368
+ return false;
14369
+ }
14370
+ const breakUnified = state.unifiedCount >= startingLine + totalLines;
14371
+ const breakSplit = state.splitCount >= startingLine + totalLines;
14372
+ if (diffStyle === "unified") {
14373
+ return breakUnified;
14374
+ } else if (diffStyle === "split") {
14375
+ return breakSplit;
14376
+ } else {
14377
+ return breakUnified && breakSplit;
14378
+ }
14379
+ },
14380
+ shouldSkip(unifiedHeight, splitHeight) {
14381
+ if (!state.isWindowedHighlight) {
14382
+ return false;
14383
+ }
14384
+ const skipUnified = state.unifiedCount + unifiedHeight < startingLine;
14385
+ const skipSplit = state.splitCount + splitHeight < startingLine;
14386
+ if (diffStyle === "unified") {
14387
+ return skipUnified;
14388
+ } else if (diffStyle === "split") {
14389
+ return skipSplit;
14390
+ } else {
14391
+ return skipUnified && skipSplit;
14392
+ }
14393
+ },
14394
+ incrementCounts(unifiedValue, splitValue) {
14395
+ if (diffStyle === "unified" || diffStyle === "both") {
14396
+ state.unifiedCount += unifiedValue;
14397
+ }
14398
+ if (diffStyle === "split" || diffStyle === "both") {
14399
+ state.splitCount += splitValue;
14400
+ }
14401
+ },
14402
+ isInWindow(unifiedHeight, splitHeight) {
14403
+ if (!state.isWindowedHighlight) {
14404
+ return true;
14405
+ }
14406
+ const unifiedInWindow = state.isInUnifiedWindow(unifiedHeight);
14407
+ const splitInWindow = state.isInSplitWindow(splitHeight);
14408
+ if (diffStyle === "unified") {
14409
+ return unifiedInWindow;
14410
+ } else if (diffStyle === "split") {
14411
+ return splitInWindow;
14412
+ } else {
14413
+ return unifiedInWindow || splitInWindow;
14414
+ }
14415
+ },
14416
+ isInUnifiedWindow(unifiedHeight) {
14417
+ return !state.isWindowedHighlight || state.unifiedCount >= startingLine - unifiedHeight && state.unifiedCount < startingLine + totalLines;
14418
+ },
14419
+ isInSplitWindow(splitHeight) {
14420
+ return !state.isWindowedHighlight || state.splitCount >= startingLine - splitHeight && state.splitCount < startingLine + totalLines;
14421
+ },
14422
+ emit(props, silent = false) {
14423
+ if (!silent) {
14424
+ if (diffStyle === "unified") {
14425
+ state.incrementCounts(1, 0);
14426
+ } else if (diffStyle === "split") {
14427
+ state.incrementCounts(0, 1);
14428
+ } else {
14429
+ state.incrementCounts(1, 1);
14430
+ }
14431
+ }
14432
+ return callback(props) ?? false;
14433
+ }
14434
+ };
14435
+ hunkIterator: for (const [hunkIndex, hunk] of diff.hunks.entries()) {
14436
+ if (state.shouldBreak()) {
14437
+ break;
14438
+ }
14439
+ const leadingRegion = getExpandedRegion(diff.isPartial, hunk.collapsedBefore, expandedHunks, hunkIndex);
14440
+ const trailingRegion = (() => {
14441
+ if (hunk !== state.finalHunk || !hasFinalCollapsedHunk(diff)) {
14442
+ return undefined;
14443
+ }
14444
+ const additionRemaining = diff.additionLines.length - (hunk.additionLineIndex + hunk.additionCount);
14445
+ const deletionRemaining = diff.deletionLines.length - (hunk.deletionLineIndex + hunk.deletionCount);
14446
+ if (additionRemaining !== deletionRemaining) {
14447
+ throw new Error(`iterateOverDiff: trailing context mismatch (additions=${additionRemaining}, deletions=${deletionRemaining}) for ${diff.name}`);
14448
+ }
14449
+ const trailingRangeSize = Math.min(additionRemaining, deletionRemaining);
14450
+ return getExpandedRegion(diff.isPartial, trailingRangeSize, expandedHunks, diff.hunks.length);
14451
+ })();
14452
+ const expandedLineCount = leadingRegion.fromStart + leadingRegion.fromEnd;
14453
+ function getTrailingCollapsedAfter(unifiedLineIndex$1, splitLineIndex$1) {
14454
+ if (trailingRegion == null || trailingRegion.collapsedLines <= 0 || trailingRegion.fromStart + trailingRegion.fromEnd > 0) {
14455
+ return 0;
14456
+ }
14457
+ if (diffStyle === "unified") {
14458
+ return unifiedLineIndex$1 === hunk.unifiedLineStart + hunk.unifiedLineCount - 1 ? trailingRegion.collapsedLines : 0;
14459
+ }
14460
+ return splitLineIndex$1 === hunk.splitLineStart + hunk.splitLineCount - 1 ? trailingRegion.collapsedLines : 0;
14461
+ }
14462
+ function getPendingCollapsed() {
14463
+ if (leadingRegion.collapsedLines === 0) {
14464
+ return 0;
14465
+ }
14466
+ const value = leadingRegion.collapsedLines;
14467
+ leadingRegion.collapsedLines = 0;
14468
+ return value;
14469
+ }
14470
+ if (!state.shouldSkip(expandedLineCount, expandedLineCount)) {
14471
+ let unifiedLineIndex$1 = hunk.unifiedLineStart - leadingRegion.rangeSize;
14472
+ let splitLineIndex$1 = hunk.splitLineStart - leadingRegion.rangeSize;
14473
+ let deletionLineIndex$1 = hunk.deletionLineIndex - leadingRegion.rangeSize;
14474
+ let additionLineIndex$1 = hunk.additionLineIndex - leadingRegion.rangeSize;
14475
+ let deletionLineNumber$1 = hunk.deletionStart - leadingRegion.rangeSize;
14476
+ let additionLineNumber$1 = hunk.additionStart - leadingRegion.rangeSize;
14477
+ let index = 0;
14478
+ while (index < leadingRegion.fromStart) {
14479
+ if (state.isInWindow(0, 0)) {
14480
+ if (state.emit({
14481
+ hunkIndex,
14482
+ hunk,
14483
+ collapsedBefore: 0,
14484
+ collapsedAfter: 0,
14485
+ unifiedDeletionLineIndex: unifiedLineIndex$1 + index,
14486
+ unifiedAdditionLineIndex: unifiedLineIndex$1 + index,
14487
+ splitLineIndex: splitLineIndex$1 + index,
14488
+ deletionLineIndex: deletionLineIndex$1 + index,
14489
+ additionLineIndex: additionLineIndex$1 + index,
14490
+ deletionLineNumber: deletionLineNumber$1 + index,
14491
+ additionLineNumber: additionLineNumber$1 + index,
14492
+ type: "context-expanded",
14493
+ noEOFCRAddition: false,
14494
+ noEOFCRDeletion: false
14495
+ })) {
14496
+ break hunkIterator;
14497
+ }
14498
+ } else {
14499
+ state.incrementCounts(1, 1);
14500
+ }
14501
+ index++;
14502
+ }
14503
+ unifiedLineIndex$1 = hunk.unifiedLineStart - leadingRegion.fromEnd;
14504
+ splitLineIndex$1 = hunk.splitLineStart - leadingRegion.fromEnd;
14505
+ deletionLineIndex$1 = hunk.deletionLineIndex - leadingRegion.fromEnd;
14506
+ additionLineIndex$1 = hunk.additionLineIndex - leadingRegion.fromEnd;
14507
+ deletionLineNumber$1 = hunk.deletionStart - leadingRegion.fromEnd;
14508
+ additionLineNumber$1 = hunk.additionStart - leadingRegion.fromEnd;
14509
+ index = 0;
14510
+ while (index < leadingRegion.fromEnd) {
14511
+ if (state.isInWindow(0, 0)) {
14512
+ if (state.emit({
14513
+ hunkIndex,
14514
+ hunk,
14515
+ collapsedBefore: getPendingCollapsed(),
14516
+ collapsedAfter: 0,
14517
+ unifiedDeletionLineIndex: unifiedLineIndex$1 + index,
14518
+ unifiedAdditionLineIndex: unifiedLineIndex$1 + index,
14519
+ splitLineIndex: splitLineIndex$1 + index,
14520
+ deletionLineIndex: deletionLineIndex$1 + index,
14521
+ additionLineIndex: additionLineIndex$1 + index,
14522
+ deletionLineNumber: deletionLineNumber$1 + index,
14523
+ additionLineNumber: additionLineNumber$1 + index,
14524
+ type: "context-expanded",
14525
+ noEOFCRAddition: false,
14526
+ noEOFCRDeletion: false
14527
+ })) {
14528
+ break hunkIterator;
14529
+ }
14530
+ } else {
14531
+ state.incrementCounts(1, 1);
14532
+ }
14533
+ index++;
14534
+ }
14535
+ } else {
14536
+ state.incrementCounts(expandedLineCount, expandedLineCount);
14537
+ getPendingCollapsed();
14538
+ }
14539
+ let unifiedLineIndex = hunk.unifiedLineStart;
14540
+ let splitLineIndex = hunk.splitLineStart;
14541
+ let deletionLineIndex = hunk.deletionLineIndex;
14542
+ let additionLineIndex = hunk.additionLineIndex;
14543
+ let deletionLineNumber = hunk.deletionStart;
14544
+ let additionLineNumber = hunk.additionStart;
14545
+ const lastContent = hunk.hunkContent.at(-1);
14546
+ for (const content of hunk.hunkContent) {
14547
+ if (state.shouldBreak()) {
14548
+ break hunkIterator;
14549
+ }
14550
+ const isLastContent = content === lastContent;
14551
+ if (content.type === "context") {
14552
+ if (!state.shouldSkip(content.lines, content.lines)) {
14553
+ let index = 0;
14554
+ while (index < content.lines) {
14555
+ if (state.isInWindow(0, 0)) {
14556
+ const isLastLine = isLastContent && index === content.lines - 1;
14557
+ const unifiedRowIndex = unifiedLineIndex + index;
14558
+ const splitRowIndex = splitLineIndex + index;
14559
+ if (state.emit({
14560
+ hunkIndex,
14561
+ hunk,
14562
+ collapsedBefore: getPendingCollapsed(),
14563
+ collapsedAfter: getTrailingCollapsedAfter(unifiedRowIndex, splitRowIndex),
14564
+ unifiedDeletionLineIndex: unifiedRowIndex,
14565
+ unifiedAdditionLineIndex: unifiedRowIndex,
14566
+ splitLineIndex: splitRowIndex,
14567
+ deletionLineIndex: deletionLineIndex + index,
14568
+ additionLineIndex: additionLineIndex + index,
14569
+ deletionLineNumber: deletionLineNumber + index,
14570
+ additionLineNumber: additionLineNumber + index,
14571
+ type: "context",
14572
+ noEOFCRAddition: isLastLine && hunk.noEOFCRAdditions,
14573
+ noEOFCRDeletion: isLastLine && hunk.noEOFCRDeletions
14574
+ })) {
14575
+ break hunkIterator;
14576
+ }
14577
+ } else {
14578
+ state.incrementCounts(1, 1);
14579
+ }
14580
+ index++;
14581
+ }
14582
+ } else {
14583
+ state.incrementCounts(content.lines, content.lines);
14584
+ getPendingCollapsed();
14585
+ }
14586
+ unifiedLineIndex += content.lines;
14587
+ splitLineIndex += content.lines;
14588
+ deletionLineIndex += content.lines;
14589
+ additionLineIndex += content.lines;
14590
+ deletionLineNumber += content.lines;
14591
+ additionLineNumber += content.lines;
14592
+ } else {
14593
+ const splitCount = Math.max(content.deletions, content.additions);
14594
+ const unifiedCount = content.deletions + content.additions;
14595
+ const shouldSkipChange = state.shouldSkip(unifiedCount, splitCount);
14596
+ if (!shouldSkipChange) {
14597
+ const iterationRanges = getChangeIterationRanges(state, content, diffStyle);
14598
+ for (const [rangeStart, rangeEnd] of iterationRanges) {
14599
+ for (let index = rangeStart; index < rangeEnd; index++) {
14600
+ const unifiedRowIndex = unifiedLineIndex + index;
14601
+ const splitRowIndex = diffStyle === "unified" ? splitLineIndex + (index < content.deletions ? index : index - content.deletions) : splitLineIndex + index;
14602
+ const collapsedAfter = getTrailingCollapsedAfter(unifiedRowIndex, splitRowIndex);
14603
+ if (state.emit(getChangeLineData({
14604
+ hunkIndex,
14605
+ hunk,
14606
+ collapsedBefore: getPendingCollapsed(),
14607
+ collapsedAfter,
14608
+ diffStyle,
14609
+ index,
14610
+ unifiedLineIndex,
14611
+ splitLineIndex,
14612
+ additionLineIndex,
14613
+ deletionLineIndex,
14614
+ additionLineNumber,
14615
+ deletionLineNumber,
14616
+ content,
14617
+ isLastContent,
14618
+ unifiedCount,
14619
+ splitCount
14620
+ }), true)) {
14621
+ break hunkIterator;
14622
+ }
14623
+ }
14624
+ }
14625
+ }
14626
+ getPendingCollapsed();
14627
+ state.incrementCounts(unifiedCount, splitCount);
14628
+ unifiedLineIndex += unifiedCount;
14629
+ splitLineIndex += splitCount;
14630
+ deletionLineIndex += content.deletions;
14631
+ additionLineIndex += content.additions;
14632
+ deletionLineNumber += content.deletions;
14633
+ additionLineNumber += content.additions;
14634
+ }
14635
+ }
14636
+ if (trailingRegion != null) {
14637
+ const { collapsedLines, fromStart, fromEnd } = trailingRegion;
14638
+ const len = fromStart + fromEnd;
14639
+ let index = 0;
14640
+ while (index < len) {
14641
+ if (state.shouldBreak()) {
14642
+ break hunkIterator;
14643
+ }
14644
+ if (state.isInWindow(0, 0)) {
14645
+ const isLastLine = index === len - 1;
14646
+ if (state.emit({
14647
+ hunkIndex: diff.hunks.length,
14648
+ hunk: undefined,
14649
+ collapsedBefore: 0,
14650
+ collapsedAfter: isLastLine ? collapsedLines : 0,
14651
+ unifiedDeletionLineIndex: unifiedLineIndex + index,
14652
+ unifiedAdditionLineIndex: unifiedLineIndex + index,
14653
+ splitLineIndex: splitLineIndex + index,
14654
+ additionLineIndex: additionLineIndex + index,
14655
+ deletionLineIndex: deletionLineIndex + index,
14656
+ additionLineNumber: additionLineNumber + index,
14657
+ deletionLineNumber: deletionLineNumber + index,
14658
+ type: "context-expanded",
14659
+ noEOFCRAddition: false,
14660
+ noEOFCRDeletion: false
14661
+ })) {
14662
+ break hunkIterator;
14663
+ }
14664
+ } else {
14665
+ state.incrementCounts(1, 1);
14666
+ }
14667
+ index++;
14668
+ }
14669
+ }
14670
+ }
14671
+ }
14672
+ function getExpandedRegion(isPartial, rangeSize, expandedHunks, hunkIndex) {
14673
+ rangeSize = Math.max(rangeSize, 0);
14674
+ if (rangeSize === 0 || isPartial) {
14675
+ return {
14676
+ fromStart: 0,
14677
+ fromEnd: 0,
14678
+ rangeSize,
14679
+ collapsedLines: Math.max(rangeSize, 0)
14680
+ };
14681
+ }
14682
+ if (expandedHunks === true) {
14683
+ return {
14684
+ fromStart: rangeSize,
14685
+ fromEnd: 0,
14686
+ rangeSize,
14687
+ collapsedLines: 0
14688
+ };
14689
+ }
14690
+ const region = expandedHunks?.get(hunkIndex);
14691
+ const fromStart = Math.min(Math.max(region?.fromStart ?? 0, 0), rangeSize);
14692
+ const fromEnd = Math.min(Math.max(region?.fromEnd ?? 0, 0), rangeSize);
14693
+ const expandedCount = fromStart + fromEnd;
14694
+ const renderAll = expandedCount >= rangeSize;
14695
+ return {
14696
+ fromStart: renderAll ? rangeSize : fromStart,
14697
+ fromEnd: renderAll ? 0 : fromEnd,
14698
+ rangeSize,
14699
+ collapsedLines: Math.max(rangeSize - expandedCount, 0)
14700
+ };
14701
+ }
14702
+ function hasFinalCollapsedHunk(diff) {
14703
+ const lastHunk = diff.hunks.at(-1);
14704
+ if (lastHunk == null || diff.isPartial || diff.additionLines.length === 0 || diff.deletionLines.length === 0) {
14705
+ return false;
14706
+ }
14707
+ return lastHunk.additionLineIndex + lastHunk.additionCount < diff.additionLines.length || lastHunk.deletionLineIndex + lastHunk.deletionCount < diff.deletionLines.length;
14708
+ }
14709
+ function getChangeIterationRanges(state, content, diffStyle) {
14710
+ if (!state.isWindowedHighlight) {
14711
+ return [[0, diffStyle === "unified" ? content.deletions + content.additions : Math.max(content.deletions, content.additions)]];
14712
+ }
14713
+ const useUnified = diffStyle !== "split";
14714
+ const useSplit = diffStyle !== "unified";
14715
+ const iterationSpace = diffStyle === "unified" ? "unified" : "split";
14716
+ const iterationRanges = [];
14717
+ function getVisibleRange(start, count) {
14718
+ const end = start + count;
14719
+ if (end <= state.viewportStart || start >= state.viewportEnd) {
14720
+ return undefined;
14721
+ }
14722
+ const visibleStart = Math.max(0, state.viewportStart - start);
14723
+ const visibleEnd = Math.min(count, state.viewportEnd - start);
14724
+ return visibleEnd > visibleStart ? [visibleStart, visibleEnd] : undefined;
14725
+ }
14726
+ function mapRangeToIteration(range$1, kind) {
14727
+ if (iterationSpace === "split") {
14728
+ return range$1;
14729
+ }
14730
+ return kind === "additions" ? [range$1[0] + content.deletions, range$1[1] + content.deletions] : range$1;
14731
+ }
14732
+ function pushRange(range$1, kind) {
14733
+ if (range$1 == null) {
14734
+ return;
14735
+ }
14736
+ const [start, end] = mapRangeToIteration(range$1, kind);
14737
+ if (end > start) {
14738
+ iterationRanges.push([start, end]);
14739
+ }
14740
+ }
14741
+ if (useUnified) {
14742
+ pushRange(getVisibleRange(state.unifiedCount, content.deletions), "deletions");
14743
+ pushRange(getVisibleRange(state.unifiedCount + content.deletions, content.additions), "additions");
14744
+ }
14745
+ if (useSplit) {
14746
+ pushRange(getVisibleRange(state.splitCount, content.deletions), "deletions");
14747
+ pushRange(getVisibleRange(state.splitCount, content.additions), "additions");
14748
+ }
14749
+ if (iterationRanges.length === 0) {
14750
+ return iterationRanges;
14751
+ }
14752
+ iterationRanges.sort((a$1, b$2) => a$1[0] - b$2[0]);
14753
+ const merged = [iterationRanges[0]];
14754
+ for (const [start, end] of iterationRanges.slice(1)) {
14755
+ const last = merged[merged.length - 1];
14756
+ if (start <= last[1]) {
14757
+ last[1] = Math.max(last[1], end);
14758
+ } else {
14759
+ merged.push([start, end]);
14760
+ }
14761
+ }
14762
+ return merged;
14763
+ }
14764
+ function getChangeLineData({ hunkIndex, hunk, collapsedAfter, collapsedBefore, diffStyle, index, unifiedLineIndex, splitLineIndex, additionLineIndex, deletionLineIndex, additionLineNumber, deletionLineNumber, content, isLastContent, unifiedCount, splitCount }) {
14765
+ if (diffStyle === "unified") {
14766
+ return {
14767
+ type: "change",
14768
+ hunkIndex,
14769
+ hunk,
14770
+ collapsedAfter,
14771
+ collapsedBefore,
14772
+ unifiedDeletionLineIndex: index < content.deletions ? unifiedLineIndex + index : undefined,
14773
+ unifiedAdditionLineIndex: index >= content.deletions ? unifiedLineIndex + index : undefined,
14774
+ splitLineIndex: splitLineIndex + (index < content.deletions ? index : index - content.deletions),
14775
+ additionLineIndex: index >= content.deletions ? additionLineIndex + (index - content.deletions) : undefined,
14776
+ additionLineNumber: index >= content.deletions ? additionLineNumber + (index - content.deletions) : undefined,
14777
+ deletionLineIndex: index < content.deletions ? deletionLineIndex + index : undefined,
14778
+ deletionLineNumber: index < content.deletions ? deletionLineNumber + index : undefined,
14779
+ noEOFCRDeletion: isLastContent && index === content.deletions - 1 && hunk.noEOFCRDeletions,
14780
+ noEOFCRAddition: isLastContent && index === unifiedCount - 1 && hunk.noEOFCRAdditions
14781
+ };
14782
+ }
14783
+ return {
14784
+ type: "change",
14785
+ hunkIndex,
14786
+ hunk,
14787
+ collapsedAfter,
14788
+ collapsedBefore,
14789
+ unifiedDeletionLineIndex: index < content.deletions ? unifiedLineIndex + index : undefined,
14790
+ unifiedAdditionLineIndex: index < content.additions ? unifiedLineIndex + content.deletions + index : undefined,
14791
+ splitLineIndex: splitLineIndex + index,
14792
+ additionLineIndex: index < content.additions ? additionLineIndex + index : undefined,
14793
+ additionLineNumber: index < content.additions ? additionLineNumber + index : undefined,
14794
+ deletionLineIndex: index < content.deletions ? deletionLineIndex + index : undefined,
14795
+ deletionLineNumber: index < content.deletions ? deletionLineNumber + index : undefined,
14796
+ noEOFCRDeletion: isLastContent && index === splitCount - 1 && hunk.noEOFCRDeletions,
14797
+ noEOFCRAddition: isLastContent && index === splitCount - 1 && hunk.noEOFCRAdditions
14798
+ };
14799
+ }
14800
+
14337
14801
  //#endregion
14338
14802
  //#region src/utils/parseDiffDecorations.ts
14339
14803
  function createDiffSpanDecoration({ line, spanStart, spanLength }) {
@@ -14366,7 +14830,16 @@ function pushOrJoinSpan({ item, arr, enableJoin, isNeutral = false, isLastItem =
14366
14830
 
14367
14831
  //#endregion
14368
14832
  //#region src/utils/renderDiffWithHighlighter.ts
14369
- function renderDiffWithHighlighter(diff, highlighter$1, options, forcePlainText = false) {
14833
+ const DEFAULT_PLAIN_TEXT_OPTIONS = { forcePlainText: false };
14834
+ function renderDiffWithHighlighter(diff, highlighter$1, options, { forcePlainText, startingLine, totalLines, expandedHunks } = DEFAULT_PLAIN_TEXT_OPTIONS) {
14835
+ if (forcePlainText) {
14836
+ startingLine ??= 0;
14837
+ totalLines ??= Infinity;
14838
+ } else {
14839
+ startingLine = 0;
14840
+ totalLines = Infinity;
14841
+ }
14842
+ const isWindowedHighlight = startingLine > 0 || totalLines < Infinity;
14370
14843
  const baseThemeType = (() => {
14371
14844
  const theme = options.theme ?? DEFAULT_THEMES;
14372
14845
  if (typeof theme === "string") {
@@ -14378,100 +14851,140 @@ function renderDiffWithHighlighter(diff, highlighter$1, options, forcePlainText
14378
14851
  theme: options.theme,
14379
14852
  highlighter: highlighter$1
14380
14853
  });
14381
- if (diff.newLines != null && diff.oldLines != null) {
14382
- const { oldContent, newContent, oldInfo, newInfo, oldDecorations, newDecorations } = processLines({
14383
- hunks: diff.hunks,
14384
- oldLines: diff.oldLines,
14385
- newLines: diff.newLines,
14386
- lineDiffType: options.lineDiffType
14387
- });
14388
- const oldFile = {
14854
+ const lineDiffType = forcePlainText && !isWindowedHighlight && (diff.unifiedLineCount > 1e3 || diff.splitLineCount > 1e3) ? "none" : options.lineDiffType;
14855
+ const code = {
14856
+ deletionLines: [],
14857
+ additionLines: []
14858
+ };
14859
+ const shouldGroupAll = !forcePlainText && !diff.isPartial;
14860
+ const expandedHunksForIteration = forcePlainText ? expandedHunks : undefined;
14861
+ const buckets = new Map();
14862
+ function getBucketForHunk(hunkIndex) {
14863
+ const index = shouldGroupAll ? 0 : hunkIndex;
14864
+ const bucket = buckets.get(index) ?? createBucket();
14865
+ buckets.set(index, bucket);
14866
+ return bucket;
14867
+ }
14868
+ function appendContent(lineContent, lineIndex, segments, contentWrapper) {
14869
+ if (isWindowedHighlight) {
14870
+ let segment = segments.at(-1);
14871
+ if (segment == null || segment.targetIndex + segment.count !== lineIndex) {
14872
+ segment = {
14873
+ targetIndex: lineIndex,
14874
+ originalOffset: contentWrapper.length,
14875
+ count: 0
14876
+ };
14877
+ segments.push(segment);
14878
+ }
14879
+ segment.count++;
14880
+ }
14881
+ contentWrapper.push(lineContent);
14882
+ }
14883
+ iterateOverDiff({
14884
+ diff,
14885
+ diffStyle: "both",
14886
+ startingLine,
14887
+ totalLines,
14888
+ expandedHunks: isWindowedHighlight ? expandedHunksForIteration : true,
14889
+ callback: ({ hunkIndex, additionLineIndex, deletionLineIndex, additionLineNumber, deletionLineNumber, unifiedAdditionLineIndex, unifiedDeletionLineIndex, splitLineIndex, type }) => {
14890
+ const bucket = getBucketForHunk(hunkIndex);
14891
+ if (type === "change" && lineDiffType !== "none" && additionLineIndex != null && deletionLineIndex != null) {
14892
+ computeLineDiffDecorations({
14893
+ additionLine: diff.additionLines[additionLineIndex],
14894
+ deletionLine: diff.deletionLines[deletionLineIndex],
14895
+ deletionLineIndex: bucket.deletionContent.length,
14896
+ additionLineIndex: bucket.additionContent.length,
14897
+ deletionDecorations: bucket.deletionDecorations,
14898
+ additionDecorations: bucket.additionDecorations,
14899
+ lineDiffType
14900
+ });
14901
+ }
14902
+ if (deletionLineIndex != null && deletionLineNumber != null && unifiedDeletionLineIndex != null) {
14903
+ appendContent(diff.deletionLines[deletionLineIndex], deletionLineIndex, bucket.deletionSegments, bucket.deletionContent);
14904
+ bucket.deletionInfo.push({
14905
+ type: type === "change" ? "change-deletion" : type,
14906
+ lineNumber: deletionLineNumber,
14907
+ altLineNumber: type === "change" ? undefined : additionLineNumber ?? undefined,
14908
+ lineIndex: `${unifiedDeletionLineIndex},${splitLineIndex}`
14909
+ });
14910
+ }
14911
+ if (additionLineIndex != null && additionLineNumber != null && unifiedAdditionLineIndex != null) {
14912
+ appendContent(diff.additionLines[additionLineIndex], additionLineIndex, bucket.additionSegments, bucket.additionContent);
14913
+ bucket.additionInfo.push({
14914
+ type: type === "change" ? "change-addition" : type,
14915
+ lineNumber: additionLineNumber,
14916
+ altLineNumber: type === "change" ? undefined : deletionLineNumber ?? undefined,
14917
+ lineIndex: `${unifiedAdditionLineIndex},${splitLineIndex}`
14918
+ });
14919
+ }
14920
+ }
14921
+ });
14922
+ for (const bucket of buckets.values()) {
14923
+ if (bucket.deletionContent.length === 0 && bucket.additionContent.length === 0) {
14924
+ continue;
14925
+ }
14926
+ const deletionFile = {
14389
14927
  name: diff.prevName ?? diff.name,
14390
- contents: oldContent
14928
+ contents: bucket.deletionContent.value
14391
14929
  };
14392
- const newFile = {
14930
+ const additionFile = {
14393
14931
  name: diff.name,
14394
- contents: newContent
14932
+ contents: bucket.additionContent.value
14395
14933
  };
14396
- const code$1 = renderTwoFiles({
14397
- oldFile,
14398
- oldInfo,
14399
- oldDecorations,
14400
- newFile,
14401
- newInfo,
14402
- newDecorations,
14934
+ const { deletionLines, additionLines } = renderTwoFiles({
14935
+ deletionFile,
14936
+ deletionInfo: bucket.deletionInfo,
14937
+ deletionDecorations: bucket.deletionDecorations,
14938
+ additionFile,
14939
+ additionInfo: bucket.additionInfo,
14940
+ additionDecorations: bucket.additionDecorations,
14403
14941
  highlighter: highlighter$1,
14404
14942
  options,
14405
14943
  languageOverride: forcePlainText ? "text" : diff.lang
14406
14944
  });
14407
- return {
14408
- code: code$1,
14409
- themeStyles,
14410
- baseThemeType
14411
- };
14412
- }
14413
- const hunks = [];
14414
- let splitLineIndex = 0;
14415
- let unifiedLineIndex = 0;
14416
- for (const hunk of diff.hunks) {
14417
- const { oldContent, newContent, oldInfo, newInfo, oldDecorations, newDecorations, splitLineIndex: newSplitLineIndex, unifiedLineIndex: newUnifiedLineIndex } = processLines({
14418
- hunks: [hunk],
14419
- splitLineIndex,
14420
- unifiedLineIndex,
14421
- lineDiffType: options.lineDiffType
14422
- });
14423
- const oldFile = {
14424
- name: diff.prevName ?? diff.name,
14425
- contents: oldContent
14426
- };
14427
- const newFile = {
14428
- name: diff.name,
14429
- contents: newContent
14430
- };
14431
- hunks.push(renderTwoFiles({
14432
- oldFile,
14433
- oldInfo,
14434
- oldDecorations,
14435
- newFile,
14436
- newInfo,
14437
- newDecorations,
14438
- highlighter: highlighter$1,
14439
- options,
14440
- languageOverride: forcePlainText ? "text" : diff.lang
14441
- }));
14442
- splitLineIndex = newSplitLineIndex;
14443
- unifiedLineIndex = newUnifiedLineIndex;
14444
- }
14445
- const code = (() => {
14446
- if (hunks.length <= 1) {
14447
- const hunk = hunks[0] ?? {
14448
- oldLines: [],
14449
- newLines: []
14450
- };
14451
- if (hunk.newLines.length === 0 || hunk.oldLines.length === 0) {
14452
- return hunk;
14945
+ if (shouldGroupAll) {
14946
+ code.deletionLines = deletionLines;
14947
+ code.additionLines = additionLines;
14948
+ continue;
14949
+ }
14950
+ if (bucket.deletionSegments.length > 0) {
14951
+ for (const seg of bucket.deletionSegments) {
14952
+ for (let i$2 = 0; i$2 < seg.count; i$2++) {
14953
+ code.deletionLines[seg.targetIndex + i$2] = deletionLines[seg.originalOffset + i$2];
14954
+ }
14453
14955
  }
14956
+ } else {
14957
+ code.deletionLines.push(...deletionLines);
14454
14958
  }
14455
- return { hunks };
14456
- })();
14959
+ if (bucket.additionSegments.length > 0) {
14960
+ for (const seg of bucket.additionSegments) {
14961
+ for (let i$2 = 0; i$2 < seg.count; i$2++) {
14962
+ code.additionLines[seg.targetIndex + i$2] = additionLines[seg.originalOffset + i$2];
14963
+ }
14964
+ }
14965
+ } else {
14966
+ code.additionLines.push(...additionLines);
14967
+ }
14968
+ }
14457
14969
  return {
14458
14970
  code,
14459
14971
  themeStyles,
14460
14972
  baseThemeType
14461
14973
  };
14462
14974
  }
14463
- function computeLineDiffDecorations({ oldLine, newLine, oldLineIndex, newLineIndex, oldDecorations, newDecorations, lineDiffType }) {
14464
- if (oldLine == null || newLine == null || lineDiffType === "none") {
14975
+ function computeLineDiffDecorations({ deletionLine, additionLine, deletionLineIndex, additionLineIndex, deletionDecorations, additionDecorations, lineDiffType }) {
14976
+ if (deletionLine == null || additionLine == null || lineDiffType === "none") {
14465
14977
  return;
14466
14978
  }
14467
- oldLine = cleanLastNewline(oldLine);
14468
- newLine = cleanLastNewline(newLine);
14469
- const lineDiff$1 = lineDiffType === "char" ? diffChars(oldLine, newLine) : diffWordsWithSpace(oldLine, newLine);
14979
+ deletionLine = cleanLastNewline(deletionLine);
14980
+ additionLine = cleanLastNewline(additionLine);
14981
+ const lineDiff$1 = lineDiffType === "char" ? diffChars(deletionLine, additionLine) : diffWordsWithSpace(deletionLine, additionLine);
14470
14982
  const deletionSpans = [];
14471
14983
  const additionSpans = [];
14472
14984
  const enableJoin = lineDiffType === "word-alt";
14985
+ const lastItem = lineDiff$1.at(-1);
14473
14986
  for (const item of lineDiff$1) {
14474
- const isLastItem = item === lineDiff$1[lineDiff$1.length - 1];
14987
+ const isLastItem = item === lastItem;
14475
14988
  if (!item.added && !item.removed) {
14476
14989
  pushOrJoinSpan({
14477
14990
  item,
@@ -14506,8 +15019,8 @@ function computeLineDiffDecorations({ oldLine, newLine, oldLineIndex, newLineInd
14506
15019
  let spanIndex = 0;
14507
15020
  for (const span of deletionSpans) {
14508
15021
  if (span[0] === 1) {
14509
- oldDecorations.push(createDiffSpanDecoration({
14510
- line: oldLineIndex - 1,
15022
+ deletionDecorations.push(createDiffSpanDecoration({
15023
+ line: deletionLineIndex,
14511
15024
  spanStart: spanIndex,
14512
15025
  spanLength: span[1].length
14513
15026
  }));
@@ -14517,8 +15030,8 @@ function computeLineDiffDecorations({ oldLine, newLine, oldLineIndex, newLineInd
14517
15030
  spanIndex = 0;
14518
15031
  for (const span of additionSpans) {
14519
15032
  if (span[0] === 1) {
14520
- newDecorations.push(createDiffSpanDecoration({
14521
- line: newLineIndex - 1,
15033
+ additionDecorations.push(createDiffSpanDecoration({
15034
+ line: additionLineIndex,
14522
15035
  spanStart: spanIndex,
14523
15036
  spanLength: span[1].length
14524
15037
  }));
@@ -14526,156 +15039,35 @@ function computeLineDiffDecorations({ oldLine, newLine, oldLineIndex, newLineInd
14526
15039
  spanIndex += span[1].length;
14527
15040
  }
14528
15041
  }
14529
- function processLines({ hunks, oldLines, newLines, splitLineIndex = 0, unifiedLineIndex = 0, lineDiffType }) {
14530
- const oldInfo = {};
14531
- const newInfo = {};
14532
- const oldDecorations = [];
14533
- const newDecorations = [];
14534
- let newLineIndex = 1;
14535
- let oldLineIndex = 1;
14536
- let newLineNumber = 1;
14537
- let oldLineNumber = 1;
14538
- let oldContent = "";
14539
- let newContent = "";
14540
- for (const hunk of hunks) {
14541
- while (oldLines != null && newLines != null && newLineIndex < hunk.additionStart && oldLineIndex < hunk.deletionStart) {
14542
- oldInfo[oldLineIndex] = {
14543
- type: "context-expanded",
14544
- lineNumber: oldLineNumber,
14545
- altLineNumber: newLineNumber,
14546
- lineIndex: `${unifiedLineIndex},${splitLineIndex}`
14547
- };
14548
- newInfo[newLineIndex] = {
14549
- type: "context-expanded",
14550
- lineNumber: newLineNumber,
14551
- altLineNumber: oldLineNumber,
14552
- lineIndex: `${unifiedLineIndex},${splitLineIndex}`
14553
- };
14554
- oldContent += oldLines[oldLineIndex - 1];
14555
- newContent += newLines[newLineIndex - 1];
14556
- oldLineIndex++;
14557
- newLineIndex++;
14558
- oldLineNumber++;
14559
- newLineNumber++;
14560
- splitLineIndex++;
14561
- unifiedLineIndex++;
14562
- }
14563
- oldLineNumber = hunk.deletionStart;
14564
- newLineNumber = hunk.additionStart;
14565
- for (const hunkContent of hunk.hunkContent) {
14566
- if (hunkContent.type === "context") {
14567
- for (const line of hunkContent.lines) {
14568
- oldInfo[oldLineIndex] = {
14569
- type: "context",
14570
- lineNumber: oldLineNumber,
14571
- altLineNumber: newLineNumber,
14572
- lineIndex: `${unifiedLineIndex},${splitLineIndex}`
14573
- };
14574
- newInfo[newLineIndex] = {
14575
- type: "context",
14576
- lineNumber: newLineNumber,
14577
- altLineNumber: oldLineNumber,
14578
- lineIndex: `${unifiedLineIndex},${splitLineIndex}`
14579
- };
14580
- oldContent += line;
14581
- newContent += line;
14582
- oldLineIndex++;
14583
- newLineIndex++;
14584
- newLineNumber++;
14585
- oldLineNumber++;
14586
- splitLineIndex++;
14587
- unifiedLineIndex++;
14588
- }
14589
- } else {
14590
- const len = Math.max(hunkContent.additions.length, hunkContent.deletions.length);
14591
- let i$2 = 0;
14592
- let _unifiedLineIndex = unifiedLineIndex;
14593
- while (i$2 < len) {
14594
- const oldLine = hunkContent.deletions[i$2];
14595
- const newLine = hunkContent.additions[i$2];
14596
- computeLineDiffDecorations({
14597
- newLine,
14598
- oldLine,
14599
- oldLineIndex,
14600
- newLineIndex,
14601
- oldDecorations,
14602
- newDecorations,
14603
- lineDiffType
14604
- });
14605
- if (oldLine != null) {
14606
- oldInfo[oldLineIndex] = {
14607
- type: "change-deletion",
14608
- lineNumber: oldLineNumber,
14609
- lineIndex: `${_unifiedLineIndex},${splitLineIndex}`
14610
- };
14611
- oldContent += oldLine;
14612
- oldLineIndex++;
14613
- oldLineNumber++;
14614
- }
14615
- if (newLine != null) {
14616
- newInfo[newLineIndex] = {
14617
- type: "change-addition",
14618
- lineNumber: newLineNumber,
14619
- lineIndex: `${_unifiedLineIndex + hunkContent.deletions.length},${splitLineIndex}`
14620
- };
14621
- newContent += newLine;
14622
- newLineIndex++;
14623
- newLineNumber++;
14624
- }
14625
- splitLineIndex++;
14626
- _unifiedLineIndex++;
14627
- i$2++;
14628
- }
14629
- unifiedLineIndex += hunkContent.additions.length + hunkContent.deletions.length;
14630
- }
14631
- }
14632
- if (oldLines == null || newLines == null || hunk !== hunks[hunks.length - 1]) continue;
14633
- while (oldLineIndex <= oldLines.length || newLineIndex <= oldLines.length) {
14634
- const oldLine = oldLines[oldLineIndex - 1];
14635
- const newLine = newLines[newLineIndex - 1];
14636
- if (oldLine == null && newLine == null) {
14637
- break;
14638
- }
14639
- if (oldLine != null) {
14640
- oldInfo[oldLineIndex] = {
14641
- type: "context-expanded",
14642
- lineNumber: oldLineNumber,
14643
- altLineNumber: newLineNumber,
14644
- lineIndex: `${unifiedLineIndex},${splitLineIndex}`
14645
- };
14646
- oldContent += oldLine;
14647
- oldLineIndex++;
14648
- oldLineNumber++;
14649
- }
14650
- if (newLine != null) {
14651
- newInfo[newLineIndex] = {
14652
- type: "context-expanded",
14653
- lineNumber: newLineNumber,
14654
- altLineNumber: oldLineNumber,
14655
- lineIndex: `${unifiedLineIndex},${splitLineIndex}`
14656
- };
14657
- newContent += newLine;
14658
- newLineIndex++;
14659
- newLineNumber++;
14660
- }
14661
- splitLineIndex++;
14662
- unifiedLineIndex++;
14663
- }
14664
- }
15042
+ function createBucket() {
14665
15043
  return {
14666
- oldContent,
14667
- newContent,
14668
- oldInfo,
14669
- newInfo,
14670
- oldDecorations,
14671
- newDecorations,
14672
- splitLineIndex,
14673
- unifiedLineIndex
15044
+ deletionContent: {
15045
+ push(value) {
15046
+ this.value += value;
15047
+ this.length++;
15048
+ },
15049
+ value: "",
15050
+ length: 0
15051
+ },
15052
+ additionContent: {
15053
+ push(value) {
15054
+ this.value += value;
15055
+ this.length++;
15056
+ },
15057
+ value: "",
15058
+ length: 0
15059
+ },
15060
+ deletionInfo: [],
15061
+ additionInfo: [],
15062
+ deletionDecorations: [],
15063
+ additionDecorations: [],
15064
+ deletionSegments: [],
15065
+ additionSegments: []
14674
15066
  };
14675
15067
  }
14676
- function renderTwoFiles({ oldFile, newFile, oldInfo, newInfo, highlighter: highlighter$1, oldDecorations, newDecorations, languageOverride, options: { theme: themeOrThemes = DEFAULT_THEMES,...options } }) {
14677
- const oldLang = languageOverride ?? getFiletypeFromFileName(oldFile.name);
14678
- const newLang = languageOverride ?? getFiletypeFromFileName(newFile.name);
15068
+ function renderTwoFiles({ deletionFile, additionFile, deletionInfo, additionInfo, highlighter: highlighter$1, deletionDecorations, additionDecorations, languageOverride, options: { theme: themeOrThemes = DEFAULT_THEMES,...options } }) {
15069
+ const deletionLang = languageOverride ?? getFiletypeFromFileName(deletionFile.name);
15070
+ const additionLang = languageOverride ?? getFiletypeFromFileName(additionFile.name);
14679
15071
  const { state, transformers } = createTransformerWithState();
14680
15072
  const hastConfig = (() => {
14681
15073
  return typeof themeOrThemes === "string" ? {
@@ -14696,27 +15088,27 @@ function renderTwoFiles({ oldFile, newFile, oldInfo, newInfo, highlighter: highl
14696
15088
  cssVariablePrefix: formatCSSVariablePrefix("token")
14697
15089
  };
14698
15090
  })();
14699
- const oldLines = (() => {
14700
- if (oldFile.contents === "") {
15091
+ const deletionLines = (() => {
15092
+ if (deletionFile.contents === "") {
14701
15093
  return [];
14702
15094
  }
14703
- hastConfig.lang = oldLang;
14704
- state.lineInfo = oldInfo;
14705
- hastConfig.decorations = oldDecorations;
14706
- return getLineNodes(highlighter$1.codeToHast(cleanLastNewline(oldFile.contents), hastConfig));
15095
+ hastConfig.lang = deletionLang;
15096
+ state.lineInfo = deletionInfo;
15097
+ hastConfig.decorations = deletionDecorations;
15098
+ return getLineNodes(highlighter$1.codeToHast(cleanLastNewline(deletionFile.contents), hastConfig));
14707
15099
  })();
14708
- const newLines = (() => {
14709
- if (newFile.contents === "") {
15100
+ const additionLines = (() => {
15101
+ if (additionFile.contents === "") {
14710
15102
  return [];
14711
15103
  }
14712
- hastConfig.lang = newLang;
14713
- hastConfig.decorations = newDecorations;
14714
- state.lineInfo = newInfo;
14715
- return getLineNodes(highlighter$1.codeToHast(cleanLastNewline(newFile.contents), hastConfig));
15104
+ hastConfig.lang = additionLang;
15105
+ hastConfig.decorations = additionDecorations;
15106
+ state.lineInfo = additionInfo;
15107
+ return getLineNodes(highlighter$1.codeToHast(cleanLastNewline(additionFile.contents), hastConfig));
14716
15108
  })();
14717
15109
  return {
14718
- oldLines,
14719
- newLines
15110
+ deletionLines,
15111
+ additionLines
14720
15112
  };
14721
15113
  }
14722
15114