lib0 1.0.0-rc.2 → 1.0.0-rc.21

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 (141) hide show
  1. package/README.md +0 -1315
  2. package/{types → dist}/buffer.d.ts +2 -10
  3. package/{types → dist}/delta/delta.d.ts +582 -144
  4. package/dist/delta/position.d.ts +65 -0
  5. package/dist/delta/rdt/delta.d.ts +57 -0
  6. package/dist/delta/rdt/dom.d.ts +102 -0
  7. package/dist/delta/rdt.d.ts +180 -0
  8. package/dist/delta/transformer/attr.d.ts +64 -0
  9. package/dist/delta/transformer/attribution-to-format.d.ts +52 -0
  10. package/dist/delta/transformer/children.d.ts +69 -0
  11. package/dist/delta/transformer/conform.d.ts +83 -0
  12. package/dist/delta/transformer/core.d.ts +189 -0
  13. package/dist/delta/transformer/full-attributions.d.ts +37 -0
  14. package/dist/delta/transformer/id.d.ts +2 -0
  15. package/dist/delta/transformer/inline.d.ts +89 -0
  16. package/dist/delta/transformer/pipe.d.ts +182 -0
  17. package/dist/delta/transformer/project.d.ts +223 -0
  18. package/dist/delta/transformer/rename-attrs.d.ts +75 -0
  19. package/dist/delta/transformer/rename.d.ts +41 -0
  20. package/dist/delta/transformer/value.d.ts +92 -0
  21. package/dist/delta/transformer.d.ts +14 -0
  22. package/dist/diff/patience.d.ts +25 -0
  23. package/{types → dist}/environment.d.ts +10 -0
  24. package/dist/hash/fnv1a.d.ts +11 -0
  25. package/{types → dist}/schema.d.ts +49 -38
  26. package/{types → dist}/ts.d.ts +4 -0
  27. package/dist/webcrypto.d.ts +3 -0
  28. package/package.json +148 -82
  29. package/src/bin/0serve.js +11 -3
  30. package/src/broadcastchannel.js +6 -1
  31. package/src/buffer.js +35 -25
  32. package/src/decoding.js +1 -1
  33. package/src/delta/delta.js +2531 -564
  34. package/src/delta/position.js +165 -0
  35. package/src/delta/rdt/delta.js +105 -0
  36. package/src/delta/rdt/dom.js +307 -0
  37. package/src/delta/rdt.js +255 -0
  38. package/src/delta/transformer/attr.js +126 -0
  39. package/src/delta/transformer/attribution-to-format.js +335 -0
  40. package/src/delta/transformer/children.js +219 -0
  41. package/src/delta/transformer/conform.js +401 -0
  42. package/src/delta/transformer/core.js +323 -0
  43. package/src/delta/transformer/full-attributions.js +282 -0
  44. package/src/delta/transformer/id.js +13 -0
  45. package/src/delta/transformer/inline.js +818 -0
  46. package/src/delta/transformer/pipe.js +272 -0
  47. package/src/delta/transformer/project.js +526 -0
  48. package/src/delta/transformer/rename-attrs.js +152 -0
  49. package/src/delta/transformer/rename.js +84 -0
  50. package/src/delta/transformer/value.js +214 -0
  51. package/src/delta/transformer.js +38 -0
  52. package/src/diff/patience.js +22 -11
  53. package/src/dom.js +2 -2
  54. package/src/encoding.js +1 -1
  55. package/src/environment.js +15 -0
  56. package/src/hash/fnv1a.js +82 -0
  57. package/src/number.js +1 -3
  58. package/src/performance.node.js +3 -3
  59. package/src/schema.js +231 -177
  60. package/src/string.js +3 -5
  61. package/src/testing.js +1 -1
  62. package/src/trait/equality.js +1 -1
  63. package/src/trait/fingerprint.js +1 -1
  64. package/src/ts.js +11 -0
  65. package/src/bin/gendocs.js +0 -117
  66. package/src/component.js +0 -414
  67. package/src/delta/binding.js +0 -372
  68. package/src/tree.js +0 -546
  69. package/types/bin/gendocs.d.ts +0 -3
  70. package/types/component.d.ts +0 -86
  71. package/types/delta/binding.d.ts +0 -106
  72. package/types/diff/patience.d.ts +0 -16
  73. package/types/tree.d.ts +0 -96
  74. package/types/webcrypto.d.ts +0 -3
  75. /package/{types → dist}/array.d.ts +0 -0
  76. /package/{types → dist}/bin/0ecdsa-generate-keypair.d.ts +0 -0
  77. /package/{types → dist}/bin/0serve.d.ts +0 -0
  78. /package/{types → dist}/bin/gentesthtml.d.ts +0 -0
  79. /package/{types → dist}/binary.d.ts +0 -0
  80. /package/{types → dist}/broadcastchannel.d.ts +0 -0
  81. /package/{types → dist}/cache.d.ts +0 -0
  82. /package/{types → dist}/conditions.d.ts +0 -0
  83. /package/{types → dist}/crypto/aes-gcm.d.ts +0 -0
  84. /package/{types → dist}/crypto/common.d.ts +0 -0
  85. /package/{types → dist}/crypto/ecdsa.d.ts +0 -0
  86. /package/{types → dist}/crypto/jwt.d.ts +0 -0
  87. /package/{types → dist}/crypto/rsa-oaep.d.ts +0 -0
  88. /package/{types → dist}/decoding.d.ts +0 -0
  89. /package/{types → dist}/diff.d.ts +0 -0
  90. /package/{types → dist}/dom.d.ts +0 -0
  91. /package/{types → dist}/encoding.d.ts +0 -0
  92. /package/{types → dist}/error.d.ts +0 -0
  93. /package/{types → dist}/eventloop.d.ts +0 -0
  94. /package/{types → dist}/function.d.ts +0 -0
  95. /package/{types → dist}/hash/rabin-gf2-polynomial.d.ts +0 -0
  96. /package/{types → dist}/hash/rabin-uncached.d.ts +0 -0
  97. /package/{types → dist}/hash/rabin.d.ts +0 -0
  98. /package/{types → dist}/hash/sha256.d.ts +0 -0
  99. /package/{types → dist}/hash/sha256.node.d.ts +0 -0
  100. /package/{types → dist}/indexeddb.d.ts +0 -0
  101. /package/{types → dist}/indexeddbV2.d.ts +0 -0
  102. /package/{types → dist}/iterator.d.ts +0 -0
  103. /package/{types → dist}/json.d.ts +0 -0
  104. /package/{types → dist}/list.d.ts +0 -0
  105. /package/{types → dist}/logging.common.d.ts +0 -0
  106. /package/{types → dist}/logging.d.ts +0 -0
  107. /package/{types → dist}/logging.node.d.ts +0 -0
  108. /package/{types → dist}/map.d.ts +0 -0
  109. /package/{types → dist}/math.d.ts +0 -0
  110. /package/{types → dist}/metric.d.ts +0 -0
  111. /package/{types → dist}/mutex.d.ts +0 -0
  112. /package/{types → dist}/number.d.ts +0 -0
  113. /package/{types → dist}/object.d.ts +0 -0
  114. /package/{types → dist}/observable.d.ts +0 -0
  115. /package/{types → dist}/pair.d.ts +0 -0
  116. /package/{types → dist}/performance.d.ts +0 -0
  117. /package/{types → dist}/performance.node.d.ts +0 -0
  118. /package/{types → dist}/pledge.d.ts +0 -0
  119. /package/{types → dist}/prng/Mt19937.d.ts +0 -0
  120. /package/{types → dist}/prng/Xoroshiro128plus.d.ts +0 -0
  121. /package/{types → dist}/prng/Xorshift32.d.ts +0 -0
  122. /package/{types → dist}/prng.d.ts +0 -0
  123. /package/{types → dist}/promise.d.ts +0 -0
  124. /package/{types → dist}/queue.d.ts +0 -0
  125. /package/{types → dist}/random.d.ts +0 -0
  126. /package/{types → dist}/set.d.ts +0 -0
  127. /package/{types → dist}/sort.d.ts +0 -0
  128. /package/{types → dist}/statistics.d.ts +0 -0
  129. /package/{types → dist}/storage.d.ts +0 -0
  130. /package/{types → dist}/string.d.ts +0 -0
  131. /package/{types → dist}/symbol.d.ts +0 -0
  132. /package/{types → dist}/testing.d.ts +0 -0
  133. /package/{types → dist}/time.d.ts +0 -0
  134. /package/{types → dist}/trait/equality.d.ts +0 -0
  135. /package/{types → dist}/trait/fingerprint.d.ts +0 -0
  136. /package/{types → dist}/trait/traits.d.ts +0 -0
  137. /package/{types → dist}/url.d.ts +0 -0
  138. /package/{types → dist}/webcrypto.deno.d.ts +0 -0
  139. /package/{types → dist}/webcrypto.node.d.ts +0 -0
  140. /package/{types → dist}/webcrypto.react-native.d.ts +0 -0
  141. /package/{types → dist}/websocket.d.ts +0 -0
