@oliversalzburg/js-utils 0.7.0 → 0.8.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.
Files changed (178) hide show
  1. package/lib/async/async.d.ts +44 -0
  2. package/lib/async/async.js +76 -0
  3. package/lib/async/async.js.map +1 -0
  4. package/lib/async/async.test.d.ts +1 -0
  5. package/lib/async/async.test.js +26 -0
  6. package/lib/async/async.test.js.map +1 -0
  7. package/lib/cli/args.d.ts +9 -0
  8. package/lib/cli/args.js +49 -0
  9. package/lib/cli/args.js.map +1 -0
  10. package/lib/cli/args.test.d.ts +1 -0
  11. package/lib/cli/args.test.js +31 -0
  12. package/lib/cli/args.test.js.map +1 -0
  13. package/lib/core.d.ts +43 -0
  14. package/lib/core.js +2 -0
  15. package/lib/core.js.map +1 -0
  16. package/lib/data/array.d.ts +55 -0
  17. package/lib/data/array.js +90 -0
  18. package/lib/data/array.js.map +1 -0
  19. package/lib/data/nil.d.ts +92 -0
  20. package/lib/data/nil.js +131 -0
  21. package/lib/data/nil.js.map +1 -0
  22. package/lib/data/random.d.ts +111 -0
  23. package/lib/data/random.js +381 -0
  24. package/lib/data/random.js.map +1 -0
  25. package/lib/data/string.d.ts +30 -0
  26. package/lib/data/string.js +53 -0
  27. package/lib/data/string.js.map +1 -0
  28. package/lib/data/tree.d.ts +28 -0
  29. package/lib/data/tree.js +45 -0
  30. package/lib/data/tree.js.map +1 -0
  31. package/lib/device/shake.d.ts +79 -0
  32. package/lib/device/shake.js +135 -0
  33. package/lib/device/shake.js.map +1 -0
  34. package/lib/dom/core.d.ts +21 -0
  35. package/lib/dom/core.js +41 -0
  36. package/lib/dom/core.js.map +1 -0
  37. package/lib/errors/AbstractError.d.ts +29 -0
  38. package/lib/errors/AbstractError.js +59 -0
  39. package/lib/errors/AbstractError.js.map +1 -0
  40. package/lib/errors/InternalError.d.ts +19 -0
  41. package/lib/errors/InternalError.js +38 -0
  42. package/lib/errors/InternalError.js.map +1 -0
  43. package/lib/errors/InvalidArgumentError.d.ts +13 -0
  44. package/lib/errors/InvalidArgumentError.js +22 -0
  45. package/lib/errors/InvalidArgumentError.js.map +1 -0
  46. package/lib/errors/InvalidOperationError.d.ts +13 -0
  47. package/lib/errors/InvalidOperationError.js +22 -0
  48. package/lib/errors/InvalidOperationError.js.map +1 -0
  49. package/lib/errors/NotImplementedError.d.ts +12 -0
  50. package/lib/errors/NotImplementedError.js +21 -0
  51. package/lib/errors/NotImplementedError.js.map +1 -0
  52. package/lib/errors/PermissionViolationError.d.ts +13 -0
  53. package/lib/errors/PermissionViolationError.js +22 -0
  54. package/lib/errors/PermissionViolationError.js.map +1 -0
  55. package/lib/errors/ResourceConflictError.d.ts +12 -0
  56. package/lib/errors/ResourceConflictError.js +21 -0
  57. package/lib/errors/ResourceConflictError.js.map +1 -0
  58. package/lib/errors/UnknownError.d.ts +16 -0
  59. package/lib/errors/UnknownError.js +25 -0
  60. package/lib/errors/UnknownError.js.map +1 -0
  61. package/lib/errors/console.d.ts +7 -0
  62. package/lib/errors/console.js +13 -0
  63. package/lib/errors/console.js.map +1 -0
  64. package/lib/errors/error-serializer.d.ts +45 -0
  65. package/lib/errors/error-serializer.js +74 -0
  66. package/lib/errors/error-serializer.js.map +1 -0
  67. package/lib/errors/error-serializer.test.d.ts +1 -0
  68. package/lib/errors/error-serializer.test.js +109 -0
  69. package/lib/errors/error-serializer.test.js.map +1 -0
  70. package/lib/errors/stream.d.ts +7 -0
  71. package/lib/errors/stream.js +15 -0
  72. package/lib/errors/stream.js.map +1 -0
  73. package/lib/errors/tools.d.ts +10 -0
  74. package/lib/errors/tools.js +13 -0
  75. package/lib/errors/tools.js.map +1 -0
  76. package/lib/events/event.d.ts +9 -0
  77. package/lib/events/event.js +10 -0
  78. package/lib/events/event.js.map +1 -0
  79. package/lib/format/bytes.d.ts +118 -0
  80. package/lib/format/bytes.js +138 -0
  81. package/lib/format/bytes.js.map +1 -0
  82. package/lib/format/bytes.test.d.ts +1 -0
  83. package/lib/format/bytes.test.js +146 -0
  84. package/lib/format/bytes.test.js.map +1 -0
  85. package/lib/format/count.d.ts +14 -0
  86. package/lib/format/count.js +51 -0
  87. package/lib/format/count.js.map +1 -0
  88. package/lib/format/count.test.d.ts +1 -0
  89. package/lib/format/count.test.js +42 -0
  90. package/lib/format/count.test.js.map +1 -0
  91. package/lib/format/milliseconds.d.ts +100 -0
  92. package/lib/format/milliseconds.js +199 -0
  93. package/lib/format/milliseconds.js.map +1 -0
  94. package/lib/format/milliseconds.test.d.ts +1 -0
  95. package/lib/format/milliseconds.test.js +393 -0
  96. package/lib/format/milliseconds.test.js.map +1 -0
  97. package/lib/format/string.d.ts +24 -0
  98. package/lib/format/string.js +32 -0
  99. package/lib/format/string.js.map +1 -0
  100. package/lib/format/string.test.d.ts +1 -0
  101. package/lib/format/string.test.js +17 -0
  102. package/lib/format/string.test.js.map +1 -0
  103. package/lib/graphics/canvas-sandbox-mp.d.ts +258 -0
  104. package/lib/graphics/canvas-sandbox-mp.js +280 -0
  105. package/lib/graphics/canvas-sandbox-mp.js.map +1 -0
  106. package/lib/graphics/canvas-sandbox.d.ts +255 -0
  107. package/lib/graphics/canvas-sandbox.js +358 -0
  108. package/lib/graphics/canvas-sandbox.js.map +1 -0
  109. package/lib/graphics/canvas.d.ts +57 -0
  110. package/lib/graphics/canvas.js +37 -0
  111. package/lib/graphics/canvas.js.map +1 -0
  112. package/lib/graphics/canvas2d-headless.d.ts +85 -0
  113. package/lib/graphics/canvas2d-headless.js +197 -0
  114. package/lib/graphics/canvas2d-headless.js.map +1 -0
  115. package/lib/graphics/canvas2d.d.ts +162 -0
  116. package/lib/graphics/canvas2d.js +332 -0
  117. package/lib/graphics/canvas2d.js.map +1 -0
  118. package/lib/graphics/canvas3d.d.ts +41 -0
  119. package/lib/graphics/canvas3d.js +67 -0
  120. package/lib/graphics/canvas3d.js.map +1 -0
  121. package/lib/graphics/color.d.ts +22 -0
  122. package/lib/graphics/color.js +38 -0
  123. package/lib/graphics/color.js.map +1 -0
  124. package/lib/graphics/core.d.ts +89 -0
  125. package/lib/graphics/core.js +146 -0
  126. package/lib/graphics/core.js.map +1 -0
  127. package/lib/graphics/palette-sampler.d.ts +7 -0
  128. package/lib/graphics/palette-sampler.js +21 -0
  129. package/lib/graphics/palette-sampler.js.map +1 -0
  130. package/lib/graphics/palette.d.ts +120 -0
  131. package/lib/graphics/palette.js +574 -0
  132. package/lib/graphics/palette.js.map +1 -0
  133. package/lib/graphics/palette.test.d.ts +1 -0
  134. package/lib/graphics/palette.test.js +43 -0
  135. package/lib/graphics/palette.test.js.map +1 -0
  136. package/lib/graphics/render-loop.d.ts +76 -0
  137. package/lib/graphics/render-loop.js +114 -0
  138. package/lib/graphics/render-loop.js.map +1 -0
  139. package/lib/graphics/shader.d.ts +56 -0
  140. package/lib/graphics/shader.js +80 -0
  141. package/lib/graphics/shader.js.map +1 -0
  142. package/lib/log/log.d.ts +11 -0
  143. package/lib/log/log.js +2 -0
  144. package/lib/log/log.js.map +1 -0
  145. package/lib/log/report.d.ts +57 -0
  146. package/lib/log/report.js +88 -0
  147. package/lib/log/report.js.map +1 -0
  148. package/lib/math/core.d.ts +85 -0
  149. package/lib/math/core.js +125 -0
  150. package/lib/math/core.js.map +1 -0
  151. package/lib/math/easing.d.ts +204 -0
  152. package/lib/math/easing.js +366 -0
  153. package/lib/math/easing.js.map +1 -0
  154. package/lib/math/euler.d.ts +18 -0
  155. package/lib/math/euler.js +22 -0
  156. package/lib/math/euler.js.map +1 -0
  157. package/lib/math/matrix3.d.ts +227 -0
  158. package/lib/math/matrix3.js +508 -0
  159. package/lib/math/matrix3.js.map +1 -0
  160. package/lib/math/quaternion.d.ts +119 -0
  161. package/lib/math/quaternion.js +270 -0
  162. package/lib/math/quaternion.js.map +1 -0
  163. package/lib/math/transformation.d.ts +26 -0
  164. package/lib/math/transformation.js +31 -0
  165. package/lib/math/transformation.js.map +1 -0
  166. package/lib/math/vector2.d.ts +202 -0
  167. package/lib/math/vector2.js +310 -0
  168. package/lib/math/vector2.js.map +1 -0
  169. package/lib/math/vector3.d.ts +293 -0
  170. package/lib/math/vector3.js +492 -0
  171. package/lib/math/vector3.js.map +1 -0
  172. package/lib/math/vector4.d.ts +182 -0
  173. package/lib/math/vector4.js +302 -0
  174. package/lib/math/vector4.js.map +1 -0
  175. package/lib/measurement/performance.d.ts +13 -0
  176. package/lib/measurement/performance.js +19 -0
  177. package/lib/measurement/performance.js.map +1 -0
  178. package/package.json +5 -7
