@git-diff-view/react 0.0.12 → 0.0.14

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 (79) hide show
  1. package/dist/cjs/index.development.js +57 -2158
  2. package/dist/cjs/index.development.js.map +1 -1
  3. package/dist/cjs/index.production.js +57 -2121
  4. package/dist/cjs/index.production.js.map +1 -1
  5. package/dist/css/diff-view.css +2 -2
  6. package/dist/esm/index.mjs +23 -2103
  7. package/dist/esm/index.mjs.map +1 -1
  8. package/index.d.ts +726 -1
  9. package/package.json +10 -6
  10. package/dist/types/components/DiffAddWidget.d.ts +0 -21
  11. package/dist/types/components/DiffAddWidget.d.ts.map +0 -1
  12. package/dist/types/components/DiffContent.d.ts +0 -11
  13. package/dist/types/components/DiffContent.d.ts.map +0 -1
  14. package/dist/types/components/DiffExpand.d.ts +0 -11
  15. package/dist/types/components/DiffExpand.d.ts.map +0 -1
  16. package/dist/types/components/DiffNoNewLine.d.ts +0 -3
  17. package/dist/types/components/DiffNoNewLine.d.ts.map +0 -1
  18. package/dist/types/components/DiffSplitExtendLineNormal.d.ts +0 -10
  19. package/dist/types/components/DiffSplitExtendLineNormal.d.ts.map +0 -1
  20. package/dist/types/components/DiffSplitExtendLineWrap.d.ts +0 -8
  21. package/dist/types/components/DiffSplitExtendLineWrap.d.ts.map +0 -1
  22. package/dist/types/components/DiffSplitHunkLineNormal.d.ts +0 -10
  23. package/dist/types/components/DiffSplitHunkLineNormal.d.ts.map +0 -1
  24. package/dist/types/components/DiffSplitHunkLineWrap.d.ts +0 -8
  25. package/dist/types/components/DiffSplitHunkLineWrap.d.ts.map +0 -1
  26. package/dist/types/components/DiffSplitLineNormal.d.ts +0 -10
  27. package/dist/types/components/DiffSplitLineNormal.d.ts.map +0 -1
  28. package/dist/types/components/DiffSplitLineWrap.d.ts +0 -8
  29. package/dist/types/components/DiffSplitLineWrap.d.ts.map +0 -1
  30. package/dist/types/components/DiffSplitView.d.ts +0 -6
  31. package/dist/types/components/DiffSplitView.d.ts.map +0 -1
  32. package/dist/types/components/DiffSplitViewLineNormal.d.ts +0 -9
  33. package/dist/types/components/DiffSplitViewLineNormal.d.ts.map +0 -1
  34. package/dist/types/components/DiffSplitViewLineWrap.d.ts +0 -7
  35. package/dist/types/components/DiffSplitViewLineWrap.d.ts.map +0 -1
  36. package/dist/types/components/DiffSplitViewNormal.d.ts +0 -6
  37. package/dist/types/components/DiffSplitViewNormal.d.ts.map +0 -1
  38. package/dist/types/components/DiffSplitViewWrap.d.ts +0 -6
  39. package/dist/types/components/DiffSplitViewWrap.d.ts.map +0 -1
  40. package/dist/types/components/DiffSplitWidgetLineNormal.d.ts +0 -10
  41. package/dist/types/components/DiffSplitWidgetLineNormal.d.ts.map +0 -1
  42. package/dist/types/components/DiffSplitWidgetLineWrap.d.ts +0 -8
  43. package/dist/types/components/DiffSplitWidgetLineWrap.d.ts.map +0 -1
  44. package/dist/types/components/DiffUnifiedExtendLine.d.ts +0 -8
  45. package/dist/types/components/DiffUnifiedExtendLine.d.ts.map +0 -1
  46. package/dist/types/components/DiffUnifiedHunkLine.d.ts +0 -8
  47. package/dist/types/components/DiffUnifiedHunkLine.d.ts.map +0 -1
  48. package/dist/types/components/DiffUnifiedLine.d.ts +0 -8
  49. package/dist/types/components/DiffUnifiedLine.d.ts.map +0 -1
  50. package/dist/types/components/DiffUnifiedView.d.ts +0 -6
  51. package/dist/types/components/DiffUnifiedView.d.ts.map +0 -1
  52. package/dist/types/components/DiffUnifiedWidgetLine.d.ts +0 -8
  53. package/dist/types/components/DiffUnifiedWidgetLine.d.ts.map +0 -1
  54. package/dist/types/components/DiffView.d.ts +0 -69
  55. package/dist/types/components/DiffView.d.ts.map +0 -1
  56. package/dist/types/components/DiffViewContext.d.ts +0 -42
  57. package/dist/types/components/DiffViewContext.d.ts.map +0 -1
  58. package/dist/types/components/DiffWidgetContext.d.ts +0 -24
  59. package/dist/types/components/DiffWidgetContext.d.ts.map +0 -1
  60. package/dist/types/components/color.d.ts +0 -35
  61. package/dist/types/components/color.d.ts.map +0 -1
  62. package/dist/types/components/tools.d.ts +0 -5
  63. package/dist/types/components/tools.d.ts.map +0 -1
  64. package/dist/types/hooks/useCallbackRef.d.ts +0 -2
  65. package/dist/types/hooks/useCallbackRef.d.ts.map +0 -1
  66. package/dist/types/hooks/useDomWidth.d.ts +0 -5
  67. package/dist/types/hooks/useDomWidth.d.ts.map +0 -1
  68. package/dist/types/hooks/useSafeLayout.d.ts +0 -3
  69. package/dist/types/hooks/useSafeLayout.d.ts.map +0 -1
  70. package/dist/types/hooks/useSyncHeight.d.ts +0 -6
  71. package/dist/types/hooks/useSyncHeight.d.ts.map +0 -1
  72. package/dist/types/hooks/useTextWidth.d.ts +0 -17
  73. package/dist/types/hooks/useTextWidth.d.ts.map +0 -1
  74. package/dist/types/hooks/useUnmount.d.ts +0 -2
  75. package/dist/types/hooks/useUnmount.d.ts.map +0 -1
  76. package/dist/types/index.d.ts +0 -4
  77. package/dist/types/index.d.ts.map +0 -1
  78. package/dist/types/index.withStyle.d.ts +0 -6
  79. package/dist/types/index.withStyle.d.ts.map +0 -1
@@ -1,9 +1,9 @@
1
1
  'use strict';
2
2
 
3
- var lowlight$1 = require('lowlight');
3
+ var core = require('@git-diff-view/core');
4
4
  var React = require('react');
5
5
  var reactivityStore = require('reactivity-store');
6
- var shim = require('use-sync-external-store/shim');
6
+ var index_js = require('use-sync-external-store/shim/index.js');
7
7
  var reactDom = require('react-dom');
8
8
 
