linked-rolls 0.56.0 → 0.58.0

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 (131) hide show
  1. package/README.md +54 -361
  2. package/lib/{constraints.d.ts → analysis/constraints.d.ts} +1 -1
  3. package/lib/{constraints.js → analysis/constraints.js} +9 -8
  4. package/lib/analysis/ownPaper.d.ts +26 -0
  5. package/lib/analysis/ownPaper.js +41 -0
  6. package/lib/{reservations.d.ts → analysis/reservations.d.ts} +3 -3
  7. package/lib/{reservations.js → analysis/reservations.js} +3 -3
  8. package/lib/{sigla.d.ts → analysis/sigla.d.ts} +2 -2
  9. package/lib/{sigla.js → analysis/sigla.js} +4 -4
  10. package/lib/{witnesses.d.ts → analysis/witnesses.d.ts} +2 -2
  11. package/lib/{witnesses.js → analysis/witnesses.js} +4 -4
  12. package/lib/{Collation.d.ts → collation/Collation.d.ts} +4 -4
  13. package/lib/{Collation.js → collation/Collation.js} +4 -4
  14. package/lib/{alignment.d.ts → collation/alignment.d.ts} +4 -4
  15. package/lib/{alignment.js → collation/alignment.js} +10 -16
  16. package/lib/{scatter.d.ts → collation/scatter.d.ts} +4 -4
  17. package/lib/{scatter.js → collation/scatter.js} +6 -6
  18. package/lib/{statistics.d.ts → collation/statistics.d.ts} +1 -1
  19. package/lib/{statistics.js → collation/statistics.js} +2 -2
  20. package/lib/{substitution.d.ts → collation/substitution.d.ts} +9 -24
  21. package/lib/{substitution.js → collation/substitution.js} +13 -37
  22. package/lib/emulation/Emulation.d.ts +64 -0
  23. package/lib/emulation/Emulation.js +282 -0
  24. package/lib/emulation/negotiation.d.ts +14 -0
  25. package/lib/emulation/negotiation.js +20 -0
  26. package/lib/index.d.ts +43 -35
  27. package/lib/index.js +36 -35
  28. package/lib/{asJsonLd.d.ts → io/asJsonLd.d.ts} +1 -1
  29. package/lib/{asJsonLd.js → io/asJsonLd.js} +22 -51
  30. package/lib/{context.d.ts → io/context.d.ts} +4 -4
  31. package/lib/{context.js → io/context.js} +4 -4
  32. package/lib/{importJsonLd.d.ts → io/importJsonLd.d.ts} +1 -1
  33. package/lib/io/importJsonLd.js +128 -0
  34. package/lib/{migrate.d.ts → io/migrate.d.ts} +9 -0
  35. package/lib/{migrate.js → io/migrate.js} +97 -54
  36. package/lib/{Agent.d.ts → model/Agent.d.ts} +1 -1
  37. package/lib/{Assumption.d.ts → model/Assumption.d.ts} +1 -1
  38. package/lib/{ConditionState.d.ts → model/ConditionState.d.ts} +1 -2
  39. package/lib/{Edit.d.ts → model/Edit.d.ts} +1 -1
  40. package/lib/{Edition.d.ts → model/Edition.d.ts} +2 -2
  41. package/lib/{Feature.d.ts → model/Feature.d.ts} +3 -1
  42. package/lib/{Feature.js → model/Feature.js} +2 -0
  43. package/lib/{FeatureSource.d.ts → model/FeatureSource.d.ts} +1 -1
  44. package/lib/{Perforator.d.ts → model/Perforator.d.ts} +1 -1
  45. package/lib/{RollCopy.d.ts → model/RollCopy.d.ts} +5 -12
  46. package/lib/{RollCopy.js → model/RollCopy.js} +3 -5
  47. package/lib/{Symbol.d.ts → model/Symbol.d.ts} +1 -1
  48. package/lib/{Version.d.ts → model/Version.d.ts} +11 -3
  49. package/lib/{Version.js → model/Version.js} +24 -1
  50. package/lib/{vocabulary.js → model/vocabulary.js} +2 -2
  51. package/lib/ops/beliefs.d.ts +9 -0
  52. package/lib/ops/beliefs.js +31 -0
  53. package/lib/ops/collation.d.ts +62 -0
  54. package/lib/ops/collation.js +228 -0
  55. package/lib/ops/commands.d.ts +9 -0
  56. package/lib/ops/commands.js +29 -0
  57. package/lib/ops/copies.d.ts +74 -0
  58. package/lib/ops/copies.js +135 -0
  59. package/lib/ops/draft.d.ts +59 -0
  60. package/lib/ops/draft.js +81 -0
  61. package/lib/ops/edits.d.ts +10 -0
  62. package/lib/ops/edits.js +82 -0
  63. package/lib/ops/features.d.ts +84 -0
  64. package/lib/ops/features.js +296 -0
  65. package/lib/ops/forget.d.ts +31 -0
  66. package/lib/ops/forget.js +110 -0
  67. package/lib/ops/immutable.d.ts +16 -0
  68. package/lib/ops/immutable.js +46 -0
  69. package/lib/ops/index.d.ts +13 -0
  70. package/lib/ops/index.js +7 -0
  71. package/lib/ops/versions.d.ts +33 -0
  72. package/lib/ops/versions.js +95 -0
  73. package/lib/readers/AtonParser.js +5 -7
  74. package/lib/readers/phillipsEroll.d.ts +3 -3
  75. package/lib/readers/phillipsEroll.js +4 -5
  76. package/lib/readers/spencerBar.d.ts +2 -2
  77. package/lib/readers/spencerBar.js +2 -3
  78. package/lib/readers/stanfordAton.d.ts +3 -3
  79. package/lib/readers/stanfordAton.js +2 -4
  80. package/lib/schema.json +11 -151
  81. package/lib/spec/context.json +2 -12
  82. package/lib/{ReproducingSystem.d.ts → systems/ReproducingSystem.d.ts} +3 -3
  83. package/lib/{TrackerBar.d.ts → systems/TrackerBar.d.ts} +48 -8
  84. package/lib/{TrackerBar.js → systems/TrackerBar.js} +11 -2
  85. package/lib/systems/index.d.ts +8 -2
  86. package/lib/systems/index.js +7 -1
  87. package/lib/systems/welte.d.ts +100 -0
  88. package/lib/systems/welte.js +119 -0
  89. package/lib/systems/welteLicensee/bar.d.ts +1 -1
  90. package/lib/systems/welteLicensee/bar.js +5 -2
  91. package/lib/systems/welteLicensee/system.d.ts +1 -1
  92. package/lib/systems/welteLicensee/system.js +1 -1
  93. package/lib/systems/welteT100/bar.d.ts +27 -1
  94. package/lib/systems/welteT100/bar.js +44 -2
  95. package/lib/systems/welteT100/system.d.ts +6 -39
  96. package/lib/systems/welteT100/system.js +19 -128
  97. package/lib/systems/welteT98/bar.d.ts +1 -1
  98. package/lib/systems/welteT98/bar.js +18 -2
  99. package/lib/systems/welteT98/system.d.ts +20 -38
  100. package/lib/systems/welteT98/system.js +20 -121
  101. package/lib/validate.d.ts +1 -1
  102. package/lib/{EditionView.d.ts → view/EditionView.d.ts} +38 -48
  103. package/lib/{EditionView.js → view/EditionView.js} +90 -96
  104. package/package.json +7 -2
  105. package/lib/Emulation.d.ts +0 -36
  106. package/lib/Emulation.js +0 -250
  107. package/lib/editionOps.d.ts +0 -260
  108. package/lib/editionOps.js +0 -1081
  109. package/lib/importJsonLd.js +0 -62
  110. /package/lib/{Agent.js → model/Agent.js} +0 -0
  111. /package/lib/{Assumption.js → model/Assumption.js} +0 -0
  112. /package/lib/{ConditionState.js → model/ConditionState.js} +0 -0
  113. /package/lib/{Edit.js → model/Edit.js} +0 -0
  114. /package/lib/{Edition.js → model/Edition.js} +0 -0
  115. /package/lib/{FeatureSource.js → model/FeatureSource.js} +0 -0
  116. /package/lib/{Perforator.js → model/Perforator.js} +0 -0
  117. /package/lib/{Quantity.d.ts → model/Quantity.d.ts} +0 -0
  118. /package/lib/{Quantity.js → model/Quantity.js} +0 -0
  119. /package/lib/{Symbol.js → model/Symbol.js} +0 -0
  120. /package/lib/{TrackCalibration.d.ts → model/TrackCalibration.d.ts} +0 -0
  121. /package/lib/{TrackCalibration.js → model/TrackCalibration.js} +0 -0
  122. /package/lib/{notes.d.ts → model/notes.d.ts} +0 -0
  123. /package/lib/{notes.js → model/notes.js} +0 -0
  124. /package/lib/{procedures.d.ts → model/procedures.d.ts} +0 -0
  125. /package/lib/{procedures.js → model/procedures.js} +0 -0
  126. /package/lib/{vocabulary.d.ts → model/vocabulary.d.ts} +0 -0
  127. /package/lib/{sorted.d.ts → shared/sorted.d.ts} +0 -0
  128. /package/lib/{sorted.js → shared/sorted.js} +0 -0
  129. /package/lib/{utils.d.ts → shared/utils.d.ts} +0 -0
  130. /package/lib/{utils.js → shared/utils.js} +0 -0
  131. /package/lib/{ReproducingSystem.js → systems/ReproducingSystem.js} +0 -0
