toosoon-utils 4.2.3 → 4.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.
Files changed (42) hide show
  1. package/README.md +499 -575
  2. package/lib/colors.d.ts +147 -66
  3. package/lib/colors.js +149 -63
  4. package/lib/constants.js +1 -1
  5. package/lib/dom.d.ts +1 -1
  6. package/lib/dom.js +1 -1
  7. package/lib/extras/colors/Color.d.ts +406 -0
  8. package/lib/extras/colors/Color.js +546 -0
  9. package/lib/extras/colors/ColorPalette.d.ts +105 -0
  10. package/lib/extras/colors/ColorPalette.js +124 -0
  11. package/lib/extras/colors/ColorScale.d.ts +257 -0
  12. package/lib/extras/colors/ColorScale.js +347 -0
  13. package/lib/extras/colors/_ColorScale.d.ts +62 -0
  14. package/lib/extras/colors/_ColorScale.js +156 -0
  15. package/lib/extras/colors/index.d.ts +3 -0
  16. package/lib/extras/colors/index.js +3 -0
  17. package/lib/extras/frame-rate/FrameRate.d.ts +1 -1
  18. package/lib/extras/frame-rate/FrameRate.js +2 -2
  19. package/lib/extras/geometry/Vector.d.ts +1 -1
  20. package/lib/extras/geometry/Vector2.d.ts +17 -11
  21. package/lib/extras/geometry/Vector2.js +29 -23
  22. package/lib/extras/geometry/Vector3.d.ts +5 -5
  23. package/lib/extras/geometry/Vector3.js +10 -10
  24. package/lib/extras/paths/Path.d.ts +3 -3
  25. package/lib/extras/paths/Path.js +10 -10
  26. package/lib/extras/paths/PathContext.d.ts +5 -10
  27. package/lib/extras/paths/PathContext.js +70 -99
  28. package/lib/extras/paths/PathSVG.d.ts +31 -25
  29. package/lib/extras/paths/PathSVG.js +36 -39
  30. package/lib/extras/paths/index.d.ts +1 -1
  31. package/lib/geometry.js +1 -1
  32. package/lib/maths.d.ts +19 -13
  33. package/lib/maths.js +23 -17
  34. package/lib/prng.d.ts +4 -4
  35. package/lib/prng.js +4 -4
  36. package/lib/random.d.ts +4 -4
  37. package/lib/random.js +4 -4
  38. package/lib/strings.d.ts +14 -8
  39. package/lib/strings.js +14 -8
  40. package/lib/tsconfig.tsbuildinfo +1 -1
  41. package/lib/types.d.ts +15 -8
  42. package/package.json +14 -14
package/README.md CHANGED
@@ -26,689 +26,849 @@ import { lerp } from 'toosoon-utils/maths';
26
26
  console.log(lerp(0.5, 0, 5)); // 2.5
27
27
  ```
28
28
 
29
+ ## Summary
30
+
31
+ - [Utility functions](#utility-functions)
32
+ - [Maths](#maths-functions)
33
+ - [Geometry](#geometry-functions)
34
+ - [Colors](#colors-functions)
35
+ - [Functions](#functions-functions)
36
+ - [Strings](#strings-functions)
37
+ - [Query](#query-functions)
38
+ - [DOM](#dom-functions)
39
+ - [Files](#files-functions)
40
+ - [Random](#random-functions)
41
+ - [PRNG](#prng-functions)
42
+ - [Utility classes](#utility-classes)
43
+ - [Geometry](#geometry-classes)
44
+ - [Curves](#curves-classes)
45
+ - [Paths](#paths-classes)
46
+ - [Colors](#colors-classes)
47
+ - [FrameRate](#frame-rate-class)
48
+ - [Constants](#constants)
49
+ - [License](#license)
50
+
29
51
  ## Utility functions
30
52
 
31
- ### Colors
53
+ ### Maths <a id="maths-functions"></a>
32
54
 
33
- ##### normalizeHexString(hex)
55
+ ##### isEven(value)
34
56
 
35
- Normalize an hexadecimal string.
57
+ Check if a number is even.
36
58
 
37
- - `hex`: Hexadecimal string.
59
+ - `value`: Value to check.
38
60
 
39
61
  ```ts
40
- normalizeHexString(hex: string): string;
62
+ isEven(value: number): boolean;
41
63
  ```
42
64
 
43
- ##### rgbToHex(rgb)
65
+ ##### isOdd(value)
44
66
 
45
- Convert RGB to hexadecimal.
67
+ Check if a number is odd.
46
68
 
47
- - `rgb`: RGB color.
69
+ - `value`: Value to check.
48
70
 
49
71
  ```ts
50
- rgbToHex([r, g, b]: [number, number, number]): number;
72
+ isOdd(value: number): boolean;
51
73
  ```
52
74
 
53
- ##### rgbToHexString(rgb)
75
+ ##### isPowerOf2(value)
54
76
 
55
- Convert RGB to hexadecimal string.
77
+ Check if a number is a power of 2.
56
78
 
57
- - `rgb`: RGB color.
79
+ - `value`: Value to check.
58
80
 
59
81
  ```ts
60
- rgbToHexString([r, g, b]: [number, number, number]): string;
82
+ isPowerOf2(value: number): boolean;
61
83
  ```
62
84
 
63
- ##### hexToRgb(hex)
85
+ ##### toPowerOf2(value)
64
86
 
65
- Convert hexadecimal to RGB.
87
+ Find closest power of 2 that fits a number.
66
88
 
67
- - `hex`: Hexadecimal color.
89
+ - `value`: Incoming value.
90
+ - `[mode='ceil']`: Can be `'floor'`, `'ceil'` or `'round'`.
68
91
 
69
92
  ```ts
70
- hexToRgb(hex: number | string): [number, number, number];
93
+ toPowerOf2(value: number, mode?: string): number;
71
94
  ```
72
95
 
73
- ##### lighten(hex, amount)
96
+ ##### sign(value)
74
97
 
75
- Lighten a color.
98
+ Return the sign (positive or negative) of a number.
76
99
 
77
- - `hex`: Hexadecimal color.
78
- - `[amount=0]`: Amount of the color offset.
100
+ - `value`: Value to check.
79
101
 
80
102
  ```ts
81
- lighten(hex: string, amount?: number): string;
103
+ sign(value: number): number;
82
104
  ```
83
105
 
84
- ##### darken(hex, amount)
106
+ ##### clamp(value, min, max)
85
107
 
86
- Darken a color.
108
+ Clamp a value between two bounds.
87
109
 
88
- - `hex`: Hexadecimal color.
89
- - `[amount=0]`: Amount of the color offset.
110
+ - `value`: Value to clamp.
111
+ - `[min=0]`: Minimum boundary.
112
+ - `[max=1]`: Maximum boundary.
90
113
 
91
114
  ```ts
92
- darken(hex: string, amount?: number): string;
115
+ clamp(value: number, min?: number, max?: number): number;
93
116
  ```
94
117
 
95
- ##### normalizeHslString(hsl)
118
+ ##### snap(value, multiple)
96
119
 
97
- Normalize an HSL string.
120
+ Round a number up to a nearest multiple.
98
121
 
99
- - `hsl`: HSL string (format: `'hsl(360, 100%, 100%)'`).
122
+ - `value`: Value to round.
123
+ - `[multiple=1]`: Multiple to round to.
100
124
 
101
125
  ```ts
102
- normalizeHslString(hsl: string): [number, number, number];
126
+ snap(value: number, multiple?: number): number;
103
127
  ```
104
128
 
105
- ##### rgbToHsl(rgb)
129
+ ##### lerp(t, min, max)
106
130
 
107
- Convert RGB to HSL.
131
+ Interpolate a value between two values using Linear interpolation (lerping).
108
132
 
109
- - `rgb`: RGB color.
133
+ - `t`: Normalized time value to interpolate.
134
+ - `min`: Minimum value.
135
+ - `max`: Maximum value.
110
136
 
111
137
  ```ts