9
9
  function _interopNamespaceDefault(e) {
@@ -54,678 +54,6 @@ function __rest(s, e) {
54
54
  return t;
55
55
  }
56
56
 
57
- function __classPrivateFieldGet$1(receiver, state, kind, f) {
58
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
59
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
60
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
61
- }
62
-
63
- function __classPrivateFieldSet$1(receiver, state, value, kind, f) {
64
- if (kind === "m") throw new TypeError("Private method is not writable");
65
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
66
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
67
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
68
- }
69
-
70
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
71
- var e = new Error(message);
72
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
73
- };
74
-
75
- exports.DiffHunkExpansionType = void 0;
76
- (function (DiffHunkExpansionType) {
77
- /** The hunk header cannot be expanded at all. */
78
- DiffHunkExpansionType["None"] = "None";
79
- /**
80
- * The hunk header can be expanded up exclusively. Only the first hunk can be
81
- * expanded up exclusively.
82
- */
83
- DiffHunkExpansionType["Up"] = "Up";
84
- /**
85
- * The hunk header can be expanded down exclusively. Only the last hunk (if
86
- * it's the dummy hunk with only one line) can be expanded down exclusively.
87
- */
88
- DiffHunkExpansionType["Down"] = "Down";
89
- /** The hunk header can be expanded both up and down. */
90
- DiffHunkExpansionType["Both"] = "Both";
91
- /**
92
- * The hunk header represents a short gap that, when expanded, will
93
- * result in merging this hunk and the hunk above.
94
- */
95
- DiffHunkExpansionType["Short"] = "Short";
96
- })(exports.DiffHunkExpansionType || (exports.DiffHunkExpansionType = {}));
97
- /** each diff is made up of a number of hunks */
98
- class DiffHunk {
99
- /**
100
- * @param header The details from the diff hunk header about the line start and patch length.
101
- * @param lines The contents - context and changes - of the diff section.
102
- * @param unifiedDiffStart The diff hunk's start position in the overall file diff.
103
- * @param unifiedDiffEnd The diff hunk's end position in the overall file diff.
104
- */
105
- constructor(header, lines, unifiedDiffStart, unifiedDiffEnd, expansionType) {
106
- this.header = header;
107
- this.lines = lines;
108
- this.unifiedDiffStart = unifiedDiffStart;
109
- this.unifiedDiffEnd = unifiedDiffEnd;
110
- this.expansionType = expansionType;
111
- }
112
- equals(other) {
113
- if (this === other) {
114
- return true;
115
- }
116
- return (this.header.equals(other.header) &&
117
- this.unifiedDiffStart === other.unifiedDiffStart &&
118
- this.unifiedDiffEnd === other.unifiedDiffEnd &&
119
- this.expansionType === other.expansionType &&
120
- this.lines.length === other.lines.length &&
121
- this.lines.every((xLine, ix) => xLine.equals(other.lines[ix])));
122
- }
123
- }
124
- /** details about the start and end of a diff hunk */
125
- class DiffHunkHeader {
126
- /**
127
- * @param oldStartLine The line in the old (or original) file where this diff hunk starts.
128
- * @param oldLineCount The number of lines in the old (or original) file that this diff hunk covers
129
- * @param newStartLine The line in the new file where this diff hunk starts.
130
- * @param newLineCount The number of lines in the new file that this diff hunk covers.
131
- */
132
- constructor(oldStartLine, oldLineCount, newStartLine, newLineCount) {
133
- this.oldStartLine = oldStartLine;
134
- this.oldLineCount = oldLineCount;
135
- this.newStartLine = newStartLine;
136
- this.newLineCount = newLineCount;
137
- }
138
- toDiffLineRepresentation() {
139
- return `@@ -${this.oldStartLine},${this.oldLineCount} +${this.newStartLine},${this.newLineCount} @@`;
140
- }
141
- equals(other) {
142
- return (this.oldStartLine === other.oldStartLine &&
143
- this.oldLineCount === other.oldLineCount &&
144
- this.newStartLine === other.newStartLine &&
145
- this.oldStartLine === other.oldStartLine);
146
- }
147
- }
148
-
149
- exports.NewLineSymbol = void 0;
150
- (function (NewLineSymbol) {
151
- NewLineSymbol[NewLineSymbol["CRLF"] = 1] = "CRLF";
152
- NewLineSymbol[NewLineSymbol["CR"] = 2] = "CR";
153
- NewLineSymbol[NewLineSymbol["LF"] = 3] = "LF";
154
- NewLineSymbol[NewLineSymbol["NEWLINE"] = 4] = "NEWLINE";
155
- })(exports.NewLineSymbol || (exports.NewLineSymbol = {}));
156
- const maxLength = 1000;
157
- /** Get the maximum position in the range. */
158
- function rangeMax(range) {
159
- return range.location + range.length;
160
- }
161
- /** Get the length of the common substring between the two strings. */
162
- function commonLength(stringA, rangeA, stringB, rangeB, reverse) {
163
- const max = Math.min(rangeA.length, rangeB.length);
164
- const startA = reverse ? rangeMax(rangeA) - 1 : rangeA.location;
165
- const startB = reverse ? rangeMax(rangeB) - 1 : rangeB.location;
166
- const stride = reverse ? -1 : 1;
167
- let length = 0;
168
- while (Math.abs(length) < max) {
169
- if (stringA[startA + length] !== stringB[startB + length]) {
170
- break;
171
- }
172
- length += stride;
173
- }
174
- return Math.abs(length);
175
- }
176
- function isInValidString(s) {
177
- return s.trim().length === 0 || s.length >= maxLength;
178
- }
179
- // TODO maybe could use the original content line
180
- /** Get the changed ranges in the strings, relative to each other. */
181
- function relativeChanges(addition, deletion) {
182
- const stringA = addition.text;
183
- const stringB = deletion.text;
184
- let bRange = { location: 0, length: stringB.length };
185
- let aRange = { location: 0, length: stringA.length };
186
- const _stringA = stringA.trimEnd();
187
- const _stringB = stringB.trimEnd();
188
- const aEndStr = stringA.slice(-2);
189
- const bEndStr = stringB.slice(-2);
190
- const hasNewLineChanged = addition.noTrailingNewLine !== deletion.noTrailingNewLine;
191
- const aSymbol = aEndStr === "\r\n" ? exports.NewLineSymbol.CRLF : aEndStr.endsWith("\r") ? exports.NewLineSymbol.CR : exports.NewLineSymbol.LF;
192
- const bSymbol = bEndStr === "\r\n" ? exports.NewLineSymbol.CRLF : bEndStr.endsWith("\r") ? exports.NewLineSymbol.CR : exports.NewLineSymbol.LF;
193
- if (_stringA === _stringB && (hasNewLineChanged || aSymbol !== bSymbol)) {
194
- return {
195
- stringARange: {
196
- location: _stringA.length,
197
- length: stringA.length - _stringA.length,
198
- newLineSymbol: hasNewLineChanged ? exports.NewLineSymbol.NEWLINE : aSymbol,
199
- },
200
- stringBRange: {
201
- location: _stringB.length,
202
- length: stringB.length - _stringB.length,
203
- newLineSymbol: hasNewLineChanged ? exports.NewLineSymbol.NEWLINE : bSymbol,
204
- },
205
- };
206
- }
207
- if (isInValidString(stringA) || isInValidString(stringB)) {
208
- aRange.length = 0;
209
- bRange.length = 0;
210
- return { stringARange: aRange, stringBRange: bRange };
211
- }
212
- const prefixLength = commonLength(stringB, bRange, stringA, aRange, false);
213
- bRange = {
214
- location: bRange.location + prefixLength,
215
- length: bRange.length - prefixLength,
216
- };
217
- aRange = {
218
- location: aRange.location + prefixLength,
219
- length: aRange.length - prefixLength,
220
- };
221
- const suffixLength = commonLength(stringB, bRange, stringA, aRange, true);
222
- bRange.length -= suffixLength;
223
- aRange.length -= suffixLength;
224
- return { stringARange: aRange, stringBRange: bRange };
225
- }
226
- /** Check two string have a diff range */
227
- function hasRelativeChange(addition, deletion) {
228
- const _stringA = addition.text.trim();
229
- const _stringB = deletion.text.trim();
230
- const _addition = addition.clone(_stringA);
231
- const _deletion = deletion.clone(_stringB);
232
- const { stringARange, stringBRange } = relativeChanges(_addition, _deletion);
233
- return (stringARange.location > 0 ||
234
- stringBRange.location > 0 ||
235
- stringARange.length < _stringA.length ||
236
- stringBRange.length < _stringB.length);
237
- }
238
-
239
- /** indicate what a line in the diff represents */
240
- exports.DiffLineType = void 0;
241
- (function (DiffLineType) {
242
- DiffLineType[DiffLineType["Context"] = 0] = "Context";
243
- DiffLineType[DiffLineType["Add"] = 1] = "Add";
244
- DiffLineType[DiffLineType["Delete"] = 2] = "Delete";
245
- DiffLineType[DiffLineType["Hunk"] = 3] = "Hunk";
246
- })(exports.DiffLineType || (exports.DiffLineType = {}));
247
- /** track details related to each line in the diff */
248
- class DiffLine {
249
- constructor(text, type,
250
- // Line number in the original diff patch (before expanding it), or null if
251
- // it was added as part of a diff expansion action.
252
- originalLineNumber, oldLineNumber, newLineNumber, noTrailingNewLine = false, needRematch = false, range) {
253
- this.text = text;
254
- this.type = type;
255
- this.originalLineNumber = originalLineNumber;
256
- this.oldLineNumber = oldLineNumber;
257
- this.newLineNumber = newLineNumber;
258
- this.noTrailingNewLine = noTrailingNewLine;
259
- this.needRematch = needRematch;
260
- this.range = range;
261
- }
262
- withNoTrailingNewLine(noTrailingNewLine) {
263
- return new DiffLine(this.text, this.type, this.originalLineNumber, this.oldLineNumber, this.newLineNumber, noTrailingNewLine);
264
- }
265
- isIncludeableLine() {
266
- return this.type === exports.DiffLineType.Add || this.type === exports.DiffLineType.Delete;
267
- }
268
- /** The content of the line, i.e., without the line type marker. */
269
- get content() {
270
- return this.text.substring(1);
271
- }
272
- equals(other) {
273
- return (this.text === other.text &&
274
- this.type === other.type &&
275
- this.originalLineNumber === other.originalLineNumber &&
276
- this.oldLineNumber === other.oldLineNumber &&
277
- this.newLineNumber === other.newLineNumber &&
278
- this.noTrailingNewLine === other.noTrailingNewLine);
279
- }
280
- clone(text) {
281
- return new DiffLine(text, this.type, this.originalLineNumber, this.oldLineNumber, this.newLineNumber);
282
- }
283
- }
284
- const checkDiffLineIncludeChange = (diffLine) => {
285
- if (!diffLine)
286
- return false;
287
- return diffLine.type === exports.DiffLineType.Add || diffLine.type === exports.DiffLineType.Delete;
288
- };
289
-
290
- /** How many new lines will be added to a diff hunk by default. */
291
- const DefaultDiffExpansionStep = 40;
292
- function assertNever(_, message) {
293
- throw new Error(message);
294
- }
295
- /** Utility function for getting the digit count of the largest line number in an array of diff hunks */
296
- function getLargestLineNumber(hunks) {
297
- var _a, _b;
298
- if (hunks.length === 0) {
299
- return 0;
300
- }
301
- for (let i = hunks.length - 1; i >= 0; i--) {
302
- const hunk = hunks[i];
303
- for (let j = hunk.lines.length - 1; j >= 0; j--) {
304
- const line = hunk.lines[j];
305
- if (line.type === exports.DiffLineType.Hunk) {
306
- continue;
307
- }
308
- const newLineNumber = (_a = line.newLineNumber) !== null && _a !== void 0 ? _a : 0;
309
- const oldLineNumber = (_b = line.oldLineNumber) !== null && _b !== void 0 ? _b : 0;
310
- return newLineNumber > oldLineNumber ? newLineNumber : oldLineNumber;
311
- }
312
- }
313
- return 0;
314
- }
315
- /**
316
- * Calculates whether or not a hunk header can be expanded up, down, both, or if
317
- * the space represented by the hunk header is short and expansion there would
318
- * mean merging with the hunk above.
319
- *
320
- * @param hunkIndex Index of the hunk to evaluate within the whole diff.
321
- * @param hunkHeader Header of the hunk to evaluate.
322
- * @param previousHunk Hunk previous to the one to evaluate. Null if the
323
- * evaluated hunk is the first one.
324
- */
325
- function getHunkHeaderExpansionType(hunkIndex, hunkHeader, previousHunk) {
326
- const distanceToPrevious = previousHunk === null
327
- ? Infinity
328
- : hunkHeader.oldStartLine - previousHunk.header.oldStartLine - previousHunk.header.oldLineCount;
329
- // In order to simplify the whole logic around expansion, only the hunk at the
330
- // top can be expanded up exclusively, and only the hunk at the bottom (the
331
- // dummy one, see getTextDiffWithBottomDummyHunk) can be expanded down
332
- // exclusively.
333
- // The rest of the hunks can be expanded both ways, except those which are too
334
- // short and therefore the direction of expansion doesn't matter.
335
- if (hunkIndex === 0) {
336
- // The top hunk can only be expanded if there is content above it
337
- if (hunkHeader.oldStartLine > 1 && hunkHeader.newStartLine > 1) {
338
- return exports.DiffHunkExpansionType.Up;
339
- }
340
- else {
341
- return exports.DiffHunkExpansionType.None;
342
- }
343
- }
344
- else if (distanceToPrevious <= DefaultDiffExpansionStep) {
345
- return exports.DiffHunkExpansionType.Short;
346
- }
347
- else {
348
- return exports.DiffHunkExpansionType.Both;
349
- }
350
- }
351
- const numIterator = (num, cb) => {
352
- const re = [];
353
- for (let i = 0; i < num; i++) {
354
- re.push(cb(i));
355
- }
356
- return re;
357
- };
358
- const getLang = (fileName) => {
359
- const dotIndex = fileName.lastIndexOf(".");
360
- const extension = fileName.slice(dotIndex + 1);
361
- return extension;
362
- };
363
- const getDiffRange = (additions, deletions) => {
364
- if (additions.length === deletions.length) {
365
- const len = additions.length;
366
- for (let i = 0; i < len; i++) {
367
- const addition = additions[i];
368
- const deletion = deletions[i];
369
- const hasDiffRange = hasRelativeChange(addition, deletion);
370
- if (hasDiffRange) {
371
- const { stringARange, stringBRange } = relativeChanges(addition, deletion);
372
- addition.needRematch = true;
373
- addition.range = stringARange;
374
- deletion.needRematch = true;
375
- deletion.range = stringBRange;
376
- }
377
- }
378
- }
379
- };
380
-
381
- /* eslint-disable max-lines */
382
- // !NOTE: ALL of the diff parse logic copy from desktop, SEE https://github.com/desktop/desktop
383
- // https://en.wikipedia.org/wiki/Diff_utility
384
- //
385
- // @@ -l,s +l,s @@ optional section heading
386
- //
387
- // The hunk range information contains two hunk ranges. The range for the hunk of the original
388
- // file is preceded by a minus symbol, and the range for the new file is preceded by a plus
389
- // symbol. Each hunk range is of the format l,s where l is the starting line number and s is
390
- // the number of lines the change hunk applies to for each respective file.
391
- //
392
- // In many versions of GNU diff, each range can omit the comma and trailing value s,
393
- // in which case s defaults to 1
394
- const diffHeaderRe = /^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/;
395
- /**
396
- * Regular expression matching invisible bidirectional Unicode characters that
397
- * may be interpreted or compiled differently than what it appears. More info:
398
- * https://github.co/hiddenchars
399
- */
400
- const HiddenBidiCharsRegex = /[\u202A-\u202E]|[\u2066-\u2069]/;
401
- const DiffPrefixAdd = "+";
402
- const DiffPrefixDelete = "-";
403
- const DiffPrefixContext = " ";
404
- const DiffPrefixNoNewline = "\\";
405
- const DiffLinePrefixChars = new Set([
406
- DiffPrefixAdd,
407
- DiffPrefixDelete,
408
- DiffPrefixContext,
409
- DiffPrefixNoNewline,
410
- ]);
411
- /**
412
- * A parser for the GNU unified diff format
413
- *
414
- * See https://www.gnu.org/software/diffutils/manual/html_node/Detailed-Unified.html
415
- */
416
- class DiffParser {
417
- constructor() {
418
- Object.defineProperty(this, "__v_skip", { value: true });
419
- this.reset();
420
- }
421
- /**
422
- * Resets the internal parser state so that it can be reused.
423
- *
424
- * This is done automatically at the end of each parse run.
425
- */
426
- reset() {
427
- this.ls = 0;
428
- this.le = -1;
429
- this.text = "";
430
- }
431
- /**
432
- * Aligns the internal character pointers at the boundaries of
433
- * the next line.
434
- *
435
- * Returns true if successful or false if the end of the diff
436
- * has been reached.
437
- */
438
- nextLine() {
439
- this.ls = this.le + 1;
440
- // We've reached the end of the diff
441
- if (this.ls >= this.text.length) {
442
- return false;
443
- }
444
- this.le = this.text.indexOf("\n", this.ls);
445
- // If we can't find the next newline character we'll put our
446
- // end pointer at the end of the diff string
447
- if (this.le === -1) {
448
- this.le = this.text.length;
449
- }
450
- // We've succeeded if there's anything to read in between the
451
- // start and the end
452
- return this.ls !== this.le;
453
- }
454
- /**
455
- * Advances to the next line and returns it as a substring
456
- * of the raw diff text. Returns null if end of diff was
457
- * reached.
458
- */
459
- readLine(header) {
460
- if (header) {
461
- return this.nextLine() ? this.text.substring(this.ls, this.le) : null;
462
- }
463
- else {
464
- return this.nextLine() ? this.text.substring(this.ls + 1, this.le + 1) : null;
465
- }
466
- }
467
- /** Tests if the current line starts with the given search text */
468
- lineStartsWith(searchString) {
469
- return this.text.startsWith(searchString, this.ls);
470
- }
471
- /** Tests if the current line ends with the given search text */
472
- lineEndsWith(searchString) {
473
- return this.text.endsWith(searchString, this.le);
474
- }
475
- /**
476
- * Returns the starting character of the next line without
477
- * advancing the internal state. Returns null if advancing
478
- * would mean reaching the end of the diff.
479
- */
480
- peek() {
481
- const p = this.le + 1;
482
- return p < this.text.length ? this.text[p] : null;
483
- }
484
- /**
485
- * Parse the diff header, meaning everything from the
486
- * start of the diff output to the end of the line beginning
487
- * with +++
488
- *
489
- * Example diff header:
490
- *
491
- * diff --git a/app/src/lib/diff-parser.ts b/app/src/lib/diff-parser.ts
492
- * index e1d4871..3bd3ee0 100644
493
- * --- a/app/src/lib/diff-parser.ts
494
- * +++ b/app/src/lib/diff-parser.ts
495
- *
496
- * Returns an object with information extracted from the diff
497
- * header (currently whether it's a binary patch) or null if
498
- * the end of the diff was reached before the +++ line could be
499
- * found (which is a valid state).
500
- */
501
- parseDiffHeader() {
502
- // TODO: There's information in here that we might want to
503
- // capture, such as mode changes
504
- while (this.nextLine()) {
505
- if (this.lineStartsWith("Binary files ") && this.lineEndsWith("differ")) {
506
- return { isBinary: true };
507
- }
508
- if (this.lineStartsWith("+++")) {
509
- return { isBinary: false };
510
- }
511
- }
512
- // It's not an error to not find the +++ line, see the
513
- // 'parses diff of empty file' test in diff-parser-tests.ts
514
- return null;
515
- }
516
- /**
517
- * Attempts to convert a RegExp capture group into a number.
518
- * If the group doesn't exist or wasn't captured the function
519
- * will return the value of the defaultValue parameter or throw
520
- * an error if no default value was provided. If the captured
521
- * string can't be converted to a number an error will be thrown.
522
- */
523
- numberFromGroup(m, group, defaultValue = null) {
524
- const str = m[group];
525
- if (!str) {
526
- if (!defaultValue) {
527
- throw new Error(`Group ${group} missing from regexp match and no defaultValue was provided`);
528
- }
529
- return defaultValue;
530
- }
531
- const num = parseInt(str, 10);
532
- if (isNaN(num)) {
533
- throw new Error(`Could not parse capture group ${group} into number: ${str}`);
534
- }
535
- return num;
536
- }
537
- /**
538
- * Parses a hunk header or throws an error if the given line isn't
539
- * a well-formed hunk header.
540
- *
541
- * We currently only extract the line number information and
542
- * ignore any hunk headings.
543
- *
544
- * Example hunk header (text within ``):
545
- *
546
- * `@@ -84,10 +82,8 @@ export function parseRawDiff(lines: ReadonlyArray<string>): Diff {`
547
- *
548
- * Where everything after the last @@ is what's known as the hunk, or section, heading
549
- */
550
- parseHunkHeader(line) {
551
- const m = diffHeaderRe.exec(line);
552
- if (!m) {
553
- throw new Error(`Invalid hunk header format`);
554
- }
555
- // If endLines are missing default to 1, see diffHeaderRe docs
556
- const oldStartLine = this.numberFromGroup(m, 1);
557
- const oldLineCount = this.numberFromGroup(m, 2, 1);
558
- const newStartLine = this.numberFromGroup(m, 3);
559
- const newLineCount = this.numberFromGroup(m, 4, 1);
560
- return new DiffHunkHeader(oldStartLine, oldLineCount, newStartLine, newLineCount);
561
- }
562
- /**
563
- * Convenience function which lets us leverage the type system to
564
- * prove exhaustive checks in parseHunk.
565
- *
566
- * Takes an arbitrary string and checks to see if the first character
567
- * of that string is one of the allowed prefix characters for diff
568
- * lines (ie lines in between hunk headers).
569
- */
570
- parseLinePrefix(c) {
571
- // Since we know that DiffLinePrefixChars and the DiffLinePrefix type
572
- // include the same characters we can tell the type system that we
573
- // now know that c[0] is one of the characters in the DifflinePrefix set
574
- if (c && c.length && DiffLinePrefixChars.has(c[0])) {
575
- return c[0];
576
- }
577
- return null;
578
- }
579
- /**
580
- * Parses a hunk, including its header or throws an error if the diff doesn't
581
- * contain a well-formed diff hunk at the current position.
582
- *
583
- * Expects that the position has been advanced to the beginning of a presumed
584
- * diff hunk header.
585
- *
586
- * @param linesConsumed The number of unified diff lines consumed up until
587
- * this point by the diff parser. Used to give the
588
- * position and length (in lines) of the parsed hunk
589
- * relative to the overall parsed diff. These numbers
590
- * have no real meaning in the context of a diff and
591
- * are only used to aid the app in line-selections.
592
- */
593
- parseHunk(linesConsumed, hunkIndex, previousHunk) {
594
- const headerLine = this.readLine(true);
595
- if (!headerLine) {
596
- throw new Error("Expected hunk header but reached end of diff");
597
- }
598
- const header = this.parseHunkHeader(headerLine);
599
- const lines = new Array();
600
- lines.push(new DiffLine(headerLine, exports.DiffLineType.Hunk, 1, null, null));
601
- let c;
602
- let rollingDiffBeforeCounter = header.oldStartLine;
603
- let rollingDiffAfterCounter = header.newStartLine;
604
- let diffLineNumber = linesConsumed;
605
- while ((c = this.parseLinePrefix(this.peek()))) {
606
- const line = this.readLine(false);
607
- diffLineNumber++;
608
- if (!line) {
609
- throw new Error("Expected unified diff line but reached end of diff");
610
- }
611
- // A marker indicating that the last line in the original or the new file
612
- // is missing a trailing newline. In other words, the presence of this marker
613
- // means that the new and/or original file lacks a trailing newline.
614
- //
615
- // When we find it we have to look up the previous line and set the
616
- // noTrailingNewLine flag
617
- if (c === DiffPrefixNoNewline) {
618
- // See https://github.com/git/git/blob/21f862b498925194f8f1ebe8203b7a7df756555b/apply.c#L1725-L1732
619
- if (line.length < 12) {
620
- throw new Error(`Expected "no newline at end of file" marker to be at least 12 bytes long`);
621
- }
622
- const previousLineIndex = lines.length - 1;
623
- const previousLine = lines[previousLineIndex];
624
- lines[previousLineIndex] = previousLine.withNoTrailingNewLine(true);
625
- continue;
626
- }
627
- let diffLine;
628
- if (c === DiffPrefixAdd) {
629
- diffLine = new DiffLine(line, exports.DiffLineType.Add, diffLineNumber, null, rollingDiffAfterCounter++);
630
- }
631
- else if (c === DiffPrefixDelete) {
632
- diffLine = new DiffLine(line, exports.DiffLineType.Delete, diffLineNumber, rollingDiffBeforeCounter++, null);
633
- }
634
- else if (c === DiffPrefixContext) {
635
- diffLine = new DiffLine(line, exports.DiffLineType.Context, diffLineNumber, rollingDiffBeforeCounter++, rollingDiffAfterCounter++);
636
- }
637
- else {
638
- return assertNever(c, `Unknown DiffLinePrefix: ${c}`);
639
- }
640
- lines.push(diffLine);
641
- }
642
- if (lines.length === 1) {
643
- throw new Error("Malformed diff, empty hunk");
644
- }
645
- return new DiffHunk(header, lines, linesConsumed, linesConsumed + lines.length - 1, getHunkHeaderExpansionType(hunkIndex, header, previousHunk));
646
- }
647
- /**
648
- * Parse a well-formed unified diff into hunks and lines.
649
- *
650
- * @param text A unified diff produced by git diff, git log --patch
651
- * or any other git plumbing command that produces unified
652
- * diffs.
653
- */
654
- parse(text) {
655
- this.text = text;
656
- try {
657
- const headerInfo = this.parseDiffHeader();
658
- const headerEnd = this.le;
659
- const header = this.text.substring(0, headerEnd);
660
- // empty diff
661
- if (!headerInfo) {
662
- return {
663
- header,
664
- contents: "",
665
- hunks: [],
666
- isBinary: false,
667
- maxLineNumber: 0,
668
- hasHiddenBidiChars: false,
669
- };
670
- }
671
- if (headerInfo.isBinary) {
672
- return {
673
- header,
674
- contents: "",
675
- hunks: [],
676
- isBinary: true,
677
- maxLineNumber: 0,
678
- hasHiddenBidiChars: false,
679
- };
680
- }
681
- const hunks = new Array();
682
- let linesConsumed = 0;
683
- let previousHunk = null;
684
- do {
685
- const hunk = this.parseHunk(linesConsumed, hunks.length, previousHunk);
686
- hunks.push(hunk);
687
- previousHunk = hunk;
688
- linesConsumed += hunk.lines.length;
689
- } while (this.peek());
690
- const contents = this.text
691
- .substring(headerEnd + 1, this.le)
692
- // Note that this simply returns a reference to the
693
- // substring if no match is found, it does not create
694
- // a new string instance.
695
- .replace(/\n\/g, "");
696
- return {
697
- header,
698
- contents,
699
- hunks,
700
- isBinary: headerInfo.isBinary,
701
- maxLineNumber: getLargestLineNumber(hunks),
702
- hasHiddenBidiChars: HiddenBidiCharsRegex.test(text),
703
- };
704
- }
705
- finally {
706
- this.reset();
707
- }
708
- }
709
- }
710
- const parseInstance = new DiffParser();
711
-
712
- /******************************************************************************
713
- Copyright (c) Microsoft Corporation.
714
-
715
- Permission to use, copy, modify, and/or distribute this software for any
716
- purpose with or without fee is hereby granted.
717
-
718
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
719
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
720
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
721
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
722
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
723
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
724
- PERFORMANCE OF THIS SOFTWARE.
725
- ***************************************************************************** */
726
- /* global Reflect, Promise, SuppressedError, Symbol */
727
-
728
-
729
57
  function __classPrivateFieldGet(receiver, state, kind, f) {
730
58
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
731
59
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
@@ -744,1413 +72,6 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
744
72
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
745
73
  };
746
74
 
