@pierre/diffs 1.2.5 → 1.3.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 (153) hide show
  1. package/dist/components/CodeView.d.ts +0 -1
  2. package/dist/components/CodeView.d.ts.map +1 -1
  3. package/dist/components/CodeView.js +0 -23
  4. package/dist/components/CodeView.js.map +1 -1
  5. package/dist/components/File.d.ts +7 -2
  6. package/dist/components/File.d.ts.map +1 -1
  7. package/dist/components/File.js +36 -2
  8. package/dist/components/File.js.map +1 -1
  9. package/dist/components/FileDiff.d.ts +8 -2
  10. package/dist/components/FileDiff.d.ts.map +1 -1
  11. package/dist/components/FileDiff.js +73 -1
  12. package/dist/components/FileDiff.js.map +1 -1
  13. package/dist/components/UnresolvedFile.js +2 -2
  14. package/dist/components/VirtualizedFile.d.ts +2 -1
  15. package/dist/components/VirtualizedFile.d.ts.map +1 -1
  16. package/dist/components/VirtualizedFile.js +48 -48
  17. package/dist/components/VirtualizedFile.js.map +1 -1
  18. package/dist/components/VirtualizedFileDiff.js +1 -6
  19. package/dist/components/VirtualizedFileDiff.js.map +1 -1
  20. package/dist/components/Virtualizer.d.ts +1 -1
  21. package/dist/components/Virtualizer.d.ts.map +1 -1
  22. package/dist/components/Virtualizer.js.map +1 -1
  23. package/dist/editor/command.d.ts +6 -0
  24. package/dist/editor/command.d.ts.map +1 -0
  25. package/dist/editor/command.js +31 -0
  26. package/dist/editor/command.js.map +1 -0
  27. package/dist/editor/css.d.ts +6 -0
  28. package/dist/editor/css.d.ts.map +1 -0
  29. package/dist/editor/css.js +218 -0
  30. package/dist/editor/css.js.map +1 -0
  31. package/dist/editor/editStack.d.ts +66 -0
  32. package/dist/editor/editStack.d.ts.map +1 -0
  33. package/dist/editor/editStack.js +218 -0
  34. package/dist/editor/editStack.js.map +1 -0
  35. package/dist/editor/editor.d.ts +22 -0
  36. package/dist/editor/editor.d.ts.map +1 -0
  37. package/dist/editor/editor.js +1323 -0
  38. package/dist/editor/editor.js.map +1 -0
  39. package/dist/editor/index.d.ts +3 -0
  40. package/dist/editor/index.js +4 -0
  41. package/dist/editor/lineAnnotations.d.ts +8 -0
  42. package/dist/editor/lineAnnotations.d.ts.map +1 -0
  43. package/dist/editor/lineAnnotations.js +32 -0
  44. package/dist/editor/lineAnnotations.js.map +1 -0
  45. package/dist/editor/pieceTable.d.ts +33 -0
  46. package/dist/editor/pieceTable.d.ts.map +1 -0
  47. package/dist/editor/pieceTable.js +590 -0
  48. package/dist/editor/pieceTable.js.map +1 -0
  49. package/dist/editor/platform.d.ts +12 -0
  50. package/dist/editor/platform.d.ts.map +1 -0
  51. package/dist/editor/platform.js +44 -0
  52. package/dist/editor/platform.js.map +1 -0
  53. package/dist/editor/quickEdit.d.ts +29 -0
  54. package/dist/editor/quickEdit.d.ts.map +1 -0
  55. package/dist/editor/quickEdit.js +81 -0
  56. package/dist/editor/quickEdit.js.map +1 -0
  57. package/dist/editor/searchPanel.d.ts +30 -0
  58. package/dist/editor/searchPanel.d.ts.map +1 -0
  59. package/dist/editor/searchPanel.js +219 -0
  60. package/dist/editor/searchPanel.js.map +1 -0
  61. package/dist/editor/selection.d.ts +126 -0
  62. package/dist/editor/selection.d.ts.map +1 -0
  63. package/dist/editor/selection.js +900 -0
  64. package/dist/editor/selection.js.map +1 -0
  65. package/dist/editor/textDocument.d.ts +139 -0
  66. package/dist/editor/textDocument.d.ts.map +1 -0
  67. package/dist/editor/textDocument.js +202 -0
  68. package/dist/editor/textDocument.js.map +1 -0
  69. package/dist/editor/textMeasure.d.ts +32 -0
  70. package/dist/editor/textMeasure.d.ts.map +1 -0
  71. package/dist/editor/textMeasure.js +108 -0
  72. package/dist/editor/textMeasure.js.map +1 -0
  73. package/dist/editor/tokenzier.d.ts +37 -0
  74. package/dist/editor/tokenzier.d.ts.map +1 -0
  75. package/dist/editor/tokenzier.js +348 -0
  76. package/dist/editor/tokenzier.js.map +1 -0
  77. package/dist/editor/utils.d.ts +16 -0
  78. package/dist/editor/utils.d.ts.map +1 -0
  79. package/dist/editor/utils.js +37 -0
  80. package/dist/editor/utils.js.map +1 -0
  81. package/dist/index.d.ts +2 -2
  82. package/dist/index.js +2 -2
  83. package/dist/react/EditorContext.d.ts +16 -0
  84. package/dist/react/EditorContext.d.ts.map +1 -0
  85. package/dist/react/EditorContext.js +26 -0
  86. package/dist/react/EditorContext.js.map +1 -0
  87. package/dist/react/File.d.ts +2 -1
  88. package/dist/react/File.d.ts.map +1 -1
  89. package/dist/react/File.js +3 -2
  90. package/dist/react/File.js.map +1 -1
  91. package/dist/react/FileDiff.d.ts +3 -1
  92. package/dist/react/FileDiff.d.ts.map +1 -1
  93. package/dist/react/FileDiff.js +3 -2
  94. package/dist/react/FileDiff.js.map +1 -1
  95. package/dist/react/MultiFileDiff.d.ts +3 -1
  96. package/dist/react/MultiFileDiff.d.ts.map +1 -1
  97. package/dist/react/MultiFileDiff.js +3 -2
  98. package/dist/react/MultiFileDiff.js.map +1 -1
  99. package/dist/react/PatchDiff.d.ts +3 -1
  100. package/dist/react/PatchDiff.d.ts.map +1 -1
  101. package/dist/react/PatchDiff.js +3 -2
  102. package/dist/react/PatchDiff.js.map +1 -1
  103. package/dist/react/index.d.ts +3 -2
  104. package/dist/react/index.js +2 -1
  105. package/dist/react/jsx.d.ts +0 -1
  106. package/dist/react/jsx.d.ts.map +1 -1
  107. package/dist/react/types.d.ts +1 -0
  108. package/dist/react/types.d.ts.map +1 -1
  109. package/dist/react/types.js +0 -1
  110. package/dist/react/utils/useFileDiffInstance.d.ts +3 -1
  111. package/dist/react/utils/useFileDiffInstance.d.ts.map +1 -1
  112. package/dist/react/utils/useFileDiffInstance.js +31 -5
  113. package/dist/react/utils/useFileDiffInstance.js.map +1 -1
  114. package/dist/react/utils/useFileInstance.d.ts +4 -1
  115. package/dist/react/utils/useFileInstance.d.ts.map +1 -1
  116. package/dist/react/utils/useFileInstance.js +30 -5
  117. package/dist/react/utils/useFileInstance.js.map +1 -1
  118. package/dist/renderers/DiffHunksRenderer.d.ts +2 -2
  119. package/dist/renderers/DiffHunksRenderer.d.ts.map +1 -1
  120. package/dist/renderers/DiffHunksRenderer.js.map +1 -1
  121. package/dist/renderers/FileRenderer.d.ts +5 -1
  122. package/dist/renderers/FileRenderer.d.ts.map +1 -1
  123. package/dist/renderers/FileRenderer.js +108 -41
  124. package/dist/renderers/FileRenderer.js.map +1 -1
  125. package/dist/ssr/index.d.ts +2 -2
  126. package/dist/style.js +1 -1
  127. package/dist/style.js.map +1 -1
  128. package/dist/types.d.ts +45 -1
  129. package/dist/types.d.ts.map +1 -1
  130. package/dist/utils/cleanLastNewline.js +6 -1
  131. package/dist/utils/cleanLastNewline.js.map +1 -1
  132. package/dist/utils/computeFileOffsets.d.ts +13 -0
  133. package/dist/utils/computeFileOffsets.d.ts.map +1 -0
  134. package/dist/utils/computeFileOffsets.js +33 -0
  135. package/dist/utils/computeFileOffsets.js.map +1 -0
  136. package/dist/utils/createTransformerWithState.js +9 -0
  137. package/dist/utils/createTransformerWithState.js.map +1 -1
  138. package/dist/utils/renderDiffWithHighlighter.js +1 -1
  139. package/dist/utils/renderFileWithHighlighter.js +5 -14
  140. package/dist/utils/renderFileWithHighlighter.js.map +1 -1
  141. package/dist/worker/WorkerPoolManager.js +1 -1
  142. package/dist/worker/{wasm-BaDzIkIn.js → wasm-D4DU5jgR.js} +2 -2
  143. package/dist/worker/wasm-D4DU5jgR.js.map +1 -0
  144. package/dist/worker/worker-portable.js +138 -153
  145. package/dist/worker/worker-portable.js.map +1 -1
  146. package/dist/worker/worker.js +41 -64
  147. package/dist/worker/worker.js.map +1 -1
  148. package/package.json +28 -20
  149. package/dist/utils/iterateOverFile.d.ts +0 -50
  150. package/dist/utils/iterateOverFile.d.ts.map +0 -1
  151. package/dist/utils/iterateOverFile.js +0 -49
  152. package/dist/utils/iterateOverFile.js.map +0 -1
  153. package/dist/worker/wasm-BaDzIkIn.js.map +0 -1