@@ -0,0 +1,65 @@
1
+ /**
2
+ * A single step of a {@link Pos} path: a `string` attribute key, or a `number` content index.
3
+ *
4
+ * @typedef {string|number} PosStep
5
+ */
6
+ /**
7
+ * A location in a delta tree. `path` descends from the node the position is relative to and ends in
8
+ * the terminal (a trailing-number cursor gap, or a trailing-string attribute leaf). `assoc` is the
9
+ * gravity at a boundary: `-1` binds to the preceding content, `1` to the following content. `attrs` is
10
+ * optional immutable user data carried with the position (e.g. an RDT's clientID/user metadata); it is
11
+ * stored on the {@link import('./delta.js').createMark mark} when the position is written with
12
+ * {@link import('./delta.js').DeltaBuilder#addMark} and read back by {@link marksToPositions}.
13
+ *
14
+ * @typedef {{ path: Array<PosStep>, assoc: -1|1, attrs?: object|null }} Pos
15
+ */
16
+ /**
17
+ * A {@link Pos} tagged with the unique id of a stored {@link import('./delta.js').createMark mark} —
18
+ * what {@link marksToPositions} returns (its `attrs` is the mark's stored metadata). Add marks with
19
+ * {@link import('./delta.js').DeltaBuilder#addMark}.
20
+ *
21
+ * @typedef {{ id: string } & Pos} MarkPos
22
+ */
23
+ /**
24
+ * Schema for a {@link Pos}.
25
+ *
26
+ * @type {s.Schema<Pos>}
27
+ */
28
+ export const $pos: s.Schema<Pos>;
29
+ export function create(path: Array<PosStep>, assoc?: -1 | 1, attrs?: object | null): Pos;
30
+ export function equals(a: Pos | MarkPos, b: Pos | MarkPos): boolean;
31
+ /**
32
+ * Schema for a {@link MarkPos}.
33
+ *
34
+ * @type {s.Schema<MarkPos>}
35
+ */
36
+ export const $markPos: s.Schema<MarkPos>;
37
+ export function marksToPositions(d: delta.DeltaAny): Array<MarkPos>;
38
+ /**
39
+ * A single step of a {@link Pos} path: a `string` attribute key, or a `number` content index.
40
+ */
41
+ export type PosStep = string | number;
42
+ /**
43
+ * A location in a delta tree. `path` descends from the node the position is relative to and ends in
44
+ * the terminal (a trailing-number cursor gap, or a trailing-string attribute leaf). `assoc` is the
45
+ * gravity at a boundary: `-1` binds to the preceding content, `1` to the following content. `attrs` is
46
+ * optional immutable user data carried with the position (e.g. an RDT's clientID/user metadata); it is
47
+ * stored on the {@link import ('./delta.js').createMark mark} when the position is written with
48
+ * {@link import ('./delta.js').DeltaBuilder#addMark} and read back by {@link marksToPositions}.
49
+ */
50
+ export type Pos = {
51
+ path: Array<PosStep>;
52
+ assoc: -1 | 1;
53
+ attrs?: object | null;
54
+ };
55
+ /**
56
+ * A {@link Pos} tagged with the unique id of a stored {@link import ('./delta.js').createMark mark} —
57
+ * what {@link marksToPositions} returns (its `attrs` is the mark's stored metadata). Add marks with
58
+ * {@link import ('./delta.js').DeltaBuilder#addMark}.
59
+ */
60
+ export type MarkPos = {
61
+ id: string;
62
+ } & Pos;
63
+ import * as s from '../schema.js';
64
+ import * as delta from './delta.js';
65
+ //# sourceMappingURL=position.d.ts.map
@@ -0,0 +1,57 @@
1
+ export function deltaRDT<Conf extends delta.DeltaConf>($delta: Schema<delta.Delta<Conf>>): DeltaRDT<Conf>;
2
+ export type Schema<T> = import("../../schema.js").Schema<T>;
3
+ export type RDT<Conf extends delta.DeltaConf> = import("../rdt.js").RDT<Conf>;
4
+ import * as delta from '../delta.js';
5
+ /**
6
+ * @template T
7
+ * @typedef {import('../../schema.js').Schema<T>} Schema
8
+ */
9
+ /**
10
+ * @template {delta.DeltaConf} Conf
11
+ * @typedef {import('../rdt.js').RDT<Conf>} RDT
12
+ */
13
+ /**
14
+ * An in-memory RDT whose state is the accumulated delta. Calling `applyDelta` merges the incoming delta
15
+ * into `state` (via {@link delta.DeltaBuilder#apply}) and re-emits it as a `'delta'`.
16
+ *
17
+ * @template {delta.DeltaConf} Conf
18
+ * @implements {RDT<Conf>}
19
+ * @extends {ObservableV2<{ delta: (delta: delta.Delta<Conf>, origin: any) => void, destroy: (rdt: DeltaRDT<Conf>) => void }>}
20
+ */
21
+ declare class DeltaRDT<Conf extends delta.DeltaConf> extends ObservableV2<{
22
+ delta: (delta: delta.Delta<Conf>, origin: any) => void;
23
+ destroy: (rdt: DeltaRDT<Conf>) => void;
24
+ }> implements RDT<Conf> {
25
+ /**
26
+ * @param {Schema<delta.Delta<Conf>>} $delta schema of the deltas this RDT produces
27
+ */
28
+ constructor($delta: Schema<delta.Delta<Conf>>);
29
+ $delta: import("../../schema.js").Schema<delta.Delta<Conf>>;
30
+ /**
31
+ * @type {delta.DeltaBuilderAny?}
32
+ */
33
+ state: delta.DeltaBuilderAny | null;
34
+ _mux: mux.mutex;
35
+ /**
36
+ * Merge an incoming delta into the current state and notify observers. Always returns `null`: this
37
+ * RDT accepts every valid delta unchanged, so it never produces a fix.
38
+ *
39
+ * @param {delta.Delta<Conf>} d
40
+ * @param {any} [origin] who produced the change; forwarded verbatim on the emitted `'delta'` event so
41
+ * listeners can recognise (and skip) changes they made themselves — see {@link RDT} “Origins”. Defaults
42
+ * to `null` (an anonymous/local change).
43
+ * @return {null}
44
+ */
45
+ applyDelta(d: delta.Delta<Conf>, origin?: any): null;
46
+ /**
47
+ * The current state as a delta: the accumulated `state`, or an empty delta when nothing has been
48
+ * applied yet.
49
+ *
50
+ * @return {delta.Delta<Conf>}
51
+ */
52
+ get delta(): delta.Delta<Conf>;
53
+ }
54
+ import { ObservableV2 } from '../../observable.js';
55
+ import * as mux from '../../mutex.js';
56
+ export {};
57
+ //# sourceMappingURL=delta.d.ts.map
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Schema describing the deltas produced/consumed by a {@link DomRDT}: a recursive node with a string
3
+ * name, string→string attributes, and text content.
4
+ */
5
+ export const $domDelta: s.Schema<delta.Delta<{
6
+ name: string;
7
+ attrs: {
8
+ [x: string]: string;
9
+ };
10
+ text: true;
11
+ recursiveChildren: true;
12
+ }>>;
13
+ export function domRDT(dom: Element): DomRDT;
14
+ export type Schema<T> = import("../../schema.js").Schema<T>;
15
+ export type RDT<Conf extends delta.DeltaConf> = import("../rdt.js").RDT<Conf>;
16
+ /**
17
+ * The {@link delta.DeltaConf} of the deltas a {@link DomRDT} produces/consumes (see {@link $domDelta}).
18
+ */
19
+ export type DomConf = {
20
+ name: string;
21
+ attrs: {
22
+ [key: string]: string;
23
+ };
24
+ text: true;
25
+ recursiveChildren: true;
26
+ };
27
+ export type DomDelta = delta.Delta<DomConf>;
28
+ import * as delta from '../delta.js';
29
+ import * as s from '../../schema.js';
30
+ /**
31
+ * The {@link delta.DeltaConf} of the deltas a {@link DomRDT} produces/consumes (see {@link $domDelta}).
32
+ *
33
+ * @typedef {{ name: string, attrs: { [key:string]: string }, text: true, recursiveChildren: true }} DomConf
34
+ */
35
+ /**
36
+ * @typedef {delta.Delta<DomConf>} DomDelta
37
+ */
38
+ /**
39
+ * An RDT backed by a live DOM subtree. DOM mutations observed via `MutationObserver` are diffed
40
+ * against the last-known state and emitted as deltas; incoming deltas are applied back onto the DOM.
41
+ *
42
+ * @implements {RDT<DomConf>}
43
+ * @extends {ObservableV2<{ delta: (delta: delta.Delta<DomConf>, origin: any) => void, destroy: (rdt: DomRDT) => void }>}
44
+ */
45
+ declare class DomRDT extends ObservableV2<{
46
+ delta: (delta: delta.Delta<DomConf>, origin: any) => void;
47
+ destroy: (rdt: DomRDT) => void;
48
+ }> implements RDT<DomConf> {
49
+ /**
50
+ * @param {Element} observedNode
51
+ */
52
+ constructor(observedNode: Element);
53
+ /**
54
+ * @type {Schema<DomDelta>}
55
+ */
56
+ $delta: Schema<DomDelta>;
57
+ observedNode: Element;
58
+ /**
59
+ * Last-known DOM state. The observe path diffs the live DOM against this to compute the change to
60
+ * emit, then advances it; `applyDelta` re-syncs it after mutating the DOM.
61
+ *
62
+ * @type {DomDelta}
63
+ */
64
+ _state: DomDelta;
65
+ observer: MutationObserver;
66
+ /**
67
+ * Pull the local DOM changes accumulated since the last sync as a delta (by diffing the live DOM
68
+ * against `_state`), advancing `_state` to the current DOM.
69
+ *
70
+ * @return {DomDelta}
71
+ */
72
+ _pull(): DomDelta;
73
+ /**
74
+ * @param {MutationRecord[]} mutations
75
+ */
76
+ _mutationHandler: (mutations: MutationRecord[]) => void;
77
+ /**
78
+ * Apply a foreign delta onto the DOM.
79
+ *
80
+ * The DOM may have been edited locally (`b`) since the last sync, concurrently with the incoming
81
+ * change (`d`). We pull `b` first and rebase the two against each other (OT) so neither is lost:
82
+ * `d` rebased onto `b` is applied to the DOM, and `b` rebased onto `d` is returned as the fix so the
83
+ * binding pipes it back through the transformer to the other side.
84
+ *
85
+ * @param {delta.Delta<DomConf>} d
86
+ * @param {any} [origin] who produced `d`; forwarded verbatim on the emitted `'delta'` event so
87
+ * listeners can recognise (and skip) their own changes — see {@link RDT} “Origins”. Defaults to `null`
88
+ * (an anonymous/local change).
89
+ * @return {delta.DeltaBuilder<DomConf> | null} the rebased local change (`b`), or `null` when there
90
+ * were no concurrent edits
91
+ */
92
+ applyDelta(d: delta.Delta<DomConf>, origin?: any): delta.DeltaBuilder<DomConf> | null;
93
+ /**
94
+ * The current state as a delta: an "insert everything" delta describing the observed subtree.
95
+ *
96
+ * @return {delta.Delta<DomConf>}
97
+ */
98
+ get delta(): delta.Delta<DomConf>;
99
+ }
100
+ import { ObservableV2 } from '../../observable.js';
101
+ export {};
102
+ //# sourceMappingURL=dom.d.ts.map
@@ -0,0 +1,180 @@
1
+ export { deltaRDT } from "./rdt/delta.js";
2
+ /**
3
+ * @template T
4
+ * @typedef {import('../schema.js').Schema<T>} Schema
5
+ */
6
+ /**
7
+ * Abstract interface for a delta-based Replicated Data Type.
8
+ *
9
+ * An RDT is an observable that emits a `'delta'` (and, on teardown, a `'destroy'`) event, exposes the
10
+ * {@link Schema schema} of the deltas it produces via `$delta` (so a {@link Binding} can initialize a
11
+ * transformer for it), exposes its current state as a delta via the `delta` getter, and accepts foreign
12
+ * deltas via `applyDelta`.
13
+ *
14
+ * `applyDelta(d, origin)` applies `d` and then, if the change would violate the RDT's own invariants,
15
+ * applies a **fix** of its own (e.g. reversing part of `d`, or inserting missing content) and returns
16
+ * that fix — `null` when none was needed. The fix is a regular change on this RDT, so a {@link Binding}
17
+ * maps it onto the other side just like any other change. `applyDelta` also emits the *effective* change
18
+ * (`d` together with the fix) on the `'delta'` channel.
19
+ *
20
+ * ## Origins
21
+ *
22
+ * Every `'delta'` event carries a second argument, `origin` — an opaque `any` value (modelled after
23
+ * {@link https://docs.yjs.dev/api/transactions Yjs transaction origins}) that identifies **where the
24
+ * change came from**. Whoever produces the change sets it, and it is usually the producing instance
25
+ * itself: a communication provider, an editor binding, or the {@link Binding} that mapped the change
26
+ * over from the other side. A change an RDT observes locally (e.g. a `MutationObserver` firing on a DOM
27
+ * edit) uses that RDT itself as the origin.
28
+ *
29
+ * Origins let a listener tell **its own** changes apart from foreign ones so it can skip the ones it
30
+ * already knows about — a change it produced is not looped back to where it came from. The canonical use
31
+ * is a network provider: it tags every remote update it applies with itself (`rdt.applyDelta(update,
32
+ * this)`) and then ignores `'delta'` events whose `origin === this`, so it never re-broadcasts an update
33
+ * it just received. The `origin` argument to `applyDelta` is optional and defaults to `null` (an
34
+ * anonymous/local change); the emitted event always carries whatever value was supplied.
35
+ *
36
+ * ## `Delta` vs `DeltaBuilder`
37
+ *
38
+ * The interface is parameterized by a {@link import('./delta.js').DeltaConf DeltaConf} (like a
39
+ * {@link import('./transformer.js').Transformer transformer}). Almost everything it exposes is the
40
+ * *read* form — {@link import('./delta.js').Delta Delta} — because those values are **shared** and must
41
+ * not be mutated in place: `$delta` is the delta schema, the `delta` getter returns a state snapshot,
42
+ * `applyDelta` reads a change into the RDT, and the `'delta'` event payload is broadcast to every
43
+ * listener. The one *owned, mutable* form — {@link import('./delta.js').DeltaBuilder DeltaBuilder} — is
44
+ * the fix `applyDelta` returns to the {@link Binding}. The binding never mutates a shared read delta: it
45
+ * {@link import('./delta.js').cloneDeep deep-clones} every change into a private builder before the
46
+ * transformer rebases it (transformers manipulate deltas in place — see {@link Binding}).
47
+ *
48
+ * @template {import('./delta.js').DeltaConf} Conf
49
+ * @typedef {import('../observable.js').ObservableV2<{ delta: (delta: delta.Delta<Conf>, origin: any) => void, destroy: (rdt: RDT<Conf>) => void }> & {
50
+ * $delta: Schema<delta.Delta<Conf>>,
51
+ * delta: delta.Delta<Conf>,
52
+ * applyDelta: (delta: delta.Delta<Conf>, origin?: any) => delta.DeltaBuilder<Conf> | null,
53
+ * destroy: () => void
54
+ * }} RDT
55
+ */
56
+ /**
57
+ * Schema guard for any {@link RDT}. RDTs are **duck-typed** — they have several independent
58
+ * implementations (`deltaRDT`, `domRDT`, …) and no common constructor — so this matches by shape
59
+ * rather than by `instanceof`: an object exposing a `$delta` {@link Schema}, an `applyDelta` method,
60
+ * and the observable `on`/`destroy` channel. The (possibly expensive) `delta` getter is not invoked.
61
+ *
62
+ * @type {Schema<RDT<any>>}
63
+ */
64
+ export const $rdt: Schema<RDT<any>>;
65
+ /**
66
+ * @typedef {object} BindOptions
67
+ * @property {delta.DiffOptions['compare']} [diffCompare] **Experimental** (may be changed or removed
68
+ * in a future release). Forwarded as `compare` to {@link delta.diff} when the initial-state sync diffs
69
+ * `a`'s projection against `b`'s current state, controlling how nodes are paired into `modify` ops.
70
+ */
71
+ /**
72
+ * Connects two RDTs so that changes on either side are transformed and reflected on the other.
73
+ *
74
+ * The {@link dt.Transformer transformer} it drives **manipulates deltas in place** (it splices op lists
75
+ * and rebases nodes directly, rather than only via `apply`/`rebase`) — a deliberate exception to the
76
+ * general rule that deltas are edited through `apply`/`rebase`. Consequently every change handed to it
77
+ * must be a privately-owned, fully-mutable delta, so the binding {@link delta.cloneDeep deep-clones}
78
+ * each incoming change (which is a shared read delta — an event payload or a snapshot) before the
79
+ * transformer touches it. See the initial-state sync below and {@link propagate}.
80
+ *
81
+ * @template {delta.DeltaConf} A
82
+ * @template {delta.DeltaConf} B
83
+ */
84
+ export class Binding<A extends delta.DeltaConf, B extends delta.DeltaConf> {
85
+ /**
86
+ * @param {RDT<A>} a
87
+ * @param {RDT<B>} b
88
+ * @param {dt.TemplateFactory<A,B>} [template] a `$d => Template` factory; defaults to the
89
+ * {@link dt.id identity} transformer. `bind` injects `a`'s schema, then materializes via `.init()`.
90
+ * @param {BindOptions} [options]
91
+ */
92
+ constructor(a: RDT<A>, b: RDT<B>, template?: dt.TemplateFactory<A, B>, options?: BindOptions);
93
+ /**
94
+ * @type {dt.Transformer<A,B>}
95
+ */
96
+ t: dt.Transformer<A, B>;
97
+ /**
98
+ * @type {RDT<A>}
99
+ */
100
+ a: RDT<A>;
101
+ /**
102
+ * @type {RDT<B>}
103
+ */
104
+ b: RDT<B>;
105
+ _mux: mux.mutex;
106
+ _achanged: (delta: delta.Delta<A>, origin: any) => void;
107
+ _bchanged: (delta: delta.Delta<B>, origin: any) => void;
108
+ /**
109
+ * Tear the binding down: unsubscribe both sides' `'delta'` and `'destroy'` listeners so changes are no
110
+ * longer propagated. Call this when you no longer need the two RDTs kept in sync. It is also invoked
111
+ * automatically when either bound RDT emits `'destroy'`. The RDTs themselves are NOT destroyed.
112
+ */
113
+ destroy: () => void;
114
+ }
115
+ export function bind<A extends delta.DeltaConf, B extends delta.DeltaConf>(a: RDT<A>, b: RDT<B>, template?: dt.TemplateFactory<A, B>, options?: BindOptions): Binding<A, B>;
116
+ export type Schema<T> = import("../schema.js").Schema<T>;
117
+ /**
118
+ * Abstract interface for a delta-based Replicated Data Type.
119
+ *
120
+ * An RDT is an observable that emits a `'delta'` (and, on teardown, a `'destroy'`) event, exposes the
121
+ * {@link Schema schema} of the deltas it produces via `$delta` (so a {@link Binding} can initialize a
122
+ * transformer for it), exposes its current state as a delta via the `delta` getter, and accepts foreign
123
+ * deltas via `applyDelta`.
124
+ *
125
+ * `applyDelta(d, origin)` applies `d` and then, if the change would violate the RDT's own invariants,
126
+ * applies a **fix** of its own (e.g. reversing part of `d`, or inserting missing content) and returns
127
+ * that fix — `null` when none was needed. The fix is a regular change on this RDT, so a {@link Binding}
128
+ * maps it onto the other side just like any other change. `applyDelta` also emits the *effective* change
129
+ * (`d` together with the fix) on the `'delta'` channel.
130
+ *
131
+ * ## Origins
132
+ *
133
+ * Every `'delta'` event carries a second argument, `origin` — an opaque `any` value (modelled after
134
+ * {@link https://docs.yjs.dev/api/transactions Yjs transaction origins}) that identifies **where the
135
+ * change came from**. Whoever produces the change sets it, and it is usually the producing instance
136
+ * itself: a communication provider, an editor binding, or the {@link Binding} that mapped the change
137
+ * over from the other side. A change an RDT observes locally (e.g. a `MutationObserver` firing on a DOM
138
+ * edit) uses that RDT itself as the origin.
139
+ *
140
+ * Origins let a listener tell **its own** changes apart from foreign ones so it can skip the ones it
141
+ * already knows about — a change it produced is not looped back to where it came from. The canonical use
142
+ * is a network provider: it tags every remote update it applies with itself (`rdt.applyDelta(update,
143
+ * this)`) and then ignores `'delta'` events whose `origin === this`, so it never re-broadcasts an update
144
+ * it just received. The `origin` argument to `applyDelta` is optional and defaults to `null` (an
145
+ * anonymous/local change); the emitted event always carries whatever value was supplied.
146
+ *
147
+ * ## `Delta` vs `DeltaBuilder`
148
+ *
149
+ * The interface is parameterized by a {@link import ('./delta.js').DeltaConf DeltaConf} (like a
150
+ * {@link import ('./transformer.js').Transformer transformer}). Almost everything it exposes is the
151
+ * *read* form — {@link import ('./delta.js').Delta Delta} — because those values are **shared** and must
152
+ * not be mutated in place: `$delta` is the delta schema, the `delta` getter returns a state snapshot,
153
+ * `applyDelta` reads a change into the RDT, and the `'delta'` event payload is broadcast to every
154
+ * listener. The one *owned, mutable* form — {@link import ('./delta.js').DeltaBuilder DeltaBuilder} — is
155
+ * the fix `applyDelta` returns to the {@link Binding}. The binding never mutates a shared read delta: it
156
+ * {@link import ('./delta.js').cloneDeep deep-clones} every change into a private builder before the
157
+ * transformer rebases it (transformers manipulate deltas in place — see {@link Binding}).
158
+ */
159
+ export type RDT<Conf extends import("./delta.js").DeltaConf> = import("../observable.js").ObservableV2<{
160
+ delta: (delta: delta.Delta<Conf>, origin: any) => void;
161
+ destroy: (rdt: RDT<Conf>) => void;
162
+ }> & {
163
+ $delta: Schema<delta.Delta<Conf>>;
164
+ delta: delta.Delta<Conf>;
165
+ applyDelta: (delta: delta.Delta<Conf>, origin?: any) => delta.DeltaBuilder<Conf> | null;
166
+ destroy: () => void;
167
+ };
168
+ export type BindOptions = {
169
+ /**
170
+ * **Experimental** (may be changed or removed
171
+ * in a future release). Forwarded as `compare` to {@link delta.diff} when the initial-state sync diffs
172
+ * `a`'s projection against `b`'s current state, controlling how nodes are paired into `modify` ops.
173
+ */
174
+ diffCompare?: delta.DiffOptions["compare"];
175
+ };
176
+ import * as delta from './delta.js';
177
+ import * as dt from './transformer.js';
178
+ import * as mux from '../mutex.js';
179
+ export { $domDelta, domRDT } from "./rdt/dom.js";
180
+ //# sourceMappingURL=rdt.d.ts.map
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Projects a single node attribute into a `lib0:value` node's `value` attribute (and back).
3
+ *
4
+ * @template {string} AttrName
5
+ * @template {delta.DeltaConf} [IN=any]
6
+ * @extends {Template<IN, ApplyAttr<AttrName, IN>>}
7
+ */
8
+ export class Attr<AttrName extends string, IN extends delta.DeltaConf = any> extends Template<IN, {
9
+ name: "lib0:value";
10
+ attrs: {
11
+ value: delta._SanifyDelta<IN extends {
12
+ attrs: { [K in AttrName]: infer V; };
13
+ } ? V : never>;
14
+ };
15
+ }> {
16
+ /**
17
+ * @param {import('../../schema.js').Schema<delta.Delta<IN>>} $d
18
+ * @param {AttrName} attrName
19
+ */
20
+ constructor($d: import("../../schema.js").Schema<delta.Delta<IN>>, attrName: AttrName);
21
+ attrName: AttrName;
22
+ }
23
+ /**
24
+ * @template {delta.DeltaConf} A
25
+ * @template {delta.DeltaConf} B
26
+ * @extends {Transformer<A,B>}
27
+ */
28
+ export class AttrTransformer<A extends delta.DeltaConf, B extends delta.DeltaConf> extends Transformer<A, B> {
29
+ /**
30
+ * @param {import('../../schema.js').Schema<delta.Delta<any>>} $in
31
+ * @param {import('../../schema.js').Schema<delta.Delta<any>>} $out
32
+ * @param {string} attrName
33
+ */
34
+ constructor($in: import("../../schema.js").Schema<delta.Delta<any>>, $out: import("../../schema.js").Schema<delta.Delta<any>>, attrName: string);
35
+ attrName: keyof import("../../ts.js").TypeIsAny<A, {
36
+ [K: string]: any;
37
+ [K: number]: any;
38
+ }, A extends {
39
+ attrs: infer Attrs;
40
+ } ? Attrs extends undefined ? {} : Attrs : {}> & (string | number);
41
+ /**
42
+ * @param {delta.DeltaBuilder<A>} d
43
+ * @return {import('./core.js').TransformResultAny}
44
+ */
45
+ applyA(d: delta.DeltaBuilder<A>): import("./core.js").TransformResultAny;
46
+ /**
47
+ * @param {delta.DeltaBuilder<B>} d
48
+ * @return {import('./core.js').TransformResultAny}
49
+ */
50
+ applyB(d: delta.DeltaBuilder<B>): import("./core.js").TransformResultAny;
51
+ }
52
+ export function attr<AttrName extends string, IN extends delta.DeltaConf>($d: import("../../schema.js").Schema<delta.Delta<IN>>, attrName: AttrName): Attr<AttrName, IN>;
53
+ export type ApplyAttr<AttrName extends string, IN extends delta.DeltaConf> = import("./core.js").ResolveOut<{
54
+ name: "lib0:value";
55
+ attrs: {
56
+ value: IN extends {
57
+ attrs: { [K in AttrName]: infer V; };
58
+ } ? V : never;
59
+ };
60
+ }>;
61
+ import * as delta from '../delta.js';
62
+ import { Template } from './core.js';
63
+ import { Transformer } from './core.js';
64
+ //# sourceMappingURL=attr.d.ts.map
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Stateless transformer (holds only its `conf`); a single shared instance per template suffices.
3
+ *
4
+ * @extends {Transformer<any,any>}
5
+ */
6
+ export class AttributionToFormatTransformer extends Transformer<any, any> {
7
+ /**
8
+ * @param {import('../../schema.js').Schema<delta.Delta<any>>} $in
9
+ * @param {import('../../schema.js').Schema<delta.Delta<any>>} $out
10
+ * @param {Conf} conf
11
+ */
12
+ constructor($in: import("../../schema.js").Schema<delta.Delta<any>>, $out: import("../../schema.js").Schema<delta.Delta<any>>, conf: Conf);
13
+ conf: Conf;
14
+ }
15
+ /**
16
+ * Template for {@link AttributionToFormatTransformer}.
17
+ *
18
+ * @template {delta.DeltaConf} [IN=any]
19
+ * @extends {Template<IN, any>}
20
+ */
21
+ export class AttributionToFormat<IN extends delta.DeltaConf = any> extends Template<IN, any> {
22
+ /**
23
+ * @param {import('../../schema.js').Schema<delta.Delta<IN>>} $d
24
+ * @param {Conf} conf
25
+ */
26
+ constructor($d: import("../../schema.js").Schema<delta.Delta<IN>>, conf: Conf);
27
+ /**
28
+ * @type {Conf}
29
+ */
30
+ conf: Conf;
31
+ }
32
+ export function attributionToFormat<IN extends delta.DeltaConf>($d: import("../../schema.js").Schema<delta.Delta<IN>>, conf: Conf): AttributionToFormat<IN>;
33
+ /**
34
+ * Maps an attribution object to the format value placed under its namespaced key (or `null` to clear
35
+ * that key, `{}`/`undefined` to leave it unchanged).
36
+ */
37
+ export type Handler = (attribution: import("../delta.js").Attribution) => any;
38
+ /**
39
+ * Per-dimension handlers. Each fires when the op's attribution has a key with that dimension's prefix
40
+ * (`insert`/`insertAt` → `insert`, etc.); the whole attribution object is passed in. A missing handler
41
+ * means "do not render that dimension".
42
+ */
43
+ export type Conf = {
44
+ insert?: Handler;
45
+ delete?: Handler;
46
+ format?: Handler;
47
+ attrs?: Handler;
48
+ };
49
+ import { Transformer } from './core.js';
50
+ import * as delta from '../delta.js';
51
+ import { Template } from './core.js';
52
+ //# sourceMappingURL=attribution-to-format.d.ts.map
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Stateful transformer that descends one level into a node's child *nodes* and applies a per-child
3
+ * sub-transformer, chosen by `handler`. Attributes and text pass through untouched. Designed to be
4
+ * applied recursively (see {@link children}).
5
+ *
6
+ * The per-child sub-transformer instances are kept in {@link ChildrenTransformer#childTs}, positionally
7
+ * aligned to the parent's child list (children carry no stable id - identity is positional). `children`
8
+ * never changes the child count at its own level, so side A and side B stay aligned position-for-
9
+ * position and the same `childTs` indexes both directions.
10
+ *
11
+ * `childTs` is a sparse positional map kept as a delta: each transformed child is an `insert([t])` op
12
+ * holding its sub-transformer; every other position (text runs, opted-out nodes) is a coalesced
13
+ * `retain(n)` gap. A run of N text characters costs one retain op, not N array slots. It is walked with
14
+ * a forward cursor in step with the change (see {@link ChildrenTransformer#transform}). Transformer
15
+ * instances are carried by reference across rebuilds, so their per-instance state survives.
16
+ *
17
+ * @extends {Transformer<any,any>}
18
+ */
19
+ export class ChildrenTransformer extends Transformer<any, any> {
20
+ /**
21
+ * @param {import('../../schema.js').Schema<delta.Delta<any>>} $in
22
+ * @param {import('../../schema.js').Schema<delta.Delta<any>>} $out
23
+ * @param {(child: delta.DeltaAny, $child: import('../../schema.js').Schema<delta.DeltaAny>) => Template | null} handler
24
+ * picks the (schema-bound) template for a child node, or `null` to leave it untransformed. Evaluated
25
+ * once, when the child is inserted, with the derived per-child schema.
26
+ * @param {import('../../schema.js').Schema<delta.DeltaAny>} childSchema per-child-node schema each
27
+ * sub-template is built against (derived from the parent's input schema; `$deltaAny` when not derivable).
28
+ */
29
+ constructor($in: import("../../schema.js").Schema<delta.Delta<any>>, $out: import("../../schema.js").Schema<delta.Delta<any>>, handler: (child: delta.DeltaAny, $child: import("../../schema.js").Schema<delta.DeltaAny>) => Template | null, childSchema: import("../../schema.js").Schema<delta.DeltaAny>);
30
+ handler: (child: delta.DeltaAny, $child: import("../../schema.js").Schema<delta.DeltaAny>) => Template | null;
31
+ /**
32
+ * Sparse positional map of sub-transformers: `insert([t])` at each transformed child, `retain(n)`
33
+ * over gaps (text and opted-out nodes).
34
+ *
35
+ * @type {delta.DeltaBuilderAny}
36
+ */
37
+ childTs: delta.DeltaBuilderAny;
38
+ childSchema: import("../../schema.js").Schema<delta.DeltaAny>;
39
+ /**
40
+ * @param {delta.DeltaBuilderAny} d the change to map
41
+ * @param {boolean} fwd `true` maps side A -> B (applying sub-transformers' `applyA`), `false` maps
42
+ * side B -> A. `children` is 1:1 over children, so the same `childTs` indexes both directions.
43
+ * @return {import('./core.js').TransformResultAny}
44
+ */
45
+ transform(d: delta.DeltaBuilderAny, fwd: boolean): import("./core.js").TransformResultAny;
46
+ }
47
+ /**
48
+ * Template for {@link ChildrenTransformer}.
49
+ *
50
+ * @template {delta.DeltaConf} [IN=any]
51
+ * @extends {Template<IN, any>}
52
+ */
53
+ export class Children<IN extends delta.DeltaConf = any> extends Template<IN, any> {
54
+ /**
55
+ * @param {import('../../schema.js').Schema<delta.Delta<IN>>} $d
56
+ * @param {(child: delta.DeltaAny, $child: import('../../schema.js').Schema<delta.DeltaAny>) => Template | null} handler
57
+ */
58
+ constructor($d: import("../../schema.js").Schema<delta.Delta<IN>>, handler: (child: delta.DeltaAny, $child: import("../../schema.js").Schema<delta.DeltaAny>) => Template | null);
59
+ handler: (child: delta.DeltaAny, $child: import("../../schema.js").Schema<delta.DeltaAny>) => Template | null;
60
+ /**
61
+ * @type {import('../../schema.js').Schema<delta.DeltaAny>}
62
+ */
63
+ childSchema: import("../../schema.js").Schema<delta.DeltaAny>;
64
+ }
65
+ export function children<IN extends delta.DeltaConf>($d: import("../../schema.js").Schema<delta.Delta<IN>>, handler: (child: delta.DeltaAny, $child: import("../../schema.js").Schema<delta.DeltaAny>) => Template | null): Children<IN>;
66
+ import { Transformer } from './core.js';
67
+ import * as delta from '../delta.js';
68
+ import { Template } from './core.js';
69
+ //# sourceMappingURL=children.d.ts.map