adaptive-extender 0.2.6 → 0.2.7

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 (139) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/dist/core/color.js +176 -179
  3. package/dist/core/color.js.map +1 -1
  4. package/dist/core/random.js +26 -18
  5. package/dist/core/random.js.map +1 -1
  6. package/dist/dom/index.js.map +1 -0
  7. package/package.json +1 -1
  8. package/dist/core/core/array.d.ts +0 -42
  9. package/dist/core/core/array.js +0 -40
  10. package/dist/core/core/array.js.map +0 -1
  11. package/dist/core/core/boolean.d.ts +0 -14
  12. package/dist/core/core/boolean.js +0 -8
  13. package/dist/core/core/boolean.js.map +0 -1
  14. package/dist/core/core/color.d.ts +0 -369
  15. package/dist/core/core/color.js +0 -540
  16. package/dist/core/core/color.js.map +0 -1
  17. package/dist/core/core/date.d.ts +0 -27
  18. package/dist/core/core/date.js +0 -18
  19. package/dist/core/core/date.js.map +0 -1
  20. package/dist/core/core/error.d.ts +0 -20
  21. package/dist/core/core/error.js +0 -20
  22. package/dist/core/core/error.js.map +0 -1
  23. package/dist/core/core/global.d.ts +0 -14
  24. package/dist/core/core/global.js +0 -13
  25. package/dist/core/core/global.js.map +0 -1
  26. package/dist/core/core/index.d.ts +0 -17
  27. package/dist/core/core/index.js +0 -16
  28. package/dist/core/core/index.js.map +0 -1
  29. package/dist/core/core/math.d.ts +0 -44
  30. package/dist/core/core/math.js +0 -43
  31. package/dist/core/core/math.js.map +0 -1
  32. package/dist/core/core/number.d.ts +0 -59
  33. package/dist/core/core/number.js +0 -51
  34. package/dist/core/core/number.js.map +0 -1
  35. package/dist/core/core/object.d.ts +0 -30
  36. package/dist/core/core/object.js +0 -21
  37. package/dist/core/core/object.js.map +0 -1
  38. package/dist/core/core/primitives.d.ts +0 -10
  39. package/dist/core/core/primitives.js +0 -3
  40. package/dist/core/core/primitives.js.map +0 -1
  41. package/dist/core/core/promise.d.ts +0 -28
  42. package/dist/core/core/promise.js +0 -58
  43. package/dist/core/core/promise.js.map +0 -1
  44. package/dist/core/core/random.d.ts +0 -103
  45. package/dist/core/core/random.js +0 -114
  46. package/dist/core/core/random.js.map +0 -1
  47. package/dist/core/core/string.d.ts +0 -67
  48. package/dist/core/core/string.js +0 -44
  49. package/dist/core/core/string.js.map +0 -1
  50. package/dist/dom/core/array.d.ts +0 -42
  51. package/dist/dom/core/array.js +0 -40
  52. package/dist/dom/core/array.js.map +0 -1
  53. package/dist/dom/core/boolean.d.ts +0 -14
  54. package/dist/dom/core/boolean.js +0 -8
  55. package/dist/dom/core/boolean.js.map +0 -1
  56. package/dist/dom/core/color.d.ts +0 -369
  57. package/dist/dom/core/color.js +0 -540
  58. package/dist/dom/core/color.js.map +0 -1
  59. package/dist/dom/core/date.d.ts +0 -27
  60. package/dist/dom/core/date.js +0 -18
  61. package/dist/dom/core/date.js.map +0 -1
  62. package/dist/dom/core/error.d.ts +0 -20
  63. package/dist/dom/core/error.js +0 -20
  64. package/dist/dom/core/error.js.map +0 -1
  65. package/dist/dom/core/global.d.ts +0 -14
  66. package/dist/dom/core/global.js +0 -13
  67. package/dist/dom/core/global.js.map +0 -1
  68. package/dist/dom/core/index.d.ts +0 -17
  69. package/dist/dom/core/index.js +0 -16
  70. package/dist/dom/core/index.js.map +0 -1
  71. package/dist/dom/core/math.d.ts +0 -44
  72. package/dist/dom/core/math.js +0 -43
  73. package/dist/dom/core/math.js.map +0 -1
  74. package/dist/dom/core/number.d.ts +0 -59
  75. package/dist/dom/core/number.js +0 -51
  76. package/dist/dom/core/number.js.map +0 -1
  77. package/dist/dom/core/object.d.ts +0 -30
  78. package/dist/dom/core/object.js +0 -21
  79. package/dist/dom/core/object.js.map +0 -1
  80. package/dist/dom/core/primitives.d.ts +0 -10
  81. package/dist/dom/core/primitives.js +0 -3
  82. package/dist/dom/core/primitives.js.map +0 -1
  83. package/dist/dom/core/promise.d.ts +0 -28
  84. package/dist/dom/core/promise.js +0 -58
  85. package/dist/dom/core/promise.js.map +0 -1
  86. package/dist/dom/core/random.d.ts +0 -103
  87. package/dist/dom/core/random.js +0 -114
  88. package/dist/dom/core/random.js.map +0 -1
  89. package/dist/dom/core/string.d.ts +0 -67
  90. package/dist/dom/core/string.js +0 -44
  91. package/dist/dom/core/string.js.map +0 -1
  92. package/dist/dom/dom/index.js.map +0 -1
  93. package/dist/node/core/array.d.ts +0 -42
  94. package/dist/node/core/array.js +0 -40
  95. package/dist/node/core/array.js.map +0 -1
  96. package/dist/node/core/boolean.d.ts +0 -14
  97. package/dist/node/core/boolean.js +0 -8
  98. package/dist/node/core/boolean.js.map +0 -1
  99. package/dist/node/core/color.d.ts +0 -369
  100. package/dist/node/core/color.js +0 -540
  101. package/dist/node/core/color.js.map +0 -1
  102. package/dist/node/core/date.d.ts +0 -27
  103. package/dist/node/core/date.js +0 -18
  104. package/dist/node/core/date.js.map +0 -1
  105. package/dist/node/core/error.d.ts +0 -20
  106. package/dist/node/core/error.js +0 -20
  107. package/dist/node/core/error.js.map +0 -1
  108. package/dist/node/core/global.d.ts +0 -14
  109. package/dist/node/core/global.js +0 -13
  110. package/dist/node/core/global.js.map +0 -1
  111. package/dist/node/core/index.d.ts +0 -17
  112. package/dist/node/core/index.js +0 -16
  113. package/dist/node/core/index.js.map +0 -1
  114. package/dist/node/core/math.d.ts +0 -44
  115. package/dist/node/core/math.js +0 -43
  116. package/dist/node/core/math.js.map +0 -1
  117. package/dist/node/core/number.d.ts +0 -59
  118. package/dist/node/core/number.js +0 -51
  119. package/dist/node/core/number.js.map +0 -1
  120. package/dist/node/core/object.d.ts +0 -30
  121. package/dist/node/core/object.js +0 -21
  122. package/dist/node/core/object.js.map +0 -1
  123. package/dist/node/core/primitives.d.ts +0 -10
  124. package/dist/node/core/primitives.js +0 -3
  125. package/dist/node/core/primitives.js.map +0 -1
  126. package/dist/node/core/promise.d.ts +0 -28
  127. package/dist/node/core/promise.js +0 -58
  128. package/dist/node/core/promise.js.map +0 -1
  129. package/dist/node/core/random.d.ts +0 -103
  130. package/dist/node/core/random.js +0 -114
  131. package/dist/node/core/random.js.map +0 -1
  132. package/dist/node/core/string.d.ts +0 -67
  133. package/dist/node/core/string.js +0 -44
  134. package/dist/node/core/string.js.map +0 -1
  135. package/dist/node/node/index.d.ts +0 -8
  136. package/dist/node/node/index.js +0 -7
  137. package/dist/node/node/index.js.map +0 -1
  138. /package/dist/dom/{dom/index.d.ts → index.d.ts} +0 -0
  139. /package/dist/dom/{dom/index.js → index.js} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,4 +1,4 @@
