@tempots/std 0.9.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 (132) hide show
  1. package/dist/arrays.d.ts +49 -0
  2. package/dist/arrays.js +249 -0
  3. package/dist/async-result.d.ts +37 -0
  4. package/dist/async-result.js +75 -0
  5. package/dist/bigint.d.ts +18 -0
  6. package/dist/bigint.js +110 -0
  7. package/dist/booleans.d.ts +23 -0
  8. package/dist/booleans.js +68 -0
  9. package/dist/colors/cmyk.d.ts +21 -0
  10. package/dist/colors/cmyk.js +54 -0
  11. package/dist/colors/convert.d.ts +283 -0
  12. package/dist/colors/convert.js +742 -0
  13. package/dist/colors/hsl.d.ts +24 -0
  14. package/dist/colors/hsl.js +56 -0
  15. package/dist/colors/hsla.d.ts +18 -0
  16. package/dist/colors/hsla.js +35 -0
  17. package/dist/colors/hsluv.d.ts +24 -0
  18. package/dist/colors/hsluv.js +56 -0
  19. package/dist/colors/hsv.d.ts +24 -0
  20. package/dist/colors/hsv.js +54 -0
  21. package/dist/colors/lab.d.ts +24 -0
  22. package/dist/colors/lab.js +54 -0
  23. package/dist/colors/lch.d.ts +19 -0
  24. package/dist/colors/lch.js +44 -0
  25. package/dist/colors/luv.d.ts +19 -0
  26. package/dist/colors/luv.js +45 -0
  27. package/dist/colors/rgb.d.ts +13 -0
  28. package/dist/colors/rgb.js +47 -0
  29. package/dist/colors/rgba.d.ts +12 -0
  30. package/dist/colors/rgba.js +44 -0
  31. package/dist/colors/srgb.d.ts +24 -0
  32. package/dist/colors/srgb.js +51 -0
  33. package/dist/colors/xyz.d.ts +19 -0
  34. package/dist/colors/xyz.js +41 -0
  35. package/dist/edit.d.ts +20 -0
  36. package/dist/edit.js +29 -0
  37. package/dist/equals.d.ts +3 -0
  38. package/dist/equals.js +122 -0
  39. package/dist/functions.d.ts +20 -0
  40. package/dist/functions.js +38 -0
  41. package/dist/json.d.ts +14 -0
  42. package/dist/json.js +33 -0
  43. package/dist/match.d.ts +16 -0
  44. package/dist/match.js +45 -0
  45. package/dist/maybe.d.ts +9 -0
  46. package/dist/maybe.js +25 -0
  47. package/dist/memoize.d.ts +1 -0
  48. package/dist/memoize.js +9 -0
  49. package/dist/newtype.d.ts +28 -0
  50. package/dist/newtype.js +29 -0
  51. package/dist/numbers.d.ts +104 -0
  52. package/dist/numbers.js +183 -0
  53. package/dist/objects.d.ts +9 -0
  54. package/dist/objects.js +33 -0
  55. package/dist/ord.d.ts +19 -0
  56. package/dist/ord.js +73 -0
  57. package/dist/reg-exps.d.ts +10 -0
  58. package/dist/reg-exps.js +43 -0
  59. package/dist/result.d.ts +31 -0
  60. package/dist/result.js +95 -0
  61. package/dist/strings.d.ts +314 -0
  62. package/dist/strings.js +685 -0
  63. package/dist/types/assert.d.ts +12 -0
  64. package/dist/types/assert.js +13 -0
  65. package/dist/types/differentiate.d.ts +13 -0
  66. package/dist/types/differentiate.js +14 -0
  67. package/dist/types/functions.d.ts +22 -0
  68. package/dist/types/functions.js +13 -0
  69. package/dist/types/generic.d.ts +9 -0
  70. package/dist/types/generic.js +13 -0
  71. package/dist/types/objects.d.ts +50 -0
  72. package/dist/types/objects.js +13 -0
  73. package/dist/types/tuples.d.ts +44 -0
  74. package/dist/types/tuples.js +24 -0
  75. package/dist/types/utility.d.ts +2 -0
  76. package/dist/types/utility.js +1 -0
  77. package/dist/uuid.d.ts +13 -0
  78. package/dist/uuid.js +56 -0
  79. package/dist/validation.d.ts +23 -0
  80. package/dist/validation.js +44 -0
  81. package/package.json +36 -0
  82. package/src/arrays.ts +296 -0
  83. package/src/async-result.ts +103 -0
  84. package/src/bigint.ts +111 -0
  85. package/src/booleans.ts +73 -0
  86. package/src/colors/cmyk.ts +84 -0
  87. package/src/colors/convert.ts +1093 -0
  88. package/src/colors/hsl.ts +73 -0
  89. package/src/colors/hsla.ts +45 -0
  90. package/src/colors/hsluv.ts +73 -0
  91. package/src/colors/hsv.ts +75 -0
  92. package/src/colors/lab.ts +69 -0
  93. package/src/colors/lch.ts +53 -0
  94. package/src/colors/luv.ts +56 -0
  95. package/src/colors/rgb.ts +55 -0
  96. package/src/colors/rgba.ts +53 -0
  97. package/src/colors/srgb.ts +72 -0
  98. package/src/colors/xyz.ts +52 -0
  99. package/src/edit.ts +29 -0
  100. package/src/equals.ts +116 -0
  101. package/src/functions.ts +108 -0
  102. package/src/json.ts +52 -0
  103. package/src/match.ts +88 -0
  104. package/src/maybe.ts +32 -0
  105. package/src/memoize.ts +9 -0
  106. package/src/newtype.ts +59 -0
  107. package/src/numbers.ts +222 -0
  108. package/src/objects.ts +47 -0
  109. package/src/ord.ts +79 -0
  110. package/src/reg-exps.ts +48 -0
  111. package/src/result.ts +140 -0
  112. package/src/strings.ts +768 -0
  113. package/src/types/assert.ts +96 -0
  114. package/src/types/differentiate.ts +89 -0
  115. package/src/types/functions.ts +114 -0
  116. package/src/types/generic.ts +42 -0
  117. package/src/types/objects.ts +212 -0
  118. package/src/types/tuples.ts +244 -0
  119. package/src/types/utility.ts +3 -0
  120. package/src/uuid.ts +61 -0
  121. package/src/validation.ts +69 -0
  122. package/test/arrays.spec.ts +410 -0
  123. package/test/colors.spec.ts +406 -0
  124. package/test/commmon.ts +9 -0
  125. package/test/equals.spec.ts +165 -0
  126. package/test/functions.spec.ts +9 -0
  127. package/test/index.d.ts +20 -0
  128. package/test/objects.spec.ts +22 -0
  129. package/test/reg-exps.spec.ts +33 -0
  130. package/test/strings.spec.ts +333 -0
  131. package/test/uuid.spec.ts +35 -0
  132. package/tsconfig.json +19 -0