112
- rgbToHsl([r, g, b]: [number, number, number]): [number, number, number];
138
+ lerp(t: number, min: number, max: number): number;
113
139
  ```
114
140
 
115
- ##### hslToRgb(hsl)
141
+ ##### normalize(value, min, max)
116
142
 
117
- Convert HSL to RGB.
143
+ Normalize a value between two bounds.
118
144
 
119
- - `hsl`: HSL color.
145
+ - `value`: Value to normalize.
146
+ - `min`: Minimum boundary.
147
+ - `max`: Maximum boundary.
120
148
 
121
149
  ```ts
122
- hslToRgb([h, s, l]: [number, number, number]): [number, number, number];
150
+ normalize(value: number, min: number, max: number): number;
123
151
  ```
124
152
 
125
- ##### rgbToHsb(rgb)
153
+ ##### map(value, currentMin, currentMax, targetMin, targetMax)
126
154
 
127
- Convert RGB to HSB.
155
+ Re-map a number from one range to another.
128
156
 
129
- - `rgb`: RGB color.
157
+ - `value`: Value to re-map.
158
+ - `currentMin`: Lower bound of the value's current range.
159
+ - `currentMax`: Upper bound of the value's current range.
160
+ - `targetMin`: Lower bound of the value's target range.
161
+ - `targetMax`: Upper bound of the value's target range.
130
162
 
131
163
  ```ts
132
- rgbToHsb([r, g, b]: [number, number, number]): [number, number, number];
164
+ map(value: number, currentMin: number, currentMax: number, targetMin: number, targetMax: number): number;
133
165
  ```
134
166
 
135
- ##### hsbToRgb(hsb)
167
+ ##### triLerp(t, min, max, peak)
136
168
 
137
- Convert HSB to RGB.
169
+ Interpolate a value between two values using Triangular interpolation.
138
170
 
139
- - `hsb`: HSB color.
171
+ - `t`: Normalized time value to interpolate.
172
+ - `min`: Minimum value.
173
+ - `max`: Maximum value.
174
+ - `peak`: Peak value controling the interpolation triangle shape.
140
175
 
141
176
  ```ts
142
- hsbToRgb([h, s, b]: [number, number, number]): [number, number, number];
177
+ triLerp(t: number, min: number, max: number, peak: number): number;
143
178
  ```
144
179
 
145
- ##### labToHcl(lab)
180
+ ##### expLerp(t, min, max, exponent)
146
181
 
147
- Convert LAB to HCL.
182
+ Interpolate a value using Exponential interpolation.
148
183
 
149
- - `lab`: LAB color.
184
+ - `t`: Normalized time value to interpolate.
185
+ - `min`: Minimum value.
186
+ - `max`: Maximum value.
187
+ - `power`: Exponent controling the interpolation curve shape.
150
188
 
151
189
  ```ts
152
- labToHcl([l, a, b]: [number, number, number]): [number, number, number];
190
+ expLerp(t: number, min: number, max: number, power: number): number;
153
191
  ```
154
192
 
155
- ##### hclToLab(hcl)
193
+ ##### quadraticBezier(t, p1, cp, p2)
156
194
 
157
- Convert HCL to LAB.
195
+ Interpolate a value using Quadratic Bézier interpolation.
158
196
 
159
- - `hcl`: HCL color.
197
+ - `t`: Normalized time value to interpolate.
198
+ - `p1`: Start point.
199
+ - `cp`: Control point.
200
+ - `p2`: End point.
160
201
 
161
202
  ```ts
162
- hclToLab([h, c, l]: [number, number, number]): [number, number, number];
203
+ quadraticBezier(t: number, p1: number, cp: number, p2: number): number;
163
204
  ```
164
205
 
165
- ##### labToRgb(lab)
206
+ ##### cubicBezier(t, p1, cp1, cp2, p2)
166
207
 
167
- Convert LAB to RGB.
208
+ Interpolate a value using Cubic Bézier interpolation.
168
209
 
169
- - `lab`: LAB color.
210
+ - `t`: Normalized time value to interpolate.
211
+ - `p1`: Start point.
212
+ - `cp1`: First control point.
213
+ - `cp2`: Second control point.
214
+ - `p2`: End point.
170
215
 
171
216
  ```ts
172
- labToRgb([l, a, b]: [number, number, number]): [number, number, number];
217
+ cubicBezier(t: number, p1: number, cp1: number, cp2: number, p2: number): number;
173
218
  ```
174
219
 
175
- ##### rgbToLab(rgb)
220
+ ##### catmullRom(t, p1, cp1, cp2, p2)
176
221
 
177
- Convert RGB to LAB.
222
+ Interpolate a value using Catmull-Rom interpolation.
178
223
 
179
- - `rgb`: RGB color.
224
+ - `t`: Normalized time value to interpolate.
225
+ - `p1`: Start point.
226
+ - `cp1`: First control point.
227
+ - `cp2`: Second control point.
228
+ - `p2`: End point.
180
229
 
181
230
  ```ts
182
- rgbToLab([r, g, b]: [number, number, number]): [number, number, number];
231
+ catmullRom(t: number, p1: number, cp1: number, cp2: number, p2: number): number;
183
232
  ```
184
233
 
185
- ##### deltaE(labA, labB)
234
+ ##### modAbs(value, length)
186
235
 
187
- Get the delta from two LAB colors.
236
+ Modulo absolute a value based on a length.
188
237
 
189
- - `labA`: First LAB color.
190
- - `labB`: Second LAB color.
238
+ - `value`: Value to modulate.
239
+ - `length`: Total length.
191
240
 
192
241
  ```ts
193
- deltaE(labA: [number, number, number], labB: [number, number, number]): number;
242
+ modAbs(value: number, length: number): number;
194
243
  ```
195
244
 
196
- ##### rgbToHcl(rgb)
245
+ ##### pingPong(value, length)
197
246
 
198
- Convert RGB to HCL.
247
+ Move back and forth a value between 0 and length, so that it is never larger than length and never smaller than 0.
199
248
 
200
- - `rgb`: RGB color.
249
+ - `value`: Value to modulate.
250
+ - `length`: Total length.
201
251
 
202
252
  ```ts
203
- rgbToHcl([r, g, b]: [number, number, number]): [number, number, number];
253
+ pingPong(value: number, length: number): number;
204
254
  ```
205
255
 
206
- ##### hclToRgb(hcl)
256
+ ##### smoothstep(value, min, max)
207
257
 
208
- Convert HCL to RGB.
258
+ Smooth a value using cubic Hermite interpolation.
209
259
 
210
- - `hcl`: HCL color.
260
+ - `value`: Value to smooth.
261
+ - `[min=0]`: Minimum boundary.
262
+ - `[max=1]`: Maximum boundary.
211
263
 
212
264
  ```ts
213
- hclToRgb([h, c, l]: [number, number, number]): [number, number, number];
265
+ smoothstep(value: number, min?: number, max?: number): number;
214
266
  ```
215
267
 
216
- ### DOM
217
-
218
- ##### closest(element, selector)
268
+ ##### parabola(x, power)
219
269
 
220
- Find the closest parent that matches a selector.
270
+ Re-map the [0, 1] interval into [0, 1] parabola, such that corners are remaped to 0 and the center to 1.
221
271
 
222
- - `element`: Target element.
223
- - `selector`: Selector or parent to match.
272
+ - `x`: Normalized coordinate on X axis.
273
+ - `[power=1]`: Parabola power.
224
274
 
225
275
  ```ts
