tensum 0.1.0 → 0.2.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 +38 -0
- package/README.md +54 -21
- package/dist/css-linear.d.ts +7 -0
- package/dist/css-linear.d.ts.map +1 -1
- package/dist/css-linear.js +88 -35
- package/dist/css-linear.js.map +1 -1
- package/dist/gsap/plugin.d.ts +8 -5
- package/dist/gsap/plugin.d.ts.map +1 -1
- package/dist/gsap/plugin.js +31 -31
- package/dist/gsap/plugin.js.map +1 -1
- package/dist/gsap/spring-to.d.ts +1 -0
- package/dist/gsap/spring-to.d.ts.map +1 -1
- package/dist/gsap/spring-to.js +4 -4
- package/dist/gsap/spring-to.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/support/additive-spring-value.d.ts +2 -3
- package/dist/support/additive-spring-value.d.ts.map +1 -1
- package/dist/support/additive-spring-value.js +11 -6
- package/dist/support/additive-spring-value.js.map +1 -1
- package/dist/support/spring-value.d.ts.map +1 -1
- package/dist/support/spring-value.js +1 -2
- package/dist/support/spring-value.js.map +1 -1
- package/package.json +2 -2
- package/src/css-linear.ts +130 -39
- package/src/gsap/plugin.ts +33 -39
- package/src/gsap/spring-to.ts +11 -3
- package/src/index.ts +1 -4
- package/src/support/additive-spring-value.ts +18 -10
- package/src/support/spring-value.ts +1 -4
|
@@ -1,24 +1,22 @@
|
|
|
1
1
|
import { springParameters } from '../parameters.js';
|
|
2
2
|
import { resolveSettlingOptions } from '../settling.js';
|
|
3
|
-
import { createSpring
|
|
3
|
+
import { createSpring } from '../spring.js';
|
|
4
4
|
import type {
|
|
5
5
|
SpringParameters,
|
|
6
6
|
SpringSettleInput,
|
|
7
7
|
SpringSolution,
|
|
8
8
|
SpringState,
|
|
9
|
-
SpringTimingInput,
|
|
10
9
|
} from '../types.js';
|
|
11
10
|
import type { FrameDriver } from './spring-value.js';
|
|
12
11
|
|
|
13
12
|
export interface AdditiveSpringOptions {
|
|
13
|
+
/** Shared physical settlement configuration for new contributions. */
|
|
14
14
|
settle?: SpringSettleInput;
|
|
15
|
-
timing?: SpringTimingInput;
|
|
16
15
|
}
|
|
17
16
|
|
|
18
17
|
export interface AdditiveSpringContributionOptions {
|
|
19
18
|
parameters?: SpringParameters;
|
|
20
19
|
settle?: SpringSettleInput;
|
|
21
|
-
timing?: SpringTimingInput;
|
|
22
20
|
velocity?: number;
|
|
23
21
|
}
|
|
24
22
|
|
|
@@ -60,6 +58,20 @@ function assertFinite(name: string, value: number): void {
|
|
|
60
58
|
}
|
|
61
59
|
}
|
|
62
60
|
|
|
61
|
+
function validateOptions(
|
|
62
|
+
value: unknown,
|
|
63
|
+
context: 'additive spring options' | 'additive contribution options',
|
|
64
|
+
): void {
|
|
65
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
66
|
+
throw new TypeError(`${context} must be an object when provided`);
|
|
67
|
+
}
|
|
68
|
+
if (Object.hasOwn(value, 'timing')) {
|
|
69
|
+
throw new TypeError(
|
|
70
|
+
`${context} does not support timing because additive values have no logical-completion phase`,
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
63
75
|
/**
|
|
64
76
|
* Composes overlapping spring effects as independent additive contributions.
|
|
65
77
|
* Use createSpringValue when each new target should replace the previous one.
|
|
@@ -71,9 +83,9 @@ export function createAdditiveSpringValue(
|
|
|
71
83
|
options: AdditiveSpringOptions = {},
|
|
72
84
|
): AdditiveSpringValue {
|
|
73
85
|
assertFinite('initialValue', initialValue);
|
|
86
|
+
validateOptions(options, 'additive spring options');
|
|
74
87
|
const defaultParameters = springParameters.fromPhysics(parameters);
|
|
75
88
|
const defaultSettling = resolveSettlingOptions(options.settle);
|
|
76
|
-
const defaultTiming = resolveSpringTimingInput(options.timing);
|
|
77
89
|
const listeners: Record<AdditiveSpringEvent, Set<AdditiveSpringListener>> = {
|
|
78
90
|
change: new Set(),
|
|
79
91
|
settle: new Set(),
|
|
@@ -223,6 +235,7 @@ export function createAdditiveSpringValue(
|
|
|
223
235
|
contributionOptions: AdditiveSpringContributionOptions = {},
|
|
224
236
|
): number {
|
|
225
237
|
if (destroyed) throw new Error('additive spring value has been destroyed');
|
|
238
|
+
validateOptions(contributionOptions, 'additive contribution options');
|
|
226
239
|
assertFinite('delta', delta);
|
|
227
240
|
const initialVelocity =
|
|
228
241
|
contributionOptions.velocity === undefined
|
|
@@ -244,10 +257,6 @@ export function createAdditiveSpringValue(
|
|
|
244
257
|
refinementIterations: defaultSettling.refinementIterations,
|
|
245
258
|
...contributionOptions.settle,
|
|
246
259
|
};
|
|
247
|
-
const timing =
|
|
248
|
-
contributionOptions.timing === undefined
|
|
249
|
-
? defaultTiming
|
|
250
|
-
: resolveSpringTimingInput(contributionOptions.timing);
|
|
251
260
|
const time = sampleNow();
|
|
252
261
|
assertFinite('target', aggregateTarget() + delta);
|
|
253
262
|
const solution = createSpring({
|
|
@@ -256,7 +265,6 @@ export function createAdditiveSpringValue(
|
|
|
256
265
|
velocity: initialVelocity,
|
|
257
266
|
...contributionParameters,
|
|
258
267
|
settle,
|
|
259
|
-
...(timing === undefined ? {} : { timing }),
|
|
260
268
|
});
|
|
261
269
|
const id = nextId;
|
|
262
270
|
nextId += 1;
|
|
@@ -166,10 +166,7 @@ export function createSpringValue(
|
|
|
166
166
|
active = undefined;
|
|
167
167
|
write(solution.initialState.target, 0);
|
|
168
168
|
if (revision !== sampledRevision) return;
|
|
169
|
-
if (
|
|
170
|
-
!sampled.logicalComplete &&
|
|
171
|
-
elapsed >= sampled.logicalDuration
|
|
172
|
-
) {
|
|
169
|
+
if (!sampled.logicalComplete) {
|
|
173
170
|
sampled.logicalComplete = true;
|
|
174
171
|
emit('logicalComplete');
|
|
175
172
|
if (revision !== sampledRevision) return;
|