lib0 1.0.0-rc.14 → 1.0.0-rc.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/dist/delta/delta.d.ts +298 -32
  2. package/dist/delta/position.d.ts +65 -0
  3. package/dist/delta/rdt/delta.d.ts +54 -0
  4. package/dist/delta/rdt/dom.d.ts +90 -0
  5. package/dist/delta/rdt.d.ts +65 -0
  6. package/dist/delta/transformer/attr.d.ts +64 -0
  7. package/dist/delta/transformer/children.d.ts +69 -0
  8. package/dist/delta/transformer/conform.d.ts +83 -0
  9. package/dist/delta/transformer/core.d.ts +174 -0
  10. package/dist/delta/transformer/id.d.ts +2 -0
  11. package/dist/delta/transformer/inline.d.ts +89 -0
  12. package/dist/delta/transformer/pipe.d.ts +182 -0
  13. package/dist/delta/transformer/project.d.ts +223 -0
  14. package/dist/delta/transformer/rename-attrs.d.ts +75 -0
  15. package/dist/delta/transformer/rename.d.ts +41 -0
  16. package/dist/delta/transformer/value.d.ts +92 -0
  17. package/dist/delta/transformer.d.ts +11 -390
  18. package/dist/environment.d.ts +5 -0
  19. package/package.json +63 -4
  20. package/src/delta/delta.js +1140 -160
  21. package/src/delta/position.js +165 -0
  22. package/src/delta/rdt/delta.js +99 -0
  23. package/src/delta/rdt/dom.js +296 -0
  24. package/src/delta/rdt.js +177 -0
  25. package/src/delta/transformer/attr.js +126 -0
  26. package/src/delta/transformer/children.js +219 -0
  27. package/src/delta/transformer/conform.js +401 -0
  28. package/src/delta/transformer/core.js +308 -0
  29. package/src/delta/transformer/id.js +13 -0
  30. package/src/delta/transformer/inline.js +818 -0
  31. package/src/delta/transformer/pipe.js +272 -0
  32. package/src/delta/transformer/project.js +526 -0
  33. package/src/delta/transformer/rename-attrs.js +152 -0
  34. package/src/delta/transformer/rename.js +84 -0
  35. package/src/delta/transformer/value.js +214 -0
  36. package/src/delta/transformer.js +33 -724
  37. package/src/environment.js +7 -0
  38. package/dist/delta/binding.d.ts +0 -106
  39. package/src/delta/binding.js +0 -372
@@ -15,12 +15,17 @@ export const $attribution: s.Schema<Attribution>;
15
15
  /**
16
16
  * @typedef {{ [key: string]: any }} FormattingAttributes
17
17
  */
18
+ /**
19
+ * @typedef {{ id: string, key: number|string, assoc: 1|-1, attrs?: object }} MarkJSON
20
+ */
18
21
  /**
19
22
  * @typedef {{
20
23
  * type: 'delta',
21
24
  * name?: string,
22
25
  * attrs?: { [Key in string|number]: DeltaAttrOpJSON },
23
- * children?: Array<DeltaListOpJSON>
26
+ * children?: Array<DeltaListOpJSON>,
27
+ * marks?: Array<MarkJSON>,
28
+ * deleteMarks?: Array<string>
24
29
  * }} DeltaJSON
25
30
  */
26
31
  /**
@@ -57,6 +62,8 @@ export const $deltaMapChangeJson: s.Schema<DeltaAttrOpJSON>;
57
62
  * fingerprint read (and any `diff` / equality check that relies on it) is
58
63
  * wrong. Fields covered: insert, delete, retain, format, attribution,
59
64
  * value, key.
65
+ *
66
+ * @internal not part of the consumer API — a content op; build deltas via {@link create}/{@link DeltaBuilder}.
60
67
  */