226
- closest(element: Element | null, selector: Element | string): Element | null;
276
+ parabola(x: number, power?: number): number;
227
277
  ```
228
278
 
229
- ##### createCanvas(width, height)
279
+ ##### sum(array)
230
280
 
231
- Create a canvas and 2d context.
281
+ Return the sum of numbers.
232
282
 
233
- - `width`: Width of the canvas.
234
- - `height`: Height of the canvas.
283
+ - `array`: Array of numbers.
235
284
 
236
285
  ```ts
237
- createCanvas(width: number, height: number): { canvas: HTMLCanvasElement; ctx: CanvasRenderingContext2D };
286
+ sum(array: number[]): number;
238
287
  ```
239
288
 
240
- ##### injectStyles(styles)
289
+ ##### average(array)
241
290
 
242
- Inject CSS styles in `document.head`.
291
+ Return the average of numbers.
243
292
 
244
- - `styles`: CSS styles to inject.
293
+ - `array`: Array of numbers.
245
294
 
246
295
  ```ts
247
- injectStyles(styles: string): void;
296
+ average(array: number[]): number;
248
297
  ```
249
298
 
250
- ### Files
251
-
252
- ##### download(blob, filename)
299
+ ##### damp(value, target, damping, delta)
253
300
 
254
- Download a Blob object into user files.
301
+ Smoothly interpolate a number toward another.
255
302
 
256
- - `blob`: Blob object to download.
257
- - `filename`: Downloaded file name.
303
+ - `value`: Value to interpolate.
304
+ - `target`: Destination of the interpolation.
305
+ - `damping`: A higher value will make the movement more sudden, and a lower value will make the movement more gradual.
306
+ - `delta`: Delta time (in seconds).
258
307
 
259
308
  ```ts
260
- download(blob: Blob, filename: string): void;
309
+ damp(value: number, target: number, damping: number, delta: number): number;
261
310
  ```
262
311
 
263
- ##### upload(onLoad)
312
+ ### Geometry <a id="geometry-functions"></a>
264
313
 
265
- Upload a file from user files.
314
+ ##### toDegrees(radians)
266
315
 
267
- - `onLoad`: Callback called once the file is loaded.
268
- - `[accept='']` MIME type the file input should accept.
316
+ Convert a radians value into degrees.
317
+
318
+ - `radians`: Angle in radians.
269
319
 
270
320
  ```ts
271
- upload(onLoad: (dataUrl: string) => void, accept?: string): void;
321
+ toDegrees(radians: number): number;
272
322
  ```
273
323
 
274
- ### Functions
324
+ ##### toRadians(degrees)
275
325
 
276
- ##### noop()
326
+ Convert a degrees value into radians.
277
327
 
278
- No-op function.
328
+ - `degrees`: Angle in degrees.
279
329
 
280
330
  ```ts
281
- noop(): void;
331
+ toRadians(degrees: number): number;
282
332
  ```
283
333
 
284
- ##### wait(delay)
334
+ ##### angle(x1, y1, x2, y2)
285
335
 
286
- Promise wrapped setTimeout.
336
+ Calculate the angle from a point to another.
287
337
 
288
- - `[delay=0]`: Time to wait (in milliseconds).
338
+ - `x1`: X value of the first point.
339
+ - `y1`: Y value of the first point.
340
+ - `x2`: X value of the second point.
341
+ - `y2`: Y value of the second point.
289
342
 
290
343
  ```ts
291
- wait(delay?: number): Promise<void>;
344
+ angle(x1: number, y1: number, x2: number, y2: number): number;
292
345
  ```
293
346
 
294
- ##### isDefined(value)
347
+ ##### closestAngle(source, target)
295
348
 
296
- Check if a value is defined.
349
+ Find the closest angle between to angles.
297
350
 
298
- - `value`: Value to check.
351
+ - `source`: Source angle (in radians).
352
+ - `target`: Target angle (in radians).
299
353
 
300
354
  ```ts
301
- isDefined(value: any): boolean;
355
+ closestAngle(source: number, target: number): number;
302
356
  ```
303
357
 
304
- ##### debounce(callback, delay)
358
+ ##### distance(x1, y1, x2, y2)
305
359
 
306
- Create a debounced function that delays the execution of `callback` until a specified `delay` time has passed since the last call.
360
+ Calculate the distance between two points.
307
361
 
308
- - `callback`: Function to debounce.
309
- - `delay`: Delay (in milliseconds).
362
+ - `x1`: X-axis coordinate of the first point.
363
+ - `y1`: Y-axis coordinate of the first point.
364
+ - `x2`: X-axis coordinate of the second point.
365
+ - `y2`: Y-axis coordinate of the second point.
310
366
 
311
367
  ```ts
312
- debounce(callback: Function, delay: number): Function;
368
+ distance(x1: number, y1: number, x2: number, y2: number): number;
313
369
  ```
314
370
 
315
- ##### throttle(callback, limit)
371
+ ##### diagonal(width, height)
316
372
 
317
- Create a throttled function that limits the execution of `callback` to once every `limit` time.
373
+ Calculate the length of the diagonal of a rectangle.
318
374
 
319
- - `callback`: Function to throttle.
320
- - `limit`: Minimum interval between two calls (in milliseconds).
375
+ - `width`: Width of the rectangle.
376
+ - `height`: Height of the rectangle.
321
377
 
322
378
  ```ts
323
- throttle(callback: Function, limit: number): Function;
379
+ diagonal(width: number, height: number): number;
324
380
  ```
325
381
 
326
- ##### defer()
382
+ #### Fit
327
383
 
328
- Deferred promise implementation.
384
+ ```ts
385
+ type FitInput = {
386
+ width: number;
387
+ height: number;
388
+ };
389
+
390
+ type FitOutput = {
391
+ left: number;
392
+ top: number;
393
+ width: number;
394
+ height: number;
395
+ scale: number;
396
+ };
397
+ ```
398
+
399
+ ##### cover(target, container)
400
+
401
+ Make a target fit a container (cover mode).
402
+
403
+ - `target`: Dimension of the target.
404
+ - `container`: Dimension of the container.
329
405
 
330
406
  ```ts
331
- defer<T>(): Deferred<T>;
407
+ cover(target: FitInput, container: FitInput): FitOutput;
332
408
  ```
333
409
 
334
- ##### now()
410
+ ##### contain(target, container)
335
411
 
336
- Polyfill for `now()` functions.
412
+ Make a target fit a container (contain mode).
413
+
414
+ - `target`: Dimension of the target.
415
+ - `container`: Dimension of the container.
337
416
 
338
417
  ```ts
339
- now(): number;
418
+ contain(target: FitInput, container: FitInput): FitOutput;
340
419
  ```
341
420
 
342
- ### Geometry
421
+ ### Colors <a id="colors-functions"></a>
343
422
 
344
- ##### toDegrees(radians)
423
+ ##### normalizeHexString(hex)
345
424
 
346
- Convert a radians value into degrees.
425
+ Normalize an hexadecimal string.
347
426
 
348
- - `radians`: Angle in radians.
427
+ - `hex`: Hexadecimal string.
349
428
 
350
429
  ```ts
351
- toDegrees(radians: number): number;
430
+ normalizeHexString(hex: string): string;
352
431
  ```
353
432
 
354
- ##### toRadians(degrees)
433
+ ##### rgbToHex(rgb)
355
434
 
356
- Convert a degrees value into radians.
435
+ Convert RGB to hexadecimal.
357
436
 
358
- - `degrees`: Angle in degrees.
437
+ - `rgb`: RGB color.
359
438
 
360
439
  ```ts
361
- toRadians(degrees: number): number;
440
+ rgbToHex([r, g, b]: [number, number, number]): number;
362
441
  ```
363
442
 
364
- ##### angle(x1, y1, x2, y2)
443
+ ##### rgbToHexString(rgb)
365
444
 
366
- Calculate the angle from a point to another.
445
+ Convert RGB to hexadecimal string.
367
446
 
368
- - `x1`: X value of the first point.
369
- - `y1`: Y value of the first point.
370
- - `x2`: X value of the second point.
371
- - `y2`: Y value of the second point.
447
+ - `rgb`: RGB color.
372
448
 
373
449
  ```ts
