@thi.ng/ramp 3.1.23 → 3.1.24

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/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2024-05-08T18:24:32Z
3
+ - **Last updated**: 2024-06-21T19:34:38Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
@@ -9,6 +9,15 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
9
9
  **Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
10
10
  and/or version bumps of transitive dependencies.
11
11
 
12
+ ### [3.1.24](https://github.com/thi-ng/umbrella/tree/@thi.ng/ramp@3.1.24) (2024-06-21)
13
+
14
+ #### ♻️ Refactoring
15
+
16
+ - dedupe samples() impls ([85515e1](https://github.com/thi-ng/umbrella/commit/85515e1))
17
+ - extract common impl as internal helper
18
+ - update Group.samples() & Ramp.samples()
19
+ - dedupe nested() min/max impls ([02e1479](https://github.com/thi-ng/umbrella/commit/02e1479))
20
+
12
21
  ## [3.1.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/ramp@3.1.0) (2024-02-19)
13
22
 
14
23
  #### 🚀 Features
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  [![Mastodon Follow](https://img.shields.io/mastodon/follow/109331703950160316?domain=https%3A%2F%2Fmastodon.thi.ng&style=social)](https://mastodon.thi.ng/@toxi)
8
8
 
9
9
  > [!NOTE]
10
- > This is one of 192 standalone projects, maintained as part
10
+ > This is one of 193 standalone projects, maintained as part
11
11
  > of the [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo
12
12
  > and anti-framework.
13
13
  >
@@ -70,7 +70,7 @@ For Node.js REPL:
70
70
  const ramp = await import("@thi.ng/ramp");
71
71
  ```
72
72
 
73
- Package sizes (brotli'd, pre-treeshake): ESM: 1.84 KB
73
+ Package sizes (brotli'd, pre-treeshake): ESM: 1.87 KB
74
74
 
75
75
  ## Dependencies
76
76
 
package/group.d.ts CHANGED
@@ -15,7 +15,7 @@ export type GroupImpl<T extends Record<string, any>> = {
15
15
  * {@link unconstrained}), which will be applied _prior_ to evaluating any child ramps.
16
16
  *
17
17
  * @example
18
- * ```ts
18
+ * ```ts tangle:../export/group.ts
19
19
  * import { group, hermite, linear } from "@thi.ng/ramp";
20
20
  *
21
21
  * const example = group({
@@ -24,14 +24,14 @@ export type GroupImpl<T extends Record<string, any>> = {
24
24
  * b: hermite([[0, 100], [1, 200]]),
25
25
  * });
26
26
  *
27
- * example.at(0.2)
27
+ * console.log(example.at(0.2));
28
28
  * // { a: -2.5, b: 110.4 }
29
29
  *
30
30
  * // set new keyframe for `b` ramp
31
31
  * // (in TS need to cast to proper type first)
32
32
  * (<Ramp<number>>example.children.b).setStopAt(0.5, 200);
33
33
  *
34
- * example.at(0.2)
34
+ * console.log(example.at(0.2));
35
35
  * // { a: -2.5, b: 135.2 }
36
36
  * ```
37
37
  *
package/group.js CHANGED
@@ -1,7 +1,5 @@
1
- import { mix } from "@thi.ng/math/mix";
2
- import { map } from "@thi.ng/transducers/map";
3
- import { normRange } from "@thi.ng/transducers/norm-range";
4
1
  import { unconstrained } from "./domain.js";
2
+ import { __samples } from "./utils.js";
5
3
  const group = (children, opts) => new Group(children, opts);
6
4
  class Group {
7
5
  constructor(children, opts) {
@@ -19,15 +17,7 @@ class Group {
19
17
  }, {});
20
18
  }
21
19
  samples(n = 100, start, end) {
22
- if (start == void 0 || end == void 0) {
23
- const bounds = this.timeBounds();
24
- start = start ?? bounds[0];
25
- end = end ?? bounds[1];
26
- }
27
- return map((t) => {
28
- t = mix(start, end, t);
29
- return [t, this.at(t)];
30
- }, normRange(n));
20
+ return __samples(this, n, start, end);
31
21
  }
32
22
  bounds() {
33
23
  return this.childEntries.reduce(
package/nested.d.ts CHANGED
@@ -14,7 +14,7 @@ export type NestedImpl<T extends Record<string, any>> = {
14
14
  * are somewhat similar but satisfy different use cases.
15
15
  *
16
16
  * @example
17
- * ```ts
17
+ * ```ts tangle:../export/nested.ts
18
18
  * import { ramp, nested, LINEAR_N, HERMITE_N } from "@thi.ng/ramp";
19
19
  *
20
20
  * const example = ramp(
@@ -27,7 +27,7 @@ export type NestedImpl<T extends Record<string, any>> = {
27
27
  * ]
28
28
  * )
29
29
  *
30
- * example.at(25)
30
+ * console.log(example.at(25));
31
31
  * // { a: -2.5, b: 1156.25 }
32
32
  * ```
33
33
  *
package/nested.js CHANGED
@@ -1,14 +1,12 @@
1
1
  const nested = (children) => {
2
2
  const pairs = Object.entries(children);
3
+ const $minmax = (op) => (acc, x) => pairs.reduce((acc2, [id, impl]) => {
4
+ acc2[id] = impl[op](acc2[id], x[id]);
5
+ return acc2;
6
+ }, acc || {});
3
7
  return {
4
- min: (acc, x) => pairs.reduce((acc2, [id, impl]) => {
5
- acc2[id] = impl.min(acc2[id], x[id]);
6
- return acc2;
7
- }, acc || {}),
8
- max: (acc, x) => pairs.reduce((acc2, [id, impl]) => {
9
- acc2[id] = impl.max(acc2[id], x[id]);
10
- return acc2;
11
- }, acc || {}),
8
+ min: $minmax("min"),
9
+ max: $minmax("max"),
12
10
  at: (stops, index, t) => pairs.reduce((acc, [id, impl]) => {
13
11
  acc[id] = impl.at(
14
12
  stops.map((x) => [x[0], x[1][id]]),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/ramp",
3
- "version": "3.1.23",
3
+ "version": "3.1.24",
4
4
  "description": "Extensible keyframe interpolation/tweening of arbitrary, nested types",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -10,7 +10,7 @@
10
10
  "type": "git",
11
11
  "url": "https://github.com/thi-ng/umbrella.git"
12
12
  },
13
- "homepage": "https://github.com/thi-ng/umbrella/tree/develop/packages/ramp#readme",
13
+ "homepage": "https://thi.ng/ramp",
14
14
  "funding": [
15
15
  {
16
16
  "type": "github",
@@ -36,19 +36,19 @@
36
36
  "tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
37
37
  },
38
38
  "dependencies": {
39
- "@thi.ng/api": "^8.11.2",
40
- "@thi.ng/arrays": "^2.9.6",
41
- "@thi.ng/compare": "^2.3.5",
42
- "@thi.ng/errors": "^2.5.7",
43
- "@thi.ng/math": "^5.10.13",
44
- "@thi.ng/transducers": "^9.0.5",
45
- "@thi.ng/vectors": "^7.10.31"
39
+ "@thi.ng/api": "^8.11.3",
40
+ "@thi.ng/arrays": "^2.9.7",
41
+ "@thi.ng/compare": "^2.3.6",
42
+ "@thi.ng/errors": "^2.5.8",
43
+ "@thi.ng/math": "^5.11.0",
44
+ "@thi.ng/transducers": "^9.0.6",
45
+ "@thi.ng/vectors": "^7.11.0"
46
46
  },
47
47
  "devDependencies": {
48
- "@microsoft/api-extractor": "^7.43.2",
49
- "esbuild": "^0.21.1",
48
+ "@microsoft/api-extractor": "^7.47.0",
49
+ "esbuild": "^0.21.5",
50
50
  "typedoc": "^0.25.13",
51
- "typescript": "^5.4.5"
51
+ "typescript": "^5.5.2"
52
52
  },
53
53
  "keywords": [
54
54
  "1d",
@@ -117,5 +117,5 @@
117
117
  "thi.ng": {
118
118
  "year": 2019
119
119
  },
120
- "gitHead": "df34b4a9e650cc7323575356de207d78933bdcf3\n"
120
+ "gitHead": "154c95cf9d6bab32174498ec3b5b5d87e42be7f9\n"
121
121
  }
package/ramp.d.ts CHANGED
@@ -26,7 +26,7 @@ export declare class Ramp<T> implements ICopy<IRamp<T>>, IEmpty<IRamp<T>>, IRamp
26
26
  * @param t
27
27
  */
28
28
  at(t: number): T;
29
- samples(n?: number, start?: number, end?: number): IterableIterator<Frame<T>>;
29
+ samples(n?: number, start?: number, end?: number): Iterable<Frame<T>>;
30
30
  bounds(): RampBounds<T>;
31
31
  timeBounds(): [number, number];
32
32
  setStopAt(t: number, val: T, eps?: number): boolean;
package/ramp.js CHANGED
@@ -4,10 +4,8 @@ import { compareNumAsc } from "@thi.ng/compare/numeric";
4
4
  import { assert } from "@thi.ng/errors/assert";
5
5
  import { absDiff } from "@thi.ng/math/abs";
6
6
  import { clamp } from "@thi.ng/math/interval";
7
- import { mix } from "@thi.ng/math/mix";
8
- import { map } from "@thi.ng/transducers/map";
9
- import { normRange } from "@thi.ng/transducers/norm-range";
10
7
  import { unconstrained } from "./domain.js";
8
+ import { __samples } from "./utils.js";
11
9
  const ramp = (impl, stops, opts) => new Ramp(impl, stops, opts);
12
10
  class Ramp {
13
11
  constructor(impl, stops, opts) {
@@ -47,15 +45,7 @@ class Ramp {
47
45
  return i < 0 ? first[1] : i >= n ? last[1] : impl.at(stops, i, t);
48
46
  }
49
47
  samples(n = 100, start, end) {
50
- if (start == void 0 || end == void 0) {
51
- const bounds = this.timeBounds();
52
- start = start ?? bounds[0];
53
- end = end ?? bounds[1];
54
- }
55
- return map((t) => {
56
- t = mix(start, end, t);
57
- return [t, this.at(t)];
58
- }, normRange(n));
48
+ return __samples(this, n, start, end);
59
49
  }
60
50
  bounds() {
61
51
  const { impl, stops } = this;
package/utils.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import type { Frame, IReadonlyRamp } from "./api.js";
2
+ export declare const __samples: <T>(ramp: IReadonlyRamp<T>, n: number, start?: number, end?: number) => IterableIterator<Frame<T>>;
3
+ //# sourceMappingURL=utils.d.ts.map
package/utils.js ADDED
@@ -0,0 +1,17 @@
1
+ import { mix } from "@thi.ng/math/mix";
2
+ import { map } from "@thi.ng/transducers/map";
3
+ import { normRange } from "@thi.ng/transducers/norm-range";
4
+ const __samples = (ramp, n, start, end) => {
5
+ if (start === void 0 || end === void 0) {
6
+ const bounds = ramp.timeBounds();
7
+ start = start ?? bounds[0];
8
+ end = end ?? bounds[1];
9
+ }
10
+ return map((t) => {
11
+ t = mix(start, end, t);
12
+ return [t, ramp.at(t)];
13
+ }, normRange(n));
14
+ };
15
+ export {
16
+ __samples
17
+ };