@ntf/math 1.4.0 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,100 +1,4 @@
1
- /**
2
- * All valid types of JavaScript you can get from `typeof`
3
- */
4
- type JavaScriptTypes = "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function";
5
- /**
6
- * A JavaScript function that can be typed (or not)
7
- */
8
- type JavaScriptFunction<Args extends Array<any> = Array<any>, ReturnType extends any = any> = (...args: Args) => ReturnType;
9
- /**
10
- * A mapped type for getting the type of a JavaScript value
11
- */
12
- type JavaScriptTypeMap = {
13
- "string": string;
14
- "number": number;
15
- "bigint": bigint;
16
- "boolean": boolean;
17
- "symbol": symbol;
18
- "undefined": undefined;
19
- "object": object;
20
- "function": JavaScriptFunction;
21
- };
22
- /**
23
- * Any kind of JavaScript number
24
- */
25
- type JavaScriptNumber = number | bigint;
26
- /**
27
- * A array that has a fixed length
28
- */
29
- type FixedArray<T, Length extends number> = Array<T> & {
30
- length: Length;
31
- };
32
- /**
33
- * A value that might look like a hex value
34
- */
35
- type HexLike = `$${string}` | `#${string}` | `0x${string}` | string;
36
- /**
37
- * A predicate function type for verifing types
38
- */
39
- type Predicate<T> = (a: unknown) => a is T;
40
- /**
41
- * Check if `value` is a finite valid number
42
- * @param value A value
43
- */
44
- declare function checkNumber(value: unknown): value is number;
45
- /**
46
- * Retrieve the value of a hex string
47
- * @param string A string
48
- */
49
- declare function getHexValue(string: string): string;
50
- /**
51
- * Check if `value` is a hex value
52
- * @param value A value
53
- */
54
- declare function checkHex(value: unknown): value is HexLike;
55
- /**
56
- * Check if `value` is a string with content
57
- * @param value A value
58
- */
59
- declare function checkString(value: unknown): value is string;
60
- /**
61
- * Check if `value` is a array
62
- * @param value A value
63
- * @param predicate A function that checks each item
64
- * @param requiredLength If needed, check if it is a fixed length array
65
- */
66
- declare function checkArray<T, Length extends number>(value: unknown, predicate?: Predicate<T>, requiredLength?: number): value is FixedArray<T, Length>;
67
- /**
68
- * Check if `value` is a number array
69
- * @param value A value
70
- * @param requiredLength If needed, check if it is a fixed length array
71
- */
72
- declare function checkNumberArray<Length extends number>(value: unknown, requiredLength?: Length): value is FixedArray<number, Length>;
73
- /**
74
- * Check if `value` is a string array
75
- * @param value A value
76
- * @param requiredLength If needed, check if it is a fixed length array
77
- */
78
- declare function checkStringArray<Length extends number>(value: unknown, requiredLength?: Length): value is FixedArray<string, Length>;
79
- /**
80
- * Check if `value` has a property called `name`
81
- * @param value A value
82
- * @param propertyName The name of the property
83
- * @param type
84
- */
85
- declare function hasProperty<Obj extends unknown, K extends PropertyKey, T extends JavaScriptTypes>(value: Obj, propertyName: K, type: T): value is Obj & {
86
- [name in K]: JavaScriptTypeMap[T];
87
- };
88
- declare const NodeJSCustomInspect: unique symbol;
89
-
90
- interface IToString {
91
- /**
92
- * Returns a string representation of an object.
93
- */
94
- toString(): string;
95
- get [Symbol.toStringTag](): string;
96
- [NodeJSCustomInspect](): string;
97
- }
1
+ import { IToString, NodeJSCustomInspect, FixedArray } from '@ntf/types';
98
2
 