374
- angle(x1: number, y1: number, x2: number, y2: number): number;
450
+ rgbToHexString([r, g, b]: [number, number, number]): string;
375
451
  ```
376
452
 
377
- ##### closestAngle(source, target)
453
+ ##### hexToRgb(hex)
378
454
 
379
- Find the closest angle between to angles.
455
+ Convert hexadecimal to RGB.
380
456
 
381
- - `source`: Source angle (in radians).
382
- - `target`: Target angle (in radians).
457
+ - `hex`: Hexadecimal color.
383
458
 
384
459
  ```ts
385
- closestAngle(source: number, target: number): number;
460
+ hexToRgb(hex: number | string): [number, number, number];
386
461
  ```
387
462
 
388
- ##### distance(x1, y1, x2, y2)
463
+ ##### lighten(hex, amount)
389
464
 
390
- Calculate the distance between two points.
465
+ Lighten a color.
391
466
 
392
- - `x1`: X-axis coordinate of the first point.
393
- - `y1`: Y-axis coordinate of the first point.
394
- - `x2`: X-axis coordinate of the second point.
395
- - `y2`: Y-axis coordinate of the second point.
467
+ - `hex`: Hexadecimal color.
468
+ - `[amount=0]`: Amount of the color offset.
396
469
 
397
470
  ```ts
398
- distance(x1: number, y1: number, x2: number, y2: number): number;
471
+ lighten(hex: string, amount?: number): string;
399
472
  ```
400
473
 
401
- ##### diagonal(width, height)
474
+ ##### darken(hex, amount)
402
475
 
403
- Calculate the length of the diagonal of a rectangle.
476
+ Darken a color.
404
477
 
405
- - `width`: Width of the rectangle.
406
- - `height`: Height of the rectangle.
478
+ - `hex`: Hexadecimal color.
479
+ - `[amount=0]`: Amount of the color offset.
407
480
 
408
481
  ```ts
409
- diagonal(width: number, height: number): number;
482
+ darken(hex: string, amount?: number): string;
410
483
  ```
411
484
 
412
- #### Fit
485
+ ##### normalizeHslString(hsl)
486
+
487
+ Normalize an HSL string.
488
+
489
+ - `hsl`: HSL string (format: `'hsl(360, 100%, 100%)'`).
413
490
 
414
491
  ```ts
415
- type FitInput = {
416
- width: number;
417
- height: number;
418
- };
492
+ normalizeHslString(hsl: string): [number, number, number];
493
+ ```
419
494
 
420
- type FitOutput = {
421
- left: number;
422
- top: number;
423
- width: number;
424
- height: number;
425
- scale: number;
426
- };
495
+ ##### rgbToHsl(rgb)
496
+
497
+ Convert RGB to HSL.
498
+
499
+ - `rgb`: RGB color.
500
+
501
+ ```ts
502
+ rgbToHsl([r, g, b]: [number, number, number]): [number, number, number];
427
503
  ```
428
504
 
429
- ##### cover(target, container)
505
+ ##### hslToRgb(hsl)
430
506
 
431
- Make a target fit a container (cover mode).
507
+ Convert HSL to RGB.
432
508
 
433
- - `target`: Dimension of the target.
434
- - `container`: Dimension of the container.
509
+ - `hsl`: HSL color.
435
510
 
436
511
  ```ts
437
- cover(target: FitInput, container: FitInput): FitOutput;
512
+ hslToRgb([h, s, l]: [number, number, number]): [number, number, number];
438
513
  ```
439
514
 
440
- ##### contain(target, container)
515
+ ##### rgbToHsb(rgb)
441
516
 
442
- Make a target fit a container (contain mode).
517
+ Convert RGB to HSB.
443
518
 
444
- - `target`: Dimension of the target.
445
- - `container`: Dimension of the container.
519
+ - `rgb`: RGB color.
446
520
 
447
521
  ```ts
448
- contain(target: FitInput, container: FitInput): FitOutput;
522
+ rgbToHsb([r, g, b]: [number, number, number]): [number, number, number];
449
523
  ```
450
524
 
451
- ### Maths
525
+ ##### hsbToRgb(hsb)
452
526
 
453
- ##### isEven(value)
527
+ Convert HSB to RGB.
454
528
 
455
- Check if a number is even.
529
+ - `hsb`: HSB color.
456
530
 
457
- - `value`: Value to check.
531
+ ```ts
532
+ hsbToRgb([h, s, b]: [number, number, number]): [number, number, number];
533
+ ```
534
+
535
+ ##### labToHcl(lab)
536
+
537
+ Convert LAB to HCL.
538
+
539
+ - `lab`: LAB color.
458
540
 
459
541
  ```ts
460
- isEven(value: number): boolean;
542
+ labToHcl([l, a, b]: [number, number, number]): [number, number, number];
461
543
  ```
462
544
 
463
- ##### isOdd(value)
545
+ ##### hclToLab(hcl)
464
546
 
465
- Check if a number is odd.
547
+ Convert HCL to LAB.
466
548
 
467
- - `value`: Value to check.
549
+ - `hcl`: HCL color.
468
550
 
469
551
  ```ts
470
- isOdd(value: number): boolean;
552
+ hclToLab([h, c, l]: [number, number, number]): [number, number, number];
471
553
  ```
472
554
 
473
- ##### isPowerOf2(value)
555
+ ##### labToRgb(lab)
474
556
 
475
- Check if a number is a power of 2.
557
+ Convert LAB to RGB.
476
558
 
477
- - `value`: Value to check.
559
+ - `lab`: LAB color.
478
560
 
479
561
  ```ts
480
- isPowerOf2(value: number): boolean;
562
+ labToRgb([l, a, b]: [number, number, number]): [number, number, number];
481
563
  ```
482
564
 
483
- ##### toPowerOf2(value)
565
+ ##### rgbToLab(rgb)
484
566
 
485
- Find closest power of 2 that fits a number.
567
+ Convert RGB to LAB.
486
568
 
487
- - `value`: Incoming value.
488
- - `[mode='ceil']`: Can be `'floor'`, `'ceil'` or `'round'`.
569
+ - `rgb`: RGB color.
489
570
 
490
571
  ```ts
491
- toPowerOf2(value: number, mode?: string): number;
572
+ rgbToLab([r, g, b]: [number, number, number]): [number, number, number];
492
573
  ```
493
574
 
494
- ##### sign(value)
575
+ ##### deltaE(labA, labB)
495
576
 
496
- Return the sign (positive or negative) of a number.
577
+ Get the delta from two LAB colors.
578
+
579
+ - `labA`: First LAB color.
580
+ - `labB`: Second LAB color.
581
+
582
+ ```ts
583
+ deltaE(labA: [number, number, number], labB: [number, number, number]): number;
584
+ ```
585
+
586
+ ##### rgbToHcl(rgb)
587
+
588
+ Convert RGB to HCL.
589
+
590
+ - `rgb`: RGB color.
591
+
592
+ ```ts
593
+ rgbToHcl([r, g, b]: [number, number, number]): [number, number, number];
594
+ ```
595
+
596
+ ##### hclToRgb(hcl)
597
+
598
+ Convert HCL to RGB.
599
+
600
+ - `hcl`: HCL color.
601
+
602
+ ```ts
603
+ hclToRgb([h, c, l]: [number, number, number]): [number, number, number];
604
+ ```
605
+
606
+ ### Functions <a id="functions-functions"></a>
607
+
608
+ ##### noop()
609
+
610
+ No-op function.
611
+
612
+ ```ts
613
+ noop(): void;
614
+ ```
615
+
616
+ ##### wait(delay)
617
+
618
+ Promise wrapped setTimeout.
619
+
620
+ - `[delay=0]`: Time to wait (in milliseconds).
621
+
622
+ ```ts
623
+ wait(delay?: number): Promise<void>;
624
+ ```
625
+
626
+ ##### isDefined(value)
627
+
628
+ Check if a value is defined.
497
629
 
498
630
  - `value`: Value to check.
499
631
 
500
632
  ```ts
