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,110 @@
1
+ import { isCommand, placementRelations } from "../model/Symbol.js";
2
+ import { editsOf } from "../model/Version.js";
3
+ import { featuresOf, statesNothing } from "../model/RollCopy.js";
4
+ import { idOf } from "../model/Assumption.js";
5
+ import { withBorneFeatures } from "../model/Feature.js";
6
+ import { stateOf, droppedIds, insertedIn, edited } from "./draft.js";
7
+ import { without, mapped, pruned, replacing, deeply, writeInto } from "./immutable.js";
8
+ /** The ids of every feature the copy bears, those a patch bears among them. */
9
+ export const featureIdsOf = (copy) => new Set(featuresOf(copy).flatMap(withBorneFeatures).map(feature => feature.id));
10
+ /**
11
+ * A symbol every carrier of which lies among the features loses its
12
+ * evidence with them. A symbol without carriers, such as a label,
13
+ * stands on its own.
14
+ */
15
+ export const carriedOnlyOn = (features) => (symbol) => symbol.carriers.length > 0 && symbol.carriers.every(carrier => features.has(idOf(carrier)));
16
+ const references = [...placementRelations, 'pairedWith'];
17
+ /** The command without its references to the dropped symbols, or the very same one where it makes none. */
18
+ const forgettingReferences = (command, dropped) => {
19
+ const stale = references.filter(relation => {
20
+ const reference = command[relation];
21
+ return reference !== undefined && dropped.has(idOf(reference));
22
+ });
23
+ if (stale.length === 0)
24
+ return command;
25
+ const kept = { ...command };
26
+ stale.forEach(relation => { delete kept[relation]; });
27
+ return kept;
28
+ };
29
+ /** The symbol without the features among its carriers, and without references to what went with them. */
30
+ const forgettingCarriers = (features, dropped) => (symbol) => {
31
+ const carriers = without(symbol.carriers, carrier => features.has(idOf(carrier)));
32
+ const relieved = carriers === symbol.carriers ? symbol : { ...symbol, carriers };
33
+ return isCommand(relieved) ? forgettingReferences(relieved, dropped) : relieved;
34
+ };
35
+ /** The edit without the dropped symbols and the features, or the very same edit where it had none of them. */
36
+ const forgettingFeatures = (features, dropped) => {
37
+ const forgetCarriers = forgettingCarriers(features, dropped);
38
+ return (edit) => {
39
+ const insert = edit.insert && mapped(without(edit.insert, symbol => dropped.has(symbol.id)), forgetCarriers);
40
+ const deleted = edit.delete && without(edit.delete, id => dropped.has(id));
41
+ if (insert === edit.insert && deleted === edit.delete)
42
+ return edit;
43
+ return { ...edit, ...(insert && { insert }), ...(deleted && { delete: deleted }) };
44
+ };
45
+ };
46
+ const isCopy = (record) => 'type' in record && record.type === 'RollCopy';
47
+ const isBelief = (record) => 'type' in record && record.type === 'belief';
48
+ const isComprehension = (reason) => reason.type === 'meaningComprehension';
49
+ const comprehendsNothing = (reason) => isComprehension(reason) && reason.comprehends.length === 0;
50
+ /**
51
+ * The modification with what it names rewritten, or the very same one
52
+ * where that leaves it as it was. Only a removal names anything by id:
53
+ * what an act produced or glued on it states itself.
54
+ */
55
+ const renamingMembers = (rename) => (modification) => modification.type === 'Removal'
56
+ ? replacing(modification, 'removed', rename(modification.removed))
57
+ : modification;
58
+ /** The reason with what a comprehension comprehends rewritten; any other reason names nothing of the kind. */
59
+ const renamingComprehended = (rename) => (reason) => isComprehension(reason) ? replacing(reason, 'comprehends', rename(reason.comprehends)) : reason;
60
+ /**
61
+ * The record with the ids it names rewritten: what a copy's removals
62
+ * removed, and what the comprehensions among a belief's reasons
63
+ * comprehend. A removal or a comprehension the rewriting emptied goes
64
+ * with what it named; one that named nothing before stays, as an edit
65
+ * that was empty before it does.
66
+ */
67
+ const renaming = (rename) => (record) => {
68
+ if (isCopy(record)) {
69
+ return replacing(record, 'modifications', pruned(record.modifications, renamingMembers(rename), statesNothing));
70
+ }
71
+ if (isBelief(record)) {
72
+ return replacing(record, 'reasons', pruned(record.reasons, renamingComprehended(rename), comprehendsNothing));
73
+ }
74
+ return record;
75
+ };
76
+ /**
77
+ * Rewrites the ids by which the edition names features and symbols
78
+ * outside the versions. A belief is annotatable anywhere, so the whole
79
+ * edition is read; what the rewriting leaves alone is left the very
80
+ * object it was.
81
+ */
82
+ export const renameReferences = (draft, rename) => {
83
+ const before = stateOf(draft);
84
+ const after = deeply(renaming(rename))(before);
85
+ if (after !== before)
86
+ writeInto(draft, before, after);
87
+ };
88
+ /**
89
+ * Strikes the features from the edition: their carriers go, a symbol
90
+ * that had no other carrier goes with them, an edit left exchanging
91
+ * nothing goes as well, and so does every reference the versions, the
92
+ * modifications of the copies and the comprehensions made to what went.
93
+ */
94
+ export const forgetFeatures = (draft, features) => {
95
+ const versions = stateOf(draft.versions);
96
+ const dropped = new Set(insertedIn(versions).filter(carriedOnlyOn(features)).map(symbol => symbol.id));
97
+ const forget = forgettingFeatures(features, dropped);
98
+ const edits = versions.map(version => version.edits && edited(version.edits, forget));
99
+ const gone = new Set([
100
+ ...features,
101
+ ...dropped,
102
+ ...versions.flatMap((version, i) => droppedIds(editsOf(version), edits[i] ?? []))
103
+ ]);
104
+ renameReferences(draft, ids => without(ids, id => gone.has(id)));
105
+ draft.versions.forEach((version, i) => {
106
+ const stated = edits[i];
107
+ if (stated)
108
+ version.edits = stated;
109
+ });
110
+ };
@@ -0,0 +1,16 @@
1
+ /** Rewritings that return the very object they were given wherever they change nothing, so that an immer draft is left untouched there. */
2
+ /** The items that do not match, or the very same array when none does, so that a draft stays untouched. */
3
+ export declare const without: <T>(items: T[], matches: (item: T) => boolean) => T[];
4
+ /** The items each changed, or the very same array when the change left every one as it was. */
5
+ export declare const mapped: <T>(items: T[], change: (item: T) => T) => T[];
6
+ /** The items each changed, less those the change emptied; the very same array where it changed none. */
7
+ export declare const pruned: <T>(items: T[], change: (item: T) => T, emptied: (item: T) => boolean) => T[];
8
+ /** The record with the field replaced, or the very same record where that is what stood there. */
9
+ export declare const replacing: <T extends object, K extends keyof T>(record: T, key: K, value: T[K]) => T;
10
+ /** A record of the edition, as the walk over it sees one. */
11
+ export type Node = Record<string, unknown>;
12
+ export declare const isRecord: (value: unknown) => value is Node;
13
+ /** The value with the change applied to every record within it and then to itself, innermost first. */
14
+ export declare const deeply: (change: (record: object) => object) => (value: unknown) => unknown;
15
+ /** Writes onto the draft what the rewriting changed, as deep as the change reaches. */
16
+ export declare const writeInto: (draft: Node, before: Node, after: Node) => void;
@@ -0,0 +1,46 @@
1
+ /** Rewritings that return the very object they were given wherever they change nothing, so that an immer draft is left untouched there. */
2
+ /** The items that do not match, or the very same array when none does, so that a draft stays untouched. */
3
+ export const without = (items, matches) => items.some(matches) ? items.filter(item => !matches(item)) : items;
4
+ /** The items each changed, or the very same array when the change left every one as it was. */
5
+ export const mapped = (items, change) => {
6
+ const changed = items.map(change);
7
+ return changed.every((item, i) => item === items[i]) ? items : changed;
8
+ };
9
+ /** The items each changed, less those the change emptied; the very same array where it changed none. */
10
+ export const pruned = (items, change, emptied) => {
11
+ const changed = mapped(items, change);
12
+ return changed === items ? items : changed.filter((item, i) => item === items[i] || !emptied(item));
13
+ };
14
+ /** The record with the field replaced, or the very same record where that is what stood there. */
15
+ export const replacing = (record, key, value) => record[key] === value ? record : { ...record, [key]: value };
16
+ export const isRecord = (value) => typeof value === 'object' && value !== null;
17
+ /** The record's values each changed, or the very same record where the change left every one as it was. */
18
+ const withValues = (record, change) => {
19
+ const entries = Object.entries(record);
20
+ const changed = entries.map(([key, value]) => [key, change(value)]);
21
+ return changed.every(([, value], i) => value === entries[i][1]) ? record : Object.fromEntries(changed);
22
+ };
23
+ /** The value with the change applied to every record within it and then to itself, innermost first. */
24
+ export const deeply = (change) => {
25
+ const changed = (value) => Array.isArray(value) ? mapped(value, changed)
26
+ : isRecord(value) ? change(withValues(value, changed))
27
+ : value;
28
+ return changed;
29
+ };
30
+ /** Whether the two stand alike, so that what differs within them can be written where it lies. */
31
+ const alike = (before, after) => {
32
+ if (!isRecord(before) || !isRecord(after))
33
+ return false;
34
+ if (Array.isArray(before))
35
+ return Array.isArray(after) && before.length === after.length;
36
+ return !Array.isArray(after);
37
+ };
38
+ /** Writes onto the draft what the rewriting changed, as deep as the change reaches. */
39
+ export const writeInto = (draft, before, after) => Object.entries(after).forEach(([key, value]) => {
40
+ if (value === before[key])
41
+ return;
42
+ if (alike(before[key], value))
43
+ writeInto(draft[key], before[key], value);
44
+ else
45
+ draft[key] = value;
46
+ });
@@ -0,0 +1,13 @@
1
+ /**
2
+ * The operations on an edition, each written onto an immer draft of it.
3
+ * They are grouped by what they change under `ops/`; this module names
4
+ * the ones the library offers.
5
+ */
6
+ export type { EditionOp } from "./draft.js";
7
+ export { createVersion, addCopy, alignCopy, unalignCopy, shortenCopy, unshortenCopy, stateSource, clearSource, nameCopy, stateCarriage, clearCarriage, addGeneralCondition, symbolsCarriedOnlyBy, removeCopy } from "./copies.js";
8
+ export { stateFeatureCondition, addFeature, addBorneFeature, removeFeatures, mergeObstacle, mergeObstacleIn, mergeFeatures, type FeatureAct, type MergeObstacle } from "./features.js";
9
+ export { detachVersion, removeVersion, removeSymbols, deriveVersion, stateDerivation, clearDerivation } from "./versions.js";
10
+ export { connectVersions, collateSymbols, separateReadings } from "./collation.js";
11
+ export { mergeEdits, splitEdit } from "./edits.js";
12
+ export { placeCommand, unplaceCommand, pairCommands, unpairCommand } from "./commands.js";
13
+ export { createBelief, clearBelief, setCertainty, addReason, removeReason } from "./beliefs.js";
@@ -0,0 +1,7 @@
1
+ export { createVersion, addCopy, alignCopy, unalignCopy, shortenCopy, unshortenCopy, stateSource, clearSource, nameCopy, stateCarriage, clearCarriage, addGeneralCondition, symbolsCarriedOnlyBy, removeCopy } from "./copies.js";
2
+ export { stateFeatureCondition, addFeature, addBorneFeature, removeFeatures, mergeObstacle, mergeObstacleIn, mergeFeatures } from "./features.js";
3
+ export { detachVersion, removeVersion, removeSymbols, deriveVersion, stateDerivation, clearDerivation } from "./versions.js";
4
+ export { connectVersions, collateSymbols, separateReadings } from "./collation.js";
5
+ export { mergeEdits, splitEdit } from "./edits.js";
6
+ export { placeCommand, unplaceCommand, pairCommands, unpairCommand } from "./commands.js";
7
+ export { createBelief, clearBelief, setCertainty, addReason, removeReason } from "./beliefs.js";
@@ -0,0 +1,33 @@
1
+ import { EditionView } from "../view/EditionView.js";
2
+ import { Derivation, Version } from "../model/Version.js";
3
+ import { Belief } from "../model/Assumption.js";
4
+ import { EditionOp } from "./draft.js";
5
+ /** The derivations the version states beside its principal one, less any naming the parent. */
6
+ export declare const hypothesesBeside: (version: Readonly<Version>, parentId: string) => Derivation[];
7
+ /**
8
+ * Makes the version stand on its own: what it inherited becomes its
9
+ * own insertions, and its derivations go, the hypotheses among them,
10
+ * with the motivations that belonged to them.
11
+ */
12
+ export declare const detachVersion: (given: EditionView, versionId: string) => EditionOp;
13
+ /**
14
+ * Takes the version out. Whatever read its text against it comes to
15
+ * stand on its own, a hypothesis that something derives from it goes,
16
+ * and so does a copy's statement that it carries the version.
17
+ */
18
+ export declare const removeVersion: (given: EditionView, versionId: string) => EditionOp;
19
+ /** Takes the symbols out of the version's own insertions, and the edits that had nothing else. */
20
+ export declare const removeSymbols: (versionId: string, symbolIds: readonly string[]) => EditionOp;
21
+ /** Moves the edits into a new version based on this one. */
22
+ export declare const deriveVersion: (versionId: string, editIds: readonly string[]) => EditionOp;
23
+ /**
24
+ * States that the version may also derive from the parent, beside what
25
+ * it derives from already: a hypothesis, such as a contamination, under
26
+ * the belief given. The text stays read against the principal derivation
27
+ * unless the belief holds this one more certain. A version derives from
28
+ * itself, twice from one parent, or from one of its own descendants in
29
+ * no statement.
30
+ */
31
+ export declare const stateDerivation: (versionId: string, parentId: string, belief?: Belief) => EditionOp;
32
+ /** Takes back the hypothesis that the version derives from the parent; the principal derivation goes with `detachVersion`. */
33
+ export declare const clearDerivation: (versionId: string, parentId: string) => EditionOp;
@@ -0,0 +1,95 @@
1
+ import { v4 } from "uuid";
2
+ import { derivesFrom, editsOf, principalDerivationOf } from "../model/Version.js";
3
+ import { assignReference, idOf } from "../model/Assumption.js";
4
+ import { onVersion, stateOf, insertion, dropInsertions, referenceHeld, withoutReferences, reading } from "./draft.js";
5
+ import { without } from "./immutable.js";
6
+ import { dropStatements } from "./copies.js";
7
+ /** Whether the version's text is read against the parent, its principal derivation naming it. */
8
+ const readsAgainst = (version, parentId) => {
9
+ const principal = principalDerivationOf(version);
10
+ return principal !== undefined && idOf(principal) === parentId;
11
+ };
12
+ /** The derivations the version states beside its principal one, less any naming the parent. */
13
+ export const hypothesesBeside = (version, parentId) => {
14
+ const principal = principalDerivationOf(version);
15
+ return (version.basedOn ?? []).filter(derivation => derivation !== principal && idOf(derivation) !== parentId);
16
+ };
17
+ /** Takes out the derivations that match, and the list itself where none is left. */
18
+ const dropDerivations = (version, matches) => {
19
+ const derivations = stateOf(version).basedOn;
20
+ if (!derivations?.some(matches))
21
+ return;
22
+ const kept = withoutReferences(derivations, matches);
23
+ if (kept)
24
+ version.basedOn = kept;
25
+ else
26
+ delete version.basedOn;
27
+ };
28
+ /**
29
+ * Makes the version stand on its own: what it inherited becomes its
30
+ * own insertions, and its derivations go, the hypotheses among them,
31
+ * with the motivations that belonged to them.
32
+ */
33
+ export const detachVersion = (given, versionId) => reading(given, view => {
34
+ const edits = view.snapshot(versionId).map(insertion);
35
+ return onVersion(versionId, version => {
36
+ version.edits = edits;
37
+ delete version.basedOn;
38
+ version.motivations = [];
39
+ });
40
+ });
41
+ /**
42
+ * Takes the version out. Whatever read its text against it comes to
43
+ * stand on its own, a hypothesis that something derives from it goes,
44
+ * and so does a copy's statement that it carries the version.
45
+ */
46
+ export const removeVersion = (given, versionId) => reading(given, view => {
47
+ const detachments = view.edition.versions
48
+ .filter(version => readsAgainst(version, versionId))
49
+ .map(version => detachVersion(view, version.id));
50
+ const namesIt = (reference) => idOf(reference) === versionId;
51
+ return draft => {
52
+ detachments.forEach(detach => detach(draft));
53
+ draft.versions.forEach(version => dropDerivations(version, namesIt));
54
+ draft.copies.forEach(copy => dropStatements(copy, namesIt));
55
+ draft.versions = without(draft.versions, version => version.id === versionId);
56
+ };
57
+ });
58
+ /** Takes the symbols out of the version's own insertions, and the edits that had nothing else. */
59
+ export const removeSymbols = (versionId, symbolIds) => onVersion(versionId, version => dropInsertions(version, new Set(symbolIds)));
60
+ /** Moves the edits into a new version based on this one. */
61
+ export const deriveVersion = (versionId, editIds) => onVersion(versionId, (version, draft) => {
62
+ const chosen = new Set(editIds);
63
+ const moved = editsOf(version).filter(edit => chosen.has(edit.id));
64
+ if (version.edits)
65
+ version.edits = without(version.edits, edit => chosen.has(edit.id));
66
+ draft.versions.push({
67
+ id: v4(),
68
+ system: stateOf(version).system,
69
+ basedOn: [assignReference(versionId)],
70
+ edits: moved,
71
+ motivations: []
72
+ });
73
+ });
74
+ /**
75
+ * States that the version may also derive from the parent, beside what
76
+ * it derives from already: a hypothesis, such as a contamination, under
77
+ * the belief given. The text stays read against the principal derivation
78
+ * unless the belief holds this one more certain. A version derives from
79
+ * itself, twice from one parent, or from one of its own descendants in
80
+ * no statement.
81
+ */
82
+ export const stateDerivation = (versionId, parentId, belief) => onVersion(versionId, (version, draft) => {
83
+ const derivations = stateOf(version).basedOn ?? [];
84
+ if (parentId === versionId || derivations.some(derivation => idOf(derivation) === parentId))
85
+ return;
86
+ if (derivesFrom(stateOf(draft.versions), parentId, versionId))
87
+ return;
88
+ version.basedOn = [...derivations, referenceHeld(parentId, belief)];
89
+ });
90
+ /** Takes back the hypothesis that the version derives from the parent; the principal derivation goes with `detachVersion`. */
91
+ export const clearDerivation = (versionId, parentId) => onVersion(versionId, version => {
92
+ if (readsAgainst(stateOf(version), parentId))
93
+ return;
94
+ dropDerivations(version, derivation => idOf(derivation) === parentId);
95
+ });
@@ -70,13 +70,13 @@ export class AtonParser {
70
70
  // Ignore unassociated text.
71
71
  return;
72
72
  }
