@thi.ng/ramp 3.2.0 → 3.3.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/CHANGELOG.md +10 -1
- package/README.md +28 -19
- package/easing.d.ts +45 -0
- package/easing.js +30 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +7 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2024-
|
|
3
|
+
- **Last updated**: 2024-09-05T12:23:14Z
|
|
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.3.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/ramp@3.3.0) (2024-09-05)
|
|
13
|
+
|
|
14
|
+
#### 🚀 Features
|
|
15
|
+
|
|
16
|
+
- add easing ramp implementations ([1e23b61](https://github.com/thi-ng/umbrella/commit/1e23b61))
|
|
17
|
+
- add `easing()`
|
|
18
|
+
- add `EASING_N` / `EASING_V`
|
|
19
|
+
- update pkg exports
|
|
20
|
+
|
|
12
21
|
## [3.2.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/ramp@3.2.0) (2024-08-28)
|
|
13
22
|
|
|
14
23
|
#### 🚀 Features
|
package/README.md
CHANGED
|
@@ -34,9 +34,15 @@ Extensible keyframe interpolation/tweening of arbitrary, nested types.
|
|
|
34
34
|

|
|
35
35
|
|
|
36
36
|
This package can perform keyframe interpolation for ramps of numeric values,
|
|
37
|
-
n-dimensional vectors and nested objects of the same. It provides
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
n-dimensional vectors and nested objects of the same. It provides several
|
|
38
|
+
interpolation methods out of the box, but can be extended by implementing a
|
|
39
|
+
simple interface to achieve other interpolation methods.
|
|
40
|
+
|
|
41
|
+
Built-in interpolation modes:
|
|
42
|
+
|
|
43
|
+
- [linear](https://docs.thi.ng/umbrella/ramp/functions/linear.html)
|
|
44
|
+
- [cubic hermite](https://docs.thi.ng/umbrella/ramp/functions/hermite.html)
|
|
45
|
+
- [arbitrary easing functions](https://docs.thi.ng/umbrella/ramp/functions/easing.html)
|
|
40
46
|
|
|
41
47
|
## Status
|
|
42
48
|
|
|
@@ -70,7 +76,7 @@ For Node.js REPL:
|
|
|
70
76
|
const ramp = await import("@thi.ng/ramp");
|
|
71
77
|
```
|
|
72
78
|
|
|
73
|
-
Package sizes (brotli'd, pre-treeshake): ESM:
|
|
79
|
+
Package sizes (brotli'd, pre-treeshake): ESM: 2.00 KB
|
|
74
80
|
|
|
75
81
|
## Dependencies
|
|
76
82
|
|
|
@@ -102,27 +108,30 @@ directory are using this package:
|
|
|
102
108
|
### Numeric
|
|
103
109
|
|
|
104
110
|
```ts tangle:export/readme.ts
|
|
105
|
-
import { linear, hermite } from "@thi.ng/ramp";
|
|
111
|
+
import { linear, hermite, easing } from "@thi.ng/ramp";
|
|
112
|
+
|
|
113
|
+
const stops = [[0.1, 0], [0.5, 1], [0.9, 0]];
|
|
106
114
|
|
|
107
|
-
const rampL = linear(
|
|
108
|
-
const rampH = hermite(
|
|
115
|
+
const rampL = linear(stops);
|
|
116
|
+
const rampH = hermite(stops);
|
|
117
|
+
const rampE = easing(stops);
|
|
109
118
|
|
|
110
119
|
for(let i = 0; i <= 10; i++) {
|
|
111
120
|
const t = i / 10;
|
|
112
|
-
console.log(t, rampL.at(t).toFixed(
|
|
121
|
+
console.log(t, rampL.at(t).toFixed(3), rampH.at(t).toFixed(3), rampE.at(t).toFixed(3));
|
|
113
122
|
}
|
|
114
123
|
|
|
115
|
-
// 0 0.
|
|
116
|
-
// 0.1 0.
|
|
117
|
-
// 0.2 0.
|
|
118
|
-
// 0.3 0.
|
|
119
|
-
// 0.4 0.
|
|
120
|
-
// 0.5 1.
|
|
121
|
-
// 0.6 0.
|
|
122
|
-
// 0.7 0.
|
|
123
|
-
// 0.8 0.
|
|
124
|
-
// 0.9 0.
|
|
125
|
-
// 1 0.
|
|
124
|
+
// 0 0.000 0.000 0.000
|
|
125
|
+
// 0.1 0.000 0.000 0.000
|
|
126
|
+
// 0.2 0.250 0.156 0.016
|
|
127
|
+
// 0.3 0.500 0.500 0.500
|
|
128
|
+
// 0.4 0.750 0.844 0.984
|
|
129
|
+
// 0.5 1.000 1.000 1.000
|
|
130
|
+
// 0.6 0.750 0.844 0.984
|
|
131
|
+
// 0.7 0.500 0.500 0.500
|
|
132
|
+
// 0.8 0.250 0.156 0.016
|
|
133
|
+
// 0.9 0.000 0.000 0.000
|
|
134
|
+
// 1 0.000 0.000 0.000
|
|
126
135
|
```
|
|
127
136
|
|
|
128
137
|
### nD vectors
|
package/easing.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { FnN } from "@thi.ng/api";
|
|
2
|
+
import type { Vec } from "@thi.ng/vectors";
|
|
3
|
+
import type { Frame, RampImpl, RampOpts, VecAPI } from "./api.js";
|
|
4
|
+
import { Ramp } from "./ramp.js";
|
|
5
|
+
/**
|
|
6
|
+
* Syntax sugar for creating a numeric {@link Ramp} using the {@link EASING_N}
|
|
7
|
+
* ramp interpolation impl (supporting arbitrary easing functions), given
|
|
8
|
+
* `stops` (aka keyframes, minimum 2 required) and options.
|
|
9
|
+
*
|
|
10
|
+
* @remarks
|
|
11
|
+
* Easing functions remap time values in the [0,1] range. By default uses
|
|
12
|
+
* [`easeInOut5()`](https://docs.thi.ng/umbrella/math/functions/easeInOut5.html).
|
|
13
|
+
*
|
|
14
|
+
* For vector-valued ramps, use {@link ramp} with {@link EASING_V}.
|
|
15
|
+
*
|
|
16
|
+
* @param stops
|
|
17
|
+
* @param opts
|
|
18
|
+
*/
|
|
19
|
+
export declare const easing: (stops: Frame<number>[], opts?: Partial<RampOpts & {
|
|
20
|
+
easing: FnN;
|
|
21
|
+
}>) => Ramp<number>;
|
|
22
|
+
/**
|
|
23
|
+
* Higher-order ramp interpolation implementation supporting arbitrary `easing`
|
|
24
|
+
* function to control keyframe interpolation.
|
|
25
|
+
*
|
|
26
|
+
* @remarks
|
|
27
|
+
* Easing functions remap time values in the [0,1] range. By default uses
|
|
28
|
+
* [`easeInOut5()`](https://docs.thi.ng/umbrella/math/functions/easeInOut5.html).
|
|
29
|
+
*
|
|
30
|
+
* @param easing
|
|
31
|
+
*/
|
|
32
|
+
export declare const EASING_N: (easing?: FnN) => RampImpl<number>;
|
|
33
|
+
/**
|
|
34
|
+
* Vector version of {@link EASING_N}. Use with any of the supplied vector APIs:
|
|
35
|
+
* {@link VEC} (arbitrary size), {@link VEC2}, {@link VEC3} or {@link VEC4}.
|
|
36
|
+
*
|
|
37
|
+
* @remarks
|
|
38
|
+
* Easing functions remap time values in the [0,1] range. By default uses
|
|
39
|
+
* [`easeInOut5()`](https://docs.thi.ng/umbrella/math/functions/easeInOut5.html).
|
|
40
|
+
*
|
|
41
|
+
* @param vec
|
|
42
|
+
* @param easing
|
|
43
|
+
*/
|
|
44
|
+
export declare const EASING_V: <T extends Vec>(vec: VecAPI, easing?: FnN) => RampImpl<T>;
|
|
45
|
+
//# sourceMappingURL=easing.d.ts.map
|
package/easing.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { easeInOut5 } from "@thi.ng/math/easing";
|
|
2
|
+
import { norm } from "@thi.ng/math/fit";
|
|
3
|
+
import { mix } from "@thi.ng/math/mix";
|
|
4
|
+
import { Ramp } from "./ramp.js";
|
|
5
|
+
const easing = (stops, opts) => new Ramp(EASING_N(opts?.easing), stops, opts);
|
|
6
|
+
const EASING_N = (easing2 = easeInOut5) => {
|
|
7
|
+
return {
|
|
8
|
+
min: (acc, x) => Math.min(acc ?? Infinity, x),
|
|
9
|
+
max: (acc, x) => Math.max(acc ?? -Infinity, x),
|
|
10
|
+
at: (stops, i, t) => {
|
|
11
|
+
const a = stops[i];
|
|
12
|
+
const b = stops[i + 1];
|
|
13
|
+
return mix(a[1], b[1], easing2(norm(t, a[0], b[0])));
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
const EASING_V = (vec, easing2 = easeInOut5) => ({
|
|
18
|
+
min: (acc, x) => vec.min(acc, acc || vec.vecOf(Infinity), x),
|
|
19
|
+
max: (acc, x) => vec.max(acc, acc || vec.vecOf(-Infinity), x),
|
|
20
|
+
at: (stops, i, t) => {
|
|
21
|
+
const a = stops[i];
|
|
22
|
+
const b = stops[i + 1];
|
|
23
|
+
return vec.mixN([], a[1], b[1], easing2(norm(t, a[0], b[0])));
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
export {
|
|
27
|
+
EASING_N,
|
|
28
|
+
EASING_V,
|
|
29
|
+
easing
|
|
30
|
+
};
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/ramp",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0",
|
|
4
4
|
"description": "Extensible keyframe interpolation/tweening of arbitrary, nested types",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
"@thi.ng/compare": "^2.4.1",
|
|
42
42
|
"@thi.ng/errors": "^2.5.15",
|
|
43
43
|
"@thi.ng/math": "^5.11.9",
|
|
44
|
-
"@thi.ng/transducers": "^9.2.
|
|
45
|
-
"@thi.ng/vectors": "^7.
|
|
44
|
+
"@thi.ng/transducers": "^9.2.2",
|
|
45
|
+
"@thi.ng/vectors": "^7.12.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@microsoft/api-extractor": "^7.47.5",
|
|
@@ -95,6 +95,9 @@
|
|
|
95
95
|
"./domain": {
|
|
96
96
|
"default": "./domain.js"
|
|
97
97
|
},
|
|
98
|
+
"./easing": {
|
|
99
|
+
"default": "./easing.js"
|
|
100
|
+
},
|
|
98
101
|
"./group": {
|
|
99
102
|
"default": "./group.js"
|
|
100
103
|
},
|
|
@@ -117,5 +120,5 @@
|
|
|
117
120
|
"thi.ng": {
|
|
118
121
|
"year": 2019
|
|
119
122
|
},
|
|
120
|
-
"gitHead": "
|
|
123
|
+
"gitHead": "9f71f7f82fed2a980078a96bdafd2e706f526c75\n"
|
|
121
124
|
}
|