501
- sign(value: number): number;
633
+ isDefined(value: any): boolean;
502
634
  ```
503
635
 
504
- ##### clamp(value, min, max)
636
+ ##### debounce(callback, delay)
505
637
 
506
- Clamp a value between two bounds.
638
+ Create a debounced function that delays the execution of `callback` until a specified `delay` time has passed since the last call.
507
639
 
508
- - `value`: Value to clamp.
509
- - `[min=0]`: Minimum boundary.
510
- - `[max=1]`: Maximum boundary.
640
+ - `callback`: Function to debounce.
641
+ - `delay`: Delay (in milliseconds).
511
642
 
512
643
  ```ts
513
- clamp(value: number, min?: number, max?: number): number;
644
+ debounce(callback: Function, delay: number): Function;
514
645
  ```
515
646
 
516
- ##### snap(value, multiple)
647
+ ##### throttle(callback, limit)
517
648
 
518
- Round a number up to a nearest multiple.
649
+ Create a throttled function that limits the execution of `callback` to once every `limit` time.
519
650
 
520
- - `value`: Value to round.
521
- - `[multiple=1]`: Multiple to round to.
651
+ - `callback`: Function to throttle.
652
+ - `limit`: Minimum interval between two calls (in milliseconds).
522
653
 
523
654
  ```ts
524
- snap(value: number, multiple?: number): number;
655
+ throttle(callback: Function, limit: number): Function;
525
656
  ```
526
657
 
527
- ##### lerp(t, min, max)
658
+ ##### defer()
528
659
 
529
- Interpolate a value between two values using Linear interpolation (lerping).
660
+ Deferred promise implementation.
530
661
 
531
- - `t`: Normalized time value to interpolate.
532
- - `min`: Minimum value.
533
- - `max`: Maximum value.
662
+ ```ts
663
+ defer<T>(): Deferred<T>;
664
+ ```
665
+
666
+ ##### now()
667
+
668
+ Polyfill for `now()` functions.
534
669
 
535
670
  ```ts
536
- lerp(t: number, min: number, max: number): number;
671
+ now(): number;
537
672
  ```
538
673
 
539
- ##### normalize(value, min, max)
674
+ ### Strings <a id="strings-functions"></a>
540
675
 
541
- Normalize a value between two bounds.
676
+ #### Cases
542
677
 
543
- - `value`: Value to normalize.
544
- - `min`: Minimum boundary.
545
- - `max`: Maximum boundary.
678
+ ##### capitalize(string)
679
+
680
+ Capitalize a string.
681
+
682
+ - `string`: String to capitalize.
546
683
 
547
684
  ```ts
548
- normalize(value: number, min: number, max: number): number;
685
+ capitalize(string: string): string;
549
686
  ```
550
687
 
551
- ##### map(value, currentMin, currentMax, targetMin, targetMax)
688
+ ##### toKebabCase(string)
552
689
 
553
- Re-map a number from one range to another.
690
+ Convert a string to kebab-case: 'Hello world' -> 'hello-world'.
554
691
 
555
- - `value`: Value to re-map.
556
- - `currentMin`: Lower bound of the value's current range.
557
- - `currentMax`: Upper bound of the value's current range.
558
- - `targetMin`: Lower bound of the value's target range.
559
- - `targetMax`: Upper bound of the value's target range.
692
+ - `string`: String to convert.
560
693
 
561
694
  ```ts
562
- map(value: number, currentMin: number, currentMax: number, targetMin: number, targetMax: number): number;
695
+ toKebabCase(string: string): string;
563
696
  ```
564
697
 
565
- ##### triLerp(t, min, max, target)
698
+ ##### toSnakeCase(string)
566
699
 
567
- Interpolate a value between two values using Triangular interpolation.
700
+ Convert a string to snake_case: 'Hello world' -> 'hello_world'.
568
701
 
569
- - `t`: Normalized time value to interpolate.
570
- - `min`: Minimum value.
571
- - `max`: Maximum value.
572
- - `target`: Triangle target value.
702
+ - `string`: String to convert.
573
703
 
574
704
  ```ts
575
- triLerp(t: number, min: number, max: number, target: number): number;
705
+ toSnakeCase(string: string): string;
576
706
  ```
577
707
 
578
- ##### expLerp(t, currentMin, currentMax, targetMin, targetMax)
708
+ ##### toCamelCase(string)
579
709
 
580
- Interpolate a value using Exponential interpolation.
710
+ Convert a string to camelCase: 'Hello world' -> 'helloWorld'.
581
711
 
582
- - `t`: Normalized time value to interpolate.
583
- - `currentMin`: Lower bound of the value's current range.
584
- - `currentMax`: Upper bound of the value's current range.
585
- - `targetMin`: Lower bound of the value's target range.
586
- - `targetMax`: Upper bound of the value's target range.
712
+ - `string`: String to convert.
587
713
 
588
714
  ```ts
589
- expLerp(t: number, currentMin: number, currentMax: number, targetMin: number, targetMax: number): number;
715
+ toCamelCase(string: string): string;
590
716
  ```
591
717
 
592
- ##### quadraticBezier(t, p1, cp, p2)
718
+ ##### toPascalCase(string)
593
719
 
594
- Interpolate a value using Quadratic Bézier interpolation.
720
+ Convert a string to PascalCase: 'Hello world' -> 'HelloWorld'.
595
721
 
596
- - `t`: Normalized time value to interpolate.
597
- - `p1`: Start point.
598
- - `cp`: Control point.
599
- - `p2`: End point.
722
+ - `string`: String to convert.
600
723
 
601
724
  ```ts
602
- quadraticBezier(t: number, p1: number, cp: number, p2: number): number;
725
+ toPascalCase(string: string): string;
603
726
  ```
604
727
 
605
- ##### cubicBezier(t, p1, cp1, cp2, p2)
728
+ ##### toTrainCase(string)
606
729
 
607
- Interpolate a value using Cubic Bézier interpolation.
730
+ Convert a string to Train-Case: 'Hello world' -> 'Hello-World'.
608
731
 
609
- - `t`: Normalized time value to interpolate.
610
- - `p1`: Start point.
611
- - `cp1`: First control point.
612
- - `cp2`: Second control point.
613
- - `p2`: End point.
732
+ - `string`: String to convert.
614
733
 
615
734
  ```ts
616
- cubicBezier(t: number, p1: number, cp1: number, cp2: number, p2: number): number;
735
+ toTrainCase(string: string): string;
617
736
  ```
618
737
 
619
- ##### catmullRom(t, p1, cp1, cp2, p2)
738
+ ##### toConstantCase(string)
739
+
740
+ Convert a string to CONSTANT_CASE: 'Hello world' -> 'HELLO_WORLD'.
741
+
742
+ - `string`: String to convert.
743
+
744
+ ```ts
745
+ toConstantCase(string: string): string;
746
+ ```
747
+
748
+ #### Paths
749
+
750
+ ##### cleanPath(path)
751
+
752
+ Clean a path by removing its parameters.
753
+
754
+ - `path`: Path to clean.
755
+
756
+ ```ts
757
+ cleanPath(path: string): string;
758
+ ```
759
+
760
+ ##### addTrailingSlash(path)
761
+
762
+ Convert a path by ensuring it has a trailing slash.
763
+
764
+ - `path`: Path to convert.
765
+
766
+ ```ts
767
+ addTrailingSlash(path: string): string;
768
+ ```
769
+
770
+ ##### removeTrailingSlash(path)
771
+
772
+ Convert a path by ensuring it has not a trailing slash.
773
+
774
+ - `path`: Path to convert.
775
+
776
+ ```ts
777
+ removeTrailingSlash(path: string): string;
778
+ ```
779
+
780
+ ### Query parameters <a id="query-functions"></a>
781
+
782
+ ##### getQuery(property)
620
783
 
621
- Interpolate a value using Catmull-Rom interpolation.
784
+ Get a query parameter.
622
785
 
623
- - `t`: Normalized time value to interpolate.
624
- - `p1`: Start point.
625
- - `cp1`: First control point.
626
- - `cp2`: Second control point.
627
- - `p2`: End point.
786
+ - `property`: Query property to check.
628
787
 
629
788
  ```ts