@@ -0,0 +1,24 @@
1
+ export declare class HSL {
2
+ static fromString(s: string): HSL;
3
+ static ofChannels([hue, saturation, lightness]: [
4
+ hue: number,
5
+ saturation: number,
6
+ lightness: number
7
+ ]): HSL;
8
+ readonly hue: number;
9
+ readonly saturation: number;
10
+ readonly lightness: number;
11
+ /**
12
+ *
13
+ * @param hue Angle in degrees (0-360)
14
+ * @param saturation Percentage (0-100)
15
+ * @param lightness Percentage (0-100)
16
+ */
17
+ constructor(hue: number, saturation?: number, lightness?: number);
18
+ withHue(hue: number): HSL;
19
+ withSaturation(saturation: number): HSL;
20
+ withLightness(lightness: number): HSL;
21
+ toChannels(): [number, number, number];
22
+ toString(): string;
23
+ equals(other: HSL, tollerance?: number): boolean;
24
+ }
@@ -0,0 +1,56 @@
1
+ import { clamp, nearEquals } from '../numbers';
2
+ const TOLLERANCE = 0.0001;
3
+ export class HSL {
4
+ static fromString(s) {
5
+ const m = s.match(/^hsl\((\d+)(deg)?, ?(\d+(?:\.\d+)?)%?, ?(\d+(?:\.\d+)?)%?\)$/);
6
+ if (m != null) {
7
+ const [, h, , s, l] = m;
8
+ return new HSL(parseFloat(h), parseFloat(s), parseFloat(l));
9
+ }
10
+ else {
11
+ throw new Error(`Invalid HSL string: ${s}`);
12
+ }
13
+ }
14
+ static ofChannels([hue, saturation, lightness]) {
15
+ return new HSL(hue, saturation * 100, lightness * 100);
16
+ }
17
+ hue;
18
+ saturation;
19
+ lightness;
20
+ /**
21
+ *
22
+ * @param hue Angle in degrees (0-360)
23
+ * @param saturation Percentage (0-100)
24
+ * @param lightness Percentage (0-100)
25
+ */
26
+ constructor(hue, saturation = 50, lightness = 50) {
27
+ this.hue = hue % 360.0;
28
+ this.saturation = clamp(saturation, 0, 100);
29
+ this.lightness = clamp(lightness, 0, 100);
30
+ }
31
+ withHue(hue) {
32
+ return new HSL(hue, this.saturation, this.lightness);
33
+ }
34
+ withSaturation(saturation) {
35
+ return new HSL(this.hue, saturation, this.lightness);
36
+ }
37
+ withLightness(lightness) {
38
+ return new HSL(this.hue, this.saturation, lightness);
39
+ }
40
+ toChannels() {
41
+ return [this.hue, this.saturation / 100, this.lightness / 100];
42
+ }
43
+ toString() {
44
+ return `hsl(${this.hue}deg, ${this.saturation}%, ${this.lightness}%)`;
45
+ }
46
+ equals(other, tollerance = TOLLERANCE) {
47
+ if ((nearEquals(this.lightness, other.lightness, tollerance) &&
48
+ nearEquals(this.saturation, 0, tollerance)) ||
49
+ nearEquals(this.saturation, 100, tollerance)) {
50
+ return true;
51
+ }
52
+ return (nearEquals(this.hue, other.hue, tollerance) &&
53
+ nearEquals(this.saturation, other.saturation, tollerance) &&
54
+ nearEquals(this.lightness, other.lightness, tollerance));
55
+ }
56
+ }
@@ -0,0 +1,18 @@
1
+ import { HSL } from './hsl';
2
+ export declare class HSLA extends HSL {
3
+ readonly alpha: number;
4
+ /**
5
+ *
6
+ * @param hue Angle in degrees (0-360)
7
+ * @param saturation Percentage (0-100)
8
+ * @param lightness Percentage (0-100)
9
+ * @param alpha Percentage (0-100)
10
+ */
11
+ constructor(hue: number, saturation?: number, lightness?: number, alpha?: number);
12
+ withHue(hue: number): HSLA;
13
+ withSaturation(saturation: number): HSLA;
14
+ withLightness(lightness: number): HSLA;
15
+ withAlpha(alpha: number): HSLA;
16
+ toString(): string;
17
+ equals(other: HSLA, tollerance?: number): boolean;
18
+ }
@@ -0,0 +1,35 @@
1
+ import { clamp, nearEquals } from '../numbers';
2
+ import { HSL } from './hsl';
3
+ const TOLLERANCE = 0.0001;
4
+ export class HSLA extends HSL {
5
+ alpha;
6
+ /**
7
+ *
8
+ * @param hue Angle in degrees (0-360)
9
+ * @param saturation Percentage (0-100)
10
+ * @param lightness Percentage (0-100)
11
+ * @param alpha Percentage (0-100)
12
+ */
13
+ constructor(hue, saturation = 50, lightness = 50, alpha = 100) {
14
+ super(hue, saturation, lightness);
15
+ this.alpha = clamp(0, 1, alpha);
16
+ }
17
+ withHue(hue) {
18
+ return new HSLA(hue, this.saturation, this.lightness, this.alpha);
19
+ }
20
+ withSaturation(saturation) {
21
+ return new HSLA(this.hue, saturation, this.lightness, this.alpha);
22
+ }
23
+ withLightness(lightness) {
24
+ return new HSLA(this.hue, this.saturation, lightness, this.alpha);
25
+ }
26
+ withAlpha(alpha) {
27
+ return new HSLA(this.hue, this.saturation, this.lightness, alpha);
28
+ }
29
+ toString() {
30
+ return `hsla(${this.hue}deg, ${this.saturation}%, ${this.lightness}%, ${this.alpha / 100})`;
31
+ }
32
+ equals(other, tollerance = TOLLERANCE) {
33
+ return super.equals(other, tollerance) && nearEquals(this.alpha, other.alpha, tollerance);
34
+ }
35
+ }
@@ -0,0 +1,24 @@
1
+ export declare class HSLuv {
2
+ static fromString(s: string): HSLuv;
3
+ static ofChannels([hue, saturation, lightness]: [
4
+ hue: number,
5
+ saturation: number,
6
+ lightness: number
7
+ ]): HSLuv;
8
+ readonly hue: number;
9
+ readonly saturation: number;
10
+ readonly lightness: number;
11
+ /**
12
+ *
13
+ * @param hue Angle in degrees (0-360)
14
+ * @param saturation
15
+ * @param lightness
16
+ */
17
+ constructor(hue: number, saturation: number, lightness: number);
18
+ withHue(hue: number): HSLuv;
19
+ withSaturation(saturation: number): HSLuv;
20
+ withLightness(lightness: number): HSLuv;
21
+ toChannels(): [number, number, number];
22
+ toString(): string;
23
+ equals(other: HSLuv, tollerance?: number): boolean;
24
+ }
@@ -0,0 +1,56 @@
1
+ import { nearEquals } from '../numbers';
2
+ const TOLLERANCE = 0.0001;
3
+ export class HSLuv {
4
+ static fromString(s) {
5
+ const m = s.match(/^hsluv\((\d+)(deg)?, ?(\d+(?:\.\d+)?)%?, ?(\d+(?:\.\d+)?)%?\)$/);
6
+ if (m != null) {
7
+ const [, h, , s, l] = m;
8
+ return new HSLuv(parseFloat(h), parseFloat(s), parseFloat(l));
9
+ }
10
+ else {
11
+ throw new Error(`Invalid HSLuv string: ${s}`);
12
+ }
13
+ }
14
+ static ofChannels([hue, saturation, lightness]) {
15
+ return new HSLuv(hue, saturation, lightness);
16
+ }
17
+ hue;
18
+ saturation;
19
+ lightness;
20
+ /**
21
+ *
22
+ * @param hue Angle in degrees (0-360)
23
+ * @param saturation
24
+ * @param lightness
25
+ */
26
+ constructor(hue, saturation, lightness) {
27
+ this.hue = hue % 360.0;
28
+ this.saturation = saturation;
29
+ this.lightness = lightness;
30
+ }
31
+ withHue(hue) {
32
+ return new HSLuv(hue, this.saturation, this.lightness);
33
+ }
34
+ withSaturation(saturation) {
35
+ return new HSLuv(this.hue, saturation, this.lightness);
36
+ }
37
+ withLightness(lightness) {
38
+ return new HSLuv(this.hue, this.saturation, lightness);
39
+ }
40
+ toChannels() {
41
+ return [this.hue, this.saturation, this.lightness];
42
+ }
43
+ toString() {
44
+ return `hsluv(${this.hue}deg, ${this.saturation}%, ${this.lightness}%)`;
45
+ }
46
+ equals(other, tollerance = TOLLERANCE) {
47
+ if ((nearEquals(this.lightness, other.lightness, tollerance) &&
48
+ nearEquals(this.saturation, 0, tollerance)) ||
49
+ nearEquals(this.saturation, 100, tollerance)) {
50
+ return true;
51
+ }
52
+ return (nearEquals(this.hue, other.hue, tollerance) &&
53
+ nearEquals(this.saturation, other.saturation, tollerance) &&
54
+ nearEquals(this.lightness, other.lightness, tollerance));
55
+ }
56
+ }
@@ -0,0 +1,24 @@
1
+ export declare class HSV {
2
+ static fromString(s: string): HSV;
3
+ static ofChannels([hue, saturation, value]: [
4
+ hue: number,
5
+ saturation: number,
6
+ value: number
7
+ ]): HSV;
8
+ readonly hue: number;
9
+ readonly saturation: number;
10
+ readonly value: number;
11
+ /**
12
+ *
13
+ * @param hue Angle in degrees (0-360)
14
+ * @param saturation Percentage (0-100)
15
+ * @param value Percentage (0-100)
16
+ */
17
+ constructor(hue: number, saturation: number, value: number);
18
+ withHue(h: number): HSV;
19
+ withSaturation(s: number): HSV;
20
+ withValue(v: number): HSV;
21
+ toChannels(): [number, number, number];
22
+ toString(): string;
23
+ equals(other: HSV, tollerance?: number): boolean;
24
+ }
@@ -0,0 +1,54 @@
1
+ import { clamp, nearEquals } from '../numbers';
2
+ const TOLLERANCE = 0.0001;
3
+ export class HSV {
4
+ static fromString(s) {
5
+ const m = s.match(/^hsv\((\d+(?:\.\d+)?)%, ?(\d+(?:\.\d+)?)%, ?(\d+(?:\.\d+)?)%\)$/i);
6
+ if (m != null) {
7
+ const [, h, s, v] = m;
8
+ return new HSV(parseFloat(h), parseFloat(s), parseFloat(v));
9
+ }
10
+ else {
11
+ throw new Error(`Invalid HSV string: ${s}`);
12
+ }
13
+ }
14
+ static ofChannels([hue, saturation, value]) {
15
+ return new HSV(hue % 360.0, clamp(saturation * 100, 0, 100), clamp(value * 100, 0, 100));
16
+ }
17
+ hue;
18
+ saturation;
19
+ value;
20
+ /**
21
+ *
22
+ * @param hue Angle in degrees (0-360)
23
+ * @param saturation Percentage (0-100)
24
+ * @param value Percentage (0-100)
25
+ */
26
+ constructor(hue, saturation, value) {
27
+ this.hue = hue;
28
+ this.saturation = saturation;
29
+ this.value = value;
30
+ }
31
+ withHue(h) {
32
+ return new HSV(h, this.saturation, this.value);
33
+ }
34
+ withSaturation(s) {
35
+ return new HSV(this.hue, s, this.value);
36
+ }
37
+ withValue(v) {
38
+ return new HSV(this.hue, this.saturation, v);
39
+ }
40
+ toChannels() {
41
+ return [this.hue, this.saturation / 100, this.value / 100];
42
+ }
43
+ toString() {
44
+ return `hsv(${this.hue}, ${this.saturation}, ${this.value})`;
45
+ }
46
+ equals(other, tollerance = TOLLERANCE) {
47
+ if (nearEquals(this.value, other.value, tollerance) && (nearEquals(this.saturation, 0, tollerance) || nearEquals(this.saturation, 100, tollerance))) {
48
+ return true;
49
+ }
50
+ return (nearEquals(this.hue, other.hue, tollerance) &&
51
+ nearEquals(this.saturation, other.saturation, tollerance) &&
52
+ nearEquals(this.value, other.value, tollerance));
53
+ }
54
+ }
@@ -0,0 +1,24 @@
1
+ export declare class LAB {
2
+ static fromString(s: string): LAB;
3
+ static ofChannels([lightness, a, b]: [
4
+ lightness: number,
5
+ a: number,
6
+ b: number
7
+ ]): LAB;
8
+ readonly lightness: number;
9
+ readonly a: number;
10
+ readonly b: number;
11
+ /**
12
+ *
13
+ * @param lightness Lightness in range (0, 100)
14
+ * @param a usually in the range (~-150, ~+150) - not clamped
15
+ * @param b usually in the range (~-150, ~+150) - not clamped
16
+ */
17
+ constructor(lightness: number, a: number, b: number);
18
+ withL(l: number): LAB;
19
+ withA(a: number): LAB;
20
+ withB(b: number): LAB;
21
+ toChannels(): [number, number, number];
22
+ toString(): string;
23
+ equals(other: LAB, tollerance?: number): boolean;
24
+ }
@@ -0,0 +1,54 @@
1
+ import { clamp, nearEquals } from '../numbers';
2
+ const TOLLERANCE = 0.0001;
3
+ export class LAB {
4
+ static fromString(s) {
5
+ const m = s.match(/^lab\((\d+(?:\.\d+)?)°, ?(\d+(?:\.\d+)?)°, ?(\d+(?:\.\d+)?)°\)$/);
6
+ if (m != null) {
7
+ const [, lightness, a, b] = m;
8
+ return new LAB(parseFloat(lightness), parseFloat(a), parseFloat(b));
9
+ }
10
+ else {
11
+ throw new Error(`Invalid LAB string: ${s}`);
12
+ }
13
+ }
14
+ static ofChannels([lightness, a, b]) {
15
+ return new LAB(lightness, a, b);
16
+ }
17
+ lightness;
18
+ a;
19
+ b;
20
+ /**
21
+ *
22
+ * @param lightness Lightness in range (0, 100)
23
+ * @param a usually in the range (~-150, ~+150) - not clamped
24
+ * @param b usually in the range (~-150, ~+150) - not clamped
25
+ */
26
+ constructor(lightness, a, b) {
27
+ this.lightness = clamp(lightness, 0, 100);
28
+ this.a = a;
29
+ this.b = b;
30
+ }
31
+ withL(l) {
32
+ return new LAB(l, this.a, this.b);
33
+ }
34
+ withA(a) {
35
+ return new LAB(this.lightness, a, this.b);
36
+ }
37
+ withB(b) {
38
+ return new LAB(this.lightness, this.a, b);
39
+ }
40
+ toChannels() {
41
+ return [this.lightness, this.a, this.b];
42
+ }
43
+ toString() {
44
+ return `lab(${this.lightness}, ${this.a}, ${this.b})`;
45
+ }
46
+ equals(other, tollerance = TOLLERANCE) {
47
+ if (nearEquals(this.lightness, other.lightness, tollerance) && ((nearEquals(this.lightness, 100, tollerance)) || nearEquals(this.lightness, 0, tollerance))) {
48
+ return true;
49
+ }
50
+ return (nearEquals(this.lightness, other.lightness, tollerance) &&
51
+ nearEquals(this.a, other.a, tollerance) &&
52
+ nearEquals(this.b, other.b, tollerance));
53
+ }
54
+ }
@@ -0,0 +1,19 @@
1
+ export declare class LCH {
2
+ static ofChannels([l, c, h]: [l: number, c: number, h: number]): LCH;
3
+ readonly luminance: number;
4
+ readonly chroma: number;
5
+ readonly hue: number;
6
+ /**
7
+ *
8
+ * @param luminance Luminance in cd/m^2
9
+ * @param chroma
10
+ * @param hue Angle in degrees (0-360)
11
+ */
12
+ constructor(luminance: number, chroma: number, hue: number);
13
+ withLightness(l: number): LCH;
14
+ withChroma(c: number): LCH;
15
+ withHue(h: number): LCH;
16
+ toChannels(): [number, number, number];
17
+ toString(): string;
18
+ equals(other: LCH, tollerance?: number): boolean;
19
+ }
@@ -0,0 +1,44 @@
1
+ import { nearEquals } from '../numbers';
2
+ const TOLLERANCE = 0.0001;
3
+ export class LCH {
4
+ static ofChannels([l, c, h]) {
5
+ return new LCH(l, c, h);
6
+ }
7
+ luminance;
8
+ chroma;
9
+ hue;
10
+ /**
11
+ *
12
+ * @param luminance Luminance in cd/m^2
13
+ * @param chroma
14
+ * @param hue Angle in degrees (0-360)
15
+ */
16
+ constructor(luminance, chroma, hue) {
17
+ this.luminance = luminance < 0 ? 0 : luminance;
18
+ this.chroma = chroma;
19
+ this.hue = hue % 360;
20
+ }
21
+ withLightness(l) {
22
+ return new LCH(l, this.chroma, this.hue);
23
+ }
24
+ withChroma(c) {
25
+ return new LCH(this.luminance, c, this.hue);
26
+ }
27
+ withHue(h) {
28
+ return new LCH(this.luminance, this.chroma, h);
29
+ }
30
+ toChannels() {
31
+ return [this.luminance, this.chroma, this.hue];
32
+ }
33
+ toString() {
34
+ return `lch(${this.luminance}, ${this.chroma}, ${this.hue})`;
35
+ }
36
+ equals(other, tollerance = TOLLERANCE) {
37
+ if (nearEquals(this.luminance, other.luminance, tollerance) && ((nearEquals(this.luminance, 100, tollerance)) || nearEquals(this.luminance, 0, tollerance))) {
38
+ return true;
39
+ }
40
+ return (nearEquals(this.luminance, other.luminance, tollerance) &&
41
+ nearEquals(this.chroma, other.chroma, tollerance) &&
42
+ nearEquals(this.hue, other.hue, tollerance));
43
+ }
44
+ }
@@ -0,0 +1,19 @@
1
+ export declare class LUV {
2
+ static ofChannels([l, u, v]: [l: number, u: number, v: number]): LUV;
3
+ readonly l: number;
4
+ readonly u: number;
5
+ readonly v: number;
6
+ /**
7
+ *
8
+ * @param l
9
+ * @param u range (0, 1)
10
+ * @param v range (0, 1)
11
+ */
12
+ constructor(l: number, u: number, v: number);
13
+ withL(l: number): LUV;
14
+ withU(u: number): LUV;
15
+ withV(v: number): LUV;
16
+ toChannels(): [number, number, number];
17
+ toString(): string;
18
+ equals(other: LUV, tollerance?: number): boolean;
19
+ }
@@ -0,0 +1,45 @@
1
+ import { nearEquals } from '../numbers';
2
+ const TOLLERANCE = 0.0001;
3
+ export class LUV {
4
+ static ofChannels([l, u, v]) {
5
+ return new LUV(l, u, v);
6
+ }
7
+ l;
8
+ u;
9
+ v;
10
+ /**
11
+ *
12
+ * @param l
13
+ * @param u range (0, 1)
14
+ * @param v range (0, 1)
15
+ */
16
+ constructor(l, u, v) {
17
+ this.l = l;
18
+ this.u = u;
19
+ this.v = v;
20
+ }
21
+ withL(l) {
22
+ return new LUV(l, this.u, this.v);
23
+ }
24
+ withU(u) {
25
+ return new LUV(this.l, u, this.v);
26
+ }
27
+ withV(v) {
28
+ return new LUV(this.l, this.u, v);
29
+ }
30
+ toChannels() {
31
+ return [this.l, this.u, this.v];
32
+ }
33
+ toString() {
34
+ return `luv(${this.l}, ${this.u}, ${this.v})`;
35
+ }
36
+ equals(other, tollerance = TOLLERANCE) {
37
+ if ((nearEquals(this.l, other.l, tollerance) && nearEquals(this.l, 1, tollerance)) ||
38
+ nearEquals(this.l, 0, tollerance)) {
39
+ return true;
40
+ }
41
+ return (nearEquals(this.l, other.l, tollerance) &&
42
+ nearEquals(this.u, other.u, tollerance) &&
43
+ nearEquals(this.v, other.v, tollerance));
44
+ }
45
+ }
@@ -0,0 +1,13 @@
1
+ export declare class RGB {
2
+ readonly value: number;
3
+ static fromString(s: string): RGB;
4
+ static fromRGB(r: number, g: number, b: number): RGB;
5
+ static ofChannels([r, g, b]: [r: number, g: number, b: number]): RGB;
6
+ constructor(value: number);
7
+ get red(): number;
8
+ get green(): number;
9
+ get blue(): number;
10
+ toChannels(): [number, number, number];
11
+ toString(): string;
12
+ equals(other: RGB): boolean;
13
+ }
@@ -0,0 +1,47 @@
1
+ import { clampInt } from '../numbers';
2
+ export class RGB {
3
+ value;
4
+ static fromString(s) {
5
+ const m = s.match(/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i);
6
+ if (m != null) {
7
+ const r = parseInt(m[1], 16);
8
+ const g = parseInt(m[2], 16);
9
+ const b = parseInt(m[3], 16);
10
+ return RGB.fromRGB(r, g, b);
11
+ }
12
+ else {
13
+ throw new Error(`Invalid RGB string: ${s}`);
14
+ }
15
+ }
16
+ static fromRGB(r, g, b) {
17
+ return new RGB((clampInt(Math.round(r), 0, 255) << 16) |
18
+ (clampInt(Math.round(g), 0, 255) << 8) |
19
+ clampInt(Math.round(b), 0, 255));
20
+ }
21
+ static ofChannels([r, g, b]) {
22
+ return RGB.fromRGB(r * 255, g * 255, b * 255);
23
+ }
24
+ constructor(value) {
25
+ this.value = value;
26
+ }
27
+ get red() {
28
+ return (this.value >> 16) & 0xff;
29
+ }
30
+ get green() {
31
+ return (this.value >> 8) & 0xff;
32
+ }
33
+ get blue() {
34
+ return this.value & 0xff;
35
+ }
36
+ toChannels() {
37
+ return [this.red / 255, this.green / 255, this.blue / 255];
38
+ }
39
+ toString() {
40
+ return `#${this.red.toString(16).padStart(2, '0')}${this.green
41
+ .toString(16)
42
+ .padStart(2, '0')}${this.blue.toString(16).padStart(2, '0')}`;
43
+ }
44
+ equals(other) {
45
+ return this.value === other.value;
46
+ }
47
+ }
@@ -0,0 +1,12 @@
1
+ export declare class RGBA {
2
+ readonly value: number;
3
+ static fromString(s: string): RGBA;
4
+ static fromRGBA(r: number, g: number, b: number, a: number): RGBA;
5
+ constructor(value: number);
6
+ get red(): number;
7
+ get green(): number;
8
+ get blue(): number;
9
+ get alpha(): number;
10
+ toString(): string;
11
+ equals(other: RGBA): boolean;
12
+ }
@@ -0,0 +1,44 @@
1
+ import { clampInt } from '../numbers';
2
+ export class RGBA {
3
+ value;
4
+ static fromString(s) {
5
+ const m = s.match(/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i);
6
+ if (m != null) {
7
+ const r = parseInt(m[1], 16);
8
+ const g = parseInt(m[2], 16);
9
+ const b = parseInt(m[3], 16);
10
+ const a = parseInt(m[4], 16);
11
+ return RGBA.fromRGBA(r, g, b, a);
12
+ }
13
+ else {
14
+ throw new Error(`Invalid RGBA string: ${s}`);
15
+ }
16
+ }
17
+ static fromRGBA(r, g, b, a) {
18
+ return new RGBA((clampInt(r, 0, 255) << 24) |
19
+ (clampInt(g, 0, 255) << 16) |
20
+ (clampInt(b, 0, 255) << 8) |
21
+ clampInt(a, 0, 255));
22
+ }
23
+ constructor(value) {
24
+ this.value = value;
25
+ }
26
+ get red() {
27
+ return (this.value >> 24) & 0xff;
28
+ }
29
+ get green() {
30
+ return (this.value >> 16) & 0xff;
31
+ }
32
+ get blue() {
33
+ return (this.value >> 8) & 0xff;
34
+ }
35
+ get alpha() {
36
+ return this.value & 0xff;
37
+ }
38
+ toString() {
39
+ return `rgba(${this.red}, ${this.green}, ${this.blue}, ${this.alpha / 256})`;
40
+ }
41
+ equals(other) {
42
+ return this.value === other.value;
43
+ }
44
+ }
@@ -0,0 +1,24 @@
1
+ export declare class SRGB {
2
+ static fromString(s: string): SRGB;
3
+ static ofChannels([red, blue, green]: [
4
+ red: number,
5
+ blue: number,
6
+ green: number
7
+ ]): SRGB;
8
+ readonly red: number;
9
+ readonly blue: number;
10
+ readonly green: number;
11
+ /**
12
+ *
13
+ * @param red Percentage (0-100)
14
+ * @param blue Percentage (0-100)
15
+ * @param green Percentage (0-100)
16
+ */
17
+ constructor(red: number, blue: number, green: number);
18
+ withRed(red: number): SRGB;
19
+ withBlue(blue: number): SRGB;
20
+ withGreen(green: number): SRGB;
21
+ toString(): string;
22
+ toChannels(): [number, number, number];
23
+ equals(other: SRGB, tollerance?: number): boolean;
24
+ }