@@ -0,0 +1,31 @@
1
+ import { v4 } from "uuid";
2
+ import { getAt } from "../view/EditionView.js";
3
+ const onAssumptionAt = (path, op) => draft => {
4
+ const assumption = getAt(path, draft);
5
+ if (assumption)
6
+ op(assumption);
7
+ };
8
+ const onBeliefAt = (path, op) => onAssumptionAt(path, assumption => {
9
+ const belief = assumption['@annotation']?.belief;
10
+ if (belief)
11
+ op(belief);
12
+ });
13
+ /** Annotates the assumption at the path with a belief held true, for reasons to be added. */
14
+ export const createBelief = (path) => onAssumptionAt(path, assumption => {
15
+ assumption['@annotation'] = {
16
+ id: v4(),
17
+ belief: { type: 'belief', id: v4(), certainty: 'true', reasons: [] }
18
+ };
19
+ });
20
+ export const clearBelief = (path) => onAssumptionAt(path, assumption => {
21
+ delete assumption['@annotation'];
22
+ });
23
+ export const setCertainty = (path, certainty) => onBeliefAt(path, belief => {
24
+ belief.certainty = certainty;
25
+ });
26
+ export const addReason = (path, reason) => onBeliefAt(path, belief => {
27
+ belief.reasons.push(reason);
28
+ });
29
+ export const removeReason = (path, index) => onBeliefAt(path, belief => {
30
+ belief.reasons.splice(index, 1);
31
+ });
@@ -0,0 +1,62 @@
1
+ import { EditionView } from "../view/EditionView.js";
2
+ import { CollationTolerance } from "../collation/Collation.js";
3
+ import { ObjectAssumption } from "../model/Assumption.js";
4
+ import { EditionOp } from "./draft.js";
5
+ /**
6
+ * Bases the child on the parent. A symbol of the child that collates
7
+ * with one the parent hands down adds its carriers to that symbol; the
8
+ * rest become the child's insertions, and what the parent hands down
9
+ * and the child lacks becomes its deletions. The derivation states the
10
+ * tolerance it was collated at and becomes the principal one; the
11
+ * hypotheses the child stated beside its former one stay.
12
+ *
13
+ * The edits the child already stated are rewritten only as far as a
14
+ * collation wrote them (`isCollationsOwn`). An editor's reading of the
15
+ * difference between the two texts stays, and the symbols it speaks for
16
+ * are left out of the collation, so that connecting the two again
17
+ * neither doubles them nor silently drops what somebody established by
18
+ * hand. An equivalence is the collation's own, since it is drawn from
19
+ * the two systems' vocabularies rather than read off the paper, but one
20
+ * drawn again over the very same symbols is kept as it stands, with its
21
+ * identifier and whatever was written on it.
22
+ *
23
+ * The child's own text is what it shows less what the parent hands
24
+ * down, so that connecting two versions already connected collates the
25
+ * child's symbols and not the parent's with themselves.
26
+ *
27
+ * A version is based on itself or on one of its own descendants in no
28
+ * statement, since the stemma would loop; asked for that, nothing
29
+ * changes.
30
+ */
31
+ export declare const connectVersions: (given: EditionView, childId: string, parentId: string, tolerance?: ObjectAssumption<CollationTolerance>) => EditionOp;
32
+ /**
33
+ * Folds the version's own symbols into those it inherits and collates
34
+ * with: the carriers pass over, and the insertions go. Collates at the
35
+ * tolerance of the derivation, where the caller names none.
36
+ */
37
+ export declare const collateSymbols: (given: EditionView, versionId: string, symbolIds: readonly string[], tolerance?: CollationTolerance) => EditionOp;
38
+ /**
39
+ * Takes the named copies' reading of a symbol back out of the symbol it
40
+ * was collated into: their carriers pass to a new symbol of the
41
+ * version's own, the remaining copies keep the symbol they had, and the
42
+ * version states the exchange.
43
+ *
44
+ * This is the inverse of the hand-over a collation makes, and it is
45
+ * what lets a derivation be collated a second time. A collated symbol
46
+ * is one symbol carrying every copy that reads it, so nothing else
47
+ * takes the two readings apart again, and without that a tolerance
48
+ * arrived at after the fact could never be applied.
49
+ *
50
+ * The copies named are one **side** of the derivation, the same side a
51
+ * window is measured over, and `sidesOf` is what says which they are.
52
+ * Naming one copy of a side that has several does not separate that
53
+ * side: what stays behind is the rest of it, mixed with the other
54
+ * side's copies, and a collation then compares one copy against that
55
+ * mixture rather than the two texts against each other.
56
+ *
57
+ * Symbols the named copies alone carry are already the version's own
58
+ * and are passed over, so a reading somebody has separated by hand
59
+ * keeps its identifier and the edit that speaks for it. Named symbols
60
+ * narrow the act to those; naming none separates the whole reading.
61
+ */
62
+ export declare const separateReadings: (given: EditionView, versionId: string, copies: ReadonlySet<string>, symbolIds?: readonly string[]) => EditionOp;
@@ -0,0 +1,228 @@
1
+ import { v4 } from "uuid";
2
+ import { getAt } from "../view/EditionView.js";
3
+ import { collationsOf, defaultCollationTolerance, isCollationsOwn, unchecked } from "../collation/Collation.js";
4
+ import { collationToleranceOf, derivesFrom, editsOf, insertedBy, principalDerivationOf } from "../model/Version.js";
5
+ import { substitutionsBetween } from "../collation/substitution.js";
6
+ import { trackerBarOf } from "../systems/index.js";
7
+ import { assignReference, idOf } from "../model/Assumption.js";
8
+ import { noChange, onVersion, stateOf, insertion, deletion, asUnchecked, declaring, insertedIn, dropInsertions, reading } from "./draft.js";
9
+ import { hypothesesBeside } from "./versions.js";
10
+ /** The carriers of each collated symbol pass to its counterpart. */
11
+ const handOverCarriers = (view, draft, collations) => collations.forEach(({ symbol, counterpart }) => {
12
+ const path = view.getPath(counterpart.id);
13
+ const target = path && getAt(path, draft);
14
+ target?.carriers.push(...symbol.carriers);
15
+ });
16
+ /** Whether the two versions are coded for different reproducing systems. */
17
+ const differ = (child, parent) => {
18
+ const one = trackerBarOf(child?.system);
19
+ const other = trackerBarOf(parent?.system);
20
+ return one !== undefined && other !== undefined && one.id !== other.id;
21
+ };
22
+ /** The symbols a set of edits speaks for, whether by inserting or by deleting them. */
23
+ const spokenForBy = (edits) => new Set(edits.flatMap(edit => [
24
+ ...(edit.insert ?? []).map(symbol => symbol.id),
25
+ ...(edit.delete ?? [])
26
+ ]));
27
+ /** An exchange of symbols, as a key: what it puts in against what it takes out. */
28
+ const exchangeKey = (inserted, deleted) => `${[...inserted].sort().join(',')}/${[...deleted].sort().join(',')}`;
29
+ /**
30
+ * The edits already stated, by the exchange each of them makes. An
31
+ * equivalence the collation draws a second time is the one already
32
+ * stated, and drawing it again is no reason to mint a new identifier or
33
+ * to drop the motivation somebody wrote on it.
34
+ */
35
+ const byExchange = (edits) => new Map(edits.map(edit => [exchangeKey((edit.insert ?? []).map(symbol => symbol.id), edit.delete ?? []), edit]));
36
+ /**
37
+ * Bases the child on the parent. A symbol of the child that collates
38
+ * with one the parent hands down adds its carriers to that symbol; the
39
+ * rest become the child's insertions, and what the parent hands down
40
+ * and the child lacks becomes its deletions. The derivation states the
41
+ * tolerance it was collated at and becomes the principal one; the
42
+ * hypotheses the child stated beside its former one stay.
43
+ *
44
+ * The edits the child already stated are rewritten only as far as a
45
+ * collation wrote them (`isCollationsOwn`). An editor's reading of the
46
+ * difference between the two texts stays, and the symbols it speaks for
47
+ * are left out of the collation, so that connecting the two again
48
+ * neither doubles them nor silently drops what somebody established by
49
+ * hand. An equivalence is the collation's own, since it is drawn from
50
+ * the two systems' vocabularies rather than read off the paper, but one
51
+ * drawn again over the very same symbols is kept as it stands, with its
52
+ * identifier and whatever was written on it.
53
+ *
54
+ * The child's own text is what it shows less what the parent hands
55
+ * down, so that connecting two versions already connected collates the
56
+ * child's symbols and not the parent's with themselves.
57
+ *
58
+ * A version is based on itself or on one of its own descendants in no
59
+ * statement, since the stemma would loop; asked for that, nothing
60
+ * changes.
61
+ */
62
+ export const connectVersions = (given, childId, parentId, tolerance = defaultCollationTolerance) => reading(given, view => {
63
+ if (childId === parentId || derivesFrom(view.edition.versions, parentId, childId))
64
+ return noChange;
65
+ const child = view.version(childId);
66
+ const stated = child ? editsOf(child) : [];
67
+ const established = stated.filter(edit => !isCollationsOwn(edit));
68
+ const spokenFor = spokenForBy(established);
69
+ const unspoken = (symbol) => !spokenFor.has(symbol.id);
70
+ // What the parent hands down and the child still shows passes
71
+ // through: it is neither the child's own symbol nor one it lacks.
72
+ // Without that, connecting a pair already connected would collate
73
+ // the inherited symbols with themselves and double their carriers.
74
+ const handedDown = view.snapshot(parentId).filter(unspoken);
75
+ const shown = new Set(view.snapshot(childId).map(symbol => symbol.id));
76
+ const inheritedIds = new Set(handedDown.map(symbol => symbol.id));
77
+ const inherited = handedDown.filter(symbol => !shown.has(symbol.id));
78
+ const own = view.snapshot(childId).filter(symbol => unspoken(symbol) && !inheritedIds.has(symbol.id));
79
+ const locate = (symbol) => view.placeOf(symbol);
80
+ const collations = collationsOf(own, inherited, locate, tolerance);
81
+ const collated = new Set(collations.map(({ symbol }) => symbol.id));
82
+ const matched = new Set(collations.map(({ counterpart }) => counterpart.id));
83
+ /**
84
+ * Where the child is coded for another system, a held command of
85
+ * its own often stands for a latched pair of the parent's. Saying so
86
+ * as one edit is the transfer being carried out, and leaving the two
87
+ * apart would make the apparatus a list of unexplained losses beside
88
+ * a list of unexplained gains.
89
+ */
90
+ const substituted = differ(child, view.version(parentId))
91
+ ? substitutionsBetween(own.filter(symbol => !collated.has(symbol.id)), inherited.filter(symbol => !matched.has(symbol.id)), locate, tolerance)
92
+ : [];
93
+ const paired = new Set(substituted.flatMap(({ replaced, by }) => [...by, ...replaced].map(symbol => symbol.id)));
94
+ const alreadyStated = byExchange(stated);
95
+ const equivalence = ({ replaced, by }) => {
96
+ const inserted = by.map(symbol => symbol.id);
97
+ const deleted = replaced.map(symbol => symbol.id);
98
+ return alreadyStated.get(exchangeKey(inserted, deleted)) ?? {
99
+ type: 'edit',
100
+ id: v4(),
101
+ editType: 'replace-with-equivalent',
102
+ motivation: unchecked,
103
+ insert: [...by],
104
+ delete: deleted
105
+ };
106
+ };
107
+ const edits = [
108
+ ...established,
109
+ ...substituted.map(equivalence),
110
+ ...own.filter(symbol => !collated.has(symbol.id) && !paired.has(symbol.id)).map(insertion).map(asUnchecked),
111
+ ...inherited
112
+ .filter(symbol => !matched.has(symbol.id) && !paired.has(symbol.id))
113
+ .map(symbol => asUnchecked(deletion(symbol.id)))
114
+ ];
115
+ return onVersion(childId, (child, draft) => {
116
+ handOverCarriers(view, draft, collations);
117
+ child.edits = edits;
118
+ child.motivations = declaring(stateOf(child).motivations, edits);
119
+ child.basedOn = [
120
+ { ...assignReference(parentId), collationTolerance: tolerance },
121
+ ...hypothesesBeside(stateOf(child), parentId)
122
+ ];
123
+ });
124
+ });
125
+ /**
126
+ * Folds the version's own symbols into those it inherits and collates
127
+ * with: the carriers pass over, and the insertions go. Collates at the
128
+ * tolerance of the derivation, where the caller names none.
129
+ */
130
+ export const collateSymbols = (given, versionId, symbolIds, tolerance) => reading(given, view => {
131
+ const version = view.version(versionId);
132
+ const principal = version && principalDerivationOf(version);
133
+ if (!version || !principal)
134
+ return noChange;
135
+ const chosen = new Set(symbolIds);
136
+ const own = insertedIn([version]).filter(symbol => chosen.has(symbol.id));
137
+ const collations = collationsOf(own, view.snapshot(idOf(principal)), symbol => view.placeOf(symbol), tolerance ?? collationToleranceOf(principal));
138
+ const collated = new Set(collations.map(({ symbol }) => symbol.id));
139
+ return onVersion(versionId, (version, draft) => {
140
+ handOverCarriers(view, draft, collations);
141
+ dropInsertions(version, collated);
142
+ });
143
+ });
144
+ /** The symbol as one copy reads it: what it says, on the given carriers, standing in no relation of its own. */
145
+ const readingOf = (symbol, carriers) => {
146
+ const identity = { id: v4(), carriers };
147
+ switch (symbol.type) {
148
+ case 'note':
149
+ return { type: 'note', pitch: symbol.pitch, ...identity };
150
+ case 'expression':
151
+ return { type: 'expression', expressionType: symbol.expressionType, scope: symbol.scope, ...identity };
152
+ case 'text':
153
+ return { type: 'text', text: symbol.text, ...identity };
154
+ }
155
+ };
156
+ /**
157
+ * The symbol where the named copies and at least one other carry it,
158
+ * with the carriers of each side.
159
+ *
160
+ * A symbol the named copies alone carry has no other side to be
161
+ * separated from and is passed over. That covers the insertions, and it
162
+ * covers a symbol an ancestor holds on one branch's witness alone,
163
+ * where the two versions do not disagree and there is nothing to take
164
+ * apart.
165
+ */
166
+ const sharedWith = (view, symbol, copies) => {
167
+ const onNamedCopy = (carrier) => {
168
+ const copy = view.copyOf(idOf(carrier));
169
+ return copy !== undefined && copies.has(copy.id);
170
+ };
171
+ const mine = symbol.carriers.filter(onNamedCopy);
172
+ const theirs = symbol.carriers.filter(carrier => !onNamedCopy(carrier));
173
+ return mine.length > 0 && theirs.length > 0 ? [{ symbol, mine, theirs }] : [];
174
+ };
175
+ /**
176
+ * Takes the named copies' reading of a symbol back out of the symbol it
177
+ * was collated into: their carriers pass to a new symbol of the
178
+ * version's own, the remaining copies keep the symbol they had, and the
179
+ * version states the exchange.
180
+ *
181
+ * This is the inverse of the hand-over a collation makes, and it is
182
+ * what lets a derivation be collated a second time. A collated symbol
183
+ * is one symbol carrying every copy that reads it, so nothing else
184
+ * takes the two readings apart again, and without that a tolerance
185
+ * arrived at after the fact could never be applied.
186
+ *
187
+ * The copies named are one **side** of the derivation, the same side a
188
+ * window is measured over, and `sidesOf` is what says which they are.
189
+ * Naming one copy of a side that has several does not separate that
190
+ * side: what stays behind is the rest of it, mixed with the other
191
+ * side's copies, and a collation then compares one copy against that
192
+ * mixture rather than the two texts against each other.
193
+ *
194
+ * Symbols the named copies alone carry are already the version's own
195
+ * and are passed over, so a reading somebody has separated by hand
196
+ * keeps its identifier and the edit that speaks for it. Named symbols
197
+ * narrow the act to those; naming none separates the whole reading.
198
+ */
199
+ export const separateReadings = (given, versionId, copies, symbolIds) => reading(given, view => {
200
+ const version = view.version(versionId);
201
+ if (!version)
202
+ return noChange;
203
+ const chosen = symbolIds && new Set(symbolIds);
204
+ const shared = view.snapshot(versionId)
205
+ .filter(symbol => chosen === undefined || chosen.has(symbol.id))
206
+ .flatMap(symbol => sharedWith(view, symbol, copies));
207
+ if (shared.length === 0)
208
+ return noChange;
209
+ const inserted = new Set(insertedBy(version).map(symbol => symbol.id));
210
+ const stated = editsOf(version);
211
+ const separations = shared.map(({ symbol, mine }) => ({
212
+ type: 'edit',
213
+ id: v4(),
214
+ insert: [readingOf(symbol, [...mine])],
215
+ // A symbol the version inserts itself stays where it is, minus
216
+ // the carriers that leave it. Only one it inherits is exchanged.
217
+ ...(inserted.has(symbol.id) ? {} : { delete: [symbol.id] })
218
+ }));
219
+ return onVersion(versionId, (version, draft) => {
220
+ shared.forEach(({ symbol, theirs }) => {
221
+ const path = view.getPath(symbol.id);
222
+ const target = path && getAt(path, draft);
223
+ if (target)
224
+ target.carriers = theirs;
225
+ });
226
+ version.edits = [...stated, ...separations];
227
+ });
228
+ });
@@ -0,0 +1,9 @@
1
+ import { EditionView } from "../view/EditionView.js";
2
+ import { PlacementRelation } from "../model/Symbol.js";
3
+ import { EditionOp } from "./draft.js";
4
+ /** States how the follower is placed relative to the reference, in place of any earlier statement. */
5
+ export declare const placeCommand: (view: EditionView, followerId: string, referenceId: string, relation: PlacementRelation) => EditionOp;
6
+ export declare const unplaceCommand: (view: EditionView, followerId: string) => EditionOp;
7
+ /** The pair is stated on `statingId` only, as the format asks. */
8
+ export declare const pairCommands: (view: EditionView, statingId: string, partnerId: string) => EditionOp;
9
+ export declare const unpairCommand: (view: EditionView, statingId: string) => EditionOp;
@@ -0,0 +1,29 @@
1
+ import { getAt } from "../view/EditionView.js";
2
+ import { isCommand, placementRelations } from "../model/Symbol.js";
3
+ import { assignReference } from "../model/Assumption.js";
4
+ import { reading } from "./draft.js";
5
+ /**
6
+ * Runs the change on the command the view locates by id, in whichever
7
+ * version inserted it. A statement made there holds in every version
8
+ * that carries the command.
9
+ */
10
+ const onCommand = (view, id, op) => reading(view, fresh => draft => {
11
+ const path = fresh.getPath(id);
12
+ const symbol = path && getAt(path, draft);
13
+ if (isCommand(symbol))
14
+ op(symbol);
15
+ });
16
+ const clearPlacement = (command) => placementRelations.forEach(relation => { delete command[relation]; });
17
+ /** States how the follower is placed relative to the reference, in place of any earlier statement. */
18
+ export const placeCommand = (view, followerId, referenceId, relation) => onCommand(view, followerId, command => {
19
+ clearPlacement(command);
20
+ command[relation] = assignReference(referenceId);
21
+ });
22
+ export const unplaceCommand = (view, followerId) => onCommand(view, followerId, clearPlacement);
23
+ /** The pair is stated on `statingId` only, as the format asks. */
24
+ export const pairCommands = (view, statingId, partnerId) => onCommand(view, statingId, command => {
25
+ command.pairedWith = assignReference(partnerId);
26
+ });
27
+ export const unpairCommand = (view, statingId) => onCommand(view, statingId, command => {
28
+ delete command.pairedWith;
29
+ });
@@ -0,0 +1,74 @@
1
+ /** Operations on the copies: adding and aligning them, and what they state of their source, their carriage and their condition. */
2
+ import { Draft } from "immer";
3
+ import { Edition } from "../model/Edition.js";
4
+ import { AnySymbol } from "../model/Symbol.js";
5
+ import { GeneralRollCondition, RollCopy, ScaleReading, Shift } from "../model/RollCopy.js";
6
+ import { FeatureSource } from "../model/FeatureSource.js";
7
+ import { Belief, ObjectAssumption, ReferenceAssumption } from "../model/Assumption.js";
8
+ import { Millimeters } from "../model/Quantity.js";
9
+ import { EditionOp } from "./draft.js";
10
+ /**
11
+ * Puts the copy into the edition with a version of its own, which
12
+ * inserts every symbol the copy's own tracker bar reads on it. The
13
+ * version is a reading in that system's words, so it is coded for the
14
+ * system the copy was cut for.
15
+ */
16
+ export declare const createVersion: (copy: RollCopy) => EditionOp;
17
+ /**
18
+ * Puts the copy into the edition without a version of its own, as for a
19
+ * copy whose features are not read into symbols: one known only from a
20
+ * recording states instead which versions it carries.
21
+ */
22
+ export declare const addCopy: (copy: RollCopy) => EditionOp;
23
+ /**
24
+ * Shifts and then scales the copy's features into line with another
25
+ * copy's, and puts the scale down to what the reading says: the paper,
26
+ * or the speed the copy was cut for.
27
+ */
28
+ export declare const alignCopy: (copyId: string, shift: Shift, scale: number, reading?: ScaleReading) => EditionOp;
29
+ /**
30
+ * Puts the copy's features back where they were measured. A paper
31
+ * stretch read off the alignment goes with it; a speed stated stays,
32
+ * being a fact about the copy.
33
+ */
34
+ export declare const unalignCopy: (copyId: string) => EditionOp;
35
+ /**
36
+ * Takes the extension a pneumatic reader adds off the ends of the
37
+ * copy's chains of holes, and records how much was taken, so that their lengths
38
+ * can be compared with a scanned copy's at all.
39
+ */
40
+ export declare const shortenCopy: (copyId: string, extension: Millimeters, leaving?: ReadonlySet<string>) => EditionOp;
41
+ /** Puts the reader's extension back on the copy's chains of holes. */
42
+ export declare const unshortenCopy: (copyId: string) => EditionOp;
43
+ /** States what the copy's features were read from, in place of any earlier statement. */
44
+ export declare const stateSource: (copyId: string, source: FeatureSource) => EditionOp;
45
+ /** Takes back the statement, leaving the copy silent about its source again. */
46
+ export declare const clearSource: (copyId: string) => EditionOp;
47
+ /** Gives the copy the siglum it is referred to by, or takes it away where the siglum given is blank. */
48
+ export declare const nameCopy: (copyId: string, siglum: string) => EditionOp;
49
+ /** Takes out the copy's statements that match, and the list itself where none is left. */
50
+ export declare const dropStatements: (copy: Draft<RollCopy>, matches: (statement: Readonly<ReferenceAssumption>) => boolean) => void;
51
+ /**
52
+ * States that the copy carries the version, under the belief given. It
53
+ * is meant for a copy whose features are not read into symbols, such as
54
+ * one known only from a recording, and `carriageProblems` reports it
55
+ * where features carry symbols already. A second statement about one
56
+ * version is none.
57
+ */
58
+ export declare const stateCarriage: (copyId: string, versionId: string, belief?: Belief) => EditionOp;
59
+ /** Takes back the copy's statement that it carries the version. */
60
+ export declare const clearCarriage: (copyId: string, versionId: string) => EditionOp;
61
+ /**
62
+ * Adds a general condition to the copy, beside whatever is stated of it
63
+ * already. The other condition a copy may be in, a paper stretch, is
64
+ * read off an alignment and stated by `alignCopy`.
65
+ */
66
+ export declare const addGeneralCondition: (copyId: string, condition: ObjectAssumption<GeneralRollCondition>) => EditionOp;
67
+ /** The symbols of the versions that no other copy carries. */
68
+ export declare const symbolsCarriedOnlyBy: (edition: Edition, copyId: string) => AnySymbol[];
69
+ /**
70
+ * Takes the copy out of the edition together with the symbols only it
71
+ * carries, and with every reference the versions and the argumentations
72
+ * made to those symbols.
73
+ */
74
+ export declare const removeCopy: (copyId: string) => EditionOp;
@@ -0,0 +1,135 @@
1
+ import { v4 } from "uuid";
2
+ import { asSymbols, barOf, featuresOf, isPaperStretch } from "../model/RollCopy.js";
3
+ import { systemOf } from "../systems/TrackerBar.js";
4
+ import { applyShift, applyScale, revertShift, revertScale, revertShortening, shortenChains } from "../collation/alignment.js";
5
+ import { idOf } from "../model/Assumption.js";
6
+ import { onCopy, stateOf, insertion, insertedIn, referenceHeld, withoutReferences } from "./draft.js";
7
+ import { without } from "./immutable.js";
8
+ import { featureIdsOf, carriedOnlyOn, forgetFeatures } from "./forget.js";
9
+ /**
10
+ * Puts the copy into the edition with a version of its own, which
11
+ * inserts every symbol the copy's own tracker bar reads on it. The
12
+ * version is a reading in that system's words, so it is coded for the
13
+ * system the copy was cut for.
14
+ */
15
+ export const createVersion = (copy) => draft => {
16
+ const bar = barOf(copy);
17
+ draft.copies.push(copy);
18
+ draft.versions.push({
19
+ id: v4(),
20
+ system: systemOf(bar),
21
+ edits: asSymbols(featuresOf(copy), bar).map(insertion),
22
+ motivations: []
23
+ });
24
+ };
25
+ /**
26
+ * Puts the copy into the edition without a version of its own, as for a
27
+ * copy whose features are not read into symbols: one known only from a
28
+ * recording states instead which versions it carries.
29
+ */
30
+ export const addCopy = (copy) => draft => {
31
+ draft.copies.push(copy);
32
+ };
33
+ /** States what the scale is put down to, in place of an earlier reading. */
34
+ const readScale = (copy, reading) => {
35
+ if (reading.cause === 'paper') {
36
+ copy.conditions = [...copy.conditions.filter(condition => !isPaperStretch(condition)), reading.condition];
37
+ return;
38
+ }
39
+ if (!copy.production)
40
+ copy.production = {};
41
+ copy.production.speed = reading.speed;
42
+ };
43
+ /**
44
+ * Shifts and then scales the copy's features into line with another
45
+ * copy's, and puts the scale down to what the reading says: the paper,
46
+ * or the speed the copy was cut for.
47
+ */
48
+ export const alignCopy = (copyId, shift, scale, reading) => onCopy(copyId, copy => {
49
+ applyShift(shift, copy);
50
+ applyScale(scale, copy);
51
+ if (reading)
52
+ readScale(copy, reading);
53
+ });
54
+ /**
55
+ * Puts the copy's features back where they were measured. A paper
56
+ * stretch read off the alignment goes with it; a speed stated stays,
57
+ * being a fact about the copy.
58
+ */
59
+ export const unalignCopy = (copyId) => onCopy(copyId, copy => {
60
+ revertScale(copy);
61
+ revertShift(copy);
62
+ copy.conditions = without(copy.conditions, isPaperStretch);
63
+ });
64
+ /**
65
+ * Takes the extension a pneumatic reader adds off the ends of the
66
+ * copy's chains of holes, and records how much was taken, so that their lengths
67
+ * can be compared with a scanned copy's at all.
68
+ */
69
+ export const shortenCopy = (copyId, extension, leaving) => onCopy(copyId, copy => shortenChains(extension, copy, leaving));
70
+ /** Puts the reader's extension back on the copy's chains of holes. */
71
+ export const unshortenCopy = (copyId) => onCopy(copyId, copy => revertShortening(copy));
72
+ /** States what the copy's features were read from, in place of any earlier statement. */
73
+ export const stateSource = (copyId, source) => onCopy(copyId, copy => {
74
+ copy.readFrom = source;
75
+ });
76
+ /** Takes back the statement, leaving the copy silent about its source again. */
77
+ export const clearSource = (copyId) => onCopy(copyId, copy => {
78
+ copy.readFrom = undefined;
79
+ });
80
+ /** Gives the copy the siglum it is referred to by, or takes it away where the siglum given is blank. */
81
+ export const nameCopy = (copyId, siglum) => onCopy(copyId, copy => {
82
+ const trimmed = siglum.trim();
83
+ if (trimmed)
84
+ copy.siglum = trimmed;
85
+ else
86
+ delete copy.siglum;
87
+ });
88
+ /** Takes out the copy's statements that match, and the list itself where none is left. */
89
+ export const dropStatements = (copy, matches) => {
90
+ const statements = stateOf(copy).carries;
91
+ if (!statements?.some(matches))
92
+ return;
93
+ const kept = withoutReferences(statements, matches);
94
+ if (kept)
95
+ copy.carries = kept;
96
+ else
97
+ delete copy.carries;
98
+ };
99
+ /**
100
+ * States that the copy carries the version, under the belief given. It
101
+ * is meant for a copy whose features are not read into symbols, such as
102
+ * one known only from a recording, and `carriageProblems` reports it
103
+ * where features carry symbols already. A second statement about one
104
+ * version is none.
105
+ */
106
+ export const stateCarriage = (copyId, versionId, belief) => onCopy(copyId, copy => {
107
+ const statements = stateOf(copy).carries ?? [];
108
+ if (statements.some(statement => idOf(statement) === versionId))
109
+ return;
110
+ copy.carries = [...statements, referenceHeld(versionId, belief)];
111
+ });
112
+ /** Takes back the copy's statement that it carries the version. */
113
+ export const clearCarriage = (copyId, versionId) => onCopy(copyId, copy => dropStatements(copy, statement => idOf(statement) === versionId));
114
+ /**
115
+ * Adds a general condition to the copy, beside whatever is stated of it
116
+ * already. The other condition a copy may be in, a paper stretch, is
117
+ * read off an alignment and stated by `alignCopy`.
118
+ */
119
+ export const addGeneralCondition = (copyId, condition) => onCopy(copyId, copy => {
120
+ copy.conditions.push(condition);
121
+ });
122
+ /** The symbols of the versions that no other copy carries. */
123
+ export const symbolsCarriedOnlyBy = (edition, copyId) => {
124
+ const copy = edition.copies.find(c => c.id === copyId);
125
+ return copy ? insertedIn(edition.versions).filter(carriedOnlyOn(featureIdsOf(copy))) : [];
126
+ };
127
+ /**
128
+ * Takes the copy out of the edition together with the symbols only it
129
+ * carries, and with every reference the versions and the argumentations
130
+ * made to those symbols.
131
+ */
132
+ export const removeCopy = (copyId) => onCopy(copyId, (copy, draft) => {
133
+ forgetFeatures(draft, featureIdsOf(copy));
134
+ draft.copies = draft.copies.filter(c => c.id !== copyId);
135
+ });
@@ -0,0 +1,59 @@
1
+ import { EditionView } from "../view/EditionView.js";
2
+ /** What the operations are built from: the type of an operation, how one finds what it writes to on the draft, and the edits it writes. */
3
+ import { Draft } from "immer";
4
+ import { Edition } from "../model/Edition.js";
5
+ import { AnySymbol } from "../model/Symbol.js";
6
+ import { Edit } from "../model/Edit.js";
7
+ import { Motivation, Version } from "../model/Version.js";
8
+ import { RollCopy } from "../model/RollCopy.js";
9
+ import { Belief, ReferenceAssumption } from "../model/Assumption.js";
10
+ import { FeatureOrPatch } from "../model/Feature.js";
11
+ import { WithId } from "../shared/utils.js";
12
+ /**
13
+ * A change to an edition, written onto an immer draft of it. One
14
+ * operation is one undo step, so an operation that has to read the
15
+ * edition first takes an `EditionView` of the state it will be
16
+ * applied to and does all its writing in the one function it returns.
17
+ * Where operations run one after another on one draft, the ones after
18
+ * the first read a view of the draft as it then stands (`reading`).
19
+ */
20
+ export type EditionOp = (draft: Draft<Edition>) => void;
21
+ export declare const noChange: EditionOp;
22
+ export declare const onCopy: (copyId: string, op: (copy: Draft<RollCopy>, draft: Draft<Edition>) => void) => EditionOp;
23
+ export declare const onVersion: (versionId: string, op: (version: Draft<Version>, draft: Draft<Edition>) => void) => EditionOp;
24
+ export declare const onFeature: (copyId: string, featureId: string, op: (feature: Draft<FeatureOrPatch>) => void) => EditionOp;
25
+ /**
26
+ * The operation built from a view of the state it is applied to. The
27
+ * view given is used where the draft still stands as the view saw it,
28
+ * and a fresh one is taken of the draft where an operation run before
29
+ * on the same draft has changed it: a path or an index read off the
30
+ * view would otherwise name what stood there before.
31
+ */
32
+ export declare const reading: (view: EditionView, build: (view: EditionView) => EditionOp) => EditionOp;
33
+ /**
34
+ * The state a draft stands at, as plain data. Reading a draft proxies
35
+ * everything it touches, so what is only read is read from this.
36
+ */
37
+ export declare const stateOf: <T>(draft: Draft<T>) => T;
38
+ /** The ids of the items the rewriting left out. */
39
+ export declare const droppedIds: (before: readonly WithId[], after: readonly WithId[]) => string[];
40
+ export type Ids = ReadonlySet<string>;
41
+ export declare const insertion: (symbol: AnySymbol) => Edit;
42
+ export declare const deletion: (symbolId: string) => Edit;
43
+ /** The edit as a collation leaves it: made by rule, and not yet read by anybody. */
44
+ export declare const asUnchecked: (edit: Edit) => Edit;
45
+ /**
46
+ * The motivations with the unchecked one declared, where any edit
47
+ * names it and the version does not state it yet. An edit naming a
48
+ * motivation the version leaves undeclared points at nothing.
49
+ */
50
+ export declare const declaring: (motivations: Motivation[], edits: readonly Edit[]) => Motivation[];
51
+ export declare const insertedIn: (versions: readonly Version[]) => AnySymbol[];
52
+ /** The edits with the change applied, less those it emptied; the very same array where it changed none. */
53
+ export declare const edited: (edits: Edit[], change: (edit: Edit) => Edit) => Edit[];
54
+ /** Takes the symbols out of the version's own insertions, and the edits that had nothing else. */
55
+ export declare const dropInsertions: (version: Draft<Version>, symbolIds: Ids) => void;
56
+ /** A reference under the belief given, where one is given. */
57
+ export declare const referenceHeld: (id: string, belief?: Belief) => ReferenceAssumption;
58
+ /** The references less those that match, or nothing where none is left. */
59
+ export declare const withoutReferences: <R extends ReferenceAssumption>(references: readonly R[], matches: (reference: Readonly<R>) => boolean) => R[] | undefined;