1
- ## 0.2.6 (14.08.2025)
1
+ ## 0.2.7 (14.08.2025)
2
2
  - Fixed alpha channel bug when converting color to string.
3
3
 
4
4
  ## 0.2.5 (14.08.2025)
@@ -1,4 +1,16 @@
1
1
  "use strict";
2
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
5
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6
+ };
7
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
8
+ if (kind === "m") throw new TypeError("Private method is not writable");
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
11
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
12
+ };
13
+ var _a, _Color_rgb, _Color_hsl, _Color_alpha, _Color_patternRGB, _Color_patternRGBA, _Color_patternHSL, _Color_patternHSLA, _Color_patternHEX, _Color_patternHEXA, _Color_variations, _Color_parse, _Color_toChannel, _Color_HSLtoRGB, _Color_toHue, _Color_RGBtoHSL, _Color_toHEXString;
2
14
  import "./number.js";
3
15
  import "./string.js";
4
16
  const { min, max, trunc, abs } = Math;
@@ -17,13 +29,11 @@ var ColorFormats;
17
29
  * conversion between formats, creation from components, and parsing from strings.
18
30
  */
19
31
  class Color {
20
- //#region Properties
21
- #rgb = new Uint8ClampedArray([0, 0, 0]);
22
32
  /**
23
33
  * Gets the red color component.
24
34
  */
25
35
  get red() {
26
- return this.#rgb[0];
36
+ return __classPrivateFieldGet(this, _Color_rgb, "f")[0];
27
37
  }
28
38
  /**
29
39
  * Sets the red color component.
@@ -31,14 +41,14 @@ class Color {
31
41
  set red(value) {
32
42
  if (!Number.isFinite(value))
33
43
  return;
34
- this.#rgb[0] = value;
35
- Color.#RGBtoHSL(this.#rgb, this.#hsl);
44
+ __classPrivateFieldGet(this, _Color_rgb, "f")[0] = value;
45
+ __classPrivateFieldGet(_a, _a, "m", _Color_RGBtoHSL).call(_a, __classPrivateFieldGet(this, _Color_rgb, "f"), __classPrivateFieldGet(this, _Color_hsl, "f"));
36
46
  }
37
47
  /**
38
48
  * Gets the green color component.
39
49
  */
40
50
  get green() {
41
- return this.#rgb[1];
51
+ return __classPrivateFieldGet(this, _Color_rgb, "f")[1];
42
52
  }
43
53
  /**
44
54
  * Sets the green color component.
@@ -46,14 +56,14 @@ class Color {
46
56
  set green(value) {
47
57
  if (!Number.isFinite(value))
48
58
  return;
49
- this.#rgb[1] = value;
50
- Color.#RGBtoHSL(this.#rgb, this.#hsl);
59
+ __classPrivateFieldGet(this, _Color_rgb, "f")[1] = value;
60
+ __classPrivateFieldGet(_a, _a, "m", _Color_RGBtoHSL).call(_a, __classPrivateFieldGet(this, _Color_rgb, "f"), __classPrivateFieldGet(this, _Color_hsl, "f"));
51
61
  }
52
62
  /**
53
63
  * Gets the blue color component.
54
64
  */
55
65
  get blue() {
56
- return this.#rgb[2];
66
+ return __classPrivateFieldGet(this, _Color_rgb, "f")[2];
57
67
  }
58
68
  /**
59
69
  * Sets the blue color component.
@@ -61,15 +71,14 @@ class Color {
61
71
  set blue(value) {
62
72
  if (!Number.isFinite(value))
63
73
  return;
64
- this.#rgb[2] = value;
65
- Color.#RGBtoHSL(this.#rgb, this.#hsl);
74
+ __classPrivateFieldGet(this, _Color_rgb, "f")[2] = value;
75
+ __classPrivateFieldGet(_a, _a, "m", _Color_RGBtoHSL).call(_a, __classPrivateFieldGet(this, _Color_rgb, "f"), __classPrivateFieldGet(this, _Color_hsl, "f"));
66
76
  }
67
- #hsl = new Uint16Array([0, 0, 0]);
68
77
  /**
69
78
  * Gets the hue color component.
70
79
  */
71
80
  get hue() {
72
- return this.#hsl[0];
81
+ return __classPrivateFieldGet(this, _Color_hsl, "f")[0];
73
82
  }
74
83
  /**
75
84
  * Sets the hue color component.
@@ -77,14 +86,14 @@ class Color {
77
86
  set hue(value) {
78
87
  if (!Number.isFinite(value))
79
88
  return;
80
- this.#hsl[0] = value.modulate(360);
81
- Color.#HSLtoRGB(this.#hsl, this.#rgb);
89
+ __classPrivateFieldGet(this, _Color_hsl, "f")[0] = value.modulate(360);
90
+ __classPrivateFieldGet(_a, _a, "m", _Color_HSLtoRGB).call(_a, __classPrivateFieldGet(this, _Color_hsl, "f"), __classPrivateFieldGet(this, _Color_rgb, "f"));
82
91
  }
83
92
  /**
84
93
  * Gets the saturation color component.
85
94
  */
86
95
  get saturation() {
87
- return this.#hsl[1];
96
+ return __classPrivateFieldGet(this, _Color_hsl, "f")[1];
88
97
  }
89
98
  /**
90
99
  * Sets the saturation color component.
@@ -92,14 +101,14 @@ class Color {
92
101
  set saturation(value) {
93
102
  if (!Number.isFinite(value))
94
103
  return;
95
- this.#hsl[1] = value.clamp(0, 100);
96
- Color.#HSLtoRGB(this.#hsl, this.#rgb);
104
+ __classPrivateFieldGet(this, _Color_hsl, "f")[1] = value.clamp(0, 100);
105
+ __classPrivateFieldGet(_a, _a, "m", _Color_HSLtoRGB).call(_a, __classPrivateFieldGet(this, _Color_hsl, "f"), __classPrivateFieldGet(this, _Color_rgb, "f"));
97
106
  }
98
107
  /**
99
108
  * Gets the lightness color component.
100
109
  */
101
110
  get lightness() {
102
- return this.#hsl[2];
111
+ return __classPrivateFieldGet(this, _Color_hsl, "f")[2];
103
112
  }
104
113
  /**
105
114
  * Sets the lightness color component.
@@ -107,15 +116,14 @@ class Color {
107
116
  set lightness(value) {
108
117
  if (!Number.isFinite(value))
109
118
  return;
110
- this.#hsl[2] = value.clamp(0, 100);
111
- Color.#HSLtoRGB(this.#hsl, this.#rgb);
119
+ __classPrivateFieldGet(this, _Color_hsl, "f")[2] = value.clamp(0, 100);
120
+ __classPrivateFieldGet(_a, _a, "m", _Color_HSLtoRGB).call(_a, __classPrivateFieldGet(this, _Color_hsl, "f"), __classPrivateFieldGet(this, _Color_rgb, "f"));
112
121
  }
113
- #alpha = 1;
114
122
  /**
115
123
  * Gets the alpha color component.
116
124
  */
117
125
  get alpha() {
118
- return this.#alpha;
126
+ return __classPrivateFieldGet(this, _Color_alpha, "f");
119
127
  }
120
128
  /**
121
129
  * Sets the alpha color component.
@@ -123,23 +131,18 @@ class Color {
123
131
  set alpha(value) {
124
132
  if (!Number.isFinite(value))
125
133
  return;
126
- this.#alpha = value.clamp(0, 1);
134
+ __classPrivateFieldSet(this, _Color_alpha, value.clamp(0, 1), "f");
127
135
  }
128
- //#endregion
129
- //#region Builders
130
- static #patternRGB = /^rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/i;
131
- static #patternRGBA = /^rgba\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*(\S+)\s*\)$/i;
132
- static #patternHSL = /^hsl\(\s*(\d+)(?:deg)?\s*,\s*(\d+)(?:%)?\s*,\s*(\d+)(?:%)?\s*\)$/i;
133
- static #patternHSLA = /^hsla\(\s*(\d+)(?:deg)?\s*,\s*(\d+)(?:%)?\s*,\s*(\d+)(?:%)?\s*,\s*(\S+)\s*\)$/i;
134
- static #patternHEX = /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i;
135
- static #patternHEXA = /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i;
136
- static #variations = Object.values(ColorFormats).flatMap(format => [{ format, deep: false }, { format, deep: true }]);
137
136
  constructor(source) {
138
- if (!(source instanceof Color))
137
+ //#region Properties
138
+ _Color_rgb.set(this, new Uint8ClampedArray([0, 0, 0]));
139
+ _Color_hsl.set(this, new Uint16Array([0, 0, 0]));
140
+ _Color_alpha.set(this, 1);
141
+ if (!(source instanceof _a))
139
142
  return;
140
- this.#rgb = Uint8ClampedArray.from(source.#rgb);
141
- this.#hsl = Uint16Array.from(source.#hsl);
142
- this.#alpha = source.#alpha;
143
+ __classPrivateFieldSet(this, _Color_rgb, Uint8ClampedArray.from(__classPrivateFieldGet(source, _Color_rgb, "f")), "f");
144
+ __classPrivateFieldSet(this, _Color_hsl, Uint16Array.from(__classPrivateFieldGet(source, _Color_hsl, "f")), "f");
145
+ __classPrivateFieldSet(this, _Color_alpha, __classPrivateFieldGet(source, _Color_alpha, "f"), "f");
143
146
  }
144
147
  static fromRGB(red, green, blue, alpha = 1) {
145
148
  if (!Number.isFinite(red))
@@ -150,12 +153,12 @@ class Color {
150
153
  throw new Error(`The blue ${blue} must be a finite number`);
151
154
  if (!Number.isFinite(alpha))
152
155
  throw new Error(`The alpha ${alpha} must be a finite number`);
153
- const color = new Color();
154
- color.#rgb[0] = red;
155
- color.#rgb[1] = green;
156
- color.#rgb[2] = blue;
157
- color.#alpha = alpha.clamp(0, 1);
158
- Color.#RGBtoHSL(color.#rgb, color.#hsl);
156
+ const color = new _a();
157
+ __classPrivateFieldGet(color, _Color_rgb, "f")[0] = red;
158
+ __classPrivateFieldGet(color, _Color_rgb, "f")[1] = green;
159
+ __classPrivateFieldGet(color, _Color_rgb, "f")[2] = blue;
160
+ __classPrivateFieldSet(color, _Color_alpha, alpha.clamp(0, 1), "f");
161
+ __classPrivateFieldGet(_a, _a, "m", _Color_RGBtoHSL).call(_a, __classPrivateFieldGet(color, _Color_rgb, "f"), __classPrivateFieldGet(color, _Color_hsl, "f"));
159
162
  return color;
160
163
  }
161
164
  static fromHSL(hue, saturation, lightness, alpha = 1) {
@@ -167,54 +170,19 @@ class Color {
167
170
  throw new Error(`The lightness ${lightness} must be a finite number`);
168
171
  if (!Number.isFinite(alpha))
169
172
  throw new Error(`The alpha ${alpha} must be a finite number`);
170
- const color = new Color();
173
+ const color = new _a();
171
174
  hue %= 360;
172
175
  if (hue < 0)
173
176
  hue += 360;
174
- color.#hsl[0] = hue;
175
- color.#hsl[1] = saturation.clamp(0, 100);
176
- color.#hsl[2] = lightness.clamp(0, 100);
177
- color.#alpha = alpha.clamp(0, 1);
178
- Color.#HSLtoRGB(color.#hsl, color.#rgb);
177
+ __classPrivateFieldGet(color, _Color_hsl, "f")[0] = hue;
178
+ __classPrivateFieldGet(color, _Color_hsl, "f")[1] = saturation.clamp(0, 100);
179
+ __classPrivateFieldGet(color, _Color_hsl, "f")[2] = lightness.clamp(0, 100);
180
+ __classPrivateFieldSet(color, _Color_alpha, alpha.clamp(0, 1), "f");
181
+ __classPrivateFieldGet(_a, _a, "m", _Color_HSLtoRGB).call(_a, __classPrivateFieldGet(color, _Color_hsl, "f"), __classPrivateFieldGet(color, _Color_rgb, "f"));
179
182
  return color;
180
183
  }
181
- static #parse(string, deep, format) {
182
- switch (format) {
183
- case ColorFormats.rgb:
184
- {
185
- const regex = (deep ? Color.#patternRGBA : Color.#patternRGB);
186
- const match = regex.exec(string.trim());
187
- if (match === null)
188
- throw new SyntaxError(`Invalid ${format} color '${string}' syntax`);
189
- const [, red, green, blue, alpha] = match.map(part => Number(part));
190
- return Color.fromRGB(red, green, blue, deep ? alpha : 1);
191
- }
192
- ;
193
- case ColorFormats.hsl:
194
- {
195
- const regex = (deep ? Color.#patternHSLA : Color.#patternHSL);
196
- const match = regex.exec(string.trim());
197
- if (match === null)
198
- throw new SyntaxError(`Invalid ${format} color '${string}' syntax`);
199
- const [, hue, saturation, lightness, alpha] = match.map(part => Number(part));
200
- return Color.fromHSL(hue, saturation, lightness, deep ? alpha : 1);
201
- }
202
- ;
203
- case ColorFormats.hex:
204
- {
205
- const regex = (deep ? Color.#patternHEXA : Color.#patternHEX);
206
- const match = regex.exec(string.trim());
207
- if (match === null)
208
- throw new SyntaxError(`Invalid ${format} color '${string}' syntax`);
209
- const [, red, green, blue, alpha] = match.map(part => Number.parseInt(part, 16));
210
- return Color.fromRGB(red, green, blue, deep ? (alpha / 255) : 1);
211
- }
212
- ;
213
- default: throw new Error(`Invalid '${format}' format for color`);
214
- }
215
- }
216
184
  static tryParse(string, options = {}) {
217
- let variations = Color.#variations;
185
+ let variations = __classPrivateFieldGet(_a, _a, "f", _Color_variations);
218
186
  for (const key in options) {
219
187
  const value = Reflect.get(options, key);
220
188
  if (value === undefined)
@@ -223,7 +191,7 @@ class Color {
223
191
  }
224
192
  for (const { format, deep } of variations) {
225
193
  try {
226
- return Color.#parse(string, deep, format);
194
+ return __classPrivateFieldGet(_a, _a, "m", _Color_parse).call(_a, string, deep, format);
227
195
  }
228
196
  catch {
229
197
  continue;
@@ -232,68 +200,19 @@ class Color {
232
200
  return null;
233
201
  }
234
202
  static parse(string, options = {}) {
235
- const color = Color.tryParse(string, options);
203
+ const color = _a.tryParse(string, options);
236
204
  if (color === null)
237
205
  throw new SyntaxError(`Unable to parse '${string}' of any selected variation`);
238
206
  return color;
239
207
  }
240
- //#endregion
241
- //#region Converters
242
- static #toChannel(offset, hue, saturation, lightness) {
243
- const sector = (offset + hue) % 12;
244
- return lightness - (saturation * min(lightness, 1 - lightness)) * min(sector - 3, 9 - sector).clamp(-1, 1);
245
- }
246
- /**
247
- * @param hsl [0 - 360], [0 - 100], [0 - 100]
248
- * @param rgb [0 - 255], [0 - 255], [0 - 255]
249
- */
250
- static #HSLtoRGB(hsl, rgb) {
251
- const hue = hsl[0] / 30;
252
- const saturation = hsl[1] / 100;
253
- const lightness = hsl[2] / 100;
254
- rgb[0] = Color.#toChannel(0, hue, saturation, lightness) * 255;
255
- rgb[1] = Color.#toChannel(8, hue, saturation, lightness) * 255;
256
- rgb[2] = Color.#toChannel(4, hue, saturation, lightness) * 255;
257
- }
258
- static #toHue(maximum, red, green, blue, difference) {
259
- switch (maximum) {
260
- case red: return (green - blue) / difference + 0;
261
- case green: return (blue - red) / difference + 2;
262
- case blue: return (red - green) / difference + 4;
263
- default: throw new Error(`Invalid '${maximum}' maximum for colors`);
264
- }
265
- }
266
- /**
267
- * @param rgb [0 - 255], [0 - 255], [0 - 255]
268
- * @param hsl [0 - 360], [0 - 100], [0 - 100]
269
- */
270
- static #RGBtoHSL(rgb, hsl) {
271
- const red = rgb[0] / 255;
272
- const green = rgb[1] / 255;
273
- const blue = rgb[2] / 255;
274
- const minimum = min(red, green, blue);
275
- const maximum = max(red, green, blue);
276
- const difference = maximum - minimum;
277
- let hue = Color.#toHue(maximum, red, green, blue, difference);
278
- hue = difference && hue;
279
- if (hue < 0)
280
- hue += 6;
281
- hsl[0] = hue * 60;
282
- const median = 1 - abs(maximum + minimum - 1);
283
- hsl[1] = (median && (difference / median)) * 100;
284
- hsl[2] = (maximum + minimum) / 2 * 100;
285
- }
286
- static #toHEXString(byte) {
287
- return byte.toString(16).padStart(2, "0");
288
- }
289
208
  toString(options = {}) {
290
209
  let { format, deep } = options;
291
- format ??= ColorFormats.rgb;
292
- deep ??= true;
210
+ format ?? (format = ColorFormats.rgb);
211
+ deep ?? (deep = true);
293
212
  switch (format) {
294
213
  case ColorFormats.rgb: return `rgb${deep ? "a" : String.empty}(${this.red}, ${this.green}, ${this.blue}${deep ? `, ${this.alpha}` : String.empty})`;
295
214
  case ColorFormats.hsl: return `hsl${deep ? "a" : String.empty}(${this.hue}deg, ${this.saturation}%, ${this.lightness}%${deep ? `, ${this.alpha}` : String.empty})`;
296
- case ColorFormats.hex: return `#${Color.#toHEXString(this.red)}${Color.#toHEXString(this.green)}${Color.#toHEXString(this.blue)}${deep ? Color.#toHEXString(trunc(this.alpha * 255)) : String.empty}`;
215
+ case ColorFormats.hex: return `#${__classPrivateFieldGet(_a, _a, "m", _Color_toHEXString).call(_a, this.red)}${__classPrivateFieldGet(_a, _a, "m", _Color_toHEXString).call(_a, this.green)}${__classPrivateFieldGet(_a, _a, "m", _Color_toHEXString).call(_a, this.blue)}${deep ? __classPrivateFieldGet(_a, _a, "m", _Color_toHEXString).call(_a, trunc(this.alpha * 255)) : String.empty}`;
297
216
  default: throw new Error(`Invalid '${format}' format for color`);
298
217
  }
299
218
  }
