linked-rolls 0.22.0 → 0.23.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.
package/lib/Quantity.d.ts CHANGED
@@ -7,8 +7,12 @@
7
7
  * The unit names are the ones the records state in their `unit` field.
8
8
  */
9
9
  declare const unit: unique symbol;
10
+ /**
11
+ * The units a record may state. A `Measure` is limited to these, since
12
+ * they are what the `unit` field is allowed to say.
13
+ */
10
14
  export type Unit = 'mm' | 'cm' | 'px' | 'track' | 's' | 'ms' | 'ft/min' | 'm/min' | 'px/in';
11
- export type Quantity<U extends Unit> = number & {
15
+ export type Quantity<U extends string> = number & {
12
16
  readonly [unit]: U;
13
17
  };
14
18
  /** A place along the roll, or any length on the paper. */
@@ -24,6 +28,8 @@ export type FeetPerMinute = Quantity<'ft/min'>;
24
28
  export type MetersPerMinute = Quantity<'m/min'>;
25
29
  /** How finely a scan was read: pixels of the image per inch of paper. */
26
30
  export type Resolution = Quantity<'px/in'>;
31
+ /** Names a number in a unit. Partially apply it to make a constructor. */
32
+ export declare const quantity: <U extends string>(value: number) => Quantity<U>;
27
33
  export declare const mm: (value: number) => Quantity<"mm">;
28
34
  export declare const cm: (value: number) => Quantity<"cm">;
29
35
  export declare const px: (value: number) => Quantity<"px">;
@@ -50,19 +56,24 @@ export interface Measure<U extends Unit> {
50
56
  */
51
57
  unit: U;
52
58
  }
53
- export declare const add: <U extends Unit>(a: Quantity<U>, b: Quantity<NoInfer<U>>) => Quantity<U>;
54
- export declare const subtract: <U extends Unit>(a: Quantity<U>, b: Quantity<NoInfer<U>>) => Quantity<U>;
55
- export declare const distance: <U extends Unit>(a: Quantity<U>, b: Quantity<NoInfer<U>>) => Quantity<U>;
59
+ export declare const add: <U extends string>(a: Quantity<U>, b: Quantity<NoInfer<U>>) => Quantity<U>;
60
+ export declare const subtract: <U extends string>(a: Quantity<U>, b: Quantity<NoInfer<U>>) => Quantity<U>;
61
+ export declare const distance: <U extends string>(a: Quantity<U>, b: Quantity<NoInfer<U>>) => Quantity<U>;
56
62
  /** A quantity times a plain factor, such as a stretch. */
57
- export declare const scale: <U extends Unit>(a: Quantity<U>, factor: number) => Quantity<U>;
58
- export declare const sum: <U extends Unit>(values: readonly Quantity<U>[]) => Quantity<U>;
59
- export declare const mean: <U extends Unit>(values: readonly Quantity<U>[]) => Quantity<U>;
63
+ export declare const scale: <U extends string>(a: Quantity<U>, factor: number) => Quantity<U>;
64
+ export declare const min: <U extends string>(a: Quantity<U>, b: Quantity<NoInfer<U>>) => Quantity<U>;
65
+ export declare const max: <U extends string>(a: Quantity<U>, b: Quantity<NoInfer<U>>) => Quantity<U>;
66
+ /** The value brought inside the bounds, which must not be the wrong way round. */
67
+ export declare const clamp: <U extends string>(value: Quantity<U>, low: Quantity<NoInfer<U>>, high: Quantity<NoInfer<U>>) => Quantity<U>;
68
+ export declare const sum: <U extends string>(values: readonly Quantity<U>[]) => Quantity<U>;
69
+ export declare const mean: <U extends string>(values: readonly Quantity<U>[]) => Quantity<U>;
60
70
  /** A place in a scan taken at `dpi` dots per inch, on the paper. */
61
71
  export declare const inMillimeters: (place: Pixels, dpi: number) => Millimeters;
62
72
  /** A place on the paper, in a scan taken at `dpi` dots per inch. */
63
73
  export declare const inPixels: (place: Millimeters, dpi: number) => Pixels;
64
74
  export declare const inCentimeters: (length: Millimeters) => Centimeters;
65
75
  export declare const inSeconds: (time: Milliseconds) => Seconds;
76
+ export declare const inMilliseconds: (time: Seconds) => Milliseconds;
66
77
  /** A speed as a record states it, in feet or metres per minute. */
67
78
  export type SpeedMeasure = Measure<'ft/min'> | Measure<'m/min'>;
68
79
  /** A speed in metres per minute, whichever unit it was stated in. */
package/lib/Quantity.js CHANGED
@@ -1,4 +1,5 @@
1
- const quantity = (value) => value;
1
+ /** Names a number in a unit. Partially apply it to make a constructor. */
2
+ export const quantity = (value) => value;
2
3
  export const mm = quantity;
3
4
  export const cm = quantity;
4
5
  export const px = quantity;
@@ -15,6 +16,12 @@ export const subtract = (a, b) => quantity(a - b);
15
16
  export const distance = (a, b) => quantity(Math.abs(a - b));
16
17
  /** A quantity times a plain factor, such as a stretch. */
17
18
  export const scale = (a, factor) => quantity(a * factor);
19
+ // Math.min and Math.max are declared over plain numbers, so a quantity
20
+ // passed through them comes back without its unit.
21
+ export const min = (a, b) => quantity(Math.min(a, b));
22
+ export const max = (a, b) => quantity(Math.max(a, b));
23
+ /** The value brought inside the bounds, which must not be the wrong way round. */
24
+ export const clamp = (value, low, high) => quantity(Math.min(high, Math.max(low, value)));
18
25
  // A list is taken at its element type, so one that mixes units yields a
19
26
  // union unit rather than an error; only the binary operations reject a mix.
20
27
  export const sum = (values) => quantity(values.reduce((total, value) => total + value, 0));
@@ -25,7 +32,9 @@ export const inMillimeters = (place, dpi) => mm(place / dpi * MM_PER_INCH);
25
32
  /** A place on the paper, in a scan taken at `dpi` dots per inch. */
26
33
  export const inPixels = (place, dpi) => px(place / MM_PER_INCH * dpi);
27
34
  export const inCentimeters = (length) => cm(length / 10);
28
- export const inSeconds = (time) => seconds(time / 1000);
35
+ const MS_PER_SECOND = 1000;
36
+ export const inSeconds = (time) => seconds(time / MS_PER_SECOND);
37
+ export const inMilliseconds = (time) => milliseconds(time * MS_PER_SECOND);
29
38
  const METERS_PER_FOOT = 0.3048;
30
39
  /** A speed in metres per minute, whichever unit it was stated in. */
31
40
  export const inMetersPerMinute = (speed) => speed.unit === 'm/min' ? speed.value : metersPerMinute(speed.value * METERS_PER_FOOT);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "linked-rolls",
3
- "version": "0.22.0",
3
+ "version": "0.23.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": {