linked-rolls 0.37.0 → 0.38.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.
@@ -4,7 +4,7 @@ import { AnySymbol, Expression, Note } from "./Symbol";
4
4
  import { Version } from "./Version";
5
5
  import { NegotiatedEvent } from "./ReproducingSystem";
6
6
  import { TrackerBar } from "./TrackerBar";
7
- import { RollCopy } from "./RollCopy";
7
+ import { Modification, ProductionEvent, RollCopy } from "./RollCopy";
8
8
  import { Millimeters } from "./Quantity";
9
9
  export type Path = (string | number)[];
10
10
  export declare const getAt: <T>(path: Path, obj: unknown) => T | undefined;
@@ -37,6 +37,15 @@ export declare class EditionView {
37
37
  carriersOf(symbol: AnySymbol): Readonly<FeatureOrPatch>[];
38
38
  /** The copy a feature sits on, a patch and everything it bears included. */
39
39
  copyOf(featureId: string): Readonly<RollCopy> | undefined;
40
+ /**
41
+ * The act a copy states a feature in: the production event that
42
+ * punched it, or the modification that brought it about. A feature
43
+ * a patch bears came onto the copy with the patch, so the act is
44
+ * the one that glued the patch on. Two features stand in one act
45
+ * where this returns the very same object, which is what
46
+ * `mergeFeatures` asks before it reads them as one.
47
+ */
48
+ actOf(featureId: string): Readonly<ProductionEvent | Modification> | undefined;
40
49
  /**
41
50
  * How a place on the edition's shared axis relates to the paper of
42
51
  * this version: place × factor = millimetres of its own paper.
@@ -1,7 +1,7 @@
1
1
  import { withBorneFeatures } from "./Feature";
2
2
  import { deletedBy, insertedBy, principalDerivationOf } from "./Version";
3
3
  import { systemIdOf } from "./TrackerBar";
4
- import { featuresOf, isPaperStretch } from "./RollCopy";
4
+ import { featuresMadeBy, featuresOf, isPaperStretch } from "./RollCopy";
5
5
  import { idOf, idsOf } from "./Assumption";
6
6
  import { mean } from "./Quantity";
7
7
  export const getAt = (path, obj) => {
@@ -161,6 +161,23 @@ export class EditionView {
161
161
  }
162
162
  return this.copiesByFeature.get(featureId);
163
163
  }
164
+ /**
165
+ * The act a copy states a feature in: the production event that
166
+ * punched it, or the modification that brought it about. A feature
167
+ * a patch bears came onto the copy with the patch, so the act is
168
+ * the one that glued the patch on. Two features stand in one act
169
+ * where this returns the very same object, which is what
170
+ * `mergeFeatures` asks before it reads them as one.
171
+ */
172
+ actOf(featureId) {
173
+ const copy = this.copyOf(featureId);
174
+ if (!copy)
175
+ return undefined;
176
+ const states = (features) => features.flatMap(withBorneFeatures).some(feature => feature.id === featureId);
177
+ if (states(copy.production?.produced ?? []))
178
+ return copy.production;
179
+ return copy.modifications.find(act => states(featuresMadeBy(act)));
180
+ }
164
181
  /**
165
182
  * How a place on the edition's shared axis relates to the paper of
166
183
  * this version: place × factor = millimetres of its own paper.
package/lib/RollCopy.d.ts CHANGED
@@ -346,6 +346,10 @@ export interface RollCopy extends WithType<'RollCopy'>, WithId {
346
346
  */
347
347
  carries?: ReferenceAssumption[];
348
348
  }
349
+ /** What an act brought onto the copy: what it produced or glued on, a removal nothing. */
350
+ export declare const featuresMadeBy: (modification: Modification) => FeatureOrPatch[];
351
+ /** Whether the act is one that modified the copy, rather than the production that punched it. */
352
+ export declare const isModification: (act: ProductionEvent | Modification) => act is Modification;
349
353
  /** Whether the act is left stating nothing: it produced, added or removed nothing. */
350
354
  export declare const statesNothing: (modification: Modification) => boolean;
