@pierre/diffs 1.0.7 → 1.1.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/dist/components/File.d.ts +4 -2
  2. package/dist/components/File.d.ts.map +1 -1
  3. package/dist/components/File.js +80 -34
  4. package/dist/components/File.js.map +1 -1
  5. package/dist/components/FileDiff.d.ts +50 -28
  6. package/dist/components/FileDiff.d.ts.map +1 -1
  7. package/dist/components/FileDiff.js +220 -79
  8. package/dist/components/FileDiff.js.map +1 -1
  9. package/dist/components/FileStream.d.ts +1 -0
  10. package/dist/components/FileStream.d.ts.map +1 -1
  11. package/dist/components/FileStream.js +8 -4
  12. package/dist/components/FileStream.js.map +1 -1
  13. package/dist/constants.d.ts +8 -2
  14. package/dist/constants.d.ts.map +1 -1
  15. package/dist/constants.js +10 -1
  16. package/dist/constants.js.map +1 -1
  17. package/dist/index.d.ts +19 -10
  18. package/dist/index.js +14 -5
  19. package/dist/managers/LineSelectionManager.d.ts.map +1 -1
  20. package/dist/managers/LineSelectionManager.js +8 -9
  21. package/dist/managers/LineSelectionManager.js.map +1 -1
  22. package/dist/react/MultiFileDiff.js +2 -2
  23. package/dist/react/MultiFileDiff.js.map +1 -1
  24. package/dist/react/index.d.ts +2 -2
  25. package/dist/react/utils/renderDiffChildren.d.ts +4 -4
  26. package/dist/react/utils/renderDiffChildren.d.ts.map +1 -1
  27. package/dist/react/utils/renderDiffChildren.js +3 -3
  28. package/dist/react/utils/renderDiffChildren.js.map +1 -1
  29. package/dist/react/utils/useFileDiffInstance.js.map +1 -1
  30. package/dist/renderers/DiffHunksRenderer.d.ts +7 -6
  31. package/dist/renderers/DiffHunksRenderer.d.ts.map +1 -1
  32. package/dist/renderers/DiffHunksRenderer.js +263 -337
  33. package/dist/renderers/DiffHunksRenderer.js.map +1 -1
  34. package/dist/renderers/FileRenderer.d.ts +1 -0
  35. package/dist/renderers/FileRenderer.d.ts.map +1 -1
  36. package/dist/renderers/FileRenderer.js +11 -4
  37. package/dist/renderers/FileRenderer.js.map +1 -1
  38. package/dist/ssr/index.d.ts +2 -2
  39. package/dist/style.js +1 -1
  40. package/dist/style.js.map +1 -1
  41. package/dist/types.d.ts +246 -42
  42. package/dist/types.d.ts.map +1 -1
  43. package/dist/utils/areDiffLineAnnotationsEqual.d.ts +7 -0
  44. package/dist/utils/areDiffLineAnnotationsEqual.d.ts.map +1 -0
  45. package/dist/utils/areDiffLineAnnotationsEqual.js +8 -0
  46. package/dist/utils/areDiffLineAnnotationsEqual.js.map +1 -0
  47. package/dist/utils/areHunkDataEqual.d.ts +7 -0
  48. package/dist/utils/areHunkDataEqual.d.ts.map +1 -0
  49. package/dist/utils/areHunkDataEqual.js +8 -0
  50. package/dist/utils/areHunkDataEqual.js.map +1 -0
  51. package/dist/utils/areLineAnnotationsEqual.d.ts +7 -0
  52. package/dist/utils/areLineAnnotationsEqual.d.ts.map +1 -0
  53. package/dist/utils/areLineAnnotationsEqual.js +8 -0
  54. package/dist/utils/areLineAnnotationsEqual.js.map +1 -0
  55. package/dist/utils/arePrePropertiesEqual.d.ts +7 -0
  56. package/dist/utils/arePrePropertiesEqual.d.ts.map +1 -0
  57. package/dist/utils/arePrePropertiesEqual.js +9 -0
  58. package/dist/utils/arePrePropertiesEqual.js.map +1 -0
  59. package/dist/utils/areRenderRangesEqual.d.ts +7 -0
  60. package/dist/utils/areRenderRangesEqual.d.ts.map +1 -0
  61. package/dist/utils/areRenderRangesEqual.js +9 -0
  62. package/dist/utils/areRenderRangesEqual.js.map +1 -0
  63. package/dist/utils/areVirtualWindowSpecsEqual.d.ts +7 -0
  64. package/dist/utils/areVirtualWindowSpecsEqual.d.ts.map +1 -0
  65. package/dist/utils/areVirtualWindowSpecsEqual.js +9 -0
  66. package/dist/utils/areVirtualWindowSpecsEqual.js.map +1 -0
  67. package/dist/utils/areWorkerStatsEqual.d.ts +8 -0
  68. package/dist/utils/areWorkerStatsEqual.d.ts.map +1 -0
  69. package/dist/utils/areWorkerStatsEqual.js +9 -0
  70. package/dist/utils/areWorkerStatsEqual.js.map +1 -0
  71. package/dist/utils/createTransformerWithState.js +1 -1
  72. package/dist/utils/createTransformerWithState.js.map +1 -1
  73. package/dist/utils/createWindowFromScrollPosition.d.ts +22 -0
  74. package/dist/utils/createWindowFromScrollPosition.d.ts.map +1 -0
  75. package/dist/utils/createWindowFromScrollPosition.js +26 -0
  76. package/dist/utils/createWindowFromScrollPosition.js.map +1 -0
  77. package/dist/utils/diffAcceptRejectHunk.js +36 -21
  78. package/dist/utils/diffAcceptRejectHunk.js.map +1 -1
  79. package/dist/utils/getOrCreateCodeNode.d.ts +14 -0
  80. package/dist/utils/getOrCreateCodeNode.d.ts.map +1 -0
  81. package/dist/utils/getOrCreateCodeNode.js +13 -0
  82. package/dist/utils/getOrCreateCodeNode.js.map +1 -0
  83. package/dist/utils/getTotalLineCountFromHunks.js +1 -1
  84. package/dist/utils/getTotalLineCountFromHunks.js.map +1 -1
  85. package/dist/utils/hast_utils.d.ts +2 -1
  86. package/dist/utils/hast_utils.d.ts.map +1 -1
  87. package/dist/utils/hast_utils.js +10 -1
  88. package/dist/utils/hast_utils.js.map +1 -1
  89. package/dist/utils/isDefaultRenderRange.d.ts +7 -0
  90. package/dist/utils/isDefaultRenderRange.d.ts.map +1 -0
  91. package/dist/utils/isDefaultRenderRange.js +8 -0
  92. package/dist/utils/isDefaultRenderRange.js.map +1 -0
  93. package/dist/utils/iterateOverDiff.d.ts +39 -0
  94. package/dist/utils/iterateOverDiff.d.ts.map +1 -0
  95. package/dist/utils/iterateOverDiff.js +356 -0
  96. package/dist/utils/iterateOverDiff.js.map +1 -0
  97. package/dist/utils/parseDiffFromFile.d.ts.map +1 -1
  98. package/dist/utils/parseDiffFromFile.js +8 -6
  99. package/dist/utils/parseDiffFromFile.js.map +1 -1
  100. package/dist/utils/parsePatchFiles.d.ts +15 -3
  101. package/dist/utils/parsePatchFiles.d.ts.map +1 -1
  102. package/dist/utils/parsePatchFiles.js +207 -158
  103. package/dist/utils/parsePatchFiles.js.map +1 -1
  104. package/dist/utils/processLine.js +4 -3
  105. package/dist/utils/processLine.js.map +1 -1
  106. package/dist/utils/renderDiffWithHighlighter.d.ts +7 -2
  107. package/dist/utils/renderDiffWithHighlighter.d.ts.map +1 -1
  108. package/dist/utils/renderDiffWithHighlighter.js +149 -227
  109. package/dist/utils/renderDiffWithHighlighter.js.map +1 -1
  110. package/dist/utils/setWrapperNodeProps.d.ts +3 -7
  111. package/dist/utils/setWrapperNodeProps.d.ts.map +1 -1
  112. package/dist/utils/setWrapperNodeProps.js +1 -1
  113. package/dist/utils/setWrapperNodeProps.js.map +1 -1
  114. package/dist/worker/WorkerPoolManager.d.ts +9 -2
  115. package/dist/worker/WorkerPoolManager.d.ts.map +1 -1
  116. package/dist/worker/WorkerPoolManager.js +124 -45
  117. package/dist/worker/WorkerPoolManager.js.map +1 -1
  118. package/dist/worker/types.d.ts +7 -0
  119. package/dist/worker/types.d.ts.map +1 -1
  120. package/dist/worker/worker-portable.js +634 -242
  121. package/dist/worker/worker-portable.js.map +1 -1
  122. package/dist/worker/worker.js +511 -231
  123. package/dist/worker/worker.js.map +1 -1
  124. package/package.json +20 -1
  125. package/dist/utils/createCodeNode.d.ts +0 -12
  126. package/dist/utils/createCodeNode.d.ts.map +0 -1
  127. package/dist/utils/createCodeNode.js +0 -12
  128. package/dist/utils/createCodeNode.js.map +0 -1