747
- const processAST = (ast) => {
748
- let lineNumber = 1;
749
- const syntaxObj = {};
750
- const loopAST = (nodes, wrapper) => {
751
- nodes.forEach((node) => {
752
- if (node.type === "text") {
753
- if (node.value.indexOf("\n") === -1) {
754
- const valueLength = node.value.length;
755
- if (!syntaxObj[lineNumber]) {
756
- node.startIndex = 0;
757
- node.endIndex = valueLength - 1;
758
- const item = {
759
- value: node.value,
760
- lineNumber,
761
- valueLength,
762
- nodeList: [{ node, wrapper }],
763
- };
764
- syntaxObj[lineNumber] = item;
765
- }
766
- else {
767
- node.startIndex = syntaxObj[lineNumber].valueLength;
768
- node.endIndex = node.startIndex + valueLength - 1;
769
- syntaxObj[lineNumber].value += node.value;
770
- syntaxObj[lineNumber].valueLength += valueLength;
771
- syntaxObj[lineNumber].nodeList.push({ node, wrapper });
772
- }
773
- node.lineNumber = lineNumber;
774
- return;
775
- }
776
- const lines = node.value.split("\n");
777
- node.children = node.children || [];
778
- for (let i = 0; i < lines.length; i++) {
779
- const _value = i === lines.length - 1 ? lines[i] : lines[i] + "\n";
780
- const _lineNumber = i === 0 ? lineNumber : ++lineNumber;
781
- const _valueLength = _value.length;
782
- const _node = {
783
- type: "text",
784
- value: _value,
785
- startIndex: Infinity,
786
- endIndex: Infinity,
787
- lineNumber: _lineNumber,
788
- };
789
- if (!syntaxObj[_lineNumber]) {
790
- _node.startIndex = 0;
791
- _node.endIndex = _valueLength - 1;
792
- const item = {
793
- value: _value,
794
- lineNumber: _lineNumber,
795
- valueLength: _valueLength,
796
- nodeList: [{ node: _node, wrapper }],
797
- };
798
- syntaxObj[_lineNumber] = item;
799
- }
800
- else {
801
- _node.startIndex = syntaxObj[_lineNumber].valueLength;
802
- _node.endIndex = _node.startIndex + _valueLength - 1;
803
- syntaxObj[_lineNumber].value += _value;
804
- syntaxObj[_lineNumber].valueLength += _valueLength;
805
- syntaxObj[_lineNumber].nodeList.push({ node: _node, wrapper });
806
- }
807
- node.children.push(_node);
808
- }
809
- node.lineNumber = lineNumber;
810
- return;
811
- }
812
- if (node.children) {
813
- loopAST(node.children, node);
814
- node.lineNumber = lineNumber;
815
- }
816
- });
817
- };
818
- loopAST(ast.children);
819
- return { syntaxFileObject: syntaxObj, syntaxFileLineNumber: lineNumber };
820
- };
821
-
822
- const lowlight = lowlight$1.createLowlight(lowlight$1.all);
823
- // !SEE https://github.com/highlightjs/highlightjs-vue
824
- lowlight.register("vue", function hljsDefineVue(hljs) {
825
- return {
826
- subLanguage: "xml",
827
- contains: [
828
- hljs.COMMENT("<!--", "-->", {
829
- relevance: 10,
830
- }),
831
- {
832
- begin: /^(\s*)(<script>)/gm,
833
- end: /^(\s*)(<\/script>)/gm,
834
- subLanguage: "javascript",
835
- excludeBegin: true,
836
- excludeEnd: true,
837
- },
838
- {
839
- begin: /^(?:\s*)(?:<script\s+lang=(["'])ts\1>)/gm,
840
- end: /^(\s*)(<\/script>)/gm,
841
- subLanguage: "typescript",
842
- excludeBegin: true,
843
- excludeEnd: true,
844
- },
845
- {
846
- begin: /^(\s*)(<style(\s+scoped)?>)/gm,
847
- end: /^(\s*)(<\/style>)/gm,
848
- subLanguage: "css",
849
- excludeBegin: true,
850
- excludeEnd: true,
851
- },
852
- {
853
- begin: /^(?:\s*)(?:<style(?:\s+scoped)?\s+lang=(["'])(?:s[ca]ss)\1(?:\s+scoped)?>)/gm,
854
- end: /^(\s*)(<\/style>)/gm,
855
- subLanguage: "scss",
856
- excludeBegin: true,
857
- excludeEnd: true,
858
- },
859
- {
860
- begin: /^(?:\s*)(?:<style(?:\s+scoped)?\s+lang=(["'])stylus\1(?:\s+scoped)?>)/gm,
861
- end: /^(\s*)(<\/style>)/gm,
862
- subLanguage: "stylus",
863
- excludeBegin: true,
864
- excludeEnd: true,
865
- },
866
- ],
867
- };
868
- });
869
- const instance = { name: "lowlight" };
870
- let _maxLineToIgnoreSyntax = 2000;
871
- const _ignoreSyntaxHighlightList = [];
872
- Object.defineProperty(instance, "maxLineToIgnoreSyntax", {
873
- get: () => _maxLineToIgnoreSyntax,
874
- });
875
- Object.defineProperty(instance, "setMaxLineToIgnoreSyntax", {
876
- value: (v) => {
877
- _maxLineToIgnoreSyntax = v;
878
- },
879
- });
880
- Object.defineProperty(instance, "ignoreSyntaxHighlightList", {
881
- get: () => _ignoreSyntaxHighlightList,
882
- });
883
- Object.defineProperty(instance, "setIgnoreSyntaxHighlightList", {
884
- value: (v) => {
885
- _ignoreSyntaxHighlightList.length = 0;
886
- _ignoreSyntaxHighlightList.push(...v);
887
- },
888
- });
889
- Object.defineProperty(instance, "getAST", {
890
- value: (raw, fileName, lang) => {
891
- let hasRegisteredLang = true;
892
- if (!lowlight.registered(lang)) {
893
- console.warn(`not support current lang: ${lang} yet`);
894
- hasRegisteredLang = false;
895
- }
896
- if (fileName &&
897
- highlighter.ignoreSyntaxHighlightList.some((item) => item instanceof RegExp ? item.test(fileName) : fileName === item)) {
898
- console.warn(`ignore syntax for current file, because the fileName is in the ignoreSyntaxHighlightList: ${fileName}`);
899
- return;
900
- }
901
- if (hasRegisteredLang) {
902
- return lowlight.highlight(lang, raw);
903
- }
904
- else {
905
- return lowlight.highlightAuto(raw);
906
- }
907
- },
908
- });
909
- Object.defineProperty(instance, "processAST", {
910
- value: (ast) => {
911
- return processAST(ast);
912
- },
913
- });
914
- Object.defineProperty(instance, "hasRegisteredCurrentLang", {
915
- value: (lang) => {
916
- return lowlight.registered(lang);
917
- },
918
- });
919
- const highlighter = instance;
920
-
921
- var _Cache_keyArray, _Cache_maxLength;
922
- class Cache extends Map {
923
- constructor() {
924
- super(...arguments);
925
- _Cache_keyArray.set(this, []);
926
- _Cache_maxLength.set(this, 30);
927
- }
928
- setMaxLength(length) {
929
- __classPrivateFieldSet(this, _Cache_maxLength, length, "f");
930
- this._checkLength();
931
- }
932
- set(key, value) {
933
- if (this.has(key))
934
- return this;
935
- __classPrivateFieldGet(this, _Cache_keyArray, "f").push(key);
936
- this._checkLength();
937
- return super.set(key, value);
938
- }
939
- _checkLength() {
940
- while (__classPrivateFieldGet(this, _Cache_keyArray, "f").length > __classPrivateFieldGet(this, _Cache_maxLength, "f")) {
941
- const key = __classPrivateFieldGet(this, _Cache_keyArray, "f").shift();
942
- this.delete(key);
943
- }
944
- }
945
- }
946
- _Cache_keyArray = new WeakMap(), _Cache_maxLength = new WeakMap();
947
-
948
- var _File_instances, _File_doCheck;
949
- const map = new Cache();
950
- const devKey = "@git-diff-cache";
951
- map.setMaxLength(50);
952
- map.name = "@git-diff-view/core";
953
- if (typeof globalThis !== "undefined") {
954
- if (Array.isArray(globalThis[devKey])) {
955
- globalThis[devKey] = globalThis[devKey].filter((i) => i !== map);
956
- if (globalThis[devKey].length > 0) {
957
- console.warn("there are multiple instance of @git-diff-view/core in the one environment!");
958
- }
959
- globalThis[devKey].push(map);
960
- }
961
- else {
962
- globalThis[devKey] = [map];
963
- }
964
- }
965
- class File {
966
- static createInstance(data) {
967
- const file = new File(data === null || data === void 0 ? void 0 : data.raw, data === null || data === void 0 ? void 0 : data.lang, data === null || data === void 0 ? void 0 : data.fileName);
968
- file.ast = data === null || data === void 0 ? void 0 : data.ast;
969
- file.rawFile = data === null || data === void 0 ? void 0 : data.rawFile;
970
- file.hasDoRaw = data === null || data === void 0 ? void 0 : data.hasDoRaw;
971
- file.rawLength = data === null || data === void 0 ? void 0 : data.rawLength;
972
- file.syntaxFile = data === null || data === void 0 ? void 0 : data.syntaxFile;
973
- file.hasDoSyntax = data === null || data === void 0 ? void 0 : data.hasDoSyntax;
974
- file.syntaxLength = data === null || data === void 0 ? void 0 : data.syntaxLength;
975
- file.highlighterName = data === null || data === void 0 ? void 0 : data.highlighterName;
976
- file.maxLineNumber = data === null || data === void 0 ? void 0 : data.maxLineNumber;
977
- return file;
978
- }
979
- constructor(raw, lang, fileName) {
980
- _File_instances.add(this);
981
- this.raw = raw;
982
- this.lang = lang;
983
- this.fileName = fileName;
984
- this.rawFile = {};
985
- this.hasDoRaw = false;
986
- this.syntaxFile = {};
987
- this.hasDoSyntax = false;
988
- this.maxLineNumber = 0;
989
- Object.defineProperty(this, "__v_skip", { value: true });
990
- }
991
- doSyntax({ registerHighlighter }) {
992
- if (!this.raw || this.hasDoSyntax)
993
- return;
994
- const _highlighter = registerHighlighter || highlighter;
995
- if (this.syntaxLength) {
996
- console.error("current file already doSyntax before!");
997
- return;
998
- }
999
- if (this.rawLength > _highlighter.maxLineToIgnoreSyntax) {
1000
- console.warn(`ignore syntax for current file, because the rawLength is too long: ${this.rawLength}`);
1001
- return;
1002
- }
1003
- this.ast = _highlighter.getAST(this.raw, this.fileName, this.lang);
1004
- if (!this.ast)
1005
- return;
1006
- const { syntaxFileObject, syntaxFileLineNumber } = _highlighter.processAST(this.ast);
1007
- this.syntaxFile = syntaxFileObject;
1008
- this.syntaxLength = syntaxFileLineNumber;
1009
- this.highlighterName = _highlighter.name;
1010
- {
1011
- __classPrivateFieldGet(this, _File_instances, "m", _File_doCheck).call(this);
1012
- }
1013
- this.hasDoSyntax = true;
1014
- }
1015
- doRaw() {
1016
- if (!this.raw || this.hasDoRaw)
1017
- return;
1018
- const rawString = this.raw;
1019
- const rawArray = rawString.split("\n");
1020
- this.rawLength = rawArray.length;
1021
- this.maxLineNumber = rawArray.length;
1022
- this.rawFile = {};
1023
- for (let i = 0; i < rawArray.length; i++) {
1024
- this.rawFile[i + 1] = i < rawArray.length - 1 ? rawArray[i] + "\n" : rawArray[i];
1025
- }
1026
- // reduce 对于大数组性能很差
1027
- // this.rawFile = rawArray.reduce(
1028
- // (p, item, index) => ({
1029
- // ...p,
1030
- // [index + 1]: index < rawArray.length - 1 ? item + "\n" : item,
1031
- // }),
1032
- // {}
1033
- // );
1034
- this.hasDoRaw = true;
1035
- }
1036
- }
1037
- _File_instances = new WeakSet(), _File_doCheck = function _File_doCheck() {
1038
- if (this.rawLength && this.syntaxLength) {
1039
- if (this.rawLength !== this.syntaxLength) {
1040
- console.warn("the rawLength not match for the syntaxLength");
1041
- }
1042
- Object.values(this.syntaxFile).forEach(({ value, lineNumber }) => {
1043
- if (value !== this.rawFile[lineNumber]) {
1044
- console.log("some line not match:" + value + " __ " + this.rawFile[lineNumber] + " __ at: " + lineNumber + " lineNumber");
1045
- }
1046
- });
1047
- }
1048
- };
1049
- const getFile = (raw, lang, fileName) => {
1050
- const key = raw + "--" + "0.0.12" + "--" + lang;
1051
- if (map.has(key))
1052
- return map.get(key);
1053
- const file = new File(raw, lang, fileName);
1054
- map.set(key, file);
1055
- return file;
1056
- };
1057
- const _cacheMap = map;
1058
-
1059
- var _DiffFile_instances, _DiffFile_oldFileResult, _DiffFile_newFileResult, _DiffFile_diffListResults, _DiffFile_diffLines, _DiffFile_oldFileDiffLines, _DiffFile_newFileDiffLines, _DiffFile_oldFileLines, _DiffFile_newFileLines, _DiffFile_oldFileSyntaxLines, _DiffFile_newFileSyntaxLines, _DiffFile_oldFilePlaceholderLines, _DiffFile_newFilePlaceholderLines, _DiffFile_splitLeftLines, _DiffFile_splitRightLines, _DiffFile_splitHunksLines, _DiffFile_unifiedLines, _DiffFile_unifiedHunksLines, _DiffFile_listeners, _DiffFile_hasInitRaw, _DiffFile_hasInitSyntax, _DiffFile_hasBuildSplit, _DiffFile_hasBuildUnified, _DiffFile_updateCount, _DiffFile_composeByDiff, _DiffFile_composeByMerge, _DiffFile_composeByFullMerge, _DiffFile_highlighterName, _DiffFile_id, _DiffFile_clonedInstance, _DiffFile_doDiff, _DiffFile_doFile, _DiffFile_composeRaw, _DiffFile_composeFile, _DiffFile_composeDiff, _DiffFile_composeSyntax, _DiffFile_getOldDiffLine, _DiffFile_getNewDiffLine, _DiffFile_getOldRawLine, _DiffFile_getNewRawLine;
1060
- const composeLen = 40;
1061
- const idSet = new Set();
1062
- class DiffFile {
1063
- static createInstance(data, bundle) {
1064
- var _a, _b, _c, _d, _e, _f;
1065
- const instance = new DiffFile(((_a = data === null || data === void 0 ? void 0 : data.oldFile) === null || _a === void 0 ? void 0 : _a.fileName) || "", ((_b = data === null || data === void 0 ? void 0 : data.oldFile) === null || _b === void 0 ? void 0 : _b.content) || "", ((_c = data === null || data === void 0 ? void 0 : data.newFile) === null || _c === void 0 ? void 0 : _c.fileName) || "", ((_d = data === null || data === void 0 ? void 0 : data.newFile) === null || _d === void 0 ? void 0 : _d.content) || "", (data === null || data === void 0 ? void 0 : data.hunks) || [], ((_e = data === null || data === void 0 ? void 0 : data.oldFile) === null || _e === void 0 ? void 0 : _e.fileLang) || "", ((_f = data === null || data === void 0 ? void 0 : data.newFile) === null || _f === void 0 ? void 0 : _f.fileLang) || "");
1066
- if (bundle) {
1067
- if (bundle.isFullMerge) {
1068
- instance._mergeFullBundle(bundle);
1069
- }
1070
- else {
1071
- instance.mergeBundle(bundle);
1072
- }
1073
- }
1074
- return instance;
1075
- }
1076
- constructor(_oldFileName, _oldFileContent, _newFileName, _newFileContent, _diffList, _oldFileLang, _newFileLang) {
1077
- _DiffFile_instances.add(this);
1078
- this._oldFileName = _oldFileName;
1079
- this._newFileName = _newFileName;
1080
- this._diffList = _diffList;
1081
- _DiffFile_oldFileResult.set(this, void 0);
1082
- _DiffFile_newFileResult.set(this, void 0);
1083
- _DiffFile_diffListResults.set(this, void 0);
1084
- _DiffFile_diffLines.set(this, void 0);
1085
- _DiffFile_oldFileDiffLines.set(this, void 0);
1086
- _DiffFile_newFileDiffLines.set(this, void 0);
1087
- _DiffFile_oldFileLines.set(this, void 0);
1088
- _DiffFile_newFileLines.set(this, void 0);
1089
- _DiffFile_oldFileSyntaxLines.set(this, void 0);
1090
- _DiffFile_newFileSyntaxLines.set(this, void 0);
1091
- _DiffFile_oldFilePlaceholderLines.set(this, void 0);
1092
- _DiffFile_newFilePlaceholderLines.set(this, void 0);
1093
- _DiffFile_splitLeftLines.set(this, []);
1094
- _DiffFile_splitRightLines.set(this, []);
1095
- _DiffFile_splitHunksLines.set(this, void 0);
1096
- _DiffFile_unifiedLines.set(this, []);
1097
- _DiffFile_unifiedHunksLines.set(this, void 0);
1098
- _DiffFile_listeners.set(this, []);
1099
- _DiffFile_hasInitRaw.set(this, false);
1100
- _DiffFile_hasInitSyntax.set(this, false);
1101
- _DiffFile_hasBuildSplit.set(this, false);
1102
- _DiffFile_hasBuildUnified.set(this, false);
1103
- _DiffFile_updateCount.set(this, 0);
1104
- _DiffFile_composeByDiff.set(this, false);
1105
- _DiffFile_composeByMerge.set(this, false);
1106
- _DiffFile_composeByFullMerge.set(this, false);
1107
- _DiffFile_highlighterName.set(this, void 0);
1108
- this._version_ = "0.0.12";
1109
- this._oldFileContent = "";
1110
- this._oldFileLang = "";
1111
- this._newFileContent = "";
1112
- this._newFileLang = "";
1113
- this.diffLineLength = 0;
1114
- this.splitLineLength = 0;
1115
- this.unifiedLineLength = 0;
1116
- this.hasExpandSplitAll = false;
1117
- this.hasExpandUnifiedAll = false;
1118
- this.hasSomeLineCollapsed = false;
1119
- _DiffFile_id.set(this, "");
1120
- _DiffFile_clonedInstance.set(this, new Map());
1121
- this.getSplitLeftLine = (index) => {
1122
- return __classPrivateFieldGet(this, _DiffFile_splitLeftLines, "f")[index];
1123
- };
1124
- this.getSplitRightLine = (index) => {
1125
- return __classPrivateFieldGet(this, _DiffFile_splitRightLines, "f")[index];
1126
- };
1127
- this.getSplitHunkLine = (index) => {
1128
- var _a;
1129
- return (_a = __classPrivateFieldGet(this, _DiffFile_splitHunksLines, "f")) === null || _a === void 0 ? void 0 : _a[index];
1130
- };
1131
- this.onSplitHunkExpand = (dir, index, needTrigger = true) => {
1132
- var _a, _b;
1133
- const current = (_a = __classPrivateFieldGet(this, _DiffFile_splitHunksLines, "f")) === null || _a === void 0 ? void 0 : _a[index];
1134
- if (!current || !current.splitInfo)
1135
- return;
1136
- if (__classPrivateFieldGet(this, _DiffFile_composeByDiff, "f"))
1137
- return;
1138
- if (dir === "all") {
1139
- for (let i = current.splitInfo.startHiddenIndex; i < current.splitInfo.endHiddenIndex; i++) {
1140
- const leftLine = __classPrivateFieldGet(this, _DiffFile_splitLeftLines, "f")[i];
1141
- const rightLine = __classPrivateFieldGet(this, _DiffFile_splitRightLines, "f")[i];
1142
- if (leftLine === null || leftLine === void 0 ? void 0 : leftLine.isHidden)
1143
- leftLine.isHidden = false;
1144
- if (rightLine === null || rightLine === void 0 ? void 0 : rightLine.isHidden)
1145
- rightLine.isHidden = false;
1146
- }
1147
- current.splitInfo = Object.assign(Object.assign(Object.assign({}, current.splitInfo), current.hunkInfo), { plainText: current.text, startHiddenIndex: current.splitInfo.endHiddenIndex });
1148
- }
1149
- else if (dir === "down") {
1150
- for (let i = current.splitInfo.startHiddenIndex; i < current.splitInfo.startHiddenIndex + composeLen; i++) {
1151
- const leftLine = __classPrivateFieldGet(this, _DiffFile_splitLeftLines, "f")[i];
1152
- const rightLine = __classPrivateFieldGet(this, _DiffFile_splitRightLines, "f")[i];
1153
- if (leftLine === null || leftLine === void 0 ? void 0 : leftLine.isHidden)
1154
- leftLine.isHidden = false;
1155
- if (rightLine === null || rightLine === void 0 ? void 0 : rightLine.isHidden)
1156
- rightLine.isHidden = false;
1157
- }
1158
- if (current.isLast) {
1159
- current.splitInfo = Object.assign(Object.assign({}, current.splitInfo), { startHiddenIndex: current.splitInfo.startHiddenIndex + composeLen });
1160
- }
1161
- else {
1162
- current.splitInfo = Object.assign(Object.assign({}, current.splitInfo), { startHiddenIndex: current.splitInfo.startHiddenIndex + composeLen, plainText: `@@ -${current.splitInfo.oldStartIndex},${current.splitInfo.oldLength} +${current.splitInfo.newStartIndex},${current.splitInfo.newLength}` });
1163
- }
1164
- }
1165
- else {
1166
- if (current.isLast) {
1167
- console.error("the last hunk can not expand up!");
1168
- return;
1169
- }
1170
- for (let i = current.splitInfo.endHiddenIndex - composeLen; i < current.splitInfo.endHiddenIndex; i++) {
1171
- const leftLine = __classPrivateFieldGet(this, _DiffFile_splitLeftLines, "f")[i];
1172
- const rightLine = __classPrivateFieldGet(this, _DiffFile_splitRightLines, "f")[i];
1173
- if (leftLine === null || leftLine === void 0 ? void 0 : leftLine.isHidden)
1174
- leftLine.isHidden = false;
1175
- if (rightLine === null || rightLine === void 0 ? void 0 : rightLine.isHidden)
1176
- rightLine.isHidden = false;
1177
- }
1178
- const oldStartIndex = current.splitInfo.oldStartIndex - composeLen;
1179
- const oldLength = current.splitInfo.oldLength + composeLen;
1180
- const newStartIndex = current.splitInfo.newStartIndex - composeLen;
1181
- const newLength = current.splitInfo.newLength + composeLen;
1182
- current.splitInfo = Object.assign(Object.assign({}, current.splitInfo), { endHiddenIndex: current.splitInfo.endHiddenIndex - composeLen, oldStartIndex,
1183
- oldLength,
1184
- newStartIndex,
1185
- newLength, plainText: `@@ -${oldStartIndex},${oldLength} +${newStartIndex},${newLength}` });
1186
- (_b = __classPrivateFieldGet(this, _DiffFile_splitHunksLines, "f")) === null || _b === void 0 ? true : delete _b[index];
1187
- __classPrivateFieldGet(this, _DiffFile_splitHunksLines, "f")[current.splitInfo.endHiddenIndex] = current;
1188
- }
1189
- needTrigger && this.notifyAll();
1190
- };
1191
- this.getUnifiedLine = (index) => {
1192
- return __classPrivateFieldGet(this, _DiffFile_unifiedLines, "f")[index];
1193
- };
1194
- this.getUnifiedHunkLine = (index) => {
1195
- var _a;
1196
- return (_a = __classPrivateFieldGet(this, _DiffFile_unifiedHunksLines, "f")) === null || _a === void 0 ? void 0 : _a[index];
1197
- };
1198
- this.onUnifiedHunkExpand = (dir, index, needTrigger = true) => {
1199
- var _a, _b, _c;
1200
- const current = (_a = __classPrivateFieldGet(this, _DiffFile_unifiedHunksLines, "f")) === null || _a === void 0 ? void 0 : _a[index];
1201
- if (!current || !current.unifiedInfo)
1202
- return;
1203
- if (__classPrivateFieldGet(this, _DiffFile_composeByDiff, "f"))
1204
- return;
1205
- if (dir === "all") {
1206
- for (let i = current.unifiedInfo.startHiddenIndex; i < current.unifiedInfo.endHiddenIndex; i++) {
1207
- const unifiedLine = (_b = __classPrivateFieldGet(this, _DiffFile_unifiedLines, "f")) === null || _b === void 0 ? void 0 : _b[i];
1208
- if (unifiedLine === null || unifiedLine === void 0 ? void 0 : unifiedLine.isHidden) {
1209
- unifiedLine.isHidden = false;
1210
- }
1211
- }
1212
- current.unifiedInfo = Object.assign(Object.assign(Object.assign({}, current.unifiedInfo), current.hunkInfo), { plainText: current.text, startHiddenIndex: current.unifiedInfo.endHiddenIndex });
1213
- }
1214
- else if (dir === "down") {
1215
- for (let i = current.unifiedInfo.startHiddenIndex; i < current.unifiedInfo.startHiddenIndex + composeLen; i++) {
1216
- const unifiedLine = __classPrivateFieldGet(this, _DiffFile_unifiedLines, "f")[i];
1217
- if (unifiedLine === null || unifiedLine === void 0 ? void 0 : unifiedLine.isHidden)
1218
- unifiedLine.isHidden = false;
1219
- }
1220
- if (current.isLast) {
1221
- current.unifiedInfo = Object.assign(Object.assign({}, current.unifiedInfo), { startHiddenIndex: current.unifiedInfo.startHiddenIndex + composeLen });
1222
- }
1223
- else {
1224
- current.unifiedInfo = Object.assign(Object.assign({}, current.unifiedInfo), { startHiddenIndex: current.unifiedInfo.startHiddenIndex + composeLen, plainText: `@@ -${current.unifiedInfo.oldStartIndex},${current.unifiedInfo.oldLength} +${current.unifiedInfo.newStartIndex},${current.unifiedInfo.newLength}` });
1225
- }
1226
- }
1227
- else {
1228
- if (current.isLast) {
1229
- console.error("the last hunk can not expand up!");
1230
- return;
1231
- }
1232
- for (let i = current.unifiedInfo.endHiddenIndex - composeLen; i < current.unifiedInfo.endHiddenIndex; i++) {
1233
- const unifiedLine = __classPrivateFieldGet(this, _DiffFile_unifiedLines, "f")[i];
1234
- if (unifiedLine === null || unifiedLine === void 0 ? void 0 : unifiedLine.isHidden)
1235
- unifiedLine.isHidden = false;
1236
- }
1237
- const oldStartIndex = current.unifiedInfo.oldStartIndex - composeLen;
1238
- const oldLength = current.unifiedInfo.oldLength + composeLen;
1239
- const newStartIndex = current.unifiedInfo.newStartIndex - composeLen;
1240
- const newLength = current.unifiedInfo.newLength + composeLen;
1241
- current.unifiedInfo = Object.assign(Object.assign({}, current.unifiedInfo), { endHiddenIndex: current.unifiedInfo.endHiddenIndex - composeLen, oldStartIndex,
1242
- oldLength,
1243
- newStartIndex,
1244
- newLength, plainText: `@@ -${oldStartIndex},${oldLength} +${newStartIndex},${newLength}` });
1245
- (_c = __classPrivateFieldGet(this, _DiffFile_unifiedHunksLines, "f")) === null || _c === void 0 ? true : delete _c[index];
1246
- __classPrivateFieldGet(this, _DiffFile_unifiedHunksLines, "f")[current.unifiedInfo.endHiddenIndex] = current;
1247
- }
1248
- needTrigger && this.notifyAll();
1249
- };
1250
- this.onAllExpand = (mode) => {
1251
- if (__classPrivateFieldGet(this, _DiffFile_composeByDiff, "f"))
1252
- return;
1253
- if (mode === "split") {
1254
- Object.keys(__classPrivateFieldGet(this, _DiffFile_splitHunksLines, "f") || {}).forEach((key) => {
1255
- this.onSplitHunkExpand("all", +key, false);
1256
- });
1257
- this.hasExpandSplitAll = true;
1258
- }
1259
- else {
1260
- Object.keys(__classPrivateFieldGet(this, _DiffFile_unifiedHunksLines, "f") || {}).forEach((key) => {
1261
- this.onUnifiedHunkExpand("all", +key, false);
1262
- });
1263
- this.hasExpandUnifiedAll = true;
1264
- }
1265
- this.notifyAll();
1266
- };
1267
- this.onAllCollapse = (mode) => {
1268
- if (__classPrivateFieldGet(this, _DiffFile_composeByDiff, "f"))
1269
- return;
1270
- if (mode === "split") {
1271
- Object.values(__classPrivateFieldGet(this, _DiffFile_splitLeftLines, "f") || {}).forEach((item) => {
1272
- if (!item.isHidden && item._isHidden) {
1273
- item.isHidden = item._isHidden;
1274
- }
1275
- });
1276
- Object.values(__classPrivateFieldGet(this, _DiffFile_splitRightLines, "f") || {}).forEach((item) => {
1277
- if (!item.isHidden && item._isHidden) {
1278
- item.isHidden = item._isHidden;
1279
- }
1280
- });
1281
- Object.values(__classPrivateFieldGet(this, _DiffFile_splitHunksLines, "f") || {}).forEach((item) => {
1282
- if (!item.splitInfo)
1283
- return;
1284
- item.splitInfo = Object.assign(Object.assign({}, item.splitInfo), { oldStartIndex: item.splitInfo._oldStartIndex, oldLength: item.splitInfo._oldLength, newStartIndex: item.splitInfo._newStartIndex, newLength: item.splitInfo._newLength, startHiddenIndex: item.splitInfo._startHiddenIndex, endHiddenIndex: item.splitInfo._endHiddenIndex, plainText: item.splitInfo._plainText });
1285
- });
1286
- Object.keys(__classPrivateFieldGet(this, _DiffFile_splitHunksLines, "f") || {}).forEach((key) => {
1287
- const item = __classPrivateFieldGet(this, _DiffFile_splitHunksLines, "f")[key];
1288
- if (!item.splitInfo)
1289
- return;
1290
- if (item.splitInfo.endHiddenIndex !== +key) {
1291
- delete __classPrivateFieldGet(this, _DiffFile_splitHunksLines, "f")[key];
1292
- __classPrivateFieldGet(this, _DiffFile_splitHunksLines, "f")[item.splitInfo.endHiddenIndex] = item;
1293
- }
1294
- });
1295
- this.hasExpandSplitAll = false;
1296
- }
1297
- else {
1298
- Object.values(__classPrivateFieldGet(this, _DiffFile_unifiedLines, "f") || {}).forEach((item) => {
1299
- if (!item.isHidden && item._isHidden) {
1300
- item.isHidden = item._isHidden;
1301
- }
1302
- });
1303
- Object.values(__classPrivateFieldGet(this, _DiffFile_unifiedHunksLines, "f") || {}).forEach((item) => {
1304
- if (!item.unifiedInfo)
1305
- return;
1306
- item.unifiedInfo = Object.assign(Object.assign({}, item.unifiedInfo), { oldStartIndex: item.unifiedInfo._oldStartIndex, oldLength: item.unifiedInfo._oldLength, newStartIndex: item.unifiedInfo._newStartIndex, newLength: item.unifiedInfo._newLength, startHiddenIndex: item.unifiedInfo._startHiddenIndex, endHiddenIndex: item.unifiedInfo._endHiddenIndex, plainText: item.unifiedInfo._plainText });
1307
- });
1308
- Object.keys(__classPrivateFieldGet(this, _DiffFile_unifiedHunksLines, "f") || {}).forEach((key) => {
1309
- const item = __classPrivateFieldGet(this, _DiffFile_unifiedHunksLines, "f")[key];
1310
- if (!item.unifiedInfo)
1311
- return;
1312
- if (item.unifiedInfo.endHiddenIndex !== +key) {
1313
- delete __classPrivateFieldGet(this, _DiffFile_unifiedHunksLines, "f")[key];
1314
- __classPrivateFieldGet(this, _DiffFile_unifiedHunksLines, "f")[item.unifiedInfo.endHiddenIndex] = item;
1315
- }
1316
- });
1317
- this.hasExpandUnifiedAll = false;
1318
- }
1319
- this.notifyAll();
1320
- };
1321
- this.getOldSyntaxLine = (lineNumber) => {
1322
- var _a;
1323
- return (_a = __classPrivateFieldGet(this, _DiffFile_oldFileSyntaxLines, "f")) === null || _a === void 0 ? void 0 : _a[lineNumber];
1324
- };
1325
- this.getNewSyntaxLine = (lineNumber) => {
1326
- var _a;
1327
- return (_a = __classPrivateFieldGet(this, _DiffFile_newFileSyntaxLines, "f")) === null || _a === void 0 ? void 0 : _a[lineNumber];
1328
- };
1329
- this.subscribe = (listener) => {
1330
- __classPrivateFieldGet(this, _DiffFile_listeners, "f").push(listener);
1331
- return () => {
1332
- __classPrivateFieldGet(this, _DiffFile_listeners, "f").filter((i) => i !== listener);
1333
- };
1334
- };
1335
- this.notifyAll = (skipSyncExternal) => {
1336
- var _a;
1337
- __classPrivateFieldSet(this, _DiffFile_updateCount, (_a = __classPrivateFieldGet(this, _DiffFile_updateCount, "f"), _a++, _a), "f");
1338
- __classPrivateFieldGet(this, _DiffFile_listeners, "f").forEach((f) => {
1339
- if (skipSyncExternal && f.isSyncExternal) {
1340
- return;
1341
- }
1342
- f();
1343
- });
1344
- // support update from outside instance
1345
- __classPrivateFieldGet(this, _DiffFile_clonedInstance, "f").forEach((_, instance) => {
1346
- instance.notifyAll(true);
1347
- });
1348
- };
1349
- this.getUpdateCount = () => __classPrivateFieldGet(this, _DiffFile_updateCount, "f");
1350
- this.getExpandEnabled = () => !__classPrivateFieldGet(this, _DiffFile_composeByDiff, "f");
1351
- this.getBundle = () => {
1352
- // common
1353
- const hasInitRaw = __classPrivateFieldGet(this, _DiffFile_hasInitRaw, "f");
1354
- const hasInitSyntax = __classPrivateFieldGet(this, _DiffFile_hasInitSyntax, "f");
1355
- const hasBuildSplit = __classPrivateFieldGet(this, _DiffFile_hasBuildSplit, "f");
1356
- const hasBuildUnified = __classPrivateFieldGet(this, _DiffFile_hasBuildUnified, "f");
1357
- const oldFileLines = __classPrivateFieldGet(this, _DiffFile_oldFileLines, "f");
1358
- const oldFileDiffLines = __classPrivateFieldGet(this, _DiffFile_oldFileDiffLines, "f");
1359
- const oldFileSyntaxLines = __classPrivateFieldGet(this, _DiffFile_oldFileSyntaxLines, "f");
1360
- const oldFilePlaceholderLines = __classPrivateFieldGet(this, _DiffFile_oldFilePlaceholderLines, "f");
1361
- const newFileLines = __classPrivateFieldGet(this, _DiffFile_newFileLines, "f");
1362
- const newFileDiffLines = __classPrivateFieldGet(this, _DiffFile_newFileDiffLines, "f");
1363
- const newFileSyntaxLines = __classPrivateFieldGet(this, _DiffFile_newFileSyntaxLines, "f");
1364
- const newFilePlaceholderLines = __classPrivateFieldGet(this, _DiffFile_newFilePlaceholderLines, "f");
1365
- const splitLineLength = this.splitLineLength;
1366
- const unifiedLineLength = this.unifiedLineLength;
1367
- const composeByDiff = __classPrivateFieldGet(this, _DiffFile_composeByDiff, "f");
1368
- const highlighterName = __classPrivateFieldGet(this, _DiffFile_highlighterName, "f");
1369
- const hasSomeLineCollapsed = this.hasSomeLineCollapsed;
1370
- // split
1371
- const splitLeftLines = __classPrivateFieldGet(this, _DiffFile_splitLeftLines, "f");
1372
- const splitRightLines = __classPrivateFieldGet(this, _DiffFile_splitRightLines, "f");
1373
- const splitHunkLines = __classPrivateFieldGet(this, _DiffFile_splitHunksLines, "f");
1374
- // unified
1375
- const unifiedLines = __classPrivateFieldGet(this, _DiffFile_unifiedLines, "f");
1376
- const unifiedHunkLines = __classPrivateFieldGet(this, _DiffFile_unifiedHunksLines, "f");
1377
- const version = this._version_;
1378
- return {
1379
- hasInitRaw,
1380
- hasInitSyntax,
1381
- hasBuildSplit,
1382
- hasBuildUnified,
1383
- oldFileLines,
1384
- oldFileDiffLines,
1385
- oldFileSyntaxLines,
1386
- oldFilePlaceholderLines,
1387
- newFileLines,
1388
- newFileDiffLines,
1389
- newFileSyntaxLines,
1390
- newFilePlaceholderLines,
1391
- splitLineLength,
1392
- unifiedLineLength,
1393
- splitLeftLines,
1394
- splitRightLines,
1395
- splitHunkLines,
1396
- unifiedLines,
1397
- unifiedHunkLines,
1398
- highlighterName,
1399
- composeByDiff,
1400
- hasSomeLineCollapsed,
1401
- version,
1402
- isFullMerge: false,
1403
- };
1404
- };
1405
- this.mergeBundle = (data) => {
1406
- __classPrivateFieldSet(this, _DiffFile_hasInitRaw, data.hasInitRaw, "f");
1407
- __classPrivateFieldSet(this, _DiffFile_hasInitSyntax, data.hasInitSyntax, "f");
1408
- __classPrivateFieldSet(this, _DiffFile_hasBuildSplit, data.hasBuildSplit, "f");
1409
- __classPrivateFieldSet(this, _DiffFile_hasBuildUnified, data.hasBuildUnified, "f");
1410
- __classPrivateFieldSet(this, _DiffFile_composeByDiff, data.composeByDiff, "f");
1411
- __classPrivateFieldSet(this, _DiffFile_highlighterName, data.highlighterName, "f");
1412
- __classPrivateFieldSet(this, _DiffFile_oldFileLines, data.oldFileLines, "f");
1413
- __classPrivateFieldSet(this, _DiffFile_oldFileDiffLines, data.oldFileDiffLines, "f");
1414
- __classPrivateFieldSet(this, _DiffFile_oldFileSyntaxLines, data.oldFileSyntaxLines, "f");
1415
- __classPrivateFieldSet(this, _DiffFile_oldFilePlaceholderLines, data.oldFilePlaceholderLines, "f");
1416
- __classPrivateFieldSet(this, _DiffFile_newFileLines, data.newFileLines, "f");
1417
- __classPrivateFieldSet(this, _DiffFile_newFileDiffLines, data.newFileDiffLines, "f");
1418
- __classPrivateFieldSet(this, _DiffFile_newFileSyntaxLines, data.newFileSyntaxLines, "f");
1419
- __classPrivateFieldSet(this, _DiffFile_newFilePlaceholderLines, data.newFilePlaceholderLines, "f");
1420
- this.splitLineLength = data.splitLineLength;
1421
- this.unifiedLineLength = data.unifiedLineLength;
1422
- this.hasSomeLineCollapsed = data.hasSomeLineCollapsed;
1423
- __classPrivateFieldSet(this, _DiffFile_splitLeftLines, data.splitLeftLines, "f");
1424
- __classPrivateFieldSet(this, _DiffFile_splitRightLines, data.splitRightLines, "f");
1425
- __classPrivateFieldSet(this, _DiffFile_splitHunksLines, data.splitHunkLines, "f");
1426
- __classPrivateFieldSet(this, _DiffFile_unifiedLines, data.unifiedLines, "f");
1427
- __classPrivateFieldSet(this, _DiffFile_unifiedHunksLines, data.unifiedHunkLines, "f");
1428
- // mark this instance as a merged instance
1429
- __classPrivateFieldSet(this, _DiffFile_composeByMerge, true, "f");
1430
- if (this._version_ !== data.version) {
1431
- console.error("the version of the `diffInstance` is not match, some error may happen!");
1432
- }
1433
- this.notifyAll();
1434
- };
1435
- this._getHighlighterName = () => __classPrivateFieldGet(this, _DiffFile_highlighterName, "f");
1436
- this._getIsPureDiffRender = () => __classPrivateFieldGet(this, _DiffFile_composeByDiff, "f");
1437
- this._addClonedInstance = (instance) => {
1438
- const updateFunc = () => {
1439
- this._notifyOthers(instance);
1440
- };
1441
- updateFunc.isSyncExternal = true;
1442
- const unsubscribe = instance.subscribe(updateFunc);
1443
- __classPrivateFieldGet(this, _DiffFile_clonedInstance, "f").set(instance, unsubscribe);
1444
- };
1445
- this._notifyOthers = (instance) => {
1446
- __classPrivateFieldGet(this, _DiffFile_clonedInstance, "f").forEach((_, i) => {
1447
- if (i !== instance) {
1448
- i.notifyAll(true);
1449
- }
1450
- });
1451
- };
1452
- this._delClonedInstance = (instance) => {
1453
- const unsubscribe = __classPrivateFieldGet(this, _DiffFile_clonedInstance, "f").get(instance);
1454
- unsubscribe && unsubscribe();
1455
- __classPrivateFieldGet(this, _DiffFile_clonedInstance, "f").delete(instance);
1456
- };
1457
- this._getFullBundle = () => {
1458
- const bundle = this.getBundle();
1459
- const oldFileResult = __classPrivateFieldGet(this, _DiffFile_oldFileResult, "f");
1460
- const newFileResult = __classPrivateFieldGet(this, _DiffFile_newFileResult, "f");
1461
- const diffLines = __classPrivateFieldGet(this, _DiffFile_diffLines, "f");
1462
- const diffListResults = __classPrivateFieldGet(this, _DiffFile_diffListResults, "f");
1463
- return Object.assign(Object.assign({}, bundle), { oldFileResult,
1464
- newFileResult,
1465
- diffLines,
1466
- diffListResults,
1467
- // get current instance is a fullMerge instance or not
1468
- isFullMerge: __classPrivateFieldGet(this, _DiffFile_composeByMerge, "f") ? __classPrivateFieldGet(this, _DiffFile_composeByFullMerge, "f") : true });
1469
- };
1470
- this._mergeFullBundle = (data) => {
1471
- this.mergeBundle(data);
1472
- try {
1473
- __classPrivateFieldSet(this, _DiffFile_oldFileResult, File.createInstance(data.oldFileResult), "f");
1474
- __classPrivateFieldSet(this, _DiffFile_newFileResult, File.createInstance(data.newFileResult), "f");
1475
- __classPrivateFieldSet(this, _DiffFile_diffLines, data.diffLines, "f");
1476
- __classPrivateFieldSet(this, _DiffFile_diffListResults, data.diffListResults, "f");
1477
- __classPrivateFieldSet(this, _DiffFile_composeByFullMerge, data.isFullMerge, "f");
1478
- }
1479
- catch (_a) {
1480
- }
1481
- };
1482
- this._destroy = () => {
1483
- this.clearId();
1484
- __classPrivateFieldGet(this, _DiffFile_listeners, "f").splice(0, __classPrivateFieldGet(this, _DiffFile_listeners, "f").length);
1485
- __classPrivateFieldGet(this, _DiffFile_clonedInstance, "f").forEach((v) => v());
1486
- __classPrivateFieldGet(this, _DiffFile_clonedInstance, "f").clear();
1487
- };
1488
- this.clear = () => {
1489
- this._destroy();
1490
- __classPrivateFieldSet(this, _DiffFile_oldFileResult, null, "f");
1491
- __classPrivateFieldSet(this, _DiffFile_newFileResult, null, "f");
1492
- __classPrivateFieldSet(this, _DiffFile_diffLines, null, "f");
1493
- __classPrivateFieldSet(this, _DiffFile_diffListResults, null, "f");
1494
- __classPrivateFieldSet(this, _DiffFile_newFileDiffLines, null, "f");
1495
- __classPrivateFieldSet(this, _DiffFile_oldFileDiffLines, null, "f");
1496
- __classPrivateFieldSet(this, _DiffFile_newFileLines, null, "f");
1497
- __classPrivateFieldSet(this, _DiffFile_oldFileLines, null, "f");
1498
- __classPrivateFieldSet(this, _DiffFile_newFileSyntaxLines, null, "f");
1499
- __classPrivateFieldSet(this, _DiffFile_oldFileSyntaxLines, null, "f");
1500
- __classPrivateFieldSet(this, _DiffFile_splitHunksLines, null, "f");
1501
- __classPrivateFieldSet(this, _DiffFile_splitLeftLines, null, "f");
1502
- __classPrivateFieldSet(this, _DiffFile_splitRightLines, null, "f");
1503
- __classPrivateFieldSet(this, _DiffFile_unifiedHunksLines, null, "f");
1504
- __classPrivateFieldSet(this, _DiffFile_unifiedLines, null, "f");
1505
- };
1506
- Object.defineProperty(this, "__v_skip", { value: true });
1507
- let oldContent = _oldFileContent;
1508
- let newContent = _newFileContent;
1509
- const diffList = Array.from(new Set(_diffList));
1510
- Object.defineProperties(this, {
1511
- _oldFileName: { get: () => _oldFileName },
1512
- _newFileName: { get: () => _newFileName },
1513
- _oldFileLang: { get: () => getLang(_oldFileLang || _oldFileName || _newFileLang || _newFileName) || "txt" },
1514
- _newFileLang: { get: () => getLang(_newFileLang || _newFileName || _oldFileLang || _oldFileName) || "txt" },
1515
- _oldFileContent: {
1516
- get: () => oldContent,
1517
- set: (v) => (oldContent = v),
1518
- },
1519
- _newFileContent: {
1520
- get: () => newContent,
1521
- set: (v) => (newContent = v),
1522
- },
1523
- _diffList: { get: () => diffList },
1524
- });
1525
- this.initId();
1526
- }
1527
- initId() {
1528
- let id = "--" + Math.random().toString().slice(2);
1529
- while (idSet.has(id)) {
1530
- id = "--" + Math.random().toString().slice(2);
1531
- }
1532
- idSet.add(id);
1533
- __classPrivateFieldSet(this, _DiffFile_id, id, "f");
1534
- }
1535
- getId() {
1536
- return __classPrivateFieldGet(this, _DiffFile_id, "f");
1537
- }
1538
- clearId() {
1539
- idSet.delete(__classPrivateFieldGet(this, _DiffFile_id, "f"));
1540
- }
1541
- initRaw() {
1542
- if (__classPrivateFieldGet(this, _DiffFile_hasInitRaw, "f"))
1543
- return;
1544
- __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_doDiff).call(this);
1545
- __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_composeDiff).call(this);
1546
- __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_doFile).call(this);
1547
- __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_composeRaw).call(this);
1548
- __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_composeFile).call(this);
1549
- __classPrivateFieldSet(this, _DiffFile_hasInitRaw, true, "f");
1550
- }
1551
- initSyntax({ registerHighlighter } = {}) {
1552
- var _a, _b;
1553
- if (__classPrivateFieldGet(this, _DiffFile_hasInitSyntax, "f"))
1554
- return;
1555
- if (__classPrivateFieldGet(this, _DiffFile_composeByMerge, "f") && !__classPrivateFieldGet(this, _DiffFile_composeByFullMerge, "f")) {
1556
- console.error(`this instance can not do syntax because of the data missing, try to use '_getFullBundle' & '_mergeFullBundle' instead of 'getBundle' & 'mergeBundle'`);
1557
- return;
1558
- }
1559
- __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_composeSyntax).call(this, { registerHighlighter });
1560
- __classPrivateFieldSet(this, _DiffFile_highlighterName, ((_a = __classPrivateFieldGet(this, _DiffFile_oldFileResult, "f")) === null || _a === void 0 ? void 0 : _a.highlighterName) || ((_b = __classPrivateFieldGet(this, _DiffFile_newFileResult, "f")) === null || _b === void 0 ? void 0 : _b.highlighterName) || __classPrivateFieldGet(this, _DiffFile_highlighterName, "f"), "f");
1561
- __classPrivateFieldSet(this, _DiffFile_hasInitSyntax, true, "f");
1562
- }
1563
- init() {
1564
- this.initRaw();
1565
- this.initSyntax();
1566
- }
1567
- buildSplitDiffLines() {
1568
- var _a, _b, _c, _d, _e, _f, _g;
1569
- if (__classPrivateFieldGet(this, _DiffFile_hasBuildSplit, "f"))
1570
- return;
1571
- let oldFileLineNumber = 1;
1572
- let newFileLineNumber = 1;
1573
- let prevIsHidden = false;
1574
- let hideStart = Infinity;
1575
- const maxOldFileLineNumber = ((_a = __classPrivateFieldGet(this, _DiffFile_oldFileResult, "f")) === null || _a === void 0 ? void 0 : _a.maxLineNumber) || 0;
1576
- const maxNewFileLineNumber = ((_b = __classPrivateFieldGet(this, _DiffFile_newFileResult, "f")) === null || _b === void 0 ? void 0 : _b.maxLineNumber) || 0;
1577
- while (oldFileLineNumber <= maxOldFileLineNumber || newFileLineNumber <= maxNewFileLineNumber) {
1578
- const oldDiffLine = __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getOldDiffLine).call(this, oldFileLineNumber);
1579
- const newDiffLine = __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getNewDiffLine).call(this, newFileLineNumber);
1580
- const oldRawLine = __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getOldRawLine).call(this, oldFileLineNumber);
1581
- const newRawLine = __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getNewRawLine).call(this, newFileLineNumber);
1582
- const oldLineHasChange = oldDiffLine === null || oldDiffLine === void 0 ? void 0 : oldDiffLine.isIncludeableLine();
1583
- const newLineHasChange = newDiffLine === null || newDiffLine === void 0 ? void 0 : newDiffLine.isIncludeableLine();
1584
- const len = __classPrivateFieldGet(this, _DiffFile_splitRightLines, "f").length;
1585
- const isHidden = !oldDiffLine && !newDiffLine;
1586
- if (oldDiffLine && !newDiffLine) {
1587
- if (oldDiffLine.newLineNumber && oldDiffLine.newLineNumber > newFileLineNumber) {
1588
- newFileLineNumber++;
1589
- continue;
1590
- }
1591
- if (oldDiffLine.newLineNumber === null || oldDiffLine.newLineNumber === undefined) {
1592
- newFileLineNumber++;
1593
- }
1594
- }
1595
- if (newDiffLine && !oldDiffLine) {
1596
- if (newDiffLine.oldLineNumber && newDiffLine.oldLineNumber > oldFileLineNumber) {
1597
- oldFileLineNumber++;
1598
- continue;
1599
- }
1600
- if (newDiffLine.oldLineNumber === null || newDiffLine.oldLineNumber === undefined) {
1601
- oldFileLineNumber++;
1602
- }
1603
- }
1604
- if (!oldDiffLine && !oldRawLine && !newDiffLine && !newRawLine)
1605
- break;
1606
- if (!oldDiffLine && !newDiffLine) {
1607
- if (((_c = __classPrivateFieldGet(this, _DiffFile_oldFilePlaceholderLines, "f")) === null || _c === void 0 ? void 0 : _c[oldFileLineNumber]) && ((_d = __classPrivateFieldGet(this, _DiffFile_newFilePlaceholderLines, "f")) === null || _d === void 0 ? void 0 : _d[newFileLineNumber])) {
1608
- oldFileLineNumber++;
1609
- newFileLineNumber++;
1610
- continue;
1611
- }
1612
- if (!oldRawLine && ((_e = __classPrivateFieldGet(this, _DiffFile_newFilePlaceholderLines, "f")) === null || _e === void 0 ? void 0 : _e[newFileLineNumber])) {
1613
- newFileLineNumber++;
1614
- continue;
1615
- }
1616
- if (!newRawLine && ((_f = __classPrivateFieldGet(this, _DiffFile_oldFilePlaceholderLines, "f")) === null || _f === void 0 ? void 0 : _f[oldFileLineNumber])) {
1617
- oldFileLineNumber++;
1618
- continue;
1619
- }
1620
- }
1621
- if ((oldLineHasChange && newLineHasChange) || (!oldLineHasChange && !newLineHasChange)) {
1622
- __classPrivateFieldGet(this, _DiffFile_splitLeftLines, "f").push({
1623
- lineNumber: oldFileLineNumber++,
1624
- value: oldRawLine,
1625
- diff: oldDiffLine,
1626
- isHidden,
1627
- _isHidden: isHidden,
1628
- });
1629
- __classPrivateFieldGet(this, _DiffFile_splitRightLines, "f").push({
1630
- lineNumber: newFileLineNumber++,
1631
- value: newRawLine,
1632
- diff: newDiffLine,
1633
- isHidden,
1634
- _isHidden: isHidden,
1635
- });
1636
- }
1637
- else if (oldLineHasChange) {
1638
- __classPrivateFieldGet(this, _DiffFile_splitLeftLines, "f").push({
1639
- lineNumber: oldFileLineNumber++,
1640
- value: oldRawLine,
1641
- diff: oldDiffLine,
1642
- isHidden,
1643
- _isHidden: isHidden,
1644
- });
1645
- __classPrivateFieldGet(this, _DiffFile_splitRightLines, "f").push({});
1646
- }
1647
- else if (newLineHasChange) {
1648
- __classPrivateFieldGet(this, _DiffFile_splitLeftLines, "f").push({});
1649
- __classPrivateFieldGet(this, _DiffFile_splitRightLines, "f").push({
1650
- lineNumber: newFileLineNumber++,
1651
- value: newRawLine,
1652
- diff: newDiffLine,
1653
- isHidden,
1654
- _isHidden: isHidden,
1655
- });
1656
- }
1657
- if (!prevIsHidden && isHidden) {
1658
- hideStart = len;
1659
- }
1660
- if (isHidden) {
1661
- this.hasSomeLineCollapsed = true;
1662
- }
1663
- prevIsHidden = isHidden;
1664
- if (oldDiffLine && newDiffLine && !oldLineHasChange && !newLineHasChange) {
1665
- const current = newDiffLine;
1666
- const previous = newDiffLine.index ? (_g = __classPrivateFieldGet(this, _DiffFile_diffLines, "f")) === null || _g === void 0 ? void 0 : _g[current.index - 1] : undefined;
1667
- if (previous && previous.type === exports.DiffLineType.Hunk) {
1668
- const typedPrevious = previous;
1669
- if (Number.isFinite(hideStart)) {
1670
- typedPrevious.splitInfo = Object.assign(Object.assign({}, typedPrevious.hunkInfo), { startHiddenIndex: hideStart, endHiddenIndex: len, plainText: typedPrevious.text, _startHiddenIndex: hideStart, _endHiddenIndex: len, _plainText: typedPrevious.text });
1671
- hideStart = Infinity;
1672
- }
1673
- __classPrivateFieldSet(this, _DiffFile_splitHunksLines, Object.assign(Object.assign({}, __classPrivateFieldGet(this, _DiffFile_splitHunksLines, "f")), { [len]: typedPrevious }), "f");
1674
- }
1675
- }
1676
- }
1677
- // have last hunk
1678
- if (Number.isFinite(hideStart)) {
1679
- const lastDiff = new DiffLine("", exports.DiffLineType.Hunk, null, null, null);
1680
- const lastHunk = lastDiff;
1681
- lastHunk.isLast = true;
1682
- lastHunk.splitInfo = {
1683
- startHiddenIndex: hideStart,
1684
- endHiddenIndex: __classPrivateFieldGet(this, _DiffFile_splitRightLines, "f").length,
1685
- _startHiddenIndex: hideStart,
1686
- _endHiddenIndex: __classPrivateFieldGet(this, _DiffFile_splitRightLines, "f").length,
1687
- // just for placeholder
1688
- plainText: "",
1689
- oldStartIndex: 0,
1690
- newStartIndex: 0,
1691
- oldLength: 0,
1692
- newLength: 0,
1693
- _plainText: "",
1694
- _oldStartIndex: 0,
1695
- _newStartIndex: 0,
1696
- _oldLength: 0,
1697
- _newLength: 0,
1698
- };
1699
- __classPrivateFieldSet(this, _DiffFile_splitHunksLines, Object.assign(Object.assign({}, __classPrivateFieldGet(this, _DiffFile_splitHunksLines, "f")), { [__classPrivateFieldGet(this, _DiffFile_splitRightLines, "f").length]: lastHunk }), "f");
1700
- hideStart = Infinity;
1701
- }
1702
- this.splitLineLength = __classPrivateFieldGet(this, _DiffFile_splitRightLines, "f").length;
1703
- __classPrivateFieldSet(this, _DiffFile_hasBuildSplit, true, "f");
1704
- this.notifyAll();
1705
- }
1706
- buildUnifiedDiffLines() {
1707
- var _a, _b, _c, _d, _e, _f, _g;
1708
- if (__classPrivateFieldGet(this, _DiffFile_hasBuildUnified, "f"))
1709
- return;
1710
- let oldFileLineNumber = 1;
1711
- let newFileLineNumber = 1;
1712
- let prevIsHidden = false;
1713
- let hideStart = Infinity;
1714
- const maxOldFileLineNumber = ((_a = __classPrivateFieldGet(this, _DiffFile_oldFileResult, "f")) === null || _a === void 0 ? void 0 : _a.maxLineNumber) || 0;
1715
- const maxNewFileLineNumber = ((_b = __classPrivateFieldGet(this, _DiffFile_newFileResult, "f")) === null || _b === void 0 ? void 0 : _b.maxLineNumber) || 0;
1716
- while (oldFileLineNumber <= maxOldFileLineNumber || newFileLineNumber <= maxNewFileLineNumber) {
1717
- const oldRawLine = __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getOldRawLine).call(this, oldFileLineNumber);
1718
- const oldDiffLine = __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getOldDiffLine).call(this, oldFileLineNumber);
1719
- const newRawLine = __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getNewRawLine).call(this, newFileLineNumber);
1720
- const newDiffLine = __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getNewDiffLine).call(this, newFileLineNumber);
1721
- const oldLineHasChange = oldDiffLine === null || oldDiffLine === void 0 ? void 0 : oldDiffLine.isIncludeableLine();
1722
- const newLineHasChange = newDiffLine === null || newDiffLine === void 0 ? void 0 : newDiffLine.isIncludeableLine();
1723
- const len = __classPrivateFieldGet(this, _DiffFile_unifiedLines, "f").length;
1724
- const isHidden = !oldDiffLine && !newDiffLine;
1725
- if (oldDiffLine && !newDiffLine) {
1726
- if (oldDiffLine.newLineNumber && oldDiffLine.newLineNumber > newFileLineNumber) {
1727
- newFileLineNumber++;
1728
- continue;
1729
- }
1730
- if (oldDiffLine.newLineNumber === null || oldDiffLine.newLineNumber === undefined) {
1731
- newFileLineNumber++;
1732
- }
1733
- }
1734
- if (newDiffLine && !oldDiffLine) {
1735
- if (newDiffLine.oldLineNumber && newDiffLine.oldLineNumber > oldFileLineNumber) {
1736
- oldFileLineNumber++;
1737
- continue;
1738
- }
1739
- if (newDiffLine.oldLineNumber === null || newDiffLine.oldLineNumber === undefined) {
1740
- oldFileLineNumber++;
1741
- }
1742
- }
1743
- if (!oldRawLine && !newRawLine && !newDiffLine && !oldDiffLine)
1744
- break;
1745
- if (!oldDiffLine && !newDiffLine) {
1746
- if (((_c = __classPrivateFieldGet(this, _DiffFile_oldFilePlaceholderLines, "f")) === null || _c === void 0 ? void 0 : _c[oldFileLineNumber]) && ((_d = __classPrivateFieldGet(this, _DiffFile_newFilePlaceholderLines, "f")) === null || _d === void 0 ? void 0 : _d[newFileLineNumber])) {
1747
- oldFileLineNumber++;
1748
- newFileLineNumber++;
1749
- continue;
1750
- }
1751
- if (!oldRawLine && ((_e = __classPrivateFieldGet(this, _DiffFile_newFilePlaceholderLines, "f")) === null || _e === void 0 ? void 0 : _e[newFileLineNumber])) {
1752
- newFileLineNumber++;
1753
- continue;
1754
- }
1755
- if (!newRawLine && ((_f = __classPrivateFieldGet(this, _DiffFile_oldFilePlaceholderLines, "f")) === null || _f === void 0 ? void 0 : _f[oldFileLineNumber])) {
1756
- oldFileLineNumber++;
1757
- continue;
1758
- }
1759
- }
1760
- if (!oldLineHasChange && !newLineHasChange) {
1761
- __classPrivateFieldGet(this, _DiffFile_unifiedLines, "f").push({
1762
- oldLineNumber: oldFileLineNumber++,
1763
- newLineNumber: newFileLineNumber++,
1764
- value: newRawLine,
1765
- diff: newDiffLine,
1766
- isHidden,
1767
- _isHidden: isHidden,
1768
- });
1769
- }
1770
- else if (oldLineHasChange) {
1771
- __classPrivateFieldGet(this, _DiffFile_unifiedLines, "f").push({
1772
- oldLineNumber: oldFileLineNumber++,
1773
- value: oldRawLine,
1774
- diff: oldDiffLine,
1775
- isHidden,
1776
- _isHidden: isHidden,
1777
- });
1778
- }
1779
- else if (newLineHasChange) {
1780
- __classPrivateFieldGet(this, _DiffFile_unifiedLines, "f").push({
1781
- newLineNumber: newFileLineNumber++,
1782
- value: newRawLine,
1783
- diff: newDiffLine,
1784
- isHidden,
1785
- _isHidden: isHidden,
1786
- });
1787
- }
1788
- if (!prevIsHidden && isHidden) {
1789
- hideStart = len;
1790
- }
1791
- if (isHidden) {
1792
- this.hasSomeLineCollapsed = true;
1793
- }
1794
- prevIsHidden = isHidden;
1795
- if (oldDiffLine && newDiffLine && !oldLineHasChange && !newLineHasChange) {
1796
- const current = newDiffLine;
1797
- const previous = current.index ? (_g = __classPrivateFieldGet(this, _DiffFile_diffLines, "f")) === null || _g === void 0 ? void 0 : _g[current.index - 1] : undefined;
1798
- if (previous && previous.type === exports.DiffLineType.Hunk) {
1799
- const typedPrevious = previous;
1800
- if (Number.isFinite(hideStart)) {
1801
- typedPrevious.unifiedInfo = Object.assign(Object.assign({}, typedPrevious.hunkInfo), { startHiddenIndex: hideStart, endHiddenIndex: len, plainText: typedPrevious.text, _startHiddenIndex: hideStart, _endHiddenIndex: len, _plainText: typedPrevious.text });
1802
- hideStart = Infinity;
1803
- }
1804
- __classPrivateFieldSet(this, _DiffFile_unifiedHunksLines, Object.assign(Object.assign({}, __classPrivateFieldGet(this, _DiffFile_unifiedHunksLines, "f")), { [len]: typedPrevious }), "f");
1805
- }
1806
- }
1807
- }
1808
- // have last hunk
1809
- if (Number.isFinite(hideStart)) {
1810
- const lastDiff = new DiffLine("", exports.DiffLineType.Hunk, null, null, null);
1811
- const lastHunk = lastDiff;
1812
- lastHunk.isLast = true;
1813
- lastHunk.unifiedInfo = {
1814
- startHiddenIndex: hideStart,
1815
- endHiddenIndex: __classPrivateFieldGet(this, _DiffFile_unifiedLines, "f").length,
1816
- _startHiddenIndex: hideStart,
1817
- _endHiddenIndex: __classPrivateFieldGet(this, _DiffFile_unifiedLines, "f").length,
1818
- // just for placeholder
1819
- plainText: "",
1820
- oldStartIndex: 0,
1821
- newStartIndex: 0,
1822
- oldLength: 0,
1823
- newLength: 0,
1824
- _plainText: "",
1825
- _oldStartIndex: 0,
1826
- _newStartIndex: 0,
1827
- _oldLength: 0,
1828
- _newLength: 0,
1829
- };
1830
- __classPrivateFieldSet(this, _DiffFile_unifiedHunksLines, Object.assign(Object.assign({}, __classPrivateFieldGet(this, _DiffFile_unifiedHunksLines, "f")), { [__classPrivateFieldGet(this, _DiffFile_unifiedLines, "f").length]: lastHunk }), "f");
1831
- hideStart = Infinity;
1832
- }
1833
- this.unifiedLineLength = __classPrivateFieldGet(this, _DiffFile_unifiedLines, "f").length;
1834
- __classPrivateFieldSet(this, _DiffFile_hasBuildUnified, true, "f");
1835
- this.notifyAll();
1836
- }
1837
- }
1838
- _DiffFile_oldFileResult = new WeakMap(), _DiffFile_newFileResult = new WeakMap(), _DiffFile_diffListResults = new WeakMap(), _DiffFile_diffLines = new WeakMap(), _DiffFile_oldFileDiffLines = new WeakMap(), _DiffFile_newFileDiffLines = new WeakMap(), _DiffFile_oldFileLines = new WeakMap(), _DiffFile_newFileLines = new WeakMap(), _DiffFile_oldFileSyntaxLines = new WeakMap(), _DiffFile_newFileSyntaxLines = new WeakMap(), _DiffFile_oldFilePlaceholderLines = new WeakMap(), _DiffFile_newFilePlaceholderLines = new WeakMap(), _DiffFile_splitLeftLines = new WeakMap(), _DiffFile_splitRightLines = new WeakMap(), _DiffFile_splitHunksLines = new WeakMap(), _DiffFile_unifiedLines = new WeakMap(), _DiffFile_unifiedHunksLines = new WeakMap(), _DiffFile_listeners = new WeakMap(), _DiffFile_hasInitRaw = new WeakMap(), _DiffFile_hasInitSyntax = new WeakMap(), _DiffFile_hasBuildSplit = new WeakMap(), _DiffFile_hasBuildUnified = new WeakMap(), _DiffFile_updateCount = new WeakMap(), _DiffFile_composeByDiff = new WeakMap(), _DiffFile_composeByMerge = new WeakMap(), _DiffFile_composeByFullMerge = new WeakMap(), _DiffFile_highlighterName = new WeakMap(), _DiffFile_id = new WeakMap(), _DiffFile_clonedInstance = new WeakMap(), _DiffFile_instances = new WeakSet(), _DiffFile_doDiff = function _DiffFile_doDiff() {
1839
- if (!this._diffList)
1840
- return;
1841
- __classPrivateFieldSet(this, _DiffFile_diffListResults, this._diffList.map((s) => parseInstance.parse(s)), "f");
1842
- }, _DiffFile_doFile = function _DiffFile_doFile() {
1843
- if (!this._oldFileContent && !this._newFileContent)
1844
- return;
1845
- if (this._oldFileContent) {
1846
- __classPrivateFieldSet(this, _DiffFile_oldFileResult, getFile(this._oldFileContent, this._oldFileLang, this._oldFileName), "f");
1847
- }
1848
- if (this._newFileContent) {
1849
- __classPrivateFieldSet(this, _DiffFile_newFileResult, getFile(this._newFileContent, this._newFileLang, this._newFileName), "f");
1850
- }
1851
- }, _DiffFile_composeRaw = function _DiffFile_composeRaw() {
1852
- var _a, _b, _c, _d;
1853
- (_a = __classPrivateFieldGet(this, _DiffFile_oldFileResult, "f")) === null || _a === void 0 ? void 0 : _a.doRaw();
1854
- __classPrivateFieldSet(this, _DiffFile_oldFileLines, (_b = __classPrivateFieldGet(this, _DiffFile_oldFileResult, "f")) === null || _b === void 0 ? void 0 : _b.rawFile, "f");
1855
- (_c = __classPrivateFieldGet(this, _DiffFile_newFileResult, "f")) === null || _c === void 0 ? void 0 : _c.doRaw();
1856
- __classPrivateFieldSet(this, _DiffFile_newFileLines, (_d = __classPrivateFieldGet(this, _DiffFile_newFileResult, "f")) === null || _d === void 0 ? void 0 : _d.rawFile, "f");
1857
- }, _DiffFile_composeFile = function _DiffFile_composeFile() {
1858
- if (this._oldFileContent && this._newFileContent)
1859
- return;
1860
- const oldFilePlaceholderLines = {};
1861
- const newFilePlaceholderLines = {};
1862
- // all of the file content not exist, try to use diff result to compose
1863
- if (!this._oldFileContent && !this._newFileContent) {
1864
- let newLineNumber = 1;
1865
- let oldLineNumber = 1;
1866
- let oldFileContent = "";
1867
- let newFileContent = "";
1868
- let hasSymbolChanged = false;
1869
- while (oldLineNumber <= this.diffLineLength || newLineNumber <= this.diffLineLength) {
1870
- const oldIndex = oldLineNumber++;
1871
- const newIndex = newLineNumber++;
1872
- const oldDiffLine = __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getOldDiffLine).call(this, oldIndex);
1873
- const newDiffLine = __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getNewDiffLine).call(this, newIndex);
1874
- if (oldDiffLine) {
1875
- oldFileContent += oldDiffLine.text;
1876
- }
1877
- else {
1878
- // empty line for placeholder
1879
- oldFileContent += "\n";
1880
- oldFilePlaceholderLines[oldIndex] = true;
1881
- }
1882
- if (newDiffLine) {
1883
- newFileContent += newDiffLine.text;
1884
- }
1885
- else {
1886
- // empty line for placeholder
1887
- newFileContent += "\n";
1888
- newFilePlaceholderLines[newIndex] = true;
1889
- }
1890
- if (!hasSymbolChanged && oldDiffLine && newDiffLine) {
1891
- hasSymbolChanged = hasSymbolChanged || oldDiffLine.noTrailingNewLine !== newDiffLine.noTrailingNewLine;
1892
- }
1893
- }
1894
- if (!hasSymbolChanged && oldFileContent === newFileContent)
1895
- return;
1896
- this._oldFileContent = oldFileContent;
1897
- this._newFileContent = newFileContent;
1898
- __classPrivateFieldSet(this, _DiffFile_oldFileResult, getFile(this._oldFileContent, this._oldFileLang, this._oldFileName), "f");
1899
- __classPrivateFieldSet(this, _DiffFile_newFileResult, getFile(this._newFileContent, this._newFileLang, this._newFileName), "f");
1900
- __classPrivateFieldSet(this, _DiffFile_oldFilePlaceholderLines, oldFilePlaceholderLines, "f");
1901
- __classPrivateFieldSet(this, _DiffFile_newFilePlaceholderLines, newFilePlaceholderLines, "f");
1902
- // all of the file just compose by diff, so we can not do the expand action
1903
- __classPrivateFieldSet(this, _DiffFile_composeByDiff, true, "f");
1904
- }
1905
- else if (__classPrivateFieldGet(this, _DiffFile_oldFileResult, "f")) {
1906
- let newLineNumber = 1;
1907
- let oldLineNumber = 1;
1908
- let newFileContent = "";
1909
- let hasSymbolChanged = false;
1910
- while (oldLineNumber <= __classPrivateFieldGet(this, _DiffFile_oldFileResult, "f").maxLineNumber) {
1911
- const newDiffLine = __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getNewDiffLine).call(this, newLineNumber++);
1912
- const oldDiffLine = __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getOldDiffLine).call(this, oldLineNumber);
1913
- if (newDiffLine) {
1914
- newFileContent += newDiffLine.text;
1915
- oldLineNumber = newDiffLine.oldLineNumber ? newDiffLine.oldLineNumber + 1 : oldLineNumber;
1916
- }
1917
- else {
1918
- if (!oldDiffLine) {
1919
- newFileContent += __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getOldRawLine).call(this, oldLineNumber);
1920
- }
1921
- oldLineNumber++;
1922
- }
1923
- if (!hasSymbolChanged && newDiffLine && oldDiffLine) {
1924
- hasSymbolChanged = hasSymbolChanged || newDiffLine.noTrailingNewLine !== oldDiffLine.noTrailingNewLine;
1925
- }
1926
- }
1927
- if (!hasSymbolChanged && newFileContent === this._oldFileContent)
1928
- return;
1929
- this._newFileContent = newFileContent;
1930
- __classPrivateFieldSet(this, _DiffFile_newFileResult, getFile(this._newFileContent, this._newFileLang, this._newFileName), "f");
1931
- }
1932
- else if (__classPrivateFieldGet(this, _DiffFile_newFileResult, "f")) {
1933
- let oldLineNumber = 1;
1934
- let newLineNumber = 1;
1935
- let oldFileContent = "";
1936
- let hasSymbolChanged = false;
1937
- while (newLineNumber <= __classPrivateFieldGet(this, _DiffFile_newFileResult, "f").maxLineNumber) {
1938
- const oldDiffLine = __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getOldDiffLine).call(this, oldLineNumber++);
1939
- const newDiffLine = __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getNewDiffLine).call(this, newLineNumber);
1940
- if (oldDiffLine) {
1941
- oldFileContent += oldDiffLine.text;
1942
- newLineNumber = oldDiffLine.newLineNumber ? oldDiffLine.newLineNumber + 1 : newLineNumber;
1943
- }
1944
- else {
1945
- if (!newDiffLine) {
1946
- oldFileContent += __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getNewRawLine).call(this, newLineNumber);
1947
- }
1948
- newLineNumber++;
1949
- }
1950
- if (!hasSymbolChanged && newDiffLine && oldDiffLine) {
1951
- hasSymbolChanged = hasSymbolChanged || newDiffLine.noTrailingNewLine !== oldDiffLine.noTrailingNewLine;
1952
- }
1953
- }
1954
- if (!hasSymbolChanged && oldFileContent === this._newFileContent)
1955
- return;
1956
- this._oldFileContent = oldFileContent;
1957
- __classPrivateFieldSet(this, _DiffFile_oldFileResult, getFile(this._oldFileContent, this._oldFileLang, this._oldFileName), "f");
1958
- }
1959
- __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_composeRaw).call(this);
1960
- }, _DiffFile_composeDiff = function _DiffFile_composeDiff() {
1961
- var _a;
1962
- if (!((_a = __classPrivateFieldGet(this, _DiffFile_diffListResults, "f")) === null || _a === void 0 ? void 0 : _a.length))
1963
- return;
1964
- __classPrivateFieldGet(this, _DiffFile_diffListResults, "f").forEach((item) => {
1965
- const hunks = item.hunks;
1966
- hunks.forEach((hunk) => {
1967
- let additions = [];
1968
- let deletions = [];
1969
- hunk.lines.forEach((line) => {
1970
- if (line.type === exports.DiffLineType.Add) {
1971
- additions.push(line);
1972
- }
1973
- else if (line.type === exports.DiffLineType.Delete) {
1974
- deletions.push(line);
1975
- }
1976
- else {
1977
- getDiffRange(additions, deletions);
1978
- additions = [];
1979
- deletions = [];
1980
- }
1981
- });
1982
- getDiffRange(additions, deletions);
1983
- });
1984
- });
1985
- __classPrivateFieldSet(this, _DiffFile_diffLines, [], "f");
1986
- const tmp = [];
1987
- __classPrivateFieldGet(this, _DiffFile_diffListResults, "f").forEach((item) => {
1988
- item.hunks.forEach((_item) => {
1989
- tmp.push(..._item.lines);
1990
- });
1991
- });
1992
- __classPrivateFieldSet(this, _DiffFile_diffLines, tmp.map((i, index) => {
1993
- var _a;
1994
- const typedI = i;
1995
- typedI.index = index;
1996
- if (typedI.type === exports.DiffLineType.Hunk) {
1997
- const numInfo = (_a = typedI.text.split("@@")) === null || _a === void 0 ? void 0 : _a[1].split(" ").filter(Boolean);
1998
- const oldNumInfo = (numInfo === null || numInfo === void 0 ? void 0 : numInfo[0]) || "";
1999
- const newNumInfo = (numInfo === null || numInfo === void 0 ? void 0 : numInfo[1]) || "";
2000
- const [oldNumStartIndex, oldNumLength] = oldNumInfo.split(",");
2001
- const [newNumStartIndex, newNumLength] = newNumInfo.split(",");
2002
- const typedTypeI = typedI;
2003
- typedTypeI.hunkInfo = {
2004
- oldStartIndex: -Number(oldNumStartIndex),
2005
- oldLength: Number(oldNumLength),
2006
- newStartIndex: +Number(newNumStartIndex),
2007
- newLength: Number(newNumLength),
2008
- _oldStartIndex: -Number(oldNumStartIndex),
2009
- _oldLength: Number(oldNumLength),
2010
- _newStartIndex: +Number(newNumStartIndex),
2011
- _newLength: Number(newNumLength),
2012
- };
2013
- }
2014
- return typedI;
2015
- }), "f");
2016
- // this.#diffLines = this.#diffListResults
2017
- // .reduce<DiffLine[]>((p, c) => p.concat(...c.hunks.reduce<DiffLine[]>((_p, _c) => _p.concat(..._c.lines), [])), [])
2018
- // .map<DiffLineItem>((i, index) => {
2019
- // const typedI = i as DiffLineItem;
2020
- // typedI.index = index;
2021
- // if (typedI.type === DiffLineType.Hunk) {
2022
- // const numInfo = typedI.text.split("@@")?.[1].split(" ").filter(Boolean);
2023
- // const oldNumInfo = numInfo?.[0] || "";
2024
- // const newNumInfo = numInfo?.[1] || "";
2025
- // const [oldNumStartIndex, oldNumLength] = oldNumInfo.split(",");
2026
- // const [newNumStartIndex, newNumLength] = newNumInfo.split(",");
2027
- // const typedTypeI = typedI as DiffHunkItem;
2028
- // typedTypeI.hunkInfo = {
2029
- // oldStartIndex: -Number(oldNumStartIndex),
2030
- // oldLength: Number(oldNumLength),
2031
- // newStartIndex: +Number(newNumStartIndex),
2032
- // newLength: Number(newNumLength),
2033
- // };
2034
- // }
2035
- // return typedI;
2036
- // });
2037
- __classPrivateFieldSet(this, _DiffFile_oldFileDiffLines, {}, "f");
2038
- __classPrivateFieldGet(this, _DiffFile_diffLines, "f").forEach((item) => {
2039
- if (item.oldLineNumber) {
2040
- this.diffLineLength = Math.max(this.diffLineLength, item.oldLineNumber);
2041
- __classPrivateFieldGet(this, _DiffFile_oldFileDiffLines, "f")[item.oldLineNumber] = item;
2042
- }
2043
- });
2044
- __classPrivateFieldSet(this, _DiffFile_newFileDiffLines, {}, "f");
2045
- __classPrivateFieldGet(this, _DiffFile_diffLines, "f").forEach((item) => {
2046
- if (item.newLineNumber) {
2047
- this.diffLineLength = Math.max(this.diffLineLength, item.newLineNumber);
2048
- __classPrivateFieldGet(this, _DiffFile_newFileDiffLines, "f")[item.newLineNumber] = item;
2049
- }
2050
- });
2051
- }, _DiffFile_composeSyntax = function _DiffFile_composeSyntax({ registerHighlighter }) {
2052
- var _a, _b, _c, _d;
2053
- (_a = __classPrivateFieldGet(this, _DiffFile_oldFileResult, "f")) === null || _a === void 0 ? void 0 : _a.doSyntax({ registerHighlighter });
2054
- __classPrivateFieldSet(this, _DiffFile_oldFileSyntaxLines, (_b = __classPrivateFieldGet(this, _DiffFile_oldFileResult, "f")) === null || _b === void 0 ? void 0 : _b.syntaxFile, "f");
2055
- (_c = __classPrivateFieldGet(this, _DiffFile_newFileResult, "f")) === null || _c === void 0 ? void 0 : _c.doSyntax({ registerHighlighter });
2056
- __classPrivateFieldSet(this, _DiffFile_newFileSyntaxLines, (_d = __classPrivateFieldGet(this, _DiffFile_newFileResult, "f")) === null || _d === void 0 ? void 0 : _d.syntaxFile, "f");
2057
- }, _DiffFile_getOldDiffLine = function _DiffFile_getOldDiffLine(lineNumber) {
2058
- var _a;
2059
- if (!lineNumber)
2060
- return;
2061
- return (_a = __classPrivateFieldGet(this, _DiffFile_oldFileDiffLines, "f")) === null || _a === void 0 ? void 0 : _a[lineNumber];
2062
- }, _DiffFile_getNewDiffLine = function _DiffFile_getNewDiffLine(lineNumber) {
2063
- var _a;
2064
- if (!lineNumber)
2065
- return;
2066
- return (_a = __classPrivateFieldGet(this, _DiffFile_newFileDiffLines, "f")) === null || _a === void 0 ? void 0 : _a[lineNumber];
2067
- }, _DiffFile_getOldRawLine = function _DiffFile_getOldRawLine(lineNumber) {
2068
- var _a;
2069
- return (_a = __classPrivateFieldGet(this, _DiffFile_oldFileLines, "f")) === null || _a === void 0 ? void 0 : _a[lineNumber];
2070
- }, _DiffFile_getNewRawLine = function _DiffFile_getNewRawLine(lineNumber) {
2071
- var _a;
2072
- return (_a = __classPrivateFieldGet(this, _DiffFile_newFileLines, "f")) === null || _a === void 0 ? void 0 : _a[lineNumber];
2073
- };
2074
-
2075
- exports.DiffFileLineType = void 0;
2076
- (function (DiffFileLineType) {
2077
- DiffFileLineType[DiffFileLineType["hunk"] = 1] = "hunk";
2078
- DiffFileLineType[DiffFileLineType["content"] = 2] = "content";
2079
- DiffFileLineType[DiffFileLineType["widget"] = 3] = "widget";
2080
- DiffFileLineType[DiffFileLineType["extend"] = 4] = "extend";
2081
- })(exports.DiffFileLineType || (exports.DiffFileLineType = {}));
2082
- const getSplitLines = (diffFile, options) => {
2083
- const splitLineLength = diffFile.splitLineLength;
2084
- const splitLines = [];
2085
- numIterator(splitLineLength, (index) => {
2086
- var _a, _b;
2087
- const hunkLine = diffFile.getSplitHunkLine(index);
2088
- const splitLeftLine = diffFile.getSplitLeftLine(index);
2089
- const splitRightLine = diffFile.getSplitRightLine(index);
2090
- const widgetLine = (options === null || options === void 0 ? void 0 : options.hasRenderWidget) && ((_a = options.widgetData) === null || _a === void 0 ? void 0 : _a[index + 1]);
2091
- const extendLine = (options === null || options === void 0 ? void 0 : options.hasRenderExtend) && ((_b = options.extendData) === null || _b === void 0 ? void 0 : _b[index + 1]);
2092
- hunkLine &&
2093
- hunkLine.splitInfo &&
2094
- hunkLine.splitInfo.startHiddenIndex < hunkLine.splitInfo.endHiddenIndex &&
2095
- splitLines.push({ type: exports.DiffFileLineType.hunk, index, lineNumber: index + 1, hunkLine: hunkLine });
2096
- hunkLine &&
2097
- !hunkLine.splitInfo &&
2098
- !hunkLine.unifiedInfo &&
2099
- hunkLine.type === exports.DiffLineType.Hunk &&
2100
- splitLines.push({ type: exports.DiffFileLineType.hunk, index, lineNumber: index + 1, hunkLine: hunkLine });
2101
- !(splitLeftLine === null || splitLeftLine === void 0 ? void 0 : splitLeftLine.isHidden) &&
2102
- !(splitRightLine === null || splitRightLine === void 0 ? void 0 : splitRightLine.isHidden) &&
2103
- splitLines.push({
2104
- type: exports.DiffFileLineType.content,
2105
- index,
2106
- lineNumber: index + 1,
2107
- splitLine: { left: splitLeftLine, right: splitRightLine },
2108
- });
2109
- widgetLine &&
2110
- splitLines.push({ type: exports.DiffFileLineType.widget, index, lineNumber: index + 1, widgetLine: widgetLine });
2111
- extendLine &&
2112
- splitLines.push({ type: exports.DiffFileLineType.extend, index, lineNumber: index + 1, extendLine: extendLine });
2113
- });
2114
- return splitLines;
2115
- };
2116
- const getSplitContentLines = (diffFile) => {
2117
- const lines = getSplitLines(diffFile, {});
2118
- return lines.filter((line) => line.type === exports.DiffFileLineType.content);
2119
- };
2120
- const getUnifiedLines = (diffFile, options) => {
2121
- const unifiedLineLength = diffFile.unifiedLineLength;
2122
- const unifiedLines = [];
2123
- numIterator(unifiedLineLength, (index) => {
2124
- var _a, _b;
2125
- const hunkLine = diffFile.getUnifiedHunkLine(index);
2126
- const unifiedLine = diffFile.getUnifiedLine(index);
2127
- const widgetLine = (options === null || options === void 0 ? void 0 : options.hasRenderWidget) && ((_a = options.widgetData) === null || _a === void 0 ? void 0 : _a[index + 1]);
2128
- const extendLine = (options === null || options === void 0 ? void 0 : options.hasRenderExtend) && ((_b = options.extendData) === null || _b === void 0 ? void 0 : _b[index + 1]);
2129
- hunkLine &&
2130
- hunkLine.unifiedInfo &&
2131
- hunkLine.unifiedInfo.startHiddenIndex < hunkLine.unifiedInfo.endHiddenIndex &&
2132
- unifiedLines.push({ type: exports.DiffFileLineType.hunk, index, lineNumber: index + 1, hunkLine: hunkLine });
2133
- hunkLine &&
2134
- !hunkLine.splitInfo &&
2135
- !hunkLine.unifiedInfo &&
2136
- hunkLine.type === exports.DiffLineType.Hunk &&
2137
- unifiedLines.push({ type: exports.DiffFileLineType.hunk, index, lineNumber: index + 1, hunkLine: hunkLine });
2138
- !unifiedLine.isHidden &&
2139
- unifiedLines.push({ type: exports.DiffFileLineType.content, index, lineNumber: index + 1, unifiedLine: unifiedLine });
2140
- widgetLine &&
2141
- unifiedLines.push({ type: exports.DiffFileLineType.widget, index, lineNumber: index + 1, widgetLine: widgetLine });
2142
- extendLine &&
2143
- unifiedLines.push({ type: exports.DiffFileLineType.extend, index, lineNumber: index + 1, extendLine: extendLine });
2144
- });
2145
- return unifiedLines;
2146
- };
2147
- const getUnifiedContentLine = (diffFile) => {
2148
- const lines = getUnifiedLines(diffFile, {});
2149
- return lines.filter((line) => line.type === exports.DiffFileLineType.content);
2150
- };
2151
-
2152
- const versions = "0.0.12";
2153
-
2154
75
  const useUnmount = (cb, deps) => {
2155
76
  const ref = React.useRef(cb);
2156
77
  ref.current = cb;
@@ -2170,14 +91,14 @@ class TextMeasure {
2170
91
  }
2171
92
  measure(text, font) {
2172
93
  const currentKey = `${font === null || font === void 0 ? void 0 : font.fontFamily}-${font === null || font === void 0 ? void 0 : font.fontStyle}-${font === null || font === void 0 ? void 0 : font.fontSize}-${text}`;
2173
- if (__classPrivateFieldGet$1(this, _TextMeasure_map, "f")[currentKey]) {
2174
- return __classPrivateFieldGet$1(this, _TextMeasure_map, "f")[currentKey];
94
+ if (__classPrivateFieldGet(this, _TextMeasure_map, "f")[currentKey]) {
95
+ return __classPrivateFieldGet(this, _TextMeasure_map, "f")[currentKey];
2175
96
  }
2176
- const instance = __classPrivateFieldGet$1(this, _TextMeasure_instances, "m", _TextMeasure_getInstance).call(this);
97
+ const instance = __classPrivateFieldGet(this, _TextMeasure_instances, "m", _TextMeasure_getInstance).call(this);
2177
98
  if (font) {
2178
99
  const currentFontKey = `${font.fontFamily}-${font.fontStyle}-${font.fontSize}`;
2179
- if (__classPrivateFieldGet$1(this, _TextMeasure_key, "f") !== currentFontKey) {
2180
- __classPrivateFieldSet$1(this, _TextMeasure_key, currentFontKey, "f");
100
+ if (__classPrivateFieldGet(this, _TextMeasure_key, "f") !== currentFontKey) {
101
+ __classPrivateFieldSet(this, _TextMeasure_key, currentFontKey, "f");
2181
102
  instance.font = `${font.fontStyle || ""} ${font.fontSize || ""} ${font.fontFamily || ""}`;
2182
103
  }
2183
104
  }
@@ -2456,8 +377,8 @@ const _DiffSplitHunkLineGitHub = ({ index, diffFile, side, lineNumber, }) => {
2456
377
  const couldExpand = expandEnabled && currentHunk && currentHunk.splitInfo;
2457
378
  const isExpandAll = currentHunk &&
2458
379
  currentHunk.splitInfo &&
2459
- currentHunk.splitInfo.endHiddenIndex - currentHunk.splitInfo.startHiddenIndex < composeLen;
2460
- const isFirstLine = currentHunk && currentHunk.index === 0;
380
+ currentHunk.splitInfo.endHiddenIndex - currentHunk.splitInfo.startHiddenIndex < core.composeLen;
381
+ const isFirstLine = currentHunk && currentHunk.isFirst;
2461
382
  const isLastLine = currentHunk && currentHunk.isLast;
2462
383
  return (React__namespace.createElement("tr", { "data-line": `${lineNumber}-hunk`, "data-state": "hunk", "data-side": exports.SplitSide[side], className: "diff-line diff-line-hunk" }, enableHunkAction ? (React__namespace.createElement(React__namespace.Fragment, null,
2463
384
  React__namespace.createElement("td", { className: "diff-line-hunk-action sticky left-0 p-[1px] w-[1%] min-w-[40px] select-none", style: {
@@ -2494,8 +415,8 @@ const _DiffSplitHunkLineGitLab = ({ index, diffFile, side, lineNumber, }) => {
2494
415
  const couldExpand = expandEnabled && currentHunk && currentHunk.splitInfo;
2495
416
  const isExpandAll = currentHunk &&
2496
417
  currentHunk.splitInfo &&
2497
- currentHunk.splitInfo.endHiddenIndex - currentHunk.splitInfo.startHiddenIndex < composeLen;
2498
- const isFirstLine = currentHunk && currentHunk.index === 0;
418
+ currentHunk.splitInfo.endHiddenIndex - currentHunk.splitInfo.startHiddenIndex < core.composeLen;
419
+ const isFirstLine = currentHunk && currentHunk.isFirst;
2499
420
  const isLastLine = currentHunk && currentHunk.isLast;
2500
421
  return (React__namespace.createElement("tr", { "data-line": `${lineNumber}-hunk`, "data-state": "hunk", "data-side": exports.SplitSide[side], className: "diff-line diff-line-hunk" },
2501
422
  React__namespace.createElement("td", { className: "diff-line-hunk-action sticky left-0 p-[1px] w-[1%] min-w-[40px] select-none", style: {
@@ -2618,16 +539,16 @@ const DiffString = ({ rawLine, diffLine, operator, enableWrap, }) => {
2618
539
  React__namespace.createElement("span", { "data-diff-highlight": true, className: "rounded-[0.2em]", style: {
2619
540
  backgroundColor: operator === "add" ? `var(${addContentHighlightBGName})` : `var(${delContentHighlightBGName})`,
2620
541
  } }, isLast
2621
- ? `${_str2}${isNewLineSymbolChanged === exports.NewLineSymbol.LF
542
+ ? `${_str2}${isNewLineSymbolChanged === core.NewLineSymbol.LF
2622
543
  ? "␊"
2623
- : isNewLineSymbolChanged === exports.NewLineSymbol.CR
544
+ : isNewLineSymbolChanged === core.NewLineSymbol.CR
2624
545
  ? "␍"
2625
- : isNewLineSymbolChanged === exports.NewLineSymbol.CRLF
546
+ : isNewLineSymbolChanged === core.NewLineSymbol.CRLF
2626
547
  ? "␍␊"
2627
548
  : ""}`
2628
549
  : str2),
2629
550
  str3),
2630
- isNewLineSymbolChanged === exports.NewLineSymbol.NEWLINE && diffLine.noTrailingNewLine && (React__namespace.createElement("span", { "data-no-newline-at-end-of-file": true, className: enableWrap ? "block text-red-500" : "inline-block align-middle text-red-500", style: {
551
+ isNewLineSymbolChanged === core.NewLineSymbol.NEWLINE && diffLine.noTrailingNewLine && (React__namespace.createElement("span", { "data-no-newline-at-end-of-file": true, className: enableWrap ? "block text-red-500" : "inline-block align-middle text-red-500", style: {
2631
552
  width: `var(${diffFontSizeName})`,
2632
553
  height: `var(${diffFontSizeName})`,
2633
554
  } },
@@ -2668,18 +589,18 @@ const DiffSyntax = ({ rawLine, diffLine, operator, syntaxLine, enableWrap, }) =>
2668
589
  borderTopRightRadius: isEnd || isLast ? "0.2em" : undefined,
2669
590
  borderBottomRightRadius: isEnd || isLast ? "0.2em" : undefined,
2670
591
  } }, isLast
2671
- ? `${_str2}${isNewLineSymbolChanged === exports.NewLineSymbol.LF
592
+ ? `${_str2}${isNewLineSymbolChanged === core.NewLineSymbol.LF
2672
593
  ? "␊"
2673
- : isNewLineSymbolChanged === exports.NewLineSymbol.CR
594
+ : isNewLineSymbolChanged === core.NewLineSymbol.CR
2674
595
  ? "␍"
2675
- : isNewLineSymbolChanged === exports.NewLineSymbol.CRLF
596
+ : isNewLineSymbolChanged === core.NewLineSymbol.CRLF
2676
597
  ? "␍␊"
2677
598
  : ""}`
2678
599
  : str2),
2679
600
  str3));
2680
601
  }
2681
602
  })),
2682
- isNewLineSymbolChanged === exports.NewLineSymbol.NEWLINE && diffLine.noTrailingNewLine && (React__namespace.createElement("span", { "data-no-newline-at-end-of-file": true, className: enableWrap ? "block text-red-500" : "inline-block align-middle text-red-500", style: {
603
+ isNewLineSymbolChanged === core.NewLineSymbol.NEWLINE && diffLine.noTrailingNewLine && (React__namespace.createElement("span", { "data-no-newline-at-end-of-file": true, className: enableWrap ? "block text-red-500" : "inline-block align-middle text-red-500", style: {
2683
604
  width: `var(${diffFontSizeName})`,
2684
605
  height: `var(${diffFontSizeName})`,
2685
606
  } },
@@ -2692,8 +613,8 @@ const DiffSyntax = ({ rawLine, diffLine, operator, syntaxLine, enableWrap, }) =>
2692
613
  };
2693
614
  const DiffContent = ({ diffLine, rawLine, syntaxLine, enableWrap, enableHighlight, }) => {
2694
615
  var _a;
2695
- const isAdded = (diffLine === null || diffLine === void 0 ? void 0 : diffLine.type) === exports.DiffLineType.Add;
2696
- const isDelete = (diffLine === null || diffLine === void 0 ? void 0 : diffLine.type) === exports.DiffLineType.Delete;
616
+ const isAdded = (diffLine === null || diffLine === void 0 ? void 0 : diffLine.type) === core.DiffLineType.Add;
617
+ const isDelete = (diffLine === null || diffLine === void 0 ? void 0 : diffLine.type) === core.DiffLineType.Delete;
2697
618
  const isMaxLineLengthToIgnoreSyntax = ((_a = syntaxLine === null || syntaxLine === void 0 ? void 0 : syntaxLine.nodeList) === null || _a === void 0 ? void 0 : _a.length) > 150;
2698
619
  return (React__namespace.createElement("div", { className: "diff-line-content-item pl-[2.0em]", "data-val": rawLine, style: {
2699
620
  whiteSpace: enableWrap ? "pre-wrap" : "pre",
@@ -2715,9 +636,9 @@ const _DiffSplitLine$1 = ({ index, diffFile, lineNumber, side, }) => {
2715
636
  const currentLine = side === exports.SplitSide.old ? oldLine : newLine;
2716
637
  const hasDiff = !!(currentLine === null || currentLine === void 0 ? void 0 : currentLine.diff);
2717
638
  const hasContent = !!currentLine.lineNumber;
2718
- const hasChange = checkDiffLineIncludeChange(currentLine === null || currentLine === void 0 ? void 0 : currentLine.diff);
2719
- const isAdded = ((_a = currentLine === null || currentLine === void 0 ? void 0 : currentLine.diff) === null || _a === void 0 ? void 0 : _a.type) === exports.DiffLineType.Add;
2720
- const isDelete = ((_b = currentLine === null || currentLine === void 0 ? void 0 : currentLine.diff) === null || _b === void 0 ? void 0 : _b.type) === exports.DiffLineType.Delete;
639
+ const hasChange = core.checkDiffLineIncludeChange(currentLine === null || currentLine === void 0 ? void 0 : currentLine.diff);
640
+ const isAdded = ((_a = currentLine === null || currentLine === void 0 ? void 0 : currentLine.diff) === null || _a === void 0 ? void 0 : _a.type) === core.DiffLineType.Add;
641
+ const isDelete = ((_b = currentLine === null || currentLine === void 0 ? void 0 : currentLine.diff) === null || _b === void 0 ? void 0 : _b.type) === core.DiffLineType.Delete;
2721
642
  const { useDiffContext } = useDiffViewContext();
2722
643
  const { enableHighlight, enableAddWidget, onAddWidgetClick } = useDiffContext(React__namespace.useCallback((s) => ({
2723
644
  enableHighlight: s.enableHighlight,
@@ -2802,7 +723,7 @@ const onMouseDown$1 = (e) => {
2802
723
  };
2803
724
  const DiffSplitViewTable = ({ side, diffFile }) => {
2804
725
  const className = side === exports.SplitSide.new ? "new-diff-table" : "old-diff-table";
2805
- const lines = getSplitContentLines(diffFile);
726
+ const lines = core.getSplitContentLines(diffFile);
2806
727
  return (React__namespace.createElement("table", { className: className + " border-collapse w-full", "data-mode": exports.SplitSide[side] },
2807
728
  React__namespace.createElement("colgroup", null,
2808
729
  React__namespace.createElement("col", { className: `diff-table-${exports.SplitSide[side]}-num-col` }),
@@ -2826,10 +747,10 @@ const DiffSplitViewTable = ({ side, diffFile }) => {
2826
747
  const DiffSplitViewNormal = React.memo(({ diffFile }) => {
2827
748
  const ref1 = React.useRef(null);
2828
749
  const ref2 = React.useRef(null);
2829
- const splitLineLength = diffFile.splitLineLength;
750
+ const splitLineLength = Math.max(diffFile.splitLineLength, diffFile.fileLineLength);
2830
751
  const { useDiffContext } = useDiffViewContext();
2831
752
  const fontSize = useDiffContext(React.useCallback((s) => s.fontSize, []));
2832
- shim.useSyncExternalStore(diffFile.subscribe, diffFile.getUpdateCount);
753
+ index_js.useSyncExternalStore(diffFile.subscribe, diffFile.getUpdateCount);
2833
754
  React.useEffect(() => {
2834
755
  const left = ref1.current;
2835
756
  const right = ref2.current;
@@ -2921,12 +842,12 @@ const DiffSplitHunkLineGitHub = ({ index, diffFile, lineNumber, }) => {
2921
842
  const couldExpand = expandEnabled && currentHunk && currentHunk.splitInfo;
2922
843
  const isExpandAll = currentHunk &&
2923
844
  currentHunk.splitInfo &&
2924
- currentHunk.splitInfo.endHiddenIndex - currentHunk.splitInfo.startHiddenIndex < composeLen;
845
+ currentHunk.splitInfo.endHiddenIndex - currentHunk.splitInfo.startHiddenIndex < core.composeLen;
2925
846
  const currentIsShow = currentHunk &&
2926
847
  currentHunk.splitInfo &&
2927
848
  currentHunk.splitInfo.startHiddenIndex < currentHunk.splitInfo.endHiddenIndex;
2928
849
  const currentIsPureHunk = currentHunk && diffFile._getIsPureDiffRender() && !currentHunk.splitInfo;
2929
- const isFirstLine = currentHunk && currentHunk.index === 0;
850
+ const isFirstLine = currentHunk && currentHunk.isFirst;
2930
851
  const isLastLine = currentHunk && currentHunk.isLast;
2931
852
  if (!currentIsShow && !currentIsPureHunk)
2932
853
  return null;
@@ -2954,12 +875,12 @@ const DiffSplitHunkLineGitLab = ({ index, diffFile, lineNumber, }) => {
2954
875
  const couldExpand = expandEnabled && currentHunk && currentHunk.splitInfo;
2955
876
  const isExpandAll = currentHunk &&
2956
877
  currentHunk.splitInfo &&
2957
- currentHunk.splitInfo.endHiddenIndex - currentHunk.splitInfo.startHiddenIndex < composeLen;
878
+ currentHunk.splitInfo.endHiddenIndex - currentHunk.splitInfo.startHiddenIndex < core.composeLen;
2958
879
  const currentIsShow = currentHunk &&
2959
880
  currentHunk.splitInfo &&
2960
881
  currentHunk.splitInfo.startHiddenIndex < currentHunk.splitInfo.endHiddenIndex;
2961
882
  const currentIsPureHunk = currentHunk && diffFile._getIsPureDiffRender() && !currentHunk.splitInfo;
2962
- const isFirstLine = currentHunk && currentHunk.index === 0;
883
+ const isFirstLine = currentHunk && currentHunk.isFirst;
2963
884
  const isLastLine = currentHunk && currentHunk.isLast;
2964
885
  if (!currentIsShow && !currentIsPureHunk)
2965
886
  return null;
@@ -3015,9 +936,9 @@ const _DiffSplitLine = ({ index, diffFile, lineNumber }) => {
3015
936
  const oldSyntaxLine = diffFile.getOldSyntaxLine(oldLine === null || oldLine === void 0 ? void 0 : oldLine.lineNumber);
3016
937
  const newSyntaxLine = diffFile.getNewSyntaxLine(newLine === null || newLine === void 0 ? void 0 : newLine.lineNumber);
3017
938
  const hasDiff = !!(oldLine === null || oldLine === void 0 ? void 0 : oldLine.diff) || !!(newLine === null || newLine === void 0 ? void 0 : newLine.diff);
3018
- const hasChange = checkDiffLineIncludeChange(oldLine === null || oldLine === void 0 ? void 0 : oldLine.diff) || checkDiffLineIncludeChange(newLine === null || newLine === void 0 ? void 0 : newLine.diff);
3019
- const oldLineIsDelete = ((_a = oldLine === null || oldLine === void 0 ? void 0 : oldLine.diff) === null || _a === void 0 ? void 0 : _a.type) === exports.DiffLineType.Delete;
3020
- const newLineIsAdded = ((_b = newLine === null || newLine === void 0 ? void 0 : newLine.diff) === null || _b === void 0 ? void 0 : _b.type) === exports.DiffLineType.Add;
939
+ const hasChange = core.checkDiffLineIncludeChange(oldLine === null || oldLine === void 0 ? void 0 : oldLine.diff) || core.checkDiffLineIncludeChange(newLine === null || newLine === void 0 ? void 0 : newLine.diff);
940
+ const oldLineIsDelete = ((_a = oldLine === null || oldLine === void 0 ? void 0 : oldLine.diff) === null || _a === void 0 ? void 0 : _a.type) === core.DiffLineType.Delete;
941
+ const newLineIsAdded = ((_b = newLine === null || newLine === void 0 ? void 0 : newLine.diff) === null || _b === void 0 ? void 0 : _b.type) === core.DiffLineType.Add;
3021
942
  const { useDiffContext } = useDiffViewContext();
3022
943
  const { enableHighlight, enableAddWidget, onAddWidgetClick } = useDiffContext(React__namespace.useCallback((s) => ({
3023
944
  enableHighlight: s.enableHighlight,
@@ -3107,7 +1028,7 @@ const Style = ({ useSelector, id, }) => {
3107
1028
  : ""));
3108
1029
  };
3109
1030
  const DiffSplitViewWrap = React.memo(({ diffFile }) => {
3110
- const splitLineLength = diffFile.splitLineLength;
1031
+ const splitLineLength = Math.max(diffFile.splitLineLength, diffFile.fileLineLength);
3111
1032
  const { useDiffContext } = useDiffViewContext();
3112
1033
  const splitSideInfo = React.useMemo(() => reactivityStore.createStore(() => {
3113
1034
  const splitRef = reactivityStore.ref(undefined);
@@ -3120,7 +1041,7 @@ const DiffSplitViewWrap = React.memo(({ diffFile }) => {
3120
1041
  }), []);
3121
1042
  const setSelectSide = splitSideInfo.getReadonlyState().setSplit;
3122
1043
  const fontSize = useDiffContext(React.useCallback((s) => s.fontSize, []));
3123
- shim.useSyncExternalStore(diffFile.subscribe, diffFile.getUpdateCount);
1044
+ index_js.useSyncExternalStore(diffFile.subscribe, diffFile.getUpdateCount);
3124
1045
  const onMouseDown = React.useCallback((e) => {
3125
1046
  let ele = e.target;
3126
1047
  // need remove all the selection
@@ -3145,7 +1066,7 @@ const DiffSplitViewWrap = React.memo(({ diffFile }) => {
3145
1066
  font,
3146
1067
  });
3147
1068
  const width = Math.max(40, _width + 25);
3148
- const lines = getSplitContentLines(diffFile);
1069
+ const lines = core.getSplitContentLines(diffFile);
3149
1070
  return (React__namespace.createElement("div", { className: "split-diff-view split-diff-view-normal w-full" },
3150
1071
  React__namespace.createElement("div", { className: "diff-table-wrapper w-full", style: {
3151
1072
  fontFamily: "Menlo, Consolas, monospace",
@@ -3256,8 +1177,8 @@ const _DiffUnifiedHunkLine = ({ index, diffFile, lineNumber, }) => {
3256
1177
  const couldExpand = expandEnabled && currentHunk && currentHunk.unifiedInfo;
3257
1178
  const isExpandAll = currentHunk &&
3258
1179
  currentHunk.unifiedInfo &&
3259
- currentHunk.unifiedInfo.endHiddenIndex - currentHunk.unifiedInfo.startHiddenIndex < composeLen;
3260
- const isFirstLine = currentHunk && currentHunk.index === 0;
1180
+ currentHunk.unifiedInfo.endHiddenIndex - currentHunk.unifiedInfo.startHiddenIndex < core.composeLen;
1181
+ const isFirstLine = currentHunk && currentHunk.isFirst;
3261
1182
  const isLastLine = currentHunk && currentHunk.isLast;
3262
1183
  return (React__namespace.createElement("tr", { "data-line": `${lineNumber}-hunk`, "data-state": "hunk", className: "diff-line diff-line-hunk" },
3263
1184
  React__namespace.createElement("td", { className: "diff-line-hunk-action sticky left-0 p-[1px] w-[1%] min-w-[100px] select-none", style: {
@@ -3338,7 +1259,7 @@ const _DiffUnifiedLine = React.memo(({ index, diffFile, lineNumber }) => {
3338
1259
  const { useWidget } = useDiffWidgetContext();
3339
1260
  const setWidget = useWidget.getReadonlyState().setWidget;
3340
1261
  const hasDiff = unifiedLine.diff;
3341
- const hasChange = checkDiffLineIncludeChange(unifiedLine.diff);
1262
+ const hasChange = core.checkDiffLineIncludeChange(unifiedLine.diff);
3342
1263
  const rawLine = unifiedLine.value || "";
3343
1264
  const diffLine = unifiedLine.diff;
3344
1265
  const newLineNumber = unifiedLine.newLineNumber;
@@ -3444,18 +1365,18 @@ const DiffUnifiedView = React.memo(({ diffFile }) => {
3444
1365
  }), [useDiffContext]);
3445
1366
  const contextValue = React.useMemo(() => ({ useWidget }), [useWidget]);
3446
1367
  const fontSize = useDiffContext(React.useCallback((s) => s.fontSize, []));
3447
- shim.useSyncExternalStore(diffFile.subscribe, diffFile.getUpdateCount);
1368
+ index_js.useSyncExternalStore(diffFile.subscribe, diffFile.getUpdateCount);
3448
1369
  React.useEffect(() => {
3449
1370
  const { setWidget } = useWidget.getReadonlyState();
3450
1371
  setWidget({});
3451
1372
  }, [diffFile, useWidget]);
3452
- const unifiedLineLength = diffFile.unifiedLineLength;
1373
+ const unifiedLineLength = Math.max(diffFile.unifiedLineLength, diffFile.fileLineLength);
3453
1374
  const _width = useTextWidth({
3454
1375
  text: unifiedLineLength.toString(),
3455
1376
  font: { fontSize: fontSize + "px", fontFamily: "Menlo, Consolas, monospace" },
3456
1377
  });
3457
1378
  const width = Math.max(40, _width + 25);
3458
- const lines = getUnifiedContentLine(diffFile);
1379
+ const lines = core.getUnifiedContentLine(diffFile);
3459
1380
  return (React__namespace.createElement(DiffWidgetContext.Provider, { value: contextValue },
3460
1381
  React__namespace.createElement("div", { className: "unified-diff-view w-full" },
3461
1382
  React__namespace.createElement("div", { className: "unified-diff-table-wrapper overflow-x-auto overflow-y-hidden w-full scrollbar-hide scrollbar-disable", style: {
@@ -3483,7 +1404,7 @@ const DiffUnifiedView = React.memo(({ diffFile }) => {
3483
1404
  DiffUnifiedView.displayName = "DiffUnifiedView";
3484
1405
 
3485
1406
  const diffFontSizeName = "--diff-font-size--";
3486
- _cacheMap.name = "@git-diff-view/react";
1407
+ core._cacheMap.name = "@git-diff-view/react";
3487
1408
  exports.SplitSide = void 0;
3488
1409
  (function (SplitSide) {
3489
1410
  SplitSide[SplitSide["old"] = 1] = "old";
@@ -3538,8 +1459,8 @@ const _InternalDiffView = (props) => {
3538
1459
  const renderExtendLine = reactivityStore.ref(props.renderExtendLine);
3539
1460
  const setRenderExtendLine = (_renderExtendLine) => (renderExtendLine.value = _renderExtendLine);
3540
1461
  // 避免无意义的订阅
3541
- const onAddWidgetClick = reactivityStore.ref(reactivityStore.markRaw({ current: props.onAddWidgetClick }));
3542
- const setOnAddWidgetClick = (_onAddWidgetClick) => (onAddWidgetClick.value.current = _onAddWidgetClick.current);
1462
+ const onAddWidgetClick = { current: props.onAddWidgetClick };
1463
+ const setOnAddWidgetClick = (_onAddWidgetClick) => (onAddWidgetClick.current = _onAddWidgetClick.current);
3543
1464
  return {
3544
1465
  id,
3545
1466
  setId,
@@ -3592,7 +1513,7 @@ const _InternalDiffView = (props) => {
3592
1513
  ]);
3593
1514
  const value = React.useMemo(() => ({ useDiffContext }), [useDiffContext]);
3594
1515
  return (React__namespace.createElement(DiffViewContext.Provider, { value: value },
3595
- React__namespace.createElement("div", { className: "diff-tailwindcss-wrapper", "data-component": "git-diff-view", "data-version": `${"0.0.12"}`, "data-highlighter": diffFile._getHighlighterName() },
1516
+ React__namespace.createElement("div", { className: "diff-tailwindcss-wrapper", "data-component": "git-diff-view", "data-version": `${"0.0.14"}`, "data-highlighter": diffFile._getHighlighterName() },
3596
1517
  React__namespace.createElement("div", { className: "diff-style-root", style: {
3597
1518
  // @ts-ignore
3598
1519
  [diffFontSizeName]: diffViewFontSize + "px",
@@ -3605,12 +1526,12 @@ const DiffViewWithRef = (props, ref) => {
3605
1526
  const diffFile = React.useMemo(() => {
3606
1527
  var _a, _b, _c, _d, _e, _f;
3607
1528
  if (_diffFile) {
3608
- const diffFile = DiffFile.createInstance({});
1529
+ const diffFile = core.DiffFile.createInstance({});
3609
1530
  diffFile._mergeFullBundle(_diffFile._getFullBundle());
3610
1531
  return diffFile;
3611
1532
  }
3612
1533
  else if (data) {
3613
- return new DiffFile(((_a = data === null || data === void 0 ? void 0 : data.oldFile) === null || _a === void 0 ? void 0 : _a.fileName) || "", ((_b = data === null || data === void 0 ? void 0 : data.oldFile) === null || _b === void 0 ? void 0 : _b.content) || "", ((_c = data === null || data === void 0 ? void 0 : data.newFile) === null || _c === void 0 ? void 0 : _c.fileName) || "", ((_d = data === null || data === void 0 ? void 0 : data.newFile) === null || _d === void 0 ? void 0 : _d.content) || "", (data === null || data === void 0 ? void 0 : data.hunks) || [], ((_e = data === null || data === void 0 ? void 0 : data.oldFile) === null || _e === void 0 ? void 0 : _e.fileLang) || "", ((_f = data === null || data === void 0 ? void 0 : data.newFile) === null || _f === void 0 ? void 0 : _f.fileLang) || "");
1534
+ return new core.DiffFile(((_a = data === null || data === void 0 ? void 0 : data.oldFile) === null || _a === void 0 ? void 0 : _a.fileName) || "", ((_b = data === null || data === void 0 ? void 0 : data.oldFile) === null || _b === void 0 ? void 0 : _b.content) || "", ((_c = data === null || data === void 0 ? void 0 : data.newFile) === null || _c === void 0 ? void 0 : _c.fileName) || "", ((_d = data === null || data === void 0 ? void 0 : data.newFile) === null || _d === void 0 ? void 0 : _d.content) || "", (data === null || data === void 0 ? void 0 : data.hunks) || [], ((_e = data === null || data === void 0 ? void 0 : data.oldFile) === null || _e === void 0 ? void 0 : _e.fileLang) || "", ((_f = data === null || data === void 0 ? void 0 : data.newFile) === null || _f === void 0 ? void 0 : _f.fileLang) || "");
3614
1535
  }
3615
1536
  return null;
3616
1537
  }, [data, _diffFile]);
@@ -3637,7 +1558,7 @@ const DiffViewWithRef = (props, ref) => {
3637
1558
  };
3638
1559
  }
3639
1560
  }, [diffFile, _diffFile]);
3640
- useUnmount(() => diffFile._destroy(), [diffFile]);
1561
+ useUnmount(() => { var _a; return (_a = diffFile === null || diffFile === void 0 ? void 0 : diffFile._destroy) === null || _a === void 0 ? void 0 : _a.call(diffFile); }, [diffFile]);
3641
1562
  React.useImperativeHandle(ref, () => ({ getDiffFileInstance: () => diffFile }), [diffFile]);
3642
1563
  if (!diffFile)
3643
1564
  return null;
@@ -3645,39 +1566,17 @@ const DiffViewWithRef = (props, ref) => {
3645
1566
  };
3646
1567
  const DiffView = React.forwardRef(DiffViewWithRef);
3647
1568
  DiffView.displayName = "DiffView";
3648
- const version = "0.0.12";
1569
+ const version = "0.0.14";
3649
1570
 
3650
- exports.DefaultDiffExpansionStep = DefaultDiffExpansionStep;
3651
- exports.DiffFile = DiffFile;
3652
- exports.DiffHunk = DiffHunk;
3653
- exports.DiffHunkHeader = DiffHunkHeader;
3654
- exports.DiffLine = DiffLine;
3655
- exports.DiffParser = DiffParser;
3656
1571
  exports.DiffView = DiffView;
3657
1572
  exports.DiffViewContext = DiffViewContext;
3658
- exports.File = File;
3659
- exports.HiddenBidiCharsRegex = HiddenBidiCharsRegex;
3660
- exports._cacheMap = _cacheMap;
3661
- exports.assertNever = assertNever;
3662
- exports.checkDiffLineIncludeChange = checkDiffLineIncludeChange;
3663
- exports.composeLen = composeLen;
3664
1573
  exports.diffFontSizeName = diffFontSizeName;
3665
- exports.getDiffRange = getDiffRange;
3666
- exports.getFile = getFile;
3667
- exports.getHunkHeaderExpansionType = getHunkHeaderExpansionType;
3668
- exports.getLang = getLang;
3669
- exports.getLargestLineNumber = getLargestLineNumber;
3670
- exports.getSplitContentLines = getSplitContentLines;
3671
- exports.getSplitLines = getSplitLines;
3672
- exports.getUnifiedContentLine = getUnifiedContentLine;
3673
- exports.getUnifiedLines = getUnifiedLines;
3674
- exports.hasRelativeChange = hasRelativeChange;
3675
- exports.highlighter = highlighter;
3676
- exports.numIterator = numIterator;
3677
- exports.parseInstance = parseInstance;
3678
- exports.processAST = processAST;
3679
- exports.relativeChanges = relativeChanges;
3680
1574
  exports.useDiffViewContext = useDiffViewContext;
3681
1575
  exports.version = version;
3682
- exports.versions = versions;
1576
+ Object.keys(core).forEach(function (k) {
1577
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
1578
+ enumerable: true,
1579
+ get: function () { return core[k]; }
1580
+ });
1581
+ });
3683
1582
  //# sourceMappingURL=index.development.js.map