@noldova/code.editor.diff 0.0.0-stage → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/api/index.d.ts ADDED
@@ -0,0 +1,678 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+
9
+ import "@noldova/context.core";
10
+ import type { DiffSpan, EditorRegistries, IBackgroundJob, IBackgroundRunner, IDiffAlgorithm, IEditorContribution, SlicedRunner, TextDocument, TextRange } from "@noldova/code.editor";
11
+ import type { IReadOnlyList } from "@noldova/context.collections";
12
+
13
+ /**
14
+ * Names one side of a two-document comparison.
15
+ */
16
+ export declare enum DiffSide {
17
+ /**
18
+ * The original, left-hand document.
19
+ */
20
+ Original = "Original",
21
+ /**
22
+ * The modified, right-hand document.
23
+ */
24
+ Modified = "Modified"
25
+ }
26
+
27
+ /**
28
+ * The character ranges that differ inside one changed block of lines, on
29
+ * each side of a comparison.
30
+ *
31
+ * @remarks
32
+ * {@link DocumentDiff} produces it for a {@link LineChange}. Both lists are
33
+ * empty when either side of the block has no lines or the block is too large
34
+ * for a character comparison.
35
+ */
36
+ export declare class ChangeRanges {
37
+ /**
38
+ * The ranges in the original document that were removed or replaced, in
39
+ * document order.
40
+ */
41
+ readonly original: IReadOnlyList<TextRange>;
42
+ /**
43
+ * The ranges in the modified document that were inserted or replaced, in
44
+ * document order.
45
+ */
46
+ readonly modified: IReadOnlyList<TextRange>;
47
+ /**
48
+ * Creates a pair of range lists. The lists are stored as given, not copied.
49
+ *
50
+ * @param original The changed ranges in the original document.
51
+ * @param modified The changed ranges in the modified document.
52
+ * @example
53
+ * ```ts
54
+ * import { TextRange } from "@noldova/code.editor";
55
+ * import { ChangeRanges } from "@noldova/code.editor.diff";
56
+ * import { List } from "@noldova/context.collections";
57
+ *
58
+ * const ranges = new ChangeRanges(new List([TextRange.of(0, 4, 0, 7)]), new List([TextRange.of(0, 4, 0, 9)]));
59
+ * ranges.modified.count(); // 1
60
+ * ```
61
+ */
62
+ constructor(original: IReadOnlyList<TextRange>, modified: IReadOnlyList<TextRange>);
63
+ }
64
+
65
+ /**
66
+ * One changed block of lines between an original and a modified document.
67
+ *
68
+ * @remarks
69
+ * Lines are zero-based and each end is exclusive. An empty range on one side
70
+ * means lines were only inserted or only removed, and its start is where they
71
+ * would go.
72
+ */
73
+ export declare class LineChange {
74
+ /**
75
+ * The change's zero-based position in its list of changes.
76
+ */
77
+ readonly index: number;
78
+ /**
79
+ * The first original line of the block.
80
+ */
81
+ readonly originalStart: number;
82
+ /**
83
+ * The original line after the block's last line.
84
+ */
85
+ readonly originalEnd: number;
86
+ /**
87
+ * The first modified line of the block.
88
+ */
89
+ readonly modifiedStart: number;
90
+ /**
91
+ * The modified line after the block's last line.
92
+ */
93
+ readonly modifiedEnd: number;
94
+ /**
95
+ * Creates a line change. The values are stored as given, not checked.
96
+ *
97
+ * @param index The change's zero-based position in its list.
98
+ * @param originalStart The first original line, zero-based.
99
+ * @param originalEnd The original end line, exclusive.
100
+ * @param modifiedStart The first modified line, zero-based.
101
+ * @param modifiedEnd The modified end line, exclusive.
102
+ * @example
103
+ * ```ts
104
+ * import { LineChange } from "@noldova/code.editor.diff";
105
+ *
106
+ * const change = new LineChange(0, 2, 3, 2, 5);
107
+ * change.originalLength; // 1
108
+ * change.modifiedLength; // 3
109
+ * ```
110
+ */
111
+ constructor(index: number, originalStart: number, originalEnd: number, modifiedStart: number, modifiedEnd: number);
112
+ /**
113
+ * The number of original lines in the block; zero for a pure insertion.
114
+ */
115
+ get originalLength(): number;
116
+ /**
117
+ * The number of modified lines in the block; zero for a pure removal.
118
+ */
119
+ get modifiedLength(): number;
120
+ /**
121
+ * Gives the block's first line on one side.
122
+ *
123
+ * @param side The side to read.
124
+ * @returns {@link LineChange.originalStart} for {@link DiffSide.Original},
125
+ * otherwise {@link LineChange.modifiedStart}.
126
+ * @example
127
+ * ```ts
128
+ * import { DiffSide, LineChange } from "@noldova/code.editor.diff";
129
+ *
130
+ * new LineChange(0, 2, 3, 4, 6).startOf(DiffSide.Modified); // 4
131
+ * ```
132
+ */
133
+ startOf(side: DiffSide): number;
134
+ /**
135
+ * Gives the block's exclusive end line on one side.
136
+ *
137
+ * @param side The side to read.
138
+ * @returns {@link LineChange.originalEnd} for {@link DiffSide.Original},
139
+ * otherwise {@link LineChange.modifiedEnd}.
140
+ * @example
141
+ * ```ts
142
+ * import { DiffSide, LineChange } from "@noldova/code.editor.diff";
143
+ *
144
+ * new LineChange(0, 2, 3, 4, 6).endOf(DiffSide.Original); // 3
145
+ * ```
146
+ */
147
+ endOf(side: DiffSide): number;
148
+ }
149
+
150
+ /**
151
+ * A run of lines that are the same on both sides of a comparison, which a diff
152
+ * view may fold. {@link DocumentDiff.unchangedRegions} produces them.
153
+ * Immutable.
154
+ *
155
+ * @example
156
+ * ```ts
157
+ * import { UnchangedRegion } from "@noldova/code.editor.diff";
158
+ *
159
+ * const region = new UnchangedRegion(10, 12, 40);
160
+ * ```
161
+ */
162
+ export declare class UnchangedRegion {
163
+ /**
164
+ * The region's first zero-based line in the original text.
165
+ */
166
+ readonly originalStart: number;
167
+
168
+ /**
169
+ * The region's first zero-based line in the modified text.
170
+ */
171
+ readonly modifiedStart: number;
172
+
173
+ /**
174
+ * The number of lines in the region, the same on both sides.
175
+ */
176
+ readonly length: number;
177
+
178
+ /**
179
+ * Creates a region. Nothing is checked.
180
+ *
181
+ * @param originalStart The first zero-based line in the original text.
182
+ * @param modifiedStart The first zero-based line in the modified text.
183
+ * @param length The number of lines in the region.
184
+ * @example
185
+ * ```ts
186
+ * import { UnchangedRegion } from "@noldova/code.editor.diff";
187
+ *
188
+ * const region = new UnchangedRegion(0, 0, 25);
189
+ * ```
190
+ */
191
+ constructor(originalStart: number, modifiedStart: number, length: number);
192
+ }
193
+
194
+ /**
195
+ * Packs line changes into a flat `Int32Array` and back, so they can cross a
196
+ * worker boundary as a transferable buffer.
197
+ *
198
+ * @example
199
+ * ```ts
200
+ * import { LineChange, LineChangeCodec } from "@noldova/code.editor.diff";
201
+ * import { List } from "@noldova/context.collections";
202
+ *
203
+ * const values = LineChangeCodec.encode(new List([new LineChange(0, 1, 2, 1, 3)]));
204
+ * LineChangeCodec.decode(values).get(0).modifiedEnd; // 3
205
+ * ```
206
+ */
207
+ export declare class LineChangeCodec {
208
+ /**
209
+ * The values packed for each change: 4.
210
+ */
211
+ static readonly width: number;
212
+
213
+ /**
214
+ * Packs line changes, or any diff ranges.
215
+ *
216
+ * @param changes The changes, in order.
217
+ * @returns Four values per change, in order: original start, original end,
218
+ * modified start, modified end. Each change's index is not kept.
219
+ * @example
220
+ * ```ts
221
+ * import { LineChange, LineChangeCodec } from "@noldova/code.editor.diff";
222
+ * import { List } from "@noldova/context.collections";
223
+ *
224
+ * LineChangeCodec.encode(new List([new LineChange(0, 1, 2, 1, 3)])); // Int32Array [1, 2, 1, 3]
225
+ * ```
226
+ */
227
+ static encode(changes: IReadOnlyList<DiffSpan>): Int32Array;
228
+
229
+ /**
230
+ * Packs some of the changes into values made for all of them, so that a
231
+ * long list can be packed a slice at a time.
232
+ *
233
+ * @param values Four values per change of the whole list.
234
+ * @param changes The whole list.
235
+ * @param start The first change to pack.
236
+ * @param end The change after the last to pack.
237
+ * @example
238
+ * ```ts
239
+ * import { LineChange, LineChangeCodec } from "@noldova/code.editor.diff";
240
+ * import { List } from "@noldova/context.collections";
241
+ *
242
+ * const changes = new List([new LineChange(0, 1, 2, 1, 3), new LineChange(1, 5, 6, 6, 6)]);
243
+ * const values = new Int32Array(changes.count() * LineChangeCodec.width);
244
+ * LineChangeCodec.encodeInto(values, changes, 1, 2); // Int32Array [0, 0, 0, 0, 5, 6, 6, 6]
245
+ * ```
246
+ */
247
+ static encodeInto(values: Int32Array, changes: IReadOnlyList<DiffSpan>, start: number, end: number): void;
248
+
249
+ /**
250
+ * Unpacks line changes that {@link LineChangeCodec.encode} packed.
251
+ *
252
+ * @param values Four values per change; trailing values short of a full
253
+ * change are ignored.
254
+ * @returns The changes in their packed order, each indexed by its place in
255
+ * the result.
256
+ * @example
257
+ * ```ts
258
+ * import { LineChangeCodec } from "@noldova/code.editor.diff";
259
+ *
260
+ * LineChangeCodec.decode(new Int32Array([1, 2, 1, 3])).get(0).originalStart; // 1
261
+ * ```
262
+ */
263
+ static decode(values: Int32Array): IReadOnlyList<LineChange>;
264
+ }
265
+
266
+ /**
267
+ * Compares two documents line by line and keeps the result current as either
268
+ * of them is edited.
269
+ *
270
+ * @remarks
271
+ * Every comparison runs through an {@link IBackgroundRunner}: in the browser
272
+ * the diff editor passes a worker runner, and the default is a
273
+ * {@link SlicedRunner} on the calling thread. While a run is out,
274
+ * {@link DocumentDiff.pending} is true and the last changes move through each
275
+ * edit, so the marks stay on the lines they belong to while a person types.
276
+ * One run is out at a time; a result for text edited meanwhile is dropped and
277
+ * the documents are compared again. The line and character diffs come from
278
+ * an {@link IDiffAlgorithm}, `@noldova/diff` by default. On the calling
279
+ * thread the runner yields between slices around the algorithm's `lines`
280
+ * call, not inside it. Dispose the diff to stop following the documents.
281
+ *
282
+ * @example
283
+ * ```ts
284
+ * import { TextDocument } from "@noldova/code.editor";
285
+ * import { DocumentDiff } from "@noldova/code.editor.diff";
286
+ *
287
+ * using diff = new DocumentDiff(TextDocument.fromText("a\nb"), TextDocument.fromText("a\nc"));
288
+ * await diff.settledAsync();
289
+ * diff.changes.count(); // 1
290
+ * ```
291
+ */
292
+ export declare class DocumentDiff implements Disposable {
293
+ /**
294
+ * The document on the original side; the diff only reads it.
295
+ */
296
+ readonly original: TextDocument;
297
+
298
+ /**
299
+ * The document on the modified side; the diff only reads it.
300
+ */
301
+ readonly modified: TextDocument;
302
+
303
+ /**
304
+ * The algorithm that finds the changed lines and characters.
305
+ */
306
+ readonly algorithm: IDiffAlgorithm;
307
+
308
+ /**
309
+ * Starts comparing two documents and following their edits.
310
+ *
311
+ * @param original The document on the original side.
312
+ * @param modified The document on the modified side.
313
+ * @param algorithm The diff algorithm. Defaults to a
314
+ * {@link DefaultDiffAlgorithm}, which uses `@noldova/diff`.
315
+ * @param runner Where the line diff runs. Defaults to a
316
+ * {@link SlicedRunner} on the calling thread; a worker runner keeps the
317
+ * screen free while large documents are compared.
318
+ * @example
319
+ * ```ts
320
+ * import { TextDocument } from "@noldova/code.editor";
321
+ * import { DocumentDiff } from "@noldova/code.editor.diff";
322
+ *
323
+ * using diff = new DocumentDiff(TextDocument.fromText("a"), TextDocument.fromText("b"));
324
+ * ```
325
+ */
326
+ constructor(original: TextDocument, modified: TextDocument, algorithm?: IDiffAlgorithm, runner?: IBackgroundRunner);
327
+
328
+ /**
329
+ * The current changed line ranges, in document order. It is empty until the
330
+ * first run lands. A new array replaces it after each edit, moved through
331
+ * the edit, and again when the next run lands.
332
+ */
333
+ get changes(): IReadOnlyList<LineChange>;
334
+
335
+ /**
336
+ * True while a run is out, so that {@link DocumentDiff.changes} may be the
337
+ * last result moved through the edits since.
338
+ */
339
+ get pending(): boolean;
340
+
341
+ /**
342
+ * True when the last run failed, such as when its algorithm threw. The
343
+ * changes then stay as they were moved through the edits, and the next edit
344
+ * runs the diff again.
345
+ */
346
+ get failed(): boolean;
347
+
348
+ /**
349
+ * The most characters, both sides of a change together, that
350
+ * {@link DocumentDiff.rangesOf} compares; a longer change gets no
351
+ * changed-character ranges. Defaults to 20,000. Setting another value drops
352
+ * the cached ranges and tells the listeners.
353
+ */
354
+ get characterDiffLimit(): number;
355
+ set characterDiffLimit(value: number);
356
+
357
+ /**
358
+ * Waits until no run is out.
359
+ *
360
+ * @returns A promise that settles once {@link DocumentDiff.pending} is
361
+ * false or the diff is disposed; at once when no run is out.
362
+ * @example
363
+ * ```ts
364
+ * import { TextDocument } from "@noldova/code.editor";
365
+ * import { DocumentDiff } from "@noldova/code.editor.diff";
366
+ *
367
+ * using diff = new DocumentDiff(TextDocument.fromText("a"), TextDocument.fromText("b"));
368
+ * await diff.settledAsync();
369
+ * diff.pending; // false
370
+ * ```
371
+ */
372
+ settledAsync(): Promise<void>;
373
+
374
+ /**
375
+ * Finds the changed characters inside one changed line range.
376
+ *
377
+ * @param change A change from {@link DocumentDiff.changes}.
378
+ * @returns The changed character ranges on each side, cached until the
379
+ * diff next changes. Both lists are empty when either side of the
380
+ * change has no lines or the two sides together exceed {@link DocumentDiff.characterDiffLimit}.
381
+ * @example
382
+ * ```ts
383
+ * import { TextDocument } from "@noldova/code.editor";
384
+ * import { DocumentDiff } from "@noldova/code.editor.diff";
385
+ *
386
+ * using diff = new DocumentDiff(TextDocument.fromText("cat"), TextDocument.fromText("car"));
387
+ * diff.rangesOf(diff.changes.get(0)).modified; // the range 0:2 to 0:3
388
+ * ```
389
+ */
390
+ rangesOf(change: LineChange): ChangeRanges;
391
+
392
+ /**
393
+ * Finds the change that covers a line on one side.
394
+ *
395
+ * @param line The zero-based line on that side.
396
+ * @param side The side the line is on.
397
+ * @returns The change whose lines on that side include the line, or `null`
398
+ * when the line is unchanged. A change with no lines on that side covers
399
+ * nothing there.
400
+ * @example
401
+ * ```ts
402
+ * import { TextDocument } from "@noldova/code.editor";
403
+ * import { DiffSide, DocumentDiff } from "@noldova/code.editor.diff";
404
+ *
405
+ * using diff = new DocumentDiff(TextDocument.fromText("a\nb"), TextDocument.fromText("a\nc"));
406
+ * diff.changeAt(1, DiffSide.Original); // the change
407
+ * diff.changeAt(0, DiffSide.Original); // null
408
+ * ```
409
+ */
410
+ changeAt(line: number, side: DiffSide): LineChange | null;
411
+
412
+ /**
413
+ * Finds the next change, for a Next Change command.
414
+ *
415
+ * @param line The zero-based line on that side to search after.
416
+ * @param side The side the line is on.
417
+ * @returns The first change that starts after the line, or the first
418
+ * change when none does, wrapping around; `null` when there are no changes.
419
+ * @example
420
+ * ```ts
421
+ * import { TextDocument } from "@noldova/code.editor";
422
+ * import { DiffSide, DocumentDiff } from "@noldova/code.editor.diff";
423
+ *
424
+ * using diff = new DocumentDiff(TextDocument.fromText("a\nb"), TextDocument.fromText("x\nb"));
425
+ * diff.changeAfter(0, DiffSide.Modified); // the change at line 0, wrapped around
426
+ * ```
427
+ */
428
+ changeAfter(line: number, side: DiffSide): LineChange | null;
429
+
430
+ /**
431
+ * Finds the previous change, for a Previous Change command.
432
+ *
433
+ * @param line The zero-based line on that side to search before.
434
+ * @param side The side the line is on.
435
+ * @returns The last change that starts before the line, or the last change
436
+ * when none does, wrapping around; `null` when there are no changes.
437
+ * @example
438
+ * ```ts
439
+ * import { TextDocument } from "@noldova/code.editor";
440
+ * import { DiffSide, DocumentDiff } from "@noldova/code.editor.diff";
441
+ *
442
+ * using diff = new DocumentDiff(TextDocument.fromText("a\nb"), TextDocument.fromText("a\nc"));
443
+ * diff.changeBefore(5, DiffSide.Modified); // the change at line 1
444
+ * ```
445
+ */
446
+ changeBefore(line: number, side: DiffSide): LineChange | null;
447
+
448
+ /**
449
+ * Finds the runs of unchanged lines that a view can fold away.
450
+ *
451
+ * @param context The unchanged lines to keep visible next to each change.
452
+ * No lines are kept before the first change's region at the document's
453
+ * start or after the last change's region at its end.
454
+ * @param minimum The fewest lines a region must hide to be listed.
455
+ * @returns The foldable regions in document order, each with its start on
456
+ * both sides and its length in lines; empty when there are no changes.
457
+ * @example
458
+ * ```ts
459
+ * import { TextDocument } from "@noldova/code.editor";
460
+ * import { DocumentDiff } from "@noldova/code.editor.diff";
461
+ *
462
+ * const same = Array.from({ length: 10 }, (_, i) => `line ${i}`).join("\n");
463
+ * using diff = new DocumentDiff(TextDocument.fromText(same + "\nold"), TextDocument.fromText(same + "\nnew"));
464
+ * diff.unchangedRegions(3, 1); // one region hiding 7 lines from line 0
465
+ * ```
466
+ */
467
+ unchangedRegions(context: number, minimum: number): IReadOnlyList<UnchangedRegion>;
468
+
469
+ /**
470
+ * Subscribes to updates of the diff.
471
+ *
472
+ * @param listener Called after the changes are recomputed: after each edit
473
+ * to either document, and when a run lands or fails, and when the character limit changes.
474
+ * @returns A function that unsubscribes the listener.
475
+ * @example
476
+ * ```ts
477
+ * import { TextDocument } from "@noldova/code.editor";
478
+ * import { DocumentDiff } from "@noldova/code.editor.diff";
479
+ *
480
+ * using diff = new DocumentDiff(TextDocument.fromText("a"), TextDocument.fromText("b"));
481
+ * const stop = diff.onChange(() => console.log(diff.changes.count()));
482
+ * stop();
483
+ * ```
484
+ */
485
+ onChange(listener: () => void): () => void;
486
+
487
+ /**
488
+ * Stops following both documents' edits; a run still out is canceled and
489
+ * its result ignored.
490
+ *
491
+ * @example
492
+ * ```ts
493
+ * import { TextDocument } from "@noldova/code.editor";
494
+ * import { DocumentDiff } from "@noldova/code.editor.diff";
495
+ *
496
+ * const diff = new DocumentDiff(TextDocument.fromText("a"), TextDocument.fromText("b"));
497
+ * diff[Symbol.dispose]();
498
+ * ```
499
+ */
500
+ [Symbol.dispose](): void;
501
+ }
502
+
503
+ /**
504
+ * The default diff algorithm, `@noldova/diff`'s `TextDiff`.
505
+ *
506
+ * @example
507
+ * ```ts
508
+ * import { DefaultDiffAlgorithm } from "@noldova/code.editor.diff";
509
+ * import { List } from "@noldova/context.collections";
510
+ *
511
+ * new DefaultDiffAlgorithm().lines(new List(["a", "b"]), new List(["a", "c"])).count(); // 1
512
+ * ```
513
+ */
514
+ export declare class DefaultDiffAlgorithm implements IDiffAlgorithm {
515
+ /**
516
+ * `noldova.diff`.
517
+ */
518
+ readonly id: string;
519
+
520
+ /**
521
+ * Finds the changed line ranges with `TextDiff.lines`.
522
+ *
523
+ * @param original The lines before.
524
+ * @param modified The lines after.
525
+ * @returns The changes in order and apart; none for equal sequences.
526
+ * @example
527
+ * ```ts
528
+ * import { DefaultDiffAlgorithm } from "@noldova/code.editor.diff";
529
+ * import { List } from "@noldova/context.collections";
530
+ *
531
+ * new DefaultDiffAlgorithm().lines(new List(["a"]), new List(["a"])).count(); // 0
532
+ * ```
533
+ */
534
+ lines(original: IReadOnlyList<string>, modified: IReadOnlyList<string>): IReadOnlyList<DiffSpan>;
535
+
536
+ /**
537
+ * Finds the changed character ranges with `TextDiff.characters`.
538
+ *
539
+ * @param original The text before.
540
+ * @param modified The text after.
541
+ * @returns The changes in order and apart, never splitting a surrogate
542
+ * pair.
543
+ * @example
544
+ * ```ts
545
+ * import { DefaultDiffAlgorithm } from "@noldova/code.editor.diff";
546
+ *
547
+ * new DefaultDiffAlgorithm().characters("cat", "cut").get(0).originalStart; // 1
548
+ * ```
549
+ */
550
+ characters(original: string, modified: string): IReadOnlyList<DiffSpan>;
551
+ }
552
+
553
+ /**
554
+ * The two line sequences a {@link LineDiffJob} compares. It holds only
555
+ * arrays of strings, so it crosses to a worker as it is.
556
+ *
557
+ * @example
558
+ * ```ts
559
+ * import { LineDiffInput } from "@noldova/code.editor.diff";
560
+ *
561
+ * new LineDiffInput(["a"], ["b"]).modified; // ["b"]
562
+ * ```
563
+ */
564
+ export declare class LineDiffInput {
565
+ /**
566
+ * The lines before.
567
+ */
568
+ readonly original: readonly string[];
569
+
570
+ /**
571
+ * The lines after.
572
+ */
573
+ readonly modified: readonly string[];
574
+
575
+ /**
576
+ * Holds the two sequences.
577
+ *
578
+ * @param original The lines before.
579
+ * @param modified The lines after.
580
+ * @example
581
+ * ```ts
582
+ * import { LineDiffInput } from "@noldova/code.editor.diff";
583
+ *
584
+ * new LineDiffInput(["a"], ["b"]);
585
+ * ```
586
+ */
587
+ constructor(original: readonly string[], modified: readonly string[]);
588
+ }
589
+
590
+ /**
591
+ * The diff model's contribution: the default algorithm and its
592
+ * {@link LineDiffJob}, in the registries' `diffAlgorithms` and
593
+ * `backgroundJobs`.
594
+ *
595
+ * @example
596
+ * ```ts
597
+ * import { EditorRegistries } from "@noldova/code.editor";
598
+ * import { DiffContribution } from "@noldova/code.editor.diff";
599
+ *
600
+ * const registries = new EditorRegistries();
601
+ * registries.add(new DiffContribution());
602
+ * registries.diffAlgorithms.current().id; // "noldova.diff"
603
+ * ```
604
+ */
605
+ export declare class DiffContribution implements IEditorContribution {
606
+ /**
607
+ * `"noldova.code.editor.diff"`.
608
+ */
609
+ readonly id: string;
610
+
611
+ /**
612
+ * Registers the default algorithm and its line diff job.
613
+ *
614
+ * @param registries The set to register them in.
615
+ * @example
616
+ * ```ts
617
+ * import { EditorRegistries } from "@noldova/code.editor";
618
+ * import { DiffContribution } from "@noldova/code.editor.diff";
619
+ *
620
+ * new DiffContribution().contribute(new EditorRegistries());
621
+ * ```
622
+ */
623
+ contribute(registries: EditorRegistries): void;
624
+ }
625
+
626
+ /**
627
+ * The background job that runs an algorithm's line diff and packs the result
628
+ * with {@link LineChangeCodec}, so it crosses back from a worker without a
629
+ * copy.
630
+ *
631
+ * @remarks
632
+ * Its steps yield before the diff and between slices of the packing; the
633
+ * algorithm's `lines` call itself is one step. A worker script serves it by
634
+ * its name; the diff editor package's worker serves the default algorithm's.
635
+ *
636
+ * @example
637
+ * ```ts
638
+ * import { SlicedRunner } from "@noldova/code.editor";
639
+ * import { DefaultDiffAlgorithm, LineChangeCodec, LineDiffInput, LineDiffJob } from "@noldova/code.editor.diff";
640
+ *
641
+ * const values = await new SlicedRunner().runAsync(new LineDiffJob(new DefaultDiffAlgorithm()), new LineDiffInput(["a"], ["b"]));
642
+ * LineChangeCodec.decode(values).count(); // 1
643
+ * ```
644
+ */
645
+ export declare class LineDiffJob implements IBackgroundJob<LineDiffInput, Int32Array> {
646
+ /**
647
+ * `code.editor.diff.lines:` and the algorithm's id.
648
+ */
649
+ readonly name: string;
650
+
651
+ /**
652
+ * Makes the job for an algorithm.
653
+ *
654
+ * @param algorithm The algorithm whose `lines` the job runs.
655
+ * @example
656
+ * ```ts
657
+ * import { DefaultDiffAlgorithm, LineDiffJob } from "@noldova/code.editor.diff";
658
+ *
659
+ * new LineDiffJob(new DefaultDiffAlgorithm()).name; // "code.editor.diff.lines:noldova.diff"
660
+ * ```
661
+ */
662
+ constructor(algorithm: IDiffAlgorithm);
663
+
664
+ /**
665
+ * The job's steps, for a runner to drive.
666
+ *
667
+ * @param input The sequences to compare.
668
+ * @returns A generator that yields between slices and returns the packed
669
+ * changes.
670
+ * @example
671
+ * ```ts
672
+ * import { DefaultDiffAlgorithm, LineDiffInput, LineDiffJob } from "@noldova/code.editor.diff";
673
+ *
674
+ * const steps = new LineDiffJob(new DefaultDiffAlgorithm()).steps(new LineDiffInput(["a"], ["a"]));
675
+ * ```
676
+ */
677
+ steps(input: LineDiffInput): Generator<void, Int32Array, void>;
678
+ }
package/api/index.js ADDED
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ export { DiffSide } from "../enums/diff-side.js";
9
+ export { ChangeRanges } from "../models/change-ranges.js";
10
+ export { LineChange } from "../models/line-change.js";
11
+ export { LineDiffInput } from "../models/line-diff-input.js";
12
+ export { UnchangedRegion } from "../models/unchanged-region.js";
13
+ export { DefaultDiffAlgorithm } from "../services/default-diff-algorithm.js";
14
+ export { DiffContribution } from "../services/diff-contribution.js";
15
+ export { DocumentDiff } from "../services/document-diff.js";
16
+ export { LineChangeCodec } from "../services/line-change-codec.js";
17
+ export { LineDiffJob } from "../services/line-diff-job.js";
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/noldova.code.editor.diff/src/api/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAC7E,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC"}