@git-diff-view/react 0.0.6 → 0.0.8

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.
@@ -25,1446 +25,114 @@ function _interopNamespaceDefault(e) {
25
25
 
26
26
  var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
27
27
 
28
- /**
29
- * @module LRUCache
30
- */
31
- const perf = typeof performance === 'object' &&
32
- performance &&
33
- typeof performance.now === 'function'
34
- ? performance
35
- : Date;
36
- const warned = new Set();
37
- /* c8 ignore start */
38
- const PROCESS = (typeof process === 'object' && !!process ? process : {});
39
- /* c8 ignore start */
40
- const emitWarning = (msg, type, code, fn) => {
41
- typeof PROCESS.emitWarning === 'function'
42
- ? PROCESS.emitWarning(msg, type, code, fn)
43
- : console.error(`[${code}] ${type}: ${msg}`);
44
- };
45
- let AC = globalThis.AbortController;
46
- let AS = globalThis.AbortSignal;
47
- /* c8 ignore start */
48
- if (typeof AC === 'undefined') {
49
- //@ts-ignore
50
- AS = class AbortSignal {
51
- onabort;
52
- _onabort = [];
53
- reason;
54
- aborted = false;
55
- addEventListener(_, fn) {
56
- this._onabort.push(fn);
57
- }
58
- };
59
- //@ts-ignore
60
- AC = class AbortController {
61
- constructor() {
62
- warnACPolyfill();
63
- }
64
- signal = new AS();
65
- abort(reason) {
66
- if (this.signal.aborted)
67
- return;
68
- //@ts-ignore
69
- this.signal.reason = reason;
70
- //@ts-ignore
71
- this.signal.aborted = true;
72
- //@ts-ignore
73
- for (const fn of this.signal._onabort) {
74
- fn(reason);
75
- }
76
- this.signal.onabort?.(reason);
77
- }
78
- };
79
- let printACPolyfillWarning = PROCESS.env?.LRU_CACHE_IGNORE_AC_WARNING !== '1';
80
- const warnACPolyfill = () => {
81
- if (!printACPolyfillWarning)
82
- return;
83
- printACPolyfillWarning = false;
84
- emitWarning('AbortController is not defined. If using lru-cache in ' +
85
- 'node 14, load an AbortController polyfill from the ' +
86
- '`node-abort-controller` package. A minimal polyfill is ' +
87
- 'provided for use by LRUCache.fetch(), but it should not be ' +
88
- 'relied upon in other contexts (eg, passing it to other APIs that ' +
89
- 'use AbortController/AbortSignal might have undesirable effects). ' +
90
- 'You may disable this with LRU_CACHE_IGNORE_AC_WARNING=1 in the env.', 'NO_ABORT_CONTROLLER', 'ENOTSUP', warnACPolyfill);
91
- };
92
- }
93
- /* c8 ignore stop */
94
- const shouldWarn = (code) => !warned.has(code);
95
- const isPosInt = (n) => n && n === Math.floor(n) && n > 0 && isFinite(n);
96
- /* c8 ignore start */
97
- // This is a little bit ridiculous, tbh.
98
- // The maximum array length is 2^32-1 or thereabouts on most JS impls.
99
- // And well before that point, you're caching the entire world, I mean,
100
- // that's ~32GB of just integers for the next/prev links, plus whatever
101
- // else to hold that many keys and values. Just filling the memory with
102
- // zeroes at init time is brutal when you get that big.
103
- // But why not be complete?
104
- // Maybe in the future, these limits will have expanded.
105
- const getUintArray = (max) => !isPosInt(max)
106
- ? null
107
- : max <= Math.pow(2, 8)
108
- ? Uint8Array
109
- : max <= Math.pow(2, 16)
110
- ? Uint16Array
111
- : max <= Math.pow(2, 32)
112
- ? Uint32Array
113
- : max <= Number.MAX_SAFE_INTEGER
114
- ? ZeroArray
115
- : null;
116
- /* c8 ignore stop */
117
- class ZeroArray extends Array {
118
- constructor(size) {
119
- super(size);
120
- this.fill(0);
121
- }
122
- }
123
- class Stack {
124
- heap;
125
- length;
126
- // private constructor
127
- static #constructing = false;
128
- static create(max) {
129
- const HeapCls = getUintArray(max);
130
- if (!HeapCls)
131
- return [];
132
- Stack.#constructing = true;
133
- const s = new Stack(max, HeapCls);
134
- Stack.#constructing = false;
135
- return s;
136
- }
137
- constructor(max, HeapCls) {
138
- /* c8 ignore start */
139
- if (!Stack.#constructing) {
140
- throw new TypeError('instantiate Stack using Stack.create(n)');
141
- }
142
- /* c8 ignore stop */
143
- this.heap = new HeapCls(max);
144
- this.length = 0;
145
- }
146
- push(n) {
147
- this.heap[this.length++] = n;
148
- }
149
- pop() {
150
- return this.heap[--this.length];
151
- }
152
- }
153
- /**
154
- * Default export, the thing you're using this module to get.
155
- *
156
- * All properties from the options object (with the exception of
157
- * {@link OptionsBase.max} and {@link OptionsBase.maxSize}) are added as
158
- * normal public members. (`max` and `maxBase` are read-only getters.)
159
- * Changing any of these will alter the defaults for subsequent method calls,
160
- * but is otherwise safe.
161
- */
162
- class LRUCache {
163
- // properties coming in from the options of these, only max and maxSize
164
- // really *need* to be protected. The rest can be modified, as they just
165
- // set defaults for various methods.
166
- #max;
167
- #maxSize;
168
- #dispose;
169
- #disposeAfter;
170
- #fetchMethod;
171
- /**
172
- * {@link LRUCache.OptionsBase.ttl}
173
- */
174
- ttl;
175
- /**
176
- * {@link LRUCache.OptionsBase.ttlResolution}
177
- */
178
- ttlResolution;
179
- /**
180
- * {@link LRUCache.OptionsBase.ttlAutopurge}
181
- */
182
- ttlAutopurge;
183
- /**
184
- * {@link LRUCache.OptionsBase.updateAgeOnGet}
185
- */
186
- updateAgeOnGet;
187
- /**
188
- * {@link LRUCache.OptionsBase.updateAgeOnHas}
189
- */
190
- updateAgeOnHas;
191
- /**
192
- * {@link LRUCache.OptionsBase.allowStale}
193
- */
194
- allowStale;
195
- /**
196
- * {@link LRUCache.OptionsBase.noDisposeOnSet}
197
- */
198
- noDisposeOnSet;
199
- /**
200
- * {@link LRUCache.OptionsBase.noUpdateTTL}
201
- */
202
- noUpdateTTL;
203
- /**
204
- * {@link LRUCache.OptionsBase.maxEntrySize}
205
- */
206
- maxEntrySize;
207
- /**
208
- * {@link LRUCache.OptionsBase.sizeCalculation}
209
- */
210
- sizeCalculation;
211
- /**
212
- * {@link LRUCache.OptionsBase.noDeleteOnFetchRejection}
213
- */
214
- noDeleteOnFetchRejection;
215
- /**
216
- * {@link LRUCache.OptionsBase.noDeleteOnStaleGet}
217
- */
218
- noDeleteOnStaleGet;
219
- /**
220
- * {@link LRUCache.OptionsBase.allowStaleOnFetchAbort}
221
- */
222
- allowStaleOnFetchAbort;
223
- /**
224
- * {@link LRUCache.OptionsBase.allowStaleOnFetchRejection}
225
- */
226
- allowStaleOnFetchRejection;
227
- /**
228
- * {@link LRUCache.OptionsBase.ignoreFetchAbort}
229
- */
230
- ignoreFetchAbort;
231
- // computed properties
232
- #size;
233
- #calculatedSize;
234
- #keyMap;
235
- #keyList;
236
- #valList;
237
- #next;
238
- #prev;
239
- #head;
240
- #tail;
241
- #free;
242
- #disposed;
243
- #sizes;
244
- #starts;
245
- #ttls;
246
- #hasDispose;
247
- #hasFetchMethod;
248
- #hasDisposeAfter;
249
- /**
250
- * Do not call this method unless you need to inspect the
251
- * inner workings of the cache. If anything returned by this
252
- * object is modified in any way, strange breakage may occur.
253
- *
254
- * These fields are private for a reason!
255
- *
256
- * @internal
257
- */
258
- static unsafeExposeInternals(c) {
259
- return {
260
- // properties
261
- starts: c.#starts,
262
- ttls: c.#ttls,
263
- sizes: c.#sizes,
264
- keyMap: c.#keyMap,
265
- keyList: c.#keyList,
266
- valList: c.#valList,
267
- next: c.#next,
268
- prev: c.#prev,
269
- get head() {
270
- return c.#head;
271
- },
272
- get tail() {
273
- return c.#tail;
274
- },
275
- free: c.#free,
276
- // methods
277
- isBackgroundFetch: (p) => c.#isBackgroundFetch(p),
278
- backgroundFetch: (k, index, options, context) => c.#backgroundFetch(k, index, options, context),
279
- moveToTail: (index) => c.#moveToTail(index),
280
- indexes: (options) => c.#indexes(options),
281
- rindexes: (options) => c.#rindexes(options),
282
- isStale: (index) => c.#isStale(index),
283
- };
284
- }
285
- // Protected read-only members
286
- /**
287
- * {@link LRUCache.OptionsBase.max} (read-only)
288
- */
289
- get max() {
290
- return this.#max;
291
- }
292
- /**
293
- * {@link LRUCache.OptionsBase.maxSize} (read-only)
294
- */
295
- get maxSize() {
296
- return this.#maxSize;
297
- }
298
- /**
299
- * The total computed size of items in the cache (read-only)
300
- */
301
- get calculatedSize() {
302
- return this.#calculatedSize;
303
- }
304
- /**
305
- * The number of items stored in the cache (read-only)
306
- */
307
- get size() {
308
- return this.#size;
309
- }
310
- /**
311
- * {@link LRUCache.OptionsBase.fetchMethod} (read-only)
312
- */
313
- get fetchMethod() {
314
- return this.#fetchMethod;
315
- }
316
- /**
317
- * {@link LRUCache.OptionsBase.dispose} (read-only)
318
- */
319
- get dispose() {
320
- return this.#dispose;
321
- }
322
- /**
323
- * {@link LRUCache.OptionsBase.disposeAfter} (read-only)
324
- */
325
- get disposeAfter() {
326
- return this.#disposeAfter;
327
- }
328
- constructor(options) {
329
- const { max = 0, ttl, ttlResolution = 1, ttlAutopurge, updateAgeOnGet, updateAgeOnHas, allowStale, dispose, disposeAfter, noDisposeOnSet, noUpdateTTL, maxSize = 0, maxEntrySize = 0, sizeCalculation, fetchMethod, noDeleteOnFetchRejection, noDeleteOnStaleGet, allowStaleOnFetchRejection, allowStaleOnFetchAbort, ignoreFetchAbort, } = options;
330
- if (max !== 0 && !isPosInt(max)) {
331
- throw new TypeError('max option must be a nonnegative integer');
332
- }
333
- const UintArray = max ? getUintArray(max) : Array;
334
- if (!UintArray) {
335
- throw new Error('invalid max value: ' + max);
336
- }
337
- this.#max = max;
338
- this.#maxSize = maxSize;
339
- this.maxEntrySize = maxEntrySize || this.#maxSize;
340
- this.sizeCalculation = sizeCalculation;
341
- if (this.sizeCalculation) {
342
- if (!this.#maxSize && !this.maxEntrySize) {
343
- throw new TypeError('cannot set sizeCalculation without setting maxSize or maxEntrySize');
344
- }
345
- if (typeof this.sizeCalculation !== 'function') {
346
- throw new TypeError('sizeCalculation set to non-function');
347
- }
348
- }
349
- if (fetchMethod !== undefined &&
350
- typeof fetchMethod !== 'function') {
351
- throw new TypeError('fetchMethod must be a function if specified');
352
- }
353
- this.#fetchMethod = fetchMethod;
354
- this.#hasFetchMethod = !!fetchMethod;
355
- this.#keyMap = new Map();
356
- this.#keyList = new Array(max).fill(undefined);
357
- this.#valList = new Array(max).fill(undefined);
358
- this.#next = new UintArray(max);
359
- this.#prev = new UintArray(max);
360
- this.#head = 0;
361
- this.#tail = 0;
362
- this.#free = Stack.create(max);
363
- this.#size = 0;
364
- this.#calculatedSize = 0;
365
- if (typeof dispose === 'function') {
366
- this.#dispose = dispose;
367
- }
368
- if (typeof disposeAfter === 'function') {
369
- this.#disposeAfter = disposeAfter;
370
- this.#disposed = [];
371
- }
372
- else {
373
- this.#disposeAfter = undefined;
374
- this.#disposed = undefined;
375
- }
376
- this.#hasDispose = !!this.#dispose;
377
- this.#hasDisposeAfter = !!this.#disposeAfter;
378
- this.noDisposeOnSet = !!noDisposeOnSet;
379
- this.noUpdateTTL = !!noUpdateTTL;
380
- this.noDeleteOnFetchRejection = !!noDeleteOnFetchRejection;
381
- this.allowStaleOnFetchRejection = !!allowStaleOnFetchRejection;
382
- this.allowStaleOnFetchAbort = !!allowStaleOnFetchAbort;
383
- this.ignoreFetchAbort = !!ignoreFetchAbort;
384
- // NB: maxEntrySize is set to maxSize if it's set
385
- if (this.maxEntrySize !== 0) {
386
- if (this.#maxSize !== 0) {
387
- if (!isPosInt(this.#maxSize)) {
388
- throw new TypeError('maxSize must be a positive integer if specified');
389
- }
390
- }
391
- if (!isPosInt(this.maxEntrySize)) {
392
- throw new TypeError('maxEntrySize must be a positive integer if specified');
393
- }
394
- this.#initializeSizeTracking();
395
- }
396
- this.allowStale = !!allowStale;
397
- this.noDeleteOnStaleGet = !!noDeleteOnStaleGet;
398
- this.updateAgeOnGet = !!updateAgeOnGet;
399
- this.updateAgeOnHas = !!updateAgeOnHas;
400
- this.ttlResolution =
401
- isPosInt(ttlResolution) || ttlResolution === 0
402
- ? ttlResolution
403
- : 1;
404
- this.ttlAutopurge = !!ttlAutopurge;
405
- this.ttl = ttl || 0;
406
- if (this.ttl) {
407
- if (!isPosInt(this.ttl)) {
408
- throw new TypeError('ttl must be a positive integer if specified');
409
- }
410
- this.#initializeTTLTracking();
411
- }
412
- // do not allow completely unbounded caches
413
- if (this.#max === 0 && this.ttl === 0 && this.#maxSize === 0) {
414
- throw new TypeError('At least one of max, maxSize, or ttl is required');
415
- }
416
- if (!this.ttlAutopurge && !this.#max && !this.#maxSize) {
417
- const code = 'LRU_CACHE_UNBOUNDED';
418
- if (shouldWarn(code)) {
419
- warned.add(code);
420
- const msg = 'TTL caching without ttlAutopurge, max, or maxSize can ' +
421
- 'result in unbounded memory consumption.';
422
- emitWarning(msg, 'UnboundedCacheWarning', code, LRUCache);
423
- }
424
- }
425
- }
426
- /**
427
- * Return the remaining TTL time for a given entry key
428
- */
429
- getRemainingTTL(key) {
430
- return this.#keyMap.has(key) ? Infinity : 0;
431
- }
432
- #initializeTTLTracking() {
433
- const ttls = new ZeroArray(this.#max);
434
- const starts = new ZeroArray(this.#max);
435
- this.#ttls = ttls;
436
- this.#starts = starts;
437
- this.#setItemTTL = (index, ttl, start = perf.now()) => {
438
- starts[index] = ttl !== 0 ? start : 0;
439
- ttls[index] = ttl;
440
- if (ttl !== 0 && this.ttlAutopurge) {
441
- const t = setTimeout(() => {
442
- if (this.#isStale(index)) {
443
- this.delete(this.#keyList[index]);
444
- }
445
- }, ttl + 1);
446
- // unref() not supported on all platforms
447
- /* c8 ignore start */
448
- if (t.unref) {
449
- t.unref();
450
- }
451
- /* c8 ignore stop */
452
- }
453
- };
454
- this.#updateItemAge = index => {
455
- starts[index] = ttls[index] !== 0 ? perf.now() : 0;
456
- };
457
- this.#statusTTL = (status, index) => {
458
- if (ttls[index]) {
459
- const ttl = ttls[index];
460
- const start = starts[index];
461
- /* c8 ignore next */
462
- if (!ttl || !start)
463
- return;
464
- status.ttl = ttl;
465
- status.start = start;
466
- status.now = cachedNow || getNow();
467
- const age = status.now - start;
468
- status.remainingTTL = ttl - age;
469
- }
470
- };
471
- // debounce calls to perf.now() to 1s so we're not hitting
472
- // that costly call repeatedly.
473
- let cachedNow = 0;
474
- const getNow = () => {
475
- const n = perf.now();
476
- if (this.ttlResolution > 0) {
477
- cachedNow = n;
478
- const t = setTimeout(() => (cachedNow = 0), this.ttlResolution);
479
- // not available on all platforms
480
- /* c8 ignore start */
481
- if (t.unref) {
482
- t.unref();
483
- }
484
- /* c8 ignore stop */
485
- }
486
- return n;
487
- };
488
- this.getRemainingTTL = key => {
489
- const index = this.#keyMap.get(key);
490
- if (index === undefined) {
491
- return 0;
492
- }
493
- const ttl = ttls[index];
494
- const start = starts[index];
495
- if (!ttl || !start) {
496
- return Infinity;
497
- }
498
- const age = (cachedNow || getNow()) - start;
499
- return ttl - age;
500
- };
501
- this.#isStale = index => {
502
- const s = starts[index];
503
- const t = ttls[index];
504
- return !!t && !!s && (cachedNow || getNow()) - s > t;
505
- };
506
- }
507
- // conditionally set private methods related to TTL
508
- #updateItemAge = () => { };
509
- #statusTTL = () => { };
510
- #setItemTTL = () => { };
511
- /* c8 ignore stop */
512
- #isStale = () => false;
513
- #initializeSizeTracking() {
514
- const sizes = new ZeroArray(this.#max);
515
- this.#calculatedSize = 0;
516
- this.#sizes = sizes;
517
- this.#removeItemSize = index => {
518
- this.#calculatedSize -= sizes[index];
519
- sizes[index] = 0;
520
- };
521
- this.#requireSize = (k, v, size, sizeCalculation) => {
522
- // provisionally accept background fetches.
523
- // actual value size will be checked when they return.
524
- if (this.#isBackgroundFetch(v)) {
525
- return 0;
526
- }
527
- if (!isPosInt(size)) {
528
- if (sizeCalculation) {
529
- if (typeof sizeCalculation !== 'function') {
530
- throw new TypeError('sizeCalculation must be a function');
531
- }
532
- size = sizeCalculation(v, k);
533
- if (!isPosInt(size)) {
534
- throw new TypeError('sizeCalculation return invalid (expect positive integer)');
535
- }
536
- }
537
- else {
538
- throw new TypeError('invalid size value (must be positive integer). ' +
539
- 'When maxSize or maxEntrySize is used, sizeCalculation ' +
540
- 'or size must be set.');
541
- }
542
- }
543
- return size;
544
- };
545
- this.#addItemSize = (index, size, status) => {
546
- sizes[index] = size;
547
- if (this.#maxSize) {
548
- const maxSize = this.#maxSize - sizes[index];
549
- while (this.#calculatedSize > maxSize) {
550
- this.#evict(true);
551
- }
552
- }
553
- this.#calculatedSize += sizes[index];
554
- if (status) {
555
- status.entrySize = size;
556
- status.totalCalculatedSize = this.#calculatedSize;
557
- }
558
- };
559
- }
560
- #removeItemSize = _i => { };
561
- #addItemSize = (_i, _s, _st) => { };
562
- #requireSize = (_k, _v, size, sizeCalculation) => {
563
- if (size || sizeCalculation) {
564
- throw new TypeError('cannot set size without setting maxSize or maxEntrySize on cache');
565
- }
566
- return 0;
567
- };
568
- *#indexes({ allowStale = this.allowStale } = {}) {
569
- if (this.#size) {
570
- for (let i = this.#tail; true;) {
571
- if (!this.#isValidIndex(i)) {
572
- break;
573
- }
574
- if (allowStale || !this.#isStale(i)) {
575
- yield i;
576
- }
577
- if (i === this.#head) {
578
- break;
579
- }
580
- else {
581
- i = this.#prev[i];
582
- }
583
- }
584
- }
585
- }
586
- *#rindexes({ allowStale = this.allowStale } = {}) {
587
- if (this.#size) {
588
- for (let i = this.#head; true;) {
589
- if (!this.#isValidIndex(i)) {
590
- break;
591
- }
592
- if (allowStale || !this.#isStale(i)) {
593
- yield i;
594
- }
595
- if (i === this.#tail) {
596
- break;
597
- }
598
- else {
599
- i = this.#next[i];
600
- }
601
- }
602
- }
603
- }
604
- #isValidIndex(index) {
605
- return (index !== undefined &&
606
- this.#keyMap.get(this.#keyList[index]) === index);
607
- }
608
- /**
609
- * Return a generator yielding `[key, value]` pairs,
610
- * in order from most recently used to least recently used.
611
- */
612
- *entries() {
613
- for (const i of this.#indexes()) {
614
- if (this.#valList[i] !== undefined &&
615
- this.#keyList[i] !== undefined &&
616
- !this.#isBackgroundFetch(this.#valList[i])) {
617
- yield [this.#keyList[i], this.#valList[i]];
618
- }
619
- }
620
- }
621
- /**
622
- * Inverse order version of {@link LRUCache.entries}
623
- *
624
- * Return a generator yielding `[key, value]` pairs,
625
- * in order from least recently used to most recently used.
626
- */
627
- *rentries() {
628
- for (const i of this.#rindexes()) {
629
- if (this.#valList[i] !== undefined &&
630
- this.#keyList[i] !== undefined &&
631
- !this.#isBackgroundFetch(this.#valList[i])) {
632
- yield [this.#keyList[i], this.#valList[i]];
633
- }
634
- }
635
- }
636
- /**
637
- * Return a generator yielding the keys in the cache,
638
- * in order from most recently used to least recently used.
639
- */
640
- *keys() {
641
- for (const i of this.#indexes()) {
642
- const k = this.#keyList[i];
643
- if (k !== undefined &&
644
- !this.#isBackgroundFetch(this.#valList[i])) {
645
- yield k;
646
- }
647
- }
648
- }
649
- /**
650
- * Inverse order version of {@link LRUCache.keys}
651
- *
652
- * Return a generator yielding the keys in the cache,
653
- * in order from least recently used to most recently used.
654
- */
655
- *rkeys() {
656
- for (const i of this.#rindexes()) {
657
- const k = this.#keyList[i];
658
- if (k !== undefined &&
659
- !this.#isBackgroundFetch(this.#valList[i])) {
660
- yield k;
661
- }
662
- }
663
- }
664
- /**
665
- * Return a generator yielding the values in the cache,
666
- * in order from most recently used to least recently used.
667
- */
668
- *values() {
669
- for (const i of this.#indexes()) {
670
- const v = this.#valList[i];
671
- if (v !== undefined &&
672
- !this.#isBackgroundFetch(this.#valList[i])) {
673
- yield this.#valList[i];
674
- }
675
- }
676
- }
677
- /**
678
- * Inverse order version of {@link LRUCache.values}
679
- *
680
- * Return a generator yielding the values in the cache,
681
- * in order from least recently used to most recently used.
682
- */
683
- *rvalues() {
684
- for (const i of this.#rindexes()) {
685
- const v = this.#valList[i];
686
- if (v !== undefined &&
687
- !this.#isBackgroundFetch(this.#valList[i])) {
688
- yield this.#valList[i];
689
- }
690
- }
691
- }
692
- /**
693
- * Iterating over the cache itself yields the same results as
694
- * {@link LRUCache.entries}
695
- */
696
- [Symbol.iterator]() {
697
- return this.entries();
698
- }
699
- /**
700
- * A String value that is used in the creation of the default string description of an object.
701
- * Called by the built-in method Object.prototype.toString.
702
- */
703
- [Symbol.toStringTag] = 'LRUCache';
704
- /**
705
- * Find a value for which the supplied fn method returns a truthy value,
706
- * similar to Array.find(). fn is called as fn(value, key, cache).
707
- */
708
- find(fn, getOptions = {}) {
709
- for (const i of this.#indexes()) {
710
- const v = this.#valList[i];
711
- const value = this.#isBackgroundFetch(v)
712
- ? v.__staleWhileFetching
713
- : v;
714
- if (value === undefined)
715
- continue;
716
- if (fn(value, this.#keyList[i], this)) {
717
- return this.get(this.#keyList[i], getOptions);
718
- }
719
- }
720
- }
721
- /**
722
- * Call the supplied function on each item in the cache, in order from
723
- * most recently used to least recently used. fn is called as
724
- * fn(value, key, cache). Does not update age or recenty of use.
725
- * Does not iterate over stale values.
726
- */
727
- forEach(fn, thisp = this) {
728
- for (const i of this.#indexes()) {
729
- const v = this.#valList[i];
730
- const value = this.#isBackgroundFetch(v)
731
- ? v.__staleWhileFetching
732
- : v;
733
- if (value === undefined)
734
- continue;
735
- fn.call(thisp, value, this.#keyList[i], this);
736
- }
737
- }
738
- /**
739
- * The same as {@link LRUCache.forEach} but items are iterated over in
740
- * reverse order. (ie, less recently used items are iterated over first.)
741
- */
742
- rforEach(fn, thisp = this) {
743
- for (const i of this.#rindexes()) {
744
- const v = this.#valList[i];
745
- const value = this.#isBackgroundFetch(v)
746
- ? v.__staleWhileFetching
747
- : v;
748
- if (value === undefined)
749
- continue;
750
- fn.call(thisp, value, this.#keyList[i], this);
751
- }
752
- }
753
- /**
754
- * Delete any stale entries. Returns true if anything was removed,
755
- * false otherwise.
756
- */
757
- purgeStale() {
758
- let deleted = false;
759
- for (const i of this.#rindexes({ allowStale: true })) {
760
- if (this.#isStale(i)) {
761
- this.delete(this.#keyList[i]);
762
- deleted = true;
763
- }
764
- }
765
- return deleted;
766
- }
767
- /**
768
- * Get the extended info about a given entry, to get its value, size, and
769
- * TTL info simultaneously. Like {@link LRUCache#dump}, but just for a
770
- * single key. Always returns stale values, if their info is found in the
771
- * cache, so be sure to check for expired TTLs if relevant.
772
- */
773
- info(key) {
774
- const i = this.#keyMap.get(key);
775
- if (i === undefined)
776
- return undefined;
777
- const v = this.#valList[i];
778
- const value = this.#isBackgroundFetch(v)
779
- ? v.__staleWhileFetching
780
- : v;
781
- if (value === undefined)
782
- return undefined;
783
- const entry = { value };
784
- if (this.#ttls && this.#starts) {
785
- const ttl = this.#ttls[i];
786
- const start = this.#starts[i];
787
- if (ttl && start) {
788
- const remain = ttl - (perf.now() - start);
789
- entry.ttl = remain;
790
- entry.start = Date.now();
791
- }
792
- }
793
- if (this.#sizes) {
794
- entry.size = this.#sizes[i];
795
- }
796
- return entry;
797
- }
798
- /**
799
- * Return an array of [key, {@link LRUCache.Entry}] tuples which can be
800
- * passed to cache.load()
801
- */
802
- dump() {
803
- const arr = [];
804
- for (const i of this.#indexes({ allowStale: true })) {
805
- const key = this.#keyList[i];
806
- const v = this.#valList[i];
807
- const value = this.#isBackgroundFetch(v)
808
- ? v.__staleWhileFetching
809
- : v;
810
- if (value === undefined || key === undefined)
811
- continue;
812
- const entry = { value };
813
- if (this.#ttls && this.#starts) {
814
- entry.ttl = this.#ttls[i];
815
- // always dump the start relative to a portable timestamp
816
- // it's ok for this to be a bit slow, it's a rare operation.
817
- const age = perf.now() - this.#starts[i];
818
- entry.start = Math.floor(Date.now() - age);
819
- }
820
- if (this.#sizes) {
821
- entry.size = this.#sizes[i];
822
- }
823
- arr.unshift([key, entry]);
824
- }
825
- return arr;
826
- }
827
- /**
828
- * Reset the cache and load in the items in entries in the order listed.
829
- * Note that the shape of the resulting cache may be different if the
830
- * same options are not used in both caches.
831
- */
832
- load(arr) {
833
- this.clear();
834
- for (const [key, entry] of arr) {
835
- if (entry.start) {
836
- // entry.start is a portable timestamp, but we may be using
837
- // node's performance.now(), so calculate the offset, so that
838
- // we get the intended remaining TTL, no matter how long it's
839
- // been on ice.
840
- //
841
- // it's ok for this to be a bit slow, it's a rare operation.
842
- const age = Date.now() - entry.start;
843
- entry.start = perf.now() - age;
844
- }
845
- this.set(key, entry.value, entry);
846
- }
847
- }
848
- /**
849
- * Add a value to the cache.
850
- *
851
- * Note: if `undefined` is specified as a value, this is an alias for
852
- * {@link LRUCache#delete}
853
- */
854
- set(k, v, setOptions = {}) {
855
- if (v === undefined) {
856
- this.delete(k);
857
- return this;
858
- }
859
- const { ttl = this.ttl, start, noDisposeOnSet = this.noDisposeOnSet, sizeCalculation = this.sizeCalculation, status, } = setOptions;
860
- let { noUpdateTTL = this.noUpdateTTL } = setOptions;
861
- const size = this.#requireSize(k, v, setOptions.size || 0, sizeCalculation);
862
- // if the item doesn't fit, don't do anything
863
- // NB: maxEntrySize set to maxSize by default
864
- if (this.maxEntrySize && size > this.maxEntrySize) {
865
- if (status) {
866
- status.set = 'miss';
867
- status.maxEntrySizeExceeded = true;
868
- }
869
- // have to delete, in case something is there already.
870
- this.delete(k);
871
- return this;
872
- }
873
- let index = this.#size === 0 ? undefined : this.#keyMap.get(k);
874
- if (index === undefined) {
875
- // addition
876
- index = (this.#size === 0
877
- ? this.#tail
878
- : this.#free.length !== 0
879
- ? this.#free.pop()
880
- : this.#size === this.#max
881
- ? this.#evict(false)
882
- : this.#size);
883
- this.#keyList[index] = k;
884
- this.#valList[index] = v;
885
- this.#keyMap.set(k, index);
886
- this.#next[this.#tail] = index;
887
- this.#prev[index] = this.#tail;
888
- this.#tail = index;
889
- this.#size++;
890
- this.#addItemSize(index, size, status);
891
- if (status)
892
- status.set = 'add';
893
- noUpdateTTL = false;
894
- }
895
- else {
896
- // update
897
- this.#moveToTail(index);
898
- const oldVal = this.#valList[index];
899
- if (v !== oldVal) {
900
- if (this.#hasFetchMethod && this.#isBackgroundFetch(oldVal)) {
901
- oldVal.__abortController.abort(new Error('replaced'));
902
- const { __staleWhileFetching: s } = oldVal;
903
- if (s !== undefined && !noDisposeOnSet) {
904
- if (this.#hasDispose) {
905
- this.#dispose?.(s, k, 'set');
906
- }
907
- if (this.#hasDisposeAfter) {
908
- this.#disposed?.push([s, k, 'set']);
909
- }
910
- }
911
- }
912
- else if (!noDisposeOnSet) {
913
- if (this.#hasDispose) {
914
- this.#dispose?.(oldVal, k, 'set');
915
- }
916
- if (this.#hasDisposeAfter) {
917
- this.#disposed?.push([oldVal, k, 'set']);
918
- }
919
- }
920
- this.#removeItemSize(index);
921
- this.#addItemSize(index, size, status);
922
- this.#valList[index] = v;
923
- if (status) {
924
- status.set = 'replace';
925
- const oldValue = oldVal && this.#isBackgroundFetch(oldVal)
926
- ? oldVal.__staleWhileFetching
927
- : oldVal;
928
- if (oldValue !== undefined)
929
- status.oldValue = oldValue;
930
- }
931
- }
932
- else if (status) {
933
- status.set = 'update';
934
- }
935
- }
936
- if (ttl !== 0 && !this.#ttls) {
937
- this.#initializeTTLTracking();
938
- }
939
- if (this.#ttls) {
940
- if (!noUpdateTTL) {
941
- this.#setItemTTL(index, ttl, start);
942
- }
943
- if (status)
944
- this.#statusTTL(status, index);
945
- }
946
- if (!noDisposeOnSet && this.#hasDisposeAfter && this.#disposed) {
947
- const dt = this.#disposed;
948
- let task;
949
- while ((task = dt?.shift())) {
950
- this.#disposeAfter?.(...task);
951
- }
952
- }
953
- return this;
954
- }
955
- /**
956
- * Evict the least recently used item, returning its value or
957
- * `undefined` if cache is empty.
958
- */
959
- pop() {
960
- try {
961
- while (this.#size) {
962
- const val = this.#valList[this.#head];
963
- this.#evict(true);
964
- if (this.#isBackgroundFetch(val)) {
965
- if (val.__staleWhileFetching) {
966
- return val.__staleWhileFetching;
967
- }
968
- }
969
- else if (val !== undefined) {
970
- return val;
971
- }
972
- }
973
- }
974
- finally {
975
- if (this.#hasDisposeAfter && this.#disposed) {
976
- const dt = this.#disposed;
977
- let task;
978
- while ((task = dt?.shift())) {
979
- this.#disposeAfter?.(...task);
980
- }
981
- }
982
- }
983
- }
984
- #evict(free) {
985
- const head = this.#head;
986
- const k = this.#keyList[head];
987
- const v = this.#valList[head];
988
- if (this.#hasFetchMethod && this.#isBackgroundFetch(v)) {
989
- v.__abortController.abort(new Error('evicted'));
990
- }
991
- else if (this.#hasDispose || this.#hasDisposeAfter) {
992
- if (this.#hasDispose) {
993
- this.#dispose?.(v, k, 'evict');
994
- }
995
- if (this.#hasDisposeAfter) {
996
- this.#disposed?.push([v, k, 'evict']);
997
- }
998
- }
999
- this.#removeItemSize(head);
1000
- // if we aren't about to use the index, then null these out
1001
- if (free) {
1002
- this.#keyList[head] = undefined;
1003
- this.#valList[head] = undefined;
1004
- this.#free.push(head);
1005
- }
1006
- if (this.#size === 1) {
1007
- this.#head = this.#tail = 0;
1008
- this.#free.length = 0;
1009
- }
1010
- else {
1011
- this.#head = this.#next[head];
1012
- }
1013
- this.#keyMap.delete(k);
1014
- this.#size--;
1015
- return head;
1016
- }
1017
- /**
1018
- * Check if a key is in the cache, without updating the recency of use.
1019
- * Will return false if the item is stale, even though it is technically
1020
- * in the cache.
1021
- *
1022
- * Will not update item age unless
1023
- * {@link LRUCache.OptionsBase.updateAgeOnHas} is set.
1024
- */
1025
- has(k, hasOptions = {}) {
1026
- const { updateAgeOnHas = this.updateAgeOnHas, status } = hasOptions;
1027
- const index = this.#keyMap.get(k);
1028
- if (index !== undefined) {
1029
- const v = this.#valList[index];
1030
- if (this.#isBackgroundFetch(v) &&
1031
- v.__staleWhileFetching === undefined) {
1032
- return false;
1033
- }
1034
- if (!this.#isStale(index)) {
1035
- if (updateAgeOnHas) {
1036
- this.#updateItemAge(index);
1037
- }
1038
- if (status) {
1039
- status.has = 'hit';
1040
- this.#statusTTL(status, index);
1041
- }
1042
- return true;
1043
- }
1044
- else if (status) {
1045
- status.has = 'stale';
1046
- this.#statusTTL(status, index);
1047
- }
1048
- }
1049
- else if (status) {
1050
- status.has = 'miss';
1051
- }
1052
- return false;
1053
- }
1054
- /**
1055
- * Like {@link LRUCache#get} but doesn't update recency or delete stale
1056
- * items.
1057
- *
1058
- * Returns `undefined` if the item is stale, unless
1059
- * {@link LRUCache.OptionsBase.allowStale} is set.
1060
- */
1061
- peek(k, peekOptions = {}) {
1062
- const { allowStale = this.allowStale } = peekOptions;
1063
- const index = this.#keyMap.get(k);
1064
- if (index === undefined ||
1065
- (!allowStale && this.#isStale(index))) {
1066
- return;
1067
- }
1068
- const v = this.#valList[index];
1069
- // either stale and allowed, or forcing a refresh of non-stale value
1070
- return this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
1071
- }
1072
- #backgroundFetch(k, index, options, context) {
1073
- const v = index === undefined ? undefined : this.#valList[index];
1074
- if (this.#isBackgroundFetch(v)) {
1075
- return v;
1076
- }
1077
- const ac = new AC();
1078
- const { signal } = options;
1079
- // when/if our AC signals, then stop listening to theirs.
1080
- signal?.addEventListener('abort', () => ac.abort(signal.reason), {
1081
- signal: ac.signal,
1082
- });
1083
- const fetchOpts = {
1084
- signal: ac.signal,
1085
- options,
1086
- context,
1087
- };
1088
- const cb = (v, updateCache = false) => {
1089
- const { aborted } = ac.signal;
1090
- const ignoreAbort = options.ignoreFetchAbort && v !== undefined;
1091
- if (options.status) {
1092
- if (aborted && !updateCache) {
1093
- options.status.fetchAborted = true;
1094
- options.status.fetchError = ac.signal.reason;
1095
- if (ignoreAbort)
1096
- options.status.fetchAbortIgnored = true;
1097
- }
1098
- else {
1099
- options.status.fetchResolved = true;
1100
- }
1101
- }
1102
- if (aborted && !ignoreAbort && !updateCache) {
1103
- return fetchFail(ac.signal.reason);
1104
- }
1105
- // either we didn't abort, and are still here, or we did, and ignored
1106
- const bf = p;
1107
- if (this.#valList[index] === p) {
1108
- if (v === undefined) {
1109
- if (bf.__staleWhileFetching) {
1110
- this.#valList[index] = bf.__staleWhileFetching;
1111
- }
1112
- else {
1113
- this.delete(k);
1114
- }
1115
- }
1116
- else {
1117
- if (options.status)
1118
- options.status.fetchUpdated = true;
1119
- this.set(k, v, fetchOpts.options);
1120
- }
1121
- }
1122
- return v;
1123
- };
1124
- const eb = (er) => {
1125
- if (options.status) {
1126
- options.status.fetchRejected = true;
1127
- options.status.fetchError = er;
1128
- }
1129
- return fetchFail(er);
1130
- };
1131
- const fetchFail = (er) => {
1132
- const { aborted } = ac.signal;
1133
- const allowStaleAborted = aborted && options.allowStaleOnFetchAbort;
1134
- const allowStale = allowStaleAborted || options.allowStaleOnFetchRejection;
1135
- const noDelete = allowStale || options.noDeleteOnFetchRejection;
1136
- const bf = p;
1137
- if (this.#valList[index] === p) {
1138
- // if we allow stale on fetch rejections, then we need to ensure that
1139
- // the stale value is not removed from the cache when the fetch fails.
1140
- const del = !noDelete || bf.__staleWhileFetching === undefined;
1141
- if (del) {
1142
- this.delete(k);
1143
- }
1144
- else if (!allowStaleAborted) {
1145
- // still replace the *promise* with the stale value,
1146
- // since we are done with the promise at this point.
1147
- // leave it untouched if we're still waiting for an
1148
- // aborted background fetch that hasn't yet returned.
1149
- this.#valList[index] = bf.__staleWhileFetching;
1150
- }
1151
- }
1152
- if (allowStale) {
1153
- if (options.status && bf.__staleWhileFetching !== undefined) {
1154
- options.status.returnedStale = true;
1155
- }
1156
- return bf.__staleWhileFetching;
1157
- }
1158
- else if (bf.__returned === bf) {
1159
- throw er;
1160
- }
1161
- };
1162
- const pcall = (res, rej) => {
1163
- const fmp = this.#fetchMethod?.(k, v, fetchOpts);
1164
- if (fmp && fmp instanceof Promise) {
1165
- fmp.then(v => res(v === undefined ? undefined : v), rej);
1166
- }
1167
- // ignored, we go until we finish, regardless.
1168
- // defer check until we are actually aborting,
1169
- // so fetchMethod can override.
1170
- ac.signal.addEventListener('abort', () => {
1171
- if (!options.ignoreFetchAbort ||
1172
- options.allowStaleOnFetchAbort) {
1173
- res(undefined);
1174
- // when it eventually resolves, update the cache.
1175
- if (options.allowStaleOnFetchAbort) {
1176
- res = v => cb(v, true);
1177
- }
1178
- }
1179
- });
1180
- };
1181
- if (options.status)
1182
- options.status.fetchDispatched = true;
1183
- const p = new Promise(pcall).then(cb, eb);
1184
- const bf = Object.assign(p, {
1185
- __abortController: ac,
1186
- __staleWhileFetching: v,
1187
- __returned: undefined,
1188
- });
1189
- if (index === undefined) {
1190
- // internal, don't expose status.
1191
- this.set(k, bf, { ...fetchOpts.options, status: undefined });
1192
- index = this.#keyMap.get(k);
1193
- }
1194
- else {
1195
- this.#valList[index] = bf;
1196
- }
1197
- return bf;
1198
- }
1199
- #isBackgroundFetch(p) {
1200
- if (!this.#hasFetchMethod)
1201
- return false;
1202
- const b = p;
1203
- return (!!b &&
1204
- b instanceof Promise &&
1205
- b.hasOwnProperty('__staleWhileFetching') &&
1206
- b.__abortController instanceof AC);
1207
- }
1208
- async fetch(k, fetchOptions = {}) {
1209
- const {
1210
- // get options
1211
- allowStale = this.allowStale, updateAgeOnGet = this.updateAgeOnGet, noDeleteOnStaleGet = this.noDeleteOnStaleGet,
1212
- // set options
1213
- ttl = this.ttl, noDisposeOnSet = this.noDisposeOnSet, size = 0, sizeCalculation = this.sizeCalculation, noUpdateTTL = this.noUpdateTTL,
1214
- // fetch exclusive options
1215
- noDeleteOnFetchRejection = this.noDeleteOnFetchRejection, allowStaleOnFetchRejection = this.allowStaleOnFetchRejection, ignoreFetchAbort = this.ignoreFetchAbort, allowStaleOnFetchAbort = this.allowStaleOnFetchAbort, context, forceRefresh = false, status, signal, } = fetchOptions;
1216
- if (!this.#hasFetchMethod) {
1217
- if (status)
1218
- status.fetch = 'get';
1219
- return this.get(k, {
1220
- allowStale,
1221
- updateAgeOnGet,
1222
- noDeleteOnStaleGet,
1223
- status,
1224
- });
1225
- }
1226
- const options = {
1227
- allowStale,
1228
- updateAgeOnGet,
1229
- noDeleteOnStaleGet,
1230
- ttl,
1231
- noDisposeOnSet,
1232
- size,
1233
- sizeCalculation,
1234
- noUpdateTTL,
1235
- noDeleteOnFetchRejection,
1236
- allowStaleOnFetchRejection,
1237
- allowStaleOnFetchAbort,
1238
- ignoreFetchAbort,
1239
- status,
1240
- signal,
1241
- };
1242
- let index = this.#keyMap.get(k);
1243
- if (index === undefined) {
1244
- if (status)
1245
- status.fetch = 'miss';
1246
- const p = this.#backgroundFetch(k, index, options, context);
1247
- return (p.__returned = p);
1248
- }
1249
- else {
1250
- // in cache, maybe already fetching
1251
- const v = this.#valList[index];
1252
- if (this.#isBackgroundFetch(v)) {
1253
- const stale = allowStale && v.__staleWhileFetching !== undefined;
1254
- if (status) {
1255
- status.fetch = 'inflight';
1256
- if (stale)
1257
- status.returnedStale = true;
1258
- }
1259
- return stale ? v.__staleWhileFetching : (v.__returned = v);
1260
- }
1261
- // if we force a refresh, that means do NOT serve the cached value,
1262
- // unless we are already in the process of refreshing the cache.
1263
- const isStale = this.#isStale(index);
1264
- if (!forceRefresh && !isStale) {
1265
- if (status)
1266
- status.fetch = 'hit';
1267
- this.#moveToTail(index);
1268
- if (updateAgeOnGet) {
1269
- this.#updateItemAge(index);
1270
- }
1271
- if (status)
1272
- this.#statusTTL(status, index);
1273
- return v;
1274
- }
1275
- // ok, it is stale or a forced refresh, and not already fetching.
1276
- // refresh the cache.
1277
- const p = this.#backgroundFetch(k, index, options, context);
1278
- const hasStale = p.__staleWhileFetching !== undefined;
1279
- const staleVal = hasStale && allowStale;
1280
- if (status) {
1281
- status.fetch = isStale ? 'stale' : 'refresh';
1282
- if (staleVal && isStale)
1283
- status.returnedStale = true;
1284
- }
1285
- return staleVal ? p.__staleWhileFetching : (p.__returned = p);
1286
- }
1287
- }
1288
- /**
1289
- * Return a value from the cache. Will update the recency of the cache
1290
- * entry found.
1291
- *
1292
- * If the key is not found, get() will return `undefined`.
1293
- */
1294
- get(k, getOptions = {}) {
1295
- const { allowStale = this.allowStale, updateAgeOnGet = this.updateAgeOnGet, noDeleteOnStaleGet = this.noDeleteOnStaleGet, status, } = getOptions;
1296
- const index = this.#keyMap.get(k);
1297
- if (index !== undefined) {
1298
- const value = this.#valList[index];
1299
- const fetching = this.#isBackgroundFetch(value);
1300
- if (status)
1301
- this.#statusTTL(status, index);
1302
- if (this.#isStale(index)) {
1303
- if (status)
1304
- status.get = 'stale';
1305
- // delete only if not an in-flight background fetch
1306
- if (!fetching) {
1307
- if (!noDeleteOnStaleGet) {
1308
- this.delete(k);
1309
- }
1310
- if (status && allowStale)
1311
- status.returnedStale = true;
1312
- return allowStale ? value : undefined;
1313
- }
1314
- else {
1315
- if (status &&
1316
- allowStale &&
1317
- value.__staleWhileFetching !== undefined) {
1318
- status.returnedStale = true;
1319
- }
1320
- return allowStale ? value.__staleWhileFetching : undefined;
1321
- }
1322
- }
1323
- else {
1324
- if (status)
1325
- status.get = 'hit';
1326
- // if we're currently fetching it, we don't actually have it yet
1327
- // it's not stale, which means this isn't a staleWhileRefetching.
1328
- // If it's not stale, and fetching, AND has a __staleWhileFetching
1329
- // value, then that means the user fetched with {forceRefresh:true},
1330
- // so it's safe to return that value.
1331
- if (fetching) {
1332
- return value.__staleWhileFetching;
1333
- }
1334
- this.#moveToTail(index);
1335
- if (updateAgeOnGet) {
1336
- this.#updateItemAge(index);
1337
- }
1338
- return value;
1339
- }
1340
- }
1341
- else if (status) {
1342
- status.get = 'miss';
1343
- }
1344
- }
1345
- #connect(p, n) {
1346
- this.#prev[n] = p;
1347
- this.#next[p] = n;
28
+ /******************************************************************************
29
+ Copyright (c) Microsoft Corporation.
30
+
31
+ Permission to use, copy, modify, and/or distribute this software for any
32
+ purpose with or without fee is hereby granted.
33
+
34
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
35
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
36
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
37
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
38
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
39
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
40
+ PERFORMANCE OF THIS SOFTWARE.
41
+ ***************************************************************************** */
42
+ /* global Reflect, Promise, SuppressedError, Symbol */
43
+
44
+
45
+ function __rest(s, e) {
46
+ var t = {};
47
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
48
+ t[p] = s[p];
49
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
50
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
51
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
52
+ t[p[i]] = s[p[i]];
53
+ }
54
+ return t;
55
+ }
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
+ /******************************************************************************
76
+ Copyright (c) Microsoft Corporation.
77
+
78
+ Permission to use, copy, modify, and/or distribute this software for any
79
+ purpose with or without fee is hereby granted.
80
+
81
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
82
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
83
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
84
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
85
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
86
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
87
+ PERFORMANCE OF THIS SOFTWARE.
88
+ ***************************************************************************** */
89
+ /* global Reflect, Promise, SuppressedError, Symbol */
90
+
91
+
92
+ function __classPrivateFieldGet(receiver, state, kind, f) {
93
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
94
+ 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");
95
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
96
+ }
97
+
98
+ function __classPrivateFieldSet(receiver, state, value, kind, f) {
99
+ if (kind === "m") throw new TypeError("Private method is not writable");
100
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
101
+ 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");
102
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
103
+ }
104
+
105
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
106
+ var e = new Error(message);
107
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
108
+ };
109
+
110
+ var _Cache_keyArray, _Cache_maxLength;
111
+ class Cache extends Map {
112
+ constructor() {
113
+ super(...arguments);
114
+ _Cache_keyArray.set(this, []);
115
+ _Cache_maxLength.set(this, 30);
1348
116
  }
1349
- #moveToTail(index) {
1350
- // if tail already, nothing to do
1351
- // if head, move head to next[index]
1352
- // else
1353
- // move next[prev[index]] to next[index] (head has no prev)
1354
- // move prev[next[index]] to prev[index]
1355
- // prev[index] = tail
1356
- // next[tail] = index
1357
- // tail = index
1358
- if (index !== this.#tail) {
1359
- if (index === this.#head) {
1360
- this.#head = this.#next[index];
1361
- }
1362
- else {
1363
- this.#connect(this.#prev[index], this.#next[index]);
1364
- }
1365
- this.#connect(this.#tail, index);
1366
- this.#tail = index;
1367
- }
117
+ setMaxLength(length) {
118
+ __classPrivateFieldSet(this, _Cache_maxLength, length, "f");
119
+ this._checkLength();
1368
120
  }
1369
- /**
1370
- * Deletes a key out of the cache.
1371
- * Returns true if the key was deleted, false otherwise.
1372
- */
1373
- delete(k) {
1374
- let deleted = false;
1375
- if (this.#size !== 0) {
1376
- const index = this.#keyMap.get(k);
1377
- if (index !== undefined) {
1378
- deleted = true;
1379
- if (this.#size === 1) {
1380
- this.clear();
1381
- }
1382
- else {
1383
- this.#removeItemSize(index);
1384
- const v = this.#valList[index];
1385
- if (this.#isBackgroundFetch(v)) {
1386
- v.__abortController.abort(new Error('deleted'));
1387
- }
1388
- else if (this.#hasDispose || this.#hasDisposeAfter) {
1389
- if (this.#hasDispose) {
1390
- this.#dispose?.(v, k, 'delete');
1391
- }
1392
- if (this.#hasDisposeAfter) {
1393
- this.#disposed?.push([v, k, 'delete']);
1394
- }
1395
- }
1396
- this.#keyMap.delete(k);
1397
- this.#keyList[index] = undefined;
1398
- this.#valList[index] = undefined;
1399
- if (index === this.#tail) {
1400
- this.#tail = this.#prev[index];
1401
- }
1402
- else if (index === this.#head) {
1403
- this.#head = this.#next[index];
1404
- }
1405
- else {
1406
- const pi = this.#prev[index];
1407
- this.#next[pi] = this.#next[index];
1408
- const ni = this.#next[index];
1409
- this.#prev[ni] = this.#prev[index];
1410
- }
1411
- this.#size--;
1412
- this.#free.push(index);
1413
- }
1414
- }
1415
- }
1416
- if (this.#hasDisposeAfter && this.#disposed?.length) {
1417
- const dt = this.#disposed;
1418
- let task;
1419
- while ((task = dt?.shift())) {
1420
- this.#disposeAfter?.(...task);
1421
- }
1422
- }
1423
- return deleted;
121
+ set(key, value) {
122
+ if (this.has(key))
123
+ return this;
124
+ __classPrivateFieldGet(this, _Cache_keyArray, "f").push(key);
125
+ this._checkLength();
126
+ return super.set(key, value);
1424
127
  }
1425
- /**
1426
- * Clear the cache entirely, throwing away all values.
1427
- */
1428
- clear() {
1429
- for (const index of this.#rindexes({ allowStale: true })) {
1430
- const v = this.#valList[index];
1431
- if (this.#isBackgroundFetch(v)) {
1432
- v.__abortController.abort(new Error('deleted'));
1433
- }
1434
- else {
1435
- const k = this.#keyList[index];
1436
- if (this.#hasDispose) {
1437
- this.#dispose?.(v, k, 'delete');
1438
- }
1439
- if (this.#hasDisposeAfter) {
1440
- this.#disposed?.push([v, k, 'delete']);
1441
- }
1442
- }
1443
- }
1444
- this.#keyMap.clear();
1445
- this.#valList.fill(undefined);
1446
- this.#keyList.fill(undefined);
1447
- if (this.#ttls && this.#starts) {
1448
- this.#ttls.fill(0);
1449
- this.#starts.fill(0);
1450
- }
1451
- if (this.#sizes) {
1452
- this.#sizes.fill(0);
1453
- }
1454
- this.#head = 0;
1455
- this.#tail = 0;
1456
- this.#free.length = 0;
1457
- this.#calculatedSize = 0;
1458
- this.#size = 0;
1459
- if (this.#hasDisposeAfter && this.#disposed) {
1460
- const dt = this.#disposed;
1461
- let task;
1462
- while ((task = dt?.shift())) {
1463
- this.#disposeAfter?.(...task);
1464
- }
128
+ _checkLength() {
129
+ while (__classPrivateFieldGet(this, _Cache_keyArray, "f").length > __classPrivateFieldGet(this, _Cache_maxLength, "f")) {
130
+ const key = __classPrivateFieldGet(this, _Cache_keyArray, "f").shift();
131
+ this.delete(key);
1465
132
  }
1466
133
  }
1467
134
  }
135
+ _Cache_keyArray = new WeakMap(), _Cache_maxLength = new WeakMap();
1468
136
 
1469
137
  const lowlight = lowlight$1.createLowlight(lowlight$1.all);
1470
138
  lowlight.register("vue", function hljsDefineVue(hljs) {
@@ -1542,23 +210,33 @@ Object.defineProperty(highlighter, "setIgnoreSyntaxHighlightList", {
1542
210
  },
1543
211
  });
1544
212
 
1545
- const map = new LRUCache({ max: 30 });
213
+ var _File_instances, _File_doAST, _File_doCheck;
214
+ const map = new Cache();
215
+ map.setMaxLength(50);
216
+ map.name = "@git-diff-view/core";
217
+ if (typeof globalThis !== "undefined") {
218
+ if (Array.isArray(globalThis.__diff_cache__)) {
219
+ globalThis.__diff_cache__ = globalThis.__diff_cache__.filter((i) => i !== map);
220
+ if (globalThis.__diff_cache__.length > 0) {
221
+ console.warn("there are multiple instance of @git-diff-view/core in the one environment!");
222
+ }
223
+ globalThis.__diff_cache__.push(map);
224
+ }
225
+ else {
226
+ globalThis.__diff_cache__ = [map];
227
+ }
228
+ }
1546
229
  class File {
1547
- raw;
1548
- lang;
1549
- fileName;
1550
- ast;
1551
- rawFile = {};
1552
- hasDoRaw = false;
1553
- rawLength;
1554
- syntaxFile = {};
1555
- hasDoSyntax = false;
1556
- syntaxLength;
1557
- maxLineNumber = 0;
1558
230
  constructor(raw, lang, fileName) {
231
+ _File_instances.add(this);
1559
232
  this.raw = raw;
1560
233
  this.lang = lang;
1561
234
  this.fileName = fileName;
235
+ this.rawFile = {};
236
+ this.hasDoRaw = false;
237
+ this.syntaxFile = {};
238
+ this.hasDoSyntax = false;
239
+ this.maxLineNumber = 0;
1562
240
  Object.defineProperty(this, "__v_skip", { value: true });
1563
241
  }
1564
242
  doSyntax({ autoDetectLang, registerHighlighter, }) {
@@ -1592,9 +270,9 @@ class File {
1592
270
  else {
1593
271
  this.ast = _highlighter.highlightAuto(this.raw);
1594
272
  }
1595
- this.#doAST();
273
+ __classPrivateFieldGet(this, _File_instances, "m", _File_doAST).call(this);
1596
274
  {
1597
- this.#doCheck();
275
+ __classPrivateFieldGet(this, _File_instances, "m", _File_doCheck).call(this);
1598
276
  }
1599
277
  this.hasDoSyntax = true;
1600
278
  }
@@ -1619,102 +297,102 @@ class File {
1619
297
  // );
1620
298
  this.hasDoRaw = true;
1621
299
  }
1622
- #doAST() {
1623
- const ast = this.ast;
1624
- let lineNumber = 1;
1625
- const syntaxObj = this.syntaxFile;
1626
- const loopAST = (nodes, wrapper) => {
1627
- nodes.forEach((node) => {
1628
- if (node.type === "text") {
1629
- if (node.value.indexOf("\n") === -1) {
1630
- const valueLength = node.value.length;
1631
- if (!syntaxObj[lineNumber]) {
1632
- node.startIndex = 0;
1633
- node.endIndex = valueLength - 1;
1634
- const item = {
1635
- value: node.value,
1636
- lineNumber,
1637
- valueLength,
1638
- nodeList: [{ node, wrapper }],
1639
- };
1640
- syntaxObj[lineNumber] = item;
1641
- }
1642
- else {
1643
- node.startIndex = syntaxObj[lineNumber].valueLength;
1644
- node.endIndex = node.startIndex + valueLength - 1;
1645
- syntaxObj[lineNumber].value += node.value;
1646
- syntaxObj[lineNumber].valueLength += valueLength;
1647
- syntaxObj[lineNumber].nodeList.push({ node, wrapper });
1648
- }
1649
- node.lineNumber = lineNumber;
1650
- return;
1651
- }
1652
- const lines = node.value.split("\n");
1653
- node.children = node.children || [];
1654
- for (let i = 0; i < lines.length; i++) {
1655
- const _value = i === lines.length - 1 ? lines[i] : lines[i] + "\n";
1656
- const _lineNumber = i === 0 ? lineNumber : ++lineNumber;
1657
- const _valueLength = _value.length;
1658
- const _node = {
1659
- type: "text",
1660
- value: _value,
1661
- startIndex: Infinity,
1662
- endIndex: Infinity,
1663
- lineNumber: _lineNumber,
300
+ }
301
+ _File_instances = new WeakSet(), _File_doAST = function _File_doAST() {
302
+ const ast = this.ast;
303
+ let lineNumber = 1;
304
+ const syntaxObj = this.syntaxFile;
305
+ const loopAST = (nodes, wrapper) => {
306
+ nodes.forEach((node) => {
307
+ if (node.type === "text") {
308
+ if (node.value.indexOf("\n") === -1) {
309
+ const valueLength = node.value.length;
310
+ if (!syntaxObj[lineNumber]) {
311
+ node.startIndex = 0;
312
+ node.endIndex = valueLength - 1;
313
+ const item = {
314
+ value: node.value,
315
+ lineNumber,
316
+ valueLength,
317
+ nodeList: [{ node, wrapper }],
1664
318
  };
1665
- if (!syntaxObj[_lineNumber]) {
1666
- _node.startIndex = 0;
1667
- _node.endIndex = _valueLength - 1;
1668
- const item = {
1669
- value: _value,
1670
- lineNumber: _lineNumber,
1671
- valueLength: _valueLength,
1672
- nodeList: [{ node: _node, wrapper }],
1673
- };
1674
- syntaxObj[_lineNumber] = item;
1675
- }
1676
- else {
1677
- _node.startIndex = syntaxObj[_lineNumber].valueLength;
1678
- _node.endIndex = _node.startIndex + _valueLength - 1;
1679
- syntaxObj[_lineNumber].value += _value;
1680
- syntaxObj[_lineNumber].valueLength += _valueLength;
1681
- syntaxObj[_lineNumber].nodeList.push({ node: _node, wrapper });
1682
- }
1683
- node.children.push(_node);
319
+ syntaxObj[lineNumber] = item;
320
+ }
321
+ else {
322
+ node.startIndex = syntaxObj[lineNumber].valueLength;
323
+ node.endIndex = node.startIndex + valueLength - 1;
324
+ syntaxObj[lineNumber].value += node.value;
325
+ syntaxObj[lineNumber].valueLength += valueLength;
326
+ syntaxObj[lineNumber].nodeList.push({ node, wrapper });
1684
327
  }
1685
328
  node.lineNumber = lineNumber;
1686
329
  return;
1687
330
  }
1688
- if (node.children) {
1689
- loopAST(node.children, node);
1690
- node.lineNumber = lineNumber;
331
+ const lines = node.value.split("\n");
332
+ node.children = node.children || [];
333
+ for (let i = 0; i < lines.length; i++) {
334
+ const _value = i === lines.length - 1 ? lines[i] : lines[i] + "\n";
335
+ const _lineNumber = i === 0 ? lineNumber : ++lineNumber;
336
+ const _valueLength = _value.length;
337
+ const _node = {
338
+ type: "text",
339
+ value: _value,
340
+ startIndex: Infinity,
341
+ endIndex: Infinity,
342
+ lineNumber: _lineNumber,
343
+ };
344
+ if (!syntaxObj[_lineNumber]) {
345
+ _node.startIndex = 0;
346
+ _node.endIndex = _valueLength - 1;
347
+ const item = {
348
+ value: _value,
349
+ lineNumber: _lineNumber,
350
+ valueLength: _valueLength,
351
+ nodeList: [{ node: _node, wrapper }],
352
+ };
353
+ syntaxObj[_lineNumber] = item;
354
+ }
355
+ else {
356
+ _node.startIndex = syntaxObj[_lineNumber].valueLength;
357
+ _node.endIndex = _node.startIndex + _valueLength - 1;
358
+ syntaxObj[_lineNumber].value += _value;
359
+ syntaxObj[_lineNumber].valueLength += _valueLength;
360
+ syntaxObj[_lineNumber].nodeList.push({ node: _node, wrapper });
361
+ }
362
+ node.children.push(_node);
1691
363
  }
1692
- });
1693
- };
1694
- loopAST(ast.children);
1695
- this.syntaxLength = lineNumber;
1696
- }
1697
- #doCheck() {
1698
- if (this.rawLength && this.syntaxLength) {
1699
- if (this.rawLength !== this.syntaxLength) {
1700
- console.warn("the rawLength not match for the syntaxLength");
364
+ node.lineNumber = lineNumber;
365
+ return;
1701
366
  }
1702
- Object.values(this.syntaxFile).forEach(({ value, lineNumber }) => {
1703
- if (value !== this.rawFile[lineNumber]) {
1704
- console.log("some line not match:" + value + " __ " + this.rawFile[lineNumber] + " __ at: " + lineNumber + " lineNumber");
1705
- }
1706
- });
367
+ if (node.children) {
368
+ loopAST(node.children, node);
369
+ node.lineNumber = lineNumber;
370
+ }
371
+ });
372
+ };
373
+ loopAST(ast.children);
374
+ this.syntaxLength = lineNumber;
375
+ }, _File_doCheck = function _File_doCheck() {
376
+ if (this.rawLength && this.syntaxLength) {
377
+ if (this.rawLength !== this.syntaxLength) {
378
+ console.warn("the rawLength not match for the syntaxLength");
1707
379
  }
380
+ Object.values(this.syntaxFile).forEach(({ value, lineNumber }) => {
381
+ if (value !== this.rawFile[lineNumber]) {
382
+ console.log("some line not match:" + value + " __ " + this.rawFile[lineNumber] + " __ at: " + lineNumber + " lineNumber");
383
+ }
384
+ });
1708
385
  }
1709
- }
386
+ };
1710
387
  const getFile = (raw, lang, fileName) => {
1711
- const key = raw + "--" + "0.0.6" + "--" + lang;
388
+ const key = raw + "--" + "0.0.8" + "--" + lang;
1712
389
  if (map.has(key))
1713
390
  return map.get(key);
1714
391
  const file = new File(raw, lang, fileName);
1715
392
  map.set(key, file);
1716
393
  return file;
1717
394
  };
395
+ const _cacheMap = map;
1718
396
 
1719
397
  const maxLength = 1000;
1720
398
  /** Get the maximum position in the range. */
@@ -1792,23 +470,15 @@ function hasRelativeChange(stringA, stringB) {
1792
470
  }
1793
471
 
1794
472
  /** indicate what a line in the diff represents */
1795
- var DiffLineType;
473
+ exports.DiffLineType = void 0;
1796
474
  (function (DiffLineType) {
1797
475
  DiffLineType[DiffLineType["Context"] = 0] = "Context";
1798
476
  DiffLineType[DiffLineType["Add"] = 1] = "Add";
1799
477
  DiffLineType[DiffLineType["Delete"] = 2] = "Delete";
1800
478
  DiffLineType[DiffLineType["Hunk"] = 3] = "Hunk";
1801
- })(DiffLineType || (DiffLineType = {}));
479
+ })(exports.DiffLineType || (exports.DiffLineType = {}));
1802
480
  /** track details related to each line in the diff */
1803
481
  class DiffLine {
1804
- text;
1805
- type;
1806
- originalLineNumber;
1807
- oldLineNumber;
1808
- newLineNumber;
1809
- noTrailingNewLine;
1810
- needRematch;
1811
- range;
1812
482
  constructor(text, type,
1813
483
  // Line number in the original diff patch (before expanding it), or null if
1814
484
  // it was added as part of a diff expansion action.
@@ -1826,7 +496,7 @@ class DiffLine {
1826
496
  return new DiffLine(this.text, this.type, this.originalLineNumber, this.oldLineNumber, this.newLineNumber, noTrailingNewLine);
1827
497
  }
1828
498
  isIncludeableLine() {
1829
- return this.type === DiffLineType.Add || this.type === DiffLineType.Delete;
499
+ return this.type === exports.DiffLineType.Add || this.type === exports.DiffLineType.Delete;
1830
500
  }
1831
501
  /** The content of the line, i.e., without the line type marker. */
1832
502
  get content() {
@@ -1844,7 +514,7 @@ class DiffLine {
1844
514
  const checkDiffLineIncludeChange = (diffLine) => {
1845
515
  if (!diffLine)
1846
516
  return false;
1847
- return diffLine.type === DiffLineType.Add || diffLine.type === DiffLineType.Delete;
517
+ return diffLine.type === exports.DiffLineType.Add || diffLine.type === exports.DiffLineType.Delete;
1848
518
  };
1849
519
 
1850
520
  var DiffHunkExpansionType;
@@ -1871,11 +541,6 @@ var DiffHunkExpansionType;
1871
541
  })(DiffHunkExpansionType || (DiffHunkExpansionType = {}));
1872
542
  /** each diff is made up of a number of hunks */
1873
543
  class DiffHunk {
1874
- header;
1875
- lines;
1876
- unifiedDiffStart;
1877
- unifiedDiffEnd;
1878
- expansionType;
1879
544
  /**
1880
545
  * @param header The details from the diff hunk header about the line start and patch length.
1881
546
  * @param lines The contents - context and changes - of the diff section.
@@ -1903,10 +568,6 @@ class DiffHunk {
1903
568
  }
1904
569
  /** details about the start and end of a diff hunk */
1905
570
  class DiffHunkHeader {
1906
- oldStartLine;
1907
- oldLineCount;
1908
- newStartLine;
1909
- newLineCount;
1910
571
  /**
1911
572
  * @param oldStartLine The line in the old (or original) file where this diff hunk starts.
1912
573
  * @param oldLineCount The number of lines in the old (or original) file that this diff hunk covers
@@ -1937,6 +598,7 @@ function assertNever(_, message) {
1937
598
  }
1938
599
  /** Utility function for getting the digit count of the largest line number in an array of diff hunks */
1939
600
  function getLargestLineNumber(hunks) {
601
+ var _a, _b;
1940
602
  if (hunks.length === 0) {
1941
603
  return 0;
1942
604
  }
@@ -1944,11 +606,11 @@ function getLargestLineNumber(hunks) {
1944
606
  const hunk = hunks[i];
1945
607
  for (let j = hunk.lines.length - 1; j >= 0; j--) {
1946
608
  const line = hunk.lines[j];
1947
- if (line.type === DiffLineType.Hunk) {
609
+ if (line.type === exports.DiffLineType.Hunk) {
1948
610
  continue;
1949
611
  }
1950
- const newLineNumber = line.newLineNumber ?? 0;
1951
- const oldLineNumber = line.oldLineNumber ?? 0;
612
+ const newLineNumber = (_a = line.newLineNumber) !== null && _a !== void 0 ? _a : 0;
613
+ const oldLineNumber = (_b = line.oldLineNumber) !== null && _b !== void 0 ? _b : 0;
1952
614
  return newLineNumber > oldLineNumber ? newLineNumber : oldLineNumber;
1953
615
  }
1954
616
  }
@@ -2056,24 +718,6 @@ const DiffLinePrefixChars = new Set([
2056
718
  * See https://www.gnu.org/software/diffutils/manual/html_node/Detailed-Unified.html
2057
719
  */
2058
720
  class DiffParser {
2059
- /**
2060
- * Line start pointer.
2061
- *
2062
- * The offset into the text property where the current line starts (ie either zero
2063
- * or one character ahead of the last newline character).
2064
- */
2065
- ls;
2066
- /**
2067
- * Line end pointer.
2068
- *
2069
- * The offset into the text property where the current line ends (ie it points to
2070
- * the newline character) or -1 if the line boundary hasn't been determined yet
2071
- */
2072
- le;
2073
- /**
2074
- * The text buffer containing the raw, unified diff output to be parsed
2075
- */
2076
- text;
2077
721
  constructor() {
2078
722
  Object.defineProperty(this, "__v_skip", { value: true });
2079
723
  this.reset();
@@ -2257,7 +901,7 @@ class DiffParser {
2257
901
  }
2258
902
  const header = this.parseHunkHeader(headerLine);
2259
903
  const lines = new Array();
2260
- lines.push(new DiffLine(headerLine, DiffLineType.Hunk, 1, null, null));
904
+ lines.push(new DiffLine(headerLine, exports.DiffLineType.Hunk, 1, null, null));
2261
905
  let c;
2262
906
  let rollingDiffBeforeCounter = header.oldStartLine;
2263
907
  let rollingDiffAfterCounter = header.newStartLine;
@@ -2286,13 +930,13 @@ class DiffParser {
2286
930
  }
2287
931
  let diffLine;
2288
932
  if (c === DiffPrefixAdd) {
2289
- diffLine = new DiffLine(line, DiffLineType.Add, diffLineNumber, null, rollingDiffAfterCounter++);
933
+ diffLine = new DiffLine(line, exports.DiffLineType.Add, diffLineNumber, null, rollingDiffAfterCounter++);
2290
934
  }
2291
935
  else if (c === DiffPrefixDelete) {
2292
- diffLine = new DiffLine(line, DiffLineType.Delete, diffLineNumber, rollingDiffBeforeCounter++, null);
936
+ diffLine = new DiffLine(line, exports.DiffLineType.Delete, diffLineNumber, rollingDiffBeforeCounter++, null);
2293
937
  }
2294
938
  else if (c === DiffPrefixContext) {
2295
- diffLine = new DiffLine(line, DiffLineType.Context, diffLineNumber, rollingDiffBeforeCounter++, rollingDiffAfterCounter++);
939
+ diffLine = new DiffLine(line, exports.DiffLineType.Context, diffLineNumber, rollingDiffBeforeCounter++, rollingDiffAfterCounter++);
2296
940
  }
2297
941
  else {
2298
942
  return assertNever(c, `Unknown DiffLinePrefix: ${c}`);
@@ -2369,288 +1013,451 @@ class DiffParser {
2369
1013
  }
2370
1014
  const parseInstance = new DiffParser();
2371
1015
 
2372
- /* eslint-disable @typescript-eslint/ban-ts-comment */
2373
- /* eslint-disable max-lines */
1016
+ 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_id, _DiffFile_clonedInstance, _DiffFile_doDiff, _DiffFile_doFile, _DiffFile_composeRaw, _DiffFile_composeFile, _DiffFile_composeDiff, _DiffFile_composeSyntax, _DiffFile_getOldDiffLine, _DiffFile_getNewDiffLine, _DiffFile_getOldRawLine, _DiffFile_getNewRawLine;
2374
1017
  const composeLen = 40;
2375
1018
  const idSet = new Set();
2376
1019
  class DiffFile {
2377
- _oldFileName;
2378
- _newFileName;
2379
- _diffList;
2380
- #oldFileResult;
2381
- #newFileResult;
2382
- #diffListResults;
2383
- #diffLines;
2384
- #oldFileDiffLines;
2385
- #newFileDiffLines;
2386
- #oldFileLines;
2387
- #newFileLines;
2388
- #oldFileSyntaxLines;
2389
- #newFileSyntaxLines;
2390
- #splitLeftLines = [];
2391
- #splitRightLines = [];
2392
- #splitHunksLines;
2393
- #unifiedLines = [];
2394
- #unifiedHunksLines;
2395
- #listeners = [];
2396
- #hasInitRaw = false;
2397
- #hasInitSyntax = false;
2398
- #hasBuildSplit = false;
2399
- #hasBuildUnified = false;
2400
- #updateCount = 0;
2401
- #composeByDiff = false;
2402
- _version_ = "0.0.6";
2403
- _oldFileContent = "";
2404
- _oldFileLang = "";
2405
- _newFileContent = "";
2406
- _newFileLang = "";
2407
- diffLineLength = 0;
2408
- splitLineLength = 0;
2409
- unifiedLineLength = 0;
2410
- #id = "";
2411
- #clonedInstance = new Map();
2412
1020
  static createInstance(data, bundle) {
2413
- const instance = new DiffFile(data?.oldFile?.fileName || "", data?.oldFile?.content || "", data?.newFile?.fileName || "", data?.newFile?.content || "", data?.hunks || [], data?.oldFile?.fileLang || "", data?.newFile?.fileLang || "");
1021
+ var _a, _b, _c, _d, _e, _f;
1022
+ 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) || "");
2414
1023
  if (bundle) {
2415
1024
  instance.mergeBundle(bundle);
2416
1025
  }
2417
1026
  return instance;
2418
1027
  }
2419
1028
  constructor(_oldFileName, _oldFileContent, _newFileName, _newFileContent, _diffList, _oldFileLang, _newFileLang) {
1029
+ _DiffFile_instances.add(this);
2420
1030
  this._oldFileName = _oldFileName;
2421
1031
  this._newFileName = _newFileName;
2422
1032
  this._diffList = _diffList;
2423
- Object.defineProperty(this, "__v_skip", { value: true });
2424
- let oldContent = _oldFileContent;
2425
- let newContent = _newFileContent;
2426
- const diffList = Array.from(new Set(_diffList));
2427
- Object.defineProperties(this, {
2428
- _oldFileName: { get: () => _oldFileName },
2429
- _newFileName: { get: () => _newFileName },
2430
- _oldFileLang: { get: () => getLang(_oldFileLang || _oldFileName || _newFileLang || _newFileName) || "txt" },
2431
- _newFileLang: { get: () => getLang(_newFileLang || _newFileName || _oldFileLang || _oldFileName) || "txt" },
2432
- _oldFileContent: {
2433
- get: () => oldContent,
2434
- set: (v) => (oldContent = v),
2435
- },
2436
- _newFileContent: {
2437
- get: () => newContent,
2438
- set: (v) => (newContent = v),
2439
- },
2440
- _diffList: { get: () => diffList },
2441
- });
2442
- this.initId();
2443
- }
2444
- #doDiff() {
2445
- if (!this._diffList)
2446
- return;
2447
- this.#diffListResults = this._diffList.map((s) => parseInstance.parse(s));
2448
- }
2449
- #doFile() {
2450
- if (!this._oldFileContent && !this._newFileContent)
2451
- return;
2452
- if (this._oldFileContent) {
2453
- this.#oldFileResult = getFile(this._oldFileContent, this._oldFileLang, this._oldFileName);
2454
- }
2455
- if (this._newFileContent) {
2456
- this.#newFileResult = getFile(this._newFileContent, this._newFileLang, this._newFileName);
2457
- }
2458
- }
2459
- #composeRaw() {
2460
- this.#oldFileResult?.doRaw();
2461
- this.#oldFileLines = this.#oldFileResult?.rawFile;
2462
- this.#newFileResult?.doRaw();
2463
- this.#newFileLines = this.#newFileResult?.rawFile;
2464
- }
2465
- #composeFile() {
2466
- if (this._oldFileContent && this._newFileContent)
2467
- return;
2468
- // all of the file content not exist, try to use diff result to compose
2469
- if (!this._oldFileContent && !this._newFileContent) {
2470
- let newLineNumber = 1;
2471
- let oldLineNumber = 1;
2472
- let oldFileContent = "";
2473
- let newFileContent = "";
2474
- while (oldLineNumber <= this.diffLineLength) {
2475
- const diffLine = this.#getOldDiffLine(oldLineNumber++);
2476
- if (diffLine) {
2477
- oldFileContent += diffLine.text;
1033
+ _DiffFile_oldFileResult.set(this, void 0);
1034
+ _DiffFile_newFileResult.set(this, void 0);
1035
+ _DiffFile_diffListResults.set(this, void 0);
1036
+ _DiffFile_diffLines.set(this, void 0);
1037
+ _DiffFile_oldFileDiffLines.set(this, void 0);
1038
+ _DiffFile_newFileDiffLines.set(this, void 0);
1039
+ _DiffFile_oldFileLines.set(this, void 0);
1040
+ _DiffFile_newFileLines.set(this, void 0);
1041
+ _DiffFile_oldFileSyntaxLines.set(this, void 0);
1042
+ _DiffFile_newFileSyntaxLines.set(this, void 0);
1043
+ _DiffFile_oldFilePlaceholderLines.set(this, void 0);
1044
+ _DiffFile_newFilePlaceholderLines.set(this, void 0);
1045
+ _DiffFile_splitLeftLines.set(this, []);
1046
+ _DiffFile_splitRightLines.set(this, []);
1047
+ _DiffFile_splitHunksLines.set(this, void 0);
1048
+ _DiffFile_unifiedLines.set(this, []);
1049
+ _DiffFile_unifiedHunksLines.set(this, void 0);
1050
+ _DiffFile_listeners.set(this, []);
1051
+ _DiffFile_hasInitRaw.set(this, false);
1052
+ _DiffFile_hasInitSyntax.set(this, false);
1053
+ _DiffFile_hasBuildSplit.set(this, false);
1054
+ _DiffFile_hasBuildUnified.set(this, false);
1055
+ _DiffFile_updateCount.set(this, 0);
1056
+ _DiffFile_composeByDiff.set(this, false);
1057
+ this._version_ = "0.0.8";
1058
+ this._oldFileContent = "";
1059
+ this._oldFileLang = "";
1060
+ this._newFileContent = "";
1061
+ this._newFileLang = "";
1062
+ this.diffLineLength = 0;
1063
+ this.splitLineLength = 0;
1064
+ this.unifiedLineLength = 0;
1065
+ this.expandSplitAll = false;
1066
+ this.expandUnifiedAll = false;
1067
+ this.hasCollapsed = false;
1068
+ _DiffFile_id.set(this, "");
1069
+ _DiffFile_clonedInstance.set(this, new Map());
1070
+ this.getSplitLeftLine = (index) => {
1071
+ return __classPrivateFieldGet(this, _DiffFile_splitLeftLines, "f")[index];
1072
+ };
1073
+ this.getSplitRightLine = (index) => {
1074
+ return __classPrivateFieldGet(this, _DiffFile_splitRightLines, "f")[index];
1075
+ };
1076
+ this.getSplitHunkLine = (index) => {
1077
+ var _a;
1078
+ return (_a = __classPrivateFieldGet(this, _DiffFile_splitHunksLines, "f")) === null || _a === void 0 ? void 0 : _a[index];
1079
+ };
1080
+ this.onSplitHunkExpand = (dir, index, needTrigger = true) => {
1081
+ var _a, _b;
1082
+ const current = (_a = __classPrivateFieldGet(this, _DiffFile_splitHunksLines, "f")) === null || _a === void 0 ? void 0 : _a[index];
1083
+ if (!current || !current.splitInfo)
1084
+ return;
1085
+ if (__classPrivateFieldGet(this, _DiffFile_composeByDiff, "f"))
1086
+ return;
1087
+ if (dir === "all") {
1088
+ for (let i = current.splitInfo.startHiddenIndex; i < current.splitInfo.endHiddenIndex; i++) {
1089
+ const leftLine = __classPrivateFieldGet(this, _DiffFile_splitLeftLines, "f")[i];
1090
+ const rightLine = __classPrivateFieldGet(this, _DiffFile_splitRightLines, "f")[i];
1091
+ if (leftLine === null || leftLine === void 0 ? void 0 : leftLine.isHidden)
1092
+ leftLine.isHidden = false;
1093
+ if (rightLine === null || rightLine === void 0 ? void 0 : rightLine.isHidden)
1094
+ rightLine.isHidden = false;
1095
+ }
1096
+ current.splitInfo = Object.assign(Object.assign(Object.assign({}, current.splitInfo), current.hunkInfo), { plainText: current.text, startHiddenIndex: current.splitInfo.endHiddenIndex });
1097
+ }
1098
+ else if (dir === "down") {
1099
+ for (let i = current.splitInfo.startHiddenIndex; i < current.splitInfo.startHiddenIndex + composeLen; i++) {
1100
+ const leftLine = __classPrivateFieldGet(this, _DiffFile_splitLeftLines, "f")[i];
1101
+ const rightLine = __classPrivateFieldGet(this, _DiffFile_splitRightLines, "f")[i];
1102
+ if (leftLine === null || leftLine === void 0 ? void 0 : leftLine.isHidden)
1103
+ leftLine.isHidden = false;
1104
+ if (rightLine === null || rightLine === void 0 ? void 0 : rightLine.isHidden)
1105
+ rightLine.isHidden = false;
1106
+ }
1107
+ if (current.isLast) {
1108
+ current.splitInfo = Object.assign(Object.assign({}, current.splitInfo), { startHiddenIndex: current.splitInfo.startHiddenIndex + composeLen });
2478
1109
  }
2479
1110
  else {
2480
- // empty line for placeholder
2481
- oldFileContent += "\n";
1111
+ 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}` });
2482
1112
  }
2483
1113
  }
2484
- while (newLineNumber <= this.diffLineLength) {
2485
- const diffLine = this.#getNewDiffLine(newLineNumber++);
2486
- if (diffLine) {
2487
- newFileContent += diffLine.text;
1114
+ else {
1115
+ if (current.isLast) {
1116
+ console.error("the last hunk can not expand up!");
1117
+ return;
2488
1118
  }
2489
- else {
2490
- // empty line for placeholder
2491
- newFileContent += "\n";
1119
+ for (let i = current.splitInfo.endHiddenIndex - composeLen; i < current.splitInfo.endHiddenIndex; i++) {
1120
+ const leftLine = __classPrivateFieldGet(this, _DiffFile_splitLeftLines, "f")[i];
1121
+ const rightLine = __classPrivateFieldGet(this, _DiffFile_splitRightLines, "f")[i];
1122
+ if (leftLine === null || leftLine === void 0 ? void 0 : leftLine.isHidden)
1123
+ leftLine.isHidden = false;
1124
+ if (rightLine === null || rightLine === void 0 ? void 0 : rightLine.isHidden)
1125
+ rightLine.isHidden = false;
1126
+ }
1127
+ const oldStartIndex = current.splitInfo.oldStartIndex - composeLen;
1128
+ const oldLength = current.splitInfo.oldLength + composeLen;
1129
+ const newStartIndex = current.splitInfo.newStartIndex - composeLen;
1130
+ const newLength = current.splitInfo.newLength + composeLen;
1131
+ current.splitInfo = Object.assign(Object.assign({}, current.splitInfo), { endHiddenIndex: current.splitInfo.endHiddenIndex - composeLen, oldStartIndex,
1132
+ oldLength,
1133
+ newStartIndex,
1134
+ newLength, plainText: `@@ -${oldStartIndex},${oldLength} +${newStartIndex},${newLength}` });
1135
+ (_b = __classPrivateFieldGet(this, _DiffFile_splitHunksLines, "f")) === null || _b === void 0 ? true : delete _b[index];
1136
+ __classPrivateFieldGet(this, _DiffFile_splitHunksLines, "f")[current.splitInfo.endHiddenIndex] = current;
1137
+ }
1138
+ needTrigger && this.notifyAll();
1139
+ };
1140
+ this.getUnifiedLine = (index) => {
1141
+ return __classPrivateFieldGet(this, _DiffFile_unifiedLines, "f")[index];
1142
+ };
1143
+ this.getUnifiedHunkLine = (index) => {
1144
+ var _a;
1145
+ return (_a = __classPrivateFieldGet(this, _DiffFile_unifiedHunksLines, "f")) === null || _a === void 0 ? void 0 : _a[index];
1146
+ };
1147
+ this.onUnifiedHunkExpand = (dir, index, needTrigger = true) => {
1148
+ var _a, _b, _c;
1149
+ const current = (_a = __classPrivateFieldGet(this, _DiffFile_unifiedHunksLines, "f")) === null || _a === void 0 ? void 0 : _a[index];
1150
+ if (!current || !current.unifiedInfo)
1151
+ return;
1152
+ if (__classPrivateFieldGet(this, _DiffFile_composeByDiff, "f"))
1153
+ return;
1154
+ if (dir === "all") {
1155
+ for (let i = current.unifiedInfo.startHiddenIndex; i < current.unifiedInfo.endHiddenIndex; i++) {
1156
+ const unifiedLine = (_b = __classPrivateFieldGet(this, _DiffFile_unifiedLines, "f")) === null || _b === void 0 ? void 0 : _b[i];
1157
+ if (unifiedLine === null || unifiedLine === void 0 ? void 0 : unifiedLine.isHidden) {
1158
+ unifiedLine.isHidden = false;
1159
+ }
2492
1160
  }
1161
+ current.unifiedInfo = Object.assign(Object.assign(Object.assign({}, current.unifiedInfo), current.hunkInfo), { plainText: current.text, startHiddenIndex: current.unifiedInfo.endHiddenIndex });
2493
1162
  }
2494
- if (oldFileContent === newFileContent)
2495
- return;
2496
- this._oldFileContent = oldFileContent;
2497
- this._newFileContent = newFileContent;
2498
- this.#oldFileResult = getFile(this._oldFileContent, this._oldFileLang, this._oldFileName);
2499
- this.#newFileResult = getFile(this._newFileContent, this._newFileLang, this._newFileName);
2500
- // all of the file just compose by diff, so we can not do the expand action
2501
- this.#composeByDiff = true;
2502
- }
2503
- else if (this.#oldFileResult) {
2504
- let newLineNumber = 1;
2505
- let oldLineNumber = 1;
2506
- let newFileContent = "";
2507
- while (oldLineNumber <= this.#oldFileResult.maxLineNumber) {
2508
- const newDiffLine = this.#getNewDiffLine(newLineNumber++);
2509
- if (newDiffLine) {
2510
- newFileContent += newDiffLine.text;
2511
- oldLineNumber = newDiffLine.oldLineNumber ? newDiffLine.oldLineNumber + 1 : oldLineNumber;
1163
+ else if (dir === "down") {
1164
+ for (let i = current.unifiedInfo.startHiddenIndex; i < current.unifiedInfo.startHiddenIndex + composeLen; i++) {
1165
+ const unifiedLine = __classPrivateFieldGet(this, _DiffFile_unifiedLines, "f")[i];
1166
+ if (unifiedLine === null || unifiedLine === void 0 ? void 0 : unifiedLine.isHidden)
1167
+ unifiedLine.isHidden = false;
1168
+ }
1169
+ if (current.isLast) {
1170
+ current.unifiedInfo = Object.assign(Object.assign({}, current.unifiedInfo), { startHiddenIndex: current.unifiedInfo.startHiddenIndex + composeLen });
2512
1171
  }
2513
1172
  else {
2514
- newFileContent += this.#getOldRawLine(oldLineNumber++);
1173
+ 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}` });
2515
1174
  }
2516
1175
  }
2517
- if (newFileContent === this._oldFileContent)
2518
- return;
2519
- this._newFileContent = newFileContent;
2520
- this.#newFileResult = getFile(this._newFileContent, this._newFileLang, this._newFileName);
2521
- }
2522
- else if (this.#newFileResult) {
2523
- let oldLineNumber = 1;
2524
- let newLineNumber = 1;
2525
- let oldFileContent = "";
2526
- while (newLineNumber <= this.#newFileResult.maxLineNumber) {
2527
- const oldDiffLine = this.#getOldDiffLine(oldLineNumber++);
2528
- if (oldDiffLine) {
2529
- oldFileContent += oldDiffLine.text;
2530
- newLineNumber = oldDiffLine.newLineNumber ? oldDiffLine.newLineNumber + 1 : newLineNumber;
2531
- }
2532
- else {
2533
- oldFileContent += this.#getNewRawLine(newLineNumber++);
1176
+ else {
1177
+ if (current.isLast) {
1178
+ console.error("the last hunk can not expand up!");
1179
+ return;
2534
1180
  }
1181
+ for (let i = current.unifiedInfo.endHiddenIndex - composeLen; i < current.unifiedInfo.endHiddenIndex; i++) {
1182
+ const unifiedLine = __classPrivateFieldGet(this, _DiffFile_unifiedLines, "f")[i];
1183
+ if (unifiedLine === null || unifiedLine === void 0 ? void 0 : unifiedLine.isHidden)
1184
+ unifiedLine.isHidden = false;
1185
+ }
1186
+ const oldStartIndex = current.unifiedInfo.oldStartIndex - composeLen;
1187
+ const oldLength = current.unifiedInfo.oldLength + composeLen;
1188
+ const newStartIndex = current.unifiedInfo.newStartIndex - composeLen;
1189
+ const newLength = current.unifiedInfo.newLength + composeLen;
1190
+ current.unifiedInfo = Object.assign(Object.assign({}, current.unifiedInfo), { endHiddenIndex: current.unifiedInfo.endHiddenIndex - composeLen, oldStartIndex,
1191
+ oldLength,
1192
+ newStartIndex,
1193
+ newLength, plainText: `@@ -${oldStartIndex},${oldLength} +${newStartIndex},${newLength}` });
1194
+ (_c = __classPrivateFieldGet(this, _DiffFile_unifiedHunksLines, "f")) === null || _c === void 0 ? true : delete _c[index];
1195
+ __classPrivateFieldGet(this, _DiffFile_unifiedHunksLines, "f")[current.unifiedInfo.endHiddenIndex] = current;
1196
+ }
1197
+ needTrigger && this.notifyAll();
1198
+ };
1199
+ this.onAllExpand = (mode) => {
1200
+ if (__classPrivateFieldGet(this, _DiffFile_composeByDiff, "f"))
1201
+ return;
1202
+ if (mode === "split") {
1203
+ Object.keys(__classPrivateFieldGet(this, _DiffFile_splitHunksLines, "f") || {}).forEach((key) => {
1204
+ this.onSplitHunkExpand("all", +key, false);
1205
+ });
1206
+ this.expandSplitAll = true;
2535
1207
  }
2536
- if (oldFileContent === this._newFileContent)
1208
+ else {
1209
+ Object.keys(__classPrivateFieldGet(this, _DiffFile_unifiedHunksLines, "f") || {}).forEach((key) => {
1210
+ this.onUnifiedHunkExpand("all", +key, false);
1211
+ });
1212
+ this.expandUnifiedAll = true;
1213
+ }
1214
+ this.notifyAll();
1215
+ };
1216
+ this.onAllCollapse = (mode) => {
1217
+ if (__classPrivateFieldGet(this, _DiffFile_composeByDiff, "f"))
2537
1218
  return;
2538
- this._oldFileContent = oldFileContent;
2539
- this.#oldFileResult = getFile(this._oldFileContent, this._oldFileLang, this._oldFileName);
2540
- }
2541
- this.#composeRaw();
2542
- }
2543
- #composeDiff() {
2544
- if (!this.#diffListResults?.length)
2545
- return;
2546
- this.#diffListResults.forEach((item) => {
2547
- const hunks = item.hunks;
2548
- hunks.forEach((hunk) => {
2549
- let additions = [];
2550
- let deletions = [];
2551
- hunk.lines.forEach((line) => {
2552
- if (line.type === DiffLineType.Add) {
2553
- additions.push(line);
1219
+ if (mode === "split") {
1220
+ Object.values(__classPrivateFieldGet(this, _DiffFile_splitLeftLines, "f") || {}).forEach((item) => {
1221
+ if (!item.isHidden && item._isHidden) {
1222
+ item.isHidden = item._isHidden;
2554
1223
  }
2555
- else if (line.type === DiffLineType.Delete) {
2556
- deletions.push(line);
1224
+ });
1225
+ Object.values(__classPrivateFieldGet(this, _DiffFile_splitRightLines, "f") || {}).forEach((item) => {
1226
+ if (!item.isHidden && item._isHidden) {
1227
+ item.isHidden = item._isHidden;
2557
1228
  }
2558
- else {
2559
- getDiffRange(additions, deletions);
2560
- additions = [];
2561
- deletions = [];
1229
+ });
1230
+ Object.values(__classPrivateFieldGet(this, _DiffFile_splitHunksLines, "f") || {}).forEach((item) => {
1231
+ if (!item.splitInfo)
1232
+ return;
1233
+ 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 });
1234
+ });
1235
+ Object.keys(__classPrivateFieldGet(this, _DiffFile_splitHunksLines, "f") || {}).forEach((key) => {
1236
+ const item = __classPrivateFieldGet(this, _DiffFile_splitHunksLines, "f")[key];
1237
+ if (!item.splitInfo)
1238
+ return;
1239
+ if (item.splitInfo.endHiddenIndex !== +key) {
1240
+ delete __classPrivateFieldGet(this, _DiffFile_splitHunksLines, "f")[key];
1241
+ __classPrivateFieldGet(this, _DiffFile_splitHunksLines, "f")[item.splitInfo.endHiddenIndex] = item;
1242
+ }
1243
+ });
1244
+ this.expandSplitAll = false;
1245
+ }
1246
+ else {
1247
+ Object.values(__classPrivateFieldGet(this, _DiffFile_unifiedLines, "f") || {}).forEach((item) => {
1248
+ if (!item.isHidden && item._isHidden) {
1249
+ item.isHidden = item._isHidden;
1250
+ }
1251
+ });
1252
+ Object.values(__classPrivateFieldGet(this, _DiffFile_unifiedHunksLines, "f") || {}).forEach((item) => {
1253
+ if (!item.unifiedInfo)
1254
+ return;
1255
+ 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 });
1256
+ });
1257
+ Object.keys(__classPrivateFieldGet(this, _DiffFile_unifiedHunksLines, "f") || {}).forEach((key) => {
1258
+ const item = __classPrivateFieldGet(this, _DiffFile_unifiedHunksLines, "f")[key];
1259
+ if (!item.unifiedInfo)
1260
+ return;
1261
+ if (item.unifiedInfo.endHiddenIndex !== +key) {
1262
+ delete __classPrivateFieldGet(this, _DiffFile_unifiedHunksLines, "f")[key];
1263
+ __classPrivateFieldGet(this, _DiffFile_unifiedHunksLines, "f")[item.unifiedInfo.endHiddenIndex] = item;
2562
1264
  }
2563
1265
  });
2564
- getDiffRange(additions, deletions);
1266
+ this.expandUnifiedAll = false;
1267
+ }
1268
+ this.notifyAll();
1269
+ };
1270
+ this.getOldSyntaxLine = (lineNumber) => {
1271
+ var _a;
1272
+ return (_a = __classPrivateFieldGet(this, _DiffFile_oldFileSyntaxLines, "f")) === null || _a === void 0 ? void 0 : _a[lineNumber];
1273
+ };
1274
+ this.getNewSyntaxLine = (lineNumber) => {
1275
+ var _a;
1276
+ return (_a = __classPrivateFieldGet(this, _DiffFile_newFileSyntaxLines, "f")) === null || _a === void 0 ? void 0 : _a[lineNumber];
1277
+ };
1278
+ this.subscribe = (listener) => {
1279
+ __classPrivateFieldGet(this, _DiffFile_listeners, "f").push(listener);
1280
+ return () => {
1281
+ __classPrivateFieldGet(this, _DiffFile_listeners, "f").filter((i) => i !== listener);
1282
+ };
1283
+ };
1284
+ this.notifyAll = (skipSyncExternal) => {
1285
+ var _a;
1286
+ __classPrivateFieldSet(this, _DiffFile_updateCount, (_a = __classPrivateFieldGet(this, _DiffFile_updateCount, "f"), _a++, _a), "f");
1287
+ __classPrivateFieldGet(this, _DiffFile_listeners, "f").forEach((f) => {
1288
+ if (skipSyncExternal && f.isSyncExternal) {
1289
+ return;
1290
+ }
1291
+ f();
2565
1292
  });
2566
- });
2567
- this.#diffLines = [];
2568
- const tmp = [];
2569
- this.#diffListResults.forEach((item) => {
2570
- item.hunks.forEach((_item) => {
2571
- tmp.push(..._item.lines);
1293
+ // support update from outside instance
1294
+ __classPrivateFieldGet(this, _DiffFile_clonedInstance, "f").forEach((_, instance) => {
1295
+ instance.notifyAll(true);
1296
+ });
1297
+ };
1298
+ this.getUpdateCount = () => __classPrivateFieldGet(this, _DiffFile_updateCount, "f");
1299
+ this.getExpandEnabled = () => !__classPrivateFieldGet(this, _DiffFile_composeByDiff, "f");
1300
+ this.getBundle = () => {
1301
+ // common
1302
+ const hasInitRaw = __classPrivateFieldGet(this, _DiffFile_hasInitRaw, "f");
1303
+ const hasInitSyntax = __classPrivateFieldGet(this, _DiffFile_hasInitSyntax, "f");
1304
+ const hasBuildSplit = __classPrivateFieldGet(this, _DiffFile_hasBuildSplit, "f");
1305
+ const hasBuildUnified = __classPrivateFieldGet(this, _DiffFile_hasBuildUnified, "f");
1306
+ const oldFileLines = __classPrivateFieldGet(this, _DiffFile_oldFileLines, "f");
1307
+ const oldFileDiffLines = __classPrivateFieldGet(this, _DiffFile_oldFileDiffLines, "f");
1308
+ const oldFileSyntaxLines = __classPrivateFieldGet(this, _DiffFile_oldFileSyntaxLines, "f");
1309
+ const oldFilePlaceholderLines = __classPrivateFieldGet(this, _DiffFile_oldFilePlaceholderLines, "f");
1310
+ const newFileLines = __classPrivateFieldGet(this, _DiffFile_newFileLines, "f");
1311
+ const newFileDiffLines = __classPrivateFieldGet(this, _DiffFile_newFileDiffLines, "f");
1312
+ const newFileSyntaxLines = __classPrivateFieldGet(this, _DiffFile_newFileSyntaxLines, "f");
1313
+ const newFilePlaceholderLines = __classPrivateFieldGet(this, _DiffFile_newFilePlaceholderLines, "f");
1314
+ const splitLineLength = this.splitLineLength;
1315
+ const unifiedLineLength = this.unifiedLineLength;
1316
+ const composeByDiff = __classPrivateFieldGet(this, _DiffFile_composeByDiff, "f");
1317
+ const hasCollapsed = this.hasCollapsed;
1318
+ // split
1319
+ const splitLeftLines = __classPrivateFieldGet(this, _DiffFile_splitLeftLines, "f");
1320
+ const splitRightLines = __classPrivateFieldGet(this, _DiffFile_splitRightLines, "f");
1321
+ const splitHunkLines = __classPrivateFieldGet(this, _DiffFile_splitHunksLines, "f");
1322
+ // unified
1323
+ const unifiedLines = __classPrivateFieldGet(this, _DiffFile_unifiedLines, "f");
1324
+ const unifiedHunkLines = __classPrivateFieldGet(this, _DiffFile_unifiedHunksLines, "f");
1325
+ const version = this._version_;
1326
+ return {
1327
+ hasInitRaw,
1328
+ hasInitSyntax,
1329
+ hasBuildSplit,
1330
+ hasBuildUnified,
1331
+ oldFileLines,
1332
+ oldFileDiffLines,
1333
+ oldFileSyntaxLines,
1334
+ oldFilePlaceholderLines,
1335
+ newFileLines,
1336
+ newFileDiffLines,
1337
+ newFileSyntaxLines,
1338
+ newFilePlaceholderLines,
1339
+ splitLineLength,
1340
+ unifiedLineLength,
1341
+ splitLeftLines,
1342
+ splitRightLines,
1343
+ splitHunkLines,
1344
+ unifiedLines,
1345
+ unifiedHunkLines,
1346
+ composeByDiff,
1347
+ hasCollapsed,
1348
+ version,
1349
+ };
1350
+ };
1351
+ this.mergeBundle = (data) => {
1352
+ __classPrivateFieldSet(this, _DiffFile_hasInitRaw, data.hasInitRaw, "f");
1353
+ __classPrivateFieldSet(this, _DiffFile_hasInitSyntax, data.hasInitSyntax, "f");
1354
+ __classPrivateFieldSet(this, _DiffFile_hasBuildSplit, data.hasBuildSplit, "f");
1355
+ __classPrivateFieldSet(this, _DiffFile_hasBuildUnified, data.hasBuildUnified, "f");
1356
+ __classPrivateFieldSet(this, _DiffFile_composeByDiff, data.composeByDiff, "f");
1357
+ __classPrivateFieldSet(this, _DiffFile_oldFileLines, data.oldFileLines, "f");
1358
+ __classPrivateFieldSet(this, _DiffFile_oldFileDiffLines, data.oldFileDiffLines, "f");
1359
+ __classPrivateFieldSet(this, _DiffFile_oldFileSyntaxLines, data.oldFileSyntaxLines, "f");
1360
+ __classPrivateFieldSet(this, _DiffFile_oldFilePlaceholderLines, data.oldFilePlaceholderLines, "f");
1361
+ __classPrivateFieldSet(this, _DiffFile_newFileLines, data.newFileLines, "f");
1362
+ __classPrivateFieldSet(this, _DiffFile_newFileDiffLines, data.newFileDiffLines, "f");
1363
+ __classPrivateFieldSet(this, _DiffFile_newFileSyntaxLines, data.newFileSyntaxLines, "f");
1364
+ __classPrivateFieldSet(this, _DiffFile_newFilePlaceholderLines, data.newFilePlaceholderLines, "f");
1365
+ this.splitLineLength = data.splitLineLength;
1366
+ this.unifiedLineLength = data.unifiedLineLength;
1367
+ this.hasCollapsed = data.hasCollapsed;
1368
+ __classPrivateFieldSet(this, _DiffFile_splitLeftLines, data.splitLeftLines, "f");
1369
+ __classPrivateFieldSet(this, _DiffFile_splitRightLines, data.splitRightLines, "f");
1370
+ __classPrivateFieldSet(this, _DiffFile_splitHunksLines, data.splitHunkLines, "f");
1371
+ __classPrivateFieldSet(this, _DiffFile_unifiedLines, data.unifiedLines, "f");
1372
+ __classPrivateFieldSet(this, _DiffFile_unifiedHunksLines, data.unifiedHunkLines, "f");
1373
+ if (this._version_ !== data.version) {
1374
+ console.error("the version of the `diffInstance` is not match, some error may happen!");
1375
+ }
1376
+ this.notifyAll();
1377
+ };
1378
+ this._getIsPureDiffRender = () => __classPrivateFieldGet(this, _DiffFile_composeByDiff, "f");
1379
+ this._addClonedInstance = (instance) => {
1380
+ const updateFunc = () => {
1381
+ this._notifyOthers(instance);
1382
+ };
1383
+ updateFunc.isSyncExternal = true;
1384
+ const unsubscribe = instance.subscribe(updateFunc);
1385
+ __classPrivateFieldGet(this, _DiffFile_clonedInstance, "f").set(instance, unsubscribe);
1386
+ };
1387
+ this._notifyOthers = (instance) => {
1388
+ __classPrivateFieldGet(this, _DiffFile_clonedInstance, "f").forEach((_, i) => {
1389
+ if (i !== instance) {
1390
+ i.notifyAll(true);
1391
+ }
2572
1392
  });
1393
+ };
1394
+ this._delClonedInstance = (instance) => {
1395
+ const unsubscribe = __classPrivateFieldGet(this, _DiffFile_clonedInstance, "f").get(instance);
1396
+ unsubscribe && unsubscribe();
1397
+ __classPrivateFieldGet(this, _DiffFile_clonedInstance, "f").delete(instance);
1398
+ };
1399
+ this._getFullBundle = () => {
1400
+ const bundle = this.getBundle();
1401
+ const oldFileResult = __classPrivateFieldGet(this, _DiffFile_oldFileResult, "f");
1402
+ const newFileResult = __classPrivateFieldGet(this, _DiffFile_newFileResult, "f");
1403
+ const diffLines = __classPrivateFieldGet(this, _DiffFile_diffLines, "f");
1404
+ const diffListResults = __classPrivateFieldGet(this, _DiffFile_diffListResults, "f");
1405
+ return Object.assign(Object.assign({}, bundle), { oldFileResult,
1406
+ newFileResult,
1407
+ diffLines,
1408
+ diffListResults });
1409
+ };
1410
+ this._mergeFullBundle = (data) => {
1411
+ this.mergeBundle(data);
1412
+ __classPrivateFieldSet(this, _DiffFile_oldFileResult, data.oldFileResult, "f");
1413
+ __classPrivateFieldSet(this, _DiffFile_newFileResult, data.newFileResult, "f");
1414
+ __classPrivateFieldSet(this, _DiffFile_diffLines, data.diffLines, "f");
1415
+ __classPrivateFieldSet(this, _DiffFile_diffListResults, data.diffListResults, "f");
1416
+ };
1417
+ this._destroy = () => {
1418
+ this.clearId();
1419
+ __classPrivateFieldGet(this, _DiffFile_listeners, "f").splice(0, __classPrivateFieldGet(this, _DiffFile_listeners, "f").length);
1420
+ __classPrivateFieldGet(this, _DiffFile_clonedInstance, "f").forEach((v) => v());
1421
+ __classPrivateFieldGet(this, _DiffFile_clonedInstance, "f").clear();
1422
+ };
1423
+ this.clear = () => {
1424
+ this._destroy();
1425
+ __classPrivateFieldSet(this, _DiffFile_oldFileResult, null, "f");
1426
+ __classPrivateFieldSet(this, _DiffFile_newFileResult, null, "f");
1427
+ __classPrivateFieldSet(this, _DiffFile_diffLines, null, "f");
1428
+ __classPrivateFieldSet(this, _DiffFile_diffListResults, null, "f");
1429
+ __classPrivateFieldSet(this, _DiffFile_newFileDiffLines, null, "f");
1430
+ __classPrivateFieldSet(this, _DiffFile_oldFileDiffLines, null, "f");
1431
+ __classPrivateFieldSet(this, _DiffFile_newFileLines, null, "f");
1432
+ __classPrivateFieldSet(this, _DiffFile_oldFileLines, null, "f");
1433
+ __classPrivateFieldSet(this, _DiffFile_newFileSyntaxLines, null, "f");
1434
+ __classPrivateFieldSet(this, _DiffFile_oldFileSyntaxLines, null, "f");
1435
+ __classPrivateFieldSet(this, _DiffFile_splitHunksLines, null, "f");
1436
+ __classPrivateFieldSet(this, _DiffFile_splitLeftLines, null, "f");
1437
+ __classPrivateFieldSet(this, _DiffFile_splitRightLines, null, "f");
1438
+ __classPrivateFieldSet(this, _DiffFile_unifiedHunksLines, null, "f");
1439
+ __classPrivateFieldSet(this, _DiffFile_unifiedLines, null, "f");
1440
+ };
1441
+ Object.defineProperty(this, "__v_skip", { value: true });
1442
+ let oldContent = _oldFileContent;
1443
+ let newContent = _newFileContent;
1444
+ const diffList = Array.from(new Set(_diffList));
1445
+ Object.defineProperties(this, {
1446
+ _oldFileName: { get: () => _oldFileName },
1447
+ _newFileName: { get: () => _newFileName },
1448
+ _oldFileLang: { get: () => getLang(_oldFileLang || _oldFileName || _newFileLang || _newFileName) || "txt" },
1449
+ _newFileLang: { get: () => getLang(_newFileLang || _newFileName || _oldFileLang || _oldFileName) || "txt" },
1450
+ _oldFileContent: {
1451
+ get: () => oldContent,
1452
+ set: (v) => (oldContent = v),
1453
+ },
1454
+ _newFileContent: {
1455
+ get: () => newContent,
1456
+ set: (v) => (newContent = v),
1457
+ },
1458
+ _diffList: { get: () => diffList },
2573
1459
  });
2574
- this.#diffLines = tmp.map((i, index) => {
2575
- const typedI = i;
2576
- typedI.index = index;
2577
- if (typedI.type === DiffLineType.Hunk) {
2578
- const numInfo = typedI.text.split("@@")?.[1].split(" ").filter(Boolean);
2579
- const oldNumInfo = numInfo?.[0] || "";
2580
- const newNumInfo = numInfo?.[1] || "";
2581
- const [oldNumStartIndex, oldNumLength] = oldNumInfo.split(",");
2582
- const [newNumStartIndex, newNumLength] = newNumInfo.split(",");
2583
- const typedTypeI = typedI;
2584
- typedTypeI.hunkInfo = {
2585
- oldStartIndex: -Number(oldNumStartIndex),
2586
- oldLength: Number(oldNumLength),
2587
- newStartIndex: +Number(newNumStartIndex),
2588
- newLength: Number(newNumLength),
2589
- _oldStartIndex: -Number(oldNumStartIndex),
2590
- _oldLength: Number(oldNumLength),
2591
- _newStartIndex: +Number(newNumStartIndex),
2592
- _newLength: Number(newNumLength),
2593
- };
2594
- }
2595
- return typedI;
2596
- });
2597
- // this.#diffLines = this.#diffListResults
2598
- // .reduce<DiffLine[]>((p, c) => p.concat(...c.hunks.reduce<DiffLine[]>((_p, _c) => _p.concat(..._c.lines), [])), [])
2599
- // .map<DiffLineItem>((i, index) => {
2600
- // const typedI = i as DiffLineItem;
2601
- // typedI.index = index;
2602
- // if (typedI.type === DiffLineType.Hunk) {
2603
- // const numInfo = typedI.text.split("@@")?.[1].split(" ").filter(Boolean);
2604
- // const oldNumInfo = numInfo?.[0] || "";
2605
- // const newNumInfo = numInfo?.[1] || "";
2606
- // const [oldNumStartIndex, oldNumLength] = oldNumInfo.split(",");
2607
- // const [newNumStartIndex, newNumLength] = newNumInfo.split(",");
2608
- // const typedTypeI = typedI as DiffHunkItem;
2609
- // typedTypeI.hunkInfo = {
2610
- // oldStartIndex: -Number(oldNumStartIndex),
2611
- // oldLength: Number(oldNumLength),
2612
- // newStartIndex: +Number(newNumStartIndex),
2613
- // newLength: Number(newNumLength),
2614
- // };
2615
- // }
2616
- // return typedI;
2617
- // });
2618
- this.#oldFileDiffLines = {};
2619
- this.#diffLines.forEach((item) => {
2620
- if (item.oldLineNumber) {
2621
- this.diffLineLength = Math.max(this.diffLineLength, item.oldLineNumber);
2622
- this.#oldFileDiffLines[item.oldLineNumber] = item;
2623
- }
2624
- });
2625
- this.#newFileDiffLines = {};
2626
- this.#diffLines.forEach((item) => {
2627
- if (item.newLineNumber) {
2628
- this.diffLineLength = Math.max(this.diffLineLength, item.newLineNumber);
2629
- this.#newFileDiffLines[item.newLineNumber] = item;
2630
- }
2631
- });
2632
- }
2633
- #composeSyntax({ autoDetectLang, registerHighlighter, }) {
2634
- this.#oldFileResult?.doSyntax({ autoDetectLang, registerHighlighter });
2635
- this.#oldFileSyntaxLines = this.#oldFileResult?.syntaxFile;
2636
- this.#newFileResult?.doSyntax({ autoDetectLang, registerHighlighter });
2637
- this.#newFileSyntaxLines = this.#newFileResult?.syntaxFile;
2638
- }
2639
- #getOldDiffLine(lineNumber) {
2640
- if (!lineNumber)
2641
- return;
2642
- return this.#oldFileDiffLines?.[lineNumber];
2643
- }
2644
- #getNewDiffLine(lineNumber) {
2645
- if (!lineNumber)
2646
- return;
2647
- return this.#newFileDiffLines?.[lineNumber];
2648
- }
2649
- #getOldRawLine(lineNumber) {
2650
- return this.#oldFileLines?.[lineNumber];
2651
- }
2652
- #getNewRawLine(lineNumber) {
2653
- return this.#newFileLines?.[lineNumber];
1460
+ this.initId();
2654
1461
  }
2655
1462
  initId() {
2656
1463
  let id = "--" + Math.random().toString().slice(2);
@@ -2658,76 +1465,97 @@ class DiffFile {
2658
1465
  id = "--" + Math.random().toString().slice(2);
2659
1466
  }
2660
1467
  idSet.add(id);
2661
- this.#id = id;
1468
+ __classPrivateFieldSet(this, _DiffFile_id, id, "f");
2662
1469
  }
2663
1470
  getId() {
2664
- return this.#id;
1471
+ return __classPrivateFieldGet(this, _DiffFile_id, "f");
2665
1472
  }
2666
1473
  clearId() {
2667
- idSet.delete(this.#id);
1474
+ idSet.delete(__classPrivateFieldGet(this, _DiffFile_id, "f"));
2668
1475
  }
2669
1476
  initRaw() {
2670
- if (this.#hasInitRaw)
1477
+ if (__classPrivateFieldGet(this, _DiffFile_hasInitRaw, "f"))
2671
1478
  return;
2672
- this.#doDiff();
2673
- this.#composeDiff();
2674
- this.#doFile();
2675
- this.#composeRaw();
2676
- this.#composeFile();
2677
- this.#hasInitRaw = true;
1479
+ __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_doDiff).call(this);
1480
+ __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_composeDiff).call(this);
1481
+ __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_doFile).call(this);
1482
+ __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_composeRaw).call(this);
1483
+ __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_composeFile).call(this);
1484
+ __classPrivateFieldSet(this, _DiffFile_hasInitRaw, true, "f");
2678
1485
  }
2679
1486
  initSyntax({ autoDetectLang, registerHighlighter, } = {}) {
2680
- if (this.#hasInitSyntax)
1487
+ if (__classPrivateFieldGet(this, _DiffFile_hasInitSyntax, "f"))
2681
1488
  return;
2682
- this.#composeSyntax({ registerHighlighter, autoDetectLang });
2683
- this.#hasInitSyntax = true;
1489
+ __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_composeSyntax).call(this, { registerHighlighter, autoDetectLang });
1490
+ __classPrivateFieldSet(this, _DiffFile_hasInitSyntax, true, "f");
2684
1491
  }
2685
1492
  init() {
2686
1493
  this.initRaw();
2687
1494
  this.initSyntax();
2688
1495
  }
2689
1496
  buildSplitDiffLines() {
2690
- if (this.#hasBuildSplit)
1497
+ var _a, _b, _c, _d, _e, _f, _g;
1498
+ if (__classPrivateFieldGet(this, _DiffFile_hasBuildSplit, "f"))
2691
1499
  return;
2692
1500
  let oldFileLineNumber = 1;
2693
1501
  let newFileLineNumber = 1;
2694
1502
  let prevIsHidden = false;
2695
1503
  let hideStart = Infinity;
2696
- const maxOldFileLineNumber = this.#oldFileResult?.maxLineNumber || 0;
2697
- const maxNewFileLineNumber = this.#newFileResult?.maxLineNumber || 0;
1504
+ const maxOldFileLineNumber = ((_a = __classPrivateFieldGet(this, _DiffFile_oldFileResult, "f")) === null || _a === void 0 ? void 0 : _a.maxLineNumber) || 0;
1505
+ const maxNewFileLineNumber = ((_b = __classPrivateFieldGet(this, _DiffFile_newFileResult, "f")) === null || _b === void 0 ? void 0 : _b.maxLineNumber) || 0;
2698
1506
  while (oldFileLineNumber <= maxOldFileLineNumber || newFileLineNumber <= maxNewFileLineNumber) {
2699
- const oldDiffLine = this.#getOldDiffLine(oldFileLineNumber);
2700
- const newDiffLine = this.#getNewDiffLine(newFileLineNumber);
2701
- const oldRawLine = this.#getOldRawLine(oldFileLineNumber);
2702
- const newRawLine = this.#getNewRawLine(newFileLineNumber);
2703
- const oldLineHasChange = oldDiffLine?.isIncludeableLine();
2704
- const newLineHasChange = newDiffLine?.isIncludeableLine();
2705
- const len = this.#splitRightLines.length;
1507
+ const oldDiffLine = __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getOldDiffLine).call(this, oldFileLineNumber);
1508
+ const newDiffLine = __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getNewDiffLine).call(this, newFileLineNumber);
1509
+ const oldRawLine = __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getOldRawLine).call(this, oldFileLineNumber);
1510
+ const newRawLine = __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getNewRawLine).call(this, newFileLineNumber);
1511
+ const oldLineHasChange = oldDiffLine === null || oldDiffLine === void 0 ? void 0 : oldDiffLine.isIncludeableLine();
1512
+ const newLineHasChange = newDiffLine === null || newDiffLine === void 0 ? void 0 : newDiffLine.isIncludeableLine();
1513
+ const len = __classPrivateFieldGet(this, _DiffFile_splitRightLines, "f").length;
2706
1514
  const isHidden = !oldDiffLine && !newDiffLine;
2707
- if ((oldDiffLine && !newDiffLine && oldDiffLine.newLineNumber && oldDiffLine.newLineNumber > newFileLineNumber) ||
2708
- (!oldDiffLine && newDiffLine && newDiffLine.oldLineNumber && newDiffLine.oldLineNumber > oldFileLineNumber)) {
2709
- if (this.#composeByDiff) {
2710
- oldDiffLine && newFileLineNumber++;
2711
- newDiffLine && oldFileLineNumber++;
1515
+ if (oldDiffLine && !newDiffLine) {
1516
+ if (oldDiffLine.newLineNumber && oldDiffLine.newLineNumber > newFileLineNumber) {
1517
+ newFileLineNumber++;
2712
1518
  continue;
2713
1519
  }
2714
- else {
2715
- {
2716
- console.error("some error happen for generate diff line!");
2717
- }
1520
+ if (oldDiffLine.newLineNumber === null || oldDiffLine.newLineNumber === undefined) {
1521
+ newFileLineNumber++;
1522
+ }
1523
+ }
1524
+ if (newDiffLine && !oldDiffLine) {
1525
+ if (newDiffLine.oldLineNumber && newDiffLine.oldLineNumber > oldFileLineNumber) {
1526
+ oldFileLineNumber++;
1527
+ continue;
1528
+ }
1529
+ if (newDiffLine.oldLineNumber === null || newDiffLine.oldLineNumber === undefined) {
1530
+ oldFileLineNumber++;
2718
1531
  }
2719
1532
  }
2720
- if (!oldDiffLine && !newRawLine && !oldDiffLine && !newDiffLine)
1533
+ if (!oldDiffLine && !oldRawLine && !newDiffLine && !newRawLine)
2721
1534
  break;
1535
+ if (!oldDiffLine && !newDiffLine) {
1536
+ 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])) {
1537
+ oldFileLineNumber++;
1538
+ newFileLineNumber++;
1539
+ continue;
1540
+ }
1541
+ if (!oldRawLine && ((_e = __classPrivateFieldGet(this, _DiffFile_newFilePlaceholderLines, "f")) === null || _e === void 0 ? void 0 : _e[newFileLineNumber])) {
1542
+ newFileLineNumber++;
1543
+ continue;
1544
+ }
1545
+ if (!newRawLine && ((_f = __classPrivateFieldGet(this, _DiffFile_oldFilePlaceholderLines, "f")) === null || _f === void 0 ? void 0 : _f[oldFileLineNumber])) {
1546
+ oldFileLineNumber++;
1547
+ continue;
1548
+ }
1549
+ }
2722
1550
  if ((oldLineHasChange && newLineHasChange) || (!oldLineHasChange && !newLineHasChange)) {
2723
- this.#splitLeftLines.push({
1551
+ __classPrivateFieldGet(this, _DiffFile_splitLeftLines, "f").push({
2724
1552
  lineNumber: oldFileLineNumber++,
2725
1553
  value: oldRawLine,
2726
1554
  diff: oldDiffLine,
2727
1555
  isHidden,
2728
1556
  _isHidden: isHidden,
2729
1557
  });
2730
- this.#splitRightLines.push({
1558
+ __classPrivateFieldGet(this, _DiffFile_splitRightLines, "f").push({
2731
1559
  lineNumber: newFileLineNumber++,
2732
1560
  value: newRawLine,
2733
1561
  diff: newDiffLine,
@@ -2736,18 +1564,18 @@ class DiffFile {
2736
1564
  });
2737
1565
  }
2738
1566
  else if (oldLineHasChange) {
2739
- this.#splitLeftLines.push({
1567
+ __classPrivateFieldGet(this, _DiffFile_splitLeftLines, "f").push({
2740
1568
  lineNumber: oldFileLineNumber++,
2741
1569
  value: oldRawLine,
2742
1570
  diff: oldDiffLine,
2743
1571
  isHidden,
2744
1572
  _isHidden: isHidden,
2745
1573
  });
2746
- this.#splitRightLines.push({});
1574
+ __classPrivateFieldGet(this, _DiffFile_splitRightLines, "f").push({});
2747
1575
  }
2748
1576
  else if (newLineHasChange) {
2749
- this.#splitLeftLines.push({});
2750
- this.#splitRightLines.push({
1577
+ __classPrivateFieldGet(this, _DiffFile_splitLeftLines, "f").push({});
1578
+ __classPrivateFieldGet(this, _DiffFile_splitRightLines, "f").push({
2751
1579
  lineNumber: newFileLineNumber++,
2752
1580
  value: newRawLine,
2753
1581
  diff: newDiffLine,
@@ -2758,41 +1586,33 @@ class DiffFile {
2758
1586
  if (!prevIsHidden && isHidden) {
2759
1587
  hideStart = len;
2760
1588
  }
1589
+ if (isHidden) {
1590
+ this.hasCollapsed = true;
1591
+ }
2761
1592
  prevIsHidden = isHidden;
2762
1593
  if (oldDiffLine && newDiffLine && !oldLineHasChange && !newLineHasChange) {
2763
1594
  const current = newDiffLine;
2764
- const previous = newDiffLine.index ? this.#diffLines?.[current.index - 1] : undefined;
2765
- if (previous && previous.type === DiffLineType.Hunk) {
1595
+ const previous = newDiffLine.index ? (_g = __classPrivateFieldGet(this, _DiffFile_diffLines, "f")) === null || _g === void 0 ? void 0 : _g[current.index - 1] : undefined;
1596
+ if (previous && previous.type === exports.DiffLineType.Hunk) {
2766
1597
  const typedPrevious = previous;
2767
1598
  if (Number.isFinite(hideStart)) {
2768
- typedPrevious.splitInfo = {
2769
- ...typedPrevious.hunkInfo,
2770
- startHiddenIndex: hideStart,
2771
- endHiddenIndex: len,
2772
- plainText: typedPrevious.text,
2773
- _startHiddenIndex: hideStart,
2774
- _endHiddenIndex: len,
2775
- _plainText: typedPrevious.text,
2776
- };
1599
+ typedPrevious.splitInfo = Object.assign(Object.assign({}, typedPrevious.hunkInfo), { startHiddenIndex: hideStart, endHiddenIndex: len, plainText: typedPrevious.text, _startHiddenIndex: hideStart, _endHiddenIndex: len, _plainText: typedPrevious.text });
2777
1600
  hideStart = Infinity;
2778
1601
  }
2779
- this.#splitHunksLines = {
2780
- ...this.#splitHunksLines,
2781
- [len]: typedPrevious,
2782
- };
1602
+ __classPrivateFieldSet(this, _DiffFile_splitHunksLines, Object.assign(Object.assign({}, __classPrivateFieldGet(this, _DiffFile_splitHunksLines, "f")), { [len]: typedPrevious }), "f");
2783
1603
  }
2784
1604
  }
2785
1605
  }
2786
1606
  // have last hunk
2787
1607
  if (Number.isFinite(hideStart)) {
2788
- const lastDiff = new DiffLine("", DiffLineType.Hunk, null, null, null);
1608
+ const lastDiff = new DiffLine("", exports.DiffLineType.Hunk, null, null, null);
2789
1609
  const lastHunk = lastDiff;
2790
1610
  lastHunk.isLast = true;
2791
1611
  lastHunk.splitInfo = {
2792
1612
  startHiddenIndex: hideStart,
2793
- endHiddenIndex: this.#splitRightLines.length,
1613
+ endHiddenIndex: __classPrivateFieldGet(this, _DiffFile_splitRightLines, "f").length,
2794
1614
  _startHiddenIndex: hideStart,
2795
- _endHiddenIndex: this.#splitRightLines.length,
1615
+ _endHiddenIndex: __classPrivateFieldGet(this, _DiffFile_splitRightLines, "f").length,
2796
1616
  // just for placeholder
2797
1617
  plainText: "",
2798
1618
  oldStartIndex: 0,
@@ -2805,51 +1625,69 @@ class DiffFile {
2805
1625
  _oldLength: 0,
2806
1626
  _newLength: 0,
2807
1627
  };
2808
- this.#splitHunksLines = {
2809
- ...this.#splitHunksLines,
2810
- [this.#splitRightLines.length]: lastHunk,
2811
- };
1628
+ __classPrivateFieldSet(this, _DiffFile_splitHunksLines, Object.assign(Object.assign({}, __classPrivateFieldGet(this, _DiffFile_splitHunksLines, "f")), { [__classPrivateFieldGet(this, _DiffFile_splitRightLines, "f").length]: lastHunk }), "f");
2812
1629
  hideStart = Infinity;
2813
1630
  }
2814
- this.splitLineLength = this.#splitRightLines.length;
2815
- this.#hasBuildSplit = true;
1631
+ this.splitLineLength = __classPrivateFieldGet(this, _DiffFile_splitRightLines, "f").length;
1632
+ __classPrivateFieldSet(this, _DiffFile_hasBuildSplit, true, "f");
2816
1633
  this.notifyAll();
2817
1634
  }
2818
1635
  buildUnifiedDiffLines() {
2819
- if (this.#hasBuildUnified)
1636
+ var _a, _b, _c, _d, _e, _f, _g;
1637
+ if (__classPrivateFieldGet(this, _DiffFile_hasBuildUnified, "f"))
2820
1638
  return;
2821
1639
  let oldFileLineNumber = 1;
2822
1640
  let newFileLineNumber = 1;
2823
1641
  let prevIsHidden = false;
2824
1642
  let hideStart = Infinity;
2825
- const maxOldFileLineNumber = this.#oldFileResult?.maxLineNumber || 0;
2826
- const maxNewFileLineNumber = this.#newFileResult?.maxLineNumber || 0;
1643
+ const maxOldFileLineNumber = ((_a = __classPrivateFieldGet(this, _DiffFile_oldFileResult, "f")) === null || _a === void 0 ? void 0 : _a.maxLineNumber) || 0;
1644
+ const maxNewFileLineNumber = ((_b = __classPrivateFieldGet(this, _DiffFile_newFileResult, "f")) === null || _b === void 0 ? void 0 : _b.maxLineNumber) || 0;
2827
1645
  while (oldFileLineNumber <= maxOldFileLineNumber || newFileLineNumber <= maxNewFileLineNumber) {
2828
- const oldRawLine = this.#getOldRawLine(oldFileLineNumber);
2829
- const oldDiffLine = this.#getOldDiffLine(oldFileLineNumber);
2830
- const newRawLine = this.#getNewRawLine(newFileLineNumber);
2831
- const newDiffLine = this.#getNewDiffLine(newFileLineNumber);
2832
- const oldLineHasChange = oldDiffLine?.isIncludeableLine();
2833
- const newLineHasChange = newDiffLine?.isIncludeableLine();
2834
- const len = this.#unifiedLines.length;
1646
+ const oldRawLine = __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getOldRawLine).call(this, oldFileLineNumber);
1647
+ const oldDiffLine = __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getOldDiffLine).call(this, oldFileLineNumber);
1648
+ const newRawLine = __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getNewRawLine).call(this, newFileLineNumber);
1649
+ const newDiffLine = __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getNewDiffLine).call(this, newFileLineNumber);
1650
+ const oldLineHasChange = oldDiffLine === null || oldDiffLine === void 0 ? void 0 : oldDiffLine.isIncludeableLine();
1651
+ const newLineHasChange = newDiffLine === null || newDiffLine === void 0 ? void 0 : newDiffLine.isIncludeableLine();
1652
+ const len = __classPrivateFieldGet(this, _DiffFile_unifiedLines, "f").length;
2835
1653
  const isHidden = !oldDiffLine && !newDiffLine;
2836
- if ((oldDiffLine && !newDiffLine && oldDiffLine.newLineNumber && oldDiffLine.newLineNumber > newFileLineNumber) ||
2837
- (!oldDiffLine && newDiffLine && newDiffLine.oldLineNumber && newDiffLine.oldLineNumber > oldFileLineNumber)) {
2838
- if (this.#composeByDiff) {
2839
- oldDiffLine && newFileLineNumber++;
2840
- newDiffLine && oldFileLineNumber++;
1654
+ if (oldDiffLine && !newDiffLine) {
1655
+ if (oldDiffLine.newLineNumber && oldDiffLine.newLineNumber > newFileLineNumber) {
1656
+ newFileLineNumber++;
2841
1657
  continue;
2842
1658
  }
2843
- else {
2844
- {
2845
- console.error("some error happen for generate diff line!");
2846
- }
1659
+ if (oldDiffLine.newLineNumber === null || oldDiffLine.newLineNumber === undefined) {
1660
+ newFileLineNumber++;
1661
+ }
1662
+ }
1663
+ if (newDiffLine && !oldDiffLine) {
1664
+ if (newDiffLine.oldLineNumber && newDiffLine.oldLineNumber > oldFileLineNumber) {
1665
+ oldFileLineNumber++;
1666
+ continue;
1667
+ }
1668
+ if (newDiffLine.oldLineNumber === null || newDiffLine.oldLineNumber === undefined) {
1669
+ oldFileLineNumber++;
2847
1670
  }
2848
1671
  }
2849
1672
  if (!oldRawLine && !newRawLine && !newDiffLine && !oldDiffLine)
2850
1673
  break;
1674
+ if (!oldDiffLine && !newDiffLine) {
1675
+ 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])) {
1676
+ oldFileLineNumber++;
1677
+ newFileLineNumber++;
1678
+ continue;
1679
+ }
1680
+ if (!oldRawLine && ((_e = __classPrivateFieldGet(this, _DiffFile_newFilePlaceholderLines, "f")) === null || _e === void 0 ? void 0 : _e[newFileLineNumber])) {
1681
+ newFileLineNumber++;
1682
+ continue;
1683
+ }
1684
+ if (!newRawLine && ((_f = __classPrivateFieldGet(this, _DiffFile_oldFilePlaceholderLines, "f")) === null || _f === void 0 ? void 0 : _f[oldFileLineNumber])) {
1685
+ oldFileLineNumber++;
1686
+ continue;
1687
+ }
1688
+ }
2851
1689
  if (!oldLineHasChange && !newLineHasChange) {
2852
- this.#unifiedLines.push({
1690
+ __classPrivateFieldGet(this, _DiffFile_unifiedLines, "f").push({
2853
1691
  oldLineNumber: oldFileLineNumber++,
2854
1692
  newLineNumber: newFileLineNumber++,
2855
1693
  value: newRawLine,
@@ -2859,7 +1697,7 @@ class DiffFile {
2859
1697
  });
2860
1698
  }
2861
1699
  else if (oldLineHasChange) {
2862
- this.#unifiedLines.push({
1700
+ __classPrivateFieldGet(this, _DiffFile_unifiedLines, "f").push({
2863
1701
  oldLineNumber: oldFileLineNumber++,
2864
1702
  value: oldRawLine,
2865
1703
  diff: oldDiffLine,
@@ -2868,7 +1706,7 @@ class DiffFile {
2868
1706
  });
2869
1707
  }
2870
1708
  else if (newLineHasChange) {
2871
- this.#unifiedLines.push({
1709
+ __classPrivateFieldGet(this, _DiffFile_unifiedLines, "f").push({
2872
1710
  newLineNumber: newFileLineNumber++,
2873
1711
  value: newRawLine,
2874
1712
  diff: newDiffLine,
@@ -2879,41 +1717,33 @@ class DiffFile {
2879
1717
  if (!prevIsHidden && isHidden) {
2880
1718
  hideStart = len;
2881
1719
  }
1720
+ if (isHidden) {
1721
+ this.hasCollapsed = true;
1722
+ }
2882
1723
  prevIsHidden = isHidden;
2883
1724
  if (oldDiffLine && newDiffLine && !oldLineHasChange && !newLineHasChange) {
2884
1725
  const current = newDiffLine;
2885
- const previous = current.index ? this.#diffLines?.[current.index - 1] : undefined;
2886
- if (previous && previous.type === DiffLineType.Hunk) {
1726
+ const previous = current.index ? (_g = __classPrivateFieldGet(this, _DiffFile_diffLines, "f")) === null || _g === void 0 ? void 0 : _g[current.index - 1] : undefined;
1727
+ if (previous && previous.type === exports.DiffLineType.Hunk) {
2887
1728
  const typedPrevious = previous;
2888
1729
  if (Number.isFinite(hideStart)) {
2889
- typedPrevious.unifiedInfo = {
2890
- ...typedPrevious.hunkInfo,
2891
- startHiddenIndex: hideStart,
2892
- endHiddenIndex: len,
2893
- plainText: typedPrevious.text,
2894
- _startHiddenIndex: hideStart,
2895
- _endHiddenIndex: len,
2896
- _plainText: typedPrevious.text,
2897
- };
1730
+ typedPrevious.unifiedInfo = Object.assign(Object.assign({}, typedPrevious.hunkInfo), { startHiddenIndex: hideStart, endHiddenIndex: len, plainText: typedPrevious.text, _startHiddenIndex: hideStart, _endHiddenIndex: len, _plainText: typedPrevious.text });
2898
1731
  hideStart = Infinity;
2899
1732
  }
2900
- this.#unifiedHunksLines = {
2901
- ...this.#unifiedHunksLines,
2902
- [len]: typedPrevious,
2903
- };
1733
+ __classPrivateFieldSet(this, _DiffFile_unifiedHunksLines, Object.assign(Object.assign({}, __classPrivateFieldGet(this, _DiffFile_unifiedHunksLines, "f")), { [len]: typedPrevious }), "f");
2904
1734
  }
2905
1735
  }
2906
1736
  }
2907
1737
  // have last hunk
2908
1738
  if (Number.isFinite(hideStart)) {
2909
- const lastDiff = new DiffLine("", DiffLineType.Hunk, null, null, null);
1739
+ const lastDiff = new DiffLine("", exports.DiffLineType.Hunk, null, null, null);
2910
1740
  const lastHunk = lastDiff;
2911
1741
  lastHunk.isLast = true;
2912
1742
  lastHunk.unifiedInfo = {
2913
1743
  startHiddenIndex: hideStart,
2914
- endHiddenIndex: this.#unifiedLines.length,
1744
+ endHiddenIndex: __classPrivateFieldGet(this, _DiffFile_unifiedLines, "f").length,
2915
1745
  _startHiddenIndex: hideStart,
2916
- _endHiddenIndex: this.#unifiedLines.length,
1746
+ _endHiddenIndex: __classPrivateFieldGet(this, _DiffFile_unifiedLines, "f").length,
2917
1747
  // just for placeholder
2918
1748
  plainText: "",
2919
1749
  oldStartIndex: 0,
@@ -2926,476 +1756,312 @@ class DiffFile {
2926
1756
  _oldLength: 0,
2927
1757
  _newLength: 0,
2928
1758
  };
2929
- this.#unifiedHunksLines = {
2930
- ...this.#unifiedHunksLines,
2931
- [this.#unifiedLines.length]: lastHunk,
2932
- };
1759
+ __classPrivateFieldSet(this, _DiffFile_unifiedHunksLines, Object.assign(Object.assign({}, __classPrivateFieldGet(this, _DiffFile_unifiedHunksLines, "f")), { [__classPrivateFieldGet(this, _DiffFile_unifiedLines, "f").length]: lastHunk }), "f");
2933
1760
  hideStart = Infinity;
2934
1761
  }
2935
- this.unifiedLineLength = this.#unifiedLines.length;
2936
- this.#hasBuildUnified = true;
1762
+ this.unifiedLineLength = __classPrivateFieldGet(this, _DiffFile_unifiedLines, "f").length;
1763
+ __classPrivateFieldSet(this, _DiffFile_hasBuildUnified, true, "f");
2937
1764
  this.notifyAll();
2938
1765
  }
2939
- getSplitLeftLine = (index) => {
2940
- return this.#splitLeftLines[index];
2941
- };
2942
- getSplitRightLine = (index) => {
2943
- return this.#splitRightLines[index];
2944
- };
2945
- getSplitHunkLine = (index) => {
2946
- return this.#splitHunksLines?.[index];
2947
- };
2948
- onSplitHunkExpand = (dir, index, needTrigger = true) => {
2949
- const current = this.#splitHunksLines?.[index];
2950
- if (!current || !current.splitInfo)
2951
- return;
2952
- if (dir === "all") {
2953
- for (let i = current.splitInfo.startHiddenIndex; i < current.splitInfo.endHiddenIndex; i++) {
2954
- const leftLine = this.#splitLeftLines[i];
2955
- const rightLine = this.#splitRightLines[i];
2956
- if (leftLine?.isHidden)
2957
- leftLine.isHidden = false;
2958
- if (rightLine?.isHidden)
2959
- rightLine.isHidden = false;
2960
- }
2961
- current.splitInfo = {
2962
- ...current.splitInfo,
2963
- ...current.hunkInfo,
2964
- plainText: current.text,
2965
- startHiddenIndex: current.splitInfo.endHiddenIndex,
2966
- };
2967
- }
2968
- else if (dir === "down") {
2969
- for (let i = current.splitInfo.startHiddenIndex; i < current.splitInfo.startHiddenIndex + composeLen; i++) {
2970
- const leftLine = this.#splitLeftLines[i];
2971
- const rightLine = this.#splitRightLines[i];
2972
- if (leftLine?.isHidden)
2973
- leftLine.isHidden = false;
2974
- if (rightLine?.isHidden)
2975
- rightLine.isHidden = false;
2976
- }
2977
- if (current.isLast) {
2978
- current.splitInfo = {
2979
- ...current.splitInfo,
2980
- startHiddenIndex: current.splitInfo.startHiddenIndex + composeLen,
2981
- };
1766
+ }
1767
+ _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_id = new WeakMap(), _DiffFile_clonedInstance = new WeakMap(), _DiffFile_instances = new WeakSet(), _DiffFile_doDiff = function _DiffFile_doDiff() {
1768
+ if (!this._diffList)
1769
+ return;
1770
+ __classPrivateFieldSet(this, _DiffFile_diffListResults, this._diffList.map((s) => parseInstance.parse(s)), "f");
1771
+ }, _DiffFile_doFile = function _DiffFile_doFile() {
1772
+ if (!this._oldFileContent && !this._newFileContent)
1773
+ return;
1774
+ if (this._oldFileContent) {
1775
+ __classPrivateFieldSet(this, _DiffFile_oldFileResult, getFile(this._oldFileContent, this._oldFileLang, this._oldFileName), "f");
1776
+ }
1777
+ if (this._newFileContent) {
1778
+ __classPrivateFieldSet(this, _DiffFile_newFileResult, getFile(this._newFileContent, this._newFileLang, this._newFileName), "f");
1779
+ }
1780
+ }, _DiffFile_composeRaw = function _DiffFile_composeRaw() {
1781
+ var _a, _b, _c, _d;
1782
+ (_a = __classPrivateFieldGet(this, _DiffFile_oldFileResult, "f")) === null || _a === void 0 ? void 0 : _a.doRaw();
1783
+ __classPrivateFieldSet(this, _DiffFile_oldFileLines, (_b = __classPrivateFieldGet(this, _DiffFile_oldFileResult, "f")) === null || _b === void 0 ? void 0 : _b.rawFile, "f");
1784
+ (_c = __classPrivateFieldGet(this, _DiffFile_newFileResult, "f")) === null || _c === void 0 ? void 0 : _c.doRaw();
1785
+ __classPrivateFieldSet(this, _DiffFile_newFileLines, (_d = __classPrivateFieldGet(this, _DiffFile_newFileResult, "f")) === null || _d === void 0 ? void 0 : _d.rawFile, "f");
1786
+ }, _DiffFile_composeFile = function _DiffFile_composeFile() {
1787
+ if (this._oldFileContent && this._newFileContent)
1788
+ return;
1789
+ const oldFilePlaceholderLines = {};
1790
+ const newFilePlaceholderLines = {};
1791
+ // all of the file content not exist, try to use diff result to compose
1792
+ if (!this._oldFileContent && !this._newFileContent) {
1793
+ let newLineNumber = 1;
1794
+ let oldLineNumber = 1;
1795
+ let oldFileContent = "";
1796
+ let newFileContent = "";
1797
+ while (oldLineNumber <= this.diffLineLength) {
1798
+ const index = oldLineNumber++;
1799
+ const diffLine = __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getOldDiffLine).call(this, index);
1800
+ if (diffLine) {
1801
+ oldFileContent += diffLine.text;
2982
1802
  }
2983
1803
  else {
2984
- current.splitInfo = {
2985
- ...current.splitInfo,
2986
- startHiddenIndex: current.splitInfo.startHiddenIndex + composeLen,
2987
- plainText: `@@ -${current.splitInfo.oldStartIndex},${current.splitInfo.oldLength} +${current.splitInfo.newStartIndex},${current.splitInfo.newLength}`,
2988
- };
1804
+ // empty line for placeholder
1805
+ oldFileContent += "\n";
1806
+ oldFilePlaceholderLines[index] = true;
2989
1807
  }
2990
1808
  }
2991
- else {
2992
- if (current.isLast) {
2993
- console.error("the last hunk can not expand up!");
2994
- return;
1809
+ while (newLineNumber <= this.diffLineLength) {
1810
+ const index = newLineNumber++;
1811
+ const diffLine = __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getNewDiffLine).call(this, index);
1812
+ if (diffLine) {
1813
+ newFileContent += diffLine.text;
2995
1814
  }
2996
- for (let i = current.splitInfo.endHiddenIndex - composeLen; i < current.splitInfo.endHiddenIndex; i++) {
2997
- const leftLine = this.#splitLeftLines[i];
2998
- const rightLine = this.#splitRightLines[i];
2999
- if (leftLine?.isHidden)
3000
- leftLine.isHidden = false;
3001
- if (rightLine?.isHidden)
3002
- rightLine.isHidden = false;
1815
+ else {
1816
+ // empty line for placeholder
1817
+ newFileContent += "\n";
1818
+ newFilePlaceholderLines[index] = true;
3003
1819
  }
3004
- const oldStartIndex = current.splitInfo.oldStartIndex - composeLen;
3005
- const oldLength = current.splitInfo.oldLength + composeLen;
3006
- const newStartIndex = current.splitInfo.newStartIndex - composeLen;
3007
- const newLength = current.splitInfo.newLength + composeLen;
3008
- current.splitInfo = {
3009
- ...current.splitInfo,
3010
- endHiddenIndex: current.splitInfo.endHiddenIndex - composeLen,
3011
- oldStartIndex,
3012
- oldLength,
3013
- newStartIndex,
3014
- newLength,
3015
- plainText: `@@ -${oldStartIndex},${oldLength} +${newStartIndex},${newLength}`,
3016
- };
3017
- delete this.#splitHunksLines?.[index];
3018
- this.#splitHunksLines[current.splitInfo.endHiddenIndex] = current;
3019
1820
  }
3020
- needTrigger && this.notifyAll();
3021
- };
3022
- getUnifiedLine = (index) => {
3023
- return this.#unifiedLines[index];
3024
- };
3025
- getUnifiedHunkLine = (index) => {
3026
- return this.#unifiedHunksLines?.[index];
3027
- };
3028
- onUnifiedHunkExpand = (dir, index, needTrigger = true) => {
3029
- const current = this.#unifiedHunksLines?.[index];
3030
- if (!current || !current.unifiedInfo)
1821
+ if (oldFileContent === newFileContent)
3031
1822
  return;
3032
- if (dir === "all") {
3033
- for (let i = current.unifiedInfo.startHiddenIndex; i < current.unifiedInfo.endHiddenIndex; i++) {
3034
- const unifiedLine = this.#unifiedLines?.[i];
3035
- if (unifiedLine?.isHidden) {
3036
- unifiedLine.isHidden = false;
3037
- }
3038
- }
3039
- current.unifiedInfo = {
3040
- ...current.unifiedInfo,
3041
- ...current.hunkInfo,
3042
- plainText: current.text,
3043
- startHiddenIndex: current.unifiedInfo.endHiddenIndex,
3044
- };
3045
- }
3046
- else if (dir === "down") {
3047
- for (let i = current.unifiedInfo.startHiddenIndex; i < current.unifiedInfo.startHiddenIndex + composeLen; i++) {
3048
- const unifiedLine = this.#unifiedLines[i];
3049
- if (unifiedLine?.isHidden)
3050
- unifiedLine.isHidden = false;
3051
- }
3052
- if (current.isLast) {
3053
- current.unifiedInfo = {
3054
- ...current.unifiedInfo,
3055
- startHiddenIndex: current.unifiedInfo.startHiddenIndex + composeLen,
3056
- };
1823
+ this._oldFileContent = oldFileContent;
1824
+ this._newFileContent = newFileContent;
1825
+ __classPrivateFieldSet(this, _DiffFile_oldFileResult, getFile(this._oldFileContent, this._oldFileLang, this._oldFileName), "f");
1826
+ __classPrivateFieldSet(this, _DiffFile_newFileResult, getFile(this._newFileContent, this._newFileLang, this._newFileName), "f");
1827
+ __classPrivateFieldSet(this, _DiffFile_oldFilePlaceholderLines, oldFilePlaceholderLines, "f");
1828
+ __classPrivateFieldSet(this, _DiffFile_newFilePlaceholderLines, newFilePlaceholderLines, "f");
1829
+ // all of the file just compose by diff, so we can not do the expand action
1830
+ __classPrivateFieldSet(this, _DiffFile_composeByDiff, true, "f");
1831
+ }
1832
+ else if (__classPrivateFieldGet(this, _DiffFile_oldFileResult, "f")) {
1833
+ let newLineNumber = 1;
1834
+ let oldLineNumber = 1;
1835
+ let newFileContent = "";
1836
+ while (oldLineNumber <= __classPrivateFieldGet(this, _DiffFile_oldFileResult, "f").maxLineNumber) {
1837
+ const newDiffLine = __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getNewDiffLine).call(this, newLineNumber++);
1838
+ if (newDiffLine) {
1839
+ newFileContent += newDiffLine.text;
1840
+ oldLineNumber = newDiffLine.oldLineNumber ? newDiffLine.oldLineNumber + 1 : oldLineNumber;
3057
1841
  }
3058
1842
  else {
3059
- current.unifiedInfo = {
3060
- ...current.unifiedInfo,
3061
- startHiddenIndex: current.unifiedInfo.startHiddenIndex + composeLen,
3062
- plainText: `@@ -${current.unifiedInfo.oldStartIndex},${current.unifiedInfo.oldLength} +${current.unifiedInfo.newStartIndex},${current.unifiedInfo.newLength}`,
3063
- };
1843
+ newFileContent += __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getOldRawLine).call(this, oldLineNumber++);
3064
1844
  }
3065
1845
  }
3066
- else {
3067
- if (current.isLast) {
3068
- console.error("the last hunk can not expand up!");
3069
- return;
1846
+ if (newFileContent === this._oldFileContent)
1847
+ return;
1848
+ this._newFileContent = newFileContent;
1849
+ __classPrivateFieldSet(this, _DiffFile_newFileResult, getFile(this._newFileContent, this._newFileLang, this._newFileName), "f");
1850
+ }
1851
+ else if (__classPrivateFieldGet(this, _DiffFile_newFileResult, "f")) {
1852
+ let oldLineNumber = 1;
1853
+ let newLineNumber = 1;
1854
+ let oldFileContent = "";
1855
+ while (newLineNumber <= __classPrivateFieldGet(this, _DiffFile_newFileResult, "f").maxLineNumber) {
1856
+ const oldDiffLine = __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getOldDiffLine).call(this, oldLineNumber++);
1857
+ if (oldDiffLine) {
1858
+ oldFileContent += oldDiffLine.text;
1859
+ newLineNumber = oldDiffLine.newLineNumber ? oldDiffLine.newLineNumber + 1 : newLineNumber;
3070
1860
  }
3071
- for (let i = current.unifiedInfo.endHiddenIndex - composeLen; i < current.unifiedInfo.endHiddenIndex; i++) {
3072
- const unifiedLine = this.#unifiedLines[i];
3073
- if (unifiedLine?.isHidden)
3074
- unifiedLine.isHidden = false;
1861
+ else {
1862
+ oldFileContent += __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_getNewRawLine).call(this, newLineNumber++);
3075
1863
  }
3076
- const oldStartIndex = current.unifiedInfo.oldStartIndex - composeLen;
3077
- const oldLength = current.unifiedInfo.oldLength + composeLen;
3078
- const newStartIndex = current.unifiedInfo.newStartIndex - composeLen;
3079
- const newLength = current.unifiedInfo.newLength + composeLen;
3080
- current.unifiedInfo = {
3081
- ...current.unifiedInfo,
3082
- endHiddenIndex: current.unifiedInfo.endHiddenIndex - composeLen,
3083
- oldStartIndex,
3084
- oldLength,
3085
- newStartIndex,
3086
- newLength,
3087
- plainText: `@@ -${oldStartIndex},${oldLength} +${newStartIndex},${newLength}`,
3088
- };
3089
- delete this.#unifiedHunksLines?.[index];
3090
- this.#unifiedHunksLines[current.unifiedInfo.endHiddenIndex] = current;
3091
- }
3092
- needTrigger && this.notifyAll();
3093
- };
3094
- onAllExpand = (mode) => {
3095
- if (mode === "split") {
3096
- Object.keys(this.#splitHunksLines || {}).forEach((key) => {
3097
- this.onSplitHunkExpand("all", +key, false);
3098
- });
3099
- }
3100
- else {
3101
- Object.keys(this.#unifiedHunksLines || {}).forEach((key) => {
3102
- this.onUnifiedHunkExpand("all", +key, false);
3103
- });
3104
1864
  }
3105
- this.notifyAll();
3106
- };
3107
- onAllCollapse = (mode) => {
3108
- if (mode === "split") {
3109
- Object.values(this.#splitLeftLines || {}).forEach((item) => {
3110
- if (!item.isHidden && item._isHidden) {
3111
- item.isHidden = item._isHidden;
3112
- }
3113
- });
3114
- Object.values(this.#splitRightLines || {}).forEach((item) => {
3115
- if (!item.isHidden && item._isHidden) {
3116
- item.isHidden = item._isHidden;
1865
+ if (oldFileContent === this._newFileContent)
1866
+ return;
1867
+ this._oldFileContent = oldFileContent;
1868
+ __classPrivateFieldSet(this, _DiffFile_oldFileResult, getFile(this._oldFileContent, this._oldFileLang, this._oldFileName), "f");
1869
+ }
1870
+ __classPrivateFieldGet(this, _DiffFile_instances, "m", _DiffFile_composeRaw).call(this);
1871
+ }, _DiffFile_composeDiff = function _DiffFile_composeDiff() {
1872
+ var _a;
1873
+ if (!((_a = __classPrivateFieldGet(this, _DiffFile_diffListResults, "f")) === null || _a === void 0 ? void 0 : _a.length))
1874
+ return;
1875
+ __classPrivateFieldGet(this, _DiffFile_diffListResults, "f").forEach((item) => {
1876
+ const hunks = item.hunks;
1877
+ hunks.forEach((hunk) => {
1878
+ let additions = [];
1879
+ let deletions = [];
1880
+ hunk.lines.forEach((line) => {
1881
+ if (line.type === exports.DiffLineType.Add) {
1882
+ additions.push(line);
1883
+ }
1884
+ else if (line.type === exports.DiffLineType.Delete) {
1885
+ deletions.push(line);
3117
1886
  }
3118
- });
3119
- Object.values(this.#splitHunksLines || {}).forEach((item) => {
3120
- if (!item.splitInfo)
3121
- return;
3122
- item.splitInfo = {
3123
- ...item.splitInfo,
3124
- oldStartIndex: item.splitInfo._oldStartIndex,
3125
- oldLength: item.splitInfo._oldLength,
3126
- newStartIndex: item.splitInfo._newStartIndex,
3127
- newLength: item.splitInfo._newLength,
3128
- startHiddenIndex: item.splitInfo._startHiddenIndex,
3129
- endHiddenIndex: item.splitInfo._endHiddenIndex,
3130
- plainText: item.splitInfo._plainText,
3131
- };
3132
- });
3133
- Object.keys(this.#splitHunksLines || {}).forEach((key) => {
3134
- const item = this.#splitHunksLines[key];
3135
- if (!item.splitInfo)
3136
- return;
3137
- if (item.splitInfo.endHiddenIndex !== +key) {
3138
- delete this.#splitHunksLines[key];
3139
- this.#splitHunksLines[item.splitInfo.endHiddenIndex] = item;
1887
+ else {
1888
+ getDiffRange(additions, deletions);
1889
+ additions = [];
1890
+ deletions = [];
3140
1891
  }
3141
1892
  });
1893
+ getDiffRange(additions, deletions);
1894
+ });
1895
+ });
1896
+ __classPrivateFieldSet(this, _DiffFile_diffLines, [], "f");
1897
+ const tmp = [];
1898
+ __classPrivateFieldGet(this, _DiffFile_diffListResults, "f").forEach((item) => {
1899
+ item.hunks.forEach((_item) => {
1900
+ tmp.push(..._item.lines);
1901
+ });
1902
+ });
1903
+ __classPrivateFieldSet(this, _DiffFile_diffLines, tmp.map((i, index) => {
1904
+ var _a;
1905
+ const typedI = i;
1906
+ typedI.index = index;
1907
+ if (typedI.type === exports.DiffLineType.Hunk) {
1908
+ const numInfo = (_a = typedI.text.split("@@")) === null || _a === void 0 ? void 0 : _a[1].split(" ").filter(Boolean);
1909
+ const oldNumInfo = (numInfo === null || numInfo === void 0 ? void 0 : numInfo[0]) || "";
1910
+ const newNumInfo = (numInfo === null || numInfo === void 0 ? void 0 : numInfo[1]) || "";
1911
+ const [oldNumStartIndex, oldNumLength] = oldNumInfo.split(",");
1912
+ const [newNumStartIndex, newNumLength] = newNumInfo.split(",");
1913
+ const typedTypeI = typedI;
1914
+ typedTypeI.hunkInfo = {
1915
+ oldStartIndex: -Number(oldNumStartIndex),
1916
+ oldLength: Number(oldNumLength),
1917
+ newStartIndex: +Number(newNumStartIndex),
1918
+ newLength: Number(newNumLength),
1919
+ _oldStartIndex: -Number(oldNumStartIndex),
1920
+ _oldLength: Number(oldNumLength),
1921
+ _newStartIndex: +Number(newNumStartIndex),
1922
+ _newLength: Number(newNumLength),
1923
+ };
3142
1924
  }
3143
- else {
3144
- Object.values(this.#unifiedLines || {}).forEach((item) => {
3145
- if (!item.isHidden && item._isHidden) {
3146
- item.isHidden = item._isHidden;
3147
- }
3148
- });
3149
- Object.values(this.#unifiedHunksLines || {}).forEach((item) => {
3150
- if (!item.unifiedInfo)
3151
- return;
3152
- item.unifiedInfo = {
3153
- ...item.unifiedInfo,
3154
- oldStartIndex: item.unifiedInfo._oldStartIndex,
3155
- oldLength: item.unifiedInfo._oldLength,
3156
- newStartIndex: item.unifiedInfo._newStartIndex,
3157
- newLength: item.unifiedInfo._newLength,
3158
- startHiddenIndex: item.unifiedInfo._startHiddenIndex,
3159
- endHiddenIndex: item.unifiedInfo._endHiddenIndex,
3160
- plainText: item.unifiedInfo._plainText,
3161
- };
3162
- });
3163
- Object.keys(this.#unifiedHunksLines || {}).forEach((key) => {
3164
- const item = this.#unifiedHunksLines[key];
3165
- if (!item.unifiedInfo)
3166
- return;
3167
- if (item.unifiedInfo.endHiddenIndex !== +key) {
3168
- delete this.#unifiedHunksLines[key];
3169
- this.#unifiedHunksLines[item.unifiedInfo.endHiddenIndex] = item;
3170
- }
3171
- });
1925
+ return typedI;
1926
+ }), "f");
1927
+ // this.#diffLines = this.#diffListResults
1928
+ // .reduce<DiffLine[]>((p, c) => p.concat(...c.hunks.reduce<DiffLine[]>((_p, _c) => _p.concat(..._c.lines), [])), [])
1929
+ // .map<DiffLineItem>((i, index) => {
1930
+ // const typedI = i as DiffLineItem;
1931
+ // typedI.index = index;
1932
+ // if (typedI.type === DiffLineType.Hunk) {
1933
+ // const numInfo = typedI.text.split("@@")?.[1].split(" ").filter(Boolean);
1934
+ // const oldNumInfo = numInfo?.[0] || "";
1935
+ // const newNumInfo = numInfo?.[1] || "";
1936
+ // const [oldNumStartIndex, oldNumLength] = oldNumInfo.split(",");
1937
+ // const [newNumStartIndex, newNumLength] = newNumInfo.split(",");
1938
+ // const typedTypeI = typedI as DiffHunkItem;
1939
+ // typedTypeI.hunkInfo = {
1940
+ // oldStartIndex: -Number(oldNumStartIndex),
1941
+ // oldLength: Number(oldNumLength),
1942
+ // newStartIndex: +Number(newNumStartIndex),
1943
+ // newLength: Number(newNumLength),
1944
+ // };
1945
+ // }
1946
+ // return typedI;
1947
+ // });
1948
+ __classPrivateFieldSet(this, _DiffFile_oldFileDiffLines, {}, "f");
1949
+ __classPrivateFieldGet(this, _DiffFile_diffLines, "f").forEach((item) => {
1950
+ if (item.oldLineNumber) {
1951
+ this.diffLineLength = Math.max(this.diffLineLength, item.oldLineNumber);
1952
+ __classPrivateFieldGet(this, _DiffFile_oldFileDiffLines, "f")[item.oldLineNumber] = item;
3172
1953
  }
3173
- this.notifyAll();
3174
- };
3175
- getOldSyntaxLine = (lineNumber) => {
3176
- return this.#oldFileSyntaxLines?.[lineNumber];
3177
- };
3178
- getNewSyntaxLine = (lineNumber) => {
3179
- return this.#newFileSyntaxLines?.[lineNumber];
3180
- };
3181
- subscribe = (listener) => {
3182
- this.#listeners.push(listener);
3183
- return () => {
3184
- this.#listeners.filter((i) => i !== listener);
3185
- };
3186
- };
3187
- notifyAll = (skipSyncExternal) => {
3188
- this.#updateCount++;
3189
- this.#listeners.forEach((f) => {
3190
- if (skipSyncExternal && f.isSyncExternal) {
3191
- return;
3192
- }
3193
- f();
3194
- });
3195
- };
3196
- getUpdateCount = () => this.#updateCount;
3197
- getExpandEnabled = () => !this.#composeByDiff;
3198
- getBundle = () => {
3199
- // common
3200
- const hasInitRaw = this.#hasInitRaw;
3201
- const hasInitSyntax = this.#hasInitSyntax;
3202
- const hasBuildSplit = this.#hasBuildSplit;
3203
- const hasBuildUnified = this.#hasBuildUnified;
3204
- const oldFileLines = this.#oldFileLines;
3205
- const oldFileDiffLines = this.#oldFileDiffLines;
3206
- const oldFileSyntaxLines = this.#oldFileSyntaxLines;
3207
- const newFileLines = this.#newFileLines;
3208
- const newFileDiffLines = this.#newFileDiffLines;
3209
- const newFileSyntaxLines = this.#newFileSyntaxLines;
3210
- const splitLineLength = this.splitLineLength;
3211
- const unifiedLineLength = this.unifiedLineLength;
3212
- const composeByDiff = this.#composeByDiff;
3213
- // split
3214
- const splitLeftLines = this.#splitLeftLines;
3215
- const splitRightLines = this.#splitRightLines;
3216
- const splitHunkLines = this.#splitHunksLines;
3217
- // unified
3218
- const unifiedLines = this.#unifiedLines;
3219
- const unifiedHunkLines = this.#unifiedHunksLines;
3220
- const version = this._version_;
3221
- return {
3222
- hasInitRaw,
3223
- hasInitSyntax,
3224
- hasBuildSplit,
3225
- hasBuildUnified,
3226
- oldFileLines,
3227
- oldFileDiffLines,
3228
- oldFileSyntaxLines,
3229
- newFileLines,
3230
- newFileDiffLines,
3231
- newFileSyntaxLines,
3232
- splitLineLength,
3233
- unifiedLineLength,
3234
- splitLeftLines,
3235
- splitRightLines,
3236
- splitHunkLines,
3237
- unifiedLines,
3238
- unifiedHunkLines,
3239
- composeByDiff,
3240
- version
3241
- };
3242
- };
3243
- mergeBundle = (data) => {
3244
- this.#hasInitRaw = data.hasInitRaw;
3245
- this.#hasInitSyntax = data.hasInitSyntax;
3246
- this.#hasBuildSplit = data.hasBuildSplit;
3247
- this.#hasBuildUnified = data.hasBuildUnified;
3248
- this.#composeByDiff = data.composeByDiff;
3249
- this.#oldFileLines = data.oldFileLines;
3250
- this.#oldFileDiffLines = data.oldFileDiffLines;
3251
- this.#oldFileSyntaxLines = data.oldFileSyntaxLines;
3252
- this.#newFileLines = data.newFileLines;
3253
- this.#newFileDiffLines = data.newFileDiffLines;
3254
- this.#newFileSyntaxLines = data.newFileSyntaxLines;
3255
- this.splitLineLength = data.splitLineLength;
3256
- this.unifiedLineLength = data.unifiedLineLength;
3257
- this.#splitLeftLines = data.splitLeftLines;
3258
- this.#splitRightLines = data.splitRightLines;
3259
- this.#splitHunksLines = data.splitHunkLines;
3260
- this.#unifiedLines = data.unifiedLines;
3261
- this.#unifiedHunksLines = data.unifiedHunkLines;
3262
- if (this._version_ !== data.version) {
3263
- console.error('the version of the `diffInstance` is not match, some error may happen!');
1954
+ });
1955
+ __classPrivateFieldSet(this, _DiffFile_newFileDiffLines, {}, "f");
1956
+ __classPrivateFieldGet(this, _DiffFile_diffLines, "f").forEach((item) => {
1957
+ if (item.newLineNumber) {
1958
+ this.diffLineLength = Math.max(this.diffLineLength, item.newLineNumber);
1959
+ __classPrivateFieldGet(this, _DiffFile_newFileDiffLines, "f")[item.newLineNumber] = item;
3264
1960
  }
3265
- this.notifyAll();
3266
- };
3267
- _addClonedInstance = (instance) => {
3268
- const updateFunc = () => {
3269
- this._notifyOthers(instance);
3270
- };
3271
- updateFunc.isSyncExternal = true;
3272
- const unsubscribe = instance.subscribe(updateFunc);
3273
- this.#clonedInstance.set(instance, unsubscribe);
3274
- };
3275
- _notifyOthers = (instance) => {
3276
- this.#clonedInstance.forEach((_, i) => {
3277
- if (i !== instance) {
3278
- i.notifyAll(true);
3279
- }
3280
- });
3281
- };
3282
- _delClonedInstance = (instance) => {
3283
- const unsubscribe = this.#clonedInstance.get(instance);
3284
- unsubscribe && unsubscribe();
3285
- this.#clonedInstance.delete(instance);
3286
- };
3287
- _getFullBundle = () => {
3288
- const bundle = this.getBundle();
3289
- const oldFileResult = this.#oldFileResult;
3290
- const newFileResult = this.#newFileResult;
3291
- const diffLines = this.#diffLines;
3292
- const diffListResults = this.#diffListResults;
3293
- return {
3294
- ...bundle,
3295
- oldFileResult,
3296
- newFileResult,
3297
- diffLines,
3298
- diffListResults,
3299
- };
3300
- };
3301
- _mergeFullBundle = (data) => {
3302
- this.mergeBundle(data);
3303
- this.#oldFileResult = data.oldFileResult;
3304
- this.#newFileResult = data.newFileResult;
3305
- this.#diffLines = data.diffLines;
3306
- this.#diffListResults = data.diffListResults;
3307
- };
3308
- _destroy = () => {
3309
- this.clearId();
3310
- this.#listeners.splice(0, this.#listeners.length);
3311
- this.#clonedInstance.forEach((v) => v());
3312
- this.#clonedInstance.clear();
3313
- };
3314
- clear = () => {
3315
- this._destroy();
3316
- this.#oldFileResult = null;
3317
- this.#newFileResult = null;
3318
- this.#diffLines = null;
3319
- this.#diffListResults = null;
3320
- this.#newFileDiffLines = null;
3321
- this.#oldFileDiffLines = null;
3322
- this.#newFileLines = null;
3323
- this.#oldFileLines = null;
3324
- this.#newFileSyntaxLines = null;
3325
- this.#oldFileSyntaxLines = null;
3326
- this.#splitHunksLines = null;
3327
- this.#splitLeftLines = null;
3328
- this.#splitRightLines = null;
3329
- this.#unifiedHunksLines = null;
3330
- this.#unifiedLines = null;
3331
- };
3332
- }
1961
+ });
1962
+ }, _DiffFile_composeSyntax = function _DiffFile_composeSyntax({ autoDetectLang, registerHighlighter, }) {
1963
+ var _a, _b, _c, _d;
1964
+ (_a = __classPrivateFieldGet(this, _DiffFile_oldFileResult, "f")) === null || _a === void 0 ? void 0 : _a.doSyntax({ autoDetectLang, registerHighlighter });
1965
+ __classPrivateFieldSet(this, _DiffFile_oldFileSyntaxLines, (_b = __classPrivateFieldGet(this, _DiffFile_oldFileResult, "f")) === null || _b === void 0 ? void 0 : _b.syntaxFile, "f");
1966
+ (_c = __classPrivateFieldGet(this, _DiffFile_newFileResult, "f")) === null || _c === void 0 ? void 0 : _c.doSyntax({ autoDetectLang, registerHighlighter });
1967
+ __classPrivateFieldSet(this, _DiffFile_newFileSyntaxLines, (_d = __classPrivateFieldGet(this, _DiffFile_newFileResult, "f")) === null || _d === void 0 ? void 0 : _d.syntaxFile, "f");
1968
+ }, _DiffFile_getOldDiffLine = function _DiffFile_getOldDiffLine(lineNumber) {
1969
+ var _a;
1970
+ if (!lineNumber)
1971
+ return;
1972
+ return (_a = __classPrivateFieldGet(this, _DiffFile_oldFileDiffLines, "f")) === null || _a === void 0 ? void 0 : _a[lineNumber];
1973
+ }, _DiffFile_getNewDiffLine = function _DiffFile_getNewDiffLine(lineNumber) {
1974
+ var _a;
1975
+ if (!lineNumber)
1976
+ return;
1977
+ return (_a = __classPrivateFieldGet(this, _DiffFile_newFileDiffLines, "f")) === null || _a === void 0 ? void 0 : _a[lineNumber];
1978
+ }, _DiffFile_getOldRawLine = function _DiffFile_getOldRawLine(lineNumber) {
1979
+ var _a;
1980
+ return (_a = __classPrivateFieldGet(this, _DiffFile_oldFileLines, "f")) === null || _a === void 0 ? void 0 : _a[lineNumber];
1981
+ }, _DiffFile_getNewRawLine = function _DiffFile_getNewRawLine(lineNumber) {
1982
+ var _a;
1983
+ return (_a = __classPrivateFieldGet(this, _DiffFile_newFileLines, "f")) === null || _a === void 0 ? void 0 : _a[lineNumber];
1984
+ };
3333
1985
 
3334
- var DiffFileLineType;
1986
+ exports.DiffFileLineType = void 0;
3335
1987
  (function (DiffFileLineType) {
3336
1988
  DiffFileLineType[DiffFileLineType["hunk"] = 1] = "hunk";
3337
1989
  DiffFileLineType[DiffFileLineType["content"] = 2] = "content";
3338
1990
  DiffFileLineType[DiffFileLineType["widget"] = 3] = "widget";
3339
1991
  DiffFileLineType[DiffFileLineType["extend"] = 4] = "extend";
3340
- })(DiffFileLineType || (DiffFileLineType = {}));
1992
+ })(exports.DiffFileLineType || (exports.DiffFileLineType = {}));
3341
1993
  const getSplitLines = (diffFile, options) => {
3342
1994
  const splitLineLength = diffFile.splitLineLength;
3343
1995
  const splitLines = [];
3344
1996
  numIterator(splitLineLength, (index) => {
1997
+ var _a, _b;
3345
1998
  const hunkLine = diffFile.getSplitHunkLine(index);
3346
1999
  const splitLeftLine = diffFile.getSplitLeftLine(index);
3347
2000
  const splitRightLine = diffFile.getSplitRightLine(index);
3348
- const widgetLine = options?.hasRenderWidget && options.widgetData?.[index + 1];
3349
- const extendLine = options?.hasRenderExtend && options.extendData?.[index + 1];
2001
+ const widgetLine = (options === null || options === void 0 ? void 0 : options.hasRenderWidget) && ((_a = options.widgetData) === null || _a === void 0 ? void 0 : _a[index + 1]);
2002
+ const extendLine = (options === null || options === void 0 ? void 0 : options.hasRenderExtend) && ((_b = options.extendData) === null || _b === void 0 ? void 0 : _b[index + 1]);
3350
2003
  hunkLine &&
3351
2004
  hunkLine.splitInfo &&
3352
2005
  hunkLine.splitInfo.startHiddenIndex < hunkLine.splitInfo.endHiddenIndex &&
3353
- splitLines.push({ type: DiffFileLineType.hunk, index, lineNumber: index + 1, hunkLine: hunkLine });
3354
- !splitLeftLine?.isHidden &&
3355
- !splitRightLine?.isHidden &&
2006
+ splitLines.push({ type: exports.DiffFileLineType.hunk, index, lineNumber: index + 1, hunkLine: hunkLine });
2007
+ hunkLine &&
2008
+ !hunkLine.splitInfo &&
2009
+ !hunkLine.unifiedInfo &&
2010
+ hunkLine.type === exports.DiffLineType.Hunk &&
2011
+ splitLines.push({ type: exports.DiffFileLineType.hunk, index, lineNumber: index + 1, hunkLine: hunkLine });
2012
+ !(splitLeftLine === null || splitLeftLine === void 0 ? void 0 : splitLeftLine.isHidden) &&
2013
+ !(splitRightLine === null || splitRightLine === void 0 ? void 0 : splitRightLine.isHidden) &&
3356
2014
  splitLines.push({
3357
- type: DiffFileLineType.content,
2015
+ type: exports.DiffFileLineType.content,
3358
2016
  index,
3359
2017
  lineNumber: index + 1,
3360
2018
  splitLine: { left: splitLeftLine, right: splitRightLine },
3361
2019
  });
3362
2020
  widgetLine &&
3363
- splitLines.push({ type: DiffFileLineType.widget, index, lineNumber: index + 1, widgetLine: widgetLine });
2021
+ splitLines.push({ type: exports.DiffFileLineType.widget, index, lineNumber: index + 1, widgetLine: widgetLine });
3364
2022
  extendLine &&
3365
- splitLines.push({ type: DiffFileLineType.extend, index, lineNumber: index + 1, extendLine: extendLine });
2023
+ splitLines.push({ type: exports.DiffFileLineType.extend, index, lineNumber: index + 1, extendLine: extendLine });
3366
2024
  });
3367
2025
  return splitLines;
3368
2026
  };
3369
2027
  const getSplitContentLines = (diffFile) => {
3370
2028
  const lines = getSplitLines(diffFile, {});
3371
- return lines.filter((line) => line.type === DiffFileLineType.content);
2029
+ return lines.filter((line) => line.type === exports.DiffFileLineType.content);
3372
2030
  };
3373
2031
  const getUnifiedLines = (diffFile, options) => {
3374
2032
  const unifiedLineLength = diffFile.unifiedLineLength;
3375
2033
  const unifiedLines = [];
3376
2034
  numIterator(unifiedLineLength, (index) => {
2035
+ var _a, _b;
3377
2036
  const hunkLine = diffFile.getUnifiedHunkLine(index);
3378
2037
  const unifiedLine = diffFile.getUnifiedLine(index);
3379
- const widgetLine = options?.hasRenderWidget && options.widgetData?.[index + 1];
3380
- const extendLine = options?.hasRenderExtend && options.extendData?.[index + 1];
2038
+ const widgetLine = (options === null || options === void 0 ? void 0 : options.hasRenderWidget) && ((_a = options.widgetData) === null || _a === void 0 ? void 0 : _a[index + 1]);
2039
+ const extendLine = (options === null || options === void 0 ? void 0 : options.hasRenderExtend) && ((_b = options.extendData) === null || _b === void 0 ? void 0 : _b[index + 1]);
3381
2040
  hunkLine &&
3382
2041
  hunkLine.unifiedInfo &&
3383
2042
  hunkLine.unifiedInfo.startHiddenIndex < hunkLine.unifiedInfo.endHiddenIndex &&
3384
- unifiedLines.push({ type: DiffFileLineType.hunk, index, lineNumber: index + 1, hunkLine: hunkLine });
2043
+ unifiedLines.push({ type: exports.DiffFileLineType.hunk, index, lineNumber: index + 1, hunkLine: hunkLine });
2044
+ hunkLine &&
2045
+ !hunkLine.splitInfo &&
2046
+ !hunkLine.unifiedInfo &&
2047
+ hunkLine.type === exports.DiffLineType.Hunk &&
2048
+ unifiedLines.push({ type: exports.DiffFileLineType.hunk, index, lineNumber: index + 1, hunkLine: hunkLine });
3385
2049
  !unifiedLine.isHidden &&
3386
- unifiedLines.push({ type: DiffFileLineType.content, index, lineNumber: index + 1, unifiedLine: unifiedLine });
2050
+ unifiedLines.push({ type: exports.DiffFileLineType.content, index, lineNumber: index + 1, unifiedLine: unifiedLine });
3387
2051
  widgetLine &&
3388
- unifiedLines.push({ type: DiffFileLineType.widget, index, lineNumber: index + 1, widgetLine: widgetLine });
2052
+ unifiedLines.push({ type: exports.DiffFileLineType.widget, index, lineNumber: index + 1, widgetLine: widgetLine });
3389
2053
  extendLine &&
3390
- unifiedLines.push({ type: DiffFileLineType.extend, index, lineNumber: index + 1, extendLine: extendLine });
2054
+ unifiedLines.push({ type: exports.DiffFileLineType.extend, index, lineNumber: index + 1, extendLine: extendLine });
3391
2055
  });
3392
2056
  return unifiedLines;
3393
2057
  };
3394
2058
  const getUnifiedContentLine = (diffFile) => {
3395
2059
  const lines = getUnifiedLines(diffFile, {});
3396
- return lines.filter((line) => line.type === DiffFileLineType.content);
2060
+ return lines.filter((line) => line.type === exports.DiffFileLineType.content);
3397
2061
  };
3398
2062
 
2063
+ const versions = "0.0.8";
2064
+
3399
2065
  const useUnmount = (cb, deps) => {
3400
2066
  const ref = React.useRef(cb);
3401
2067
  ref.current = cb;
@@ -3405,24 +2071,24 @@ const useUnmount = (cb, deps) => {
3405
2071
  const isClient = typeof window !== "undefined";
3406
2072
  const useSafeLayout = isClient ? React.useLayoutEffect : React.useEffect;
3407
2073
 
2074
+ var _TextMeasure_instances, _TextMeasure_key, _TextMeasure_map, _TextMeasure_getInstance;
3408
2075
  let canvasCtx = null;
3409
2076
  class TextMeasure {
3410
- #key = "";
3411
- #map = {};
3412
- #getInstance() {
3413
- canvasCtx = canvasCtx || document.createElement("canvas").getContext("2d");
3414
- return canvasCtx;
2077
+ constructor() {
2078
+ _TextMeasure_instances.add(this);
2079
+ _TextMeasure_key.set(this, "");
2080
+ _TextMeasure_map.set(this, {});
3415
2081
  }
3416
2082
  measure(text, font) {
3417
- const currentKey = `${font?.fontFamily}-${font?.fontStyle}-${font?.fontSize}-${text}`;
3418
- if (this.#map[currentKey]) {
3419
- return this.#map[currentKey];
2083
+ 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}`;
2084
+ if (__classPrivateFieldGet$1(this, _TextMeasure_map, "f")[currentKey]) {
2085
+ return __classPrivateFieldGet$1(this, _TextMeasure_map, "f")[currentKey];
3420
2086
  }
3421
- const instance = this.#getInstance();
2087
+ const instance = __classPrivateFieldGet$1(this, _TextMeasure_instances, "m", _TextMeasure_getInstance).call(this);
3422
2088
  if (font) {
3423
2089
  const currentFontKey = `${font.fontFamily}-${font.fontStyle}-${font.fontSize}`;
3424
- if (this.#key !== currentFontKey) {
3425
- this.#key = currentFontKey;
2090
+ if (__classPrivateFieldGet$1(this, _TextMeasure_key, "f") !== currentFontKey) {
2091
+ __classPrivateFieldSet$1(this, _TextMeasure_key, currentFontKey, "f");
3426
2092
  instance.font = `${font.fontStyle || ""} ${font.fontSize || ""} ${font.fontFamily || ""}`;
3427
2093
  }
3428
2094
  }
@@ -3433,6 +2099,10 @@ class TextMeasure {
3433
2099
  return textWidth;
3434
2100
  }
3435
2101
  }
2102
+ _TextMeasure_key = new WeakMap(), _TextMeasure_map = new WeakMap(), _TextMeasure_instances = new WeakSet(), _TextMeasure_getInstance = function _TextMeasure_getInstance() {
2103
+ canvasCtx = canvasCtx || document.createElement("canvas").getContext("2d");
2104
+ return canvasCtx;
2105
+ };
3436
2106
  const measureInstance = new TextMeasure();
3437
2107
  const useTextWidth = ({ text, font, }) => {
3438
2108
  const [width, setWidth] = React.useState(0);
@@ -3450,19 +2120,21 @@ const useDomWidth = ({ selector, enable }) => {
3450
2120
  React.useEffect(() => {
3451
2121
  if (enable) {
3452
2122
  const container = document.querySelector(`#diff-root${id}`);
3453
- const wrapper = container?.querySelector(selector);
2123
+ const wrapper = container === null || container === void 0 ? void 0 : container.querySelector(selector);
3454
2124
  if (!wrapper)
3455
2125
  return;
3456
2126
  const typedWrapper = wrapper;
3457
2127
  const cb = () => {
3458
- const rect = wrapper?.getBoundingClientRect();
3459
- setWidth(rect?.width ?? 0);
2128
+ var _a;
2129
+ const rect = wrapper === null || wrapper === void 0 ? void 0 : wrapper.getBoundingClientRect();
2130
+ setWidth((_a = rect === null || rect === void 0 ? void 0 : rect.width) !== null && _a !== void 0 ? _a : 0);
3460
2131
  };
3461
2132
  cb();
3462
2133
  const cleanCb = () => {
2134
+ var _a;
3463
2135
  typedWrapper.__observeCallback.delete(cb);
3464
2136
  if (typedWrapper.__observeCallback.size === 0) {
3465
- typedWrapper.__observeInstance?.disconnect();
2137
+ (_a = typedWrapper.__observeInstance) === null || _a === void 0 ? void 0 : _a.disconnect();
3466
2138
  typedWrapper.removeAttribute("data-observe");
3467
2139
  delete typedWrapper.__observeCallback;
3468
2140
  delete typedWrapper.__observeInstance;
@@ -3499,7 +2171,7 @@ const useSyncHeight = ({ selector, side, enable, }) => {
3499
2171
  useSafeLayout(() => {
3500
2172
  if (enable) {
3501
2173
  const container = document.querySelector(`#diff-root${id}`);
3502
- const elements = Array.from(container?.querySelectorAll(selector) || []);
2174
+ const elements = Array.from((container === null || container === void 0 ? void 0 : container.querySelectorAll(selector)) || []);
3503
2175
  if (elements.length === 2) {
3504
2176
  const ele1 = elements[0];
3505
2177
  const ele2 = elements[1];
@@ -3527,7 +2199,7 @@ const useSyncHeight = ({ selector, side, enable, }) => {
3527
2199
  target.setAttribute("data-observe", "height");
3528
2200
  return () => {
3529
2201
  observer.disconnect();
3530
- target?.removeAttribute("data-observe");
2202
+ target === null || target === void 0 ? void 0 : target.removeAttribute("data-observe");
3531
2203
  };
3532
2204
  }
3533
2205
  }
@@ -3570,12 +2242,13 @@ const getLineNumberBG = (isAdded, isDelete, hasDiff) => {
3570
2242
  };
3571
2243
 
3572
2244
  const _DiffSplitExtendLine$1 = ({ index, diffFile, side, lineNumber, }) => {
2245
+ var _a, _b;
3573
2246
  const { useDiffContext } = useDiffViewContext();
3574
2247
  const { extendData, renderExtendLine } = useDiffContext(React__namespace.useCallback((s) => ({ extendData: s.extendData, renderExtendLine: s.renderExtendLine }), []));
3575
2248
  const oldLine = diffFile.getSplitLeftLine(index);
3576
2249
  const newLine = diffFile.getSplitRightLine(index);
3577
- const oldLineExtend = extendData?.oldFile?.[oldLine?.lineNumber];
3578
- const newLineExtend = extendData?.newFile?.[newLine?.lineNumber];
2250
+ const oldLineExtend = (_a = extendData === null || extendData === void 0 ? void 0 : extendData.oldFile) === null || _a === void 0 ? void 0 : _a[oldLine === null || oldLine === void 0 ? void 0 : oldLine.lineNumber];
2251
+ const newLineExtend = (_b = extendData === null || extendData === void 0 ? void 0 : extendData.newFile) === null || _b === void 0 ? void 0 : _b[newLine === null || newLine === void 0 ? void 0 : newLine.lineNumber];
3579
2252
  const currentExtend = side === exports.SplitSide.old ? oldLineExtend : newLineExtend;
3580
2253
  const currentLineNumber = side === exports.SplitSide.old ? oldLine.lineNumber : newLine.lineNumber;
3581
2254
  const otherSide = side === exports.SplitSide.old ? exports.SplitSide.new : exports.SplitSide.old;
@@ -3592,20 +2265,20 @@ const _DiffSplitExtendLine$1 = ({ index, diffFile, side, lineNumber, }) => {
3592
2265
  return null;
3593
2266
  return (React__namespace.createElement("tr", { "data-line": `${lineNumber}-extend`, "data-state": "extend", "data-side": exports.SplitSide[side], className: "diff-line diff-line-extend" }, currentExtend ? (React__namespace.createElement("td", { className: `diff-line-extend-${exports.SplitSide[side]}-content p-0`, colSpan: 2 },
3594
2267
  React__namespace.createElement("div", { className: "diff-line-extend-wrapper sticky left-0", style: { width } }, width > 0 &&
3595
- renderExtendLine?.({
2268
+ (renderExtendLine === null || renderExtendLine === void 0 ? void 0 : renderExtendLine({
3596
2269
  diffFile,
3597
2270
  side,
3598
2271
  lineNumber: currentLineNumber,
3599
2272
  data: currentExtend.data,
3600
2273
  onUpdate: diffFile.notifyAll,
3601
- })))) : (React__namespace.createElement("td", { className: `diff-line-extend-${exports.SplitSide[side]}-placeholder p-0 select-none`, style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 },
2274
+ }))))) : (React__namespace.createElement("td", { className: `diff-line-extend-${exports.SplitSide[side]}-placeholder p-0 select-none`, style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 },
3602
2275
  React__namespace.createElement("span", null, "\u2002")))));
3603
2276
  };
3604
2277
  const DiffSplitExtendLine$1 = ({ index, diffFile, side, lineNumber, }) => {
3605
2278
  const { useDiffContext } = useDiffViewContext();
3606
2279
  const oldLine = diffFile.getSplitLeftLine(index);
3607
2280
  const newLine = diffFile.getSplitRightLine(index);
3608
- const hasExtend = useDiffContext(React__namespace.useCallback((s) => s.extendData?.oldFile?.[oldLine?.lineNumber] || s.extendData?.newFile?.[newLine?.lineNumber], [oldLine?.lineNumber, newLine?.lineNumber]));
2281
+ const hasExtend = useDiffContext(React__namespace.useCallback((s) => { var _a, _b, _c, _d; return ((_b = (_a = s.extendData) === null || _a === void 0 ? void 0 : _a.oldFile) === null || _b === void 0 ? void 0 : _b[oldLine === null || oldLine === void 0 ? void 0 : oldLine.lineNumber]) || ((_d = (_c = s.extendData) === null || _c === void 0 ? void 0 : _c.newFile) === null || _d === void 0 ? void 0 : _d[newLine === null || newLine === void 0 ? void 0 : newLine.lineNumber]); }, [oldLine === null || oldLine === void 0 ? void 0 : oldLine.lineNumber, newLine === null || newLine === void 0 ? void 0 : newLine.lineNumber]));
3609
2282
  // if the expand action not enabled, the `isHidden` property will never change
3610
2283
  const enableExpand = diffFile.getExpandEnabled();
3611
2284
  const currentLine = side === exports.SplitSide.old ? oldLine : newLine;
@@ -3628,7 +2301,40 @@ const ExpandAll = ({ className }) => {
3628
2301
  React__namespace.createElement("path", { d: "m8.177.677 2.896 2.896a.25.25 0 0 1-.177.427H8.75v1.25a.75.75 0 0 1-1.5 0V4H5.104a.25.25 0 0 1-.177-.427L7.823.677a.25.25 0 0 1 .354 0ZM7.25 10.75a.75.75 0 0 1 1.5 0V12h2.146a.25.25 0 0 1 .177.427l-2.896 2.896a.25.25 0 0 1-.354 0l-2.896-2.896A.25.25 0 0 1 5.104 12H7.25v-1.25Zm-5-2a.75.75 0 0 0 0-1.5h-.5a.75.75 0 0 0 0 1.5h.5ZM6 8a.75.75 0 0 1-.75.75h-.5a.75.75 0 0 1 0-1.5h.5A.75.75 0 0 1 6 8Zm2.25.75a.75.75 0 0 0 0-1.5h-.5a.75.75 0 0 0 0 1.5h.5ZM12 8a.75.75 0 0 1-.75.75h-.5a.75.75 0 0 1 0-1.5h.5A.75.75 0 0 1 12 8Zm2.25.75a.75.75 0 0 0 0-1.5h-.5a.75.75 0 0 0 0 1.5h.5Z" })));
3629
2302
  };
3630
2303
 
2304
+ const removeAllSelection = () => {
2305
+ const selection = window.getSelection();
2306
+ for (let i = 0; i < selection.rangeCount; i++) {
2307
+ selection.removeRange(selection.getRangeAt(i));
2308
+ }
2309
+ };
2310
+ const syncScroll = (left, right) => {
2311
+ const onScroll = function (event) {
2312
+ if (event === null || event.target === null)
2313
+ return;
2314
+ if (event.target === left) {
2315
+ right.scrollTop = left.scrollTop;
2316
+ right.scrollLeft = left.scrollLeft;
2317
+ }
2318
+ else {
2319
+ left.scrollTop = right.scrollTop;
2320
+ left.scrollLeft = right.scrollLeft;
2321
+ }
2322
+ };
2323
+ if (!left.onscroll) {
2324
+ left.onscroll = onScroll;
2325
+ }
2326
+ if (!right.onscroll) {
2327
+ right.onscroll = onScroll;
2328
+ }
2329
+ return () => {
2330
+ left.onscroll = null;
2331
+ right.onscroll = null;
2332
+ };
2333
+ };
2334
+ const asideWidth = "--diff-aside-width--";
2335
+
3631
2336
  const _DiffSplitHunkLine = ({ index, diffFile, side, lineNumber, }) => {
2337
+ var _a;
3632
2338
  const currentHunk = diffFile.getSplitHunkLine(index);
3633
2339
  const expandEnabled = diffFile.getExpandEnabled();
3634
2340
  useSyncHeight({
@@ -3637,6 +2343,7 @@ const _DiffSplitHunkLine = ({ index, diffFile, side, lineNumber, }) => {
3637
2343
  enable: side === exports.SplitSide.new,
3638
2344
  });
3639
2345
  const enableHunkAction = side === exports.SplitSide.old;
2346
+ const couldExpand = expandEnabled && currentHunk && currentHunk.splitInfo;
3640
2347
  const isExpandAll = currentHunk &&
3641
2348
  currentHunk.splitInfo &&
3642
2349
  currentHunk.splitInfo.endHiddenIndex - currentHunk.splitInfo.startHiddenIndex < composeLen;
@@ -3646,7 +2353,10 @@ const _DiffSplitHunkLine = ({ index, diffFile, side, lineNumber, }) => {
3646
2353
  React__namespace.createElement("td", { className: "diff-line-hunk-action sticky left-0 p-[1px] w-[1%] min-w-[40px] select-none", style: {
3647
2354
  backgroundColor: `var(${hunkLineNumberBGName})`,
3648
2355
  color: `var(${plainLineNumberColorName})`,
3649
- } }, expandEnabled ? (isFirstLine ? (React__namespace.createElement("button", { className: "w-full diff-widget-tooltip hover:bg-blue-300 flex justify-center items-center py-[6px] cursor-pointer rounded-[2px]", title: "Expand Up", "data-title": "Expand Up", onClick: () => diffFile.onSplitHunkExpand("up", index) },
2356
+ width: `var(${asideWidth})`,
2357
+ minWidth: `var(${asideWidth})`,
2358
+ maxWidth: `var(${asideWidth})`,
2359
+ } }, couldExpand ? (isFirstLine ? (React__namespace.createElement("button", { className: "w-full diff-widget-tooltip hover:bg-blue-300 flex justify-center items-center py-[6px] cursor-pointer rounded-[2px]", title: "Expand Up", "data-title": "Expand Up", onClick: () => diffFile.onSplitHunkExpand("up", index) },
3650
2360
  React__namespace.createElement(ExpandUp, { className: "fill-current" }))) : isLastLine ? (React__namespace.createElement("button", { className: "w-full diff-widget-tooltip hover:bg-blue-300 flex justify-center items-center py-[6px] cursor-pointer rounded-[2px] relative", title: "Expand Down", "data-title": "Expand Down", onClick: () => {
3651
2361
  diffFile.onSplitHunkExpand("down", index);
3652
2362
  } },
@@ -3659,7 +2369,7 @@ const _DiffSplitHunkLine = ({ index, diffFile, side, lineNumber, }) => {
3659
2369
  React__namespace.createElement("td", { className: "diff-line-hunk-content pr-[10px] align-middle", style: { backgroundColor: `var(${hunkContentBGName})` } },
3660
2370
  React__namespace.createElement("div", { className: "pl-[1.5em]", style: {
3661
2371
  color: `var(${hunkContentColorName})`,
3662
- } }, currentHunk.splitInfo.plainText)))) : (React__namespace.createElement("td", { className: "diff-line-hunk-placeholder select-none", colSpan: 2, style: { backgroundColor: `var(${hunkContentBGName})` } },
2372
+ } }, ((_a = currentHunk.splitInfo) === null || _a === void 0 ? void 0 : _a.plainText) || currentHunk.text)))) : (React__namespace.createElement("td", { className: "diff-line-hunk-placeholder select-none", colSpan: 2, style: { backgroundColor: `var(${hunkContentBGName})` } },
3663
2373
  React__namespace.createElement("div", { className: "min-h-[28px]" }, "\u2002")))));
3664
2374
  };
3665
2375
  const DiffSplitHunkLine$1 = ({ index, diffFile, side, lineNumber, }) => {
@@ -3667,7 +2377,8 @@ const DiffSplitHunkLine$1 = ({ index, diffFile, side, lineNumber, }) => {
3667
2377
  const currentIsShow = currentHunk &&
3668
2378
  currentHunk.splitInfo &&
3669
2379
  currentHunk.splitInfo.startHiddenIndex < currentHunk.splitInfo.endHiddenIndex;
3670
- if (!currentIsShow)
2380
+ const currentIsPureHunk = currentHunk && diffFile._getIsPureDiffRender() && !currentHunk.splitInfo;
2381
+ if (!currentIsShow && !currentIsPureHunk)
3671
2382
  return null;
3672
2383
  return React__namespace.createElement(_DiffSplitHunkLine, { index: index, diffFile: diffFile, side: side, lineNumber: lineNumber });
3673
2384
  };
@@ -3684,7 +2395,7 @@ const DiffSplitAddWidget = ({ side, className, lineNumber, onWidgetClick, onOpen
3684
2395
  backgroundColor: `var(${addWidgetBGName})`,
3685
2396
  }, onClick: () => {
3686
2397
  onOpenAddWidget(lineNumber, side);
3687
- onWidgetClick?.(lineNumber, side);
2398
+ onWidgetClick === null || onWidgetClick === void 0 ? void 0 : onWidgetClick(lineNumber, side);
3688
2399
  } }, "+")));
3689
2400
  };
3690
2401
  const DiffUnifiedAddWidget = ({ lineNumber, side, onWidgetClick, onOpenAddWidget, }) => {
@@ -3699,12 +2410,12 @@ const DiffUnifiedAddWidget = ({ lineNumber, side, onWidgetClick, onOpenAddWidget
3699
2410
  backgroundColor: `var(${addWidgetBGName})`,
3700
2411
  }, onClick: () => {
3701
2412
  onOpenAddWidget(lineNumber, side);
3702
- onWidgetClick?.(lineNumber, side);
2413
+ onWidgetClick === null || onWidgetClick === void 0 ? void 0 : onWidgetClick(lineNumber, side);
3703
2414
  } }, "+")));
3704
2415
  };
3705
2416
 
3706
2417
  const DiffString = ({ rawLine, diffLine, operator, }) => {
3707
- const range = diffLine?.range;
2418
+ const range = diffLine === null || diffLine === void 0 ? void 0 : diffLine.range;
3708
2419
  if (range) {
3709
2420
  const str1 = rawLine.slice(0, range.location);
3710
2421
  const str2 = rawLine.slice(range.location, range.location + range.length);
@@ -3729,15 +2440,17 @@ const DiffString = ({ rawLine, diffLine, operator, }) => {
3729
2440
  return React__namespace.createElement("span", { className: "diff-line-content-raw" }, rawLine);
3730
2441
  };
3731
2442
  const DiffSyntax = ({ rawLine, diffLine, operator, syntaxLine, }) => {
2443
+ var _a, _b;
3732
2444
  if (!syntaxLine) {
3733
2445
  return React__namespace.createElement(DiffString, { rawLine: rawLine, diffLine: diffLine, operator: operator });
3734
2446
  }
3735
- const range = diffLine?.range;
2447
+ const range = diffLine === null || diffLine === void 0 ? void 0 : diffLine.range;
3736
2448
  if (range) {
3737
2449
  return (React__namespace.createElement("span", { className: "diff-line-syntax-raw" },
3738
- React__namespace.createElement("span", { "data-range-start": range.location, "data-range-end": range.location + range.length }, syntaxLine.nodeList?.map(({ node, wrapper }, index) => {
2450
+ React__namespace.createElement("span", { "data-range-start": range.location, "data-range-end": range.location + range.length }, (_a = syntaxLine.nodeList) === null || _a === void 0 ? void 0 : _a.map(({ node, wrapper }, index) => {
2451
+ var _a, _b, _c, _d;
3739
2452
  if (node.endIndex < range.location || range.location + range.length < node.startIndex) {
3740
- return (React__namespace.createElement("span", { key: index, "data-start": node.startIndex, "data-end": node.endIndex, className: wrapper?.properties?.className?.join(" ") }, node.value));
2453
+ return (React__namespace.createElement("span", { key: index, "data-start": node.startIndex, "data-end": node.endIndex, className: (_b = (_a = wrapper === null || wrapper === void 0 ? void 0 : wrapper.properties) === null || _a === void 0 ? void 0 : _a.className) === null || _b === void 0 ? void 0 : _b.join(" ") }, node.value));
3741
2454
  }
3742
2455
  else {
3743
2456
  const index1 = range.location - node.startIndex;
@@ -3748,7 +2461,7 @@ const DiffSyntax = ({ rawLine, diffLine, operator, syntaxLine, }) => {
3748
2461
  const isStart = str1.length || range.location === node.startIndex;
3749
2462
  const isEnd = str3.length || node.endIndex === range.location + range.length - 1;
3750
2463
  const isNewLineSymbolChanged = range.isNewLineSymbolChanged;
3751
- return (React__namespace.createElement("span", { key: index, "data-start": node.startIndex, "data-end": node.endIndex, className: wrapper?.properties?.className?.join(" ") },
2464
+ return (React__namespace.createElement("span", { key: index, "data-start": node.startIndex, "data-end": node.endIndex, className: (_d = (_c = wrapper === null || wrapper === void 0 ? void 0 : wrapper.properties) === null || _c === void 0 ? void 0 : _c.className) === null || _d === void 0 ? void 0 : _d.join(" ") },
3752
2465
  str1,
3753
2466
  React__namespace.createElement("span", { "data-diff-highlight": true, style: {
3754
2467
  backgroundColor: operator === "add" ? `var(${addContentHighlightBGName})` : `var(${delContentHighlightBGName})`,
@@ -3769,12 +2482,16 @@ const DiffSyntax = ({ rawLine, diffLine, operator, syntaxLine, }) => {
3769
2482
  }
3770
2483
  }))));
3771
2484
  }
3772
- return (React__namespace.createElement("span", { className: "diff-line-syntax-raw" }, syntaxLine?.nodeList?.map(({ node, wrapper }, index) => (React__namespace.createElement("span", { key: index, "data-start": node.startIndex, "data-end": node.endIndex, className: wrapper?.properties?.className?.join(" ") }, node.value)))));
2485
+ return (React__namespace.createElement("span", { className: "diff-line-syntax-raw" }, (_b = syntaxLine === null || syntaxLine === void 0 ? void 0 : syntaxLine.nodeList) === null || _b === void 0 ? void 0 : _b.map(({ node, wrapper }, index) => {
2486
+ var _a, _b;
2487
+ return (React__namespace.createElement("span", { key: index, "data-start": node.startIndex, "data-end": node.endIndex, className: (_b = (_a = wrapper === null || wrapper === void 0 ? void 0 : wrapper.properties) === null || _a === void 0 ? void 0 : _a.className) === null || _b === void 0 ? void 0 : _b.join(" ") }, node.value));
2488
+ })));
3773
2489
  };
3774
2490
  const DiffContent = ({ diffLine, rawLine, syntaxLine, enableWrap, enableHighlight, }) => {
3775
- const isAdded = diffLine?.type === DiffLineType.Add;
3776
- const isDelete = diffLine?.type === DiffLineType.Delete;
3777
- const isMaxLineLengthToIgnoreSyntax = syntaxLine?.nodeList?.length > 150;
2491
+ var _a;
2492
+ const isAdded = (diffLine === null || diffLine === void 0 ? void 0 : diffLine.type) === exports.DiffLineType.Add;
2493
+ const isDelete = (diffLine === null || diffLine === void 0 ? void 0 : diffLine.type) === exports.DiffLineType.Delete;
2494
+ const isMaxLineLengthToIgnoreSyntax = ((_a = syntaxLine === null || syntaxLine === void 0 ? void 0 : syntaxLine.nodeList) === null || _a === void 0 ? void 0 : _a.length) > 150;
3778
2495
  return (React__namespace.createElement("div", { className: "diff-line-content-item pl-[2.0em]", "data-val": rawLine, style: {
3779
2496
  whiteSpace: enableWrap ? "pre-wrap" : "pre",
3780
2497
  wordBreak: enableWrap ? "break-all" : "initial",
@@ -3788,15 +2505,16 @@ DiffWidgetContext.displayName = "DiffWidgetContext";
3788
2505
  const useDiffWidgetContext = () => React.useContext(DiffWidgetContext);
3789
2506
 
3790
2507
  const _DiffSplitLine$1 = ({ index, diffFile, lineNumber, side, }) => {
2508
+ var _a, _b;
3791
2509
  const getCurrentSyntaxLine = side === exports.SplitSide.old ? diffFile.getOldSyntaxLine : diffFile.getNewSyntaxLine;
3792
2510
  const oldLine = diffFile.getSplitLeftLine(index);
3793
2511
  const newLine = diffFile.getSplitRightLine(index);
3794
2512
  const currentLine = side === exports.SplitSide.old ? oldLine : newLine;
3795
- const hasDiff = !!currentLine?.diff;
2513
+ const hasDiff = !!(currentLine === null || currentLine === void 0 ? void 0 : currentLine.diff);
3796
2514
  const hasContent = !!currentLine.lineNumber;
3797
- const hasChange = checkDiffLineIncludeChange(currentLine?.diff);
3798
- const isAdded = currentLine?.diff?.type === DiffLineType.Add;
3799
- const isDelete = currentLine?.diff?.type === DiffLineType.Delete;
2515
+ const hasChange = checkDiffLineIncludeChange(currentLine === null || currentLine === void 0 ? void 0 : currentLine.diff);
2516
+ const isAdded = ((_a = currentLine === null || currentLine === void 0 ? void 0 : currentLine.diff) === null || _a === void 0 ? void 0 : _a.type) === exports.DiffLineType.Add;
2517
+ const isDelete = ((_b = currentLine === null || currentLine === void 0 ? void 0 : currentLine.diff) === null || _b === void 0 ? void 0 : _b.type) === exports.DiffLineType.Delete;
3800
2518
  const { useDiffContext } = useDiffViewContext();
3801
2519
  const { enableHighlight, enableAddWidget, onAddWidgetClick } = useDiffContext(React__namespace.useCallback((s) => ({
3802
2520
  enableHighlight: s.enableHighlight,
@@ -3812,6 +2530,9 @@ const _DiffSplitLine$1 = ({ index, diffFile, lineNumber, side, }) => {
3812
2530
  React__namespace.createElement("td", { className: `diff-line-${exports.SplitSide[side]}-num sticky left-0 pl-[10px] pr-[10px] text-right align-top select-none w-[1%] min-w-[40px]`, style: {
3813
2531
  backgroundColor: lineNumberBG,
3814
2532
  color: `var(${plainLineNumberColorName})`,
2533
+ width: `var(${asideWidth})`,
2534
+ minWidth: `var(${asideWidth})`,
2535
+ maxWidth: `var(${asideWidth})`,
3815
2536
  } },
3816
2537
  hasDiff && enableAddWidget && (React__namespace.createElement(DiffSplitAddWidget, { index: index, lineNumber: currentLine.lineNumber, side: side, diffFile: diffFile, onWidgetClick: onAddWidgetClick, className: "absolute left-[100%] translate-x-[-50%] z-[1]", onOpenAddWidget: (lineNumber, side) => setWidget({ lineNumber: lineNumber, side: side }) })),
3817
2538
  React__namespace.createElement("span", { "data-line-num": currentLine.lineNumber, style: { opacity: hasChange ? undefined : 0.5 } }, currentLine.lineNumber)),
@@ -3822,7 +2543,7 @@ const _DiffSplitLine$1 = ({ index, diffFile, lineNumber, side, }) => {
3822
2543
  const DiffSplitLine$1 = ({ index, diffFile, lineNumber, side, }) => {
3823
2544
  const getCurrentLine = side === exports.SplitSide.old ? diffFile.getSplitLeftLine : diffFile.getSplitRightLine;
3824
2545
  const currentLine = getCurrentLine(index);
3825
- if (currentLine?.isHidden)
2546
+ if (currentLine === null || currentLine === void 0 ? void 0 : currentLine.isHidden)
3826
2547
  return null;
3827
2548
  return React__namespace.createElement(_DiffSplitLine$1, { index: index, diffFile: diffFile, lineNumber: lineNumber, side: side });
3828
2549
  };
@@ -3844,12 +2565,12 @@ const _DiffSplitWidgetLine$1 = ({ diffFile, side, lineNumber, currentLine, setWi
3844
2565
  return null;
3845
2566
  return (React__namespace.createElement("tr", { "data-line": `${lineNumber}-widget`, "data-state": "widget", "data-side": exports.SplitSide[side], className: "diff-line diff-line-widget" }, currentWidget ? (React__namespace.createElement("td", { className: `diff-line-widget-${exports.SplitSide[side]}-content p-0`, colSpan: 2 },
3846
2567
  React__namespace.createElement("div", { className: "diff-line-widget-wrapper sticky left-0", style: { width } }, width > 0 &&
3847
- renderWidgetLine?.({
2568
+ (renderWidgetLine === null || renderWidgetLine === void 0 ? void 0 : renderWidgetLine({
3848
2569
  diffFile,
3849
2570
  side,
3850
2571
  lineNumber: currentLine.lineNumber,
3851
2572
  onClose: () => setWidget({}),
3852
- })))) : (React__namespace.createElement("td", { className: `diff-line-widget-${exports.SplitSide[side]}-placeholder p-0`, style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 },
2573
+ }))))) : (React__namespace.createElement("td", { className: `diff-line-widget-${exports.SplitSide[side]}-placeholder p-0`, style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 },
3853
2574
  React__namespace.createElement("span", null, "\u2002")))));
3854
2575
  };
3855
2576
  const DiffSplitWidgetLine$1 = ({ index, diffFile, side, lineNumber, }) => {
@@ -3867,37 +2588,7 @@ const DiffSplitWidgetLine$1 = ({ index, diffFile, side, lineNumber, }) => {
3867
2588
  return (React__namespace.createElement(_DiffSplitWidgetLine$1, { index: index, diffFile: diffFile, side: side, lineNumber: lineNumber, currentLine: currentLine, setWidget: setWidget, currentWidget: currentWidget }));
3868
2589
  };
3869
2590
 
3870
- const removeAllSelection = () => {
3871
- const selection = window.getSelection();
3872
- for (let i = 0; i < selection.rangeCount; i++) {
3873
- selection.removeRange(selection.getRangeAt(i));
3874
- }
3875
- };
3876
- const syncScroll = (left, right) => {
3877
- const onScroll = function (event) {
3878
- if (event === null || event.target === null)
3879
- return;
3880
- if (event.target === left) {
3881
- right.scrollTop = left.scrollTop;
3882
- right.scrollLeft = left.scrollLeft;
3883
- }
3884
- else {
3885
- left.scrollTop = right.scrollTop;
3886
- left.scrollLeft = right.scrollLeft;
3887
- }
3888
- };
3889
- if (!left.onscroll) {
3890
- left.onscroll = onScroll;
3891
- }
3892
- if (!right.onscroll) {
3893
- right.onscroll = onScroll;
3894
- }
3895
- return () => {
3896
- left.onscroll = null;
3897
- right.onscroll = null;
3898
- };
3899
- };
3900
-
2591
+ /* eslint-disable @typescript-eslint/ban-ts-comment */
3901
2592
  const onMouseDown$1 = (e) => {
3902
2593
  const ele = e.target;
3903
2594
  // need remove all the selection
@@ -3906,12 +2597,12 @@ const onMouseDown$1 = (e) => {
3906
2597
  return;
3907
2598
  }
3908
2599
  };
3909
- const DiffSplitViewTable = ({ side, diffFile, width }) => {
2600
+ const DiffSplitViewTable = ({ side, diffFile }) => {
3910
2601
  const className = side === exports.SplitSide.new ? "new-diff-table" : "old-diff-table";
3911
2602
  const lines = getSplitContentLines(diffFile);
3912
2603
  return (React__namespace.createElement("table", { className: className + " border-collapse w-full", "data-mode": exports.SplitSide[side] },
3913
2604
  React__namespace.createElement("colgroup", null,
3914
- React__namespace.createElement("col", { className: `diff-table-${exports.SplitSide[side]}-num-col`, style: { minWidth: Math.round(width) + 25 } }),
2605
+ React__namespace.createElement("col", { className: `diff-table-${exports.SplitSide[side]}-num-col` }),
3915
2606
  React__namespace.createElement("col", { className: `diff-table-${exports.SplitSide[side]}-content-col` })),
3916
2607
  React__namespace.createElement("thead", { className: "hidden" },
3917
2608
  React__namespace.createElement("tr", null,
@@ -3943,40 +2634,46 @@ const DiffSplitViewNormal = React.memo(({ diffFile }) => {
3943
2634
  return;
3944
2635
  return syncScroll(left, right);
3945
2636
  }, []);
3946
- const width = useTextWidth({
2637
+ const _width = useTextWidth({
3947
2638
  text: splitLineLength.toString(),
3948
2639
  font: { fontSize: fontSize + "px", fontFamily: "Menlo, Consolas, monospace" },
3949
2640
  });
2641
+ const width = Math.max(40, _width + 25);
3950
2642
  return (React__namespace.createElement("div", { className: "split-diff-view split-diff-view-wrap w-full flex basis-[50%]" },
3951
2643
  React__namespace.createElement("div", { className: "old-diff-table-wrapper overflow-auto w-full scrollbar-hide scrollbar-disable", ref: ref1, style: {
2644
+ // @ts-ignore
2645
+ [asideWidth]: `${Math.round(width)}px`,
3952
2646
  overscrollBehaviorX: "none",
3953
2647
  fontFamily: "Menlo, Consolas, monospace",
3954
2648
  fontSize: "var(--diff-font-size--)",
3955
2649
  } },
3956
- React__namespace.createElement(DiffSplitViewTable, { side: exports.SplitSide.old, diffFile: diffFile, width: width })),
2650
+ React__namespace.createElement(DiffSplitViewTable, { side: exports.SplitSide.old, diffFile: diffFile })),
3957
2651
  React__namespace.createElement("div", { className: "diff-split-line w-[1.5px] bg-[#ccc]" }),
3958
2652
  React__namespace.createElement("div", { className: "new-diff-table-wrapper overflow-auto w-full scrollbar-hide scrollbar-disable", ref: ref2, style: {
2653
+ // @ts-ignore
2654
+ [asideWidth]: `${Math.round(width)}px`,
3959
2655
  overscrollBehaviorX: "none",
3960
2656
  fontFamily: "Menlo, Consolas, monospace",
3961
2657
  fontSize: "var(--diff-font-size--)",
3962
2658
  } },
3963
- React__namespace.createElement(DiffSplitViewTable, { side: exports.SplitSide.new, diffFile: diffFile, width: width }))));
2659
+ React__namespace.createElement(DiffSplitViewTable, { side: exports.SplitSide.new, diffFile: diffFile }))));
3964
2660
  });
3965
2661
  DiffSplitViewNormal.displayName = "DiffSplitViewNormal";
3966
2662
 
3967
2663
  const _DiffSplitExtendLine = ({ index, diffFile, lineNumber, }) => {
2664
+ var _a, _b;
3968
2665
  const { useDiffContext } = useDiffViewContext();
3969
2666
  // 需要显示的时候才进行方法订阅,可以大幅度提高性能
3970
2667
  const { extendData, renderExtendLine } = useDiffContext(React__namespace.useCallback((s) => ({ extendData: s.extendData, renderExtendLine: s.renderExtendLine }), []));
3971
2668
  const oldLine = diffFile.getSplitLeftLine(index);
3972
2669
  const newLine = diffFile.getSplitRightLine(index);
3973
- const oldLineExtend = extendData?.oldFile?.[oldLine?.lineNumber];
3974
- const newLineExtend = extendData?.newFile?.[newLine?.lineNumber];
2670
+ const oldLineExtend = (_a = extendData === null || extendData === void 0 ? void 0 : extendData.oldFile) === null || _a === void 0 ? void 0 : _a[oldLine === null || oldLine === void 0 ? void 0 : oldLine.lineNumber];
2671
+ const newLineExtend = (_b = extendData === null || extendData === void 0 ? void 0 : extendData.newFile) === null || _b === void 0 ? void 0 : _b[newLine === null || newLine === void 0 ? void 0 : newLine.lineNumber];
3975
2672
  if (!renderExtendLine)
3976
2673
  return null;
3977
2674
  return (React__namespace.createElement("tr", { "data-line": `${lineNumber}-extend`, "data-state": "extend", className: "diff-line diff-line-extend" },
3978
2675
  oldLineExtend ? (React__namespace.createElement("td", { className: "diff-line-extend-old-content p-0", colSpan: 2 },
3979
- React__namespace.createElement("div", { className: "diff-line-extend-wrapper" }, renderExtendLine?.({
2676
+ React__namespace.createElement("div", { className: "diff-line-extend-wrapper" }, renderExtendLine === null || renderExtendLine === void 0 ? void 0 : renderExtendLine({
3980
2677
  diffFile,
3981
2678
  side: exports.SplitSide.old,
3982
2679
  lineNumber: oldLine.lineNumber,
@@ -3985,7 +2682,7 @@ const _DiffSplitExtendLine = ({ index, diffFile, lineNumber, }) => {
3985
2682
  })))) : (React__namespace.createElement("td", { className: "diff-line-extend-old-placeholder p-0 select-none", style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 },
3986
2683
  React__namespace.createElement("span", null, "\u2002"))),
3987
2684
  newLineExtend ? (React__namespace.createElement("td", { className: "diff-line-extend-new-content p-0 border-l-[1px] border-l-[#ccc]", colSpan: 2 },
3988
- React__namespace.createElement("div", { className: "diff-line-extend-wrapper" }, renderExtendLine?.({
2685
+ React__namespace.createElement("div", { className: "diff-line-extend-wrapper" }, renderExtendLine === null || renderExtendLine === void 0 ? void 0 : renderExtendLine({
3989
2686
  diffFile,
3990
2687
  side: exports.SplitSide.new,
3991
2688
  lineNumber: newLine.lineNumber,
@@ -3998,33 +2695,36 @@ const DiffSplitExtendLine = ({ index, diffFile, lineNumber, }) => {
3998
2695
  const { useDiffContext } = useDiffViewContext();
3999
2696
  const oldLine = diffFile.getSplitLeftLine(index);
4000
2697
  const newLine = diffFile.getSplitRightLine(index);
4001
- const hasExtend = useDiffContext(React__namespace.useCallback((s) => s.extendData?.oldFile?.[oldLine?.lineNumber] || s.extendData?.newFile?.[newLine?.lineNumber], [oldLine?.lineNumber, newLine?.lineNumber]));
2698
+ const hasExtend = useDiffContext(React__namespace.useCallback((s) => { var _a, _b, _c, _d; return ((_b = (_a = s.extendData) === null || _a === void 0 ? void 0 : _a.oldFile) === null || _b === void 0 ? void 0 : _b[oldLine === null || oldLine === void 0 ? void 0 : oldLine.lineNumber]) || ((_d = (_c = s.extendData) === null || _c === void 0 ? void 0 : _c.newFile) === null || _d === void 0 ? void 0 : _d[newLine === null || newLine === void 0 ? void 0 : newLine.lineNumber]); }, [oldLine === null || oldLine === void 0 ? void 0 : oldLine.lineNumber, newLine === null || newLine === void 0 ? void 0 : newLine.lineNumber]));
4002
2699
  // if the expand action not enabled, the `isHidden` property will never change
4003
2700
  const enableExpand = diffFile.getExpandEnabled();
4004
- const currentIsShow = hasExtend && ((!oldLine?.isHidden && !newLine?.isHidden) || !enableExpand);
2701
+ const currentIsShow = hasExtend && ((!(oldLine === null || oldLine === void 0 ? void 0 : oldLine.isHidden) && !(newLine === null || newLine === void 0 ? void 0 : newLine.isHidden)) || !enableExpand);
4005
2702
  if (!currentIsShow)
4006
2703
  return null;
4007
2704
  return React__namespace.createElement(_DiffSplitExtendLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
4008
2705
  };
4009
2706
 
4010
2707
  const DiffSplitHunkLine = ({ index, diffFile, lineNumber, }) => {
2708
+ var _a;
4011
2709
  const currentHunk = diffFile.getSplitHunkLine(index);
4012
2710
  const expandEnabled = diffFile.getExpandEnabled();
2711
+ const couldExpand = expandEnabled && currentHunk && currentHunk.splitInfo;
4013
2712
  const isExpandAll = currentHunk &&
4014
2713
  currentHunk.splitInfo &&
4015
2714
  currentHunk.splitInfo.endHiddenIndex - currentHunk.splitInfo.startHiddenIndex < composeLen;
4016
2715
  const currentIsShow = currentHunk &&
4017
2716
  currentHunk.splitInfo &&
4018
2717
  currentHunk.splitInfo.startHiddenIndex < currentHunk.splitInfo.endHiddenIndex;
2718
+ const currentIsPureHunk = currentHunk && diffFile._getIsPureDiffRender() && !currentHunk.splitInfo;
4019
2719
  const isFirstLine = currentHunk && currentHunk.index === 0;
4020
2720
  const isLastLine = currentHunk && currentHunk.isLast;
4021
- if (!currentIsShow)
2721
+ if (!currentIsShow && !currentIsPureHunk)
4022
2722
  return null;
4023
2723
  return (React__namespace.createElement("tr", { "data-line": `${lineNumber}-hunk`, "data-state": "hunk", className: "diff-line diff-line-hunk" },
4024
2724
  React__namespace.createElement("td", { className: "diff-line-hunk-action p-[1px] w-[1%] min-w-[40px] select-none", style: {
4025
2725
  backgroundColor: `var(${hunkLineNumberBGName})`,
4026
2726
  color: `var(${plainLineNumberColorName})`,
4027
- } }, expandEnabled ? (isFirstLine ? (React__namespace.createElement("button", { className: "w-full diff-widget-tooltip hover:bg-blue-300 flex justify-center items-center py-[6px] cursor-pointer rounded-[2px]", title: "Expand Up", "data-title": "Expand Up", onClick: () => diffFile.onSplitHunkExpand("up", index) },
2727
+ } }, couldExpand ? (isFirstLine ? (React__namespace.createElement("button", { className: "w-full diff-widget-tooltip hover:bg-blue-300 flex justify-center items-center py-[6px] cursor-pointer rounded-[2px]", title: "Expand Up", "data-title": "Expand Up", onClick: () => diffFile.onSplitHunkExpand("up", index) },
4028
2728
  React__namespace.createElement(ExpandUp, { className: "fill-current" }))) : isLastLine ? (React__namespace.createElement("button", { className: "w-full diff-widget-tooltip hover:bg-blue-300 flex justify-center items-center py-[6px] cursor-pointer rounded-[2px]", title: "Expand Down", "data-title": "Expand Down", onClick: () => diffFile.onSplitHunkExpand("down", index) },
4029
2729
  React__namespace.createElement(ExpandDown, { className: "fill-current" }))) : isExpandAll ? (React__namespace.createElement("button", { className: "w-full diff-widget-tooltip hover:bg-blue-300 flex justify-center items-center py-[6px] cursor-pointer rounded-[2px]", title: "Expand All", "data-title": "Expand All", onClick: () => diffFile.onSplitHunkExpand("all", index) },
4030
2730
  React__namespace.createElement(ExpandAll, { className: "fill-current" }))) : (React__namespace.createElement(React__namespace.Fragment, null,
@@ -4035,18 +2735,19 @@ const DiffSplitHunkLine = ({ index, diffFile, lineNumber, }) => {
4035
2735
  React__namespace.createElement("td", { className: "diff-line-hunk-content pr-[10px] align-middle", style: { backgroundColor: `var(${hunkContentBGName})` }, colSpan: 3 },
4036
2736
  React__namespace.createElement("div", { className: "pl-[1.5em]", style: {
4037
2737
  color: `var(${hunkContentColorName})`,
4038
- } }, currentHunk.splitInfo.plainText))));
2738
+ } }, ((_a = currentHunk.splitInfo) === null || _a === void 0 ? void 0 : _a.plainText) || currentHunk.text))));
4039
2739
  };
4040
2740
 
4041
2741
  const _DiffSplitLine = ({ index, diffFile, lineNumber }) => {
2742
+ var _a, _b;
4042
2743
  const oldLine = diffFile.getSplitLeftLine(index);
4043
2744
  const newLine = diffFile.getSplitRightLine(index);
4044
- const oldSyntaxLine = diffFile.getOldSyntaxLine(oldLine?.lineNumber);
4045
- const newSyntaxLine = diffFile.getNewSyntaxLine(newLine?.lineNumber);
4046
- const hasDiff = !!oldLine?.diff || !!newLine?.diff;
4047
- const hasChange = checkDiffLineIncludeChange(oldLine?.diff) || checkDiffLineIncludeChange(newLine?.diff);
4048
- const oldLineIsDelete = oldLine?.diff?.type === DiffLineType.Delete;
4049
- const newLineIsAdded = newLine?.diff?.type === DiffLineType.Add;
2745
+ const oldSyntaxLine = diffFile.getOldSyntaxLine(oldLine === null || oldLine === void 0 ? void 0 : oldLine.lineNumber);
2746
+ const newSyntaxLine = diffFile.getNewSyntaxLine(newLine === null || newLine === void 0 ? void 0 : newLine.lineNumber);
2747
+ const hasDiff = !!(oldLine === null || oldLine === void 0 ? void 0 : oldLine.diff) || !!(newLine === null || newLine === void 0 ? void 0 : newLine.diff);
2748
+ const hasChange = checkDiffLineIncludeChange(oldLine === null || oldLine === void 0 ? void 0 : oldLine.diff) || checkDiffLineIncludeChange(newLine === null || newLine === void 0 ? void 0 : newLine.diff);
2749
+ const oldLineIsDelete = ((_a = oldLine === null || oldLine === void 0 ? void 0 : oldLine.diff) === null || _a === void 0 ? void 0 : _a.type) === exports.DiffLineType.Delete;
2750
+ const newLineIsAdded = ((_b = newLine === null || newLine === void 0 ? void 0 : newLine.diff) === null || _b === void 0 ? void 0 : _b.type) === exports.DiffLineType.Add;
4050
2751
  const { useDiffContext } = useDiffViewContext();
4051
2752
  const { enableHighlight, enableAddWidget, onAddWidgetClick } = useDiffContext(React__namespace.useCallback((s) => ({
4052
2753
  enableHighlight: s.enableHighlight,
@@ -4082,7 +2783,7 @@ const _DiffSplitLine = ({ index, diffFile, lineNumber }) => {
4082
2783
  const DiffSplitLine = ({ index, diffFile, lineNumber, }) => {
4083
2784
  const oldLine = diffFile.getSplitLeftLine(index);
4084
2785
  const newLine = diffFile.getSplitRightLine(index);
4085
- if (oldLine?.isHidden && newLine?.isHidden)
2786
+ if ((oldLine === null || oldLine === void 0 ? void 0 : oldLine.isHidden) && (newLine === null || newLine === void 0 ? void 0 : newLine.isHidden))
4086
2787
  return null;
4087
2788
  return React__namespace.createElement(_DiffSplitLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
4088
2789
  };
@@ -4100,7 +2801,7 @@ const _DiffSplitWidgetLine = ({ index, diffFile, lineNumber, }) => {
4100
2801
  return null;
4101
2802
  return (React__namespace.createElement("tr", { "data-line": `${lineNumber}-widget`, "data-state": "widget", className: "diff-line diff-line-widget" },
4102
2803
  oldLineWidget ? (React__namespace.createElement("td", { className: "diff-line-widget-old-content p-0", colSpan: 2 },
4103
- React__namespace.createElement("div", { className: "diff-line-widget-wrapper" }, renderWidgetLine?.({
2804
+ React__namespace.createElement("div", { className: "diff-line-widget-wrapper" }, renderWidgetLine === null || renderWidgetLine === void 0 ? void 0 : renderWidgetLine({
4104
2805
  diffFile,
4105
2806
  side: exports.SplitSide.old,
4106
2807
  lineNumber: oldLine.lineNumber,
@@ -4108,7 +2809,7 @@ const _DiffSplitWidgetLine = ({ index, diffFile, lineNumber, }) => {
4108
2809
  })))) : (React__namespace.createElement("td", { className: "diff-line-widget-old-placeholder p-0 select-none", style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 },
4109
2810
  React__namespace.createElement("span", null, "\u2002"))),
4110
2811
  newLineWidget ? (React__namespace.createElement("td", { className: "diff-line-widget-new-content p-0 border-l-[1px] border-l-[#ccc]", colSpan: 2 },
4111
- React__namespace.createElement("div", { className: "diff-line-widget-wrapper" }, renderWidgetLine?.({
2812
+ React__namespace.createElement("div", { className: "diff-line-widget-wrapper" }, renderWidgetLine === null || renderWidgetLine === void 0 ? void 0 : renderWidgetLine({
4112
2813
  diffFile,
4113
2814
  side: exports.SplitSide.new,
4114
2815
  lineNumber: newLine.lineNumber,
@@ -4170,10 +2871,11 @@ const DiffSplitViewWrap = React.memo(({ diffFile }) => {
4170
2871
  }
4171
2872
  }
4172
2873
  }, [setSelectSide]);
4173
- const width = useTextWidth({
2874
+ const _width = useTextWidth({
4174
2875
  text: splitLineLength.toString(),
4175
2876
  font: { fontSize: fontSize + "px", fontFamily: "Menlo, Consolas, monospace" },
4176
2877
  });
2878
+ const width = Math.max(40, _width + 25);
4177
2879
  const lines = getSplitContentLines(diffFile);
4178
2880
  return (React__namespace.createElement("div", { className: "split-diff-view split-diff-view-normal w-full" },
4179
2881
  React__namespace.createElement("div", { className: "diff-table-wrapper w-full", style: {
@@ -4183,9 +2885,9 @@ const DiffSplitViewWrap = React.memo(({ diffFile }) => {
4183
2885
  React__namespace.createElement(Style, { useSelector: splitSideInfo, id: `diff-root${diffFile.getId()}` }),
4184
2886
  React__namespace.createElement("table", { className: "diff-table border-collapse table-fixed w-full" },
4185
2887
  React__namespace.createElement("colgroup", null,
4186
- React__namespace.createElement("col", { className: "diff-table-old-num-col", width: Math.round(width) + 25 }),
2888
+ React__namespace.createElement("col", { className: "diff-table-old-num-col", width: Math.round(width) }),
4187
2889
  React__namespace.createElement("col", { className: "diff-table-old-content-col" }),
4188
- React__namespace.createElement("col", { className: "diff-table-new-num-col", width: Math.round(width) + 25 }),
2890
+ React__namespace.createElement("col", { className: "diff-table-new-num-col", width: Math.round(width) }),
4189
2891
  React__namespace.createElement("col", { className: "diff-table-new-content-col" })),
4190
2892
  React__namespace.createElement("thead", { className: "hidden" },
4191
2893
  React__namespace.createElement("tr", null,
@@ -4233,8 +2935,8 @@ const _DiffUnifiedExtendLine = ({ index, diffFile, lineNumber, }) => {
4233
2935
  const { useDiffContext } = useDiffViewContext();
4234
2936
  const renderExtendLine = useDiffContext(React.useCallback((s) => s.renderExtendLine, []));
4235
2937
  const unifiedItem = diffFile.getUnifiedLine(index);
4236
- const oldExtend = useDiffContext(React.useCallback((s) => s.extendData?.oldFile?.[unifiedItem?.oldLineNumber], [unifiedItem?.oldLineNumber]));
4237
- const newExtend = useDiffContext(React.useCallback((s) => s.extendData?.newFile?.[unifiedItem?.newLineNumber], [unifiedItem?.newLineNumber]));
2938
+ const oldExtend = useDiffContext(React.useCallback((s) => { var _a, _b; return (_b = (_a = s.extendData) === null || _a === void 0 ? void 0 : _a.oldFile) === null || _b === void 0 ? void 0 : _b[unifiedItem === null || unifiedItem === void 0 ? void 0 : unifiedItem.oldLineNumber]; }, [unifiedItem === null || unifiedItem === void 0 ? void 0 : unifiedItem.oldLineNumber]));
2939
+ const newExtend = useDiffContext(React.useCallback((s) => { var _a, _b; return (_b = (_a = s.extendData) === null || _a === void 0 ? void 0 : _a.newFile) === null || _b === void 0 ? void 0 : _b[unifiedItem === null || unifiedItem === void 0 ? void 0 : unifiedItem.newLineNumber]; }, [unifiedItem === null || unifiedItem === void 0 ? void 0 : unifiedItem.newLineNumber]));
4238
2940
  const width = useDomWidth({
4239
2941
  selector: ".unified-diff-table-wrapper",
4240
2942
  enable: typeof renderExtendLine === "function",
@@ -4246,37 +2948,39 @@ const _DiffUnifiedExtendLine = ({ index, diffFile, lineNumber, }) => {
4246
2948
  React__namespace.createElement("div", { className: "diff-line-extend-wrapper sticky left-0", style: { width } },
4247
2949
  width > 0 &&
4248
2950
  oldExtend &&
4249
- renderExtendLine?.({
2951
+ (renderExtendLine === null || renderExtendLine === void 0 ? void 0 : renderExtendLine({
4250
2952
  diffFile,
4251
2953
  side: exports.SplitSide.old,
4252
2954
  lineNumber: unifiedItem.oldLineNumber,
4253
2955
  data: oldExtend.data,
4254
2956
  onUpdate: diffFile.notifyAll,
4255
- }),
2957
+ })),
4256
2958
  width > 0 &&
4257
2959
  newExtend &&
4258
- renderExtendLine?.({
2960
+ (renderExtendLine === null || renderExtendLine === void 0 ? void 0 : renderExtendLine({
4259
2961
  diffFile,
4260
2962
  side: exports.SplitSide.new,
4261
2963
  lineNumber: unifiedItem.newLineNumber,
4262
2964
  data: newExtend.data,
4263
2965
  onUpdate: diffFile.notifyAll,
4264
- })))));
2966
+ }))))));
4265
2967
  };
4266
2968
  const DiffUnifiedExtendLine = ({ index, diffFile, lineNumber, }) => {
4267
2969
  const { useDiffContext } = useDiffViewContext();
4268
2970
  const unifiedItem = diffFile.getUnifiedLine(index);
4269
- const hasExtend = useDiffContext(React.useCallback((s) => s.extendData?.oldFile?.[unifiedItem?.oldLineNumber] || s.extendData?.newFile?.[unifiedItem?.newLineNumber], [unifiedItem.oldLineNumber, unifiedItem.newLineNumber]));
2971
+ const hasExtend = useDiffContext(React.useCallback((s) => { var _a, _b, _c, _d; return ((_b = (_a = s.extendData) === null || _a === void 0 ? void 0 : _a.oldFile) === null || _b === void 0 ? void 0 : _b[unifiedItem === null || unifiedItem === void 0 ? void 0 : unifiedItem.oldLineNumber]) || ((_d = (_c = s.extendData) === null || _c === void 0 ? void 0 : _c.newFile) === null || _d === void 0 ? void 0 : _d[unifiedItem === null || unifiedItem === void 0 ? void 0 : unifiedItem.newLineNumber]); }, [unifiedItem.oldLineNumber, unifiedItem.newLineNumber]));
4270
2972
  if (!hasExtend || !unifiedItem || unifiedItem.isHidden || !unifiedItem.diff)
4271
2973
  return null;
4272
2974
  return React__namespace.createElement(_DiffUnifiedExtendLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
4273
2975
  };
4274
2976
 
4275
2977
  const _DiffUnifiedHunkLine = ({ index, diffFile, lineNumber, }) => {
2978
+ var _a;
4276
2979
  const currentHunk = diffFile.getUnifiedHunkLine(index);
4277
2980
  const expandEnabled = diffFile.getExpandEnabled();
4278
2981
  const { useDiffContext } = useDiffViewContext();
4279
2982
  const enableWrap = useDiffContext(React.useCallback((s) => s.enableWrap, []));
2983
+ const couldExpand = expandEnabled && currentHunk && currentHunk.unifiedInfo;
4280
2984
  const isExpandAll = currentHunk &&
4281
2985
  currentHunk.unifiedInfo &&
4282
2986
  currentHunk.unifiedInfo.endHiddenIndex - currentHunk.unifiedInfo.startHiddenIndex < composeLen;
@@ -4286,7 +2990,10 @@ const _DiffUnifiedHunkLine = ({ index, diffFile, lineNumber, }) => {
4286
2990
  React__namespace.createElement("td", { className: "diff-line-hunk-action sticky left-0 p-[1px] w-[1%] min-w-[100px] select-none", style: {
4287
2991
  backgroundColor: `var(${hunkLineNumberBGName})`,
4288
2992
  color: `var(${plainLineNumberColorName})`,
4289
- } }, expandEnabled ? (isFirstLine ? (React__namespace.createElement("button", { className: "w-full diff-widget-tooltip hover:bg-blue-300 flex justify-center items-center py-[6px] cursor-pointer rounded-[2px]", title: "Expand Up", "data-title": "Expand Up", onClick: () => diffFile.onUnifiedHunkExpand("up", index) },
2993
+ width: `calc(calc(var(${asideWidth}) + 5px) * 2)`,
2994
+ maxWidth: `calc(calc(var(${asideWidth}) + 5px) * 2)`,
2995
+ minWidth: `calc(calc(var(${asideWidth}) + 5px) * 2)`,
2996
+ } }, couldExpand ? (isFirstLine ? (React__namespace.createElement("button", { className: "w-full diff-widget-tooltip hover:bg-blue-300 flex justify-center items-center py-[6px] cursor-pointer rounded-[2px]", title: "Expand Up", "data-title": "Expand Up", onClick: () => diffFile.onUnifiedHunkExpand("up", index) },
4290
2997
  React__namespace.createElement(ExpandUp, { className: "fill-current" }))) : isLastLine ? (React__namespace.createElement("button", { className: "w-full diff-widget-tooltip hover:bg-blue-300 flex justify-center items-center py-[6px] cursor-pointer rounded-[2px]", title: "Expand Down", "data-title": "Expand Down", onClick: () => diffFile.onUnifiedHunkExpand("down", index) },
4291
2998
  React__namespace.createElement(ExpandDown, { className: "fill-current" }))) : isExpandAll ? (React__namespace.createElement("button", { className: "w-full diff-widget-tooltip hover:bg-blue-300 flex justify-center items-center py-[6px] cursor-pointer rounded-[2px]", title: "Expand All", "data-title": "Expand All", onClick: () => diffFile.onUnifiedHunkExpand("all", index) },
4292
2999
  React__namespace.createElement(ExpandAll, { className: "fill-current" }))) : (React__namespace.createElement(React__namespace.Fragment, null,
@@ -4299,14 +3006,15 @@ const _DiffUnifiedHunkLine = ({ index, diffFile, lineNumber, }) => {
4299
3006
  whiteSpace: enableWrap ? "pre-wrap" : "pre",
4300
3007
  wordBreak: enableWrap ? "break-all" : "initial",
4301
3008
  color: `var(${hunkContentColorName})`,
4302
- } }, currentHunk.unifiedInfo.plainText))));
3009
+ } }, ((_a = currentHunk.unifiedInfo) === null || _a === void 0 ? void 0 : _a.plainText) || currentHunk.text))));
4303
3010
  };
4304
3011
  const DiffUnifiedHunkLine = ({ index, diffFile, lineNumber, }) => {
4305
3012
  const currentHunk = diffFile.getUnifiedHunkLine(index);
4306
3013
  const currentIsShow = currentHunk &&
4307
3014
  currentHunk.unifiedInfo &&
4308
3015
  currentHunk.unifiedInfo.startHiddenIndex < currentHunk.unifiedInfo.endHiddenIndex;
4309
- if (!currentIsShow)
3016
+ const currentIsPureHunk = currentHunk && diffFile._getIsPureDiffRender() && !currentHunk.unifiedInfo;
3017
+ if (!currentIsShow && !currentIsPureHunk)
4310
3018
  return null;
4311
3019
  return React__namespace.createElement(_DiffUnifiedHunkLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
4312
3020
  };
@@ -4316,6 +3024,9 @@ const DiffUnifiedOldLine = ({ index, diffLine, rawLine, syntaxLine, lineNumber,
4316
3024
  React__namespace.createElement("td", { className: "diff-line-num sticky left-0 pl-[10px] pr-[10px] text-right select-none w-[1%] min-w-[100px] whitespace-nowrap align-top", style: {
4317
3025
  color: `var(${plainLineNumberColorName})`,
4318
3026
  backgroundColor: `var(${delLineNumberBGName})`,
3027
+ width: `calc(calc(var(${asideWidth}) + 5px) * 2)`,
3028
+ maxWidth: `calc(calc(var(${asideWidth}) + 5px) * 2)`,
3029
+ minWidth: `calc(calc(var(${asideWidth}) + 5px) * 2)`,
4319
3030
  } },
4320
3031
  enableAddWidget && (React__namespace.createElement(DiffUnifiedAddWidget, { index: index - 1, lineNumber: lineNumber, diffFile: diffFile, side: exports.SplitSide.old, onWidgetClick: onAddWidgetClick, onOpenAddWidget: (lineNumber, side) => setWidget({ lineNumber, side }) })),
4321
3032
  React__namespace.createElement("div", { className: "flex" },
@@ -4330,6 +3041,9 @@ const DiffUnifiedNewLine = ({ index, diffLine, rawLine, syntaxLine, lineNumber,
4330
3041
  React__namespace.createElement("td", { className: "diff-line-num sticky left-0 pl-[10px] pr-[10px] text-right select-none w-[1%] min-w-[100px] whitespace-nowrap align-top", style: {
4331
3042
  color: `var(${plainLineNumberColorName})`,
4332
3043
  backgroundColor: `var(${addLineNumberBGName})`,
3044
+ width: `calc(calc(var(${asideWidth}) + 5px) * 2)`,
3045
+ maxWidth: `calc(calc(var(${asideWidth}) + 5px) * 2)`,
3046
+ minWidth: `calc(calc(var(${asideWidth}) + 5px) * 2)`,
4333
3047
  } },
4334
3048
  enableAddWidget && (React__namespace.createElement(DiffUnifiedAddWidget, { index: index - 1, lineNumber: lineNumber, diffFile: diffFile, side: exports.SplitSide.new, onWidgetClick: onAddWidgetClick, onOpenAddWidget: (lineNumber, side) => setWidget({ lineNumber, side }) })),
4335
3049
  React__namespace.createElement("div", { className: "flex" },
@@ -4373,6 +3087,9 @@ const _DiffUnifiedLine = React.memo(({ index, diffFile, lineNumber }) => {
4373
3087
  return (React__namespace.createElement("tr", { "data-line": lineNumber, "data-state": unifiedLine.diff ? "diff" : "plain", className: "diff-line group" },
4374
3088
  React__namespace.createElement("td", { className: "diff-line-num sticky left-0 pl-[10px] pr-[10px] text-right select-none w-[1%] min-w-[100px] whitespace-nowrap align-top", style: {
4375
3089
  color: `var(${plainLineNumberColorName})`,
3090
+ width: `calc(calc(var(${asideWidth}) + 5px) * 2)`,
3091
+ maxWidth: `calc(calc(var(${asideWidth}) + 5px) * 2)`,
3092
+ minWidth: `calc(calc(var(${asideWidth}) + 5px) * 2)`,
4376
3093
  backgroundColor: hasDiff ? `var(${plainLineNumberBGName})` : `var(${expandContentBGName})`,
4377
3094
  } },
4378
3095
  enableAddWidget && hasDiff && (React__namespace.createElement(DiffUnifiedAddWidget, { index: index, diffFile: diffFile, lineNumber: unifiedLine.newLineNumber, side: exports.SplitSide.new, onWidgetClick: onAddWidgetClick, onOpenAddWidget: (lineNumber, side) => setWidget({ lineNumber, side }) })),
@@ -4389,7 +3106,7 @@ const _DiffUnifiedLine = React.memo(({ index, diffFile, lineNumber }) => {
4389
3106
  _DiffUnifiedLine.displayName = "_DiffUnifiedLine";
4390
3107
  const DiffUnifiedLine = ({ index, diffFile, lineNumber, }) => {
4391
3108
  const unifiedLine = diffFile.getUnifiedLine(index);
4392
- if (unifiedLine?.isHidden)
3109
+ if (unifiedLine === null || unifiedLine === void 0 ? void 0 : unifiedLine.isHidden)
4393
3110
  return null;
4394
3111
  return React__namespace.createElement(_DiffUnifiedLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
4395
3112
  };
@@ -4411,10 +3128,10 @@ const _DiffUnifiedWidgetLine = ({ index, diffFile, oldWidget, newWidget, lineNum
4411
3128
  React__namespace.createElement("div", { className: "diff-line-widget-wrapper sticky left-0", style: { width } },
4412
3129
  width > 0 &&
4413
3130
  oldWidget &&
4414
- renderWidgetLine?.({ diffFile, side: exports.SplitSide.old, lineNumber: unifiedItem.oldLineNumber, onClose }),
3131
+ (renderWidgetLine === null || renderWidgetLine === void 0 ? void 0 : renderWidgetLine({ diffFile, side: exports.SplitSide.old, lineNumber: unifiedItem.oldLineNumber, onClose })),
4415
3132
  width > 0 &&
4416
3133
  newWidget &&
4417
- renderWidgetLine?.({ diffFile, side: exports.SplitSide.new, lineNumber: unifiedItem.newLineNumber, onClose })))));
3134
+ (renderWidgetLine === null || renderWidgetLine === void 0 ? void 0 : renderWidgetLine({ diffFile, side: exports.SplitSide.new, lineNumber: unifiedItem.newLineNumber, onClose }))))));
4418
3135
  };
4419
3136
  const DiffUnifiedWidgetLine = ({ index, diffFile, lineNumber, }) => {
4420
3137
  const { useWidget } = useDiffWidgetContext();
@@ -4428,6 +3145,7 @@ const DiffUnifiedWidgetLine = ({ index, diffFile, lineNumber, }) => {
4428
3145
  return (React__namespace.createElement(_DiffUnifiedWidgetLine, { index: index, diffFile: diffFile, lineNumber: lineNumber, oldWidget: oldWidget, newWidget: newWidget, setWidget: setWidget }));
4429
3146
  };
4430
3147
 
3148
+ /* eslint-disable @typescript-eslint/ban-ts-comment */
4431
3149
  const onMouseDown = (e) => {
4432
3150
  const ele = e.target;
4433
3151
  // need remove all the selection
@@ -4452,15 +3170,27 @@ const DiffUnifiedView = React.memo(({ diffFile }) => {
4452
3170
  return { widgetSide, widgetLineNumber, setWidget };
4453
3171
  }), [useDiffContext]);
4454
3172
  const contextValue = React.useMemo(() => ({ useWidget }), [useWidget]);
3173
+ const fontSize = useDiffContext(React.useCallback((s) => s.fontSize, []));
4455
3174
  shim.useSyncExternalStore(diffFile.subscribe, diffFile.getUpdateCount);
4456
3175
  React.useEffect(() => {
4457
3176
  const { setWidget } = useWidget.getReadonlyState();
4458
3177
  setWidget({});
4459
3178
  }, [diffFile, useWidget]);
3179
+ const unifiedLineLength = diffFile.unifiedLineLength;
3180
+ const _width = useTextWidth({
3181
+ text: unifiedLineLength.toString(),
3182
+ font: { fontSize: fontSize + "px", fontFamily: "Menlo, Consolas, monospace" },
3183
+ });
3184
+ const width = Math.max(40, _width + 25);
4460
3185
  const lines = getUnifiedContentLine(diffFile);
4461
3186
  return (React__namespace.createElement(DiffWidgetContext.Provider, { value: contextValue },
4462
3187
  React__namespace.createElement("div", { className: "unified-diff-view w-full" },
4463
- React__namespace.createElement("div", { className: "unified-diff-table-wrapper overflow-auto w-full scrollbar-hide scrollbar-disable", style: { fontFamily: "Menlo, Consolas, monospace", fontSize: "var(--diff-font-size--)" } },
3188
+ React__namespace.createElement("div", { className: "unified-diff-table-wrapper overflow-auto w-full scrollbar-hide scrollbar-disable", style: {
3189
+ // @ts-ignore
3190
+ [asideWidth]: `${Math.round(width)}px`,
3191
+ fontFamily: "Menlo, Consolas, monospace",
3192
+ fontSize: "var(--diff-font-size--)",
3193
+ } },
4464
3194
  React__namespace.createElement("table", { className: "unified-diff-table border-collapse w-full" },
4465
3195
  React__namespace.createElement("colgroup", null,
4466
3196
  React__namespace.createElement("col", { className: "unified-diff-table-num-col" }),
@@ -4469,7 +3199,7 @@ const DiffUnifiedView = React.memo(({ diffFile }) => {
4469
3199
  React__namespace.createElement("tr", null,
4470
3200
  React__namespace.createElement("th", { scope: "col" }, "line number"),
4471
3201
  React__namespace.createElement("th", { scope: "col" }, "line content"))),
4472
- React__namespace.createElement("tbody", { className: "diff-table-body leading-[1.4]", onMouseDownCapture: onMouseDown },
3202
+ React__namespace.createElement("tbody", { className: "diff-table-body leading-[1.4]", onMouseDownCapture: onMouseDown },
4473
3203
  lines.map((item) => (React__namespace.createElement(React.Fragment, { key: item.index },
4474
3204
  React__namespace.createElement(DiffUnifiedHunkLine, { index: item.index, lineNumber: item.lineNumber, diffFile: diffFile }),
4475
3205
  React__namespace.createElement(DiffUnifiedLine, { index: item.index, lineNumber: item.lineNumber, diffFile: diffFile }),
@@ -4479,9 +3209,8 @@ const DiffUnifiedView = React.memo(({ diffFile }) => {
4479
3209
  });
4480
3210
  DiffUnifiedView.displayName = "DiffUnifiedView";
4481
3211
 
4482
- /* eslint-disable @typescript-eslint/no-unnecessary-type-constraint */
4483
- /* eslint-disable @typescript-eslint/ban-ts-comment */
4484
3212
  const diffFontSizeName = "--diff-font-size--";
3213
+ _cacheMap.name = "@git-diff-view/react";
4485
3214
  exports.SplitSide = void 0;
4486
3215
  (function (SplitSide) {
4487
3216
  SplitSide[SplitSide["old"] = 1] = "old";
@@ -4492,6 +3221,7 @@ const _InternalDiffView = (props) => {
4492
3221
  const diffFileId = React.useMemo(() => diffFile.getId(), [diffFile]);
4493
3222
  // performance optimization
4494
3223
  const useDiffContext = React.useMemo(() => reactivityStore.createStore(() => {
3224
+ var _a, _b;
4495
3225
  const id = reactivityStore.ref(diffFileId);
4496
3226
  const setId = (_id) => (id.value = _id);
4497
3227
  const mode = reactivityStore.ref(props.diffViewMode);
@@ -4505,8 +3235,8 @@ const _InternalDiffView = (props) => {
4505
3235
  const fontSize = reactivityStore.ref(props.diffViewFontSize);
4506
3236
  const setFontSize = (_fontSize) => (fontSize.value = _fontSize);
4507
3237
  const extendData = reactivityStore.ref({
4508
- oldFile: { ...props.extendData?.oldFile },
4509
- newFile: { ...props.extendData?.newFile },
3238
+ oldFile: Object.assign({}, (_a = props.extendData) === null || _a === void 0 ? void 0 : _a.oldFile),
3239
+ newFile: Object.assign({}, (_b = props.extendData) === null || _b === void 0 ? void 0 : _b.newFile),
4510
3240
  });
4511
3241
  const setExtendData = (_extendData) => {
4512
3242
  const existOldKeys = Object.keys(extendData.value.oldFile || {});
@@ -4588,7 +3318,7 @@ const _InternalDiffView = (props) => {
4588
3318
  ]);
4589
3319
  const value = React.useMemo(() => ({ useDiffContext }), [useDiffContext]);
4590
3320
  return (React__namespace.createElement(DiffViewContext.Provider, { value: value },
4591
- React__namespace.createElement("div", { className: "diff-tailwindcss-wrapper", "data-component": "git-diff-view", "data-version": `${"0.0.6"}` },
3321
+ React__namespace.createElement("div", { className: "diff-tailwindcss-wrapper", "data-component": "git-diff-view", "data-version": `${"0.0.8"}` },
4592
3322
  React__namespace.createElement("div", { className: "diff-style-root", style: {
4593
3323
  // @ts-ignore
4594
3324
  [diffFontSizeName]: diffViewFontSize + "px",
@@ -4597,15 +3327,16 @@ const _InternalDiffView = (props) => {
4597
3327
  };
4598
3328
  const InternalDiffView = React.memo(_InternalDiffView);
4599
3329
  const DiffViewWithRef = (props, ref) => {
4600
- const { registerHighlighter, autoDetectLang, data, diffFile: _diffFile, ...restProps } = props;
3330
+ const { registerHighlighter, autoDetectLang, data, diffFile: _diffFile } = props, restProps = __rest(props, ["registerHighlighter", "autoDetectLang", "data", "diffFile"]);
4601
3331
  const diffFile = React.useMemo(() => {
3332
+ var _a, _b, _c, _d, _e, _f;
4602
3333
  if (_diffFile) {
4603
3334
  const diffFile = DiffFile.createInstance({});
4604
3335
  diffFile._mergeFullBundle(_diffFile._getFullBundle());
4605
3336
  return diffFile;
4606
3337
  }
4607
3338
  else if (data) {
4608
- return new DiffFile(data?.oldFile?.fileName || "", data?.oldFile?.content || "", data?.newFile?.fileName || "", data?.newFile?.content || "", data?.hunks || [], data?.oldFile?.fileLang || "", data?.newFile?.fileLang || "");
3339
+ 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) || "");
4609
3340
  }
4610
3341
  return null;
4611
3342
  }, [data, _diffFile]);
@@ -4636,14 +3367,36 @@ const DiffViewWithRef = (props, ref) => {
4636
3367
  React.useImperativeHandle(ref, () => ({ getDiffFileInstance: () => diffFile }), [diffFile]);
4637
3368
  if (!diffFile)
4638
3369
  return null;
4639
- return (React__namespace.createElement(InternalDiffView, { key: diffFile.getId(), ...restProps, diffFile: diffFile, diffViewFontSize: restProps.diffViewFontSize || 14 }));
3370
+ return (React__namespace.createElement(InternalDiffView, Object.assign({ key: diffFile.getId() }, restProps, { diffFile: diffFile, diffViewFontSize: restProps.diffViewFontSize || 14 })));
4640
3371
  };
4641
3372
  const DiffView = React.forwardRef(DiffViewWithRef);
4642
3373
  DiffView.displayName = "DiffView";
4643
- const version = "0.0.6";
3374
+ const version = "0.0.8";
4644
3375
 
3376
+ exports.DefaultDiffExpansionStep = DefaultDiffExpansionStep;
3377
+ exports.DiffFile = DiffFile;
3378
+ exports.DiffLine = DiffLine;
4645
3379
  exports.DiffView = DiffView;
4646
3380
  exports.DiffViewContext = DiffViewContext;
3381
+ exports.File = File;
3382
+ exports._cacheMap = _cacheMap;
3383
+ exports.assertNever = assertNever;
3384
+ exports.checkDiffLineIncludeChange = checkDiffLineIncludeChange;
3385
+ exports.composeLen = composeLen;
3386
+ exports.getDiffRange = getDiffRange;
3387
+ exports.getFile = getFile;
3388
+ exports.getHunkHeaderExpansionType = getHunkHeaderExpansionType;
3389
+ exports.getLang = getLang;
3390
+ exports.getLargestLineNumber = getLargestLineNumber;
3391
+ exports.getSplitContentLines = getSplitContentLines;
3392
+ exports.getSplitLines = getSplitLines;
3393
+ exports.getUnifiedContentLine = getUnifiedContentLine;
3394
+ exports.getUnifiedLines = getUnifiedLines;
3395
+ exports.hasRelativeChange = hasRelativeChange;
3396
+ exports.highlighter = highlighter;
3397
+ exports.numIterator = numIterator;
3398
+ exports.relativeChanges = relativeChanges;
4647
3399
  exports.useDiffViewContext = useDiffViewContext;
4648
3400
  exports.version = version;
3401
+ exports.versions = versions;
4649
3402
  //# sourceMappingURL=index.development.js.map