61
68
  export class TextOp extends list.ListNode {
62
69
  /**
@@ -102,9 +109,13 @@ export class TextOp extends list.ListNode {
102
109
  */
103
110
  toJSON(): DeltaListOpJSON;
104
111
  /**
112
+ * @param {number} [start]
113
+ * @param {number} [end]
114
+ * @param {boolean} [_markAsDone] accepted for a uniform children-op `clone` signature; ignored (text
115
+ * holds no nested deltas to freeze).
105
116
  * @return {TextOp}
106
117
  */
107
- clone(start?: number, end?: number): TextOp;
118
+ clone(start?: number, end?: number, _markAsDone?: boolean): TextOp;
108
119
  $type: s.Schema<TextOp>;
109
120
  /**
110
121
  * @param {TextOp} other
@@ -113,6 +124,7 @@ export class TextOp extends list.ListNode {
113
124
  }
114
125
  /**
115
126
  * @template {any} ArrayContent
127
+ * @internal not part of the consumer API — a content op; build deltas via {@link create}/{@link DeltaBuilder}.
116
128
  */
117
129
  export class InsertOp<ArrayContent extends unknown> extends list.ListNode {
118
130
  /**
@@ -167,9 +179,15 @@ export class InsertOp<ArrayContent extends unknown> extends list.ListNode {
167
179
  */
168
180
  toJSON(): DeltaListOpJSON;
169
181
  /**
182
+ * @param {number} [start]
183
+ * @param {number} [end]
184
+ * @param {boolean} [markAsDone] freeze the cloned child deltas (the default — a shared clone must be
185
+ * immutable). Pass `false` only when the caller is the SOLE owner of the cloned range (a *move*, e.g.
186
+ * `splitHere` which `_splice`s the range out of the source), so the content can stay mutable and is
187
+ * not re-cloned on the next modify (see {@link modValue}).
170
188
  * @return {InsertOp<ArrayContent>}
171
189
  */
172
- clone(start?: number, end?: number): InsertOp<ArrayContent>;
190
+ clone(start?: number, end?: number, markAsDone?: boolean): InsertOp<ArrayContent>;
173
191
  $type: s.Schema<InsertOp<any>>;
174
192
  /**
175
193
  * @param {InsertOp<ArrayContent>} other
@@ -178,6 +196,7 @@ export class InsertOp<ArrayContent extends unknown> extends list.ListNode {
178
196
  }
179
197
  /**
180
198
  * @template {DeltaConf} [Conf={}]
199
+ * @internal not part of the consumer API — a content op; build deltas via {@link create}/{@link DeltaBuilder}.
181
200
  */
182
201
  export class DeleteOp<Conf extends DeltaConf = {}> extends list.ListNode {
183
202
  /**
@@ -209,17 +228,22 @@ export class DeleteOp<Conf extends DeltaConf = {}> extends list.ListNode {
209
228
  */
210
229
  toJSON(): DeltaListOpJSON;
211
230
  /**
212
- * @param {number} start
213
- * @param {number} end
231
+ * @param {number} [start]
232
+ * @param {number} [end]
233
+ * @param {boolean} [_markAsDone] accepted for a uniform children-op `clone` signature; ignored (a
234
+ * cloned delete carries no prevValue).
214
235
  * @return {DeleteOp}
215
236
  */
216
- clone(start?: number, end?: number): DeleteOp;
237
+ clone(start?: number, end?: number, _markAsDone?: boolean): DeleteOp;
217
238
  $type: s.Schema<DeleteOp<any>>;
218
239
  /**
219
240
  * @param {DeleteOp} other
220
241
  */
221
242
  [equalityTrait.EqualityTraitSymbol](other: DeleteOp): boolean;
222
243
  }
244
+ /**
245
+ * @internal not part of the consumer API — a content op; build deltas via {@link create}/{@link DeltaBuilder}.
246
+ */
223
247
  export class RetainOp extends list.ListNode {
224
248
  /**
225
249
  * @param {number} retain
@@ -263,7 +287,14 @@ export class RetainOp extends list.ListNode {
263
287
  * @return {DeltaListOpJSON}
264
288
  */
265
289
  toJSON(): DeltaListOpJSON;
266
- clone(start?: number, end?: number): RetainOp;
290
+ /**
291
+ * @param {number} [start]
292
+ * @param {number} [end]
293
+ * @param {boolean} [_markAsDone] accepted for a uniform children-op `clone` signature; ignored (retain
294
+ * holds no nested deltas).
295
+ * @return {RetainOp}
296
+ */
297
+ clone(start?: number, end?: number, _markAsDone?: boolean): RetainOp;
267
298
  $type: s.Schema<RetainOp>;
268
299
  /**
269
300
  * @param {RetainOp} other
@@ -274,6 +305,7 @@ export class RetainOp extends list.ListNode {
274
305
  * Delta that can be applied on a YType Embed
275
306
  *
276
307
  * @template {Delta} [DTypes=DeltaAny]
308
+ * @internal not part of the consumer API — a content op; build deltas via {@link create}/{@link DeltaBuilder}.
277
309
  */
278
310
  export class ModifyOp<DTypes extends Delta = DeltaAny> extends list.ListNode {
279
311
  /**
@@ -323,9 +355,13 @@ export class ModifyOp<DTypes extends Delta = DeltaAny> extends list.ListNode {
323
355
  */
324
356
  toJSON(): DeltaListOpJSON;
325
357
  /**
358
+ * @param {number} [_start] ignored (a modify is atomic); accepted for a uniform children-op signature.
359
+ * @param {number} [_end] ignored.
360
+ * @param {boolean} [markAsDone] freeze the cloned value (default); `false` shares it mutable — see
361
+ * {@link InsertOp#clone}. The op itself is still a fresh node; only its `value` is consumed.
326
362
  * @return {ModifyOp<DTypes>}
327
363
  */
328
- clone(): ModifyOp<DTypes>;
364
+ clone(_start?: number, _end?: number, markAsDone?: boolean): ModifyOp<DTypes>;
329
365
  $type: s.Schema<ModifyOp<Delta<any>>>;
330
366
  /**
331
367
  * @param {ModifyOp<any>} other
@@ -335,6 +371,7 @@ export class ModifyOp<DTypes extends Delta = DeltaAny> extends list.ListNode {
335
371
  /**
336
372
  * @template {any} [V=any]
337
373
  * @template {string|number} [K=any]
374
+ * @internal not part of the consumer API — an attribute op; build deltas via {@link create}/{@link DeltaBuilder}.
338
375
  */
339
376
  export class SetAttrOp<V extends unknown = any, K extends string | number = any> {
340
377
  /**
@@ -379,13 +416,16 @@ export class SetAttrOp<V extends unknown = any, K extends string | number = any>
379
416
  get fingerprint(): string;
380
417
  toJSON(): {
381
418
  type: "insert";
382
- value: DeltaJSON | V;
419
+ value: V | DeltaJSON;
383
420
  } & ({
384
421
  attribution: Attribution;
385
422
  } | {
386
423
  attribution?: undefined;
387
424
  });
388
425
  /**
426
+ * Full (frozen) clone. A `move` apply reuses the source op instead of cloning, so there is no
427
+ * shared-mutable variant — see {@link DeltaBuilder#apply}.
428
+ *
389
429
  * @return {SetAttrOp<V,K>}
390
430
  */
391
431
  clone(): SetAttrOp<V, K>;
@@ -398,6 +438,7 @@ export class SetAttrOp<V extends unknown = any, K extends string | number = any>
398
438
  /**
399
439
  * @template [V=any]
400
440
  * @template {string|number} [K=string|number]
441
+ * @internal not part of the consumer API — an attribute op; build deltas via {@link create}/{@link DeltaBuilder}.
401
442
  */
402
443
  export class DeleteAttrOp<V = any, K extends string | number = string | number> {
403
444
  /**
@@ -429,6 +470,11 @@ export class DeleteAttrOp<V = any, K extends string | number = string | number>
429
470
  * @return {DeltaAttrOpJSON}
430
471
  */
431
472
  toJSON(): DeltaAttrOpJSON;
473
+ /**
474
+ * Full (frozen) clone; a `move` apply reuses the source op instead — see {@link DeltaBuilder#apply}.
475
+ *
476
+ * @return {DeleteAttrOp<V,K>}
477
+ */
432
478
  clone(): DeleteAttrOp<V, K>;
433
479
  $type: s.Schema<DeleteAttrOp<any, string | number>>;
434
480
  /**
@@ -439,6 +485,7 @@ export class DeleteAttrOp<V = any, K extends string | number = string | number>
439
485
  /**
440
486
  * @template {DeltaAny} [Modifier=DeltaAny]
441
487
  * @template {string|number} [K=string]
488
+ * @internal not part of the consumer API — an attribute op; build deltas via {@link create}/{@link DeltaBuilder}.
442
489
  */
443
490
  export class ModifyAttrOp<Modifier extends DeltaAny = DeltaAny, K extends string | number = string> {
444
491
  /**
@@ -474,6 +521,8 @@ export class ModifyAttrOp<Modifier extends DeltaAny = DeltaAny, K extends string
474
521
  */
475
522
  toJSON(): DeltaAttrOpJSON;
476
523
  /**
524
+ * Full (frozen) clone; a `move` apply reuses the source op instead — see {@link DeltaBuilder#apply}.
525
+ *
477
526
  * @return {ModifyAttrOp<Modifier,K>}
478
527
  */
479
528
  clone(): ModifyAttrOp<Modifier, K>;
@@ -488,15 +537,17 @@ export const $modifyOp: s.Schema<ModifyOp<Delta<any>>>;
488
537
  export const $textOp: s.Schema<TextOp>;
489
538
  export const $deleteOp: s.Schema<DeleteOp<any>>;
490
539
  export const $retainOp: s.Schema<RetainOp>;
491
- export const $anyOp: s.Schema<TextOp | InsertOp<any> | DeleteOp<any> | ModifyOp<Delta<any>>>;
540
+ export const $anyOp: s.Schema<DeleteOp<any> | TextOp | InsertOp<any> | ModifyOp<Delta<any>>>;
492
541
  export const $setAttrOp: s.Schema<SetAttrOp<any>>;
493
542
  export const $modifyAttrOp: s.Schema<ModifyAttrOp<any>>;
494
543
  export const $deleteAttrOp: s.Schema<DeleteAttrOp<any>>;
495
- export const $anyAttrOp: s.Schema<SetAttrOp<any, any> | DeleteAttrOp<any, string | number> | ModifyAttrOp<any, string>>;
544
+ export const $anyAttrOp: s.Schema<ModifyAttrOp<any, string> | SetAttrOp<any, any> | DeleteAttrOp<any, string | number>>;
496
545
  export function $setAttrOpWith<Content extends fingerprintTrait.Fingerprintable>($content: s.Schema<Content>): s.Schema<SetAttrOp<Content>>;
497
546
  export function $insertOpWith<Content extends fingerprintTrait.Fingerprintable>($content: s.Schema<Content>): s.Schema<InsertOp<Content>>;
498
547
  export function $modifyOpWith<Modify extends DeltaAny>($content: s.Schema<Modify>): s.Schema<ModifyOp<Modify>>;
499
548
  export function $modifyAttrOpWith<Modify extends DeltaAny>($content: s.Schema<Modify>): s.Schema<ModifyAttrOp<Modify>>;
549
+ export const $mark: s.Schema<Mark>;
550
+ export function createMark(key: number | string, id?: string, assoc?: 1 | -1, attrs?: object | null): Mark;
500
551
  /**
501
552
  * @template {DeltaConf} [Conf={}]
502
553
  * @extends {DeltaData<
@@ -551,6 +602,14 @@ export class Delta<Conf extends DeltaConf = {}> extends DeltaData<DeltaConfGetNa
551
602
  }
552
603
  export function slice<Conf_1 extends DeltaConf>(d: Delta<Conf_1>, start?: number, end?: number, currNode?: ChildrenOpAny | null): DeltaBuilder<Conf_1>;
553
604
  export function clone<D extends DeltaAny>(d: D): D extends Delta<infer Conf_1> ? DeltaBuilder<Conf_1> : never;
605
+ export function cloneShallow<D extends DeltaAny>(d: D): D extends Delta<infer Conf_1> ? DeltaBuilder<Conf_1> : never;
606
+ export function _mergeChildWithPrev(d: DeltaBuilderAny, op: InsertOp<any> | RetainOp | DeleteOp<any> | TextOp | ModifyOp<any>): boolean;
607
+ export function _splitChildAt(d: DeltaBuilderAny, op: ChildrenOpAny, offset: number): ChildrenOpAny;
608
+ export function _insertChild(d: DeltaBuilderAny, ref: ChildrenOpAny | null, op: ChildrenOpAny): ChildrenOpAny;
609
+ export function _removeChild(d: DeltaBuilderAny, op: ChildrenOpAny): void;
610
+ export function _shrinkChild(d: DeltaBuilderAny, op: ChildrenOpAny, offset: number, len: number): void;
611
+ export function _growRun(d: DeltaBuilderAny, op: RetainOp | DeleteOp<any>, n: number): void;
612
+ export function _spliceInsert(d: DeltaBuilderAny, op: InsertOp<any>, offset: number, elems: Array<any>): void;
554
613
  /**
555
614
  * @template {DeltaConf} [Conf={}]
556
615
  * @template {boolean} [FixedConf=false]
@@ -615,6 +674,30 @@ export class DeltaBuilder<Conf extends DeltaConf = {}, FixedConf extends boolean
615
674
  modify<NewContent extends Extract<DeltaConfGetAllowedChildren<Conf, FixedConf>, Delta | DeltaData<any, any, any, any> | DeltaBuilder>>(modify: NewContent, formatting?: FormattingAttributes | null, attribution?: Attribution | null): DeltaBuilder<DeltaConfOverwrite<Conf, {
616
675
  children: DeltaConfGetChildren<Conf> | NewContent;
617
676
  }>, FixedConf>;
677
+ /**
678
+ * Add a cursor/selection {@link Mark} at `pos` — a {@link import('./position.js').Pos}: a `path` of
679
+ * content-index / attribute-key steps plus an `assoc` and optional immutable `attrs` (user data
680
+ * carried with the mark). Returns `this` for chaining (like every other builder method). Pass an
681
+ * explicit `id` to reference the mark later — re-adding the same `id` replaces it (e.g. to move a
682
+ * cursor or update its `attrs`) and {@link DeltaBuilder#removeMark} deletes it; an anonymous one-shot
683
+ * mark gets a fresh GUID otherwise.
684
+ *
685
+ * @param {import('./position.js').Pos} pos
686
+ * @param {string} [id]
687
+ * @return {this}
688
+ */
689
+ addMark(pos: import("./position.js").Pos, id?: string): this;
690
+ /**
691
+ * Remove the mark with `id`, located via `pos` (the position it was added at). On a settled document
692
+ * that holds the mark this removes it in place; on a fresh/markless builder it records a transmittable
693
+ * `deleteMarks` change (symmetric to {@link DeltaBuilder#addMark}), so
694
+ * `delta.create().removeMark(pos, id)` yields the delete-mark change to apply / rebase / transmit.
695
+ *
696
+ * @param {import('./position.js').Pos} pos
697
+ * @param {string} id
698
+ * @return {this}
699
+ */
700
+ removeMark(pos: import("./position.js").Pos, id: string): this;
618
701
  /**
619
702
  * @param {number} len
620
703
  * @param {FormattingAttributes?} [format]
@@ -687,11 +770,14 @@ export class DeltaBuilder<Conf extends DeltaConf = {}, FixedConf extends boolean
687
770
  * attribute). Any kind of `delete` op might be considered a bug. A final delta is not idempotent.
688
771
  *
689
772
  * @param {Delta<Conf>?} other
690
- * @param {{ final?: boolean }} opts -- (experimental)
773
+ * @param {{ final?: boolean, move?: boolean }} [opts] `move`: the caller donates `other` (it is not
774
+ * read again), so its content is consumed (shared mutable) rather than frozen-cloned — see {@link
775
+ * InsertOp#clone}. UNSAFE if the caller keeps using `other`.
691
776
  * @return {DeltaBuilder<Conf>}
692
777
  */
693
- apply(other: Delta<Conf> | null, { final }?: {
778
+ apply(other: Delta<Conf> | null, { final, move }?: {
694
779
  final?: boolean;
780
+ move?: boolean;
695
781
  }): DeltaBuilder<Conf>;
696
782
  /**
697
783
  * Rebase this op against a concurrent op. We can apply this op on a doc that already applied
@@ -727,9 +813,14 @@ export class DeltaBuilder<Conf extends DeltaConf = {}, FixedConf extends boolean
727
813
  text: true;
728
814
  } : never)>, FixedConf>;
729
815
  }
816
+ export function remapRootMarks(node: DeltaAny, mapKey: (key: number | string) => number | string | null): void;
817
+ export function addRootMark(node: DeltaAny, mark: Mark): void;
818
+ export function deleteRootMark(node: DeltaAny, id: string): void;
819
+ export function mergeRootMarks(target: DeltaAny, source: DeltaAny, mapKey?: (key: number | string) => number | string | null): void;
730
820
  /**
731
821
  * @template {DeltaConf} Conf
732
822
  * @extends {s.Schema<Delta<Conf>>}
823
+ * @internal use the {@link $delta} factory; this class is exported only for the `$$delta` predicate.
733
824
  */
734
825
  export class $Delta<Conf extends DeltaConf> extends s.Schema<Delta<Conf>> {
735
826
  /**
@@ -764,7 +855,28 @@ export class $Delta<Conf extends DeltaConf> extends s.Schema<Delta<Conf>> {
764
855
  }>;
765
856
  };
766
857
  }
767
- export function $delta<DeltaConf extends ReadableDeltaConf = {}>({ name, attrs, children, text, formats, recursiveChildren: recursive }: DeltaConf): s.Schema<Delta<ReadDeltaConf<DeltaConf>>>;
858
+ /**
859
+ * Name-first form: a string-literal `name` as the first argument is preserved as a literal type
860
+ * (generic argument inference), so callers don't need `s.$literal('x')` / `@type {const}` to keep the
861
+ * node name literal. The remaining options follow in `opts`.
862
+ *
863
+ * @template {string} Name
864
+ * @template {Omit<ReadableDeltaConf, 'name'>} [Opts={}]
865
+ * @overload
866
+ * @param {Name} name
867
+ * @param {Opts} [opts]
868
+ * @return {s.Schema<Delta<ReadDeltaConf<Opts & { name: Name }>>>}
869
+ */
870
+ export function $delta<Name extends string, Opts extends Omit<ReadableDeltaConf, "name"> = {}>(name: Name, opts?: Opts | undefined): s.Schema<Delta<ReadDeltaConf<Opts & {
871
+ name: Name;
872
+ }>>>;
873
+ /**
874
+ * @template {ReadableDeltaConf} [Conf={}]
875
+ * @overload
876
+ * @param {Conf} opts
877
+ * @return {s.Schema<Delta<ReadDeltaConf<Conf>>>}
878
+ */
879
+ export function $delta<Conf extends ReadableDeltaConf = {}>(opts: Conf): s.Schema<Delta<ReadDeltaConf<Conf>>>;
768
880
  export const $$delta: s.Schema<$Delta<DeltaConf>>;
769
881
  export const $deltaAny: s.Schema<Delta<any>>;
770
882
  export const $deltaBuilderAny: s.Schema<DeltaBuilderAny>;
@@ -796,13 +908,13 @@ export function create<NodeName extends string | null>(nodeName: NodeName): Delt
796
908
  } : {}>;
797
909
  /**
798
910
  * @template {string} NodeName
799
- * @template {DeltaConf} Conf
911
+ * @template {s.Schema<DeltaAny>} Schema
800
912
  * @overload
801
913
  * @param {NodeName} nodeName
802
- * @param {s.Schema<Delta<Conf>>} schema
803
- * @return {DeltaBuilder<Conf, true>}
914
+ * @param {Schema} schema
915
+ * @return {Schema extends s.Schema<Delta<infer Conf>> ? DeltaBuilder<Conf, true> : never}
804
916
  */
805
- export function create<NodeName extends string | null, Conf extends DeltaConf>(nodeName: NodeName, schema: s.Schema<Delta<Conf>>): DeltaBuilder<Conf, true>;
917
+ export function create<NodeName extends string | null, Schema extends s.Schema<DeltaAny>>(nodeName: NodeName, schema: Schema): Schema extends s.Schema<Delta<infer Conf_1>> ? DeltaBuilder<Conf_1, true> : never;
806
918
  /**
807
919
  * @template {s.Schema<DeltaAny>} Schema
808
920
  * @overload
@@ -818,8 +930,7 @@ export function create<Schema extends s.Schema<DeltaAny>>(schema: Schema): Schem
818
930
  * @param {NodeName} nodeName
819
931
  * @param {Attrs} attrs
820
932
  * @param {Children} [children]
821
- * @return {DeltaBuilder<{
822
- * name: NodeName,
933
+ * @return {DeltaBuilder<(NodeName extends string ? { name: NodeName } : {}) & {
823
934
  * attrs: Attrs extends null ? {} : Attrs,
824
935
  * children: Extract<Children,Array<any>> extends Array<infer Ac> ? (unknown extends Ac ? never : Ac) : never,
825
936
  * text: Extract<Children,string> extends never ? false : true
@@ -827,8 +938,9 @@ export function create<Schema extends s.Schema<DeltaAny>>(schema: Schema): Schem
827
938
  */
828
939
  export function create<NodeName extends string | null, Attrs extends {
829
940
  [k: string | number]: any;
830
- } | null, Children extends Array<any> | string = never>(nodeName: NodeName, attrs: Attrs, children?: Children | undefined): DeltaBuilder<{
941
+ } | null, Children extends Array<any> | string = never>(nodeName: NodeName, attrs: Attrs, children?: Children | undefined): DeltaBuilder<(NodeName extends string ? {
831
942
  name: NodeName;
943
+ } : {}) & {
832
944
  attrs: Attrs extends null ? {} : Attrs;
833
945
  children: Extract<Children, Array<any>> extends Array<infer Ac> ? (unknown extends Ac ? never : Ac) : never;
834
946
  text: Extract<Children, string> extends never ? false : true;
@@ -839,14 +951,14 @@ export function create<NodeName extends string | null, Attrs extends {
839
951
  * @overload
840
952
  * @param {NodeName} nodeName
841
953
  * @param {...Array<Children>} children
842
- * @return {DeltaBuilder<{
843
- * name: NodeName,
954
+ * @return {DeltaBuilder<(NodeName extends string ? { name: NodeName } : {}) & {
844
955
  * children: Extract<Children,Array<any>> extends Array<infer Ac> ? (unknown extends Ac ? never : Ac) : never,
845
956
  * text: Extract<Children,string> extends never ? false : true
846
957
  * }>}
847
958
  */
848
- export function from<NodeName extends string | null, Children extends Array<any> | string = never>(nodeName: NodeName, ...children: Array<Children>[]): DeltaBuilder<{
959
+ export function from<NodeName extends string | null, Children extends Array<any> | string = never>(nodeName: NodeName, ...children: Array<Children>[]): DeltaBuilder<(NodeName extends string ? {
849
960
  name: NodeName;
961
+ } : {}) & {
850
962
  children: Extract<Children, Array<any>> extends Array<infer Ac> ? (unknown extends Ac ? never : Ac) : never;
851
963
  text: Extract<Children, string> extends never ? false : true;
852
964
  }>;
@@ -890,8 +1002,7 @@ export function from<Attrs extends {
890
1002
  * @param {NodeName} nodeName
891
1003
  * @param {Attrs} attrs
892
1004
  * @param {...Array<Children>} children
893
- * @return {DeltaBuilder<{
894
- * name: NodeName,
1005
+ * @return {DeltaBuilder<(NodeName extends string ? { name: NodeName } : {}) & {
895
1006
  * attrs: Attrs extends null ? {} : Attrs,
896
1007
  * children: Extract<Children,Array<any>> extends Array<infer Ac> ? (unknown extends Ac ? never : Ac) : never,
897
1008
  * text: Extract<Children,string> extends never ? false : true
@@ -899,13 +1010,14 @@ export function from<Attrs extends {
899
1010
  */
900
1011
  export function from<NodeName extends string | null, Attrs extends {
901
1012
  [k: string | number]: any;
902
- } | null, Children extends Array<any> | string = never>(nodeName: NodeName, attrs: Attrs, ...children: Array<Children>[]): DeltaBuilder<{
1013
+ } | null, Children extends Array<any> | string = never>(nodeName: NodeName, attrs: Attrs, ...children: Array<Children>[]): DeltaBuilder<(NodeName extends string ? {
903
1014
  name: NodeName;
1015
+ } : {}) & {
904
1016
  attrs: Attrs extends null ? {} : Attrs;
905
1017
  children: Extract<Children, Array<any>> extends Array<infer Ac> ? (unknown extends Ac ? never : Ac) : never;
906
1018
  text: Extract<Children, string> extends never ? false : true;
907
1019
  }>;
908
- export function diff<Conf_1 extends DeltaConf>(d1: Delta<Conf_1>, d2: NoInfer<Delta<Conf_1>>): Delta<Conf_1>;
1020
+ export function diff<Conf_1 extends DeltaConf>(d1: Delta<Conf_1>, d2: NoInfer<Delta<Conf_1>>, options?: DiffOptions): Delta<Conf_1>;
909
1021
  export function diffChangesetWithSeparator(changeset: Array<{
910
1022
  index: number;
911
1023
  remove: Array<any>;
@@ -922,11 +1034,19 @@ export type Attribution = {
922
1034
  export type FormattingAttributes = {
923
1035
  [key: string]: any;
924
1036
  };
1037
+ export type MarkJSON = {
1038
+ id: string;
1039
+ key: number | string;
1040
+ assoc: 1 | -1;
1041
+ attrs?: object;
1042
+ };
925
1043
  export type DeltaJSON = {
926
1044
  type: "delta";
927
1045
  name?: string;
928
1046
  attrs?: { [Key in string | number]: DeltaAttrOpJSON; };
929
1047
  children?: Array<DeltaListOpJSON>;
1048
+ marks?: Array<MarkJSON>;
1049
+ deleteMarks?: Array<string>;
930
1050
  };
931
1051
  export type DeltaListOpJSON = {
932
1052
  type: "insert";
@@ -979,9 +1099,16 @@ export type DeltaConf = {
979
1099
  recursiveChildren?: boolean | undefined;
980
1100
  recursiveAttrs?: boolean | undefined;
981
1101
  };
1102
+ /**
1103
+ * Coerce a computed conf to provably satisfy the `DeltaConf` constraint. Declaration emit re-checks
1104
+ * type arguments eagerly, so a deeply-computed conf (mapped/recursive) passed to `Delta<…>` /
1105
+ * `Transformer<…>` must be wrapped here: the conditional exposes `DeltaConf` as its upper bound,
1106
+ * letting the constraint resolve without forcing TS to expand the (self-referential) body.
1107
+ */
1108
+ export type AsDeltaConf<T> = T extends infer DC extends DeltaConf ? DC : never;
982
1109
  export type DeltaConfGetName<Conf_1 extends DeltaConf> = Conf_1 extends {
983
- name: infer Name;
984
- } ? (unknown extends Name ? any : (Exclude<Name, undefined>)) : any;
1110
+ name: infer Name_1;
1111
+ } ? (unknown extends Name_1 ? any : (Exclude<Name_1, undefined>)) : any;
985
1112
  export type DeltaConfGetChildren<Conf_1 extends DeltaConf> = (Conf_1 extends {
986
1113
  children: infer Children_1;
987
1114
  } ? (unknown extends Children_1 ? any : Children_1) : never) | (Conf_1 extends {
@@ -1034,7 +1161,7 @@ export type ReadDeltaConf<DConfSpec extends ReadableDeltaConf> = [DConfSpec exte
1034
1161
  attrs: infer A;
1035
1162
  } ? s.ReadSchemaUnwrapped<A> : {}, DConfSpec extends {
1036
1163
  children: infer C;
1037
- } ? s.ReadSchemaUnwrapped<C> : never] extends [infer NodeName_1, infer Attrs_1, infer Children_1] ? PrettifyDeltaConf<(import("../ts.js").TypeIsAny<NodeName_1, {}, {
1164
+ } ? s.ReadSchemaUnwrapped<C> : never] extends [infer NodeName_1, infer Attrs_1, infer Children_1] ? AsDeltaConf<PrettifyDeltaConf<(import("../ts.js").TypeIsAny<NodeName_1, {}, {
1038
1165
  name: NodeName_1;
1039
1166
  }> & ([keyof Attrs_1] extends [never] ? {} : {
1040
1167
  attrs: Attrs_1;
@@ -1048,7 +1175,15 @@ export type ReadDeltaConf<DConfSpec extends ReadableDeltaConf> = [DConfSpec exte
1048
1175
  recursiveChildren: true;
1049
1176
  } ? {
1050
1177
  recursiveChildren: true;
1051
- } : {})) extends infer DC extends DeltaConf ? DC : never> : never;
1178
+ } : {}))>> : never;
1179
+ export type DiffOptions = {
1180
+ /**
1181
+ * Predicate deciding when two nodes
1182
+ * are paired into a `modify` (vs. replaced wholesale). Defaults to comparing names
1183
+ * (`(d1, d2) => d1.name === d2.name`). Called as `compare(fromNode, toNode)`.
1184
+ */
1185
+ compare?: ((d1: DeltaAny, d2: DeltaAny) => boolean) | undefined;
1186
+ };
1052
1187
  import * as s from '../schema.js';
1053
1188
  import * as list from '../list.js';
1054
1189
  import * as equalityTrait from '../trait/equality.js';
@@ -1064,6 +1199,67 @@ import * as fingerprintTrait from '../trait/fingerprint.js';
1064
1199
  * @template {{[Key in string|number|symbol]: any}} NewAttrs
1065
1200
  * @typedef {{ [K in (keyof NewAttrs | keyof Attrs)]: (unknown extends Attrs[K] ? never : Attrs[K]) | (unknown extends NewAttrs[K] ? never : NewAttrs[K]) }} MergeAttrs
1066
1201
  */
1202
+ /**
1203
+ * A cursor/selection anchor stored inside a delta tree (see {@link import('./position.js').marksToPositions}).
1204
+ *
1205
+ * - `key` — the *terminal* step of the position: a content offset (number) or an attribute key
1206
+ * (string) within the node that holds the mark.
1207
+ * - `id` — a unique, user-defined identifier.
1208
+ * - `assoc` — the gravity at a boundary (left `-1` / right `1`).
1209
+ * - `attrs` — optional user-supplied data carried with the mark **by reference**: the same
1210
+ * object is shared across the mark, its `copy`/`clone`s, `toJSON`, and every `MarkPos` from
1211
+ * `marksToPositions`, so the caller must treat it as immutable (do not mutate it after attaching).
1212
+ *
1213
+ * A `Mark` is **immutable** — never mutate one in place; to "move" a mark, replace it with a fresh
1214
+ * `Mark` via {@link Mark#copy} (the {@link Marks} set keys by id, so re-adding the same id replaces
1215
+ * it). Immutability lets a `Mark` be shared freely across a delta and its clones. The class is not
1216
+ * exported — construct via {@link createMark} and validate via {@link $mark}.
1217
+ */
1218
+ declare class Mark {
1219
+ /**
1220
+ * @param {number|string} key
1221
+ * @param {string} [id] unique id; defaults to a fresh GUID
1222
+ * @param {1|-1} [assoc] gravity at a boundary; defaults to right (`1`)
1223
+ * @param {object?} [attrs] optional user data, stored by reference; treat as immutable
1224
+ */
1225
+ constructor(key: number | string, id?: string, assoc?: 1 | -1, attrs?: object | null);
1226
+ /**
1227
+ * @readonly
1228
+ * @type {number|string}
1229
+ */
1230
+ readonly key: number | string;
1231
+ /**
1232
+ * @readonly
1233
+ * @type {string}
1234
+ */
1235
+ readonly id: string;
1236
+ /**
1237
+ * @readonly
1238
+ * @type {1|-1}
1239
+ */
1240
+ readonly assoc: 1 | -1;
1241
+ /**
1242
+ * @readonly
1243
+ * @type {object?}
1244
+ */
1245
+ readonly attrs: object | null;
1246
+ /**
1247
+ * A copy of this mark, optionally at a different `key` (used to "move" an otherwise-immutable mark).
1248
+ *
1249
+ * @param {number|string} [key]
1250
+ * @return {Mark}
1251
+ */
1252
+ copy(key?: number | string): Mark;
1253
+ /**
1254
+ * @return {MarkJSON}
1255
+ */
1256
+ toJSON(): MarkJSON;
1257
+ $type: s.Schema<Mark>;
1258
+ /**
1259
+ * @param {Mark} other
1260
+ */
1261
+ [equalityTrait.EqualityTraitSymbol](other: Mark): boolean;
1262
+ }
1067
1263
  /**
1068
1264
  * @typedef {Delta<any>} DeltaAny
1069
1265
  */
@@ -1079,6 +1275,15 @@ import * as fingerprintTrait from '../trait/fingerprint.js';
1079
1275
  * @property {boolean} [DeltaConf.recursiveChildren=false]
1080
1276
  * @property {boolean} [DeltaConf.recursiveAttrs=false]
1081
1277
  */
1278
+ /**
1279
+ * Coerce a computed conf to provably satisfy the `DeltaConf` constraint. Declaration emit re-checks
1280
+ * type arguments eagerly, so a deeply-computed conf (mapped/recursive) passed to `Delta<…>` /
1281
+ * `Transformer<…>` must be wrapped here: the conditional exposes `DeltaConf` as its upper bound,
1282
+ * letting the constraint resolve without forcing TS to expand the (self-referential) body.
1283
+ *
1284
+ * @template T
1285
+ * @typedef {T extends infer DC extends DeltaConf ? DC : never} AsDeltaConf
1286
+ */
1082
1287
  /**
1083
1288
  * @template {DeltaConf} Conf
1084
1289
  * @typedef {Conf extends {name:infer Name} ? (unknown extends Name ? any : (Exclude<Name,undefined>)) : any} DeltaConfGetName
@@ -1174,7 +1379,68 @@ declare class DeltaData<Name extends string, Attrs extends { [K in string | numb
1174
1379
  * Is the final document and does not contain delete, modify, or retain ops.
1175
1380
  */
1176
1381
  isFinal: boolean;
1382
+ /**
1383
+ * Leaf {@link Mark marks} whose cursor sits in THIS node (in a settled delta), or the marks to ADD
1384
+ * to the target node (in a change delta). Local/ephemeral cursor state — NOT part of the document
1385
+ * fingerprint or equality. `null` when there are none. See {@link Marks}.
1386
+ *
1387
+ * @type {Marks?}
1388
+ */
1389
+ marks: Marks | null;
1390
+ /**
1391
+ * Mark ids to DELETE (tombstones). Only present in a (non-settled) change delta — like a
1392
+ * `DeleteAttrOp`, a deletion is dropped from a final delta (a materialized document carries none, at
1393
+ * any depth). `null` when there are none. Marks follow *last-writer-wins*, treating each op as an
1394
+ * absolute per-id assignment (present vs absent): adding a mark cancels a pending delete of the same
1395
+ * id ({@link addMarkTo}) and a delete cancels a present add ({@link deleteMarkTo}), so a node never
1396
+ * holds both an add and a delete for one id. {@link deleteMarkTo} is the sole writer of this set
1397
+ * (and `addMarkTo`'s mirror); see {@link applyMarkOps}.
1398
+ *
1399
+ * @type {Set<string>?}
1400
+ */
1401
+ deleteMarks: Set<string> | null;
1402
+ /**
1403
+ * Conservative "this subtree might hold a {@link Mark}" flag (own {@link DeltaData#marks} or any
1404
+ * descendant's). Set `true` when a mark is introduced and OR-propagated up to every ancestor; it is
1405
+ * **never** decremented (removal leaves it conservatively `true`). {@link
1406
+ * import('./position.js').marksToPositions} is the sole resetter: it prunes subtrees where this is
1407
+ * `false` (a guaranteed-empty subtree) and lazily clears a stale `true` to `false` when a descended
1408
+ * subtree turns out to hold none. `false` therefore *guarantees* no marks; `true` only *maybe*.
1409
+ */
1410
+ maybeHasMarks: boolean;
1177
1411
  }
1178
1412
  import * as prng from '../prng.js';
1413
+ /**
1414
+ * The set of leaf {@link Mark marks} on a single delta node, deduplicated by id (so adding the same id
1415
+ * again replaces it). An internal data-shape class (never a public/`new`-from-outside class): every
1416
+ * mutation goes through its methods, so a stored {@link Mark} is treated as immutable and is never
1417
+ * manipulated in place — to "move" a mark you replace it with a fresh `Mark`. {@link clone}/{@link
1418
+ * slice} copy the set so a `done` delta's marks are never mutated through a shared reference. Marks are
1419
+ * local/ephemeral cursor state
1420
+ * and not part of a delta's identity, so this set has no fingerprint/equality of its own.
1421
+ */
1422
+ declare class Marks {
1423
+ /**
1424
+ * @type {Array<Mark>}
1425
+ */
1426
+ _marks: Array<Mark>;
1427
+ get size(): number;
1428
+ /**
1429
+ * Add or replace `mark` (by id). Returns `true` if it was added as a new mark, `false` if it
1430
+ * replaced an existing one with the same id.
1431
+ *
1432
+ * @param {Mark} mark
1433
+ * @return {boolean}
1434
+ */
1435
+ add(mark: Mark): boolean;
1436
+ /**
1437
+ * Remove the mark with `id`. Returns `true` if a mark was present and removed, `false` if absent.
1438
+ *
1439
+ * @param {string} id
1440
+ * @return {boolean}
1441
+ */
1442
+ delete(id: string): boolean;
1443
+ [Symbol.iterator](): ArrayIterator<Mark>;
1444
+ }
1179
1445
  export {};
1180
1446
  //# sourceMappingURL=delta.d.ts.map