630
- catmullRom(t: number, p1: number, cp1: number, cp2: number, p2: number): number;
789
+ getQuery(property: string): string | null;
631
790
  ```
632
791
 
633
- ##### modAbs(value, length)
792
+ ##### setQuery(property)
634
793
 
635
- Modulo absolute a value based on a length.
794
+ Set a query parameter.
636
795
 
637
- - `value`: Value to modulate.
638
- - `length`: Total length.
796
+ - `property`: Query property to set.
797
+ - `value`: Value to set.
639
798
 
640
799
  ```ts
641
- modAbs(value: number, length: number): number;
800
+ setQuery(property: string, value: string): void;
642
801
  ```
643
802
 
644
- ##### pingPong(value, length)
803
+ ##### hasQuery(property)
645
804
 
646
- Move back and forth a value between 0 and length, so that it is never larger than length and never smaller than 0.
805
+ Check if a query parameter exists.
647
806
 
648
- - `value`: Value to modulate.
649
- - `length`: Total length.
807
+ - `property`: Query property to check.
650
808
 
651
809
  ```ts
652
- pingPong(value: number, length: number): number;
810
+ hasQuery(property: string): boolean;
653
811
  ```
654
812
 
655
- ##### smoothstep(value, min, max)
813
+ ### DOM <a id="dom-functions"></a>
656
814
 
657
- Smooth a value using cubic Hermite interpolation.
815
+ ##### closest(element, selector)
658
816
 
659
- - `value`: Value to smooth.
660
- - `[min=0]`: Minimum boundary.
661
- - `[max=1]`: Maximum boundary.
817
+ Find the closest parent that matches a selector.
818
+
819
+ - `element`: Target element.
820
+ - `selector`: Selector or parent to match.
662
821
 
663
822
  ```ts
664
- smoothstep(value: number, min?: number, max?: number): number;
823
+ closest(element: Element | null, selector: Element | string): Element | null;
665
824
  ```
666
825
 
667
- ##### parabola(x, power)
826
+ ##### createCanvas(width, height)
668
827
 
669
- Re-map the [0, 1] interval into [0, 1] parabola, such that corners are remaped to 0 and the center to 1.
828
+ Create a canvas and 2d context.
670
829
 
671
- - `x`: Normalized coordinate on X axis.
672
- - `[power=1]`: Parabola power.
830
+ - `width`: Width of the canvas.
831
+ - `height`: Height of the canvas.
673
832
 
674
833
  ```ts
675
- parabola(x: number, power?: number): number;
834
+ createCanvas(width: number, height: number): { canvas: HTMLCanvasElement; ctx: CanvasRenderingContext2D };
676
835
  ```
677
836
 
678
- ##### sum(array)
837
+ ##### injectStyles(styles)
679
838
 
680
- Return the sum of numbers.
839
+ Inject CSS styles in `document.head`.
681
840
 
682
- - `array`: Array of numbers.
841
+ - `styles`: CSS styles to inject.
683
842
 
684
843
  ```ts
685
- sum(array: number[]): number;
844
+ injectStyles(styles: string): void;
686
845
  ```
687
846
 
688
- ##### average(array)
847
+ ### Files <a id="files-functions"></a>
689
848
 
690
- Return the average of numbers.
849
+ ##### download(blob, filename)
691
850
 
692
- - `array`: Array of numbers.
851
+ Download a Blob object into user files.
852
+
853
+ - `blob`: Blob object to download.
854
+ - `filename`: Downloaded file name.
693
855
 
694
856
  ```ts
695
- average(array: number[]): number;
857
+ download(blob: Blob, filename: string): void;
696
858
  ```
697
859
 
698
- ##### damp(value, target, damping, delta)
860
+ ##### upload(onLoad)
699
861
 
700
- Smoothly interpolate a number toward another.
862
+ Upload a file from user files.
701
863
 
702
- - `value`: Value to interpolate.
703
- - `target`: Destination of the interpolation.
704
- - `damping`: A higher value will make the movement more sudden, and a lower value will make the movement more gradual.
705
- - `delta`: Delta time (in seconds).
864
+ - `onLoad`: Callback called once the file is loaded.
865
+ - `[accept='']` MIME type the file input should accept.
706
866
 
707
867
  ```ts
708
- damp(value: number, target: number, damping: number, delta: number): number;
868
+ upload(onLoad: (dataUrl: string) => void, accept?: string): void;
709
869
  ```
710
870
 
711
- ### Random
871
+ ### Random <a id="random-functions"></a>
712
872
 
713
873
  ##### randomBoolean(probability)
714
874
 
@@ -842,7 +1002,7 @@ Produce a random 3D point inside a sphere.
842
1002
  insideSphere(radius?: number): [number, number, number];
843
1003
  ```
844
1004
 
845
- ### Pseudo-Random Number Generator (PRNG)
1005
+ ### Pseudo-Random Number Generator (PRNG) <a id="prng-functions"></a>
846
1006
 
847
1007
  #### PRNG Algorithms
848
1008
 
@@ -902,7 +1062,7 @@ xoshiro128ss(a: number, b: number, c: number, d: number): number;
902
1062
 
