@semio/utils 0.0.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.
@@ -0,0 +1,1020 @@
1
+ import * as react from 'react';
2
+ import * as zustand from 'zustand';
3
+
4
+ /**
5
+ * Logs a message to the console.
6
+ *
7
+ * @param value - The message to be logged
8
+ *
9
+ * @remarks
10
+ * This function temporarily disables ESLint console warnings for testing purposes.
11
+ */
12
+ declare function log(value: string): void;
13
+
14
+ /**
15
+ * Generates a namespaced lookup key.
16
+ *
17
+ * @param namespace - The namespace identifier ("default" is treated specially)
18
+ * @param id - The identifier to namespace
19
+ * @returns A dot-separated namespaced key (e.g., "namespace.id")
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * getLookup("users", "123") // Returns: "users.123"
24
+ * getLookup("default", "123") // Returns: "default.123"
25
+ * ```
26
+ */
27
+ declare function getLookup(namespace: string, id: string): string;
28
+ /**
29
+ * Extracts the namespace from a lookup key.
30
+ *
31
+ * @param lookup - The namespaced lookup key
32
+ * @returns The namespace portion, or "default" if no namespace is present
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * getNamespace("users.123") // Returns: "users"
37
+ * getNamespace("123") // Returns: "default"
38
+ * ```
39
+ */
40
+ declare function getNamespace(lookup: string): string;
41
+ /**
42
+ * Extracts the identifier from a lookup key.
43
+ *
44
+ * @param lookup - The namespaced lookup key
45
+ * @returns The identifier portion, or the entire key if no namespace is present
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * getId("users.123") // Returns: "123"
50
+ * getId("123") // Returns: "123"
51
+ * ```
52
+ */
53
+ declare function getId(lookup: string): string;
54
+
55
+ /**
56
+ * Time representation in milliseconds.
57
+ */
58
+ type RawTime = number;
59
+ /**
60
+ * A timer implementation for managing animation playback.
61
+ *
62
+ * The timer operates on a normalized time range of [0, 1], where:
63
+ * - 0 represents the start of the animation
64
+ * - 1 represents the end of the animation
65
+ *
66
+ * @property running - Whether the timer is actively running
67
+ * @property _previousTime - The last update time in milliseconds
68
+ * @property _currentTime - The current time in milliseconds
69
+ * @property stamp - Current normalized time position [0, 1]
70
+ * @property timescale - Playback speed multiplier (negative for reverse)
71
+ * @property bounds - Constrains playback to a [start, end] range within [0, 1]
72
+ * @property playback - Animation behavior at bounds ("loop"|"bounce"|"once")
73
+ * @property viewport - Visible time range as [start, end] within [0, 1]
74
+ * @property duration - Total animation duration in milliseconds
75
+ */
76
+ interface Player {
77
+ running: boolean;
78
+ _previousTime: RawTime;
79
+ _currentTime: RawTime;
80
+ stamp: number;
81
+ timescale: number;
82
+ bounds: [number, number];
83
+ playback: "loop" | "bounce" | "once";
84
+ viewport: [number, number];
85
+ duration: number;
86
+ }
87
+ /**
88
+ * Creates a copy of the provided timer, but updated with the new timestamp.
89
+ * @param timer - the timer to be updated
90
+ * @param stamp - the new timestamp in the range [0, 1]
91
+ * @returns the updated timer
92
+ */
93
+ declare function reset(player: Player, stamp?: number): Player;
94
+ /**
95
+ * Returns the current time in milliseconds.
96
+ * @returns the current time in milliseconds
97
+ */
98
+ declare function now(): RawTime;
99
+ /**
100
+ * Creates a copy of the provided timer, but updated with a new timestamp as determined by
101
+ * the timestamp since it was last called and the duration of the animation itself.
102
+ * @param timer - the timer to be updated
103
+ * @returns the updated timer
104
+ */
105
+ declare function update(player: Player, coldStart: boolean): Player;
106
+ /**
107
+ * Sets the bounds for the player.
108
+ * @param player - the player to be updated
109
+ * @param bounds - the new bounds in the range [0, 1]
110
+ * @returns the updated player
111
+ */
112
+ declare function setBounds(player: Player, bounds: [number, number]): Player;
113
+ /**
114
+ * Sets the viewport for the player
115
+ * @param player - the player to be updated
116
+ * @param viewport - the new viewport in the range [0, 1]
117
+ * @returns the updated player
118
+ */
119
+ declare function setViewport(player: Player, viewport: [number, number]): Player;
120
+ /**
121
+ * Creates a copy of the provided timer, but updated with a timescale based on the speed provided.
122
+ * @param timer - the timer to be updated
123
+ * @param speed - the speed of playback desired (defaults to 1)
124
+ * @returns the updated timer
125
+ */
126
+ declare function play(player: Player, speed?: number): Player;
127
+ /**
128
+ * Creates a copy of the provided timer, but updated with a timescale of 0 (paused)
129
+ * @param timer - the timer to be updated
130
+ * @returns the updated timer
131
+ */
132
+ declare function pause(player: Player): Player;
133
+ /**
134
+ * Returns the provided player, with the viewport centered around the provided stamp as much as possible.
135
+ * @param player - the player to be updated
136
+ * @param stamp - the new stamp to center the viewport around
137
+ * @returns the updated player
138
+ */
139
+ declare function seek(player: Player, stamp: number): Player;
140
+ /**
141
+ * Returns the provided player, with the duration set to the provided value.
142
+ * @param player - the player to be updated
143
+ * @param duration - the new duration
144
+ * @returns the updated player
145
+ */
146
+ declare function setDuration(player: Player, duration: number): Player;
147
+ /**
148
+ * Creates a new Player instance with default values.
149
+ *
150
+ * @returns A new Player instance initialized with:
151
+ * - Not running
152
+ * - Current timestamp
153
+ * - Zero stamp position
154
+ * - No timescale
155
+ * - Full bounds [0, 1]
156
+ * - Loop playback
157
+ * - Full viewport [0, 1]
158
+ * - 1000ms duration
159
+ */
160
+ declare function newPlayer(): Player;
161
+
162
+ /**
163
+ * Core data structure for player state
164
+ */
165
+ interface PlayerData {
166
+ /** The player instance containing current state */
167
+ player: Player;
168
+ }
169
+ /**
170
+ * Actions available for controlling the player
171
+ */
172
+ interface PlayerActions {
173
+ /** Updates the total duration of the animation */
174
+ updateDuration: (duration: number) => void;
175
+ /** Updates the playback speed multiplier */
176
+ updateTimescale: (speed: number) => void;
177
+ /** Resets the player to initial state or specified time */
178
+ resetPlayer: (time?: number) => void;
179
+ /** Plays the animation */
180
+ playPlayer: (speed?: number) => void;
181
+ /** Pauses the animation */
182
+ pausePlayer: () => void;
183
+ /** Updates the timer */
184
+ updatePlayer: (coldStart?: boolean) => void;
185
+ /** Sets the player bounds */
186
+ updatePlayerBounds: (start: number, end: number) => void;
187
+ /** Updates one bound of the player */
188
+ updatePlayerBound: (bound: "start" | "end", time?: number) => void;
189
+ /** Sets the player viewport */
190
+ updatePlayerViewport: (start: number, end: number) => void;
191
+ /** Seeks the viewport to center the player at a time */
192
+ updatePlayerViewportCenter: (time?: number) => void;
193
+ /** Updates one bound of the player viewport */
194
+ updatePlayerViewportBound: (bound: "start" | "end", time: number) => void;
195
+ }
196
+ type PlayerStoreSetter = (partial: (PlayerData & PlayerActions) | Partial<PlayerData & PlayerActions> | ((state: PlayerData & PlayerActions) => (PlayerData & PlayerActions) | Partial<PlayerData & PlayerActions>), replace?: false | undefined) => void;
197
+ type PlayerStoreGetter = () => PlayerData & PlayerActions;
198
+ declare const PlayerSlice: (set: PlayerStoreSetter) => {
199
+ player: Player;
200
+ updateDuration: (duration: number) => void;
201
+ updateTimescale: (speed: number) => void;
202
+ resetPlayer: (time?: number) => void;
203
+ playPlayer: (speed?: number) => void;
204
+ pausePlayer: () => void;
205
+ updatePlayer: (coldStart?: boolean) => void;
206
+ updatePlayerBounds: (start: number, end: number) => void;
207
+ updatePlayerBound: (bound: "start" | "end", time?: number) => void;
208
+ updatePlayerViewport: (start: number, end: number) => void;
209
+ updatePlayerViewportCenter: (time?: number) => void;
210
+ updatePlayerViewportBound: (bound: "start" | "end", time: number) => void;
211
+ };
212
+ declare const usePlayerStore: zustand.UseBoundStore<Omit<zustand.StoreApi<PlayerData & PlayerActions>, "subscribe"> & {
213
+ subscribe: {
214
+ (listener: (selectedState: PlayerData & PlayerActions, previousSelectedState: PlayerData & PlayerActions) => void): () => void;
215
+ <U>(selector: (state: PlayerData & PlayerActions) => U, listener: (selectedState: U, previousSelectedState: U) => void, options?: {
216
+ equalityFn?: ((a: U, b: U) => boolean) | undefined;
217
+ fireImmediately?: boolean;
218
+ } | undefined): () => void;
219
+ };
220
+ }>;
221
+ type PlayerStore = typeof usePlayerStore;
222
+ declare const PlayerContext: react.Context<zustand.UseBoundStore<Omit<zustand.StoreApi<PlayerData & PlayerActions>, "subscribe"> & {
223
+ subscribe: {
224
+ (listener: (selectedState: PlayerData & PlayerActions, previousSelectedState: PlayerData & PlayerActions) => void): () => void;
225
+ <U>(selector: (state: PlayerData & PlayerActions) => U, listener: (selectedState: U, previousSelectedState: U) => void, options?: {
226
+ equalityFn?: ((a: U, b: U) => boolean) | undefined;
227
+ fireImmediately?: boolean;
228
+ } | undefined): () => void;
229
+ };
230
+ }> | null>;
231
+
232
+ type RawBoolean = boolean;
233
+ type RawNumber = number;
234
+ type RawString = string;
235
+ interface RawVector3 {
236
+ x: number;
237
+ y: number;
238
+ z: number;
239
+ }
240
+ interface RawVector2 {
241
+ x: number;
242
+ y: number;
243
+ }
244
+ interface RawEuler {
245
+ x: number;
246
+ y: number;
247
+ z: number;
248
+ }
249
+ interface RawRGB {
250
+ r: number;
251
+ g: number;
252
+ b: number;
253
+ }
254
+ interface RawHSL {
255
+ h: number;
256
+ s: number;
257
+ l: number;
258
+ }
259
+ type RawColor = RawRGB | RawHSL;
260
+ type RawValue = RawBoolean | RawNumber | RawString | RawVector3 | RawVector2 | RawEuler | RawColor;
261
+ interface AnimatablePubInfo {
262
+ public: boolean;
263
+ units?: string;
264
+ output: string;
265
+ color?: string;
266
+ }
267
+ type AnimatableValue = AnimatableBoolean | AnimatableNumber | AnimatableString | AnimatableVector3 | AnimatableVector2 | AnimatableEuler | AnimatableColor;
268
+ /**
269
+ * A specification for an animated numerical value
270
+ *
271
+ * @param id - a unique identifier for the value.
272
+ * @param name - the name of the value, defined by the user.
273
+ * @param type - the type of the value (always "boolean" for this type).
274
+ * @param default - the default value of the boolean.
275
+ * @param constraints - a collection of constraints that the value must adhere to.
276
+ * @param pub - a collection of properties that determine whether the value is public and what its output should be.
277
+ */
278
+ interface AnimatableBoolean {
279
+ id: string;
280
+ name?: string;
281
+ type: "boolean";
282
+ default: RawBoolean;
283
+ constraints: {
284
+ frequency?: number;
285
+ };
286
+ pub?: AnimatablePubInfo;
287
+ }
288
+ /**
289
+ * A specification for an animated numerical value
290
+ *
291
+ * @param id - a unique identifier for the value.
292
+ * @param name - the name of the value, defined by the user.
293
+ * @param type - the type of the value (always "number" for this type).
294
+ * @param default - the default value of the number.
295
+ * @param constraints - a collection of constraints that the value must adhere to.
296
+ * @param angle - a boolean indicating whether the value represents an angle.
297
+ * @param pub - a collection of properties that determine whether the value is public and what its output should be.
298
+ */
299
+ interface AnimatableNumber {
300
+ id: string;
301
+ name?: string;
302
+ type: "number";
303
+ default: RawNumber;
304
+ constraints: {
305
+ min?: number;
306
+ max?: number;
307
+ velocity?: number;
308
+ };
309
+ pub?: AnimatablePubInfo;
310
+ }
311
+ /**
312
+ * A specification for an animated string value
313
+ *
314
+ * @param id - a unique identifier for the value.
315
+ * @param name - the name of the value, defined by the user.
316
+ * @param type - the type of the value (always "string" for this type).
317
+ * @param default - the default value of the string.
318
+ * @param constraints - a collection of constraints that the value must adhere to.
319
+ * @param pub - a collection of properties that determine whether the value is public and what its output should be.
320
+ */
321
+ interface AnimatableString {
322
+ id: string;
323
+ name?: string;
324
+ type: "string";
325
+ default: RawString;
326
+ constraints: {
327
+ length?: number;
328
+ };
329
+ pub?: AnimatablePubInfo;
330
+ }
331
+ /**
332
+ * A specification for an animated 3-vector value
333
+ *
334
+ * @param id - a unique identifier for the value.
335
+ * @param name - the name of the value, defined by the user.
336
+ * @param type - the type of the value (always "vector3" for this type).
337
+ * @param default - the default value of the vector3.
338
+ * @param constraints - a collection of constraints that the value must adhere to.
339
+ * @param pub - a collection of properties that determine whether the value is public and what its output should be.
340
+ */
341
+ interface AnimatableVector3 {
342
+ id: string;
343
+ name?: string;
344
+ type: "vector3";
345
+ default: RawVector3;
346
+ constraints: {
347
+ min?: [number | null, number | null, number | null];
348
+ max?: [number | null, number | null, number | null];
349
+ velocity?: number;
350
+ };
351
+ pub?: AnimatablePubInfo;
352
+ }
353
+ /**
354
+ * A specification for an animated 2-vector value
355
+ *
356
+ * @param id - a unique identifier for the value.
357
+ * @param name - the name of the value, defined by the user.
358
+ * @param type - the type of the value (always "vector2" for this type).
359
+ * @param default - the default value of the vector2.
360
+ * @param constraints - a collection of constraints that the value must adhere to.
361
+ * @param pub - a collection of properties that determine whether the value is public and what its output should be.
362
+ */
363
+ interface AnimatableVector2 {
364
+ id: string;
365
+ name?: string;
366
+ type: "vector2";
367
+ default: RawVector2;
368
+ constraints: {
369
+ min?: [number | null, number | null];
370
+ max?: [number | null, number | null];
371
+ velocity?: number;
372
+ };
373
+ pub?: AnimatablePubInfo;
374
+ }
375
+ /**
376
+ * A specification for an animated Euler value
377
+ *
378
+ * @param id - a unique identifier for the value.
379
+ * @param name - the name of the value, defined by the user.
380
+ * @param type - the type of the value (always "euler" for this type).
381
+ * @param default - the default value of the euler.
382
+ * @param constraints - a collection of constraints that the value must adhere to.
383
+ * @param pub - a collection of properties that determine whether the value is public and what its output should be.
384
+ */
385
+ interface AnimatableEuler {
386
+ id: string;
387
+ name?: string;
388
+ type: "euler";
389
+ default: RawEuler;
390
+ constraints: {
391
+ min?: [number | null, number | null, number | null];
392
+ max?: [number | null, number | null, number | null];
393
+ velocity?: number;
394
+ };
395
+ pub?: AnimatablePubInfo;
396
+ }
397
+ /**
398
+ * A specification for an animated encoded color value
399
+ *
400
+ * @param id - a unique identifier for the value.
401
+ * @param name - the name of the value, defined by the user.
402
+ * @param type - the type of the value (always "rgb" or "hsl" for this type).
403
+ * @param default - the default value of the color.
404
+ * @param constraints - a collection of constraints that the value must adhere to.
405
+ * @param pub - a collection of properties that determine whether the value is public and what its output should be.
406
+ */
407
+ interface AnimatableColor {
408
+ id: string;
409
+ name?: string;
410
+ type: "rgb" | "hsl";
411
+ default: RawColor;
412
+ constraints: {
413
+ min?: [number | null, number | null, number | null];
414
+ max?: [number | null, number | null, number | null];
415
+ velocity?: number;
416
+ };
417
+ pub?: AnimatablePubInfo;
418
+ }
419
+ declare function instanceOfRawBoolean(object: any): object is RawBoolean;
420
+ declare function instanceOfRawNumber(object: any): object is RawNumber;
421
+ declare function instanceOfRawString(object: any): object is RawString;
422
+ declare function instanceOfRawVector3(object: any): object is RawVector3;
423
+ declare function instanceOfRawVector2(object: any): object is RawVector2;
424
+ declare function instanceOfRawEuler(object: any): object is RawEuler;
425
+ declare function instanceOfRawColor(object: any): object is RawColor;
426
+ declare function instanceOfRawRGB(object: any): object is RawRGB;
427
+ declare function instanceOfRawHSL(object: any): object is RawHSL;
428
+ declare function isRawObject(value: any): boolean;
429
+
430
+ /**
431
+ * Converts a duration in milliseconds to a formatted time string.
432
+ *
433
+ * @param duration - The duration in milliseconds to convert
434
+ * @returns A string in the format "mm:ss:ms" where:
435
+ * - mm: minutes (zero-padded to 2 digits)
436
+ * - ss: seconds (zero-padded to 2 digits)
437
+ * - ms: milliseconds (zero-padded to 2 digits)
438
+ *
439
+ * @example
440
+ * ```typescript
441
+ * numberToDurationString(63450) // Returns "01:03:45"
442
+ * numberToDurationString(5000) // Returns "00:05:00"
443
+ * ```
444
+ */
445
+ declare const numberToDurationString: (duration: number) => string;
446
+
447
+ /**
448
+ * Creates pairs of adjacent elements from an array.
449
+ *
450
+ * @template T - The type of elements in the array
451
+ * @param arr - The source array to create pairs from
452
+ * @returns An array of tuples, where each tuple contains consecutive elements
453
+ *
454
+ * @example
455
+ * ```typescript
456
+ * pairwise([1, 2, 3, 4]) // Returns: [[1,2], [2,3], [3,4]]
457
+ * ```
458
+ */
459
+ declare function pairwise<T>(arr: T[]): [T, T][];
460
+
461
+ /**
462
+ * A hook that delays the nullification of a boolean state value.
463
+ *
464
+ * Useful for maintaining hover states or other temporary UI states
465
+ * for a specified duration after the triggering condition becomes false.
466
+ *
467
+ * @param value - The current boolean state value
468
+ * @param timeout - The delay duration in milliseconds
469
+ * @returns The delayed boolean state value
470
+ *
471
+ * @example
472
+ * ```typescript
473
+ * const isHoveredWithDelay = useLazy(isHovered, 500);
474
+ * ```
475
+ */
476
+ declare function useLazy(value: boolean, timeout: number): boolean;
477
+
478
+ /**
479
+ * Generates an SVG path string for a hexagon with flanges.
480
+ *
481
+ * @param x - Center X coordinate of the hexagon
482
+ * @param y - Center Y coordinate of the hexagon
483
+ * @param size - Width/height of the hexagon's body
484
+ * @param height - Total height including top and bottom flanges
485
+ * @returns SVG path string for the hexagon
486
+ *
487
+ * @example
488
+ * ```typescript
489
+ * const path = getHexagonPath(100, 100, 50, 80);
490
+ * // Use in SVG: <path d={path} />
491
+ * ```
492
+ */
493
+ declare function getHexagonPath(x: number, y: number, size: number, height: number): string;
494
+ /**
495
+ * Generates an SVG path string for a degenerate (collapsed) hexagon.
496
+ *
497
+ * Creates a vertical line with the same number of vertices as a regular hexagon,
498
+ * allowing smooth interpolation between the two shapes.
499
+ *
500
+ * @param x - Center X coordinate of the line
501
+ * @param y - Center Y coordinate of the line
502
+ * @param size - Reference size (affects vertical spacing of points)
503
+ * @param height - Total height of the line including endpoints
504
+ * @returns SVG path string for the degenerate hexagon
505
+ */
506
+ declare function getDegenerateHexagonPath(x: number, y: number, size: number, height: number): string;
507
+
508
+ /**
509
+ * Takes in the completion percentage and the total number of frames in an animation,
510
+ * and returns the closest frame as a percentage of the whole animation's duration.
511
+ *
512
+ * @param completion - The completion of the animation from 0 to 1.
513
+ * @param count - The number of frames in the animation.
514
+ * @returns The closest frame number to the completion as a percentage of the total frames.
515
+ */
516
+ declare function closestFrame(completion: number, count: number): number;
517
+
518
+ /**
519
+ * Converts an angle from radians to degrees.
520
+ *
521
+ * @param radians - The angle in radians
522
+ * @returns The angle in degrees
523
+ *
524
+ * @example
525
+ * ```typescript
526
+ * toDegrees(Math.PI) // Returns: 180
527
+ * ```
528
+ */
529
+ declare const toDegrees: (radians: number) => number;
530
+ /**
531
+ * Converts an angle from degrees to radians.
532
+ *
533
+ * @param degrees - The angle in degrees
534
+ * @returns The angle in radians
535
+ *
536
+ * @example
537
+ * ```typescript
538
+ * toRadians(180) // Returns: 3.141592653589793
539
+ * ```
540
+ */
541
+ declare const toRadians: (degrees: number) => number;
542
+
543
+ /**
544
+ * Converts a hexadecimal color value to an RGBA color string.
545
+ *
546
+ * @param hex - The hex color string (with or without #)
547
+ * @param alpha - The opacity value between 0 and 1
548
+ * @returns An RGBA color string
549
+ * @throws {Error} If the hex color format is invalid
550
+ *
551
+ * @example
552
+ * ```typescript
553
+ * const color = hexToRgba('#ff0000', 0.5); // "rgba(255, 0, 0, 0.5)"
554
+ * ```
555
+ */
556
+ declare const hexToRgba: (hex: string, alpha: number) => string;
557
+ /**
558
+ * Converts an RGB color value to an RGBA color string.
559
+ *
560
+ * @param rgb - The RGB color string in format "r, g, b"
561
+ * @param alpha - The opacity value between 0 and 1
562
+ * @returns An RGBA color string
563
+ * @throws {Error} If the RGB color format is invalid
564
+ */
565
+ declare const rgbToRgba: (rgb: string, alpha: number) => string;
566
+ /**
567
+ * Converts an HSL color value to an RGBA color string.
568
+ *
569
+ * @param hsl - The HSL color string in format "h, s, l"
570
+ * @param alpha - The opacity value between 0 and 1
571
+ * @returns An RGBA color string
572
+ * @throws {Error} If the HSL color format is invalid
573
+ */
574
+ declare const hslToRgba: (hsl: string, alpha: number) => string;
575
+ /**
576
+ * Adds transparency to a color string of any supported format (hex, rgb, hsl).
577
+ *
578
+ * @param color - The color string in hex, RGB, or HSL format
579
+ * @param opacity - The desired opacity value between 0 and 1
580
+ * @returns An RGBA color string
581
+ * @throws {Error} If the color format is not supported
582
+ *
583
+ * @example
584
+ * ```typescript
585
+ * const transparentRed = alpha('#ff0000', 0.5); // "rgba(255, 0, 0, 0.5)"
586
+ * const transparentBlue = alpha('rgb(0, 0, 255)', 0.7); // "rgba(0, 0, 255, 0.7)"
587
+ * ```
588
+ */
589
+ declare const alpha: (color: string, opacity: number) => string;
590
+ /**
591
+ * Lightens or darkens a color by a given factor.
592
+ *
593
+ * @param color - The color string to modify
594
+ * @param factor - Positive values lighten the color, negative values darken it
595
+ * @returns A hex color string
596
+ *
597
+ * @example
598
+ * ```typescript
599
+ * const lighterBlue = altColor('#0000ff', 0.2); // Lightens blue by 20%
600
+ * const darkerRed = altColor('#ff0000', -0.3); // Darkens red by 30%
601
+ * ```
602
+ */
603
+ declare function altColor(color: string, factor: number): string;
604
+ declare function hexToRgbArray(color: string): [number, number, number];
605
+ declare function rawRGBToHex({ r, g, b }: RawRGB): string;
606
+ declare function rawHSLToHex({ h, s, l }: RawHSL): string;
607
+
608
+ /**
609
+ * Creates a memoized selector function that only updates when the selected value
610
+ * deeply changes.
611
+ *
612
+ * @param selector - A function that selects a value from the state
613
+ * @returns A memoized selector function that returns the same reference if the
614
+ * selected value hasn't deeply changed
615
+ *
616
+ * @example
617
+ * ```typescript
618
+ * const selectUserData = useDeepSelector((state) => state.user.data);
619
+ * const userData = selectUserData(state);
620
+ * ```
621
+ */
622
+ declare function useDeepSelector<S, U>(selector: (state: S) => U): (state: S) => U;
623
+ /**
624
+ * Similar to useMemo, but performs a deep comparison of dependencies instead of
625
+ * reference equality.
626
+ *
627
+ * @param initializer - Function that returns the value to be memoized
628
+ * @param dependencies - Array of dependencies that trigger recalculation when deeply changed
629
+ * @returns The memoized value
630
+ *
631
+ * @example
632
+ * ```typescript
633
+ * const memoizedValue = useDeep(
634
+ * () => expensiveCalculation(obj),
635
+ * [obj]
636
+ * );
637
+ * ```
638
+ */
639
+ declare function useDeep<V, D>(initializer: () => V, dependencies: D[]): V;
640
+
641
+ /**
642
+ * Custom hook to handle responsive media queries in React components.
643
+ *
644
+ * @param query - A valid CSS media query string (e.g., '(min-width: 768px)')
645
+ * @returns A boolean indicating whether the media query matches
646
+ *
647
+ * @example
648
+ * ```typescript
649
+ * const isMobile = useMediaQuery('(max-width: 768px)');
650
+ *
651
+ * return (
652
+ * <div>
653
+ * {isMobile ? <MobileView /> : <DesktopView />}
654
+ * </div>
655
+ * );
656
+ * ```
657
+ */
658
+ declare const useMediaQuery: (query: string) => boolean;
659
+
660
+ /**
661
+ * A utility type that overwrites properties in T with properties from U.
662
+ * @template T - The original type
663
+ * @template U - The type containing properties to overwrite with
664
+ */
665
+ type Write<T, U> = Omit<T, keyof U> & U;
666
+ /**
667
+ * Interface for a store that supports subscribing to state changes with selector support.
668
+ * @template T - The type of the store's state
669
+ */
670
+ interface StoreSubscribeWithSelector<T> {
671
+ subscribe: {
672
+ /**
673
+ * Subscribe to all state changes
674
+ * @param listener - Callback called with the new and previous state values
675
+ * @returns Unsubscribe function
676
+ */
677
+ (listener: (selectedState: T, previousSelectedState: T) => void): () => void;
678
+ /**
679
+ * Subscribe to changes in a selected portion of the state
680
+ * @template U - The type of the selected state portion
681
+ * @param selector - Function to select a portion of the state
682
+ * @param listener - Callback called with the new and previous selected values
683
+ * @param options - Configuration options for the subscription
684
+ * @returns Unsubscribe function
685
+ */
686
+ <U>(selector: (state: T) => U, listener: (selectedState: U, previousSelectedState: U) => void, options?: {
687
+ equalityFn?: (a: U, b: U) => boolean;
688
+ fireImmediately?: boolean;
689
+ }): () => void;
690
+ };
691
+ }
692
+
693
+ /**
694
+ * Converts a value to a JSON string, handling Maps appropriately.
695
+ *
696
+ * @param value - The value to stringify.
697
+ * @returns The JSON string representation of the value.
698
+ */
699
+ declare function stringifyMapped(value: unknown): string;
700
+ /**
701
+ * Parses a JSON string, reviving Maps appropriately.
702
+ *
703
+ * @param json - The JSON string to parse.
704
+ * @returns The parsed value.
705
+ */
706
+ declare function parseToMapped(json: string): unknown;
707
+ /**
708
+ * Parses the files in the given event and calls the provided function on each array item.
709
+ *
710
+ * @param event - The event containing the files to parse.
711
+ * @param fn - The function to call on each array item.
712
+ */
713
+ declare function parseJSONFileEvent(event: React.ChangeEvent<HTMLInputElement>, fn: (item: unknown) => void): void;
714
+
715
+ /**
716
+ * Downloads a JSON object as a file.
717
+ *
718
+ * @param data - The data to be converted to JSON and downloaded.
719
+ * @param filename - The name of the file to be downloaded.
720
+ */
721
+ declare function downloadJSONFile(data: unknown, filename: string): void;
722
+ /**
723
+ * Downloads a Blob as a file.
724
+ *
725
+ * @param blob - The Blob to be downloaded.
726
+ * @param filename - The name of the file to be downloaded.
727
+ */
728
+ declare function downloadBlob(blob: Blob, filename: string): void;
729
+
730
+ /**
731
+ * Converts an array of 2D points to an SVG path string.
732
+ *
733
+ * @param points - Array of [x, y] coordinate pairs
734
+ * @param close - If true, closes the path by adding a 'Z' command
735
+ * @returns An SVG path string using absolute move ('M') and line ('L') commands
736
+ *
737
+ * @example
738
+ * ```typescript
739
+ * pointsToPath([[0, 0], [1, 1], [2, 0]]) // Returns "M 0 0 L 1 1 L 2 0"
740
+ * pointsToPath([[0, 0], [1, 1]], true) // Returns "M 0 0 L 1 1 Z"
741
+ * ```
742
+ *
743
+ * @remarks
744
+ * The path starts with a move command to the first point, followed by line commands
745
+ * to each subsequent point. If close is true, a final 'Z' command is added to
746
+ * create a closed shape.
747
+ */
748
+ declare function pointsToPath(points: [number, number][], close?: boolean): string;
749
+
750
+ /**
751
+ * Converts Euler angles to a 3x3 rotation matrix.
752
+ * Uses ZYX order (intrinsic rotations).
753
+ *
754
+ * @param euler - Array of three numbers representing rotation angles in radians [z, y, x]
755
+ * @returns A 3x3 rotation matrix as a nested array
756
+ *
757
+ * @example
758
+ * ```typescript
759
+ * const matrix = eulerToRotationMatrix([0, Math.PI/2, 0]);
760
+ * ```
761
+ */
762
+ declare function eulerToRotationMatrix(euler: [number, number, number]): number[][];
763
+ /**
764
+ * Calculates the angle of rotation from a rotation matrix.
765
+ *
766
+ * @param R - A 3x3 rotation matrix as a nested array
767
+ * @returns The angle of rotation in radians
768
+ */
769
+ declare function rotationMatrixToAngle(R: number[][]): number;
770
+ /**
771
+ * Calculates the angular distance between two orientations specified by Euler angles.
772
+ *
773
+ * @param euler1 - First orientation in Euler angles [z, y, x] in radians
774
+ * @param euler2 - Second orientation in Euler angles [z, y, x] in radians
775
+ * @returns The angular distance in radians
776
+ *
777
+ * @example
778
+ * ```typescript
779
+ * const distance = angularDistance([0, 0, 0], [0, Math.PI/2, 0]);
780
+ * ```
781
+ */
782
+ declare function angularDistance(euler1: [number, number, number], euler2: [number, number, number]): number;
783
+
784
+ /**
785
+ * Merges overlapping segments in an array of intervals.
786
+ *
787
+ * This function takes an array of intervals represented as tuples of two numbers,
788
+ * sorts them, and merges any overlapping intervals. The result is an array of
789
+ * non-overlapping intervals that cover the same ranges as the input.
790
+ *
791
+ * @param original - An array of intervals represented as tuples of two numbers.
792
+ * Each tuple contains a start and end value.
793
+ * @returns An array of merged, non-overlapping intervals.
794
+ *
795
+ * @example
796
+ * ```typescript
797
+ * const intervals = [[1, 3], [2, 4], [5, 7]];
798
+ * const result = overlappingSegments(intervals);
799
+ * console.log(result); // Output: [[1, 4], [5, 7]]
800
+ * ```
801
+ */
802
+ declare function overlappingSegments(original: [number, number][]): [number, number][];
803
+
804
+ /**
805
+ * A class representing a Result type that can either contain a success value of type T
806
+ * or an error value of type E. This implementation is inspired by Rust's Result type.
807
+ *
808
+ * @typeParam T - The type of the success value
809
+ * @typeParam E - The type of the error value, defaults to Error
810
+ *
811
+ * @example
812
+ * ```typescript
813
+ * // Creating a success result
814
+ * const okResult = Result.Ok<number, string>(42);
815
+ *
816
+ * // Creating an error result
817
+ * const errResult = Result.Err<number, string>("something went wrong");
818
+ *
819
+ * // Using map to transform the success value
820
+ * const doubled = okResult.map(x => x * 2);
821
+ *
822
+ * // Using match to handle both cases
823
+ * const output = result.match(
824
+ * value => `Success: ${value}`,
825
+ * error => `Error: ${error}`
826
+ * );
827
+ * ```
828
+ *
829
+ * @remarks
830
+ * This class provides a way to handle operations that might fail, making error handling more explicit
831
+ * and type-safe. It includes methods for transforming, combining, and extracting values in a safe manner.
832
+ *
833
+ * The Result type is immutable - all transformation methods return a new Result instance.
834
+ */
835
+ declare class Result<T, E = Error> {
836
+ readonly value?: T | undefined;
837
+ readonly error?: E | undefined;
838
+ private constructor();
839
+ /**
840
+ * Creates a new Result instance with a success value
841
+ * @template T The type of the success value
842
+ * @template E The type of the error value
843
+ * @param value The success value
844
+ * @returns A new Result instance containing the success value
845
+ */
846
+ static Ok<T, E>(value: T): Result<T, E>;
847
+ /**
848
+ * Creates a new Result instance with an error value
849
+ * @template T The type of the success value
850
+ * @template E The type of the error value
851
+ * @param error The error value
852
+ * @returns A new Result instance containing the error value
853
+ */
854
+ static Err<T, E>(error: E): Result<T, E>;
855
+ /**
856
+ * Creates a new Result instance with an Error created from a string message
857
+ * @template T The type of the success value
858
+ * @param errorMessage The error message string
859
+ * @returns A new Result instance containing an Error with the given message
860
+ */
861
+ static ErrFromStr<T>(errorMessage: string): Result<T>;
862
+ /**
863
+ * Maps the success value to a new value using the provided function
864
+ * @template U The type of the new success value
865
+ * @param fn The mapping function
866
+ * @returns A new Result with the mapped success value or the original error
867
+ */
868
+ map<U>(fn: (value: T) => U): Result<U, E>;
869
+ /**
870
+ * Maps the error value to a new error using the provided function
871
+ * @template F The type of the new error value
872
+ * @param fn The mapping function
873
+ * @returns A new Result with the mapped error value or the original success value
874
+ */
875
+ mapErr<F>(fn: (error: E) => F): Result<T, F>;
876
+ /**
877
+ * Chains a computation that returns a Result
878
+ * @template U The type of the new success value
879
+ * @param fn The function to chain
880
+ * @returns The result of the chained function or the original error
881
+ */
882
+ andThen<U>(fn: (value: T) => Result<U, E>): Result<U, E>;
883
+ /**
884
+ * Applies one of two functions depending on whether the Result is Ok or Err
885
+ * @template U The type of the return value
886
+ * @param ok The function to apply to the success value
887
+ * @param err The function to apply to the error value
888
+ * @returns The result of applying the appropriate function
889
+ */
890
+ match<U>(ok: (value: T) => U, err: (error: E) => U): U;
891
+ /**
892
+ * Checks if the Result contains a success value
893
+ * @returns true if the Result contains a success value, false otherwise
894
+ */
895
+ isOk(): boolean;
896
+ /**
897
+ * Checks if the Result contains an error value
898
+ * @returns true if the Result contains an error value, false otherwise
899
+ */
900
+ isErr(): boolean;
901
+ /**
902
+ * Extracts the success value from the Result
903
+ * @throws Error if the Result contains an error value
904
+ * @returns The success value
905
+ */
906
+ unwrap(): T;
907
+ /**
908
+ * Returns the success value or a default value if the Result contains an error
909
+ * @param defaultValue The value to return if the Result contains an error
910
+ * @returns The success value or the default value
911
+ */
912
+ unwrapOr(defaultValue: T): T;
913
+ /**
914
+ * Extracts the error value from the Result
915
+ * @throws Error if the Result contains a success value
916
+ * @returns The error value
917
+ */
918
+ unwrapErr(): E;
919
+ /**
920
+ * Converts the Result to a string representation
921
+ * @returns A string representation of the Result
922
+ */
923
+ toString(): string;
924
+ }
925
+
926
+ /**
927
+ * Represents progress towards a goal with optional status message.
928
+ *
929
+ * @remarks
930
+ * Used to track progress of operations without depending on DOM ProgressEvent.
931
+ * Progress is indeterminate when total is 0.
932
+ */
933
+ interface Progress {
934
+ /** Current progress value */
935
+ current: number;
936
+ /** Total value representing 100% completion. 0 indicates indeterminate progress */
937
+ total: number;
938
+ /** Optional status message describing current progress state */
939
+ message?: string;
940
+ }
941
+ /**
942
+ * Creates and updated progress object by adding the given increment, and updating the message.
943
+ * @param progress - The progress object to update.
944
+ * @param increment - The amount to increment the progress by. Default is 1.
945
+ * @param message - The message to set on the progress object. Default is undefined.
946
+ * @returns The new progress object.
947
+ */
948
+ declare function incrementProgress(progress: Progress, message?: string, increment?: number): Progress;
949
+ /**
950
+ * Sums the given progresses into a single progress object.
951
+ * @param progresses - A collection of progresses.
952
+ * @returns A new progress which is the sum of all the given progresses.
953
+ */
954
+ declare function composeProgress(progresses: Progress[]): Progress;
955
+ /**
956
+ * Represents a result that can either be a success or a failure, with an associated progress.
957
+ * Until result is defined, the operation is still pending.
958
+ */
959
+ interface ProgressiveResult<T, E = Error> {
960
+ result?: Result<T, E>;
961
+ progress: Progress;
962
+ }
963
+ /**
964
+ * Composes multiple progressive results into a single progressive result containing an array of results.
965
+ *
966
+ * @remarks
967
+ * This function handles both array and single item progressive results, combining them into a unified result
968
+ * while maintaining progress information. It can optionally filter and order results based on expected IDs.
969
+ *
970
+ * @typeparam T - Type of the result items, must contain an 'id' string property
971
+ *
972
+ * @param progressiveResults - Array of progressive results to compose
973
+ * @param expectedIds - Optional array of IDs to filter and order the results
974
+ *
975
+ * @returns A ProgressiveResult containing an array of results (or undefined values)
976
+ * where:
977
+ * - If any input result is an error, returns an error result
978
+ * - If expectedIds is provided, returns results ordered by the expected IDs
979
+ * - If expectedIds is provided and not all IDs are found when progress is complete, returns an error
980
+ * - Otherwise returns all results combined into an array
981
+ */
982
+ declare function composeProgressiveResult<T extends {
983
+ id: string;
984
+ }>(progressiveResults: ProgressiveResult<T[] | T | undefined | null>[], expectedIds?: string[]): ProgressiveResult<(T | undefined | null)[]>;
985
+
986
+ /**
987
+ * Regular expression for validating email addresses.
988
+ *
989
+ * @remarks
990
+ * This regex validates email addresses following RFC 5322 standards.
991
+ * It checks for:
992
+ * - Local part (before @) allowing letters, numbers, and special characters
993
+ * - Domain part (after @) requiring at least one dot and valid characters
994
+ * - Case-insensitive matching
995
+ *
996
+ * @example
997
+ * ```typescript
998
+ * EMAIL.test('user@example.com') // Returns true
999
+ * EMAIL.test('invalid.email') // Returns false
1000
+ * ```
1001
+ */
1002
+ declare const EMAIL: RegExp;
1003
+
1004
+ /**
1005
+ * Compares two maps for deep equality by checking all key/value pairs.
1006
+ *
1007
+ * @param map1 - The first map to compare.
1008
+ * @param map2 - The second map to compare.
1009
+ * @returns True if both maps have the same entries; false otherwise.
1010
+ *
1011
+ * @example
1012
+ * ```typescript
1013
+ * const mapA = new Map([["key1", { a: 1 }]]);
1014
+ * const mapB = new Map([["key1", { a: 1 }]]);
1015
+ * console.log(isMapDeepEqual(mapA, mapB)); // true
1016
+ * ```
1017
+ */
1018
+ declare function isMapDeepEqual<K, V>(map1: Map<K, V>, map2: Map<K, V>): boolean;
1019
+
1020
+ export { type AnimatableBoolean, type AnimatableColor, type AnimatableEuler, type AnimatableNumber, type AnimatablePubInfo, type AnimatableString, type AnimatableValue, type AnimatableVector2, type AnimatableVector3, EMAIL, type Player, type PlayerActions, PlayerContext, type PlayerData, PlayerSlice, type PlayerStore, type PlayerStoreGetter, type PlayerStoreSetter, type Progress, type ProgressiveResult, type RawBoolean, type RawColor, type RawEuler, type RawHSL, type RawNumber, type RawRGB, type RawString, type RawTime, type RawValue, type RawVector2, type RawVector3, Result, type StoreSubscribeWithSelector, type Write, alpha, altColor, angularDistance, closestFrame, composeProgress, composeProgressiveResult, downloadBlob, downloadJSONFile, eulerToRotationMatrix, getDegenerateHexagonPath, getHexagonPath, getId, getLookup, getNamespace, hexToRgbArray, hexToRgba, hslToRgba, incrementProgress, instanceOfRawBoolean, instanceOfRawColor, instanceOfRawEuler, instanceOfRawHSL, instanceOfRawNumber, instanceOfRawRGB, instanceOfRawString, instanceOfRawVector2, instanceOfRawVector3, isMapDeepEqual, isRawObject, log, newPlayer, now, numberToDurationString, overlappingSegments, pairwise, parseJSONFileEvent, parseToMapped, pause, play, pointsToPath, rawHSLToHex, rawRGBToHex, reset, rgbToRgba, rotationMatrixToAngle, seek, setBounds, setDuration, setViewport, stringifyMapped, toDegrees, toRadians, update, useDeep, useDeepSelector, useLazy, useMediaQuery, usePlayerStore };