@flighthq/easing 0.3.0-next.906.07cea63 → 0.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/dist/contract.d.ts +2 -0
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +2 -0
- package/dist/contract.js.map +1 -1
- package/dist/easeDampedSine.d.ts +34 -0
- package/dist/easeDampedSine.d.ts.map +1 -0
- package/dist/easeDampedSine.js +81 -0
- package/dist/easeDampedSine.js.map +1 -0
- package/dist/easeSteps.d.ts +2 -1
- package/dist/easeSteps.d.ts.map +1 -1
- package/dist/easeSteps.js +15 -4
- package/dist/easeSteps.js.map +1 -1
- package/dist/enableEasingGuards.d.ts +3 -0
- package/dist/enableEasingGuards.d.ts.map +1 -0
- package/dist/enableEasingGuards.js +25 -0
- package/dist/enableEasingGuards.js.map +1 -0
- 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/package.json +5 -2
- package/src/easeDampedSine.test.ts +100 -0
- package/src/easeSteps.test.ts +33 -1
- package/src/enableEasingGuards.test.ts +70 -0
package/dist/contract.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
export * from './createEasingSamples';
|
|
2
2
|
export * from './easeBack';
|
|
3
|
+
export * from './enableEasingGuards';
|
|
3
4
|
export * from './easeBounce';
|
|
4
5
|
export * from './easeCircular';
|
|
5
6
|
export * from './easeCombinators';
|
|
6
7
|
export * from './easeCubic';
|
|
7
8
|
export * from './easeCubicBezier';
|
|
9
|
+
export * from './easeDampedSine';
|
|
8
10
|
export * from './easeElastic';
|
|
9
11
|
export * from './easeExponential';
|
|
10
12
|
export * from './easeLinear';
|
package/dist/contract.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,uBAAuB,CAAC"}
|
|
1
|
+
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,YAAY,CAAC;AAC3B,cAAc,sBAAsB,CAAC;AACrC,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,uBAAuB,CAAC"}
|
package/dist/contract.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
export * from './createEasingSamples';
|
|
2
2
|
export * from './easeBack';
|
|
3
|
+
export * from './enableEasingGuards';
|
|
3
4
|
export * from './easeBounce';
|
|
4
5
|
export * from './easeCircular';
|
|
5
6
|
export * from './easeCombinators';
|
|
6
7
|
export * from './easeCubic';
|
|
7
8
|
export * from './easeCubicBezier';
|
|
9
|
+
export * from './easeDampedSine';
|
|
8
10
|
export * from './easeElastic';
|
|
9
11
|
export * from './easeExponential';
|
|
10
12
|
export * from './easeLinear';
|
package/dist/contract.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,uBAAuB,CAAC"}
|
|
1
|
+
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,YAAY,CAAC;AAC3B,cAAc,sBAAsB,CAAC;AACrC,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { EasingFunction } from '@flighthq/types/contract';
|
|
2
|
+
/**
|
|
3
|
+
* The parameterized form of `easeInElastic`: a decaying sine that winds up before departing, with the
|
|
4
|
+
* overshoot and wavelength stated rather than fixed.
|
|
5
|
+
*/
|
|
6
|
+
export declare function easeInDampedSine(amplitude: number, period: number): EasingFunction;
|
|
7
|
+
/**
|
|
8
|
+
* The parameterized form of `easeInOutElastic`: a decaying sine that winds up, crosses, and settles,
|
|
9
|
+
* with the overshoot and wavelength stated rather than fixed.
|
|
10
|
+
*/
|
|
11
|
+
export declare function easeInOutDampedSine(amplitude: number, period: number): EasingFunction;
|
|
12
|
+
/**
|
|
13
|
+
* The parameterized form of `easeOutElastic`: a decaying sine that overshoots the target and settles
|
|
14
|
+
* back onto it.
|
|
15
|
+
*
|
|
16
|
+
* `easeInElastic` / `easeOutElastic` / `easeInOutElastic` are this same published curve with the two
|
|
17
|
+
* parameters fixed. They stay the right choice when those constants suit; this family exists for a
|
|
18
|
+
* caller that states its own — an importer whose source file names an amplitude and a period, where
|
|
19
|
+
* substituting the fixed curve would be confidently wrong rather than approximately right.
|
|
20
|
+
*
|
|
21
|
+
* **Both degenerate cases are Flight's own choices, not anyone else's**, and both are stated here
|
|
22
|
+
* because they are the only places this can differ from another implementation of the same curve:
|
|
23
|
+
*
|
|
24
|
+
* - **An amplitude below 1 is raised to 1.** The phase term is `asin(1 / amplitude)`, which has no real
|
|
25
|
+
* solution below unit amplitude, so the published curve is simply not defined there. Rather than
|
|
26
|
+
* invent a shape for it we take the smallest curve the form does define, which also keeps the
|
|
27
|
+
* endpoints exact. An elastic with less than unit overshoot is a contradiction in terms.
|
|
28
|
+
* - **A non-positive period falls back to 0.4.** It divides the wave, so zero has no meaning. 0.4 is the
|
|
29
|
+
* constant our own `easeOutElastic` already uses, so a caller who states nothing gets the curve this
|
|
30
|
+
* package's preset would have given — the least surprising answer available, and one that keeps the
|
|
31
|
+
* two families consistent with each other.
|
|
32
|
+
*/
|
|
33
|
+
export declare function easeOutDampedSine(amplitude: number, period: number): EasingFunction;
|
|
34
|
+
//# sourceMappingURL=easeDampedSine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"easeDampedSine.d.ts","sourceRoot":"","sources":["../src/easeDampedSine.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE/D;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,cAAc,CASlF;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,cAAc,CAYrF;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,cAAc,CAQnF"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The parameterized form of `easeInElastic`: a decaying sine that winds up before departing, with the
|
|
3
|
+
* overshoot and wavelength stated rather than fixed.
|
|
4
|
+
*/
|
|
5
|
+
export function easeInDampedSine(amplitude, period) {
|
|
6
|
+
const wavelength = toDampedSineWavelength(period);
|
|
7
|
+
const overshoot = toDampedSineOvershoot(amplitude);
|
|
8
|
+
const phase = toDampedSinePhase(overshoot, wavelength);
|
|
9
|
+
return (t) => {
|
|
10
|
+
if (t === 0 || t === 1)
|
|
11
|
+
return t;
|
|
12
|
+
const time = t - 1;
|
|
13
|
+
return -(overshoot * Math.pow(2, 10 * time) * Math.sin(((time - phase) * TAU) / wavelength));
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The parameterized form of `easeInOutElastic`: a decaying sine that winds up, crosses, and settles,
|
|
18
|
+
* with the overshoot and wavelength stated rather than fixed.
|
|
19
|
+
*/
|
|
20
|
+
export function easeInOutDampedSine(amplitude, period) {
|
|
21
|
+
const wavelength = toDampedSineWavelength(period);
|
|
22
|
+
const overshoot = toDampedSineOvershoot(amplitude);
|
|
23
|
+
const phase = toDampedSinePhase(overshoot, wavelength);
|
|
24
|
+
return (t) => {
|
|
25
|
+
if (t === 0 || t === 1)
|
|
26
|
+
return t;
|
|
27
|
+
const time = t * 2 - 1;
|
|
28
|
+
if (time < 0) {
|
|
29
|
+
return -0.5 * overshoot * Math.pow(2, 10 * time) * Math.sin(((time - phase) * TAU) / wavelength);
|
|
30
|
+
}
|
|
31
|
+
return 0.5 * overshoot * Math.pow(2, -10 * time) * Math.sin(((time - phase) * TAU) / wavelength) + 1;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The parameterized form of `easeOutElastic`: a decaying sine that overshoots the target and settles
|
|
36
|
+
* back onto it.
|
|
37
|
+
*
|
|
38
|
+
* `easeInElastic` / `easeOutElastic` / `easeInOutElastic` are this same published curve with the two
|
|
39
|
+
* parameters fixed. They stay the right choice when those constants suit; this family exists for a
|
|
40
|
+
* caller that states its own — an importer whose source file names an amplitude and a period, where
|
|
41
|
+
* substituting the fixed curve would be confidently wrong rather than approximately right.
|
|
42
|
+
*
|
|
43
|
+
* **Both degenerate cases are Flight's own choices, not anyone else's**, and both are stated here
|
|
44
|
+
* because they are the only places this can differ from another implementation of the same curve:
|
|
45
|
+
*
|
|
46
|
+
* - **An amplitude below 1 is raised to 1.** The phase term is `asin(1 / amplitude)`, which has no real
|
|
47
|
+
* solution below unit amplitude, so the published curve is simply not defined there. Rather than
|
|
48
|
+
* invent a shape for it we take the smallest curve the form does define, which also keeps the
|
|
49
|
+
* endpoints exact. An elastic with less than unit overshoot is a contradiction in terms.
|
|
50
|
+
* - **A non-positive period falls back to 0.4.** It divides the wave, so zero has no meaning. 0.4 is the
|
|
51
|
+
* constant our own `easeOutElastic` already uses, so a caller who states nothing gets the curve this
|
|
52
|
+
* package's preset would have given — the least surprising answer available, and one that keeps the
|
|
53
|
+
* two families consistent with each other.
|
|
54
|
+
*/
|
|
55
|
+
export function easeOutDampedSine(amplitude, period) {
|
|
56
|
+
const wavelength = toDampedSineWavelength(period);
|
|
57
|
+
const overshoot = toDampedSineOvershoot(amplitude);
|
|
58
|
+
const phase = toDampedSinePhase(overshoot, wavelength);
|
|
59
|
+
return (t) => {
|
|
60
|
+
if (t === 0 || t === 1)
|
|
61
|
+
return t;
|
|
62
|
+
return overshoot * Math.pow(2, -10 * t) * Math.sin(((t - phase) * TAU) / wavelength) + 1;
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
// Where the decaying sine crosses its endpoint, which is what makes t=0 land exactly on 0.
|
|
66
|
+
function toDampedSinePhase(overshoot, wavelength) {
|
|
67
|
+
return (wavelength / TAU) * Math.asin(1 / overshoot);
|
|
68
|
+
}
|
|
69
|
+
// Below unit overshoot the phase term has no real solution, so the curve is undefined rather than
|
|
70
|
+
// merely small. Clamping is Flight's choice: the smallest defined curve beats an invented one.
|
|
71
|
+
function toDampedSineOvershoot(amplitude) {
|
|
72
|
+
return amplitude < 1 ? 1 : amplitude;
|
|
73
|
+
}
|
|
74
|
+
// A period divides the wave, so a non-positive one is meaningless. Flight's choice is the constant its
|
|
75
|
+
// own fixed elastic already uses, so the two families agree with each other.
|
|
76
|
+
function toDampedSineWavelength(period) {
|
|
77
|
+
return period > 0 ? period : DEFAULT_DAMPED_SINE_PERIOD;
|
|
78
|
+
}
|
|
79
|
+
const TAU = 2 * Math.PI;
|
|
80
|
+
const DEFAULT_DAMPED_SINE_PERIOD = 0.4;
|
|
81
|
+
//# sourceMappingURL=easeDampedSine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"easeDampedSine.js","sourceRoot":"","sources":["../src/easeDampedSine.ts"],"names":[],"mappings":"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"}
|
package/dist/easeSteps.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import type { EasingFunction, StepPosition } from '@flighthq/types/contract';
|
|
1
|
+
import type { EasingFunction, EasingStepsGuard, StepPosition } from '@flighthq/types/contract';
|
|
2
2
|
export declare function easeSteps(count: number, position?: StepPosition): EasingFunction;
|
|
3
|
+
export declare function setEasingStepsGuard(guard: EasingStepsGuard | null): void;
|
|
3
4
|
//# sourceMappingURL=easeSteps.d.ts.map
|
package/dist/easeSteps.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"easeSteps.d.ts","sourceRoot":"","sources":["../src/easeSteps.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"easeSteps.d.ts","sourceRoot":"","sources":["../src/easeSteps.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAe/F,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,GAAE,YAAwB,GAAG,cAAc,CAe3F;AAMD,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,gBAAgB,GAAG,IAAI,GAAG,IAAI,CAExE"}
|
package/dist/easeSteps.js
CHANGED
|
@@ -6,11 +6,14 @@
|
|
|
6
6
|
// jumpBoth - jump at both edges; count+1 levels from 0 to 1 inclusive.
|
|
7
7
|
// Follows the CSS Easing Level 1 step algorithm.
|
|
8
8
|
//
|
|
9
|
-
// Sharp edge: easeSteps(1, 'jumpNone') has jumps = count - 1 = 0, so the returned
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
9
|
+
// Sharp edge: easeSteps(1, 'jumpNone') has jumps = count - 1 = 0, so the returned function divides by
|
|
10
|
+
// zero and yields NaN for every input. This mirrors the CSS spec, which forbids steps(1, jump-none) for
|
|
11
|
+
// the same reason; `count >= 2` is required with 'jumpNone', while every other position is well-defined
|
|
12
|
+
// for count >= 1. The failure is SILENT — NaN propagates into whatever the easing drives — so the
|
|
13
|
+
// degenerate call routes through the guard seam below, which enableEasingGuards turns into a warning.
|
|
13
14
|
export function easeSteps(count, position = 'jumpEnd') {
|
|
15
|
+
if (position === 'jumpNone' && count < 2)
|
|
16
|
+
_stepsGuard?.(count, position);
|
|
14
17
|
const jumps = position === 'jumpNone' ? count - 1 : position === 'jumpBoth' ? count + 1 : count;
|
|
15
18
|
const startOffset = position === 'jumpStart' || position === 'jumpBoth' ? 1 : 0;
|
|
16
19
|
return (t) => {
|
|
@@ -24,4 +27,12 @@ export function easeSteps(count, position = 'jumpEnd') {
|
|
|
24
27
|
return step / jumps;
|
|
25
28
|
};
|
|
26
29
|
}
|
|
30
|
+
// The diagnostics seam for the degenerate `easeSteps` call, not the caller-facing entry point — use
|
|
31
|
+
// `enableEasingGuards`, which installs the @flighthq/log reporter through here. Null uninstalls it, and a
|
|
32
|
+
// null slot is what production sees: the check above is one comparison and the message text plus the
|
|
33
|
+
// @flighthq/log dependency live only in the separately-imported guard module.
|
|
34
|
+
export function setEasingStepsGuard(guard) {
|
|
35
|
+
_stepsGuard = guard;
|
|
36
|
+
}
|
|
37
|
+
let _stepsGuard = null;
|
|
27
38
|
//# sourceMappingURL=easeSteps.js.map
|
package/dist/easeSteps.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"easeSteps.js","sourceRoot":"","sources":["../src/easeSteps.ts"],"names":[],"mappings":"AAEA,4EAA4E;AAC5E,gEAAgE;AAChE,yEAAyE;AACzE,+EAA+E;AAC/E,uFAAuF;AACvF,0EAA0E;AAC1E,iDAAiD;AACjD,EAAE;AACF,
|
|
1
|
+
{"version":3,"file":"easeSteps.js","sourceRoot":"","sources":["../src/easeSteps.ts"],"names":[],"mappings":"AAEA,4EAA4E;AAC5E,gEAAgE;AAChE,yEAAyE;AACzE,+EAA+E;AAC/E,uFAAuF;AACvF,0EAA0E;AAC1E,iDAAiD;AACjD,EAAE;AACF,sGAAsG;AACtG,wGAAwG;AACxG,wGAAwG;AACxG,kGAAkG;AAClG,sGAAsG;AACtG,MAAM,UAAU,SAAS,CAAC,KAAa,EAAE,WAAyB,SAAS;IACzE,IAAI,QAAQ,KAAK,UAAU,IAAI,KAAK,GAAG,CAAC;QAAE,WAAW,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IACzE,MAAM,KAAK,GAAG,QAAQ,KAAK,UAAU,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,KAAK,UAAU,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAChG,MAAM,WAAW,GAAG,QAAQ,KAAK,WAAW,IAAI,QAAQ,KAAK,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAEhF,OAAO,CAAC,CAAC,EAAE,EAAE;QACX,IAAI,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,KAAK,CAAC,GAAG,WAAW,CAAC;QAC/C,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,GAAG,CAAC,EAAE,CAAC;YACvB,IAAI,GAAG,CAAC,CAAC;QACX,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,GAAG,KAAK,EAAE,CAAC;YAC3B,IAAI,GAAG,KAAK,CAAC;QACf,CAAC;QACD,OAAO,IAAI,GAAG,KAAK,CAAC;IACtB,CAAC,CAAC;AACJ,CAAC;AAED,oGAAoG;AACpG,0GAA0G;AAC1G,qGAAqG;AACrG,8EAA8E;AAC9E,MAAM,UAAU,mBAAmB,CAAC,KAA8B;IAChE,WAAW,GAAG,KAAK,CAAC;AACtB,CAAC;AAED,IAAI,WAAW,GAA4B,IAAI,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enableEasingGuards.d.ts","sourceRoot":"","sources":["../src/enableEasingGuards.ts"],"names":[],"mappings":"AAOA,wBAAgB,mBAAmB,IAAI,IAAI,CAE1C;AAWD,wBAAgB,kBAAkB,IAAI,IAAI,CAEzC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { logOnce } from '@flighthq/log/contract';
|
|
2
|
+
import { LogLevel } from '@flighthq/types/contract';
|
|
3
|
+
import { setEasingStepsGuard } from './easeSteps';
|
|
4
|
+
// Uninstalls the guard installed by enableEasingGuards.
|
|
5
|
+
export function disableEasingGuards() {
|
|
6
|
+
setEasingStepsGuard(null);
|
|
7
|
+
}
|
|
8
|
+
// Installs the caller-facing easing guard (opt-in, dev-only). This package has one silent footgun:
|
|
9
|
+
// `easeSteps(count, 'jumpNone')` with `count < 2` leaves zero jumps, so the returned function divides by
|
|
10
|
+
// zero and hands back NaN for every input. Nothing throws and nothing logs — the NaN just propagates into
|
|
11
|
+
// whatever the easing drives, which is why a comment telling callers "pass count >= 2" was not enough.
|
|
12
|
+
//
|
|
13
|
+
// @flighthq/easing is a CORE package, and core may otherwise depend only on types/core. This module is the
|
|
14
|
+
// sanctioned exception: it is separately importable and shakeable, so a build that never imports it never
|
|
15
|
+
// pulls @flighthq/log, and the layer rule's actual concern — feature weight in core's always-loaded graph —
|
|
16
|
+
// does not arise. `packages:check` enforces that the import appears in guard modules only. Idempotent.
|
|
17
|
+
export function enableEasingGuards() {
|
|
18
|
+
setEasingStepsGuard(warnOnDegenerateSteps);
|
|
19
|
+
}
|
|
20
|
+
function warnOnDegenerateSteps(count, position) {
|
|
21
|
+
logOnce('easing:degenerate-steps', LogLevel.Warn, {
|
|
22
|
+
message: `easeSteps(${count}, '${position}'): '${position}' has count - 1 jumps, so it needs count >= 2. With ${count} there are no jumps, the easing divides by zero, and every input returns NaN. Pass count >= 2, or use a position that jumps at an edge ('jumpEnd', 'jumpStart', 'jumpBoth') — those are defined for count >= 1.`,
|
|
23
|
+
}, 'easing');
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=enableEasingGuards.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enableEasingGuards.js","sourceRoot":"","sources":["../src/enableEasingGuards.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAEjD,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAElD,wDAAwD;AACxD,MAAM,UAAU,mBAAmB;IACjC,mBAAmB,CAAC,IAAI,CAAC,CAAC;AAC5B,CAAC;AAED,mGAAmG;AACnG,yGAAyG;AACzG,0GAA0G;AAC1G,uGAAuG;AACvG,EAAE;AACF,2GAA2G;AAC3G,0GAA0G;AAC1G,4GAA4G;AAC5G,uGAAuG;AACvG,MAAM,UAAU,kBAAkB;IAChC,mBAAmB,CAAC,qBAAqB,CAAC,CAAC;AAC7C,CAAC;AAED,SAAS,qBAAqB,CAAC,KAAa,EAAE,QAAsB;IAClE,OAAO,CACL,yBAAyB,EACzB,QAAQ,CAAC,IAAI,EACb;QACE,OAAO,EAAE,aAAa,KAAK,MAAM,QAAQ,QAAQ,QAAQ,uDAAuD,KAAK,iNAAiN;KACvU,EACD,QAAQ,CACT,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { createEasingSamples, easeClamp, easeClampOutput, easeCubicBezier, easeInBack, easeInBounce, easeInCircular, easeInCubic, easeInElastic, easeInExponential, easeInOutBack, easeInOutBounce, easeInOutCircular, easeInOutCubic, easeInOutElastic, easeInOutExponential, easeInOutPower, easeInOutQuadratic, easeInOutQuartic, easeInOutQuintic, easeInOutSine, easeInPower, easeInQuadratic, easeInQuartic, easeInQuintic, easeInSine, easeInvert, easeLinear, easeMirror, easeOutBack, easeOutBounce, easeOutCircular, easeOutCubic, easeOutElastic, easeOutExponential, easeOutPower, easeOutQuadratic, easeOutQuartic, easeOutQuintic, easeOutSine, easePiecewise, easeReverse, easeScaleOutput, easeSmootherstep, easeSmoothstep, easeSmoothstepRange, easeSteps, getEasingDerivative, } from './contract';
|
|
1
|
+
export { createEasingSamples, easeClamp, easeClampOutput, easeCubicBezier, easeInBack, easeInBounce, easeInCircular, easeInCubic, easeInDampedSine, easeInElastic, easeInExponential, easeInOutBack, easeInOutBounce, easeInOutCircular, easeInOutCubic, easeInOutDampedSine, easeInOutElastic, easeInOutExponential, easeInOutPower, easeInOutQuadratic, easeInOutQuartic, easeInOutQuintic, easeInOutSine, easeInPower, easeInQuadratic, easeInQuartic, easeInQuintic, easeInSine, easeInvert, easeLinear, easeMirror, easeOutBack, easeOutBounce, easeOutCircular, easeOutCubic, easeOutDampedSine, easeOutElastic, easeOutExponential, easeOutPower, easeOutQuadratic, easeOutQuartic, easeOutQuintic, easeOutSine, easePiecewise, easeReverse, easeScaleOutput, easeSmootherstep, easeSmoothstep, easeSmoothstepRange, easeSteps, getEasingDerivative, } from './contract';
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,SAAS,EACT,eAAe,EACf,eAAe,EACf,UAAU,EACV,YAAY,EACZ,cAAc,EACd,WAAW,EACX,aAAa,EACb,iBAAiB,EACjB,aAAa,EACb,eAAe,EACf,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EAChB,oBAAoB,EACpB,cAAc,EACd,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,EAChB,aAAa,EACb,WAAW,EACX,eAAe,EACf,aAAa,EACb,aAAa,EACb,UAAU,EACV,UAAU,EACV,UAAU,EACV,UAAU,EACV,WAAW,EACX,aAAa,EACb,eAAe,EACf,YAAY,EACZ,cAAc,EACd,kBAAkB,EAClB,YAAY,EACZ,gBAAgB,EAChB,cAAc,EACd,cAAc,EACd,WAAW,EACX,aAAa,EACb,WAAW,EACX,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,mBAAmB,EACnB,SAAS,EACT,mBAAmB,GACpB,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,SAAS,EACT,eAAe,EACf,eAAe,EACf,UAAU,EACV,YAAY,EACZ,cAAc,EACd,WAAW,EACX,gBAAgB,EAChB,aAAa,EACb,iBAAiB,EACjB,aAAa,EACb,eAAe,EACf,iBAAiB,EACjB,cAAc,EACd,mBAAmB,EACnB,gBAAgB,EAChB,oBAAoB,EACpB,cAAc,EACd,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,EAChB,aAAa,EACb,WAAW,EACX,eAAe,EACf,aAAa,EACb,aAAa,EACb,UAAU,EACV,UAAU,EACV,UAAU,EACV,UAAU,EACV,WAAW,EACX,aAAa,EACb,eAAe,EACf,YAAY,EACZ,iBAAiB,EACjB,cAAc,EACd,kBAAkB,EAClB,YAAY,EACZ,gBAAgB,EAChB,cAAc,EACd,cAAc,EACd,WAAW,EACX,aAAa,EACb,WAAW,EACX,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,mBAAmB,EACnB,SAAS,EACT,mBAAmB,GACpB,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { createEasingSamples, easeClamp, easeClampOutput, easeCubicBezier, easeInBack, easeInBounce, easeInCircular, easeInCubic, easeInElastic, easeInExponential, easeInOutBack, easeInOutBounce, easeInOutCircular, easeInOutCubic, easeInOutElastic, easeInOutExponential, easeInOutPower, easeInOutQuadratic, easeInOutQuartic, easeInOutQuintic, easeInOutSine, easeInPower, easeInQuadratic, easeInQuartic, easeInQuintic, easeInSine, easeInvert, easeLinear, easeMirror, easeOutBack, easeOutBounce, easeOutCircular, easeOutCubic, easeOutElastic, easeOutExponential, easeOutPower, easeOutQuadratic, easeOutQuartic, easeOutQuintic, easeOutSine, easePiecewise, easeReverse, easeScaleOutput, easeSmootherstep, easeSmoothstep, easeSmoothstepRange, easeSteps, getEasingDerivative, } from './contract';
|
|
1
|
+
export { createEasingSamples, easeClamp, easeClampOutput, easeCubicBezier, easeInBack, easeInBounce, easeInCircular, easeInCubic, easeInDampedSine, easeInElastic, easeInExponential, easeInOutBack, easeInOutBounce, easeInOutCircular, easeInOutCubic, easeInOutDampedSine, easeInOutElastic, easeInOutExponential, easeInOutPower, easeInOutQuadratic, easeInOutQuartic, easeInOutQuintic, easeInOutSine, easeInPower, easeInQuadratic, easeInQuartic, easeInQuintic, easeInSine, easeInvert, easeLinear, easeMirror, easeOutBack, easeOutBounce, easeOutCircular, easeOutCubic, easeOutDampedSine, easeOutElastic, easeOutExponential, easeOutPower, easeOutQuadratic, easeOutQuartic, easeOutQuintic, easeOutSine, easePiecewise, easeReverse, easeScaleOutput, easeSmootherstep, easeSmoothstep, easeSmoothstepRange, easeSteps, getEasingDerivative, } from './contract';
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,SAAS,EACT,eAAe,EACf,eAAe,EACf,UAAU,EACV,YAAY,EACZ,cAAc,EACd,WAAW,EACX,aAAa,EACb,iBAAiB,EACjB,aAAa,EACb,eAAe,EACf,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EAChB,oBAAoB,EACpB,cAAc,EACd,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,EAChB,aAAa,EACb,WAAW,EACX,eAAe,EACf,aAAa,EACb,aAAa,EACb,UAAU,EACV,UAAU,EACV,UAAU,EACV,UAAU,EACV,WAAW,EACX,aAAa,EACb,eAAe,EACf,YAAY,EACZ,cAAc,EACd,kBAAkB,EAClB,YAAY,EACZ,gBAAgB,EAChB,cAAc,EACd,cAAc,EACd,WAAW,EACX,aAAa,EACb,WAAW,EACX,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,mBAAmB,EACnB,SAAS,EACT,mBAAmB,GACpB,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,SAAS,EACT,eAAe,EACf,eAAe,EACf,UAAU,EACV,YAAY,EACZ,cAAc,EACd,WAAW,EACX,gBAAgB,EAChB,aAAa,EACb,iBAAiB,EACjB,aAAa,EACb,eAAe,EACf,iBAAiB,EACjB,cAAc,EACd,mBAAmB,EACnB,gBAAgB,EAChB,oBAAoB,EACpB,cAAc,EACd,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,EAChB,aAAa,EACb,WAAW,EACX,eAAe,EACf,aAAa,EACb,aAAa,EACb,UAAU,EACV,UAAU,EACV,UAAU,EACV,UAAU,EACV,WAAW,EACX,aAAa,EACb,eAAe,EACf,YAAY,EACZ,iBAAiB,EACjB,cAAc,EACd,kBAAkB,EAClB,YAAY,EACZ,gBAAgB,EAChB,cAAc,EACd,cAAc,EACd,WAAW,EACX,aAAa,EACb,WAAW,EACX,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,mBAAmB,EACnB,SAAS,EACT,mBAAmB,GACpB,MAAM,YAAY,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flighthq/easing",
|
|
3
|
-
"version": "0.3.0
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"author": "Joshua Granick and other contributors",
|
|
5
|
+
"license": "MIT",
|
|
4
6
|
"repository": {
|
|
5
7
|
"type": "git",
|
|
6
8
|
"url": "https://github.com/flighthq/flight.git",
|
|
@@ -36,7 +38,8 @@
|
|
|
36
38
|
"clean:dist": "tsx ../../scripts/clean-package-dist.ts"
|
|
37
39
|
},
|
|
38
40
|
"dependencies": {
|
|
39
|
-
"@flighthq/
|
|
41
|
+
"@flighthq/log": "0.3.0",
|
|
42
|
+
"@flighthq/types": "0.3.0"
|
|
40
43
|
},
|
|
41
44
|
"devDependencies": {
|
|
42
45
|
"typescript": "^5.3.0"
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { easeInDampedSine, easeInOutDampedSine, easeOutDampedSine } from './easeDampedSine';
|
|
2
|
+
import { easeInElastic, easeInOutElastic, easeOutElastic } from './easeElastic';
|
|
3
|
+
|
|
4
|
+
describe('easeInDampedSine', () => {
|
|
5
|
+
it('returns 0 at t=0 and 1 at t=1', () => {
|
|
6
|
+
const ease = easeInDampedSine(1, 0.4);
|
|
7
|
+
|
|
8
|
+
expect(ease(0)).toBe(0);
|
|
9
|
+
expect(ease(1)).toBe(1);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it('winds up below 0 before departing', () => {
|
|
13
|
+
expect(easeInDampedSine(1, 0.4)(0.8)).toBeLessThan(0);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('matches the fixed easeInElastic at the constants that one hardcodes', () => {
|
|
17
|
+
// The fixed curve is this one at amplitude 1, period 0.4 — the check that the general form is
|
|
18
|
+
// right rather than merely plausible.
|
|
19
|
+
const ease = easeInDampedSine(1, 0.4);
|
|
20
|
+
for (const t of [0.1, 0.25, 0.4, 0.6, 0.75, 0.9]) {
|
|
21
|
+
expect(ease(t)).toBeCloseTo(easeInElastic(t), 10);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
describe('easeInOutDampedSine', () => {
|
|
27
|
+
it('returns 0 at t=0 and 1 at t=1', () => {
|
|
28
|
+
const ease = easeInOutDampedSine(1, 0.45);
|
|
29
|
+
|
|
30
|
+
expect(ease(0)).toBe(0);
|
|
31
|
+
expect(ease(1)).toBe(1);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('matches the fixed easeInOutElastic at the constants that one hardcodes', () => {
|
|
35
|
+
const ease = easeInOutDampedSine(1, 0.45);
|
|
36
|
+
for (const t of [0.1, 0.3, 0.5, 0.7, 0.9]) {
|
|
37
|
+
expect(ease(t)).toBeCloseTo(easeInOutElastic(t), 10);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
describe('easeOutDampedSine', () => {
|
|
43
|
+
it('returns 0 at t=0 and 1 at t=1', () => {
|
|
44
|
+
const ease = easeOutDampedSine(1, 0.4);
|
|
45
|
+
|
|
46
|
+
expect(ease(0)).toBe(0);
|
|
47
|
+
expect(ease(1)).toBe(1);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('overshoots past 1 near the start', () => {
|
|
51
|
+
expect(easeOutDampedSine(1, 0.4)(0.6)).toBeGreaterThan(1);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('matches the fixed easeOutElastic at the constants that one hardcodes', () => {
|
|
55
|
+
const ease = easeOutDampedSine(1, 0.4);
|
|
56
|
+
for (const t of [0.1, 0.25, 0.4, 0.6, 0.75, 0.9]) {
|
|
57
|
+
expect(ease(t)).toBeCloseTo(easeOutElastic(t), 10);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('separates the curves that the fixed form collapses together', () => {
|
|
62
|
+
// The whole reason this family exists: a source stating its own period gets a materially
|
|
63
|
+
// different curve, so substituting the fixed one is wrong rather than approximate. Measured as
|
|
64
|
+
// the widest gap across the curve — any single sample can land where two curves happen to cross.
|
|
65
|
+
const wide = easeOutDampedSine(1, 0.9);
|
|
66
|
+
const narrow = easeOutDampedSine(1, 0.2);
|
|
67
|
+
const widest = Math.max(
|
|
68
|
+
...Array.from({ length: 99 }, (_, index) => Math.abs(wide((index + 1) / 100) - narrow((index + 1) / 100))),
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
expect(widest).toBeGreaterThan(0.5);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('overshoots further as amplitude grows', () => {
|
|
75
|
+
const peak = (amplitude: number): number =>
|
|
76
|
+
Math.max(...Array.from({ length: 99 }, (_, index) => easeOutDampedSine(amplitude, 0.4)((index + 1) / 100)));
|
|
77
|
+
|
|
78
|
+
expect(peak(3)).toBeGreaterThan(peak(1));
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('raises an amplitude below 1 to the smallest defined curve', () => {
|
|
82
|
+
// The phase term is asin(1 / amplitude), which has no real solution below unit amplitude, so the
|
|
83
|
+
// curve is undefined there rather than merely small. Flight clamps rather than inventing a shape.
|
|
84
|
+
const clamped = easeOutDampedSine(0.5, 0.4);
|
|
85
|
+
const unit = easeOutDampedSine(1, 0.4);
|
|
86
|
+
|
|
87
|
+
for (const t of [0.2, 0.5, 0.8]) expect(clamped(t)).toBeCloseTo(unit(t), 10);
|
|
88
|
+
expect(Number.isFinite(clamped(0.3))).toBe(true);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('falls back to this package own fixed period when the period is not positive', () => {
|
|
92
|
+
// A period divides the wave, so zero has no meaning. Flight's choice is 0.4 — the constant
|
|
93
|
+
// easeOutElastic already uses — so the parameterized and fixed families agree with each other.
|
|
94
|
+
for (const period of [0, -1]) {
|
|
95
|
+
const ease = easeOutDampedSine(1, period);
|
|
96
|
+
expect(Number.isFinite(ease(0.5))).toBe(true);
|
|
97
|
+
expect(ease(0.5)).toBeCloseTo(easeOutDampedSine(1, 0.4)(0.5), 10);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
});
|
package/src/easeSteps.test.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { StepPosition } from '@flighthq/types/contract';
|
|
2
|
+
|
|
3
|
+
import { easeSteps, setEasingStepsGuard } from './easeSteps';
|
|
2
4
|
|
|
3
5
|
describe('easeSteps', () => {
|
|
4
6
|
it('jumpEnd holds at 0 first and reaches 1 only at t=1', () => {
|
|
@@ -63,3 +65,33 @@ describe('easeSteps', () => {
|
|
|
63
65
|
}
|
|
64
66
|
});
|
|
65
67
|
});
|
|
68
|
+
|
|
69
|
+
describe('setEasingStepsGuard', () => {
|
|
70
|
+
it('reports the degenerate jumpNone call that silently returns NaN', () => {
|
|
71
|
+
const seen: [number, StepPosition][] = [];
|
|
72
|
+
setEasingStepsGuard((count, position) => seen.push([count, position]));
|
|
73
|
+
try {
|
|
74
|
+
// The failure being reported: one step with no edge jump leaves zero jumps to divide by.
|
|
75
|
+
expect(Number.isNaN(easeSteps(1, 'jumpNone')(0.5))).toBe(true);
|
|
76
|
+
} finally {
|
|
77
|
+
setEasingStepsGuard(null);
|
|
78
|
+
}
|
|
79
|
+
expect(seen).toEqual([[1, 'jumpNone']]);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('stays silent for well-defined calls, and once uninstalled', () => {
|
|
83
|
+
const seen: number[] = [];
|
|
84
|
+
setEasingStepsGuard((count) => seen.push(count));
|
|
85
|
+
try {
|
|
86
|
+
easeSteps(2, 'jumpNone')(0.5); // count >= 2 is the documented minimum for jumpNone
|
|
87
|
+
easeSteps(1, 'jumpEnd')(0.5); // edge-jumping positions are defined for count >= 1
|
|
88
|
+
easeSteps(1, 'jumpBoth')(0.5);
|
|
89
|
+
} finally {
|
|
90
|
+
setEasingStepsGuard(null);
|
|
91
|
+
}
|
|
92
|
+
expect(seen).toEqual([]);
|
|
93
|
+
// Uninstalled: the degenerate call still returns NaN, but nothing is reported.
|
|
94
|
+
easeSteps(1, 'jumpNone')(0.5);
|
|
95
|
+
expect(seen).toEqual([]);
|
|
96
|
+
});
|
|
97
|
+
});
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { addLogSink, createMemoryLogSink, getMemoryLogSinkEntries, removeLogSink } from '@flighthq/log/contract';
|
|
2
|
+
import type { LogEntry } from '@flighthq/types/contract';
|
|
3
|
+
import { describe, expect, it } from 'vitest';
|
|
4
|
+
|
|
5
|
+
import { easeSteps } from './easeSteps';
|
|
6
|
+
import { disableEasingGuards, enableEasingGuards } from './enableEasingGuards';
|
|
7
|
+
|
|
8
|
+
function captureLog(run: () => void): readonly LogEntry[] {
|
|
9
|
+
const sink = createMemoryLogSink(8);
|
|
10
|
+
addLogSink(sink.sink);
|
|
11
|
+
try {
|
|
12
|
+
run();
|
|
13
|
+
return getMemoryLogSinkEntries(sink);
|
|
14
|
+
} finally {
|
|
15
|
+
removeLogSink(sink.sink);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function messageOf(entry: Readonly<LogEntry>): string {
|
|
20
|
+
const data = entry.data;
|
|
21
|
+
return typeof data === 'string' ? data : String(data.message);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
describe('disableEasingGuards', () => {
|
|
25
|
+
it('uninstalls the guard, returning the degenerate call to silence', () => {
|
|
26
|
+
const entries = captureLog(() => {
|
|
27
|
+
enableEasingGuards();
|
|
28
|
+
disableEasingGuards();
|
|
29
|
+
// Still NaN — disabling removes the reporting, not the sharp edge.
|
|
30
|
+
expect(Number.isNaN(easeSteps(1, 'jumpNone')(0.5))).toBe(true);
|
|
31
|
+
});
|
|
32
|
+
expect(entries.length).toBe(0);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe('enableEasingGuards', () => {
|
|
37
|
+
it('WARNS on the degenerate jumpNone step count that silently returns NaN', () => {
|
|
38
|
+
const entries = captureLog(() => {
|
|
39
|
+
enableEasingGuards();
|
|
40
|
+
try {
|
|
41
|
+
expect(Number.isNaN(easeSteps(1, 'jumpNone')(0.5))).toBe(true);
|
|
42
|
+
} finally {
|
|
43
|
+
disableEasingGuards();
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
expect(entries.length).toBe(1);
|
|
47
|
+
expect(messageOf(entries[0])).toContain('count >= 2');
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('stays SILENT for well-defined calls, and without the guard at all', () => {
|
|
51
|
+
const guarded = captureLog(() => {
|
|
52
|
+
enableEasingGuards();
|
|
53
|
+
try {
|
|
54
|
+
easeSteps(2, 'jumpNone')(0.5);
|
|
55
|
+
easeSteps(1, 'jumpEnd')(0.5);
|
|
56
|
+
easeSteps(1, 'jumpStart')(0.5);
|
|
57
|
+
easeSteps(1, 'jumpBoth')(0.5);
|
|
58
|
+
} finally {
|
|
59
|
+
disableEasingGuards();
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
expect(guarded.length).toBe(0);
|
|
63
|
+
|
|
64
|
+
// Production default: still NaN, but nothing is logged — the guard is opt-in.
|
|
65
|
+
const unguarded = captureLog(() => {
|
|
66
|
+
expect(Number.isNaN(easeSteps(1, 'jumpNone')(0.5))).toBe(true);
|
|
67
|
+
});
|
|
68
|
+
expect(unguarded.length).toBe(0);
|
|
69
|
+
});
|
|
70
|
+
});
|