73
- else if (matches = line.match(/^@@[^@ ]/)) {
73
+ else if ((matches = line.match(/^@@[^@ ]/))) {
74
74
  // Control message.
75
75
  // End current property.
76
76
  this.cleanParameter(state);
77
77
  state.curkey = undefined;
78
78
  state.ocurkey = undefined;
79
- if (matches = line.match(/^@@(BEGIN|START)\s*:\s*(.*)\s*$/i)) {
79
+ if ((matches = line.match(/^@@(BEGIN|START)\s*:\s*(.*)\s*$/i))) {
80
80
  state.label = matches[2];
81
81
  //console.log(state.label)
82
82
  if (typeof state.curobj[state.label] === 'undefined') {
@@ -107,7 +107,7 @@ export class AtonParser {
107
107
  state.curobj = state.curobj[state.label][state.curobj[state.label].length - 1];
108
108
  }
109
109
  }
110
- else if (matches = line.match(/^@@(END|STOP)\s*:?\s*(.*)\s*$/i)) {
110
+ else if ((matches = line.match(/^@@(END|STOP)\s*:?\s*(.*)\s*$/i))) {
111
111
  // End an object, so go back to the parent.
112
112
  if (typeof state.curkey !== 'undefined') {
113
113
  // clean whitespace of last read property:
@@ -121,8 +121,6 @@ export class AtonParser {
121
121
  if (typeof state.node[state.node.length - 1].startline === 'undefined') {
122
122
  throw new Error('No start for ' + state.action + ' tag on line '
123
123
  + state.node[state.node.length - 1].startline + ': ' + line);
124
- state.output = {};
125
- // return v.output;
126
124
  }
127
125
  if (typeof state.labelend !== 'undefined') {
128
126
  // ensure that the v.label begin/end tags match
@@ -144,12 +142,12 @@ export class AtonParser {
144
142
  obj[x.label][x.index] : obj[x.label];
145
143
  }, state.output);
146
144
  }
147
- else if (matches = line.match(/^@@TYPE\s*:\s*([^:]+)\s*:\s*(.*)\s*$/i)) {
145
+ else if ((matches = line.match(/^@@TYPE\s*:\s*([^:]+)\s*:\s*(.*)\s*$/i))) {
148
146
  // Automatic property value conversion.
149
147
  state.typer[matches[1]] = matches[2];
150
148
  }
151
149
  }
152
- else if (matches = line.match(/^@([^\s:@][^:]*)\s*:\s*(.*)\s*$/)) {
150
+ else if ((matches = line.match(/^@([^\s:@][^:]*)\s*:\s*(.*)\s*$/))) {
153
151
  // New property
154
152
  state.newkey = matches[1];
155
153
  state.onewkey = state.newkey;
@@ -1,6 +1,6 @@
1
- import { RollCopy } from "../RollCopy.js";
2
- import { TrackerBar } from "../TrackerBar.js";
3
- import { Millimeters, Seconds } from "../Quantity.js";
1
+ import { RollCopy } from "../model/RollCopy.js";
2
+ import { TrackerBar } from "../systems/TrackerBar.js";
3
+ import { Millimeters, Seconds } from "../model/Quantity.js";
4
4
  /**
5
5
  * Peter Phillips's "e-roll" file, the unprocessed output of his
6
6
  * pneumatic roll reader (thesis pp. 182–196): the roll runs over a
@@ -1,11 +1,11 @@
1
1
  import { read } from "midifile-ts";
2
2
  import { v4 } from "uuid";
3
- import { assignObject } from "../Assumption.js";
4
- import { systemOf } from "../TrackerBar.js";
5
- import { shortenChains } from "../alignment.js";
3
+ import { assignObject } from "../model/Assumption.js";
4
+ import { systemOf } from "../systems/TrackerBar.js";
5
+ import { shortenChains } from "../collation/alignment.js";
6
6
  import { welteT100 } from "../systems/welteT100/bar.js";
7
7
  import { welteLicensee } from "../systems/welteLicensee/bar.js";
8
- import { inMetersPerMinute, mm, seconds, track } from "../Quantity.js";
8
+ import { inMetersPerMinute, mm, seconds, track } from "../model/Quantity.js";
9
9
  /**
10
10
  * Peter Phillips's "e-roll" file, the unprocessed output of his
11
11
  * pneumatic roll reader (thesis pp. 182–196): the roll runs over a
@@ -166,7 +166,6 @@ export function readFromPhillipsEroll(buffer, { system = welteT100, controlOffse
166
166
  const copy = {
167
167
  type: 'RollCopy',
168
168
  id: v4(),
169
- ops: [],
170
169
  conditions: [],
171
170
  measurements: {},
172
171
  production: { system: systemOf(system), produced: features },
@@ -1,5 +1,5 @@
1
- import { PaperSpeed, RollCopy } from "../RollCopy.js";
2
- import { TrackerBar } from "../TrackerBar.js";
1
+ import { PaperSpeed, RollCopy } from "../model/RollCopy.js";
2
+ import { TrackerBar } from "../systems/TrackerBar.js";
3
3
  /**
4
4
  * Rows of the image on an inch of paper. The player reads eight rows a
5
5
  * second per unit of roll tempo (tempo 80 comes with a sample rate of
@@ -1,7 +1,7 @@
1
1
  import { v4 } from "uuid";
2
- import { systemOf } from "../TrackerBar.js";
2
+ import { systemOf } from "../systems/TrackerBar.js";
3
3
  import { welteLicensee } from "../systems/welteLicensee/bar.js";
4
- import { feetPerMinute, inMillimeters, px, track } from "../Quantity.js";
4
+ import { feetPerMinute, inMillimeters, px, track } from "../model/Quantity.js";
5
5
  /**
6
6
  * Spencer Chase's e-roll file (`.bar`, "eRoll Tracker Bar Image") holds
7
7
  * a roll as a list of events: a distance in rows of the scanned image,
@@ -111,7 +111,6 @@ export function readFromSpencerBar(buffer, { rowsPerInch = SPENCER_ROWS_PER_INCH
111
111
  return {
112
112
  type: 'RollCopy',
113
113
  id: v4(),
114
- ops: [],
115
114
  conditions: [],
116
115
  measurements: {},
117
116
  production: { system: systemOf(system), produced: features },
@@ -1,6 +1,6 @@
1
- import { RollCopy } from "../RollCopy.js";
2
- import { TrackerBar } from "../TrackerBar.js";
3
- import { Track } from "../Quantity.js";
1
+ import { RollCopy } from "../model/RollCopy.js";
2
+ import { TrackerBar } from "../systems/TrackerBar.js";
3
+ import { Track } from "../model/Quantity.js";
4
4
  export interface StanfordAtonOptions {
5
5
  /**
6
6
  * Added to the scanning software's hole numbering to reach the
@@ -1,8 +1,8 @@
1
1
  import { v4 } from "uuid";
2
2
  import { AtonParser } from "./AtonParser.js";
3
- import { systemOf } from "../TrackerBar.js";
3
+ import { systemOf } from "../systems/TrackerBar.js";
4
4
  import { welteT100 } from "../systems/welteT100/bar.js";
5
- import { inMillimeters, mean, mm, pixelsPerInch, px, subtract, track } from "../Quantity.js";
5
+ import { inMillimeters, mean, mm, pixelsPerInch, px, subtract, track } from "../model/Quantity.js";
6
6
  /** Values in these files carry their unit as a suffix, e.g. "37.7646px". */
7
7
  const readPx = (value) => px(parseFloat(value));
8
8
  /** The parser writes one record as an object and several as an array. */
@@ -155,7 +155,6 @@ export function readFromStanfordAton(atonString, { trackShift, system = welteT10
155
155
  return {
156
156
  type: 'RollCopy',
157
157
  id: v4(),
158
- ops: [],
159
158
  conditions: [],
160
159
  production: {
161
160
  system: systemOf(system),
@@ -164,7 +163,6 @@ export function readFromStanfordAton(atonString, { trackShift, system = welteT10
164
163
  type: 'Perforator',
165
164
  id: `perforator_${v4()}`,
166
165
  condition: {
167
- type: 'ConditionState',
168
166
  conditionType: 'setting',
169
167
  punchDiameter: { value: punchDiameter, unit: 'mm' }
170
168
  }