@@ -303,109 +222,109 @@ class Color {
303
222
  * Transparent color preset.
304
223
  * @readonly
305
224
  */
306
- static get newTransparent() { return Color.fromRGB(0, 0, 0, 0); }
225
+ static get newTransparent() { return _a.fromRGB(0, 0, 0, 0); }
307
226
  ;
308
227
  /**
309
228
  * Maroon color preset.
310
229
  * @readonly
311
230
  */
312
- static get newMaroon() { return Color.fromRGB(128, 0, 0); }
231
+ static get newMaroon() { return _a.fromRGB(128, 0, 0); }
313
232
  ;
314
233
  /**
315
234
  * Red color preset.
316
235
  * @readonly
317
236
  */
318
- static get newRed() { return Color.fromRGB(255, 0, 0); }
237
+ static get newRed() { return _a.fromRGB(255, 0, 0); }
319
238
  ;
320
239
  /**
321
240
  * Orange color preset.
322
241
  * @readonly
323
242
  */
324
- static get newOrange() { return Color.fromRGB(255, 165, 0); }
243
+ static get newOrange() { return _a.fromRGB(255, 165, 0); }
325
244
  ;
326
245
  /**
327
246
  * Yellow color preset.
328
247
  * @readonly
329
248
  */
330
- static get newYellow() { return Color.fromRGB(255, 255, 0); }
249
+ static get newYellow() { return _a.fromRGB(255, 255, 0); }
331
250
  ;
332
251
  /**
333
252
  * Olive color preset.
334
253
  * @readonly
335
254
  */
336
- static get newOlive() { return Color.fromRGB(128, 128, 0); }
255
+ static get newOlive() { return _a.fromRGB(128, 128, 0); }
337
256
  ;
338
257
  /**
339
258
  * Green color preset.
340
259
  * @readonly
341
260
  */
342
- static get newGreen() { return Color.fromRGB(0, 128, 0); }
261
+ static get newGreen() { return _a.fromRGB(0, 128, 0); }
343
262
  ;
344
263
  /**
345
264
  * Purple color preset.
346
265
  * @readonly
347
266
  */
348
- static get newPurple() { return Color.fromRGB(128, 0, 128); }
267
+ static get newPurple() { return _a.fromRGB(128, 0, 128); }
349
268
  ;
350
269
  /**
351
270
  * Fuchsia color preset.
352
271
  * @readonly
353
272
  */
354
- static get newFuchsia() { return Color.fromRGB(255, 0, 255); }
273
+ static get newFuchsia() { return _a.fromRGB(255, 0, 255); }
355
274
  ;
356
275
  /**
357
276
  * Lime color preset.
358
277
  * @readonly
359
278
  */
360
- static get newLime() { return Color.fromRGB(0, 255, 0); }
279
+ static get newLime() { return _a.fromRGB(0, 255, 0); }
361
280
  ;
362
281
  /**
363
282
  * Teal color preset.
364
283
  * @readonly
365
284
  */
366
- static get newTeal() { return Color.fromRGB(0, 128, 128); }
285
+ static get newTeal() { return _a.fromRGB(0, 128, 128); }
367
286
  ;
368
287
  /**
369
288
  * Aqua color preset.
370
289
  * @readonly
371
290
  */
372
- static get newAqua() { return Color.fromRGB(0, 255, 255); }
291
+ static get newAqua() { return _a.fromRGB(0, 255, 255); }
373
292
  ;
374
293
  /**
375
294
  * Blue color preset.
376
295
  * @readonly
377
296
  */
378
- static get newBlue() { return Color.fromRGB(0, 0, 255); }
297
+ static get newBlue() { return _a.fromRGB(0, 0, 255); }
379
298
  ;
380
299
  /**
381
300
  * Navy color preset.
382
301
  * @readonly
383
302
  */
384
- static get newNavy() { return Color.fromRGB(0, 0, 128); }
303
+ static get newNavy() { return _a.fromRGB(0, 0, 128); }
385
304
  ;
386
305
  /**
387
306
  * Black color preset.
388
307
  * @readonly
389
308
  */
390
- static get newBlack() { return Color.fromRGB(0, 0, 0); }
309
+ static get newBlack() { return _a.fromRGB(0, 0, 0); }
391
310
  ;
392
311
  /**
393
312
  * Gray color preset.
394
313
  * @readonly
395
314
  */
396
- static get newGray() { return Color.fromRGB(128, 128, 128); }
315
+ static get newGray() { return _a.fromRGB(128, 128, 128); }
397
316
  ;
398
317
  /**
399
318
  * Silver color preset.
400
319
  * @readonly
401
320
  */
402
- static get newSilver() { return Color.fromRGB(192, 192, 192); }
321
+ static get newSilver() { return _a.fromRGB(192, 192, 192); }
403
322
  ;
404
323
  /**
405
324
  * White color preset.
406
325
  * @readonly
407
326
  */
408
- static get newWhite() { return Color.fromRGB(255, 255, 255); }
327
+ static get newWhite() { return _a.fromRGB(255, 255, 255); }
409
328
  ;
410
329
  static mix(first, second, ratio = 0.5) {
411
330
  if (!Number.isFinite(ratio))
@@ -415,7 +334,7 @@ class Color {
415
334
  const green = first.green + (second.green - first.green) * ratio;
416
335
  const blue = first.blue + (second.blue - first.blue) * ratio;
417
336
  const alpha = first.alpha + (second.alpha - first.alpha) * ratio;
418
- return Color.fromRGB(red, green, blue, alpha);
337
+ return _a.fromRGB(red, green, blue, alpha);
419
338
  }
420
339
  grayscale(scale = 1) {
421
340
  if (!Number.isFinite(scale))
@@ -423,10 +342,10 @@ class Color {
423
342
  scale = scale.clamp(0, 1);
424
343
  const { red, green, blue } = this;
425
344
  const achromatic = (red + green + blue) / 3;
426
- this.#rgb[0] = red + (achromatic - red) * scale;
427
- this.#rgb[1] = green + (achromatic - green) * scale;
428
- this.#rgb[2] = blue + (achromatic - blue) * scale;
429
- Color.#RGBtoHSL(this.#rgb, this.#hsl);
345
+ __classPrivateFieldGet(this, _Color_rgb, "f")[0] = red + (achromatic - red) * scale;
346
+ __classPrivateFieldGet(this, _Color_rgb, "f")[1] = green + (achromatic - green) * scale;
347
+ __classPrivateFieldGet(this, _Color_rgb, "f")[2] = blue + (achromatic - blue) * scale;
348
+ __classPrivateFieldGet(_a, _a, "m", _Color_RGBtoHSL).call(_a, __classPrivateFieldGet(this, _Color_rgb, "f"), __classPrivateFieldGet(this, _Color_hsl, "f"));
430
349
  return this;
431
350
  }
432
351
  redEmphasis(scale = 1) {
@@ -435,9 +354,9 @@ class Color {
435
354
  scale = scale.clamp(0, 1);
436
355
  const { green, blue } = this;
437
356
  const average = (green + blue) / 2;
438
- this.#rgb[1] = green + (average - green) * scale;
439
- this.#rgb[2] = blue + (average - blue) * scale;
440
- Color.#RGBtoHSL(this.#rgb, this.#hsl);
357
+ __classPrivateFieldGet(this, _Color_rgb, "f")[1] = green + (average - green) * scale;
358
+ __classPrivateFieldGet(this, _Color_rgb, "f")[2] = blue + (average - blue) * scale;
359
+ __classPrivateFieldGet(_a, _a, "m", _Color_RGBtoHSL).call(_a, __classPrivateFieldGet(this, _Color_rgb, "f"), __classPrivateFieldGet(this, _Color_hsl, "f"));
441
360
  return this;
442
361
  }
443
362
  greenEmphasis(scale = 1) {
@@ -446,9 +365,9 @@ class Color {
446
365
  scale = scale.clamp(0, 1);
447
366
  const { red, blue } = this;
448
367
  const average = (red + blue) / 2;
449
- this.#rgb[0] = red + (average - red) * scale;
450
- this.#rgb[2] = blue + (average - blue) * scale;
451
- Color.#RGBtoHSL(this.#rgb, this.#hsl);
368
+ __classPrivateFieldGet(this, _Color_rgb, "f")[0] = red + (average - red) * scale;
369
+ __classPrivateFieldGet(this, _Color_rgb, "f")[2] = blue + (average - blue) * scale;
370
+ __classPrivateFieldGet(_a, _a, "m", _Color_RGBtoHSL).call(_a, __classPrivateFieldGet(this, _Color_rgb, "f"), __classPrivateFieldGet(this, _Color_hsl, "f"));
452
371
  return this;
453
372
  }
454
373
  blueEmphasis(scale = 1) {
@@ -457,9 +376,9 @@ class Color {
457
376
  scale = scale.clamp(0, 1);
458
377
  const { red, green } = this;
459
378
  const average = (red + green) / 2;
460
- this.#rgb[0] = red + (average - red) * scale;
461
- this.#rgb[1] = green + (average - green) * scale;
462
- Color.#RGBtoHSL(this.#rgb, this.#hsl);
379
+ __classPrivateFieldGet(this, _Color_rgb, "f")[0] = red + (average - red) * scale;
380
+ __classPrivateFieldGet(this, _Color_rgb, "f")[1] = green + (average - green) * scale;
381
+ __classPrivateFieldGet(_a, _a, "m", _Color_RGBtoHSL).call(_a, __classPrivateFieldGet(this, _Color_rgb, "f"), __classPrivateFieldGet(this, _Color_hsl, "f"));
463
382
  return this;
464
383
  }
465
384
  invert(scale = 1) {
@@ -467,10 +386,10 @@ class Color {
467
386
  throw new Error(`The scale ${scale} must be a finite number`);
468
387
  scale = scale.clamp(0, 1);
469
388
  const { red, green, blue } = this;
470
- this.#rgb[0] = red + ((255 - red) - red) * scale;
471
- this.#rgb[1] = green + ((255 - green) - green) * scale;
472
- this.#rgb[2] = blue + ((255 - blue) - blue) * scale;
473
- Color.#RGBtoHSL(this.#rgb, this.#hsl);
389
+ __classPrivateFieldGet(this, _Color_rgb, "f")[0] = red + ((255 - red) - red) * scale;
390
+ __classPrivateFieldGet(this, _Color_rgb, "f")[1] = green + ((255 - green) - green) * scale;
391
+ __classPrivateFieldGet(this, _Color_rgb, "f")[2] = blue + ((255 - blue) - blue) * scale;
392
+ __classPrivateFieldGet(_a, _a, "m", _Color_RGBtoHSL).call(_a, __classPrivateFieldGet(this, _Color_rgb, "f"), __classPrivateFieldGet(this, _Color_hsl, "f"));
474
393
  return this;
475
394
  }
476
395
  sepia(scale = 1) {
@@ -481,10 +400,10 @@ class Color {
481
400
  const redness = (red * 0.393) + (green * 0.769) + (blue * 0.189);
482
401
  const greenness = (red * 0.349) + (green * 0.686) + (blue * 0.168);
483
402
  const blueness = (red * 0.272) + (green * 0.534) + (blue * 0.131);
484
- this.#rgb[0] = red + (redness - red) * scale;
485
- this.#rgb[1] = green + (greenness - green) * scale;
486
- this.#rgb[2] = blue + (blueness - blue) * scale;
487
- Color.#RGBtoHSL(this.#rgb, this.#hsl);
403
+ __classPrivateFieldGet(this, _Color_rgb, "f")[0] = red + (redness - red) * scale;
404
+ __classPrivateFieldGet(this, _Color_rgb, "f")[1] = green + (greenness - green) * scale;
405
+ __classPrivateFieldGet(this, _Color_rgb, "f")[2] = blue + (blueness - blue) * scale;
406
+ __classPrivateFieldGet(_a, _a, "m", _Color_RGBtoHSL).call(_a, __classPrivateFieldGet(this, _Color_rgb, "f"), __classPrivateFieldGet(this, _Color_hsl, "f"));
488
407
  return this;
489
408
  }
490
409
  /**
@@ -536,5 +455,83 @@ class Color {
536
455
  return this;
537
456
  }
538
457
  }
458
+ _a = Color, _Color_rgb = new WeakMap(), _Color_hsl = new WeakMap(), _Color_alpha = new WeakMap(), _Color_parse = function _Color_parse(string, deep, format) {
459
+ switch (format) {
460
+ case ColorFormats.rgb:
461
+ {
462
+ const regex = (deep ? __classPrivateFieldGet(_a, _a, "f", _Color_patternRGBA) : __classPrivateFieldGet(_a, _a, "f", _Color_patternRGB));
463
+ const match = regex.exec(string.trim());
464
+ if (match === null)
465
+ throw new SyntaxError(`Invalid ${format} color '${string}' syntax`);
466
+ const [, red, green, blue, alpha] = match.map(part => Number(part));
467
+ return _a.fromRGB(red, green, blue, deep ? alpha : 1);
468
+ }
469
+ ;
470
+ case ColorFormats.hsl:
471
+ {
472
+ const regex = (deep ? __classPrivateFieldGet(_a, _a, "f", _Color_patternHSLA) : __classPrivateFieldGet(_a, _a, "f", _Color_patternHSL));
473
+ const match = regex.exec(string.trim());
474
+ if (match === null)
475
+ throw new SyntaxError(`Invalid ${format} color '${string}' syntax`);
476
+ const [, hue, saturation, lightness, alpha] = match.map(part => Number(part));
477
+ return _a.fromHSL(hue, saturation, lightness, deep ? alpha : 1);
478
+ }
479
+ ;
480
+ case ColorFormats.hex:
481
+ {
482
+ const regex = (deep ? __classPrivateFieldGet(_a, _a, "f", _Color_patternHEXA) : __classPrivateFieldGet(_a, _a, "f", _Color_patternHEX));
483
+ const match = regex.exec(string.trim());
484
+ if (match === null)
485
+ throw new SyntaxError(`Invalid ${format} color '${string}' syntax`);
486
+ const [, red, green, blue, alpha] = match.map(part => Number.parseInt(part, 16));
487
+ return _a.fromRGB(red, green, blue, deep ? (alpha / 255) : 1);
488
+ }
489
+ ;
490
+ default: throw new Error(`Invalid '${format}' format for color`);
491
+ }
492
+ }, _Color_toChannel = function _Color_toChannel(offset, hue, saturation, lightness) {
493
+ const sector = (offset + hue) % 12;
494
+ return lightness - (saturation * min(lightness, 1 - lightness)) * min(sector - 3, 9 - sector).clamp(-1, 1);
495
+ }, _Color_HSLtoRGB = function _Color_HSLtoRGB(hsl, rgb) {
496
+ const hue = hsl[0] / 30;
497
+ const saturation = hsl[1] / 100;
498
+ const lightness = hsl[2] / 100;
499
+ rgb[0] = __classPrivateFieldGet(_a, _a, "m", _Color_toChannel).call(_a, 0, hue, saturation, lightness) * 255;
500
+ rgb[1] = __classPrivateFieldGet(_a, _a, "m", _Color_toChannel).call(_a, 8, hue, saturation, lightness) * 255;
501
+ rgb[2] = __classPrivateFieldGet(_a, _a, "m", _Color_toChannel).call(_a, 4, hue, saturation, lightness) * 255;
502
+ }, _Color_toHue = function _Color_toHue(maximum, red, green, blue, difference) {
503
+ switch (maximum) {
504
+ case red: return (green - blue) / difference + 0;
505
+ case green: return (blue - red) / difference + 2;
506
+ case blue: return (red - green) / difference + 4;
507
+ default: throw new Error(`Invalid '${maximum}' maximum for colors`);
508
+ }
509
+ }, _Color_RGBtoHSL = function _Color_RGBtoHSL(rgb, hsl) {
510
+ const red = rgb[0] / 255;
511
+ const green = rgb[1] / 255;
512
+ const blue = rgb[2] / 255;
513
+ const minimum = min(red, green, blue);
514
+ const maximum = max(red, green, blue);
515
+ const difference = maximum - minimum;
516
+ let hue = __classPrivateFieldGet(_a, _a, "m", _Color_toHue).call(_a, maximum, red, green, blue, difference);
517
+ hue = difference && hue;
518
+ if (hue < 0)
519
+ hue += 6;
520
+ hsl[0] = hue * 60;
521
+ const median = 1 - abs(maximum + minimum - 1);
522
+ hsl[1] = (median && (difference / median)) * 100;
523
+ hsl[2] = (maximum + minimum) / 2 * 100;
524
+ }, _Color_toHEXString = function _Color_toHEXString(byte) {
525
+ return byte.toString(16).padStart(2, "0");
526
+ };
527
+ //#endregion
528
+ //#region Builders
529
+ _Color_patternRGB = { value: /^rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/i };
530
+ _Color_patternRGBA = { value: /^rgba\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*(\S+)\s*\)$/i };
531
+ _Color_patternHSL = { value: /^hsl\(\s*(\d+)(?:deg)?\s*,\s*(\d+)(?:%)?\s*,\s*(\d+)(?:%)?\s*\)$/i };
532
+ _Color_patternHSLA = { value: /^hsla\(\s*(\d+)(?:deg)?\s*,\s*(\d+)(?:%)?\s*,\s*(\d+)(?:%)?\s*,\s*(\S+)\s*\)$/i };
533
+ _Color_patternHEX = { value: /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i };
534
+ _Color_patternHEXA = { value: /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i };
535
+ _Color_variations = { value: Object.values(ColorFormats).flatMap(format => [{ format, deep: false }, { format, deep: true }]) };
539
536
  export { ColorFormats, Color };
540
537
  //# sourceMappingURL=color.js.map