@@ -27,7 +27,7 @@ declare class File<LAnnotation = undefined> {
27
27
  private workerManager?;
28
28
  private isContainerManaged;
29
29
  static LoadedCustomComponent: boolean;
30
- readonly __id: number;
30
+ readonly __id: string;
31
31
  private fileContainer;
32
32
  private spriteSVG;
33
33
  private pre;
@@ -35,13 +35,15 @@ declare class File<LAnnotation = undefined> {
35
35
  private unsafeCSSStyle;
36
36
  private hoverContent;
37
37
  private errorWrapper;
38
+ private lastRenderedHeaderHTML;
39
+ private appliedPreAttributes;
38
40
  private headerElement;
39
41
  private headerMetadata;
40
42
  private fileRenderer;
41
43
  private resizeManager;
42
44
  private mouseEventManager;
43
45
  private lineSelectionManager;
44
- private annotationElements;
46
+ private annotationCache;
45
47
  private lineAnnotations;
46
48
  private file;
47
49
  constructor(options?: FileOptions<LAnnotation>, workerManager?: WorkerPoolManager | undefined, isContainerManaged?: boolean);
@@ -1 +1 @@
1
- {"version":3,"file":"File.d.ts","names":["options: FileOptions<LAnnotation>","workerManager?: WorkerPoolManager | undefined"],"sources":["../../src/components/File.ts"],"sourcesContent":[],"mappings":";;;;;;;UA2CiB;QACT;kBACU;EAFlB,gBAAiB,CAAA,EAGI,WAHJ;EACT,WAAA,CAAA,EAAA,OAAA;EACU,eAAA,CAAA,EAGE,cAHF,CAGiB,WAHjB,CAAA,EAAA;;AAGiB,UAGlB,gBAHkB,CAAA,WAAA,CAAA,SAIzB,IAJyB,CAIpB,eAJoB,CAIJ,WAJI,CAAA,EAAA,eAAA,CAAA,CAAA;EAAf,aAAA,EAKH,WALG;EAAA,eAAA,CAAA,EAAA,MAAA;AAGpB;AAC+B,UAKd,WALc,CAAA,WAAA,CAAA,SAMrB,eANqB,EAO3B,4BAP2B,CAAA,MAAA,CAAA,EAQ3B,oBAR2B,CAAA;EAAhB,iBAAA,CAAA,EAAA,OAAA;EACE,oBAAA,CAAA,EASQ,kBATR;EADP,gBAAA,EAAA,UAAA,EAYM,cAZN,CAYqB,WAZrB,CAAA,CAAA,EAaL,WAbK,GAAA,SAAA;EAAA,kBAAA,EAAA,aAAA,EAAA,GAAA,GAee,oBAff,CAAA,MAAA,CAAA,GAAA,SAAA,CAAA,EAgBL,WAhBK,GAAA,IAAA;AAKV;AAKyB,cAWZ,IAXY,CAAA,cAAA,SAAA,CAAA,CAAA;EAEM,OAAA,EAmCX,WAnCW,CAmCC,WAnCD,CAAA;EAAf,QAAA,aAAA;EACX,QAAA,kBAAA;EAEoB,OAAA,qBAAA,EAAA,OAAA;EACpB,SAAA,IAAA,EAAA,MAAA;EAVK,QAAA,aAAA;EACN,QAAA,SAAA;EACA,QAAA,GAAA;EAAA,QAAA,IAAA;EAaJ,QAAa,cAAA;EA0BmB,QAAA,YAAA;EAAZ,QAAA,YAAA;EAAY,QAAA,aAAA;EAAZ,QAAA,cAAA;EACQ,QAAA,YAAA;EA4BM,QAAA,aAAA;EAAZ,QAAA,iBAAA;EAWI,QAAA,oBAAA;EA8BH,QAAA,kBAAA;EAI8B,QAAA,eAAA;EAAf,QAAA,IAAA;EAIZ,WAAA,CAAA,OAAA,CAAA,EA9EN,WA8EM,CA9EM,WA8EN,CAAA,EAAA,aAAA,CAAA,EA7EE,iBA6EF,GAAA,SAAA,EAAA,kBAAA,CAAA,EAAA,OAAA;EA6BQ,QAAA,qBAAA;EAAjB,QAAA,CAAA,CAAA,EAAA,IAAA;EAsDb,UAAA,CAAA,OAAA,EApIkB,WAoIlB,CApI8B,WAoI9B,CAAA,GAAA,SAAA,CAAA,EAAA,IAAA;EACA,QAAA,YAAA;EACA,YAAA,CAAA,SAAA,EA3HsB,UA2HtB,CAAA,EAAA,IAAA;EACA,cAAA,EAAA,GAAA,GA9FmB,oBA8FnB,CAAA,MAAA,CAAA,GAAA,SAAA;EACA,kBAAA,CAAA,eAAA,EA3FkC,cA2FlC,CA3FiD,WA2FjD,CAAA,EAAA,CAAA,EAAA,IAAA;EACiB,gBAAA,CAAA,KAAA,EAxFK,iBAwFL,GAAA,IAAA,CAAA,EAAA,IAAA;EAAhB,OAAA,CAAA,CAAA,EAAA,IAAA;EAAA,OAAA,CAAA,KAAA,EA3DY,gBA2DZ,CA3D6B,WA2D7B,CAAA,CAAA,EAAA,IAAA;;;;;;;KAAA,gBAAgB"}
1
+ {"version":3,"file":"File.d.ts","names":["options: FileOptions<LAnnotation>","workerManager?: WorkerPoolManager | undefined"],"sources":["../../src/components/File.ts"],"sourcesContent":[],"mappings":";;;;;;;UA8CiB;QACT;kBACU;EAFlB,gBAAiB,CAAA,EAGI,WAHJ;EACT,WAAA,CAAA,EAAA,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AA,EA5GW,iBA4GX,GAAA,SAAA,EAAA,kBAAA,CAAA,EAAA,OAAA;EAwDb,QAAA,qBAAA;EACA,QAAA,CAAA,CAAA,EAAA,IAAA;EACA,UAAA,CAAA,OAAA,EA1IkB,WA0IlB,CA1I8B,WA0I9B,CAAA,GAAA,SAAA,CAAA,EAAA,IAAA;EACA,QAAA,YAAA;EACA,YAAA,CAAA,SAAA,EAjIsB,UAiItB,CAAA,EAAA,IAAA;EACiB,cAAA,EAAA,GAAA,GApGE,oBAoGF,CAAA,MAAA,CAAA,GAAA,SAAA;EAAhB,kBAAA,CAAA,eAAA,EAhGiC,cAgGjC,CAhGgD,WAgGhD,CAAA,EAAA,CAAA,EAAA,IAAA;EAAA,gBAAA,CAAA,KAAA,EA5FqB,iBA4FrB,GAAA,IAAA,CAAA,EAAA,IAAA;;iBA7DY,iBAAiB;;;;;;;KA6D7B,gBAAgB"}
@@ -6,11 +6,13 @@ import { getLineAnnotationName } from "../utils/getLineAnnotationName.js";
6
6
  import { FileRenderer } from "../renderers/FileRenderer.js";
7
7
  import { SVGSpriteSheet } from "../sprite.js";
8
8
  import { areFilesEqual } from "../utils/areFilesEqual.js";
9
+ import { areLineAnnotationsEqual } from "../utils/areLineAnnotationsEqual.js";
10
+ import { arePrePropertiesEqual } from "../utils/arePrePropertiesEqual.js";
9
11
  import { createAnnotationWrapperNode } from "../utils/createAnnotationWrapperNode.js";
10
- import { createCodeNode } from "../utils/createCodeNode.js";
11
12
  import { createHoverContentNode } from "../utils/createHoverContentNode.js";
12
13
  import { createUnsafeCSSStyleNode } from "../utils/createUnsafeCSSStyleNode.js";
13
14
  import { wrapUnsafeCSS } from "../utils/cssWrappers.js";
15
+ import { getOrCreateCodeNode } from "../utils/getOrCreateCodeNode.js";
14
16
  import { prerenderHTMLIfNecessary } from "../utils/prerenderHTMLIfNecessary.js";
15
17
  import { setPreNodeProperties } from "../utils/setWrapperNodeProps.js";
16
18
  import { DiffsContainerLoaded } from "./web-components.js";
@@ -20,7 +22,7 @@ import { toHtml } from "hast-util-to-html";
20
22
  let instanceId = -1;
21
23
  var File = class {
22
24
  static LoadedCustomComponent = DiffsContainerLoaded;
23
- __id = ++instanceId;
25
+ __id = `file:${++instanceId}`;
24
26
  fileContainer;
25
27
  spriteSVG;
26
28
  pre;
@@ -28,13 +30,15 @@ var File = class {
28
30
  unsafeCSSStyle;
29
31
  hoverContent;
30
32
  errorWrapper;
33
+ lastRenderedHeaderHTML;
34
+ appliedPreAttributes;
31
35
  headerElement;
32
36
  headerMetadata;
33
37
  fileRenderer;
34
38
  resizeManager;
35
39
  mouseEventManager;
36
40
  lineSelectionManager;
37
- annotationElements = [];
41
+ annotationCache = /* @__PURE__ */ new Map();
38
42
  lineAnnotations = [];
39
43
  file;
40
44
  constructor(options = { theme: DEFAULT_THEMES }, workerManager, isContainerManaged = false) {
@@ -106,7 +110,9 @@ var File = class {
106
110
  if (this.fileContainer?.shadowRoot != null) this.fileContainer.shadowRoot.innerHTML = "";
107
111
  this.fileContainer = void 0;
108
112
  this.pre = void 0;
113
+ this.appliedPreAttributes = void 0;
109
114
  this.headerElement = void 0;
115
+ this.lastRenderedHeaderHTML = void 0;
110
116
  this.errorWrapper = void 0;
111
117
  this.unsafeCSSStyle = void 0;
112
118
  }
@@ -121,6 +127,7 @@ var File = class {
121
127
  if (!(element instanceof HTMLElement)) continue;
122
128
  if (element instanceof HTMLPreElement) {
123
129
  this.pre = element;
130
+ this.appliedPreAttributes = void 0;
124
131
  continue;
125
132
  }
126
133
  if (element instanceof HTMLStyleElement && element.hasAttribute(UNSAFE_CSS_ATTRIBUTE)) {
@@ -129,6 +136,7 @@ var File = class {
129
136
  }
130
137
  if ("diffsHeader" in element.dataset) {
131
138
  this.headerElement = element;
139
+ this.lastRenderedHeaderHTML = void 0;
132
140
  continue;
133
141
  }
134
142
  }
@@ -160,6 +168,7 @@ var File = class {
160
168
  if (this.headerElement != null) {
161
169
  this.headerElement.parentNode?.removeChild(this.headerElement);
162
170
  this.headerElement = void 0;
171
+ this.lastRenderedHeaderHTML = void 0;
163
172
  }
164
173
  }
165
174
  fileContainer = this.getOrCreateFileContainerNode(fileContainer, containerWrapper);
@@ -175,33 +184,55 @@ var File = class {
175
184
  this.renderAnnotations();
176
185
  this.renderHoverUtility();
177
186
  } catch (error) {
178
- if (error instanceof Error) this.applyErrorToDOM(error, fileContainer);
187
+ if (error instanceof Error) {
188
+ console.error(error);
189
+ this.applyErrorToDOM(error, fileContainer);
190
+ }
179
191
  }
180
192
  }
181
193
  renderAnnotations() {
182
- if (this.isContainerManaged || this.fileContainer == null) return;
183
- for (const element of this.annotationElements) element.parentNode?.removeChild(element);
184
- this.annotationElements.length = 0;
194
+ if (this.isContainerManaged || this.fileContainer == null) {
195
+ for (const { element } of this.annotationCache.values()) element.parentNode?.removeChild(element);
196
+ this.annotationCache.clear();
197
+ return;
198
+ }
199
+ const staleAnnotations = new Map(this.annotationCache);
185
200
  const { renderAnnotation } = this.options;
186
- if (renderAnnotation != null && this.lineAnnotations.length > 0) for (const annotation of this.lineAnnotations) {
187
- const content = renderAnnotation(annotation);
188
- if (content == null) continue;
189
- const el = createAnnotationWrapperNode(getLineAnnotationName(annotation));
190
- el.appendChild(content);
191
- this.annotationElements.push(el);
192
- this.fileContainer.appendChild(el);
201
+ if (renderAnnotation != null && this.lineAnnotations.length > 0) for (const [index, annotation] of this.lineAnnotations.entries()) {
202
+ const id = `${index}-${getLineAnnotationName(annotation)}`;
203
+ let cache = this.annotationCache.get(id);
204
+ if (cache == null || !areLineAnnotationsEqual(annotation, cache.annotation)) {
205
+ cache?.element.parentElement?.removeChild(cache.element);
206
+ const content = renderAnnotation(annotation);
207
+ if (content == null) continue;
208
+ cache = {
209
+ element: createAnnotationWrapperNode(getLineAnnotationName(annotation)),
210
+ annotation
211
+ };
212
+ cache.element.appendChild(content);
213
+ this.fileContainer.appendChild(cache.element);
214
+ this.annotationCache.set(id, cache);
215
+ }
216
+ staleAnnotations.delete(id);
217
+ }
218
+ for (const [id, { element }] of staleAnnotations.entries()) {
219
+ this.annotationCache.delete(id);
220
+ element.parentNode?.removeChild(element);
193
221
  }
194
222
  }
195
223
  renderHoverUtility() {
196
224
  const { renderHoverUtility } = this.options;
197
225
  if (this.fileContainer == null || renderHoverUtility == null) return;
198
- if (this.hoverContent == null) {
199
- this.hoverContent = createHoverContentNode();
200
- this.fileContainer.appendChild(this.hoverContent);
201
- }
202
226
  const element = renderHoverUtility(this.mouseEventManager.getHoveredLine);
203
- this.hoverContent.innerHTML = "";
204
- if (element != null) this.hoverContent.appendChild(element);
227
+ if (element != null && this.hoverContent != null) return;
228
+ else if (element == null) {
229
+ this.hoverContent?.parentNode?.removeChild(this.hoverContent);
230
+ this.hoverContent = void 0;
231
+ return;
232
+ }
233
+ this.hoverContent = createHoverContentNode();
234
+ this.hoverContent.appendChild(element);
235
+ this.fileContainer.appendChild(this.hoverContent);
205
236
  }
206
237
  injectUnsafeCSS() {
207
238
  if (this.fileContainer?.shadowRoot == null) return;
@@ -222,10 +253,9 @@ var File = class {
222
253
  applyHunksToDOM(result, pre) {
223
254
  this.cleanupErrorWrapper();
224
255
  this.applyPreNodeAttributes(pre, result);
225
- pre.innerHTML = "";
226
- this.code = createCodeNode();
256
+ this.code = getOrCreateCodeNode({ code: this.code });
227
257
  this.code.innerHTML = this.fileRenderer.renderPartialHTML(result.codeAST);
228
- pre.appendChild(this.code);
258
+ pre.replaceChildren(this.code);
229
259
  this.injectUnsafeCSS();
230
260
  this.mouseEventManager.setup(pre);
231
261
  this.lineSelectionManager.setup(pre);
@@ -237,13 +267,17 @@ var File = class {
237
267
  const { file } = this;
238
268
  if (file == null) return;
239
269
  this.cleanupErrorWrapper();
240
- const tempDiv = document.createElement("div");
241
- tempDiv.innerHTML = toHtml(headerAST);
242
- const newHeader = tempDiv.firstElementChild;
243
- if (!(newHeader instanceof HTMLElement)) return;
244
- if (this.headerElement != null) container.shadowRoot?.replaceChild(newHeader, this.headerElement);
245
- else container.shadowRoot?.prepend(newHeader);
246
- this.headerElement = newHeader;
270
+ const headerHTML = toHtml(headerAST);
271
+ if (headerHTML !== this.lastRenderedHeaderHTML) {
272
+ const tempDiv = document.createElement("div");
273
+ tempDiv.innerHTML = headerHTML;
274
+ const newHeader = tempDiv.firstElementChild;
275
+ if (!(newHeader instanceof HTMLElement)) return;
276
+ if (this.headerElement != null) container.shadowRoot?.replaceChild(newHeader, this.headerElement);
277
+ else container.shadowRoot?.prepend(newHeader);
278
+ this.headerElement = newHeader;
279
+ this.lastRenderedHeaderHTML = headerHTML;
280
+ }
247
281
  if (this.isContainerManaged) return;
248
282
  const { renderCustomMetadata } = this.options;
249
283
  if (this.headerMetadata != null) this.headerMetadata.parentNode?.removeChild(this.headerMetadata);
@@ -257,7 +291,12 @@ var File = class {
257
291
  }
258
292
  }
259
293
  getOrCreateFileContainerNode(fileContainer, parentNode) {
294
+ const previousContainer = this.fileContainer;
260
295
  this.fileContainer = fileContainer ?? this.fileContainer ?? document.createElement(DIFFS_TAG_NAME);
296
+ if (previousContainer != null && previousContainer !== this.fileContainer) {
297
+ this.lastRenderedHeaderHTML = void 0;
298
+ this.headerElement = void 0;
299
+ }
261
300
  if (parentNode != null && this.fileContainer.parentNode !== parentNode) parentNode.appendChild(this.fileContainer);
262
301
  if (this.spriteSVG == null) {
263
302
  const fragment = document.createElement("div");
@@ -274,13 +313,16 @@ var File = class {
274
313
  if (this.pre == null) {
275
314
  this.pre = document.createElement("pre");
276
315
  container.shadowRoot?.appendChild(this.pre);
277
- } else if (this.pre.parentNode !== container) container.shadowRoot?.appendChild(this.pre);
316
+ this.appliedPreAttributes = void 0;
317
+ } else if (this.pre.parentNode !== container) {
318
+ container.shadowRoot?.appendChild(this.pre);
319
+ this.appliedPreAttributes = void 0;
320
+ }
278
321
  return this.pre;
279
322
  }
280
323
  applyPreNodeAttributes(pre, { totalLines, themeStyles, baseThemeType }) {
281
324
  const { overflow = "scroll", themeType = "system", disableLineNumbers = false } = this.options;
282
- setPreNodeProperties({
283
- pre,
325
+ const preProperties = {
284
326
  split: false,
285
327
  themeStyles,
286
328
  overflow,
@@ -289,7 +331,10 @@ var File = class {
289
331
  diffIndicators: "none",
290
332
  disableBackground: true,
291
333
  totalLines
292
- });
334
+ };
335
+ if (arePrePropertiesEqual(preProperties, this.appliedPreAttributes)) return;
336
+ setPreNodeProperties(pre, preProperties);
337
+ this.appliedPreAttributes = preProperties;
293
338
  }
294
339
  applyErrorToDOM(error, container) {
295
340
  this.cleanupErrorWrapper();
@@ -297,6 +342,7 @@ var File = class {
297
342
  pre.innerHTML = "";
298
343
  pre.parentNode?.removeChild(pre);
299
344
  this.pre = void 0;
345
+ this.appliedPreAttributes = void 0;
300
346
  const shadowRoot = container.shadowRoot ?? container.attachShadow({ mode: "open" });
301
347
  this.errorWrapper ??= document.createElement("div");
302
348
  this.errorWrapper.dataset.errorWrapper = "";
@@ -1 +1 @@
1
- {"version":3,"file":"File.js","names":["options: FileOptions<LAnnotation>","workerManager?: WorkerPoolManager | undefined","error: unknown"],"sources":["../../src/components/File.ts"],"sourcesContent":["import type { Element as HASTElement } from 'hast';\nimport { toHtml } from 'hast-util-to-html';\n\nimport {\n DEFAULT_THEMES,\n DIFFS_TAG_NAME,\n HEADER_METADATA_SLOT_ID,\n UNSAFE_CSS_ATTRIBUTE,\n} from '../constants';\nimport {\n LineSelectionManager,\n type LineSelectionOptions,\n type SelectedLineRange,\n pluckLineSelectionOptions,\n} from '../managers/LineSelectionManager';\nimport {\n type GetHoveredLineResult,\n MouseEventManager,\n type MouseEventManagerBaseOptions,\n pluckMouseEventOptions,\n} from '../managers/MouseEventManager';\nimport { ResizeManager } from '../managers/ResizeManager';\nimport { type FileRenderResult, FileRenderer } from '../renderers/FileRenderer';\nimport { SVGSpriteSheet } from '../sprite';\nimport type {\n BaseCodeOptions,\n FileContents,\n LineAnnotation,\n RenderFileMetadata,\n ThemeTypes,\n} from '../types';\nimport { areFilesEqual } from '../utils/areFilesEqual';\nimport { createAnnotationWrapperNode } from '../utils/createAnnotationWrapperNode';\nimport { createCodeNode } from '../utils/createCodeNode';\nimport { createHoverContentNode } from '../utils/createHoverContentNode';\nimport { createUnsafeCSSStyleNode } from '../utils/createUnsafeCSSStyleNode';\nimport { wrapUnsafeCSS } from '../utils/cssWrappers';\nimport { getLineAnnotationName } from '../utils/getLineAnnotationName';\nimport { prerenderHTMLIfNecessary } from '../utils/prerenderHTMLIfNecessary';\nimport { setPreNodeProperties } from '../utils/setWrapperNodeProps';\nimport type { WorkerPoolManager } from '../worker';\nimport { DiffsContainerLoaded } from './web-components';\n\nexport interface FileRenderProps<LAnnotation> {\n file: FileContents;\n fileContainer?: HTMLElement;\n containerWrapper?: HTMLElement;\n forceRender?: boolean;\n lineAnnotations?: LineAnnotation<LAnnotation>[];\n}\n\nexport interface FileHyrdateProps<LAnnotation>\n extends Omit<FileRenderProps<LAnnotation>, 'fileContainer'> {\n fileContainer: HTMLElement;\n prerenderedHTML?: string;\n}\n\nexport interface FileOptions<LAnnotation>\n extends BaseCodeOptions,\n MouseEventManagerBaseOptions<'file'>,\n LineSelectionOptions {\n disableFileHeader?: boolean;\n renderCustomMetadata?: RenderFileMetadata;\n renderAnnotation?(\n annotation: LineAnnotation<LAnnotation>\n ): HTMLElement | undefined;\n renderHoverUtility?(\n getHoveredRow: () => GetHoveredLineResult<'file'> | undefined\n ): HTMLElement | null;\n}\n\nlet instanceId = -1;\n\nexport class File<LAnnotation = undefined> {\n static LoadedCustomComponent: boolean = DiffsContainerLoaded;\n\n readonly __id: number = ++instanceId;\n private fileContainer: HTMLElement | undefined;\n private spriteSVG: SVGElement | undefined;\n private pre: HTMLPreElement | undefined;\n private code: HTMLElement | undefined;\n private unsafeCSSStyle: HTMLStyleElement | undefined;\n private hoverContent: HTMLElement | undefined;\n private errorWrapper: HTMLElement | undefined;\n\n private headerElement: HTMLElement | undefined;\n private headerMetadata: HTMLElement | undefined;\n\n private fileRenderer: FileRenderer<LAnnotation>;\n private resizeManager: ResizeManager;\n private mouseEventManager: MouseEventManager<'file'>;\n private lineSelectionManager: LineSelectionManager;\n\n private annotationElements: HTMLElement[] = [];\n private lineAnnotations: LineAnnotation<LAnnotation>[] = [];\n\n private file: FileContents | undefined;\n\n constructor(\n public options: FileOptions<LAnnotation> = { theme: DEFAULT_THEMES },\n private workerManager?: WorkerPoolManager | undefined,\n private isContainerManaged = false\n ) {\n this.fileRenderer = new FileRenderer<LAnnotation>(\n options,\n this.handleHighlightRender,\n this.workerManager\n );\n this.resizeManager = new ResizeManager();\n this.mouseEventManager = new MouseEventManager(\n 'file',\n pluckMouseEventOptions(options)\n );\n this.lineSelectionManager = new LineSelectionManager(\n pluckLineSelectionOptions(options)\n );\n this.workerManager?.subscribeToThemeChanges(this);\n }\n\n private handleHighlightRender = (): void => {\n this.rerender();\n };\n\n rerender(): void {\n if (this.file == null) return;\n this.render({ file: this.file, forceRender: true });\n }\n\n setOptions(options: FileOptions<LAnnotation> | undefined): void {\n if (options == null) return;\n this.options = options;\n this.mouseEventManager.setOptions(pluckMouseEventOptions(options));\n this.lineSelectionManager.setOptions(pluckLineSelectionOptions(options));\n }\n\n private mergeOptions(options: Partial<FileOptions<LAnnotation>>): void {\n this.options = { ...this.options, ...options };\n }\n\n setThemeType(themeType: ThemeTypes): void {\n const currentThemeType = this.options.themeType ?? 'system';\n if (currentThemeType === themeType) {\n return;\n }\n this.mergeOptions({ themeType });\n this.fileRenderer.setThemeType(themeType);\n\n if (this.headerElement != null) {\n if (themeType === 'system') {\n delete this.headerElement.dataset.themeType;\n } else {\n this.headerElement.dataset.themeType = themeType;\n }\n }\n\n // Update pre element theme mode\n if (this.pre != null) {\n switch (themeType) {\n case 'system':\n delete this.pre.dataset.themeType;\n break;\n case 'light':\n case 'dark':\n this.pre.dataset.themeType = themeType;\n break;\n }\n }\n }\n\n getHoveredLine = (): GetHoveredLineResult<'file'> | undefined => {\n return this.mouseEventManager.getHoveredLine();\n };\n\n setLineAnnotations(lineAnnotations: LineAnnotation<LAnnotation>[]): void {\n this.lineAnnotations = lineAnnotations;\n }\n\n setSelectedLines(range: SelectedLineRange | null): void {\n this.lineSelectionManager.setSelection(range);\n }\n\n cleanUp(): void {\n this.fileRenderer.cleanUp();\n this.resizeManager.cleanUp();\n this.mouseEventManager.cleanUp();\n this.lineSelectionManager.cleanUp();\n this.workerManager?.unsubscribeToThemeChanges(this);\n this.workerManager = undefined;\n\n // Clean up the data\n this.file = undefined;\n\n // Clean up the elements\n if (!this.isContainerManaged) {\n this.fileContainer?.parentNode?.removeChild(this.fileContainer);\n }\n if (this.fileContainer?.shadowRoot != null) {\n this.fileContainer.shadowRoot.innerHTML = '';\n }\n this.fileContainer = undefined;\n this.pre = undefined;\n this.headerElement = undefined;\n this.errorWrapper = undefined;\n this.unsafeCSSStyle = undefined;\n }\n\n hydrate(props: FileHyrdateProps<LAnnotation>): void {\n const { fileContainer, prerenderedHTML } = props;\n prerenderHTMLIfNecessary(fileContainer, prerenderedHTML);\n for (const element of Array.from(\n fileContainer.shadowRoot?.children ?? []\n )) {\n if (element instanceof SVGElement) {\n this.spriteSVG = element;\n continue;\n }\n if (!(element instanceof HTMLElement)) {\n continue;\n }\n if (element instanceof HTMLPreElement) {\n this.pre = element;\n continue;\n }\n if (\n element instanceof HTMLStyleElement &&\n element.hasAttribute(UNSAFE_CSS_ATTRIBUTE)\n ) {\n this.unsafeCSSStyle = element;\n continue;\n }\n if ('diffsHeader' in element.dataset) {\n this.headerElement = element;\n continue;\n }\n }\n // If we have no pre tag, then we should render\n if (this.pre == null) {\n this.render(props);\n }\n // Otherwise orchestrate our setup\n else {\n const { file, lineAnnotations } = props;\n this.fileContainer = fileContainer;\n delete this.pre.dataset.dehydrated;\n\n this.lineAnnotations = lineAnnotations ?? this.lineAnnotations;\n this.file = file;\n this.fileRenderer.hydrate(file);\n this.renderAnnotations();\n this.renderHoverUtility();\n this.injectUnsafeCSS();\n this.mouseEventManager.setup(this.pre);\n this.lineSelectionManager.setup(this.pre);\n if ((this.options.overflow ?? 'scroll') === 'scroll') {\n this.resizeManager.setup(this.pre);\n }\n }\n }\n\n render({\n file,\n fileContainer,\n forceRender = false,\n containerWrapper,\n lineAnnotations,\n }: FileRenderProps<LAnnotation>): void {\n const annotationsChanged =\n lineAnnotations != null &&\n (lineAnnotations.length > 0 || this.lineAnnotations.length > 0)\n ? lineAnnotations !== this.lineAnnotations\n : false;\n if (!forceRender && areFilesEqual(this.file, file) && !annotationsChanged) {\n return;\n }\n\n this.file = file;\n this.fileRenderer.setOptions(this.options);\n if (lineAnnotations != null) {\n this.setLineAnnotations(lineAnnotations);\n }\n this.fileRenderer.setLineAnnotations(this.lineAnnotations);\n\n const { disableFileHeader = false } = this.options;\n if (disableFileHeader) {\n // Remove existing header from DOM\n if (this.headerElement != null) {\n this.headerElement.parentNode?.removeChild(this.headerElement);\n this.headerElement = undefined;\n }\n }\n\n fileContainer = this.getOrCreateFileContainerNode(\n fileContainer,\n containerWrapper\n );\n\n try {\n const fileResult = this.fileRenderer.renderFile(file);\n if (fileResult == null) {\n if (this.workerManager != null && !this.workerManager.isInitialized()) {\n void this.workerManager.initialize().then(() => this.rerender());\n }\n return;\n }\n if (fileResult.headerAST != null) {\n this.applyHeaderToDOM(fileResult.headerAST, fileContainer);\n }\n const pre = this.getOrCreatePreNode(fileContainer);\n this.applyHunksToDOM(fileResult, pre);\n this.renderAnnotations();\n this.renderHoverUtility();\n } catch (error: unknown) {\n if (error instanceof Error) {\n this.applyErrorToDOM(error, fileContainer);\n }\n }\n }\n\n private renderAnnotations(): void {\n if (this.isContainerManaged || this.fileContainer == null) {\n return;\n }\n // Handle annotation elements\n for (const element of this.annotationElements) {\n element.parentNode?.removeChild(element);\n }\n this.annotationElements.length = 0;\n\n const { renderAnnotation } = this.options;\n if (renderAnnotation != null && this.lineAnnotations.length > 0) {\n for (const annotation of this.lineAnnotations) {\n const content = renderAnnotation(annotation);\n if (content == null) continue;\n const el = createAnnotationWrapperNode(\n getLineAnnotationName(annotation)\n );\n el.appendChild(content);\n this.annotationElements.push(el);\n this.fileContainer.appendChild(el);\n }\n }\n }\n\n private renderHoverUtility() {\n const { renderHoverUtility } = this.options;\n if (this.fileContainer == null || renderHoverUtility == null) return;\n if (this.hoverContent == null) {\n this.hoverContent = createHoverContentNode();\n this.fileContainer.appendChild(this.hoverContent);\n }\n const element = renderHoverUtility(this.mouseEventManager.getHoveredLine);\n this.hoverContent.innerHTML = '';\n if (element != null) {\n this.hoverContent.appendChild(element);\n }\n }\n\n private injectUnsafeCSS(): void {\n if (this.fileContainer?.shadowRoot == null) {\n return;\n }\n const { unsafeCSS } = this.options;\n\n if (unsafeCSS == null || unsafeCSS === '') {\n if (this.unsafeCSSStyle != null) {\n this.unsafeCSSStyle.parentNode?.removeChild(this.unsafeCSSStyle);\n this.unsafeCSSStyle = undefined;\n }\n return;\n }\n\n // Create or update the style element\n if (this.unsafeCSSStyle == null) {\n this.unsafeCSSStyle = createUnsafeCSSStyleNode();\n this.fileContainer.shadowRoot.appendChild(this.unsafeCSSStyle);\n }\n // Wrap in @layer unsafe to match SSR behavior\n this.unsafeCSSStyle.innerText = wrapUnsafeCSS(unsafeCSS);\n }\n\n private applyHunksToDOM(result: FileRenderResult, pre: HTMLPreElement): void {\n this.cleanupErrorWrapper();\n this.applyPreNodeAttributes(pre, result);\n pre.innerHTML = '';\n // Create code elements and insert HTML content\n this.code = createCodeNode();\n this.code.innerHTML = this.fileRenderer.renderPartialHTML(result.codeAST);\n pre.appendChild(this.code);\n this.injectUnsafeCSS();\n this.mouseEventManager.setup(pre);\n this.lineSelectionManager.setup(pre);\n this.lineSelectionManager.setDirty();\n if ((this.options.overflow ?? 'scroll') === 'scroll') {\n this.resizeManager.setup(pre);\n } else {\n this.resizeManager.cleanUp();\n }\n }\n\n private applyHeaderToDOM(\n headerAST: HASTElement,\n container: HTMLElement\n ): void {\n const { file } = this;\n if (file == null) return;\n this.cleanupErrorWrapper();\n const tempDiv = document.createElement('div');\n tempDiv.innerHTML = toHtml(headerAST);\n const newHeader = tempDiv.firstElementChild;\n if (!(newHeader instanceof HTMLElement)) {\n return;\n }\n if (this.headerElement != null) {\n container.shadowRoot?.replaceChild(newHeader, this.headerElement);\n } else {\n container.shadowRoot?.prepend(newHeader);\n }\n this.headerElement = newHeader;\n\n if (this.isContainerManaged) return;\n\n const { renderCustomMetadata } = this.options;\n if (this.headerMetadata != null) {\n this.headerMetadata.parentNode?.removeChild(this.headerMetadata);\n }\n const content = renderCustomMetadata?.(file) ?? undefined;\n if (content != null) {\n this.headerMetadata = document.createElement('div');\n this.headerMetadata.slot = HEADER_METADATA_SLOT_ID;\n if (content instanceof Element) {\n this.headerMetadata.appendChild(content);\n } else {\n this.headerMetadata.innerText = `${content}`;\n }\n container.appendChild(this.headerMetadata);\n }\n }\n\n private getOrCreateFileContainerNode(\n fileContainer?: HTMLElement,\n parentNode?: HTMLElement\n ): HTMLElement {\n this.fileContainer =\n fileContainer ??\n this.fileContainer ??\n document.createElement(DIFFS_TAG_NAME);\n if (parentNode != null && this.fileContainer.parentNode !== parentNode) {\n parentNode.appendChild(this.fileContainer);\n }\n if (this.spriteSVG == null) {\n const fragment = document.createElement('div');\n fragment.innerHTML = SVGSpriteSheet;\n const firstChild = fragment.firstChild;\n if (firstChild instanceof SVGElement) {\n this.spriteSVG = firstChild;\n this.fileContainer.shadowRoot?.appendChild(this.spriteSVG);\n }\n }\n return this.fileContainer;\n }\n\n private getOrCreatePreNode(container: HTMLElement): HTMLPreElement {\n // If we haven't created a pre element yet, lets go ahead and do that\n if (this.pre == null) {\n this.pre = document.createElement('pre');\n container.shadowRoot?.appendChild(this.pre);\n }\n // If we have a new parent container for the pre element, lets go ahead and\n // move it into the new container\n else if (this.pre.parentNode !== container) {\n container.shadowRoot?.appendChild(this.pre);\n }\n return this.pre;\n }\n\n private applyPreNodeAttributes(\n pre: HTMLPreElement,\n { totalLines, themeStyles, baseThemeType }: FileRenderResult\n ): void {\n const {\n overflow = 'scroll',\n themeType = 'system',\n disableLineNumbers = false,\n } = this.options;\n setPreNodeProperties({\n pre,\n split: false,\n themeStyles,\n overflow,\n disableLineNumbers,\n themeType: baseThemeType ?? themeType,\n diffIndicators: 'none',\n disableBackground: true,\n totalLines,\n });\n }\n\n private applyErrorToDOM(error: Error, container: HTMLElement) {\n this.cleanupErrorWrapper();\n const pre = this.getOrCreatePreNode(container);\n pre.innerHTML = '';\n pre.parentNode?.removeChild(pre);\n this.pre = undefined;\n const shadowRoot =\n container.shadowRoot ?? container.attachShadow({ mode: 'open' });\n this.errorWrapper ??= document.createElement('div');\n this.errorWrapper.dataset.errorWrapper = '';\n this.errorWrapper.innerHTML = '';\n shadowRoot.appendChild(this.errorWrapper);\n const errorMessage = document.createElement('div');\n errorMessage.dataset.errorMessage = '';\n errorMessage.innerText = error.message;\n this.errorWrapper.appendChild(errorMessage);\n const errorStack = document.createElement('pre');\n errorStack.dataset.errorStack = '';\n errorStack.innerText = error.stack ?? 'No Error Stack';\n this.errorWrapper.appendChild(errorStack);\n }\n\n private cleanupErrorWrapper() {\n this.errorWrapper?.parentNode?.removeChild(this.errorWrapper);\n this.errorWrapper = undefined;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAuEA,IAAI,aAAa;AAEjB,IAAa,OAAb,MAA2C;CACzC,OAAO,wBAAiC;CAExC,AAAS,OAAe,EAAE;CAC1B,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;CAER,AAAQ;CACR,AAAQ;CAER,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;CAER,AAAQ,qBAAoC,EAAE;CAC9C,AAAQ,kBAAiD,EAAE;CAE3D,AAAQ;CAER,YACE,AAAOA,UAAoC,EAAE,OAAO,gBAAgB,EACpE,AAAQC,eACR,AAAQ,qBAAqB,OAC7B;EAHO;EACC;EACA;AAER,OAAK,eAAe,IAAI,aACtB,SACA,KAAK,uBACL,KAAK,cACN;AACD,OAAK,gBAAgB,IAAI,eA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O,MAAM;AACpB,QAAK,MAAM,SAAS,cAAc,MAAM;AACxC,aAAU,YAAY,YAAY,KAAK,IAAI;aAIpC,KAAK,IAAI,eAAe,UAC/B,WAAU,YAAY,YAAY,KAAK,IAAI;AAE7C,SAAO,KAAK;;CAGd,AAAQ,uBACN,KACA,EAAE,YAAY,aAAa,iBACrB;EACN,MAAM,EACJ,WAAW,UACX,YAAY,UACZ,qBAAqB,UACnB,KAAK;AACT,uBAAqB;GACnB;GACA,OAAO;GACP;GACA;GACA;GACA,WAAW,iBAAiB;GAC5B,gBAAgB;GAChB,mBAAmB;GACnB;GACD,CAAC;;CAGJ,AAAQ,gBAAgB,OAAc,WAAwB;AAC5D,OAAK,qBAAqB;EAC1B,MAAM,MAAM,KAAK,mBAAmB,UAAU;AAC9C,MAAI,YAAY;AAChB,MAAI,YAAY,YAAY,IAAI;AAChC,OAAK,MAAM;EACX,MAAM,aACJ,UAAU,cAAc,UAAU,aAAa,EAAE,MAAM,QAAQ,CAAC;AAClE,OAAK,iBAAiB,SAAS,cAAc,MAAM;AACnD,OAAK,aAAa,QAAQ,eAAe;AACzC,OAAK,aAAa,YAAY;AAC9B,aAAW,YAAY,KAAK,aAAa;EACzC,MAAM,eAAe,SAAS,cAAc,MAAM;AAClD,eAAa,QAAQ,eAAe;AACpC,eAAa,YAAY,MAAM;AAC/B,OAAK,aAAa,YAAY,aAAa;EAC3C,MAAM,aAAa,SAAS,cAAc,MAAM;AAChD,aAAW,QAAQ,aAAa;AAChC,aAAW,YAAY,MAAM,SAAS;AACtC,OAAK,aAAa,YAAY,WAAW;;CAG3C,AAAQ,sBAAsB;AAC5B,OAAK,cAAc,YAAY,YAAY,KAAK,aAAa;AAC7D,OAAK,eAAe"}
1
+ {"version":3,"file":"File.js","names":["options: FileOptions<LAnnotation>","workerManager?: WorkerPoolManager | undefined","error: unknown","preProperties: PrePropertiesConfig"],"sources":["../../src/components/File.ts"],"sourcesContent":["import type { Element as HASTElement } from 'hast';\nimport { toHtml } from 'hast-util-to-html';\n\nimport {\n DEFAULT_THEMES,\n DIFFS_TAG_NAME,\n HEADER_METADATA_SLOT_ID,\n UNSAFE_CSS_ATTRIBUTE,\n} from '../constants';\nimport {\n LineSelectionManager,\n type LineSelectionOptions,\n type SelectedLineRange,\n pluckLineSelectionOptions,\n} from '../managers/LineSelectionManager';\nimport {\n type GetHoveredLineResult,\n MouseEventManager,\n type MouseEventManagerBaseOptions,\n pluckMouseEventOptions,\n} from '../managers/MouseEventManager';\nimport { ResizeManager } from '../managers/ResizeManager';\nimport { type FileRenderResult, FileRenderer } from '../renderers/FileRenderer';\nimport { SVGSpriteSheet } from '../sprite';\nimport type {\n BaseCodeOptions,\n FileContents,\n LineAnnotation,\n PrePropertiesConfig,\n RenderFileMetadata,\n ThemeTypes,\n} from '../types';\nimport { areFilesEqual } from '../utils/areFilesEqual';\nimport { areLineAnnotationsEqual } from '../utils/areLineAnnotationsEqual';\nimport { arePrePropertiesEqual } from '../utils/arePrePropertiesEqual';\nimport { createAnnotationWrapperNode } from '../utils/createAnnotationWrapperNode';\nimport { createHoverContentNode } from '../utils/createHoverContentNode';\nimport { createUnsafeCSSStyleNode } from '../utils/createUnsafeCSSStyleNode';\nimport { wrapUnsafeCSS } from '../utils/cssWrappers';\nimport { getLineAnnotationName } from '../utils/getLineAnnotationName';\nimport { getOrCreateCodeNode } from '../utils/getOrCreateCodeNode';\nimport { prerenderHTMLIfNecessary } from '../utils/prerenderHTMLIfNecessary';\nimport { setPreNodeProperties } from '../utils/setWrapperNodeProps';\nimport type { WorkerPoolManager } from '../worker';\nimport { DiffsContainerLoaded } from './web-components';\n\nexport interface FileRenderProps<LAnnotation> {\n file: FileContents;\n fileContainer?: HTMLElement;\n containerWrapper?: HTMLElement;\n forceRender?: boolean;\n lineAnnotations?: LineAnnotation<LAnnotation>[];\n}\n\nexport interface FileHyrdateProps<LAnnotation>\n extends Omit<FileRenderProps<LAnnotation>, 'fileContainer'> {\n fileContainer: HTMLElement;\n prerenderedHTML?: string;\n}\n\nexport interface FileOptions<LAnnotation>\n extends BaseCodeOptions,\n MouseEventManagerBaseOptions<'file'>,\n LineSelectionOptions {\n disableFileHeader?: boolean;\n renderCustomMetadata?: RenderFileMetadata;\n renderAnnotation?(\n annotation: LineAnnotation<LAnnotation>\n ): HTMLElement | undefined;\n renderHoverUtility?(\n getHoveredRow: () => GetHoveredLineResult<'file'> | undefined\n ): HTMLElement | null;\n}\n\ninterface AnnotationElementCache<LAnnotation> {\n element: HTMLElement;\n annotation: LineAnnotation<LAnnotation>;\n}\n\nlet instanceId = -1;\n\nexport class File<LAnnotation = undefined> {\n static LoadedCustomComponent: boolean = DiffsContainerLoaded;\n\n readonly __id: string = `file:${++instanceId}`;\n\n private fileContainer: HTMLElement | undefined;\n private spriteSVG: SVGElement | undefined;\n private pre: HTMLPreElement | undefined;\n private code: HTMLElement | undefined;\n private unsafeCSSStyle: HTMLStyleElement | undefined;\n private hoverContent: HTMLElement | undefined;\n private errorWrapper: HTMLElement | undefined;\n private lastRenderedHeaderHTML: string | undefined;\n private appliedPreAttributes: PrePropertiesConfig | undefined;\n\n private headerElement: HTMLElement | undefined;\n private headerMetadata: HTMLElement | undefined;\n\n private fileRenderer: FileRenderer<LAnnotation>;\n private resizeManager: ResizeManager;\n private mouseEventManager: MouseEventManager<'file'>;\n private lineSelectionManager: LineSelectionManager;\n\n private annotationCache: Map<string, AnnotationElementCache<LAnnotation>> =\n new Map();\n private lineAnnotations: LineAnnotation<LAnnotation>[] = [];\n\n private file: FileContents | undefined;\n\n constructor(\n public options: FileOptions<LAnnotation> = { theme: DEFAULT_THEMES },\n private workerManager?: WorkerPoolManager | undefined,\n private isContainerManaged = false\n ) {\n this.fileRenderer = new FileRenderer<LAnnotation>(\n options,\n this.handleHighlightRender,\n this.workerManager\n );\n this.resizeManager = new ResizeManager();\n this.mouseEventManager = new MouseEventManager(\n 'file',\n pluckMouseEventOptions(options)\n );\n this.lineSelectionManager = new LineSelectionManager(\n pluckLineSelectionOptions(options)\n );\n this.workerManager?.subscribeToThemeChanges(this);\n }\n\n private handleHighlightRender = (): void => {\n this.rerender();\n };\n\n rerender(): void {\n if (this.file == null) return;\n this.render({ file: this.file, forceRender: true });\n }\n\n setOptions(options: FileOptions<LAnnotation> | undefined): void {\n if (options == null) return;\n this.options = options;\n this.mouseEventManager.setOptions(pluckMouseEventOptions(options));\n this.lineSelectionManager.setOptions(pluckLineSelectionOptions(options));\n }\n\n private mergeOptions(options: Partial<FileOptions<LAnnotation>>): void {\n this.options = { ...this.options, ...options };\n }\n\n setThemeType(themeType: ThemeTypes): void {\n const currentThemeType = this.options.themeType ?? 'system';\n if (currentThemeType === themeType) {\n return;\n }\n this.mergeOptions({ themeType });\n this.fileRenderer.setThemeType(themeType);\n\n if (this.headerElement != null) {\n if (themeType === 'system') {\n delete this.headerElement.dataset.themeType;\n } else {\n this.headerElement.dataset.themeType = themeType;\n }\n }\n\n // Update pre element theme mode\n if (this.pre != null) {\n switch (themeType) {\n case 'system':\n delete this.pre.dataset.themeType;\n break;\n case 'light':\n case 'dark':\n this.pre.dataset.themeType = themeType;\n break;\n }\n }\n }\n\n getHoveredLine = (): GetHoveredLineResult<'file'> | undefined => {\n return this.mouseEventManager.getHoveredLine();\n };\n\n setLineAnnotations(lineAnnotations: LineAnnotation<LAnnotation>[]): void {\n this.lineAnnotations = lineAnnotations;\n }\n\n setSelectedLines(range: SelectedLineRange | null): void {\n this.lineSelectionManager.setSelection(range);\n }\n\n cleanUp(): void {\n this.fileRenderer.cleanUp();\n this.resizeManager.cleanUp();\n this.mouseEventManager.cleanUp();\n this.lineSelectionManager.cleanUp();\n this.workerManager?.unsubscribeToThemeChanges(this);\n this.workerManager = undefined;\n\n // Clean up the data\n this.file = undefined;\n\n // Clean up the elements\n if (!this.isContainerManaged) {\n this.fileContainer?.parentNode?.removeChild(this.fileContainer);\n }\n if (this.fileContainer?.shadowRoot != null) {\n this.fileContainer.shadowRoot.innerHTML = '';\n }\n this.fileContainer = undefined;\n this.pre = undefined;\n this.appliedPreAttributes = undefined;\n this.headerElement = undefined;\n this.lastRenderedHeaderHTML = undefined;\n this.errorWrapper = undefined;\n this.unsafeCSSStyle = undefined;\n }\n\n hydrate(props: FileHyrdateProps<LAnnotation>): void {\n const { fileContainer, prerenderedHTML } = props;\n prerenderHTMLIfNecessary(fileContainer, prerenderedHTML);\n for (const element of Array.from(\n fileContainer.shadowRoot?.children ?? []\n )) {\n if (element instanceof SVGElement) {\n this.spriteSVG = element;\n continue;\n }\n if (!(element instanceof HTMLElement)) {\n continue;\n }\n if (element instanceof HTMLPreElement) {\n this.pre = element;\n this.appliedPreAttributes = undefined;\n continue;\n }\n if (\n element instanceof HTMLStyleElement &&\n element.hasAttribute(UNSAFE_CSS_ATTRIBUTE)\n ) {\n this.unsafeCSSStyle = element;\n continue;\n }\n if ('diffsHeader' in element.dataset) {\n this.headerElement = element;\n this.lastRenderedHeaderHTML = undefined;\n continue;\n }\n }\n // If we have no pre tag, then we should render\n if (this.pre == null) {\n this.render(props);\n }\n // Otherwise orchestrate our setup\n else {\n const { file, lineAnnotations } = props;\n this.fileContainer = fileContainer;\n delete this.pre.dataset.dehydrated;\n\n this.lineAnnotations = lineAnnotations ?? this.lineAnnotations;\n this.file = file;\n this.fileRenderer.hydrate(file);\n this.renderAnnotations();\n this.renderHoverUtility();\n this.injectUnsafeCSS();\n this.mouseEventManager.setup(this.pre);\n this.lineSelectionManager.setup(this.pre);\n if ((this.options.overflow ?? 'scroll') === 'scroll') {\n this.resizeManager.setup(this.pre);\n }\n }\n }\n\n render({\n file,\n fileContainer,\n forceRender = false,\n containerWrapper,\n lineAnnotations,\n }: FileRenderProps<LAnnotation>): void {\n const annotationsChanged =\n lineAnnotations != null &&\n (lineAnnotations.length > 0 || this.lineAnnotations.length > 0)\n ? lineAnnotations !== this.lineAnnotations\n : false;\n if (!forceRender && areFilesEqual(this.file, file) && !annotationsChanged) {\n return;\n }\n\n this.file = file;\n this.fileRenderer.setOptions(this.options);\n if (lineAnnotations != null) {\n this.setLineAnnotations(lineAnnotations);\n }\n this.fileRenderer.setLineAnnotations(this.lineAnnotations);\n\n const { disableFileHeader = false } = this.options;\n if (disableFileHeader) {\n // Remove existing header from DOM\n if (this.headerElement != null) {\n this.headerElement.parentNode?.removeChild(this.headerElement);\n this.headerElement = undefined;\n this.lastRenderedHeaderHTML = undefined;\n }\n }\n\n fileContainer = this.getOrCreateFileContainerNode(\n fileContainer,\n containerWrapper\n );\n\n try {\n const fileResult = this.fileRenderer.renderFile(file);\n if (fileResult == null) {\n if (this.workerManager != null && !this.workerManager.isInitialized()) {\n void this.workerManager.initialize().then(() => this.rerender());\n }\n return;\n }\n if (fileResult.headerAST != null) {\n this.applyHeaderToDOM(fileResult.headerAST, fileContainer);\n }\n const pre = this.getOrCreatePreNode(fileContainer);\n this.applyHunksToDOM(fileResult, pre);\n this.renderAnnotations();\n this.renderHoverUtility();\n } catch (error: unknown) {\n if (error instanceof Error) {\n console.error(error);\n this.applyErrorToDOM(error, fileContainer);\n }\n }\n }\n\n private renderAnnotations(): void {\n if (this.isContainerManaged || this.fileContainer == null) {\n for (const { element } of this.annotationCache.values()) {\n element.parentNode?.removeChild(element);\n }\n this.annotationCache.clear();\n return;\n }\n const staleAnnotations = new Map(this.annotationCache);\n const { renderAnnotation } = this.options;\n if (renderAnnotation != null && this.lineAnnotations.length > 0) {\n for (const [index, annotation] of this.lineAnnotations.entries()) {\n const id = `${index}-${getLineAnnotationName(annotation)}`;\n let cache = this.annotationCache.get(id);\n if (\n cache == null ||\n !areLineAnnotationsEqual(annotation, cache.annotation)\n ) {\n cache?.element.parentElement?.removeChild(cache.element);\n const content = renderAnnotation(annotation);\n // If we can't render anything, then we should not render anything\n // and clear the annotation cache if necessary.\n if (content == null) {\n continue;\n }\n cache = {\n element: createAnnotationWrapperNode(\n getLineAnnotationName(annotation)\n ),\n annotation,\n };\n cache.element.appendChild(content);\n this.fileContainer.appendChild(cache.element);\n this.annotationCache.set(id, cache);\n }\n staleAnnotations.delete(id);\n }\n }\n for (const [id, { element }] of staleAnnotations.entries()) {\n this.annotationCache.delete(id);\n element.parentNode?.removeChild(element);\n }\n }\n\n private renderHoverUtility() {\n const { renderHoverUtility } = this.options;\n if (this.fileContainer == null || renderHoverUtility == null) {\n return;\n }\n const element = renderHoverUtility(this.mouseEventManager.getHoveredLine);\n if (element != null && this.hoverContent != null) {\n return;\n } else if (element == null) {\n this.hoverContent?.parentNode?.removeChild(this.hoverContent);\n this.hoverContent = undefined;\n return;\n }\n this.hoverContent = createHoverContentNode();\n this.hoverContent.appendChild(element);\n this.fileContainer.appendChild(this.hoverContent);\n }\n\n private injectUnsafeCSS(): void {\n if (this.fileContainer?.shadowRoot == null) {\n return;\n }\n const { unsafeCSS } = this.options;\n\n if (unsafeCSS == null || unsafeCSS === '') {\n if (this.unsafeCSSStyle != null) {\n this.unsafeCSSStyle.parentNode?.removeChild(this.unsafeCSSStyle);\n this.unsafeCSSStyle = undefined;\n }\n return;\n }\n\n // Create or update the style element\n if (this.unsafeCSSStyle == null) {\n this.unsafeCSSStyle = createUnsafeCSSStyleNode();\n this.fileContainer.shadowRoot.appendChild(this.unsafeCSSStyle);\n }\n // Wrap in @layer unsafe to match SSR behavior\n this.unsafeCSSStyle.innerText = wrapUnsafeCSS(unsafeCSS);\n }\n\n private applyHunksToDOM(result: FileRenderResult, pre: HTMLPreElement): void {\n this.cleanupErrorWrapper();\n this.applyPreNodeAttributes(pre, result);\n // Create code elements and insert HTML content\n this.code = getOrCreateCodeNode({ code: this.code });\n this.code.innerHTML = this.fileRenderer.renderPartialHTML(result.codeAST);\n pre.replaceChildren(this.code);\n this.injectUnsafeCSS();\n this.mouseEventManager.setup(pre);\n this.lineSelectionManager.setup(pre);\n this.lineSelectionManager.setDirty();\n if ((this.options.overflow ?? 'scroll') === 'scroll') {\n this.resizeManager.setup(pre);\n } else {\n this.resizeManager.cleanUp();\n }\n }\n\n private applyHeaderToDOM(\n headerAST: HASTElement,\n container: HTMLElement\n ): void {\n const { file } = this;\n if (file == null) return;\n this.cleanupErrorWrapper();\n const headerHTML = toHtml(headerAST);\n if (headerHTML !== this.lastRenderedHeaderHTML) {\n const tempDiv = document.createElement('div');\n tempDiv.innerHTML = headerHTML;\n const newHeader = tempDiv.firstElementChild;\n if (!(newHeader instanceof HTMLElement)) {\n return;\n }\n if (this.headerElement != null) {\n container.shadowRoot?.replaceChild(newHeader, this.headerElement);\n } else {\n container.shadowRoot?.prepend(newHeader);\n }\n this.headerElement = newHeader;\n this.lastRenderedHeaderHTML = headerHTML;\n }\n\n if (this.isContainerManaged) return;\n\n const { renderCustomMetadata } = this.options;\n if (this.headerMetadata != null) {\n this.headerMetadata.parentNode?.removeChild(this.headerMetadata);\n }\n const content = renderCustomMetadata?.(file) ?? undefined;\n if (content != null) {\n this.headerMetadata = document.createElement('div');\n this.headerMetadata.slot = HEADER_METADATA_SLOT_ID;\n if (content instanceof Element) {\n this.headerMetadata.appendChild(content);\n } else {\n this.headerMetadata.innerText = `${content}`;\n }\n container.appendChild(this.headerMetadata);\n }\n }\n\n private getOrCreateFileContainerNode(\n fileContainer?: HTMLElement,\n parentNode?: HTMLElement\n ): HTMLElement {\n const previousContainer = this.fileContainer;\n this.fileContainer =\n fileContainer ??\n this.fileContainer ??\n document.createElement(DIFFS_TAG_NAME);\n if (previousContainer != null && previousContainer !== this.fileContainer) {\n this.lastRenderedHeaderHTML = undefined;\n this.headerElement = undefined;\n }\n if (parentNode != null && this.fileContainer.parentNode !== parentNode) {\n parentNode.appendChild(this.fileContainer);\n }\n if (this.spriteSVG == null) {\n const fragment = document.createElement('div');\n fragment.innerHTML = SVGSpriteSheet;\n const firstChild = fragment.firstChild;\n if (firstChild instanceof SVGElement) {\n this.spriteSVG = firstChild;\n this.fileContainer.shadowRoot?.appendChild(this.spriteSVG);\n }\n }\n return this.fileContainer;\n }\n\n private getOrCreatePreNode(container: HTMLElement): HTMLPreElement {\n // If we haven't created a pre element yet, lets go ahead and do that\n if (this.pre == null) {\n this.pre = document.createElement('pre');\n container.shadowRoot?.appendChild(this.pre);\n this.appliedPreAttributes = undefined;\n }\n // If we have a new parent container for the pre element, lets go ahead and\n // move it into the new container\n else if (this.pre.parentNode !== container) {\n container.shadowRoot?.appendChild(this.pre);\n this.appliedPreAttributes = undefined;\n }\n return this.pre;\n }\n\n private applyPreNodeAttributes(\n pre: HTMLPreElement,\n { totalLines, themeStyles, baseThemeType }: FileRenderResult\n ): void {\n const {\n overflow = 'scroll',\n themeType = 'system',\n disableLineNumbers = false,\n } = this.options;\n const preProperties: PrePropertiesConfig = {\n split: false,\n themeStyles,\n overflow,\n disableLineNumbers,\n themeType: baseThemeType ?? themeType,\n diffIndicators: 'none',\n disableBackground: true,\n totalLines,\n };\n if (arePrePropertiesEqual(preProperties, this.appliedPreAttributes)) {\n return;\n }\n setPreNodeProperties(pre, preProperties);\n this.appliedPreAttributes = preProperties;\n }\n\n private applyErrorToDOM(error: Error, container: HTMLElement) {\n this.cleanupErrorWrapper();\n const pre = this.getOrCreatePreNode(container);\n pre.innerHTML = '';\n pre.parentNode?.removeChild(pre);\n this.pre = undefined;\n this.appliedPreAttributes = undefined;\n const shadowRoot =\n container.shadowRoot ?? container.attachShadow({ mode: 'open' });\n this.errorWrapper ??= document.createElement('div');\n this.errorWrapper.dataset.errorWrapper = '';\n this.errorWrapper.innerHTML = '';\n shadowRoot.appendChild(this.errorWrapper);\n const errorMessage = document.createElement('div');\n errorMessage.dataset.errorMessage = '';\n errorMessage.innerText = error.message;\n this.errorWrapper.appendChild(errorMessage);\n const errorStack = document.createElement('pre');\n errorStack.dataset.errorStack = '';\n errorStack.innerText = error.stack ?? 'No Error Stack';\n this.errorWrapper.appendChild(errorStack);\n }\n\n private cleanupErrorWrapper() {\n this.errorWrapper?.parentNode?.removeChild(this.errorWrapper);\n this.errorWrapper = undefined;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA+EA,IAAI,aAAa;AAEjB,IAAa,OAAb,MAA2C;C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;AAChC,aAAW,YAAY,MAAM,SAAS;AACtC,OAAK,aAAa,YAAY,WAAW;;CAG3C,AAAQ,sBAAsB;AAC5B,OAAK,cAAc,YAAY,YAAY,KAAK,aAAa;AAC7D,OAAK,eAAe"}
@@ -1,8 +1,11 @@
1
- import { BaseDiffOptions, DiffLineAnnotation, ExpansionDirections, FileContents, FileDiffMetadata, HunkData, HunkSeparators, RenderHeaderMetadataCallback, ThemeTypes } from "../types.js";
2
- import { LineSelectionOptions, SelectedLineRange } from "../managers/LineSelectionManager.js";
3
- import { GetHoveredLineResult, MouseEventManagerBaseOptions } from "../managers/MouseEventManager.js";
1
+ import { BaseDiffOptions, DiffLineAnnotation, ExpansionDirections, FileContents, FileDiffMetadata, HunkData, HunkSeparators, PrePropertiesConfig, RenderHeaderMetadataCallback, RenderRange, ThemeTypes } from "../types.js";
2
+ import { LineSelectionManager, LineSelectionOptions, SelectedLineRange } from "../managers/LineSelectionManager.js";
3
+ import { GetHoveredLineResult, MouseEventManager, MouseEventManagerBaseOptions } from "../managers/MouseEventManager.js";
4
4
  import { WorkerPoolManager } from "../worker/WorkerPoolManager.js";
5
5
  import "../worker/index.js";
6
+ import { ResizeManager } from "../managers/ResizeManager.js";
7
+ import { ScrollSyncManager } from "../managers/ScrollSyncManager.js";
8
+ import { DiffHunksRenderer } from "../renderers/DiffHunksRenderer.js";
6
9
 
7
10
  //#region src/components/FileDiff.d.ts
8
11
  interface FileDiffRenderProps<LAnnotation> {
@@ -13,6 +16,7 @@ interface FileDiffRenderProps<LAnnotation> {
13
16
  fileContainer?: HTMLElement;
14
17
  containerWrapper?: HTMLElement;
15
18
  lineAnnotations?: DiffLineAnnotation<LAnnotation>[];
19
+ renderRange?: RenderRange;
16
20
  }
17
21
  interface FileDiffHydrationProps<LAnnotation> extends Omit<FileDiffRenderProps<LAnnotation>, "fileContainer"> {
18
22
  fileContainer: HTMLElement;
@@ -25,31 +29,46 @@ interface FileDiffOptions<LAnnotation> extends Omit<BaseDiffOptions, "hunkSepara
25
29
  renderAnnotation?(annotation: DiffLineAnnotation<LAnnotation>): HTMLElement | undefined;
26
30
  renderHoverUtility?(getHoveredRow: () => GetHoveredLineResult<"diff"> | undefined): HTMLElement | null;
27
31
  }
32
+ interface AnnotationElementCache<LAnnotation> {
33
+ element: HTMLElement;
34
+ annotation: DiffLineAnnotation<LAnnotation>;
35
+ }
36
+ interface CustomHunkElementCache {
37
+ element: HTMLElement;
38
+ hunkData: HunkData;
39
+ }
28
40
  declare class FileDiff<LAnnotation = undefined> {
29
41
  options: FileDiffOptions<LAnnotation>;
30
- private workerManager?;
31
- private isContainerManaged;
42
+ protected workerManager?: WorkerPoolManager | undefined;
43
+ protected isContainerManaged: boolean;
32
44
  static LoadedCustomComponent: boolean;
33
- readonly __id: number;
34
- private fileContainer;
35
- private spriteSVG;
36
- private pre;
37
- private unsafeCSSStyle;
38
- private hoverContent;
39
- private headerElement;
40
- private headerMetadata;
41
- private customHunkElements;
42
- private errorWrapper;
43
- private hunksRenderer;
44
- private resizeManager;
45
- private scrollSyncManager;
46
- private mouseEventManager;
47
- private lineSelectionManager;
48
- private annotationElements;
49
- private lineAnnotations;
50
- private oldFile;
51
- private newFile;
52
- private fileDiff;
45
+ readonly __id: string;
46
+ protected fileContainer: HTMLElement | undefined;
47
+ protected spriteSVG: SVGElement | undefined;
48
+ protected pre: HTMLPreElement | undefined;
49
+ protected codeUnified: HTMLElement | undefined;
50
+ protected codeDeletions: HTMLElement | undefined;
51
+ protected codeAdditions: HTMLElement | undefined;
52
+ protected unsafeCSSStyle: HTMLStyleElement | undefined;
53
+ protected hoverContent: HTMLElement | undefined;
54
+ protected headerElement: HTMLElement | undefined;
55
+ protected headerMetadata: HTMLElement | undefined;
56
+ protected separatorCache: Map<string, CustomHunkElementCache>;
57
+ protected errorWrapper: HTMLElement | undefined;
58
+ protected hunksRenderer: DiffHunksRenderer<LAnnotation>;
59
+ protected resizeManager: ResizeManager;
60
+ protected scrollSyncManager: ScrollSyncManager;
61
+ protected mouseEventManager: MouseEventManager<"diff">;
62
+ protected lineSelectionManager: LineSelectionManager;
63
+ protected annotationCache: Map<string, AnnotationElementCache<LAnnotation>>;
64
+ protected lineAnnotations: DiffLineAnnotation<LAnnotation>[];
65
+ protected deletionFile: FileContents | undefined;
66
+ protected additionFile: FileContents | undefined;
67
+ protected fileDiff: FileDiffMetadata | undefined;
68
+ protected renderRange: RenderRange | undefined;
69
+ protected appliedPreAttributes: PrePropertiesConfig | undefined;
70
+ protected lastRenderedHeaderHTML: string | undefined;
71
+ protected enabled: boolean;
53
72
  constructor(options?: FileDiffOptions<LAnnotation>, workerManager?: WorkerPoolManager | undefined, isContainerManaged?: boolean);
54
73
  private handleHighlightRender;
55
74
  setOptions(options: FileDiffOptions<LAnnotation> | undefined): void;
@@ -58,7 +77,8 @@ declare class FileDiff<LAnnotation = undefined> {
58
77
  getHoveredLine: () => GetHoveredLineResult<"diff"> | undefined;
59
78
  setLineAnnotations(lineAnnotations: DiffLineAnnotation<LAnnotation>[]): void;
60
79
  setSelectedLines(range: SelectedLineRange | null): void;
61
- cleanUp(): void;
80
+ cleanUp(recycle?: boolean): void;
81
+ virtualizedSetup(): void;
62
82
  hydrate(props: FileDiffHydrationProps<LAnnotation>): void;
63
83
  rerender(): void;
64
84
  handleExpandHunk: (hunkIndex: number, direction: ExpansionDirections) => void;
@@ -70,14 +90,16 @@ declare class FileDiff<LAnnotation = undefined> {
70
90
  forceRender,
71
91
  lineAnnotations,
72
92
  fileContainer,
73
- containerWrapper
93
+ containerWrapper,
94
+ renderRange
74
95
  }: FileDiffRenderProps<LAnnotation>): void;
75
96
  private renderSeparators;
76
97
  private renderAnnotations;
77
98
  private renderHoverUtility;
78
- private getOrCreateFileContainer;
99
+ getOrCreateFileContainer(fileContainer?: HTMLElement, parentNode?: HTMLElement): HTMLElement;
79
100
  getFileContainer(): HTMLElement | undefined;
80
101
  private getOrCreatePreNode;
102
+ private syncCodeNodesFromPre;
81
103
  private applyHeaderToDOM;
82
104
  private injectUnsafeCSS;
83
105
  private applyHunksToDOM;
@@ -1 +1 @@
1
- {"version":3,"file":"FileDiff.d.ts","names":["options: FileDiffOptions<LAnnotation>","workerManager?: WorkerPoolManager | undefined"],"sources":["../../src/components/FileDiff.ts"],"sourcesContent":[],"mappings":";;;;;;;UAoDiB;aACJ;YACD;EAFZ,OAAiB,CAAA,EAGL,YAHK;EACJ,WAAA,CAAA,EAAA,OAAA;EACD,aAAA,CAAA,EAGM,WAHN;EACA,gBAAA,CAAA,EAGS,WAHT;EAEM,eAAA,CAAA,EAEE,kBAFF,CAEqB,WAFrB,CAAA,EAAA;;AAEqB,UAGtB,sBAHsB,CAAA,WAAA,CAAA,SAI7B,IAJ6B,CAIxB,mBAJwB,CAIJ,WAJI,CAAA,EAAA,eAAA,CAAA,CAAA;EAAnB,aAAA,EAKH,WALG;EAAA,eAAA,CAAA,EAAA,MAAA;AAGpB;AACmC,UAKlB,eALkB,CAAA,WAAA,CAAA,SAMzB,IANyB,CAMpB,eANoB,EAAA,gBAAA,CAAA,EAO/B,4BAP+B,CAAA,MAAA,CAAA,EAQ/B,oBAR+B,CAAA;EAApB,cAAA,CAAA,EAUT,OAVS,CAUD,cAVC,EAAA,QAAA,CAAA,GAAA,CAAA,CAAA,IAAA,EAYD,QAZC,EAAA,QAAA,EAaG,QAbH,CAaY,WAbZ,CAAA,EAAA,GAcJ,WAdI,GAcU,gBAdV,CAAA;EACE,iBAAA,CAAA,EAAA,OAAA;EADP,oBAAA,CAAA,EAgBe,4BAhBf;EAAA,gBAAA,EAAA,UAAA,EAkBM,kBAlBN,CAkByB,WAlBzB,CAAA,CAAA,EAmBL,WAnBK,GAAA,SAAA;EAKV,kBAAiB,EAAA,aAAA,EAAA,GAAA,GAgBQ,oBAhBR,CAAA,MAAA,CAAA,GAAA,SAAA,CAAA,EAiBZ,WAjBY,GAAA,IAAA;;AAKH,cAiBD,QAjBC,CAAA,cAAA,SAAA,CAAA,CAAA;EAAR,OAAA,EAiDc,eA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CAAA,SAAA,EAAA,MAAA,EAAA,SAAA,EAbW,mBAaX,EAAA,GAAA,IAAA;EACA,UAAA,CAAA,SAAA,EAAA,MAAA,EAAA,SAAA,EATuC,mBASvC,CAAA,EAAA,IAAA;EACA,MAAA,CAAA;IAAA,OAAA;IAAA,OAAA;IAAA,QAAA;IAAA,WAAA;IAAA,eAAA;IAAA,aAAA;IAAA;EAAA,CAAA,EAGC,mBAHD,CAGqB,WAHrB,CAAA,CAAA,EAAA,IAAA;EACA,QAAA,gBAAA;EACA,QAAA,iBAAA;EACqB,QAAA,kBAAA;EAApB,QAAA,wBAAA;EA2KiB,gBAAA,CAAA,CAAA,EAAA,WAAA,GAAA,SAAA;EAAA,QAAA,kBAAA"}
1
+ {"version":3,"file":"FileDiff.d.ts","names":["options: FileDiffOptions<LAnnotation>","workerManager?: WorkerPoolManager | undefined"],"sources":["../../src/components/FileDiff.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;UA0DiB;aACJ;YACD;EAFZ,OAAiB,CAAA,EAGL,YAHK;EACJ,WAAA,CAAA,EAAA,OAAA;EACD,aAAA,CAAA,EAGM,WAHN;EACA,gBAAA,CAAA,EAGS,WAHT;EAEM,eAAA,CAAA,EAEE,kBAFF,CAEqB,WAFrB,CAAA,EAAA;EACG,WAAA,CAAA,EAEL,WAFK;;AACD,UAIH,sBAJG,CAAA,WAAA,CAAA,SAKV,IALU,CAKL,mBALK,CAKe,WALf,CAAA,EAAA,eAAA,CAAA,CAAA;EACJ,aAAA,EAKC,WALD;EAAA,eAAA,CAAA,EAAA,MAAA;AAGhB;AACmC,UAKlB,eALkB,CAAA,WAAA,CAAA,SAMzB,IANyB,CAMpB,eANoB,EAAA,gBAAA,CAAA,EAO/B,4BAP+B,CAAA,MAAA,CAAA,EAQ/B,oBAR+B,CAAA;EAApB,cAAA,CAAA,EAUT,OAVS,CAUD,cAVC,EAAA,QAAA,CAAA,GAAA,CAAA,CAAA,IAAA,EAYD,QAZC,EAAA,QAAA,EAaG,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