@pierre/diffs 1.3.0-beta.9 → 1.3.0-rc.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 (241) hide show
  1. package/README.md +9 -0
  2. package/dist/components/CodeView.d.ts +12 -13
  3. package/dist/components/CodeView.d.ts.map +1 -1
  4. package/dist/components/CodeView.js +50 -58
  5. package/dist/components/CodeView.js.map +1 -1
  6. package/dist/components/File.d.ts +10 -3
  7. package/dist/components/File.d.ts.map +1 -1
  8. package/dist/components/File.js +41 -10
  9. package/dist/components/File.js.map +1 -1
  10. package/dist/components/FileDiff.d.ts +37 -6
  11. package/dist/components/FileDiff.d.ts.map +1 -1
  12. package/dist/components/FileDiff.js +202 -19
  13. package/dist/components/FileDiff.js.map +1 -1
  14. package/dist/components/UnresolvedFile.d.ts.map +1 -1
  15. package/dist/components/UnresolvedFile.js +7 -2
  16. package/dist/components/UnresolvedFile.js.map +1 -1
  17. package/dist/components/VirtualizedFile.d.ts +2 -1
  18. package/dist/components/VirtualizedFile.d.ts.map +1 -1
  19. package/dist/components/VirtualizedFile.js +9 -5
  20. package/dist/components/VirtualizedFile.js.map +1 -1
  21. package/dist/components/VirtualizedFileDiff.d.ts +14 -0
  22. package/dist/components/VirtualizedFileDiff.d.ts.map +1 -1
  23. package/dist/components/VirtualizedFileDiff.js +61 -3
  24. package/dist/components/VirtualizedFileDiff.js.map +1 -1
  25. package/dist/components/Virtualizer.d.ts +14 -2
  26. package/dist/components/Virtualizer.d.ts.map +1 -1
  27. package/dist/components/Virtualizer.js +27 -2
  28. package/dist/components/Virtualizer.js.map +1 -1
  29. package/dist/edit/index.d.ts +5 -0
  30. package/dist/edit/index.js +3 -0
  31. package/dist/editor/command.d.ts +1 -1
  32. package/dist/editor/command.d.ts.map +1 -1
  33. package/dist/editor/command.js +11 -0
  34. package/dist/editor/command.js.map +1 -1
  35. package/dist/editor/editStack.d.ts +6 -2
  36. package/dist/editor/editStack.d.ts.map +1 -1
  37. package/dist/editor/editStack.js +53 -12
  38. package/dist/editor/editStack.js.map +1 -1
  39. package/dist/editor/editor.d.ts +51 -23
  40. package/dist/editor/editor.d.ts.map +1 -1
  41. package/dist/editor/editor.js +977 -241
  42. package/dist/editor/editor.js.map +1 -1
  43. package/dist/editor/editor2.js +1 -1
  44. package/dist/editor/languages.d.ts +26 -0
  45. package/dist/editor/languages.d.ts.map +1 -0
  46. package/dist/editor/languages.js +363 -0
  47. package/dist/editor/languages.js.map +1 -0
  48. package/dist/editor/lineAnnotations.d.ts.map +1 -1
  49. package/dist/editor/lineAnnotations.js +25 -26
  50. package/dist/editor/lineAnnotations.js.map +1 -1
  51. package/dist/editor/marker.d.ts +5 -3
  52. package/dist/editor/marker.d.ts.map +1 -1
  53. package/dist/editor/marker.js +111 -91
  54. package/dist/editor/marker.js.map +1 -1
  55. package/dist/editor/matchBrackets.d.ts +3 -2
  56. package/dist/editor/matchBrackets.d.ts.map +1 -1
  57. package/dist/editor/matchBrackets.js +2 -10
  58. package/dist/editor/matchBrackets.js.map +1 -1
  59. package/dist/editor/pieceTable.d.ts +2 -1
  60. package/dist/editor/pieceTable.d.ts.map +1 -1
  61. package/dist/editor/pieceTable.js +103 -39
  62. package/dist/editor/pieceTable.js.map +1 -1
  63. package/dist/editor/platform.js +2 -0
  64. package/dist/editor/platform.js.map +1 -1
  65. package/dist/editor/popover.d.ts +25 -5
  66. package/dist/editor/popover.d.ts.map +1 -1
  67. package/dist/editor/popover.js +60 -14
  68. package/dist/editor/popover.js.map +1 -1
  69. package/dist/editor/searchPanel.d.ts.map +1 -1
  70. package/dist/editor/searchPanel.js +9 -2
  71. package/dist/editor/searchPanel.js.map +1 -1
  72. package/dist/editor/selection.d.ts +31 -11
  73. package/dist/editor/selection.d.ts.map +1 -1
  74. package/dist/editor/selection.js +198 -70
  75. package/dist/editor/selection.js.map +1 -1
  76. package/dist/editor/selectionAction.d.ts +4 -3
  77. package/dist/editor/selectionAction.d.ts.map +1 -1
  78. package/dist/editor/selectionAction.js +9 -5
  79. package/dist/editor/selectionAction.js.map +1 -1
  80. package/dist/editor/stateStorage.d.ts +15 -0
  81. package/dist/editor/stateStorage.d.ts.map +1 -0
  82. package/dist/editor/stateStorage.js +65 -0
  83. package/dist/editor/stateStorage.js.map +1 -0
  84. package/dist/editor/textDocument.d.ts +12 -77
  85. package/dist/editor/textDocument.d.ts.map +1 -1
  86. package/dist/editor/textDocument.js +76 -34
  87. package/dist/editor/textDocument.js.map +1 -1
  88. package/dist/editor/textMeasure.d.ts +7 -12
  89. package/dist/editor/textMeasure.d.ts.map +1 -1
  90. package/dist/editor/textMeasure.js +40 -32
  91. package/dist/editor/textMeasure.js.map +1 -1
  92. package/dist/editor/{tokenzier.d.ts → tokenizer.d.ts} +3 -3
  93. package/dist/editor/tokenizer.d.ts.map +1 -0
  94. package/dist/editor/{tokenzier.js → tokenizer.js} +170 -50
  95. package/dist/editor/tokenizer.js.map +1 -0
  96. package/dist/editor/utils.js +1 -1
  97. package/dist/editor/utils.js.map +1 -1
  98. package/dist/index.d.ts +4 -3
  99. package/dist/index.js +6 -5
  100. package/dist/managers/InteractionManager.d.ts +18 -7
  101. package/dist/managers/InteractionManager.d.ts.map +1 -1
  102. package/dist/managers/InteractionManager.js +154 -99
  103. package/dist/managers/InteractionManager.js.map +1 -1
  104. package/dist/managers/UniversalRenderingManager.d.ts.map +1 -1
  105. package/dist/managers/UniversalRenderingManager.js +1 -2
  106. package/dist/managers/UniversalRenderingManager.js.map +1 -1
  107. package/dist/react/CodeView.d.ts +13 -13
  108. package/dist/react/CodeView.d.ts.map +1 -1
  109. package/dist/react/CodeView.js +37 -28
  110. package/dist/react/CodeView.js.map +1 -1
  111. package/dist/react/EditContext.d.ts +20 -0
  112. package/dist/react/EditContext.d.ts.map +1 -0
  113. package/dist/react/EditContext.js +20 -0
  114. package/dist/react/EditContext.js.map +1 -0
  115. package/dist/react/File.d.ts +2 -1
  116. package/dist/react/File.d.ts.map +1 -1
  117. package/dist/react/File.js +3 -2
  118. package/dist/react/File.js.map +1 -1
  119. package/dist/react/FileDiff.d.ts +2 -2
  120. package/dist/react/FileDiff.d.ts.map +1 -1
  121. package/dist/react/FileDiff.js +3 -2
  122. package/dist/react/FileDiff.js.map +1 -1
  123. package/dist/react/MultiFileDiff.d.ts +2 -2
  124. package/dist/react/MultiFileDiff.d.ts.map +1 -1
  125. package/dist/react/MultiFileDiff.js +3 -2
  126. package/dist/react/MultiFileDiff.js.map +1 -1
  127. package/dist/react/PatchDiff.d.ts +2 -2
  128. package/dist/react/PatchDiff.d.ts.map +1 -1
  129. package/dist/react/PatchDiff.js +3 -2
  130. package/dist/react/PatchDiff.js.map +1 -1
  131. package/dist/react/UnresolvedFile.d.ts +1 -1
  132. package/dist/react/UnresolvedFile.js.map +1 -1
  133. package/dist/react/index.d.ts +4 -4
  134. package/dist/react/index.js +3 -3
  135. package/dist/react/types.d.ts +9 -1
  136. package/dist/react/types.d.ts.map +1 -1
  137. package/dist/react/utils/useFileDiffInstance.d.ts +5 -3
  138. package/dist/react/utils/useFileDiffInstance.d.ts.map +1 -1
  139. package/dist/react/utils/useFileDiffInstance.js +24 -34
  140. package/dist/react/utils/useFileDiffInstance.js.map +1 -1
  141. package/dist/react/utils/useFileInstance.d.ts +5 -3
  142. package/dist/react/utils/useFileInstance.d.ts.map +1 -1
  143. package/dist/react/utils/useFileInstance.js +23 -33
  144. package/dist/react/utils/useFileInstance.js.map +1 -1
  145. package/dist/react/utils/useUnresolvedFileInstance.js +4 -4
  146. package/dist/react/utils/useUnresolvedFileInstance.js.map +1 -1
  147. package/dist/renderers/DiffHunksRenderer.d.ts +41 -1
  148. package/dist/renderers/DiffHunksRenderer.d.ts.map +1 -1
  149. package/dist/renderers/DiffHunksRenderer.js +167 -29
  150. package/dist/renderers/DiffHunksRenderer.js.map +1 -1
  151. package/dist/renderers/FileRenderer.d.ts +20 -1
  152. package/dist/renderers/FileRenderer.d.ts.map +1 -1
  153. package/dist/renderers/FileRenderer.js +119 -29
  154. package/dist/renderers/FileRenderer.js.map +1 -1
  155. package/dist/ssr/index.d.ts +2 -2
  156. package/dist/ssr/preloadDiffs.d.ts.map +1 -1
  157. package/dist/ssr/preloadDiffs.js +3 -1
  158. package/dist/ssr/preloadDiffs.js.map +1 -1
  159. package/dist/ssr/preloadFile.d.ts.map +1 -1
  160. package/dist/ssr/preloadFile.js +2 -0
  161. package/dist/ssr/preloadFile.js.map +1 -1
  162. package/dist/style.js +1 -1
  163. package/dist/types.d.ts +192 -42
  164. package/dist/types.d.ts.map +1 -1
  165. package/dist/utils/annotationHelpers.d.ts +20 -0
  166. package/dist/utils/annotationHelpers.d.ts.map +1 -0
  167. package/dist/utils/annotationHelpers.js +29 -0
  168. package/dist/utils/annotationHelpers.js.map +1 -0
  169. package/dist/utils/computeFileOffsets.d.ts.map +1 -1
  170. package/dist/utils/computeFileOffsets.js +34 -5
  171. package/dist/utils/computeFileOffsets.js.map +1 -1
  172. package/dist/utils/editSessionHunks.d.ts +66 -0
  173. package/dist/utils/editSessionHunks.d.ts.map +1 -0
  174. package/dist/utils/editSessionHunks.js +437 -0
  175. package/dist/utils/editSessionHunks.js.map +1 -0
  176. package/dist/utils/getDiffHunksRendererOptions.d.ts.map +1 -1
  177. package/dist/utils/getDiffHunksRendererOptions.js +2 -1
  178. package/dist/utils/getDiffHunksRendererOptions.js.map +1 -1
  179. package/dist/utils/getFileRendererOptions.d.ts.map +1 -1
  180. package/dist/utils/getFileRendererOptions.js +2 -1
  181. package/dist/utils/getFileRendererOptions.js.map +1 -1
  182. package/dist/utils/getHunkSideBoundaries.d.ts +7 -0
  183. package/dist/utils/getHunkSideBoundaries.d.ts.map +1 -0
  184. package/dist/utils/getHunkSideBoundaries.js +12 -0
  185. package/dist/utils/getHunkSideBoundaries.js.map +1 -0
  186. package/dist/utils/getTotalLineCountFromHunks.d.ts.map +1 -1
  187. package/dist/utils/getTotalLineCountFromHunks.js +2 -1
  188. package/dist/utils/getTotalLineCountFromHunks.js.map +1 -1
  189. package/dist/utils/hydratePartialDiff.d.ts.map +1 -1
  190. package/dist/utils/hydratePartialDiff.js +4 -3
  191. package/dist/utils/hydratePartialDiff.js.map +1 -1
  192. package/dist/utils/isGutterUtilityPath.d.ts +5 -0
  193. package/dist/utils/isGutterUtilityPath.d.ts.map +1 -0
  194. package/dist/utils/isGutterUtilityPath.js +12 -0
  195. package/dist/utils/isGutterUtilityPath.js.map +1 -0
  196. package/dist/utils/iterateOverDiff.d.ts.map +1 -1
  197. package/dist/utils/iterateOverDiff.js +17 -12
  198. package/dist/utils/iterateOverDiff.js.map +1 -1
  199. package/dist/utils/parseMergeConflictDiffFromFile.d.ts.map +1 -1
  200. package/dist/utils/parseMergeConflictDiffFromFile.js +9 -6
  201. package/dist/utils/parseMergeConflictDiffFromFile.js.map +1 -1
  202. package/dist/utils/parsePatchFiles.d.ts.map +1 -1
  203. package/dist/utils/parsePatchFiles.js +6 -3
  204. package/dist/utils/parsePatchFiles.js.map +1 -1
  205. package/dist/utils/realignChangeContent.d.ts +33 -0
  206. package/dist/utils/realignChangeContent.d.ts.map +1 -0
  207. package/dist/utils/realignChangeContent.js +148 -0
  208. package/dist/utils/realignChangeContent.js.map +1 -0
  209. package/dist/utils/renderDiffWithHighlighter.js +1 -1
  210. package/dist/utils/resolveRegion.d.ts.map +1 -1
  211. package/dist/utils/resolveRegion.js +18 -2
  212. package/dist/utils/resolveRegion.js.map +1 -1
  213. package/dist/utils/shouldUseTokenTransformer.d.ts +7 -3
  214. package/dist/utils/shouldUseTokenTransformer.d.ts.map +1 -1
  215. package/dist/utils/shouldUseTokenTransformer.js +1 -1
  216. package/dist/utils/shouldUseTokenTransformer.js.map +1 -1
  217. package/dist/utils/updateDiffHunks.d.ts +8 -2
  218. package/dist/utils/updateDiffHunks.d.ts.map +1 -1
  219. package/dist/utils/updateDiffHunks.js +9 -7
  220. package/dist/utils/updateDiffHunks.js.map +1 -1
  221. package/dist/utils/virtualDiffLayout.d.ts +42 -2
  222. package/dist/utils/virtualDiffLayout.d.ts.map +1 -1
  223. package/dist/utils/virtualDiffLayout.js +101 -7
  224. package/dist/utils/virtualDiffLayout.js.map +1 -1
  225. package/dist/worker/WorkerPoolManager.d.ts +2 -1
  226. package/dist/worker/WorkerPoolManager.d.ts.map +1 -1
  227. package/dist/worker/WorkerPoolManager.js +3 -0
  228. package/dist/worker/WorkerPoolManager.js.map +1 -1
  229. package/dist/worker/worker-portable.js +60 -20
  230. package/dist/worker/worker-portable.js.map +1 -1
  231. package/dist/worker/worker.js +61 -19
  232. package/dist/worker/worker.js.map +1 -1
  233. package/package.json +10 -7
  234. package/dist/editor/index.d.ts +0 -3
  235. package/dist/editor/index.js +0 -3
  236. package/dist/editor/tokenzier.d.ts.map +0 -1
  237. package/dist/editor/tokenzier.js.map +0 -1
  238. package/dist/react/EditorContext.d.ts +0 -15
  239. package/dist/react/EditorContext.d.ts.map +0 -1
  240. package/dist/react/EditorContext.js +0 -23
  241. package/dist/react/EditorContext.js.map +0 -1
@@ -20,9 +20,11 @@ import { getHighlighterOptions } from "../utils/getHighlighterOptions.js";
20
20
  import { getLineAnnotationName } from "../utils/getLineAnnotationName.js";
21
21
  import { isFilePlainText } from "../utils/isFilePlainText.js";
22
22
  import { renderFileWithHighlighter } from "../utils/renderFileWithHighlighter.js";
23
- import { shouldUseTokenTransformer } from "../utils/shouldUseTokenTransformer.js";
24
23
  import { toHtml } from "hast-util-to-html";
25
24
  //#region src/renderers/FileRenderer.ts
25
+ function isLineCacheForFile(lineCache, file) {
26
+ return file.cacheKey == null ? lineCache.file === file && lineCache.sourceContents === file.contents : lineCache.cacheKey === file.cacheKey;
27
+ }
26
28
  let instanceId = -1;