@@ -12,7 +12,6 @@ const DIFFS_DEVELOPMENT_BUILD = (() => {
12
12
  return false;
13
13
  }
14
14
  })();
15
- const SPLIT_WITH_NEWLINES = /(?<=\n)/;
16
15
  const DEFAULT_THEMES = {
17
16
  dark: "pierre-dark",
18
17
  light: "pierre-light"
@@ -454,7 +453,12 @@ function replaceCustomExtensions(version, map) {
454
453
  //#endregion
455
454
  //#region src/utils/cleanLastNewline.ts
456
455
  function cleanLastNewline(contents) {
457
- return contents.replace(/\n$|\r\n$/, "");
456
+ let end = contents.length;
457
+ if (contents.charCodeAt(end - 1) === 10) {
458
+ end--;
459
+ if (contents.charCodeAt(end - 1) === 13) end--;
460
+ }
461
+ return contents.slice(0, end);
458
462
  }
459
463
 
460
464
  //#endregion
@@ -631,6 +635,15 @@ function createTransformerWithState(useTokenTransformer = false, useCSSClasses =
631
635
  } : null
632
636
  }];
633
637
  if (useCSSClasses) transformers.push(tokenStyleNormalizer, toClass);
638
+ if (useTokenTransformer) transformers.push({ line: (node) => {
639
+ if (node.type === "element" && node.children.length === 0) node.children.push({
640
+ type: "element",
641
+ tagName: "br",
642
+ properties: {},
643
+ children: []
644
+ });
645
+ return node;
646
+ } });
634
647
  return {
635
648
  state,
636
649
  transformers,
@@ -1542,63 +1555,34 @@ function renderTwoFiles({ deletionFile, additionFile, deletionInfo, additionInfo
1542
1555
  }
1543
1556
 
1544
1557
  //#endregion
1545
- //#region src/utils/iterateOverFile.ts
1558
+ //#region src/utils/computeFileOffsets.ts
1559
+ const LINE_FEED = 10;
1560
+ const CARRIAGE_RETURN = 13;
1546
1561
  /**
1547
- * Iterates over lines in a file with optional windowing support.
1548
- *
1549
- * Similar to `iterateOverDiff` but simplified for linear file content.
1550
- * Supports viewport windowing for virtualization scenarios.
1551
- *
1552
- * @param props - Configuration for iteration
1553
- * @param props.lines - Pre-split array of lines (use splitFileContents() to create from string)
1554
- * @param props.startingLine - Optional starting line index (0-based, default: 0)
1555
- * @param props.totalLines - Optional max lines to iterate (default: Infinity)
1556
- * @param props.callback - Callback invoked for each line in the window.
1557
- * Return `true` to stop iteration early.
1558
- *
1559
- * @example
1560
- * ```typescript
1561
- * const lines = splitFileContents('line1\nline2\nline3');
1562
- * iterateOverFile({
1563
- * lines,
1564
- * startingLine: 0,
1565
- * totalLines: 10,
1566
- * callback: ({ lineIndex, lineNumber, content, isLastLine }) => {
1567
- * console.log(`Line ${lineNumber}: ${content}`);
1568
- * if (content.includes('stop')) return true; // Stop iteration
1569
- * }
1570
- * });
1571
- * ```
1562
+ * Computes line start offsets for a string.
1572
1563
  */
1573
- function iterateOverFile({ lines, startingLine = 0, totalLines = Infinity, callback }) {
1574
- const len = Math.min(startingLine + totalLines, lines.length);
1575
- const lastLineIndex = (() => {
1576
- const lastLine = lines.at(-1);
1577
- if (lastLine === "" || lastLine === "\n" || lastLine === "\r\n" || lastLine === "\r") return Math.max(0, lines.length - 2);
1578
- return lines.length - 1;
1579
- })();
1580
- for (let lineIndex = startingLine; lineIndex < len; lineIndex++) {
1581
- const isLastLine = lineIndex === lastLineIndex;
1582
- if (callback({
1583
- lineIndex,
1584
- lineNumber: lineIndex + 1,
1585
- content: lines[lineIndex],
1586
- isLastLine
1587
- }) === true || isLastLine) break;
1564
+ function computeLineOffsets(contents) {
1565
+ const offsets = [0];
1566
+ for (let i = 0; i < contents.length; i++) {
1567
+ const char = contents.charCodeAt(i);
1568
+ if (char === LINE_FEED || char === CARRIAGE_RETURN) {
1569
+ if (char === CARRIAGE_RETURN && i + 1 < contents.length && contents.charCodeAt(i + 1) === LINE_FEED) i++;
1570
+ offsets.push(i + 1);
1571
+ }
1588
1572
  }
1573
+ return offsets;
1589
1574
  }
1590
-
1591
- //#endregion
1592
- //#region src/utils/splitFileContents.ts
1593
1575
  /**
1594
- * Splits file contents into lines using the same logic as diff parsing.
1595
- * - Preserves trailing newlines on each line
1596
- *
1597
- * @param contents - The raw file contents string
1598
- * @returns Array of lines with newlines preserved
1576
+ * Splits file contents into lines aligned with {@link computeLineOffsets}.
1577
+ * Unlike splitFileContents, a trailing newline produces a final empty line.
1599
1578
  */
1600
- function splitFileContents(contents) {
1601
- return contents !== "" ? contents.split(SPLIT_WITH_NEWLINES) : [];
1579
+ function linesFromFileContents(contents) {
1580
+ const offsets = computeLineOffsets(contents);
1581
+ return Array.from({ length: offsets.length }, (_, i) => {
1582
+ const start = offsets[i];
1583
+ const end = offsets[i + 1] ?? contents.length;
1584
+ return contents.slice(start, end);
1585
+ });
1602
1586
  }
1603
1587
 
1604
1588
  //#endregion
@@ -1643,7 +1627,7 @@ function renderFileWithHighlighter(file, highlighter$1, { theme = DEFAULT_THEMES
1643
1627
  tokenizeMaxLineLength
1644
1628
  };
1645
1629
  })();
1646
- const highlightedLines = getLineNodes(highlighter$1.codeToHast(isWindowedHighlight ? extractWindowedFileContent(lines ?? splitFileContents(file.contents), startingLine, totalLines) : cleanLastNewline(file.contents), hastConfig));
1630
+ const highlightedLines = getLineNodes(highlighter$1.codeToHast(isWindowedHighlight ? extractWindowedFileContent(lines ?? linesFromFileContents(file.contents), startingLine, totalLines) : file.contents, hastConfig));
1647
1631
  const code = isWindowedHighlight ? new Array(startingLine) : highlightedLines;
1648
1632
  if (isWindowedHighlight) code.push(...highlightedLines);
1649
1633
  return {
@@ -1653,16 +1637,9 @@ function renderFileWithHighlighter(file, highlighter$1, { theme = DEFAULT_THEMES
1653
1637
  };
1654
1638
  }
1655
1639
  function extractWindowedFileContent(lines, startingLine, totalLines) {
1656
- let windowContent = "";
1657
- iterateOverFile({
1658
- lines,
1659
- startingLine,
1660
- totalLines,
1661
- callback({ content }) {
1662
- windowContent += content;
1663
- }
1664
- });
1665
- return windowContent;
1640
+ if (lines.length === 0) return "";
1641
+ const endLine = Math.min(startingLine + totalLines, lines.length);
1642
+ return lines.slice(startingLine, endLine).join("");
1666
1643
  }
1667
1644
 
1668
1645
  //#endregion