1 | declare namespace gsap.utils {
|
2 |
|
3 | interface DistributeConfig {
|
4 | amount?: number;
|
5 | axis?: "x" | "y";
|
6 | base?: number;
|
7 | each?: number;
|
8 | ease?: string | EaseFunction;
|
9 | from?: "start" | "center" | "end" | "edges" | "random" | number | [number, number];
|
10 | grid?: "auto" | [number, number];
|
11 | }
|
12 |
|
13 | interface SnapNumberConfig {
|
14 | increment?: number;
|
15 | values?: number[];
|
16 | radius: number;
|
17 | }
|
18 |
|
19 | interface SnapPoint2DConfig {
|
20 | values: Point2D[];
|
21 | radius: number;
|
22 | }
|
23 |
|
24 | type toArrayValue = string | object | Element | null;
|
25 |
|
26 | |
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 | function checkPrefix(property: string): string;
|
39 |
|
40 | |
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 | function clamp(minimum: number, maximum: number, valueToClamp: number): number;
|
57 | function clamp(minimum: number, maximum: number): (valueToClamp: number) => number;
|
58 |
|
59 | |
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 | function distribute(config: DistributeConfig): FunctionBasedValue<number>;
|
78 |
|
79 | |
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 | function getUnit(value: string): string;
|
91 |
|
92 | |
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 | function interpolate<T>(startValue: T, endValue: T, progress: number): T;
|
109 | function interpolate<T>(startValue: T, endValue: T): (progress: number) => T;
|
110 | |
111 |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 | function interpolate<T>(array: T[], progress: number): T;
|
126 | function interpolate<T>(array: T[]): (progress: number) => T;
|
127 |
|
128 | |
129 |
|
130 |
|
131 |
|
132 |
|
133 |
|
134 |
|
135 |
|
136 |
|
137 |
|
138 |
|
139 |
|
140 |
|
141 |
|
142 |
|
143 |
|
144 |
|
145 |
|
146 | function mapRange(inMin: number, inMax: number, outMin: number, outMax: number, value: number): number;
|
147 | function mapRange(inMin: number, inMax: number, outMin: number, outMax: number): (value: number) => number;
|
148 |
|
149 | |
150 |
|
151 |
|
152 |
|
153 |
|
154 |
|
155 |
|
156 |
|
157 |
|
158 |
|
159 |
|
160 |
|
161 |
|
162 |
|
163 |
|
164 |
|
165 | function normalize(inMin: number, inMax: number, value: number): number;
|
166 | function normalize(inMin: number, inMax: number): (value: number) => number;
|
167 |
|
168 | |
169 |
|
170 |
|
171 |
|
172 |
|
173 |
|
174 |
|
175 |
|
176 |
|
177 |
|
178 |
|
179 |
|
180 |
|
181 |
|
182 |
|
183 | function pipe<A extends Array<unknown>, B>(
|
184 | ab: (...a: A) => B
|
185 | ): (...a: A) => B;
|
186 | function pipe<A extends Array<unknown>, B, C>(
|
187 | ab: (...a: A) => B,
|
188 | bc: (b: B) => C
|
189 | ): (...a: A) => C
|
190 | function pipe<A extends Array<unknown>, B, C, D>(
|
191 | ab: (...a: A) => B,
|
192 | bc: (b: B) => C,
|
193 | cd: (c: C) => D
|
194 | ): (...a: A) => D;
|
195 | function pipe<A extends Array<unknown>, B, C, D, E>(
|
196 | ab: (...a: A) => B,
|
197 | bc: (b: B) => C,
|
198 | cd: (c: C) => D,
|
199 | de: (d: D) => E
|
200 | ): (...a: A) => E;
|
201 | function pipe<A extends Array<unknown>, B, C, D, E, F>(
|
202 | ab: (...a: A) => B,
|
203 | bc: (b: B) => C,
|
204 | cd: (c: C) => D,
|
205 | de: (d: D) => E,
|
206 | ef: (e: E) => F
|
207 | ): (...a: A) => F;
|
208 | function pipe<A extends Array<unknown>, B, C, D, E, F, G>(
|
209 | ab: (...a: A) => B,
|
210 | bc: (b: B) => C,
|
211 | cd: (c: C) => D,
|
212 | de: (d: D) => E,
|
213 | ef: (e: E) => F,
|
214 | fg: (f: F) => G
|
215 | ): (...a: A) => G;
|
216 | function pipe<A extends Array<unknown>, B, C, D, E, F, G, H>(
|
217 | ab: (...a: A) => B,
|
218 | bc: (b: B) => C,
|
219 | cd: (c: C) => D,
|
220 | de: (d: D) => E,
|
221 | ef: (e: E) => F,
|
222 | fg: (f: F) => G,
|
223 | gh: (g: G) => H
|
224 | ): (...a: A) => H;
|
225 | function pipe<A extends Array<unknown>, B, C, D, E, F, G, H, I>(
|
226 | ab: (...a: A) => B,
|
227 | bc: (b: B) => C,
|
228 | cd: (c: C) => D,
|
229 | de: (d: D) => E,
|
230 | ef: (e: E) => F,
|
231 | fg: (f: F) => G,
|
232 | gh: (g: G) => H,
|
233 | hi: (h: H) => I
|
234 | ): (...a: A) => I;
|
235 | function pipe<A extends Array<unknown>, B, C, D, E, F, G, H, I, J>(
|
236 | ab: (...a: A) => B,
|
237 | bc: (b: B) => C,
|
238 | cd: (c: C) => D,
|
239 | de: (d: D) => E,
|
240 | ef: (e: E) => F,
|
241 | fg: (f: F) => G,
|
242 | gh: (g: G) => H,
|
243 | hi: (h: H) => I,
|
244 | ij: (i: I) => J
|
245 | ): (...a: A) => J;
|
246 |
|
247 | /**
|
248 | * Get a random number within a range, optionally rounding to an increment you provide.
|
249 | *
|
250 | * ```js
|
251 | * gsap.utils.random(-100, 100);
|
252 | * gsap.utils.random(0, 500, 5);
|
253 | *
|
254 | * const random = gsap.utils.random(-200, 500, 10, true);
|
255 | * console.log( random() );
|
256 | * ```
|
257 | *
|
258 | * @param {number} minValue
|
259 | * @param {number} maxValue
|
260 | * @param {number} [snapIncrement]
|
261 | * @param {boolean} [returnFunction]
|
262 | * @returns {number | Function} The random number or random number generator function
|
263 | * @memberof gsap.utils
|
264 | */
|
265 | function random(minValue: number, maxValue: number, snapIncrement?: number): number;
|
266 | function random<T extends boolean>(minValue: number, maxValue: number, returnFunction?: T): T extends true ? () => number : number;
|
267 | function random<T extends boolean>(minValue: number, maxValue: number, snapIncrement: number, returnFunction?: T): T extends true ? () => number : number;
|
268 | /**
|
269 | * Get a random random element in an array.
|
270 | *
|
271 | * ```js
|
272 | * gsap.utils.random(["red", "blue", "green"]);
|
273 | *
|
274 | * const random = gsap.utils.random([0, 100, 200], true);
|
275 | * console.log( random() );
|
276 | * ```
|
277 | *
|
278 | * @param {T[]} array
|
279 | * @param {boolean} [returnFunction]
|
280 | * @returns {number | Function} The random number or random number generator function
|
281 | * @memberof gsap.utils
|
282 | */
|
283 | function random<T>(array: T[]): T;
|
284 | function random<T, U extends boolean>(array: T[], returnFunction?: U): U extends true ? () => T : T;
|
285 |
|
286 | /**
|
287 | * Takes an array and randomly shuffles it, returning the same (but shuffled) array.
|
288 | *
|
289 | * ```js
|
290 | * gsap.utils.shuffle(array);
|
291 | * ```
|
292 | *
|
293 | * @param {T[]} array
|
294 | * @returns {T[]} The same shuffled array
|
295 | * @memberof gsap.utils
|
296 | */
|
297 | function shuffle<T>(array: T[]): T[];
|
298 |
|
299 | /**
|
300 | * Snaps a value to the nearest increment of the number provided.
|
301 | * Or snaps to a value in the given array.
|
302 | * Or snaps to a value within the given radius (if an object is provided).
|
303 | * Or returns a function that does the above (if the second value is not provided).
|
304 | *
|
305 | * ```js
|
306 | * gsap.utils.snap(10, 23.5);
|
307 | * gsap.utils.snap([100, 50, 500], 65);
|
308 | * gsap.utils.snap({values:[0, 100, 300], radius:20}, 30.5);
|
309 | * gsap.utils.snap({increment:500, radius:150}, 310);
|
310 | *
|
311 | * const snap = gsap.utils.snap(5);
|
312 | * console.log( snap(0.5) );
|
313 | * ```
|
314 | *
|
315 | * @param {SnapNumberConfig} snapConfig
|
316 | * @param {number} [valueToSnap]
|
317 | * @returns {number | Function} The snapped number or snap function
|
318 | * @memberof gsap.utils
|
319 | */
|
320 | function snap(snapConfig: number | number[] | SnapNumberConfig, valueToSnap: number): number;
|
321 | function snap(snapConfig: number | number[] | SnapNumberConfig): (valueToSnap: number) => number;
|
322 | /**
|
323 | * Snaps a value if within the given radius of a points (objects with "x" and "y" properties).
|
324 | * Or returns a function that does the above (if the second value is not provided).
|
325 | *
|
326 | * ```js
|
327 | *
|
328 | * gsap.utils.snap({values:[0, 100, 300], radius:20}, 85);
|
329 | *
|
330 | * const snap = gsap.utils.snap({values:[{x:0, y:0}, {x:10, y:10}, {x:20, y:20}], radius:5});
|
331 | * console.log( snap({x:8, y:8}) );
|
332 | * ```
|
333 | *
|
334 | * @param {SnapPoint2DConfig} snapConfig
|
335 | * @param {number} [valueToSnap]
|
336 | * @returns {Point2D | Function} The snapped number or snap function
|
337 | * @memberof gsap.utils
|
338 | */
|
339 | function snap(snapConfig: SnapPoint2DConfig, valueToSnap: Point2D): Point2D;
|
340 | function snap(snapConfig: SnapPoint2DConfig): (valueToSnap: Point2D) => Point2D;
|
341 |
|
342 | /**
|
343 | * Converts a string-based color value into an array consisting of RGB(A) or HSL values.
|
344 | *
|
345 | * ```js
|
346 | * gsap.utils.splitColor("red");
|
347 | * gsap.utils.splitColor("rgba(204, 153, 51, 0.5)");
|
348 | *
|
349 | * gsap.utils.splitColor("#6fb936", true);
|
350 | * ```
|
351 | *
|
352 | * @param {string} color
|
353 | * @param {boolean} [hsl]
|
354 | * @returns {[number, number, number] | [number, number, number, number]} The converted color array
|
355 | * @memberof gsap.utils
|
356 | */
|
357 | function splitColor(color: string, hsl?: boolean): [number, number, number] | [number, number, number, number];
|
358 |
|
359 | /**
|
360 | * Converts almost any array-like object into a flat Array.
|
361 | *
|
362 | * ```js
|
363 | * var targets = gsap.utils.toArray(".class");
|
364 | * var targets = gsap.utils.toArray(myElement);
|
365 | * var targets = gsap.utils.toArray($(".class"));
|
366 | * var targets = gsap.utils.toArray(document.querySelectorAll(".class1"), ".class2", rawElement);
|
367 | * ```
|
368 | *
|
369 | * @param {toArrayValue} value
|
370 | * @param {boolean} [leaveStrings]
|
371 | * @returns {T[]} The converted array
|
372 | * @memberof gsap.utils
|
373 | */
|
374 | function toArray<T>(value: toArrayValue, leaveStrings?: boolean): T[];
|
375 | function toArray<T>(value1: toArrayValue, value2: toArrayValue, leaveStrings?: boolean): T[];
|
376 | function toArray<T>(value1: toArrayValue, value2: toArrayValue, value3: toArrayValue, leaveStrings?: boolean): T[];
|
377 | function toArray<T>(value1: toArrayValue, value2: toArrayValue, value3: toArrayValue, value4: toArrayValue, leaveStrings?: boolean): T[];
|
378 | function toArray<T>(value1: toArrayValue, value2: toArrayValue, value3: toArrayValue, value4: toArrayValue, value5: toArrayValue, leaveStrings?: boolean): T[];
|
379 |
|
380 | /**
|
381 | * Ensures that a specific unit gets applied.
|
382 | *
|
383 | * ```js
|
384 | * const clamp = gsap.utils.unitize( gsap.utils.clamp(0, 100), "px");
|
385 | * clamp(132);
|
386 | *
|
387 | * gsap.to(".class", {
|
388 | * x: 1000,
|
389 | * modifiers: {
|
390 | * x: gsap.utils.unitize( gsap.utils.wrap(0, window.innerWidth), "px")
|
391 | * }
|
392 | * });
|
393 | * ```
|
394 | *
|
395 | * @param {Function} fn
|
396 | * @param {string} [unit]
|
397 | * @returns {string} The value with unit added
|
398 | * @memberof gsap.utils
|
399 | */
|
400 | function unitize<T extends Array<unknown>>(fn: (...args: T) => unknown, unit?: string): (...args: T) => string;
|
401 |
|
402 | /**
|
403 | * Returns the next number in a range after the given index, jumping to the start after the end has been reached.
|
404 | *
|
405 | * ```js
|
406 | * let color = gsap.utils.wrap(["red", "green", "yellow"], 5);
|
407 | *
|
408 | * let wrapper = gsap.utils.wrap(["red", "green", "yellow"]);
|
409 | * let color = wrapper(5)
|
410 | * ```
|
411 | *
|
412 | * @param {number} value1
|
413 | * @param {number} value2
|
414 | * @param {number} [index]
|
415 | * @returns {string} The wrapped value or wrap function
|
416 | * @memberof gsap.utils
|
417 | */
|
418 | function wrap(value1: number, value2: number, index: number): number;
|
419 | function wrap(value1: number, value2: number): (index: number) => number;
|
420 | /**
|
421 | * Returns the next item in an array after the given index, jumping to the start after the end has been reached.
|
422 | *
|
423 | * ```js
|
424 | * let color = gsap.utils.wrap(["red", "green", "yellow"], 5);
|
425 | *
|
426 | * let wrapper = gsap.utils.wrap(["red", "green", "yellow"]);
|
427 | * let color = wrapper(5)
|
428 | * ```
|
429 | *
|
430 | * @param {T[]} values
|
431 | * @param {number} [index]
|
432 | * @returns {string} The wrapper value or wrap function
|
433 | * @memberof gsap.utils
|
434 | */
|
435 | function wrap<T>(values: T[], index: number): T;
|
436 | function wrap<T>(values: T[]): (index: number) => T;
|
437 |
|
438 | /**
|
439 | * Returns the next number in a range after the given index, wrapping backwards towards the start after the end has been reached.
|
440 | *
|
441 | * ```js
|
442 | * let color = gsap.utils.wrap(["red", "green", "yellow"], 5);
|
443 | *
|
444 | * let wrapper = gsap.utils.wrap(["red", "green", "yellow"]);
|
445 | * let color = wrapper(5)
|
446 | * ```
|
447 | *
|
448 | * @param {number} value1
|
449 | * @param {number} value2
|
450 | * @param {number} [index]
|
451 | * @returns {string} The wrapped value or wrap function
|
452 | * @memberof gsap.utils
|
453 | */
|
454 | function wrapYoyo(value1: number, value2: number, index: number): number;
|
455 | function wrapYoyo(value1: number, value2: number): (index: number) => number;
|
456 | /**
|
457 | * Returns the next item in an array after the given index, wrapping backwards towards the start after the end has been reached.
|
458 | *
|
459 | * ```js
|
460 | * let color = gsap.utils.wrap(["red", "green", "yellow"], 5);
|
461 | *
|
462 | * let wrapper = gsap.utils.wrap(["red", "green", "yellow"]);
|
463 | * let color = wrapper(5)
|
464 | * ```
|
465 | *
|
466 | * @param {T[]} values
|
467 | * @param {number} [index]
|
468 | * @returns {string} The wrapper value or wrap function
|
469 | * @memberof gsap.utils
|
470 | */
|
471 | function wrapYoyo<T>(values: T[], index: number): T;
|
472 | function wrapYoyo<T>(values: T[]): (index: number) => T;
|
473 | }
|
474 |
|
475 | declare module "gsap/gsap-core" {
|
476 | export const clamp: typeof gsap.utils.clamp;
|
477 | export const distribute: typeof gsap.utils.distribute;
|
478 | export const getUnit: typeof gsap.utils.getUnit;
|
479 | export const interpolate: typeof gsap.utils.interpolate;
|
480 | export const mapRange: typeof gsap.utils.mapRange;
|
481 | export const normalize: typeof gsap.utils.normalize;
|
482 | export const pipe: typeof gsap.utils.pipe;
|
483 | export const random: typeof gsap.utils.random;
|
484 | export const shuffle: typeof gsap.utils.shuffle;
|
485 | export const snap: typeof gsap.utils.snap;
|
486 | export const splitColor: typeof gsap.utils.splitColor;
|
487 | export const toArray: typeof gsap.utils.toArray;
|
488 | export const unitize: typeof gsap.utils.unitize;
|
489 | export const wrap: typeof gsap.utils.wrap;
|
490 | export const wrapYoyo: typeof gsap.utils.wrapYoyo;
|
491 | }
|
492 |
|
\ | No newline at end of file |