99
3
  interface IGeometryObject extends IToString {
100
4
  readonly area: number;
@@ -134,135 +38,6 @@ declare class Size implements ISize, IGeometryObject, IToVec2 {
134
38
  toVec2(): Vec2Like;
135
39
  }
136
40
 
137
- interface IRGB {
138
- red: number;
139
- green: number;
140
- blue: number;
141
- }
142
- interface IToRGB {
143
- toRGB(): RGBLike;
144
- }
145
- type RGBArray = [number, number, number];
146
- type RGBString = `rgb(${number},${number},${number})`;
147
- type RGBLike = IRGB | RGBArray | RGBString | IToRGB;
148
- type RGBArguments = [rgb: RGBLike] | RGBArray;
149
- interface IRBBA extends IRGB {
150
- alpha: number;
151
- }
152
- interface IToRGBA {
153
- toRGBA(): RGBALike;
154
- }
155
- type RGBAArray = [number, number, number, number];
156
- type RGBAString = `rgba(${number},${number},${number},${number})`;
157
- type RGBALike = IRBBA | RGBAArray | RGBAString | IToRGBA;
158
- type RGBAArguments = [rgba: RGBALike] | RGBAArray;
159
- type IAnyRGB = IRGB | IRBBA;
160
- type AnyRGBArray = RGBArray | RGBAArray;
161
- type AnyRGBString = RGBString | RGBAString;
162
- type IAnyToRGB = IToRGB | IToRGBA;
163
- type AnyRGBLike = IAnyRGB | AnyRGBArray | AnyRGBString | HexLike | number | IAnyToRGB;
164
- type AnyRGBArguments = RGBArguments | RGBAArguments;
165
- declare class RGBA implements IRBBA, IToVec2, IToVec3, IToHSL, IToHSLA, IToString {
166
- private _red;
167
- get red(): number;
168
- set red(val: number);
169
- private _green;
170
- get green(): number;
171
- set green(val: number);
172
- private _blue;
173
- get blue(): number;
174
- set blue(val: number);
175
- private _alpha;
176
- get alpha(): number;
177
- set alpha(val: number);
178
- static resolve(a: unknown): RGBA;
179
- static resolveArgs(args: AnyRGBArguments): RGBA;
180
- static cast(a: unknown): RGBA | undefined;
181
- static is(a: unknown): a is AnyRGBLike;
182
- constructor(red: number, green: number, blue: number, alpha?: number);
183
- toArray(withAlpha?: boolean): AnyRGBArray;
184
- toJSON(withAlpha?: boolean): IAnyRGB;
185
- toString(withAlpha?: boolean): AnyRGBString;
186
- get [Symbol.toStringTag](): string;
187
- [NodeJSCustomInspect](): string;
188
- toVec2(): Vec2Like;
189
- toVec3(): Vec3Like;
190
- toHSL(withAlpha?: false): HSLLike;
191
- toHSL(withAlpha?: true): HSLALike;
192
- toHSLA(): HSLALike;
193
- invert(withAlpha?: boolean): RGBA;
194
- }
195
- interface IHSL {
196
- hue: number;
197
- saturation: number;
198
- luminace: number;
199
- }
200
- interface IToHSL {
201
- toHSL(): HSLLike;
202
- }
203
- type HSLArray = [number, number, number];
204
- type HSLString = `hsl(${number},${number},${number})`;
205
- type HSLLike = IHSL | HSLArray | HSLString | IToHSL;
206
- type HSLArguments = HSLArray | [hsl: HSLLike];
207
- interface IHSLA extends IHSL {
208
- alpha: number;
209
- }
210
- interface IToHSLA {
211
- toHSLA(): HSLALike;
212
- }
213
- type HSLAArray = [number, number, number, number];
214
- type HSLAString = `hsla(${number},${number},${number},${number})`;
215
- type HSLALike = IHSLA | HSLAArray | HSLAString | IToHSLA;
216
- type HSLAArguments = HSLAArray | [hsla: HSLALike];
217
- type IAnyHSL = IHSL | IHSLA;
218
- type AnyHSLArray = HSLArray | HSLAArray;
219
- type AnyHSLString = HSLString | HSLAString;
220
- type IAnyToHSL = IToHSL | IToHSLA;
221
- type AnyHSLLike = IAnyHSL | AnyHSLArray | AnyHSLString | HexLike | number | IAnyToHSL;
222
- type AnyHSLArguments = HSLArguments | HSLAArguments;
223
- declare class HSLA implements IHSLA, IToRGB, IToRGBA, IToVec2, IToVec3, IToString {
224
- private _hue;
225
- get hue(): number;
226
- set hue(val: number);
227
- private _saturation;
228
- get saturation(): number;
229
- set saturation(val: number);
230
- private _luminace;
231
- get luminace(): number;
232
- set luminace(val: number);
233
- private _alpha;
234
- get alpha(): number;
235
- set alpha(val: number);
236
- static resolve(a: unknown): HSLA;
237
- static resolveArgs(args: AnyHSLArguments): HSLA;
238
- static cast(a: unknown): HSLA | undefined;
239
- static is(a: unknown): a is AnyHSLLike;
240
- constructor(hue: number, saturation: number, luminace: number, alpha?: number);
241
- toArray(withAlpha?: boolean): AnyHSLArray;
242
- toJSON(withAlpha?: boolean): IAnyHSL;
243
- toString(withAlpha?: boolean): AnyHSLString;
244
- get [Symbol.toStringTag](): string;
245
- [NodeJSCustomInspect](): string;
246
- toRGB(withAlpha?: true): RGBALike;
247
- toRGB(withAlpha?: false): RGBLike;
248
- toRGBA(): RGBALike;
249
- toVec2(): Vec2Like;
250
- toVec3(): Vec3Like;
251
- invert(withAlpha?: boolean): HSLA;
252
- }
253
- type AnyColorArray = AnyRGBArray | AnyHSLArray;
254
- type AnyColorString = AnyRGBString | AnyHSLString;
255
- type IAnyColor = IAnyRGB | IAnyHSL;
256
- type IAnyToColor = IAnyToRGB | IAnyToHSL;
257
- type AnyColorLike = AnyColorArray | AnyColorString | IAnyColor | HexLike | number;
258
- type AnyColorArguments = AnyColorArray | [color: AnyColorLike];
259
- type AnyColor = RGBA | HSLA;
260
- declare namespace AnyColor {
261
- function cast(a: unknown, preferHSL?: boolean): AnyColor | undefined;
262
- function resolve(a: unknown, preferHSL?: boolean): AnyColor;
263
- function resolveArgs(args: AnyColorArguments, preferHSL?: boolean): AnyColor;
264
- }
265
-
266
41
  interface ICircle extends IVec2 {
267
42
  radius: number;
268
43
  }
@@ -634,6 +409,124 @@ declare class Quaternion implements IToVec3, IToMat3, IToMat4, IToString {
634
409
  toMat4(): Mat4Like;
635
410
  }
636
411
 
412
+ interface IRGB {
413
+ red: number;
414
+ green: number;
415
+ blue: number;
416
+ }
417
+ interface IToRGB {
418
+ toRGB(): RGBLike;
419
+ }
420
+ type RGBArray = [number, number, number];
421
+ type RGBString = `rgb(${number},${number},${number})`;
422
+ type RGBLike = IRGB | RGBArray | RGBString | IToRGB;
423
+ type RGBArguments = [rgb: RGBLike] | RGBArray;
424
+ interface IRBBA extends IRGB {
425
+ alpha: number;
426
+ }
427
+ interface IToRGBA {
428
+ toRGBA(): RGBALike;
429
+ }
430
+ type RGBAArray = [number, number, number, number];
431
+ type RGBAString = `rgba(${number},${number},${number},${number})`;
432
+ type RGBALike = IRBBA | RGBAArray | RGBAString | IToRGBA;
433
+ type RGBAArguments = [rgba: RGBALike] | RGBAArray;
434
+ type IAnyRGB = IRGB | IRBBA;
435
+ type AnyRGBArray = RGBArray | RGBAArray;
436
+ type AnyRGBString = RGBString | RGBAString;
437
+ type IAnyToRGB = IToRGB | IToRGBA;
438
+ type AnyRGBLike = IAnyRGB | AnyRGBArray | AnyRGBString | number | IAnyToRGB;
439
+ type AnyRGBArguments = RGBArguments | RGBAArguments;
440
+ declare class RGBA implements IRBBA, IToVec2, IToVec3, IToHSL, IToHSLA, IToString {
441
+ private _red;
442
+ get red(): number;
443
+ set red(val: number);
444
+ private _green;
445
+ get green(): number;
446
+ set green(val: number);
447
+ private _blue;
448
+ get blue(): number;
449
+ set blue(val: number);
450
+ private _alpha;
451
+ get alpha(): number;
452
+ set alpha(val: number);
453
+ static resolve(a: unknown): RGBA;
454
+ static resolveArgs(args: AnyRGBArguments): RGBA;
455
+ static cast(a: unknown): RGBA | undefined;
456
+ static is(a: unknown): a is AnyRGBLike;
457
+ constructor(red: number, green: number, blue: number, alpha?: number);
458
+ toArray(withAlpha?: boolean): AnyRGBArray;
459
+ toJSON(withAlpha?: boolean): IAnyRGB;
460
+ toString(withAlpha?: boolean): AnyRGBString;
461
+ get [Symbol.toStringTag](): string;
462
+ [NodeJSCustomInspect](): string;
463
+ toVec2(): Vec2Like;
464
+ toVec3(): Vec3Like;
465
+ toHSL(withAlpha?: false): HSLLike;
466
+ toHSL(withAlpha?: true): HSLALike;
467
+ toHSLA(): HSLALike;
468
+ invert(withAlpha?: boolean): RGBA;
469
+ }
470
+
471
+ interface IHSL {
472
+ hue: number;
473
+ saturation: number;
474
+ luminace: number;
475
+ }
476
+ interface IToHSL {
477
+ toHSL(): HSLLike;
478
+ }
479
+ type HSLArray = [number, number, number];
480
+ type HSLString = `hsl(${number},${number},${number})`;
481
+ type HSLLike = IHSL | HSLArray | HSLString | IToHSL;
482
+ type HSLArguments = HSLArray | [hsl: HSLLike];
483
+ interface IHSLA extends IHSL {
484
+ alpha: number;
485
+ }
486
+ interface IToHSLA {
487
+ toHSLA(): HSLALike;
488
+ }
489
+ type HSLAArray = [number, number, number, number];
490
+ type HSLAString = `hsla(${number},${number},${number},${number})`;
491
+ type HSLALike = IHSLA | HSLAArray | HSLAString | IToHSLA;
492
+ type HSLAArguments = HSLAArray | [hsla: HSLALike];
493
+ type IAnyHSL = IHSL | IHSLA;
494
+ type AnyHSLArray = HSLArray | HSLAArray;
495
+ type AnyHSLString = HSLString | HSLAString;
496
+ type IAnyToHSL = IToHSL | IToHSLA;
497
+ type AnyHSLLike = IAnyHSL | AnyHSLArray | AnyHSLString | number | IAnyToHSL;
498
+ type AnyHSLArguments = HSLArguments | HSLAArguments;
499
+ declare class HSLA implements IHSLA, IToRGB, IToRGBA, IToVec2, IToVec3, IToString {
500
+ private _hue;
501
+ get hue(): number;
502
+ set hue(val: number);
503
+ private _saturation;
504
+ get saturation(): number;
505
+ set saturation(val: number);
506
+ private _luminace;
507
+ get luminace(): number;
508
+ set luminace(val: number);
509
+ private _alpha;
510
+ get alpha(): number;
511
+ set alpha(val: number);
512
+ static resolve(a: unknown): HSLA;
513
+ static resolveArgs(args: AnyHSLArguments): HSLA;
514
+ static cast(a: unknown): HSLA | undefined;
515
+ static is(a: unknown): a is AnyHSLLike;
516
+ constructor(hue: number, saturation: number, luminace: number, alpha?: number);
517
+ toArray(withAlpha?: boolean): AnyHSLArray;
518
+ toJSON(withAlpha?: boolean): IAnyHSL;
519
+ toString(withAlpha?: boolean): AnyHSLString;
520
+ get [Symbol.toStringTag](): string;
521
+ [NodeJSCustomInspect](): string;
522
+ toRGB(withAlpha?: true): RGBALike;
523
+ toRGB(withAlpha?: false): RGBLike;
524
+ toRGBA(): RGBALike;
525
+ toVec2(): Vec2Like;
526
+ toVec3(): Vec3Like;
527
+ invert(withAlpha?: boolean): HSLA;
528
+ }
529
+
637
530
  interface IVec3 extends IVec2 {
638
531
  z: number;
639
532
  }
@@ -870,6 +763,9 @@ declare class QuadFunction extends MathFunction<[number]> {
870
763
  [NodeJSCustomInspect](): string;
871
764
  }
872
765
 
766
+ declare function numberToRGB(number: number): FixedArray<number, 3>;
767
+ declare function numberToRGBA(number: number): FixedArray<number, 4>;
768
+
873
769
  /**
874
770
  * A error when a value wasn't able to be resolved to another type
875
771
  */
@@ -958,6 +854,19 @@ declare class Triangle3D extends Triangle<Vec3> {
958
854
  get c(): number;
959
855
  }
960
856
 
857
+ type AnyColorArray = AnyRGBArray | AnyHSLArray;
858
+ type AnyColorString = AnyRGBString | AnyHSLString;
859
+ type IAnyColor = IAnyRGB | IAnyHSL;
860
+ type IAnyToColor = IAnyToRGB | IAnyToHSL;
861
+ type AnyColorLike = AnyColorArray | AnyColorString | IAnyColor | number;
862
+ type AnyColorArguments = AnyColorArray | [color: AnyColorLike];
863
+ type AnyColor = RGBA | HSLA;
864
+ declare namespace AnyColor {
865
+ function cast(a: unknown, preferHSL?: boolean): AnyColor | undefined;
866
+ function resolve(a: unknown, preferHSL?: boolean): AnyColor;
867
+ function resolveArgs(args: AnyColorArguments, preferHSL?: boolean): AnyColor;
868
+ }
869
+
961
870
  declare class Transform2D implements IToMat3, IToString {
962
871
  parent?: Transform2D | undefined;
963
872
  origin: Vec2;
@@ -1034,4 +943,4 @@ declare function logHypot(a: number, b: number): number;
1034
943
  declare const EPSILON = 1e-16;
1035
944
  declare const lerp: <T extends number | bigint>(a: T, b: T, t: T) => number;
1036
945
 
1037
- export { AnyColor, type AnyColorArguments, type AnyColorArray, type AnyColorLike, type AnyColorString, type AnyHSLArguments, type AnyHSLArray, type AnyHSLLike, type AnyHSLString, type AnyRGBArguments, type AnyRGBArray, type AnyRGBLike, type AnyRGBString, BoundingBox, type BoundingBoxArgs, type BoundingBoxArray, type BoundingBoxLike, type BoundingBoxString, Circle, type CircleArguments, type CircleArray, type CircleLike, type CircleString, DJB2_OFFSET, EPSILON, FNV1_OFFSET, FNV1_PRIME, type FixedArray, HSLA, type HSLAArguments, type HSLAArray, type HSLALike, type HSLAString, type HSLArguments, type HSLArray, type HSLLike, type HSLString, type HexLike, type IAnyColor, type IAnyHSL, type IAnyRGB, type IAnyToColor, type IAnyToHSL, type IAnyToRGB, type IBoundingBox, type ICircle, type IGeometryObject, type IHSL, type IHSLA, type IHash, type IMat3, type IMat4, type IQuaternion, type IRBBA, type IRGB, type IRectangle, type ISize, type IToBoundingBox, type IToCircle, type IToHSL, type IToHSLA, type IToMat3, type IToMat4, type IToQuaternion, type IToRGB, type IToRGBA, type IToRectangle, type IToSize, type IToVec2, type IToVec3, type ITriangle, type IVec2, type IVec3, type JavaScriptFunction, type JavaScriptNumber, type JavaScriptTypeMap, type JavaScriptTypes, LinearFunction, type LinearFunctionString, MAX_ANGLE_DEGREE, MD2, Mat3, type Mat3Arguments, type Mat3Array, type Mat3Like, type Mat3NestedArray, type Mat3String, Mat4, type Mat4Arguments, type Mat4Array, type Mat4Like, type Mat4NestedArray, type Mat4String, MathFunction, NodeJSCustomInspect, type Predicate, QuadFunction, type QuadFunctionString, type QuadFunctionStrings, type QuadFunctionType, Quaternion, type QuaternionArguments, type QuaternionArray, type QuaternionLike, type QuaternionString, RGBA, type RGBAArguments, type RGBAArray, type RGBALike, type RGBAString, type RGBArguments, type RGBArray, type RGBLike, type RGBString, Rectangle, type RectangleArguments, type RectangleArray, type RectangleLike, type RectangleString, ResolveError, type SignCharacter, Size, type SizeArguments, type SizeArray, type SizeLike, type SizeString, Transform2D, Transform3D, Triangle, Triangle2D, Triangle3D, Vec2, type Vec2Arguments, type Vec2Array, type Vec2Like, type Vec2String, Vec3, type Vec3Arguments, type Vec3Array, type Vec3Like, type Vec3String, checkArray, checkHex, checkNumber, checkNumberArray, checkString, checkStringArray, clamp, clampAngleDegree, clampAngleRadian, degreeToRadian, djb2, fnv1, getHexValue, hasProperty, lerp, logHypot, radianToDegree, sdbm, signCharacter };
946
+ export { AnyColor, type AnyColorArguments, type AnyColorArray, type AnyColorLike, type AnyColorString, type AnyHSLArguments, type AnyHSLArray, type AnyHSLLike, type AnyHSLString, type AnyRGBArguments, type AnyRGBArray, type AnyRGBLike, type AnyRGBString, BoundingBox, type BoundingBoxArgs, type BoundingBoxArray, type BoundingBoxLike, type BoundingBoxString, Circle, type CircleArguments, type CircleArray, type CircleLike, type CircleString, DJB2_OFFSET, EPSILON, FNV1_OFFSET, FNV1_PRIME, HSLA, type HSLAArguments, type HSLAArray, type HSLALike, type HSLAString, type HSLArguments, type HSLArray, type HSLLike, type HSLString, type IAnyColor, type IAnyHSL, type IAnyRGB, type IAnyToColor, type IAnyToHSL, type IAnyToRGB, type IBoundingBox, type ICircle, type IGeometryObject, type IHSL, type IHSLA, type IHash, type IMat3, type IMat4, type IQuaternion, type IRBBA, type IRGB, type IRectangle, type ISize, type IToBoundingBox, type IToCircle, type IToHSL, type IToHSLA, type IToMat3, type IToMat4, type IToQuaternion, type IToRGB, type IToRGBA, type IToRectangle, type IToSize, type IToVec2, type IToVec3, type ITriangle, type IVec2, type IVec3, LinearFunction, type LinearFunctionString, MAX_ANGLE_DEGREE, MD2, Mat3, type Mat3Arguments, type Mat3Array, type Mat3Like, type Mat3NestedArray, type Mat3String, Mat4, type Mat4Arguments, type Mat4Array, type Mat4Like, type Mat4NestedArray, type Mat4String, MathFunction, QuadFunction, type QuadFunctionString, type QuadFunctionStrings, type QuadFunctionType, Quaternion, type QuaternionArguments, type QuaternionArray, type QuaternionLike, type QuaternionString, RGBA, type RGBAArguments, type RGBAArray, type RGBALike, type RGBAString, type RGBArguments, type RGBArray, type RGBLike, type RGBString, Rectangle, type RectangleArguments, type RectangleArray, type RectangleLike, type RectangleString, ResolveError, type SignCharacter, Size, type SizeArguments, type SizeArray, type SizeLike, type SizeString, Transform2D, Transform3D, Triangle, Triangle2D, Triangle3D, Vec2, type Vec2Arguments, type Vec2Array, type Vec2Like, type Vec2String, Vec3, type Vec3Arguments, type Vec3Array, type Vec3Like, type Vec3String, clamp, clampAngleDegree, clampAngleRadian, degreeToRadian, djb2, fnv1, lerp, logHypot, numberToRGB, numberToRGBA, radianToDegree, sdbm, signCharacter };