@vived/core 1.0.1 → 1.1.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/cjs/Utilities/LengthConverters.js +21 -0
- package/dist/cjs/Utilities/LengthConverters.js.map +1 -0
- package/dist/cjs/Utilities/LengthConverters.test.js +24 -0
- package/dist/cjs/Utilities/LengthConverters.test.js.map +1 -0
- package/dist/cjs/Utilities/LerpNumber.js +85 -0
- package/dist/cjs/Utilities/LerpNumber.js.map +1 -0
- package/dist/cjs/Utilities/LerpNumber.test.js +90 -0
- package/dist/cjs/Utilities/LerpNumber.test.js.map +1 -0
- package/dist/cjs/Utilities/degreesToRadians.js +7 -0
- package/dist/cjs/Utilities/degreesToRadians.js.map +1 -0
- package/dist/cjs/Utilities/degreesToRadians.test.js +9 -0
- package/dist/cjs/Utilities/degreesToRadians.test.js.map +1 -0
- package/dist/cjs/Utilities/easeFunctions.js +208 -0
- package/dist/cjs/Utilities/easeFunctions.js.map +1 -0
- package/dist/cjs/Utilities/easeFunctions.test.js +209 -0
- package/dist/cjs/Utilities/easeFunctions.test.js.map +1 -0
- package/dist/cjs/Utilities/generateUniqueID.js +8 -0
- package/dist/cjs/Utilities/generateUniqueID.js.map +1 -0
- package/dist/cjs/Utilities/index.js +22 -0
- package/dist/cjs/Utilities/index.js.map +1 -0
- package/dist/cjs/Utilities/interpolateNumber.js +18 -0
- package/dist/cjs/Utilities/interpolateNumber.js.map +1 -0
- package/dist/cjs/Utilities/interpolateNumber.test.js +26 -0
- package/dist/cjs/Utilities/interpolateNumber.test.js.map +1 -0
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/Utilities/LengthConverters.js +15 -0
- package/dist/esm/Utilities/LengthConverters.js.map +1 -0
- package/dist/esm/Utilities/LengthConverters.test.js +22 -0
- package/dist/esm/Utilities/LengthConverters.test.js.map +1 -0
- package/dist/esm/Utilities/LerpNumber.js +81 -0
- package/dist/esm/Utilities/LerpNumber.js.map +1 -0
- package/dist/esm/Utilities/LerpNumber.test.js +88 -0
- package/dist/esm/Utilities/LerpNumber.test.js.map +1 -0
- package/dist/esm/Utilities/degreesToRadians.js +4 -0
- package/dist/esm/Utilities/degreesToRadians.js.map +1 -0
- package/dist/esm/Utilities/degreesToRadians.test.js +7 -0
- package/dist/esm/Utilities/degreesToRadians.test.js.map +1 -0
- package/dist/esm/Utilities/easeFunctions.js +183 -0
- package/dist/esm/Utilities/easeFunctions.js.map +1 -0
- package/dist/esm/Utilities/easeFunctions.test.js +207 -0
- package/dist/esm/Utilities/easeFunctions.test.js.map +1 -0
- package/dist/esm/Utilities/generateUniqueID.js +5 -0
- package/dist/esm/Utilities/generateUniqueID.js.map +1 -0
- package/dist/esm/Utilities/index.js +6 -0
- package/dist/esm/Utilities/index.js.map +1 -0
- package/dist/esm/Utilities/interpolateNumber.js +15 -0
- package/dist/esm/Utilities/interpolateNumber.js.map +1 -0
- package/dist/esm/Utilities/interpolateNumber.test.js +24 -0
- package/dist/esm/Utilities/interpolateNumber.test.js.map +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/types/Utilities/LengthConverters.d.ts +5 -0
- package/dist/types/Utilities/LengthConverters.d.ts.map +1 -0
- package/dist/types/Utilities/LengthConverters.test.d.ts +2 -0
- package/dist/types/Utilities/LengthConverters.test.d.ts.map +1 -0
- package/dist/types/Utilities/LerpNumber.d.ts +57 -0
- package/dist/types/Utilities/LerpNumber.d.ts.map +1 -0
- package/dist/types/Utilities/LerpNumber.test.d.ts +2 -0
- package/dist/types/Utilities/LerpNumber.test.d.ts.map +1 -0
- package/dist/types/Utilities/degreesToRadians.d.ts +2 -0
- package/dist/types/Utilities/degreesToRadians.d.ts.map +1 -0
- package/dist/types/Utilities/degreesToRadians.test.d.ts +2 -0
- package/dist/types/Utilities/degreesToRadians.test.d.ts.map +1 -0
- package/dist/types/Utilities/easeFunctions.d.ts +24 -0
- package/dist/types/Utilities/easeFunctions.d.ts.map +1 -0
- package/dist/types/Utilities/easeFunctions.test.d.ts +2 -0
- package/dist/types/Utilities/easeFunctions.test.d.ts.map +1 -0
- package/dist/types/Utilities/generateUniqueID.d.ts +2 -0
- package/dist/types/Utilities/generateUniqueID.d.ts.map +1 -0
- package/dist/types/Utilities/index.d.ts +6 -0
- package/dist/types/Utilities/index.d.ts.map +1 -0
- package/dist/types/Utilities/interpolateNumber.d.ts +2 -0
- package/dist/types/Utilities/interpolateNumber.d.ts.map +1 -0
- package/dist/types/Utilities/interpolateNumber.test.d.ts +2 -0
- package/dist/types/Utilities/interpolateNumber.test.d.ts.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +6 -2
- package/src/Utilities/LengthConverters.test.ts +30 -0
- package/src/Utilities/LengthConverters.ts +18 -0
- package/src/Utilities/LerpNumber.test.ts +109 -0
- package/src/Utilities/LerpNumber.ts +109 -0
- package/src/Utilities/degreesToRadians.test.ts +8 -0
- package/src/Utilities/degreesToRadians.ts +3 -0
- package/src/Utilities/easeFunctions.test.ts +251 -0
- package/src/Utilities/easeFunctions.ts +180 -0
- package/src/Utilities/generateUniqueID.ts +5 -0
- package/src/Utilities/index.ts +6 -0
- package/src/Utilities/interpolateNumber.test.ts +28 -0
- package/src/Utilities/interpolateNumber.ts +21 -0
- package/src/index.ts +1 -0
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { EaseFn } from "../Types";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
export const easeLinear: EaseFn = (x: number): number => {
|
|
5
|
+
if (x <= 0) return 0;
|
|
6
|
+
if (x >= 1) return 1;
|
|
7
|
+
|
|
8
|
+
return x;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const quadIn: EaseFn = (x: number) => {
|
|
12
|
+
if (x <= 0) return 0;
|
|
13
|
+
if (x >= 1) return 1;
|
|
14
|
+
|
|
15
|
+
return x * x;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const quadOut: EaseFn = (x: number) => {
|
|
19
|
+
if (x <= 0) return 0;
|
|
20
|
+
if (x >= 1) return 1;
|
|
21
|
+
|
|
22
|
+
return x * (2 - x);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const quadInOut: EaseFn = (x: number): number => {
|
|
26
|
+
if (x <= 0) return 0;
|
|
27
|
+
if (x >= 1) return 1;
|
|
28
|
+
|
|
29
|
+
if (x < 0.5) {
|
|
30
|
+
return 2 * x * x;
|
|
31
|
+
} else {
|
|
32
|
+
return 1 - Math.pow(-2 * x + 2, 2) / 2;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export const cubicIn: EaseFn = (x: number): number => {
|
|
37
|
+
if (x <= 0) return 0;
|
|
38
|
+
if (x >= 1) return 1;
|
|
39
|
+
|
|
40
|
+
return x * x * x;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const cubicOut: EaseFn = (x: number): number => {
|
|
44
|
+
if (x <= 0) return 0;
|
|
45
|
+
if (x >= 1) return 1;
|
|
46
|
+
|
|
47
|
+
return --x * x * x + 1;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export const cubicInOut: EaseFn = (x: number): number => {
|
|
51
|
+
if (x <= 0) return 0;
|
|
52
|
+
if (x >= 1) return 1;
|
|
53
|
+
|
|
54
|
+
x *= 2;
|
|
55
|
+
|
|
56
|
+
if (x <= 1) {
|
|
57
|
+
return (x * x * x) / 2;
|
|
58
|
+
} else {
|
|
59
|
+
return ((x -= 2) * x * x + 2) / 2;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export const expoIn: EaseFn = (x: number): number => {
|
|
64
|
+
if (x <= 0) return 0;
|
|
65
|
+
if (x >= 1) return 1;
|
|
66
|
+
|
|
67
|
+
return Math.pow(2, 10 * x - 10);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export const expoOut: EaseFn = (x: number): number => {
|
|
71
|
+
if (x <= 0) return 0;
|
|
72
|
+
if (x >= 1) return 1;
|
|
73
|
+
|
|
74
|
+
return 1 - Math.pow(2, -10 * x);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export const expoInOut: EaseFn = (x: number): number => {
|
|
78
|
+
if (x <= 0) return 0;
|
|
79
|
+
if (x >= 1) return 1;
|
|
80
|
+
|
|
81
|
+
return x < 0.5
|
|
82
|
+
? Math.pow(2, 20 * x - 10) / 2
|
|
83
|
+
: (2 - Math.pow(2, -20 * x + 10)) / 2;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export const sinIn: EaseFn = (x: number): number => {
|
|
87
|
+
if (x <= 0) return 0;
|
|
88
|
+
if (x >= 1) return 1;
|
|
89
|
+
|
|
90
|
+
return 1 - Math.cos((x * Math.PI) / 2);
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
export const sinOut: EaseFn = (x: number): number => {
|
|
94
|
+
if (x <= 0) return 0;
|
|
95
|
+
if (x >= 1) return 1;
|
|
96
|
+
|
|
97
|
+
return Math.sin((x * Math.PI) / 2);
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
export const sinInOut: EaseFn = (x: number): number => {
|
|
101
|
+
if (x <= 0) return 0;
|
|
102
|
+
if (x >= 1) return 1;
|
|
103
|
+
|
|
104
|
+
return -(Math.cos(Math.PI * x) - 1) / 2;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export const quartIn: EaseFn = (x: number): number => {
|
|
108
|
+
if (x <= 0) return 0;
|
|
109
|
+
if (x >= 1) return 1;
|
|
110
|
+
|
|
111
|
+
return x * x * x * x;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
export const quartOut: EaseFn = (x: number): number => {
|
|
115
|
+
if (x <= 0) return 0;
|
|
116
|
+
if (x >= 1) return 1;
|
|
117
|
+
|
|
118
|
+
return 1 - Math.pow(1 - x, 4);
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
export const quartInOut: EaseFn = (x: number): number => {
|
|
122
|
+
if (x <= 0) return 0;
|
|
123
|
+
if (x >= 1) return 1;
|
|
124
|
+
|
|
125
|
+
if (x < 0.5) {
|
|
126
|
+
return 8 * x * x * x * x;
|
|
127
|
+
} else {
|
|
128
|
+
return 1 - Math.pow(-2 * x + 2, 4) / 2;
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
export const quintIn: EaseFn = (x: number): number => {
|
|
133
|
+
if (x <= 0) return 0;
|
|
134
|
+
if (x >= 1) return 1;
|
|
135
|
+
|
|
136
|
+
return x * x * x * x * x;
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
export const quintOut: EaseFn = (x: number): number => {
|
|
140
|
+
if (x <= 0) return 0;
|
|
141
|
+
if (x >= 1) return 1;
|
|
142
|
+
|
|
143
|
+
return 1 - Math.pow(1 - x, 5);
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
export const quintInOut: EaseFn = (x: number): number => {
|
|
147
|
+
if (x <= 0) return 0;
|
|
148
|
+
if (x >= 1) return 1;
|
|
149
|
+
|
|
150
|
+
if (x < 0.5) {
|
|
151
|
+
return 16 * x * x * x * x * x;
|
|
152
|
+
} else {
|
|
153
|
+
return 1 - Math.pow(-2 * x + 2, 5) / 2;
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
export const circIn: EaseFn = (x: number): number => {
|
|
158
|
+
if (x <= 0) return 0;
|
|
159
|
+
if (x >= 1) return 1;
|
|
160
|
+
|
|
161
|
+
return 1 - Math.sqrt(1 - Math.pow(x, 2));
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
export const circOut: EaseFn = (x: number): number => {
|
|
165
|
+
if (x <= 0) return 0;
|
|
166
|
+
if (x >= 1) return 1;
|
|
167
|
+
|
|
168
|
+
return Math.sqrt(1 - Math.pow(x - 1, 2));
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
export const circInOut: EaseFn = (x: number): number => {
|
|
172
|
+
if (x <= 0) return 0;
|
|
173
|
+
if (x >= 1) return 1;
|
|
174
|
+
|
|
175
|
+
if (x < 0.5) {
|
|
176
|
+
return (1 - Math.sqrt(1 - Math.pow(2 * x, 2))) / 2;
|
|
177
|
+
} else {
|
|
178
|
+
return (Math.sqrt(1 - Math.pow(-2 * x + 2, 2)) + 1) / 2;
|
|
179
|
+
}
|
|
180
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { interpolateNumber } from "./interpolateNumber";
|
|
2
|
+
|
|
3
|
+
describe("Lerp number", () => {
|
|
4
|
+
it("Interpolate as expected", () => {
|
|
5
|
+
const lerpedVal = interpolateNumber(0, 10, 0.5);
|
|
6
|
+
expect(lerpedVal).toEqual(5);
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
it("Interpolate without clamping", () => {
|
|
10
|
+
const lerpedVal = interpolateNumber(0, 10, -0.5);
|
|
11
|
+
expect(lerpedVal).toEqual(-5);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("Interpolate without clamping", () => {
|
|
15
|
+
const lerpedVal = interpolateNumber(0, 10, 1.5);
|
|
16
|
+
expect(lerpedVal).toEqual(15);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("Interpolate with clamping", () => {
|
|
20
|
+
const lerpedVal = interpolateNumber(0, 10, -0.5, true);
|
|
21
|
+
expect(lerpedVal).toEqual(0);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("Interpolate with clamping", () => {
|
|
25
|
+
const lerpedVal = interpolateNumber(0, 10, 1.5, true);
|
|
26
|
+
expect(lerpedVal).toEqual(10);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export function interpolateNumber(
|
|
2
|
+
start: number,
|
|
3
|
+
end: number,
|
|
4
|
+
percent: number,
|
|
5
|
+
clamp: boolean = false
|
|
6
|
+
): number {
|
|
7
|
+
const range = end - start;
|
|
8
|
+
|
|
9
|
+
if (!clamp) {
|
|
10
|
+
return percent * range + start;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
let clampedP = percent;
|
|
14
|
+
if (clampedP < 0) {
|
|
15
|
+
clampedP = 0;
|
|
16
|
+
} else if (clampedP > 1) {
|
|
17
|
+
clampedP = 1;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return clampedP * range + start;
|
|
21
|
+
}
|