351
355
  /**
package/lib/RollCopy.js CHANGED
@@ -17,20 +17,22 @@ export const modificationPurposes = [
17
17
  'glossing'
18
18
  ];
19
19
  /** What an act brought onto the copy: what it produced or glued on, a removal nothing. */
20
- const madeBy = (modification) => {
20
+ export const featuresMadeBy = (modification) => {
21
21
  if (modification.type === 'Alteration')
22
22
  return modification.produced;
23
23
  return modification.type === 'Attachment' ? modification.added : [];
24
24
  };
25
+ /** Whether the act is one that modified the copy, rather than the production that punched it. */
26
+ export const isModification = (act) => 'type' in act;
25
27
  /** Whether the act is left stating nothing: it produced, added or removed nothing. */
26
- export const statesNothing = (modification) => modification.type === 'Removal' ? modification.removed.length === 0 : madeBy(modification).length === 0;
28
+ export const statesNothing = (modification) => modification.type === 'Removal' ? modification.removed.length === 0 : featuresMadeBy(modification).length === 0;
27
29
  /**
28
30
  * The features of the copy act by act: what the punching produced
29
31
  * first, then what each modification produced or glued on. A feature a
30
32
  * patch bears states no place of its own and is not among them;
31
33
  * `withBorneFeatures` reaches those.
32
34
  */
33
- export const featuresByAct = (copy) => [copy.production?.produced ?? [], ...copy.modifications.map(madeBy)];
35
+ export const featuresByAct = (copy) => [copy.production?.produced ?? [], ...copy.modifications.map(featuresMadeBy)];
34
36
  /** Every feature the copy states at a place of its own, whichever act made it. */
35
37
  export const featuresOf = (copy) => featuresByAct(copy).flat();
36
38
  /**
@@ -4,10 +4,10 @@ import { Edition } from "./Edition";
4
4
  import { AnySymbol, PlacementRelation } from "./Symbol";
5
5
  import { CollationTolerance } from "./Collation";
6
6
  import { Edit } from "./Edit";
7
- import { GeneralRollCondition, RollCopy, ScaleReading, Shift } from "./RollCopy";
7
+ import { GeneralRollCondition, ModificationPurpose, RollCopy, ScaleReading, Shift } from "./RollCopy";
8
8
  import { FeatureSource } from "./FeatureSource";
9
9
  import { AnyArgumentation, Belief, Certainty, ObjectAssumption } from "./Assumption";
10
- import { FeatureConditionAssignment, FeatureOrPatch } from "./Feature";
10
+ import { FeatureConditionAssignment, FeatureOrPatch, NestedFeature } from "./Feature";
11
11
  /**
12
12
  * A change to an edition, written onto an immer draft of it. One
13
13
  * operation is one undo step, so an operation that has to read the
@@ -70,6 +70,34 @@ export declare const addGeneralCondition: (copyId: string, condition: ObjectAssu
70
70
  export declare const stateFeatureCondition: (copyId: string, featureId: string, condition: FeatureConditionAssignment) => EditionOp;
71
71
  /** The symbols of the versions that no other copy carries. */
72
72
  export declare const symbolsCarriedOnlyBy: (edition: Edition, copyId: string) => AnySymbol[];
73
+ /**
74
+ * The act a feature an editor states belongs to: the punching of the
75
+ * copy, the act that brought another feature about, or, where neither
76
+ * is said, an act of its own for the purpose given. A patch is never
77
+ * punched, being glued on, so `punched` says nothing of one.
78
+ */
79
+ export interface FeatureAct {
80
+ /** The copy was punched with it, which is where a reading of a scan puts every hole. */
81
+ punched?: boolean;
82
+ /** The act that brought this feature about brought the new one about as well. */
83
+ beside?: string;
84
+ /** What the act was for, where a new one is made for the feature. */
85
+ purpose?: ModificationPurpose;
86
+ }
87
+ /**
88
+ * States that the copy bears the feature, in the act that brought it
89
+ * about: a patch was glued on by an attachment, anything else was
90
+ * produced, by the punching or by a later act. Which act, `FeatureAct`
91
+ * says; a `beside` that names nothing the copy bears is passed over and
92
+ * the feature goes into an act of its own.
93
+ */
94
+ export declare const addFeature: (copyId: string, feature: FeatureOrPatch, act?: FeatureAct) => EditionOp;
95
+ /**
96
+ * States that the patch bears the feature. What a patch bears came onto
97
+ * the copy with the patch, so it belongs to no act of its own and
98
+ * states no place: it stands where the patch stands.
99
+ */
100
+ export declare const addBorneFeature: (copyId: string, patchId: string, feature: NestedFeature) => EditionOp;
73
101
  /**
74
102
  * Takes the features off the copy, and out of the versions with what
75
103
  * only they carried. A feature may be named wherever the copy bears it:
package/lib/editionOps.js CHANGED
@@ -379,6 +379,66 @@ const rewriteFeatures = (copy, rewrite) => {
379
379
  }
380
380
  copy.modifications = pruned(state.modifications, rewritingAct(rewrite), statesNothing);
381
381
  };
382
+ /** The features of the act that brought the named feature about, where that act produces features. */
383
+ const producedBeside = (copy, featureId) => {
384
+ const names = (features) => features.some(feature => feature.id === featureId);
385
+ const punched = copy.production?.produced;
386
+ if (punched && names(punched))
387
+ return punched;
388
+ const act = copy.modifications.find(act => act.type === 'Alteration' && names(act.produced));
389
+ return act?.type === 'Alteration' ? act.produced : undefined;
390
+ };
391
+ /** The patches of the attachment that glued the named one on. */
392
+ const gluedBeside = (copy, patchId) => {
393
+ const act = copy.modifications.find(act => act.type === 'Attachment' && act.added.some(patch => patch.id === patchId));
394
+ return act?.type === 'Attachment' ? act.added : undefined;
395
+ };
396
+ /** The list the copy states a new feature in, making the act it belongs to where there is none. */
397
+ const actFor = (copy, patch, act) => {
398
+ const beside = act.beside !== undefined
399
+ ? (patch ? gluedBeside(copy, act.beside) : producedBeside(copy, act.beside))
400
+ : undefined;
401
+ if (beside)
402
+ return beside;
403
+ if (patch) {
404
+ const added = [];
405
+ copy.modifications.push({ type: 'Attachment', added, ...(act.purpose && { purpose: act.purpose }) });
406
+ return added;
407
+ }
408
+ if (act.punched) {
409
+ if (!copy.production)
410
+ copy.production = {};
411
+ if (!copy.production.produced)
412
+ copy.production.produced = [];
413
+ return copy.production.produced;
414
+ }
415
+ const produced = [];
416
+ copy.modifications.push({ type: 'Alteration', produced, ...(act.purpose && { purpose: act.purpose }) });
417
+ return produced;
418
+ };
419
+ /**
420
+ * States that the copy bears the feature, in the act that brought it
421
+ * about: a patch was glued on by an attachment, anything else was
422
+ * produced, by the punching or by a later act. Which act, `FeatureAct`
423
+ * says; a `beside` that names nothing the copy bears is passed over and
424
+ * the feature goes into an act of its own.
425
+ */
426
+ export const addFeature = (copyId, feature, act = {}) => onCopy(copyId, copy => {
427
+ actFor(copy, isGluedOn(feature), act).push(feature);
428
+ });
429
+ /**
430
+ * States that the patch bears the feature. What a patch bears came onto
431
+ * the copy with the patch, so it belongs to no act of its own and
432
+ * states no place: it stands where the patch stands.
433
+ */
434
+ export const addBorneFeature = (copyId, patchId, feature) => onCopy(copyId, copy => {
435
+ const patch = featuresOf(copy).flatMap(withBorneFeatures).find(borne => borne.id === patchId);
436
+ if (!patch || !isGluedOn(patch))
437
+ return;
438
+ if (!patch.features)
439
+ patch.features = [];
440
+ patch.features.push(feature);
441
+ });
382
442
  /**
383
443
  * Takes the features off the copy, and out of the versions with what
384
444
  * only they carried. A feature may be named wherever the copy bears it:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "linked-rolls",
3
- "version": "0.37.0",
3
+ "version": "0.38.0",
4
4
  "description": "Digital editions of piano rolls: import, collation, editorial assumptions, JSON-LD export, and emulation through a reproducing system",
5
5
  "license": "MIT",
6
6
  "repository": {