903
1063
  Thanks to the above algorithms, a seed-based version of most of the [random functions](#random) exist with additionnal parameters for a `seed` string and a PRNG `algorithm` function.
904
1064
 
905
- PRNG parameters:
1065
+ PRNG parameters: <a id="prng-parameters"></a>
906
1066
 
907
1067
  ```ts
908
1068
  type PRNGParameters = string | { seed: string; algorithm: (...args: number[]) => number };
@@ -912,7 +1072,7 @@ type PRNGParameters = string | { seed: string; algorithm: (...args: number[]) =>
912
1072
 
913
1073
  Generate a pseudo-random number in the interval [0, 1]. It is the PRNG equivalent of `Math.random()`.
914
1074
 
915
- - `prng`: PRNG parameters.
1075
+ - `prng`: [PRNG parameters](#prng-parameters).
916
1076
 
917
1077
  ```ts
918
1078
  random(prng: PRNGParameters): number;
@@ -922,7 +1082,7 @@ random(prng: PRNGParameters): number;
922
1082
 
923
1083
  Generate a pseudo-random boolean (true or false).
924
1084
 
925
- - `prng`: PRNG parameters.
1085
+ - `prng`: [PRNG parameters](#prng-parameters).
926
1086
  - `[probability=0.5]`: Probability to get true.
927
1087
 
928
1088
  ```ts
@@ -933,7 +1093,7 @@ randomBoolean(prng: PRNGParameters, probability?: number): boolean;
933
1093
 
934
1094
  Generate a pseudo-random sign (1 or -1).
935
1095
 
936
- - `prng`: PRNG parameters.
1096
+ - `prng`: [PRNG parameters](#prng-parameters).
937
1097
  - `[probability=0.5]`: Probability to get 1.
938
1098
 
939
1099
  ```ts
@@ -944,7 +1104,7 @@ randomSign(prng: PRNGParameters, probability?: number): number;
944
1104
 
945
1105
  Generate a pseudo-random floating-point number within a specified range.
946
1106
 
947
- - `prng`: PRNG parameters.
1107
+ - `prng`: [PRNG parameters](#prng-parameters).
948
1108
  - `[min=0]`: Minimum boundary.
949
1109
  - `[max=1]`: Maximum boundary.
950
1110
  - `[precision=2]`: Number of digits after the decimal point.
@@ -957,7 +1117,7 @@ randomFloat(prng: PRNGParameters, min?: number, max?: number, precision?: number
957
1117
 
958
1118
  Generate a pseudo-random integer number within a specified range.
959
1119
 
960
- - `prng`: PRNG parameters.
1120
+ - `prng`: [PRNG parameters](#prng-parameters).
961
1121
  - `min`: Minimum boundary.
962
1122
  - `max`: Maximum boundary.
963
1123
 
@@ -969,7 +1129,7 @@ randomInt(prng: PRNGParameters, min: number, max: number): number;
969
1129
 
970
1130
  Generate a pseudo-random hexadecimal color.
971
1131
 
972
- - `prng`: PRNG parameters.
1132
+ - `prng`: [PRNG parameters](#prng-parameters).
973
1133
 
974
1134
  ```ts
975
1135
  randomHexColor(prng: PRNGParameters): string;
@@ -979,7 +1139,7 @@ randomHexColor(prng: PRNGParameters): string;
979
1139
 
980
1140
  Pick a pseudo-random item from a given array.
981
1141
 
982
- - `prng`: PRNG parameters.
1142
+ - `prng`: [PRNG parameters](#prng-parameters).
983
1143
  - `array`: Array to pick the item from.
984
1144
 
985
1145
  ```ts
@@ -990,7 +1150,7 @@ randomItem<T>(prng: PRNGParameters, array: T[]): T | undefined;
990
1150
 
991
1151
  Pick a pseudo-random property value from a given object.
992
1152
 
993
- - `prng`: PRNG parameters.
1153
+ - `prng`: [PRNG parameters](#prng-parameters).
994
1154
  - `object`: Object to pick the property from.
995
1155
 
996
1156
  ```ts
@@ -1001,7 +1161,7 @@ randomObjectProperty<T>(prng: PRNGParameters, object: Record<string, T>): T | un
1001
1161
 
1002
1162
  Select a pseudo-random index from an array of weighted items.
1003
1163
 
1004
- - `prng`: PRNG parameters.
1164
+ - `prng`: [PRNG parameters](#prng-parameters).
1005
1165
  - `weights`: Array of weights.
1006
1166
 
1007
1167
  ```ts
@@ -1012,7 +1172,7 @@ randomIndex(prng: string | object, weights: number[]): number;
1012
1172
 
1013
1173
  Generate a pseudo-random number fitting a Gaussian (normal) distribution.
1014
1174
 
1015
- - `prng`: PRNG parameters.
1175
+ - `prng`: [PRNG parameters](#prng-parameters).
1016
1176
  - `[mean=0]`: Central value.
1017
1177
  - `[spread=1]`: Standard deviation.
1018
1178
 
@@ -1020,158 +1180,19 @@ Generate a pseudo-random number fitting a Gaussian (normal) distribution.
1020
1180
  randomGaussian(prng: string | object, mean?: number, spread?: number): number;
1021
1181
  ```
1022
1182
 
1023
- ### Query parameters
1024
-
1025
- ##### getQuery(property)
1026
-
1027
- Get a query parameter.
1028
-
1029
- - `property`: Query property to check.
1030
-
1031
- ```ts
1032
- getQuery(property: string): string | null;
1033
- ```
1034
-
1035
- ##### setQuery(property)
1036
-
1037
- Set a query parameter.
1038
-
1039
- - `property`: Query property to set.
1040
- - `value`: Value to set.
1041
-
1042
- ```ts
1043
- setQuery(property: string, value: string): void;
1044
- ```
1045
-
1046
- ##### hasQuery(property)
1047
-
1048
- Check if a query parameter exists.
1049
-
1050
- - `property`: Query property to check.
1051
-
1052
- ```ts
1053
- hasQuery(property: string): boolean;
1054
- ```
1055
-
1056
- ### Strings
1057
-
1058
- #### Cases
1059
-
1060
- ##### capitalize(string)
1061
-
1062
- Capitalize a string.
1063
-
1064
- - `string`: String to capitalize.
1065
-
1066
- ```ts
1067
- capitalize(string: string): string;
1068
- ```
1069
-
1070
- ##### toKebabCase(string)
1071
-
1072
- Convert a string to kebab-case: 'Hello world' -> 'hello-world'.
1073
-
1074
- - `string`: String to convert.
1075
-
1076
- ```ts
1077
- toKebabCase(string: string): string;
1078
- ```
1079
-
1080
- ##### toSnakeCase(string)
1081
-
1082
- Convert a string to snake_case: 'Hello world' -> 'hello_world'.
1083
-
1084
- - `string`: String to convert.
1085
-
1086
- ```ts
1087
- toSnakeCase(string: string): string;
1088
- ```
1089
-
1090
- ##### toCamelCase(string)
1091
-
1092
- Convert a string to camelCase: 'Hello world' -> 'helloWorld'.
1093
-
1094
- - `string`: String to convert.
1095
-
1096
- ```ts
1097
- toCamelCase(string: string): string;
1098
- ```
1099
-
1100
- ##### toPascalCase(string)
1101
-
1102
- Convert a string to PascalCase: 'Hello world' -> 'HelloWorld'.
1103
-
1104
- - `string`: String to convert.
1105
-
1106
- ```ts
1107
- toPascalCase(string: string): string;
1108
- ```
1109
-
1110
- ##### toTrainCase(string)
1111
-
1112
- Convert a string to Train-Case: 'Hello world' -> 'Hello-World'.
1113
-
1114
- - `string`: String to convert.
1115
-
1116
- ```ts
1117
- toTrainCase(string: string): string;
1118
- ```
1119
-
1120
- ##### toConstantCase(string)
1121
-
1122
- Convert a string to CONSTANT_CASE: 'Hello world' -> 'HELLO_WORLD'.
1123
-
1124
- - `string`: String to convert.
1125
-
1126
- ```ts
1127
- toConstantCase(string: string): string;
1128
- ```
1129
-
1130
- #### Paths
1131
-
1132
- ##### cleanPath(path)
1133
-
1134
- Clean a path by removing its parameters.
1135
-
1136
- - `path`: Path to clean.
1137
-
1138
- ```ts
1139
- cleanPath(path: string): string;
1140
- ```
1141
-
1142
- ##### addTrailingSlash(path)
1143
-
1144
- Convert a path by ensuring it has a trailing slash.
1145
-
1146
- - `path`: Path to convert.
1147
-
1148
- ```ts
1149
- addTrailingSlash(path: string): string;
1150
- ```
1151
-
1152
- ##### removeTrailingSlash(path)
1153
-
1154
- Convert a path by ensuring it has not a trailing slash.
1155
-
1156
- - `path`: Path to convert.
1157
-
1158
- ```ts
1159
- removeTrailingSlash(path: string): string;
1160
- ```
1161
-
1162
1183
  ## Utility classes
1163
1184
 
1164
- ### Geometry
1185
+ ### Geometry <a id="geometry-classes"></a>
1165
1186
 
1166
- See Geometry documentation [here](./docs/GEOMETRY.md).
1187
+ See Geometry utility classes documentation [here](./docs/GEOMETRY.md).
1167
1188
 
1168
1189
  #### [Vector2](./docs//GEOMETRY.md#vector-2)
1169
1190
 
1170
1191
  #### [Vector3](./docs//GEOMETRY.md#vector-3)
1171
1192
 
1172
- ### Curves
1193
+ ### Curves <a id="curves-classes"></a>
1173
1194
 
1174
- See Curves documentation [here](./docs/CURVES.md).
1195
+ See Curves utility classes documentation [here](./docs/CURVES.md).
1175
1196
 
1176
1197
  #### [Curve](./docs/CURVES.md#curve)
1177
1198
 
@@ -1203,9 +1224,9 @@ See Curves documentation [here](./docs/CURVES.md).
1203
1224
 
1204
1225
  #### [ArcCurve](./docs/CURVES.md#arc-curve)
1205
1226
 
1206
- ### Paths
1227
+ ### Paths <a id="paths-classes"></a>
1207
1228
 
1208
- See Paths documentation [here](./docs/PATHS.md).
1229
+ See Paths utility classes documentation [here](./docs/PATHS.md).
1209
1230
 
1210
1231
  #### [Path](./docs/PATHS.md#path)
1211
1232
 
@@ -1213,109 +1234,15 @@ See Paths documentation [here](./docs/PATHS.md).
1213
1234
 
1214
1235
  #### [PathSVG](./docs/PATHS.md#path-svg)
1215
1236
 
1216
- ### Color scale
1217
-
1218
- Utility class for generating color scales and interpolating between colors.
1219
-
1220
- - [new ColorScale(input, target)](#color-scale-constructor)
1221
- - [.colors](#color-scale-colors): `Array<[number, number, number]>`
1222
- - `static` [.generate(input, target, length)](#color-scale-static-generate-method): `Array<[number, number, number]>`
1223
- - `static` [.interpolate(inputColor, targetColor, value)](#color-scale-static-interpolate-method): `[number, number, number]`
1224
-
1225
- #### Constructor <a id="color-scale-constructor"></a>
1226
-
1227
- | Parameter | Type | Default | Description |
1228
- | --------------------- | ---------------------------------- | ----------------------- | ------------------------------------------- |
1229
- | input | `ColorRepresentation` | | Input color representation. |
1230
- | target | `ColorRepresentation` | | Target color representation. |
1231
- | [length] | `number` | `5` | Amount of colors composing the color scale. |
1232
- | [settings] | `ColorScaleSettings` | `{ colorSpace: 'rgb' }` | Color scale generation settings. |
1233
- | [settings.colorSpace] | `'rgb' \| 'hsl' \| 'hsb' \| 'hcl'` | `'rgb'` | Color scale color space. |
1237
+ ### Colors <a id="colors-classes"></a>
1234
1238
 
1235
- ##### HSL color scales
1239
+ See Colors utility classes documentation [here](./docs/COLORS.md).
1236
1240
 
1237
- HSL color scales come with offsets settings, so when `settings.colorSpace` is equal to `'hsl'`, the following settings are parameterable:
1241
+ #### [Color](./docs/COLORS.md#color)
1238
1242
 
1239
- | Parameter | Type | Default | Description |
1240
- | --------------------------- | -------- | ------- | ------------------------------- |
1241
- | [settings.hueOffset] | `number` | `0` | Target color hue offset. |
1242
- | [settings.saturationOffset] | `number` | `0` | Target color saturation offset. |
1243
- | [settings.lightnessOffset] | `number` | `0` | Target color lightness offset. |
1243
+ #### [ColorScale](./docs/COLORS.md#color-scale)
1244
1244
 
1245
- ##### HSB color scales
1246
-
1247
- HSB color scales come with offsets settings, so when `settings.colorSpace` is equal to `'hsb'`, the following settings are parameterable:
1248
-
1249
- | Parameter | Type | Default | Description |
1250
- | --------------------------- | -------- | ------- | ------------------------------- |
1251
- | [settings.hueOffset] | `number` | `0` | Target color hue offset. |
1252
- | [settings.saturationOffset] | `number` | `0` | Target color saturation offset. |
1253
- | [settings.brightnessOffset] | `number` | `0` | Target color brightness offset. |
1254
-
1255
- ##### HCL color scales
1256
-
1257
- HCL color scales come with a bunch of other settings, so when `settings.colorSpace` is equal to `'hcl'`, the following settings are parameterable:
1258
-
1259
- | Parameter | Type | Default | Description |
1260
- | -------------------------- | ---------------------------------------------- | ------- | ---------------------------------------- |
1261
- | [settings.mode] | `'qualitative' \| 'sequential' \| 'diverging'` | | Color scale mode. |
1262
- | [settings.triangular] | `number` | | Triangular interpolation `target` value. |
1263
- | [settings.powerStrength] | `number` | `1` | Interpolation power strength value. |
1264
- | [settings.hueOffset] | `number` | `0` | Target color hue offset. |
1265
- | [settings.chromaOffset] | `number` | `0` | Target color chroma offset. |
1266
- | [settings.luminanceOffset] | `number` | `0` | Target color luminance offset. |
1267
-
1268
- Learn more about [HCL-Based Color Palettes](https://colorspace.r-forge.r-project.org/articles/hcl_palettes.html).
1269
-
1270
- #### Properties
1271
-
1272
- ##### colors <a id="color-scale-colors"></a>
1273
-
1274
- Array of colors composing the color scale.
1275
-
1276
- ```ts
1277
- ColorScale.colors: Array<[number, number, number]>;
1278
- ```
1279
-
1280
- #### Methods
1281
-
1282
- ##### `static` generate(input, target, length) <a id="color-scale-static-generate-method"></a>
1283
-
1284
- Generate a color scale.
1285
-
1286
- - `input`: Input color representation.
1287
- - `target`: Target color representation.
1288
- - `length`: Amount of colors composing the color scale.
1289
- - `[settings]`: Color scale generation settings.
1290
-
1291
- ```ts
1292
- static ColorScale.generate(
1293
- input: ColorRepresentation,
1294
- target: ColorRepresentation,
1295
- length: number,
1296
- settings?: ColorScaleSettings
1297
- ): Array<[number, number, number]>;
1298
- ```
1299
-
1300
- ##### `static` interpolate(inputColor, targetColor, value) <a id="color-scale-static-interpolate-method"></a>
1301
-
1302
- Interpolate between colors.
1303
-
1304
- - `inputColor`: Input color.
1305
- - `targetColor`: Target color.
1306
- - `value`: Interpolation normalized value.
1307
- - `[settings]`: Color scale settings.
1308
-
1309
- ```ts
1310
- static ColorScale.interpolate(
1311
- inputColor: [number, number, number],
1312
- targetColor: [number, number, number],
1313
- value: number,
1314
- settings?: ColorScaleSettings
1315
- ): [number, number, number];
1316
- ```
1317
-
1318
- ### Frame rate
1245
+ ### Frame rate <a id="frame-rate-class"></a>
1319
1246
 
1320
1247
  Utility class for controlling FPS calls.
1321
1248
 
@@ -1327,7 +1254,7 @@ Utility class for controlling FPS calls.
1327
1254
 
1328
1255
  | Parameter | Type | Default | Description |
1329
1256
  | --------- | -------- | ------- | ----------------------- |
1330
- | [fps] | `number` | `30` | Frame per second limit. |
1257
+ | [fps] | `number` | `60` | Frame per second limit. |
1331
1258
 
1332
1259
  #### Properties
1333
1260
 
@@ -1355,15 +1282,12 @@ FrameRate.update(): boolean;
1355
1282
 
1356
1283
  `EPSILON`
1357
1284
 
1358
- ### Geomery
1285
+ ### Geometry
1359
1286
 
1360
1287
  `PI`
1361
-
1362
1288
  `TWO_PI`
1363
1289
  `TAU`
1364
-
1365
1290
  `HALF_PI`
1366
-
1367
1291
  `QUARTER_PI`
1368
1292
 
1369
1293
  ### Colors