@flighthq/easing 0.3.0-next.1783.cd11ab1 → 0.3.0-next.1848.58f06fb
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 +1 -0
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +1 -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/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 +3 -3
- package/src/easeDampedSine.test.ts +100 -0
package/dist/contract.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export * from './easeCircular';
|
|
|
6
6
|
export * from './easeCombinators';
|
|
7
7
|
export * from './easeCubic';
|
|
8
8
|
export * from './easeCubicBezier';
|
|
9
|
+
export * from './easeDampedSine';
|
|
9
10
|
export * from './easeElastic';
|
|
10
11
|
export * from './easeExponential';
|
|
11
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,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,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
|
@@ -6,6 +6,7 @@ export * from './easeCircular';
|
|
|
6
6
|
export * from './easeCombinators';
|
|
7
7
|
export * from './easeCubic';
|
|
8
8
|
export * from './easeCubicBezier';
|
|
9
|
+
export * from './easeDampedSine';
|
|
9
10
|
export * from './easeElastic';
|
|
10
11
|
export * from './easeExponential';
|
|
11
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,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,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":"AAEA;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,SAAiB,EAAE,MAAc;IAChE,MAAM,UAAU,GAAG,sBAAsB,CAAC,MAAM,CAAC,CAAC;IAClD,MAAM,SAAS,GAAG,qBAAqB,CAAC,SAAS,CAAC,CAAC;IACnD,MAAM,KAAK,GAAG,iBAAiB,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;IACvD,OAAO,CAAC,CAAC,EAAE,EAAE;QACX,IAAI,CAAC,KAAK,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MAAM,0BAA0B,GAAG,GAAG,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,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flighthq/easing",
|
|
3
|
-
"version": "0.3.0-next.
|
|
3
|
+
"version": "0.3.0-next.1848.58f06fb",
|
|
4
4
|
"author": "Joshua Granick and other contributors",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"clean:dist": "tsx ../../scripts/clean-package-dist.ts"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@flighthq/log": "0.3.0-next.
|
|
42
|
-
"@flighthq/types": "0.3.0-next.
|
|
41
|
+
"@flighthq/log": "0.3.0-next.1848.58f06fb",
|
|
42
|
+
"@flighthq/types": "0.3.0-next.1848.58f06fb"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
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
|
+
});
|