@pierre/diffs 1.3.0-rc.1 → 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.
- package/README.md +9 -0
- package/dist/components/CodeView.d.ts +0 -1
- package/dist/components/CodeView.d.ts.map +1 -1
- package/dist/components/CodeView.js +2 -17
- package/dist/components/CodeView.js.map +1 -1
- package/dist/components/File.d.ts +3 -1
- package/dist/components/File.d.ts.map +1 -1
- package/dist/components/File.js +6 -3
- package/dist/components/File.js.map +1 -1
- package/dist/components/FileDiff.d.ts +4 -1
- package/dist/components/FileDiff.d.ts.map +1 -1
- package/dist/components/FileDiff.js +5 -3
- package/dist/components/FileDiff.js.map +1 -1
- package/dist/components/UnresolvedFile.d.ts.map +1 -1
- package/dist/components/UnresolvedFile.js +7 -2
- package/dist/components/UnresolvedFile.js.map +1 -1
- package/dist/editor/editor.d.ts.map +1 -1
- package/dist/editor/editor.js +6 -10
- package/dist/editor/editor.js.map +1 -1
- package/dist/editor/tokenizer.d.ts.map +1 -1
- package/dist/editor/tokenizer.js +106 -51
- package/dist/editor/tokenizer.js.map +1 -1
- package/dist/react/CodeView.js +1 -1
- package/dist/react/utils/useFileDiffInstance.js +6 -17
- package/dist/react/utils/useFileDiffInstance.js.map +1 -1
- package/dist/react/utils/useFileInstance.js +5 -19
- package/dist/react/utils/useFileInstance.js.map +1 -1
- package/dist/react/utils/useUnresolvedFileInstance.js +1 -1
- package/dist/react/utils/useUnresolvedFileInstance.js.map +1 -1
- package/dist/renderers/DiffHunksRenderer.d.ts +10 -2
- package/dist/renderers/DiffHunksRenderer.d.ts.map +1 -1
- package/dist/renderers/DiffHunksRenderer.js +36 -11
- package/dist/renderers/DiffHunksRenderer.js.map +1 -1
- package/dist/renderers/FileRenderer.d.ts +18 -1
- package/dist/renderers/FileRenderer.d.ts.map +1 -1
- package/dist/renderers/FileRenderer.js +86 -18
- package/dist/renderers/FileRenderer.js.map +1 -1
- package/dist/ssr/FileDiffReact.js +1 -1
- package/dist/ssr/preloadDiffs.d.ts.map +1 -1
- package/dist/ssr/preloadDiffs.js +2 -0
- package/dist/ssr/preloadDiffs.js.map +1 -1
- package/dist/ssr/preloadFile.d.ts.map +1 -1
- package/dist/ssr/preloadFile.js +2 -0
- package/dist/ssr/preloadFile.js.map +1 -1
- package/dist/types.d.ts +13 -6
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/getDiffHunksRendererOptions.d.ts.map +1 -1
- package/dist/utils/getDiffHunksRendererOptions.js +2 -1
- package/dist/utils/getDiffHunksRendererOptions.js.map +1 -1
- package/dist/utils/getFileRendererOptions.d.ts.map +1 -1
- package/dist/utils/getFileRendererOptions.js +2 -1
- package/dist/utils/getFileRendererOptions.js.map +1 -1
- package/dist/utils/shouldUseTokenTransformer.d.ts +7 -3
- package/dist/utils/shouldUseTokenTransformer.d.ts.map +1 -1
- package/dist/utils/shouldUseTokenTransformer.js +1 -1
- package/dist/utils/shouldUseTokenTransformer.js.map +1 -1
- package/dist/worker/WorkerPoolManager.d.ts +2 -1
- package/dist/worker/WorkerPoolManager.d.ts.map +1 -1
- package/dist/worker/WorkerPoolManager.js +3 -0
- package/dist/worker/WorkerPoolManager.js.map +1 -1
- package/package.json +3 -3
|
@@ -20,7 +20,6 @@ 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
|
|
26
25
|
function isLineCacheForFile(lineCache, file) {
|
|
@@ -37,7 +36,9 @@ var FileRenderer = class {
|
|
|
37
36
|
computedLang = "text";
|
|
38
37
|
lineAnnotations = {};
|
|
39
38
|
lineCache;
|
|
39
|
+
pendingStructuralRows;
|
|
40
40
|
textDocumentCache = /* @__PURE__ */ new WeakMap();
|
|
41
|
+
editSessionActive = false;
|
|
41
42
|
constructor(options = { theme: DEFAULT_THEMES }, onRenderUpdate, workerManager) {
|
|
42
43
|
this.options = options;
|
|
43
44
|
this.onRenderUpdate = onRenderUpdate;
|
|
@@ -66,11 +67,31 @@ var FileRenderer = class {
|
|
|
66
67
|
this.workerManager = void 0;
|
|
67
68
|
this.onRenderUpdate = void 0;
|
|
68
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
|
+
}
|
|
69
89
|
recycle() {
|
|
70
90
|
this.clearRenderCache();
|
|
71
91
|
this.highlighter = void 0;
|
|
72
92
|
this.workerManager?.cleanUpTasks(this);
|
|
73
93
|
this.lineCache = void 0;
|
|
94
|
+
this.endEditSession();
|
|
74
95
|
this.textDocumentCache = /* @__PURE__ */ new WeakMap();
|
|
75
96
|
}
|
|
76
97
|
syncEditedContentsToFile() {
|
|
@@ -91,6 +112,7 @@ var FileRenderer = class {
|
|
|
91
112
|
}
|
|
92
113
|
clearRenderCache() {
|
|
93
114
|
this.syncEditedContentsToFile();
|
|
115
|
+
this.pendingStructuralRows = void 0;
|
|
94
116
|
const renderCache = this.renderCache;
|
|
95
117
|
this.renderCache = void 0;
|
|
96
118
|
if (renderCache != null && renderCache.isDirty === true && renderCache.file.cacheKey != null) this.workerManager?.evictFileFromCache(renderCache.file.cacheKey);
|
|
@@ -107,20 +129,30 @@ var FileRenderer = class {
|
|
|
107
129
|
result: massiveFile ? void 0 : cache?.result,
|
|
108
130
|
renderRange: void 0
|
|
109
131
|
};
|
|
110
|
-
if (this.workerManager?.isWorkingPool() === true) {
|
|
132
|
+
if (!this.editSessionActive && this.workerManager?.isWorkingPool() === true) {
|
|
111
133
|
if (this.renderCache.result == null && !massiveFile) this.workerManager.highlightFileAST(this, file);
|
|
112
134
|
} else if (this.highlighter == null) {
|
|
113
135
|
this.computedLang = file.lang ?? getFiletypeFromFileName(file.name);
|
|
114
136
|
this.initializeHighlighter();
|
|
115
137
|
}
|
|
116
138
|
}
|
|
139
|
+
getLocalHighlightTheme() {
|
|
140
|
+
return this.workerManager?.getFileRenderOptions().theme ?? this.options.theme ?? DEFAULT_THEMES;
|
|
141
|
+
}
|
|
117
142
|
getRenderOptions(file) {
|
|
118
143
|
const options = (() => {
|
|
119
|
-
if (this.workerManager?.isWorkingPool() === true)
|
|
120
|
-
|
|
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;
|
|
121
153
|
return {
|
|
122
|
-
theme,
|
|
123
|
-
useTokenTransformer:
|
|
154
|
+
theme: this.getLocalHighlightTheme(),
|
|
155
|
+
useTokenTransformer: this.editSessionActive || this.options.useTokenTransformer === true,
|
|
124
156
|
tokenizeMaxLineLength
|
|
125
157
|
};
|
|
126
158
|
})();
|
|
@@ -154,17 +186,20 @@ var FileRenderer = class {
|
|
|
154
186
|
const lines = this.getOrCreateLineCache(file);
|
|
155
187
|
return this.textDocumentCache.get(file)?.lineCount ?? lines.length;
|
|
156
188
|
}
|
|
157
|
-
updateRenderCache(dirtyLines, themeType) {
|
|
189
|
+
updateRenderCache(dirtyLines, themeType, lineCountChangeInFlight = false) {
|
|
190
|
+
this.pendingStructuralRows = void 0;
|
|
158
191
|
if (this.renderCache == null) return;
|
|
159
192
|
const { file, result } = this.renderCache;
|
|
160
193
|
if (result == null) return;
|
|
194
|
+
const pendingStructuralRows = lineCountChangeInFlight ? /* @__PURE__ */ new Map() : void 0;
|
|
195
|
+
this.pendingStructuralRows = pendingStructuralRows;
|
|
161
196
|
const lineCache = this.lineCache != null && isLineCacheForFile(this.lineCache, file) ? this.lineCache : void 0;
|
|
162
197
|
for (const [line, tokens] of dirtyLines) {
|
|
163
|
-
if (lineCache != null && line < lineCache.lines.length) {
|
|
198
|
+
if (pendingStructuralRows === void 0 && lineCache != null && line < lineCache.lines.length) {
|
|
164
199
|
const lineText = tokens.map((token) => token[2]).join("");
|
|
165
200
|
lineCache.lines[line] = applyLineTextWithNewline(lineCache.lines[line] ?? "", lineText);
|
|
166
201
|
}
|
|
167
|
-
|
|
202
|
+
const row = {
|
|
168
203
|
type: "element",
|
|
169
204
|
tagName: "div",
|
|
170
205
|
properties: {
|
|
@@ -199,17 +234,34 @@ var FileRenderer = class {
|
|
|
199
234
|
};
|
|
200
235
|
})
|
|
201
236
|
};
|
|
237
|
+
if (pendingStructuralRows !== void 0) pendingStructuralRows.set(line, row);
|
|
238
|
+
else result.code[line] = row;
|
|
202
239
|
}
|
|
203
240
|
result.baseThemeType = themeType;
|
|
204
241
|
this.renderCache.isDirty = true;
|
|
205
242
|
}
|
|
206
243
|
applyDocumentChange(textDocument) {
|
|
244
|
+
const pendingStructuralRows = this.pendingStructuralRows;
|
|
245
|
+
this.pendingStructuralRows = void 0;
|
|
207
246
|
if (this.renderCache == null) return;
|
|
208
247
|
const { file, result } = this.renderCache;
|
|
209
248
|
if (result == null) return;
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
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] ??= {
|
|
213
265
|
type: "element",
|
|
214
266
|
tagName: "div",
|
|
215
267
|
properties: {
|
|
@@ -226,14 +278,21 @@ var FileRenderer = class {
|
|
|
226
278
|
value: textDocument.getLineText(i)
|
|
227
279
|
}]
|
|
228
280
|
}]
|
|
229
|
-
}
|
|
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
|
+
}
|
|
230
289
|
this.renderCache.isDirty = true;
|
|
231
290
|
}
|
|
232
291
|
this.lineCache = {
|
|
233
292
|
cacheKey: file.cacheKey,
|
|
234
293
|
file,
|
|
235
294
|
sourceContents: file.contents,
|
|
236
|
-
lines:
|
|
295
|
+
lines: nextLines
|
|
237
296
|
};
|
|
238
297
|
this.textDocumentCache.set(file, textDocument);
|
|
239
298
|
}
|
|
@@ -246,6 +305,7 @@ var FileRenderer = class {
|
|
|
246
305
|
this.textDocumentCache = /* @__PURE__ */ new WeakMap();
|
|
247
306
|
}
|
|
248
307
|
let { options, forceHighlight } = this.getRenderOptions(file);
|
|
308
|
+
if (this.renderCache?.isDirty === true && !areFileRenderOptionsEqual(options, this.renderCache.options)) this.clearRenderCache();
|
|
249
309
|
const cache = this.getMatchingWorkerResultCache(file, options);
|
|
250
310
|
if (cache != null && !this.hasHighlightedRenderCache(file, options)) {
|
|
251
311
|
this.renderCache = {
|
|
@@ -268,7 +328,7 @@ var FileRenderer = class {
|
|
|
268
328
|
const forcePlainText = !hasContent || isFilePlainText(file) || isFileMassive(lines.length, this.getTokenizeMaxLength());
|
|
269
329
|
const newContent = !areFilesEqual(file, this.renderCache.file);
|
|
270
330
|
const newRenderRange = !areRenderRangesEqual(this.renderCache.renderRange, renderRange);
|
|
271
|
-
if (this.workerManager?.isWorkingPool() === true) {
|
|
331
|
+
if (!this.editSessionActive && this.workerManager?.isWorkingPool() === true) {
|
|
272
332
|
if (forcePlainText || this.renderCache.result == null || !this.renderCache.highlighted && (newContent || newRenderRange)) {
|
|
273
333
|
this.renderCache.file = file;
|
|
274
334
|
this.renderCache.options = options;
|
|
@@ -294,7 +354,7 @@ var FileRenderer = class {
|
|
|
294
354
|
}
|
|
295
355
|
if (!hasThemes || !forcePlainText && !hasLangs) this.asyncHighlight(file).then(({ result, options }) => {
|
|
296
356
|
if (this.renderCache != null) this.renderCache.highlighted = false;
|
|
297
|
-
this.
|
|
357
|
+
this.applyHighlightResult(file, result, options, !forcePlainText);
|
|
298
358
|
});
|
|
299
359
|
}
|
|
300
360
|
return this.renderCache.result != null ? this.processFileResult(this.renderCache.file, renderRange, this.renderCache.result) : void 0;
|
|
@@ -306,7 +366,7 @@ var FileRenderer = class {
|
|
|
306
366
|
async asyncHighlight(file) {
|
|
307
367
|
const forcePlainText = isFileMassive(this.getOrCreateLineCache(file).length, this.getTokenizeMaxLength());
|
|
308
368
|
this.computedLang = forcePlainText ? "text" : file.lang ?? getFiletypeFromFileName(file.name);
|
|
309
|
-
const hasThemes = this.highlighter != null && hasResolvedThemes(getThemes(this.
|
|
369
|
+
const hasThemes = this.highlighter != null && hasResolvedThemes(getThemes(this.getLocalHighlightTheme()));
|
|
310
370
|
const hasLangs = forcePlainText || this.highlighter != null && areLanguagesAttached(this.computedLang);
|
|
311
371
|
if (this.highlighter == null || !hasThemes || !hasLangs) this.highlighter = await this.initializeHighlighter();
|
|
312
372
|
return this.renderFileWithHighlighter(file, this.highlighter, forcePlainText);
|
|
@@ -415,10 +475,17 @@ var FileRenderer = class {
|
|
|
415
475
|
}));
|
|
416
476
|
}
|
|
417
477
|
async initializeHighlighter() {
|
|
418
|
-
this.highlighter = await getSharedHighlighter(getHighlighterOptions(this.computedLang,
|
|
478
|
+
this.highlighter = await getSharedHighlighter(getHighlighterOptions(this.computedLang, {
|
|
479
|
+
theme: this.getLocalHighlightTheme(),
|
|
480
|
+
preferredHighlighter: this.workerManager?.getPreferredHighlighter() ?? this.options.preferredHighlighter
|
|
481
|
+
}));
|
|
419
482
|
return this.highlighter;
|
|
420
483
|
}
|
|
421
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) {
|
|
422
489
|
if (this.renderCache == null) return;
|
|
423
490
|
const triggerRenderUpdate = !areFilesEqual(file, this.renderCache.file) || !this.renderCache.highlighted || !areFileRenderOptionsEqual(options, this.renderCache.options);
|
|
424
491
|
this.renderCache = {
|
|
@@ -431,6 +498,7 @@ var FileRenderer = class {
|
|
|
431
498
|
if (triggerRenderUpdate) this.onRenderUpdate?.();
|
|
432
499
|
}
|
|
433
500
|
getMatchingWorkerResultCache(file, options) {
|
|
501
|
+
if (this.editSessionActive) return;
|
|
434
502
|
const cache = this.workerManager?.getFileResultCache(file);
|
|
435
503
|
if (cache == null || !areFileRenderOptionsEqual(options, cache.options)) return;
|
|
436
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 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 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.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 // 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 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 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 ): 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 && isLineCacheForFile(this.lineCache, file)\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: `color:${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 this.lineCache = {\n cacheKey: file.cacheKey,\n file,\n sourceContents: file.contents,\n lines: linesFromFileContents(textDocument.getText()),\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 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,SAAS,mBAAmB,WAAsB,MAA6B;CAC7E,OAAO,KAAK,YAAY,OACpB,UAAU,SAAS,QAAQ,UAAU,mBAAmB,KAAK,WAC7D,UAAU,aAAa,KAAK;AAClC;AAMA,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;E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,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;AAEjB,IAAa,eAAb,MAAmD;CAmB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F,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"}
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
import { DIFFS_TAG_NAME } from "../constants.js";
|
|
3
3
|
import { getLineAnnotationName } from "../utils/getLineAnnotationName.js";
|
|
4
4
|
import { useEffect, useRef } from "react";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
6
|
import { hydrateRoot } from "react-dom/client";
|
|
6
7
|
import { renderToString } from "react-dom/server";
|
|
7
|
-
import { jsx } from "react/jsx-runtime";
|
|
8
8
|
//#region src/ssr/FileDiffReact.tsx
|
|
9
9
|
function escapeHtml(unsafe) {
|
|
10
10
|
return unsafe.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preloadDiffs.d.ts","names":[],"sources":["../../src/ssr/preloadDiffs.ts"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"preloadDiffs.d.ts","names":[],"sources":["../../src/ssr/preloadDiffs.ts"],"mappings":";;;;;UA8BU,sBAAA;EACR,OAAA,GAAU,eAAA,CAAgB,WAAA;EAC1B,WAAA,GAAc,kBAAA,CAAmB,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BAAA;EACpB,IAAA;EACA,OAAA;EACA;AAAA,GACC,4BAAA,CAA6B,WAAA,IAAe,OAAA,CAC7C,2BAAA,CAA4B,WAAA;AAAA,UAcb,uBAAA;EACf,KAAA;EACA,OAAA,GAAU,eAAA,CAAgB,WAAA;EAC1B,WAAA,GAAc,kBAAA,CAAmB,WAAA;AAAA;AAAA,UAGlB,sBAAA,sBAEP,uBAAuB,CAAC,WAAA;EAChC,eAAA;AAAA;AAAA,iBAGoB,gBAAA;EACpB,KAAA;EACA,OAAA;EACA;AAAA,GACC,uBAAA,CAAwB,WAAA,IAAe,OAAA,CACxC,sBAAA,CAAuB,WAAA"}
|
package/dist/ssr/preloadDiffs.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { parseDiffFromFile } from "../utils/parseDiffFromFile.js";
|
|
2
2
|
import { wrapThemeCSS } from "../utils/cssWrappers.js";
|
|
3
|
+
import { shouldUseTokenTransformer } from "../utils/shouldUseTokenTransformer.js";
|
|
3
4
|
import { getDiffFileInput } from "../utils/getDiffFileInput.js";
|
|
4
5
|
import { DiffHunksRenderer } from "../renderers/DiffHunksRenderer.js";
|
|
5
6
|
import { parseMergeConflictDiffFromFile } from "../utils/parseMergeConflictDiffFromFile.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":"
|
|
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;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;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":";;;;
|
|
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"}
|
package/dist/ssr/preloadFile.js
CHANGED
|
@@ -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);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preloadFile.js","names":[],"sources":["../../src/ssr/preloadFile.ts"],"sourcesContent":["import type { FileOptions } from '../components/File';\nimport { FileRenderer } from '../renderers/FileRenderer';\nimport type { FileContents, LineAnnotation } from '../types';\nimport {\n createStyleElement,\n createThemeStyleElement,\n} from '../utils/createStyleElement';\nimport { wrapThemeCSS } from '../utils/cssWrappers';\nimport { renderHTML } from './renderHTML';\n\nexport type PreloadFileOptions<LAnnotation> = {\n file: FileContents;\n options?: FileOptions<LAnnotation>;\n annotations?: LineAnnotation<LAnnotation>[];\n};\n\nexport interface PreloadedFileResult<LAnnotation> {\n file: FileContents;\n options?: FileOptions<LAnnotation>;\n annotations?: LineAnnotation<LAnnotation>[];\n prerenderedHTML: string;\n}\n\nexport async function preloadFile<LAnnotation = undefined>({\n file,\n options,\n annotations,\n}: PreloadFileOptions<LAnnotation>): Promise<PreloadedFileResult<LAnnotation>> {\n const fileRenderer = new FileRenderer<LAnnotation>({\n ...options,\n headerRenderMode:\n options?.renderCustomHeader != null ? 'custom' : 'default',\n });\n\n // Set line annotations if provided\n if (annotations !== undefined && annotations.length > 0) {\n fileRenderer.setLineAnnotations(annotations);\n }\n\n const fileResult = await fileRenderer.asyncRender(file);\n const children = [createStyleElement(fileResult.css, true)];\n\n children.push(\n createThemeStyleElement(\n wrapThemeCSS(\n fileResult.themeStyles,\n fileResult.baseThemeType ?? options?.themeType ?? 'system'\n )\n )\n );\n\n if (options?.unsafeCSS != null) {\n children.push(createStyleElement(options.unsafeCSS));\n }\n\n if (fileResult.headerAST != null) {\n children.push(fileResult.headerAST);\n }\n const code = fileRenderer.renderFullAST(fileResult);\n code.properties['data-dehydrated'] = '';\n children.push(code);\n\n return {\n file,\n options,\n annotations,\n prerenderedHTML: renderHTML(children),\n };\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"preloadFile.js","names":[],"sources":["../../src/ssr/preloadFile.ts"],"sourcesContent":["import type { FileOptions } from '../components/File';\nimport { FileRenderer } from '../renderers/FileRenderer';\nimport type { FileContents, LineAnnotation } from '../types';\nimport {\n createStyleElement,\n createThemeStyleElement,\n} from '../utils/createStyleElement';\nimport { wrapThemeCSS } from '../utils/cssWrappers';\nimport { shouldUseTokenTransformer } from '../utils/shouldUseTokenTransformer';\nimport { renderHTML } from './renderHTML';\n\nexport type PreloadFileOptions<LAnnotation> = {\n file: FileContents;\n options?: FileOptions<LAnnotation>;\n annotations?: LineAnnotation<LAnnotation>[];\n};\n\nexport interface PreloadedFileResult<LAnnotation> {\n file: FileContents;\n options?: FileOptions<LAnnotation>;\n annotations?: LineAnnotation<LAnnotation>[];\n prerenderedHTML: string;\n}\n\nexport async function preloadFile<LAnnotation = undefined>({\n file,\n options,\n annotations,\n}: PreloadFileOptions<LAnnotation>): Promise<PreloadedFileResult<LAnnotation>> {\n const fileRenderer = new FileRenderer<LAnnotation>({\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(options),\n headerRenderMode:\n options?.renderCustomHeader != null ? 'custom' : 'default',\n });\n\n // Set line annotations if provided\n if (annotations !== undefined && annotations.length > 0) {\n fileRenderer.setLineAnnotations(annotations);\n }\n\n const fileResult = await fileRenderer.asyncRender(file);\n const children = [createStyleElement(fileResult.css, true)];\n\n children.push(\n createThemeStyleElement(\n wrapThemeCSS(\n fileResult.themeStyles,\n fileResult.baseThemeType ?? options?.themeType ?? 'system'\n )\n )\n );\n\n if (options?.unsafeCSS != null) {\n children.push(createStyleElement(options.unsafeCSS));\n }\n\n if (fileResult.headerAST != null) {\n children.push(fileResult.headerAST);\n }\n const code = fileRenderer.renderFullAST(fileResult);\n code.properties['data-dehydrated'] = '';\n children.push(code);\n\n return {\n file,\n options,\n annotations,\n prerenderedHTML: renderHTML(children),\n };\n}\n"],"mappings":";;;;;;AAwBA,eAAsB,YAAqC,EACzD,MACA,SACA,eAC6E;CAC7E,MAAM,eAAe,IAAI,aAA0B;EACjD,GAAG;EAGH,qBAAqB,0BAA0B,OAAO;EACtD,kBACE,SAAS,sBAAsB,OAAO,WAAW;CACrD,CAAC;CAGD,IAAI,gBAAgB,KAAA,KAAa,YAAY,SAAS,GACpD,aAAa,mBAAmB,WAAW;CAG7C,MAAM,aAAa,MAAM,aAAa,YAAY,IAAI;CACtD,MAAM,WAAW,CAAC,mBAAmB,WAAW,KAAK,IAAI,CAAC;CAE1D,SAAS,KACP,wBACE,aACE,WAAW,aACX,WAAW,iBAAiB,SAAS,aAAa,QACpD,CACF,CACF;CAEA,IAAI,SAAS,aAAa,MACxB,SAAS,KAAK,mBAAmB,QAAQ,SAAS,CAAC;CAGrD,IAAI,WAAW,aAAa,MAC1B,SAAS,KAAK,WAAW,SAAS;CAEpC,MAAM,OAAO,aAAa,cAAc,UAAU;CAClD,KAAK,WAAW,qBAAqB;CACrC,SAAS,KAAK,IAAI;CAElB,OAAO;EACL;EACA;EACA;EACA,iBAAiB,WAAW,QAAQ;CACtC;AACF"}
|
package/dist/types.d.ts
CHANGED
|
@@ -855,12 +855,19 @@ interface DiffsEditableComponent<LAnnotation> extends DiffsBaseComponent {
|
|
|
855
855
|
*/
|
|
856
856
|
attachEditor: (editor: DiffsEditor<LAnnotation>) => (recycle?: boolean) => void;
|
|
857
857
|
applyDocumentChange: (textDocument: DiffsTextDocument, newLineAnnotations?: DiffLineAnnotation<LAnnotation>[], shouldUpdateBuffer?: boolean) => void;
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
858
|
+
updateRenderCache: (lines: Map<number, Array<HighlightedToken>>, themeType: 'dark' | 'light', options?: {
|
|
859
|
+
/**
|
|
860
|
+
* Whether to refresh the diffs view.
|
|
861
|
+
* Deferred background-tokenize passes always pass false.
|
|
862
|
+
*/
|
|
863
|
+
shouldRefreshDiffsView?: boolean;
|
|
864
|
+
/**
|
|
865
|
+
* Whether the line count has changed in flight.
|
|
866
|
+
* True only during an edit pass whose line count changed,
|
|
867
|
+
* deferred background-tokenize passes always pass false.
|
|
868
|
+
*/
|
|
869
|
+
lineCountChangeInFlight?: boolean;
|
|
870
|
+
}) => void;
|
|
864
871
|
}
|
|
865
872
|
type EditableInstance<T extends {
|
|
866
873
|
type: string;
|