27
29
  var FileRenderer = class {
28
30
  options;
@@ -34,7 +36,9 @@ var FileRenderer = class {
34
36
  computedLang = "text";
35
37
  lineAnnotations = {};
36
38
  lineCache;
39
+ pendingStructuralRows;
37
40
  textDocumentCache = /* @__PURE__ */ new WeakMap();
41
+ editSessionActive = false;
38
42
  constructor(options = { theme: DEFAULT_THEMES }, onRenderUpdate, workerManager) {
39
43
  this.options = options;
40
44
  this.onRenderUpdate = onRenderUpdate;
@@ -63,20 +67,52 @@ var FileRenderer = class {
63
67
  this.workerManager = void 0;
64
68
  this.onRenderUpdate = void 0;
65
69
  }
70
+ /**
71
+ * Enter edit-session mode: rendering happens locally with the token
72
+ * transformer forced on, and worker-pool requests/results are suspended
73
+ * for this renderer. Called on every editor attach, including a re-attach
74
+ * after recycle.
75
+ */
76
+ beginEditSession() {
77
+ this.editSessionActive = true;
78
+ }
79
+ /** Leave edit-session mode. Rendering returns to the pool when one works. */
80
+ endEditSession() {
81
+ this.editSessionActive = false;
82
+ }
83
+ /**
84
+ * Ensures that the DOM is compatible with editor render updates
85
+ */
86
+ editorRenderReady() {
87
+ return this.renderCache?.options.useTokenTransformer === true && this.renderCache.highlighted && this.renderCache.result != null;
88
+ }
66
89
  recycle() {
67
- this.syncEditedContentsToFile();
68
90
  this.clearRenderCache();
69
91
  this.highlighter = void 0;
70
92
  this.workerManager?.cleanUpTasks(this);
71
93
  this.lineCache = void 0;
94
+ this.endEditSession();
72
95
  this.textDocumentCache = /* @__PURE__ */ new WeakMap();
73
96
  }
74
97
  syncEditedContentsToFile() {
75
98
  const { renderCache, lineCache } = this;
76
- if (renderCache?.isDirty !== true || lineCache == null || renderCache.file.cacheKey == null || renderCache.file.cacheKey !== lineCache.cacheKey) return;
99
+ if (renderCache?.isDirty !== true || lineCache == null || !isLineCacheForFile(lineCache, renderCache.file)) return;
77
100
  renderCache.file.contents = lineCache.lines.join("");
78
101
  }
102
+ hasUnkeyedFileContentsChanged(file) {
103
+ const { lineCache } = this;
104
+ return file.cacheKey == null && lineCache != null && lineCache.file === file && lineCache.sourceContents !== file.contents;
105
+ }
106
+ invalidateChangedUnkeyedFile(file) {
107
+ if (!this.hasUnkeyedFileContentsChanged(file)) return;
108
+ this.workerManager?.cleanUpTasks(this);
109
+ this.clearRenderCache();
110
+ this.lineCache = void 0;
111
+ this.textDocumentCache = /* @__PURE__ */ new WeakMap();
112
+ }
79
113
  clearRenderCache() {
114
+ this.syncEditedContentsToFile();
115
+ this.pendingStructuralRows = void 0;
80
116
  const renderCache = this.renderCache;
81
117
  this.renderCache = void 0;
82
118
  if (renderCache != null && renderCache.isDirty === true && renderCache.file.cacheKey != null) this.workerManager?.evictFileFromCache(renderCache.file.cacheKey);
@@ -93,20 +129,30 @@ var FileRenderer = class {
93
129
  result: massiveFile ? void 0 : cache?.result,
94
130
  renderRange: void 0
95
131
  };
96
- if (this.workerManager?.isWorkingPool() === true) {
132
+ if (!this.editSessionActive && this.workerManager?.isWorkingPool() === true) {
97
133
  if (this.renderCache.result == null && !massiveFile) this.workerManager.highlightFileAST(this, file);
98
134
  } else if (this.highlighter == null) {
99
135
  this.computedLang = file.lang ?? getFiletypeFromFileName(file.name);
100
136
  this.initializeHighlighter();
101
137
  }
102
138
  }
139
+ getLocalHighlightTheme() {
140
+ return this.workerManager?.getFileRenderOptions().theme ?? this.options.theme ?? DEFAULT_THEMES;
141
+ }
103
142
  getRenderOptions(file) {
104
143
  const options = (() => {
105
- if (this.workerManager?.isWorkingPool() === true) return this.workerManager.getFileRenderOptions();
106
- const { theme = DEFAULT_THEMES, tokenizeMaxLineLength = 1e3 } = this.options;
144
+ if (this.workerManager?.isWorkingPool() === true) {
145
+ const poolOptions = this.workerManager.getFileRenderOptions();
146
+ if (this.editSessionActive && poolOptions.useTokenTransformer !== true) return {
147
+ ...poolOptions,
148
+ useTokenTransformer: true
149
+ };
150
+ return poolOptions;
151
+ }
152
+ const { tokenizeMaxLineLength = 1e3 } = this.options;
107
153
  return {
108
- theme,
109
- useTokenTransformer: shouldUseTokenTransformer(this.options),
154
+ theme: this.getLocalHighlightTheme(),
155
+ useTokenTransformer: this.editSessionActive || this.options.useTokenTransformer === true,
110
156
  tokenizeMaxLineLength
111
157
  };
112
158
  })();
@@ -125,32 +171,35 @@ var FileRenderer = class {
125
171
  };
126
172
  }
127
173
  getOrCreateLineCache(file) {
128
- if (file.cacheKey == null) {
129
- this.lineCache = void 0;
130
- return linesFromFileContents(file.contents);
131
- }
174
+ this.invalidateChangedUnkeyedFile(file);
132
175
  let { lineCache } = this;
133
- if (lineCache == null || lineCache.cacheKey !== file.cacheKey) lineCache = {
176
+ if (lineCache == null || !isLineCacheForFile(lineCache, file)) lineCache = {
134
177
  cacheKey: file.cacheKey,
178
+ file,
179
+ sourceContents: file.contents,
135
180
  lines: linesFromFileContents(file.contents)
136
181
  };
137
182
  this.lineCache = lineCache;
138
183
  return lineCache.lines;
139
184
  }
140
185
  getLineCount(file) {
141
- return this.textDocumentCache.get(file)?.lineCount ?? this.getOrCreateLineCache(file).length;
186
+ const lines = this.getOrCreateLineCache(file);
187
+ return this.textDocumentCache.get(file)?.lineCount ?? lines.length;
142
188
  }
143
- updateRenderCache(dirtyLines, themeType) {
189
+ updateRenderCache(dirtyLines, themeType, lineCountChangeInFlight = false) {
190
+ this.pendingStructuralRows = void 0;
144
191
  if (this.renderCache == null) return;
145
192
  const { file, result } = this.renderCache;
146
193
  if (result == null) return;
147
- const lineCache = this.lineCache != null && file.cacheKey != null && this.lineCache.cacheKey === file.cacheKey ? this.lineCache : void 0;
194
+ const pendingStructuralRows = lineCountChangeInFlight ? /* @__PURE__ */ new Map() : void 0;
195
+ this.pendingStructuralRows = pendingStructuralRows;
196
+ const lineCache = this.lineCache != null && isLineCacheForFile(this.lineCache, file) ? this.lineCache : void 0;
148
197
  for (const [line, tokens] of dirtyLines) {
149
- if (lineCache != null && line < lineCache.lines.length) {
198
+ if (pendingStructuralRows === void 0 && lineCache != null && line < lineCache.lines.length) {
150
199
  const lineText = tokens.map((token) => token[2]).join("");
151
200
  lineCache.lines[line] = applyLineTextWithNewline(lineCache.lines[line] ?? "", lineText);
152
201
  }
153
- result.code[line] = {
202
+ const row = {
154
203
  type: "element",
155
204
  tagName: "div",
156
205
  properties: {
@@ -176,7 +225,7 @@ var FileRenderer = class {
176
225
  tagName: "span",
177
226
  properties: {
178
227
  "data-char": char,
179
- style: `--diffs-token-${themeType}:${fg};`
228
+ style: `color:${fg};`
180
229
  },
181
230
  children: [{
182
231
  type: "text",
@@ -185,17 +234,34 @@ var FileRenderer = class {
185
234
  };
186
235
  })
187
236
  };
237
+ if (pendingStructuralRows !== void 0) pendingStructuralRows.set(line, row);
238
+ else result.code[line] = row;
188
239
  }
189
240
  result.baseThemeType = themeType;
190
241
  this.renderCache.isDirty = true;
191
242
  }
192
243
  applyDocumentChange(textDocument) {
244
+ const pendingStructuralRows = this.pendingStructuralRows;
245
+ this.pendingStructuralRows = void 0;
193
246
  if (this.renderCache == null) return;
194
247
  const { file, result } = this.renderCache;
195
248
  if (result == null) return;
196
- if (result.code.length !== textDocument.lineCount) {
197
- result.code.length = Math.min(result.code.length, textDocument.lineCount);
198
- for (let i = result.code.length; i < textDocument.lineCount; i++) result.code.push({
249
+ const previousLines = this.lineCache != null && isLineCacheForFile(this.lineCache, file) ? this.lineCache.lines : linesFromFileContents(file.contents);
250
+ const nextLines = linesFromFileContents(textDocument.getText());
251
+ if (previousLines.length !== nextLines.length) {
252
+ const maxShared = Math.min(previousLines.length, nextLines.length);
253
+ let prefix = 0;
254
+ while (prefix < maxShared && previousLines[prefix] === nextLines[prefix]) prefix++;
255
+ let suffix = 0;
256
+ while (suffix < maxShared - prefix && previousLines[previousLines.length - 1 - suffix] === nextLines[nextLines.length - 1 - suffix]) suffix++;
257
+ const previousCode = result.code;
258
+ result.code = new Array(nextLines.length);
259
+ for (let i = 0; i < prefix; i++) result.code[i] = previousCode[i];
260
+ for (let i = 0; i < suffix; i++) result.code[nextLines.length - 1 - i] = previousCode[previousLines.length - 1 - i];
261
+ if (pendingStructuralRows !== void 0) {
262
+ for (const [line, row] of pendingStructuralRows) if (line < nextLines.length) result.code[line] = row;
263
+ }
264
+ for (let i = prefix; i < nextLines.length - suffix; i++) result.code[i] ??= {
199
265
  type: "element",
200
266
  tagName: "div",
201
267
  properties: {
@@ -212,18 +278,34 @@ var FileRenderer = class {
212
278
  value: textDocument.getLineText(i)
213
279
  }]
214
280
  }]
215
- });
281
+ };
282
+ for (let i = 0; i < result.code.length; i++) {
283
+ const line = result.code[i];
284
+ if (line?.type === "element") {
285
+ line.properties["data-line"] = i + 1;
286
+ line.properties["data-line-index"] = i;
287
+ }
288
+ }
216
289
  this.renderCache.isDirty = true;
217
290
  }
218
- if (file.cacheKey != null) this.lineCache = {
291
+ this.lineCache = {
219
292
  cacheKey: file.cacheKey,
220
- lines: linesFromFileContents(textDocument.getText())
293
+ file,
294
+ sourceContents: file.contents,
295
+ lines: nextLines
221
296
  };
222
297
  this.textDocumentCache.set(file, textDocument);
223
298
  }
224
299
  renderFile(file = this.renderCache?.file, renderRange = DEFAULT_RENDER_RANGE) {
225
300
  if (file == null) return;
301
+ this.invalidateChangedUnkeyedFile(file);
302
+ if (this.renderCache?.isDirty === true && !areFilesEqual(file, this.renderCache.file)) {
303
+ this.clearRenderCache();
304
+ this.lineCache = void 0;
305
+ this.textDocumentCache = /* @__PURE__ */ new WeakMap();
306
+ }
226
307
  let { options, forceHighlight } = this.getRenderOptions(file);
308
+ if (this.renderCache?.isDirty === true && !areFileRenderOptionsEqual(options, this.renderCache.options)) this.clearRenderCache();
227
309
  const cache = this.getMatchingWorkerResultCache(file, options);
228
310
  if (cache != null && !this.hasHighlightedRenderCache(file, options)) {
229
311
  this.renderCache = {
@@ -246,7 +328,7 @@ var FileRenderer = class {
246
328
  const forcePlainText = !hasContent || isFilePlainText(file) || isFileMassive(lines.length, this.getTokenizeMaxLength());
247
329
  const newContent = !areFilesEqual(file, this.renderCache.file);
248
330
  const newRenderRange = !areRenderRangesEqual(this.renderCache.renderRange, renderRange);
249
- if (this.workerManager?.isWorkingPool() === true) {
331
+ if (!this.editSessionActive && this.workerManager?.isWorkingPool() === true) {
250
332
  if (forcePlainText || this.renderCache.result == null || !this.renderCache.highlighted && (newContent || newRenderRange)) {
251
333
  this.renderCache.file = file;
252
334
  this.renderCache.options = options;
@@ -272,7 +354,7 @@ var FileRenderer = class {
272
354
  }
273
355
  if (!hasThemes || !forcePlainText && !hasLangs) this.asyncHighlight(file).then(({ result, options }) => {
274
356
  if (this.renderCache != null) this.renderCache.highlighted = false;
275
- this.onHighlightSuccess(file, result, options, !forcePlainText);
357
+ this.applyHighlightResult(file, result, options, !forcePlainText);
276
358
  });
277
359
  }
278
360
  return this.renderCache.result != null ? this.processFileResult(this.renderCache.file, renderRange, this.renderCache.result) : void 0;
@@ -284,7 +366,7 @@ var FileRenderer = class {
284
366
  async asyncHighlight(file) {
285
367
  const forcePlainText = isFileMassive(this.getOrCreateLineCache(file).length, this.getTokenizeMaxLength());
286
368
  this.computedLang = forcePlainText ? "text" : file.lang ?? getFiletypeFromFileName(file.name);
287
- const hasThemes = this.highlighter != null && hasResolvedThemes(getThemes(this.options.theme));
369
+ const hasThemes = this.highlighter != null && hasResolvedThemes(getThemes(this.getLocalHighlightTheme()));
288
370
  const hasLangs = forcePlainText || this.highlighter != null && areLanguagesAttached(this.computedLang);
289
371
  if (this.highlighter == null || !hasThemes || !hasLangs) this.highlighter = await this.initializeHighlighter();
290
372
  return this.renderFileWithHighlighter(file, this.highlighter, forcePlainText);
@@ -393,10 +475,17 @@ var FileRenderer = class {
393
475
  }));
394
476
  }
395
477
  async initializeHighlighter() {
396
- this.highlighter = await getSharedHighlighter(getHighlighterOptions(this.computedLang, this.options));
478
+ this.highlighter = await getSharedHighlighter(getHighlighterOptions(this.computedLang, {
479
+ theme: this.getLocalHighlightTheme(),
480
+ preferredHighlighter: this.workerManager?.getPreferredHighlighter() ?? this.options.preferredHighlighter
481
+ }));
397
482
  return this.highlighter;
398
483
  }
399
484
  onHighlightSuccess(file, result, options, highlighted = true) {
485
+ if (this.editSessionActive) return;
486
+ this.applyHighlightResult(file, result, options, highlighted);
487
+ }
488
+ applyHighlightResult(file, result, options, highlighted = true) {
400
489
  if (this.renderCache == null) return;
401
490
  const triggerRenderUpdate = !areFilesEqual(file, this.renderCache.file) || !this.renderCache.highlighted || !areFileRenderOptionsEqual(options, this.renderCache.options);
402
491
  this.renderCache = {
@@ -409,6 +498,7 @@ var FileRenderer = class {
409
498
  if (triggerRenderUpdate) this.onRenderUpdate?.();
410
499
  }
411
500
  getMatchingWorkerResultCache(file, options) {
501
+ if (this.editSessionActive) return;
412
502
  const cache = this.workerManager?.getFileResultCache(file);
413
503
  if (cache == null || !areFileRenderOptionsEqual(options, cache.options)) return;
414
504
  return cache;
@@ -1 +1 @@
1
- {"version":3,"file":"FileRenderer.js","names":[],"sources":["../../src/renderers/FileRenderer.ts"],"sourcesContent":["import type { ElementContent, Element as HASTElement } from 'hast';\nimport { toHtml } from 'hast-util-to-html';\n\nimport {\n DEFAULT_RENDER_RANGE,\n DEFAULT_THEMES,\n DEFAULT_TOKENIZE_MAX_LENGTH,\n} from '../constants';\nimport { areLanguagesAttached } from '../highlighter/languages/areLanguagesAttached';\nimport {\n getHighlighterIfLoaded,\n getSharedHighlighter,\n} from '../highlighter/shared_highlighter';\nimport { areThemesAttached } from '../highlighter/themes/areThemesAttached';\nimport { hasResolvedThemes } from '../highlighter/themes/hasResolvedThemes';\nimport type {\n BaseCodeOptions,\n DiffsHighlighter,\n DiffsTextDocument,\n FileContents,\n FileHeaderRenderMode,\n HighlightedToken,\n LineAnnotation,\n RenderedFileASTCache,\n RenderFileOptions,\n RenderFileResult,\n RenderRange,\n SupportedLanguages,\n ThemedFileResult,\n} from '../types';\nimport { applyLineTextWithNewline } from '../utils/applyLineTextWithNewline';\nimport { areFileRenderOptionsEqual } from '../utils/areFileRenderOptionsEqual';\nimport { areFilesEqual } from '../utils/areFilesEqual';\nimport { areRenderRangesEqual } from '../utils/areRenderRangesEqual';\nimport { linesFromFileContents } from '../utils/computeFileOffsets';\nimport { createAnnotationElement } from '../utils/createAnnotationElement';\nimport { createContentColumn } from '../utils/createContentColumn';\nimport { createFileHeaderElement } from '../utils/createFileHeaderElement';\nimport { createPreElement } from '../utils/createPreElement';\nimport { getFiletypeFromFileName } from '../utils/getFiletypeFromFileName';\nimport { getHighlighterOptions } from '../utils/getHighlighterOptions';\nimport { getLineAnnotationName } from '../utils/getLineAnnotationName';\nimport { getThemes } from '../utils/getThemes';\nimport {\n createGutterGap,\n createGutterItem,\n createGutterWrapper,\n createHastElement,\n} from '../utils/hast_utils';\nimport {\n FILE_ANNOTATION_HUNK_INDEX,\n FILE_ANNOTATION_LINE_INDEX,\n getFileAnnotations,\n shouldRenderFileAnnotations,\n} from '../utils/includesFileAnnotations';\nimport { isFilePlainText } from '../utils/isFilePlainText';\nimport { renderFileWithHighlighter } from '../utils/renderFileWithHighlighter';\nimport { shouldUseTokenTransformer } from '../utils/shouldUseTokenTransformer';\nimport type { WorkerPoolManager } from '../worker';\n\ntype AnnotationLineMap<LAnnotation> = Record<\n number,\n LineAnnotation<LAnnotation>[] | undefined\n>;\n\ninterface GetRenderOptionsReturn {\n options: RenderFileOptions;\n forceHighlight: boolean;\n}\n\nexport interface FileRenderResult {\n gutterAST: ElementContent[];\n contentAST: ElementContent[];\n preAST: HASTElement;\n headerAST: HASTElement | undefined;\n css: string;\n totalLines: number;\n themeStyles: string;\n baseThemeType: 'light' | 'dark' | undefined;\n rowCount: number;\n bufferBefore: number;\n bufferAfter: number;\n}\n\ninterface LineCache {\n cacheKey: string | undefined;\n lines: string[];\n}\n\nexport interface FileRendererOptions extends BaseCodeOptions {\n headerRenderMode?: FileHeaderRenderMode;\n}\n\nlet instanceId = -1;\n\nexport class FileRenderer<LAnnotation = undefined> {\n readonly __id: string = `file-renderer:${++instanceId}`;\n\n private highlighter: DiffsHighlighter | undefined;\n private renderCache: RenderedFileASTCache | undefined;\n private computedLang: SupportedLanguages = 'text';\n private lineAnnotations: AnnotationLineMap<LAnnotation> = {};\n private lineCache: LineCache | undefined;\n private textDocumentCache = new WeakMap<FileContents, DiffsTextDocument>();\n\n constructor(\n public options: FileRendererOptions = { theme: DEFAULT_THEMES },\n private onRenderUpdate?: () => unknown,\n private workerManager?: WorkerPoolManager | undefined\n ) {\n if (workerManager?.isWorkingPool() !== true) {\n this.highlighter = areThemesAttached(options.theme ?? DEFAULT_THEMES)\n ? getHighlighterIfLoaded()\n : undefined;\n }\n }\n\n public setOptions(options: FileRendererOptions): void {\n this.options = options;\n }\n\n public mergeOptions(options: Partial<FileRendererOptions>): void {\n this.options = { ...this.options, ...options };\n }\n\n public setLineAnnotations(\n lineAnnotations: LineAnnotation<LAnnotation>[]\n ): void {\n this.lineAnnotations = {};\n for (const annotation of lineAnnotations) {\n const arr = this.lineAnnotations[annotation.lineNumber] ?? [];\n this.lineAnnotations[annotation.lineNumber] = arr;\n arr.push(annotation);\n }\n }\n\n public cleanUp(): void {\n this.recycle();\n this.workerManager = undefined;\n this.onRenderUpdate = undefined;\n }\n\n public recycle(): void {\n this.syncEditedContentsToFile();\n this.clearRenderCache();\n this.highlighter = undefined;\n this.workerManager?.cleanUpTasks(this);\n this.lineCache = undefined;\n // The edited-document cache is only coherent alongside the render cache\n // it patched. Keeping it across a recycle would let getLineCount report\n // editor-session line counts (keyed by the long-lived file object) against\n // a result rebuilt from the file's own contents, which processFileResult\n // treats as a missing-line error.\n this.textDocumentCache = new WeakMap();\n }\n\n // An edit session patches the render caches in place but never rewrites\n // `file.contents`, so a recycled host would otherwise rebuild from the\n // pre-edit text while the editor resumes its retained (edited) document.\n // Diffs don't have this problem because DiffHunksRenderer keeps\n // `diff.additionLines` in sync during the session; the file equivalent is\n // joining the session-synced line cache back into the file object before\n // the caches are dropped.\n private syncEditedContentsToFile(): void {\n const { renderCache, lineCache } = this;\n if (\n renderCache?.isDirty !== true ||\n lineCache == null ||\n renderCache.file.cacheKey == null ||\n renderCache.file.cacheKey !== lineCache.cacheKey\n ) {\n return;\n }\n renderCache.file.contents = lineCache.lines.join('');\n }\n\n public clearRenderCache(): void {\n const renderCache = this.renderCache;\n this.renderCache = undefined;\n if (\n renderCache != null &&\n renderCache.isDirty === true &&\n renderCache.file.cacheKey != null\n ) {\n // The render cache has been updated by the host, let's purge it\n // from the worker manager cache.\n this.workerManager?.evictFileFromCache(renderCache.file.cacheKey);\n }\n }\n\n public hydrate(file: FileContents): void {\n const { options } = this.getRenderOptions(file);\n const lines = this.getOrCreateLineCache(file);\n const massiveFile = isFileMassive(\n lines.length,\n this.getTokenizeMaxLength()\n );\n let cache = this.workerManager?.getFileResultCache(file);\n if (cache != null && !areFileRenderOptionsEqual(options, cache.options)) {\n cache = undefined;\n }\n this.renderCache ??= {\n file,\n options,\n highlighted: !massiveFile && !isFilePlainText(file),\n result: massiveFile ? undefined : cache?.result,\n // FIXME(amadeus): Add support for renderRanges\n renderRange: undefined,\n };\n if (this.workerManager?.isWorkingPool() === true) {\n if (this.renderCache.result == null && !massiveFile) {\n // We should only kick off a preload of the AST if we have a WorkerPool\n this.workerManager.highlightFileAST(this, file);\n }\n }\n // Lets attempt to get the highlighter/languages ready immediately\n else if (this.highlighter == null) {\n this.computedLang = file.lang ?? getFiletypeFromFileName(file.name);\n void this.initializeHighlighter();\n }\n }\n\n private getRenderOptions(file: FileContents): GetRenderOptionsReturn {\n const options: RenderFileOptions = (() => {\n if (this.workerManager?.isWorkingPool() === true) {\n return this.workerManager.getFileRenderOptions();\n }\n const { theme = DEFAULT_THEMES, tokenizeMaxLineLength = 1000 } =\n this.options;\n return {\n theme,\n useTokenTransformer: shouldUseTokenTransformer(this.options),\n tokenizeMaxLineLength,\n };\n })();\n const { renderCache } = this;\n if (renderCache?.result == null) {\n return { options, forceHighlight: true };\n }\n if (\n !areFilesEqual(file, renderCache.file) ||\n !areFileRenderOptionsEqual(options, renderCache.options)\n ) {\n return { options, forceHighlight: true };\n }\n return { options, forceHighlight: false };\n }\n\n public getOrCreateLineCache(file: FileContents): string[] {\n // Uncached files will get split every time, not the greatest experience\n // tbh... but something people should try to optimize away\n if (file.cacheKey == null) {\n this.lineCache = undefined;\n return linesFromFileContents(file.contents);\n }\n\n let { lineCache } = this;\n if (lineCache == null || lineCache.cacheKey !== file.cacheKey) {\n lineCache = {\n cacheKey: file.cacheKey,\n lines: linesFromFileContents(file.contents),\n };\n }\n this.lineCache = lineCache;\n return lineCache.lines;\n }\n\n // when a emitLineCountChange is called,\n // calculate the line count using the cached text document\n public getLineCount(file: FileContents): number {\n return (\n this.textDocumentCache.get(file)?.lineCount ??\n this.getOrCreateLineCache(file).length\n );\n }\n\n public updateRenderCache(\n dirtyLines: Map<number, Array<HighlightedToken>>,\n themeType: 'dark' | 'light'\n ): void {\n if (this.renderCache == null) {\n return;\n }\n const { file, result } = this.renderCache;\n if (result == null) {\n return;\n }\n // Mirror DiffHunksRenderer keeping `diff.additionLines` in sync during an\n // edit session: patch the split-line cache with the edited line text so\n // recycle() can persist the session's contents into the file. The line\n // cache includes the document's trailing empty line, so editor line\n // indexes map 1:1; lines past the cache (document grew) are handled by\n // applyDocumentChange instead.\n const lineCache =\n this.lineCache != null &&\n file.cacheKey != null &&\n this.lineCache.cacheKey === file.cacheKey\n ? this.lineCache\n : undefined;\n for (const [line, tokens] of dirtyLines) {\n if (lineCache != null && line < lineCache.lines.length) {\n const lineText = tokens.map((token) => token[2]).join('');\n lineCache.lines[line] = applyLineTextWithNewline(\n lineCache.lines[line] ?? '',\n lineText\n );\n }\n result.code[line] = {\n type: 'element',\n tagName: 'div',\n properties: {\n 'data-line': line + 1,\n 'data-line-type': 'context',\n 'data-line-index': line,\n },\n children: tokens.map(([char, fg, text]) => {\n if (char === 0 && fg === '') {\n if (text === '') {\n return {\n type: 'element',\n tagName: 'br',\n properties: {},\n children: [],\n };\n }\n return { type: 'text', value: text };\n }\n return {\n type: 'element',\n tagName: 'span',\n properties: {\n 'data-char': char,\n style: `--diffs-token-${themeType}:${fg};`,\n },\n children: [{ type: 'text', value: text }],\n };\n }),\n };\n }\n\n result.baseThemeType = themeType;\n this.renderCache.isDirty = true;\n }\n\n // normally triggered by the host when the document line count changes\n public applyDocumentChange(textDocument: DiffsTextDocument): void {\n if (this.renderCache == null) {\n return undefined;\n }\n const { file, result } = this.renderCache;\n // Without a result there is nothing to reconcile the document against, so\n // do not record it either: the document cache must never claim line\n // counts the (possibly still highlighting) result cannot back, or the\n // async highlight pass would process lines that do not exist.\n if (result == null) {\n return undefined;\n }\n if (result.code.length !== textDocument.lineCount) {\n result.code.length = Math.min(result.code.length, textDocument.lineCount);\n for (let i = result.code.length; i < textDocument.lineCount; i++) {\n // prefill lines with plain text content\n result.code.push({\n type: 'element',\n tagName: 'div',\n properties: {\n 'data-line': i + 1,\n 'data-line-type': 'context',\n 'data-line-index': i,\n },\n children: [\n {\n type: 'element',\n tagName: 'span',\n properties: {\n 'data-char': 0,\n },\n children: [\n {\n type: 'text',\n value: textDocument.getLineText(i),\n },\n ],\n },\n ],\n });\n }\n this.renderCache.isDirty = true;\n }\n // A line-count change invalidates the per-line sync updateRenderCache\n // performs, so rebuild the split-line cache from the document wholesale\n // (the file analog of DiffHunksRenderer re-splitting `additionLines`).\n if (file.cacheKey != null) {\n this.lineCache = {\n cacheKey: file.cacheKey,\n lines: linesFromFileContents(textDocument.getText()),\n };\n }\n this.textDocumentCache.set(file, textDocument);\n }\n\n public renderFile(\n file: FileContents | undefined = this.renderCache?.file,\n renderRange: RenderRange = DEFAULT_RENDER_RANGE\n ): FileRenderResult | undefined {\n if (file == null) {\n return undefined;\n }\n let { options, forceHighlight } = this.getRenderOptions(file);\n const cache = this.getMatchingWorkerResultCache(file, options);\n if (cache != null && !this.hasHighlightedRenderCache(file, options)) {\n this.renderCache = {\n file,\n highlighted: true,\n renderRange: undefined,\n ...cache,\n };\n forceHighlight = false;\n }\n this.renderCache ??= {\n file,\n highlighted: false,\n options,\n result: undefined,\n renderRange: undefined,\n };\n const lines = this.getOrCreateLineCache(file);\n const hasContent = file.contents.length > 0;\n const forcePlainText =\n !hasContent ||\n isFilePlainText(file) ||\n isFileMassive(lines.length, this.getTokenizeMaxLength());\n const newContent = !areFilesEqual(file, this.renderCache.file);\n const newRenderRange = !areRenderRangesEqual(\n this.renderCache.renderRange,\n renderRange\n );\n if (this.workerManager?.isWorkingPool() === true) {\n // Cache invalidation based on renderRange comparison\n if (\n forcePlainText ||\n this.renderCache.result == null ||\n (!this.renderCache.highlighted && (newContent || newRenderRange))\n ) {\n this.renderCache.file = file;\n this.renderCache.options = options;\n this.renderCache.highlighted = false;\n if (\n this.renderCache.result == null ||\n newContent ||\n newRenderRange ||\n forceHighlight\n ) {\n this.renderCache.result = this.workerManager.getPlainFileAST(\n file,\n renderRange.startingLine,\n renderRange.totalLines,\n lines\n );\n }\n this.renderCache.renderRange = renderRange;\n }\n\n if (\n !forcePlainText &&\n hasContent &&\n (!this.renderCache.highlighted || forceHighlight)\n ) {\n this.workerManager.highlightFileAST(this, file);\n }\n } else {\n this.computedLang = file.lang ?? getFiletypeFromFileName(file.name);\n const hasThemes =\n this.highlighter != null && areThemesAttached(options.theme);\n const hasLangs =\n this.highlighter != null && areLanguagesAttached(this.computedLang);\n const canHighlight = !forcePlainText && hasLangs;\n\n // If we have any semblance of a highlighter with the correct theme(s)\n // attached, we can kick off some form of rendering. If we don't have\n // the correct language, then we can render plain text and after kick off\n // an async job to get the highlighted AST\n if (\n this.highlighter != null &&\n hasThemes &&\n (forceHighlight ||\n forcePlainText ||\n (!this.renderCache.highlighted && canHighlight) ||\n this.renderCache.result == null)\n ) {\n const { result, options } = this.renderFileWithHighlighter(\n file,\n this.highlighter,\n forcePlainText || !hasLangs\n );\n this.renderCache = {\n file,\n options,\n highlighted: canHighlight,\n result,\n renderRange: undefined,\n };\n }\n\n // If we get in here it means we'll have to kick off an async highlight\n // process which will involve initializing the highlighter with new themes\n // and languages\n if (!hasThemes || (!forcePlainText && !hasLangs)) {\n void this.asyncHighlight(file).then(({ result, options }) => {\n // In this case we need to force a re-render, so we can do that by\n // reaching into renderCache\n if (this.renderCache != null) {\n this.renderCache.highlighted = false;\n }\n this.onHighlightSuccess(file, result, options, !forcePlainText);\n });\n }\n }\n\n return this.renderCache.result != null\n ? this.processFileResult(\n this.renderCache.file,\n renderRange,\n this.renderCache.result\n )\n : undefined;\n }\n\n async asyncRender(\n file: FileContents,\n renderRange: RenderRange = DEFAULT_RENDER_RANGE\n ): Promise<FileRenderResult> {\n const { result } = await this.asyncHighlight(file);\n return this.processFileResult(file, renderRange, result);\n }\n\n private async asyncHighlight(file: FileContents): Promise<RenderFileResult> {\n const lines = this.getOrCreateLineCache(file);\n const forcePlainText = isFileMassive(\n lines.length,\n this.getTokenizeMaxLength()\n );\n this.computedLang = forcePlainText\n ? 'text'\n : (file.lang ?? getFiletypeFromFileName(file.name));\n const hasThemes =\n this.highlighter != null &&\n hasResolvedThemes(getThemes(this.options.theme));\n const hasLangs =\n forcePlainText ||\n (this.highlighter != null && areLanguagesAttached(this.computedLang));\n // If we don't have the required langs or themes, then we need to\n // initialize the highlighter to load the appropriate languages and themes\n if (this.highlighter == null || !hasThemes || !hasLangs) {\n this.highlighter = await this.initializeHighlighter();\n }\n return this.renderFileWithHighlighter(\n file,\n this.highlighter,\n forcePlainText\n );\n }\n\n private renderFileWithHighlighter(\n file: FileContents,\n highlighter: DiffsHighlighter,\n forcePlainText = false\n ): RenderFileResult {\n const { options } = this.getRenderOptions(file);\n const result = renderFileWithHighlighter(file, highlighter, options, {\n forcePlainText,\n });\n return { result, options };\n }\n\n private processFileResult(\n file: FileContents,\n renderRange: RenderRange,\n { code, themeStyles, baseThemeType }: ThemedFileResult\n ): FileRenderResult {\n const totalLines = this.getLineCount(file);\n const { disableFileHeader = false } = this.options;\n const contentArray: ElementContent[] = [];\n const gutter = createGutterWrapper();\n const endLine = Math.min(\n renderRange.startingLine + renderRange.totalLines,\n totalLines\n );\n let rowCount = 0;\n\n const fileLevelAnnotations = shouldRenderFileAnnotations(renderRange)\n ? getFileAnnotations(this.lineAnnotations)\n : undefined;\n if (fileLevelAnnotations != null) {\n gutter.children.push(createGutterGap('context', 'annotation', 1));\n contentArray.push(\n createAnnotationElement({\n type: 'annotation',\n hunkIndex: FILE_ANNOTATION_HUNK_INDEX,\n lineIndex: FILE_ANNOTATION_LINE_INDEX,\n annotations: fileLevelAnnotations.map((annotation) =>\n getLineAnnotationName(annotation)\n ),\n })\n );\n rowCount++;\n }\n\n for (\n let lineIndex = renderRange.startingLine;\n lineIndex < endLine;\n lineIndex++\n ) {\n const lineNumber = lineIndex + 1;\n\n // Sparse array - directly indexed by lineIndex\n const line = code[lineIndex];\n if (line == null) {\n const message = 'FileRenderer.processFileResult: Line doesnt exist';\n console.error(message, {\n name: file.name,\n lineIndex,\n lineNumber,\n });\n throw new Error(message);\n }\n\n // Add gutter line number\n gutter.children.push(\n createGutterItem('context', lineNumber, `${lineIndex}`)\n );\n contentArray.push(line);\n rowCount++;\n\n // Check annotations using ACTUAL line number from file\n const annotations = this.lineAnnotations[lineNumber];\n if (annotations != null) {\n gutter.children.push(createGutterGap('context', 'annotation', 1));\n contentArray.push(\n createAnnotationElement({\n type: 'annotation',\n hunkIndex: 0,\n lineIndex: lineNumber,\n annotations: annotations.map((annotation) =>\n getLineAnnotationName(annotation)\n ),\n })\n );\n rowCount++;\n }\n }\n\n // Finalize: wrap gutter and content\n gutter.properties.style = `grid-row: span ${rowCount}`;\n return {\n gutterAST: gutter.children ?? [],\n contentAST: contentArray,\n preAST: this.createPreElement(totalLines),\n headerAST: !disableFileHeader ? this.renderHeader(file) : undefined,\n totalLines: totalLines,\n rowCount,\n themeStyles: themeStyles,\n baseThemeType,\n bufferBefore: renderRange.bufferBefore,\n bufferAfter: renderRange.bufferAfter,\n css: '',\n };\n }\n\n private renderHeader(file: FileContents) {\n const { headerRenderMode = 'default', stickyHeader = false } = this.options;\n return createFileHeaderElement({\n fileOrDiff: file,\n mode: headerRenderMode,\n stickyHeader,\n });\n }\n\n public renderFullHTML(result: FileRenderResult): string {\n return toHtml(this.renderFullAST(result));\n }\n\n public renderFullAST(\n result: FileRenderResult,\n children: ElementContent[] = []\n ): HASTElement {\n children.push(\n createHastElement({\n tagName: 'code',\n children: this.renderCodeAST(result),\n properties: { 'data-code': '' },\n })\n );\n return { ...result.preAST, children };\n }\n\n public renderCodeAST(result: FileRenderResult): ElementContent[] {\n const gutter = createGutterWrapper();\n gutter.children = result.gutterAST;\n gutter.properties.style = `grid-row: span ${result.rowCount}`;\n const contentColumn = createContentColumn(\n result.contentAST,\n result.rowCount\n );\n return [gutter, contentColumn];\n }\n\n public renderPartialHTML(\n children: ElementContent[],\n includeCodeNode: boolean = false\n ): string {\n if (!includeCodeNode) {\n return toHtml(children);\n }\n return toHtml(\n createHastElement({\n tagName: 'code',\n children,\n properties: { 'data-code': '' },\n })\n );\n }\n\n public async initializeHighlighter(): Promise<DiffsHighlighter> {\n this.highlighter = await getSharedHighlighter(\n getHighlighterOptions(this.computedLang, this.options)\n );\n return this.highlighter;\n }\n\n public onHighlightSuccess(\n file: FileContents,\n result: ThemedFileResult,\n options: RenderFileOptions,\n highlighted = true\n ): void {\n if (this.renderCache == null) {\n return;\n }\n const triggerRenderUpdate =\n !areFilesEqual(file, this.renderCache.file) ||\n !this.renderCache.highlighted ||\n !areFileRenderOptionsEqual(options, this.renderCache.options);\n\n this.renderCache = {\n file,\n options,\n highlighted,\n result,\n renderRange: undefined,\n };\n\n if (triggerRenderUpdate) {\n this.onRenderUpdate?.();\n }\n }\n\n private getMatchingWorkerResultCache(\n file: FileContents,\n options: RenderFileOptions\n ): RenderFileResult | undefined {\n const cache = this.workerManager?.getFileResultCache(file);\n if (cache == null || !areFileRenderOptionsEqual(options, cache.options)) {\n return undefined;\n }\n return cache;\n }\n\n private hasHighlightedRenderCache(\n file: FileContents,\n options: RenderFileOptions\n ): boolean {\n const { renderCache } = this;\n return (\n renderCache?.result != null &&\n renderCache.highlighted &&\n areFilesEqual(file, renderCache.file) &&\n areFileRenderOptionsEqual(options, renderCache.options)\n );\n }\n\n public onHighlightError(error: unknown): void {\n console.error(error);\n }\n\n private getTokenizeMaxLength(): number {\n return this.options.tokenizeMaxLength ?? DEFAULT_TOKENIZE_MAX_LENGTH;\n }\n\n private createPreElement(totalLines: number): HASTElement {\n const { disableLineNumbers = false, overflow = 'scroll' } = this.options;\n return createPreElement({\n type: 'file',\n diffIndicators: 'none',\n disableBackground: true,\n disableLineNumbers,\n overflow,\n split: false,\n totalLines,\n });\n }\n}\n\nfunction isFileMassive(lineCount: number, tokenizeMaxLength: number): boolean {\n return lineCount > tokenizeMaxLength;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA6FA,IAAI,aAAa;AAEjB,IAAa,eAAb,MAAmD;CAWxC;CACC;CACA;CAZV,OAAwB,iBAAiB,EAAE;CAE3C;CACA;CACA,eAA2C;CAC3C,kBAA0D,CAAC;CAC3D;CACA,oCAA4B,IAAI,QAAyC;CAEzE,YACE,UAAsC,EAAE,OAAO,eAAe,GAC9D,gBACA,eACA;EAHO,KAAA,UAAA;EACC,KAAA,iBAAA;EACA,KAAA,gBAAA;EAER,IAAI,eAAe,cAAc,MAAM,MACrC,KAAK,cAAc,kBAAkB,QAAQ,SAAS,cAAc,IAChE,uBAAuB,IACvB,KAAA;CAER;CAEA,WAAkB,SAAoC;EACpD,KAAK,UAAU;CACjB;CAEA,aAAoB,SAA6C;EAC/D,KAAK,UAAU;GAAE,GAAG,KAAK;GAAS,GAAG;EAAQ;CAC/C;CAEA,mBACE,iBACM;EACN,KAAK,kBAAkB,CAAC;EACxB,KAAK,MAAM,cAAc,iBAAiB;GACxC,MAAM,MAAM,KAAK,gBAAgB,WAAW,eAAe,CAAC;GAC5D,KAAK,gBAAgB,WAAW,cAAc;GAC9C,IAAI,KAAK,UAAU;EACrB;CACF;CAEA,UAAuB;EACrB,KAAK,QAAQ;EACb,KAAK,gBAAgB,KAAA;EACrB,KAAK,iBAAiB,KAAA;CACxB;CAEA,UAAuB;EACrB,KAAK,yBAAyB;EAC9B,KAAK,iBAAiB;EACtB,KAAK,cAAc,KAAA;EACnB,KAAK,eAAe,aAAa,IAAI;EACrC,KAAK,YAAY,KAAA;EAMjB,KAAK,oCAAoB,IAAI,QAAQ;CACvC;CASA,2BA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I,KAAK,eAAe,MACtB;EAEF,MAAM,sBACJ,CAAC,cAAc,MAAM,KAAK,YAAY,IAAI,KAC1C,CAAC,KAAK,YAAY,eAClB,CAAC,0BAA0B,SAAS,KAAK,YAAY,OAAO;EAE9D,KAAK,cAAc;GACjB;GACA;GACA;GACA;GACA,aAAa,KAAA;EACf;EAEA,IAAI,qBACF,KAAK,iBAAiB;CAE1B;CAEA,6BACE,MACA,SAC8B;EAC9B,MAAM,QAAQ,KAAK,eAAe,mBAAmB,IAAI;EACzD,IAAI,SAAS,QAAQ,CAAC,0BAA0B,SAAS,MAAM,OAAO,GACpE;EAEF,OAAO;CACT;CAEA,0BACE,MACA,SACS;EACT,MAAM,EAAE,gBAAgB;EACxB,OACE,aAAa,UAAU,QACvB,YAAY,eACZ,cAAc,MAAM,YAAY,IAAI,KACpC,0BAA0B,SAAS,YAAY,OAAO;CAE1D;CAEA,iBAAwB,OAAsB;EAC5C,QAAQ,MAAM,KAAK;CACrB;CAEA,uBAAuC;EACrC,OAAO,KAAK,QAAQ,qBAAA;CACtB;CAEA,iBAAyB,YAAiC;EACxD,MAAM,EAAE,qBAAqB,OAAO,WAAW,aAAa,KAAK;EACjE,OAAO,iBAAiB;GACtB,MAAM;GACN,gBAAgB;GAChB,mBAAmB;GACnB;GACA;GACA,OAAO;GACP;EACF,CAAC;CACH;AACF;AAEA,SAAS,cAAc,WAAmB,mBAAoC;CAC5E,OAAO,YAAY;AACrB"}
1
+ {"version":3,"file":"FileRenderer.js","names":[],"sources":["../../src/renderers/FileRenderer.ts"],"sourcesContent":["import type { ElementContent, Element as HASTElement } from 'hast';\nimport { toHtml } from 'hast-util-to-html';\n\nimport {\n DEFAULT_RENDER_RANGE,\n DEFAULT_THEMES,\n DEFAULT_TOKENIZE_MAX_LENGTH,\n} from '../constants';\nimport { areLanguagesAttached } from '../highlighter/languages/areLanguagesAttached';\nimport {\n getHighlighterIfLoaded,\n getSharedHighlighter,\n} from '../highlighter/shared_highlighter';\nimport { areThemesAttached } from '../highlighter/themes/areThemesAttached';\nimport { hasResolvedThemes } from '../highlighter/themes/hasResolvedThemes';\nimport type {\n BaseCodeOptions,\n DiffsHighlighter,\n DiffsTextDocument,\n FileContents,\n FileHeaderRenderMode,\n HighlightedToken,\n LineAnnotation,\n RenderedFileASTCache,\n RenderFileOptions,\n RenderFileResult,\n RenderRange,\n SupportedLanguages,\n ThemedFileResult,\n} from '../types';\nimport { applyLineTextWithNewline } from '../utils/applyLineTextWithNewline';\nimport { areFileRenderOptionsEqual } from '../utils/areFileRenderOptionsEqual';\nimport { areFilesEqual } from '../utils/areFilesEqual';\nimport { areRenderRangesEqual } from '../utils/areRenderRangesEqual';\nimport { linesFromFileContents } from '../utils/computeFileOffsets';\nimport { createAnnotationElement } from '../utils/createAnnotationElement';\nimport { createContentColumn } from '../utils/createContentColumn';\nimport { createFileHeaderElement } from '../utils/createFileHeaderElement';\nimport { createPreElement } from '../utils/createPreElement';\nimport { getFiletypeFromFileName } from '../utils/getFiletypeFromFileName';\nimport { getHighlighterOptions } from '../utils/getHighlighterOptions';\nimport { getLineAnnotationName } from '../utils/getLineAnnotationName';\nimport { getThemes } from '../utils/getThemes';\nimport {\n createGutterGap,\n createGutterItem,\n createGutterWrapper,\n createHastElement,\n} from '../utils/hast_utils';\nimport {\n FILE_ANNOTATION_HUNK_INDEX,\n FILE_ANNOTATION_LINE_INDEX,\n getFileAnnotations,\n shouldRenderFileAnnotations,\n} from '../utils/includesFileAnnotations';\nimport { isFilePlainText } from '../utils/isFilePlainText';\nimport { renderFileWithHighlighter } from '../utils/renderFileWithHighlighter';\nimport type { WorkerPoolManager } from '../worker';\n\ntype AnnotationLineMap<LAnnotation> = Record<\n number,\n LineAnnotation<LAnnotation>[] | undefined\n>;\n\ninterface GetRenderOptionsReturn {\n options: RenderFileOptions;\n forceHighlight: boolean;\n}\n\nexport interface FileRenderResult {\n gutterAST: ElementContent[];\n contentAST: ElementContent[];\n preAST: HASTElement;\n headerAST: HASTElement | undefined;\n css: string;\n totalLines: number;\n themeStyles: string;\n baseThemeType: 'light' | 'dark' | undefined;\n rowCount: number;\n bufferBefore: number;\n bufferAfter: number;\n}\n\ninterface LineCache {\n cacheKey: string | undefined;\n file: FileContents;\n sourceContents: string;\n lines: string[];\n}\n\n// Explicit keys may share cached lines across equivalent file objects. Unkeyed\n// files stay isolated by object identity while still supporting edit recycle.\nfunction isLineCacheForFile(lineCache: LineCache, file: FileContents): boolean {\n return file.cacheKey == null\n ? lineCache.file === file && lineCache.sourceContents === file.contents\n : lineCache.cacheKey === file.cacheKey;\n}\n\nexport interface FileRendererOptions extends BaseCodeOptions {\n headerRenderMode?: FileHeaderRenderMode;\n}\n\nlet instanceId = -1;\n\nexport class FileRenderer<LAnnotation = undefined> {\n readonly __id: string = `file-renderer:${++instanceId}`;\n\n private highlighter: DiffsHighlighter | undefined;\n private renderCache: RenderedFileASTCache | undefined;\n private computedLang: SupportedLanguages = 'text';\n private lineAnnotations: AnnotationLineMap<LAnnotation> = {};\n private lineCache: LineCache | undefined;\n private pendingStructuralRows: Map<number, HASTElement> | undefined;\n private textDocumentCache = new WeakMap<FileContents, DiffsTextDocument>();\n\n // Edit-session state: while active, this renderer stays on the main thread\n // with editor-compatible token markup — the editor's caret/selection\n // mapping needs the token transformer, and the pool's global options are\n // not guaranteed to produce it. The pool keeps serving every surface\n // without a session.\n private editSessionActive = false;\n\n constructor(\n public options: FileRendererOptions = { theme: DEFAULT_THEMES },\n private onRenderUpdate?: () => unknown,\n private workerManager?: WorkerPoolManager | undefined\n ) {\n if (workerManager?.isWorkingPool() !== true) {\n this.highlighter = areThemesAttached(options.theme ?? DEFAULT_THEMES)\n ? getHighlighterIfLoaded()\n : undefined;\n }\n }\n\n public setOptions(options: FileRendererOptions): void {\n this.options = options;\n }\n\n public mergeOptions(options: Partial<FileRendererOptions>): void {\n this.options = { ...this.options, ...options };\n }\n\n public setLineAnnotations(\n lineAnnotations: LineAnnotation<LAnnotation>[]\n ): void {\n this.lineAnnotations = {};\n for (const annotation of lineAnnotations) {\n const arr = this.lineAnnotations[annotation.lineNumber] ?? [];\n this.lineAnnotations[annotation.lineNumber] = arr;\n arr.push(annotation);\n }\n }\n\n public cleanUp(): void {\n this.recycle();\n this.workerManager = undefined;\n this.onRenderUpdate = undefined;\n }\n\n /**\n * Enter edit-session mode: rendering happens locally with the token\n * transformer forced on, and worker-pool requests/results are suspended\n * for this renderer. Called on every editor attach, including a re-attach\n * after recycle.\n */\n public beginEditSession(): void {\n this.editSessionActive = true;\n }\n\n /** Leave edit-session mode. Rendering returns to the pool when one works. */\n public endEditSession(): void {\n this.editSessionActive = false;\n }\n\n /**\n * Ensures that the DOM is compatible with editor render updates\n */\n public editorRenderReady(): boolean {\n return (\n this.renderCache?.options.useTokenTransformer === true &&\n this.renderCache.highlighted &&\n this.renderCache.result != null\n );\n }\n\n public recycle(): void {\n this.clearRenderCache();\n this.highlighter = undefined;\n this.workerManager?.cleanUpTasks(this);\n this.lineCache = undefined;\n // The session flag re-seeds on the next editor attach (beginEditSession).\n this.endEditSession();\n // The edited-document cache is only coherent alongside the render cache\n // it patched. Keeping it across a recycle would let getLineCount report\n // edit-session line counts (keyed by the long-lived file object) against\n // a result rebuilt from the file's own contents, which processFileResult\n // treats as a missing-line error.\n this.textDocumentCache = new WeakMap();\n }\n\n // An edit session patches the render caches in place but never rewrites\n // `file.contents`, so a recycled host would otherwise rebuild from the\n // pre-edit text while the editor resumes its retained (edited) document.\n // Diffs don't have this problem because DiffHunksRenderer keeps\n // `diff.additionLines` in sync during the session; the file equivalent is\n // joining the session-synced line cache back into the file object before\n // the caches are dropped.\n private syncEditedContentsToFile(): void {\n const { renderCache, lineCache } = this;\n if (\n renderCache?.isDirty !== true ||\n lineCache == null ||\n !isLineCacheForFile(lineCache, renderCache.file)\n ) {\n return;\n }\n renderCache.file.contents = lineCache.lines.join('');\n }\n\n // Unkeyed files use object identity, so compare the retained source text to\n // detect in-place mutations that an aliased file object cannot reveal.\n public hasUnkeyedFileContentsChanged(file: FileContents): boolean {\n const { lineCache } = this;\n return (\n file.cacheKey == null &&\n lineCache != null &&\n lineCache.file === file &&\n lineCache.sourceContents !== file.contents\n );\n }\n\n private invalidateChangedUnkeyedFile(file: FileContents): void {\n if (!this.hasUnkeyedFileContentsChanged(file)) return;\n this.workerManager?.cleanUpTasks(this);\n this.clearRenderCache();\n this.lineCache = undefined;\n this.textDocumentCache = new WeakMap();\n }\n\n public clearRenderCache(): void {\n this.syncEditedContentsToFile();\n this.pendingStructuralRows = undefined;\n const renderCache = this.renderCache;\n this.renderCache = undefined;\n if (\n renderCache != null &&\n renderCache.isDirty === true &&\n renderCache.file.cacheKey != null\n ) {\n // The render cache has been updated by the host, let's purge it\n // from the worker manager cache.\n this.workerManager?.evictFileFromCache(renderCache.file.cacheKey);\n }\n }\n\n public hydrate(file: FileContents): void {\n const { options } = this.getRenderOptions(file);\n const lines = this.getOrCreateLineCache(file);\n const massiveFile = isFileMassive(\n lines.length,\n this.getTokenizeMaxLength()\n );\n let cache = this.workerManager?.getFileResultCache(file);\n if (cache != null && !areFileRenderOptionsEqual(options, cache.options)) {\n cache = undefined;\n }\n this.renderCache ??= {\n file,\n options,\n highlighted: !massiveFile && !isFilePlainText(file),\n result: massiveFile ? undefined : cache?.result,\n // FIXME(amadeus): Add support for renderRanges\n renderRange: undefined,\n };\n if (\n !this.editSessionActive &&\n this.workerManager?.isWorkingPool() === true\n ) {\n if (this.renderCache.result == null && !massiveFile) {\n // We should only kick off a preload of the AST if we have a WorkerPool\n this.workerManager.highlightFileAST(this, file);\n }\n }\n // Lets attempt to get the highlighter/languages ready immediately\n else if (this.highlighter == null) {\n this.computedLang = file.lang ?? getFiletypeFromFileName(file.name);\n void this.initializeHighlighter();\n }\n }\n\n private getLocalHighlightTheme(): RenderFileOptions['theme'] {\n return (\n this.workerManager?.getFileRenderOptions().theme ??\n this.options.theme ??\n DEFAULT_THEMES\n );\n }\n\n private getRenderOptions(file: FileContents): GetRenderOptionsReturn {\n const options: RenderFileOptions = (() => {\n if (this.workerManager?.isWorkingPool() === true) {\n const poolOptions = this.workerManager.getFileRenderOptions();\n // Active edit sessions require `useTokenTransformer: true`\n if (\n this.editSessionActive &&\n poolOptions.useTokenTransformer !== true\n ) {\n return { ...poolOptions, useTokenTransformer: true };\n }\n return poolOptions;\n }\n const { tokenizeMaxLineLength = 1000 } = this.options;\n return {\n theme: this.getLocalHighlightTheme(),\n useTokenTransformer:\n this.editSessionActive || this.options.useTokenTransformer === true,\n tokenizeMaxLineLength,\n };\n })();\n const { renderCache } = this;\n if (renderCache?.result == null) {\n return { options, forceHighlight: true };\n }\n if (\n !areFilesEqual(file, renderCache.file) ||\n !areFileRenderOptionsEqual(options, renderCache.options)\n ) {\n return { options, forceHighlight: true };\n }\n return { options, forceHighlight: false };\n }\n\n public getOrCreateLineCache(file: FileContents): string[] {\n this.invalidateChangedUnkeyedFile(file);\n let { lineCache } = this;\n if (lineCache == null || !isLineCacheForFile(lineCache, file)) {\n lineCache = {\n cacheKey: file.cacheKey,\n file,\n sourceContents: file.contents,\n lines: linesFromFileContents(file.contents),\n };\n }\n this.lineCache = lineCache;\n return lineCache.lines;\n }\n\n // when a emitLineCountChange is called,\n // calculate the line count using the cached text document\n public getLineCount(file: FileContents): number {\n const lines = this.getOrCreateLineCache(file);\n return this.textDocumentCache.get(file)?.lineCount ?? lines.length;\n }\n\n public updateRenderCache(\n dirtyLines: Map<number, Array<HighlightedToken>>,\n themeType: 'dark' | 'light',\n lineCountChangeInFlight = false\n ): void {\n this.pendingStructuralRows = undefined;\n if (this.renderCache == null) {\n return;\n }\n const { file, result } = this.renderCache;\n if (result == null) {\n return;\n }\n const pendingStructuralRows = lineCountChangeInFlight\n ? new Map<number, HASTElement>()\n : undefined;\n this.pendingStructuralRows = pendingStructuralRows;\n // Same-line edits can update the document cache immediately. Structural\n // rows use post-edit indexes, so hold them until applyDocumentChange has\n // shifted the old cache; writing now would overwrite rows that must move.\n const lineCache =\n this.lineCache != null && isLineCacheForFile(this.lineCache, file)\n ? this.lineCache\n : undefined;\n for (const [line, tokens] of dirtyLines) {\n if (\n pendingStructuralRows === undefined &&\n lineCache != null &&\n line < lineCache.lines.length\n ) {\n const lineText = tokens.map((token) => token[2]).join('');\n lineCache.lines[line] = applyLineTextWithNewline(\n lineCache.lines[line] ?? '',\n lineText\n );\n }\n const row: HASTElement = {\n type: 'element',\n tagName: 'div',\n properties: {\n 'data-line': line + 1,\n 'data-line-type': 'context',\n 'data-line-index': line,\n },\n children: tokens.map(([char, fg, text]) => {\n if (char === 0 && fg === '') {\n if (text === '') {\n return {\n type: 'element',\n tagName: 'br',\n properties: {},\n children: [],\n };\n }\n return { type: 'text', value: text };\n }\n return {\n type: 'element',\n tagName: 'span',\n properties: {\n 'data-char': char,\n style: `color:${fg};`,\n },\n children: [{ type: 'text', value: text }],\n };\n }),\n };\n if (pendingStructuralRows !== undefined) {\n pendingStructuralRows.set(line, row);\n } else {\n result.code[line] = row;\n }\n }\n\n result.baseThemeType = themeType;\n this.renderCache.isDirty = true;\n }\n\n // normally triggered by the host when the document line count changes\n public applyDocumentChange(textDocument: DiffsTextDocument): void {\n const pendingStructuralRows = this.pendingStructuralRows;\n this.pendingStructuralRows = undefined;\n if (this.renderCache == null) {\n return undefined;\n }\n const { file, result } = this.renderCache;\n // Without a result there is nothing to reconcile the document against, so\n // do not record it either: the document cache must never claim line\n // counts the (possibly still highlighting) result cannot back, or the\n // async highlight pass would process lines that do not exist.\n if (result == null) {\n return undefined;\n }\n // Structural edits renumber cached HAST rows. Keep the unchanged prefix\n // and suffix, and plain-fill only the window that still needs tokenizing.\n const previousLines =\n this.lineCache != null && isLineCacheForFile(this.lineCache, file)\n ? this.lineCache.lines\n : linesFromFileContents(file.contents);\n const nextLines = linesFromFileContents(textDocument.getText());\n if (previousLines.length !== nextLines.length) {\n const maxShared = Math.min(previousLines.length, nextLines.length);\n let prefix = 0;\n while (\n prefix < maxShared &&\n previousLines[prefix] === nextLines[prefix]\n ) {\n prefix++;\n }\n let suffix = 0;\n while (\n suffix < maxShared - prefix &&\n previousLines[previousLines.length - 1 - suffix] ===\n nextLines[nextLines.length - 1 - suffix]\n ) {\n suffix++;\n }\n\n const previousCode = result.code;\n result.code = new Array(nextLines.length);\n for (let i = 0; i < prefix; i++) {\n result.code[i] = previousCode[i];\n }\n for (let i = 0; i < suffix; i++) {\n result.code[nextLines.length - 1 - i] =\n previousCode[previousLines.length - 1 - i];\n }\n if (pendingStructuralRows !== undefined) {\n for (const [line, row] of pendingStructuralRows) {\n if (line < nextLines.length) {\n result.code[line] = row;\n }\n }\n }\n for (let i = prefix; i < nextLines.length - suffix; i++) {\n result.code[i] ??= {\n type: 'element',\n tagName: 'div',\n properties: {\n 'data-line': i + 1,\n 'data-line-type': 'context',\n 'data-line-index': i,\n },\n children: [\n {\n type: 'element',\n tagName: 'span',\n properties: {\n 'data-char': 0,\n },\n children: [\n {\n type: 'text',\n value: textDocument.getLineText(i),\n },\n ],\n },\n ],\n };\n }\n for (let i = 0; i < result.code.length; i++) {\n const line = result.code[i];\n if (line?.type === 'element') {\n line.properties['data-line'] = i + 1;\n line.properties['data-line-index'] = i;\n }\n }\n this.renderCache.isDirty = true;\n }\n // Replace the old split-line cache with the authoritative edited document.\n this.lineCache = {\n cacheKey: file.cacheKey,\n file,\n sourceContents: file.contents,\n lines: nextLines,\n };\n this.textDocumentCache.set(file, textDocument);\n }\n\n public renderFile(\n file: FileContents | undefined = this.renderCache?.file,\n renderRange: RenderRange = DEFAULT_RENDER_RANGE\n ): FileRenderResult | undefined {\n if (file == null) {\n return undefined;\n }\n this.invalidateChangedUnkeyedFile(file);\n if (\n this.renderCache?.isDirty === true &&\n !areFilesEqual(file, this.renderCache.file)\n ) {\n this.clearRenderCache();\n this.lineCache = undefined;\n this.textDocumentCache = new WeakMap();\n }\n let { options, forceHighlight } = this.getRenderOptions(file);\n // A dirty edit-session cache must not be superseded by a render with\n // different options (e.g. a session ending and returning to pool\n // options): persist the session text into the file and evict the stale\n // pool cache entry first (clearRenderCache does both) so the rebuild\n // below uses the edited contents instead of resurrecting pre-edit\n // markup.\n if (\n this.renderCache?.isDirty === true &&\n !areFileRenderOptionsEqual(options, this.renderCache.options)\n ) {\n this.clearRenderCache();\n }\n const cache = this.getMatchingWorkerResultCache(file, options);\n if (cache != null && !this.hasHighlightedRenderCache(file, options)) {\n this.renderCache = {\n file,\n highlighted: true,\n renderRange: undefined,\n ...cache,\n };\n forceHighlight = false;\n }\n this.renderCache ??= {\n file,\n highlighted: false,\n options,\n result: undefined,\n renderRange: undefined,\n };\n const lines = this.getOrCreateLineCache(file);\n const hasContent = file.contents.length > 0;\n const forcePlainText =\n !hasContent ||\n isFilePlainText(file) ||\n isFileMassive(lines.length, this.getTokenizeMaxLength());\n const newContent = !areFilesEqual(file, this.renderCache.file);\n const newRenderRange = !areRenderRangesEqual(\n this.renderCache.renderRange,\n renderRange\n );\n if (\n !this.editSessionActive &&\n this.workerManager?.isWorkingPool() === true\n ) {\n // Cache invalidation based on renderRange comparison\n if (\n forcePlainText ||\n this.renderCache.result == null ||\n (!this.renderCache.highlighted && (newContent || newRenderRange))\n ) {\n this.renderCache.file = file;\n this.renderCache.options = options;\n this.renderCache.highlighted = false;\n if (\n this.renderCache.result == null ||\n newContent ||\n newRenderRange ||\n forceHighlight\n ) {\n this.renderCache.result = this.workerManager.getPlainFileAST(\n file,\n renderRange.startingLine,\n renderRange.totalLines,\n lines\n );\n }\n this.renderCache.renderRange = renderRange;\n }\n\n if (\n !forcePlainText &&\n hasContent &&\n (!this.renderCache.highlighted || forceHighlight)\n ) {\n this.workerManager.highlightFileAST(this, file);\n }\n } else {\n this.computedLang = file.lang ?? getFiletypeFromFileName(file.name);\n const hasThemes =\n this.highlighter != null && areThemesAttached(options.theme);\n const hasLangs =\n this.highlighter != null && areLanguagesAttached(this.computedLang);\n const canHighlight = !forcePlainText && hasLangs;\n\n // If we have any semblance of a highlighter with the correct theme(s)\n // attached, we can kick off some form of rendering. If we don't have\n // the correct language, then we can render plain text and after kick off\n // an async job to get the highlighted AST\n if (\n this.highlighter != null &&\n hasThemes &&\n (forceHighlight ||\n forcePlainText ||\n (!this.renderCache.highlighted && canHighlight) ||\n this.renderCache.result == null)\n ) {\n const { result, options } = this.renderFileWithHighlighter(\n file,\n this.highlighter,\n forcePlainText || !hasLangs\n );\n this.renderCache = {\n file,\n options,\n highlighted: canHighlight,\n result,\n renderRange: undefined,\n };\n }\n\n // If we get in here it means we'll have to kick off an async highlight\n // process which will involve initializing the highlighter with new themes\n // and languages\n if (!hasThemes || (!forcePlainText && !hasLangs)) {\n void this.asyncHighlight(file).then(({ result, options }) => {\n // In this case we need to force a re-render, so we can do that by\n // reaching into renderCache\n if (this.renderCache != null) {\n this.renderCache.highlighted = false;\n }\n this.applyHighlightResult(file, result, options, !forcePlainText);\n });\n }\n }\n\n return this.renderCache.result != null\n ? this.processFileResult(\n this.renderCache.file,\n renderRange,\n this.renderCache.result\n )\n : undefined;\n }\n\n async asyncRender(\n file: FileContents,\n renderRange: RenderRange = DEFAULT_RENDER_RANGE\n ): Promise<FileRenderResult> {\n const { result } = await this.asyncHighlight(file);\n return this.processFileResult(file, renderRange, result);\n }\n\n private async asyncHighlight(file: FileContents): Promise<RenderFileResult> {\n const lines = this.getOrCreateLineCache(file);\n const forcePlainText = isFileMassive(\n lines.length,\n this.getTokenizeMaxLength()\n );\n this.computedLang = forcePlainText\n ? 'text'\n : (file.lang ?? getFiletypeFromFileName(file.name));\n const hasThemes =\n this.highlighter != null &&\n hasResolvedThemes(getThemes(this.getLocalHighlightTheme()));\n const hasLangs =\n forcePlainText ||\n (this.highlighter != null && areLanguagesAttached(this.computedLang));\n // If we don't have the required langs or themes, then we need to\n // initialize the highlighter to load the appropriate languages and themes\n if (this.highlighter == null || !hasThemes || !hasLangs) {\n this.highlighter = await this.initializeHighlighter();\n }\n return this.renderFileWithHighlighter(\n file,\n this.highlighter,\n forcePlainText\n );\n }\n\n private renderFileWithHighlighter(\n file: FileContents,\n highlighter: DiffsHighlighter,\n forcePlainText = false\n ): RenderFileResult {\n const { options } = this.getRenderOptions(file);\n const result = renderFileWithHighlighter(file, highlighter, options, {\n forcePlainText,\n });\n return { result, options };\n }\n\n private processFileResult(\n file: FileContents,\n renderRange: RenderRange,\n { code, themeStyles, baseThemeType }: ThemedFileResult\n ): FileRenderResult {\n const totalLines = this.getLineCount(file);\n const { disableFileHeader = false } = this.options;\n const contentArray: ElementContent[] = [];\n const gutter = createGutterWrapper();\n const endLine = Math.min(\n renderRange.startingLine + renderRange.totalLines,\n totalLines\n );\n let rowCount = 0;\n\n const fileLevelAnnotations = shouldRenderFileAnnotations(renderRange)\n ? getFileAnnotations(this.lineAnnotations)\n : undefined;\n if (fileLevelAnnotations != null) {\n gutter.children.push(createGutterGap('context', 'annotation', 1));\n contentArray.push(\n createAnnotationElement({\n type: 'annotation',\n hunkIndex: FILE_ANNOTATION_HUNK_INDEX,\n lineIndex: FILE_ANNOTATION_LINE_INDEX,\n annotations: fileLevelAnnotations.map((annotation) =>\n getLineAnnotationName(annotation)\n ),\n })\n );\n rowCount++;\n }\n\n for (\n let lineIndex = renderRange.startingLine;\n lineIndex < endLine;\n lineIndex++\n ) {\n const lineNumber = lineIndex + 1;\n\n // Sparse array - directly indexed by lineIndex\n const line = code[lineIndex];\n if (line == null) {\n const message = 'FileRenderer.processFileResult: Line doesnt exist';\n console.error(message, {\n name: file.name,\n lineIndex,\n lineNumber,\n });\n throw new Error(message);\n }\n\n // Add gutter line number\n gutter.children.push(\n createGutterItem('context', lineNumber, `${lineIndex}`)\n );\n contentArray.push(line);\n rowCount++;\n\n // Check annotations using ACTUAL line number from file\n const annotations = this.lineAnnotations[lineNumber];\n if (annotations != null) {\n gutter.children.push(createGutterGap('context', 'annotation', 1));\n contentArray.push(\n createAnnotationElement({\n type: 'annotation',\n hunkIndex: 0,\n lineIndex: lineNumber,\n annotations: annotations.map((annotation) =>\n getLineAnnotationName(annotation)\n ),\n })\n );\n rowCount++;\n }\n }\n\n // Finalize: wrap gutter and content\n gutter.properties.style = `grid-row: span ${rowCount}`;\n return {\n gutterAST: gutter.children ?? [],\n contentAST: contentArray,\n preAST: this.createPreElement(totalLines),\n headerAST: !disableFileHeader ? this.renderHeader(file) : undefined,\n totalLines: totalLines,\n rowCount,\n themeStyles: themeStyles,\n baseThemeType,\n bufferBefore: renderRange.bufferBefore,\n bufferAfter: renderRange.bufferAfter,\n css: '',\n };\n }\n\n private renderHeader(file: FileContents) {\n const { headerRenderMode = 'default', stickyHeader = false } = this.options;\n return createFileHeaderElement({\n fileOrDiff: file,\n mode: headerRenderMode,\n stickyHeader,\n });\n }\n\n public renderFullHTML(result: FileRenderResult): string {\n return toHtml(this.renderFullAST(result));\n }\n\n public renderFullAST(\n result: FileRenderResult,\n children: ElementContent[] = []\n ): HASTElement {\n children.push(\n createHastElement({\n tagName: 'code',\n children: this.renderCodeAST(result),\n properties: { 'data-code': '' },\n })\n );\n return { ...result.preAST, children };\n }\n\n public renderCodeAST(result: FileRenderResult): ElementContent[] {\n const gutter = createGutterWrapper();\n gutter.children = result.gutterAST;\n gutter.properties.style = `grid-row: span ${result.rowCount}`;\n const contentColumn = createContentColumn(\n result.contentAST,\n result.rowCount\n );\n return [gutter, contentColumn];\n }\n\n public renderPartialHTML(\n children: ElementContent[],\n includeCodeNode: boolean = false\n ): string {\n if (!includeCodeNode) {\n return toHtml(children);\n }\n return toHtml(\n createHastElement({\n tagName: 'code',\n children,\n properties: { 'data-code': '' },\n })\n );\n }\n\n public async initializeHighlighter(): Promise<DiffsHighlighter> {\n this.highlighter = await getSharedHighlighter(\n getHighlighterOptions(this.computedLang, {\n theme: this.getLocalHighlightTheme(),\n preferredHighlighter:\n this.workerManager?.getPreferredHighlighter() ??\n this.options.preferredHighlighter,\n })\n );\n return this.highlighter;\n }\n\n public onHighlightSuccess(\n file: FileContents,\n result: ThemedFileResult,\n options: RenderFileOptions,\n highlighted = true\n ): void {\n if (this.editSessionActive) {\n return;\n }\n this.applyHighlightResult(file, result, options, highlighted);\n }\n\n private applyHighlightResult(\n file: FileContents,\n result: ThemedFileResult,\n options: RenderFileOptions,\n highlighted = true\n ): void {\n if (this.renderCache == null) {\n return;\n }\n const triggerRenderUpdate =\n !areFilesEqual(file, this.renderCache.file) ||\n !this.renderCache.highlighted ||\n !areFileRenderOptionsEqual(options, this.renderCache.options);\n\n this.renderCache = {\n file,\n options,\n highlighted,\n result,\n renderRange: undefined,\n };\n\n if (triggerRenderUpdate) {\n this.onRenderUpdate?.();\n }\n }\n\n private getMatchingWorkerResultCache(\n file: FileContents,\n options: RenderFileOptions\n ): RenderFileResult | undefined {\n if (this.editSessionActive) {\n return undefined;\n }\n const cache = this.workerManager?.getFileResultCache(file);\n if (cache == null || !areFileRenderOptionsEqual(options, cache.options)) {\n return undefined;\n }\n return cache;\n }\n\n private hasHighlightedRenderCache(\n file: FileContents,\n options: RenderFileOptions\n ): boolean {\n const { renderCache } = this;\n return (\n renderCache?.result != null &&\n renderCache.highlighted &&\n areFilesEqual(file, renderCache.file) &&\n areFileRenderOptionsEqual(options, renderCache.options)\n );\n }\n\n public onHighlightError(error: unknown): void {\n console.error(error);\n }\n\n private getTokenizeMaxLength(): number {\n return this.options.tokenizeMaxLength ?? DEFAULT_TOKENIZE_MAX_LENGTH;\n }\n\n private createPreElement(totalLines: number): HASTElement {\n const { disableLineNumbers = false, overflow = 'scroll' } = this.options;\n return createPreElement({\n type: 'file',\n diffIndicators: 'none',\n disableBackground: true,\n disableLineNumbers,\n overflow,\n split: false,\n totalLines,\n });\n }\n}\n\nfunction isFileMassive(lineCount: number, tokenizeMaxLength: number): boolean {\n return lineCount > tokenizeMaxLength;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA4FA,SAAS,mBAAmB,WAAsB,MAA6B;CAC7E,OAAO,KAAK,YAAY,OACpB,UAAU,SAAS,QAAQ,UAAU,mBAAmB,KAAK,WAC7D,UAAU,aAAa,KAAK;AAClC;AAMA,IAAI,aAAa;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0B,SAAS,MAAM,OAAO,GACpE;EAEF,OAAO;CACT;CAEA,0BACE,MACA,SACS;EACT,MAAM,EAAE,gBAAgB;EACxB,OACE,aAAa,UAAU,QACvB,YAAY,eACZ,cAAc,MAAM,YAAY,IAAI,KACpC,0BAA0B,SAAS,YAAY,OAAO;CAE1D;CAEA,iBAAwB,OAAsB;EAC5C,QAAQ,MAAM,KAAK;CACrB;CAEA,uBAAuC;EACrC,OAAO,KAAK,QAAQ,qBAAA;CACtB;CAEA,iBAAyB,YAAiC;EACxD,MAAM,EAAE,qBAAqB,OAAO,WAAW,aAAa,KAAK;EACjE,OAAO,iBAAiB;GACtB,MAAM;GACN,gBAAgB;GAChB,mBAAmB;GACnB;GACA;GACA,OAAO;GACP;EACF,CAAC;CACH;AACF;AAEA,SAAS,cAAc,WAAmB,mBAAoC;CAC5E,OAAO,YAAY;AACrB"}
@@ -1,6 +1,6 @@
1
- import { AnnotationLineMap, AnnotationSide, AnnotationSpan, AppliedThemeStyleCache, BaseCodeOptions, BaseDiffOptions, BaseDiffOptionsWithDefaults, BundledLanguage, ChangeContent, ChangeTypes, CodeColumnType, CodeToHastOptions, CodeViewCreateEditorOptions, CodeViewDiffItem, CodeViewFileItem, CodeViewItem, CodeViewItemScrollTarget, CodeViewLayout, CodeViewLineScrollTarget, CodeViewPositionScrollTarget, CodeViewRangeScrollTarget, CodeViewScrollBehavior, CodeViewScrollTarget, ConflictResolverTypes, ContextContent, CreatePatchOptionsNonabortable, CustomPreProperties, DecorationItem, DiffAcceptRejectHunkConfig, DiffAcceptRejectHunkType, DiffFileInput, DiffIndicators, DiffLineAnnotation, DiffLineEventBaseProps, DiffTokenEventBaseProps, DiffsBaseComponent, DiffsComponentOptions, DiffsEditableComponent, DiffsEditor, DiffsEditorHost, DiffsEditorSelection, DiffsHighlighter, DiffsTextDocument, DiffsThemeNames, ExpansionDirections, ExtensionFormatMap, FileContents, FileDiffContentsLoader, FileDiffLoadedChangedFiles, FileDiffLoadedFiles, FileDiffLoadedPureRenamedFile, FileDiffMetadata, FileHeaderRenderMode, ForceDiffPlainTextOptions, ForceFilePlainTextOptions, GapSpan, HighlightedToken, HighlighterTypes, Hunk, HunkData, HunkExpansionRegion, HunkLineType, HunkSeparators, LanguageRegistration, LineAnnotation, LineDiffTypes, LineEventBaseProps, LineInfo, LineSpans, LineTypes, MaybeDiffFileInput, MergeConflictActionPayload, MergeConflictMarkerRow, MergeConflictMarkerRowType, MergeConflictRegion, MergeConflictResolution, NumericScrollLineAnchor, ObservedAnnotationNodes, ObservedGridNodes, ParsedPatch, PendingCodeViewLayoutReset, PostRenderPhase, PrePropertiesConfig, ProcessFileConflictData, RenderDiffFilesResult, RenderDiffOptions, RenderDiffResult, RenderFileMetadata, RenderFileOptions, RenderFileResult, RenderHeaderFilenameSuffixCallback, RenderHeaderMetadataCallback, RenderHeaderPrefixCallback, RenderRange, RenderWindow, RenderedDiffASTCache, RenderedFileASTCache, SelectedLineRange, SelectionPoint, SelectionSide, SharedRenderState, ShikiTransformer, SmoothScrollSettings, StickySpecs, SupportedLanguages, ThemeRegistration, ThemeRegistrationResolved, ThemeTypes, ThemedDiffResult, ThemedFileResult, ThemedToken, ThemesType, TokenEventBase, VirtualFileMetrics, VirtualWindowSpecs } from "../types.js";
1
+ import { AnnotationLineMap, AnnotationSide, AnnotationSpan, AppliedThemeStyleCache, BaseCodeOptions, BaseDiffOptions, BaseDiffOptionsWithDefaults, BundledLanguage, ChangeContent, ChangeTypes, CodeColumnType, CodeToHastOptions, CodeViewCreateEditorOptions, CodeViewDiffItem, CodeViewFileItem, CodeViewItem, CodeViewItemScrollTarget, CodeViewLayout, CodeViewLineScrollTarget, CodeViewPositionScrollTarget, CodeViewRangeScrollTarget, CodeViewScrollBehavior, CodeViewScrollTarget, ConflictResolverTypes, ContextContent, CreatePatchOptionsNonabortable, CustomPreProperties, DecorationItem, DiffAcceptRejectHunkConfig, DiffAcceptRejectHunkType, DiffFileInput, DiffIndicators, DiffLineAnnotation, DiffLineEventBaseProps, DiffTokenEventBaseProps, DiffsBaseComponent, DiffsComponentOptions, DiffsEditableComponent, DiffsEditor, DiffsHighlighter, DiffsTextDocument, DiffsThemeNames, EditableInstance, EditorActiveLineOptions, EditorSelection, EditorState, EditorViewState, ExpansionDirections, ExtensionFormatMap, FileContents, FileDiffContentsLoader, FileDiffLoadedChangedFiles, FileDiffLoadedFiles, FileDiffLoadedPureRenamedFile, FileDiffMetadata, FileHeaderRenderMode, ForceDiffPlainTextOptions, ForceFilePlainTextOptions, GapSpan, HighlightedToken, HighlighterTypes, Hunk, HunkData, HunkExpansionRegion, HunkLineType, HunkSeparators, LanguageRegistration, LineAnnotation, LineDiffTypes, LineEventBaseProps, LineInfo, LineSpans, LineTypes, MaybeDiffFileInput, MergeConflictActionPayload, MergeConflictMarkerRow, MergeConflictMarkerRowType, MergeConflictRegion, MergeConflictResolution, NumericScrollLineAnchor, ObservedAnnotationNodes, ObservedGridNodes, ParsedPatch, PendingCodeViewLayoutReset, Position, PostRenderPhase, PrePropertiesConfig, ProcessFileConflictData, Range, RenderDiffFilesResult, RenderDiffOptions, RenderDiffResult, RenderFileMetadata, RenderFileOptions, RenderFileResult, RenderHeaderFilenameSuffixCallback, RenderHeaderMetadataCallback, RenderHeaderPrefixCallback, RenderRange, RenderWindow, RenderedDiffASTCache, RenderedFileASTCache, SelectedLineRange, SelectionDirection, SelectionPoint, SelectionSide, SharedRenderState, ShikiTransformer, SmoothScrollSettings, StickySpecs, SupportedLanguages, TextEdit, ThemeRegistration, ThemeRegistrationResolved, ThemeTypes, ThemedDiffResult, ThemedFileResult, ThemedToken, ThemesType, TokenEventBase, VirtualFileMetrics, VirtualWindowSpecs } from "../types.js";
2
2
  import { PreloadDiffOptions, PreloadFileDiffOptions, PreloadFileDiffResult, PreloadMultiFileDiffOptions, PreloadMultiFileDiffResult, PreloadPatchDiffOptions, PreloadPatchDiffResult, PreloadUnresolvedFileOptions, PreloadUnresolvedFileResult, preloadDiffHTML, preloadFileDiff, preloadMultiFileDiff, preloadPatchDiff, preloadUnresolvedFile, preloadUnresolvedFileHTML } from "./preloadDiffs.js";
3
3
  import { PreloadFileOptions, PreloadedFileResult, preloadFile } from "./preloadFile.js";
4
4
  import { PreloadPatchFileOptions, preloadPatchFile } from "./preloadPatchFile.js";
5
5
  import { renderHTML } from "./renderHTML.js";
6
- export { AnnotationLineMap, AnnotationSide, AnnotationSpan, AppliedThemeStyleCache, BaseCodeOptions, BaseDiffOptions, BaseDiffOptionsWithDefaults, type BundledLanguage, ChangeContent, ChangeTypes, CodeColumnType, type CodeToHastOptions, CodeViewCreateEditorOptions, CodeViewDiffItem, CodeViewFileItem, CodeViewItem, CodeViewItemScrollTarget, CodeViewLayout, CodeViewLineScrollTarget, CodeViewPositionScrollTarget, CodeViewRangeScrollTarget, CodeViewScrollBehavior, CodeViewScrollTarget, ConflictResolverTypes, ContextContent, type CreatePatchOptionsNonabortable, CustomPreProperties, type DecorationItem, DiffAcceptRejectHunkConfig, DiffAcceptRejectHunkType, DiffFileInput, DiffIndicators, DiffLineAnnotation, DiffLineEventBaseProps, DiffTokenEventBaseProps, DiffsBaseComponent, DiffsComponentOptions, DiffsEditableComponent, DiffsEditor, DiffsEditorHost, DiffsEditorSelection, DiffsHighlighter, DiffsTextDocument, DiffsThemeNames, ExpansionDirections, ExtensionFormatMap, FileContents, FileDiffContentsLoader, FileDiffLoadedChangedFiles, FileDiffLoadedFiles, FileDiffLoadedPureRenamedFile, FileDiffMetadata, FileHeaderRenderMode, ForceDiffPlainTextOptions, ForceFilePlainTextOptions, GapSpan, HighlightedToken, HighlighterTypes, Hunk, HunkData, HunkExpansionRegion, HunkLineType, HunkSeparators, type LanguageRegistration, LineAnnotation, LineDiffTypes, LineEventBaseProps, LineInfo, LineSpans, LineTypes, MaybeDiffFileInput, MergeConflictActionPayload, MergeConflictMarkerRow, MergeConflictMarkerRowType, MergeConflictRegion, MergeConflictResolution, NumericScrollLineAnchor, ObservedAnnotationNodes, ObservedGridNodes, ParsedPatch, PendingCodeViewLayoutReset, PostRenderPhase, PrePropertiesConfig, PreloadDiffOptions, PreloadFileDiffOptions, PreloadFileDiffResult, PreloadFileOptions, PreloadMultiFileDiffOptions, PreloadMultiFileDiffResult, PreloadPatchDiffOptions, PreloadPatchDiffResult, PreloadPatchFileOptions, PreloadUnresolvedFileOptions, PreloadUnresolvedFileResult, PreloadedFileResult, ProcessFileConflictData, RenderDiffFilesResult, RenderDiffOptions, RenderDiffResult, RenderFileMetadata, RenderFileOptions, RenderFileResult, RenderHeaderFilenameSuffixCallback, RenderHeaderMetadataCallback, RenderHeaderPrefixCallback, RenderRange, RenderWindow, RenderedDiffASTCache, RenderedFileASTCache, SelectedLineRange, SelectionPoint, SelectionSide, SharedRenderState, type ShikiTransformer, SmoothScrollSettings, StickySpecs, SupportedLanguages, type ThemeRegistration, type ThemeRegistrationResolved, ThemeTypes, ThemedDiffResult, ThemedFileResult, type ThemedToken, ThemesType, TokenEventBase, VirtualFileMetrics, VirtualWindowSpecs, preloadDiffHTML, preloadFile, preloadFileDiff, preloadMultiFileDiff, preloadPatchDiff, preloadPatchFile, preloadUnresolvedFile, preloadUnresolvedFileHTML, renderHTML };
6
+ export { AnnotationLineMap, AnnotationSide, AnnotationSpan, AppliedThemeStyleCache, BaseCodeOptions, BaseDiffOptions, BaseDiffOptionsWithDefaults, type BundledLanguage, ChangeContent, ChangeTypes, CodeColumnType, type CodeToHastOptions, CodeViewCreateEditorOptions, CodeViewDiffItem, CodeViewFileItem, CodeViewItem, CodeViewItemScrollTarget, CodeViewLayout, CodeViewLineScrollTarget, CodeViewPositionScrollTarget, CodeViewRangeScrollTarget, CodeViewScrollBehavior, CodeViewScrollTarget, ConflictResolverTypes, ContextContent, type CreatePatchOptionsNonabortable, CustomPreProperties, type DecorationItem, DiffAcceptRejectHunkConfig, DiffAcceptRejectHunkType, DiffFileInput, DiffIndicators, DiffLineAnnotation, DiffLineEventBaseProps, DiffTokenEventBaseProps, DiffsBaseComponent, DiffsComponentOptions, DiffsEditableComponent, DiffsEditor, DiffsHighlighter, DiffsTextDocument, DiffsThemeNames, EditableInstance, EditorActiveLineOptions, EditorSelection, EditorState, EditorViewState, ExpansionDirections, ExtensionFormatMap, FileContents, FileDiffContentsLoader, FileDiffLoadedChangedFiles, FileDiffLoadedFiles, FileDiffLoadedPureRenamedFile, FileDiffMetadata, FileHeaderRenderMode, ForceDiffPlainTextOptions, ForceFilePlainTextOptions, GapSpan, HighlightedToken, HighlighterTypes, Hunk, HunkData, HunkExpansionRegion, HunkLineType, HunkSeparators, type LanguageRegistration, LineAnnotation, LineDiffTypes, LineEventBaseProps, LineInfo, LineSpans, LineTypes, MaybeDiffFileInput, MergeConflictActionPayload, MergeConflictMarkerRow, MergeConflictMarkerRowType, MergeConflictRegion, MergeConflictResolution, NumericScrollLineAnchor, ObservedAnnotationNodes, ObservedGridNodes, ParsedPatch, PendingCodeViewLayoutReset, Position, PostRenderPhase, PrePropertiesConfig, PreloadDiffOptions, PreloadFileDiffOptions, PreloadFileDiffResult, PreloadFileOptions, PreloadMultiFileDiffOptions, PreloadMultiFileDiffResult, PreloadPatchDiffOptions, PreloadPatchDiffResult, PreloadPatchFileOptions, PreloadUnresolvedFileOptions, PreloadUnresolvedFileResult, PreloadedFileResult, ProcessFileConflictData, Range, RenderDiffFilesResult, RenderDiffOptions, RenderDiffResult, RenderFileMetadata, RenderFileOptions, RenderFileResult, RenderHeaderFilenameSuffixCallback, RenderHeaderMetadataCallback, RenderHeaderPrefixCallback, RenderRange, RenderWindow, RenderedDiffASTCache, RenderedFileASTCache, SelectedLineRange, SelectionDirection, SelectionPoint, SelectionSide, SharedRenderState, type ShikiTransformer, SmoothScrollSettings, StickySpecs, SupportedLanguages, TextEdit, type ThemeRegistration, type ThemeRegistrationResolved, ThemeTypes, ThemedDiffResult, ThemedFileResult, type ThemedToken, ThemesType, TokenEventBase, VirtualFileMetrics, VirtualWindowSpecs, preloadDiffHTML, preloadFile, preloadFileDiff, preloadMultiFileDiff, preloadPatchDiff, preloadPatchFile, preloadUnresolvedFile, preloadUnresolvedFileHTML, renderHTML };
@@ -1 +1 @@
1
- {"version":3,"file":"preloadDiffs.d.ts","names":[],"sources":["../../src/ssr/preloadDiffs.ts"],"mappings":";;;;;UA6BU,sBAAA;EACR,OAAA,GAAU,eAAA,CAAgB,WAAA;EAC1B,WAAA,GAAc,kBAAA,CAAmB,WAAA;AAAA;AAAA,KAGvB,kBAAA,gBACV,sBAAA,CAAuB,WAAA;EAEd,QAAA,EAAU,gBAAA;AAAA,IAAqB,kBAAA;EAC/B,QAAA;AAAA,IAAyB,aAAA;AAAA,iBAGd,eAAA;EACpB,QAAA;EACA,OAAA;EACA,OAAA;EACA,OAAA;EACA;AAAA,GACC,kBAAA,CAAmB,WAAA,IAAe,OAAA;AAAA,iBA8Bf,yBAAA;EACpB,IAAA;EACA,OAAA;EACA;AAAA,GACC,4BAAA,CAA6B,WAAA,IAAe,OAAA;AAAA,UAsBrC,+BAAA;EACR,OAAA,GAAU,eAAA,CAAgB,WAAA;EAC1B,WAAA,GAAc,kBAAA,CAAmB,WAAA;AAAA;AAAA,KAGvB,2BAAA,gBACV,+BAAA,CAAgC,WAAA,IAAe,aAAA;AAAA,KAErC,0BAAA,gBACV,2BAA2B,CAAC,WAAA;EAC1B,eAAA;AAAA;AAAA,iBAGkB,oBAAA;EACpB,OAAA;EACA,OAAA;EACA,OAAA;EACA;AAAA,GACC,2BAAA,CAA4B,WAAA,IAAe,OAAA,CAC5C,0BAAA,CAA2B,WAAA;AAAA,UAuBZ,sBAAA;EACf,QAAA,EAAU,gBAAA;EACV,OAAA,GAAU,eAAA,CAAgB,WAAA;EAC1B,WAAA,GAAc,kBAAA,CAAmB,WAAA;AAAA;AAAA,UAGlB,qBAAA,sBAEP,sBAAsB,CAAC,WAAA;EAC/B,eAAA;AAAA;AAAA,iBAGoB,eAAA;EACpB,QAAA;EACA,OAAA;EACA;AAAA,GACC,sBAAA,CAAuB,WAAA,IAAe,OAAA,CAC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
1
+ import { parseDiffFromFile } from "../utils/parseDiffFromFile.js";
1
2
  import { wrapThemeCSS } from "../utils/cssWrappers.js";
3
+ import { shouldUseTokenTransformer } from "../utils/shouldUseTokenTransformer.js";
2
4
  import { getDiffFileInput } from "../utils/getDiffFileInput.js";
3
- import { parseDiffFromFile } from "../utils/parseDiffFromFile.js";
4
5
  import { DiffHunksRenderer } from "../renderers/DiffHunksRenderer.js";
5
6
  import { parseMergeConflictDiffFromFile } from "../utils/parseMergeConflictDiffFromFile.js";
6
7
  import { UnresolvedFileHunksRenderer } from "../renderers/UnresolvedFileHunksRenderer.js";
@@ -93,6 +94,7 @@ function processHunkResult(hunkResult, renderer, unsafeCSS, themeType) {
93
94
  function getHunksRendererOptions(options) {
94
95
  return {
95
96
  ...options,
97
+ useTokenTransformer: shouldUseTokenTransformer(options),
96
98
  headerRenderMode: options?.renderCustomHeader != null ? "custom" : "default",
97
99
  hunkSeparators: typeof options?.hunkSeparators === "function" ? "custom" : options?.hunkSeparators
98
100
  };
@@ -1 +1 @@
1
- {"version":3,"file":"preloadDiffs.js","names":[],"sources":["../../src/ssr/preloadDiffs.ts"],"sourcesContent":["import type { FileDiffOptions } from '../components/FileDiff';\nimport {\n getUnresolvedDiffHunksRendererOptions,\n type UnresolvedFileOptions,\n} from '../components/UnresolvedFile';\nimport {\n DiffHunksRenderer,\n type DiffHunksRendererOptions,\n type HunksRenderResult,\n} from '../renderers/DiffHunksRenderer';\nimport { UnresolvedFileHunksRenderer } from '../renderers/UnresolvedFileHunksRenderer';\nimport type {\n DiffFileInput,\n DiffLineAnnotation,\n FileContents,\n FileDiffMetadata,\n MaybeDiffFileInput,\n} from '../types';\nimport {\n createStyleElement,\n createThemeStyleElement,\n} from '../utils/createStyleElement';\nimport { wrapThemeCSS } from '../utils/cssWrappers';\nimport { getDiffFileInput } from '../utils/getDiffFileInput';\nimport { getSingularPatch } from '../utils/getSingularPatch';\nimport { parseDiffFromFile } from '../utils/parseDiffFromFile';\nimport { parseMergeConflictDiffFromFile } from '../utils/parseMergeConflictDiffFromFile';\nimport { renderHTML } from './renderHTML';\n\ninterface PreloadDiffBaseOptions<LAnnotation> {\n options?: FileDiffOptions<LAnnotation>;\n annotations?: DiffLineAnnotation<LAnnotation>[];\n}\n\nexport type PreloadDiffOptions<LAnnotation> =\n PreloadDiffBaseOptions<LAnnotation> &\n (\n | ({ fileDiff: FileDiffMetadata } & MaybeDiffFileInput)\n | ({ fileDiff?: undefined } & DiffFileInput)\n );\n\nexport async function preloadDiffHTML<LAnnotation = undefined>({\n fileDiff,\n oldFile,\n newFile,\n options,\n annotations,\n}: PreloadDiffOptions<LAnnotation>): Promise<string> {\n const fileInput = getDiffFileInput({ oldFile, newFile }, 'preloadDiffHTML');\n if (fileDiff == null && fileInput != null) {\n fileDiff = parseDiffFromFile(\n fileInput.oldFile,\n fileInput.newFile,\n options?.parseDiffOptions\n );\n }\n if (fileDiff == null) {\n throw new Error(\n 'preloadFileDiff: You must pass at least a fileDiff, oldFile, or newFile prop'\n );\n }\n const renderer = new DiffHunksRenderer<LAnnotation>(\n getHunksRendererOptions(options)\n );\n if (annotations != null && annotations.length > 0) {\n renderer.setLineAnnotations(annotations);\n }\n return renderHTML(\n processHunkResult(\n await renderer.asyncRender(fileDiff),\n renderer,\n options?.unsafeCSS,\n options?.themeType ?? 'system'\n )\n );\n}\n\nexport async function preloadUnresolvedFileHTML<LAnnotation = undefined>({\n file,\n options,\n annotations,\n}: PreloadUnresolvedFileOptions<LAnnotation>): Promise<string> {\n const { fileDiff, actions, markerRows } = parseMergeConflictDiffFromFile(\n file,\n options?.maxContextLines\n );\n const renderer = new UnresolvedFileHunksRenderer<LAnnotation>(\n getUnresolvedDiffHunksRendererOptions(options)\n );\n if (annotations != null && annotations.length > 0) {\n renderer.setLineAnnotations(annotations);\n }\n renderer.setConflictState(actions, markerRows, fileDiff);\n return renderHTML(\n processHunkResult(\n await renderer.asyncRender(fileDiff),\n renderer,\n options?.unsafeCSS,\n options?.themeType ?? 'system'\n )\n );\n}\n\ninterface PreloadMultiFileDiffBaseOptions<LAnnotation> {\n options?: FileDiffOptions<LAnnotation>;\n annotations?: DiffLineAnnotation<LAnnotation>[];\n}\n\nexport type PreloadMultiFileDiffOptions<LAnnotation> =\n PreloadMultiFileDiffBaseOptions<LAnnotation> & DiffFileInput;\n\nexport type PreloadMultiFileDiffResult<LAnnotation> =\n PreloadMultiFileDiffOptions<LAnnotation> & {\n prerenderedHTML: string;\n };\n\nexport async function preloadMultiFileDiff<LAnnotation = undefined>({\n oldFile,\n newFile,\n options,\n annotations,\n}: PreloadMultiFileDiffOptions<LAnnotation>): Promise<\n PreloadMultiFileDiffResult<LAnnotation>\n> {\n const fileInput = getDiffFileInput(\n { oldFile, newFile },\n 'preloadMultiFileDiff'\n );\n if (fileInput == null) {\n throw new Error(\n 'preloadMultiFileDiff: You must pass oldFile, newFile, or both'\n );\n }\n return {\n ...fileInput,\n options,\n annotations,\n prerenderedHTML: await preloadDiffHTML({\n ...fileInput,\n options,\n annotations,\n }),\n };\n}\n\nexport interface PreloadFileDiffOptions<LAnnotation> {\n fileDiff: FileDiffMetadata;\n options?: FileDiffOptions<LAnnotation>;\n annotations?: DiffLineAnnotation<LAnnotation>[];\n}\n\nexport interface PreloadFileDiffResult<\n LAnnotation,\n> extends PreloadFileDiffOptions<LAnnotation> {\n prerenderedHTML: string;\n}\n\nexport async function preloadFileDiff<LAnnotation = undefined>({\n fileDiff,\n options,\n annotations,\n}: PreloadFileDiffOptions<LAnnotation>): Promise<\n PreloadFileDiffResult<LAnnotation>\n> {\n return {\n fileDiff,\n options,\n annotations,\n prerenderedHTML: await preloadDiffHTML({\n fileDiff,\n options,\n annotations,\n }),\n };\n}\n\nexport interface PreloadUnresolvedFileOptions<LAnnotation> {\n file: FileContents;\n options?: Omit<\n UnresolvedFileOptions<LAnnotation>,\n 'onMergeConflictAction' | 'onMergeConflictResolve' | 'onPostRender'\n >;\n annotations?: DiffLineAnnotation<LAnnotation>[];\n}\n\nexport interface PreloadUnresolvedFileResult<\n LAnnotation,\n> extends PreloadUnresolvedFileOptions<LAnnotation> {\n prerenderedHTML: string;\n}\n\nexport async function preloadUnresolvedFile<LAnnotation = undefined>({\n file,\n options,\n annotations,\n}: PreloadUnresolvedFileOptions<LAnnotation>): Promise<\n PreloadUnresolvedFileResult<LAnnotation>\n> {\n return {\n file,\n options,\n annotations,\n prerenderedHTML: await preloadUnresolvedFileHTML({\n file,\n options,\n annotations,\n }),\n };\n}\n\nexport interface PreloadPatchDiffOptions<LAnnotation> {\n patch: string;\n options?: FileDiffOptions<LAnnotation>;\n annotations?: DiffLineAnnotation<LAnnotation>[];\n}\n\nexport interface PreloadPatchDiffResult<\n LAnnotation,\n> extends PreloadPatchDiffOptions<LAnnotation> {\n prerenderedHTML: string;\n}\n\nexport async function preloadPatchDiff<LAnnotation = undefined>({\n patch,\n options,\n annotations,\n}: PreloadPatchDiffOptions<LAnnotation>): Promise<\n PreloadPatchDiffResult<LAnnotation>\n> {\n const fileDiff = getSingularPatch(patch);\n return {\n patch,\n options,\n annotations,\n prerenderedHTML: await preloadDiffHTML({\n fileDiff,\n options,\n annotations,\n }),\n };\n}\n\nfunction processHunkResult<LAnnotation>(\n hunkResult: HunksRenderResult,\n renderer:\n | DiffHunksRenderer<LAnnotation>\n | UnresolvedFileHunksRenderer<LAnnotation>,\n unsafeCSS: string | undefined,\n themeType: 'system' | 'light' | 'dark'\n) {\n const children = [createStyleElement(hunkResult.css, true)];\n children.push(\n createThemeStyleElement(\n wrapThemeCSS(\n hunkResult.themeStyles,\n hunkResult.baseThemeType ?? themeType\n )\n )\n );\n if (unsafeCSS != null) {\n children.push(createStyleElement(unsafeCSS));\n }\n if (hunkResult.headerElement != null) {\n children.push(hunkResult.headerElement);\n }\n const code = renderer.renderFullAST(hunkResult);\n code.properties['data-dehydrated'] = '';\n children.push(code);\n return children;\n}\n\nfunction getHunksRendererOptions<LAnnotation>(\n options: FileDiffOptions<LAnnotation> | undefined\n): DiffHunksRendererOptions {\n return {\n ...options,\n headerRenderMode:\n options?.renderCustomHeader != null ? 'custom' : 'default',\n hunkSeparators:\n typeof options?.hunkSeparators === 'function'\n ? 'custom'\n : options?.hunkSeparators,\n };\n}\n"],"mappings":";;;;;;;;;;;AAyCA,eAAsB,gBAAyC,EAC7D,UACA,SACA,SACA,SACA,eACmD;CACnD,MAAM,YAAY,iBAAiB;EAAE;EAAS;CAAQ,GAAG,iBAAiB;CAC1E,IAAI,YAAY,QAAQ,aAAa,MACnC,WAAW,kBACT,UAAU,SACV,UAAU,SACV,SAAS,gBACX;CAEF,IAAI,YAAY,MACd,MAAM,IAAI,MACR,8EACF;CAEF,MAAM,WAAW,IAAI,kBACnB,wBAAwB,OAAO,CACjC;CACA,IAAI,eAAe,QAAQ,YAAY,SAAS,GAC9C,SAAS,mBAAmB,WAAW;CAEzC,OAAO,WACL,kBACE,MAAM,SAAS,YAAY,QAAQ,GACnC,UACA,SAAS,WACT,SAAS,aAAa,QACxB,CACF;AACF;AAEA,eAAsB,0BAAmD,EACvE,MACA,SACA,eAC6D;CAC7D,MAAM,EAAE,UAAU,SAAS,eAAe,+BACxC,MACA,SAAS,eACX;CACA,MAAM,WAAW,IAAI,4BACnB,sCAAsC,OAAO,CAC/C;CACA,IAAI,eAAe,QAAQ,YAAY,SAAS,GAC9C,SAAS,mBAAmB,WAAW;CAEzC,SAAS,iBAAiB,SAAS,YAAY,QAAQ;CACvD,OAAO,WACL,kBACE,MAAM,SAAS,YAAY,QAAQ,GACnC,UACA,SAAS,WACT,SAAS,aAAa,QACxB,CACF;AACF;AAeA,eAAsB,qBAA8C,EAClE,SACA,SACA,SACA,eAGA;CACA,MAAM,YAAY,iBAChB;EAAE;EAAS;CAAQ,GACnB,sBACF;CACA,IAAI,aAAa,MACf,MAAM,IAAI,MACR,+DACF;CAEF,OAAO;EACL,GAAG;EACH;EACA;EACA,iBAAiB,MAAM,gBAAgB;GACrC,GAAG;GACH;GACA;EACF,CAAC;CACH;AACF;AAcA,eAAsB,gBAAyC,EAC7D,UACA,SACA,eAGA;CACA,OAAO;EACL;EACA;EACA;EACA,iBAAiB,MAAM,gBAAgB;GACrC;GACA;GACA;EACF,CAAC;CACH;AACF;AAiBA,eAAsB,sBAA+C,EACnE,MACA,SACA,eAGA;CACA,OAAO;EACL;EACA;EACA;EACA,iBAAiB,MAAM,0BAA0B;GAC/C;GACA;GACA;EACF,CAAC;CACH;AACF;AAcA,eAAsB,iBAA0C,EAC9D,OACA,SACA,eAGA;CAEA,OAAO;EACL;EACA;EACA;EACA,iBAAiB,MAAM,gBAAgB;GACrC,UANa,iBAAiB,KAMvB;GACP;GACA;EACF,CAAC;CACH;AACF;AAEA,SAAS,kBACP,YACA,UAGA,WACA,WACA;CACA,MAAM,WAAW,CAAC,mBAAmB,WAAW,KAAK,IAAI,CAAC;CAC1D,SAAS,KACP,wBACE,aACE,WAAW,aACX,WAAW,iBAAiB,SAC9B,CACF,CACF;CACA,IAAI,aAAa,MACf,SAAS,KAAK,mBAAmB,SAAS,CAAC;CAE7C,IAAI,WAAW,iBAAiB,MAC9B,SAAS,KAAK,WAAW,aAAa;CAExC,MAAM,OAAO,SAAS,cAAc,UAAU;CAC9C,KAAK,WAAW,qBAAqB;CACrC,SAAS,KAAK,IAAI;CAClB,OAAO;AACT;AAEA,SAAS,wBACP,SAC0B;CAC1B,OAAO;EACL,GAAG;EACH,kBACE,SAAS,sBAAsB,OAAO,WAAW;EACnD,gBACE,OAAO,SAAS,mBAAmB,aAC/B,WACA,SAAS;CACjB;AACF"}
1
+ {"version":3,"file":"preloadDiffs.js","names":[],"sources":["../../src/ssr/preloadDiffs.ts"],"sourcesContent":["import type { FileDiffOptions } from '../components/FileDiff';\nimport {\n getUnresolvedDiffHunksRendererOptions,\n type UnresolvedFileOptions,\n} from '../components/UnresolvedFile';\nimport {\n DiffHunksRenderer,\n type DiffHunksRendererOptions,\n type HunksRenderResult,\n} from '../renderers/DiffHunksRenderer';\nimport { UnresolvedFileHunksRenderer } from '../renderers/UnresolvedFileHunksRenderer';\nimport type {\n DiffFileInput,\n DiffLineAnnotation,\n FileContents,\n FileDiffMetadata,\n MaybeDiffFileInput,\n} from '../types';\nimport {\n createStyleElement,\n createThemeStyleElement,\n} from '../utils/createStyleElement';\nimport { wrapThemeCSS } from '../utils/cssWrappers';\nimport { getDiffFileInput } from '../utils/getDiffFileInput';\nimport { getSingularPatch } from '../utils/getSingularPatch';\nimport { parseDiffFromFile } from '../utils/parseDiffFromFile';\nimport { parseMergeConflictDiffFromFile } from '../utils/parseMergeConflictDiffFromFile';\nimport { shouldUseTokenTransformer } from '../utils/shouldUseTokenTransformer';\nimport { renderHTML } from './renderHTML';\n\ninterface PreloadDiffBaseOptions<LAnnotation> {\n options?: FileDiffOptions<LAnnotation>;\n annotations?: DiffLineAnnotation<LAnnotation>[];\n}\n\nexport type PreloadDiffOptions<LAnnotation> =\n PreloadDiffBaseOptions<LAnnotation> &\n (\n | ({ fileDiff: FileDiffMetadata } & MaybeDiffFileInput)\n | ({ fileDiff?: undefined } & DiffFileInput)\n );\n\nexport async function preloadDiffHTML<LAnnotation = undefined>({\n fileDiff,\n oldFile,\n newFile,\n options,\n annotations,\n}: PreloadDiffOptions<LAnnotation>): Promise<string> {\n const fileInput = getDiffFileInput({ oldFile, newFile }, 'preloadDiffHTML');\n if (fileDiff == null && fileInput != null) {\n fileDiff = parseDiffFromFile(\n fileInput.oldFile,\n fileInput.newFile,\n options?.parseDiffOptions\n );\n }\n if (fileDiff == null) {\n throw new Error(\n 'preloadFileDiff: You must pass at least a fileDiff, oldFile, or newFile prop'\n );\n }\n const renderer = new DiffHunksRenderer<LAnnotation>(\n getHunksRendererOptions(options)\n );\n if (annotations != null && annotations.length > 0) {\n renderer.setLineAnnotations(annotations);\n }\n return renderHTML(\n processHunkResult(\n await renderer.asyncRender(fileDiff),\n renderer,\n options?.unsafeCSS,\n options?.themeType ?? 'system'\n )\n );\n}\n\nexport async function preloadUnresolvedFileHTML<LAnnotation = undefined>({\n file,\n options,\n annotations,\n}: PreloadUnresolvedFileOptions<LAnnotation>): Promise<string> {\n const { fileDiff, actions, markerRows } = parseMergeConflictDiffFromFile(\n file,\n options?.maxContextLines\n );\n const renderer = new UnresolvedFileHunksRenderer<LAnnotation>(\n getUnresolvedDiffHunksRendererOptions(options)\n );\n if (annotations != null && annotations.length > 0) {\n renderer.setLineAnnotations(annotations);\n }\n renderer.setConflictState(actions, markerRows, fileDiff);\n return renderHTML(\n processHunkResult(\n await renderer.asyncRender(fileDiff),\n renderer,\n options?.unsafeCSS,\n options?.themeType ?? 'system'\n )\n );\n}\n\ninterface PreloadMultiFileDiffBaseOptions<LAnnotation> {\n options?: FileDiffOptions<LAnnotation>;\n annotations?: DiffLineAnnotation<LAnnotation>[];\n}\n\nexport type PreloadMultiFileDiffOptions<LAnnotation> =\n PreloadMultiFileDiffBaseOptions<LAnnotation> & DiffFileInput;\n\nexport type PreloadMultiFileDiffResult<LAnnotation> =\n PreloadMultiFileDiffOptions<LAnnotation> & {\n prerenderedHTML: string;\n };\n\nexport async function preloadMultiFileDiff<LAnnotation = undefined>({\n oldFile,\n newFile,\n options,\n annotations,\n}: PreloadMultiFileDiffOptions<LAnnotation>): Promise<\n PreloadMultiFileDiffResult<LAnnotation>\n> {\n const fileInput = getDiffFileInput(\n { oldFile, newFile },\n 'preloadMultiFileDiff'\n );\n if (fileInput == null) {\n throw new Error(\n 'preloadMultiFileDiff: You must pass oldFile, newFile, or both'\n );\n }\n return {\n ...fileInput,\n options,\n annotations,\n prerenderedHTML: await preloadDiffHTML({\n ...fileInput,\n options,\n annotations,\n }),\n };\n}\n\nexport interface PreloadFileDiffOptions<LAnnotation> {\n fileDiff: FileDiffMetadata;\n options?: FileDiffOptions<LAnnotation>;\n annotations?: DiffLineAnnotation<LAnnotation>[];\n}\n\nexport interface PreloadFileDiffResult<\n LAnnotation,\n> extends PreloadFileDiffOptions<LAnnotation> {\n prerenderedHTML: string;\n}\n\nexport async function preloadFileDiff<LAnnotation = undefined>({\n fileDiff,\n options,\n annotations,\n}: PreloadFileDiffOptions<LAnnotation>): Promise<\n PreloadFileDiffResult<LAnnotation>\n> {\n return {\n fileDiff,\n options,\n annotations,\n prerenderedHTML: await preloadDiffHTML({\n fileDiff,\n options,\n annotations,\n }),\n };\n}\n\nexport interface PreloadUnresolvedFileOptions<LAnnotation> {\n file: FileContents;\n options?: Omit<\n UnresolvedFileOptions<LAnnotation>,\n 'onMergeConflictAction' | 'onMergeConflictResolve' | 'onPostRender'\n >;\n annotations?: DiffLineAnnotation<LAnnotation>[];\n}\n\nexport interface PreloadUnresolvedFileResult<\n LAnnotation,\n> extends PreloadUnresolvedFileOptions<LAnnotation> {\n prerenderedHTML: string;\n}\n\nexport async function preloadUnresolvedFile<LAnnotation = undefined>({\n file,\n options,\n annotations,\n}: PreloadUnresolvedFileOptions<LAnnotation>): Promise<\n PreloadUnresolvedFileResult<LAnnotation>\n> {\n return {\n file,\n options,\n annotations,\n prerenderedHTML: await preloadUnresolvedFileHTML({\n file,\n options,\n annotations,\n }),\n };\n}\n\nexport interface PreloadPatchDiffOptions<LAnnotation> {\n patch: string;\n options?: FileDiffOptions<LAnnotation>;\n annotations?: DiffLineAnnotation<LAnnotation>[];\n}\n\nexport interface PreloadPatchDiffResult<\n LAnnotation,\n> extends PreloadPatchDiffOptions<LAnnotation> {\n prerenderedHTML: string;\n}\n\nexport async function preloadPatchDiff<LAnnotation = undefined>({\n patch,\n options,\n annotations,\n}: PreloadPatchDiffOptions<LAnnotation>): Promise<\n PreloadPatchDiffResult<LAnnotation>\n> {\n const fileDiff = getSingularPatch(patch);\n return {\n patch,\n options,\n annotations,\n prerenderedHTML: await preloadDiffHTML({\n fileDiff,\n options,\n annotations,\n }),\n };\n}\n\nfunction processHunkResult<LAnnotation>(\n hunkResult: HunksRenderResult,\n renderer:\n | DiffHunksRenderer<LAnnotation>\n | UnresolvedFileHunksRenderer<LAnnotation>,\n unsafeCSS: string | undefined,\n themeType: 'system' | 'light' | 'dark'\n) {\n const children = [createStyleElement(hunkResult.css, true)];\n children.push(\n createThemeStyleElement(\n wrapThemeCSS(\n hunkResult.themeStyles,\n hunkResult.baseThemeType ?? themeType\n )\n )\n );\n if (unsafeCSS != null) {\n children.push(createStyleElement(unsafeCSS));\n }\n if (hunkResult.headerElement != null) {\n children.push(hunkResult.headerElement);\n }\n const code = renderer.renderFullAST(hunkResult);\n code.properties['data-dehydrated'] = '';\n children.push(code);\n return children;\n}\n\nfunction getHunksRendererOptions<LAnnotation>(\n options: FileDiffOptions<LAnnotation> | undefined\n): DiffHunksRendererOptions {\n return {\n ...options,\n // Match the client's option snapshot: token callbacks imply the\n // transformer, so server markup hydrates into identical client renders.\n useTokenTransformer: shouldUseTokenTransformer<'diff'>(options),\n headerRenderMode:\n options?.renderCustomHeader != null ? 'custom' : 'default',\n hunkSeparators:\n typeof options?.hunkSeparators === 'function'\n ? 'custom'\n : options?.hunkSeparators,\n };\n}\n"],"mappings":";;;;;;;;;;;;AA0CA,eAAsB,gBAAyC,EAC7D,UACA,SACA,SACA,SACA,eACmD;CACnD,MAAM,YAAY,iBAAiB;EAAE;EAAS;CAAQ,GAAG,iBAAiB;CAC1E,IAAI,YAAY,QAAQ,aAAa,MACnC,WAAW,kBACT,UAAU,SACV,UAAU,SACV,SAAS,gBACX;CAEF,IAAI,YAAY,MACd,MAAM,IAAI,MACR,8EACF;CAEF,MAAM,WAAW,IAAI,kBACnB,wBAAwB,OAAO,CACjC;CACA,IAAI,eAAe,QAAQ,YAAY,SAAS,GAC9C,SAAS,mBAAmB,WAAW;CAEzC,OAAO,WACL,kBACE,MAAM,SAAS,YAAY,QAAQ,GACnC,UACA,SAAS,WACT,SAAS,aAAa,QACxB,CACF;AACF;AAEA,eAAsB,0BAAmD,EACvE,MACA,SACA,eAC6D;CAC7D,MAAM,EAAE,UAAU,SAAS,eAAe,+BACxC,MACA,SAAS,eACX;CACA,MAAM,WAAW,IAAI,4BACnB,sCAAsC,OAAO,CAC/C;CAC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,IAAI;CAClB,OAAO;AACT;AAEA,SAAS,wBACP,SAC0B;CAC1B,OAAO;EACL,GAAG;EAGH,qBAAqB,0BAAkC,OAAO;EAC9D,kBACE,SAAS,sBAAsB,OAAO,WAAW;EACnD,gBACE,OAAO,SAAS,mBAAmB,aAC/B,WACA,SAAS;CACjB;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"preloadFile.d.ts","names":[],"sources":["../../src/ssr/preloadFile.ts"],"mappings":";;;;KAUY,kBAAA;EACV,IAAA,EAAM,YAAA;EACN,OAAA,GAAU,WAAA,CAAY,WAAA;EACtB,WAAA,GAAc,cAAA,CAAe,WAAA;AAAA;AAAA,UAGd,mBAAA;EACf,IAAA,EAAM,YAAA;EACN,OAAA,GAAU,WAAA,CAAY,WAAA;EACtB,WAAA,GAAc,cAAA,CAAe,WAAA;EAC7B,eAAA;AAAA;AAAA,iBAGoB,WAAA;EACpB,IAAA;EACA,OAAA;EACA;AAAA,GACC,kBAAA,CAAmB,WAAA,IAAe,OAAA,CAAQ,mBAAA,CAAoB,WAAA"}
1
+ {"version":3,"file":"preloadFile.d.ts","names":[],"sources":["../../src/ssr/preloadFile.ts"],"mappings":";;;;KAWY,kBAAA;EACV,IAAA,EAAM,YAAA;EACN,OAAA,GAAU,WAAA,CAAY,WAAA;EACtB,WAAA,GAAc,cAAA,CAAe,WAAA;AAAA;AAAA,UAGd,mBAAA;EACf,IAAA,EAAM,YAAA;EACN,OAAA,GAAU,WAAA,CAAY,WAAA;EACtB,WAAA,GAAc,cAAA,CAAe,WAAA;EAC7B,eAAA;AAAA;AAAA,iBAGoB,WAAA;EACpB,IAAA;EACA,OAAA;EACA;AAAA,GACC,kBAAA,CAAmB,WAAA,IAAe,OAAA,CAAQ,mBAAA,CAAoB,WAAA"}
@@ -1,11 +1,13 @@
1
1
  import { FileRenderer } from "../renderers/FileRenderer.js";
2
2
  import { wrapThemeCSS } from "../utils/cssWrappers.js";
3
+ import { shouldUseTokenTransformer } from "../utils/shouldUseTokenTransformer.js";
3
4
  import { createStyleElement, createThemeStyleElement } from "../utils/createStyleElement.js";
4
5
  import { renderHTML } from "./renderHTML.js";
5
6
  //#region src/ssr/preloadFile.ts
6
7
  async function preloadFile({ file, options, annotations }) {
7
8
  const fileRenderer = new FileRenderer({
8
9
  ...options,
10
+ useTokenTransformer: shouldUseTokenTransformer(options),
9
11
  headerRenderMode: options?.renderCustomHeader != null ? "custom" : "default"
10
12
  });
11
13
  if (annotations !== void 0 && annotations.length > 0) fileRenderer.setLineAnnotations(annotations);