@@ -0,0 +1,125 @@
1
+ /**
2
+ * `PI` times 2.
3
+ */
4
+ export const TWO_PI = /* __PURE__ */ Math.PI * 2;
5
+ /**
6
+ * Converts the degrees to radians.
7
+ * @param degrees - The degrees to convert to radians.
8
+ * @returns The degrees in radians.
9
+ */
10
+ export const degreesToRadians = (degrees) => {
11
+ return degrees * (Math.PI / 180);
12
+ };
13
+ /**
14
+ * Convertrs the radians to degrees.
15
+ * @param radians - The radians to convert to degrees.
16
+ * @returns The radians as degrees.
17
+ */
18
+ export const radiansToDegrees = (radians) => {
19
+ return radians * (180 / Math.PI);
20
+ };
21
+ /**
22
+ * Calculates the sine for a given degree value.
23
+ * @param value - The value in degrees to calculate the sine for.
24
+ * @returns The sine for the given value.
25
+ */
26
+ export const sinDegrees = (value) => {
27
+ return Math.sin(degreesToRadians(value));
28
+ };
29
+ /**
30
+ * Calculates the cosine for a given degree value.
31
+ * @param value - The value in degrees to calculate the cosine for.
32
+ * @returns The cosine for the given value.
33
+ */
34
+ export const cosDegrees = (value) => {
35
+ return Math.cos(degreesToRadians(value));
36
+ };
37
+ /**
38
+ * Calculates the distance between two vectors.
39
+ * @param x1 - The X component of the first vector.
40
+ * @param y1 - The Y comoinent of the first vector.
41
+ * @param x2 - The X component of the second vector.
42
+ * @param y2 - The Y component of the second vector.
43
+ * @returns The distance between the two vectors.
44
+ */
45
+ export const distance = (x1, y1, x2, y2) => {
46
+ const distx = x2 - x1;
47
+ const disty = y2 - y1;
48
+ return Math.sqrt(distx * distx + disty * disty);
49
+ };
50
+ /**
51
+ * Finds the integer square root of a positive number.
52
+ * @param value - The value to calcuate the square root for.
53
+ * @returns The square root for the given value.
54
+ */
55
+ export const isqrt = (value) => {
56
+ if (0 === value) {
57
+ return 0;
58
+ } // Avoid zero divide
59
+ let n = value / 2 + 1; // Initial estimate, never low
60
+ let n1 = (n + value / n) / 2;
61
+ while (n1 < n) {
62
+ n = n1;
63
+ n1 = (n + value / n) / 2;
64
+ }
65
+ return n;
66
+ };
67
+ /**
68
+ * Checks whether a number is an integer.
69
+ * @param value - The value to check.
70
+ * @returns `true` when the value is an integer, `false` otherwise.
71
+ */
72
+ export const isInteger = (value) => {
73
+ return Math.trunc(value) === value;
74
+ };
75
+ /**
76
+ * Ensures a given value is within a given boundary.
77
+ * @param input - The number to clamp.
78
+ * @param floor - The lower bound.
79
+ * @param ceil - The upper bound.
80
+ * @returns The number clamped to the desired range.
81
+ */
82
+ export const clamp = (input, floor, ceil) => {
83
+ return Math.max(floor, Math.min(input, ceil));
84
+ };
85
+ /**
86
+ * Rounds a given number to the next highest value.
87
+ * @param input - The number to round.
88
+ * @param fractionDigits - The amount of digits to retain in the fraction.
89
+ * @returns The rounded number.
90
+ */
91
+ export const ceilTo = (input, fractionDigits = 0) => {
92
+ const scale = 10 ** fractionDigits;
93
+ return Math.floor(input * scale) / scale;
94
+ };
95
+ /**
96
+ * Rounds a given number to the next lowest value.
97
+ * @param input - The number to round.
98
+ * @param fractionDigits - The amount of digits to retain in the fraction.
99
+ * @returns The rounded number.
100
+ */
101
+ export const floorTo = (input, fractionDigits = 0) => {
102
+ const scale = 10 ** fractionDigits;
103
+ return Math.floor(input * scale) / scale;
104
+ };
105
+ /**
106
+ * Rounds a given number to the next closest value.
107
+ * @param input - The number to round.
108
+ * @param fractionDigits - The amount of digits to retain in the fraction.
109
+ * @returns The rounded number.
110
+ */
111
+ export const roundTo = (input, fractionDigits = 0) => {
112
+ const scale = 10 ** fractionDigits;
113
+ return Math.round(input * scale) / scale;
114
+ };
115
+ /**
116
+ * Cuts off digits of a number.
117
+ * @param input - The number to round.
118
+ * @param fractionDigits - The amount of digits to retain in the fraction.
119
+ * @returns The rounded number.
120
+ */
121
+ export const truncTo = (input, fractionDigits = 0) => {
122
+ const scale = 10 ** fractionDigits;
123
+ return Math.trunc(input * scale) / scale;
124
+ };
125
+ //# sourceMappingURL=core.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core.js","sourceRoot":"","sources":["../../source/math/core.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,204 @@
1
+ /**
2
+ * Calculates an easing multiplier for: Quad In
3
+ * @param position - The current position between start and end (from `0` to `1`)
4
+ * @returns The easing multiplier for the position.
5
+ */
6
+ export declare const easeInQuad: (position: number) => number;
7
+ /**
8
+ * Calculates an easing multiplier for: Quad Out
9
+ * @param position - The current position between start and end (from `0` to `1`)
10
+ * @returns The easing multiplier for the position.
11
+ */
12
+ export declare const easeOutQuad: (position: number) => number;
13
+ /**
14
+ * Calculates an easing multiplier for: Quad In+Out
15
+ * @param position - The current position between start and end (from `0` to `1`)
16
+ * @returns The easing multiplier for the position.
17
+ */
18
+ export declare const easeInOutQuad: (position: number) => number;
19
+ /**
20
+ * Calculates an easing multiplier for: Cubic In
21
+ * @param position - The current position between start and end (from `0` to `1`)
22
+ * @returns The easing multiplier for the position.
23
+ */
24
+ export declare const easeInCubic: (position: number) => number;
25
+ /**
26
+ * Calculates an easing multiplier for: Cubic Out
27
+ * @param position - The current position between start and end (from `0` to `1`)
28
+ * @returns The easing multiplier for the position.
29
+ */
30
+ export declare const easeOutCubic: (position: number) => number;
31
+ /**
32
+ * Calculates an easing multiplier for: Cubic In+Out
33
+ * @param position - The current position between start and end (from `0` to `1`)
34
+ * @returns The easing multiplier for the position.
35
+ */
36
+ export declare const easeInOutCubic: (position: number) => number;
37
+ /**
38
+ * Calculates an easing multiplier for: Quart In
39
+ * @param position - The current position between start and end (from `0` to `1`)
40
+ * @returns The easing multiplier for the position.
41
+ */
42
+ export declare const easeInQuart: (position: number) => number;
43
+ /**
44
+ * Calculates an easing multiplier for: Quad Out
45
+ * @param position - The current position between start and end (from `0` to `1`)
46
+ * @returns The easing multiplier for the position.
47
+ */
48
+ export declare const easeOutQuart: (position: number) => number;
49
+ /**
50
+ * Calculates an easing multiplier for: Quart In+Out
51
+ * @param position - The current position between start and end (from `0` to `1`)
52
+ * @returns The easing multiplier for the position.
53
+ */
54
+ export declare const easeInOutQuart: (position: number) => number;
55
+ /**
56
+ * Calculates an easing multiplier for: Quint In
57
+ * @param position - The current position between start and end (from `0` to `1`)
58
+ * @returns The easing multiplier for the position.
59
+ */
60
+ export declare const easeInQuint: (position: number) => number;
61
+ /**
62
+ * Calculates an easing multiplier for: Quint Out
63
+ * @param position - The current position between start and end (from `0` to `1`)
64
+ * @returns The easing multiplier for the position.
65
+ */
66
+ export declare const easeOutQuint: (position: number) => number;
67
+ /**
68
+ * Calculates an easing multiplier for: Quint In+Out
69
+ * @param position - The current position between start and end (from `0` to `1`)
70
+ * @returns The easing multiplier for the position.
71
+ */
72
+ export declare const easeInOutQuint: (position: number) => number;
73
+ /**
74
+ * Calculates an easing multiplier for: Sine In
75
+ * @param position - The current position between start and end (from `0` to `1`)
76
+ * @returns The easing multiplier for the position.
77
+ */
78
+ export declare const easeInSine: (position: number) => number;
79
+ /**
80
+ * Calculates an easing multiplier for: Sine Out
81
+ * @param position - The current position between start and end (from `0` to `1`)
82
+ * @returns The easing multiplier for the position.
83
+ */
84
+ export declare const easeOutSine: (position: number) => number;
85
+ /**
86
+ * Calculates an easing multiplier for: Sine In+Out
87
+ * @param position - The current position between start and end (from `0` to `1`)
88
+ * @returns The easing multiplier for the position.
89
+ */
90
+ export declare const easeInOutSine: (position: number) => number;
91
+ /**
92
+ * Calculates an easing multiplier for: Expo In
93
+ * @param position - The current position between start and end (from `0` to `1`)
94
+ * @returns The easing multiplier for the position.
95
+ */
96
+ export declare const easeInExpo: (position: number) => number;
97
+ /**
98
+ * Calculates an easing multiplier for: Expo Out
99
+ * @param position - The current position between start and end (from `0` to `1`)
100
+ * @returns The easing multiplier for the position.
101
+ */
102
+ export declare const easeOutExpo: (position: number) => number;
103
+ /**
104
+ * Calculates an easing multiplier for: Expo In+Out
105
+ * @param position - The current position between start and end (from `0` to `1`)
106
+ * @returns The easing multiplier for the position.
107
+ */
108
+ export declare const easeInOutExpo: (position: number) => number;
109
+ /**
110
+ * Calculates an easing multiplier for: Circ In
111
+ * @param position - The current position between start and end (from `0` to `1`)
112
+ * @returns The easing multiplier for the position.
113
+ */
114
+ export declare const easeInCirc: (position: number) => number;
115
+ /**
116
+ * Calculates an easing multiplier for: Circ Out
117
+ * @param position - The current position between start and end (from `0` to `1`)
118
+ * @returns The easing multiplier for the position.
119
+ */
120
+ export declare const easeOutCirc: (position: number) => number;
121
+ /**
122
+ * Calculates an easing multiplier for: Circ In+Out
123
+ * @param position - The current position between start and end (from `0` to `1`)
124
+ * @returns The easing multiplier for the position.
125
+ */
126
+ export declare const easeInOutCirc: (position: number) => number;
127
+ /**
128
+ * Calculates an easing multiplier for: Bounce Out
129
+ * @param position - The current position between start and end (from `0` to `1`)
130
+ * @returns The easing multiplier for the position.
131
+ */
132
+ export declare const easeOutBounce: (position: number) => number;
133
+ /**
134
+ * Calculates an easing multiplier for: Back In
135
+ * @param position - The current position between start and end (from `0` to `1`)
136
+ * @returns The easing multiplier for the position.
137
+ */
138
+ export declare const easeInBack: (position: number) => number;
139
+ /**
140
+ * Calculates an easing multiplier for: Back Out
141
+ * @param position - The current position between start and end (from `0` to `1`)
142
+ * @returns The easing multiplier for the position.
143
+ */
144
+ export declare const easeOutBack: (position: number) => number;
145
+ /**
146
+ * Calculates an easing multiplier for: Back In+Out
147
+ * @param position - The current position between start and end (from `0` to `1`)
148
+ * @returns The easing multiplier for the position.
149
+ */
150
+ export declare const easeInOutBack: (position: number) => number;
151
+ /**
152
+ * Calculates an easing multiplier for: Elastic
153
+ * @param position - The current position between start and end (from `0` to `1`)
154
+ * @returns The easing multiplier for the position.
155
+ */
156
+ export declare const easeElastic: (position: number) => number;
157
+ /**
158
+ * Calculates an easing multiplier for: Swing In+Out
159
+ * @param position - The current position between start and end (from `0` to `1`)
160
+ * @returns The easing multiplier for the position.
161
+ */
162
+ export declare const swingInOut: (position: number) => number;
163
+ /**
164
+ * Calculates an easing multiplier for: Swing In
165
+ * @param position - The current position between start and end (from `0` to `1`)
166
+ * @returns The easing multiplier for the position.
167
+ */
168
+ export declare const easeSwingIn: (position: number) => number;
169
+ /**
170
+ * Calculates an easing multiplier for: Swing Out
171
+ * @param position - The current position between start and end (from `0` to `1`)
172
+ * @returns The easing multiplier for the position.
173
+ */
174
+ export declare const easeSwingOut: (position: number) => number;
175
+ /**
176
+ * Calculates an easing multiplier for: Bounce
177
+ * @param position - The current position between start and end (from `0` to `1`)
178
+ * @returns The easing multiplier for the position.
179
+ */
180
+ export declare const easeBounce: (position: number) => number;
181
+ /**
182
+ * Calculates an easing multiplier for: Bounce Past
183
+ * @param position - The current position between start and end (from `0` to `1`)
184
+ * @returns The easing multiplier for the position.
185
+ */
186
+ export declare const easeBouncePast: (position: number) => number;
187
+ /**
188
+ * Calculates an easing multiplier for: Simple In+Out
189
+ * @param position - The current position between start and end (from `0` to `1`)
190
+ * @returns The easing multiplier for the position.
191
+ */
192
+ export declare const easeFromTo: (position: number) => number;
193
+ /**
194
+ * Calculates an easing multiplier for: Simple In
195
+ * @param position - The current position between start and end (from `0` to `1`)
196
+ * @returns The easing multiplier for the position.
197
+ */
198
+ export declare const easeFrom: (position: number) => number;
199
+ /**
200
+ * Calculates an easing multiplier for: Simple Out
201
+ * @param position - The current position between start and end (from `0` to `1`)
202
+ * @returns The easing multiplier for the position.
203
+ */
204
+ export declare const easeTo: (position: number) => number;
@@ -0,0 +1,366 @@
1
+ // http://robertpenner.com/easing_terms_of_use.html
2
+ /**
3
+ * Calculates an easing multiplier for: Quad In
4
+ * @param position - The current position between start and end (from `0` to `1`)
5
+ * @returns The easing multiplier for the position.
6
+ */
7
+ export const easeInQuad = (position) => {
8
+ return position ** 2;
9
+ };
10
+ /**
11
+ * Calculates an easing multiplier for: Quad Out
12
+ * @param position - The current position between start and end (from `0` to `1`)
13
+ * @returns The easing multiplier for the position.
14
+ */
15
+ export const easeOutQuad = (position) => {
16
+ return -((position - 1) ** 2 - 1);
17
+ };
18
+ /**
19
+ * Calculates an easing multiplier for: Quad In+Out
20
+ * @param position - The current position between start and end (from `0` to `1`)
21
+ * @returns The easing multiplier for the position.
22
+ */
23
+ export const easeInOutQuad = (position) => {
24
+ position /= 0.5;
25
+ if (position < 1) {
26
+ return 0.5 * position ** 2;
27
+ }
28
+ position -= 2;
29
+ return -0.5 * (position * position - 2);
30
+ };
31
+ /**
32
+ * Calculates an easing multiplier for: Cubic In
33
+ * @param position - The current position between start and end (from `0` to `1`)
34
+ * @returns The easing multiplier for the position.
35
+ */
36
+ export const easeInCubic = (position) => {
37
+ return position ** 3;
38
+ };
39
+ /**
40
+ * Calculates an easing multiplier for: Cubic Out
41
+ * @param position - The current position between start and end (from `0` to `1`)
42
+ * @returns The easing multiplier for the position.
43
+ */
44
+ export const easeOutCubic = (position) => {
45
+ return (position - 1) ** 3 + 1;
46
+ };
47
+ /**
48
+ * Calculates an easing multiplier for: Cubic In+Out
49
+ * @param position - The current position between start and end (from `0` to `1`)
50
+ * @returns The easing multiplier for the position.
51
+ */
52
+ export const easeInOutCubic = (position) => {
53
+ position /= 0.5;
54
+ if (position < 1)
55
+ return 0.5 * position ** 3;
56
+ return 0.5 * ((position - 2) ** 3 + 2);
57
+ };
58
+ /**
59
+ * Calculates an easing multiplier for: Quart In
60
+ * @param position - The current position between start and end (from `0` to `1`)
61
+ * @returns The easing multiplier for the position.
62
+ */
63
+ export const easeInQuart = (position) => {
64
+ return position ** 4;
65
+ };
66
+ /**
67
+ * Calculates an easing multiplier for: Quad Out
68
+ * @param position - The current position between start and end (from `0` to `1`)
69
+ * @returns The easing multiplier for the position.
70
+ */
71
+ export const easeOutQuart = (position) => {
72
+ return -((position - 1) ** 4 - 1);
73
+ };
74
+ /**
75
+ * Calculates an easing multiplier for: Quart In+Out
76
+ * @param position - The current position between start and end (from `0` to `1`)
77
+ * @returns The easing multiplier for the position.
78
+ */
79
+ export const easeInOutQuart = (position) => {
80
+ position /= 0.5;
81
+ if (position < 1)
82
+ return 0.5 * position ** 4;
83
+ position -= 2;
84
+ return -0.5 * (position * position ** 3 - 2);
85
+ };
86
+ /**
87
+ * Calculates an easing multiplier for: Quint In
88
+ * @param position - The current position between start and end (from `0` to `1`)
89
+ * @returns The easing multiplier for the position.
90
+ */
91
+ export const easeInQuint = (position) => {
92
+ return position ** 5;
93
+ };
94
+ /**
95
+ * Calculates an easing multiplier for: Quint Out
96
+ * @param position - The current position between start and end (from `0` to `1`)
97
+ * @returns The easing multiplier for the position.
98
+ */
99
+ export const easeOutQuint = (position) => {
100
+ return (position - 1) ** 5 + 1;
101
+ };
102
+ /**
103
+ * Calculates an easing multiplier for: Quint In+Out
104
+ * @param position - The current position between start and end (from `0` to `1`)
105
+ * @returns The easing multiplier for the position.
106
+ */
107
+ export const easeInOutQuint = (position) => {
108
+ position /= 0.5;
109
+ if (position < 1)
110
+ return 0.5 * position ** 5;
111
+ return 0.5 * ((position - 2) ** 5 + 2);
112
+ };
113
+ /**
114
+ * Calculates an easing multiplier for: Sine In
115
+ * @param position - The current position between start and end (from `0` to `1`)
116
+ * @returns The easing multiplier for the position.
117
+ */
118
+ export const easeInSine = (position) => {
119
+ return -Math.cos(position * (Math.PI / 2)) + 1;
120
+ };
121
+ /**
122
+ * Calculates an easing multiplier for: Sine Out
123
+ * @param position - The current position between start and end (from `0` to `1`)
124
+ * @returns The easing multiplier for the position.
125
+ */
126
+ export const easeOutSine = (position) => {
127
+ return Math.sin(position * (Math.PI / 2));
128
+ };
129
+ /**
130
+ * Calculates an easing multiplier for: Sine In+Out
131
+ * @param position - The current position between start and end (from `0` to `1`)
132
+ * @returns The easing multiplier for the position.
133
+ */
134
+ export const easeInOutSine = (position) => {
135
+ return -0.5 * (Math.cos(Math.PI * position) - 1);
136
+ };
137
+ /**
138
+ * Calculates an easing multiplier for: Expo In
139
+ * @param position - The current position between start and end (from `0` to `1`)
140
+ * @returns The easing multiplier for the position.
141
+ */
142
+ export const easeInExpo = (position) => {
143
+ return position === 0 ? 0 : 2 ** (10 * (position - 1));
144
+ };
145
+ /**
146
+ * Calculates an easing multiplier for: Expo Out
147
+ * @param position - The current position between start and end (from `0` to `1`)
148
+ * @returns The easing multiplier for the position.
149
+ */
150
+ export const easeOutExpo = (position) => {
151
+ return position === 1 ? 1 : -(2 ** (-10 * position)) + 1;
152
+ };
153
+ /**
154
+ * Calculates an easing multiplier for: Expo In+Out
155
+ * @param position - The current position between start and end (from `0` to `1`)
156
+ * @returns The easing multiplier for the position.
157
+ */
158
+ export const easeInOutExpo = (position) => {
159
+ if (position === 0)
160
+ return 0;
161
+ if (position === 1)
162
+ return 1;
163
+ position /= 0.5;
164
+ if (position < 1)
165
+ return 0.5 * 2 ** (10 * (position - 1));
166
+ return 0.5 * (-(2 ** (-10 * --position)) + 2);
167
+ };
168
+ /**
169
+ * Calculates an easing multiplier for: Circ In
170
+ * @param position - The current position between start and end (from `0` to `1`)
171
+ * @returns The easing multiplier for the position.
172
+ */
173
+ export const easeInCirc = (position) => {
174
+ return -(Math.sqrt(1 - position * position) - 1);
175
+ };
176
+ /**
177
+ * Calculates an easing multiplier for: Circ Out
178
+ * @param position - The current position between start and end (from `0` to `1`)
179
+ * @returns The easing multiplier for the position.
180
+ */
181
+ export const easeOutCirc = (position) => {
182
+ return Math.sqrt(1 - (position - 1) ** 2);
183
+ };
184
+ /**
185
+ * Calculates an easing multiplier for: Circ In+Out
186
+ * @param position - The current position between start and end (from `0` to `1`)
187
+ * @returns The easing multiplier for the position.
188
+ */
189
+ export const easeInOutCirc = (position) => {
190
+ position /= 0.5;
191
+ if (position < 1)
192
+ return -0.5 * (Math.sqrt(1 - position * position) - 1);
193
+ position -= 2;
194
+ return 0.5 * (Math.sqrt(1 - position * position) + 1);
195
+ };
196
+ /**
197
+ * Calculates an easing multiplier for: Bounce Out
198
+ * @param position - The current position between start and end (from `0` to `1`)
199
+ * @returns The easing multiplier for the position.
200
+ */
201
+ export const easeOutBounce = (position) => {
202
+ if (position < 1 / 2.75) {
203
+ return 7.5625 * position * position;
204
+ }
205
+ else if (position < 2 / 2.75) {
206
+ position -= 1.5 / 2.75;
207
+ return 7.5625 * position * position + 0.75;
208
+ }
209
+ else if (position < 2.5 / 2.75) {
210
+ position -= 2.25 / 2.75;
211
+ return 7.5625 * position * position + 0.9375;
212
+ }
213
+ position -= 2.625 / 2.75;
214
+ return 7.5625 * position * position + 0.984375;
215
+ };
216
+ /**
217
+ * Calculates an easing multiplier for: Back In
218
+ * @param position - The current position between start and end (from `0` to `1`)
219
+ * @returns The easing multiplier for the position.
220
+ */
221
+ export const easeInBack = (position) => {
222
+ const s = 1.70158;
223
+ return position * position * ((s + 1) * position - s);
224
+ };
225
+ /**
226
+ * Calculates an easing multiplier for: Back Out
227
+ * @param position - The current position between start and end (from `0` to `1`)
228
+ * @returns The easing multiplier for the position.
229
+ */
230
+ export const easeOutBack = (position) => {
231
+ const s = 1.70158;
232
+ position = position - 1;
233
+ return position * position * ((s + 1) * position + s) + 1;
234
+ };
235
+ /**
236
+ * Calculates an easing multiplier for: Back In+Out
237
+ * @param position - The current position between start and end (from `0` to `1`)
238
+ * @returns The easing multiplier for the position.
239
+ */
240
+ export const easeInOutBack = (position) => {
241
+ let s = 1.70158;
242
+ position /= 0.5;
243
+ if (position < 1) {
244
+ s *= 1.525;
245
+ return 0.5 * (position * position * ((s + 1) * position - s));
246
+ }
247
+ position -= 2;
248
+ s *= 1.525;
249
+ return 0.5 * (position * position * ((s + 1) * position + s) + 2);
250
+ };
251
+ /**
252
+ * Calculates an easing multiplier for: Elastic
253
+ * @param position - The current position between start and end (from `0` to `1`)
254
+ * @returns The easing multiplier for the position.
255
+ */
256
+ export const easeElastic = (position) => {
257
+ return (-1 *
258
+ 4 ** (-8 * position) *
259
+ Math.sin(((position * 6 - 1) * (2 * Math.PI)) / 2) +
260
+ 1);
261
+ };
262
+ /**
263
+ * Calculates an easing multiplier for: Swing In+Out
264
+ * @param position - The current position between start and end (from `0` to `1`)
265
+ * @returns The easing multiplier for the position.
266
+ */
267
+ export const swingInOut = (position) => {
268
+ let s = 1.70158;
269
+ position /= 0.5;
270
+ if (position < 1) {
271
+ s *= 1.525;
272
+ return 0.5 * (position * position * ((s + 1) * position - s));
273
+ }
274
+ position -= 2;
275
+ s *= 1.525;
276
+ return 0.5 * (position * position * ((s + 1) * position + s) + 2);
277
+ };
278
+ /**
279
+ * Calculates an easing multiplier for: Swing In
280
+ * @param position - The current position between start and end (from `0` to `1`)
281
+ * @returns The easing multiplier for the position.
282
+ */
283
+ export const easeSwingIn = (position) => {
284
+ const s = 1.70158;
285
+ return position * position * ((s + 1) * position - s);
286
+ };
287
+ /**
288
+ * Calculates an easing multiplier for: Swing Out
289
+ * @param position - The current position between start and end (from `0` to `1`)
290
+ * @returns The easing multiplier for the position.
291
+ */
292
+ export const easeSwingOut = (position) => {
293
+ const s = 1.70158;
294
+ position -= 1;
295
+ return position * position * ((s + 1) * position + s) + 1;
296
+ };
297
+ /**
298
+ * Calculates an easing multiplier for: Bounce
299
+ * @param position - The current position between start and end (from `0` to `1`)
300
+ * @returns The easing multiplier for the position.
301
+ */
302
+ export const easeBounce = (position) => {
303
+ if (position < 1 / 2.75) {
304
+ return 7.5625 * position * position;
305
+ }
306
+ else if (position < 2 / 2.75) {
307
+ position -= 1.5 / 2.75;
308
+ return 7.5625 * position * position + 0.75;
309
+ }
310
+ else if (position < 2.5 / 2.75) {
311
+ position -= 2.25 / 2.75;
312
+ return 7.5625 * position * position + 0.9375;
313
+ }
314
+ position -= 2.625 / 2.75;
315
+ return 7.5625 * position * position + 0.984375;
316
+ };
317
+ /**
318
+ * Calculates an easing multiplier for: Bounce Past
319
+ * @param position - The current position between start and end (from `0` to `1`)
320
+ * @returns The easing multiplier for the position.
321
+ */
322
+ export const easeBouncePast = (position) => {
323
+ if (position < 1 / 2.75) {
324
+ return 7.5625 * position * position;
325
+ }
326
+ else if (position < 2 / 2.75) {
327
+ position -= 1.5 / 2.75;
328
+ return 2 - (7.5625 * position * position + 0.75);
329
+ }
330
+ else if (position < 2.5 / 2.75) {
331
+ position -= 2.25 / 2.75;
332
+ return 2 - (7.5625 * position * position + 0.9375);
333
+ }
334
+ position -= 2.625 / 2.75;
335
+ return 2 - (7.5625 * position * position + 0.984375);
336
+ };
337
+ /**
338
+ * Calculates an easing multiplier for: Simple In+Out
339
+ * @param position - The current position between start and end (from `0` to `1`)
340
+ * @returns The easing multiplier for the position.
341
+ */
342
+ export const easeFromTo = (position) => {
343
+ position /= 0.5;
344
+ if (position < 1) {
345
+ return 0.5 * position ** 4;
346
+ }
347
+ position -= 2;
348
+ return -0.5 * (position * position ** 3 - 2);
349
+ };
350
+ /**
351
+ * Calculates an easing multiplier for: Simple In
352
+ * @param position - The current position between start and end (from `0` to `1`)
353
+ * @returns The easing multiplier for the position.
354
+ */
355
+ export const easeFrom = (position) => {
356
+ return position ** 4;
357
+ };
358
+ /**
359
+ * Calculates an easing multiplier for: Simple Out
360
+ * @param position - The current position between start and end (from `0` to `1`)
361
+ * @returns The easing multiplier for the position.
362
+ */
363
+ export const easeTo = (position) => {
364
+ return position ** 0.25;
365
+ };
366
+ //# sourceMappingURL=easing.js.map